diff --git a/packages/logging/package.json b/packages/logging/package.json index fa79d494776..c8c09a8d4f7 100644 --- a/packages/logging/package.json +++ b/packages/logging/package.json @@ -55,7 +55,7 @@ "@google-cloud/common": "^0.8.0", "arrify": "^1.0.0", "extend": "^3.0.0", - "google-gax": "^0.9.1", + "google-gax": "^0.10.0", "google-proto-files": "^0.8.0", "is": "^3.0.1", "is-circular": "^1.0.1", diff --git a/packages/logging/src/v2/config_service_v2_api.js b/packages/logging/src/v2/config_service_v2_client.js similarity index 57% rename from packages/logging/src/v2/config_service_v2_api.js rename to packages/logging/src/v2/config_service_v2_client.js index 03391cc3681..ff9b0c1c7e9 100644 --- a/packages/logging/src/v2/config_service_v2_api.js +++ b/packages/logging/src/v2/config_service_v2_client.js @@ -37,7 +37,6 @@ var DEFAULT_SERVICE_PORT = 443; var CODE_GEN_NAME_VERSION = 'gapic/0.1.0'; - var PAGE_DESCRIPTORS = { listSinks: new gax.PageDescriptor( 'pageToken', @@ -58,22 +57,22 @@ var ALL_SCOPES = [ ]; /** - * Service for configuring sinks used to export log entries outside Stackdriver - * Logging. + * Service for configuring sinks used to export log entries outside of + * Stackdriver Logging. * * This will be created through a builder function which can be obtained by the module. * See the following example of how to initialize the module and how to access to the builder. - * @see {@link configServiceV2Api} + * @see {@link configServiceV2Client} * * @example * var loggingV2 = require('@google-cloud/logging').v2({ * // optional auth parameters. * }); - * var api = loggingV2.configServiceV2Api(); + * var client = loggingV2.configServiceV2Client(); * * @class */ -function ConfigServiceV2Api(gaxGrpc, grpcClients, opts) { +function ConfigServiceV2Client(gaxGrpc, grpcClients, opts) { opts = opts || {}; var servicePath = opts.servicePath || SERVICE_ADDRESS; var port = opts.port || DEFAULT_SERVICE_PORT; @@ -92,8 +91,6 @@ function ConfigServiceV2Api(gaxGrpc, grpcClients, opts) { 'google.logging.v2.ConfigServiceV2', configData, clientConfig, - PAGE_DESCRIPTORS, - null, {'x-goog-api-client': googleApiClient}); var configServiceV2Stub = gaxGrpc.createStub( @@ -113,7 +110,8 @@ function ConfigServiceV2Api(gaxGrpc, grpcClients, opts) { configServiceV2Stub.then(function(configServiceV2Stub) { return configServiceV2Stub[methodName].bind(configServiceV2Stub); }), - defaults[methodName]); + defaults[methodName], + PAGE_DESCRIPTORS[methodName]); }.bind(this)); } @@ -130,7 +128,7 @@ var SINK_PATH_TEMPLATE = new gax.PathTemplate( * @param {String} project * @returns {String} */ -ConfigServiceV2Api.prototype.parentPath = function(project) { +ConfigServiceV2Client.prototype.parentPath = function(project) { return PARENT_PATH_TEMPLATE.render({ project: project }); @@ -142,7 +140,7 @@ ConfigServiceV2Api.prototype.parentPath = function(project) { * A fully-qualified path representing a parent resources. * @returns {String} - A string representing the project. */ -ConfigServiceV2Api.prototype.matchProjectFromParentName = function(parentName) { +ConfigServiceV2Client.prototype.matchProjectFromParentName = function(parentName) { return PARENT_PATH_TEMPLATE.match(parentName).project; }; @@ -152,7 +150,7 @@ ConfigServiceV2Api.prototype.matchProjectFromParentName = function(parentName) { * @param {String} sink * @returns {String} */ -ConfigServiceV2Api.prototype.sinkPath = function(project, sink) { +ConfigServiceV2Client.prototype.sinkPath = function(project, sink) { return SINK_PATH_TEMPLATE.render({ project: project, sink: sink @@ -165,7 +163,7 @@ ConfigServiceV2Api.prototype.sinkPath = function(project, sink) { * A fully-qualified path representing a sink resources. * @returns {String} - A string representing the project. */ -ConfigServiceV2Api.prototype.matchProjectFromSinkName = function(sinkName) { +ConfigServiceV2Client.prototype.matchProjectFromSinkName = function(sinkName) { return SINK_PATH_TEMPLATE.match(sinkName).project; }; @@ -175,7 +173,7 @@ ConfigServiceV2Api.prototype.matchProjectFromSinkName = function(sinkName) { * A fully-qualified path representing a sink resources. * @returns {String} - A string representing the sink. */ -ConfigServiceV2Api.prototype.matchSinkFromSinkName = function(sinkName) { +ConfigServiceV2Client.prototype.matchSinkFromSinkName = function(sinkName) { return SINK_PATH_TEMPLATE.match(sinkName).sink; }; @@ -187,8 +185,10 @@ ConfigServiceV2Api.prototype.matchSinkFromSinkName = function(sinkName) { * @param {Object} request * The request object that will be sent. * @param {string} request.parent - * Required. The cloud resource containing the sinks. - * Example: `"projects/my-logging-project"`. + * Required. The resource name where this sink was created: + * + * "projects/[PROJECT_ID]" + * "organizations/[ORGANIZATION_ID]" * @param {number=} request.pageSize * The maximum number of resources contained in the underlying API * response. If page streaming is performed per-resource, this @@ -198,42 +198,64 @@ ConfigServiceV2Api.prototype.matchSinkFromSinkName = function(sinkName) { * @param {Object=} options * Optional parameters. You can override the default settings for this call, e.g, timeout, * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object, ?string)=} callback - * When specified, the results are not streamed but this callback - * will be called with the response object representing [ListSinksResponse]{@link ListSinksResponse}. - * The third item will be set if the response contains the token for the further results - * and can be reused to `pageToken` field in the options in the next request. - * @returns {Stream|Promise} - * An object stream which emits an object representing - * [LogSink]{@link LogSink} on 'data' event. - * When the callback is specified or streaming is suppressed through options, - * it will return a promise that resolves to the response object. The promise - * has a method named "cancel" which cancels the ongoing API call. + * @param {function(?Error, ?Array, ?Object, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is Array of [LogSink]{@link LogSink}. + * + * When autoPaginate: false is specified through options, it contains the result + * in a single response. If the response indicates the next page exists, the third + * parameter is set to be used for the next request object. The fourth parameter keeps + * the raw response object of an object representing [ListSinksResponse]{@link ListSinksResponse}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is Array of [LogSink]{@link LogSink}. + * + * When autoPaginate: false is specified through options, the array has three elements. + * The first element is Array of [LogSink]{@link LogSink} in a single response. + * The second element is the next request object if the response + * indicates the next page exists, or null. The third element is + * an object representing [ListSinksResponse]{@link ListSinksResponse}. + * + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * - * var api = loggingV2.configServiceV2Api(); - * var formattedParent = api.parentPath("[PROJECT]"); + * var client = loggingV2.configServiceV2Client(); + * var formattedParent = client.parentPath("[PROJECT]"); * // Iterate over all elements. - * api.listSinks({parent: formattedParent}).on('data', function(element) { - * // doThingsWith(element) + * client.listSinks({parent: formattedParent}).then(function(responses) { + * var resources = responses[0]; + * for (var i = 0; i < resources.length; ++i) { + * // doThingsWith(resources[i]) + * } + * }).catch(function(err) { + * console.error(err); * }); * - * // Or obtain the paged response through the callback. - * function callback(err, response, nextPageToken) { - * if (err) { - * console.error(err); - * return; + * // Or obtain the paged response. + * var options = {autoPaginate: false}; + * function callback(responses) { + * // The actual resources in a response. + * var resources = responses[0]; + * // The next request if the response shows there's more responses. + * var nextRequest = responses[1]; + * // The actual response object, if necessary. + * // var rawResponse = responses[2]; + * for (var i = 0; i < resources.length; ++i) { + * // doThingsWith(resources[i]); * } - * // doThingsWith(response) - * if (nextPageToken) { - * // fetch the next page. - * api.listSinks({parent: formattedParent}, {pageToken: nextPageToken}, callback); + * if (nextRequest) { + * // Fetch the next page. + * return client.listSinks(nextRequest, options).then(callback); * } * } - * api.listSinks({parent: formattedParent}, {flattenPages: false}, callback); + * client.listSinks({parent: formattedParent}, options) + * .then(callback) + * .catch(function(err) { + * console.error(err); + * }); */ -ConfigServiceV2Api.prototype.listSinks = function(request, options, callback) { +ConfigServiceV2Client.prototype.listSinks = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -241,38 +263,93 @@ ConfigServiceV2Api.prototype.listSinks = function(request, options, callback) { if (options === undefined) { options = {}; } + return this._listSinks(request, options, callback); }; +/** + * Equivalent to {@link listSinks}, but returns a NodeJS Stream object. + * + * This fetches the paged responses for {@link listSinks} continuously + * and invokes the callback registered for 'data' event for each element in the + * responses. + * + * The returned object has 'end' method when no more elements are required. + * + * autoPaginate option will be ignored. + * + * @see {@link https://nodejs.org/api/stream.html} + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The resource name where this sink was created: + * + * "projects/[PROJECT_ID]" + * "organizations/[ORGANIZATION_ID]" + * @param {number=} request.pageSize + * The maximum number of resources contained in the underlying API + * response. If page streaming is performed per-resource, this + * parameter does not affect the return value. If page streaming is + * performed per-page, this determines the maximum number of + * resources in a page. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @return {Stream} + * An object stream which emits an object representing [LogSink]{@link LogSink} on 'data' event. + * + * @example + * + * var client = loggingV2.configServiceV2Client(); + * var formattedParent = client.parentPath("[PROJECT]"); + * client.listSinksStream({parent: formattedParent}).on('data', function(element) { + * // doThingsWith(element) + * }).on('error', funciton(err) { + * console.error(err); + * }); + */ +ConfigServiceV2Client.prototype.listSinksStream = function(request, options) { + if (options === undefined) { + options = {}; + } + + return PAGE_DESCRIPTORS.listSinks.createStream(this._listSinks, request, options); +}; + /** * Gets a sink. * * @param {Object} request * The request object that will be sent. * @param {string} request.sinkName - * Required. The resource name of the sink to return. - * Example: `"projects/my-project-id/sinks/my-sink-id"`. + * Required. The resource name of the sink to return: + * + * "projects/[PROJECT_ID]/sinks/[SINK_ID]" + * "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" * @param {Object=} options * Optional parameters. You can override the default settings for this call, e.g, timeout, * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * - * The second parameter to the callback is an object representing [LogSink]{@link LogSink} - * @returns {Promise} - The promise which resolves to the response object. + * The second parameter to the callback is an object representing [LogSink]{@link LogSink}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [LogSink]{@link LogSink}. * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * - * var api = loggingV2.configServiceV2Api(); - * var formattedSinkName = api.sinkPath("[PROJECT]", "[SINK]"); - * api.getSink({sinkName: formattedSinkName}).then(function(response) { + * var client = loggingV2.configServiceV2Client(); + * var formattedSinkName = client.sinkPath("[PROJECT]", "[SINK]"); + * client.getSink({sinkName: formattedSinkName}).then(function(responses) { + * var response = responses[0]; * // doThingsWith(response) * }).catch(function(err) { * console.error(err); * }); */ -ConfigServiceV2Api.prototype.getSink = function(request, options, callback) { +ConfigServiceV2Client.prototype.getSink = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -280,6 +357,7 @@ ConfigServiceV2Api.prototype.getSink = function(request, options, callback) { if (options === undefined) { options = {}; } + return this._getSink(request, options, callback); }; @@ -289,40 +367,49 @@ ConfigServiceV2Api.prototype.getSink = function(request, options, callback) { * @param {Object} request * The request object that will be sent. * @param {string} request.parent - * Required. The resource in which to create the sink. - * Example: `"projects/my-project-id"`. - * The new sink must be provided in the request. + * Required. The resource in which to create the sink: + * + * "projects/[PROJECT_ID]" + * "organizations/[ORGANIZATION_ID]" * @param {Object} request.sink * Required. The new sink, whose `name` parameter is a sink identifier that * is not already in use. * * This object should have the same structure as [LogSink]{@link LogSink} + * @param {boolean=} request.uniqueWriterIdentity + * Optional. Whether the sink will have a dedicated service account returned + * in the sink's writer_identity. Set this field to be true to export + * logs from one project to a different project. This field is ignored for + * non-project sinks (e.g. organization sinks) because those sinks are + * required to have dedicated service accounts. * @param {Object=} options * Optional parameters. You can override the default settings for this call, e.g, timeout, * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * - * The second parameter to the callback is an object representing [LogSink]{@link LogSink} - * @returns {Promise} - The promise which resolves to the response object. + * The second parameter to the callback is an object representing [LogSink]{@link LogSink}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [LogSink]{@link LogSink}. * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * - * var api = loggingV2.configServiceV2Api(); - * var formattedParent = api.parentPath("[PROJECT]"); + * var client = loggingV2.configServiceV2Client(); + * var formattedParent = client.parentPath("[PROJECT]"); * var sink = {}; * var request = { * parent: formattedParent, * sink: sink * }; - * api.createSink(request).then(function(response) { + * client.createSink(request).then(function(responses) { + * var response = responses[0]; * // doThingsWith(response) * }).catch(function(err) { * console.error(err); * }); */ -ConfigServiceV2Api.prototype.createSink = function(request, options, callback) { +ConfigServiceV2Client.prototype.createSink = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -330,6 +417,7 @@ ConfigServiceV2Api.prototype.createSink = function(request, options, callback) { if (options === undefined) { options = {}; } + return this._createSink(request, options, callback); }; @@ -340,40 +428,52 @@ ConfigServiceV2Api.prototype.createSink = function(request, options, callback) { * The request object that will be sent. * @param {string} request.sinkName * Required. The resource name of the sink to update, including the parent - * resource and the sink identifier. If the sink does not exist, this method - * creates the sink. Example: `"projects/my-project-id/sinks/my-sink-id"`. + * resource and the sink identifier: + * + * "projects/[PROJECT_ID]/sinks/[SINK_ID]" + * "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" + * + * Example: `"projects/my-project-id/sinks/my-sink-id"`. * @param {Object} request.sink * Required. The updated sink, whose name is the same identifier that appears * as part of `sinkName`. If `sinkName` does not exist, then * this method creates a new sink. * * This object should have the same structure as [LogSink]{@link LogSink} + * @param {boolean=} request.uniqueWriterIdentity + * Optional. Whether the sink will have a dedicated service account returned + * in the sink's writer_identity. Set this field to be true to export + * logs from one project to a different project. This field is ignored for + * non-project sinks (e.g. organization sinks) because those sinks are + * required to have dedicated service accounts. * @param {Object=} options * Optional parameters. You can override the default settings for this call, e.g, timeout, * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * - * The second parameter to the callback is an object representing [LogSink]{@link LogSink} - * @returns {Promise} - The promise which resolves to the response object. + * The second parameter to the callback is an object representing [LogSink]{@link LogSink}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [LogSink]{@link LogSink}. * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * - * var api = loggingV2.configServiceV2Api(); - * var formattedSinkName = api.sinkPath("[PROJECT]", "[SINK]"); + * var client = loggingV2.configServiceV2Client(); + * var formattedSinkName = client.sinkPath("[PROJECT]", "[SINK]"); * var sink = {}; * var request = { * sinkName: formattedSinkName, * sink: sink * }; - * api.updateSink(request).then(function(response) { + * client.updateSink(request).then(function(responses) { + * var response = responses[0]; * // doThingsWith(response) * }).catch(function(err) { * console.error(err); * }); */ -ConfigServiceV2Api.prototype.updateSink = function(request, options, callback) { +ConfigServiceV2Client.prototype.updateSink = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -381,6 +481,7 @@ ConfigServiceV2Api.prototype.updateSink = function(request, options, callback) { if (options === undefined) { options = {}; } + return this._updateSink(request, options, callback); }; @@ -391,26 +492,29 @@ ConfigServiceV2Api.prototype.updateSink = function(request, options, callback) { * The request object that will be sent. * @param {string} request.sinkName * Required. The resource name of the sink to delete, including the parent - * resource and the sink identifier. Example: - * `"projects/my-project-id/sinks/my-sink-id"`. It is an error if the sink - * does not exist. + * resource and the sink identifier: + * + * "projects/[PROJECT_ID]/sinks/[SINK_ID]" + * "organizations/[ORGANIZATION_ID]/sinks/[SINK_ID]" + * + * It is an error if the sink does not exist. * @param {Object=} options * Optional parameters. You can override the default settings for this call, e.g, timeout, * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error)=} callback * The function which will be called with the result of the API call. - * @returns {Promise} - The promise which resolves to the response object. + * @return {Promise} - The promise which resolves when API call finishes. * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * - * var api = loggingV2.configServiceV2Api(); - * var formattedSinkName = api.sinkPath("[PROJECT]", "[SINK]"); - * api.deleteSink({sinkName: formattedSinkName}).catch(function(err) { + * var client = loggingV2.configServiceV2Client(); + * var formattedSinkName = client.sinkPath("[PROJECT]", "[SINK]"); + * client.deleteSink({sinkName: formattedSinkName}).catch(function(err) { * console.error(err); * }); */ -ConfigServiceV2Api.prototype.deleteSink = function(request, options, callback) { +ConfigServiceV2Client.prototype.deleteSink = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -418,12 +522,13 @@ ConfigServiceV2Api.prototype.deleteSink = function(request, options, callback) { if (options === undefined) { options = {}; } + return this._deleteSink(request, options, callback); }; -function ConfigServiceV2ApiBuilder(gaxGrpc) { - if (!(this instanceof ConfigServiceV2ApiBuilder)) { - return new ConfigServiceV2ApiBuilder(gaxGrpc); +function ConfigServiceV2ClientBuilder(gaxGrpc) { + if (!(this instanceof ConfigServiceV2ClientBuilder)) { + return new ConfigServiceV2ClientBuilder(gaxGrpc); } var configServiceV2Client = gaxGrpc.load([{ @@ -437,7 +542,7 @@ function ConfigServiceV2ApiBuilder(gaxGrpc) { }; /** - * Build a new instance of {@link ConfigServiceV2Api}. + * Build a new instance of {@link ConfigServiceV2Client}. * * @param {Object=} opts - The optional parameters. * @param {String=} opts.servicePath @@ -454,11 +559,11 @@ function ConfigServiceV2ApiBuilder(gaxGrpc) { * @param {String=} opts.appVersion * The version of the calling service. */ - this.configServiceV2Api = function(opts) { - return new ConfigServiceV2Api(gaxGrpc, grpcClients, opts); + this.configServiceV2Client = function(opts) { + return new ConfigServiceV2Client(gaxGrpc, grpcClients, opts); }; - extend(this.configServiceV2Api, ConfigServiceV2Api); + extend(this.configServiceV2Client, ConfigServiceV2Client); } -module.exports = ConfigServiceV2ApiBuilder; +module.exports = ConfigServiceV2ClientBuilder; module.exports.SERVICE_ADDRESS = SERVICE_ADDRESS; module.exports.ALL_SCOPES = ALL_SCOPES; \ No newline at end of file diff --git a/packages/logging/src/v2/index.js b/packages/logging/src/v2/index.js index 309e3183971..115c482b02e 100644 --- a/packages/logging/src/v2/index.js +++ b/packages/logging/src/v2/index.js @@ -15,9 +15,9 @@ */ 'use strict'; -var configServiceV2Api = require('./config_service_v2_api'); -var loggingServiceV2Api = require('./logging_service_v2_api'); -var metricsServiceV2Api = require('./metrics_service_v2_api'); +var configServiceV2Client = require('./config_service_v2_client'); +var loggingServiceV2Client = require('./logging_service_v2_client'); +var metricsServiceV2Client = require('./metrics_service_v2_client'); var extend = require('extend'); var gax = require('google-gax'); @@ -27,12 +27,12 @@ function v2(options) { }, options); var gaxGrpc = gax.grpc(options); var result = {}; - extend(result, configServiceV2Api(gaxGrpc)); - extend(result, loggingServiceV2Api(gaxGrpc)); - extend(result, metricsServiceV2Api(gaxGrpc)); + extend(result, configServiceV2Client(gaxGrpc)); + extend(result, loggingServiceV2Client(gaxGrpc)); + extend(result, metricsServiceV2Client(gaxGrpc)); return result; } -v2.SERVICE_ADDRESS = loggingServiceV2Api.SERVICE_ADDRESS; -v2.ALL_SCOPES = loggingServiceV2Api.ALL_SCOPES; +v2.SERVICE_ADDRESS = loggingServiceV2Client.SERVICE_ADDRESS; +v2.ALL_SCOPES = loggingServiceV2Client.ALL_SCOPES; module.exports = v2; diff --git a/packages/logging/src/v2/logging_service_v2_api.js b/packages/logging/src/v2/logging_service_v2_client.js similarity index 50% rename from packages/logging/src/v2/logging_service_v2_api.js rename to packages/logging/src/v2/logging_service_v2_client.js index 9f98cdcbcd5..43988f94f0e 100644 --- a/packages/logging/src/v2/logging_service_v2_api.js +++ b/packages/logging/src/v2/logging_service_v2_client.js @@ -37,7 +37,6 @@ var DEFAULT_SERVICE_PORT = 443; var CODE_GEN_NAME_VERSION = 'gapic/0.1.0'; - var PAGE_DESCRIPTORS = { listLogEntries: new gax.PageDescriptor( 'pageToken', @@ -66,17 +65,17 @@ var ALL_SCOPES = [ * * This will be created through a builder function which can be obtained by the module. * See the following example of how to initialize the module and how to access to the builder. - * @see {@link loggingServiceV2Api} + * @see {@link loggingServiceV2Client} * * @example * var loggingV2 = require('@google-cloud/logging').v2({ * // optional auth parameters. * }); - * var api = loggingV2.loggingServiceV2Api(); + * var client = loggingV2.loggingServiceV2Client(); * * @class */ -function LoggingServiceV2Api(gaxGrpc, grpcClients, opts) { +function LoggingServiceV2Client(gaxGrpc, grpcClients, opts) { opts = opts || {}; var servicePath = opts.servicePath || SERVICE_ADDRESS; var port = opts.port || DEFAULT_SERVICE_PORT; @@ -95,8 +94,6 @@ function LoggingServiceV2Api(gaxGrpc, grpcClients, opts) { 'google.logging.v2.LoggingServiceV2', configData, clientConfig, - PAGE_DESCRIPTORS, - null, {'x-goog-api-client': googleApiClient}); var loggingServiceV2Stub = gaxGrpc.createStub( @@ -115,7 +112,8 @@ function LoggingServiceV2Api(gaxGrpc, grpcClients, opts) { loggingServiceV2Stub.then(function(loggingServiceV2Stub) { return loggingServiceV2Stub[methodName].bind(loggingServiceV2Stub); }), - defaults[methodName]); + defaults[methodName], + PAGE_DESCRIPTORS[methodName]); }.bind(this)); } @@ -132,7 +130,7 @@ var LOG_PATH_TEMPLATE = new gax.PathTemplate( * @param {String} project * @returns {String} */ -LoggingServiceV2Api.prototype.parentPath = function(project) { +LoggingServiceV2Client.prototype.parentPath = function(project) { return PARENT_PATH_TEMPLATE.render({ project: project }); @@ -144,7 +142,7 @@ LoggingServiceV2Api.prototype.parentPath = function(project) { * A fully-qualified path representing a parent resources. * @returns {String} - A string representing the project. */ -LoggingServiceV2Api.prototype.matchProjectFromParentName = function(parentName) { +LoggingServiceV2Client.prototype.matchProjectFromParentName = function(parentName) { return PARENT_PATH_TEMPLATE.match(parentName).project; }; @@ -154,7 +152,7 @@ LoggingServiceV2Api.prototype.matchProjectFromParentName = function(parentName) * @param {String} log * @returns {String} */ -LoggingServiceV2Api.prototype.logPath = function(project, log) { +LoggingServiceV2Client.prototype.logPath = function(project, log) { return LOG_PATH_TEMPLATE.render({ project: project, log: log @@ -167,7 +165,7 @@ LoggingServiceV2Api.prototype.logPath = function(project, log) { * A fully-qualified path representing a log resources. * @returns {String} - A string representing the project. */ -LoggingServiceV2Api.prototype.matchProjectFromLogName = function(logName) { +LoggingServiceV2Client.prototype.matchProjectFromLogName = function(logName) { return LOG_PATH_TEMPLATE.match(logName).project; }; @@ -177,38 +175,46 @@ LoggingServiceV2Api.prototype.matchProjectFromLogName = function(logName) { * A fully-qualified path representing a log resources. * @returns {String} - A string representing the log. */ -LoggingServiceV2Api.prototype.matchLogFromLogName = function(logName) { +LoggingServiceV2Client.prototype.matchLogFromLogName = function(logName) { return LOG_PATH_TEMPLATE.match(logName).log; }; // Service calls /** - * Deletes a log and all its log entries. - * The log will reappear if it receives new entries. + * Deletes all the log entries in a log. + * The log reappears if it receives new entries. * * @param {Object} request * The request object that will be sent. * @param {string} request.logName - * Required. The resource name of the log to delete. Example: - * `"projects/my-project/logs/syslog"`. + * Required. The resource name of the log to delete: + * + * "projects/[PROJECT_ID]/logs/[LOG_ID]" + * "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]" + * + * `[LOG_ID]` must be URL-encoded. For example, + * `"projects/my-project-id/logs/syslog"`, + * `"organizations/1234567890/logs/cloudresourcemanager.googleapis.com%2Factivity"`. + * For more information about log names, see + * {@link LogEntry}. * @param {Object=} options * Optional parameters. You can override the default settings for this call, e.g, timeout, * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error)=} callback * The function which will be called with the result of the API call. - * @returns {Promise} - The promise which resolves to the response object. + * @return {Promise} - The promise which resolves when API call finishes. * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * - * var api = loggingV2.loggingServiceV2Api(); - * var formattedLogName = api.logPath("[PROJECT]", "[LOG]"); - * api.deleteLog({logName: formattedLogName}).catch(function(err) { + * var client = loggingV2.loggingServiceV2Client(); + * var formattedLogName = client.logPath("[PROJECT]", "[LOG]"); + * client.deleteLog({logName: formattedLogName}).catch(function(err) { * console.error(err); * }); */ -LoggingServiceV2Api.prototype.deleteLog = function(request, options, callback) { +LoggingServiceV2Client.prototype.deleteLog = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -216,6 +222,7 @@ LoggingServiceV2Api.prototype.deleteLog = function(request, options, callback) { if (options === undefined) { options = {}; } + return this._deleteLog(request, options, callback); }; @@ -239,8 +246,15 @@ LoggingServiceV2Api.prototype.deleteLog = function(request, options, callback) { * This object should have the same structure as [LogEntry]{@link LogEntry} * @param {string=} request.logName * Optional. A default log resource name that is assigned to all log entries - * in `entries` that do not specify a value for `log_name`. Example: - * `"projects/my-project/logs/syslog"`. See + * in `entries` that do not specify a value for `log_name`: + * + * "projects/[PROJECT_ID]/logs/[LOG_ID]" + * "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]" + * + * `[LOG_ID]` must be URL-encoded. For example, + * `"projects/my-project-id/logs/syslog"` or + * `"organizations/1234567890/logs/cloudresourcemanager.googleapis.com%2Factivity"`. + * For more information about log names, see * {@link LogEntry}. * @param {Object=} request.resource * Optional. A default monitored resource object that is assigned to all log @@ -270,21 +284,23 @@ LoggingServiceV2Api.prototype.deleteLog = function(request, options, callback) { * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * - * The second parameter to the callback is an object representing [WriteLogEntriesResponse]{@link WriteLogEntriesResponse} - * @returns {Promise} - The promise which resolves to the response object. + * The second parameter to the callback is an object representing [WriteLogEntriesResponse]{@link WriteLogEntriesResponse}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [WriteLogEntriesResponse]{@link WriteLogEntriesResponse}. * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * - * var api = loggingV2.loggingServiceV2Api(); + * var client = loggingV2.loggingServiceV2Client(); * var entries = []; - * api.writeLogEntries({entries: entries}).then(function(response) { + * client.writeLogEntries({entries: entries}).then(function(responses) { + * var response = responses[0]; * // doThingsWith(response) * }).catch(function(err) { * console.error(err); * }); */ -LoggingServiceV2Api.prototype.writeLogEntries = function(request, options, callback) { +LoggingServiceV2Client.prototype.writeLogEntries = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -292,6 +308,7 @@ LoggingServiceV2Api.prototype.writeLogEntries = function(request, options, callb if (options === undefined) { options = {}; } + return this._writeLogEntries(request, options, callback); }; @@ -302,20 +319,25 @@ LoggingServiceV2Api.prototype.writeLogEntries = function(request, options, callb * * @param {Object} request * The request object that will be sent. - * @param {string[]} request.projectIds + * @param {string[]} request.resourceNames + * Required. One or more cloud resources from which to retrieve log + * entries: + * + * "projects/[PROJECT_ID]" + * "organizations/[ORGANIZATION_ID]" + * + * Projects listed in the `project_ids` field are added to this list. + * @param {string[]=} request.projectIds * Deprecated. One or more project identifiers or project numbers from which - * to retrieve log entries. Examples: `"my-project-1A"`, `"1234567890"`. If + * to retrieve log entries. Example: `"my-project-1A"`. If * present, these project identifiers are converted to resource format and * added to the list of resources in `resourceNames`. Callers should use * `resourceNames` rather than this parameter. - * @param {string[]=} request.resourceNames - * Optional. One or more cloud resources from which to retrieve log entries. - * Example: `"projects/my-project-1A"`, `"projects/1234567890"`. Projects - * listed in `projectIds` are added to this list. * @param {string=} request.filter * Optional. A filter that chooses which log entries to return. See [Advanced * Logs Filters](https://cloud.google.com/logging/docs/view/advanced_filters). Only log entries that * match the filter are returned. An empty filter matches all log entries. + * The maximum length of the filter is 20000 characters. * @param {string=} request.orderBy * Optional. How the results should be sorted. Presently, the only permitted * values are `"timestamp asc"` (default) and `"timestamp desc"`. The first @@ -332,42 +354,64 @@ LoggingServiceV2Api.prototype.writeLogEntries = function(request, options, callb * @param {Object=} options * Optional parameters. You can override the default settings for this call, e.g, timeout, * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object, ?string)=} callback - * When specified, the results are not streamed but this callback - * will be called with the response object representing [ListLogEntriesResponse]{@link ListLogEntriesResponse}. - * The third item will be set if the response contains the token for the further results - * and can be reused to `pageToken` field in the options in the next request. - * @returns {Stream|Promise} - * An object stream which emits an object representing - * [LogEntry]{@link LogEntry} on 'data' event. - * When the callback is specified or streaming is suppressed through options, - * it will return a promise that resolves to the response object. The promise - * has a method named "cancel" which cancels the ongoing API call. + * @param {function(?Error, ?Array, ?Object, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is Array of [LogEntry]{@link LogEntry}. + * + * When autoPaginate: false is specified through options, it contains the result + * in a single response. If the response indicates the next page exists, the third + * parameter is set to be used for the next request object. The fourth parameter keeps + * the raw response object of an object representing [ListLogEntriesResponse]{@link ListLogEntriesResponse}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is Array of [LogEntry]{@link LogEntry}. + * + * When autoPaginate: false is specified through options, the array has three elements. + * The first element is Array of [LogEntry]{@link LogEntry} in a single response. + * The second element is the next request object if the response + * indicates the next page exists, or null. The third element is + * an object representing [ListLogEntriesResponse]{@link ListLogEntriesResponse}. + * + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * - * var api = loggingV2.loggingServiceV2Api(); - * var projectIds = []; + * var client = loggingV2.loggingServiceV2Client(); + * var resourceNames = []; * // Iterate over all elements. - * api.listLogEntries({projectIds: projectIds}).on('data', function(element) { - * // doThingsWith(element) + * client.listLogEntries({resourceNames: resourceNames}).then(function(responses) { + * var resources = responses[0]; + * for (var i = 0; i < resources.length; ++i) { + * // doThingsWith(resources[i]) + * } + * }).catch(function(err) { + * console.error(err); * }); * - * // Or obtain the paged response through the callback. - * function callback(err, response, nextPageToken) { - * if (err) { - * console.error(err); - * return; + * // Or obtain the paged response. + * var options = {autoPaginate: false}; + * function callback(responses) { + * // The actual resources in a response. + * var resources = responses[0]; + * // The next request if the response shows there's more responses. + * var nextRequest = responses[1]; + * // The actual response object, if necessary. + * // var rawResponse = responses[2]; + * for (var i = 0; i < resources.length; ++i) { + * // doThingsWith(resources[i]); * } - * // doThingsWith(response) - * if (nextPageToken) { - * // fetch the next page. - * api.listLogEntries({projectIds: projectIds}, {pageToken: nextPageToken}, callback); + * if (nextRequest) { + * // Fetch the next page. + * return client.listLogEntries(nextRequest, options).then(callback); * } * } - * api.listLogEntries({projectIds: projectIds}, {flattenPages: false}, callback); + * client.listLogEntries({resourceNames: resourceNames}, options) + * .then(callback) + * .catch(function(err) { + * console.error(err); + * }); */ -LoggingServiceV2Api.prototype.listLogEntries = function(request, options, callback) { +LoggingServiceV2Client.prototype.listLogEntries = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -375,9 +419,81 @@ LoggingServiceV2Api.prototype.listLogEntries = function(request, options, callba if (options === undefined) { options = {}; } + return this._listLogEntries(request, options, callback); }; +/** + * Equivalent to {@link listLogEntries}, but returns a NodeJS Stream object. + * + * This fetches the paged responses for {@link listLogEntries} continuously + * and invokes the callback registered for 'data' event for each element in the + * responses. + * + * The returned object has 'end' method when no more elements are required. + * + * autoPaginate option will be ignored. + * + * @see {@link https://nodejs.org/api/stream.html} + * + * @param {Object} request + * The request object that will be sent. + * @param {string[]} request.resourceNames + * Required. One or more cloud resources from which to retrieve log + * entries: + * + * "projects/[PROJECT_ID]" + * "organizations/[ORGANIZATION_ID]" + * + * Projects listed in the `project_ids` field are added to this list. + * @param {string[]=} request.projectIds + * Deprecated. One or more project identifiers or project numbers from which + * to retrieve log entries. Example: `"my-project-1A"`. If + * present, these project identifiers are converted to resource format and + * added to the list of resources in `resourceNames`. Callers should use + * `resourceNames` rather than this parameter. + * @param {string=} request.filter + * Optional. A filter that chooses which log entries to return. See [Advanced + * Logs Filters](https://cloud.google.com/logging/docs/view/advanced_filters). Only log entries that + * match the filter are returned. An empty filter matches all log entries. + * The maximum length of the filter is 20000 characters. + * @param {string=} request.orderBy + * Optional. How the results should be sorted. Presently, the only permitted + * values are `"timestamp asc"` (default) and `"timestamp desc"`. The first + * option returns entries in order of increasing values of + * `LogEntry.timestamp` (oldest first), and the second option returns entries + * in order of decreasing timestamps (newest first). Entries with equal + * timestamps are returned in order of `LogEntry.insertId`. + * @param {number=} request.pageSize + * The maximum number of resources contained in the underlying API + * response. If page streaming is performed per-resource, this + * parameter does not affect the return value. If page streaming is + * performed per-page, this determines the maximum number of + * resources in a page. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @return {Stream} + * An object stream which emits an object representing [LogEntry]{@link LogEntry} on 'data' event. + * + * @example + * + * var client = loggingV2.loggingServiceV2Client(); + * var resourceNames = []; + * client.listLogEntriesStream({resourceNames: resourceNames}).on('data', function(element) { + * // doThingsWith(element) + * }).on('error', funciton(err) { + * console.error(err); + * }); + */ +LoggingServiceV2Client.prototype.listLogEntriesStream = function(request, options) { + if (options === undefined) { + options = {}; + } + + return PAGE_DESCRIPTORS.listLogEntries.createStream(this._listLogEntries, request, options); +}; + /** * Lists the monitored resource descriptors used by Stackdriver Logging. * @@ -392,42 +508,64 @@ LoggingServiceV2Api.prototype.listLogEntries = function(request, options, callba * @param {Object=} options * Optional parameters. You can override the default settings for this call, e.g, timeout, * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object, ?string)=} callback - * When specified, the results are not streamed but this callback - * will be called with the response object representing [ListMonitoredResourceDescriptorsResponse]{@link ListMonitoredResourceDescriptorsResponse}. - * The third item will be set if the response contains the token for the further results - * and can be reused to `pageToken` field in the options in the next request. - * @returns {Stream|Promise} - * An object stream which emits an object representing - * [google.api.MonitoredResourceDescriptor]{@link external:"google.api.MonitoredResourceDescriptor"} on 'data' event. - * When the callback is specified or streaming is suppressed through options, - * it will return a promise that resolves to the response object. The promise - * has a method named "cancel" which cancels the ongoing API call. + * @param {function(?Error, ?Array, ?Object, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is Array of [google.api.MonitoredResourceDescriptor]{@link external:"google.api.MonitoredResourceDescriptor"}. + * + * When autoPaginate: false is specified through options, it contains the result + * in a single response. If the response indicates the next page exists, the third + * parameter is set to be used for the next request object. The fourth parameter keeps + * the raw response object of an object representing [ListMonitoredResourceDescriptorsResponse]{@link ListMonitoredResourceDescriptorsResponse}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is Array of [google.api.MonitoredResourceDescriptor]{@link external:"google.api.MonitoredResourceDescriptor"}. + * + * When autoPaginate: false is specified through options, the array has three elements. + * The first element is Array of [google.api.MonitoredResourceDescriptor]{@link external:"google.api.MonitoredResourceDescriptor"} in a single response. + * The second element is the next request object if the response + * indicates the next page exists, or null. The third element is + * an object representing [ListMonitoredResourceDescriptorsResponse]{@link ListMonitoredResourceDescriptorsResponse}. + * + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * - * var api = loggingV2.loggingServiceV2Api(); + * var client = loggingV2.loggingServiceV2Client(); * * // Iterate over all elements. - * api.listMonitoredResourceDescriptors({}).on('data', function(element) { - * // doThingsWith(element) + * client.listMonitoredResourceDescriptors({}).then(function(responses) { + * var resources = responses[0]; + * for (var i = 0; i < resources.length; ++i) { + * // doThingsWith(resources[i]) + * } + * }).catch(function(err) { + * console.error(err); * }); * - * // Or obtain the paged response through the callback. - * function callback(err, response, nextPageToken) { - * if (err) { - * console.error(err); - * return; + * // Or obtain the paged response. + * var options = {autoPaginate: false}; + * function callback(responses) { + * // The actual resources in a response. + * var resources = responses[0]; + * // The next request if the response shows there's more responses. + * var nextRequest = responses[1]; + * // The actual response object, if necessary. + * // var rawResponse = responses[2]; + * for (var i = 0; i < resources.length; ++i) { + * // doThingsWith(resources[i]); * } - * // doThingsWith(response) - * if (nextPageToken) { - * // fetch the next page. - * api.listMonitoredResourceDescriptors({}, {pageToken: nextPageToken}, callback); + * if (nextRequest) { + * // Fetch the next page. + * return client.listMonitoredResourceDescriptors(nextRequest, options).then(callback); * } * } - * api.listMonitoredResourceDescriptors({}, {flattenPages: false}, callback); + * client.listMonitoredResourceDescriptors({}, options) + * .then(callback) + * .catch(function(err) { + * console.error(err); + * }); */ -LoggingServiceV2Api.prototype.listMonitoredResourceDescriptors = function(request, options, callback) { +LoggingServiceV2Client.prototype.listMonitoredResourceDescriptors = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -435,12 +573,58 @@ LoggingServiceV2Api.prototype.listMonitoredResourceDescriptors = function(reques if (options === undefined) { options = {}; } + return this._listMonitoredResourceDescriptors(request, options, callback); }; -function LoggingServiceV2ApiBuilder(gaxGrpc) { - if (!(this instanceof LoggingServiceV2ApiBuilder)) { - return new LoggingServiceV2ApiBuilder(gaxGrpc); +/** + * Equivalent to {@link listMonitoredResourceDescriptors}, but returns a NodeJS Stream object. + * + * This fetches the paged responses for {@link listMonitoredResourceDescriptors} continuously + * and invokes the callback registered for 'data' event for each element in the + * responses. + * + * The returned object has 'end' method when no more elements are required. + * + * autoPaginate option will be ignored. + * + * @see {@link https://nodejs.org/api/stream.html} + * + * @param {Object} request + * The request object that will be sent. + * @param {number=} request.pageSize + * The maximum number of resources contained in the underlying API + * response. If page streaming is performed per-resource, this + * parameter does not affect the return value. If page streaming is + * performed per-page, this determines the maximum number of + * resources in a page. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @return {Stream} + * An object stream which emits an object representing [google.api.MonitoredResourceDescriptor]{@link external:"google.api.MonitoredResourceDescriptor"} on 'data' event. + * + * @example + * + * var client = loggingV2.loggingServiceV2Client(); + * + * client.listMonitoredResourceDescriptorsStream({}).on('data', function(element) { + * // doThingsWith(element) + * }).on('error', funciton(err) { + * console.error(err); + * }); + */ +LoggingServiceV2Client.prototype.listMonitoredResourceDescriptorsStream = function(request, options) { + if (options === undefined) { + options = {}; + } + + return PAGE_DESCRIPTORS.listMonitoredResourceDescriptors.createStream(this._listMonitoredResourceDescriptors, request, options); +}; + +function LoggingServiceV2ClientBuilder(gaxGrpc) { + if (!(this instanceof LoggingServiceV2ClientBuilder)) { + return new LoggingServiceV2ClientBuilder(gaxGrpc); } var loggingServiceV2Client = gaxGrpc.load([{ @@ -454,7 +638,7 @@ function LoggingServiceV2ApiBuilder(gaxGrpc) { }; /** - * Build a new instance of {@link LoggingServiceV2Api}. + * Build a new instance of {@link LoggingServiceV2Client}. * * @param {Object=} opts - The optional parameters. * @param {String=} opts.servicePath @@ -471,11 +655,11 @@ function LoggingServiceV2ApiBuilder(gaxGrpc) { * @param {String=} opts.appVersion * The version of the calling service. */ - this.loggingServiceV2Api = function(opts) { - return new LoggingServiceV2Api(gaxGrpc, grpcClients, opts); + this.loggingServiceV2Client = function(opts) { + return new LoggingServiceV2Client(gaxGrpc, grpcClients, opts); }; - extend(this.loggingServiceV2Api, LoggingServiceV2Api); + extend(this.loggingServiceV2Client, LoggingServiceV2Client); } -module.exports = LoggingServiceV2ApiBuilder; +module.exports = LoggingServiceV2ClientBuilder; module.exports.SERVICE_ADDRESS = SERVICE_ADDRESS; module.exports.ALL_SCOPES = ALL_SCOPES; \ No newline at end of file diff --git a/packages/logging/src/v2/metrics_service_v2_api.js b/packages/logging/src/v2/metrics_service_v2_client.js similarity index 59% rename from packages/logging/src/v2/metrics_service_v2_api.js rename to packages/logging/src/v2/metrics_service_v2_client.js index 5982217df24..c268f8fc3e3 100644 --- a/packages/logging/src/v2/metrics_service_v2_api.js +++ b/packages/logging/src/v2/metrics_service_v2_client.js @@ -37,7 +37,6 @@ var DEFAULT_SERVICE_PORT = 443; var CODE_GEN_NAME_VERSION = 'gapic/0.1.0'; - var PAGE_DESCRIPTORS = { listLogMetrics: new gax.PageDescriptor( 'pageToken', @@ -62,17 +61,17 @@ var ALL_SCOPES = [ * * This will be created through a builder function which can be obtained by the module. * See the following example of how to initialize the module and how to access to the builder. - * @see {@link metricsServiceV2Api} + * @see {@link metricsServiceV2Client} * * @example * var loggingV2 = require('@google-cloud/logging').v2({ * // optional auth parameters. * }); - * var api = loggingV2.metricsServiceV2Api(); + * var client = loggingV2.metricsServiceV2Client(); * * @class */ -function MetricsServiceV2Api(gaxGrpc, grpcClients, opts) { +function MetricsServiceV2Client(gaxGrpc, grpcClients, opts) { opts = opts || {}; var servicePath = opts.servicePath || SERVICE_ADDRESS; var port = opts.port || DEFAULT_SERVICE_PORT; @@ -91,8 +90,6 @@ function MetricsServiceV2Api(gaxGrpc, grpcClients, opts) { 'google.logging.v2.MetricsServiceV2', configData, clientConfig, - PAGE_DESCRIPTORS, - null, {'x-goog-api-client': googleApiClient}); var metricsServiceV2Stub = gaxGrpc.createStub( @@ -112,7 +109,8 @@ function MetricsServiceV2Api(gaxGrpc, grpcClients, opts) { metricsServiceV2Stub.then(function(metricsServiceV2Stub) { return metricsServiceV2Stub[methodName].bind(metricsServiceV2Stub); }), - defaults[methodName]); + defaults[methodName], + PAGE_DESCRIPTORS[methodName]); }.bind(this)); } @@ -129,7 +127,7 @@ var METRIC_PATH_TEMPLATE = new gax.PathTemplate( * @param {String} project * @returns {String} */ -MetricsServiceV2Api.prototype.parentPath = function(project) { +MetricsServiceV2Client.prototype.parentPath = function(project) { return PARENT_PATH_TEMPLATE.render({ project: project }); @@ -141,7 +139,7 @@ MetricsServiceV2Api.prototype.parentPath = function(project) { * A fully-qualified path representing a parent resources. * @returns {String} - A string representing the project. */ -MetricsServiceV2Api.prototype.matchProjectFromParentName = function(parentName) { +MetricsServiceV2Client.prototype.matchProjectFromParentName = function(parentName) { return PARENT_PATH_TEMPLATE.match(parentName).project; }; @@ -151,7 +149,7 @@ MetricsServiceV2Api.prototype.matchProjectFromParentName = function(parentName) * @param {String} metric * @returns {String} */ -MetricsServiceV2Api.prototype.metricPath = function(project, metric) { +MetricsServiceV2Client.prototype.metricPath = function(project, metric) { return METRIC_PATH_TEMPLATE.render({ project: project, metric: metric @@ -164,7 +162,7 @@ MetricsServiceV2Api.prototype.metricPath = function(project, metric) { * A fully-qualified path representing a metric resources. * @returns {String} - A string representing the project. */ -MetricsServiceV2Api.prototype.matchProjectFromMetricName = function(metricName) { +MetricsServiceV2Client.prototype.matchProjectFromMetricName = function(metricName) { return METRIC_PATH_TEMPLATE.match(metricName).project; }; @@ -174,7 +172,7 @@ MetricsServiceV2Api.prototype.matchProjectFromMetricName = function(metricName) * A fully-qualified path representing a metric resources. * @returns {String} - A string representing the metric. */ -MetricsServiceV2Api.prototype.matchMetricFromMetricName = function(metricName) { +MetricsServiceV2Client.prototype.matchMetricFromMetricName = function(metricName) { return METRIC_PATH_TEMPLATE.match(metricName).metric; }; @@ -186,8 +184,9 @@ MetricsServiceV2Api.prototype.matchMetricFromMetricName = function(metricName) { * @param {Object} request * The request object that will be sent. * @param {string} request.parent - * Required. The resource name containing the metrics. - * Example: `"projects/my-project-id"`. + * Required. The name of the project containing the metrics: + * + * "projects/[PROJECT_ID]" * @param {number=} request.pageSize * The maximum number of resources contained in the underlying API * response. If page streaming is performed per-resource, this @@ -197,42 +196,64 @@ MetricsServiceV2Api.prototype.matchMetricFromMetricName = function(metricName) { * @param {Object=} options * Optional parameters. You can override the default settings for this call, e.g, timeout, * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object, ?string)=} callback - * When specified, the results are not streamed but this callback - * will be called with the response object representing [ListLogMetricsResponse]{@link ListLogMetricsResponse}. - * The third item will be set if the response contains the token for the further results - * and can be reused to `pageToken` field in the options in the next request. - * @returns {Stream|Promise} - * An object stream which emits an object representing - * [LogMetric]{@link LogMetric} on 'data' event. - * When the callback is specified or streaming is suppressed through options, - * it will return a promise that resolves to the response object. The promise - * has a method named "cancel" which cancels the ongoing API call. + * @param {function(?Error, ?Array, ?Object, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is Array of [LogMetric]{@link LogMetric}. + * + * When autoPaginate: false is specified through options, it contains the result + * in a single response. If the response indicates the next page exists, the third + * parameter is set to be used for the next request object. The fourth parameter keeps + * the raw response object of an object representing [ListLogMetricsResponse]{@link ListLogMetricsResponse}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is Array of [LogMetric]{@link LogMetric}. + * + * When autoPaginate: false is specified through options, the array has three elements. + * The first element is Array of [LogMetric]{@link LogMetric} in a single response. + * The second element is the next request object if the response + * indicates the next page exists, or null. The third element is + * an object representing [ListLogMetricsResponse]{@link ListLogMetricsResponse}. + * + * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * - * var api = loggingV2.metricsServiceV2Api(); - * var formattedParent = api.parentPath("[PROJECT]"); + * var client = loggingV2.metricsServiceV2Client(); + * var formattedParent = client.parentPath("[PROJECT]"); * // Iterate over all elements. - * api.listLogMetrics({parent: formattedParent}).on('data', function(element) { - * // doThingsWith(element) + * client.listLogMetrics({parent: formattedParent}).then(function(responses) { + * var resources = responses[0]; + * for (var i = 0; i < resources.length; ++i) { + * // doThingsWith(resources[i]) + * } + * }).catch(function(err) { + * console.error(err); * }); * - * // Or obtain the paged response through the callback. - * function callback(err, response, nextPageToken) { - * if (err) { - * console.error(err); - * return; + * // Or obtain the paged response. + * var options = {autoPaginate: false}; + * function callback(responses) { + * // The actual resources in a response. + * var resources = responses[0]; + * // The next request if the response shows there's more responses. + * var nextRequest = responses[1]; + * // The actual response object, if necessary. + * // var rawResponse = responses[2]; + * for (var i = 0; i < resources.length; ++i) { + * // doThingsWith(resources[i]); * } - * // doThingsWith(response) - * if (nextPageToken) { - * // fetch the next page. - * api.listLogMetrics({parent: formattedParent}, {pageToken: nextPageToken}, callback); + * if (nextRequest) { + * // Fetch the next page. + * return client.listLogMetrics(nextRequest, options).then(callback); * } * } - * api.listLogMetrics({parent: formattedParent}, {flattenPages: false}, callback); + * client.listLogMetrics({parent: formattedParent}, options) + * .then(callback) + * .catch(function(err) { + * console.error(err); + * }); */ -MetricsServiceV2Api.prototype.listLogMetrics = function(request, options, callback) { +MetricsServiceV2Client.prototype.listLogMetrics = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -240,38 +261,91 @@ MetricsServiceV2Api.prototype.listLogMetrics = function(request, options, callba if (options === undefined) { options = {}; } + return this._listLogMetrics(request, options, callback); }; +/** + * Equivalent to {@link listLogMetrics}, but returns a NodeJS Stream object. + * + * This fetches the paged responses for {@link listLogMetrics} continuously + * and invokes the callback registered for 'data' event for each element in the + * responses. + * + * The returned object has 'end' method when no more elements are required. + * + * autoPaginate option will be ignored. + * + * @see {@link https://nodejs.org/api/stream.html} + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The name of the project containing the metrics: + * + * "projects/[PROJECT_ID]" + * @param {number=} request.pageSize + * The maximum number of resources contained in the underlying API + * response. If page streaming is performed per-resource, this + * parameter does not affect the return value. If page streaming is + * performed per-page, this determines the maximum number of + * resources in a page. + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @return {Stream} + * An object stream which emits an object representing [LogMetric]{@link LogMetric} on 'data' event. + * + * @example + * + * var client = loggingV2.metricsServiceV2Client(); + * var formattedParent = client.parentPath("[PROJECT]"); + * client.listLogMetricsStream({parent: formattedParent}).on('data', function(element) { + * // doThingsWith(element) + * }).on('error', funciton(err) { + * console.error(err); + * }); + */ +MetricsServiceV2Client.prototype.listLogMetricsStream = function(request, options) { + if (options === undefined) { + options = {}; + } + + return PAGE_DESCRIPTORS.listLogMetrics.createStream(this._listLogMetrics, request, options); +}; + /** * Gets a logs-based metric. * * @param {Object} request * The request object that will be sent. * @param {string} request.metricName - * The resource name of the desired metric. - * Example: `"projects/my-project-id/metrics/my-metric-id"`. + * The resource name of the desired metric: + * + * "projects/[PROJECT_ID]/metrics/[METRIC_ID]" * @param {Object=} options * Optional parameters. You can override the default settings for this call, e.g, timeout, * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * - * The second parameter to the callback is an object representing [LogMetric]{@link LogMetric} - * @returns {Promise} - The promise which resolves to the response object. + * The second parameter to the callback is an object representing [LogMetric]{@link LogMetric}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [LogMetric]{@link LogMetric}. * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * - * var api = loggingV2.metricsServiceV2Api(); - * var formattedMetricName = api.metricPath("[PROJECT]", "[METRIC]"); - * api.getLogMetric({metricName: formattedMetricName}).then(function(response) { + * var client = loggingV2.metricsServiceV2Client(); + * var formattedMetricName = client.metricPath("[PROJECT]", "[METRIC]"); + * client.getLogMetric({metricName: formattedMetricName}).then(function(responses) { + * var response = responses[0]; * // doThingsWith(response) * }).catch(function(err) { * console.error(err); * }); */ -MetricsServiceV2Api.prototype.getLogMetric = function(request, options, callback) { +MetricsServiceV2Client.prototype.getLogMetric = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -279,6 +353,7 @@ MetricsServiceV2Api.prototype.getLogMetric = function(request, options, callback if (options === undefined) { options = {}; } + return this._getLogMetric(request, options, callback); }; @@ -288,8 +363,9 @@ MetricsServiceV2Api.prototype.getLogMetric = function(request, options, callback * @param {Object} request * The request object that will be sent. * @param {string} request.parent - * The resource name of the project in which to create the metric. - * Example: `"projects/my-project-id"`. + * The resource name of the project in which to create the metric: + * + * "projects/[PROJECT_ID]" * * The new metric must be provided in the request. * @param {Object} request.metric @@ -303,26 +379,28 @@ MetricsServiceV2Api.prototype.getLogMetric = function(request, options, callback * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * - * The second parameter to the callback is an object representing [LogMetric]{@link LogMetric} - * @returns {Promise} - The promise which resolves to the response object. + * The second parameter to the callback is an object representing [LogMetric]{@link LogMetric}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [LogMetric]{@link LogMetric}. * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * - * var api = loggingV2.metricsServiceV2Api(); - * var formattedParent = api.parentPath("[PROJECT]"); + * var client = loggingV2.metricsServiceV2Client(); + * var formattedParent = client.parentPath("[PROJECT]"); * var metric = {}; * var request = { * parent: formattedParent, * metric: metric * }; - * api.createLogMetric(request).then(function(response) { + * client.createLogMetric(request).then(function(responses) { + * var response = responses[0]; * // doThingsWith(response) * }).catch(function(err) { * console.error(err); * }); */ -MetricsServiceV2Api.prototype.createLogMetric = function(request, options, callback) { +MetricsServiceV2Client.prototype.createLogMetric = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -330,6 +408,7 @@ MetricsServiceV2Api.prototype.createLogMetric = function(request, options, callb if (options === undefined) { options = {}; } + return this._createLogMetric(request, options, callback); }; @@ -339,16 +418,15 @@ MetricsServiceV2Api.prototype.createLogMetric = function(request, options, callb * @param {Object} request * The request object that will be sent. * @param {string} request.metricName - * The resource name of the metric to update. - * Example: `"projects/my-project-id/metrics/my-metric-id"`. + * The resource name of the metric to update: + * + * "projects/[PROJECT_ID]/metrics/[METRIC_ID]" * - * The updated metric must be provided in the request and have the - * same identifier that is specified in `metricName`. - * If the metric does not exist, it is created. + * The updated metric must be provided in the request and it's + * `name` field must be the same as `[METRIC_ID]` If the metric + * does not exist in `[PROJECT_ID]`, then a new metric is created. * @param {Object} request.metric - * The updated metric, whose name must be the same as the - * metric identifier in `metricName`. If `metricName` does not - * exist, then a new metric is created. + * The updated metric. * * This object should have the same structure as [LogMetric]{@link LogMetric} * @param {Object=} options @@ -357,26 +435,28 @@ MetricsServiceV2Api.prototype.createLogMetric = function(request, options, callb * @param {function(?Error, ?Object)=} callback * The function which will be called with the result of the API call. * - * The second parameter to the callback is an object representing [LogMetric]{@link LogMetric} - * @returns {Promise} - The promise which resolves to the response object. + * The second parameter to the callback is an object representing [LogMetric]{@link LogMetric}. + * @return {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [LogMetric]{@link LogMetric}. * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * - * var api = loggingV2.metricsServiceV2Api(); - * var formattedMetricName = api.metricPath("[PROJECT]", "[METRIC]"); + * var client = loggingV2.metricsServiceV2Client(); + * var formattedMetricName = client.metricPath("[PROJECT]", "[METRIC]"); * var metric = {}; * var request = { * metricName: formattedMetricName, * metric: metric * }; - * api.updateLogMetric(request).then(function(response) { + * client.updateLogMetric(request).then(function(responses) { + * var response = responses[0]; * // doThingsWith(response) * }).catch(function(err) { * console.error(err); * }); */ -MetricsServiceV2Api.prototype.updateLogMetric = function(request, options, callback) { +MetricsServiceV2Client.prototype.updateLogMetric = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -384,6 +464,7 @@ MetricsServiceV2Api.prototype.updateLogMetric = function(request, options, callb if (options === undefined) { options = {}; } + return this._updateLogMetric(request, options, callback); }; @@ -393,25 +474,26 @@ MetricsServiceV2Api.prototype.updateLogMetric = function(request, options, callb * @param {Object} request * The request object that will be sent. * @param {string} request.metricName - * The resource name of the metric to delete. - * Example: `"projects/my-project-id/metrics/my-metric-id"`. + * The resource name of the metric to delete: + * + * "projects/[PROJECT_ID]/metrics/[METRIC_ID]" * @param {Object=} options * Optional parameters. You can override the default settings for this call, e.g, timeout, * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. * @param {function(?Error)=} callback * The function which will be called with the result of the API call. - * @returns {Promise} - The promise which resolves to the response object. + * @return {Promise} - The promise which resolves when API call finishes. * The promise has a method named "cancel" which cancels the ongoing API call. * * @example * - * var api = loggingV2.metricsServiceV2Api(); - * var formattedMetricName = api.metricPath("[PROJECT]", "[METRIC]"); - * api.deleteLogMetric({metricName: formattedMetricName}).catch(function(err) { + * var client = loggingV2.metricsServiceV2Client(); + * var formattedMetricName = client.metricPath("[PROJECT]", "[METRIC]"); + * client.deleteLogMetric({metricName: formattedMetricName}).catch(function(err) { * console.error(err); * }); */ -MetricsServiceV2Api.prototype.deleteLogMetric = function(request, options, callback) { +MetricsServiceV2Client.prototype.deleteLogMetric = function(request, options, callback) { if (options instanceof Function && callback === undefined) { callback = options; options = {}; @@ -419,12 +501,13 @@ MetricsServiceV2Api.prototype.deleteLogMetric = function(request, options, callb if (options === undefined) { options = {}; } + return this._deleteLogMetric(request, options, callback); }; -function MetricsServiceV2ApiBuilder(gaxGrpc) { - if (!(this instanceof MetricsServiceV2ApiBuilder)) { - return new MetricsServiceV2ApiBuilder(gaxGrpc); +function MetricsServiceV2ClientBuilder(gaxGrpc) { + if (!(this instanceof MetricsServiceV2ClientBuilder)) { + return new MetricsServiceV2ClientBuilder(gaxGrpc); } var metricsServiceV2Client = gaxGrpc.load([{ @@ -438,7 +521,7 @@ function MetricsServiceV2ApiBuilder(gaxGrpc) { }; /** - * Build a new instance of {@link MetricsServiceV2Api}. + * Build a new instance of {@link MetricsServiceV2Client}. * * @param {Object=} opts - The optional parameters. * @param {String=} opts.servicePath @@ -455,11 +538,11 @@ function MetricsServiceV2ApiBuilder(gaxGrpc) { * @param {String=} opts.appVersion * The version of the calling service. */ - this.metricsServiceV2Api = function(opts) { - return new MetricsServiceV2Api(gaxGrpc, grpcClients, opts); + this.metricsServiceV2Client = function(opts) { + return new MetricsServiceV2Client(gaxGrpc, grpcClients, opts); }; - extend(this.metricsServiceV2Api, MetricsServiceV2Api); + extend(this.metricsServiceV2Client, MetricsServiceV2Client); } -module.exports = MetricsServiceV2ApiBuilder; +module.exports = MetricsServiceV2ClientBuilder; module.exports.SERVICE_ADDRESS = SERVICE_ADDRESS; module.exports.ALL_SCOPES = ALL_SCOPES; \ No newline at end of file