From 8b1f6e3482aeb9a9962e5b92f3ff4806a2f95196 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Wed, 22 Mar 2023 12:10:03 -0700 Subject: [PATCH] feat: Update Compute Engine API to revision 20230307 (#786) (#5986) Source-Link: https://github.com/googleapis/googleapis/commit/f64a3c8418e2e4e493b6a432220d774e7942141a Source-Link: https://github.com/googleapis/googleapis-gen/commit/808541b7e7697e2984a0ea0eba1adb5560dade97 Copy-Tag: eyJwIjoiQ29tcHV0ZS8uT3dsQm90LnlhbWwiLCJoIjoiODA4NTQxYjdlNzY5N2UyOTg0YTBlYTBlYmExYWRiNTU2MGRhZGU5NyJ9 --- Compute/metadata/V1/Compute.php | Bin 579129 -> 579938 bytes .../simulate_maintenance_event.php | 87 +++++++ Compute/src/V1/Enums/GuestOsFeature/Type.php | 2 + .../src/V1/Gapic/NodeGroupsGapicClient.php | 81 +++++++ Compute/src/V1/GuestOsFeature/Type.php | 5 + .../HealthState.php | 8 + ...eGroupsSimulateMaintenanceEventRequest.php | 66 ++++++ ...mulateMaintenanceEventNodeGroupRequest.php | 223 ++++++++++++++++++ Compute/src/V1/gapic_metadata.json | 5 + .../resources/node_groups_client_config.json | 5 + .../node_groups_descriptor_config.php | 16 ++ .../node_groups_rest_client_config.php | 22 ++ .../tests/Unit/V1/NodeGroupsClientTest.php | 124 ++++++++++ 13 files changed, 644 insertions(+) create mode 100644 Compute/samples/V1/NodeGroupsClient/simulate_maintenance_event.php create mode 100644 Compute/src/V1/NodeGroupsSimulateMaintenanceEventRequest.php create mode 100644 Compute/src/V1/SimulateMaintenanceEventNodeGroupRequest.php diff --git a/Compute/metadata/V1/Compute.php b/Compute/metadata/V1/Compute.php index ce6fedb6625b675472a75c4f5e709fd196771e02..e766d085d78dcc8523c1462d492c4db5292bb68e 100644 GIT binary patch delta 388 zcmdnFM)}bu&T{>ilcCllkMjf^{|&)LGL!PL$)J#asx^z?^Y7z<^jxrBpV z!{U8B!(8KiJ>7#GLmZuaTm^b&|JcRY9=Mfpd*D_ki5tAOT$+CQDXH#7`K1NL)8%il zNle%6W|nHt>}B4b*~@ahpXDGEmj+m3a-f8sLk}aDc^*(hd^%W1d~s%OX-;BEYJ6^D zW?o5ZUSeKyYJ6&0YFA>lYA?(78{?k8tvMb3HH(9FcN>@Cv;lF4Z?yrp zZ?ys!*oVc91GmME1lNy;;2s5s;2s9I;2sB_BLe#xw}3(i#tVnfPY1WpPY9EV6$2_; diff --git a/Compute/samples/V1/NodeGroupsClient/simulate_maintenance_event.php b/Compute/samples/V1/NodeGroupsClient/simulate_maintenance_event.php new file mode 100644 index 00000000000..185e9f0e17e --- /dev/null +++ b/Compute/samples/V1/NodeGroupsClient/simulate_maintenance_event.php @@ -0,0 +1,87 @@ +simulateMaintenanceEvent( + $nodeGroup, + $nodeGroupsSimulateMaintenanceEventRequestResource, + $project, + $zone + ); + $response->pollUntilComplete(); + + if ($response->operationSucceeded()) { + printf('Operation completed successfully.' . PHP_EOL); + } else { + /** @var Status $error */ + $error = $response->getError(); + printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString()); + } + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample 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. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $nodeGroup = '[NODE_GROUP]'; + $project = '[PROJECT]'; + $zone = '[ZONE]'; + + simulate_maintenance_event_sample($nodeGroup, $project, $zone); +} +// [END compute_v1_generated_NodeGroups_SimulateMaintenanceEvent_sync] diff --git a/Compute/src/V1/Enums/GuestOsFeature/Type.php b/Compute/src/V1/Enums/GuestOsFeature/Type.php index 3cd060bcf81..cbe3464d950 100644 --- a/Compute/src/V1/Enums/GuestOsFeature/Type.php +++ b/Compute/src/V1/Enums/GuestOsFeature/Type.php @@ -42,6 +42,8 @@ class Type const SEV_CAPABLE = 'SEV_CAPABLE'; + const SEV_LIVE_MIGRATABLE = 'SEV_LIVE_MIGRATABLE'; + const SEV_SNP_CAPABLE = 'SEV_SNP_CAPABLE'; const UEFI_COMPATIBLE = 'UEFI_COMPATIBLE'; diff --git a/Compute/src/V1/Gapic/NodeGroupsGapicClient.php b/Compute/src/V1/Gapic/NodeGroupsGapicClient.php index 6245450f14b..e3b53f2847c 100644 --- a/Compute/src/V1/Gapic/NodeGroupsGapicClient.php +++ b/Compute/src/V1/Gapic/NodeGroupsGapicClient.php @@ -49,11 +49,13 @@ use Google\Cloud\Compute\V1\NodeGroupsDeleteNodesRequest; use Google\Cloud\Compute\V1\NodeGroupsListNodes; use Google\Cloud\Compute\V1\NodeGroupsSetNodeTemplateRequest; +use Google\Cloud\Compute\V1\NodeGroupsSimulateMaintenanceEventRequest; use Google\Cloud\Compute\V1\Operation; use Google\Cloud\Compute\V1\PatchNodeGroupRequest; use Google\Cloud\Compute\V1\Policy; use Google\Cloud\Compute\V1\SetIamPolicyNodeGroupRequest; use Google\Cloud\Compute\V1\SetNodeTemplateNodeGroupRequest; +use Google\Cloud\Compute\V1\SimulateMaintenanceEventNodeGroupRequest; use Google\Cloud\Compute\V1\TestIamPermissionsNodeGroupRequest; use Google\Cloud\Compute\V1\TestPermissionsRequest; use Google\Cloud\Compute\V1\TestPermissionsResponse; @@ -1156,6 +1158,85 @@ public function setNodeTemplate($nodeGroup, $nodeGroupsSetNodeTemplateRequestRes return $this->startOperationsCall('SetNodeTemplate', $optionalArgs, $request, $this->getOperationsClient(), null, Operation::class)->wait(); } + /** + * Simulates maintenance event on specified nodes from the node group. + * + * Sample code: + * ``` + * $nodeGroupsClient = new NodeGroupsClient(); + * try { + * $nodeGroup = 'node_group'; + * $nodeGroupsSimulateMaintenanceEventRequestResource = new NodeGroupsSimulateMaintenanceEventRequest(); + * $project = 'project'; + * $zone = 'zone'; + * $operationResponse = $nodeGroupsClient->simulateMaintenanceEvent($nodeGroup, $nodeGroupsSimulateMaintenanceEventRequestResource, $project, $zone); + * $operationResponse->pollUntilComplete(); + * if ($operationResponse->operationSucceeded()) { + * // if creating/modifying, retrieve the target resource + * } else { + * $error = $operationResponse->getError(); + * // handleError($error) + * } + * // Alternatively: + * // start the operation, keep the operation name, and resume later + * $operationResponse = $nodeGroupsClient->simulateMaintenanceEvent($nodeGroup, $nodeGroupsSimulateMaintenanceEventRequestResource, $project, $zone); + * $operationName = $operationResponse->getName(); + * // ... do other work + * $newOperationResponse = $nodeGroupsClient->resumeOperation($operationName, 'simulateMaintenanceEvent'); + * while (!$newOperationResponse->isDone()) { + * // ... do other work + * $newOperationResponse->reload(); + * } + * if ($newOperationResponse->operationSucceeded()) { + * // if creating/modifying, retrieve the target resource + * } else { + * $error = $newOperationResponse->getError(); + * // handleError($error) + * } + * } finally { + * $nodeGroupsClient->close(); + * } + * ``` + * + * @param string $nodeGroup Name of the NodeGroup resource whose nodes will go under maintenance simulation. + * @param NodeGroupsSimulateMaintenanceEventRequest $nodeGroupsSimulateMaintenanceEventRequestResource The body resource for this request + * @param string $project Project ID for this request. + * @param string $zone The name of the zone for this request. + * @param array $optionalArgs { + * Optional. + * + * @type string $requestId + * An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return \Google\ApiCore\OperationResponse + * + * @throws ApiException if the remote call fails + */ + public function simulateMaintenanceEvent($nodeGroup, $nodeGroupsSimulateMaintenanceEventRequestResource, $project, $zone, array $optionalArgs = []) + { + $request = new SimulateMaintenanceEventNodeGroupRequest(); + $requestParamHeaders = []; + $request->setNodeGroup($nodeGroup); + $request->setNodeGroupsSimulateMaintenanceEventRequestResource($nodeGroupsSimulateMaintenanceEventRequestResource); + $request->setProject($project); + $request->setZone($zone); + $requestParamHeaders['node_group'] = $nodeGroup; + $requestParamHeaders['project'] = $project; + $requestParamHeaders['zone'] = $zone; + if (isset($optionalArgs['requestId'])) { + $request->setRequestId($optionalArgs['requestId']); + } + + $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); + $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); + return $this->startOperationsCall('SimulateMaintenanceEvent', $optionalArgs, $request, $this->getOperationsClient(), null, Operation::class)->wait(); + } + /** * Returns permissions that a caller has on the specified resource. * diff --git a/Compute/src/V1/GuestOsFeature/Type.php b/Compute/src/V1/GuestOsFeature/Type.php index e6c1f27b026..41fb53fdd5f 100644 --- a/Compute/src/V1/GuestOsFeature/Type.php +++ b/Compute/src/V1/GuestOsFeature/Type.php @@ -39,6 +39,10 @@ class Type * Generated from protobuf enum SEV_CAPABLE = 87083793; */ const SEV_CAPABLE = 87083793; + /** + * Generated from protobuf enum SEV_LIVE_MIGRATABLE = 392039820; + */ + const SEV_LIVE_MIGRATABLE = 392039820; /** * Generated from protobuf enum SEV_SNP_CAPABLE = 426919; */ @@ -63,6 +67,7 @@ class Type self::MULTI_IP_SUBNET => 'MULTI_IP_SUBNET', self::SECURE_BOOT => 'SECURE_BOOT', self::SEV_CAPABLE => 'SEV_CAPABLE', + self::SEV_LIVE_MIGRATABLE => 'SEV_LIVE_MIGRATABLE', self::SEV_SNP_CAPABLE => 'SEV_SNP_CAPABLE', self::UEFI_COMPATIBLE => 'UEFI_COMPATIBLE', self::VIRTIO_SCSI_MULTIQUEUE => 'VIRTIO_SCSI_MULTIQUEUE', diff --git a/Compute/src/V1/HealthStatusForNetworkEndpoint/HealthState.php b/Compute/src/V1/HealthStatusForNetworkEndpoint/HealthState.php index f67de416c72..c2c48cfd29d 100644 --- a/Compute/src/V1/HealthStatusForNetworkEndpoint/HealthState.php +++ b/Compute/src/V1/HealthStatusForNetworkEndpoint/HealthState.php @@ -20,18 +20,26 @@ class HealthState */ const UNDEFINED_HEALTH_STATE = 0; /** + * Endpoint is being drained. + * * Generated from protobuf enum DRAINING = 480455402; */ const DRAINING = 480455402; /** + * Endpoint is healthy. + * * Generated from protobuf enum HEALTHY = 439801213; */ const HEALTHY = 439801213; /** + * Endpoint is unhealthy. + * * Generated from protobuf enum UNHEALTHY = 462118084; */ const UNHEALTHY = 462118084; /** + * Health status of the endpoint is unknown. + * * Generated from protobuf enum UNKNOWN = 433141802; */ const UNKNOWN = 433141802; diff --git a/Compute/src/V1/NodeGroupsSimulateMaintenanceEventRequest.php b/Compute/src/V1/NodeGroupsSimulateMaintenanceEventRequest.php new file mode 100644 index 00000000000..212a93eb22b --- /dev/null +++ b/Compute/src/V1/NodeGroupsSimulateMaintenanceEventRequest.php @@ -0,0 +1,66 @@ +google.cloud.compute.v1.NodeGroupsSimulateMaintenanceEventRequest + */ +class NodeGroupsSimulateMaintenanceEventRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Names of the nodes to go under maintenance simulation. + * + * Generated from protobuf field repeated string nodes = 104993457; + */ + private $nodes; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array|\Google\Protobuf\Internal\RepeatedField $nodes + * Names of the nodes to go under maintenance simulation. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Compute\V1\Compute::initOnce(); + parent::__construct($data); + } + + /** + * Names of the nodes to go under maintenance simulation. + * + * Generated from protobuf field repeated string nodes = 104993457; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getNodes() + { + return $this->nodes; + } + + /** + * Names of the nodes to go under maintenance simulation. + * + * Generated from protobuf field repeated string nodes = 104993457; + * @param array|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setNodes($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->nodes = $arr; + + return $this; + } + +} + diff --git a/Compute/src/V1/SimulateMaintenanceEventNodeGroupRequest.php b/Compute/src/V1/SimulateMaintenanceEventNodeGroupRequest.php new file mode 100644 index 00000000000..e1893985cda --- /dev/null +++ b/Compute/src/V1/SimulateMaintenanceEventNodeGroupRequest.php @@ -0,0 +1,223 @@ +google.cloud.compute.v1.SimulateMaintenanceEventNodeGroupRequest + */ +class SimulateMaintenanceEventNodeGroupRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Name of the NodeGroup resource whose nodes will go under maintenance simulation. + * + * Generated from protobuf field string node_group = 469958146 [(.google.api.field_behavior) = REQUIRED]; + */ + private $node_group = ''; + /** + * The body resource for this request + * + * Generated from protobuf field .google.cloud.compute.v1.NodeGroupsSimulateMaintenanceEventRequest node_groups_simulate_maintenance_event_request_resource = 351468764 [(.google.api.field_behavior) = REQUIRED]; + */ + private $node_groups_simulate_maintenance_event_request_resource = null; + /** + * Project ID for this request. + * + * Generated from protobuf field string project = 227560217 [(.google.api.field_behavior) = REQUIRED, (.google.cloud.operation_request_field) = "project"]; + */ + private $project = ''; + /** + * An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). + * + * Generated from protobuf field optional string request_id = 37109963; + */ + private $request_id = null; + /** + * The name of the zone for this request. + * + * Generated from protobuf field string zone = 3744684 [(.google.api.field_behavior) = REQUIRED, (.google.cloud.operation_request_field) = "zone"]; + */ + private $zone = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $node_group + * Name of the NodeGroup resource whose nodes will go under maintenance simulation. + * @type \Google\Cloud\Compute\V1\NodeGroupsSimulateMaintenanceEventRequest $node_groups_simulate_maintenance_event_request_resource + * The body resource for this request + * @type string $project + * Project ID for this request. + * @type string $request_id + * An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). + * @type string $zone + * The name of the zone for this request. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Compute\V1\Compute::initOnce(); + parent::__construct($data); + } + + /** + * Name of the NodeGroup resource whose nodes will go under maintenance simulation. + * + * Generated from protobuf field string node_group = 469958146 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getNodeGroup() + { + return $this->node_group; + } + + /** + * Name of the NodeGroup resource whose nodes will go under maintenance simulation. + * + * Generated from protobuf field string node_group = 469958146 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setNodeGroup($var) + { + GPBUtil::checkString($var, True); + $this->node_group = $var; + + return $this; + } + + /** + * The body resource for this request + * + * Generated from protobuf field .google.cloud.compute.v1.NodeGroupsSimulateMaintenanceEventRequest node_groups_simulate_maintenance_event_request_resource = 351468764 [(.google.api.field_behavior) = REQUIRED]; + * @return \Google\Cloud\Compute\V1\NodeGroupsSimulateMaintenanceEventRequest|null + */ + public function getNodeGroupsSimulateMaintenanceEventRequestResource() + { + return $this->node_groups_simulate_maintenance_event_request_resource; + } + + public function hasNodeGroupsSimulateMaintenanceEventRequestResource() + { + return isset($this->node_groups_simulate_maintenance_event_request_resource); + } + + public function clearNodeGroupsSimulateMaintenanceEventRequestResource() + { + unset($this->node_groups_simulate_maintenance_event_request_resource); + } + + /** + * The body resource for this request + * + * Generated from protobuf field .google.cloud.compute.v1.NodeGroupsSimulateMaintenanceEventRequest node_groups_simulate_maintenance_event_request_resource = 351468764 [(.google.api.field_behavior) = REQUIRED]; + * @param \Google\Cloud\Compute\V1\NodeGroupsSimulateMaintenanceEventRequest $var + * @return $this + */ + public function setNodeGroupsSimulateMaintenanceEventRequestResource($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Compute\V1\NodeGroupsSimulateMaintenanceEventRequest::class); + $this->node_groups_simulate_maintenance_event_request_resource = $var; + + return $this; + } + + /** + * Project ID for this request. + * + * Generated from protobuf field string project = 227560217 [(.google.api.field_behavior) = REQUIRED, (.google.cloud.operation_request_field) = "project"]; + * @return string + */ + public function getProject() + { + return $this->project; + } + + /** + * Project ID for this request. + * + * Generated from protobuf field string project = 227560217 [(.google.api.field_behavior) = REQUIRED, (.google.cloud.operation_request_field) = "project"]; + * @param string $var + * @return $this + */ + public function setProject($var) + { + GPBUtil::checkString($var, True); + $this->project = $var; + + return $this; + } + + /** + * An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). + * + * Generated from protobuf field optional string request_id = 37109963; + * @return string + */ + public function getRequestId() + { + return isset($this->request_id) ? $this->request_id : ''; + } + + public function hasRequestId() + { + return isset($this->request_id); + } + + public function clearRequestId() + { + unset($this->request_id); + } + + /** + * An optional request ID to identify requests. Specify a unique request ID so that if you must retry your request, the server will know to ignore the request if it has already been completed. For example, consider a situation where you make an initial request and the request times out. If you make the request again with the same request ID, the server can check if original operation with the same request ID was received, and if so, will ignore the second request. This prevents clients from accidentally creating duplicate commitments. The request ID must be a valid UUID with the exception that zero UUID is not supported ( 00000000-0000-0000-0000-000000000000). + * + * Generated from protobuf field optional string request_id = 37109963; + * @param string $var + * @return $this + */ + public function setRequestId($var) + { + GPBUtil::checkString($var, True); + $this->request_id = $var; + + return $this; + } + + /** + * The name of the zone for this request. + * + * Generated from protobuf field string zone = 3744684 [(.google.api.field_behavior) = REQUIRED, (.google.cloud.operation_request_field) = "zone"]; + * @return string + */ + public function getZone() + { + return $this->zone; + } + + /** + * The name of the zone for this request. + * + * Generated from protobuf field string zone = 3744684 [(.google.api.field_behavior) = REQUIRED, (.google.cloud.operation_request_field) = "zone"]; + * @param string $var + * @return $this + */ + public function setZone($var) + { + GPBUtil::checkString($var, True); + $this->zone = $var; + + return $this; + } + +} + diff --git a/Compute/src/V1/gapic_metadata.json b/Compute/src/V1/gapic_metadata.json index e1c5a37520e..f71c1cfece6 100644 --- a/Compute/src/V1/gapic_metadata.json +++ b/Compute/src/V1/gapic_metadata.json @@ -1954,6 +1954,11 @@ "setNodeTemplate" ] }, + "SimulateMaintenanceEvent": { + "methods": [ + "simulateMaintenanceEvent" + ] + }, "TestIamPermissions": { "methods": [ "testIamPermissions" diff --git a/Compute/src/V1/resources/node_groups_client_config.json b/Compute/src/V1/resources/node_groups_client_config.json index 2ac0100b146..b8e6d16032f 100644 --- a/Compute/src/V1/resources/node_groups_client_config.json +++ b/Compute/src/V1/resources/node_groups_client_config.json @@ -99,6 +99,11 @@ "retry_codes_name": "no_retry_1_codes", "retry_params_name": "no_retry_1_params" }, + "SimulateMaintenanceEvent": { + "timeout_millis": 600000, + "retry_codes_name": "no_retry_1_codes", + "retry_params_name": "no_retry_1_params" + }, "TestIamPermissions": { "timeout_millis": 600000, "retry_codes_name": "no_retry_1_codes", diff --git a/Compute/src/V1/resources/node_groups_descriptor_config.php b/Compute/src/V1/resources/node_groups_descriptor_config.php index eedadb4d1d7..16a78a7f818 100644 --- a/Compute/src/V1/resources/node_groups_descriptor_config.php +++ b/Compute/src/V1/resources/node_groups_descriptor_config.php @@ -99,6 +99,22 @@ 'operationStatusDoneValue' => \Google\Cloud\Compute\V1\Operation\Status::DONE, ], ], + 'SimulateMaintenanceEvent' => [ + 'longRunning' => [ + 'additionalArgumentMethods' => [ + 'getProject', + 'getZone', + ], + 'getOperationMethod' => 'get', + 'cancelOperationMethod' => null, + 'deleteOperationMethod' => 'delete', + 'operationErrorCodeMethod' => 'getHttpErrorStatusCode', + 'operationErrorMessageMethod' => 'getHttpErrorMessage', + 'operationNameMethod' => 'getName', + 'operationStatusMethod' => 'getStatus', + 'operationStatusDoneValue' => \Google\Cloud\Compute\V1\Operation\Status::DONE, + ], + ], 'AggregatedList' => [ 'pageStreaming' => [ 'requestPageTokenGetMethod' => 'getPageToken', diff --git a/Compute/src/V1/resources/node_groups_rest_client_config.php b/Compute/src/V1/resources/node_groups_rest_client_config.php index 65b01d5b89a..ff8b3a61877 100644 --- a/Compute/src/V1/resources/node_groups_rest_client_config.php +++ b/Compute/src/V1/resources/node_groups_rest_client_config.php @@ -244,6 +244,28 @@ ], ], ], + 'SimulateMaintenanceEvent' => [ + 'method' => 'post', + 'uriTemplate' => '/compute/v1/projects/{project}/zones/{zone}/nodeGroups/{node_group}/simulateMaintenanceEvent', + 'body' => 'node_groups_simulate_maintenance_event_request_resource', + 'placeholders' => [ + 'node_group' => [ + 'getters' => [ + 'getNodeGroup', + ], + ], + 'project' => [ + 'getters' => [ + 'getProject', + ], + ], + 'zone' => [ + 'getters' => [ + 'getZone', + ], + ], + ], + ], 'TestIamPermissions' => [ 'method' => 'post', 'uriTemplate' => '/compute/v1/projects/{project}/zones/{zone}/nodeGroups/{resource}/testIamPermissions', diff --git a/Compute/tests/Unit/V1/NodeGroupsClientTest.php b/Compute/tests/Unit/V1/NodeGroupsClientTest.php index 8c9547f7e82..cd63178ab02 100644 --- a/Compute/tests/Unit/V1/NodeGroupsClientTest.php +++ b/Compute/tests/Unit/V1/NodeGroupsClientTest.php @@ -37,6 +37,7 @@ use Google\Cloud\Compute\V1\NodeGroupsListNodes; use Google\Cloud\Compute\V1\NodeGroupsScopedList; use Google\Cloud\Compute\V1\NodeGroupsSetNodeTemplateRequest; +use Google\Cloud\Compute\V1\NodeGroupsSimulateMaintenanceEventRequest; use Google\Cloud\Compute\V1\Operation; use Google\Cloud\Compute\V1\Operation\Status; use Google\Cloud\Compute\V1\Policy; @@ -1284,6 +1285,129 @@ public function setNodeTemplateExceptionTest() $this->assertTrue($operationsTransport->isExhausted()); } + /** @test */ + public function simulateMaintenanceEventTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new ZoneOperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('customOperations/simulateMaintenanceEventTest'); + $incompleteOperation->setStatus(Status::RUNNING); + $transport->addResponse($incompleteOperation); + $completeOperation = new Operation(); + $completeOperation->setName('customOperations/simulateMaintenanceEventTest'); + $completeOperation->setStatus(Status::DONE); + $operationsTransport->addResponse($completeOperation); + // Mock request + $nodeGroup = 'nodeGroup1543699970'; + $nodeGroupsSimulateMaintenanceEventRequestResource = new NodeGroupsSimulateMaintenanceEventRequest(); + $project = 'project-309310695'; + $zone = 'zone3744684'; + $response = $gapicClient->simulateMaintenanceEvent($nodeGroup, $nodeGroupsSimulateMaintenanceEventRequestResource, $project, $zone); + $this->assertFalse($response->isDone()); + $apiRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($apiRequests)); + $operationsRequestsEmpty = $operationsTransport->popReceivedCalls(); + $this->assertSame(0, count($operationsRequestsEmpty)); + $actualApiFuncCall = $apiRequests[0]->getFuncCall(); + $actualApiRequestObject = $apiRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.compute.v1.NodeGroups/SimulateMaintenanceEvent', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getNodeGroup(); + $this->assertProtobufEquals($nodeGroup, $actualValue); + $actualValue = $actualApiRequestObject->getNodeGroupsSimulateMaintenanceEventRequestResource(); + $this->assertProtobufEquals($nodeGroupsSimulateMaintenanceEventRequestResource, $actualValue); + $actualValue = $actualApiRequestObject->getProject(); + $this->assertProtobufEquals($project, $actualValue); + $actualValue = $actualApiRequestObject->getZone(); + $this->assertProtobufEquals($zone, $actualValue); + $expectedOperationsRequestObject = new GetZoneOperationRequest(); + $expectedOperationsRequestObject->setOperation($completeOperation->getName()); + $expectedOperationsRequestObject->setProject($project); + $expectedOperationsRequestObject->setZone($zone); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $apiRequestsEmpty = $transport->popReceivedCalls(); + $this->assertSame(0, count($apiRequestsEmpty)); + $operationsRequests = $operationsTransport->popReceivedCalls(); + $this->assertSame(1, count($operationsRequests)); + $actualOperationsFuncCall = $operationsRequests[0]->getFuncCall(); + $actualOperationsRequestObject = $operationsRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.compute.v1.ZoneOperations/Get', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function simulateMaintenanceEventExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new ZoneOperationsClient([ + 'apiEndpoint' => '', + 'transport' => $operationsTransport, + 'credentials' => $this->createCredentials(), + ]); + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + 'operationsClient' => $operationsClient, + ]); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + // Mock response + $incompleteOperation = new Operation(); + $incompleteOperation->setName('customOperations/simulateMaintenanceEventExceptionTest'); + $incompleteOperation->setStatus(Status::RUNNING); + $transport->addResponse($incompleteOperation); + $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); + $operationsTransport->addResponse(null, $status); + // Mock request + $nodeGroup = 'nodeGroup1543699970'; + $nodeGroupsSimulateMaintenanceEventRequestResource = new NodeGroupsSimulateMaintenanceEventRequest(); + $project = 'project-309310695'; + $zone = 'zone3744684'; + $response = $gapicClient->simulateMaintenanceEvent($nodeGroup, $nodeGroupsSimulateMaintenanceEventRequestResource, $project, $zone); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + try { + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + // If the pollUntilComplete() 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 stubs are exhausted + $transport->popReceivedCalls(); + $operationsTransport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + /** @test */ public function testIamPermissionsTest() {