From a1986cb1be62f0351ea845a8e08fc2a2b82a74f8 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 31 Mar 2022 10:44:15 -0700 Subject: [PATCH] feat: introduce hot tablet/ping and warm RPCs (#5119) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add WarmAndPing request for channel priming PiperOrigin-RevId: 428795660 Source-Link: https://github.com/googleapis/googleapis/commit/6cce671cb21e5ba9ee785dfe50f5a86b87bb5f21 Source-Link: https://github.com/googleapis/googleapis-gen/commit/2282bc1b081364ea783300be91a8c14cb4a718c4 Copy-Tag: eyJwIjoiQmlndGFibGUvLk93bEJvdC55YW1sIiwiaCI6IjIyODJiYzFiMDgxMzY0ZWE3ODMzMDBiZTkxYThjMTRjYjRhNzE4YzQifQ== * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * feat: Add ListHotTablets API method and protobufs PiperOrigin-RevId: 436758628 Source-Link: https://github.com/googleapis/googleapis/commit/92ab86a79f4a9e774dfd6ee533d9376af084b376 Source-Link: https://github.com/googleapis/googleapis-gen/commit/931ef114d5f845abf117bf8e0a29836ca300b694 Copy-Tag: eyJwIjoiQmlndGFibGUvLk93bEJvdC55YW1sIiwiaCI6IjkzMWVmMTE0ZDVmODQ1YWJmMTE3YmY4ZTBhMjk4MzZjYTMwMGI2OTQifQ== * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * docs: Update `cpu_utilization_percent` limit docs: Remove the limitation of all clusters in a CMEK instance must use the same key PiperOrigin-RevId: 438385300 Source-Link: https://github.com/googleapis/googleapis/commit/c59f02e87d3ce01699ebf2adda7381af7c5eca31 Source-Link: https://github.com/googleapis/googleapis-gen/commit/04d03d17aafa7b4422f73c93600f040542817fcd Copy-Tag: eyJwIjoiQmlndGFibGUvLk93bEJvdC55YW1sIiwiaCI6IjA0ZDAzZDE3YWFmYTdiNDQyMmY3M2M5MzYwMGYwNDA1NDI4MTdmY2QifQ== * 🦉 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 --- .../Admin/V2/BigtableInstanceAdmin.php | 19 +- Bigtable/metadata/Admin/V2/Instance.php | Bin 3569 -> 3965 bytes Bigtable/metadata/V2/Bigtable.php | Bin 5910 -> 6367 bytes Bigtable/src/Admin/V2/AutoscalingTargets.php | 12 +- .../V2/BigtableInstanceAdminGrpcClient.php | 16 + .../src/Admin/V2/Cluster/EncryptionConfig.php | 4 - .../BigtableInstanceAdminGapicClient.php | 95 +++++- Bigtable/src/Admin/V2/HotTablet.php | 315 ++++++++++++++++++ .../src/Admin/V2/ListHotTabletsRequest.php | 275 +++++++++++++++ .../src/Admin/V2/ListHotTabletsResponse.php | 125 +++++++ ...bigtable_instance_admin_client_config.json | 5 + ...table_instance_admin_descriptor_config.php | 10 + ...able_instance_admin_rest_client_config.php | 11 + Bigtable/src/V2/BigtableGrpcClient.php | 16 + Bigtable/src/V2/Gapic/BigtableGapicClient.php | 87 +++++ Bigtable/src/V2/PingAndWarmRequest.php | 109 ++++++ Bigtable/src/V2/PingAndWarmResponse.php | 33 ++ Bigtable/src/V2/gapic_metadata.json | 5 + .../V2/resources/bigtable_client_config.json | 5 + .../resources/bigtable_rest_client_config.php | 12 + .../V2/BigtableInstanceAdminClientTest.php | 76 ++++- Bigtable/tests/Unit/V2/BigtableClientTest.php | 63 ++++ 22 files changed, 1279 insertions(+), 14 deletions(-) create mode 100644 Bigtable/src/Admin/V2/HotTablet.php create mode 100644 Bigtable/src/Admin/V2/ListHotTabletsRequest.php create mode 100644 Bigtable/src/Admin/V2/ListHotTabletsResponse.php create mode 100644 Bigtable/src/V2/PingAndWarmRequest.php create mode 100644 Bigtable/src/V2/PingAndWarmResponse.php diff --git a/Bigtable/metadata/Admin/V2/BigtableInstanceAdmin.php b/Bigtable/metadata/Admin/V2/BigtableInstanceAdmin.php index 8df9f1d39e1..c4ca9908346 100644 --- a/Bigtable/metadata/Admin/V2/BigtableInstanceAdmin.php +++ b/Bigtable/metadata/Admin/V2/BigtableInstanceAdmin.php @@ -27,7 +27,7 @@ public static function initOnce() { \GPBMetadata\Google\Protobuf\Timestamp::initOnce(); $pool->internalAddGeneratedFile( ' -Á@ +ÍD 6google/bigtable/admin/v2/bigtable_instance_admin.protogoogle.bigtable.admin.v2google/api/client.protogoogle/api/field_behavior.protogoogle/api/resource.proto\'google/bigtable/admin/v2/instance.protogoogle/iam/v1/iam_policy.protogoogle/iam/v1/policy.proto#google/longrunning/operations.protogoogle/protobuf/empty.proto google/protobuf/field_mask.protogoogle/protobuf/timestamp.proto"Û CreateInstanceRequestC parent ( B3àAúA- @@ -127,7 +127,19 @@ public static function initOnce() { name ( B/àAúA) \'bigtableadmin.googleapis.com/AppProfile ignore_warnings (BàA" -UpdateAppProfileMetadata2‰ +UpdateAppProfileMetadata"Ú +ListHotTabletsRequest< +parent ( B,àAúA& +$bigtableadmin.googleapis.com/Cluster. + +start_time ( 2.google.protobuf.Timestamp, +end_time ( 2.google.protobuf.Timestamp + page_size ( + +page_token ( "k +ListHotTabletsResponse8 + hot_tablets ( 2#.google.bigtable.admin.v2.HotTablet +next_page_token ( 2Ë! BigtableInstanceAdminÚ CreateInstance/.google.bigtable.admin.v2.CreateInstanceRequest.google.longrunning.Operation"x‚Óä“&"!/v2/{parent=projects/*}/instances:*ÚA$parent,instance_id,instance,clustersÊA" InstanceCreateInstanceMetadata‘ @@ -156,7 +168,8 @@ public static function initOnce() { DeleteAppProfile1.google.bigtable.admin.v2.DeleteAppProfileRequest.google.protobuf.Empty">‚Óä“1*//v2/{name=projects/*/instances/*/appProfiles/*}ÚAname“ GetIamPolicy".google.iam.v1.GetIamPolicyRequest.google.iam.v1.Policy"H‚Óä“7"2/v2/{resource=projects/*/instances/*}:getIamPolicy:*ÚAresourceš SetIamPolicy".google.iam.v1.SetIamPolicyRequest.google.iam.v1.Policy"O‚Óä“7"2/v2/{resource=projects/*/instances/*}:setIamPolicy:*ÚAresource,policyÅ -TestIamPermissions(.google.iam.v1.TestIamPermissionsRequest).google.iam.v1.TestIamPermissionsResponse"Z‚Óä“="8/v2/{resource=projects/*/instances/*}:testIamPermissions:*ÚAresource,permissionsšÊAbigtableadmin.googleapis.comÒA÷https://www.googleapis.com/auth/bigtable.admin,https://www.googleapis.com/auth/bigtable.admin.cluster,https://www.googleapis.com/auth/bigtable.admin.instance,https://www.googleapis.com/auth/cloud-bigtable.admin,https://www.googleapis.com/auth/cloud-bigtable.admin.cluster,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/cloud-platform.read-onlyBâ +TestIamPermissions(.google.iam.v1.TestIamPermissionsRequest).google.iam.v1.TestIamPermissionsResponse"Z‚Óä“="8/v2/{resource=projects/*/instances/*}:testIamPermissions:*ÚAresource,permissions¿ +ListHotTablets/.google.bigtable.admin.v2.ListHotTabletsRequest0.google.bigtable.admin.v2.ListHotTabletsResponse"J‚Óä“;9/v2/{parent=projects/*/instances/*/clusters/*}/hotTabletsÚAparentšÊAbigtableadmin.googleapis.comÒA÷https://www.googleapis.com/auth/bigtable.admin,https://www.googleapis.com/auth/bigtable.admin.cluster,https://www.googleapis.com/auth/bigtable.admin.instance,https://www.googleapis.com/auth/cloud-bigtable.admin,https://www.googleapis.com/auth/cloud-bigtable.admin.cluster,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/cloud-platform.read-onlyBâ com.google.bigtable.admin.v2BBigtableInstanceAdminProtoPZ=google.golang.org/genproto/googleapis/bigtable/admin/v2;adminªGoogle.Cloud.Bigtable.Admin.V2ÊGoogle\\Cloud\\Bigtable\\Admin\\V2ê"Google::Cloud::Bigtable::Admin::V2bproto3' , true); diff --git a/Bigtable/metadata/Admin/V2/Instance.php b/Bigtable/metadata/Admin/V2/Instance.php index c1a5ecb89fd804495582ac26ca43b133bda30523..e1e6f19af8ec2f2b7df6de99ba9dc26d5a05217e 100644 GIT binary patch delta 262 zcmew;{a0=SGc)T-39cCRiQej)^_k^3EtEQ#xi~%YOF|Npa#Bl#c(_>d5_3}}7!?>b zIEAdaxJp3c@nA6~keE}9`Y%TnE~UvAxn)JcnuLtGxQa^>i%Q~4GJ!goCm&}~8bGr zsYS`Dc_k9;KzSx7<_C__fdKSGc)TvQLY&EiQej)^_k^3H{ax4!UzC)1_*Ef diff --git a/Bigtable/metadata/V2/Bigtable.php b/Bigtable/metadata/V2/Bigtable.php index 084764919797c4113949aff1a0e9e6cef6f8fe13..ab1c621f186a92d6a3f240ca299aa4ec4702dd24 100644 GIT binary patch delta 313 zcmbQHci(VBH#1X<*5+R3v+R1ATtWevdFhUMDdCAlxk0IgrK!awLe^X?d5O8H5{wFr z8k|nL4;-0(ImW1SsZO5AA#3iLS6q^qmz*jj#>JOdP!L~Gl%JNFlNz6yBEbYwuO!MP zjACYSL4ICw>gGspenzGZBAc^#n%D&2F>-MuDH2kfe34H?6iEc?6sZ_>kc={l48%aC zUdE=&PbM>IE2-(18R=I~ZseDisint32 cpu_utilization_percent = 2; */ @@ -33,7 +34,8 @@ class AutoscalingTargets extends \Google\Protobuf\Internal\Message * @type int $cpu_utilization_percent * The cpu utilization that the Autoscaler should be trying to achieve. * This number is on a scale from 0 (no utilization) to - * 100 (total utilization). + * 100 (total utilization), and is limited between 10 and 80, otherwise it + * will return INVALID_ARGUMENT error. * } */ public function __construct($data = NULL) { @@ -44,7 +46,8 @@ public function __construct($data = NULL) { /** * The cpu utilization that the Autoscaler should be trying to achieve. * This number is on a scale from 0 (no utilization) to - * 100 (total utilization). + * 100 (total utilization), and is limited between 10 and 80, otherwise it + * will return INVALID_ARGUMENT error. * * Generated from protobuf field int32 cpu_utilization_percent = 2; * @return int @@ -57,7 +60,8 @@ public function getCpuUtilizationPercent() /** * The cpu utilization that the Autoscaler should be trying to achieve. * This number is on a scale from 0 (no utilization) to - * 100 (total utilization). + * 100 (total utilization), and is limited between 10 and 80, otherwise it + * will return INVALID_ARGUMENT error. * * Generated from protobuf field int32 cpu_utilization_percent = 2; * @param int $var diff --git a/Bigtable/src/Admin/V2/BigtableInstanceAdminGrpcClient.php b/Bigtable/src/Admin/V2/BigtableInstanceAdminGrpcClient.php index d0b131b9e59..d86ac2c55ab 100644 --- a/Bigtable/src/Admin/V2/BigtableInstanceAdminGrpcClient.php +++ b/Bigtable/src/Admin/V2/BigtableInstanceAdminGrpcClient.php @@ -366,4 +366,20 @@ public function TestIamPermissions(\Google\Cloud\Iam\V1\TestIamPermissionsReques $metadata, $options); } + /** + * Lists hot tablets in a cluster, within the time range provided. Hot + * tablets are ordered based on CPU usage. + * @param \Google\Cloud\Bigtable\Admin\V2\ListHotTabletsRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function ListHotTablets(\Google\Cloud\Bigtable\Admin\V2\ListHotTabletsRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.bigtable.admin.v2.BigtableInstanceAdmin/ListHotTablets', + $argument, + ['\Google\Cloud\Bigtable\Admin\V2\ListHotTabletsResponse', 'decode'], + $metadata, $options); + } + } diff --git a/Bigtable/src/Admin/V2/Cluster/EncryptionConfig.php b/Bigtable/src/Admin/V2/Cluster/EncryptionConfig.php index 7c96053470d..0c7007aa588 100644 --- a/Bigtable/src/Admin/V2/Cluster/EncryptionConfig.php +++ b/Bigtable/src/Admin/V2/Cluster/EncryptionConfig.php @@ -24,7 +24,6 @@ class EncryptionConfig extends \Google\Protobuf\Internal\Message * `cloudkms.cryptoKeyEncrypterDecrypter` role on the CMEK key. * 2) Only regional keys can be used and the region of the CMEK key must * match the region of the cluster. - * 3) All clusters within an instance must use the same CMEK key. * * Generated from protobuf field string kms_key_name = 1 [(.google.api.resource_reference) = { */ @@ -44,7 +43,6 @@ class EncryptionConfig extends \Google\Protobuf\Internal\Message * `cloudkms.cryptoKeyEncrypterDecrypter` role on the CMEK key. * 2) Only regional keys can be used and the region of the CMEK key must * match the region of the cluster. - * 3) All clusters within an instance must use the same CMEK key. * } */ public function __construct($data = NULL) { @@ -60,7 +58,6 @@ public function __construct($data = NULL) { * `cloudkms.cryptoKeyEncrypterDecrypter` role on the CMEK key. * 2) Only regional keys can be used and the region of the CMEK key must * match the region of the cluster. - * 3) All clusters within an instance must use the same CMEK key. * * Generated from protobuf field string kms_key_name = 1 [(.google.api.resource_reference) = { * @return string @@ -78,7 +75,6 @@ public function getKmsKeyName() * `cloudkms.cryptoKeyEncrypterDecrypter` role on the CMEK key. * 2) Only regional keys can be used and the region of the CMEK key must * match the region of the cluster. - * 3) All clusters within an instance must use the same CMEK key. * * Generated from protobuf field string kms_key_name = 1 [(.google.api.resource_reference) = { * @param string $var diff --git a/Bigtable/src/Admin/V2/Gapic/BigtableInstanceAdminGapicClient.php b/Bigtable/src/Admin/V2/Gapic/BigtableInstanceAdminGapicClient.php index 650f23ec50b..028badd5279 100644 --- a/Bigtable/src/Admin/V2/Gapic/BigtableInstanceAdminGapicClient.php +++ b/Bigtable/src/Admin/V2/Gapic/BigtableInstanceAdminGapicClient.php @@ -54,13 +54,15 @@ use Google\Cloud\Bigtable\Admin\V2\GetAppProfileRequest; use Google\Cloud\Bigtable\Admin\V2\GetClusterRequest; use Google\Cloud\Bigtable\Admin\V2\GetInstanceRequest; - use Google\Cloud\Bigtable\Admin\V2\Instance; + use Google\Cloud\Bigtable\Admin\V2\Instance\Type; use Google\Cloud\Bigtable\Admin\V2\ListAppProfilesRequest; use Google\Cloud\Bigtable\Admin\V2\ListAppProfilesResponse; use Google\Cloud\Bigtable\Admin\V2\ListClustersRequest; use Google\Cloud\Bigtable\Admin\V2\ListClustersResponse; +use Google\Cloud\Bigtable\Admin\V2\ListHotTabletsRequest; +use Google\Cloud\Bigtable\Admin\V2\ListHotTabletsResponse; use Google\Cloud\Bigtable\Admin\V2\ListInstancesRequest; use Google\Cloud\Bigtable\Admin\V2\ListInstancesResponse; use Google\Cloud\Bigtable\Admin\V2\PartialUpdateClusterRequest; @@ -73,8 +75,8 @@ use Google\Cloud\Iam\V1\TestIamPermissionsRequest; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; use Google\LongRunning\Operation; - use Google\Protobuf\FieldMask; + use Google\Protobuf\GPBEmpty; use Google\Protobuf\Timestamp; @@ -1099,6 +1101,95 @@ public function listClusters($parent, array $optionalArgs = []) return $this->startCall('ListClusters', ListClustersResponse::class, $optionalArgs, $request)->wait(); } + /** + * Lists hot tablets in a cluster, within the time range provided. Hot + * tablets are ordered based on CPU usage. + * + * Sample code: + * ``` + * $bigtableInstanceAdminClient = new Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient(); + * try { + * $formattedParent = $bigtableInstanceAdminClient->clusterName('[PROJECT]', '[INSTANCE]', '[CLUSTER]'); + * // Iterate over pages of elements + * $pagedResponse = $bigtableInstanceAdminClient->listHotTablets($formattedParent); + * foreach ($pagedResponse->iteratePages() as $page) { + * foreach ($page as $element) { + * // doSomethingWith($element); + * } + * } + * // Alternatively: + * // Iterate through all elements + * $pagedResponse = $bigtableInstanceAdminClient->listHotTablets($formattedParent); + * foreach ($pagedResponse->iterateAllElements() as $element) { + * // doSomethingWith($element); + * } + * } finally { + * $bigtableInstanceAdminClient->close(); + * } + * ``` + * + * @param string $parent Required. The cluster name to list hot tablets. + * Value is in the following form: + * `projects/{project}/instances/{instance}/clusters/{cluster}`. + * @param array $optionalArgs { + * Optional. + * + * @type Timestamp $startTime + * The start time to list hot tablets. The hot tablets in the response will + * have start times between the requested start time and end time. Start time + * defaults to Now if it is unset, and end time defaults to Now - 24 hours if + * it is unset. The start time should be less than the end time, and the + * maximum allowed time range between start time and end time is 48 hours. + * Start time and end time should have values between Now and Now - 14 days. + * @type Timestamp $endTime + * The end time to list hot tablets. + * @type int $pageSize + * The maximum number of resources contained in the underlying API + * response. The API may return fewer values in a page, even if + * there are additional values to be retrieved. + * @type string $pageToken + * A page token is used to specify a page of values to be returned. + * If no page token is specified (the default), the first page + * of values will be returned. Any page token used here must have + * been generated by a previous call to the API. + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. + * } + * + * @return \Google\ApiCore\PagedListResponse + * + * @throws ApiException if the remote call fails + */ + public function listHotTablets($parent, array $optionalArgs = []) + { + $request = new ListHotTabletsRequest(); + $requestParamHeaders = []; + $request->setParent($parent); + $requestParamHeaders['parent'] = $parent; + if (isset($optionalArgs['startTime'])) { + $request->setStartTime($optionalArgs['startTime']); + } + + if (isset($optionalArgs['endTime'])) { + $request->setEndTime($optionalArgs['endTime']); + } + + if (isset($optionalArgs['pageSize'])) { + $request->setPageSize($optionalArgs['pageSize']); + } + + if (isset($optionalArgs['pageToken'])) { + $request->setPageToken($optionalArgs['pageToken']); + } + + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->getPagedListResponse('ListHotTablets', $optionalArgs, ListHotTabletsResponse::class, $request); + } + /** * Lists information about instances in a project. * diff --git a/Bigtable/src/Admin/V2/HotTablet.php b/Bigtable/src/Admin/V2/HotTablet.php new file mode 100644 index 00000000000..e3e13a3a8ab --- /dev/null +++ b/Bigtable/src/Admin/V2/HotTablet.php @@ -0,0 +1,315 @@ +google.bigtable.admin.v2.HotTablet + */ +class HotTablet extends \Google\Protobuf\Internal\Message +{ + /** + * The unique name of the hot tablet. Values are of the form + * `projects/{project}/instances/{instance}/clusters/{cluster}/hotTablets/[a-zA-Z0-9_-]*`. + * + * Generated from protobuf field string name = 1; + */ + private $name = ''; + /** + * Name of the table that contains the tablet. Values are of the form + * `projects/{project}/instances/{instance}/tables/[_a-zA-Z0-9][-_.a-zA-Z0-9]*`. + * + * Generated from protobuf field string table_name = 2 [(.google.api.resource_reference) = { + */ + private $table_name = ''; + /** + * Output only. The start time of the hot tablet. + * + * Generated from protobuf field .google.protobuf.Timestamp start_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $start_time = null; + /** + * Output only. The end time of the hot tablet. + * + * Generated from protobuf field .google.protobuf.Timestamp end_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $end_time = null; + /** + * Tablet Start Key (inclusive). + * + * Generated from protobuf field string start_key = 5; + */ + private $start_key = ''; + /** + * Tablet End Key (inclusive). + * + * Generated from protobuf field string end_key = 6; + */ + private $end_key = ''; + /** + * Output only. The average CPU usage spent by a node on this tablet over the start_time to + * end_time time range. The percentage is the amount of CPU used by the node + * to serve the tablet, from 0% (tablet was not interacted with) to 100% (the + * node spent all cycles serving the hot tablet). + * + * Generated from protobuf field float node_cpu_usage_percent = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $node_cpu_usage_percent = 0.0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The unique name of the hot tablet. Values are of the form + * `projects/{project}/instances/{instance}/clusters/{cluster}/hotTablets/[a-zA-Z0-9_-]*`. + * @type string $table_name + * Name of the table that contains the tablet. Values are of the form + * `projects/{project}/instances/{instance}/tables/[_a-zA-Z0-9][-_.a-zA-Z0-9]*`. + * @type \Google\Protobuf\Timestamp $start_time + * Output only. The start time of the hot tablet. + * @type \Google\Protobuf\Timestamp $end_time + * Output only. The end time of the hot tablet. + * @type string $start_key + * Tablet Start Key (inclusive). + * @type string $end_key + * Tablet End Key (inclusive). + * @type float $node_cpu_usage_percent + * Output only. The average CPU usage spent by a node on this tablet over the start_time to + * end_time time range. The percentage is the amount of CPU used by the node + * to serve the tablet, from 0% (tablet was not interacted with) to 100% (the + * node spent all cycles serving the hot tablet). + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Bigtable\Admin\V2\Instance::initOnce(); + parent::__construct($data); + } + + /** + * The unique name of the hot tablet. Values are of the form + * `projects/{project}/instances/{instance}/clusters/{cluster}/hotTablets/[a-zA-Z0-9_-]*`. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The unique name of the hot tablet. Values are of the form + * `projects/{project}/instances/{instance}/clusters/{cluster}/hotTablets/[a-zA-Z0-9_-]*`. + * + * Generated from protobuf field string name = 1; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Name of the table that contains the tablet. Values are of the form + * `projects/{project}/instances/{instance}/tables/[_a-zA-Z0-9][-_.a-zA-Z0-9]*`. + * + * Generated from protobuf field string table_name = 2 [(.google.api.resource_reference) = { + * @return string + */ + public function getTableName() + { + return $this->table_name; + } + + /** + * Name of the table that contains the tablet. Values are of the form + * `projects/{project}/instances/{instance}/tables/[_a-zA-Z0-9][-_.a-zA-Z0-9]*`. + * + * Generated from protobuf field string table_name = 2 [(.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setTableName($var) + { + GPBUtil::checkString($var, True); + $this->table_name = $var; + + return $this; + } + + /** + * Output only. The start time of the hot tablet. + * + * Generated from protobuf field .google.protobuf.Timestamp start_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Timestamp|null + */ + public function getStartTime() + { + return $this->start_time; + } + + public function hasStartTime() + { + return isset($this->start_time); + } + + public function clearStartTime() + { + unset($this->start_time); + } + + /** + * Output only. The start time of the hot tablet. + * + * Generated from protobuf field .google.protobuf.Timestamp start_time = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setStartTime($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->start_time = $var; + + return $this; + } + + /** + * Output only. The end time of the hot tablet. + * + * Generated from protobuf field .google.protobuf.Timestamp end_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Timestamp|null + */ + public function getEndTime() + { + return $this->end_time; + } + + public function hasEndTime() + { + return isset($this->end_time); + } + + public function clearEndTime() + { + unset($this->end_time); + } + + /** + * Output only. The end time of the hot tablet. + * + * Generated from protobuf field .google.protobuf.Timestamp end_time = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setEndTime($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->end_time = $var; + + return $this; + } + + /** + * Tablet Start Key (inclusive). + * + * Generated from protobuf field string start_key = 5; + * @return string + */ + public function getStartKey() + { + return $this->start_key; + } + + /** + * Tablet Start Key (inclusive). + * + * Generated from protobuf field string start_key = 5; + * @param string $var + * @return $this + */ + public function setStartKey($var) + { + GPBUtil::checkString($var, True); + $this->start_key = $var; + + return $this; + } + + /** + * Tablet End Key (inclusive). + * + * Generated from protobuf field string end_key = 6; + * @return string + */ + public function getEndKey() + { + return $this->end_key; + } + + /** + * Tablet End Key (inclusive). + * + * Generated from protobuf field string end_key = 6; + * @param string $var + * @return $this + */ + public function setEndKey($var) + { + GPBUtil::checkString($var, True); + $this->end_key = $var; + + return $this; + } + + /** + * Output only. The average CPU usage spent by a node on this tablet over the start_time to + * end_time time range. The percentage is the amount of CPU used by the node + * to serve the tablet, from 0% (tablet was not interacted with) to 100% (the + * node spent all cycles serving the hot tablet). + * + * Generated from protobuf field float node_cpu_usage_percent = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return float + */ + public function getNodeCpuUsagePercent() + { + return $this->node_cpu_usage_percent; + } + + /** + * Output only. The average CPU usage spent by a node on this tablet over the start_time to + * end_time time range. The percentage is the amount of CPU used by the node + * to serve the tablet, from 0% (tablet was not interacted with) to 100% (the + * node spent all cycles serving the hot tablet). + * + * Generated from protobuf field float node_cpu_usage_percent = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param float $var + * @return $this + */ + public function setNodeCpuUsagePercent($var) + { + GPBUtil::checkFloat($var); + $this->node_cpu_usage_percent = $var; + + return $this; + } + +} + diff --git a/Bigtable/src/Admin/V2/ListHotTabletsRequest.php b/Bigtable/src/Admin/V2/ListHotTabletsRequest.php new file mode 100644 index 00000000000..e23d3bb663d --- /dev/null +++ b/Bigtable/src/Admin/V2/ListHotTabletsRequest.php @@ -0,0 +1,275 @@ +google.bigtable.admin.v2.ListHotTabletsRequest + */ +class ListHotTabletsRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The cluster name to list hot tablets. + * Value is in the following form: + * `projects/{project}/instances/{instance}/clusters/{cluster}`. + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + private $parent = ''; + /** + * The start time to list hot tablets. The hot tablets in the response will + * have start times between the requested start time and end time. Start time + * defaults to Now if it is unset, and end time defaults to Now - 24 hours if + * it is unset. The start time should be less than the end time, and the + * maximum allowed time range between start time and end time is 48 hours. + * Start time and end time should have values between Now and Now - 14 days. + * + * Generated from protobuf field .google.protobuf.Timestamp start_time = 2; + */ + private $start_time = null; + /** + * The end time to list hot tablets. + * + * Generated from protobuf field .google.protobuf.Timestamp end_time = 3; + */ + private $end_time = null; + /** + * Maximum number of results per page. + * A page_size that is empty or zero lets the server choose the number of + * items to return. A page_size which is strictly positive will return at most + * that many items. A negative page_size will cause an error. + * Following the first request, subsequent paginated calls do not need a + * page_size field. If a page_size is set in subsequent calls, it must match + * the page_size given in the first request. + * + * Generated from protobuf field int32 page_size = 4; + */ + private $page_size = 0; + /** + * The value of `next_page_token` returned by a previous call. + * + * Generated from protobuf field string page_token = 5; + */ + private $page_token = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $parent + * Required. The cluster name to list hot tablets. + * Value is in the following form: + * `projects/{project}/instances/{instance}/clusters/{cluster}`. + * @type \Google\Protobuf\Timestamp $start_time + * The start time to list hot tablets. The hot tablets in the response will + * have start times between the requested start time and end time. Start time + * defaults to Now if it is unset, and end time defaults to Now - 24 hours if + * it is unset. The start time should be less than the end time, and the + * maximum allowed time range between start time and end time is 48 hours. + * Start time and end time should have values between Now and Now - 14 days. + * @type \Google\Protobuf\Timestamp $end_time + * The end time to list hot tablets. + * @type int $page_size + * Maximum number of results per page. + * A page_size that is empty or zero lets the server choose the number of + * items to return. A page_size which is strictly positive will return at most + * that many items. A negative page_size will cause an error. + * Following the first request, subsequent paginated calls do not need a + * page_size field. If a page_size is set in subsequent calls, it must match + * the page_size given in the first request. + * @type string $page_token + * The value of `next_page_token` returned by a previous call. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Bigtable\Admin\V2\BigtableInstanceAdmin::initOnce(); + parent::__construct($data); + } + + /** + * Required. The cluster name to list hot tablets. + * Value is in the following form: + * `projects/{project}/instances/{instance}/clusters/{cluster}`. + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getParent() + { + return $this->parent; + } + + /** + * Required. The cluster name to list hot tablets. + * Value is in the following form: + * `projects/{project}/instances/{instance}/clusters/{cluster}`. + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setParent($var) + { + GPBUtil::checkString($var, True); + $this->parent = $var; + + return $this; + } + + /** + * The start time to list hot tablets. The hot tablets in the response will + * have start times between the requested start time and end time. Start time + * defaults to Now if it is unset, and end time defaults to Now - 24 hours if + * it is unset. The start time should be less than the end time, and the + * maximum allowed time range between start time and end time is 48 hours. + * Start time and end time should have values between Now and Now - 14 days. + * + * Generated from protobuf field .google.protobuf.Timestamp start_time = 2; + * @return \Google\Protobuf\Timestamp|null + */ + public function getStartTime() + { + return $this->start_time; + } + + public function hasStartTime() + { + return isset($this->start_time); + } + + public function clearStartTime() + { + unset($this->start_time); + } + + /** + * The start time to list hot tablets. The hot tablets in the response will + * have start times between the requested start time and end time. Start time + * defaults to Now if it is unset, and end time defaults to Now - 24 hours if + * it is unset. The start time should be less than the end time, and the + * maximum allowed time range between start time and end time is 48 hours. + * Start time and end time should have values between Now and Now - 14 days. + * + * Generated from protobuf field .google.protobuf.Timestamp start_time = 2; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setStartTime($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->start_time = $var; + + return $this; + } + + /** + * The end time to list hot tablets. + * + * Generated from protobuf field .google.protobuf.Timestamp end_time = 3; + * @return \Google\Protobuf\Timestamp|null + */ + public function getEndTime() + { + return $this->end_time; + } + + public function hasEndTime() + { + return isset($this->end_time); + } + + public function clearEndTime() + { + unset($this->end_time); + } + + /** + * The end time to list hot tablets. + * + * Generated from protobuf field .google.protobuf.Timestamp end_time = 3; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setEndTime($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->end_time = $var; + + return $this; + } + + /** + * Maximum number of results per page. + * A page_size that is empty or zero lets the server choose the number of + * items to return. A page_size which is strictly positive will return at most + * that many items. A negative page_size will cause an error. + * Following the first request, subsequent paginated calls do not need a + * page_size field. If a page_size is set in subsequent calls, it must match + * the page_size given in the first request. + * + * Generated from protobuf field int32 page_size = 4; + * @return int + */ + public function getPageSize() + { + return $this->page_size; + } + + /** + * Maximum number of results per page. + * A page_size that is empty or zero lets the server choose the number of + * items to return. A page_size which is strictly positive will return at most + * that many items. A negative page_size will cause an error. + * Following the first request, subsequent paginated calls do not need a + * page_size field. If a page_size is set in subsequent calls, it must match + * the page_size given in the first request. + * + * Generated from protobuf field int32 page_size = 4; + * @param int $var + * @return $this + */ + public function setPageSize($var) + { + GPBUtil::checkInt32($var); + $this->page_size = $var; + + return $this; + } + + /** + * The value of `next_page_token` returned by a previous call. + * + * Generated from protobuf field string page_token = 5; + * @return string + */ + public function getPageToken() + { + return $this->page_token; + } + + /** + * The value of `next_page_token` returned by a previous call. + * + * Generated from protobuf field string page_token = 5; + * @param string $var + * @return $this + */ + public function setPageToken($var) + { + GPBUtil::checkString($var, True); + $this->page_token = $var; + + return $this; + } + +} + diff --git a/Bigtable/src/Admin/V2/ListHotTabletsResponse.php b/Bigtable/src/Admin/V2/ListHotTabletsResponse.php new file mode 100644 index 00000000000..e0e86dbcbb3 --- /dev/null +++ b/Bigtable/src/Admin/V2/ListHotTabletsResponse.php @@ -0,0 +1,125 @@ +google.bigtable.admin.v2.ListHotTabletsResponse + */ +class ListHotTabletsResponse extends \Google\Protobuf\Internal\Message +{ + /** + * List of hot tablets in the tables of the requested cluster that fall + * within the requested time range. Hot tablets are ordered by node cpu usage + * percent. If there are multiple hot tablets that correspond to the same + * tablet within a 15-minute interval, only the hot tablet with the highest + * node cpu usage will be included in the response. + * + * Generated from protobuf field repeated .google.bigtable.admin.v2.HotTablet hot_tablets = 1; + */ + private $hot_tablets; + /** + * Set if not all hot tablets could be returned in a single response. + * Pass this value to `page_token` in another request to get the next + * page of results. + * + * Generated from protobuf field string next_page_token = 2; + */ + private $next_page_token = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Cloud\Bigtable\Admin\V2\HotTablet[]|\Google\Protobuf\Internal\RepeatedField $hot_tablets + * List of hot tablets in the tables of the requested cluster that fall + * within the requested time range. Hot tablets are ordered by node cpu usage + * percent. If there are multiple hot tablets that correspond to the same + * tablet within a 15-minute interval, only the hot tablet with the highest + * node cpu usage will be included in the response. + * @type string $next_page_token + * Set if not all hot tablets could be returned in a single response. + * Pass this value to `page_token` in another request to get the next + * page of results. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Bigtable\Admin\V2\BigtableInstanceAdmin::initOnce(); + parent::__construct($data); + } + + /** + * List of hot tablets in the tables of the requested cluster that fall + * within the requested time range. Hot tablets are ordered by node cpu usage + * percent. If there are multiple hot tablets that correspond to the same + * tablet within a 15-minute interval, only the hot tablet with the highest + * node cpu usage will be included in the response. + * + * Generated from protobuf field repeated .google.bigtable.admin.v2.HotTablet hot_tablets = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getHotTablets() + { + return $this->hot_tablets; + } + + /** + * List of hot tablets in the tables of the requested cluster that fall + * within the requested time range. Hot tablets are ordered by node cpu usage + * percent. If there are multiple hot tablets that correspond to the same + * tablet within a 15-minute interval, only the hot tablet with the highest + * node cpu usage will be included in the response. + * + * Generated from protobuf field repeated .google.bigtable.admin.v2.HotTablet hot_tablets = 1; + * @param \Google\Cloud\Bigtable\Admin\V2\HotTablet[]|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setHotTablets($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Bigtable\Admin\V2\HotTablet::class); + $this->hot_tablets = $arr; + + return $this; + } + + /** + * Set if not all hot tablets could be returned in a single response. + * Pass this value to `page_token` in another request to get the next + * page of results. + * + * Generated from protobuf field string next_page_token = 2; + * @return string + */ + public function getNextPageToken() + { + return $this->next_page_token; + } + + /** + * Set if not all hot tablets could be returned in a single response. + * Pass this value to `page_token` in another request to get the next + * page of results. + * + * Generated from protobuf field string next_page_token = 2; + * @param string $var + * @return $this + */ + public function setNextPageToken($var) + { + GPBUtil::checkString($var, True); + $this->next_page_token = $var; + + return $this; + } + +} + diff --git a/Bigtable/src/Admin/V2/resources/bigtable_instance_admin_client_config.json b/Bigtable/src/Admin/V2/resources/bigtable_instance_admin_client_config.json index 777756e6175..536c98a6fb2 100644 --- a/Bigtable/src/Admin/V2/resources/bigtable_instance_admin_client_config.json +++ b/Bigtable/src/Admin/V2/resources/bigtable_instance_admin_client_config.json @@ -80,6 +80,11 @@ "retry_codes_name": "idempotent", "retry_params_name": "default" }, + "ListHotTablets": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "default" + }, "ListInstances": { "timeout_millis": 60000, "retry_codes_name": "idempotent", diff --git a/Bigtable/src/Admin/V2/resources/bigtable_instance_admin_descriptor_config.php b/Bigtable/src/Admin/V2/resources/bigtable_instance_admin_descriptor_config.php index 0eba9c88f58..8ed837538e7 100644 --- a/Bigtable/src/Admin/V2/resources/bigtable_instance_admin_descriptor_config.php +++ b/Bigtable/src/Admin/V2/resources/bigtable_instance_admin_descriptor_config.php @@ -73,6 +73,16 @@ 'resourcesGetMethod' => 'getAppProfiles', ], ], + 'ListHotTablets' => [ + 'pageStreaming' => [ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getHotTablets', + ], + ], ], ], ]; diff --git a/Bigtable/src/Admin/V2/resources/bigtable_instance_admin_rest_client_config.php b/Bigtable/src/Admin/V2/resources/bigtable_instance_admin_rest_client_config.php index ad875d67545..239d8b10ede 100644 --- a/Bigtable/src/Admin/V2/resources/bigtable_instance_admin_rest_client_config.php +++ b/Bigtable/src/Admin/V2/resources/bigtable_instance_admin_rest_client_config.php @@ -148,6 +148,17 @@ ], ], ], + 'ListHotTablets' => [ + 'method' => 'get', + 'uriTemplate' => '/v2/{parent=projects/*/instances/*/clusters/*}/hotTablets', + 'placeholders' => [ + 'parent' => [ + 'getters' => [ + 'getParent', + ], + ], + ], + ], 'ListInstances' => [ 'method' => 'get', 'uriTemplate' => '/v2/{parent=projects/*}/instances', diff --git a/Bigtable/src/V2/BigtableGrpcClient.php b/Bigtable/src/V2/BigtableGrpcClient.php index c677934a3f7..d96b2cd00ce 100644 --- a/Bigtable/src/V2/BigtableGrpcClient.php +++ b/Bigtable/src/V2/BigtableGrpcClient.php @@ -117,6 +117,22 @@ public function CheckAndMutateRow(\Google\Cloud\Bigtable\V2\CheckAndMutateRowReq $metadata, $options); } + /** + * Warm up associated instance metadata for this connection. + * This call is not required but may be useful for connection keep-alive. + * @param \Google\Cloud\Bigtable\V2\PingAndWarmRequest $argument input argument + * @param array $metadata metadata + * @param array $options call options + * @return \Grpc\UnaryCall + */ + public function PingAndWarm(\Google\Cloud\Bigtable\V2\PingAndWarmRequest $argument, + $metadata = [], $options = []) { + return $this->_simpleRequest('/google.bigtable.v2.Bigtable/PingAndWarm', + $argument, + ['\Google\Cloud\Bigtable\V2\PingAndWarmResponse', 'decode'], + $metadata, $options); + } + /** * Modifies a row atomically on the server. The method reads the latest * existing timestamp and value from the specified columns and writes a new diff --git a/Bigtable/src/V2/Gapic/BigtableGapicClient.php b/Bigtable/src/V2/Gapic/BigtableGapicClient.php index f4c8d776530..7c125a4ed85 100644 --- a/Bigtable/src/V2/Gapic/BigtableGapicClient.php +++ b/Bigtable/src/V2/Gapic/BigtableGapicClient.php @@ -43,6 +43,8 @@ use Google\Cloud\Bigtable\V2\MutateRowsRequest\Entry; use Google\Cloud\Bigtable\V2\MutateRowsResponse; use Google\Cloud\Bigtable\V2\Mutation; +use Google\Cloud\Bigtable\V2\PingAndWarmRequest; +use Google\Cloud\Bigtable\V2\PingAndWarmResponse; use Google\Cloud\Bigtable\V2\ReadModifyWriteRowRequest; use Google\Cloud\Bigtable\V2\ReadModifyWriteRowResponse; use Google\Cloud\Bigtable\V2\ReadModifyWriteRule; @@ -111,6 +113,8 @@ class BigtableGapicClient 'https://www.googleapis.com/auth/cloud-platform.read-only', ]; + private static $instanceNameTemplate; + private static $tableNameTemplate; private static $pathTemplateMap; @@ -134,6 +138,15 @@ private static function getClientDefaults() ]; } + private static function getInstanceNameTemplate() + { + if (self::$instanceNameTemplate == null) { + self::$instanceNameTemplate = new PathTemplate('projects/{project}/instances/{instance}'); + } + + return self::$instanceNameTemplate; + } + private static function getTableNameTemplate() { if (self::$tableNameTemplate == null) { @@ -147,6 +160,7 @@ private static function getPathTemplateMap() { if (self::$pathTemplateMap == null) { self::$pathTemplateMap = [ + 'instance' => self::getInstanceNameTemplate(), 'table' => self::getTableNameTemplate(), ]; } @@ -154,6 +168,23 @@ private static function getPathTemplateMap() return self::$pathTemplateMap; } + /** + * Formats a string containing the fully-qualified path to represent a instance + * resource. + * + * @param string $project + * @param string $instance + * + * @return string The formatted instance resource. + */ + public static function instanceName($project, $instance) + { + return self::getInstanceNameTemplate()->render([ + 'project' => $project, + 'instance' => $instance, + ]); + } + /** * Formats a string containing the fully-qualified path to represent a table * resource. @@ -177,6 +208,7 @@ public static function tableName($project, $instance, $table) * Parses a formatted name string and returns an associative array of the components in the name. * The following name formats are supported: * Template: Pattern + * - instance: projects/{project}/instances/{instance} * - table: projects/{project}/instances/{instance}/tables/{table} * * The optional $template argument can be supplied to specify a particular pattern, @@ -492,6 +524,61 @@ public function mutateRows($tableName, $entries, array $optionalArgs = []) return $this->startCall('MutateRows', MutateRowsResponse::class, $optionalArgs, $request, Call::SERVER_STREAMING_CALL); } + /** + * Warm up associated instance metadata for this connection. + * This call is not required but may be useful for connection keep-alive. + * + * Sample code: + * ``` + * $bigtableClient = new Google\Cloud\Bigtable\V2\BigtableClient(); + * try { + * $formattedName = $bigtableClient->instanceName('[PROJECT]', '[INSTANCE]'); + * $response = $bigtableClient->pingAndWarm($formattedName); + * } finally { + * $bigtableClient->close(); + * } + * ``` + * + * @param string $name Required. The unique name of the instance to check permissions for as well as + * respond. Values are of the form `projects//instances/`. + * @param array $optionalArgs { + * Optional. + * + * @type string $appProfileId + * This value specifies routing for replication. If not specified, the + * "default" application profile will be used. + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a + * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry + * settings parameters. See the documentation on + * {@see Google\ApiCore\RetrySettings} for example usage. + * } + * + * @return \Google\Cloud\Bigtable\V2\PingAndWarmResponse + * + * @throws ApiException if the remote call fails + */ + public function pingAndWarm($name, array $optionalArgs = []) + { + $request = new PingAndWarmRequest(); + $requestParamHeaders = []; + $request->setName($name); + $nameMatches = []; + if (preg_match('/^(?projects\/[^\/]+\/instances\/[^\/]+)$/', $name, $nameMatches)) { + $requestParamHeaders['name'] = $nameMatches['name']; + } + + + if (isset($optionalArgs['appProfileId'])) { + $request->setAppProfileId($optionalArgs['appProfileId']); + $requestParamHeaders['app_profile_id'] = $optionalArgs['app_profile_id']; + } + + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startCall('PingAndWarm', PingAndWarmResponse::class, $optionalArgs, $request)->wait(); + } + /** * Modifies a row atomically on the server. The method reads the latest * existing timestamp and value from the specified columns and writes a new diff --git a/Bigtable/src/V2/PingAndWarmRequest.php b/Bigtable/src/V2/PingAndWarmRequest.php new file mode 100644 index 00000000000..4918a6050b6 --- /dev/null +++ b/Bigtable/src/V2/PingAndWarmRequest.php @@ -0,0 +1,109 @@ +google.bigtable.v2.PingAndWarmRequest + */ +class PingAndWarmRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The unique name of the instance to check permissions for as well as + * respond. Values are of the form `projects//instances/`. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + private $name = ''; + /** + * This value specifies routing for replication. If not specified, the + * "default" application profile will be used. + * + * Generated from protobuf field string app_profile_id = 2; + */ + private $app_profile_id = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The unique name of the instance to check permissions for as well as + * respond. Values are of the form `projects//instances/`. + * @type string $app_profile_id + * This value specifies routing for replication. If not specified, the + * "default" application profile will be used. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Bigtable\V2\Bigtable::initOnce(); + parent::__construct($data); + } + + /** + * Required. The unique name of the instance to check permissions for as well as + * respond. Values are of the form `projects//instances/`. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. The unique name of the instance to check permissions for as well as + * respond. Values are of the form `projects//instances/`. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * This value specifies routing for replication. If not specified, the + * "default" application profile will be used. + * + * Generated from protobuf field string app_profile_id = 2; + * @return string + */ + public function getAppProfileId() + { + return $this->app_profile_id; + } + + /** + * This value specifies routing for replication. If not specified, the + * "default" application profile will be used. + * + * Generated from protobuf field string app_profile_id = 2; + * @param string $var + * @return $this + */ + public function setAppProfileId($var) + { + GPBUtil::checkString($var, True); + $this->app_profile_id = $var; + + return $this; + } + +} + diff --git a/Bigtable/src/V2/PingAndWarmResponse.php b/Bigtable/src/V2/PingAndWarmResponse.php new file mode 100644 index 00000000000..a1485727466 --- /dev/null +++ b/Bigtable/src/V2/PingAndWarmResponse.php @@ -0,0 +1,33 @@ +google.bigtable.v2.PingAndWarmResponse + */ +class PingAndWarmResponse extends \Google\Protobuf\Internal\Message +{ + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Bigtable\V2\Bigtable::initOnce(); + parent::__construct($data); + } + +} + diff --git a/Bigtable/src/V2/gapic_metadata.json b/Bigtable/src/V2/gapic_metadata.json index 48bd5c1367b..2c2a3614753 100644 --- a/Bigtable/src/V2/gapic_metadata.json +++ b/Bigtable/src/V2/gapic_metadata.json @@ -25,6 +25,11 @@ "mutateRows" ] }, + "PingAndWarm": { + "methods": [ + "pingAndWarm" + ] + }, "ReadModifyWriteRow": { "methods": [ "readModifyWriteRow" diff --git a/Bigtable/src/V2/resources/bigtable_client_config.json b/Bigtable/src/V2/resources/bigtable_client_config.json index c26bce8a7d2..c0e9a393fec 100644 --- a/Bigtable/src/V2/resources/bigtable_client_config.json +++ b/Bigtable/src/V2/resources/bigtable_client_config.json @@ -33,6 +33,11 @@ "MutateRows": { "timeout_millis": 60000 }, + "PingAndWarm": { + "timeout_millis": 60000, + "retry_codes_name": "non_idempotent", + "retry_params_name": "default" + }, "ReadModifyWriteRow": { "timeout_millis": 60000, "retry_codes_name": "non_idempotent", diff --git a/Bigtable/src/V2/resources/bigtable_rest_client_config.php b/Bigtable/src/V2/resources/bigtable_rest_client_config.php index b38f79acdf3..38fffbd5301 100644 --- a/Bigtable/src/V2/resources/bigtable_rest_client_config.php +++ b/Bigtable/src/V2/resources/bigtable_rest_client_config.php @@ -39,6 +39,18 @@ ], ], ], + 'PingAndWarm' => [ + 'method' => 'post', + 'uriTemplate' => '/v2/{name=projects/*/instances/*}:ping', + 'body' => '*', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], 'ReadModifyWriteRow' => [ 'method' => 'post', 'uriTemplate' => '/v2/{table_name=projects/*/instances/*/tables/*}:readModifyWriteRow', diff --git a/Bigtable/tests/Unit/Admin/V2/BigtableInstanceAdminClientTest.php b/Bigtable/tests/Unit/Admin/V2/BigtableInstanceAdminClientTest.php index 83898442c27..0411d15821b 100644 --- a/Bigtable/tests/Unit/Admin/V2/BigtableInstanceAdminClientTest.php +++ b/Bigtable/tests/Unit/Admin/V2/BigtableInstanceAdminClientTest.php @@ -33,11 +33,13 @@ use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient; use Google\Cloud\Bigtable\Admin\V2\Cluster; -use Google\Cloud\Bigtable\Admin\V2\Instance; +use Google\Cloud\Bigtable\Admin\V2\HotTablet; +use Google\Cloud\Bigtable\Admin\V2\Instance; use Google\Cloud\Bigtable\Admin\V2\Instance\Type; use Google\Cloud\Bigtable\Admin\V2\ListAppProfilesResponse; use Google\Cloud\Bigtable\Admin\V2\ListClustersResponse; +use Google\Cloud\Bigtable\Admin\V2\ListHotTabletsResponse; use Google\Cloud\Bigtable\Admin\V2\ListInstancesResponse; use Google\Cloud\Iam\V1\Policy; use Google\Cloud\Iam\V1\TestIamPermissionsResponse; @@ -1067,6 +1069,78 @@ public function listClustersExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** + * @test + */ + public function listHotTabletsTest() + { + $transport = $this->createTransport(); + $client = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $hotTabletsElement = new HotTablet(); + $hotTablets = [ + $hotTabletsElement, + ]; + $expectedResponse = new ListHotTabletsResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setHotTablets($hotTablets); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $client->clusterName('[PROJECT]', '[INSTANCE]', '[CLUSTER]'); + $response = $client->listHotTablets($formattedParent); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getHotTablets()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.bigtable.admin.v2.BigtableInstanceAdmin/ListHotTablets', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** + * @test + */ + public function listHotTabletsExceptionTest() + { + $transport = $this->createTransport(); + $client = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedParent = $client->clusterName('[PROJECT]', '[INSTANCE]', '[CLUSTER]'); + try { + $client->listHotTablets($formattedParent); + // If the $client method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** * @test */ diff --git a/Bigtable/tests/Unit/V2/BigtableClientTest.php b/Bigtable/tests/Unit/V2/BigtableClientTest.php index a9619a17e80..5884f230856 100644 --- a/Bigtable/tests/Unit/V2/BigtableClientTest.php +++ b/Bigtable/tests/Unit/V2/BigtableClientTest.php @@ -33,6 +33,7 @@ use Google\Cloud\Bigtable\V2\CheckAndMutateRowResponse; use Google\Cloud\Bigtable\V2\MutateRowResponse; use Google\Cloud\Bigtable\V2\MutateRowsResponse; +use Google\Cloud\Bigtable\V2\PingAndWarmResponse; use Google\Cloud\Bigtable\V2\ReadModifyWriteRowResponse; use Google\Cloud\Bigtable\V2\ReadRowsResponse; use Google\Cloud\Bigtable\V2\SampleRowKeysResponse; @@ -289,6 +290,68 @@ public function mutateRowsExceptionTest() $this->assertTrue($transport->isExhausted()); } + /** + * @test + */ + public function pingAndWarmTest() + { + $transport = $this->createTransport(); + $client = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new PingAndWarmResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $client->instanceName('[PROJECT]', '[INSTANCE]'); + $response = $client->pingAndWarm($formattedName); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.bigtable.v2.Bigtable/PingAndWarm', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** + * @test + */ + public function pingAndWarmExceptionTest() + { + $transport = $this->createTransport(); + $client = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode([ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], JSON_PRETTY_PRINT); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $client->instanceName('[PROJECT]', '[INSTANCE]'); + try { + $client->pingAndWarm($formattedName); + // If the $client method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + /** * @test */