Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ public CreateInstanceRequest addLabel(@Nonnull String key, @Nonnull String value
return this;
}

/**
* Adds a tag to the instance.
*
* <p>Tags are a way to organize and govern resources across Google Cloud. Unlike labels, Tags are
* standalone resources created and managed through the Resource Manager API.
*
* @see <a href="https://cloud.google.com/bigtable/docs/tags">For more details</a>
*/
@SuppressWarnings("WeakerAccess")
public CreateInstanceRequest addTag(@Nonnull String key, @Nonnull String value) {
Preconditions.checkNotNull(key, "Key can't be null");
Preconditions.checkNotNull(value, "Value can't be null");
builder.getInstanceBuilder().putTags(key, value);
return this;
}

/**
* Adds a cluster to the instance request with manual scaling enabled.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ public String getDisplayName() {
return proto.getDisplayName();
}

/** Gets the instance's tags. */
@SuppressWarnings("WeakerAccess")
public Map<String, String> getTags() {
return proto.getTagsMap();
}

/** Gets the instance's current type. Can be DEVELOPMENT or PRODUCTION. */
@SuppressWarnings("WeakerAccess")
public Type getType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void testOptionalFields() {
.setDisplayName("custom display name")
.addLabel("my label", "with some value")
.addLabel("my other label", "with some value")
.addTag("tagKeys/123", "tagValues/456")
.setType(Instance.Type.DEVELOPMENT)
.addCluster("cluster1", "us-east1-c", 1, StorageType.SSD);

Expand All @@ -142,6 +143,7 @@ public void testOptionalFields() {
.setDisplayName("custom display name")
.putLabels("my label", "with some value")
.putLabels("my other label", "with some value")
.putTags("tagKeys/123", "tagValues/456")
.setType(com.google.bigtable.admin.v2.Instance.Type.DEVELOPMENT))
.putClusters(
"cluster1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public void testFromProto() {
.setState(com.google.bigtable.admin.v2.Instance.State.READY)
.putLabels("label1", "value1")
.putLabels("label2", "value2")
.putTags("tagKeys/123", "tagValues/456")
.putTags("tagKeys/234", "tagValues/567")
.build();

Instance result = Instance.fromProto(proto);
Expand All @@ -48,6 +50,8 @@ public void testFromProto() {
.containsExactly(
"label1", "value1",
"label2", "value2");
assertThat(result.getTags())
.containsExactly("tagKeys/123", "tagValues/456", "tagKeys/234", "tagValues/567");
}

@Test
Expand All @@ -59,6 +63,7 @@ public void testRequiresName() {
.setState(com.google.bigtable.admin.v2.Instance.State.READY)
.putLabels("label1", "value1")
.putLabels("label2", "value2")
.putTags("tagKeys/123", "tagValues/456")
.build();

Exception actualException = null;
Expand Down
Loading