-
Notifications
You must be signed in to change notification settings - Fork 641
bigtable: v2 support #1439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
bigtable: v2 support #1439
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
43f6e17
bigtable: v2 support
callmehiphop 377c39a
added support for grpc operations
callmehiphop adda9e0
added system tests for new apis
callmehiphop d77b73c
documented all the things!
callmehiphop 50c7403
linted + streaming tests
callmehiphop 7b9b764
updated docs for grpc operations
callmehiphop ed1f7cc
fixed broken unit tests
callmehiphop ef548c8
added Instance tests
callmehiphop 13b0417
added Cluster tests
callmehiphop 87de5e9
added GrpcOperation tests
callmehiphop c7e41b9
linting all the things
callmehiphop 363d4d4
updated proto files
callmehiphop 1b9e002
fixed documentation typos
callmehiphop 0973ca9
updated several assertions
callmehiphop 17e5362
created getLocation method for clusters
callmehiphop c5a58cc
adding tests for new/updated methods
callmehiphop 3516c59
fix lint issue
callmehiphop fc47d5d
additional unit tests
callmehiphop 502c2e8
small documentation changes
callmehiphop f34b47c
lint round 2
callmehiphop 51c8d3e
update mutations to not re-encode buffers
callmehiphop 4f63a08
add encode/decode options
callmehiphop 878e1a2
fix linting errors
callmehiphop e0bbc4d
reverted jscs rules
callmehiphop fc1e9fb
bumping common version
callmehiphop a0e461a
removed encode option
callmehiphop 718b7d2
refactored Table#mutate to only return failed statuses
callmehiphop 952dcdc
mutate tweaks + doc updates
callmehiphop 4125d3f
updated mutate to return an event emitter
callmehiphop 9fcba7d
renamed entries param to mutationErrors
callmehiphop 36458f4
updated emitter docs + changed finish event to complete
callmehiphop fc34f2f
updating system-tests
callmehiphop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
|
|
||
| /** | ||
| * 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; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.