Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit f83c08b

Browse files
committed
feat(bigtable): Add support for creating instance with tags
1 parent 552b6a2 commit f83c08b

5 files changed

Lines changed: 49 additions & 22 deletions

File tree

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/CreateInstanceRequest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ public CreateInstanceRequest addLabel(@Nonnull String key, @Nonnull String value
118118
return this;
119119
}
120120

121+
/**
122+
* Adds a tag to the instance.
123+
*
124+
* <p>Tags are a way to organize and govern resources across Google Cloud. Unlike labels,
125+
* Tags are standalone resources created and managed through the Resource Manager API.
126+
*
127+
* @see <a href="https://https://cloud.google.com/bigtable/docs/tags">For more details</a>
128+
*/
129+
@SuppressWarnings("WeakerAccess")
130+
public CreateInstanceRequest addTag(@Nonnull String key, @Nonnull String value) {
131+
Preconditions.checkNotNull(key, "Key can't be null");
132+
Preconditions.checkNotNull(value, "Value can't be null");
133+
builder.getInstanceBuilder().putTags(key, value);
134+
return this;
135+
}
136+
121137
/**
122138
* Adds a cluster to the instance request with manual scaling enabled.
123139
*

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/admin/v2/models/Instance.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ public String getDisplayName() {
150150
return proto.getDisplayName();
151151
}
152152

153+
/** Gets the instance's tags. */
154+
@SuppressWarnings("WeakerAccess")
155+
public Map<String,String> getTags() {
156+
return proto.getTagsMap();
157+
}
158+
153159
/** Gets the instance's current type. Can be DEVELOPMENT or PRODUCTION. */
154160
@SuppressWarnings("WeakerAccess")
155161
public Type getType() {

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClientTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ public void testCreateInstance() {
334334
.setInstance(
335335
com.google.bigtable.admin.v2.Instance.newBuilder()
336336
.setType(com.google.bigtable.admin.v2.Instance.Type.DEVELOPMENT)
337-
.setDisplayName(INSTANCE_ID))
337+
.setDisplayName(INSTANCE_ID)
338+
.putTags("tagKeys/123", "tagValues/456"))
338339
.putClusters(
339340
"cluster1",
340341
com.google.bigtable.admin.v2.Cluster.newBuilder()

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/CreateClusterRequestTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public void testOptionalFields() {
128128
.setDisplayName("custom display name")
129129
.addLabel("my label", "with some value")
130130
.addLabel("my other label", "with some value")
131+
.addTag("tagKeys/123", "tagValues/456")
131132
.setType(Instance.Type.DEVELOPMENT)
132133
.addCluster("cluster1", "us-east1-c", 1, StorageType.SSD);
133134

@@ -142,6 +143,7 @@ public void testOptionalFields() {
142143
.setDisplayName("custom display name")
143144
.putLabels("my label", "with some value")
144145
.putLabels("my other label", "with some value")
146+
.putTags("tagKeys/123", "tagValues/456")
145147
.setType(com.google.bigtable.admin.v2.Instance.Type.DEVELOPMENT))
146148
.putClusters(
147149
"cluster1",

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/InstanceTest.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ public class InstanceTest {
2828

2929
@Test
3030
public void testFromProto() {
31-
com.google.bigtable.admin.v2.Instance proto =
32-
com.google.bigtable.admin.v2.Instance.newBuilder()
33-
.setName("projects/my-project/instances/my-instance")
34-
.setDisplayName("my display name")
35-
.setType(com.google.bigtable.admin.v2.Instance.Type.PRODUCTION)
36-
.setState(com.google.bigtable.admin.v2.Instance.State.READY)
37-
.putLabels("label1", "value1")
38-
.putLabels("label2", "value2")
39-
.build();
31+
com.google.bigtable.admin.v2.Instance proto = com.google.bigtable.admin.v2.Instance.newBuilder()
32+
.setName("projects/my-project/instances/my-instance")
33+
.setDisplayName("my display name")
34+
.setType(com.google.bigtable.admin.v2.Instance.Type.PRODUCTION)
35+
.setState(com.google.bigtable.admin.v2.Instance.State.READY)
36+
.putLabels("label1", "value1")
37+
.putLabels("label2", "value2")
38+
.putTags("tagKeys/123", "tagValues/456")
39+
.putTags("tagKeys/234", "tagValues/567")
40+
.build();
4041

4142
Instance result = Instance.fromProto(proto);
4243

@@ -48,18 +49,19 @@ public void testFromProto() {
4849
.containsExactly(
4950
"label1", "value1",
5051
"label2", "value2");
52+
assertThat(result.getTags()).containsExactly("tagKeys/123", "tagValues/456", "tagKeys/234", "tagValues/567");
5153
}
5254

5355
@Test
5456
public void testRequiresName() {
55-
com.google.bigtable.admin.v2.Instance proto =
56-
com.google.bigtable.admin.v2.Instance.newBuilder()
57-
.setDisplayName("my display name")
58-
.setType(com.google.bigtable.admin.v2.Instance.Type.PRODUCTION)
59-
.setState(com.google.bigtable.admin.v2.Instance.State.READY)
60-
.putLabels("label1", "value1")
61-
.putLabels("label2", "value2")
62-
.build();
57+
com.google.bigtable.admin.v2.Instance proto = com.google.bigtable.admin.v2.Instance.newBuilder()
58+
.setDisplayName("my display name")
59+
.setType(com.google.bigtable.admin.v2.Instance.Type.PRODUCTION)
60+
.setState(com.google.bigtable.admin.v2.Instance.State.READY)
61+
.putLabels("label1", "value1")
62+
.putLabels("label2", "value2")
63+
.putTags("tagKeys/123", "tagValues/456")
64+
.build();
6365

6466
Exception actualException = null;
6567

@@ -74,8 +76,8 @@ public void testRequiresName() {
7476

7577
@Test
7678
public void testTypeEnumUpToDate() {
77-
List<com.google.bigtable.admin.v2.Instance.Type> validProtoValues =
78-
Lists.newArrayList(com.google.bigtable.admin.v2.Instance.Type.values());
79+
List<com.google.bigtable.admin.v2.Instance.Type> validProtoValues = Lists
80+
.newArrayList(com.google.bigtable.admin.v2.Instance.Type.values());
7981

8082
// TYPE_UNSPECIFIED is not surfaced
8183
validProtoValues.remove(com.google.bigtable.admin.v2.Instance.Type.TYPE_UNSPECIFIED);
@@ -100,8 +102,8 @@ public void testTypeEnumUpToDate() {
100102

101103
@Test
102104
public void testStateEnumUpToDate() {
103-
List<com.google.bigtable.admin.v2.Instance.State> validProtoValues =
104-
Lists.newArrayList(com.google.bigtable.admin.v2.Instance.State.values());
105+
List<com.google.bigtable.admin.v2.Instance.State> validProtoValues = Lists
106+
.newArrayList(com.google.bigtable.admin.v2.Instance.State.values());
105107

106108
List<Instance.State> validModelValues = Lists.newArrayList(Instance.State.values());
107109

0 commit comments

Comments
 (0)