Cluster

Cluster

Create a cluster object to interact with your cluster.

Constructor

new Cluster(instance, id)

Parameters:
Name Type Description
instance Instance

The parent instance of this cluster.

id string

Id of the cluster.

Example
```
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
const cluster = instance.cluster('my-cluster');
```

Methods

backup(id) → {Backup}

Get a reference to a Bigtable Cluster.

Parameters:
Name Type Description
id string

The backup name or id.

Returns:
Type Description
Backup

create(optionsopt, callbackopt)

Create a cluster.

Parameters:
Name Type Attributes Description
options object <optional>

See Instance#createCluster.

callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

apiResponse object

The full API response.

Example
    const {Bigtable} = require('@google-cloud/bigtable');
    const bigtable = new Bigtable();
    const instance = bigtable.instance(instanceId);

    // const options = {
    //   location: 'us-central1-b',
    //   nodes: 3,
    //   storage: 'ssd',
    // };
    const options = {
      location: 'us-central1-b',
      storage: 'hdd',
    };
    instance
      .createCluster(clusterId, options)
      .then(result => {
        const newCluster = result[0];
        // const operations = result[1];
        // const apiResponse = result[2];
      })
      .catch(err => {
        // Handle the error.
      });

createBackup(id, config, callbackopt) → {void|Promise.<CreateBackupResponse>}

Backup a table from this cluster.

Parameters:
Name Type Attributes Description
id string

A unique ID for the backup.

config object

Configuration object.

Properties
Name Type Attributes Description
expireTime BackupTimestamp

When the backup will be automatically deleted.

table string | Table

Table to create the backup from.

gaxOptions CallOptions <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback CreateBackupCallback <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

backup Backup

The newly created Backup.

operation Operation

An operation object that can be used to check the status of the request.

apiResponse object

The full API response.

Returns:
Type Description
void | Promise.<CreateBackupResponse>
Example
  const {Bigtable} = require('@google-cloud/bigtable');
  const bigtable = new Bigtable();

  async function createBackup() {
    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const instanceId = 'YOUR_INSTANCE_ID';
    // const tableId = 'YOUR_TABLE_ID';
    // const clusterId = 'YOUR_CLUSTER_ID';
    // const backupId = 'YOUR_BACKUP_ID';

    const instance = bigtable.instance(instanceId);
    const cluster = instance.cluster(clusterId);

    const [backup, operation] = await cluster.createBackup(backupId, {
      table: tableId,
      expireTime: new Date(Date.now() + 7 * 60 * 60 * 1000), // 7 hours from now
    });

    console.log('Started a table backup operation.');
    await operation.promise();

    console.log(`Backup "${backup.id}" is now ready for use.`);
  }

  await createBackup();

delete(gaxOptionsopt, callbackopt)

Delete the cluster.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

apiResponse object

The full API response.

Example
    const {Bigtable} = require('@google-cloud/bigtable');
    const bigtable = new Bigtable();
    const instance = bigtable.instance(instanceId);
    const cluster = instance.cluster(clusterId);

    cluster
      .delete()
      .then(result => {
        const apiResponse = result[0];
      })
      .catch(err => {
        // Handle the error.
      });

exists(gaxOptionsopt, callback)

Check if a cluster exists.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

exists boolean

Whether the cluster exists or not.

Example
    const {Bigtable} = require('@google-cloud/bigtable');
    const bigtable = new Bigtable();
    const instance = bigtable.instance(instanceId);
    const cluster = instance.cluster(clusterId);

    cluster
      .exists()
      .then(result => {
        const exists = result[0];
      })
      .catch(err => {
        // Handle the error.
      });

get(gaxOptionsopt, callback)

Get a cluster if it exists.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

apiResponse object

The full API response.

Example
    const {Bigtable} = require('@google-cloud/bigtable');
    const bigtable = new Bigtable();
    const instance = bigtable.instance(instanceId);
    const cluster = instance.cluster(clusterId);

    cluster
      .get()
      .then(result => {
        const cluster = result[0];
        const apiResponse = result[1];
      })
      .catch(err => {
        // Handle the error.
      });

getBackups(optionsOrCallbackopt, callbackopt) → {void|Promise.<ListBackupsResponse>}

Get Cloud Bigtable Backup instances within this cluster. This returns both completed and pending backups.

Parameters:
Name Type Attributes Description
optionsOrCallback GetBackupsOptions | GetBackupsCallback <optional>
callback GetBackupsResponse <optional>

The callback function.

Properties
Name Type Attributes Description
error error <nullable>

An error returned while making this request.

backups Array.<Backup>

All matching Backup instances.

apiResponse object

The full API response.

Returns:
Type Description
void | Promise.<ListBackupsResponse>
Example
  const {Bigtable} = require('@google-cloud/bigtable');
  const bigtable = new Bigtable();

  async function listBackups() {
    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const instanceId = 'YOUR_INSTANCE_ID';
    // const tableId = 'YOUR_TABLE_ID';
    // const clusterId = 'YOUR_CLUSTER_ID';
    const instance = bigtable.instance(instanceId);
    const table = instance.table(tableId);
    const cluster = table.cluster(clusterId);

    const [backupsFromInstance] = await instance.listBackups();
    console.log(
      `${backupsFromInstance.length} backups returned from the instance.`
    );

    const [backupsFromCluster] = await cluster.listBackups();
    console.log(
      `${backupsFromCluster.length} backups returned from the cluster.`
    );
  }

  await listBackups();

getBackupsStream(optionsopt) → {ReadableStream.<Backup>}

Lists Cloud Bigtable backups within this cluster. Provides both completed and pending backups as a readable object stream.

Parameters:
Name Type Attributes Description
options GetBackupsOptions <optional>

Configuration object. See Cluster#getBackups for a complete list of options.

Returns:
Type Description
ReadableStream.<Backup>
Example
```
const {Bigtable} = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance('my-instance');
const cluster = instance.cluster('my-cluster');

cluster.getBackupsStream()
  .on('error', console.error)
  .on('data', function(backup) {
    // backup is a Backup object.
  })
  .on('end', () => {
    // All backups retrieved.
  });

//-
// If you anticipate many results, you can end a stream early to prevent
// unnecessary processing and API requests.
//-
cluster.getBackupsStream()
  .on('data', function(backup) {
    this.end();
  });
```

getMetadata(gaxOptionsopt, callback)

Get the cluster metadata.

Parameters:
Name Type Attributes Description
gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

metadata object

The metadata.

apiResponse object

The full API response.

Example
    const {Bigtable} = require('@google-cloud/bigtable');
    const bigtable = new Bigtable();
    const instance = bigtable.instance(instanceId);
    const cluster = instance.cluster(clusterId);

    cluster
      .getMetadata()
      .then(result => {
        const metadata = result[0];
        const apiResponse = result[1];
      })
      .catch(err => {
        // Handle the error.
      });

setMetadata(metadata, gaxOptionsopt, callback)

Set the cluster metadata.

Parameters:
Name Type Attributes Description
metadata object

See Instance#createCluster for the available metadata options.

gaxOptions object <optional>

Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/CallSettings.html.

callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

operation Operation

An operation object that can be used to check the status of the request.

apiResponse object

The full API response.

Example
    const {Bigtable} = require('@google-cloud/bigtable');
    const bigtable = new Bigtable();
    const instance = bigtable.instance(instanceId);
    const cluster = instance.cluster(clusterId);

    const metadata = {
      nodes: 4,
    };

    cluster
      .setMetadata(metadata)
      .then(result => {
        const operation = result[0];
        const apiResponse = result[1];
      })
      .catch(err => {
        // Handle the error.
      });