Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
43f6e17
bigtable: v2 support
callmehiphop Aug 8, 2016
377c39a
added support for grpc operations
callmehiphop Aug 17, 2016
adda9e0
added system tests for new apis
callmehiphop Aug 17, 2016
d77b73c
documented all the things!
callmehiphop Aug 17, 2016
50c7403
linted + streaming tests
callmehiphop Aug 17, 2016
7b9b764
updated docs for grpc operations
callmehiphop Aug 18, 2016
ed1f7cc
fixed broken unit tests
callmehiphop Aug 19, 2016
ef548c8
added Instance tests
callmehiphop Aug 19, 2016
13b0417
added Cluster tests
callmehiphop Aug 19, 2016
87de5e9
added GrpcOperation tests
callmehiphop Aug 19, 2016
c7e41b9
linting all the things
callmehiphop Aug 19, 2016
363d4d4
updated proto files
callmehiphop Aug 19, 2016
1b9e002
fixed documentation typos
callmehiphop Aug 21, 2016
0973ca9
updated several assertions
callmehiphop Aug 21, 2016
17e5362
created getLocation method for clusters
callmehiphop Aug 21, 2016
c5a58cc
adding tests for new/updated methods
callmehiphop Aug 21, 2016
3516c59
fix lint issue
callmehiphop Aug 21, 2016
fc47d5d
additional unit tests
callmehiphop Aug 22, 2016
502c2e8
small documentation changes
callmehiphop Aug 22, 2016
f34b47c
lint round 2
callmehiphop Aug 25, 2016
51c8d3e
update mutations to not re-encode buffers
callmehiphop Aug 25, 2016
4f63a08
add encode/decode options
callmehiphop Aug 25, 2016
878e1a2
fix linting errors
callmehiphop Aug 25, 2016
e0bbc4d
reverted jscs rules
callmehiphop Aug 25, 2016
fc1e9fb
bumping common version
callmehiphop Aug 29, 2016
a0e461a
removed encode option
callmehiphop Aug 29, 2016
718b7d2
refactored Table#mutate to only return failed statuses
callmehiphop Aug 29, 2016
952dcdc
mutate tweaks + doc updates
callmehiphop Aug 29, 2016
4125d3f
updated mutate to return an event emitter
callmehiphop Aug 29, 2016
9fcba7d
renamed entries param to mutationErrors
callmehiphop Aug 29, 2016
36458f4
updated emitter docs + changed finish event to complete
callmehiphop Aug 29, 2016
fc34f2f
updating system-tests
callmehiphop Aug 29, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/bigtable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
"bigtable"
],
"dependencies": {
"@google-cloud/common": "^0.1.0",
"arrify": "^1.0.0",
"concat-stream": "^1.5.0",
"create-error-class": "^2.0.1",
"dot-prop": "^2.4.0",
"extend": "^3.0.0",
"google-proto-files": "^0.2.1",
"@google-cloud/common": "^0.3.0",
"google-proto-files": "^0.7.0",
"is": "^3.0.1",
"lodash.flatten": "^4.2.0",
"node-int64": "^0.4.0",
Expand Down
275 changes: 275 additions & 0 deletions packages/bigtable/src/cluster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
/*!
* Copyright 2016 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.
*/

/*!
* @module bigtable/instance
*/

'use strict';

var common = require('@google-cloud/common');
var format = require('string-format-obj');
var is = require('is');
var util = require('util');

/**
* Create a cluster object to interact with your cluster.
*
* @constructor
* @alias module:bigtable/cluster
*
* @param {string} name - Name of the cluster.
*
* @example
* var instance = bigtable.instance('my-instance');
* var cluster = instance.cluster('my-cluster');
*/
function Cluster(instance, name) {
var id = name;

if (id.indexOf('/') === -1) {
id = instance.id + '/clusters/' + name;
}

var methods = {

/**
* Create a cluster.
*
* @param {object} options - See {module:bigtable/instance#createCluster}
*
* @example
* 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.
* });
* });
*/
create: true,

/**
* Delete the cluster.
*
* @param {function=} callback - The callback function.
* @param {?error} callback.err - An error returned while making this
* request.
* @param {object} callback.apiResponse - The full API response.
*
* @example
* cluster.delete(function(err, apiResponse) {});
*/
delete: {
protoOpts: {
service: 'BigtableInstanceAdmin',
method: 'deleteCluster'
},
reqOpts: {
name: id
}
},

/**
* Check if a cluster exists.
*
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error returned while making this
* request.
* @param {boolean} callback.exists - Whether the cluster exists or not.
*
* @example
* cluster.exists(function(err, exists) {});
*/
exists: true,

/**
* Get a cluster if it exists.
*
* @example
* cluster.get(function(err, cluster, apiResponse) {
* // The `cluster` data has been populated.
* });
*/
get: true,

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


/**
* Get the cluster metadata.
*
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error returned while making this
* request.
* @param {object} callback.metadata - The metadata.
* @param {object} callback.apiResponse - The full API response.
*
* @example
* cluster.getMetadata(function(err, metadata, apiResponse) {});
*/
getMetadata: {
protoOpts: {
service: 'BigtableInstanceAdmin',
method: 'getCluster'
},
reqOpts: {
name: id
}
}
};

var config = {
parent: instance,
id: id,
methods: methods,
createMethod: function(_, options, callback) {
instance.createCluster(name, options, callback);
}
};

common.GrpcServiceObject.call(this, config);
}

util.inherits(Cluster, common.GrpcServiceObject);

/**
* Formats zone location.
*
* @private
*
* @param {string} project - The project.
* @param {string} location - The zone location.
* @return {string}
*
* @example
* Cluster.getLocation_('my-project', 'us-central1-b');
* // 'projects/my-project/locations/us-central1-b'
*/
Cluster.getLocation_ = function(project, location) {
if (location.indexOf('/') > -1) {
return location;
}

return format('projects/{project}/locations/{location}', {
project: project,
location: location
});
};

/**
* Maps the storage type to the proper integer.
*
* @private
*
* @param {string} type - The storage type (hdd, ssd).
* @return {number}
*
* @example
* Cluster.getStorageType_('ssd');
* // 1
*/
Cluster.getStorageType_ = function(type) {
var storageTypes = {
unspecified: 0,
ssd: 1,
hdd: 2
};

if (is.string(type)) {
type = type.toLowerCase();
}

return storageTypes[type] || storageTypes.unspecified;
};

/**
* Set the cluster metadata.
*
* See {module:bigtable/instance#createCluster} for a detailed explanation of
* the arguments.
*
* @param {object} metadata - Metadata object.
* @param {string} metadata.location - The cluster location.
* @param {number} metadata.nodes - Number of nodes allocated to the cluster.
* @param {string} metadata.storage - The cluster storage type.
* @param {function} callback - The callback function.
* @param {?error} callback.err - An error returned while making this request.
* @param {Operation} callback.operation - An operation object that can be used
* to check the status of the request.
* @param {object} callback.apiResponse - The full API response.
*
* @example
* var callback = function(err, operation, apiResponse) {
* if (err) {
* // Error handling omitted.
* }
*
* operation
* .on('error', console.error)
* .on('complete', function() {
* // The cluster was updated successfully.
* });
* };
*
* cluster.setMetadata({
* location: 'us-central1-b',
* nodes: 3,
* storage: 'ssd'
* }, callback);
*/
Cluster.prototype.setMetadata = function(options, callback) {
var protoOpts = {
service: 'BigtableInstanceAdmin',
method: 'updateCluster'
};

var reqOpts = {
name: this.id
};

var bigtable = this.parent.parent;

if (options.location) {
reqOpts.location = Cluster.getLocation_(
bigtable.projectId,
options.location
);
}

if (options.nodes) {
reqOpts.serveNodes = options.nodes;
}

if (options.storage) {
reqOpts.defaultStorageType = Cluster.getStorageType_(options.storage);
}

this.request(protoOpts, reqOpts, function(err, resp) {
if (err) {
callback(err, null, resp);
return;
}

var operation = bigtable.operation(resp.name);
operation.metadata = resp;

callback(null, operation, resp);
});
};

module.exports = Cluster;
Loading