Skip to content

Commit

Permalink
Spanner gapic migration lro methods (#3166)
Browse files Browse the repository at this point in the history
Migrate longrunning methods to GAPIC including: createDatabase, updateDatabaseDdl, createInstance, and updateInstance.
  • Loading branch information
yihanzhen authored May 9, 2018
1 parent 6cc31d1 commit f9df8a2
Show file tree
Hide file tree
Showing 18 changed files with 522 additions and 215 deletions.
6 changes: 3 additions & 3 deletions google-cloud-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@
<testing.version>0.46.1-alpha-SNAPSHOT</testing.version><!-- {x-version-update:google-cloud-testing:current} -->

<api-common.version>1.5.0</api-common.version>
<gax.version>1.25.0</gax.version>
<gax-grpc.version>1.25.0</gax-grpc.version>
<gax-httpjson.version>0.42.0</gax-httpjson.version>
<gax.version>1.26.0</gax.version>
<gax-grpc.version>1.26.0</gax-grpc.version>
<gax-httpjson.version>0.43.0</gax-httpjson.version>
<generated-proto-beta.version>0.11.0</generated-proto-beta.version>
<generated-proto-ga.version>1.10.0</generated-proto-ga.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@

package com.google.cloud.examples.spanner.snippets;

import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.paging.Page;
import com.google.common.collect.Iterables;
import com.google.cloud.spanner.DatabaseAdminClient;
import com.google.cloud.spanner.Options;
import com.google.cloud.spanner.Database;
import com.google.cloud.spanner.Operation;
import com.google.cloud.spanner.SpannerExceptionFactory;
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;

/**
* This class contains snippets for {@link DatabaseAdminClient} interface.
Expand All @@ -53,7 +55,7 @@ public DatabaseAdminClientSnippets(DatabaseAdminClient dbAdminClient) {
// [VARIABLE my_database_id]
public Database createDatabase(String instanceId, String databaseId) {
// [START createDatabase]
Operation<Database, CreateDatabaseMetadata> op = dbAdminClient
OperationFuture<Database, CreateDatabaseMetadata> op = dbAdminClient
.createDatabase(
instanceId,
databaseId,
Expand All @@ -70,9 +72,13 @@ public Database createDatabase(String instanceId, String databaseId) {
+ " AlbumTitle STRING(MAX)\n"
+ ") PRIMARY KEY (SingerId, AlbumId),\n"
+ " INTERLEAVE IN PARENT Singers ON DELETE CASCADE"));
Database db = op.waitFor().getResult();
// [END createDatabase]
return db;
try {
return op.get();
// [END createDatabase]
} catch (ExecutionException | InterruptedException e) {
// DO error handing
}
return null;
}

/**
Expand All @@ -96,10 +102,14 @@ public Database getDatabase(String instanceId, String databaseId) {
// [VARIABLE my_database_id]
public void updateDatabaseDdl(String instanceId, String databaseId) {
// [START updateDatabaseDdl]
dbAdminClient.updateDatabaseDdl(instanceId,
try {
dbAdminClient.updateDatabaseDdl(instanceId,
databaseId,
Arrays.asList("ALTER TABLE Albums ADD COLUMN MarketingBudget INT64"),
null).waitFor();
null).get();
} catch (ExecutionException | InterruptedException e) {
// DO error handling
}
// [END updateDatabaseDdl]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.google.common.base.Preconditions.checkArgument;

import com.google.api.gax.longrunning.OperationFuture;
import com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata;

/**
Expand Down Expand Up @@ -51,7 +52,7 @@ public Database reload() throws SpannerException {
* one. This must be unique within a database abd must be a valid identifier
* [a-zA-Z][a-zA-Z0-9_]*.
*/
public Operation<Void, UpdateDatabaseDdlMetadata> updateDdl(
public OperationFuture<Void, UpdateDatabaseDdlMetadata> updateDdl(
Iterable<String> statements, String operationId) throws SpannerException {
return dbClient.updateDatabaseDdl(instance(), database(), statements, operationId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.spanner;

import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.paging.Page;
import com.google.cloud.spanner.Options.ListOption;
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
Expand Down Expand Up @@ -58,7 +59,7 @@ public interface DatabaseAdminClient {
* @param statements DDL statements to run while creating the database, for example {@code CREATE
* TABLE MyTable ( ... )}. This should not include {@code CREATE DATABASE} statement.
*/
Operation<Database, CreateDatabaseMetadata> createDatabase(
OperationFuture<Database, CreateDatabaseMetadata> createDatabase(
String instanceId, String databaseId, Iterable<String> statements) throws SpannerException;

/**
Expand Down Expand Up @@ -97,7 +98,7 @@ Operation<Database, CreateDatabaseMetadata> createDatabase(
* one. This must be unique within a database abd must be a valid identifier
* [a-zA-Z][a-zA-Z0-9_]*.
*/
Operation<Void, UpdateDatabaseDdlMetadata> updateDatabaseDdl(
OperationFuture<Void, UpdateDatabaseDdlMetadata> updateDatabaseDdl(
String instanceId,
String databaseId,
Iterable<String> statements,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.spanner;

import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.paging.Page;
import com.google.spanner.admin.database.v1.CreateDatabaseMetadata;
import com.google.spanner.admin.instance.v1.UpdateInstanceMetadata;
Expand Down Expand Up @@ -104,7 +105,7 @@ public void delete() {
instanceClient.deleteInstance(instanceId());
}

public Operation<Instance, UpdateInstanceMetadata> update(
public OperationFuture<Instance, UpdateInstanceMetadata> update(
InstanceInfo.InstanceField... fieldsToUpdate) {
return instanceClient.updateInstance(this, fieldsToUpdate);
}
Expand All @@ -125,7 +126,7 @@ public Database getDatabase(String databaseId) {
* @param statements DDL statements to run while creating the database, for example {@code CREATE
* TABLE MyTable ( ... )}. This should not include {@code CREATE DATABASE} statement.
*/
public Operation<Database, CreateDatabaseMetadata> createDatabase(
public OperationFuture<Database, CreateDatabaseMetadata> createDatabase(
String databaseId, Iterable<String> statements) throws SpannerException {
return dbClient.createDatabase(instanceId(), databaseId, statements);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.spanner;

import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.paging.Page;
import com.google.cloud.spanner.Options.ListOption;
import com.google.spanner.admin.instance.v1.CreateInstanceMetadata;
Expand Down Expand Up @@ -59,7 +60,7 @@ public interface InstanceAdminClient {
* <li> The instance's allocated resource levels are readable via the
* </ul>
*/
Operation<Instance, CreateInstanceMetadata> createInstance(InstanceInfo instance)
OperationFuture<Instance, CreateInstanceMetadata> createInstance(InstanceInfo instance)
throws SpannerException;

/** Gets an instance. */
Expand Down Expand Up @@ -113,7 +114,7 @@ Operation<Instance, CreateInstanceMetadata> createInstance(InstanceInfo instance
* <li> The instance's new resource levels are readable via the API.
* </ul>
*/
Operation<Instance, UpdateInstanceMetadata> updateInstance(
OperationFuture<Instance, UpdateInstanceMetadata> updateInstance(
InstanceInfo instance, InstanceInfo.InstanceField... fieldsToUpdate);

/** Returns a builder for {@code Instance} object with the given id. */
Expand Down
Loading

0 comments on commit f9df8a2

Please sign in to comment.