Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(diregapic)(LRO): Add minimum wrapper for mitigate future full-implementation diregapic LRO change #967

Merged
merged 8 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,19 @@ message GetRegionOperationRequest {

}

// A request message for RegionOperations.Wait. See the method description for details.
message WaitRegionOperationRequest {
// Name of the Operations resource to return.
string operation = 52090215 [(google.api.field_behavior) = REQUIRED];

// Project ID for this request.
string project = 227560217 [(google.api.field_behavior) = REQUIRED];

// Name of the region for this request.
string region = 138946292 [(google.api.field_behavior) = REQUIRED];

}

//
// Services
//
Expand Down Expand Up @@ -688,5 +701,16 @@ service RegionOperations {
option (google.api.method_signature) = "project,region,operation";
}

}
// Waits for the specified Operation resource to return as `DONE` or for the request to approach the 2 minute deadline, and retrieves the specified Operation resource. This method differs from the `GET` method in that it waits for no more than the default deadline (2 minutes) and then returns the current state of the operation, which might be `DONE` or still in progress.
//
// This method is called on a best-effort basis. Specifically:
// - In uncommon cases, when the server is overloaded, the request might return before the default deadline is reached, or might return after zero seconds.
// - If the default deadline is reached, there is no guarantee that the operation is actually done when the method returns. Be prepared to retry if the operation is not `DONE`.
rpc Wait(WaitRegionOperationRequest) returns (Operation) {
option (google.api.http) = {
post: "/compute/v1/projects/projects/{project}/regions/{region}/operations/{operation}/wait"
};
option (google.api.method_signature) = "project,region,operation";
}

}
60 changes: 43 additions & 17 deletions baselines/compute/src/v1/addresses_client.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/* global window */
import * as gax from 'google-gax';
import {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall} from 'google-gax';
import {Callback, CallOptions, Descriptors, ClientOptions, LROperation, PaginationCallback, GaxCall} from 'google-gax';

import { Transform } from 'stream';
import { RequestType } from 'google-gax/build/src/apitypes';
Expand Down Expand Up @@ -297,8 +297,8 @@ export class AddressesClient {
request?: protos.google.cloud.compute.v1.IDeleteAddressRequest,
options?: CallOptions):
Promise<[
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IDeleteAddressRequest|undefined, {}|undefined
LROperation<protos.google.cloud.compute.v1.IOperation, null>,
alexander-fenster marked this conversation as resolved.
Show resolved Hide resolved
protos.google.cloud.compute.v1.IOperation|undefined, {}|undefined
]>;
delete(
request: protos.google.cloud.compute.v1.IDeleteAddressRequest,
Expand Down Expand Up @@ -333,12 +333,17 @@ export class AddressesClient {
* @param {object} [options]
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [Operation]{@link google.cloud.compute.v1.Operation}.
* The first element of the array is an object representing
* a long running operation.
* Please see the
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations)
alexander-fenster marked this conversation as resolved.
Show resolved Hide resolved
* for more details and examples.
* This method is considered to be in beta. This means while
* stable it is still a work-in-progress and under active development,
* and might get backwards-incompatible changes at any time.
* `.promise()` is not supported yet.
summer-ji-eng marked this conversation as resolved.
Show resolved Hide resolved
* @example
* const [response] = await client.delete(request);
* const [operation] = await client.delete(request);
*/
delete(
request?: protos.google.cloud.compute.v1.IDeleteAddressRequest,
Expand All @@ -351,8 +356,8 @@ export class AddressesClient {
protos.google.cloud.compute.v1.IDeleteAddressRequest|null|undefined,
{}|null|undefined>):
Promise<[
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IDeleteAddressRequest|undefined, {}|undefined
LROperation<protos.google.cloud.compute.v1.IOperation, null>,
protos.google.cloud.compute.v1.IOperation|undefined, {}|undefined
]>|void {
request = request || {};
let options: CallOptions;
Expand All @@ -372,14 +377,22 @@ export class AddressesClient {
'project': request.project || '',
});
this.initialize();
return this.innerApiCalls.delete(request, options, callback);
return this.innerApiCalls.delete(request, options, callback)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need to disable no-explicit-any now :)

.then(([response, next, rawResponse]: [any, any, any]) => {
summer-ji-eng marked this conversation as resolved.
Show resolved Hide resolved
return [
{ latestResponse: response, done: false, name: response.id, metadata: null, result: {}},
next,
rawResponse
];
});
}
insert(
request?: protos.google.cloud.compute.v1.IInsertAddressRequest,
options?: CallOptions):
Promise<[
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IInsertAddressRequest|undefined, {}|undefined
LROperation<protos.google.cloud.compute.v1.IOperation, null>,
protos.google.cloud.compute.v1.IOperation|undefined, {}|undefined
]>;
insert(
request: protos.google.cloud.compute.v1.IInsertAddressRequest,
Expand Down Expand Up @@ -414,12 +427,17 @@ export class AddressesClient {
* @param {object} [options]
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [Operation]{@link google.cloud.compute.v1.Operation}.
* The first element of the array is an object representing
* a long running operation.
* Please see the
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations)
* for more details and examples.
* This method is considered to be in beta. This means while
* stable it is still a work-in-progress and under active development,
* and might get backwards-incompatible changes at any time.
* `.promise()` is not supported yet.
* @example
* const [response] = await client.insert(request);
* const [operation] = await client.insert(request);
*/
insert(
request?: protos.google.cloud.compute.v1.IInsertAddressRequest,
Expand All @@ -432,8 +450,8 @@ export class AddressesClient {
protos.google.cloud.compute.v1.IInsertAddressRequest|null|undefined,
{}|null|undefined>):
Promise<[
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IInsertAddressRequest|undefined, {}|undefined
LROperation<protos.google.cloud.compute.v1.IOperation, null>,
protos.google.cloud.compute.v1.IOperation|undefined, {}|undefined
]>|void {
request = request || {};
let options: CallOptions;
Expand All @@ -453,7 +471,15 @@ export class AddressesClient {
'project': request.project || '',
});
this.initialize();
return this.innerApiCalls.insert(request, options, callback);
return this.innerApiCalls.insert(request, options, callback)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.then(([response, next, rawResponse]: [any, any, any]) => {
return [
summer-ji-eng marked this conversation as resolved.
Show resolved Hide resolved
{ latestResponse: response, done: false, name: response.id, metadata: null, result: {}},
next,
rawResponse
];
});
}


Expand Down
81 changes: 80 additions & 1 deletion baselines/compute/src/v1/region_operations_client.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class RegionOperationsClient {
// Iterate over each of the methods that the service provides
// and create an API call method for each.
const regionOperationsStubMethods =
['get'];
['get', 'wait'];
for (const methodName of regionOperationsStubMethods) {
const callPromise = this.regionOperationsStub.then(
stub => (...args: Array<{}>) => {
Expand Down Expand Up @@ -353,6 +353,85 @@ export class RegionOperationsClient {
this.initialize();
return this.innerApiCalls.get(request, options, callback);
}
wait(
request?: protos.google.cloud.compute.v1.IWaitRegionOperationRequest,
options?: CallOptions):
Promise<[
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IWaitRegionOperationRequest|undefined, {}|undefined
]>;
wait(
request: protos.google.cloud.compute.v1.IWaitRegionOperationRequest,
options: CallOptions,
callback: Callback<
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IWaitRegionOperationRequest|null|undefined,
{}|null|undefined>): void;
wait(
request: protos.google.cloud.compute.v1.IWaitRegionOperationRequest,
callback: Callback<
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IWaitRegionOperationRequest|null|undefined,
{}|null|undefined>): void;
/**
* Waits for the specified Operation resource to return as `DONE` or for the request to approach the 2 minute deadline, and retrieves the specified Operation resource. This method differs from the `GET` method in that it waits for no more than the default deadline (2 minutes) and then returns the current state of the operation, which might be `DONE` or still in progress.
*
* This method is called on a best-effort basis. Specifically:
* - In uncommon cases, when the server is overloaded, the request might return before the default deadline is reached, or might return after zero seconds.
* - If the default deadline is reached, there is no guarantee that the operation is actually done when the method returns. Be prepared to retry if the operation is not `DONE`.
*
* @param {Object} request
* The request object that will be sent.
* @param {string} request.operation
* Name of the Operations resource to return.
* @param {string} request.project
* Project ID for this request.
* @param {string} request.region
* Name of the region for this request.
* @param {object} [options]
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing [Operation]{@link google.cloud.compute.v1.Operation}.
* Please see the
* [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods)
* for more details and examples.
* @example
* const [response] = await client.wait(request);
*/
wait(
request?: protos.google.cloud.compute.v1.IWaitRegionOperationRequest,
optionsOrCallback?: CallOptions|Callback<
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IWaitRegionOperationRequest|null|undefined,
{}|null|undefined>,
callback?: Callback<
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IWaitRegionOperationRequest|null|undefined,
{}|null|undefined>):
Promise<[
protos.google.cloud.compute.v1.IOperation,
protos.google.cloud.compute.v1.IWaitRegionOperationRequest|undefined, {}|undefined
]>|void {
request = request || {};
let options: CallOptions;
if (typeof optionsOrCallback === 'function' && callback === undefined) {
callback = optionsOrCallback;
options = {};
}
else {
options = optionsOrCallback as CallOptions;
}
options = options || {};
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers[
'x-goog-request-params'
] = gax.routingHeader.fromParams({
'project': request.project || '',
});
this.initialize();
return this.innerApiCalls.wait(request, options, callback);
}


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"Get": {
"retry_codes_name": "non_idempotent",
"retry_params_name": "default"
},
"Wait": {
"retry_codes_name": "non_idempotent",
"retry_params_name": "default"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions baselines/compute/test/gapic_addresses_v1.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('v1.AddressesClient', () => {
const expectedResponse = generateSampleMessage(new protos.google.cloud.compute.v1.Operation());
client.innerApiCalls.delete = stubSimpleCall(expectedResponse);
const [response] = await client.delete(request);
assert.deepStrictEqual(response, expectedResponse);
assert.deepStrictEqual(response.latestResponse, expectedResponse);
assert((client.innerApiCalls.delete as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand Down Expand Up @@ -280,7 +280,7 @@ describe('v1.AddressesClient', () => {
const expectedResponse = generateSampleMessage(new protos.google.cloud.compute.v1.Operation());
client.innerApiCalls.insert = stubSimpleCall(expectedResponse);
const [response] = await client.insert(request);
assert.deepStrictEqual(response, expectedResponse);
assert.deepStrictEqual(response.latestResponse, expectedResponse);
assert((client.innerApiCalls.insert as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
Expand Down
84 changes: 84 additions & 0 deletions baselines/compute/test/gapic_region_operations_v1.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,88 @@ describe('v1.RegionOperationsClient', () => {
.getCall(0).calledWith(request, expectedOptions, undefined));
});
});

describe('wait', () => {
it('invokes wait without error', async () => {
const client = new regionoperationsModule.v1.RegionOperationsClient({
auth: googleAuth,
projectId: 'bogus',
});
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.compute.v1.WaitRegionOperationRequest());
request.project = '';
const expectedHeaderRequestParams = "project=";
const expectedOptions = {
otherArgs: {
headers: {
'x-goog-request-params': expectedHeaderRequestParams,
},
},
};
const expectedResponse = generateSampleMessage(new protos.google.cloud.compute.v1.Operation());
client.innerApiCalls.wait = stubSimpleCall(expectedResponse);
const [response] = await client.wait(request);
assert.deepStrictEqual(response, expectedResponse);
assert((client.innerApiCalls.wait as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});

it('invokes wait without error using callback', async () => {
const client = new regionoperationsModule.v1.RegionOperationsClient({
auth: googleAuth,
projectId: 'bogus',
});
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.compute.v1.WaitRegionOperationRequest());
request.project = '';
const expectedHeaderRequestParams = "project=";
const expectedOptions = {
otherArgs: {
headers: {
'x-goog-request-params': expectedHeaderRequestParams,
},
},
};
const expectedResponse = generateSampleMessage(new protos.google.cloud.compute.v1.Operation());
client.innerApiCalls.wait = stubSimpleCallWithCallback(expectedResponse);
const promise = new Promise((resolve, reject) => {
client.wait(
request,
(err?: Error|null, result?: protos.google.cloud.compute.v1.IOperation|null) => {
if (err) {
reject(err);
} else {
resolve(result);
}
});
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
assert((client.innerApiCalls.wait as SinonStub)
.getCall(0).calledWith(request, expectedOptions /*, callback defined above */));
});

it('invokes wait with error', async () => {
const client = new regionoperationsModule.v1.RegionOperationsClient({
auth: googleAuth,
projectId: 'bogus',
});
client.initialize();
const request = generateSampleMessage(new protos.google.cloud.compute.v1.WaitRegionOperationRequest());
request.project = '';
const expectedHeaderRequestParams = "project=";
const expectedOptions = {
otherArgs: {
headers: {
'x-goog-request-params': expectedHeaderRequestParams,
},
},
};
const expectedError = new Error('expected');
client.innerApiCalls.wait = stubSimpleCall(undefined, expectedError);
await assert.rejects(client.wait(request), expectedError);
assert((client.innerApiCalls.wait as SinonStub)
.getCall(0).calledWith(request, expectedOptions, undefined));
});
});
});
Loading