-
Notifications
You must be signed in to change notification settings - Fork 616
compute: implement HealthChecks #1276
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
callmehiphop
merged 6 commits into
googleapis:master
from
stephenplusplus:spp--1073-health-checks
May 3, 2016
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
daf42b7
compute: implement HealthChecks
stephenplusplus ffd2de0
add to toc.json
stephenplusplus 4e2b035
healthCheck -> health-check
stephenplusplus 2588dfd
hyphenate camelcase module names
stephenplusplus 06f0ce9
finish renaming camelcase modules
stephenplusplus a2b3b21
fix createHealthCheck type
stephenplusplus 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
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,244 @@ | ||
/*! | ||
* 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 compute/healthCheck | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var extend = require('extend'); | ||
var is = require('is'); | ||
var nodeutil = require('util'); | ||
|
||
/** | ||
* @type {module:common/serviceObject} | ||
* @private | ||
*/ | ||
var ServiceObject = require('../common/service-object.js'); | ||
|
||
/** | ||
* @type {module:common/util} | ||
* @private | ||
*/ | ||
var util = require('../common/util.js'); | ||
|
||
/*! Developer Documentation | ||
* | ||
* @param {module:compute} compute - Compute object this health check belongs | ||
* to. | ||
* @param {string} name - Name of the health check. | ||
* @param {object=} options - Optional configuration. | ||
* @param {boolean} options.https - Specify if this is an HTTPS health check | ||
* resource. Default: `false` | ||
*/ | ||
/** | ||
* Health checks ensure that Compute Engine forwards new connections only to | ||
* instances that are up and ready to receive them. Compute Engine sends health | ||
* check requests to each instance at the specified frequency; once an instance | ||
* exceeds its allowed number of health check failures, it is no longer | ||
* considered an eligible instance for receiving new traffic. | ||
* | ||
* @resource [Health Checks Overview]{@link https://cloud.google.com/compute/docs/load-balancing/health-checks} | ||
* | ||
* @constructor | ||
* @alias module:compute/healthCheck | ||
* | ||
* @example | ||
* var gcloud = require('gcloud')({ | ||
* keyFilename: '/path/to/keyfile.json', | ||
* projectId: 'grape-spaceship-123' | ||
* }); | ||
* | ||
* var gce = gcloud.compute(); | ||
* | ||
* var healthCheck = gce.healthCheck('health-check-name'); | ||
*/ | ||
function HealthCheck(compute, name, options) { | ||
var methods = { | ||
/** | ||
* Create an HTTP or HTTPS health check. | ||
* | ||
* @param {object} options - See {module:compute#createHealthCheck}. | ||
* | ||
* @example | ||
* healthCheck.create(function(err, healthCheck, operation, apiResponse) { | ||
* // `healthCheck` is a HealthCheck object. | ||
* | ||
* // `operation` is an Operation object that can be used to check the | ||
* // status of the request. | ||
* }); | ||
*/ | ||
create: true, | ||
|
||
/** | ||
* Check if the health check exists. | ||
* | ||
* @param {function} callback - The callback function. | ||
* @param {?error} callback.err - An error returned while making this | ||
* request. | ||
* @param {boolean} callback.exists - Whether the health check exists or | ||
* not. | ||
* | ||
* @example | ||
* healthCheck.exists(function(err, exists) {}); | ||
*/ | ||
exists: true, | ||
|
||
/** | ||
* Get the health check if it exists. | ||
* | ||
* You may optionally use this to "get or create" an object by providing an | ||
* object with `autoCreate` set to `true`. Any extra configuration that is | ||
* normally required for the `create` method must be contained within this | ||
* object as well. | ||
* | ||
* @param {options=} options - Configuration object. | ||
* @param {boolean} options.autoCreate - Automatically create the object if | ||
* it does not exist. Default: `false` | ||
* | ||
* @example | ||
* healthCheck.get(function(err, healthCheck, apiResponse) { | ||
* // `healthCheck` is a HealthCheck object. | ||
* }); | ||
*/ | ||
get: true, | ||
|
||
/** | ||
* Get the health check's metadata. | ||
* | ||
* @resource [HttpHealthChecks: get API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/httpHealthChecks/get} | ||
* @resource [HttpHealthCheck resource](https://cloud.google.com/compute/docs/reference/v1/httpHealthChecks#resource) | ||
* @resource [HttpsHealthChecks: get API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/httpsHealthChecks/get} | ||
* @resource [HttpsHealthCheck resource](https://cloud.google.com/compute/docs/reference/v1/httpsHealthChecks#resource) | ||
* | ||
* @param {function=} callback - The callback function. | ||
* @param {?error} callback.err - An error returned while making this | ||
* request. | ||
* @param {object} callback.metadata - The health check's metadata. | ||
* @param {object} callback.apiResponse - The full API response. | ||
* | ||
* @example | ||
* healthCheck.getMetadata(function(err, metadata, apiResponse) {}); | ||
*/ | ||
getMetadata: true | ||
}; | ||
|
||
options = options || {}; | ||
|
||
var https = options.https; | ||
this.compute = compute; | ||
|
||
ServiceObject.call(this, { | ||
parent: compute, | ||
baseUrl: '/global/' + (https ? 'httpsHealthChecks' : 'httpHealthChecks'), | ||
id: name, | ||
createMethod: function(name, options, callback) { | ||
if (is.fn(options)) { | ||
callback = options; | ||
options = {}; | ||
} | ||
|
||
options = extend({}, options, { https: https }); | ||
|
||
compute.createHealthCheck(name, options, callback); | ||
}, | ||
methods: methods | ||
}); | ||
} | ||
|
||
nodeutil.inherits(HealthCheck, ServiceObject); | ||
|
||
/** | ||
* Delete the health check. | ||
* | ||
* @resource [HttpHealthCheck: delete API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/httpHealthChecks/delete} | ||
* @resource [HttpsHealthCheck: delete API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/httpsHealthChecks/delete} | ||
* | ||
* @param {function=} callback - The callback function. | ||
* @param {?error} callback.err - An error returned while making this request. | ||
* @param {module:compute/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 | ||
* healthCheck.delete(function(err, operation, apiResponse) { | ||
* // `operation` is an Operation object that can be used to check the status | ||
* // of the request. | ||
* }); | ||
*/ | ||
HealthCheck.prototype.delete = function(callback) { | ||
var compute = this.compute; | ||
|
||
callback = callback || util.noop; | ||
|
||
ServiceObject.prototype.delete.call(this, function(err, resp) { | ||
if (err) { | ||
callback(err, null, resp); | ||
return; | ||
} | ||
|
||
var operation = compute.operation(resp.name); | ||
operation.metadata = resp; | ||
|
||
callback(null, operation, resp); | ||
}); | ||
}; | ||
|
||
/** | ||
* Set the health check's metadata. | ||
* | ||
* @resource [HttpHealthCheck: insert API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/httpHealthChecks/insert} | ||
* @resource [HttpsHealthCheck: insert API Documentation]{@link https://cloud.google.com/compute/docs/reference/v1/httpsHealthChecks/insert} | ||
* | ||
* @param {object} metadata - See a | ||
* [HttpHealthCheck resource](https://cloud.google.com/compute/docs/reference/v1/httpHealthChecks#resource) | ||
* and [HttpsHealthCheck resource](https://cloud.google.com/compute/docs/reference/v1/httpsHealthChecks#resource). | ||
* @param {function=} callback - The callback function. | ||
* @param {?error} callback.err - An error returned while making this request. | ||
* @param {module:compute/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 metadata = { | ||
* description: 'New description' | ||
* }; | ||
* | ||
* healthCheck.setMetadata(metadata, function(err, operation, apiResponse) { | ||
* // `operation` is an Operation object that can be used to check the status | ||
* // of the request. | ||
* }); | ||
*/ | ||
HealthCheck.prototype.setMetadata = function(metadata, callback) { | ||
var compute = this.compute; | ||
|
||
callback = callback || util.noop; | ||
|
||
ServiceObject.prototype.setMetadata.call(this, metadata, function(err, resp) { | ||
if (err) { | ||
callback(err, null, resp); | ||
return; | ||
} | ||
|
||
var operation = compute.operation(resp.name); | ||
operation.metadata = resp; | ||
|
||
callback(null, operation, resp); | ||
}); | ||
}; | ||
|
||
module.exports = HealthCheck; |
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.