Skip to content

Commit

Permalink
Spanner gapic migration (#3881)
Browse files Browse the repository at this point in the history
* Add GapicSpannerRpc stub (#3016)

* spanner: implement partitionRead (#3022)

* spanner: implement LRO methods using GAPIC stub (#3039)

* Add implementation to:listInstances, listInstanceConfigs, listDatabases, getInstance, getInstanceConfigs, getDatabase, dropDatabase, deleteInstance, getDatabaseDdl  (#3043) 

* spanner: move admin clients to GAPIC stub (#3067)

* Spanner: migrate all unary call methods to gapic and inject headers (#3112)

* Spanner: migrate streaming methods to gapic (#3139)

* Spanner gapic migration lro methods (#3166)

Migrate longrunning methods to GAPIC including: createDatabase, updateDatabaseDdl, createInstance, and updateInstance.

* Make ChannelPool work (#3258)

* Spanner gapic migration error augmentation with interceptor (#3304)

* Add interceptors (#3346)

* Clean up Spanner before merging to master (#3362)

* Spanner Gapic Migration: fix updateDatabaseDdl (#3403)
  • Loading branch information
yihanzhen committed Nov 7, 2018
1 parent 269546f commit 28fab80
Show file tree
Hide file tree
Showing 26 changed files with 1,474 additions and 1,153 deletions.
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 All @@ -29,7 +30,8 @@ public interface DatabaseAdminClient {
* Creates a new database in a Cloud Spanner instance.
*
* <p>Example to create database.
* <pre> {@code
*
* <pre>{@code
* String instanceId = my_instance_id;
* String databaseId = my_database_id;
* Operation<Database, CreateDatabaseMetadata> op = dbAdminClient
Expand Down Expand Up @@ -58,19 +60,19 @@ 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;

/**
* Gets the current state of a Cloud Spanner database.
/**
* Gets the current state of a Cloud Spanner database.
*
* <p>Example to getDatabase.
* <pre> {@code
*
* <pre>{@code
* String instanceId = my_instance_id;
* String databaseId = my_database_id;
* Database db = dbAdminClient.getDatabase(instanceId, databaseId);
* }</pre>
*
*/
Database getDatabase(String instanceId, String databaseId) throws SpannerException;

Expand All @@ -84,7 +86,8 @@ Operation<Database, CreateDatabaseMetadata> createDatabase(
* fails, all subsequent statements in the batch are automatically cancelled.
*
* <p>Example to update the database DDL.
* <pre> {@code
*
* <pre>{@code
* String instanceId = my_instance_id;
* String databaseId = my_database_id;
* dbAdminClient.updateDatabaseDdl(instanceId,
Expand All @@ -97,7 +100,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 @@ -51,29 +52,30 @@ public interface InstanceAdminClient {
* upon completion of this request:
*
* <ul>
* <li> The instance is readable via the API, with all requested attributes but no allocated
* <li>The instance is readable via the API, with all requested attributes but no allocated
* resources.
* <li> Its state is {@code CREATING}.
* <li>Its state is {@code CREATING}.
* </ul>
*
* Until completion of the returned operation:
*
* <ul>
* <li> Cancelling the operation renders the instance immediately unreadable via the API.
* <li> The instance can be deleted.
* <li> All other attempts to modify the instance are rejected.
* <li>Cancelling the operation renders the instance immediately unreadable via the API.
* <li>The instance can be deleted.
* <li>All other attempts to modify the instance are rejected.
* </ul>
*
* Upon completion of the returned operation:
*
* <ul>
* <li> Billing for all successfully-allocated resources begins (some types may have lower than
* <li>Billing for all successfully-allocated resources begins (some types may have lower than
* the requested levels).
* <li> Databases can be created in the instance.
* <li> The instance's allocated resource levels are readable via the
* <li>Databases can be created in the instance.
* <li>The instance's allocated resource levels are readable via the
* </ul>
*
* <!--SNIPPET instance_admin_client_create_instance-->
*
* <pre>{@code
* final String instanceId = my_instance_id;
* final String configId = my_config_id;
Expand All @@ -88,9 +90,10 @@ public interface InstanceAdminClient {
* .build());
* op.waitFor();
* }</pre>
*
* <!--SNIPPET instance_admin_client_create_instance-->
*/
Operation<Instance, CreateInstanceMetadata> createInstance(InstanceInfo instance)
OperationFuture<Instance, CreateInstanceMetadata> createInstance(InstanceInfo instance)
throws SpannerException;

/** Gets an instance. */
Expand Down Expand Up @@ -142,31 +145,32 @@ Operation<Instance, CreateInstanceMetadata> createInstance(InstanceInfo instance
* <p>Immediately upon completion of this request:
*
* <ul>
* <li> For resource types for which a decrease in the instance's allocation has been requested,
* <li>For resource types for which a decrease in the instance's allocation has been requested,
* billing is based on the newly-requested level.
* </ul>
*
* Until completion of the returned operation:
*
* <ul>
* <li> Cancelling the operation sets its metadata's
* <li>Cancelling the operation sets its metadata's
* [cancel_time][UpdateInstanceMetadata.cancel_time], and begins restoring resources to
* their pre-request values. The operation is guaranteed to succeed at undoing all resource
* changes, after which point it terminates with a `CANCELLED` status.
* <li> All other attempts to modify the instance are rejected.
* <li> Reading the instance via the API continues to give the pre-request resource levels.
* <li>All other attempts to modify the instance are rejected.
* <li>Reading the instance via the API continues to give the pre-request resource levels.
* </ul>
*
* Upon completion of the returned operation:
*
* <ul>
* <li> Billing begins for all successfully-allocated resources (some types may have lower than
* <li>Billing begins for all successfully-allocated resources (some types may have lower than
* the requested levels).
* <li> All newly-reserved resources are available for serving the instance's tables.
* <li> The instance's new resource levels are readable via the API.
* <li>All newly-reserved resources are available for serving the instance's tables.
* <li>The instance's new resource levels are readable via the API.
* </ul>
*
* <!--SNIPPET instance_admin_client_update_instance-->
*
* <pre>{@code
* Instance instance = my_instance;
* final String clientProject = my_client_project;
Expand All @@ -184,9 +188,10 @@ Operation<Instance, CreateInstanceMetadata> createInstance(InstanceInfo instance
* instanceAdminClient.updateInstance(toUpdate, InstanceInfo.InstanceField.DISPLAY_NAME);
* op.waitFor().getResult();
* }</pre>
*
* <!--SNIPPET instance_admin_client_update_instance-->
*/
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 28fab80

Please sign in to comment.