From 3fb48d37715cdcfc16c09ff54bd5326b56ab40ab Mon Sep 17 00:00:00 2001 From: "gcf-merge-on-green[bot]" <60162190+gcf-merge-on-green[bot]@users.noreply.github.com> Date: Fri, 6 Mar 2020 00:12:11 +0000 Subject: [PATCH] feat: deferred client initialization (#323) This PR includes changes from https://github.com/googleapis/gapic-generator-typescript/pull/317 that will move the asynchronous initialization and authentication from the client constructor to an `initialize()` method. This method will be automatically called when the first RPC call is performed. The client library usage has not changed, there is no need to update any code. If you want to make sure the client is authenticated _before_ the first RPC call, you can do ```js await client.initialize(); ``` manually before calling any client method. --- src/v1/autoscaling_policy_service_client.ts | 81 ++++++++---- src/v1/cluster_controller_client.ts | 120 +++++++++++------ src/v1/job_controller_client.ts | 86 ++++++++---- src/v1/workflow_template_service_client.ts | 121 +++++++++++------ .../autoscaling_policy_service_client.ts | 81 ++++++++---- src/v1beta2/cluster_controller_client.ts | 122 +++++++++++------- src/v1beta2/job_controller_client.ts | 86 ++++++++---- .../workflow_template_service_client.ts | 119 +++++++++++------ synth.metadata | 8 +- test/gapic-autoscaling_policy_service-v1.ts | 36 ++++++ ...apic-autoscaling_policy_service-v1beta2.ts | 36 ++++++ test/gapic-cluster_controller-v1.ts | 40 ++++++ test/gapic-cluster_controller-v1beta2.ts | 40 ++++++ test/gapic-job_controller-v1.ts | 40 ++++++ test/gapic-job_controller-v1beta2.ts | 40 ++++++ test/gapic-workflow_template_service-v1.ts | 44 +++++++ ...gapic-workflow_template_service-v1beta2.ts | 44 +++++++ 17 files changed, 868 insertions(+), 276 deletions(-) diff --git a/src/v1/autoscaling_policy_service_client.ts b/src/v1/autoscaling_policy_service_client.ts index c323b164..00e504bb 100644 --- a/src/v1/autoscaling_policy_service_client.ts +++ b/src/v1/autoscaling_policy_service_client.ts @@ -37,8 +37,13 @@ export class AutoscalingPolicyServiceClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; - autoscalingPolicyServiceStub: Promise<{[name: string]: Function}>; + autoscalingPolicyServiceStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of AutoscalingPolicyServiceClient. @@ -62,8 +67,6 @@ export class AutoscalingPolicyServiceClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -91,28 +94,31 @@ export class AutoscalingPolicyServiceClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof AutoscalingPolicyServiceClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (gaxGrpc.auth as gax.GoogleAuth); + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); // Determine the client header string. const clientHeader = [ - `gax/${gaxModule.version}`, + `gax/${this._gaxModule.version}`, `gapic/${version}`, ]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -122,7 +128,7 @@ export class AutoscalingPolicyServiceClient { // For browsers, pass the JSON content. const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json'); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require("../../protos/protos.json") : nodejsProtoPath @@ -132,16 +138,16 @@ export class AutoscalingPolicyServiceClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - projectLocationAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectLocationAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/autoscalingPolicies/{autoscaling_policy}' ), - projectLocationWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectLocationWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/workflowTemplates/{workflow_template}' ), - projectRegionAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectRegionAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/autoscalingPolicies/{autoscaling_policy}' ), - projectRegionWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectRegionWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/workflowTemplates/{workflow_template}' ), }; @@ -151,11 +157,11 @@ export class AutoscalingPolicyServiceClient { // pages). Denote the keys used for pagination and results. this._descriptors.page = { listAutoscalingPolicies: - new gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'policies') + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'policies') }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.cloud.dataproc.v1.AutoscalingPolicyService', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); @@ -163,15 +169,33 @@ export class AutoscalingPolicyServiceClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.autoscalingPolicyServiceStub) { + return this.autoscalingPolicyServiceStub; + } // Put together the "service stub" for // google.cloud.dataproc.v1.AutoscalingPolicyService. - this.autoscalingPolicyServiceStub = gaxGrpc.createStub( - opts.fallback ? - (protos as protobuf.Root).lookupService('google.cloud.dataproc.v1.AutoscalingPolicyService') : + this.autoscalingPolicyServiceStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.cloud.dataproc.v1.AutoscalingPolicyService') : // tslint:disable-next-line no-any - (protos as any).google.cloud.dataproc.v1.AutoscalingPolicyService, - opts) as Promise<{[method: string]: Function}>; + (this._protos as any).google.cloud.dataproc.v1.AutoscalingPolicyService, + this._opts) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides // and create an API call method for each. @@ -190,9 +214,9 @@ export class AutoscalingPolicyServiceClient { throw err; }); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -206,6 +230,8 @@ export class AutoscalingPolicyServiceClient { return apiCall(argument, callOptions, callback); }; } + + return this.autoscalingPolicyServiceStub; } /** @@ -327,6 +353,7 @@ export class AutoscalingPolicyServiceClient { ] = gax.routingHeader.fromParams({ 'parent': request.parent || '', }); + this.initialize(); return this._innerApiCalls.createAutoscalingPolicy(request, options, callback); } updateAutoscalingPolicy( @@ -389,6 +416,7 @@ export class AutoscalingPolicyServiceClient { ] = gax.routingHeader.fromParams({ 'policy.name': request.policy!.name || '', }); + this.initialize(); return this._innerApiCalls.updateAutoscalingPolicy(request, options, callback); } getAutoscalingPolicy( @@ -457,6 +485,7 @@ export class AutoscalingPolicyServiceClient { ] = gax.routingHeader.fromParams({ 'name': request.name || '', }); + this.initialize(); return this._innerApiCalls.getAutoscalingPolicy(request, options, callback); } deleteAutoscalingPolicy( @@ -526,6 +555,7 @@ export class AutoscalingPolicyServiceClient { ] = gax.routingHeader.fromParams({ 'name': request.name || '', }); + this.initialize(); return this._innerApiCalls.deleteAutoscalingPolicy(request, options, callback); } @@ -616,6 +646,7 @@ export class AutoscalingPolicyServiceClient { ] = gax.routingHeader.fromParams({ 'parent': request.parent || '', }); + this.initialize(); return this._innerApiCalls.listAutoscalingPolicies(request, options, callback); } @@ -670,6 +701,7 @@ export class AutoscalingPolicyServiceClient { 'parent': request.parent || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listAutoscalingPolicies.createStream( this._innerApiCalls.listAutoscalingPolicies as gax.GaxCall, request, @@ -882,8 +914,9 @@ export class AutoscalingPolicyServiceClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.autoscalingPolicyServiceStub.then(stub => { + return this.autoscalingPolicyServiceStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/src/v1/cluster_controller_client.ts b/src/v1/cluster_controller_client.ts index 7d78198c..c2388425 100644 --- a/src/v1/cluster_controller_client.ts +++ b/src/v1/cluster_controller_client.ts @@ -37,9 +37,14 @@ export class ClusterControllerClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; operationsClient: gax.OperationsClient; - clusterControllerStub: Promise<{[name: string]: Function}>; + clusterControllerStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of ClusterControllerClient. @@ -63,8 +68,6 @@ export class ClusterControllerClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -92,28 +95,31 @@ export class ClusterControllerClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof ClusterControllerClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (gaxGrpc.auth as gax.GoogleAuth); + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); // Determine the client header string. const clientHeader = [ - `gax/${gaxModule.version}`, + `gax/${this._gaxModule.version}`, `gapic/${version}`, ]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -123,7 +129,7 @@ export class ClusterControllerClient { // For browsers, pass the JSON content. const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json'); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require("../../protos/protos.json") : nodejsProtoPath @@ -133,16 +139,16 @@ export class ClusterControllerClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - projectLocationAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectLocationAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/autoscalingPolicies/{autoscaling_policy}' ), - projectLocationWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectLocationWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/workflowTemplates/{workflow_template}' ), - projectRegionAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectRegionAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/autoscalingPolicies/{autoscaling_policy}' ), - projectRegionWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectRegionWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/workflowTemplates/{workflow_template}' ), }; @@ -152,19 +158,19 @@ export class ClusterControllerClient { // pages). Denote the keys used for pagination and results. this._descriptors.page = { listClusters: - new gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'clusters') + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'clusters') }; // This API contains "long-running operations", which return a // an Operation object that allows for tracking of the operation, // rather than holding a request open. const protoFilesRoot = opts.fallback? - gaxModule.protobuf.Root.fromJSON(require("../../protos/protos.json")) : - gaxModule.protobuf.loadSync(nodejsProtoPath); + this._gaxModule.protobuf.Root.fromJSON(require("../../protos/protos.json")) : + this._gaxModule.protobuf.loadSync(nodejsProtoPath); - this.operationsClient = gaxModule.lro({ + this.operationsClient = this._gaxModule.lro({ auth: this.auth, - grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined + grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined }).operationsClient(opts); const createClusterResponse = protoFilesRoot.lookup( '.google.cloud.dataproc.v1.Cluster') as gax.protobuf.Type; @@ -184,26 +190,26 @@ export class ClusterControllerClient { '.google.cloud.dataproc.v1.DiagnoseClusterResults') as gax.protobuf.Type; this._descriptors.longrunning = { - createCluster: new gaxModule.LongrunningDescriptor( + createCluster: new this._gaxModule.LongrunningDescriptor( this.operationsClient, createClusterResponse.decode.bind(createClusterResponse), createClusterMetadata.decode.bind(createClusterMetadata)), - updateCluster: new gaxModule.LongrunningDescriptor( + updateCluster: new this._gaxModule.LongrunningDescriptor( this.operationsClient, updateClusterResponse.decode.bind(updateClusterResponse), updateClusterMetadata.decode.bind(updateClusterMetadata)), - deleteCluster: new gaxModule.LongrunningDescriptor( + deleteCluster: new this._gaxModule.LongrunningDescriptor( this.operationsClient, deleteClusterResponse.decode.bind(deleteClusterResponse), deleteClusterMetadata.decode.bind(deleteClusterMetadata)), - diagnoseCluster: new gaxModule.LongrunningDescriptor( + diagnoseCluster: new this._gaxModule.LongrunningDescriptor( this.operationsClient, diagnoseClusterResponse.decode.bind(diagnoseClusterResponse), diagnoseClusterMetadata.decode.bind(diagnoseClusterMetadata)) }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.cloud.dataproc.v1.ClusterController', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); @@ -211,15 +217,33 @@ export class ClusterControllerClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.clusterControllerStub) { + return this.clusterControllerStub; + } // Put together the "service stub" for // google.cloud.dataproc.v1.ClusterController. - this.clusterControllerStub = gaxGrpc.createStub( - opts.fallback ? - (protos as protobuf.Root).lookupService('google.cloud.dataproc.v1.ClusterController') : + this.clusterControllerStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.cloud.dataproc.v1.ClusterController') : // tslint:disable-next-line no-any - (protos as any).google.cloud.dataproc.v1.ClusterController, - opts) as Promise<{[method: string]: Function}>; + (this._protos as any).google.cloud.dataproc.v1.ClusterController, + this._opts) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides // and create an API call method for each. @@ -238,9 +262,9 @@ export class ClusterControllerClient { throw err; }); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -254,6 +278,8 @@ export class ClusterControllerClient { return apiCall(argument, callOptions, callback); }; } + + return this.clusterControllerStub; } /** @@ -362,6 +388,7 @@ export class ClusterControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.getCluster(request, options, callback); } @@ -381,7 +408,7 @@ export class ClusterControllerClient { {}|undefined>): void; /** * Creates a cluster in a project. The returned - * [Operation.metadata][google.longrunning.Operation.metadata] will be + * {@link google.longrunning.Operation.metadata|Operation.metadata} will be * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). * * @param {Object} request @@ -395,9 +422,9 @@ export class ClusterControllerClient { * Required. The cluster to create. * @param {string} [request.requestId] * Optional. A unique id used to identify the request. If the server - * receives two [CreateClusterRequest][google.cloud.dataproc.v1.CreateClusterRequest] requests with the same + * receives two {@link google.cloud.dataproc.v1.CreateClusterRequest|CreateClusterRequest} requests with the same * id, then the second request will be ignored and the - * first [google.longrunning.Operation][google.longrunning.Operation] created and stored in the backend + * first {@link google.longrunning.Operation|google.longrunning.Operation} created and stored in the backend * is returned. * * It is recommended to always set this value to a @@ -434,6 +461,7 @@ export class ClusterControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.createCluster(request, options, callback); } updateCluster( @@ -452,7 +480,7 @@ export class ClusterControllerClient { {}|undefined>): void; /** * Updates a cluster in a project. The returned - * [Operation.metadata][google.longrunning.Operation.metadata] will be + * {@link google.longrunning.Operation.metadata|Operation.metadata} will be * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). * * @param {Object} request @@ -530,9 +558,9 @@ export class ClusterControllerClient { * * @param {string} [request.requestId] * Optional. A unique id used to identify the request. If the server - * receives two [UpdateClusterRequest][google.cloud.dataproc.v1.UpdateClusterRequest] requests with the same + * receives two {@link google.cloud.dataproc.v1.UpdateClusterRequest|UpdateClusterRequest} requests with the same * id, then the second request will be ignored and the - * first [google.longrunning.Operation][google.longrunning.Operation] created and stored in the + * first {@link google.longrunning.Operation|google.longrunning.Operation} created and stored in the * backend is returned. * * It is recommended to always set this value to a @@ -569,6 +597,7 @@ export class ClusterControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.updateCluster(request, options, callback); } deleteCluster( @@ -587,7 +616,7 @@ export class ClusterControllerClient { {}|undefined>): void; /** * Deletes a cluster in a project. The returned - * [Operation.metadata][google.longrunning.Operation.metadata] will be + * {@link google.longrunning.Operation.metadata|Operation.metadata} will be * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). * * @param {Object} request @@ -604,9 +633,9 @@ export class ClusterControllerClient { * (with error NOT_FOUND) if cluster with specified UUID does not exist. * @param {string} [request.requestId] * Optional. A unique id used to identify the request. If the server - * receives two [DeleteClusterRequest][google.cloud.dataproc.v1.DeleteClusterRequest] requests with the same + * receives two {@link google.cloud.dataproc.v1.DeleteClusterRequest|DeleteClusterRequest} requests with the same * id, then the second request will be ignored and the - * first [google.longrunning.Operation][google.longrunning.Operation] created and stored in the + * first {@link google.longrunning.Operation|google.longrunning.Operation} created and stored in the * backend is returned. * * It is recommended to always set this value to a @@ -643,6 +672,7 @@ export class ClusterControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.deleteCluster(request, options, callback); } diagnoseCluster( @@ -661,10 +691,10 @@ export class ClusterControllerClient { {}|undefined>): void; /** * Gets cluster diagnostic information. The returned - * [Operation.metadata][google.longrunning.Operation.metadata] will be + * {@link google.longrunning.Operation.metadata|Operation.metadata} will be * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#clusteroperationmetadata). * After the operation completes, - * [Operation.response][google.longrunning.Operation.response] + * {@link google.longrunning.Operation.response|Operation.response} * contains * [DiagnoseClusterResults](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#diagnoseclusterresults). * @@ -706,6 +736,7 @@ export class ClusterControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.diagnoseCluster(request, options, callback); } listClusters( @@ -800,6 +831,7 @@ export class ClusterControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.listClusters(request, options, callback); } @@ -859,6 +891,7 @@ export class ClusterControllerClient { request = request || {}; options = options || {}; const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listClusters.createStream( this._innerApiCalls.listClusters as gax.GaxCall, request, @@ -1071,8 +1104,9 @@ export class ClusterControllerClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.clusterControllerStub.then(stub => { + return this.clusterControllerStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/src/v1/job_controller_client.ts b/src/v1/job_controller_client.ts index b8fbfdaa..b2da8faa 100644 --- a/src/v1/job_controller_client.ts +++ b/src/v1/job_controller_client.ts @@ -36,8 +36,13 @@ export class JobControllerClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; - jobControllerStub: Promise<{[name: string]: Function}>; + jobControllerStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of JobControllerClient. @@ -61,8 +66,6 @@ export class JobControllerClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -90,28 +93,31 @@ export class JobControllerClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof JobControllerClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (gaxGrpc.auth as gax.GoogleAuth); + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); // Determine the client header string. const clientHeader = [ - `gax/${gaxModule.version}`, + `gax/${this._gaxModule.version}`, `gapic/${version}`, ]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -121,7 +127,7 @@ export class JobControllerClient { // For browsers, pass the JSON content. const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json'); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require("../../protos/protos.json") : nodejsProtoPath @@ -131,16 +137,16 @@ export class JobControllerClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - projectLocationAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectLocationAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/autoscalingPolicies/{autoscaling_policy}' ), - projectLocationWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectLocationWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/workflowTemplates/{workflow_template}' ), - projectRegionAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectRegionAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/autoscalingPolicies/{autoscaling_policy}' ), - projectRegionWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectRegionWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/workflowTemplates/{workflow_template}' ), }; @@ -150,11 +156,11 @@ export class JobControllerClient { // pages). Denote the keys used for pagination and results. this._descriptors.page = { listJobs: - new gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'jobs') + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'jobs') }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.cloud.dataproc.v1.JobController', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); @@ -162,15 +168,33 @@ export class JobControllerClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.jobControllerStub) { + return this.jobControllerStub; + } // Put together the "service stub" for // google.cloud.dataproc.v1.JobController. - this.jobControllerStub = gaxGrpc.createStub( - opts.fallback ? - (protos as protobuf.Root).lookupService('google.cloud.dataproc.v1.JobController') : + this.jobControllerStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.cloud.dataproc.v1.JobController') : // tslint:disable-next-line no-any - (protos as any).google.cloud.dataproc.v1.JobController, - opts) as Promise<{[method: string]: Function}>; + (this._protos as any).google.cloud.dataproc.v1.JobController, + this._opts) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides // and create an API call method for each. @@ -189,9 +213,9 @@ export class JobControllerClient { throw err; }); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -205,6 +229,8 @@ export class JobControllerClient { return apiCall(argument, callOptions, callback); }; } + + return this.jobControllerStub; } /** @@ -286,9 +312,9 @@ export class JobControllerClient { * Required. The job resource. * @param {string} [request.requestId] * Optional. A unique id used to identify the request. If the server - * receives two [SubmitJobRequest][google.cloud.dataproc.v1.SubmitJobRequest] requests with the same + * receives two {@link google.cloud.dataproc.v1.SubmitJobRequest|SubmitJobRequest} requests with the same * id, then the second request will be ignored and the - * first [Job][google.cloud.dataproc.v1.Job] created and stored in the backend + * first {@link google.cloud.dataproc.v1.Job|Job} created and stored in the backend * is returned. * * It is recommended to always set this value to a @@ -325,6 +351,7 @@ export class JobControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.submitJob(request, options, callback); } getJob( @@ -382,6 +409,7 @@ export class JobControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.getJob(request, options, callback); } updateJob( @@ -448,6 +476,7 @@ export class JobControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.updateJob(request, options, callback); } cancelJob( @@ -509,6 +538,7 @@ export class JobControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.cancelJob(request, options, callback); } deleteJob( @@ -567,6 +597,7 @@ export class JobControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.deleteJob(request, options, callback); } @@ -666,6 +697,7 @@ export class JobControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.listJobs(request, options, callback); } @@ -729,6 +761,7 @@ export class JobControllerClient { request = request || {}; options = options || {}; const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listJobs.createStream( this._innerApiCalls.listJobs as gax.GaxCall, request, @@ -941,8 +974,9 @@ export class JobControllerClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.jobControllerStub.then(stub => { + return this.jobControllerStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/src/v1/workflow_template_service_client.ts b/src/v1/workflow_template_service_client.ts index b65c1fc9..641f83ba 100644 --- a/src/v1/workflow_template_service_client.ts +++ b/src/v1/workflow_template_service_client.ts @@ -37,9 +37,14 @@ export class WorkflowTemplateServiceClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; operationsClient: gax.OperationsClient; - workflowTemplateServiceStub: Promise<{[name: string]: Function}>; + workflowTemplateServiceStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of WorkflowTemplateServiceClient. @@ -63,8 +68,6 @@ export class WorkflowTemplateServiceClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -92,28 +95,31 @@ export class WorkflowTemplateServiceClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof WorkflowTemplateServiceClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (gaxGrpc.auth as gax.GoogleAuth); + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); // Determine the client header string. const clientHeader = [ - `gax/${gaxModule.version}`, + `gax/${this._gaxModule.version}`, `gapic/${version}`, ]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -123,7 +129,7 @@ export class WorkflowTemplateServiceClient { // For browsers, pass the JSON content. const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json'); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require("../../protos/protos.json") : nodejsProtoPath @@ -133,19 +139,19 @@ export class WorkflowTemplateServiceClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - projectLocationAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectLocationAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/autoscalingPolicies/{autoscaling_policy}' ), - projectLocationWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectLocationWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/workflowTemplates/{workflow_template}' ), - projectRegionAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectRegionAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/autoscalingPolicies/{autoscaling_policy}' ), - projectRegionWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectRegionWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/workflowTemplates/{workflow_template}' ), - regionPathTemplate: new gaxModule.PathTemplate( + regionPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}' ), }; @@ -155,19 +161,19 @@ export class WorkflowTemplateServiceClient { // pages). Denote the keys used for pagination and results. this._descriptors.page = { listWorkflowTemplates: - new gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'templates') + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'templates') }; // This API contains "long-running operations", which return a // an Operation object that allows for tracking of the operation, // rather than holding a request open. const protoFilesRoot = opts.fallback? - gaxModule.protobuf.Root.fromJSON(require("../../protos/protos.json")) : - gaxModule.protobuf.loadSync(nodejsProtoPath); + this._gaxModule.protobuf.Root.fromJSON(require("../../protos/protos.json")) : + this._gaxModule.protobuf.loadSync(nodejsProtoPath); - this.operationsClient = gaxModule.lro({ + this.operationsClient = this._gaxModule.lro({ auth: this.auth, - grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined + grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined }).operationsClient(opts); const instantiateWorkflowTemplateResponse = protoFilesRoot.lookup( '.google.protobuf.Empty') as gax.protobuf.Type; @@ -179,18 +185,18 @@ export class WorkflowTemplateServiceClient { '.google.cloud.dataproc.v1.WorkflowMetadata') as gax.protobuf.Type; this._descriptors.longrunning = { - instantiateWorkflowTemplate: new gaxModule.LongrunningDescriptor( + instantiateWorkflowTemplate: new this._gaxModule.LongrunningDescriptor( this.operationsClient, instantiateWorkflowTemplateResponse.decode.bind(instantiateWorkflowTemplateResponse), instantiateWorkflowTemplateMetadata.decode.bind(instantiateWorkflowTemplateMetadata)), - instantiateInlineWorkflowTemplate: new gaxModule.LongrunningDescriptor( + instantiateInlineWorkflowTemplate: new this._gaxModule.LongrunningDescriptor( this.operationsClient, instantiateInlineWorkflowTemplateResponse.decode.bind(instantiateInlineWorkflowTemplateResponse), instantiateInlineWorkflowTemplateMetadata.decode.bind(instantiateInlineWorkflowTemplateMetadata)) }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.cloud.dataproc.v1.WorkflowTemplateService', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); @@ -198,15 +204,33 @@ export class WorkflowTemplateServiceClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.workflowTemplateServiceStub) { + return this.workflowTemplateServiceStub; + } // Put together the "service stub" for // google.cloud.dataproc.v1.WorkflowTemplateService. - this.workflowTemplateServiceStub = gaxGrpc.createStub( - opts.fallback ? - (protos as protobuf.Root).lookupService('google.cloud.dataproc.v1.WorkflowTemplateService') : + this.workflowTemplateServiceStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.cloud.dataproc.v1.WorkflowTemplateService') : // tslint:disable-next-line no-any - (protos as any).google.cloud.dataproc.v1.WorkflowTemplateService, - opts) as Promise<{[method: string]: Function}>; + (this._protos as any).google.cloud.dataproc.v1.WorkflowTemplateService, + this._opts) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides // and create an API call method for each. @@ -225,9 +249,9 @@ export class WorkflowTemplateServiceClient { throw err; }); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -241,6 +265,8 @@ export class WorkflowTemplateServiceClient { return apiCall(argument, callOptions, callback); }; } + + return this.workflowTemplateServiceStub; } /** @@ -362,6 +388,7 @@ export class WorkflowTemplateServiceClient { ] = gax.routingHeader.fromParams({ 'parent': request.parent || '', }); + this.initialize(); return this._innerApiCalls.createWorkflowTemplate(request, options, callback); } getWorkflowTemplate( @@ -438,6 +465,7 @@ export class WorkflowTemplateServiceClient { ] = gax.routingHeader.fromParams({ 'name': request.name || '', }); + this.initialize(); return this._innerApiCalls.getWorkflowTemplate(request, options, callback); } updateWorkflowTemplate( @@ -500,6 +528,7 @@ export class WorkflowTemplateServiceClient { ] = gax.routingHeader.fromParams({ 'template.name': request.template!.name || '', }); + this.initialize(); return this._innerApiCalls.updateWorkflowTemplate(request, options, callback); } deleteWorkflowTemplate( @@ -572,6 +601,7 @@ export class WorkflowTemplateServiceClient { ] = gax.routingHeader.fromParams({ 'name': request.name || '', }); + this.initialize(); return this._innerApiCalls.deleteWorkflowTemplate(request, options, callback); } @@ -594,22 +624,22 @@ export class WorkflowTemplateServiceClient { * * The returned Operation can be used to track execution of * workflow by polling - * [operations.get][google.longrunning.Operations.GetOperation]. + * {@link google.longrunning.Operations.GetOperation|operations.get}. * The Operation will complete when entire workflow is finished. * * The running workflow can be aborted via - * [operations.cancel][google.longrunning.Operations.CancelOperation]. + * {@link google.longrunning.Operations.CancelOperation|operations.cancel}. * This will cause any inflight jobs to be cancelled and workflow-owned * clusters to be deleted. * - * The [Operation.metadata][google.longrunning.Operation.metadata] will be + * The {@link google.longrunning.Operation.metadata|Operation.metadata} will be * [WorkflowMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#workflowmetadata). * Also see [Using * WorkflowMetadata](https://cloud.google.com/dataproc/docs/concepts/workflows/debugging#using_workflowmetadata). * * On successful completion, - * [Operation.response][google.longrunning.Operation.response] will be - * [Empty][google.protobuf.Empty]. + * {@link google.longrunning.Operation.response|Operation.response} will be + * {@link google.protobuf.Empty|Empty}. * * @param {Object} request * The request object that will be sent. @@ -680,6 +710,7 @@ export class WorkflowTemplateServiceClient { ] = gax.routingHeader.fromParams({ 'name': request.name || '', }); + this.initialize(); return this._innerApiCalls.instantiateWorkflowTemplate(request, options, callback); } instantiateInlineWorkflowTemplate( @@ -700,27 +731,27 @@ export class WorkflowTemplateServiceClient { * Instantiates a template and begins execution. * * This method is equivalent to executing the sequence - * [CreateWorkflowTemplate][google.cloud.dataproc.v1.WorkflowTemplateService.CreateWorkflowTemplate], [InstantiateWorkflowTemplate][google.cloud.dataproc.v1.WorkflowTemplateService.InstantiateWorkflowTemplate], - * [DeleteWorkflowTemplate][google.cloud.dataproc.v1.WorkflowTemplateService.DeleteWorkflowTemplate]. + * {@link google.cloud.dataproc.v1.WorkflowTemplateService.CreateWorkflowTemplate|CreateWorkflowTemplate}, {@link google.cloud.dataproc.v1.WorkflowTemplateService.InstantiateWorkflowTemplate|InstantiateWorkflowTemplate}, + * {@link google.cloud.dataproc.v1.WorkflowTemplateService.DeleteWorkflowTemplate|DeleteWorkflowTemplate}. * * The returned Operation can be used to track execution of * workflow by polling - * [operations.get][google.longrunning.Operations.GetOperation]. + * {@link google.longrunning.Operations.GetOperation|operations.get}. * The Operation will complete when entire workflow is finished. * * The running workflow can be aborted via - * [operations.cancel][google.longrunning.Operations.CancelOperation]. + * {@link google.longrunning.Operations.CancelOperation|operations.cancel}. * This will cause any inflight jobs to be cancelled and workflow-owned * clusters to be deleted. * - * The [Operation.metadata][google.longrunning.Operation.metadata] will be + * The {@link google.longrunning.Operation.metadata|Operation.metadata} will be * [WorkflowMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#workflowmetadata). * Also see [Using * WorkflowMetadata](https://cloud.google.com/dataproc/docs/concepts/workflows/debugging#using_workflowmetadata). * * On successful completion, - * [Operation.response][google.longrunning.Operation.response] will be - * [Empty][google.protobuf.Empty]. + * {@link google.longrunning.Operation.response|Operation.response} will be + * {@link google.protobuf.Empty|Empty}. * * @param {Object} request * The request object that will be sent. @@ -783,6 +814,7 @@ export class WorkflowTemplateServiceClient { ] = gax.routingHeader.fromParams({ 'parent': request.parent || '', }); + this.initialize(); return this._innerApiCalls.instantiateInlineWorkflowTemplate(request, options, callback); } listWorkflowTemplates( @@ -871,6 +903,7 @@ export class WorkflowTemplateServiceClient { ] = gax.routingHeader.fromParams({ 'parent': request.parent || '', }); + this.initialize(); return this._innerApiCalls.listWorkflowTemplates(request, options, callback); } @@ -924,6 +957,7 @@ export class WorkflowTemplateServiceClient { 'parent': request.parent || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listWorkflowTemplates.createStream( this._innerApiCalls.listWorkflowTemplates as gax.GaxCall, request, @@ -1172,8 +1206,9 @@ export class WorkflowTemplateServiceClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.workflowTemplateServiceStub.then(stub => { + return this.workflowTemplateServiceStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/src/v1beta2/autoscaling_policy_service_client.ts b/src/v1beta2/autoscaling_policy_service_client.ts index 11cdb410..c2c619eb 100644 --- a/src/v1beta2/autoscaling_policy_service_client.ts +++ b/src/v1beta2/autoscaling_policy_service_client.ts @@ -37,8 +37,13 @@ export class AutoscalingPolicyServiceClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; - autoscalingPolicyServiceStub: Promise<{[name: string]: Function}>; + autoscalingPolicyServiceStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of AutoscalingPolicyServiceClient. @@ -62,8 +67,6 @@ export class AutoscalingPolicyServiceClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -91,28 +94,31 @@ export class AutoscalingPolicyServiceClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof AutoscalingPolicyServiceClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (gaxGrpc.auth as gax.GoogleAuth); + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); // Determine the client header string. const clientHeader = [ - `gax/${gaxModule.version}`, + `gax/${this._gaxModule.version}`, `gapic/${version}`, ]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -122,7 +128,7 @@ export class AutoscalingPolicyServiceClient { // For browsers, pass the JSON content. const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json'); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require("../../protos/protos.json") : nodejsProtoPath @@ -132,16 +138,16 @@ export class AutoscalingPolicyServiceClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - projectLocationAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectLocationAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/autoscalingPolicies/{autoscaling_policy}' ), - projectLocationWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectLocationWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/workflowTemplates/{workflow_template}' ), - projectRegionAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectRegionAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/autoscalingPolicies/{autoscaling_policy}' ), - projectRegionWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectRegionWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/workflowTemplates/{workflow_template}' ), }; @@ -151,11 +157,11 @@ export class AutoscalingPolicyServiceClient { // pages). Denote the keys used for pagination and results. this._descriptors.page = { listAutoscalingPolicies: - new gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'policies') + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'policies') }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.cloud.dataproc.v1beta2.AutoscalingPolicyService', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); @@ -163,15 +169,33 @@ export class AutoscalingPolicyServiceClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.autoscalingPolicyServiceStub) { + return this.autoscalingPolicyServiceStub; + } // Put together the "service stub" for // google.cloud.dataproc.v1beta2.AutoscalingPolicyService. - this.autoscalingPolicyServiceStub = gaxGrpc.createStub( - opts.fallback ? - (protos as protobuf.Root).lookupService('google.cloud.dataproc.v1beta2.AutoscalingPolicyService') : + this.autoscalingPolicyServiceStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.cloud.dataproc.v1beta2.AutoscalingPolicyService') : // tslint:disable-next-line no-any - (protos as any).google.cloud.dataproc.v1beta2.AutoscalingPolicyService, - opts) as Promise<{[method: string]: Function}>; + (this._protos as any).google.cloud.dataproc.v1beta2.AutoscalingPolicyService, + this._opts) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides // and create an API call method for each. @@ -190,9 +214,9 @@ export class AutoscalingPolicyServiceClient { throw err; }); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -206,6 +230,8 @@ export class AutoscalingPolicyServiceClient { return apiCall(argument, callOptions, callback); }; } + + return this.autoscalingPolicyServiceStub; } /** @@ -327,6 +353,7 @@ export class AutoscalingPolicyServiceClient { ] = gax.routingHeader.fromParams({ 'parent': request.parent || '', }); + this.initialize(); return this._innerApiCalls.createAutoscalingPolicy(request, options, callback); } updateAutoscalingPolicy( @@ -389,6 +416,7 @@ export class AutoscalingPolicyServiceClient { ] = gax.routingHeader.fromParams({ 'policy.name': request.policy!.name || '', }); + this.initialize(); return this._innerApiCalls.updateAutoscalingPolicy(request, options, callback); } getAutoscalingPolicy( @@ -457,6 +485,7 @@ export class AutoscalingPolicyServiceClient { ] = gax.routingHeader.fromParams({ 'name': request.name || '', }); + this.initialize(); return this._innerApiCalls.getAutoscalingPolicy(request, options, callback); } deleteAutoscalingPolicy( @@ -526,6 +555,7 @@ export class AutoscalingPolicyServiceClient { ] = gax.routingHeader.fromParams({ 'name': request.name || '', }); + this.initialize(); return this._innerApiCalls.deleteAutoscalingPolicy(request, options, callback); } @@ -616,6 +646,7 @@ export class AutoscalingPolicyServiceClient { ] = gax.routingHeader.fromParams({ 'parent': request.parent || '', }); + this.initialize(); return this._innerApiCalls.listAutoscalingPolicies(request, options, callback); } @@ -670,6 +701,7 @@ export class AutoscalingPolicyServiceClient { 'parent': request.parent || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listAutoscalingPolicies.createStream( this._innerApiCalls.listAutoscalingPolicies as gax.GaxCall, request, @@ -882,8 +914,9 @@ export class AutoscalingPolicyServiceClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.autoscalingPolicyServiceStub.then(stub => { + return this.autoscalingPolicyServiceStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/src/v1beta2/cluster_controller_client.ts b/src/v1beta2/cluster_controller_client.ts index dad2b4d1..6c100282 100644 --- a/src/v1beta2/cluster_controller_client.ts +++ b/src/v1beta2/cluster_controller_client.ts @@ -37,9 +37,14 @@ export class ClusterControllerClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; operationsClient: gax.OperationsClient; - clusterControllerStub: Promise<{[name: string]: Function}>; + clusterControllerStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of ClusterControllerClient. @@ -63,8 +68,6 @@ export class ClusterControllerClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -92,28 +95,31 @@ export class ClusterControllerClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof ClusterControllerClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (gaxGrpc.auth as gax.GoogleAuth); + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); // Determine the client header string. const clientHeader = [ - `gax/${gaxModule.version}`, + `gax/${this._gaxModule.version}`, `gapic/${version}`, ]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -123,7 +129,7 @@ export class ClusterControllerClient { // For browsers, pass the JSON content. const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json'); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require("../../protos/protos.json") : nodejsProtoPath @@ -133,16 +139,16 @@ export class ClusterControllerClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - projectLocationAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectLocationAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/autoscalingPolicies/{autoscaling_policy}' ), - projectLocationWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectLocationWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/workflowTemplates/{workflow_template}' ), - projectRegionAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectRegionAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/autoscalingPolicies/{autoscaling_policy}' ), - projectRegionWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectRegionWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/workflowTemplates/{workflow_template}' ), }; @@ -152,19 +158,19 @@ export class ClusterControllerClient { // pages). Denote the keys used for pagination and results. this._descriptors.page = { listClusters: - new gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'clusters') + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'clusters') }; // This API contains "long-running operations", which return a // an Operation object that allows for tracking of the operation, // rather than holding a request open. const protoFilesRoot = opts.fallback? - gaxModule.protobuf.Root.fromJSON(require("../../protos/protos.json")) : - gaxModule.protobuf.loadSync(nodejsProtoPath); + this._gaxModule.protobuf.Root.fromJSON(require("../../protos/protos.json")) : + this._gaxModule.protobuf.loadSync(nodejsProtoPath); - this.operationsClient = gaxModule.lro({ + this.operationsClient = this._gaxModule.lro({ auth: this.auth, - grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined + grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined }).operationsClient(opts); const createClusterResponse = protoFilesRoot.lookup( '.google.cloud.dataproc.v1beta2.Cluster') as gax.protobuf.Type; @@ -184,26 +190,26 @@ export class ClusterControllerClient { '.google.cloud.dataproc.v1beta2.ClusterOperationMetadata') as gax.protobuf.Type; this._descriptors.longrunning = { - createCluster: new gaxModule.LongrunningDescriptor( + createCluster: new this._gaxModule.LongrunningDescriptor( this.operationsClient, createClusterResponse.decode.bind(createClusterResponse), createClusterMetadata.decode.bind(createClusterMetadata)), - updateCluster: new gaxModule.LongrunningDescriptor( + updateCluster: new this._gaxModule.LongrunningDescriptor( this.operationsClient, updateClusterResponse.decode.bind(updateClusterResponse), updateClusterMetadata.decode.bind(updateClusterMetadata)), - deleteCluster: new gaxModule.LongrunningDescriptor( + deleteCluster: new this._gaxModule.LongrunningDescriptor( this.operationsClient, deleteClusterResponse.decode.bind(deleteClusterResponse), deleteClusterMetadata.decode.bind(deleteClusterMetadata)), - diagnoseCluster: new gaxModule.LongrunningDescriptor( + diagnoseCluster: new this._gaxModule.LongrunningDescriptor( this.operationsClient, diagnoseClusterResponse.decode.bind(diagnoseClusterResponse), diagnoseClusterMetadata.decode.bind(diagnoseClusterMetadata)) }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.cloud.dataproc.v1beta2.ClusterController', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); @@ -211,15 +217,33 @@ export class ClusterControllerClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.clusterControllerStub) { + return this.clusterControllerStub; + } // Put together the "service stub" for // google.cloud.dataproc.v1beta2.ClusterController. - this.clusterControllerStub = gaxGrpc.createStub( - opts.fallback ? - (protos as protobuf.Root).lookupService('google.cloud.dataproc.v1beta2.ClusterController') : + this.clusterControllerStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.cloud.dataproc.v1beta2.ClusterController') : // tslint:disable-next-line no-any - (protos as any).google.cloud.dataproc.v1beta2.ClusterController, - opts) as Promise<{[method: string]: Function}>; + (this._protos as any).google.cloud.dataproc.v1beta2.ClusterController, + this._opts) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides // and create an API call method for each. @@ -238,9 +262,9 @@ export class ClusterControllerClient { throw err; }); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -254,6 +278,8 @@ export class ClusterControllerClient { return apiCall(argument, callOptions, callback); }; } + + return this.clusterControllerStub; } /** @@ -362,6 +388,7 @@ export class ClusterControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.getCluster(request, options, callback); } @@ -381,7 +408,7 @@ export class ClusterControllerClient { {}|undefined>): void; /** * Creates a cluster in a project. The returned - * [Operation.metadata][google.longrunning.Operation.metadata] will be + * {@link google.longrunning.Operation.metadata|Operation.metadata} will be * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1beta2#clusteroperationmetadata). * * @param {Object} request @@ -395,9 +422,9 @@ export class ClusterControllerClient { * Required. The cluster to create. * @param {string} [request.requestId] * Optional. A unique id used to identify the request. If the server - * receives two [CreateClusterRequest][google.cloud.dataproc.v1beta2.CreateClusterRequest] requests with the same + * receives two {@link google.cloud.dataproc.v1beta2.CreateClusterRequest|CreateClusterRequest} requests with the same * id, then the second request will be ignored and the - * first [google.longrunning.Operation][google.longrunning.Operation] created and stored in the backend + * first {@link google.longrunning.Operation|google.longrunning.Operation} created and stored in the backend * is returned. * * It is recommended to always set this value to a @@ -434,6 +461,7 @@ export class ClusterControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.createCluster(request, options, callback); } updateCluster( @@ -452,7 +480,7 @@ export class ClusterControllerClient { {}|undefined>): void; /** * Updates a cluster in a project. The returned - * [Operation.metadata][google.longrunning.Operation.metadata] will be + * {@link google.longrunning.Operation.metadata|Operation.metadata} will be * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1beta2#clusteroperationmetadata). * * @param {Object} request @@ -539,9 +567,9 @@ export class ClusterControllerClient { * * @param {string} [request.requestId] * Optional. A unique id used to identify the request. If the server - * receives two [UpdateClusterRequest][google.cloud.dataproc.v1beta2.UpdateClusterRequest] requests with the same + * receives two {@link google.cloud.dataproc.v1beta2.UpdateClusterRequest|UpdateClusterRequest} requests with the same * id, then the second request will be ignored and the - * first [google.longrunning.Operation][google.longrunning.Operation] created and stored in the + * first {@link google.longrunning.Operation|google.longrunning.Operation} created and stored in the * backend is returned. * * It is recommended to always set this value to a @@ -578,6 +606,7 @@ export class ClusterControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.updateCluster(request, options, callback); } deleteCluster( @@ -596,7 +625,7 @@ export class ClusterControllerClient { {}|undefined>): void; /** * Deletes a cluster in a project. The returned - * [Operation.metadata][google.longrunning.Operation.metadata] will be + * {@link google.longrunning.Operation.metadata|Operation.metadata} will be * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1beta2#clusteroperationmetadata). * * @param {Object} request @@ -613,9 +642,9 @@ export class ClusterControllerClient { * (with error NOT_FOUND) if cluster with specified UUID does not exist. * @param {string} [request.requestId] * Optional. A unique id used to identify the request. If the server - * receives two [DeleteClusterRequest][google.cloud.dataproc.v1beta2.DeleteClusterRequest] requests with the same + * receives two {@link google.cloud.dataproc.v1beta2.DeleteClusterRequest|DeleteClusterRequest} requests with the same * id, then the second request will be ignored and the - * first [google.longrunning.Operation][google.longrunning.Operation] created and stored in the + * first {@link google.longrunning.Operation|google.longrunning.Operation} created and stored in the * backend is returned. * * It is recommended to always set this value to a @@ -652,6 +681,7 @@ export class ClusterControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.deleteCluster(request, options, callback); } diagnoseCluster( @@ -670,12 +700,12 @@ export class ClusterControllerClient { {}|undefined>): void; /** * Gets cluster diagnostic information. The returned - * [Operation.metadata][google.longrunning.Operation.metadata] will be + * {@link google.longrunning.Operation.metadata|Operation.metadata} will be * [ClusterOperationMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1beta2#clusteroperationmetadata). * After the operation completes, - * [Operation.response][google.longrunning.Operation.response] + * {@link google.longrunning.Operation.response|Operation.response} * contains - * [Empty][google.protobuf.Empty]. + * {@link google.protobuf.Empty|Empty}. * * @param {Object} request * The request object that will be sent. @@ -715,6 +745,7 @@ export class ClusterControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.diagnoseCluster(request, options, callback); } listClusters( @@ -809,6 +840,7 @@ export class ClusterControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.listClusters(request, options, callback); } @@ -868,6 +900,7 @@ export class ClusterControllerClient { request = request || {}; options = options || {}; const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listClusters.createStream( this._innerApiCalls.listClusters as gax.GaxCall, request, @@ -1080,8 +1113,9 @@ export class ClusterControllerClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.clusterControllerStub.then(stub => { + return this.clusterControllerStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/src/v1beta2/job_controller_client.ts b/src/v1beta2/job_controller_client.ts index 141a294e..07899705 100644 --- a/src/v1beta2/job_controller_client.ts +++ b/src/v1beta2/job_controller_client.ts @@ -36,8 +36,13 @@ export class JobControllerClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; - jobControllerStub: Promise<{[name: string]: Function}>; + jobControllerStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of JobControllerClient. @@ -61,8 +66,6 @@ export class JobControllerClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -90,28 +93,31 @@ export class JobControllerClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof JobControllerClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (gaxGrpc.auth as gax.GoogleAuth); + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); // Determine the client header string. const clientHeader = [ - `gax/${gaxModule.version}`, + `gax/${this._gaxModule.version}`, `gapic/${version}`, ]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -121,7 +127,7 @@ export class JobControllerClient { // For browsers, pass the JSON content. const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json'); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require("../../protos/protos.json") : nodejsProtoPath @@ -131,16 +137,16 @@ export class JobControllerClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - projectLocationAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectLocationAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/autoscalingPolicies/{autoscaling_policy}' ), - projectLocationWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectLocationWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/workflowTemplates/{workflow_template}' ), - projectRegionAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectRegionAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/autoscalingPolicies/{autoscaling_policy}' ), - projectRegionWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectRegionWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/workflowTemplates/{workflow_template}' ), }; @@ -150,11 +156,11 @@ export class JobControllerClient { // pages). Denote the keys used for pagination and results. this._descriptors.page = { listJobs: - new gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'jobs') + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'jobs') }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.cloud.dataproc.v1beta2.JobController', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); @@ -162,15 +168,33 @@ export class JobControllerClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.jobControllerStub) { + return this.jobControllerStub; + } // Put together the "service stub" for // google.cloud.dataproc.v1beta2.JobController. - this.jobControllerStub = gaxGrpc.createStub( - opts.fallback ? - (protos as protobuf.Root).lookupService('google.cloud.dataproc.v1beta2.JobController') : + this.jobControllerStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.cloud.dataproc.v1beta2.JobController') : // tslint:disable-next-line no-any - (protos as any).google.cloud.dataproc.v1beta2.JobController, - opts) as Promise<{[method: string]: Function}>; + (this._protos as any).google.cloud.dataproc.v1beta2.JobController, + this._opts) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides // and create an API call method for each. @@ -189,9 +213,9 @@ export class JobControllerClient { throw err; }); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -205,6 +229,8 @@ export class JobControllerClient { return apiCall(argument, callOptions, callback); }; } + + return this.jobControllerStub; } /** @@ -286,9 +312,9 @@ export class JobControllerClient { * Required. The job resource. * @param {string} [request.requestId] * Optional. A unique id used to identify the request. If the server - * receives two [SubmitJobRequest][google.cloud.dataproc.v1beta2.SubmitJobRequest] requests with the same + * receives two {@link google.cloud.dataproc.v1beta2.SubmitJobRequest|SubmitJobRequest} requests with the same * id, then the second request will be ignored and the - * first [Job][google.cloud.dataproc.v1beta2.Job] created and stored in the backend + * first {@link google.cloud.dataproc.v1beta2.Job|Job} created and stored in the backend * is returned. * * It is recommended to always set this value to a @@ -325,6 +351,7 @@ export class JobControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.submitJob(request, options, callback); } getJob( @@ -382,6 +409,7 @@ export class JobControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.getJob(request, options, callback); } updateJob( @@ -448,6 +476,7 @@ export class JobControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.updateJob(request, options, callback); } cancelJob( @@ -509,6 +538,7 @@ export class JobControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.cancelJob(request, options, callback); } deleteJob( @@ -567,6 +597,7 @@ export class JobControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.deleteJob(request, options, callback); } @@ -666,6 +697,7 @@ export class JobControllerClient { options = optionsOrCallback as gax.CallOptions; } options = options || {}; + this.initialize(); return this._innerApiCalls.listJobs(request, options, callback); } @@ -729,6 +761,7 @@ export class JobControllerClient { request = request || {}; options = options || {}; const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listJobs.createStream( this._innerApiCalls.listJobs as gax.GaxCall, request, @@ -941,8 +974,9 @@ export class JobControllerClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.jobControllerStub.then(stub => { + return this.jobControllerStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/src/v1beta2/workflow_template_service_client.ts b/src/v1beta2/workflow_template_service_client.ts index 964bfe40..3dc647a6 100644 --- a/src/v1beta2/workflow_template_service_client.ts +++ b/src/v1beta2/workflow_template_service_client.ts @@ -37,9 +37,14 @@ export class WorkflowTemplateServiceClient { private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; private _terminated = false; + private _opts: ClientOptions; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; auth: gax.GoogleAuth; operationsClient: gax.OperationsClient; - workflowTemplateServiceStub: Promise<{[name: string]: Function}>; + workflowTemplateServiceStub?: Promise<{[name: string]: Function}>; /** * Construct an instance of WorkflowTemplateServiceClient. @@ -63,8 +68,6 @@ export class WorkflowTemplateServiceClient { * app is running in an environment which supports * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, * your project ID will be detected automatically. - * @param {function} [options.promise] - Custom promise module to use instead - * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the * API remote host. */ @@ -92,28 +95,31 @@ export class WorkflowTemplateServiceClient { // If we are in browser, we are already using fallback because of the // "browser" field in package.json. // But if we were explicitly requested to use fallback, let's do it now. - const gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; + this._gaxModule = !isBrowser && opts.fallback ? gax.fallback : gax; // Create a `gaxGrpc` object, with any grpc-specific options // sent to the client. opts.scopes = (this.constructor as typeof WorkflowTemplateServiceClient).scopes; - const gaxGrpc = new gaxModule.GrpcClient(opts); + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; // Save the auth object to the client, for use by other methods. - this.auth = (gaxGrpc.auth as gax.GoogleAuth); + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); // Determine the client header string. const clientHeader = [ - `gax/${gaxModule.version}`, + `gax/${this._gaxModule.version}`, `gapic/${version}`, ]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); } else { - clientHeader.push(`gl-web/${gaxModule.version}`); + clientHeader.push(`gl-web/${this._gaxModule.version}`); } if (!opts.fallback) { - clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`); + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); } if (opts.libName && opts.libVersion) { clientHeader.push(`${opts.libName}/${opts.libVersion}`); @@ -123,7 +129,7 @@ export class WorkflowTemplateServiceClient { // For browsers, pass the JSON content. const nodejsProtoPath = path.join(__dirname, '..', '..', 'protos', 'protos.json'); - const protos = gaxGrpc.loadProto( + this._protos = this._gaxGrpc.loadProto( opts.fallback ? require("../../protos/protos.json") : nodejsProtoPath @@ -133,16 +139,16 @@ export class WorkflowTemplateServiceClient { // identifiers to uniquely identify resources within the API. // Create useful helper objects for these. this._pathTemplates = { - projectLocationAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectLocationAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/autoscalingPolicies/{autoscaling_policy}' ), - projectLocationWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectLocationWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/locations/{location}/workflowTemplates/{workflow_template}' ), - projectRegionAutoscalingPolicyPathTemplate: new gaxModule.PathTemplate( + projectRegionAutoscalingPolicyPathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/autoscalingPolicies/{autoscaling_policy}' ), - projectRegionWorkflowTemplatePathTemplate: new gaxModule.PathTemplate( + projectRegionWorkflowTemplatePathTemplate: new this._gaxModule.PathTemplate( 'projects/{project}/regions/{region}/workflowTemplates/{workflow_template}' ), }; @@ -152,19 +158,19 @@ export class WorkflowTemplateServiceClient { // pages). Denote the keys used for pagination and results. this._descriptors.page = { listWorkflowTemplates: - new gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'templates') + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'templates') }; // This API contains "long-running operations", which return a // an Operation object that allows for tracking of the operation, // rather than holding a request open. const protoFilesRoot = opts.fallback? - gaxModule.protobuf.Root.fromJSON(require("../../protos/protos.json")) : - gaxModule.protobuf.loadSync(nodejsProtoPath); + this._gaxModule.protobuf.Root.fromJSON(require("../../protos/protos.json")) : + this._gaxModule.protobuf.loadSync(nodejsProtoPath); - this.operationsClient = gaxModule.lro({ + this.operationsClient = this._gaxModule.lro({ auth: this.auth, - grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined + grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined }).operationsClient(opts); const instantiateWorkflowTemplateResponse = protoFilesRoot.lookup( '.google.protobuf.Empty') as gax.protobuf.Type; @@ -176,18 +182,18 @@ export class WorkflowTemplateServiceClient { '.google.cloud.dataproc.v1beta2.WorkflowMetadata') as gax.protobuf.Type; this._descriptors.longrunning = { - instantiateWorkflowTemplate: new gaxModule.LongrunningDescriptor( + instantiateWorkflowTemplate: new this._gaxModule.LongrunningDescriptor( this.operationsClient, instantiateWorkflowTemplateResponse.decode.bind(instantiateWorkflowTemplateResponse), instantiateWorkflowTemplateMetadata.decode.bind(instantiateWorkflowTemplateMetadata)), - instantiateInlineWorkflowTemplate: new gaxModule.LongrunningDescriptor( + instantiateInlineWorkflowTemplate: new this._gaxModule.LongrunningDescriptor( this.operationsClient, instantiateInlineWorkflowTemplateResponse.decode.bind(instantiateInlineWorkflowTemplateResponse), instantiateInlineWorkflowTemplateMetadata.decode.bind(instantiateInlineWorkflowTemplateMetadata)) }; // Put together the default options sent with requests. - const defaults = gaxGrpc.constructSettings( + this._defaults = this._gaxGrpc.constructSettings( 'google.cloud.dataproc.v1beta2.WorkflowTemplateService', gapicConfig as gax.ClientConfig, opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); @@ -195,15 +201,33 @@ export class WorkflowTemplateServiceClient { // of calling the API is handled in `google-gax`, with this code // merely providing the destination and request information. this._innerApiCalls = {}; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.workflowTemplateServiceStub) { + return this.workflowTemplateServiceStub; + } // Put together the "service stub" for // google.cloud.dataproc.v1beta2.WorkflowTemplateService. - this.workflowTemplateServiceStub = gaxGrpc.createStub( - opts.fallback ? - (protos as protobuf.Root).lookupService('google.cloud.dataproc.v1beta2.WorkflowTemplateService') : + this.workflowTemplateServiceStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.cloud.dataproc.v1beta2.WorkflowTemplateService') : // tslint:disable-next-line no-any - (protos as any).google.cloud.dataproc.v1beta2.WorkflowTemplateService, - opts) as Promise<{[method: string]: Function}>; + (this._protos as any).google.cloud.dataproc.v1beta2.WorkflowTemplateService, + this._opts) as Promise<{[method: string]: Function}>; // Iterate over each of the methods that the service provides // and create an API call method for each. @@ -222,9 +246,9 @@ export class WorkflowTemplateServiceClient { throw err; }); - const apiCall = gaxModule.createApiCall( + const apiCall = this._gaxModule.createApiCall( innerCallPromise, - defaults[methodName], + this._defaults[methodName], this._descriptors.page[methodName] || this._descriptors.stream[methodName] || this._descriptors.longrunning[methodName] @@ -238,6 +262,8 @@ export class WorkflowTemplateServiceClient { return apiCall(argument, callOptions, callback); }; } + + return this.workflowTemplateServiceStub; } /** @@ -359,6 +385,7 @@ export class WorkflowTemplateServiceClient { ] = gax.routingHeader.fromParams({ 'parent': request.parent || '', }); + this.initialize(); return this._innerApiCalls.createWorkflowTemplate(request, options, callback); } getWorkflowTemplate( @@ -435,6 +462,7 @@ export class WorkflowTemplateServiceClient { ] = gax.routingHeader.fromParams({ 'name': request.name || '', }); + this.initialize(); return this._innerApiCalls.getWorkflowTemplate(request, options, callback); } updateWorkflowTemplate( @@ -497,6 +525,7 @@ export class WorkflowTemplateServiceClient { ] = gax.routingHeader.fromParams({ 'template.name': request.template!.name || '', }); + this.initialize(); return this._innerApiCalls.updateWorkflowTemplate(request, options, callback); } deleteWorkflowTemplate( @@ -569,6 +598,7 @@ export class WorkflowTemplateServiceClient { ] = gax.routingHeader.fromParams({ 'name': request.name || '', }); + this.initialize(); return this._innerApiCalls.deleteWorkflowTemplate(request, options, callback); } @@ -591,22 +621,22 @@ export class WorkflowTemplateServiceClient { * * The returned Operation can be used to track execution of * workflow by polling - * [operations.get][google.longrunning.Operations.GetOperation]. + * {@link google.longrunning.Operations.GetOperation|operations.get}. * The Operation will complete when entire workflow is finished. * * The running workflow can be aborted via - * [operations.cancel][google.longrunning.Operations.CancelOperation]. + * {@link google.longrunning.Operations.CancelOperation|operations.cancel}. * This will cause any inflight jobs to be cancelled and workflow-owned * clusters to be deleted. * - * The [Operation.metadata][google.longrunning.Operation.metadata] will be + * The {@link google.longrunning.Operation.metadata|Operation.metadata} will be * [WorkflowMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1beta2#workflowmetadata). * Also see [Using * WorkflowMetadata](https://cloud.google.com/dataproc/docs/concepts/workflows/debugging#using_workflowmetadata). * * On successful completion, - * [Operation.response][google.longrunning.Operation.response] will be - * [Empty][google.protobuf.Empty]. + * {@link google.longrunning.Operation.response|Operation.response} will be + * {@link google.protobuf.Empty|Empty}. * * @param {Object} request * The request object that will be sent. @@ -679,6 +709,7 @@ export class WorkflowTemplateServiceClient { ] = gax.routingHeader.fromParams({ 'name': request.name || '', }); + this.initialize(); return this._innerApiCalls.instantiateWorkflowTemplate(request, options, callback); } instantiateInlineWorkflowTemplate( @@ -699,27 +730,27 @@ export class WorkflowTemplateServiceClient { * Instantiates a template and begins execution. * * This method is equivalent to executing the sequence - * [CreateWorkflowTemplate][google.cloud.dataproc.v1beta2.WorkflowTemplateService.CreateWorkflowTemplate], [InstantiateWorkflowTemplate][google.cloud.dataproc.v1beta2.WorkflowTemplateService.InstantiateWorkflowTemplate], - * [DeleteWorkflowTemplate][google.cloud.dataproc.v1beta2.WorkflowTemplateService.DeleteWorkflowTemplate]. + * {@link google.cloud.dataproc.v1beta2.WorkflowTemplateService.CreateWorkflowTemplate|CreateWorkflowTemplate}, {@link google.cloud.dataproc.v1beta2.WorkflowTemplateService.InstantiateWorkflowTemplate|InstantiateWorkflowTemplate}, + * {@link google.cloud.dataproc.v1beta2.WorkflowTemplateService.DeleteWorkflowTemplate|DeleteWorkflowTemplate}. * * The returned Operation can be used to track execution of * workflow by polling - * [operations.get][google.longrunning.Operations.GetOperation]. + * {@link google.longrunning.Operations.GetOperation|operations.get}. * The Operation will complete when entire workflow is finished. * * The running workflow can be aborted via - * [operations.cancel][google.longrunning.Operations.CancelOperation]. + * {@link google.longrunning.Operations.CancelOperation|operations.cancel}. * This will cause any inflight jobs to be cancelled and workflow-owned * clusters to be deleted. * - * The [Operation.metadata][google.longrunning.Operation.metadata] will be + * The {@link google.longrunning.Operation.metadata|Operation.metadata} will be * [WorkflowMetadata](https://cloud.google.com/dataproc/docs/reference/rpc/google.cloud.dataproc.v1#workflowmetadata). * Also see [Using * WorkflowMetadata](https://cloud.google.com/dataproc/docs/concepts/workflows/debugging#using_workflowmetadata). * * On successful completion, - * [Operation.response][google.longrunning.Operation.response] will be - * [Empty][google.protobuf.Empty]. + * {@link google.longrunning.Operation.response|Operation.response} will be + * {@link google.protobuf.Empty|Empty}. * * @param {Object} request * The request object that will be sent. @@ -784,6 +815,7 @@ export class WorkflowTemplateServiceClient { ] = gax.routingHeader.fromParams({ 'parent': request.parent || '', }); + this.initialize(); return this._innerApiCalls.instantiateInlineWorkflowTemplate(request, options, callback); } listWorkflowTemplates( @@ -872,6 +904,7 @@ export class WorkflowTemplateServiceClient { ] = gax.routingHeader.fromParams({ 'parent': request.parent || '', }); + this.initialize(); return this._innerApiCalls.listWorkflowTemplates(request, options, callback); } @@ -925,6 +958,7 @@ export class WorkflowTemplateServiceClient { 'parent': request.parent || '', }); const callSettings = new gax.CallSettings(options); + this.initialize(); return this._descriptors.page.listWorkflowTemplates.createStream( this._innerApiCalls.listWorkflowTemplates as gax.GaxCall, request, @@ -1137,8 +1171,9 @@ export class WorkflowTemplateServiceClient { * The client will no longer be usable and all future behavior is undefined. */ close(): Promise { + this.initialize(); if (!this._terminated) { - return this.workflowTemplateServiceStub.then(stub => { + return this.workflowTemplateServiceStub!.then(stub => { this._terminated = true; stub.close(); }); diff --git a/synth.metadata b/synth.metadata index 26d83542..441fe5d8 100644 --- a/synth.metadata +++ b/synth.metadata @@ -1,13 +1,13 @@ { - "updateTime": "2020-03-01T12:21:45.590214Z", + "updateTime": "2020-03-05T23:05:26.554565Z", "sources": [ { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "83c6f84035ee0f80eaa44d8b688a010461cc4080", - "internalRef": "297918498", - "log": "83c6f84035ee0f80eaa44d8b688a010461cc4080\nUpdate google/api/auth.proto to make AuthProvider to have JwtLocation\n\nPiperOrigin-RevId: 297918498\n\ne9e90a787703ec5d388902e2cb796aaed3a385b4\nDialogflow weekly v2/v2beta1 library update:\n - adding get validation result\n - adding field mask override control for output audio config\nImportant updates are also posted at:\nhttps://cloud.google.com/dialogflow/docs/release-notes\n\nPiperOrigin-RevId: 297671458\n\n1a2b05cc3541a5f7714529c665aecc3ea042c646\nAdding .yaml and .json config files.\n\nPiperOrigin-RevId: 297570622\n\ndfe1cf7be44dee31d78f78e485d8c95430981d6e\nPublish `QueryOptions` proto.\n\nIntroduced a `query_options` input in `ExecuteSqlRequest`.\n\nPiperOrigin-RevId: 297497710\n\ndafc905f71e5d46f500b41ed715aad585be062c3\npubsub: revert pull init_rpc_timeout & max_rpc_timeout back to 25 seconds and reset multiplier to 1.0\n\nPiperOrigin-RevId: 297486523\n\nf077632ba7fee588922d9e8717ee272039be126d\nfirestore: add update_transform\n\nPiperOrigin-RevId: 297405063\n\n" + "sha": "f0b581b5bdf803e45201ecdb3688b60e381628a8", + "internalRef": "299181282", + "log": "f0b581b5bdf803e45201ecdb3688b60e381628a8\nfix: recommendationengine/v1beta1 update some comments\n\nPiperOrigin-RevId: 299181282\n\n10e9a0a833dc85ff8f05b2c67ebe5ac785fe04ff\nbuild: add generated BUILD file for Routes Preferred API\n\nPiperOrigin-RevId: 299164808\n\n86738c956a8238d7c77f729be78b0ed887a6c913\npublish v1p1beta1: update with absolute address in comments\n\nPiperOrigin-RevId: 299152383\n\n73d9f2ad4591de45c2e1f352bc99d70cbd2a6d95\npublish v1: update with absolute address in comments\n\nPiperOrigin-RevId: 299147194\n\nd2158f24cb77b0b0ccfe68af784c6a628705e3c6\npublish v1beta2: update with absolute address in comments\n\nPiperOrigin-RevId: 299147086\n\n7fca61292c11b4cd5b352cee1a50bf88819dd63b\npublish v1p2beta1: update with absolute address in comments\n\nPiperOrigin-RevId: 299146903\n\n583b7321624736e2c490e328f4b1957335779295\npublish v1p3beta1: update with absolute address in comments\n\nPiperOrigin-RevId: 299146674\n\n638253bf86d1ce1c314108a089b7351440c2f0bf\nfix: add java_multiple_files option for automl text_sentiment.proto\n\nPiperOrigin-RevId: 298971070\n\n373d655703bf914fb8b0b1cc4071d772bac0e0d1\nUpdate Recs AI Beta public bazel file\n\nPiperOrigin-RevId: 298961623\n\ndcc5d00fc8a8d8b56f16194d7c682027b2c66a3b\nfix: add java_multiple_files option for automl classification.proto\n\nPiperOrigin-RevId: 298953301\n\na3f791827266f3496a6a5201d58adc4bb265c2a3\nchore: automl/v1 publish annotations and retry config\n\nPiperOrigin-RevId: 298942178\n\n01c681586d8d6dbd60155289b587aee678530bd9\nMark return_immediately in PullRequest deprecated.\n\nPiperOrigin-RevId: 298893281\n\nc9f5e9c4bfed54bbd09227e990e7bded5f90f31c\nRemove out of date documentation for predicate support on the Storage API\n\nPiperOrigin-RevId: 298883309\n\nfd5b3b8238d783b04692a113ffe07c0363f5de0f\ngenerate webrisk v1 proto\n\nPiperOrigin-RevId: 298847934\n\n541b1ded4abadcc38e8178680b0677f65594ea6f\nUpdate cloud asset api v1p4beta1.\n\nPiperOrigin-RevId: 298686266\n\nc0d171acecb4f5b0bfd2c4ca34fc54716574e300\n Updated to include the Notification v1 API.\n\nPiperOrigin-RevId: 298652775\n\n2346a9186c0bff2c9cc439f2459d558068637e05\nAdd Service Directory v1beta1 protos and configs\n\nPiperOrigin-RevId: 298625638\n\na78ed801b82a5c6d9c5368e24b1412212e541bb7\nPublishing v3 protos and configs.\n\nPiperOrigin-RevId: 298607357\n\n4a180bfff8a21645b3a935c2756e8d6ab18a74e0\nautoml/v1beta1 publish proto updates\n\nPiperOrigin-RevId: 298484782\n\n6de6e938b7df1cd62396563a067334abeedb9676\nchore: use the latest gapic-generator and protoc-java-resource-name-plugin in Bazel workspace.\n\nPiperOrigin-RevId: 298474513\n\n244ab2b83a82076a1fa7be63b7e0671af73f5c02\nAdds service config definition for bigqueryreservation v1\n\nPiperOrigin-RevId: 298455048\n\n" } }, { diff --git a/test/gapic-autoscaling_policy_service-v1.ts b/test/gapic-autoscaling_policy_service-v1.ts index e07adcdf..890c8e07 100644 --- a/test/gapic-autoscaling_policy_service-v1.ts +++ b/test/gapic-autoscaling_policy_service-v1.ts @@ -78,12 +78,30 @@ describe('v1.AutoscalingPolicyServiceClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new autoscalingpolicyserviceModule.v1.AutoscalingPolicyServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.autoscalingPolicyServiceStub, undefined); + await client.initialize(); + assert(client.autoscalingPolicyServiceStub); + }); + it('has close method', () => { + const client = new autoscalingpolicyserviceModule.v1.AutoscalingPolicyServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.close(); + }); describe('createAutoscalingPolicy', () => { it('invokes createAutoscalingPolicy without error', done => { const client = new autoscalingpolicyserviceModule.v1.AutoscalingPolicyServiceClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.ICreateAutoscalingPolicyRequest = {}; request.parent = ''; @@ -107,6 +125,8 @@ describe('v1.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.ICreateAutoscalingPolicyRequest = {}; request.parent = ''; @@ -132,6 +152,8 @@ describe('v1.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IUpdateAutoscalingPolicyRequest = {}; request.policy = {}; @@ -156,6 +178,8 @@ describe('v1.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IUpdateAutoscalingPolicyRequest = {}; request.policy = {}; @@ -182,6 +206,8 @@ describe('v1.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IGetAutoscalingPolicyRequest = {}; request.name = ''; @@ -205,6 +231,8 @@ describe('v1.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IGetAutoscalingPolicyRequest = {}; request.name = ''; @@ -230,6 +258,8 @@ describe('v1.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IDeleteAutoscalingPolicyRequest = {}; request.name = ''; @@ -253,6 +283,8 @@ describe('v1.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IDeleteAutoscalingPolicyRequest = {}; request.name = ''; @@ -278,6 +310,8 @@ describe('v1.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IListAutoscalingPoliciesRequest = {}; request.parent = ''; @@ -301,6 +335,8 @@ describe('v1.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IListAutoscalingPoliciesRequest = {}; request.parent = ''; diff --git a/test/gapic-autoscaling_policy_service-v1beta2.ts b/test/gapic-autoscaling_policy_service-v1beta2.ts index c983e633..463f428d 100644 --- a/test/gapic-autoscaling_policy_service-v1beta2.ts +++ b/test/gapic-autoscaling_policy_service-v1beta2.ts @@ -78,12 +78,30 @@ describe('v1beta2.AutoscalingPolicyServiceClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new autoscalingpolicyserviceModule.v1beta2.AutoscalingPolicyServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.autoscalingPolicyServiceStub, undefined); + await client.initialize(); + assert(client.autoscalingPolicyServiceStub); + }); + it('has close method', () => { + const client = new autoscalingpolicyserviceModule.v1beta2.AutoscalingPolicyServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.close(); + }); describe('createAutoscalingPolicy', () => { it('invokes createAutoscalingPolicy without error', done => { const client = new autoscalingpolicyserviceModule.v1beta2.AutoscalingPolicyServiceClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.ICreateAutoscalingPolicyRequest = {}; request.parent = ''; @@ -107,6 +125,8 @@ describe('v1beta2.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.ICreateAutoscalingPolicyRequest = {}; request.parent = ''; @@ -132,6 +152,8 @@ describe('v1beta2.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IUpdateAutoscalingPolicyRequest = {}; request.policy = {}; @@ -156,6 +178,8 @@ describe('v1beta2.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IUpdateAutoscalingPolicyRequest = {}; request.policy = {}; @@ -182,6 +206,8 @@ describe('v1beta2.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IGetAutoscalingPolicyRequest = {}; request.name = ''; @@ -205,6 +231,8 @@ describe('v1beta2.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IGetAutoscalingPolicyRequest = {}; request.name = ''; @@ -230,6 +258,8 @@ describe('v1beta2.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IDeleteAutoscalingPolicyRequest = {}; request.name = ''; @@ -253,6 +283,8 @@ describe('v1beta2.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IDeleteAutoscalingPolicyRequest = {}; request.name = ''; @@ -278,6 +310,8 @@ describe('v1beta2.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IListAutoscalingPoliciesRequest = {}; request.parent = ''; @@ -301,6 +335,8 @@ describe('v1beta2.AutoscalingPolicyServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IListAutoscalingPoliciesRequest = {}; request.parent = ''; diff --git a/test/gapic-cluster_controller-v1.ts b/test/gapic-cluster_controller-v1.ts index e6538802..7204f54c 100644 --- a/test/gapic-cluster_controller-v1.ts +++ b/test/gapic-cluster_controller-v1.ts @@ -96,12 +96,30 @@ describe('v1.ClusterControllerClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new clustercontrollerModule.v1.ClusterControllerClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.clusterControllerStub, undefined); + await client.initialize(); + assert(client.clusterControllerStub); + }); + it('has close method', () => { + const client = new clustercontrollerModule.v1.ClusterControllerClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.close(); + }); describe('getCluster', () => { it('invokes getCluster without error', done => { const client = new clustercontrollerModule.v1.ClusterControllerClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IGetClusterRequest = {}; // Mock response @@ -124,6 +142,8 @@ describe('v1.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IGetClusterRequest = {}; // Mock response @@ -148,6 +168,8 @@ describe('v1.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.ICreateClusterRequest = {}; // Mock response @@ -173,6 +195,8 @@ describe('v1.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.ICreateClusterRequest = {}; // Mock response @@ -201,6 +225,8 @@ describe('v1.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IUpdateClusterRequest = {}; // Mock response @@ -226,6 +252,8 @@ describe('v1.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IUpdateClusterRequest = {}; // Mock response @@ -254,6 +282,8 @@ describe('v1.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IDeleteClusterRequest = {}; // Mock response @@ -279,6 +309,8 @@ describe('v1.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IDeleteClusterRequest = {}; // Mock response @@ -307,6 +339,8 @@ describe('v1.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IDiagnoseClusterRequest = {}; // Mock response @@ -332,6 +366,8 @@ describe('v1.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IDiagnoseClusterRequest = {}; // Mock response @@ -360,6 +396,8 @@ describe('v1.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IListClustersRequest = {}; // Mock response @@ -382,6 +420,8 @@ describe('v1.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IListClustersRequest = {}; // Mock response diff --git a/test/gapic-cluster_controller-v1beta2.ts b/test/gapic-cluster_controller-v1beta2.ts index 7ea9fa4f..b9fc901d 100644 --- a/test/gapic-cluster_controller-v1beta2.ts +++ b/test/gapic-cluster_controller-v1beta2.ts @@ -96,12 +96,30 @@ describe('v1beta2.ClusterControllerClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new clustercontrollerModule.v1beta2.ClusterControllerClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.clusterControllerStub, undefined); + await client.initialize(); + assert(client.clusterControllerStub); + }); + it('has close method', () => { + const client = new clustercontrollerModule.v1beta2.ClusterControllerClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.close(); + }); describe('getCluster', () => { it('invokes getCluster without error', done => { const client = new clustercontrollerModule.v1beta2.ClusterControllerClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IGetClusterRequest = {}; // Mock response @@ -124,6 +142,8 @@ describe('v1beta2.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IGetClusterRequest = {}; // Mock response @@ -148,6 +168,8 @@ describe('v1beta2.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.ICreateClusterRequest = {}; // Mock response @@ -173,6 +195,8 @@ describe('v1beta2.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.ICreateClusterRequest = {}; // Mock response @@ -201,6 +225,8 @@ describe('v1beta2.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IUpdateClusterRequest = {}; // Mock response @@ -226,6 +252,8 @@ describe('v1beta2.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IUpdateClusterRequest = {}; // Mock response @@ -254,6 +282,8 @@ describe('v1beta2.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IDeleteClusterRequest = {}; // Mock response @@ -279,6 +309,8 @@ describe('v1beta2.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IDeleteClusterRequest = {}; // Mock response @@ -307,6 +339,8 @@ describe('v1beta2.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IDiagnoseClusterRequest = {}; // Mock response @@ -332,6 +366,8 @@ describe('v1beta2.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IDiagnoseClusterRequest = {}; // Mock response @@ -360,6 +396,8 @@ describe('v1beta2.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IListClustersRequest = {}; // Mock response @@ -382,6 +420,8 @@ describe('v1beta2.ClusterControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IListClustersRequest = {}; // Mock response diff --git a/test/gapic-job_controller-v1.ts b/test/gapic-job_controller-v1.ts index cf2de18a..7b9746cc 100644 --- a/test/gapic-job_controller-v1.ts +++ b/test/gapic-job_controller-v1.ts @@ -78,12 +78,30 @@ describe('v1.JobControllerClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new jobcontrollerModule.v1.JobControllerClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.jobControllerStub, undefined); + await client.initialize(); + assert(client.jobControllerStub); + }); + it('has close method', () => { + const client = new jobcontrollerModule.v1.JobControllerClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.close(); + }); describe('submitJob', () => { it('invokes submitJob without error', done => { const client = new jobcontrollerModule.v1.JobControllerClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.ISubmitJobRequest = {}; // Mock response @@ -106,6 +124,8 @@ describe('v1.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.ISubmitJobRequest = {}; // Mock response @@ -130,6 +150,8 @@ describe('v1.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IGetJobRequest = {}; // Mock response @@ -152,6 +174,8 @@ describe('v1.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IGetJobRequest = {}; // Mock response @@ -176,6 +200,8 @@ describe('v1.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IUpdateJobRequest = {}; // Mock response @@ -198,6 +224,8 @@ describe('v1.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IUpdateJobRequest = {}; // Mock response @@ -222,6 +250,8 @@ describe('v1.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.ICancelJobRequest = {}; // Mock response @@ -244,6 +274,8 @@ describe('v1.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.ICancelJobRequest = {}; // Mock response @@ -268,6 +300,8 @@ describe('v1.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IDeleteJobRequest = {}; // Mock response @@ -290,6 +324,8 @@ describe('v1.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IDeleteJobRequest = {}; // Mock response @@ -314,6 +350,8 @@ describe('v1.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IListJobsRequest = {}; // Mock response @@ -336,6 +374,8 @@ describe('v1.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IListJobsRequest = {}; // Mock response diff --git a/test/gapic-job_controller-v1beta2.ts b/test/gapic-job_controller-v1beta2.ts index 8b49868d..11e0aa05 100644 --- a/test/gapic-job_controller-v1beta2.ts +++ b/test/gapic-job_controller-v1beta2.ts @@ -78,12 +78,30 @@ describe('v1beta2.JobControllerClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new jobcontrollerModule.v1beta2.JobControllerClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.jobControllerStub, undefined); + await client.initialize(); + assert(client.jobControllerStub); + }); + it('has close method', () => { + const client = new jobcontrollerModule.v1beta2.JobControllerClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.close(); + }); describe('submitJob', () => { it('invokes submitJob without error', done => { const client = new jobcontrollerModule.v1beta2.JobControllerClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.ISubmitJobRequest = {}; // Mock response @@ -106,6 +124,8 @@ describe('v1beta2.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.ISubmitJobRequest = {}; // Mock response @@ -130,6 +150,8 @@ describe('v1beta2.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IGetJobRequest = {}; // Mock response @@ -152,6 +174,8 @@ describe('v1beta2.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IGetJobRequest = {}; // Mock response @@ -176,6 +200,8 @@ describe('v1beta2.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IUpdateJobRequest = {}; // Mock response @@ -198,6 +224,8 @@ describe('v1beta2.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IUpdateJobRequest = {}; // Mock response @@ -222,6 +250,8 @@ describe('v1beta2.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.ICancelJobRequest = {}; // Mock response @@ -244,6 +274,8 @@ describe('v1beta2.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.ICancelJobRequest = {}; // Mock response @@ -268,6 +300,8 @@ describe('v1beta2.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IDeleteJobRequest = {}; // Mock response @@ -290,6 +324,8 @@ describe('v1beta2.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IDeleteJobRequest = {}; // Mock response @@ -314,6 +350,8 @@ describe('v1beta2.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IListJobsRequest = {}; // Mock response @@ -336,6 +374,8 @@ describe('v1beta2.JobControllerClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IListJobsRequest = {}; // Mock response diff --git a/test/gapic-workflow_template_service-v1.ts b/test/gapic-workflow_template_service-v1.ts index 63470a4d..4b9ffa45 100644 --- a/test/gapic-workflow_template_service-v1.ts +++ b/test/gapic-workflow_template_service-v1.ts @@ -96,12 +96,30 @@ describe('v1.WorkflowTemplateServiceClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new workflowtemplateserviceModule.v1.WorkflowTemplateServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.workflowTemplateServiceStub, undefined); + await client.initialize(); + assert(client.workflowTemplateServiceStub); + }); + it('has close method', () => { + const client = new workflowtemplateserviceModule.v1.WorkflowTemplateServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.close(); + }); describe('createWorkflowTemplate', () => { it('invokes createWorkflowTemplate without error', done => { const client = new workflowtemplateserviceModule.v1.WorkflowTemplateServiceClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.ICreateWorkflowTemplateRequest = {}; request.parent = ''; @@ -125,6 +143,8 @@ describe('v1.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.ICreateWorkflowTemplateRequest = {}; request.parent = ''; @@ -150,6 +170,8 @@ describe('v1.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IGetWorkflowTemplateRequest = {}; request.name = ''; @@ -173,6 +195,8 @@ describe('v1.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IGetWorkflowTemplateRequest = {}; request.name = ''; @@ -198,6 +222,8 @@ describe('v1.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IUpdateWorkflowTemplateRequest = {}; request.template = {}; @@ -222,6 +248,8 @@ describe('v1.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IUpdateWorkflowTemplateRequest = {}; request.template = {}; @@ -248,6 +276,8 @@ describe('v1.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IDeleteWorkflowTemplateRequest = {}; request.name = ''; @@ -271,6 +301,8 @@ describe('v1.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IDeleteWorkflowTemplateRequest = {}; request.name = ''; @@ -296,6 +328,8 @@ describe('v1.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IInstantiateWorkflowTemplateRequest = {}; request.name = ''; @@ -322,6 +356,8 @@ describe('v1.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IInstantiateWorkflowTemplateRequest = {}; request.name = ''; @@ -351,6 +387,8 @@ describe('v1.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IInstantiateInlineWorkflowTemplateRequest = {}; request.parent = ''; @@ -377,6 +415,8 @@ describe('v1.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IInstantiateInlineWorkflowTemplateRequest = {}; request.parent = ''; @@ -406,6 +446,8 @@ describe('v1.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IListWorkflowTemplatesRequest = {}; request.parent = ''; @@ -429,6 +471,8 @@ describe('v1.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1.IListWorkflowTemplatesRequest = {}; request.parent = ''; diff --git a/test/gapic-workflow_template_service-v1beta2.ts b/test/gapic-workflow_template_service-v1beta2.ts index 0514cdbf..7019065f 100644 --- a/test/gapic-workflow_template_service-v1beta2.ts +++ b/test/gapic-workflow_template_service-v1beta2.ts @@ -96,12 +96,30 @@ describe('v1beta2.WorkflowTemplateServiceClient', () => { }); assert(client); }); + it('has initialize method and supports deferred initialization', async () => { + const client = new workflowtemplateserviceModule.v1beta2.WorkflowTemplateServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + assert.strictEqual(client.workflowTemplateServiceStub, undefined); + await client.initialize(); + assert(client.workflowTemplateServiceStub); + }); + it('has close method', () => { + const client = new workflowtemplateserviceModule.v1beta2.WorkflowTemplateServiceClient({ + credentials: { client_email: 'bogus', private_key: 'bogus' }, + projectId: 'bogus', + }); + client.close(); + }); describe('createWorkflowTemplate', () => { it('invokes createWorkflowTemplate without error', done => { const client = new workflowtemplateserviceModule.v1beta2.WorkflowTemplateServiceClient({ credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.ICreateWorkflowTemplateRequest = {}; request.parent = ''; @@ -125,6 +143,8 @@ describe('v1beta2.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.ICreateWorkflowTemplateRequest = {}; request.parent = ''; @@ -150,6 +170,8 @@ describe('v1beta2.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IGetWorkflowTemplateRequest = {}; request.name = ''; @@ -173,6 +195,8 @@ describe('v1beta2.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IGetWorkflowTemplateRequest = {}; request.name = ''; @@ -198,6 +222,8 @@ describe('v1beta2.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IUpdateWorkflowTemplateRequest = {}; request.template = {}; @@ -222,6 +248,8 @@ describe('v1beta2.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IUpdateWorkflowTemplateRequest = {}; request.template = {}; @@ -248,6 +276,8 @@ describe('v1beta2.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IDeleteWorkflowTemplateRequest = {}; request.name = ''; @@ -271,6 +301,8 @@ describe('v1beta2.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IDeleteWorkflowTemplateRequest = {}; request.name = ''; @@ -296,6 +328,8 @@ describe('v1beta2.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IInstantiateWorkflowTemplateRequest = {}; request.name = ''; @@ -322,6 +356,8 @@ describe('v1beta2.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IInstantiateWorkflowTemplateRequest = {}; request.name = ''; @@ -351,6 +387,8 @@ describe('v1beta2.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IInstantiateInlineWorkflowTemplateRequest = {}; request.parent = ''; @@ -377,6 +415,8 @@ describe('v1beta2.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IInstantiateInlineWorkflowTemplateRequest = {}; request.parent = ''; @@ -406,6 +446,8 @@ describe('v1beta2.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IListWorkflowTemplatesRequest = {}; request.parent = ''; @@ -429,6 +471,8 @@ describe('v1beta2.WorkflowTemplateServiceClient', () => { credentials: {client_email: 'bogus', private_key: 'bogus'}, projectId: 'bogus', }); + // Initialize client before mocking + client.initialize(); // Mock request const request: protosTypes.google.cloud.dataproc.v1beta2.IListWorkflowTemplatesRequest = {}; request.parent = '';