Interface InstanceAdminClient (6.89.0)

publicinterfaceInstanceAdminClient

Client to do admin operations on Cloud Spanner Instance and Instance Configs.

Methods

cancelOperation(String name)

publicabstractvoidcancelOperation(Stringname)

Cancels the specified long-running operation.

Parameter
NameDescription
nameString

createInstance(InstanceInfo instance)

publicabstractOperationFuture<Instance,CreateInstanceMetadata>createInstance(InstanceInfoinstance)

Creates an instance and begins preparing it to begin serving. The returned Operation 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.

Until completion of the returned operation:

  • 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.

Upon completion of the returned operation:

  • 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
finalStringinstanceId=my_instance_id;finalStringconfigId=my_config_id;finalStringclientProject=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();
Parameter
NameDescription
instanceInstanceInfo
Returns
TypeDescription
OperationFuture<Instance,CreateInstanceMetadata>
Exceptions
TypeDescription
SpannerException

createInstanceConfig(InstanceConfigInfo instanceConfig, Options.CreateAdminApiOption[] options)

publicdefaultOperationFuture<InstanceConfig,CreateInstanceConfigMetadata>createInstanceConfig(InstanceConfigInfoinstanceConfig,Options.CreateAdminApiOption[]options)

Creates an instance config and begins preparing it to be used. The returned Operation 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 is CREATING.

While the operation is pending:

  • 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.

Upon completion of the returned operation:

  • Instances can be created using the instance configuration.
  • The instance config's reconciling field becomes false.
  • Its state becomes READY.
StringprojectId="my-project";StringbaseInstanceConfig="my-base-config";StringinstanceConfigId="custom-user-config";finalInstanceConfigbaseConfig=instanceAdminClient.getInstanceConfig(baseInstanceConfig);List<ReplicaInfo>readOnlyReplicas=ImmutableList.of(baseConfig.getOptionalReplicas().get(0));InstanceConfigInfoinstanceConfigInfo=InstanceConfigInfo.newBuilder(InstanceConfigId.of(projectId,instanceConfigId),baseConfig).setDisplayName(instanceConfigId).addReadOnlyReplicas(readOnlyReplicas).build();finalOperationFuture<InstanceConfig,CreateInstanceConfigMetadata>operation=instanceAdminClient.createInstanceConfig(instanceConfigInfo);InstanceConfiginstanceConfig=op.get(5,TimeUnit.MINUTES)
Parameters
NameDescription
instanceConfigInstanceConfigInfo
optionsCreateAdminApiOption[]
Returns
TypeDescription
OperationFuture<InstanceConfig,CreateInstanceConfigMetadata>
Exceptions
TypeDescription
SpannerException

deleteInstance(String instanceId)

publicabstractvoiddeleteInstance(StringinstanceId)

Deletes an instance.

Parameter
NameDescription
instanceIdString
Exceptions
TypeDescription
SpannerException

deleteInstanceConfig(String instanceConfigId, Options.DeleteAdminApiOption[] options)

publicdefaultvoiddeleteInstanceConfig(StringinstanceConfigId,Options.DeleteAdminApiOption[]options)

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.

StringprojectId="my-project";StringinstanceConfigId="custom-user-config";instanceAdminClient.deleteInstanceConfig(instanceConfigId);
Parameters
NameDescription
instanceConfigIdString
optionsDeleteAdminApiOption[]
Exceptions
TypeDescription
SpannerException

getInstance(String instanceId)

publicabstractInstancegetInstance(StringinstanceId)

Gets an instance.

Parameter
NameDescription
instanceIdString
Returns
TypeDescription
Instance
Exceptions
TypeDescription
SpannerException

getInstanceConfig(String configId)

publicabstractInstanceConfiggetInstanceConfig(StringconfigId)

Gets an instance config.

Parameter
NameDescription
configIdString
Returns
TypeDescription
InstanceConfig
Exceptions
TypeDescription
SpannerException

getInstanceIAMPolicy(String instanceId)

publicabstractPolicygetInstanceIAMPolicy(StringinstanceId)

Returns the IAM policy for the given instance.

Parameter
NameDescription
instanceIdString
Returns
TypeDescription
com.google.cloud.Policy

getOperation(String name)

publicabstractOperationgetOperation(Stringname)

Gets the specified long-running operation.

Parameter
NameDescription
nameString
Returns
TypeDescription
Operation

listInstanceConfigOperations(Options.ListOption[] options)

publicdefaultPage<Operation>listInstanceConfigOperations(Options.ListOption[]options)

Lists long-running instance config operations.

Parameter
NameDescription
optionsListOption[]
Returns
TypeDescription
Page<Operation>

listInstanceConfigs(Options.ListOption[] options)

publicabstractPage<InstanceConfig>listInstanceConfigs(Options.ListOption[]options)

Lists the supported instance configs for current project.

Parameter
NameDescription
optionsListOption[]
Returns
TypeDescription
Page<InstanceConfig>
Exceptions
TypeDescription
SpannerException

listInstances(Options.ListOption[] options)

publicabstractPage<Instance>listInstances(Options.ListOption[]options)

Lists the instances.

Parameter
NameDescription
optionsListOption[]

Options to control the instances returned. It also supports Options#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());
 <!--SNIPPET instance_admin_client_list_instances--> 
Returns
TypeDescription
Page<Instance>
Exceptions
TypeDescription
SpannerException

newInstanceBuilder(InstanceId id)

publicabstractInstance.BuildernewInstanceBuilder(InstanceIdid)

Returns a builder for Instance object with the given id.

Parameter
NameDescription
idInstanceId
Returns
TypeDescription
Instance.Builder

setInstanceIAMPolicy(String instanceId, Policy policy)

publicabstractPolicysetInstanceIAMPolicy(StringinstanceId,Policypolicy)

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. See Policy.Builder#setEtag(String) for information on the recommended read-modify-write cycle.

Parameters
NameDescription
instanceIdString
policycom.google.cloud.Policy
Returns
TypeDescription
com.google.cloud.Policy

testInstanceIAMPermissions(String instanceId, Iterable<String> permissions)

publicabstractIterable<String>testInstanceIAMPermissions(StringinstanceId,Iterable<String>permissions)

Tests for the given permissions on the specified instance for the caller.

Parameters
NameDescription
instanceIdString

the id of the instance to test.

permissionsIterable<String>

the permissions to test for. Permissions with wildcards (such as '', 'spanner.', 'spanner.instances.*') are not allowed.

Returns
TypeDescription
Iterable<String>

the subset of the tested permissions that the caller is allowed.

updateInstance(InstanceInfo instance, InstanceInfo.InstanceField[] fieldsToUpdate)

publicabstractOperationFuture<Instance,UpdateInstanceMetadata>updateInstance(InstanceInfoinstance,InstanceInfo.InstanceField[]fieldsToUpdate)

Updates an instance, and begins allocating or releasing resources as requested. The returned Operation 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.

Until completion of the returned operation:

  • Cancelling the operation sets its metadata's 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.

Upon completion of the returned operation:

  • 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.
Instanceinstance=my_instance;finalStringclientProject=my_client_project;finalStringinstanceId=my_instance_id;finalStringnewDisplayName=my_display_name;InstanceInfotoUpdate=InstanceInfo.newBuilder(InstanceId.of(clientProject,instanceId)).setDisplayName(newDisplayName).setNodeCount(instance.getNodeCount()+1).build();// Only update display nameOperation<Instance,UpdateInstanceMetadata>op=instanceAdminClient.updateInstance(toUpdate,InstanceInfo.InstanceField.DISPLAY_NAME);op.waitFor().getResult();
Parameters
NameDescription
instanceInstanceInfo
fieldsToUpdateInstanceField[]
Returns
TypeDescription
OperationFuture<Instance,UpdateInstanceMetadata>

updateInstanceConfig(InstanceConfigInfo instanceConfig, Iterable<InstanceConfigInfo.InstanceConfigField> fieldsToUpdate, Options.UpdateAdminApiOption[] options)

publicdefaultOperationFuture<InstanceConfig,UpdateInstanceConfigMetadata>updateInstanceConfig(InstanceConfigInfoinstanceConfig,Iterable<InstanceConfigInfo.InstanceConfigField>fieldsToUpdate,Options.UpdateAdminApiOption[]options)

Updates a custom instance config. This can not be used to update a Google managed instance config. The returned Operation 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.

While the operation is pending:

  • 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.

Upon completion of the returned operation:

  • 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.
StringprojectId="my-project";StringinstanceConfigId="custom-user-config";StringdisplayName="my-display-name";InstanceConfigInfoinstanceConfigInfo=InstanceConfigInfo.newBuilder(InstanceConfigId.of(projectId,instanceConfigId)).setDisplayName(displayName).build();// Only update display name.finalOperationFuture<InstanceConfig,UpdateInstanceConfigMetadata>operation=instanceAdminClient.updateInstanceConfig(instanceConfigInfo,ImmutableList.of(InstanceConfigField.DISPLAY_NAME));InstanceConfiginstanceConfig=operation.get(5,TimeUnit.MINUTES);
Parameters
NameDescription
instanceConfigInstanceConfigInfo
fieldsToUpdateIterable<InstanceConfigField>
optionsUpdateAdminApiOption[]
Returns
TypeDescription
OperationFuture<InstanceConfig,UpdateInstanceConfigMetadata>
Exceptions
TypeDescription
SpannerException