Skip to content

Added example region-tags for cluster object #284

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 8 commits into from
Nov 9, 2018
Merged
135 changes: 135 additions & 0 deletions samples/document-snippets/cluster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* Copyright 2018, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const snippets = {
create: (instanceId, clusterId) => {
// [START bigtable_create_cluster]
const Bigtable = require('@google-cloud/bigtable');
const bigtable = new Bigtable();
const instance = bigtable.instance(instanceId);
const cluster = instance.cluster(clusterId);

cluster
.create()
.then(result => {
const cluster = result[0];
const operation = result[1];
const apiResponse = result[2];
})
.catch(err => {
// Handle the error.
});
// [END bigtable_create_cluster]
},

delete: (instanceId, clusterId) => {
// [START bigtable_delete_cluster]
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.
});
// [END bigtable_delete_cluster]
},

exists: (instanceId, clusterId) => {
// [START bigtable_exists_cluster]
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.
});
// [END bigtable_exists_cluster]
},

get: (instanceId, clusterId) => {
// [START bigtable_get_cluster]
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.
});
// [END bigtable_get_cluster]
},

getMeta: (instanceId, clusterId) => {
// [START bigtable_cluster_get_meta]
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.
});
// [END bigtable_cluster_get_meta]
},

setMeta: (instanceId, clusterId) => {
// [START bigtable_cluster_set_meta]
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.
});
// [END bigtable_cluster_set_meta]
},
};

module.exports = snippets;
76 changes: 76 additions & 0 deletions samples/document-snippets/tests/cluster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Copyright 2018 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';
const uuid = require(`uuid`);

const Bigtable = require(`@google-cloud/bigtable`);
const bigtable = new Bigtable();

const INSTANCE_ID = `nodejs-bigtable-samples-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules
const CLUSTER_ID = `nodejs-bigtable-samples-${uuid.v4()}`.substr(0, 30); // Bigtable naming rules

const clusterSnippets = require('../cluster.js');

const instance = bigtable.instance(INSTANCE_ID);

describe('Cluster Snippets', function() {
before(() => {
instance.create({
clusters: [
{
name: CLUSTER_ID,
location: 'us-central1-f',
storage: 'hdd',
},
],
type: 'DEVELOPMENT',
});
});

after(() => {
instance.exists().then(result => {
const exists = result[0];
if (exists) {
instance.delete();
}
});
});

it('should create a cluster', () => {
clusterSnippets.create(INSTANCE_ID, CLUSTER_ID);
});

it('should check cluster exists', () => {
clusterSnippets.exists(INSTANCE_ID, CLUSTER_ID);
});

it('should get the cluster', () => {
clusterSnippets.get(INSTANCE_ID, CLUSTER_ID);
});

it('should get cluster metadata', () => {
clusterSnippets.getMeta(INSTANCE_ID, CLUSTER_ID);
});

it('should set cluster metadata', () => {
clusterSnippets.setMeta(INSTANCE_ID, CLUSTER_ID);
});

it('should delete a cluster', () => {
clusterSnippets.delete(INSTANCE_ID, CLUSTER_ID);
});
});
111 changes: 12 additions & 99 deletions src/cluster.js
Original file line number Diff line number Diff line change
@@ -114,32 +114,8 @@ Please use the format 'my-cluster' or '${instance.name}/clusters/my-cluster'.`
* request.
* @param {object} callback.apiResponse The full API response.
*
* @example
* const Bigtable = require('@google-cloud/bigtable');
* const bigtable = new Bigtable();
* const instance = bigtable.instance('my-instance');
* const cluster = instance.cluster('my-cluster');
*
* cluster.create(function(err, cluster, operation, apiResponse) {
* if (err) {
* // Error handling omitted.
* }
*
* operation
* .on('error', console.error)
* .on('complete', function() {
* // The cluster was created successfully.
* });
* });
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* cluster.create().then(function(data) {
* const cluster = data[0];
* const operation = data[1];
* const apiResponse = data[2];
* });
* @example <caption>include:samples/document-snippets/cluster.js</caption>
* region_tag:bigtable_create_cluster
*/
create(options, callback) {
if (is.fn(options)) {
@@ -160,15 +136,8 @@ Please use the format 'my-cluster' or '${instance.name}/clusters/my-cluster'.`
* request.
* @param {object} callback.apiResponse The full API response.
*
* @example
* cluster.delete(function(err, apiResponse) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* cluster.delete().then(function(data) {
* var apiResponse = data[0];
* });
* @example <caption>include:samples/document-snippets/cluster.js</caption>
* region_tag:bigtable_delete_cluster
*/
delete(gaxOptions, callback) {
if (is.fn(gaxOptions)) {
@@ -199,15 +168,8 @@ Please use the format 'my-cluster' or '${instance.name}/clusters/my-cluster'.`
* request.
* @param {boolean} callback.exists Whether the cluster exists or not.
*
* @example
* cluster.exists(function(err, exists) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* cluster.exists().then(function(data) {
* var exists = data[0];
* });
* @example <caption>include:samples/document-snippets/cluster.js</caption>
* region_tag:bigtable_exists_cluster
*/
exists(gaxOptions, callback) {
if (is.fn(gaxOptions)) {
@@ -240,18 +202,8 @@ Please use the format 'my-cluster' or '${instance.name}/clusters/my-cluster'.`
* request.
* @param {object} callback.apiResponse The full API response.
*
* @example
* cluster.get(function(err, cluster, apiResponse) {
* // The `cluster` data has been populated.
* });
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* cluster.get().then(function(data) {
* var cluster = data[0];
* var apiResponse = data[1];
* });
* @example <caption>include:samples/document-snippets/cluster.js</caption>
* region_tag:bigtable_get_cluster
*/
get(gaxOptions, callback) {
if (is.fn(gaxOptions)) {
@@ -275,16 +227,8 @@ Please use the format 'my-cluster' or '${instance.name}/clusters/my-cluster'.`
* @param {object} callback.metadata The metadata.
* @param {object} callback.apiResponse The full API response.
*
* @example
* cluster.getMetadata(function(err, metadata, apiResponse) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* cluster.getMetadata().then(function(data) {
* var metadata = data[0];
* var apiResponse = data[1];
* });
* @example <caption>include:samples/document-snippets/cluster.js</caption>
* region_tag:bigtable_cluster_get_meta
*/
getMetadata(gaxOptions, callback) {
if (is.fn(gaxOptions)) {
@@ -324,39 +268,8 @@ Please use the format 'my-cluster' or '${instance.name}/clusters/my-cluster'.`
* to check the status of the request.
* @param {object} callback.apiResponse The full API response.
*
* @example
* const Bigtable = require('@google-cloud/bigtable');
* const bigtable = new Bigtable();
* const instance = bigtable.instance('my-instance');
* const cluster = instance.cluster('my-cluster');
*
* const callback = function(err, operation, apiResponse) {
* if (err) {
* // Error handling omitted.
* }
*
* operation
* .on('error', console.error)
* .on('complete', function() {
* // The cluster was updated successfully.
* });
* };
*
* const metadata = {
* location: 'us-central1-b',
* nodes: 3,
* storage: 'ssd'
* };
*
* cluster.setMetadata(metadata, callback);
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* cluster.setMetadata(metadata).then(function(data) {
* const operation = data[0];
* const apiResponse = data[1];
* });
* @example <caption>include:samples/document-snippets/cluster.js</caption>
* region_tag:bigtable_cluster_set_meta
*/
setMetadata(metadata, gaxOptions, callback) {
if (is.fn(gaxOptions)) {