From 595ab2845ac8a70fc2e94d7f69029396cb6414f0 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Tue, 18 Apr 2023 10:36:56 -0400 Subject: [PATCH] feat: [tpu] make reservation_name parameter generally visible in QueuedResource message (#4178) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: make reservation_name parameter generally visible in QueuedResource message --- feat: add DeleteQueuedResource experiment --- docs(v2alpha1): minor formatting to the description for `queued_resource_id` PiperOrigin-RevId: 524336094 Source-Link: https://github.com/googleapis/googleapis/commit/cad90d2ae086097bf0f4924ff60100d75b3dd501 Source-Link: https://github.com/googleapis/googleapis-gen/commit/848f9c294076db6d1d1a78013040251b1c0ad7a9 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLXRwdS8uT3dsQm90LnlhbWwiLCJoIjoiODQ4ZjljMjk0MDc2ZGI2ZDFkMWE3ODAxMzA0MDI1MWIxYzBhZDdhOSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot Co-authored-by: Denis DelGrosso <85250797+ddelgrosso1@users.noreply.github.com> --- packages/google-cloud-tpu/README.md | 1 + .../google/cloud/tpu/v2alpha1/cloud_tpu.proto | 32 ++- packages/google-cloud-tpu/protos/protos.d.ts | 124 +++++++++ packages/google-cloud-tpu/protos/protos.js | 259 ++++++++++++++++++ packages/google-cloud-tpu/protos/protos.json | 44 +++ packages/google-cloud-tpu/samples/README.md | 18 ++ .../snippet_metadata.google.cloud.tpu.v1.json | 2 +- .../snippet_metadata.google.cloud.tpu.v2.json | 2 +- ...et_metadata.google.cloud.tpu.v2alpha1.json | 42 ++- .../v2alpha1/tpu.create_queued_resource.js | 2 +- .../v2alpha1/tpu.reset_queued_resource.js | 62 +++++ .../src/v2alpha1/gapic_metadata.json | 10 + .../src/v2alpha1/tpu_client.ts | 152 +++++++++- .../src/v2alpha1/tpu_client_config.json | 5 + .../test/gapic_tpu_v2alpha1.ts | 194 +++++++++++++ 15 files changed, 943 insertions(+), 6 deletions(-) create mode 100644 packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.reset_queued_resource.js diff --git a/packages/google-cloud-tpu/README.md b/packages/google-cloud-tpu/README.md index ee2dfb3fde9..330a73fd28d 100644 --- a/packages/google-cloud-tpu/README.md +++ b/packages/google-cloud-tpu/README.md @@ -125,6 +125,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/google-cloud-node/ | Tpu.list_nodes | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.list_nodes.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.list_nodes.js,samples/README.md) | | Tpu.list_queued_resources | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.list_queued_resources.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.list_queued_resources.js,samples/README.md) | | Tpu.list_runtime_versions | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.list_runtime_versions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.list_runtime_versions.js,samples/README.md) | +| Tpu.reset_queued_resource | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.reset_queued_resource.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.reset_queued_resource.js,samples/README.md) | | Tpu.simulate_maintenance_event | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.simulate_maintenance_event.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.simulate_maintenance_event.js,samples/README.md) | | Tpu.start_node | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.start_node.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.start_node.js,samples/README.md) | | Tpu.stop_node | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.stop_node.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.stop_node.js,samples/README.md) | diff --git a/packages/google-cloud-tpu/protos/google/cloud/tpu/v2alpha1/cloud_tpu.proto b/packages/google-cloud-tpu/protos/google/cloud/tpu/v2alpha1/cloud_tpu.proto index db6b9326a6e..7d2037e9f53 100644 --- a/packages/google-cloud-tpu/protos/google/cloud/tpu/v2alpha1/cloud_tpu.proto +++ b/packages/google-cloud-tpu/protos/google/cloud/tpu/v2alpha1/cloud_tpu.proto @@ -164,6 +164,20 @@ service Tpu { }; } + // Resets a QueuedResource TPU instance + rpc ResetQueuedResource(ResetQueuedResourceRequest) + returns (google.longrunning.Operation) { + option (google.api.http) = { + post: "/v2alpha1/{name=projects/*/locations/*/queuedResources/*}:reset" + body: "*" + }; + option (google.api.method_signature) = "name"; + option (google.longrunning.operation_info) = { + response_type: "QueuedResource" + metadata_type: "OperationMetadata" + }; + } + // Generates the Cloud TPU service identity for the project. rpc GenerateServiceIdentity(GenerateServiceIdentityRequest) returns (GenerateServiceIdentityResponse) { @@ -629,6 +643,10 @@ message QueuedResource { // Output only. State of the QueuedResource request. QueuedResourceState state = 6 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Name of the reservation in which the resource should be provisioned. + // Format: projects/{project}/locations/{zone}/reservations/{reservation} + string reservation_name = 8; } // QueuedResourceState defines the details of the QueuedResource request. @@ -884,7 +902,7 @@ message CreateQueuedResourceRequest { } ]; - // The unqualified resource name. Should follow the ^[A-Za-z0-9_.~+%-]+$ + // The unqualified resource name. Should follow the `^[A-Za-z0-9_.~+%-]+$` // regex format. string queued_resource_id = 2; @@ -910,6 +928,18 @@ message DeleteQueuedResourceRequest { string request_id = 2; } +// Request for +// [ResetQueuedResource][google.cloud.tpu.v2alpha1.Tpu.ResetQueuedResource]. +message ResetQueuedResourceRequest { + // Required. The name of the queued resource. + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "tpu.googleapis.com/QueuedResource" + } + ]; +} + // The per-product per-project service identity for Cloud TPU service. message ServiceIdentity { // The email address of the service identity. diff --git a/packages/google-cloud-tpu/protos/protos.d.ts b/packages/google-cloud-tpu/protos/protos.d.ts index 5ddbc79ca5c..df582366308 100644 --- a/packages/google-cloud-tpu/protos/protos.d.ts +++ b/packages/google-cloud-tpu/protos/protos.d.ts @@ -7017,6 +7017,20 @@ export namespace google { */ public deleteQueuedResource(request: google.cloud.tpu.v2alpha1.IDeleteQueuedResourceRequest): Promise; + /** + * Calls ResetQueuedResource. + * @param request ResetQueuedResourceRequest message or plain object + * @param callback Node-style callback called with the error, if any, and Operation + */ + public resetQueuedResource(request: google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest, callback: google.cloud.tpu.v2alpha1.Tpu.ResetQueuedResourceCallback): void; + + /** + * Calls ResetQueuedResource. + * @param request ResetQueuedResourceRequest message or plain object + * @returns Promise + */ + public resetQueuedResource(request: google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest): Promise; + /** * Calls GenerateServiceIdentity. * @param request GenerateServiceIdentityRequest message or plain object @@ -7195,6 +7209,13 @@ export namespace google { */ type DeleteQueuedResourceCallback = (error: (Error|null), response?: google.longrunning.Operation) => void; + /** + * Callback as used by {@link google.cloud.tpu.v2alpha1.Tpu|resetQueuedResource}. + * @param error Error, if any + * @param [response] Operation + */ + type ResetQueuedResourceCallback = (error: (Error|null), response?: google.longrunning.Operation) => void; + /** * Callback as used by {@link google.cloud.tpu.v2alpha1.Tpu|generateServiceIdentity}. * @param error Error, if any @@ -8482,6 +8503,9 @@ export namespace google { /** QueuedResource state */ state?: (google.cloud.tpu.v2alpha1.IQueuedResourceState|null); + + /** QueuedResource reservationName */ + reservationName?: (string|null); } /** Represents a QueuedResource. */ @@ -8511,6 +8535,9 @@ export namespace google { /** QueuedResource state. */ public state?: (google.cloud.tpu.v2alpha1.IQueuedResourceState|null); + /** QueuedResource reservationName. */ + public reservationName: string; + /** QueuedResource resource. */ public resource?: "tpu"; @@ -11386,6 +11413,103 @@ export namespace google { public static getTypeUrl(typeUrlPrefix?: string): string; } + /** Properties of a ResetQueuedResourceRequest. */ + interface IResetQueuedResourceRequest { + + /** ResetQueuedResourceRequest name */ + name?: (string|null); + } + + /** Represents a ResetQueuedResourceRequest. */ + class ResetQueuedResourceRequest implements IResetQueuedResourceRequest { + + /** + * Constructs a new ResetQueuedResourceRequest. + * @param [properties] Properties to set + */ + constructor(properties?: google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest); + + /** ResetQueuedResourceRequest name. */ + public name: string; + + /** + * Creates a new ResetQueuedResourceRequest instance using the specified properties. + * @param [properties] Properties to set + * @returns ResetQueuedResourceRequest instance + */ + public static create(properties?: google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest): google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest; + + /** + * Encodes the specified ResetQueuedResourceRequest message. Does not implicitly {@link google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest.verify|verify} messages. + * @param message ResetQueuedResourceRequest message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified ResetQueuedResourceRequest message, length delimited. Does not implicitly {@link google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest.verify|verify} messages. + * @param message ResetQueuedResourceRequest message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a ResetQueuedResourceRequest message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns ResetQueuedResourceRequest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest; + + /** + * Decodes a ResetQueuedResourceRequest message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns ResetQueuedResourceRequest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest; + + /** + * Verifies a ResetQueuedResourceRequest message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a ResetQueuedResourceRequest message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns ResetQueuedResourceRequest + */ + public static fromObject(object: { [k: string]: any }): google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest; + + /** + * Creates a plain object from a ResetQueuedResourceRequest message. Also converts values to other types if specified. + * @param message ResetQueuedResourceRequest + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this ResetQueuedResourceRequest to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for ResetQueuedResourceRequest + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + /** Properties of a ServiceIdentity. */ interface IServiceIdentity { diff --git a/packages/google-cloud-tpu/protos/protos.js b/packages/google-cloud-tpu/protos/protos.js index 53f01ac5efb..313618cdd8c 100644 --- a/packages/google-cloud-tpu/protos/protos.js +++ b/packages/google-cloud-tpu/protos/protos.js @@ -16783,6 +16783,39 @@ * @variation 2 */ + /** + * Callback as used by {@link google.cloud.tpu.v2alpha1.Tpu|resetQueuedResource}. + * @memberof google.cloud.tpu.v2alpha1.Tpu + * @typedef ResetQueuedResourceCallback + * @type {function} + * @param {Error|null} error Error, if any + * @param {google.longrunning.Operation} [response] Operation + */ + + /** + * Calls ResetQueuedResource. + * @function resetQueuedResource + * @memberof google.cloud.tpu.v2alpha1.Tpu + * @instance + * @param {google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest} request ResetQueuedResourceRequest message or plain object + * @param {google.cloud.tpu.v2alpha1.Tpu.ResetQueuedResourceCallback} callback Node-style callback called with the error, if any, and Operation + * @returns {undefined} + * @variation 1 + */ + Object.defineProperty(Tpu.prototype.resetQueuedResource = function resetQueuedResource(request, callback) { + return this.rpcCall(resetQueuedResource, $root.google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest, $root.google.longrunning.Operation, request, callback); + }, "name", { value: "ResetQueuedResource" }); + + /** + * Calls ResetQueuedResource. + * @function resetQueuedResource + * @memberof google.cloud.tpu.v2alpha1.Tpu + * @instance + * @param {google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest} request ResetQueuedResourceRequest message or plain object + * @returns {Promise} Promise + * @variation 2 + */ + /** * Callback as used by {@link google.cloud.tpu.v2alpha1.Tpu|generateServiceIdentity}. * @memberof google.cloud.tpu.v2alpha1.Tpu @@ -20334,6 +20367,7 @@ * @property {google.cloud.tpu.v2alpha1.QueuedResource.IGuaranteed|null} [guaranteed] QueuedResource guaranteed * @property {google.cloud.tpu.v2alpha1.QueuedResource.IQueueingPolicy|null} [queueingPolicy] QueuedResource queueingPolicy * @property {google.cloud.tpu.v2alpha1.IQueuedResourceState|null} [state] QueuedResource state + * @property {string|null} [reservationName] QueuedResource reservationName */ /** @@ -20399,6 +20433,14 @@ */ QueuedResource.prototype.state = null; + /** + * QueuedResource reservationName. + * @member {string} reservationName + * @memberof google.cloud.tpu.v2alpha1.QueuedResource + * @instance + */ + QueuedResource.prototype.reservationName = ""; + // OneOf field names bound to virtual getters and setters var $oneOfFields; @@ -20460,6 +20502,8 @@ $root.google.cloud.tpu.v2alpha1.QueuedResource.QueueingPolicy.encode(message.queueingPolicy, writer.uint32(/* id 5, wireType 2 =*/42).fork()).ldelim(); if (message.state != null && Object.hasOwnProperty.call(message, "state")) $root.google.cloud.tpu.v2alpha1.QueuedResourceState.encode(message.state, writer.uint32(/* id 6, wireType 2 =*/50).fork()).ldelim(); + if (message.reservationName != null && Object.hasOwnProperty.call(message, "reservationName")) + writer.uint32(/* id 8, wireType 2 =*/66).string(message.reservationName); return writer; }; @@ -20518,6 +20562,10 @@ message.state = $root.google.cloud.tpu.v2alpha1.QueuedResourceState.decode(reader, reader.uint32()); break; } + case 8: { + message.reservationName = reader.string(); + break; + } default: reader.skipType(tag & 7); break; @@ -20593,6 +20641,9 @@ if (error) return "state." + error; } + if (message.reservationName != null && message.hasOwnProperty("reservationName")) + if (!$util.isString(message.reservationName)) + return "reservationName: string expected"; return null; }; @@ -20635,6 +20686,8 @@ throw TypeError(".google.cloud.tpu.v2alpha1.QueuedResource.state: object expected"); message.state = $root.google.cloud.tpu.v2alpha1.QueuedResourceState.fromObject(object.state); } + if (object.reservationName != null) + message.reservationName = String(object.reservationName); return message; }; @@ -20655,6 +20708,7 @@ object.name = ""; object.queueingPolicy = null; object.state = null; + object.reservationName = ""; } if (message.name != null && message.hasOwnProperty("name")) object.name = message.name; @@ -20677,6 +20731,8 @@ object.queueingPolicy = $root.google.cloud.tpu.v2alpha1.QueuedResource.QueueingPolicy.toObject(message.queueingPolicy, options); if (message.state != null && message.hasOwnProperty("state")) object.state = $root.google.cloud.tpu.v2alpha1.QueuedResourceState.toObject(message.state, options); + if (message.reservationName != null && message.hasOwnProperty("reservationName")) + object.reservationName = message.reservationName; return object; }; @@ -27108,6 +27164,209 @@ return DeleteQueuedResourceRequest; })(); + v2alpha1.ResetQueuedResourceRequest = (function() { + + /** + * Properties of a ResetQueuedResourceRequest. + * @memberof google.cloud.tpu.v2alpha1 + * @interface IResetQueuedResourceRequest + * @property {string|null} [name] ResetQueuedResourceRequest name + */ + + /** + * Constructs a new ResetQueuedResourceRequest. + * @memberof google.cloud.tpu.v2alpha1 + * @classdesc Represents a ResetQueuedResourceRequest. + * @implements IResetQueuedResourceRequest + * @constructor + * @param {google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest=} [properties] Properties to set + */ + function ResetQueuedResourceRequest(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * ResetQueuedResourceRequest name. + * @member {string} name + * @memberof google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest + * @instance + */ + ResetQueuedResourceRequest.prototype.name = ""; + + /** + * Creates a new ResetQueuedResourceRequest instance using the specified properties. + * @function create + * @memberof google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest + * @static + * @param {google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest=} [properties] Properties to set + * @returns {google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest} ResetQueuedResourceRequest instance + */ + ResetQueuedResourceRequest.create = function create(properties) { + return new ResetQueuedResourceRequest(properties); + }; + + /** + * Encodes the specified ResetQueuedResourceRequest message. Does not implicitly {@link google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest.verify|verify} messages. + * @function encode + * @memberof google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest + * @static + * @param {google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest} message ResetQueuedResourceRequest message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ResetQueuedResourceRequest.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.name != null && Object.hasOwnProperty.call(message, "name")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.name); + return writer; + }; + + /** + * Encodes the specified ResetQueuedResourceRequest message, length delimited. Does not implicitly {@link google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest.verify|verify} messages. + * @function encodeDelimited + * @memberof google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest + * @static + * @param {google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest} message ResetQueuedResourceRequest message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ResetQueuedResourceRequest.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a ResetQueuedResourceRequest message from the specified reader or buffer. + * @function decode + * @memberof google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest} ResetQueuedResourceRequest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ResetQueuedResourceRequest.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.name = reader.string(); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a ResetQueuedResourceRequest message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest} ResetQueuedResourceRequest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ResetQueuedResourceRequest.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a ResetQueuedResourceRequest message. + * @function verify + * @memberof google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + ResetQueuedResourceRequest.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.name != null && message.hasOwnProperty("name")) + if (!$util.isString(message.name)) + return "name: string expected"; + return null; + }; + + /** + * Creates a ResetQueuedResourceRequest message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest + * @static + * @param {Object.} object Plain object + * @returns {google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest} ResetQueuedResourceRequest + */ + ResetQueuedResourceRequest.fromObject = function fromObject(object) { + if (object instanceof $root.google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest) + return object; + var message = new $root.google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest(); + if (object.name != null) + message.name = String(object.name); + return message; + }; + + /** + * Creates a plain object from a ResetQueuedResourceRequest message. Also converts values to other types if specified. + * @function toObject + * @memberof google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest + * @static + * @param {google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest} message ResetQueuedResourceRequest + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + ResetQueuedResourceRequest.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + object.name = ""; + if (message.name != null && message.hasOwnProperty("name")) + object.name = message.name; + return object; + }; + + /** + * Converts this ResetQueuedResourceRequest to JSON. + * @function toJSON + * @memberof google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest + * @instance + * @returns {Object.} JSON object + */ + ResetQueuedResourceRequest.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for ResetQueuedResourceRequest + * @function getTypeUrl + * @memberof google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + ResetQueuedResourceRequest.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest"; + }; + + return ResetQueuedResourceRequest; + })(); + v2alpha1.ServiceIdentity = (function() { /** diff --git a/packages/google-cloud-tpu/protos/protos.json b/packages/google-cloud-tpu/protos/protos.json index d090838e3d8..56290a31cd4 100644 --- a/packages/google-cloud-tpu/protos/protos.json +++ b/packages/google-cloud-tpu/protos/protos.json @@ -2068,6 +2068,34 @@ } ] }, + "ResetQueuedResource": { + "requestType": "ResetQueuedResourceRequest", + "responseType": "google.longrunning.Operation", + "options": { + "(google.api.http).post": "/v2alpha1/{name=projects/*/locations/*/queuedResources/*}:reset", + "(google.api.http).body": "*", + "(google.api.method_signature)": "name", + "(google.longrunning.operation_info).response_type": "QueuedResource", + "(google.longrunning.operation_info).metadata_type": "OperationMetadata" + }, + "parsedOptions": [ + { + "(google.api.http)": { + "post": "/v2alpha1/{name=projects/*/locations/*/queuedResources/*}:reset", + "body": "*" + } + }, + { + "(google.api.method_signature)": "name" + }, + { + "(google.longrunning.operation_info)": { + "response_type": "QueuedResource", + "metadata_type": "OperationMetadata" + } + } + ] + }, "GenerateServiceIdentity": { "requestType": "GenerateServiceIdentityRequest", "responseType": "GenerateServiceIdentityResponse", @@ -2550,6 +2578,10 @@ "options": { "(google.api.field_behavior)": "OUTPUT_ONLY" } + }, + "reservationName": { + "type": "string", + "id": 8 } }, "nested": { @@ -2971,6 +3003,18 @@ } } }, + "ResetQueuedResourceRequest": { + "fields": { + "name": { + "type": "string", + "id": 1, + "options": { + "(google.api.field_behavior)": "REQUIRED", + "(google.api.resource_reference).type": "tpu.googleapis.com/QueuedResource" + } + } + } + }, "ServiceIdentity": { "fields": { "email": { diff --git a/packages/google-cloud-tpu/samples/README.md b/packages/google-cloud-tpu/samples/README.md index 5e078745dfd..838d507e703 100644 --- a/packages/google-cloud-tpu/samples/README.md +++ b/packages/google-cloud-tpu/samples/README.md @@ -50,6 +50,7 @@ * [Tpu.list_nodes](#tpu.list_nodes) * [Tpu.list_queued_resources](#tpu.list_queued_resources) * [Tpu.list_runtime_versions](#tpu.list_runtime_versions) + * [Tpu.reset_queued_resource](#tpu.reset_queued_resource) * [Tpu.simulate_maintenance_event](#tpu.simulate_maintenance_event) * [Tpu.start_node](#tpu.start_node) * [Tpu.stop_node](#tpu.stop_node) @@ -718,6 +719,23 @@ __Usage:__ +### Tpu.reset_queued_resource + +View the [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.reset_queued_resource.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/google-cloud-node&page=editor&open_in_editor=packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.reset_queued_resource.js,samples/README.md) + +__Usage:__ + + +`node packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.reset_queued_resource.js` + + +----- + + + + ### Tpu.simulate_maintenance_event View the [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.simulate_maintenance_event.js). diff --git a/packages/google-cloud-tpu/samples/generated/v1/snippet_metadata.google.cloud.tpu.v1.json b/packages/google-cloud-tpu/samples/generated/v1/snippet_metadata.google.cloud.tpu.v1.json index 8c2babe507d..aab03c168bc 100644 --- a/packages/google-cloud-tpu/samples/generated/v1/snippet_metadata.google.cloud.tpu.v1.json +++ b/packages/google-cloud-tpu/samples/generated/v1/snippet_metadata.google.cloud.tpu.v1.json @@ -1,7 +1,7 @@ { "clientLibrary": { "name": "nodejs-tpu", - "version": "2.5.0", + "version": "2.5.1", "language": "TYPESCRIPT", "apis": [ { diff --git a/packages/google-cloud-tpu/samples/generated/v2/snippet_metadata.google.cloud.tpu.v2.json b/packages/google-cloud-tpu/samples/generated/v2/snippet_metadata.google.cloud.tpu.v2.json index 1d5f52d9093..7eaa9ec8059 100644 --- a/packages/google-cloud-tpu/samples/generated/v2/snippet_metadata.google.cloud.tpu.v2.json +++ b/packages/google-cloud-tpu/samples/generated/v2/snippet_metadata.google.cloud.tpu.v2.json @@ -1,7 +1,7 @@ { "clientLibrary": { "name": "nodejs-tpu", - "version": "2.5.0", + "version": "2.5.1", "language": "TYPESCRIPT", "apis": [ { diff --git a/packages/google-cloud-tpu/samples/generated/v2alpha1/snippet_metadata.google.cloud.tpu.v2alpha1.json b/packages/google-cloud-tpu/samples/generated/v2alpha1/snippet_metadata.google.cloud.tpu.v2alpha1.json index 1ccb3324309..6077bcd03e3 100644 --- a/packages/google-cloud-tpu/samples/generated/v2alpha1/snippet_metadata.google.cloud.tpu.v2alpha1.json +++ b/packages/google-cloud-tpu/samples/generated/v2alpha1/snippet_metadata.google.cloud.tpu.v2alpha1.json @@ -1,7 +1,7 @@ { "clientLibrary": { "name": "nodejs-tpu", - "version": "2.5.0", + "version": "2.5.1", "language": "TYPESCRIPT", "apis": [ { @@ -503,6 +503,46 @@ } } }, + { + "regionTag": "tpu_v2alpha1_generated_Tpu_ResetQueuedResource_async", + "title": "Tpu resetQueuedResource Sample", + "origin": "API_DEFINITION", + "description": " Resets a QueuedResource TPU instance", + "canonical": true, + "file": "tpu.reset_queued_resource.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 54, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "ResetQueuedResource", + "fullName": "google.cloud.tpu.v2alpha1.Tpu.ResetQueuedResource", + "async": true, + "parameters": [ + { + "name": "name", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.longrunning.Operation", + "client": { + "shortName": "TpuClient", + "fullName": "google.cloud.tpu.v2alpha1.TpuClient" + }, + "method": { + "shortName": "ResetQueuedResource", + "fullName": "google.cloud.tpu.v2alpha1.Tpu.ResetQueuedResource", + "service": { + "shortName": "Tpu", + "fullName": "google.cloud.tpu.v2alpha1.Tpu" + } + } + } + }, { "regionTag": "tpu_v2alpha1_generated_Tpu_GenerateServiceIdentity_async", "title": "Tpu generateServiceIdentity Sample", diff --git a/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.create_queued_resource.js b/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.create_queued_resource.js index cb6dd204258..c28e8945ad3 100644 --- a/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.create_queued_resource.js +++ b/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.create_queued_resource.js @@ -33,7 +33,7 @@ function main(parent, queuedResource) { */ // const parent = 'abc123' /** - * The unqualified resource name. Should follow the ^[A-Za-z0-9_.~+%-]+$ + * The unqualified resource name. Should follow the `^[A-Za-z0-9_.~+%-]+$` * regex format. */ // const queuedResourceId = 'abc123' diff --git a/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.reset_queued_resource.js b/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.reset_queued_resource.js new file mode 100644 index 00000000000..a7a49d9aed0 --- /dev/null +++ b/packages/google-cloud-tpu/samples/generated/v2alpha1/tpu.reset_queued_resource.js @@ -0,0 +1,62 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + + +'use strict'; + +function main(name) { + // [START tpu_v2alpha1_generated_Tpu_ResetQueuedResource_async] + /** + * This snippet has been automatically generated and should be regarded as a code template only. + * It will require modifications to work. + * It may require correct/in-range values for request initialization. + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the queued resource. + */ + // const name = 'abc123' + + // Imports the Tpu library + const {TpuClient} = require('@google-cloud/tpu').v2alpha1; + + // Instantiates a client + const tpuClient = new TpuClient(); + + async function callResetQueuedResource() { + // Construct request + const request = { + name, + }; + + // Run request + const [operation] = await tpuClient.resetQueuedResource(request); + const [response] = await operation.promise(); + console.log(response); + } + + callResetQueuedResource(); + // [END tpu_v2alpha1_generated_Tpu_ResetQueuedResource_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-tpu/src/v2alpha1/gapic_metadata.json b/packages/google-cloud-tpu/src/v2alpha1/gapic_metadata.json index 521ba0b7c56..8e1cbeb798b 100644 --- a/packages/google-cloud-tpu/src/v2alpha1/gapic_metadata.json +++ b/packages/google-cloud-tpu/src/v2alpha1/gapic_metadata.json @@ -75,6 +75,11 @@ "deleteQueuedResource" ] }, + "ResetQueuedResource": { + "methods": [ + "resetQueuedResource" + ] + }, "SimulateMaintenanceEvent": { "methods": [ "simulateMaintenanceEvent" @@ -178,6 +183,11 @@ "deleteQueuedResource" ] }, + "ResetQueuedResource": { + "methods": [ + "resetQueuedResource" + ] + }, "SimulateMaintenanceEvent": { "methods": [ "simulateMaintenanceEvent" diff --git a/packages/google-cloud-tpu/src/v2alpha1/tpu_client.ts b/packages/google-cloud-tpu/src/v2alpha1/tpu_client.ts index 58d4f771d0a..71c33f08b09 100644 --- a/packages/google-cloud-tpu/src/v2alpha1/tpu_client.ts +++ b/packages/google-cloud-tpu/src/v2alpha1/tpu_client.ts @@ -318,6 +318,12 @@ export class TpuClient { const deleteQueuedResourceMetadata = protoFilesRoot.lookup( '.google.cloud.tpu.v2alpha1.OperationMetadata' ) as gax.protobuf.Type; + const resetQueuedResourceResponse = protoFilesRoot.lookup( + '.google.cloud.tpu.v2alpha1.QueuedResource' + ) as gax.protobuf.Type; + const resetQueuedResourceMetadata = protoFilesRoot.lookup( + '.google.cloud.tpu.v2alpha1.OperationMetadata' + ) as gax.protobuf.Type; const simulateMaintenanceEventResponse = protoFilesRoot.lookup( '.google.cloud.tpu.v2alpha1.Node' ) as gax.protobuf.Type; @@ -361,6 +367,11 @@ export class TpuClient { deleteQueuedResourceResponse.decode.bind(deleteQueuedResourceResponse), deleteQueuedResourceMetadata.decode.bind(deleteQueuedResourceMetadata) ), + resetQueuedResource: new this._gaxModule.LongrunningDescriptor( + this.operationsClient, + resetQueuedResourceResponse.decode.bind(resetQueuedResourceResponse), + resetQueuedResourceMetadata.decode.bind(resetQueuedResourceMetadata) + ), simulateMaintenanceEvent: new this._gaxModule.LongrunningDescriptor( this.operationsClient, simulateMaintenanceEventResponse.decode.bind( @@ -433,6 +444,7 @@ export class TpuClient { 'getQueuedResource', 'createQueuedResource', 'deleteQueuedResource', + 'resetQueuedResource', 'generateServiceIdentity', 'listAcceleratorTypes', 'getAcceleratorType', @@ -1790,7 +1802,7 @@ export class TpuClient { * @param {string} request.parent * Required. The parent resource name. * @param {string} request.queuedResourceId - * The unqualified resource name. Should follow the ^[A-Za-z0-9_.~+%-]+$ + * The unqualified resource name. Should follow the `^[A-Za-z0-9_.~+%-]+$` * regex format. * @param {google.cloud.tpu.v2alpha1.QueuedResource} request.queuedResource * Required. The queued resource. @@ -2067,6 +2079,144 @@ export class TpuClient { protos.google.cloud.tpu.v2alpha1.OperationMetadata >; } + /** + * Resets a QueuedResource TPU instance + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The name of the queued resource. + * @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 + * a long running operation. Its `promise()` method returns a promise + * you can `await` for. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) + * for more details and examples. + * @example include:samples/generated/v2alpha1/tpu.reset_queued_resource.js + * region_tag:tpu_v2alpha1_generated_Tpu_ResetQueuedResource_async + */ + resetQueuedResource( + request?: protos.google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest, + options?: CallOptions + ): Promise< + [ + LROperation< + protos.google.cloud.tpu.v2alpha1.IQueuedResource, + protos.google.cloud.tpu.v2alpha1.IOperationMetadata + >, + protos.google.longrunning.IOperation | undefined, + {} | undefined + ] + >; + resetQueuedResource( + request: protos.google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest, + options: CallOptions, + callback: Callback< + LROperation< + protos.google.cloud.tpu.v2alpha1.IQueuedResource, + protos.google.cloud.tpu.v2alpha1.IOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + > + ): void; + resetQueuedResource( + request: protos.google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest, + callback: Callback< + LROperation< + protos.google.cloud.tpu.v2alpha1.IQueuedResource, + protos.google.cloud.tpu.v2alpha1.IOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + > + ): void; + resetQueuedResource( + request?: protos.google.cloud.tpu.v2alpha1.IResetQueuedResourceRequest, + optionsOrCallback?: + | CallOptions + | Callback< + LROperation< + protos.google.cloud.tpu.v2alpha1.IQueuedResource, + protos.google.cloud.tpu.v2alpha1.IOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + >, + callback?: Callback< + LROperation< + protos.google.cloud.tpu.v2alpha1.IQueuedResource, + protos.google.cloud.tpu.v2alpha1.IOperationMetadata + >, + protos.google.longrunning.IOperation | null | undefined, + {} | null | undefined + > + ): Promise< + [ + LROperation< + protos.google.cloud.tpu.v2alpha1.IQueuedResource, + protos.google.cloud.tpu.v2alpha1.IOperationMetadata + >, + protos.google.longrunning.IOperation | 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'] = + this._gaxModule.routingHeader.fromParams({ + name: request.name ?? '', + }); + this.initialize(); + return this.innerApiCalls.resetQueuedResource(request, options, callback); + } + /** + * Check the status of the long running operation returned by `resetQueuedResource()`. + * @param {String} name + * The operation name that will be passed. + * @returns {Promise} - The promise which resolves to an object. + * The decoded operation object has result and metadata field to get information from. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations) + * for more details and examples. + * @example include:samples/generated/v2alpha1/tpu.reset_queued_resource.js + * region_tag:tpu_v2alpha1_generated_Tpu_ResetQueuedResource_async + */ + async checkResetQueuedResourceProgress( + name: string + ): Promise< + LROperation< + protos.google.cloud.tpu.v2alpha1.QueuedResource, + protos.google.cloud.tpu.v2alpha1.OperationMetadata + > + > { + const request = + new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest( + {name} + ); + const [operation] = await this.operationsClient.getOperation(request); + const decodeOperation = new this._gaxModule.Operation( + operation, + this.descriptors.longrunning.resetQueuedResource, + this._gaxModule.createDefaultBackoffSettings() + ); + return decodeOperation as LROperation< + protos.google.cloud.tpu.v2alpha1.QueuedResource, + protos.google.cloud.tpu.v2alpha1.OperationMetadata + >; + } /** * Simulates a maintenance event. * diff --git a/packages/google-cloud-tpu/src/v2alpha1/tpu_client_config.json b/packages/google-cloud-tpu/src/v2alpha1/tpu_client_config.json index 5adc5503d1e..73f0119221c 100644 --- a/packages/google-cloud-tpu/src/v2alpha1/tpu_client_config.json +++ b/packages/google-cloud-tpu/src/v2alpha1/tpu_client_config.json @@ -75,6 +75,11 @@ "retry_codes_name": "non_idempotent", "retry_params_name": "default" }, + "ResetQueuedResource": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, "GenerateServiceIdentity": { "timeout_millis": 60000, "retry_codes_name": "non_idempotent", diff --git a/packages/google-cloud-tpu/test/gapic_tpu_v2alpha1.ts b/packages/google-cloud-tpu/test/gapic_tpu_v2alpha1.ts index 949861be7c9..05bc82644c1 100644 --- a/packages/google-cloud-tpu/test/gapic_tpu_v2alpha1.ts +++ b/packages/google-cloud-tpu/test/gapic_tpu_v2alpha1.ts @@ -2390,6 +2390,200 @@ describe('v2alpha1.TpuClient', () => { }); }); + describe('resetQueuedResource', () => { + it('invokes resetQueuedResource without error', async () => { + const client = new tpuModule.v2alpha1.TpuClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest() + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.resetQueuedResource = + stubLongRunningCall(expectedResponse); + const [operation] = await client.resetQueuedResource(request); + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.resetQueuedResource as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetQueuedResource as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes resetQueuedResource without error using callback', async () => { + const client = new tpuModule.v2alpha1.TpuClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest() + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.longrunning.Operation() + ); + client.innerApiCalls.resetQueuedResource = + stubLongRunningCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.resetQueuedResource( + request, + ( + err?: Error | null, + result?: LROperation< + protos.google.cloud.tpu.v2alpha1.IQueuedResource, + protos.google.cloud.tpu.v2alpha1.IOperationMetadata + > | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const operation = (await promise) as LROperation< + protos.google.cloud.tpu.v2alpha1.IQueuedResource, + protos.google.cloud.tpu.v2alpha1.IOperationMetadata + >; + const [response] = await operation.promise(); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.resetQueuedResource as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetQueuedResource as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes resetQueuedResource with call error', async () => { + const client = new tpuModule.v2alpha1.TpuClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest() + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.resetQueuedResource = stubLongRunningCall( + undefined, + expectedError + ); + await assert.rejects(client.resetQueuedResource(request), expectedError); + const actualRequest = ( + client.innerApiCalls.resetQueuedResource as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetQueuedResource as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes resetQueuedResource with LRO error', async () => { + const client = new tpuModule.v2alpha1.TpuClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest() + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.tpu.v2alpha1.ResetQueuedResourceRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.resetQueuedResource = stubLongRunningCall( + undefined, + undefined, + expectedError + ); + const [operation] = await client.resetQueuedResource(request); + await assert.rejects(operation.promise(), expectedError); + const actualRequest = ( + client.innerApiCalls.resetQueuedResource as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.resetQueuedResource as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes checkResetQueuedResourceProgress without error', async () => { + const client = new tpuModule.v2alpha1.TpuClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const expectedResponse = generateSampleMessage( + new operationsProtos.google.longrunning.Operation() + ); + expectedResponse.name = 'test'; + expectedResponse.response = {type_url: 'url', value: Buffer.from('')}; + expectedResponse.metadata = {type_url: 'url', value: Buffer.from('')}; + + client.operationsClient.getOperation = stubSimpleCall(expectedResponse); + const decodedOperation = await client.checkResetQueuedResourceProgress( + expectedResponse.name + ); + assert.deepStrictEqual(decodedOperation.name, expectedResponse.name); + assert(decodedOperation.metadata); + assert((client.operationsClient.getOperation as SinonStub).getCall(0)); + }); + + it('invokes checkResetQueuedResourceProgress with error', async () => { + const client = new tpuModule.v2alpha1.TpuClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const expectedError = new Error('expected'); + + client.operationsClient.getOperation = stubSimpleCall( + undefined, + expectedError + ); + await assert.rejects( + client.checkResetQueuedResourceProgress(''), + expectedError + ); + assert((client.operationsClient.getOperation as SinonStub).getCall(0)); + }); + }); + describe('simulateMaintenanceEvent', () => { it('invokes simulateMaintenanceEvent without error', async () => { const client = new tpuModule.v2alpha1.TpuClient({