Package com.google.cloud.spanner
Interface InstanceAdminClient
public interface InstanceAdminClient
Client to do admin operations on Cloud Spanner Instance and Instance Configs.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
cancelOperation
(String name) Cancels the specified long-running operation.com.google.api.gax.longrunning.OperationFuture<Instance,
CreateInstanceMetadata> createInstance
(InstanceInfo instance) Creates an instance and begins preparing it to begin serving.default com.google.api.gax.longrunning.OperationFuture<InstanceConfig,
CreateInstanceConfigMetadata> createInstanceConfig
(InstanceConfigInfo instanceConfig, Options.CreateAdminApiOption... options) Creates an instance config and begins preparing it to be used.void
deleteInstance
(String instanceId) Deletes an instance.default void
deleteInstanceConfig
(String instanceConfigId, Options.DeleteAdminApiOption... options) Deletes a custom instance config.getInstance
(String instanceId) Gets an instance.getInstanceConfig
(String configId) Gets an instance config.com.google.cloud.Policy
getInstanceIAMPolicy
(String instanceId) Returns the IAM policy for the given instance.com.google.longrunning.Operation
getOperation
(String name) Gets the specified long-running operation.default com.google.api.gax.paging.Page<com.google.longrunning.Operation>
listInstanceConfigOperations
(Options.ListOption... options) Lists long-running instance config operations.com.google.api.gax.paging.Page<InstanceConfig>
listInstanceConfigs
(Options.ListOption... options) Lists the supported instance configs for current project.com.google.api.gax.paging.Page<Instance>
listInstances
(Options.ListOption... options) Lists the instances.Returns a builder forInstance
object with the given id.com.google.cloud.Policy
setInstanceIAMPolicy
(String instanceId, com.google.cloud.Policy policy) Updates the IAM policy for the given instance and returns the resulting policy.testInstanceIAMPermissions
(String instanceId, Iterable<String> permissions) Tests for the given permissions on the specified instance for the caller.com.google.api.gax.longrunning.OperationFuture<Instance,
UpdateInstanceMetadata> updateInstance
(InstanceInfo instance, InstanceInfo.InstanceField... fieldsToUpdate) Updates an instance, and begins allocating or releasing resources as requested.default com.google.api.gax.longrunning.OperationFuture<InstanceConfig,
UpdateInstanceConfigMetadata> updateInstanceConfig
(InstanceConfigInfo instanceConfig, Iterable<InstanceConfigInfo.InstanceConfigField> fieldsToUpdate, Options.UpdateAdminApiOption... options) Updates a custom instance config.
-
Method Details
-
createInstanceConfig
default com.google.api.gax.longrunning.OperationFuture<InstanceConfig,CreateInstanceConfigMetadata> createInstanceConfig(InstanceConfigInfo instanceConfig, Options.CreateAdminApiOption... options) throws SpannerException Creates an instance config and begins preparing it to be used. The returnedOperation
can be used to track the progress of preparing the new instance config. The instance config name is assigned by the caller and must start with the string 'custom'. If the named instance config already exists, a SpannerException is thrown.Immediately after the request returns:
- The instance config is readable via the API, with all requested attributes.
- The instance config's
reconciling
field is set to true. Its state isCREATING
.
- Cancelling the operation renders the instance config immediately unreadable via the API.
- Except for deleting the creating resource, all other attempts to modify the instance config are rejected.
- Instances can be created using the instance configuration.
- The instance config's
reconciling
field becomes false. - Its state becomes
READY
.
String projectId = "my-project"; String baseInstanceConfig = "my-base-config"; String instanceConfigId = "custom-user-config"; final InstanceConfig baseConfig = instanceAdminClient.getInstanceConfig(baseInstanceConfig); List<ReplicaInfo> readOnlyReplicas = ImmutableList.of(baseConfig.getOptionalReplicas().get(0)); InstanceConfigInfo instanceConfigInfo = InstanceConfigInfo.newBuilder(InstanceConfigId.of(projectId, instanceConfigId), baseConfig) .setDisplayName(instanceConfigId) .addReadOnlyReplicas(readOnlyReplicas) .build(); final OperationFuture<InstanceConfig, CreateInstanceConfigMetadata> operation = instanceAdminClient.createInstanceConfig(instanceConfigInfo); InstanceConfig instanceConfig = op.get(5, TimeUnit.MINUTES)
- Throws:
SpannerException
-
updateInstanceConfig
default com.google.api.gax.longrunning.OperationFuture<InstanceConfig,UpdateInstanceConfigMetadata> updateInstanceConfig(InstanceConfigInfo instanceConfig, Iterable<InstanceConfigInfo.InstanceConfigField> fieldsToUpdate, Options.UpdateAdminApiOption... options) throws SpannerException Updates a custom instance config. This can not be used to update a Google managed instance config. The returnedOperation
can be used to track the progress of updating the instance. If the named instance config does not exist, a SpannerException is thrown. The request must include at least one field to update.Only user managed configurations can be updated.
Immediately after the request returns:
- The instance config's
reconciling
field is set to true.
- Cancelling the operation sets its metadata's cancel_time.
- The operation is guaranteed to succeed at undoing all changes, after which point it terminates with a `CANCELLED` status.
- All other attempts to modify the instance config are rejected.
- Reading the instance config via the API continues to give the pre-request values.
- Creating instances using the instance configuration uses the new values.
- The instance config's new values are readable via the API.
- The instance config's
reconciling
field becomes false.
String projectId = "my-project"; String instanceConfigId = "custom-user-config"; String displayName = "my-display-name"; InstanceConfigInfo instanceConfigInfo = InstanceConfigInfo.newBuilder(InstanceConfigId.of(projectId, instanceConfigId)) .setDisplayName(displayName) .build(); // Only update display name. final OperationFuture<InstanceConfig, UpdateInstanceConfigMetadata> operation = instanceAdminClient.updateInstanceConfig( instanceConfigInfo, ImmutableList.of(InstanceConfigField.DISPLAY_NAME)); InstanceConfig instanceConfig = operation.get(5, TimeUnit.MINUTES);
- Throws:
SpannerException
- The instance config's
-
getInstanceConfig
Gets an instance config.- Throws:
SpannerException
-
deleteInstanceConfig
default void deleteInstanceConfig(String instanceConfigId, Options.DeleteAdminApiOption... options) throws SpannerException Deletes a custom instance config. Deletion is only allowed for custom instance configs and when no instances are using the configuration. If any instances are using the config, a SpannerException is thrown.Only user managed configurations can be deleted.
String projectId = "my-project"; String instanceConfigId = "custom-user-config"; instanceAdminClient.deleteInstanceConfig(instanceConfigId);
- Throws:
SpannerException
-
listInstanceConfigs
com.google.api.gax.paging.Page<InstanceConfig> listInstanceConfigs(Options.ListOption... options) throws SpannerException Lists the supported instance configs for current project.- Throws:
SpannerException
-
listInstanceConfigOperations
default com.google.api.gax.paging.Page<com.google.longrunning.Operation> listInstanceConfigOperations(Options.ListOption... options) Lists long-running instance config operations. -
createInstance
com.google.api.gax.longrunning.OperationFuture<Instance,CreateInstanceMetadata> createInstance(InstanceInfo instance) throws SpannerException Creates an instance and begins preparing it to begin serving. The returnedOperation
can be used to track the progress of preparing the new instance. The instance name is assigned by the caller. If the named instance already exists, a SpannerException is thrown. Immediately upon completion of this request:- The instance is readable via the API, with all requested attributes but no allocated resources.
- Its state is
CREATING
.
- Cancelling the operation renders the instance immediately unreadable via the API.
- The instance can be deleted.
- All other attempts to modify the instance are rejected.
- Billing for all successfully-allocated resources begins (some types may have lower than the requested levels).
- Databases can be created in the instance.
- The instance's allocated resource levels are readable via the
final String instanceId = my_instance_id; final String configId = my_config_id; final String clientProject = my_client_project; Operation<Instance, CreateInstanceMetadata> op = instanceAdminClient.createInstance(InstanceInfo .newBuilder(InstanceId.of(clientProject, instanceId)) .setInstanceConfigId(InstanceConfigId.of(clientProject, configId)) .setDisplayName(instanceId) .setNodeCount(1) .build()); op.waitFor();
- Throws:
SpannerException
-
getInstance
Gets an instance.- Throws:
SpannerException
-
listInstances
com.google.api.gax.paging.Page<Instance> listInstances(Options.ListOption... options) throws SpannerException Lists the instances.- Parameters:
options
- Options to control the instances returned. It also supportsOptions.filter(String)
option. The fields eligible for filtering are:- name
- display_name
- labels.key where key is the name of a label
List<Instance> instances = Lists.newArrayList( instanceAdminClient.listInstances(Options.pageSize(1)).iterateAll());
- Throws:
SpannerException
-
deleteInstance
Deletes an instance.- Throws:
SpannerException
-
updateInstance
com.google.api.gax.longrunning.OperationFuture<Instance,UpdateInstanceMetadata> updateInstance(InstanceInfo instance, InstanceInfo.InstanceField... fieldsToUpdate) Updates an instance, and begins allocating or releasing resources as requested. The returnedOperation
can be used to track the progress of updating the instance. If the named instance does not exist, throws SpannerException.Immediately upon completion of this request:
- For resource types for which a decrease in the instance's allocation has been requested, billing is based on the newly-requested level.
- 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.
- All other attempts to modify the instance are rejected.
- Reading the instance via the API continues to give the pre-request resource levels.
- Billing begins for all successfully-allocated resources (some types may have lower than the requested levels).
- All newly-reserved resources are available for serving the instance's tables.
- The instance's new resource levels are readable via the API.
Instance instance = my_instance; final String clientProject = my_client_project; final String instanceId = my_instance_id; final String newDisplayName = my_display_name; InstanceInfo toUpdate = InstanceInfo.newBuilder(InstanceId.of(clientProject, instanceId)) .setDisplayName(newDisplayName) .setNodeCount(instance.getNodeCount() + 1) .build(); // Only update display name Operation<Instance, UpdateInstanceMetadata> op = instanceAdminClient.updateInstance(toUpdate, InstanceInfo.InstanceField.DISPLAY_NAME); op.waitFor().getResult();
-
getInstanceIAMPolicy
Returns the IAM policy for the given instance. -
setInstanceIAMPolicy
Updates the IAM policy for the given instance and returns the resulting policy. It is highly recommended to first get the current policy and base the updated policy on the returned policy. SeePolicy.Builder.setEtag(String)
for information on the recommended read-modify-write cycle. -
testInstanceIAMPermissions
Tests for the given permissions on the specified instance for the caller.- Parameters:
instanceId
- the id of the instance to test.permissions
- the permissions to test for. Permissions with wildcards (such as '*', 'spanner.*', 'spanner.instances.*') are not allowed.- Returns:
- the subset of the tested permissions that the caller is allowed.
-
newInstanceBuilder
Returns a builder forInstance
object with the given id. -
cancelOperation
Cancels the specified long-running operation. -
getOperation
Gets the specified long-running operation.
-