Constructor

InstanceAdminClient

new InstanceAdminClient(options)

Construct an instance of InstanceAdminClient.

Parameter

options

Optional

object

The configuration object. See the subsequent parameters for more details.

Properties

port

static

The port for this API service.

scopes

static

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

static

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.

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');

var client = new spanner.v1.InstanceAdminClient({
  // optional auth parameters.
});

var formattedParent = client.projectPath('[PROJECT]');
var instanceId = '';
var instance = {};
var request = {
  parent: formattedParent,
  instanceId: instanceId,
  instance: instance,
};

// Handle the operation using the promise pattern.
client.createInstance(request)
  .then(responses => {
    var operation = responses[0];
    var initialApiResponse = responses[1];

    // Operation#promise starts polling for the completion of the LRO.
    return operation.promise();
  })
  .then(responses => {
    // The final result of the operation.
    var result = responses[0];

    // The metadata value of the completed operation.
    var metadata = responses[1];

    // The response of the api call returning the complete operation.
    var finalApiResponse = responses[2];
  })
  .catch(err => {
    console.error(err);
  });

var formattedParent = client.projectPath('[PROJECT]');
var instanceId = '';
var instance = {};
var request = {
  parent: formattedParent,
  instanceId: instanceId,
  instance: instance,
};

// Handle the operation using the event emitter pattern.
client.createInstance(request)
  .then(responses => {
    var operation = responses[0];
    var initialApiResponse = responses[1];

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

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');

var client = new spanner.v1.InstanceAdminClient({
  // optional auth parameters.
});

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

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');

var client = new spanner.v1.InstanceAdminClient({
  // optional auth parameters.
});

var formattedResource = client.instancePath('[PROJECT]', '[INSTANCE]');
client.getIamPolicy({resource: formattedResource})
  .then(responses => {
    var 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.

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');

var client = new spanner.v1.InstanceAdminClient({
  // optional auth parameters.
});

var formattedName = client.instancePath('[PROJECT]', '[INSTANCE]');
client.getInstance({name: formattedName})
  .then(responses => {
    var 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.

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');

var client = new spanner.v1.InstanceAdminClient({
  // optional auth parameters.
});

var formattedName = client.instanceConfigPath('[PROJECT]', '[INSTANCE_CONFIG]');
client.getInstanceConfig({name: formattedName})
  .then(responses => {
    var 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.

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');

var client = new spanner.v1.InstanceAdminClient({
  // optional auth parameters.
});

// Iterate over all elements.
var formattedParent = client.projectPath('[PROJECT]');

client.listInstanceConfigs({parent: formattedParent})
  .then(responses => {
    var resources = responses[0];
    for (let i = 0; i < resources.length; i += 1) {
      // doThingsWith(resources[i])
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
var formattedParent = client.projectPath('[PROJECT]');


var options = {autoPaginate: false};
var callback = responses => {
  // The actual resources in a response.
  var resources = responses[0];
  // The next request if the response shows that there are more responses.
  var nextRequest = responses[1];
  // The actual response object, if necessary.
  // var rawResponse = responses[2];
  for (let i = 0; i < resources.length; i += 1) {
    // doThingsWith(resources[i]);
  }
  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.

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');

var client = new spanner.v1.InstanceAdminClient({
  // optional auth parameters.
});

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

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');

var client = new spanner.v1.InstanceAdminClient({
  // optional auth parameters.
});

// Iterate over all elements.
var formattedParent = client.projectPath('[PROJECT]');

client.listInstances({parent: formattedParent})
  .then(responses => {
    var resources = responses[0];
    for (let i = 0; i < resources.length; i += 1) {
      // doThingsWith(resources[i])
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
var formattedParent = client.projectPath('[PROJECT]');


var options = {autoPaginate: false};
var callback = responses => {
  // The actual resources in a response.
  var resources = responses[0];
  // The next request if the response shows that there are more responses.
  var nextRequest = responses[1];
  // The actual response object, if necessary.
  // var rawResponse = responses[2];
  for (let i = 0; i < resources.length; i += 1) {
    // doThingsWith(resources[i]);
  }
  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.

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');

var client = new spanner.v1.InstanceAdminClient({
  // optional auth parameters.
});

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

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');

var client = new spanner.v1.InstanceAdminClient({
  // optional auth parameters.
});

var formattedResource = client.instancePath('[PROJECT]', '[INSTANCE]');
var policy = {};
var request = {
  resource: formattedResource,
  policy: policy,
};
client.setIamPolicy(request)
  .then(responses => {
    var 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.

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');

var client = new spanner.v1.InstanceAdminClient({
  // optional auth parameters.
});

var formattedResource = client.instancePath('[PROJECT]', '[INSTANCE]');
var permissions = [];
var request = {
  resource: formattedResource,
  permissions: permissions,
};
client.testIamPermissions(request)
  .then(responses => {
    var 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.

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');

var client = new spanner.v1.InstanceAdminClient({
  // optional auth parameters.
});

var instance = {};
var fieldMask = {};
var request = {
  instance: instance,
  fieldMask: fieldMask,
};

// Handle the operation using the promise pattern.
client.updateInstance(request)
  .then(responses => {
    var operation = responses[0];
    var initialApiResponse = responses[1];

    // Operation#promise starts polling for the completion of the LRO.
    return operation.promise();
  })
  .then(responses => {
    // The final result of the operation.
    var result = responses[0];

    // The metadata value of the completed operation.
    var metadata = responses[1];

    // The response of the api call returning the complete operation.
    var finalApiResponse = responses[2];
  })
  .catch(err => {
    console.error(err);
  });

var instance = {};
var fieldMask = {};
var request = {
  instance: instance,
  fieldMask: fieldMask,
};

// Handle the operation using the event emitter pattern.
client.updateInstance(request)
  .then(responses => {
    var operation = responses[0];
    var initialApiResponse = responses[1];

    // 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);
  });