Skip to content

Commit 73a5658

Browse files
committed
feat(Bigtable): Add support for creating instances with tags
1 parent 5cf4e9d commit 73a5658

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

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, Tags are
125+
* standalone resources created and managed through the Resource Manager API.
126+
*
127+
* @see <a href="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/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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public void testFromProto() {
3636
.setState(com.google.bigtable.admin.v2.Instance.State.READY)
3737
.putLabels("label1", "value1")
3838
.putLabels("label2", "value2")
39+
.putTags("tagKeys/123", "tagValues/456")
40+
.putTags("tagKeys/234", "tagValues/567")
3941
.build();
4042

4143
Instance result = Instance.fromProto(proto);
@@ -48,6 +50,9 @@ public void testFromProto() {
4850
.containsExactly(
4951
"label1", "value1",
5052
"label2", "value2");
53+
54+
assertThat(result.getTags())
55+
.containsExactly("tagKeys/123", "tagValues/456", "tagKeys/234", "tagValues/567");
5156
}
5257

5358
@Test
@@ -59,6 +64,7 @@ public void testRequiresName() {
5964
.setState(com.google.bigtable.admin.v2.Instance.State.READY)
6065
.putLabels("label1", "value1")
6166
.putLabels("label2", "value2")
67+
.putTags("tagKeys/123", "tagValues/456")
6268
.build();
6369

6470
Exception actualException = null;

0 commit comments

Comments
 (0)