From 11752f5200aea2f9e5fbf6a3aaab161afa1b3bce Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 4 Dec 2024 09:56:36 -0500 Subject: [PATCH] feat: [bigquery-reservation] Add the managed disaster recovery API(https://cloud.google.com/bigquery/docs/managed-disaster-recovery) (#5850) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add the managed disaster recovery API(https://cloud.google.com/bigquery/docs/managed-disaster-recovery) feat: Add a new field `is_flat_rate` to `.google.cloud.bigquery.reservation.v1.CapacityCommitment` to distinguish between flat rate and edition commitments docs: Clarify that `Autoscale.current_slots` in message `.google.cloud.bigquery.reservation.v1.Reservation` can temporarily be larger than `Autoscale.max_slots` if users reduce `Autoscale.max_slots` docs: Update comment for `slot_capacity` in message `.google.cloud.bigquery.reservation.v1.Reservation` to provide more clarity about reservation baselines, committed slots and autoscaler SKU charges when the baseline exceeds committed slots docs: Update comments for `commitment_start_time` and `commitment_end_time` in message `.google.cloud.bigquery.reservation.v1.CapacityCommitment` to provide details on how these values are affected by commitment renewal PiperOrigin-RevId: 702079972 Source-Link: https://github.com/googleapis/googleapis/commit/4743cf9ecab30cb113a7809aacbdbbba376f79f6 Source-Link: https://github.com/googleapis/googleapis-gen/commit/30e936000bfab99bf2856bb846a50eb0ee0385b7 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWJpZ3F1ZXJ5LXJlc2VydmF0aW9uLy5Pd2xCb3QueWFtbCIsImgiOiIzMGU5MzYwMDBiZmFiOTliZjI4NTZiYjg0NmE1MGViMGVlMDM4NWI3In0= * 🦉 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 --- .../README.md | 5 +- .../bigquery/reservation/v1/reservation.proto | 111 +++++- .../protos/protos.d.ts | 142 ++++++++ .../protos/protos.js | 328 ++++++++++++++++++ .../protos/protos.json | 69 +++- .../samples/README.md | 18 + ...eservation_service.failover_reservation.js | 62 ++++ ..._google.cloud.bigquery.reservation.v1.json | 40 +++ .../src/v1/gapic_metadata.json | 10 + .../src/v1/reservation_service_client.ts | 102 ++++++ .../v1/reservation_service_client_config.json | 4 + .../test/gapic_reservation_service_v1.ts | 131 +++++++ 12 files changed, 1001 insertions(+), 21 deletions(-) create mode 100644 packages/google-cloud-bigquery-reservation/samples/generated/v1/reservation_service.failover_reservation.js diff --git a/packages/google-cloud-bigquery-reservation/README.md b/packages/google-cloud-bigquery-reservation/README.md index b211a0a0da4..7fadd94f003 100644 --- a/packages/google-cloud-bigquery-reservation/README.md +++ b/packages/google-cloud-bigquery-reservation/README.md @@ -44,7 +44,7 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained]. 1. [Select or create a Cloud Platform project][projects]. 1. [Enable billing for your project][billing]. 1. [Enable the Google BigQuery Reservation API][enable_api]. -1. [Set up authentication with a service account][auth] so you can access the +1. [Set up authentication][auth] so you can access the API from your local workstation. ### Installing the client library @@ -105,6 +105,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/google-cloud-node/ | Reservation_service.delete_assignment | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-bigquery-reservation/samples/generated/v1/reservation_service.delete_assignment.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-bigquery-reservation/samples/generated/v1/reservation_service.delete_assignment.js,packages/google-cloud-bigquery-reservation/samples/README.md) | | Reservation_service.delete_capacity_commitment | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-bigquery-reservation/samples/generated/v1/reservation_service.delete_capacity_commitment.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-bigquery-reservation/samples/generated/v1/reservation_service.delete_capacity_commitment.js,packages/google-cloud-bigquery-reservation/samples/README.md) | | Reservation_service.delete_reservation | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-bigquery-reservation/samples/generated/v1/reservation_service.delete_reservation.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-bigquery-reservation/samples/generated/v1/reservation_service.delete_reservation.js,packages/google-cloud-bigquery-reservation/samples/README.md) | +| Reservation_service.failover_reservation | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-bigquery-reservation/samples/generated/v1/reservation_service.failover_reservation.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-bigquery-reservation/samples/generated/v1/reservation_service.failover_reservation.js,packages/google-cloud-bigquery-reservation/samples/README.md) | | Reservation_service.get_bi_reservation | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-bigquery-reservation/samples/generated/v1/reservation_service.get_bi_reservation.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-bigquery-reservation/samples/generated/v1/reservation_service.get_bi_reservation.js,packages/google-cloud-bigquery-reservation/samples/README.md) | | Reservation_service.get_capacity_commitment | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-bigquery-reservation/samples/generated/v1/reservation_service.get_capacity_commitment.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-bigquery-reservation/samples/generated/v1/reservation_service.get_capacity_commitment.js,packages/google-cloud-bigquery-reservation/samples/README.md) | | Reservation_service.get_reservation | [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-bigquery-reservation/samples/generated/v1/reservation_service.get_reservation.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-bigquery-reservation/samples/generated/v1/reservation_service.get_reservation.js,packages/google-cloud-bigquery-reservation/samples/README.md) | @@ -190,4 +191,4 @@ See [LICENSE](https://github.com/googleapis/google-cloud-node/blob/main/LICENSE) [projects]: https://console.cloud.google.com/project [billing]: https://support.google.com/cloud/answer/6293499#enable-billing [enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=bigqueryreservation.googleapis.com -[auth]: https://cloud.google.com/docs/authentication/getting-started +[auth]: https://cloud.google.com/docs/authentication/external/set-up-adc-local diff --git a/packages/google-cloud-bigquery-reservation/protos/google/cloud/bigquery/reservation/v1/reservation.proto b/packages/google-cloud-bigquery-reservation/protos/google/cloud/bigquery/reservation/v1/reservation.proto index cc72af26412..ba8609f2b1b 100644 --- a/packages/google-cloud-bigquery-reservation/protos/google/cloud/bigquery/reservation/v1/reservation.proto +++ b/packages/google-cloud-bigquery-reservation/protos/google/cloud/bigquery/reservation/v1/reservation.proto @@ -99,6 +99,18 @@ service ReservationService { option (google.api.method_signature) = "reservation,update_mask"; } + // Fail over a reservation to the secondary location. The operation should be + // done in the current secondary location, which will be promoted to the + // new primary location for the reservation. + // Attempting to failover a reservation in the current primary location will + // fail with the error code `google.rpc.Code.FAILED_PRECONDITION`. + rpc FailoverReservation(FailoverReservationRequest) returns (Reservation) { + option (google.api.http) = { + post: "/v1/{name=projects/*/locations/*/reservations/*}:failoverReservation" + body: "*" + }; + } + // Creates a new capacity commitment resource. rpc CreateCapacityCommitment(CreateCapacityCommitmentRequest) returns (CapacityCommitment) { @@ -401,7 +413,10 @@ message Reservation { // Auto scaling settings. message Autoscale { // Output only. The slot capacity added to this reservation when autoscale - // happens. Will be between [0, max_slots]. + // happens. Will be between [0, max_slots]. Note: after users reduce + // max_slots, it may take a while before it can be propagated, so + // current_slots may stay in the original value and could be larger than + // max_slots for that brief period (less than one minute) int64 current_slots = 1 [(google.api.field_behavior) = OUTPUT_ONLY]; // Number of slots to be scaled when needed. @@ -415,20 +430,26 @@ message Reservation { // maximum length is 64 characters. string name = 1; - // Minimum slots available to this reservation. A slot is a unit of + // Baseline slots available to this reservation. A slot is a unit of // computational power in BigQuery, and serves as the unit of parallelism. // // Queries using this reservation might use more slots during runtime if - // ignore_idle_slots is set to false. - // - // If total slot_capacity of the reservation and its siblings - // exceeds the total slot_count of all capacity commitments, the request will - // fail with `google.rpc.Code.RESOURCE_EXHAUSTED`. + // ignore_idle_slots is set to false, or autoscaling is enabled. // + // If edition is EDITION_UNSPECIFIED and total slot_capacity of the + // reservation and its siblings exceeds the total slot_count of all capacity + // commitments, the request will fail with + // `google.rpc.Code.RESOURCE_EXHAUSTED`. // - // NOTE: for reservations in US or EU multi-regions, slot capacity constraints - // are checked separately for default and auxiliary regions. See - // multi_region_auxiliary flag for more details. + // If edition is any value but EDITION_UNSPECIFIED, then the above requirement + // is not needed. The total slot_capacity of the reservation and its siblings + // may exceed the total slot_count of capacity commitments. In that case, the + // exceeding slots will be charged with the autoscale SKU. You can increase + // the number of baseline slots in a reservation every few minutes. If you + // want to decrease your baseline slots, you are limited to once an hour if + // you have recently changed your baseline slot capacity and your baseline + // slots exceed your committed slots. Otherwise, you can decrease your + // baseline slots every few minutes. int64 slot_capacity = 2; // If false, any query or pipeline job using this reservation will use idle @@ -437,8 +458,7 @@ message Reservation { // capacity specified in the slot_capacity field at most. bool ignore_idle_slots = 4; - // The configuration parameters for the auto scaling feature. Note this is an - // alpha feature. + // The configuration parameters for the auto scaling feature. Autoscale autoscale = 7; // Job concurrency target which sets a soft upper bound on the number of jobs @@ -447,8 +467,8 @@ message Reservation { // queries. // Default value is 0 which means that concurrency target will be // automatically computed by the system. - // NOTE: this field is exposed as `target_job_concurrency` in the Information - // Schema, DDL and BQ CLI. + // NOTE: this field is exposed as target job concurrency in the Information + // Schema, DDL and BigQuery CLI. int64 concurrency = 16; // Output only. Creation time of the reservation. @@ -472,6 +492,38 @@ message Reservation { // Edition of the reservation. Edition edition = 17; + + // Optional. The current location of the reservation's primary replica. This + // field is only set for reservations using the managed disaster recovery + // feature. + string primary_location = 18 [ + (google.api.field_behavior) = OPTIONAL, + (google.api.resource_reference) = { + type: "locations.googleapis.com/Location" + } + ]; + + // Optional. The current location of the reservation's secondary replica. This + // field is only set for reservations using the managed disaster recovery + // feature. Users can set this in create reservation calls + // to create a failover reservation or in update reservation calls to convert + // a non-failover reservation to a failover reservation(or vice versa). + string secondary_location = 19 [ + (google.api.field_behavior) = OPTIONAL, + (google.api.resource_reference) = { + type: "locations.googleapis.com/Location" + } + ]; + + // Optional. The location where the reservation was originally created. This + // is set only during the failover reservation's creation. All billing charges + // for the failover reservation will be applied to this location. + string original_primary_location = 20 [ + (google.api.field_behavior) = OPTIONAL, + (google.api.resource_reference) = { + type: "locations.googleapis.com/Location" + } + ]; } // Capacity commitment is a way to purchase compute capacity for BigQuery jobs @@ -510,7 +562,7 @@ message CapacityCommitment { // ACTIVE. After that, they are converted to a new commitment based on the // `renewal_plan`. Default `renewal_plan` for Trial commitment is Flex so // that it can be deleted right after committed period ends. - TRIAL = 5; + TRIAL = 5 [deprecated = true]; // Monthly commitments have a committed period of 30 days after becoming // ACTIVE. After that, they are not in a committed period anymore and can be @@ -579,12 +631,17 @@ message CapacityCommitment { State state = 4 [(google.api.field_behavior) = OUTPUT_ONLY]; // Output only. The start of the current commitment period. It is applicable - // only for ACTIVE capacity commitments. + // only for ACTIVE capacity commitments. Note after the commitment is renewed, + // commitment_start_time won't be changed. It refers to the start time of the + // original commitment. google.protobuf.Timestamp commitment_start_time = 9 [(google.api.field_behavior) = OUTPUT_ONLY]; // Output only. The end of the current commitment period. It is applicable - // only for ACTIVE capacity commitments. + // only for ACTIVE capacity commitments. Note after renewal, + // commitment_end_time is the time the renewed commitment expires. So it would + // be at a time after commitment_start_time + committed period, because we + // don't change commitment_start_time , google.protobuf.Timestamp commitment_end_time = 5 [(google.api.field_behavior) = OUTPUT_ONLY]; @@ -610,6 +667,10 @@ message CapacityCommitment { // Edition of the capacity commitment. Edition edition = 12; + + // Output only. If true, the commitment is a flat-rate commitment, otherwise, + // it's an edition commitment. + bool is_flat_rate = 14 [(google.api.field_behavior) = OUTPUT_ONLY]; } // The request for @@ -699,6 +760,18 @@ message UpdateReservationRequest { google.protobuf.FieldMask update_mask = 2; } +// The request for ReservationService.FailoverReservation. +message FailoverReservationRequest { + // Required. Resource name of the reservation to failover. E.g., + // `projects/myproject/locations/US/reservations/team1-prod` + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "bigqueryreservation.googleapis.com/Reservation" + } + ]; +} + // The request for // [ReservationService.CreateCapacityCommitment][google.cloud.bigquery.reservation.v1.ReservationService.CreateCapacityCommitment]. message CreateCapacityCommitmentRequest { @@ -846,6 +919,8 @@ message Assignment { option (google.api.resource) = { type: "bigqueryreservation.googleapis.com/Assignment" pattern: "projects/{project}/locations/{location}/reservations/{reservation}/assignments/{assignment}" + plural: "assignments" + singular: "assignment" }; // Types of job, which could be specified when using the reservation. @@ -1172,6 +1247,6 @@ enum Edition { // Enterprise edition. ENTERPRISE = 2; - // Enterprise plus edition. + // Enterprise Plus edition. ENTERPRISE_PLUS = 3; } diff --git a/packages/google-cloud-bigquery-reservation/protos/protos.d.ts b/packages/google-cloud-bigquery-reservation/protos/protos.d.ts index bda6b09b477..32f85da76d4 100644 --- a/packages/google-cloud-bigquery-reservation/protos/protos.d.ts +++ b/packages/google-cloud-bigquery-reservation/protos/protos.d.ts @@ -119,6 +119,20 @@ export namespace google { */ public updateReservation(request: google.cloud.bigquery.reservation.v1.IUpdateReservationRequest): Promise; + /** + * Calls FailoverReservation. + * @param request FailoverReservationRequest message or plain object + * @param callback Node-style callback called with the error, if any, and Reservation + */ + public failoverReservation(request: google.cloud.bigquery.reservation.v1.IFailoverReservationRequest, callback: google.cloud.bigquery.reservation.v1.ReservationService.FailoverReservationCallback): void; + + /** + * Calls FailoverReservation. + * @param request FailoverReservationRequest message or plain object + * @returns Promise + */ + public failoverReservation(request: google.cloud.bigquery.reservation.v1.IFailoverReservationRequest): Promise; + /** * Calls CreateCapacityCommitment. * @param request CreateCapacityCommitmentRequest message or plain object @@ -381,6 +395,13 @@ export namespace google { */ type UpdateReservationCallback = (error: (Error|null), response?: google.cloud.bigquery.reservation.v1.Reservation) => void; + /** + * Callback as used by {@link google.cloud.bigquery.reservation.v1.ReservationService|failoverReservation}. + * @param error Error, if any + * @param [response] Reservation + */ + type FailoverReservationCallback = (error: (Error|null), response?: google.cloud.bigquery.reservation.v1.Reservation) => void; + /** * Callback as used by {@link google.cloud.bigquery.reservation.v1.ReservationService|createCapacityCommitment}. * @param error Error, if any @@ -523,6 +544,15 @@ export namespace google { /** Reservation edition */ edition?: (google.cloud.bigquery.reservation.v1.Edition|keyof typeof google.cloud.bigquery.reservation.v1.Edition|null); + + /** Reservation primaryLocation */ + primaryLocation?: (string|null); + + /** Reservation secondaryLocation */ + secondaryLocation?: (string|null); + + /** Reservation originalPrimaryLocation */ + originalPrimaryLocation?: (string|null); } /** Represents a Reservation. */ @@ -561,6 +591,15 @@ export namespace google { /** Reservation edition. */ public edition: (google.cloud.bigquery.reservation.v1.Edition|keyof typeof google.cloud.bigquery.reservation.v1.Edition); + /** Reservation primaryLocation. */ + public primaryLocation: string; + + /** Reservation secondaryLocation. */ + public secondaryLocation: string; + + /** Reservation originalPrimaryLocation. */ + public originalPrimaryLocation: string; + /** * Creates a new Reservation instance using the specified properties. * @param [properties] Properties to set @@ -777,6 +816,9 @@ export namespace google { /** CapacityCommitment edition */ edition?: (google.cloud.bigquery.reservation.v1.Edition|keyof typeof google.cloud.bigquery.reservation.v1.Edition|null); + + /** CapacityCommitment isFlatRate */ + isFlatRate?: (boolean|null); } /** Represents a CapacityCommitment. */ @@ -818,6 +860,9 @@ export namespace google { /** CapacityCommitment edition. */ public edition: (google.cloud.bigquery.reservation.v1.Edition|keyof typeof google.cloud.bigquery.reservation.v1.Edition); + /** CapacityCommitment isFlatRate. */ + public isFlatRate: boolean; + /** * Creates a new CapacityCommitment instance using the specified properties. * @param [properties] Properties to set @@ -1539,6 +1584,103 @@ export namespace google { public static getTypeUrl(typeUrlPrefix?: string): string; } + /** Properties of a FailoverReservationRequest. */ + interface IFailoverReservationRequest { + + /** FailoverReservationRequest name */ + name?: (string|null); + } + + /** Represents a FailoverReservationRequest. */ + class FailoverReservationRequest implements IFailoverReservationRequest { + + /** + * Constructs a new FailoverReservationRequest. + * @param [properties] Properties to set + */ + constructor(properties?: google.cloud.bigquery.reservation.v1.IFailoverReservationRequest); + + /** FailoverReservationRequest name. */ + public name: string; + + /** + * Creates a new FailoverReservationRequest instance using the specified properties. + * @param [properties] Properties to set + * @returns FailoverReservationRequest instance + */ + public static create(properties?: google.cloud.bigquery.reservation.v1.IFailoverReservationRequest): google.cloud.bigquery.reservation.v1.FailoverReservationRequest; + + /** + * Encodes the specified FailoverReservationRequest message. Does not implicitly {@link google.cloud.bigquery.reservation.v1.FailoverReservationRequest.verify|verify} messages. + * @param message FailoverReservationRequest message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.cloud.bigquery.reservation.v1.IFailoverReservationRequest, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified FailoverReservationRequest message, length delimited. Does not implicitly {@link google.cloud.bigquery.reservation.v1.FailoverReservationRequest.verify|verify} messages. + * @param message FailoverReservationRequest message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.cloud.bigquery.reservation.v1.IFailoverReservationRequest, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a FailoverReservationRequest message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns FailoverReservationRequest + * @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.bigquery.reservation.v1.FailoverReservationRequest; + + /** + * Decodes a FailoverReservationRequest message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns FailoverReservationRequest + * @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.bigquery.reservation.v1.FailoverReservationRequest; + + /** + * Verifies a FailoverReservationRequest 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 FailoverReservationRequest message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns FailoverReservationRequest + */ + public static fromObject(object: { [k: string]: any }): google.cloud.bigquery.reservation.v1.FailoverReservationRequest; + + /** + * Creates a plain object from a FailoverReservationRequest message. Also converts values to other types if specified. + * @param message FailoverReservationRequest + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.cloud.bigquery.reservation.v1.FailoverReservationRequest, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this FailoverReservationRequest to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for FailoverReservationRequest + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + /** Properties of a CreateCapacityCommitmentRequest. */ interface ICreateCapacityCommitmentRequest { diff --git a/packages/google-cloud-bigquery-reservation/protos/protos.js b/packages/google-cloud-bigquery-reservation/protos/protos.js index 04a3e591d2c..cf728a4823e 100644 --- a/packages/google-cloud-bigquery-reservation/protos/protos.js +++ b/packages/google-cloud-bigquery-reservation/protos/protos.js @@ -272,6 +272,39 @@ * @variation 2 */ + /** + * Callback as used by {@link google.cloud.bigquery.reservation.v1.ReservationService|failoverReservation}. + * @memberof google.cloud.bigquery.reservation.v1.ReservationService + * @typedef FailoverReservationCallback + * @type {function} + * @param {Error|null} error Error, if any + * @param {google.cloud.bigquery.reservation.v1.Reservation} [response] Reservation + */ + + /** + * Calls FailoverReservation. + * @function failoverReservation + * @memberof google.cloud.bigquery.reservation.v1.ReservationService + * @instance + * @param {google.cloud.bigquery.reservation.v1.IFailoverReservationRequest} request FailoverReservationRequest message or plain object + * @param {google.cloud.bigquery.reservation.v1.ReservationService.FailoverReservationCallback} callback Node-style callback called with the error, if any, and Reservation + * @returns {undefined} + * @variation 1 + */ + Object.defineProperty(ReservationService.prototype.failoverReservation = function failoverReservation(request, callback) { + return this.rpcCall(failoverReservation, $root.google.cloud.bigquery.reservation.v1.FailoverReservationRequest, $root.google.cloud.bigquery.reservation.v1.Reservation, request, callback); + }, "name", { value: "FailoverReservation" }); + + /** + * Calls FailoverReservation. + * @function failoverReservation + * @memberof google.cloud.bigquery.reservation.v1.ReservationService + * @instance + * @param {google.cloud.bigquery.reservation.v1.IFailoverReservationRequest} request FailoverReservationRequest message or plain object + * @returns {Promise} Promise + * @variation 2 + */ + /** * Callback as used by {@link google.cloud.bigquery.reservation.v1.ReservationService|createCapacityCommitment}. * @memberof google.cloud.bigquery.reservation.v1.ReservationService @@ -818,6 +851,9 @@ * @property {google.protobuf.ITimestamp|null} [updateTime] Reservation updateTime * @property {boolean|null} [multiRegionAuxiliary] Reservation multiRegionAuxiliary * @property {google.cloud.bigquery.reservation.v1.Edition|null} [edition] Reservation edition + * @property {string|null} [primaryLocation] Reservation primaryLocation + * @property {string|null} [secondaryLocation] Reservation secondaryLocation + * @property {string|null} [originalPrimaryLocation] Reservation originalPrimaryLocation */ /** @@ -907,6 +943,30 @@ */ Reservation.prototype.edition = 0; + /** + * Reservation primaryLocation. + * @member {string} primaryLocation + * @memberof google.cloud.bigquery.reservation.v1.Reservation + * @instance + */ + Reservation.prototype.primaryLocation = ""; + + /** + * Reservation secondaryLocation. + * @member {string} secondaryLocation + * @memberof google.cloud.bigquery.reservation.v1.Reservation + * @instance + */ + Reservation.prototype.secondaryLocation = ""; + + /** + * Reservation originalPrimaryLocation. + * @member {string} originalPrimaryLocation + * @memberof google.cloud.bigquery.reservation.v1.Reservation + * @instance + */ + Reservation.prototype.originalPrimaryLocation = ""; + /** * Creates a new Reservation instance using the specified properties. * @function create @@ -949,6 +1009,12 @@ writer.uint32(/* id 16, wireType 0 =*/128).int64(message.concurrency); if (message.edition != null && Object.hasOwnProperty.call(message, "edition")) writer.uint32(/* id 17, wireType 0 =*/136).int32(message.edition); + if (message.primaryLocation != null && Object.hasOwnProperty.call(message, "primaryLocation")) + writer.uint32(/* id 18, wireType 2 =*/146).string(message.primaryLocation); + if (message.secondaryLocation != null && Object.hasOwnProperty.call(message, "secondaryLocation")) + writer.uint32(/* id 19, wireType 2 =*/154).string(message.secondaryLocation); + if (message.originalPrimaryLocation != null && Object.hasOwnProperty.call(message, "originalPrimaryLocation")) + writer.uint32(/* id 20, wireType 2 =*/162).string(message.originalPrimaryLocation); return writer; }; @@ -1019,6 +1085,18 @@ message.edition = reader.int32(); break; } + case 18: { + message.primaryLocation = reader.string(); + break; + } + case 19: { + message.secondaryLocation = reader.string(); + break; + } + case 20: { + message.originalPrimaryLocation = reader.string(); + break; + } default: reader.skipType(tag & 7); break; @@ -1094,6 +1172,15 @@ case 3: break; } + if (message.primaryLocation != null && message.hasOwnProperty("primaryLocation")) + if (!$util.isString(message.primaryLocation)) + return "primaryLocation: string expected"; + if (message.secondaryLocation != null && message.hasOwnProperty("secondaryLocation")) + if (!$util.isString(message.secondaryLocation)) + return "secondaryLocation: string expected"; + if (message.originalPrimaryLocation != null && message.hasOwnProperty("originalPrimaryLocation")) + if (!$util.isString(message.originalPrimaryLocation)) + return "originalPrimaryLocation: string expected"; return null; }; @@ -1172,6 +1259,12 @@ message.edition = 3; break; } + if (object.primaryLocation != null) + message.primaryLocation = String(object.primaryLocation); + if (object.secondaryLocation != null) + message.secondaryLocation = String(object.secondaryLocation); + if (object.originalPrimaryLocation != null) + message.originalPrimaryLocation = String(object.originalPrimaryLocation); return message; }; @@ -1206,6 +1299,9 @@ } else object.concurrency = options.longs === String ? "0" : 0; object.edition = options.enums === String ? "EDITION_UNSPECIFIED" : 0; + object.primaryLocation = ""; + object.secondaryLocation = ""; + object.originalPrimaryLocation = ""; } if (message.name != null && message.hasOwnProperty("name")) object.name = message.name; @@ -1231,6 +1327,12 @@ object.concurrency = options.longs === String ? $util.Long.prototype.toString.call(message.concurrency) : options.longs === Number ? new $util.LongBits(message.concurrency.low >>> 0, message.concurrency.high >>> 0).toNumber() : message.concurrency; if (message.edition != null && message.hasOwnProperty("edition")) object.edition = options.enums === String ? $root.google.cloud.bigquery.reservation.v1.Edition[message.edition] === undefined ? message.edition : $root.google.cloud.bigquery.reservation.v1.Edition[message.edition] : message.edition; + if (message.primaryLocation != null && message.hasOwnProperty("primaryLocation")) + object.primaryLocation = message.primaryLocation; + if (message.secondaryLocation != null && message.hasOwnProperty("secondaryLocation")) + object.secondaryLocation = message.secondaryLocation; + if (message.originalPrimaryLocation != null && message.hasOwnProperty("originalPrimaryLocation")) + object.originalPrimaryLocation = message.originalPrimaryLocation; return object; }; @@ -1534,6 +1636,7 @@ * @property {google.cloud.bigquery.reservation.v1.CapacityCommitment.CommitmentPlan|null} [renewalPlan] CapacityCommitment renewalPlan * @property {boolean|null} [multiRegionAuxiliary] CapacityCommitment multiRegionAuxiliary * @property {google.cloud.bigquery.reservation.v1.Edition|null} [edition] CapacityCommitment edition + * @property {boolean|null} [isFlatRate] CapacityCommitment isFlatRate */ /** @@ -1631,6 +1734,14 @@ */ CapacityCommitment.prototype.edition = 0; + /** + * CapacityCommitment isFlatRate. + * @member {boolean} isFlatRate + * @memberof google.cloud.bigquery.reservation.v1.CapacityCommitment + * @instance + */ + CapacityCommitment.prototype.isFlatRate = false; + /** * Creates a new CapacityCommitment instance using the specified properties. * @function create @@ -1675,6 +1786,8 @@ writer.uint32(/* id 10, wireType 0 =*/80).bool(message.multiRegionAuxiliary); if (message.edition != null && Object.hasOwnProperty.call(message, "edition")) writer.uint32(/* id 12, wireType 0 =*/96).int32(message.edition); + if (message.isFlatRate != null && Object.hasOwnProperty.call(message, "isFlatRate")) + writer.uint32(/* id 14, wireType 0 =*/112).bool(message.isFlatRate); return writer; }; @@ -1749,6 +1862,10 @@ message.edition = reader.int32(); break; } + case 14: { + message.isFlatRate = reader.bool(); + break; + } default: reader.skipType(tag & 7); break; @@ -1860,6 +1977,9 @@ case 3: break; } + if (message.isFlatRate != null && message.hasOwnProperty("isFlatRate")) + if (typeof message.isFlatRate !== "boolean") + return "isFlatRate: boolean expected"; return null; }; @@ -2047,6 +2167,8 @@ message.edition = 3; break; } + if (object.isFlatRate != null) + message.isFlatRate = Boolean(object.isFlatRate); return message; }; @@ -2078,6 +2200,7 @@ object.commitmentStartTime = null; object.multiRegionAuxiliary = false; object.edition = options.enums === String ? "EDITION_UNSPECIFIED" : 0; + object.isFlatRate = false; } if (message.name != null && message.hasOwnProperty("name")) object.name = message.name; @@ -2102,6 +2225,8 @@ object.multiRegionAuxiliary = message.multiRegionAuxiliary; if (message.edition != null && message.hasOwnProperty("edition")) object.edition = options.enums === String ? $root.google.cloud.bigquery.reservation.v1.Edition[message.edition] === undefined ? message.edition : $root.google.cloud.bigquery.reservation.v1.Edition[message.edition] : message.edition; + if (message.isFlatRate != null && message.hasOwnProperty("isFlatRate")) + object.isFlatRate = message.isFlatRate; return object; }; @@ -3578,6 +3703,209 @@ return UpdateReservationRequest; })(); + v1.FailoverReservationRequest = (function() { + + /** + * Properties of a FailoverReservationRequest. + * @memberof google.cloud.bigquery.reservation.v1 + * @interface IFailoverReservationRequest + * @property {string|null} [name] FailoverReservationRequest name + */ + + /** + * Constructs a new FailoverReservationRequest. + * @memberof google.cloud.bigquery.reservation.v1 + * @classdesc Represents a FailoverReservationRequest. + * @implements IFailoverReservationRequest + * @constructor + * @param {google.cloud.bigquery.reservation.v1.IFailoverReservationRequest=} [properties] Properties to set + */ + function FailoverReservationRequest(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]]; + } + + /** + * FailoverReservationRequest name. + * @member {string} name + * @memberof google.cloud.bigquery.reservation.v1.FailoverReservationRequest + * @instance + */ + FailoverReservationRequest.prototype.name = ""; + + /** + * Creates a new FailoverReservationRequest instance using the specified properties. + * @function create + * @memberof google.cloud.bigquery.reservation.v1.FailoverReservationRequest + * @static + * @param {google.cloud.bigquery.reservation.v1.IFailoverReservationRequest=} [properties] Properties to set + * @returns {google.cloud.bigquery.reservation.v1.FailoverReservationRequest} FailoverReservationRequest instance + */ + FailoverReservationRequest.create = function create(properties) { + return new FailoverReservationRequest(properties); + }; + + /** + * Encodes the specified FailoverReservationRequest message. Does not implicitly {@link google.cloud.bigquery.reservation.v1.FailoverReservationRequest.verify|verify} messages. + * @function encode + * @memberof google.cloud.bigquery.reservation.v1.FailoverReservationRequest + * @static + * @param {google.cloud.bigquery.reservation.v1.IFailoverReservationRequest} message FailoverReservationRequest message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + FailoverReservationRequest.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 FailoverReservationRequest message, length delimited. Does not implicitly {@link google.cloud.bigquery.reservation.v1.FailoverReservationRequest.verify|verify} messages. + * @function encodeDelimited + * @memberof google.cloud.bigquery.reservation.v1.FailoverReservationRequest + * @static + * @param {google.cloud.bigquery.reservation.v1.IFailoverReservationRequest} message FailoverReservationRequest message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + FailoverReservationRequest.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a FailoverReservationRequest message from the specified reader or buffer. + * @function decode + * @memberof google.cloud.bigquery.reservation.v1.FailoverReservationRequest + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.cloud.bigquery.reservation.v1.FailoverReservationRequest} FailoverReservationRequest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + FailoverReservationRequest.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.bigquery.reservation.v1.FailoverReservationRequest(); + 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 FailoverReservationRequest message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.cloud.bigquery.reservation.v1.FailoverReservationRequest + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.cloud.bigquery.reservation.v1.FailoverReservationRequest} FailoverReservationRequest + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + FailoverReservationRequest.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a FailoverReservationRequest message. + * @function verify + * @memberof google.cloud.bigquery.reservation.v1.FailoverReservationRequest + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + FailoverReservationRequest.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 FailoverReservationRequest message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.cloud.bigquery.reservation.v1.FailoverReservationRequest + * @static + * @param {Object.} object Plain object + * @returns {google.cloud.bigquery.reservation.v1.FailoverReservationRequest} FailoverReservationRequest + */ + FailoverReservationRequest.fromObject = function fromObject(object) { + if (object instanceof $root.google.cloud.bigquery.reservation.v1.FailoverReservationRequest) + return object; + var message = new $root.google.cloud.bigquery.reservation.v1.FailoverReservationRequest(); + if (object.name != null) + message.name = String(object.name); + return message; + }; + + /** + * Creates a plain object from a FailoverReservationRequest message. Also converts values to other types if specified. + * @function toObject + * @memberof google.cloud.bigquery.reservation.v1.FailoverReservationRequest + * @static + * @param {google.cloud.bigquery.reservation.v1.FailoverReservationRequest} message FailoverReservationRequest + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + FailoverReservationRequest.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 FailoverReservationRequest to JSON. + * @function toJSON + * @memberof google.cloud.bigquery.reservation.v1.FailoverReservationRequest + * @instance + * @returns {Object.} JSON object + */ + FailoverReservationRequest.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for FailoverReservationRequest + * @function getTypeUrl + * @memberof google.cloud.bigquery.reservation.v1.FailoverReservationRequest + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + FailoverReservationRequest.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.cloud.bigquery.reservation.v1.FailoverReservationRequest"; + }; + + return FailoverReservationRequest; + })(); + v1.CreateCapacityCommitmentRequest = (function() { /** diff --git a/packages/google-cloud-bigquery-reservation/protos/protos.json b/packages/google-cloud-bigquery-reservation/protos/protos.json index 11aa079eba0..1a4d9953234 100644 --- a/packages/google-cloud-bigquery-reservation/protos/protos.json +++ b/packages/google-cloud-bigquery-reservation/protos/protos.json @@ -1,4 +1,7 @@ { + "options": { + "syntax": "proto3" + }, "nested": { "google": { "nested": { @@ -118,6 +121,22 @@ } ] }, + "FailoverReservation": { + "requestType": "FailoverReservationRequest", + "responseType": "Reservation", + "options": { + "(google.api.http).post": "/v1/{name=projects/*/locations/*/reservations/*}:failoverReservation", + "(google.api.http).body": "*" + }, + "parsedOptions": [ + { + "(google.api.http)": { + "post": "/v1/{name=projects/*/locations/*/reservations/*}:failoverReservation", + "body": "*" + } + } + ] + }, "CreateCapacityCommitment": { "requestType": "CreateCapacityCommitmentRequest", "responseType": "CapacityCommitment", @@ -475,6 +494,30 @@ "edition": { "type": "Edition", "id": 17 + }, + "primaryLocation": { + "type": "string", + "id": 18, + "options": { + "(google.api.field_behavior)": "OPTIONAL", + "(google.api.resource_reference).type": "locations.googleapis.com/Location" + } + }, + "secondaryLocation": { + "type": "string", + "id": 19, + "options": { + "(google.api.field_behavior)": "OPTIONAL", + "(google.api.resource_reference).type": "locations.googleapis.com/Location" + } + }, + "originalPrimaryLocation": { + "type": "string", + "id": 20, + "options": { + "(google.api.field_behavior)": "OPTIONAL", + "(google.api.resource_reference).type": "locations.googleapis.com/Location" + } } }, "nested": { @@ -555,6 +598,13 @@ "edition": { "type": "Edition", "id": 12 + }, + "isFlatRate": { + "type": "bool", + "id": 14, + "options": { + "(google.api.field_behavior)": "OUTPUT_ONLY" + } } }, "nested": { @@ -563,6 +613,9 @@ "FLEX_FLAT_RATE": { "deprecated": true }, + "TRIAL": { + "deprecated": true + }, "MONTHLY_FLAT_RATE": { "deprecated": true }, @@ -682,6 +735,18 @@ } } }, + "FailoverReservationRequest": { + "fields": { + "name": { + "type": "string", + "id": 1, + "options": { + "(google.api.field_behavior)": "REQUIRED", + "(google.api.resource_reference).type": "bigqueryreservation.googleapis.com/Reservation" + } + } + } + }, "CreateCapacityCommitmentRequest": { "fields": { "parent": { @@ -826,7 +891,9 @@ "Assignment": { "options": { "(google.api.resource).type": "bigqueryreservation.googleapis.com/Assignment", - "(google.api.resource).pattern": "projects/{project}/locations/{location}/reservations/{reservation}/assignments/{assignment}" + "(google.api.resource).pattern": "projects/{project}/locations/{location}/reservations/{reservation}/assignments/{assignment}", + "(google.api.resource).plural": "assignments", + "(google.api.resource).singular": "assignment" }, "fields": { "name": { diff --git a/packages/google-cloud-bigquery-reservation/samples/README.md b/packages/google-cloud-bigquery-reservation/samples/README.md index 6f60847f1cb..0347134be2a 100644 --- a/packages/google-cloud-bigquery-reservation/samples/README.md +++ b/packages/google-cloud-bigquery-reservation/samples/README.md @@ -18,6 +18,7 @@ * [Reservation_service.delete_assignment](#reservation_service.delete_assignment) * [Reservation_service.delete_capacity_commitment](#reservation_service.delete_capacity_commitment) * [Reservation_service.delete_reservation](#reservation_service.delete_reservation) + * [Reservation_service.failover_reservation](#reservation_service.failover_reservation) * [Reservation_service.get_bi_reservation](#reservation_service.get_bi_reservation) * [Reservation_service.get_capacity_commitment](#reservation_service.get_capacity_commitment) * [Reservation_service.get_reservation](#reservation_service.get_reservation) @@ -152,6 +153,23 @@ __Usage:__ +### Reservation_service.failover_reservation + +View the [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-bigquery-reservation/samples/generated/v1/reservation_service.failover_reservation.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-bigquery-reservation/samples/generated/v1/reservation_service.failover_reservation.js,samples/README.md) + +__Usage:__ + + +`node packages/google-cloud-bigquery-reservation/samples/generated/v1/reservation_service.failover_reservation.js` + + +----- + + + + ### Reservation_service.get_bi_reservation View the [source code](https://github.com/googleapis/google-cloud-node/blob/main/packages/google-cloud-bigquery-reservation/samples/generated/v1/reservation_service.get_bi_reservation.js). diff --git a/packages/google-cloud-bigquery-reservation/samples/generated/v1/reservation_service.failover_reservation.js b/packages/google-cloud-bigquery-reservation/samples/generated/v1/reservation_service.failover_reservation.js new file mode 100644 index 00000000000..bec84845114 --- /dev/null +++ b/packages/google-cloud-bigquery-reservation/samples/generated/v1/reservation_service.failover_reservation.js @@ -0,0 +1,62 @@ +// Copyright 2024 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 bigqueryreservation_v1_generated_ReservationService_FailoverReservation_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. Resource name of the reservation to failover. E.g., + * `projects/myproject/locations/US/reservations/team1-prod` + */ + // const name = 'abc123' + + // Imports the Reservation library + const {ReservationServiceClient} = require('@google-cloud/bigquery-reservation').v1; + + // Instantiates a client + const reservationClient = new ReservationServiceClient(); + + async function callFailoverReservation() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await reservationClient.failoverReservation(request); + console.log(response); + } + + callFailoverReservation(); + // [END bigqueryreservation_v1_generated_ReservationService_FailoverReservation_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-bigquery-reservation/samples/generated/v1/snippet_metadata_google.cloud.bigquery.reservation.v1.json b/packages/google-cloud-bigquery-reservation/samples/generated/v1/snippet_metadata_google.cloud.bigquery.reservation.v1.json index 07ea926ea44..866a1eaf891 100644 --- a/packages/google-cloud-bigquery-reservation/samples/generated/v1/snippet_metadata_google.cloud.bigquery.reservation.v1.json +++ b/packages/google-cloud-bigquery-reservation/samples/generated/v1/snippet_metadata_google.cloud.bigquery.reservation.v1.json @@ -231,6 +231,46 @@ } } }, + { + "regionTag": "bigqueryreservation_v1_generated_ReservationService_FailoverReservation_async", + "title": "ReservationService failoverReservation Sample", + "origin": "API_DEFINITION", + "description": " Fail over a reservation to the secondary location. The operation should be done in the current secondary location, which will be promoted to the new primary location for the reservation. Attempting to failover a reservation in the current primary location will fail with the error code `google.rpc.Code.FAILED_PRECONDITION`.", + "canonical": true, + "file": "reservation_service.failover_reservation.js", + "language": "JAVASCRIPT", + "segments": [ + { + "start": 25, + "end": 54, + "type": "FULL" + } + ], + "clientMethod": { + "shortName": "FailoverReservation", + "fullName": "google.cloud.bigquery.reservation.v1.ReservationService.FailoverReservation", + "async": true, + "parameters": [ + { + "name": "name", + "type": "TYPE_STRING" + } + ], + "resultType": ".google.cloud.bigquery.reservation.v1.Reservation", + "client": { + "shortName": "ReservationServiceClient", + "fullName": "google.cloud.bigquery.reservation.v1.ReservationServiceClient" + }, + "method": { + "shortName": "FailoverReservation", + "fullName": "google.cloud.bigquery.reservation.v1.ReservationService.FailoverReservation", + "service": { + "shortName": "ReservationService", + "fullName": "google.cloud.bigquery.reservation.v1.ReservationService" + } + } + } + }, { "regionTag": "bigqueryreservation_v1_generated_ReservationService_CreateCapacityCommitment_async", "title": "ReservationService createCapacityCommitment Sample", diff --git a/packages/google-cloud-bigquery-reservation/src/v1/gapic_metadata.json b/packages/google-cloud-bigquery-reservation/src/v1/gapic_metadata.json index 03838a39d9b..b2eadeec04a 100644 --- a/packages/google-cloud-bigquery-reservation/src/v1/gapic_metadata.json +++ b/packages/google-cloud-bigquery-reservation/src/v1/gapic_metadata.json @@ -30,6 +30,11 @@ "updateReservation" ] }, + "FailoverReservation": { + "methods": [ + "failoverReservation" + ] + }, "CreateCapacityCommitment": { "methods": [ "createCapacityCommitment" @@ -150,6 +155,11 @@ "updateReservation" ] }, + "FailoverReservation": { + "methods": [ + "failoverReservation" + ] + }, "CreateCapacityCommitment": { "methods": [ "createCapacityCommitment" diff --git a/packages/google-cloud-bigquery-reservation/src/v1/reservation_service_client.ts b/packages/google-cloud-bigquery-reservation/src/v1/reservation_service_client.ts index f736ff492bb..23fcbf7c76c 100644 --- a/packages/google-cloud-bigquery-reservation/src/v1/reservation_service_client.ts +++ b/packages/google-cloud-bigquery-reservation/src/v1/reservation_service_client.ts @@ -320,6 +320,7 @@ export class ReservationServiceClient { 'getReservation', 'deleteReservation', 'updateReservation', + 'failoverReservation', 'createCapacityCommitment', 'listCapacityCommitments', 'getCapacityCommitment', @@ -850,6 +851,107 @@ export class ReservationServiceClient { this.initialize(); return this.innerApiCalls.updateReservation(request, options, callback); } + /** + * Fail over a reservation to the secondary location. The operation should be + * done in the current secondary location, which will be promoted to the + * new primary location for the reservation. + * Attempting to failover a reservation in the current primary location will + * fail with the error code `google.rpc.Code.FAILED_PRECONDITION`. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. Resource name of the reservation to failover. E.g., + * `projects/myproject/locations/US/reservations/team1-prod` + * @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 {@link protos.google.cloud.bigquery.reservation.v1.Reservation|Reservation}. + * Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation } + * for more details and examples. + * @example include:samples/generated/v1/reservation_service.failover_reservation.js + * region_tag:bigqueryreservation_v1_generated_ReservationService_FailoverReservation_async + */ + failoverReservation( + request?: protos.google.cloud.bigquery.reservation.v1.IFailoverReservationRequest, + options?: CallOptions + ): Promise< + [ + protos.google.cloud.bigquery.reservation.v1.IReservation, + ( + | protos.google.cloud.bigquery.reservation.v1.IFailoverReservationRequest + | undefined + ), + {} | undefined, + ] + >; + failoverReservation( + request: protos.google.cloud.bigquery.reservation.v1.IFailoverReservationRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.bigquery.reservation.v1.IReservation, + | protos.google.cloud.bigquery.reservation.v1.IFailoverReservationRequest + | null + | undefined, + {} | null | undefined + > + ): void; + failoverReservation( + request: protos.google.cloud.bigquery.reservation.v1.IFailoverReservationRequest, + callback: Callback< + protos.google.cloud.bigquery.reservation.v1.IReservation, + | protos.google.cloud.bigquery.reservation.v1.IFailoverReservationRequest + | null + | undefined, + {} | null | undefined + > + ): void; + failoverReservation( + request?: protos.google.cloud.bigquery.reservation.v1.IFailoverReservationRequest, + optionsOrCallback?: + | CallOptions + | Callback< + protos.google.cloud.bigquery.reservation.v1.IReservation, + | protos.google.cloud.bigquery.reservation.v1.IFailoverReservationRequest + | null + | undefined, + {} | null | undefined + >, + callback?: Callback< + protos.google.cloud.bigquery.reservation.v1.IReservation, + | protos.google.cloud.bigquery.reservation.v1.IFailoverReservationRequest + | null + | undefined, + {} | null | undefined + > + ): Promise< + [ + protos.google.cloud.bigquery.reservation.v1.IReservation, + ( + | protos.google.cloud.bigquery.reservation.v1.IFailoverReservationRequest + | 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.failoverReservation(request, options, callback); + } /** * Creates a new capacity commitment resource. * diff --git a/packages/google-cloud-bigquery-reservation/src/v1/reservation_service_client_config.json b/packages/google-cloud-bigquery-reservation/src/v1/reservation_service_client_config.json index 2ac442ba027..7db5c0ff175 100644 --- a/packages/google-cloud-bigquery-reservation/src/v1/reservation_service_client_config.json +++ b/packages/google-cloud-bigquery-reservation/src/v1/reservation_service_client_config.json @@ -45,6 +45,10 @@ "retry_codes_name": "non_idempotent", "retry_params_name": "default" }, + "FailoverReservation": { + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, "CreateCapacityCommitment": { "timeout_millis": 300000, "retry_codes_name": "non_idempotent", diff --git a/packages/google-cloud-bigquery-reservation/test/gapic_reservation_service_v1.ts b/packages/google-cloud-bigquery-reservation/test/gapic_reservation_service_v1.ts index f89be66dcd9..99ee2502e2f 100644 --- a/packages/google-cloud-bigquery-reservation/test/gapic_reservation_service_v1.ts +++ b/packages/google-cloud-bigquery-reservation/test/gapic_reservation_service_v1.ts @@ -834,6 +834,137 @@ describe('v1.ReservationServiceClient', () => { }); }); + describe('failoverReservation', () => { + it('invokes failoverReservation without error', async () => { + const client = new reservationserviceModule.v1.ReservationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.bigquery.reservation.v1.FailoverReservationRequest() + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.bigquery.reservation.v1.FailoverReservationRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.bigquery.reservation.v1.Reservation() + ); + client.innerApiCalls.failoverReservation = + stubSimpleCall(expectedResponse); + const [response] = await client.failoverReservation(request); + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.failoverReservation as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.failoverReservation as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes failoverReservation without error using callback', async () => { + const client = new reservationserviceModule.v1.ReservationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.bigquery.reservation.v1.FailoverReservationRequest() + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.bigquery.reservation.v1.FailoverReservationRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedResponse = generateSampleMessage( + new protos.google.cloud.bigquery.reservation.v1.Reservation() + ); + client.innerApiCalls.failoverReservation = + stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.failoverReservation( + request, + ( + err?: Error | null, + result?: protos.google.cloud.bigquery.reservation.v1.IReservation | null + ) => { + if (err) { + reject(err); + } else { + resolve(result); + } + } + ); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + const actualRequest = ( + client.innerApiCalls.failoverReservation as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.failoverReservation as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes failoverReservation with error', async () => { + const client = new reservationserviceModule.v1.ReservationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.bigquery.reservation.v1.FailoverReservationRequest() + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.bigquery.reservation.v1.FailoverReservationRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedHeaderRequestParams = `name=${defaultValue1}`; + const expectedError = new Error('expected'); + client.innerApiCalls.failoverReservation = stubSimpleCall( + undefined, + expectedError + ); + await assert.rejects(client.failoverReservation(request), expectedError); + const actualRequest = ( + client.innerApiCalls.failoverReservation as SinonStub + ).getCall(0).args[0]; + assert.deepStrictEqual(actualRequest, request); + const actualHeaderRequestParams = ( + client.innerApiCalls.failoverReservation as SinonStub + ).getCall(0).args[1].otherArgs.headers['x-goog-request-params']; + assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); + }); + + it('invokes failoverReservation with closed client', async () => { + const client = new reservationserviceModule.v1.ReservationServiceClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage( + new protos.google.cloud.bigquery.reservation.v1.FailoverReservationRequest() + ); + const defaultValue1 = getTypeDefaultValue( + '.google.cloud.bigquery.reservation.v1.FailoverReservationRequest', + ['name'] + ); + request.name = defaultValue1; + const expectedError = new Error('The client has already been closed.'); + client.close(); + await assert.rejects(client.failoverReservation(request), expectedError); + }); + }); + describe('createCapacityCommitment', () => { it('invokes createCapacityCommitment without error', async () => { const client = new reservationserviceModule.v1.ReservationServiceClient({