Skip to content

Commit 563c43b

Browse files
feat: check status of long running operation by its name (#372)
For each client method returning a long running operation, a separate method to check its status is added. Added methods: `checkCreateClusterProgress`, `checkDeleteClusterProgress`, `checkDiagnoseClusterProgress`, `checkInstantiateInlineWorkflowTemplateProgress`, `checkInstantiateWorkflowTemplateProgress`, `checkSubmitJobAsOperationProgress`, `checkUpdateClusterProgress`.
1 parent 28feea4 commit 563c43b

16 files changed

+2031
-1013
lines changed

packages/google-cloud-dataproc/protos/protos.js

+774-774
Large diffs are not rendered by default.

packages/google-cloud-dataproc/src/v1/cluster_controller_client.ts

+145-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {Transform} from 'stream';
3232
import {RequestType} from 'google-gax/build/src/apitypes';
3333
import * as protos from '../../protos/protos';
3434
import * as gapicConfig from './cluster_controller_client_config.json';
35-
35+
import {operationsProtos} from 'google-gax';
3636
const version = require('../../../package.json').version;
3737

3838
/**
@@ -582,6 +582,42 @@ export class ClusterControllerClient {
582582
this.initialize();
583583
return this.innerApiCalls.createCluster(request, options, callback);
584584
}
585+
/**
586+
* Check the status of the long running operation returned by the createCluster() method.
587+
* @param {String} name
588+
* The operation name that will be passed.
589+
* @returns {Promise} - The promise which resolves to an object.
590+
* The decoded operation object has result and metadata field to get information from.
591+
*
592+
* @example:
593+
* const decodedOperation = await checkCreateClusterProgress(name);
594+
* console.log(decodedOperation.result);
595+
* console.log(decodedOperation.done);
596+
* console.log(decodedOperation.metadata);
597+
*
598+
*/
599+
async checkCreateClusterProgress(
600+
name: string
601+
): Promise<
602+
LROperation<
603+
protos.google.cloud.dataproc.v1.Cluster,
604+
protos.google.cloud.dataproc.v1.ClusterOperationMetadata
605+
>
606+
> {
607+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
608+
{name}
609+
);
610+
const [operation] = await this.operationsClient.getOperation(request);
611+
const decodeOperation = new gax.Operation(
612+
operation,
613+
this.descriptors.longrunning.createCluster,
614+
gax.createDefaultBackoffSettings()
615+
);
616+
return decodeOperation as LROperation<
617+
protos.google.cloud.dataproc.v1.Cluster,
618+
protos.google.cloud.dataproc.v1.ClusterOperationMetadata
619+
>;
620+
}
585621
updateCluster(
586622
request: protos.google.cloud.dataproc.v1.IUpdateClusterRequest,
587623
options?: gax.CallOptions
@@ -763,6 +799,42 @@ export class ClusterControllerClient {
763799
this.initialize();
764800
return this.innerApiCalls.updateCluster(request, options, callback);
765801
}
802+
/**
803+
* Check the status of the long running operation returned by the updateCluster() method.
804+
* @param {String} name
805+
* The operation name that will be passed.
806+
* @returns {Promise} - The promise which resolves to an object.
807+
* The decoded operation object has result and metadata field to get information from.
808+
*
809+
* @example:
810+
* const decodedOperation = await checkUpdateClusterProgress(name);
811+
* console.log(decodedOperation.result);
812+
* console.log(decodedOperation.done);
813+
* console.log(decodedOperation.metadata);
814+
*
815+
*/
816+
async checkUpdateClusterProgress(
817+
name: string
818+
): Promise<
819+
LROperation<
820+
protos.google.cloud.dataproc.v1.Cluster,
821+
protos.google.cloud.dataproc.v1.ClusterOperationMetadata
822+
>
823+
> {
824+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
825+
{name}
826+
);
827+
const [operation] = await this.operationsClient.getOperation(request);
828+
const decodeOperation = new gax.Operation(
829+
operation,
830+
this.descriptors.longrunning.updateCluster,
831+
gax.createDefaultBackoffSettings()
832+
);
833+
return decodeOperation as LROperation<
834+
protos.google.cloud.dataproc.v1.Cluster,
835+
protos.google.cloud.dataproc.v1.ClusterOperationMetadata
836+
>;
837+
}
766838
deleteCluster(
767839
request: protos.google.cloud.dataproc.v1.IDeleteClusterRequest,
768840
options?: gax.CallOptions
@@ -883,6 +955,42 @@ export class ClusterControllerClient {
883955
this.initialize();
884956
return this.innerApiCalls.deleteCluster(request, options, callback);
885957
}
958+
/**
959+
* Check the status of the long running operation returned by the deleteCluster() method.
960+
* @param {String} name
961+
* The operation name that will be passed.
962+
* @returns {Promise} - The promise which resolves to an object.
963+
* The decoded operation object has result and metadata field to get information from.
964+
*
965+
* @example:
966+
* const decodedOperation = await checkDeleteClusterProgress(name);
967+
* console.log(decodedOperation.result);
968+
* console.log(decodedOperation.done);
969+
* console.log(decodedOperation.metadata);
970+
*
971+
*/
972+
async checkDeleteClusterProgress(
973+
name: string
974+
): Promise<
975+
LROperation<
976+
protos.google.protobuf.Empty,
977+
protos.google.cloud.dataproc.v1.ClusterOperationMetadata
978+
>
979+
> {
980+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
981+
{name}
982+
);
983+
const [operation] = await this.operationsClient.getOperation(request);
984+
const decodeOperation = new gax.Operation(
985+
operation,
986+
this.descriptors.longrunning.deleteCluster,
987+
gax.createDefaultBackoffSettings()
988+
);
989+
return decodeOperation as LROperation<
990+
protos.google.protobuf.Empty,
991+
protos.google.cloud.dataproc.v1.ClusterOperationMetadata
992+
>;
993+
}
886994
diagnoseCluster(
887995
request: protos.google.cloud.dataproc.v1.IDiagnoseClusterRequest,
888996
options?: gax.CallOptions
@@ -992,6 +1100,42 @@ export class ClusterControllerClient {
9921100
this.initialize();
9931101
return this.innerApiCalls.diagnoseCluster(request, options, callback);
9941102
}
1103+
/**
1104+
* Check the status of the long running operation returned by the diagnoseCluster() method.
1105+
* @param {String} name
1106+
* The operation name that will be passed.
1107+
* @returns {Promise} - The promise which resolves to an object.
1108+
* The decoded operation object has result and metadata field to get information from.
1109+
*
1110+
* @example:
1111+
* const decodedOperation = await checkDiagnoseClusterProgress(name);
1112+
* console.log(decodedOperation.result);
1113+
* console.log(decodedOperation.done);
1114+
* console.log(decodedOperation.metadata);
1115+
*
1116+
*/
1117+
async checkDiagnoseClusterProgress(
1118+
name: string
1119+
): Promise<
1120+
LROperation<
1121+
protos.google.protobuf.Empty,
1122+
protos.google.cloud.dataproc.v1.DiagnoseClusterResults
1123+
>
1124+
> {
1125+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
1126+
{name}
1127+
);
1128+
const [operation] = await this.operationsClient.getOperation(request);
1129+
const decodeOperation = new gax.Operation(
1130+
operation,
1131+
this.descriptors.longrunning.diagnoseCluster,
1132+
gax.createDefaultBackoffSettings()
1133+
);
1134+
return decodeOperation as LROperation<
1135+
protos.google.protobuf.Empty,
1136+
protos.google.cloud.dataproc.v1.DiagnoseClusterResults
1137+
>;
1138+
}
9951139
listClusters(
9961140
request: protos.google.cloud.dataproc.v1.IListClustersRequest,
9971141
options?: gax.CallOptions

packages/google-cloud-dataproc/src/v1/job_controller_client.ts

+37-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {Transform} from 'stream';
3232
import {RequestType} from 'google-gax/build/src/apitypes';
3333
import * as protos from '../../protos/protos';
3434
import * as gapicConfig from './job_controller_client_config.json';
35-
35+
import {operationsProtos} from 'google-gax';
3636
const version = require('../../../package.json').version;
3737

3838
/**
@@ -913,6 +913,42 @@ export class JobControllerClient {
913913
this.initialize();
914914
return this.innerApiCalls.submitJobAsOperation(request, options, callback);
915915
}
916+
/**
917+
* Check the status of the long running operation returned by the submitJobAsOperation() method.
918+
* @param {String} name
919+
* The operation name that will be passed.
920+
* @returns {Promise} - The promise which resolves to an object.
921+
* The decoded operation object has result and metadata field to get information from.
922+
*
923+
* @example:
924+
* const decodedOperation = await checkSubmitJobAsOperationProgress(name);
925+
* console.log(decodedOperation.result);
926+
* console.log(decodedOperation.done);
927+
* console.log(decodedOperation.metadata);
928+
*
929+
*/
930+
async checkSubmitJobAsOperationProgress(
931+
name: string
932+
): Promise<
933+
LROperation<
934+
protos.google.cloud.dataproc.v1.Job,
935+
protos.google.cloud.dataproc.v1.JobMetadata
936+
>
937+
> {
938+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
939+
{name}
940+
);
941+
const [operation] = await this.operationsClient.getOperation(request);
942+
const decodeOperation = new gax.Operation(
943+
operation,
944+
this.descriptors.longrunning.submitJobAsOperation,
945+
gax.createDefaultBackoffSettings()
946+
);
947+
return decodeOperation as LROperation<
948+
protos.google.cloud.dataproc.v1.Job,
949+
protos.google.cloud.dataproc.v1.JobMetadata
950+
>;
951+
}
916952
listJobs(
917953
request: protos.google.cloud.dataproc.v1.IListJobsRequest,
918954
options?: gax.CallOptions

packages/google-cloud-dataproc/src/v1/workflow_template_service_client.ts

+73-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {Transform} from 'stream';
3232
import {RequestType} from 'google-gax/build/src/apitypes';
3333
import * as protos from '../../protos/protos';
3434
import * as gapicConfig from './workflow_template_service_client_config.json';
35-
35+
import {operationsProtos} from 'google-gax';
3636
const version = require('../../../package.json').version;
3737

3838
/**
@@ -949,6 +949,42 @@ export class WorkflowTemplateServiceClient {
949949
callback
950950
);
951951
}
952+
/**
953+
* Check the status of the long running operation returned by the instantiateWorkflowTemplate() method.
954+
* @param {String} name
955+
* The operation name that will be passed.
956+
* @returns {Promise} - The promise which resolves to an object.
957+
* The decoded operation object has result and metadata field to get information from.
958+
*
959+
* @example:
960+
* const decodedOperation = await checkInstantiateWorkflowTemplateProgress(name);
961+
* console.log(decodedOperation.result);
962+
* console.log(decodedOperation.done);
963+
* console.log(decodedOperation.metadata);
964+
*
965+
*/
966+
async checkInstantiateWorkflowTemplateProgress(
967+
name: string
968+
): Promise<
969+
LROperation<
970+
protos.google.protobuf.Empty,
971+
protos.google.cloud.dataproc.v1.WorkflowMetadata
972+
>
973+
> {
974+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
975+
{name}
976+
);
977+
const [operation] = await this.operationsClient.getOperation(request);
978+
const decodeOperation = new gax.Operation(
979+
operation,
980+
this.descriptors.longrunning.instantiateWorkflowTemplate,
981+
gax.createDefaultBackoffSettings()
982+
);
983+
return decodeOperation as LROperation<
984+
protos.google.protobuf.Empty,
985+
protos.google.cloud.dataproc.v1.WorkflowMetadata
986+
>;
987+
}
952988
instantiateInlineWorkflowTemplate(
953989
request: protos.google.cloud.dataproc.v1.IInstantiateInlineWorkflowTemplateRequest,
954990
options?: gax.CallOptions
@@ -1095,6 +1131,42 @@ export class WorkflowTemplateServiceClient {
10951131
callback
10961132
);
10971133
}
1134+
/**
1135+
* Check the status of the long running operation returned by the instantiateInlineWorkflowTemplate() method.
1136+
* @param {String} name
1137+
* The operation name that will be passed.
1138+
* @returns {Promise} - The promise which resolves to an object.
1139+
* The decoded operation object has result and metadata field to get information from.
1140+
*
1141+
* @example:
1142+
* const decodedOperation = await checkInstantiateInlineWorkflowTemplateProgress(name);
1143+
* console.log(decodedOperation.result);
1144+
* console.log(decodedOperation.done);
1145+
* console.log(decodedOperation.metadata);
1146+
*
1147+
*/
1148+
async checkInstantiateInlineWorkflowTemplateProgress(
1149+
name: string
1150+
): Promise<
1151+
LROperation<
1152+
protos.google.protobuf.Empty,
1153+
protos.google.cloud.dataproc.v1.WorkflowMetadata
1154+
>
1155+
> {
1156+
const request = new operationsProtos.google.longrunning.GetOperationRequest(
1157+
{name}
1158+
);
1159+
const [operation] = await this.operationsClient.getOperation(request);
1160+
const decodeOperation = new gax.Operation(
1161+
operation,
1162+
this.descriptors.longrunning.instantiateInlineWorkflowTemplate,
1163+
gax.createDefaultBackoffSettings()
1164+
);
1165+
return decodeOperation as LROperation<
1166+
protos.google.protobuf.Empty,
1167+
protos.google.cloud.dataproc.v1.WorkflowMetadata
1168+
>;
1169+
}
10981170
listWorkflowTemplates(
10991171
request: protos.google.cloud.dataproc.v1.IListWorkflowTemplatesRequest,
11001172
options?: gax.CallOptions

0 commit comments

Comments
 (0)