From 43665060afda4053db639d427f202bfbc3b29a86 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 6 Mar 2023 15:53:58 -0800 Subject: [PATCH] feat!: [Batch] added StatusEvent.task_state (#5915) feat: added StatusEvent.task_state docs: updated comments PiperOrigin-RevId: 513426000 Source-Link: https://github.com/googleapis/googleapis/commit/3f95ea2d86b8e826350897efac1674d6784b4030 Source-Link: https://github.com/googleapis/googleapis-gen/commit/b191b40b95e42eeea8d0bccf91dd1d1ba8a61fb1 Copy-Tag: eyJwIjoiQmF0Y2gvLk93bEJvdC55YW1sIiwiaCI6ImIxOTFiNDBiOTVlNDJlZWVhOGQwYmNjZjkxZGQxZDFiYThhNjFmYjEifQ== --- Batch/metadata/V1/Batch.php | 5 +- Batch/metadata/V1/Task.php | Bin 3626 -> 3688 bytes Batch/src/V1/CreateJobRequest.php | 16 +- Batch/src/V1/DeleteJobRequest.php | 16 +- .../src/V1/Gapic/BatchServiceGapicClient.php | 211 +----------------- Batch/src/V1/Job.php | 12 +- Batch/src/V1/LifecyclePolicy.php | 16 ++ Batch/src/V1/Runnable/Script.php | 36 +++ Batch/src/V1/StatusEvent.php | 34 +++ Batch/src/V1/TaskSpec.php | 52 ++--- Batch/src/V1/gapic_metadata.json | 15 -- .../batch_service_client_config.json | 15 -- .../batch_service_rest_client_config.php | 37 --- .../tests/Unit/V1/BatchServiceClientTest.php | 192 ---------------- 14 files changed, 141 insertions(+), 516 deletions(-) diff --git a/Batch/metadata/V1/Batch.php b/Batch/metadata/V1/Batch.php index 4abdc154039c..08b6865323ca 100644 --- a/Batch/metadata/V1/Batch.php +++ b/Batch/metadata/V1/Batch.php @@ -21,11 +21,12 @@ public static function initOnce() { \GPBMetadata\Google\Cloud\Batch\V1\Job::initOnce(); \GPBMetadata\Google\Cloud\Batch\V1\Task::initOnce(); \GPBMetadata\Google\Longrunning\Operations::initOnce(); + \GPBMetadata\Google\Protobuf\GPBEmpty::initOnce(); \GPBMetadata\Google\Protobuf\Timestamp::initOnce(); $pool->internalAddGeneratedFile( ' -µ -!google/cloud/batch/v1/batch.protogoogle.cloud.batch.v1google/api/client.protogoogle/api/field_behavior.protogoogle/api/resource.protogoogle/cloud/batch/v1/job.proto google/cloud/batch/v1/task.proto#google/longrunning/operations.protogoogle/protobuf/timestamp.proto"› +Ò +!google/cloud/batch/v1/batch.protogoogle.cloud.batch.v1google/api/client.protogoogle/api/field_behavior.protogoogle/api/resource.protogoogle/cloud/batch/v1/job.proto google/cloud/batch/v1/task.proto#google/longrunning/operations.protogoogle/protobuf/empty.protogoogle/protobuf/timestamp.proto"› CreateJobRequest0 parent ( B àAúAbatch.googleapis.com/Job job_id ( , diff --git a/Batch/metadata/V1/Task.php b/Batch/metadata/V1/Task.php index 611846841622d3e68a29fe25dd5fac1bd8cb6020..c9fc730172c399dcd31476809f2da51ccc9ed1e8 100644 GIT binary patch delta 59 zcmZ1_^Fn6BPA0}jlXo$FWV}6j4fA|)A!{zKlEmWd_~Mepl2i#+1x5`%qZswcjNFQB Ndch#E&E72cIRTRk6UhJo delta 24 gcmaDMvr1;ePA0~slXo$FWSlp74fFiXohgetIamPolicy($resource); - * } finally { - * $batchServiceClient->close(); - * } - * ``` - * - * @param string $resource REQUIRED: The resource for which the policy is being requested. - * See the operation documentation for the appropriate value for this field. - * @param array $optionalArgs { - * Optional. - * - * @type GetPolicyOptions $options - * OPTIONAL: A `GetPolicyOptions` object for specifying options to - * `GetIamPolicy`. - * @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\Cloud\Iam\V1\Policy - * - * @throws ApiException if the remote call fails - */ - public function getIamPolicy($resource, array $optionalArgs = []) - { - $request = new GetIamPolicyRequest(); - $requestParamHeaders = []; - $request->setResource($resource); - $requestParamHeaders['resource'] = $resource; - if (isset($optionalArgs['options'])) { - $request->setOptions($optionalArgs['options']); - } - - $requestParams = new RequestParamsHeaderDescriptor( - $requestParamHeaders - ); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - return $this->startCall( - 'GetIamPolicy', - Policy::class, - $optionalArgs, - $request, - Call::UNARY_CALL, - 'google.iam.v1.IAMPolicy' - )->wait(); - } - - /** - * Sets the access control policy on the specified resource. Replaces - any existing policy. - - Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED` - errors. - * - * Sample code: - * ``` - * $batchServiceClient = new BatchServiceClient(); - * try { - * $resource = 'resource'; - * $policy = new Policy(); - * $response = $batchServiceClient->setIamPolicy($resource, $policy); - * } finally { - * $batchServiceClient->close(); - * } - * ``` - * - * @param string $resource REQUIRED: The resource for which the policy is being specified. - * See the operation documentation for the appropriate value for this field. - * @param Policy $policy REQUIRED: The complete policy to be applied to the `resource`. The size of - * the policy is limited to a few 10s of KB. An empty policy is a - * valid policy but certain Cloud Platform services (such as Projects) - * might reject them. - * @param array $optionalArgs { - * Optional. - * - * @type FieldMask $updateMask - * OPTIONAL: A FieldMask specifying which fields of the policy to modify. Only - * the fields in the mask will be modified. If no mask is provided, the - * following default mask is used: - * - * `paths: "bindings, etag"` - * @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\Cloud\Iam\V1\Policy - * - * @throws ApiException if the remote call fails - */ - public function setIamPolicy($resource, $policy, array $optionalArgs = []) - { - $request = new SetIamPolicyRequest(); - $requestParamHeaders = []; - $request->setResource($resource); - $request->setPolicy($policy); - $requestParamHeaders['resource'] = $resource; - if (isset($optionalArgs['updateMask'])) { - $request->setUpdateMask($optionalArgs['updateMask']); - } - - $requestParams = new RequestParamsHeaderDescriptor( - $requestParamHeaders - ); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - return $this->startCall( - 'SetIamPolicy', - Policy::class, - $optionalArgs, - $request, - Call::UNARY_CALL, - 'google.iam.v1.IAMPolicy' - )->wait(); - } - - /** - * Returns permissions that a caller has on the specified resource. If the - resource does not exist, this will return an empty set of - permissions, not a `NOT_FOUND` error. - - Note: This operation is designed to be used for building - permission-aware UIs and command-line tools, not for authorization - checking. This operation may "fail open" without warning. - * - * Sample code: - * ``` - * $batchServiceClient = new BatchServiceClient(); - * try { - * $resource = 'resource'; - * $permissions = []; - * $response = $batchServiceClient->testIamPermissions($resource, $permissions); - * } finally { - * $batchServiceClient->close(); - * } - * ``` - * - * @param string $resource REQUIRED: The resource for which the policy detail is being requested. - * See the operation documentation for the appropriate value for this field. - * @param string[] $permissions The set of permissions to check for the `resource`. Permissions with - * wildcards (such as '*' or 'storage.*') are not allowed. For more - * information see - * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). - * @param array $optionalArgs { - * Optional. - * - * @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\Cloud\Iam\V1\TestIamPermissionsResponse - * - * @throws ApiException if the remote call fails - */ - public function testIamPermissions( - $resource, - $permissions, - array $optionalArgs = [] - ) { - $request = new TestIamPermissionsRequest(); - $requestParamHeaders = []; - $request->setResource($resource); - $request->setPermissions($permissions); - $requestParamHeaders['resource'] = $resource; - $requestParams = new RequestParamsHeaderDescriptor( - $requestParamHeaders - ); - $optionalArgs['headers'] = isset($optionalArgs['headers']) - ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) - : $requestParams->getHeader(); - return $this->startCall( - 'TestIamPermissions', - TestIamPermissionsResponse::class, - $optionalArgs, - $request, - Call::UNARY_CALL, - 'google.iam.v1.IAMPolicy' - )->wait(); - } } diff --git a/Batch/src/V1/Job.php b/Batch/src/V1/Job.php index 3993ef006ff5..6a902bd6f016 100644 --- a/Batch/src/V1/Job.php +++ b/Batch/src/V1/Job.php @@ -30,7 +30,8 @@ class Job extends \Google\Protobuf\Internal\Message private $uid = ''; /** * Priority of the Job. - * The valid value range is [0, 100). + * The valid value range is [0, 100). Default value is 0. + * Higher value indicates higher priority. * A job with higher priority value is more likely to run earlier if all other * requirements are satisfied. * @@ -108,7 +109,8 @@ class Job extends \Google\Protobuf\Internal\Message * Output only. A system generated unique ID (in UUID4 format) for the Job. * @type int|string $priority * Priority of the Job. - * The valid value range is [0, 100). + * The valid value range is [0, 100). Default value is 0. + * Higher value indicates higher priority. * A job with higher priority value is more likely to run earlier if all other * requirements are satisfied. * @type array<\Google\Cloud\Batch\V1\TaskGroup>|\Google\Protobuf\Internal\RepeatedField $task_groups @@ -199,7 +201,8 @@ public function setUid($var) /** * Priority of the Job. - * The valid value range is [0, 100). + * The valid value range is [0, 100). Default value is 0. + * Higher value indicates higher priority. * A job with higher priority value is more likely to run earlier if all other * requirements are satisfied. * @@ -213,7 +216,8 @@ public function getPriority() /** * Priority of the Job. - * The valid value range is [0, 100). + * The valid value range is [0, 100). Default value is 0. + * Higher value indicates higher priority. * A job with higher priority value is more likely to run earlier if all other * requirements are satisfied. * diff --git a/Batch/src/V1/LifecyclePolicy.php b/Batch/src/V1/LifecyclePolicy.php index aac39977c9b7..a3bea43f2e16 100644 --- a/Batch/src/V1/LifecyclePolicy.php +++ b/Batch/src/V1/LifecyclePolicy.php @@ -18,6 +18,10 @@ class LifecyclePolicy extends \Google\Protobuf\Internal\Message { /** * Action to execute when ActionCondition is true. + * When RETRY_TASK is specified, we will retry failed tasks + * if we notice any exit code match and fail tasks if no match is found. + * Likewise, when FAIL_TASK is specified, we will fail tasks + * if we notice any exit code match and retry tasks if no match is found. * * Generated from protobuf field .google.cloud.batch.v1.LifecyclePolicy.Action action = 1; */ @@ -37,6 +41,10 @@ class LifecyclePolicy extends \Google\Protobuf\Internal\Message * * @type int $action * Action to execute when ActionCondition is true. + * When RETRY_TASK is specified, we will retry failed tasks + * if we notice any exit code match and fail tasks if no match is found. + * Likewise, when FAIL_TASK is specified, we will fail tasks + * if we notice any exit code match and retry tasks if no match is found. * @type \Google\Cloud\Batch\V1\LifecyclePolicy\ActionCondition $action_condition * Conditions that decide why a task failure is dealt with a specific action. * } @@ -48,6 +56,10 @@ public function __construct($data = NULL) { /** * Action to execute when ActionCondition is true. + * When RETRY_TASK is specified, we will retry failed tasks + * if we notice any exit code match and fail tasks if no match is found. + * Likewise, when FAIL_TASK is specified, we will fail tasks + * if we notice any exit code match and retry tasks if no match is found. * * Generated from protobuf field .google.cloud.batch.v1.LifecyclePolicy.Action action = 1; * @return int @@ -59,6 +71,10 @@ public function getAction() /** * Action to execute when ActionCondition is true. + * When RETRY_TASK is specified, we will retry failed tasks + * if we notice any exit code match and fail tasks if no match is found. + * Likewise, when FAIL_TASK is specified, we will fail tasks + * if we notice any exit code match and retry tasks if no match is found. * * Generated from protobuf field .google.cloud.batch.v1.LifecyclePolicy.Action action = 1; * @param int $var diff --git a/Batch/src/V1/Runnable/Script.php b/Batch/src/V1/Runnable/Script.php index 5eeb24440ebd..e6e291925dfb 100644 --- a/Batch/src/V1/Runnable/Script.php +++ b/Batch/src/V1/Runnable/Script.php @@ -25,8 +25,20 @@ class Script extends \Google\Protobuf\Internal\Message * * @type string $path * Script file path on the host VM. + * To specify an interpreter, please add a `#!`(also known as + * [shebang line](https://en.wikipedia.org/wiki/Shebang_(Unix))) as the + * first line of the file.(For example, to execute the script using bash, + * `#!/bin/bash` should be the first line of the file. To execute the + * script using`Python3`, `#!/usr/bin/env python3` should be the first + * line of the file.) Otherwise, the file will by default be excuted by + * `/bin/sh`. * @type string $text * Shell script text. + * To specify an interpreter, please add a `#!\n` at the + * beginning of the text.(For example, to execute the script using bash, + * `#!/bin/bash\n` should be added. To execute the script using`Python3`, + * `#!/usr/bin/env python3\n` should be added.) Otherwise, the script will + * by default be excuted by `/bin/sh`. * } */ public function __construct($data = NULL) { @@ -36,6 +48,13 @@ public function __construct($data = NULL) { /** * Script file path on the host VM. + * To specify an interpreter, please add a `#!`(also known as + * [shebang line](https://en.wikipedia.org/wiki/Shebang_(Unix))) as the + * first line of the file.(For example, to execute the script using bash, + * `#!/bin/bash` should be the first line of the file. To execute the + * script using`Python3`, `#!/usr/bin/env python3` should be the first + * line of the file.) Otherwise, the file will by default be excuted by + * `/bin/sh`. * * Generated from protobuf field string path = 1; * @return string @@ -52,6 +71,13 @@ public function hasPath() /** * Script file path on the host VM. + * To specify an interpreter, please add a `#!`(also known as + * [shebang line](https://en.wikipedia.org/wiki/Shebang_(Unix))) as the + * first line of the file.(For example, to execute the script using bash, + * `#!/bin/bash` should be the first line of the file. To execute the + * script using`Python3`, `#!/usr/bin/env python3` should be the first + * line of the file.) Otherwise, the file will by default be excuted by + * `/bin/sh`. * * Generated from protobuf field string path = 1; * @param string $var @@ -67,6 +93,11 @@ public function setPath($var) /** * Shell script text. + * To specify an interpreter, please add a `#!\n` at the + * beginning of the text.(For example, to execute the script using bash, + * `#!/bin/bash\n` should be added. To execute the script using`Python3`, + * `#!/usr/bin/env python3\n` should be added.) Otherwise, the script will + * by default be excuted by `/bin/sh`. * * Generated from protobuf field string text = 2; * @return string @@ -83,6 +114,11 @@ public function hasText() /** * Shell script text. + * To specify an interpreter, please add a `#!\n` at the + * beginning of the text.(For example, to execute the script using bash, + * `#!/bin/bash\n` should be added. To execute the script using`Python3`, + * `#!/usr/bin/env python3\n` should be added.) Otherwise, the script will + * by default be excuted by `/bin/sh`. * * Generated from protobuf field string text = 2; * @param string $var diff --git a/Batch/src/V1/StatusEvent.php b/Batch/src/V1/StatusEvent.php index bcddeac0a40a..1802f667cff9 100644 --- a/Batch/src/V1/StatusEvent.php +++ b/Batch/src/V1/StatusEvent.php @@ -39,6 +39,12 @@ class StatusEvent extends \Google\Protobuf\Internal\Message * Generated from protobuf field .google.cloud.batch.v1.TaskExecution task_execution = 4; */ private $task_execution = null; + /** + * Task State + * + * Generated from protobuf field .google.cloud.batch.v1.TaskStatus.State task_state = 5; + */ + private $task_state = 0; /** * Constructor. @@ -54,6 +60,8 @@ class StatusEvent extends \Google\Protobuf\Internal\Message * The time this event occurred. * @type \Google\Cloud\Batch\V1\TaskExecution $task_execution * Task Execution + * @type int $task_state + * Task State * } */ public function __construct($data = NULL) { @@ -185,5 +193,31 @@ public function setTaskExecution($var) return $this; } + /** + * Task State + * + * Generated from protobuf field .google.cloud.batch.v1.TaskStatus.State task_state = 5; + * @return int + */ + public function getTaskState() + { + return $this->task_state; + } + + /** + * Task State + * + * Generated from protobuf field .google.cloud.batch.v1.TaskStatus.State task_state = 5; + * @param int $var + * @return $this + */ + public function setTaskState($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\Batch\V1\TaskStatus\State::class); + $this->task_state = $var; + + return $this; + } + } diff --git a/Batch/src/V1/TaskSpec.php b/Batch/src/V1/TaskSpec.php index 956491e4a1ee..ddcd57645654 100644 --- a/Batch/src/V1/TaskSpec.php +++ b/Batch/src/V1/TaskSpec.php @@ -52,13 +52,12 @@ class TaskSpec extends \Google\Protobuf\Internal\Message private $max_retry_count = 0; /** * Lifecycle management schema when any task in a task group is failed. - * The valid size of lifecycle policies are [0, 10]. - * For each lifecycle policy, when the condition is met, - * the action in that policy will execute. - * If there are multiple policies that the task execution result matches, - * we use the action from the first matched policy. If task execution result - * does not meet with any of the defined lifecycle policy, we consider it as - * the default policy. Default policy means if the exit code is 0, exit task. + * Currently we only support one lifecycle policy. + * When the lifecycle policy condition is met, + * the action in the policy will execute. + * If task execution result does not meet with the defined lifecycle + * policy, we consider it as the default policy. + * Default policy means if the exit code is 0, exit task. * If task ends with non-zero exit code, retry the task with max_retry_count. * * Generated from protobuf field repeated .google.cloud.batch.v1.LifecyclePolicy lifecycle_policies = 9; @@ -111,13 +110,12 @@ class TaskSpec extends \Google\Protobuf\Internal\Message * The valid value range is [0, 10]. * @type array<\Google\Cloud\Batch\V1\LifecyclePolicy>|\Google\Protobuf\Internal\RepeatedField $lifecycle_policies * Lifecycle management schema when any task in a task group is failed. - * The valid size of lifecycle policies are [0, 10]. - * For each lifecycle policy, when the condition is met, - * the action in that policy will execute. - * If there are multiple policies that the task execution result matches, - * we use the action from the first matched policy. If task execution result - * does not meet with any of the defined lifecycle policy, we consider it as - * the default policy. Default policy means if the exit code is 0, exit task. + * Currently we only support one lifecycle policy. + * When the lifecycle policy condition is met, + * the action in the policy will execute. + * If task execution result does not meet with the defined lifecycle + * policy, we consider it as the default policy. + * Default policy means if the exit code is 0, exit task. * If task ends with non-zero exit code, retry the task with max_retry_count. * @type array|\Google\Protobuf\Internal\MapField $environments * Deprecated: please use environment(non-plural) instead. @@ -280,13 +278,12 @@ public function setMaxRetryCount($var) /** * Lifecycle management schema when any task in a task group is failed. - * The valid size of lifecycle policies are [0, 10]. - * For each lifecycle policy, when the condition is met, - * the action in that policy will execute. - * If there are multiple policies that the task execution result matches, - * we use the action from the first matched policy. If task execution result - * does not meet with any of the defined lifecycle policy, we consider it as - * the default policy. Default policy means if the exit code is 0, exit task. + * Currently we only support one lifecycle policy. + * When the lifecycle policy condition is met, + * the action in the policy will execute. + * If task execution result does not meet with the defined lifecycle + * policy, we consider it as the default policy. + * Default policy means if the exit code is 0, exit task. * If task ends with non-zero exit code, retry the task with max_retry_count. * * Generated from protobuf field repeated .google.cloud.batch.v1.LifecyclePolicy lifecycle_policies = 9; @@ -299,13 +296,12 @@ public function getLifecyclePolicies() /** * Lifecycle management schema when any task in a task group is failed. - * The valid size of lifecycle policies are [0, 10]. - * For each lifecycle policy, when the condition is met, - * the action in that policy will execute. - * If there are multiple policies that the task execution result matches, - * we use the action from the first matched policy. If task execution result - * does not meet with any of the defined lifecycle policy, we consider it as - * the default policy. Default policy means if the exit code is 0, exit task. + * Currently we only support one lifecycle policy. + * When the lifecycle policy condition is met, + * the action in the policy will execute. + * If task execution result does not meet with the defined lifecycle + * policy, we consider it as the default policy. + * Default policy means if the exit code is 0, exit task. * If task ends with non-zero exit code, retry the task with max_retry_count. * * Generated from protobuf field repeated .google.cloud.batch.v1.LifecyclePolicy lifecycle_policies = 9; diff --git a/Batch/src/V1/gapic_metadata.json b/Batch/src/V1/gapic_metadata.json index 0e283913b18d..eae7f15d2f08 100644 --- a/Batch/src/V1/gapic_metadata.json +++ b/Batch/src/V1/gapic_metadata.json @@ -49,21 +49,6 @@ "methods": [ "listLocations" ] - }, - "GetIamPolicy": { - "methods": [ - "getIamPolicy" - ] - }, - "SetIamPolicy": { - "methods": [ - "setIamPolicy" - ] - }, - "TestIamPermissions": { - "methods": [ - "testIamPermissions" - ] } } } diff --git a/Batch/src/V1/resources/batch_service_client_config.json b/Batch/src/V1/resources/batch_service_client_config.json index 40f45e675167..4fae7bea9f19 100644 --- a/Batch/src/V1/resources/batch_service_client_config.json +++ b/Batch/src/V1/resources/batch_service_client_config.json @@ -77,21 +77,6 @@ "timeout_millis": 60000, "retry_codes_name": "no_retry_codes", "retry_params_name": "no_retry_params" - }, - "GetIamPolicy": { - "timeout_millis": 60000, - "retry_codes_name": "no_retry_codes", - "retry_params_name": "no_retry_params" - }, - "SetIamPolicy": { - "timeout_millis": 60000, - "retry_codes_name": "no_retry_codes", - "retry_params_name": "no_retry_params" - }, - "TestIamPermissions": { - "timeout_millis": 60000, - "retry_codes_name": "no_retry_codes", - "retry_params_name": "no_retry_params" } } } diff --git a/Batch/src/V1/resources/batch_service_rest_client_config.php b/Batch/src/V1/resources/batch_service_rest_client_config.php index 76f3cd746fd2..a72321464b81 100644 --- a/Batch/src/V1/resources/batch_service_rest_client_config.php +++ b/Batch/src/V1/resources/batch_service_rest_client_config.php @@ -95,43 +95,6 @@ ], ], ], - 'google.iam.v1.IAMPolicy' => [ - 'GetIamPolicy' => [ - 'method' => 'get', - 'uriTemplate' => '/v1/{resource=projects/*/locations/*/jobs/*}:getIamPolicy', - 'placeholders' => [ - 'resource' => [ - 'getters' => [ - 'getResource', - ], - ], - ], - ], - 'SetIamPolicy' => [ - 'method' => 'post', - 'uriTemplate' => '/v1/{resource=projects/*/locations/*/jobs/*}:setIamPolicy', - 'body' => '*', - 'placeholders' => [ - 'resource' => [ - 'getters' => [ - 'getResource', - ], - ], - ], - ], - 'TestIamPermissions' => [ - 'method' => 'post', - 'uriTemplate' => '/v1/{resource=projects/*/locations/*/jobs/*}:testIamPermissions', - 'body' => '*', - 'placeholders' => [ - 'resource' => [ - 'getters' => [ - 'getResource', - ], - ], - ], - ], - ], 'google.longrunning.Operations' => [ 'CancelOperation' => [ 'method' => 'post', diff --git a/Batch/tests/Unit/V1/BatchServiceClientTest.php b/Batch/tests/Unit/V1/BatchServiceClientTest.php index 9a4fc9a96124..6739d9ec0c48 100644 --- a/Batch/tests/Unit/V1/BatchServiceClientTest.php +++ b/Batch/tests/Unit/V1/BatchServiceClientTest.php @@ -32,8 +32,6 @@ use Google\Cloud\Batch\V1\ListJobsResponse; use Google\Cloud\Batch\V1\ListTasksResponse; use Google\Cloud\Batch\V1\Task; -use Google\Cloud\Iam\V1\Policy; -use Google\Cloud\Iam\V1\TestIamPermissionsResponse; use Google\Cloud\Location\ListLocationsResponse; use Google\Cloud\Location\Location; use Google\LongRunning\GetOperationRequest; @@ -627,194 +625,4 @@ public function listLocationsExceptionTest() $transport->popReceivedCalls(); $this->assertTrue($transport->isExhausted()); } - - /** @test */ - public function getIamPolicyTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $version = 351608024; - $etag = '21'; - $expectedResponse = new Policy(); - $expectedResponse->setVersion($version); - $expectedResponse->setEtag($etag); - $transport->addResponse($expectedResponse); - // Mock request - $resource = 'resource-341064690'; - $response = $gapicClient->getIamPolicy($resource); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.iam.v1.IAMPolicy/GetIamPolicy', $actualFuncCall); - $actualValue = $actualRequestObject->getResource(); - $this->assertProtobufEquals($resource, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getIamPolicyExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $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 - $resource = 'resource-341064690'; - try { - $gapicClient->getIamPolicy($resource); - // If the $gapicClient 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 */ - public function setIamPolicyTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $version = 351608024; - $etag = '21'; - $expectedResponse = new Policy(); - $expectedResponse->setVersion($version); - $expectedResponse->setEtag($etag); - $transport->addResponse($expectedResponse); - // Mock request - $resource = 'resource-341064690'; - $policy = new Policy(); - $response = $gapicClient->setIamPolicy($resource, $policy); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.iam.v1.IAMPolicy/SetIamPolicy', $actualFuncCall); - $actualValue = $actualRequestObject->getResource(); - $this->assertProtobufEquals($resource, $actualValue); - $actualValue = $actualRequestObject->getPolicy(); - $this->assertProtobufEquals($policy, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function setIamPolicyExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $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 - $resource = 'resource-341064690'; - $policy = new Policy(); - try { - $gapicClient->setIamPolicy($resource, $policy); - // If the $gapicClient 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 */ - public function testIamPermissionsTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new TestIamPermissionsResponse(); - $transport->addResponse($expectedResponse); - // Mock request - $resource = 'resource-341064690'; - $permissions = []; - $response = $gapicClient->testIamPermissions($resource, $permissions); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.iam.v1.IAMPolicy/TestIamPermissions', $actualFuncCall); - $actualValue = $actualRequestObject->getResource(); - $this->assertProtobufEquals($resource, $actualValue); - $actualValue = $actualRequestObject->getPermissions(); - $this->assertProtobufEquals($permissions, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function testIamPermissionsExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $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 - $resource = 'resource-341064690'; - $permissions = []; - try { - $gapicClient->testIamPermissions($resource, $permissions); - // If the $gapicClient 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()); - } }