Skip to content

Commit e705d4d

Browse files
---
yaml --- r: 16357 b: refs/heads/autosynth-iot c: 28720b5 h: refs/heads/master i: 16355: 603efd8
1 parent 4a51ad9 commit e705d4d

27 files changed

Lines changed: 581 additions & 359 deletions

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ refs/heads/autosynth-datastore: 9acd400b484d6691a080c9152a331d88d24fefc1
133133
refs/heads/autosynth-dialogflow: d7477419376eac9b6dcc7dbcede581152527351d
134134
refs/heads/autosynth-errorreporting: 9891e73a56af7c097829ca7a521b0e862ba6af30
135135
refs/heads/autosynth-firestore: ddb29f8ee445a938fc40be8227dea87b3f508ab3
136-
refs/heads/autosynth-iot: ba4ba16b4d056c720dca3e0f5f568e79986acd51
136+
refs/heads/autosynth-iot: 28720b51769e728785ea7d76bdb77062750ade8d
137137
refs/heads/autosynth-kms: dcc6e15d68759010c8735cc868135bd7e6c1cc5f
138138
refs/heads/autosynth-language: 8972866b016473559702424205ce5569de47b34d
139139
refs/heads/autosynth-os-login: daa910328b954bbe87068f684a3088ed910f1ddf

branches/autosynth-iot/.kokoro/continuous/bigtableadmin-it.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ env_vars: {
88

99
env_vars: {
1010
key: "INTEGRATION_TEST_ARGS"
11-
value: "google-cloud-clients/google-cloud-bigtable-admin -Dbigtable.instance=projects/gcloud-devel/instances/google-cloud-bigtable"
11+
value: "google-cloud-clients/google-cloud-bigtable-admin -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable"
1212
}
1313

1414
env_vars: {

branches/autosynth-iot/.kokoro/nightly/bigtableadmin-it.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ env_vars: {
88

99
env_vars: {
1010
key: "INTEGRATION_TEST_ARGS"
11-
value: "google-cloud-clients/google-cloud-bigtable-admin -Dbigtable.instance=projects/gcloud-devel/instances/google-cloud-bigtable"
11+
value: "google-cloud-clients/google-cloud-bigtable-admin -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable"
1212
}
1313

1414
env_vars: {

branches/autosynth-iot/.kokoro/presubmit/bigtableadmin-it.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ env_vars: {
88

99
env_vars: {
1010
key: "INTEGRATION_TEST_ARGS"
11-
value: "google-cloud-clients/google-cloud-bigtable-admin -Dbigtable.instance=projects/gcloud-devel/instances/google-cloud-bigtable"
11+
value: "google-cloud-clients/google-cloud-bigtable-admin -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable"
1212
}
1313

1414
env_vars: {

branches/autosynth-iot/TESTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ To run the tests:
7979
created earlier. Example:
8080
```shell
8181
mvn verify -am -pl google-cloud-bigtable-admin \
82-
-Dbigtable.instance=projects/my-project/instances/my-instance
82+
-Dbigtable.project=my-project
83+
-Dbigtable.instance=my-instance
8384
```
8485
8586
### Testing code that uses Compute

branches/autosynth-iot/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminClient.java

Lines changed: 92 additions & 66 deletions
Large diffs are not rendered by default.

branches/autosynth-iot/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettings.java

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@
2626
/**
2727
* Settings class to configure an instance of {@link BigtableInstanceAdminClient}.
2828
*
29-
* <p>It must be configured with a {@link ProjectName} and can be used to change default RPC
30-
* settings.
29+
* <p>It must be configured with a project id and can be used to change default RPC settings.
3130
*
3231
* <p>Example usage:
3332
*
3433
* <pre>{@code
3534
* BigtableInstanceAdminSettings.Builder settingsBuilder = BigtableInstanceAdminSettings.newBuilder()
36-
* .setProjectName(ProjectName.of("my-project"));
35+
* .setProjectId("my-project");
3736
*
3837
* settingsBuilder.stubSettings().createInstanceSettings()
3938
* .setRetrySettings(
@@ -45,21 +44,32 @@
4544
* }</pre>
4645
*/
4746
public final class BigtableInstanceAdminSettings {
48-
private final ProjectName projectName;
47+
private final String projectId;
4948
private final BigtableInstanceAdminStubSettings stubSettings;
5049

5150
private BigtableInstanceAdminSettings(Builder builder) throws IOException {
52-
Preconditions.checkNotNull(builder.projectName, "ProjectName must be set");
51+
Preconditions.checkNotNull(builder.projectId, "Project ud must be set");
5352
Verify.verifyNotNull(builder.stubSettings, "stubSettings should never be null");
5453

55-
this.projectName = builder.projectName;
54+
this.projectId = builder.projectId;
5655
this.stubSettings = builder.stubSettings.build();
5756
}
5857

59-
/** Gets the anme of the project whose instances the client will manager. */
58+
/** Gets the id of the project whose instances the client will manage. */
6059
@Nonnull
61-
public ProjectName getProjectName() {
62-
return projectName;
60+
public String getProjectId() {
61+
return projectId;
62+
}
63+
64+
/**
65+
* Gets the name of the project whose instances the client will manager.
66+
*
67+
* @deprecated Please use {@link #getProjectId()}.
68+
*/
69+
@Deprecated
70+
@Nonnull
71+
public com.google.bigtable.admin.v2.ProjectName getProjectName() {
72+
return ProjectName.of(projectId);
6373
}
6474

6575
/** Gets the underlying RPC settings. */
@@ -80,29 +90,53 @@ public static Builder newBuilder() {
8090

8191
/** Builder for BigtableInstanceAdminSettings. */
8292
public static final class Builder {
83-
@Nullable private ProjectName projectName;
93+
@Nullable private String projectId;
8494
private final BigtableInstanceAdminStubSettings.Builder stubSettings;
8595

8696
private Builder() {
8797
stubSettings = BigtableInstanceAdminStubSettings.newBuilder();
8898
}
8999

90100
private Builder(BigtableInstanceAdminSettings settings) {
91-
this.projectName = settings.projectName;
101+
this.projectId = settings.projectId;
92102
this.stubSettings = settings.stubSettings.toBuilder();
93103
}
94104

95-
/** Sets the name of instance whose tables the client will manage. */
96-
public Builder setProjectName(@Nonnull ProjectName projectName) {
97-
Preconditions.checkNotNull(projectName);
98-
this.projectName = projectName;
105+
/** Sets the id of the project whose instances the client will manage. */
106+
public Builder setProjectId(@Nonnull String projectId) {
107+
Preconditions.checkNotNull(projectId);
108+
this.projectId = projectId;
99109
return this;
100110
}
101111

102-
/** Gets the name of the project whose instances the client will manage. */
112+
/** Gets the id of the project whose instances the client will manage. */
113+
@Nullable
114+
public String getProjectId() {
115+
return projectId;
116+
}
117+
118+
/**
119+
* Sets the name of instance whose tables the client will manage.
120+
*
121+
* @deprecated Please use {@link #setProjectId(String)}.
122+
*/
123+
@Deprecated
124+
public Builder setProjectName(@Nonnull com.google.bigtable.admin.v2.ProjectName projectName) {
125+
return setProjectId(projectName.getProject());
126+
}
127+
128+
/**
129+
* Gets the name of the project whose instances the client will manage.
130+
*
131+
* @deprecated Please use {@link #getProjectId()}.
132+
*/
133+
@Deprecated
103134
@Nullable
104135
public ProjectName getProjectName() {
105-
return projectName;
136+
if (projectId != null) {
137+
return ProjectName.of(projectId);
138+
}
139+
return null;
106140
}
107141

108142
/**

branches/autosynth-iot/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java

Lines changed: 74 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
import com.google.bigtable.admin.v2.DeleteTableRequest;
2525
import com.google.bigtable.admin.v2.DropRowRangeRequest;
2626
import com.google.bigtable.admin.v2.GetTableRequest;
27-
import com.google.bigtable.admin.v2.InstanceName;
2827
import com.google.bigtable.admin.v2.ListTablesRequest;
29-
import com.google.bigtable.admin.v2.TableName;
3028
import com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPage;
3129
import com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse;
30+
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
3231
import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest;
3332
import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest;
3433
import com.google.cloud.bigtable.admin.v2.models.Table;
@@ -52,7 +51,7 @@
5251
* <p>Sample code to get started:
5352
*
5453
* <pre>{@code
55-
* try(BigtableTableAdminClient client = BigtableTableAdminClient.create(InstanceName.of("[PROJECT]", "[INSTANCE]"))) {
54+
* try(BigtableTableAdminClient client = BigtableTableAdminClient.create("[PROJECT]", "[INSTANCE]")) {
5655
* CreateTable request =
5756
* CreateTableRequest.of("my-table")
5857
* .addFamily("cf1")
@@ -73,7 +72,8 @@
7372
*
7473
* <pre>{@code
7574
* BigtableTableAdminSettings tableAdminSettings = BigtableTableAdminSettings.newBuilder()
76-
* .setInstanceName(InstanceName.of("[PROJECT]", "[INSTANCE]"))
75+
* .setProjectId("[PROJECT]")
76+
* .setInstanceId("[INSTANCE]")
7777
* .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
7878
* .build();
7979
*
@@ -85,47 +85,86 @@
8585
*
8686
* <pre>{@code
8787
* BigtableTableAdminSettings tableAdminSettings = BigtableTableAdminSettings.newBuilder()
88-
* .setInstanceName(InstanceName.of("[PROJECT]", "[INSTANCE]"))
88+
* .setProjectId("[PROJECT]")
89+
* .setInstanceId("[INSTANCE]")
8990
* .setEndpoint(myEndpoint).build();
9091
*
9192
* BigtableTableAdminClient client = BigtableTableAdminClient.create(tableAdminSettings);
9293
* }</pre>
9394
*/
9495
public final class BigtableTableAdminClient implements AutoCloseable {
96+
9597
private final EnhancedBigtableTableAdminStub stub;
96-
private final InstanceName instanceName;
98+
private final String projectId;
99+
private final String instanceId;
97100

98-
/** Constructs an instance of BigtableTableAdminClient with the given instanceName. */
99-
public static BigtableTableAdminClient create(@Nonnull InstanceName instanceName)
100-
throws IOException {
101-
return create(BigtableTableAdminSettings.newBuilder().setInstanceName(instanceName).build());
101+
/** Constructs an instance of BigtableTableAdminClient with the given project and instance ids. */
102+
public static BigtableTableAdminClient create(
103+
@Nonnull String projectId, @Nonnull String instanceId) throws IOException {
104+
return create(
105+
BigtableTableAdminSettings.newBuilder()
106+
.setProjectId(projectId)
107+
.setInstanceId(instanceId)
108+
.build());
109+
}
110+
111+
/**
112+
* Constructs an instance of BigtableTableAdminClient with the given instanceName.
113+
*
114+
* @deprecated Please {@link #create(String, String)}.
115+
*/
116+
@Deprecated
117+
public static BigtableTableAdminClient create(
118+
@Nonnull com.google.bigtable.admin.v2.InstanceName instanceName) throws IOException {
119+
return create(instanceName.getProject(), instanceName.getInstance());
102120
}
103121

104122
/** Constructs an instance of BigtableTableAdminClient with the given settings. */
105123
public static BigtableTableAdminClient create(@Nonnull BigtableTableAdminSettings settings)
106124
throws IOException {
107125
EnhancedBigtableTableAdminStub stub =
108126
EnhancedBigtableTableAdminStub.createEnhanced(settings.getStubSettings());
109-
return create(settings.getInstanceName(), stub);
127+
return create(settings.getProjectId(), settings.getInstanceId(), stub);
110128
}
111129

112130
/** Constructs an instance of BigtableTableAdminClient with the given instanceName and stub. */
113131
public static BigtableTableAdminClient create(
114-
@Nonnull InstanceName instanceName, @Nonnull EnhancedBigtableTableAdminStub stub) {
115-
return new BigtableTableAdminClient(instanceName, stub);
132+
@Nonnull String projectId,
133+
@Nonnull String instanceId,
134+
@Nonnull EnhancedBigtableTableAdminStub stub) {
135+
return new BigtableTableAdminClient(projectId, instanceId, stub);
116136
}
117137

118138
private BigtableTableAdminClient(
119-
@Nonnull InstanceName instanceName, @Nonnull EnhancedBigtableTableAdminStub stub) {
120-
Preconditions.checkNotNull(instanceName);
139+
@Nonnull String projectId,
140+
@Nonnull String instanceId,
141+
@Nonnull EnhancedBigtableTableAdminStub stub) {
142+
Preconditions.checkNotNull(projectId);
143+
Preconditions.checkNotNull(instanceId);
121144
Preconditions.checkNotNull(stub);
122-
this.instanceName = instanceName;
145+
this.projectId = projectId;
146+
this.instanceId = instanceId;
123147
this.stub = stub;
124148
}
125149

126-
/** Gets the instanceName this client is associated with. */
127-
public InstanceName getInstanceName() {
128-
return instanceName;
150+
/** Gets the project id of the instance whose tables this client manages. */
151+
public String getProjectId() {
152+
return projectId;
153+
}
154+
155+
/** Gets the id of the instance whose tables this client manages. */
156+
public String getInstanceId() {
157+
return instanceId;
158+
}
159+
160+
/**
161+
* Gets the instanceName this client is associated with.
162+
*
163+
* @deprecated Please use {@link #getProjectId()} and {@link #getInstanceId()}.
164+
*/
165+
@Deprecated
166+
public com.google.bigtable.admin.v2.InstanceName getInstanceName() {
167+
return com.google.bigtable.admin.v2.InstanceName.of(projectId, instanceId);
129168
}
130169

131170
@Override
@@ -183,7 +222,7 @@ public Table createTable(CreateTableRequest request) {
183222
@SuppressWarnings("WeakerAccess")
184223
public ApiFuture<Table> createTableAsync(CreateTableRequest request) {
185224
return transformToTableResponse(
186-
this.stub.createTableCallable().futureCall(request.toProto(instanceName)));
225+
this.stub.createTableCallable().futureCall(request.toProto(projectId, instanceId)));
187226
}
188227

189228
/**
@@ -275,7 +314,9 @@ public Table modifyFamilies(ModifyColumnFamiliesRequest request) {
275314
@SuppressWarnings("WeakerAccess")
276315
public ApiFuture<Table> modifyFamiliesAsync(ModifyColumnFamiliesRequest request) {
277316
return transformToTableResponse(
278-
this.stub.modifyColumnFamiliesCallable().futureCall(request.toProto(instanceName)));
317+
this.stub
318+
.modifyColumnFamiliesCallable()
319+
.futureCall(request.toProto(projectId, instanceId)));
279320
}
280321

281322
/**
@@ -500,7 +541,9 @@ public List<String> listTables() {
500541
@SuppressWarnings("WeakerAccess")
501542
public ApiFuture<List<String>> listTablesAsync() {
502543
ListTablesRequest request =
503-
ListTablesRequest.newBuilder().setParent(instanceName.toString()).build();
544+
ListTablesRequest.newBuilder()
545+
.setParent(NameUtil.formatInstanceName(projectId, instanceId))
546+
.build();
504547

505548
// TODO(igorbernstein2): try to upstream pagination spooling or figure out a way to expose the
506549
// paginated responses while maintaining the wrapper facade.
@@ -550,7 +593,7 @@ public ApiFuture<List<com.google.bigtable.admin.v2.Table>> apply(
550593
public List<String> apply(List<com.google.bigtable.admin.v2.Table> protos) {
551594
List<String> results = Lists.newArrayListWithCapacity(protos.size());
552595
for (com.google.bigtable.admin.v2.Table proto : protos) {
553-
results.add(TableName.parse(proto.getName()).getTable());
596+
results.add(NameUtil.extractTableIdFromTableName(proto.getName()));
554597
}
555598
return results;
556599
}
@@ -718,8 +761,10 @@ public ApiFuture<Void> dropAllRowsAsync(String tableId) {
718761
*/
719762
@SuppressWarnings("WeakerAccess")
720763
public void awaitReplication(String tableId) {
721-
TableName tableName =
722-
TableName.of(instanceName.getProject(), instanceName.getInstance(), tableId);
764+
// TODO(igorbernstein2): remove usage of typesafe names
765+
com.google.bigtable.admin.v2.TableName tableName =
766+
com.google.bigtable.admin.v2.TableName.of(projectId, instanceId, tableId);
767+
723768
ApiExceptions.callAndTranslateApiException(
724769
stub.awaitReplicationCallable().futureCall(tableName));
725770
}
@@ -752,8 +797,9 @@ public void awaitReplication(String tableId) {
752797
*/
753798
@SuppressWarnings("WeakerAccess")
754799
public ApiFuture<Void> awaitReplicationAsync(final String tableId) {
755-
TableName tableName =
756-
TableName.of(instanceName.getProject(), instanceName.getInstance(), tableId);
800+
// TODO(igorbernstein2): remove usage of trypesafe names
801+
com.google.bigtable.admin.v2.TableName tableName =
802+
com.google.bigtable.admin.v2.TableName.of(projectId, instanceId, tableId);
757803
return stub.awaitReplicationCallable().futureCall(tableName);
758804
}
759805

@@ -762,7 +808,7 @@ public ApiFuture<Void> awaitReplicationAsync(final String tableId) {
762808
* projects/{project}/instances/{instance}/tables/{tableId}
763809
*/
764810
private String getTableName(String tableId) {
765-
return TableName.of(instanceName.getProject(), instanceName.getInstance(), tableId).toString();
811+
return NameUtil.formatTableName(projectId, instanceId, tableId);
766812
}
767813

768814
// TODO(igorbernstein): rename methods to make clear that they deal with futures.

0 commit comments

Comments
 (0)