v1. InstanceAdminClient
Cloud Spanner Instance Admin API
The Cloud Spanner Instance Admin API can be used to create, delete, modify and list instances. Instances are dedicated Cloud Spanner serving and storage resources to be used by Cloud Spanner databases.
Each instance has a "configuration", which dictates where the serving resources for the Cloud Spanner instance are located (e.g., US-central, Europe). Configurations are created by Google based on resource availability.
Cloud Spanner billing is based on the instances that exist and their sizes. After an instance exists, there are no additional per-database or per-operation charges for use of the instance (though there may be additional network bandwidth charges). Instances offer isolation: problems with databases in one instance will not affect other instances. However, within an instance databases can affect each other. For example, if one database in an instance receives a lot of requests and consumes most of the instance resources, fewer resources are available for other databases in that instance, and their performance may suffer.
Constructor
InstanceAdminClient
new InstanceAdminClient(options)
Construct an instance of InstanceAdminClient.
Parameter |
|||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Optional object The configuration object. See the subsequent parameters for more details. Values in
|
Properties
port
The port for this API service.
scopes
The scopes needed to make gRPC calls for every method defined in this service.
servicePath
The DNS address for this API service.
Methods
createInstance
createInstance(request, options, callback) returns Promise
Creates an instance and begins preparing it to begin serving. The returned long-running 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, CreateInstance
returns
ALREADY_EXISTS
.
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 API.
- The instance's state becomes
READY
.
The returned long-running operation will have a name of the format <instance_name>/operations/<operation_id>
and can be used to track creation of the instance. The metadata field type is CreateInstanceMetadata. The
response field type is Instance, if successful.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||||||
options |
Optional Object Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||||||
callback |
Optional function(nullable Error, nullable Object) The function which will be called with the result of the API call. The second parameter to the callback is a gax.Operation object. |
- Returns
-
Promise
- The promise which resolves to an array. The first element of the array is a gax.Operation object. The promise has a method named "cancel" which cancels the ongoing API call.
Example
const spanner = require('@google-cloud/spanner');
const client = new spanner.v1.InstanceAdminClient({
// optional auth parameters.
});
const formattedParent = client.projectPath('[PROJECT]');
const instanceId = '';
const instance = {};
const request = {
parent: formattedParent,
instanceId: instanceId,
instance: instance,
};
// Handle the operation using the promise pattern.
client.createInstance(request)
.then(responses => {
const [operation, initialApiResponse] = responses;
// Operation#promise starts polling for the completion of the LRO.
return operation.promise();
})
.then(responses => {
const result = responses[0];
const metadata = responses[1];
const finalApiResponse = responses[2];
})
.catch(err => {
console.error(err);
});
const formattedParent = client.projectPath('[PROJECT]');
const instanceId = '';
const instance = {};
const request = {
parent: formattedParent,
instanceId: instanceId,
instance: instance,
};
// Handle the operation using the event emitter pattern.
client.createInstance(request)
.then(responses => {
const [operation, initialApiResponse] = responses;
// Adding a listener for the "complete" event starts polling for the
// completion of the operation.
operation.on('complete', (result, metadata, finalApiResponse) => {
// doSomethingWith(result);
});
// Adding a listener for the "progress" event causes the callback to be
// called on any change in metadata when the operation is polled.
operation.on('progress', (metadata, apiResponse) => {
// doSomethingWith(metadata)
});
// Adding a listener for the "error" event handles any errors found during polling.
operation.on('error', err => {
// throw(err);
});
})
.catch(err => {
console.error(err);
});
deleteInstance
deleteInstance(request, options, callback) returns Promise
Deletes an instance.
Immediately upon completion of the request:
- Billing ceases for all of the instance's reserved resources.
Soon afterward:
- The instance and all of its databases immediately and irrevocably disappear from the API. All data in the databases is permanently deleted.
Parameter |
|||||
---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||
options |
Optional Object Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||
callback |
Optional function(nullable Error) The function which will be called with the result of the API call. |
- Returns
-
Promise
- The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.
Example
const spanner = require('@google-cloud/spanner');
const client = new spanner.v1.InstanceAdminClient({
// optional auth parameters.
});
const formattedName = client.instancePath('[PROJECT]', '[INSTANCE]');
client.deleteInstance({name: formattedName}).catch(err => {
console.error(err);
});
getIamPolicy
getIamPolicy(request, options, callback) returns Promise
Gets the access control policy for an instance resource. Returns an empty policy if an instance exists but does not have a policy set.
Authorization requires spanner.instances.getIamPolicy
on resource.
Parameter |
|||||
---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||
options |
Optional Object Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||
callback |
Optional function(nullable Error, nullable Object) The function which will be called with the result of the API call. The second parameter to the callback is an object representing Policy. |
- Returns
-
Promise
- The promise which resolves to an array. The first element of the array is an object representing Policy. The promise has a method named "cancel" which cancels the ongoing API call.
Example
const spanner = require('@google-cloud/spanner');
const client = new spanner.v1.InstanceAdminClient({
// optional auth parameters.
});
const formattedResource = client.instancePath('[PROJECT]', '[INSTANCE]');
client.getIamPolicy({resource: formattedResource})
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});
getInstance
getInstance(request, options, callback) returns Promise
Gets information about a particular instance.
Parameter |
|||||
---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||
options |
Optional Object Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||
callback |
Optional function(nullable Error, nullable Object) The function which will be called with the result of the API call. The second parameter to the callback is an object representing Instance. |
- Returns
-
Promise
- The promise which resolves to an array. The first element of the array is an object representing Instance. The promise has a method named "cancel" which cancels the ongoing API call.
Example
const spanner = require('@google-cloud/spanner');
const client = new spanner.v1.InstanceAdminClient({
// optional auth parameters.
});
const formattedName = client.instancePath('[PROJECT]', '[INSTANCE]');
client.getInstance({name: formattedName})
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});
getInstanceConfig
getInstanceConfig(request, options, callback) returns Promise
Gets information about a particular instance configuration.
Parameter |
|||||
---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||
options |
Optional Object Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||
callback |
Optional function(nullable Error, nullable Object) The function which will be called with the result of the API call. The second parameter to the callback is an object representing InstanceConfig. |
- Returns
-
Promise
- The promise which resolves to an array. The first element of the array is an object representing InstanceConfig. The promise has a method named "cancel" which cancels the ongoing API call.
Example
const spanner = require('@google-cloud/spanner');
const client = new spanner.v1.InstanceAdminClient({
// optional auth parameters.
});
const formattedName = client.instanceConfigPath('[PROJECT]', '[INSTANCE_CONFIG]');
client.getInstanceConfig({name: formattedName})
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});
getProjectId
getProjectId(callback)
Return the project ID used by this class.
Parameter |
|
---|---|
callback |
function(Error, string) the callback to be called with the current project Id. |
instanceConfigPath
instanceConfigPath(project, instanceConfig) returns String
Return a fully-qualified instance_config resource name string.
Parameter |
|
---|---|
project |
String |
instanceConfig |
String |
- Returns
-
String
instancePath
instancePath(project, instance) returns String
Return a fully-qualified instance resource name string.
Parameter |
|
---|---|
project |
String |
instance |
String |
- Returns
-
String
listInstanceConfigs
listInstanceConfigs(request, options, callback) returns Promise
Lists the supported instance configurations for a given project.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||||
options |
Optional Object Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||||
callback |
Optional function(nullable Error, nullable Array, nullable Object, nullable Object) The function which will be called with the result of the API call. The second parameter to the callback is Array of InstanceConfig. When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListInstanceConfigsResponse. |
- Returns
-
Promise
-
The promise which resolves to an array. The first element of the array is Array of InstanceConfig.
When autoPaginate: false is specified through options, the array has three elements. The first element is Array of InstanceConfig in a single response. The second element is the next request object if the response indicates the next page exists, or null. The third element is an object representing ListInstanceConfigsResponse.
The promise has a method named "cancel" which cancels the ongoing API call.
-
Example
const spanner = require('@google-cloud/spanner');
const client = new spanner.v1.InstanceAdminClient({
// optional auth parameters.
});
// Iterate over all elements.
const formattedParent = client.projectPath('[PROJECT]');
client.listInstanceConfigs({parent: formattedParent})
.then(responses => {
const resources = responses[0];
for (const resource of resources) {
// doThingsWith(resource)
}
})
.catch(err => {
console.error(err);
});
// Or obtain the paged response.
const formattedParent = client.projectPath('[PROJECT]');
const options = {autoPaginate: false};
const callback = responses => {
// The actual resources in a response.
const resources = responses[0];
// The next request if the response shows that there are more responses.
const nextRequest = responses[1];
// The actual response object, if necessary.
// const rawResponse = responses[2];
for (const resource of resources) {
// doThingsWith(resource);
}
if (nextRequest) {
// Fetch the next page.
return client.listInstanceConfigs(nextRequest, options).then(callback);
}
}
client.listInstanceConfigs({parent: formattedParent}, options)
.then(callback)
.catch(err => {
console.error(err);
});
listInstanceConfigsStream
listInstanceConfigsStream(request, options) returns Stream
Equivalent to listInstanceConfigs, but returns a NodeJS Stream object.
This fetches the paged responses for listInstanceConfigs continuously and invokes the callback registered for 'data' event for each element in the responses.
The returned object has 'end' method when no more elements are required.
autoPaginate option will be ignored.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||||
options |
Optional Object Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
- See also
- https://nodejs.org/api/stream.html
- Returns
-
Stream
An object stream which emits an object representing InstanceConfig on 'data' event.
Example
const spanner = require('@google-cloud/spanner');
const client = new spanner.v1.InstanceAdminClient({
// optional auth parameters.
});
const formattedParent = client.projectPath('[PROJECT]');
client.listInstanceConfigsStream({parent: formattedParent})
.on('data', element => {
// doThingsWith(element)
}).on('error', err => {
console.log(err);
});
listInstances
listInstances(request, options, callback) returns Promise
Lists all instances in the given project.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||||||
options |
Optional Object Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||||||
callback |
Optional function(nullable Error, nullable Array, nullable Object, nullable Object) The function which will be called with the result of the API call. The second parameter to the callback is Array of Instance. When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListInstancesResponse. |
- Returns
-
Promise
-
The promise which resolves to an array. The first element of the array is Array of Instance.
When autoPaginate: false is specified through options, the array has three elements. The first element is Array of Instance in a single response. The second element is the next request object if the response indicates the next page exists, or null. The third element is an object representing ListInstancesResponse.
The promise has a method named "cancel" which cancels the ongoing API call.
-
Example
const spanner = require('@google-cloud/spanner');
const client = new spanner.v1.InstanceAdminClient({
// optional auth parameters.
});
// Iterate over all elements.
const formattedParent = client.projectPath('[PROJECT]');
client.listInstances({parent: formattedParent})
.then(responses => {
const resources = responses[0];
for (const resource of resources) {
// doThingsWith(resource)
}
})
.catch(err => {
console.error(err);
});
// Or obtain the paged response.
const formattedParent = client.projectPath('[PROJECT]');
const options = {autoPaginate: false};
const callback = responses => {
// The actual resources in a response.
const resources = responses[0];
// The next request if the response shows that there are more responses.
const nextRequest = responses[1];
// The actual response object, if necessary.
// const rawResponse = responses[2];
for (const resource of resources) {
// doThingsWith(resource);
}
if (nextRequest) {
// Fetch the next page.
return client.listInstances(nextRequest, options).then(callback);
}
}
client.listInstances({parent: formattedParent}, options)
.then(callback)
.catch(err => {
console.error(err);
});
listInstancesStream
listInstancesStream(request, options) returns Stream
Equivalent to listInstances, but returns a NodeJS Stream object.
This fetches the paged responses for listInstances continuously and invokes the callback registered for 'data' event for each element in the responses.
The returned object has 'end' method when no more elements are required.
autoPaginate option will be ignored.
Parameter |
|||||||||
---|---|---|---|---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||||||
options |
Optional Object Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
- See also
- https://nodejs.org/api/stream.html
- Returns
-
Stream
An object stream which emits an object representing Instance on 'data' event.
Example
const spanner = require('@google-cloud/spanner');
const client = new spanner.v1.InstanceAdminClient({
// optional auth parameters.
});
const formattedParent = client.projectPath('[PROJECT]');
client.listInstancesStream({parent: formattedParent})
.on('data', element => {
// doThingsWith(element)
}).on('error', err => {
console.log(err);
});
matchInstanceConfigFromInstanceConfigName
matchInstanceConfigFromInstanceConfigName(instanceConfigName) returns String
Parse the instanceConfigName from a instance_config resource.
Parameter |
|
---|---|
instanceConfigName |
String A fully-qualified path representing a instance_config resources. |
- Returns
-
String
- A string representing the instance_config.
matchInstanceFromInstanceName
matchInstanceFromInstanceName(instanceName) returns String
Parse the instanceName from a instance resource.
Parameter |
|
---|---|
instanceName |
String A fully-qualified path representing a instance resources. |
- Returns
-
String
- A string representing the instance.
matchProjectFromInstanceConfigName
matchProjectFromInstanceConfigName(instanceConfigName) returns String
Parse the instanceConfigName from a instance_config resource.
Parameter |
|
---|---|
instanceConfigName |
String A fully-qualified path representing a instance_config resources. |
- Returns
-
String
- A string representing the project.
matchProjectFromInstanceName
matchProjectFromInstanceName(instanceName) returns String
Parse the instanceName from a instance resource.
Parameter |
|
---|---|
instanceName |
String A fully-qualified path representing a instance resources. |
- Returns
-
String
- A string representing the project.
matchProjectFromProjectName
matchProjectFromProjectName(projectName) returns String
Parse the projectName from a project resource.
Parameter |
|
---|---|
projectName |
String A fully-qualified path representing a project resources. |
- Returns
-
String
- A string representing the project.
projectPath
projectPath(project) returns String
Return a fully-qualified project resource name string.
Parameter |
|
---|---|
project |
String |
- Returns
-
String
setIamPolicy
setIamPolicy(request, options, callback) returns Promise
Sets the access control policy on an instance resource. Replaces any existing policy.
Authorization requires spanner.instances.setIamPolicy
on resource.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||||
options |
Optional Object Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||||
callback |
Optional function(nullable Error, nullable Object) The function which will be called with the result of the API call. The second parameter to the callback is an object representing Policy. |
- Returns
-
Promise
- The promise which resolves to an array. The first element of the array is an object representing Policy. The promise has a method named "cancel" which cancels the ongoing API call.
Example
const spanner = require('@google-cloud/spanner');
const client = new spanner.v1.InstanceAdminClient({
// optional auth parameters.
});
const formattedResource = client.instancePath('[PROJECT]', '[INSTANCE]');
const policy = {};
const request = {
resource: formattedResource,
policy: policy,
};
client.setIamPolicy(request)
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});
testIamPermissions
testIamPermissions(request, options, callback) returns Promise
Returns permissions that the caller has on the specified instance resource.
Attempting this RPC on a non-existent Cloud Spanner instance resource will result in a NOT_FOUND error if the user has spanner.instances.list
permission on the containing Google Cloud Project. Otherwise returns an empty set
of permissions.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||||
options |
Optional Object Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||||
callback |
Optional function(nullable Error, nullable Object) The function which will be called with the result of the API call. The second parameter to the callback is an object representing TestIamPermissionsResponse. |
- Returns
-
Promise
- The promise which resolves to an array. The first element of the array is an object representing TestIamPermissionsResponse. The promise has a method named "cancel" which cancels the ongoing API call.
Example
const spanner = require('@google-cloud/spanner');
const client = new spanner.v1.InstanceAdminClient({
// optional auth parameters.
});
const formattedResource = client.instancePath('[PROJECT]', '[INSTANCE]');
const permissions = [];
const request = {
resource: formattedResource,
permissions: permissions,
};
client.testIamPermissions(request)
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});
updateInstance
updateInstance(request, options, callback) returns Promise
Updates an instance, and begins allocating or releasing resources as requested. The returned long-running operation can be used to track the progress of updating the instance. If the named instance does not exist, returns NOT_FOUND
.
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.
The returned long-running operation will have a name of the format <instance_name>/operations/<operation_id>
and can be used to track the instance modification. The metadata field type is UpdateInstanceMetadata.
The response field type is Instance, if successful.
Authorization requires spanner.instances.update
permission on resource name.
Parameter |
|||||||
---|---|---|---|---|---|---|---|
request |
Object The request object that will be sent. Values in
|
||||||
options |
Optional Object Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details. |
||||||
callback |
Optional function(nullable Error, nullable Object) The function which will be called with the result of the API call. The second parameter to the callback is a gax.Operation object. |
- Returns
-
Promise
- The promise which resolves to an array. The first element of the array is a gax.Operation object. The promise has a method named "cancel" which cancels the ongoing API call.
Example
const spanner = require('@google-cloud/spanner');
const client = new spanner.v1.InstanceAdminClient({
// optional auth parameters.
});
const instance = {};
const fieldMask = {};
const request = {
instance: instance,
fieldMask: fieldMask,
};
// Handle the operation using the promise pattern.
client.updateInstance(request)
.then(responses => {
const [operation, initialApiResponse] = responses;
// Operation#promise starts polling for the completion of the LRO.
return operation.promise();
})
.then(responses => {
const result = responses[0];
const metadata = responses[1];
const finalApiResponse = responses[2];
})
.catch(err => {
console.error(err);
});
const instance = {};
const fieldMask = {};
const request = {
instance: instance,
fieldMask: fieldMask,
};
// Handle the operation using the event emitter pattern.
client.updateInstance(request)
.then(responses => {
const [operation, initialApiResponse] = responses;
// Adding a listener for the "complete" event starts polling for the
// completion of the operation.
operation.on('complete', (result, metadata, finalApiResponse) => {
// doSomethingWith(result);
});
// Adding a listener for the "progress" event causes the callback to be
// called on any change in metadata when the operation is polled.
operation.on('progress', (metadata, apiResponse) => {
// doSomethingWith(metadata)
});
// Adding a listener for the "error" event handles any errors found during polling.
operation.on('error', err => {
// throw(err);
});
})
.catch(err => {
console.error(err);
});