diff --git a/Run/metadata/V2/ContainerStatus.php b/Run/metadata/V2/ContainerStatus.php new file mode 100644 index 000000000000..58e1ee7a03b4 --- /dev/null +++ b/Run/metadata/V2/ContainerStatus.php @@ -0,0 +1,30 @@ +internalAddGeneratedFile( + ' +Þ +*google/cloud/run/v2/container_status.protogoogle.cloud.run.v2"5 +ContainerStatus +name (  + image_digest ( B\\ +com.google.cloud.run.v2BContainerStatusProtoPZ)cloud.google.com/go/run/apiv2/runpb;runpbbproto3' + , true); + + static::$is_initialized = true; + } +} + diff --git a/Run/metadata/V2/Instance.php b/Run/metadata/V2/Instance.php new file mode 100644 index 000000000000..b9b645c95241 Binary files /dev/null and b/Run/metadata/V2/Instance.php differ diff --git a/Run/metadata/V2/K8SMin.php b/Run/metadata/V2/K8SMin.php index d6e29d39776b..b596449b57eb 100644 Binary files a/Run/metadata/V2/K8SMin.php and b/Run/metadata/V2/K8SMin.php differ diff --git a/Run/samples/V2/InstancesClient/create_instance.php b/Run/samples/V2/InstancesClient/create_instance.php new file mode 100644 index 000000000000..9188fc3bd08f --- /dev/null +++ b/Run/samples/V2/InstancesClient/create_instance.php @@ -0,0 +1,101 @@ +setImage($instanceContainersImage); + $instanceContainers = [$container,]; + $instance = (new Instance()) + ->setContainers($instanceContainers); + $request = (new CreateInstanceRequest()) + ->setParent($formattedParent) + ->setInstance($instance) + ->setInstanceId($instanceId); + + // Call the API and handle any network failures. + try { + /** @var OperationResponse $response */ + $response = $instancesClient->createInstance($request); + $response->pollUntilComplete(); + + if ($response->operationSucceeded()) { + /** @var Instance $result */ + $result = $response->getResult(); + printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString()); + } 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 +{ + $formattedParent = InstancesClient::locationName('[PROJECT]', '[LOCATION]'); + $instanceContainersImage = '[IMAGE]'; + $instanceId = '[INSTANCE_ID]'; + + create_instance_sample($formattedParent, $instanceContainersImage, $instanceId); +} +// [END run_v2_generated_Instances_CreateInstance_sync] diff --git a/Run/samples/V2/InstancesClient/delete_instance.php b/Run/samples/V2/InstancesClient/delete_instance.php new file mode 100644 index 000000000000..376ce1a65561 --- /dev/null +++ b/Run/samples/V2/InstancesClient/delete_instance.php @@ -0,0 +1,82 @@ +setName($formattedName); + + // Call the API and handle any network failures. + try { + /** @var OperationResponse $response */ + $response = $instancesClient->deleteInstance($request); + $response->pollUntilComplete(); + + if ($response->operationSucceeded()) { + /** @var Instance $result */ + $result = $response->getResult(); + printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString()); + } 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 +{ + $formattedName = InstancesClient::instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + + delete_instance_sample($formattedName); +} +// [END run_v2_generated_Instances_DeleteInstance_sync] diff --git a/Run/samples/V2/InstancesClient/get_instance.php b/Run/samples/V2/InstancesClient/get_instance.php new file mode 100644 index 000000000000..569d14efcebb --- /dev/null +++ b/Run/samples/V2/InstancesClient/get_instance.php @@ -0,0 +1,70 @@ +setName($formattedName); + + // Call the API and handle any network failures. + try { + /** @var Instance $response */ + $response = $instancesClient->getInstance($request); + printf('Response data: %s' . PHP_EOL, $response->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 +{ + $formattedName = InstancesClient::instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + + get_instance_sample($formattedName); +} +// [END run_v2_generated_Instances_GetInstance_sync] diff --git a/Run/samples/V2/InstancesClient/list_instances.php b/Run/samples/V2/InstancesClient/list_instances.php new file mode 100644 index 000000000000..3d2036221e27 --- /dev/null +++ b/Run/samples/V2/InstancesClient/list_instances.php @@ -0,0 +1,78 @@ +setParent($formattedParent); + + // Call the API and handle any network failures. + try { + /** @var PagedListResponse $response */ + $response = $instancesClient->listInstances($request); + + /** @var Instance $element */ + foreach ($response as $element) { + printf('Element data: %s' . PHP_EOL, $element->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 +{ + $formattedParent = InstancesClient::locationName('[PROJECT]', '[LOCATION]'); + + list_instances_sample($formattedParent); +} +// [END run_v2_generated_Instances_ListInstances_sync] diff --git a/Run/samples/V2/InstancesClient/start_instance.php b/Run/samples/V2/InstancesClient/start_instance.php new file mode 100644 index 000000000000..f154fc7940ac --- /dev/null +++ b/Run/samples/V2/InstancesClient/start_instance.php @@ -0,0 +1,86 @@ +setName($formattedName); + + // Call the API and handle any network failures. + try { + /** @var OperationResponse $response */ + $response = $instancesClient->startInstance($request); + $response->pollUntilComplete(); + + if ($response->operationSucceeded()) { + /** @var Instance $result */ + $result = $response->getResult(); + printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString()); + } 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 +{ + $formattedName = InstancesClient::instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + + start_instance_sample($formattedName); +} +// [END run_v2_generated_Instances_StartInstance_sync] diff --git a/Run/samples/V2/InstancesClient/stop_instance.php b/Run/samples/V2/InstancesClient/stop_instance.php new file mode 100644 index 000000000000..93081da7711c --- /dev/null +++ b/Run/samples/V2/InstancesClient/stop_instance.php @@ -0,0 +1,86 @@ +setName($formattedName); + + // Call the API and handle any network failures. + try { + /** @var OperationResponse $response */ + $response = $instancesClient->stopInstance($request); + $response->pollUntilComplete(); + + if ($response->operationSucceeded()) { + /** @var Instance $result */ + $result = $response->getResult(); + printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString()); + } 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 +{ + $formattedName = InstancesClient::instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + + stop_instance_sample($formattedName); +} +// [END run_v2_generated_Instances_StopInstance_sync] diff --git a/Run/src/V2/Client/InstancesClient.php b/Run/src/V2/Client/InstancesClient.php new file mode 100644 index 000000000000..2145e20791cd --- /dev/null +++ b/Run/src/V2/Client/InstancesClient.php @@ -0,0 +1,594 @@ + createInstanceAsync(CreateInstanceRequest $request, array $optionalArgs = []) + * @method PromiseInterface deleteInstanceAsync(DeleteInstanceRequest $request, array $optionalArgs = []) + * @method PromiseInterface getInstanceAsync(GetInstanceRequest $request, array $optionalArgs = []) + * @method PromiseInterface listInstancesAsync(ListInstancesRequest $request, array $optionalArgs = []) + * @method PromiseInterface startInstanceAsync(StartInstanceRequest $request, array $optionalArgs = []) + * @method PromiseInterface stopInstanceAsync(StopInstanceRequest $request, array $optionalArgs = []) + */ +final class InstancesClient +{ + use GapicClientTrait; + use ResourceHelperTrait; + + /** The name of the service. */ + private const SERVICE_NAME = 'google.cloud.run.v2.Instances'; + + /** + * The default address of the service. + * + * @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead. + */ + private const SERVICE_ADDRESS = 'run.googleapis.com'; + + /** The address template of the service. */ + private const SERVICE_ADDRESS_TEMPLATE = 'run.UNIVERSE_DOMAIN'; + + /** The default port of the service. */ + private const DEFAULT_SERVICE_PORT = 443; + + /** The name of the code generator, to be included in the agent header. */ + private const CODEGEN_NAME = 'gapic'; + + /** The default scopes required by the service. */ + public static $serviceScopes = ['https://www.googleapis.com/auth/cloud-platform']; + + private $operationsClient; + + private static function getClientDefaults() + { + return [ + 'serviceName' => self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../resources/instances_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../resources/instances_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../resources/instances_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../resources/instances_rest_client_config.php', + ], + ], + ]; + } + + /** + * Return an OperationsClient object with the same endpoint as $this. + * + * @return OperationsClient + */ + public function getOperationsClient() + { + return $this->operationsClient; + } + + /** + * Resume an existing long running operation that was previously started by a long + * running API method. If $methodName is not provided, or does not match a long + * running API method, then the operation can still be resumed, but the + * OperationResponse object will not deserialize the final response. + * + * @param string $operationName The name of the long running operation + * @param string $methodName The name of the method used to start the operation + * + * @return OperationResponse + */ + public function resumeOperation($operationName, $methodName = null) + { + $options = $this->descriptors[$methodName]['longRunning'] ?? []; + $operation = new OperationResponse($operationName, $this->getOperationsClient(), $options); + $operation->reload(); + return $operation; + } + + /** + * Create the default operation client for the service. + * + * @param array $options ClientOptions for the client. + * + * @return OperationsClient + */ + private function createOperationsClient(array $options) + { + // Unset client-specific configuration options + unset($options['serviceName'], $options['clientConfig'], $options['descriptorsConfigPath']); + + if (isset($options['operationsClient'])) { + return $options['operationsClient']; + } + + return new OperationsClient($options); + } + + /** + * Formats a string containing the fully-qualified path to represent a connector + * resource. + * + * @param string $project + * @param string $location + * @param string $connector + * + * @return string The formatted connector resource. + */ + public static function connectorName(string $project, string $location, string $connector): string + { + return self::getPathTemplate('connector')->render([ + 'project' => $project, + 'location' => $location, + 'connector' => $connector, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a crypto_key + * resource. + * + * @param string $project + * @param string $location + * @param string $keyRing + * @param string $cryptoKey + * + * @return string The formatted crypto_key resource. + */ + public static function cryptoKeyName(string $project, string $location, string $keyRing, string $cryptoKey): string + { + return self::getPathTemplate('cryptoKey')->render([ + 'project' => $project, + 'location' => $location, + 'key_ring' => $keyRing, + 'crypto_key' => $cryptoKey, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a instance + * resource. + * + * @param string $project + * @param string $location + * @param string $instance + * + * @return string The formatted instance resource. + */ + public static function instanceName(string $project, string $location, string $instance): string + { + return self::getPathTemplate('instance')->render([ + 'project' => $project, + 'location' => $location, + 'instance' => $instance, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a location + * resource. + * + * @param string $project + * @param string $location + * + * @return string The formatted location resource. + */ + public static function locationName(string $project, string $location): string + { + return self::getPathTemplate('location')->render([ + 'project' => $project, + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * location_policy resource. + * + * @param string $location + * + * @return string The formatted location_policy resource. + */ + public static function locationPolicyName(string $location): string + { + return self::getPathTemplate('locationPolicy')->render([ + 'location' => $location, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a policy + * resource. + * + * @param string $project + * + * @return string The formatted policy resource. + */ + public static function policyName(string $project): string + { + return self::getPathTemplate('policy')->render([ + 'project' => $project, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * project_policy resource. + * + * @param string $project + * + * @return string The formatted project_policy resource. + */ + public static function projectPolicyName(string $project): string + { + return self::getPathTemplate('projectPolicy')->render([ + 'project' => $project, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a secret + * resource. + * + * @param string $project + * @param string $secret + * + * @return string The formatted secret resource. + */ + public static function secretName(string $project, string $secret): string + { + return self::getPathTemplate('secret')->render([ + 'project' => $project, + 'secret' => $secret, + ]); + } + + /** + * Formats a string containing the fully-qualified path to represent a + * secret_version resource. + * + * @param string $project + * @param string $secret + * @param string $version + * + * @return string The formatted secret_version resource. + */ + public static function secretVersionName(string $project, string $secret, string $version): string + { + return self::getPathTemplate('secretVersion')->render([ + 'project' => $project, + 'secret' => $secret, + 'version' => $version, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - connector: projects/{project}/locations/{location}/connectors/{connector} + * - cryptoKey: projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key} + * - instance: projects/{project}/locations/{location}/instances/{instance} + * - location: projects/{project}/locations/{location} + * - locationPolicy: locations/{location}/policy + * - policy: projects/{project}/policy + * - projectPolicy: projects/{project}/policy + * - secret: projects/{project}/secrets/{secret} + * - secretVersion: projects/{project}/secrets/{secret}/versions/{version} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param ?string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, ?string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array|ClientOptions $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'run.googleapis.com:443'. + * @type FetchAuthTokenInterface|CredentialsWrapper $credentials + * This option should only be used with a pre-constructed + * {@see FetchAuthTokenInterface} or {@see CredentialsWrapper} object. Note that + * when one of these objects are provided, any settings in $credentialsConfig will + * be ignored. + * **Important**: If you are providing a path to a credentials file, or a decoded + * credentials file as a PHP array, this usage is now DEPRECATED. Providing an + * unvalidated credential configuration to Google APIs can compromise the security + * of your systems and data. It is recommended to create the credentials explicitly + * ``` + * use Google\Auth\Credentials\ServiceAccountCredentials; + * use Google\Cloud\Run\V2\InstancesClient; + * $creds = new ServiceAccountCredentials($scopes, $json); + * $options = new InstancesClient(['credentials' => $creds]); + * ``` + * {@see + * https://cloud.google.com/docs/authentication/external/externally-sourced-credentials} + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * @type false|LoggerInterface $logger + * A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the + * 'GOOGLE_SDK_PHP_LOGGING' environment flag + * @type string $universeDomain + * The service domain for the client. Defaults to 'googleapis.com'. + * } + * + * @throws ValidationException + */ + public function __construct(array|ClientOptions $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + $this->operationsClient = $this->createOperationsClient($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Creates an Instance. + * + * The async variant is {@see InstancesClient::createInstanceAsync()} . + * + * @example samples/V2/InstancesClient/create_instance.php + * + * @param CreateInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function createInstance(CreateInstanceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('CreateInstance', $request, $callOptions)->wait(); + } + + /** + * Deletes a Instance + * + * The async variant is {@see InstancesClient::deleteInstanceAsync()} . + * + * @example samples/V2/InstancesClient/delete_instance.php + * + * @param DeleteInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function deleteInstance(DeleteInstanceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('DeleteInstance', $request, $callOptions)->wait(); + } + + /** + * Gets a Instance + * + * The async variant is {@see InstancesClient::getInstanceAsync()} . + * + * @example samples/V2/InstancesClient/get_instance.php + * + * @param GetInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 Instance + * + * @throws ApiException Thrown if the API call fails. + */ + public function getInstance(GetInstanceRequest $request, array $callOptions = []): Instance + { + return $this->startApiCall('GetInstance', $request, $callOptions)->wait(); + } + + /** + * Lists Instances. Results are sorted by creation time, descending. + * + * The async variant is {@see InstancesClient::listInstancesAsync()} . + * + * @example samples/V2/InstancesClient/list_instances.php + * + * @param ListInstancesRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function listInstances(ListInstancesRequest $request, array $callOptions = []): PagedListResponse + { + return $this->startApiCall('ListInstances', $request, $callOptions); + } + + /** + * Starts an Instance. + * + * The async variant is {@see InstancesClient::startInstanceAsync()} . + * + * @example samples/V2/InstancesClient/start_instance.php + * + * @param StartInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function startInstance(StartInstanceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('StartInstance', $request, $callOptions)->wait(); + } + + /** + * Stops an Instance. + * + * The async variant is {@see InstancesClient::stopInstanceAsync()} . + * + * @example samples/V2/InstancesClient/stop_instance.php + * + * @param StopInstanceRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * 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 OperationResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function stopInstance(StopInstanceRequest $request, array $callOptions = []): OperationResponse + { + return $this->startApiCall('StopInstance', $request, $callOptions)->wait(); + } +} diff --git a/Run/src/V2/Container.php b/Run/src/V2/Container.php index 50f99c57de60..2ffcd41a34c8 100644 --- a/Run/src/V2/Container.php +++ b/Run/src/V2/Container.php @@ -105,6 +105,12 @@ class Container extends \Google\Protobuf\Internal\Message * Generated from protobuf field .google.cloud.run.v2.Probe startup_probe = 11; */ protected $startup_probe = null; + /** + * Readiness probe to be used for health checks. + * + * Generated from protobuf field .google.cloud.run.v2.Probe readiness_probe = 14; + */ + protected $readiness_probe = null; /** * Names of the containers that must start before this container. * @@ -169,6 +175,8 @@ class Container extends \Google\Protobuf\Internal\Message * All other probes are disabled if a startup probe is provided, until it * succeeds. Container will not be added to service endpoints if the probe * fails. + * @type \Google\Cloud\Run\V2\Probe $readiness_probe + * Readiness probe to be used for health checks. * @type array|\Google\Protobuf\Internal\RepeatedField $depends_on * Names of the containers that must start before this container. * @type string $base_image_uri @@ -563,6 +571,42 @@ public function setStartupProbe($var) return $this; } + /** + * Readiness probe to be used for health checks. + * + * Generated from protobuf field .google.cloud.run.v2.Probe readiness_probe = 14; + * @return \Google\Cloud\Run\V2\Probe|null + */ + public function getReadinessProbe() + { + return $this->readiness_probe; + } + + public function hasReadinessProbe() + { + return isset($this->readiness_probe); + } + + public function clearReadinessProbe() + { + unset($this->readiness_probe); + } + + /** + * Readiness probe to be used for health checks. + * + * Generated from protobuf field .google.cloud.run.v2.Probe readiness_probe = 14; + * @param \Google\Cloud\Run\V2\Probe $var + * @return $this + */ + public function setReadinessProbe($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Run\V2\Probe::class); + $this->readiness_probe = $var; + + return $this; + } + /** * Names of the containers that must start before this container. * diff --git a/Run/src/V2/ContainerStatus.php b/Run/src/V2/ContainerStatus.php new file mode 100644 index 000000000000..793b0b005d77 --- /dev/null +++ b/Run/src/V2/ContainerStatus.php @@ -0,0 +1,114 @@ +google.cloud.run.v2.ContainerStatus + */ +class ContainerStatus extends \Google\Protobuf\Internal\Message +{ + /** + * The name of the container, if specified. + * + * Generated from protobuf field string name = 1; + */ + protected $name = ''; + /** + * ImageDigest holds the resolved digest for the image specified and resolved + * during the creation of Revision. This field holds the digest value + * regardless of whether a tag or digest was originally specified in the + * Container object. + * + * Generated from protobuf field string image_digest = 2; + */ + protected $image_digest = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The name of the container, if specified. + * @type string $image_digest + * ImageDigest holds the resolved digest for the image specified and resolved + * during the creation of Revision. This field holds the digest value + * regardless of whether a tag or digest was originally specified in the + * Container object. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Run\V2\ContainerStatus::initOnce(); + parent::__construct($data); + } + + /** + * The name of the container, if specified. + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The name of the container, if specified. + * + * 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; + } + + /** + * ImageDigest holds the resolved digest for the image specified and resolved + * during the creation of Revision. This field holds the digest value + * regardless of whether a tag or digest was originally specified in the + * Container object. + * + * Generated from protobuf field string image_digest = 2; + * @return string + */ + public function getImageDigest() + { + return $this->image_digest; + } + + /** + * ImageDigest holds the resolved digest for the image specified and resolved + * during the creation of Revision. This field holds the digest value + * regardless of whether a tag or digest was originally specified in the + * Container object. + * + * Generated from protobuf field string image_digest = 2; + * @param string $var + * @return $this + */ + public function setImageDigest($var) + { + GPBUtil::checkString($var, True); + $this->image_digest = $var; + + return $this; + } + +} + diff --git a/Run/src/V2/CreateInstanceRequest.php b/Run/src/V2/CreateInstanceRequest.php new file mode 100644 index 000000000000..efbfeb467beb --- /dev/null +++ b/Run/src/V2/CreateInstanceRequest.php @@ -0,0 +1,190 @@ +google.cloud.run.v2.CreateInstanceRequest + */ +class CreateInstanceRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + protected $parent = ''; + /** + * Generated from protobuf field .google.cloud.run.v2.Instance instance = 2 [(.google.api.field_behavior) = REQUIRED]; + */ + protected $instance = null; + /** + * Required. The unique identifier for the Instance. It must begin with + * letter, and cannot end with hyphen; must contain fewer than 50 characters. + * The name of the instance becomes {parent}/instances/{instance_id}. + * + * Generated from protobuf field string instance_id = 3 [(.google.api.field_behavior) = REQUIRED]; + */ + protected $instance_id = ''; + /** + * Optional. Indicates that the request should be validated and default values + * populated, without persisting the request or creating any resources. + * + * Generated from protobuf field bool validate_only = 4 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $validate_only = false; + + /** + * @param string $parent Please see {@see InstancesClient::locationName()} for help formatting this field. + * @param \Google\Cloud\Run\V2\Instance $instance + * + * @return \Google\Cloud\Run\V2\CreateInstanceRequest + * + * @experimental + */ + public static function build(string $parent, \Google\Cloud\Run\V2\Instance $instance): self + { + return (new self()) + ->setParent($parent) + ->setInstance($instance); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $parent + * @type \Google\Cloud\Run\V2\Instance $instance + * @type string $instance_id + * Required. The unique identifier for the Instance. It must begin with + * letter, and cannot end with hyphen; must contain fewer than 50 characters. + * The name of the instance becomes {parent}/instances/{instance_id}. + * @type bool $validate_only + * Optional. Indicates that the request should be validated and default values + * populated, without persisting the request or creating any resources. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Run\V2\Instance::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getParent() + { + return $this->parent; + } + + /** + * 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; + } + + /** + * Generated from protobuf field .google.cloud.run.v2.Instance instance = 2 [(.google.api.field_behavior) = REQUIRED]; + * @return \Google\Cloud\Run\V2\Instance|null + */ + public function getInstance() + { + return $this->instance; + } + + public function hasInstance() + { + return isset($this->instance); + } + + public function clearInstance() + { + unset($this->instance); + } + + /** + * Generated from protobuf field .google.cloud.run.v2.Instance instance = 2 [(.google.api.field_behavior) = REQUIRED]; + * @param \Google\Cloud\Run\V2\Instance $var + * @return $this + */ + public function setInstance($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Run\V2\Instance::class); + $this->instance = $var; + + return $this; + } + + /** + * Required. The unique identifier for the Instance. It must begin with + * letter, and cannot end with hyphen; must contain fewer than 50 characters. + * The name of the instance becomes {parent}/instances/{instance_id}. + * + * Generated from protobuf field string instance_id = 3 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getInstanceId() + { + return $this->instance_id; + } + + /** + * Required. The unique identifier for the Instance. It must begin with + * letter, and cannot end with hyphen; must contain fewer than 50 characters. + * The name of the instance becomes {parent}/instances/{instance_id}. + * + * Generated from protobuf field string instance_id = 3 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setInstanceId($var) + { + GPBUtil::checkString($var, True); + $this->instance_id = $var; + + return $this; + } + + /** + * Optional. Indicates that the request should be validated and default values + * populated, without persisting the request or creating any resources. + * + * Generated from protobuf field bool validate_only = 4 [(.google.api.field_behavior) = OPTIONAL]; + * @return bool + */ + public function getValidateOnly() + { + return $this->validate_only; + } + + /** + * Optional. Indicates that the request should be validated and default values + * populated, without persisting the request or creating any resources. + * + * Generated from protobuf field bool validate_only = 4 [(.google.api.field_behavior) = OPTIONAL]; + * @param bool $var + * @return $this + */ + public function setValidateOnly($var) + { + GPBUtil::checkBool($var); + $this->validate_only = $var; + + return $this; + } + +} + diff --git a/Run/src/V2/DeleteInstanceRequest.php b/Run/src/V2/DeleteInstanceRequest.php new file mode 100644 index 000000000000..6f6a803224bd --- /dev/null +++ b/Run/src/V2/DeleteInstanceRequest.php @@ -0,0 +1,147 @@ +google.cloud.run.v2.DeleteInstanceRequest + */ +class DeleteInstanceRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + protected $name = ''; + /** + * Optional. Indicates that the request should be validated without actually + * deleting any resources. + * + * Generated from protobuf field bool validate_only = 2 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $validate_only = false; + /** + * Optional. A system-generated fingerprint for this version of the + * resource. May be used to detect modification conflict during updates. + * + * Generated from protobuf field string etag = 3 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $etag = ''; + + /** + * @param string $name Please see {@see InstancesClient::instanceName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\DeleteInstanceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * @type bool $validate_only + * Optional. Indicates that the request should be validated without actually + * deleting any resources. + * @type string $etag + * Optional. A system-generated fingerprint for this version of the + * resource. May be used to detect modification conflict during updates. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Run\V2\Instance::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * 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; + } + + /** + * Optional. Indicates that the request should be validated without actually + * deleting any resources. + * + * Generated from protobuf field bool validate_only = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @return bool + */ + public function getValidateOnly() + { + return $this->validate_only; + } + + /** + * Optional. Indicates that the request should be validated without actually + * deleting any resources. + * + * Generated from protobuf field bool validate_only = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @param bool $var + * @return $this + */ + public function setValidateOnly($var) + { + GPBUtil::checkBool($var); + $this->validate_only = $var; + + return $this; + } + + /** + * Optional. A system-generated fingerprint for this version of the + * resource. May be used to detect modification conflict during updates. + * + * Generated from protobuf field string etag = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @return string + */ + public function getEtag() + { + return $this->etag; + } + + /** + * Optional. A system-generated fingerprint for this version of the + * resource. May be used to detect modification conflict during updates. + * + * Generated from protobuf field string etag = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @param string $var + * @return $this + */ + public function setEtag($var) + { + GPBUtil::checkString($var, True); + $this->etag = $var; + + return $this; + } + +} + diff --git a/Run/src/V2/GetInstanceRequest.php b/Run/src/V2/GetInstanceRequest.php new file mode 100644 index 000000000000..f32ee862bb05 --- /dev/null +++ b/Run/src/V2/GetInstanceRequest.php @@ -0,0 +1,71 @@ +google.cloud.run.v2.GetInstanceRequest + */ +class GetInstanceRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + protected $name = ''; + + /** + * @param string $name Please see {@see InstancesClient::instanceName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\GetInstanceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Run\V2\Instance::initOnce(); + parent::__construct($data); + } + + /** + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * 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; + } + +} + diff --git a/Run/src/V2/Instance.php b/Run/src/V2/Instance.php new file mode 100644 index 000000000000..c1ed7068c81f --- /dev/null +++ b/Run/src/V2/Instance.php @@ -0,0 +1,1579 @@ +google.cloud.run.v2.Instance + */ +class Instance extends \Google\Protobuf\Internal\Message +{ + /** + * The fully qualified name of this Instance. In CreateInstanceRequest, this + * field is ignored, and instead composed from CreateInstanceRequest.parent + * and CreateInstanceRequest.instance_id. + * Format: + * projects/{project}/locations/{location}/instances/{instance_id} + * + * Generated from protobuf field string name = 1; + */ + protected $name = ''; + /** + * User-provided description of the Instance. This field currently has a + * 512-character limit. + * + * Generated from protobuf field string description = 3; + */ + protected $description = ''; + /** + * Output only. Server assigned unique identifier for the trigger. The value + * is a UUID4 string and guaranteed to remain unchanged until the resource is + * deleted. + * + * Generated from protobuf field string uid = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $uid = ''; + /** + * Output only. A number that monotonically increases every time the user + * modifies the desired state. + * Please note that unlike v1, this is an int64 value. As with most Google + * APIs, its JSON representation will be a `string` instead of an `integer`. + * + * Generated from protobuf field int64 generation = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $generation = 0; + /** + * Generated from protobuf field map labels = 6; + */ + private $labels; + /** + * Generated from protobuf field map annotations = 7; + */ + private $annotations; + /** + * Output only. The creation time. + * + * Generated from protobuf field .google.protobuf.Timestamp create_time = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $create_time = null; + /** + * Output only. The last-modified time. + * + * Generated from protobuf field .google.protobuf.Timestamp update_time = 9 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $update_time = null; + /** + * Output only. The deletion time. + * + * Generated from protobuf field .google.protobuf.Timestamp delete_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $delete_time = null; + /** + * Output only. For a deleted resource, the time after which it will be + * permamently deleted. + * + * Generated from protobuf field .google.protobuf.Timestamp expire_time = 11 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $expire_time = null; + /** + * Output only. Email address of the authenticated creator. + * + * Generated from protobuf field string creator = 12 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $creator = ''; + /** + * Output only. Email address of the last authenticated modifier. + * + * Generated from protobuf field string last_modifier = 13 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $last_modifier = ''; + /** + * Arbitrary identifier for the API client. + * + * Generated from protobuf field string client = 14; + */ + protected $client = ''; + /** + * Arbitrary version identifier for the API client. + * + * Generated from protobuf field string client_version = 15; + */ + protected $client_version = ''; + /** + * The launch stage as defined by [Google Cloud Platform + * Launch Stages](https://cloud.google.com/terms/launch-stages). + * Cloud Run supports `ALPHA`, `BETA`, and `GA`. If no value is specified, GA + * is assumed. + * Set the launch stage to a preview stage on input to allow use of preview + * features in that stage. On read (or output), describes whether the + * resource uses preview features. + *

+ * For example, if ALPHA is provided as input, but only BETA and GA-level + * features are used, this field will be BETA on output. + * + * Generated from protobuf field .google.api.LaunchStage launch_stage = 16; + */ + protected $launch_stage = 0; + /** + * Settings for the Binary Authorization feature. + * + * Generated from protobuf field .google.cloud.run.v2.BinaryAuthorization binary_authorization = 17; + */ + protected $binary_authorization = null; + /** + * Optional. VPC Access configuration to use for this Revision. For more + * information, visit + * https://cloud.google.com/run/docs/configuring/connecting-vpc. + * + * Generated from protobuf field .google.cloud.run.v2.VpcAccess vpc_access = 18 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $vpc_access = null; + /** + * Generated from protobuf field string service_account = 19; + */ + protected $service_account = ''; + /** + * Required. Holds the single container that defines the unit of execution for + * this Instance. + * + * Generated from protobuf field repeated .google.cloud.run.v2.Container containers = 20 [(.google.api.field_behavior) = REQUIRED]; + */ + private $containers; + /** + * A list of Volumes to make available to containers. + * + * Generated from protobuf field repeated .google.cloud.run.v2.Volume volumes = 21; + */ + private $volumes; + /** + * A reference to a customer managed encryption key (CMEK) to use to encrypt + * this container image. For more information, go to + * https://cloud.google.com/run/docs/securing/using-cmek + * + * Generated from protobuf field string encryption_key = 22 [(.google.api.resource_reference) = { + */ + protected $encryption_key = ''; + /** + * The action to take if the encryption key is revoked. + * + * Generated from protobuf field .google.cloud.run.v2.EncryptionKeyRevocationAction encryption_key_revocation_action = 24; + */ + protected $encryption_key_revocation_action = 0; + /** + * If encryption_key_revocation_action is SHUTDOWN, the duration before + * shutting down all instances. The minimum increment is 1 hour. + * + * Generated from protobuf field .google.protobuf.Duration encryption_key_shutdown_duration = 25; + */ + protected $encryption_key_shutdown_duration = null; + /** + * Optional. The node selector for the instance. + * + * Generated from protobuf field .google.cloud.run.v2.NodeSelector node_selector = 26 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $node_selector = null; + /** + * Optional. True if GPU zonal redundancy is disabled on this instance. + * + * Generated from protobuf field optional bool gpu_zonal_redundancy_disabled = 27 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $gpu_zonal_redundancy_disabled = null; + /** + * Optional. Provides the ingress settings for this Instance. On output, + * returns the currently observed ingress settings, or + * INGRESS_TRAFFIC_UNSPECIFIED if no revision is active. + * + * Generated from protobuf field .google.cloud.run.v2.IngressTraffic ingress = 28 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $ingress = 0; + /** + * Optional. Disables IAM permission check for run.routes.invoke for callers + * of this Instance. For more information, visit + * https://cloud.google.com/run/docs/securing/managing-access#invoker_check. + * + * Generated from protobuf field bool invoker_iam_disabled = 29 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $invoker_iam_disabled = false; + /** + * Optional. IAP settings on the Instance. + * + * Generated from protobuf field bool iap_enabled = 30 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $iap_enabled = false; + /** + * Output only. The generation of this Instance currently serving traffic. See + * comments in `reconciling` for additional information on reconciliation + * process in Cloud Run. Please note that unlike v1, this is an int64 value. + * As with most Google APIs, its JSON representation will be a `string` + * instead of an `integer`. + * + * Generated from protobuf field int64 observed_generation = 40 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $observed_generation = 0; + /** + * Output only. The Google Console URI to obtain logs for the Instance. + * + * Generated from protobuf field string log_uri = 41 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $log_uri = ''; + /** + * Output only. The Condition of this Instance, containing its readiness + * status, and detailed error information in case it did not reach a serving + * state. See comments in `reconciling` for additional information on + * reconciliation process in Cloud Run. + * + * Generated from protobuf field .google.cloud.run.v2.Condition terminal_condition = 42 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $terminal_condition = null; + /** + * Output only. The Conditions of all other associated sub-resources. They + * contain additional diagnostics information in case the Instance does not + * reach its Serving state. See comments in `reconciling` for additional + * information on reconciliation process in Cloud Run. + * + * Generated from protobuf field repeated .google.cloud.run.v2.Condition conditions = 43 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $conditions; + /** + * Output only. Status information for each of the specified containers. The + * status includes the resolved digest for specified images. + * + * Generated from protobuf field repeated .google.cloud.run.v2.ContainerStatus container_statuses = 44 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $container_statuses; + /** + * Output only. Reserved for future use. + * + * Generated from protobuf field bool satisfies_pzs = 46 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $satisfies_pzs = false; + /** + * Output only. All URLs serving traffic for this Instance. + * + * Generated from protobuf field repeated string urls = 45 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + private $urls; + /** + * Output only. Returns true if the Instance is currently being acted upon by + * the system to bring it into the desired state. + * When a new Instance is created, or an existing one is updated, Cloud Run + * will asynchronously perform all necessary steps to bring the Instance to + * the desired serving state. This process is called reconciliation. While + * reconciliation is in process, `observed_generation` will have a transient + * value that might mismatch the intended state. + * Once reconciliation is over (and this field is false), there are two + * possible outcomes: reconciliation succeeded and the serving state matches + * the Instance, or there was an error, and reconciliation failed. This state + * can be found in `terminal_condition.state`. + * + * Generated from protobuf field bool reconciling = 98 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $reconciling = false; + /** + * Optional. A system-generated fingerprint for this version of the + * resource. May be used to detect modification conflict during updates. + * + * Generated from protobuf field string etag = 99 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $etag = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * The fully qualified name of this Instance. In CreateInstanceRequest, this + * field is ignored, and instead composed from CreateInstanceRequest.parent + * and CreateInstanceRequest.instance_id. + * Format: + * projects/{project}/locations/{location}/instances/{instance_id} + * @type string $description + * User-provided description of the Instance. This field currently has a + * 512-character limit. + * @type string $uid + * Output only. Server assigned unique identifier for the trigger. The value + * is a UUID4 string and guaranteed to remain unchanged until the resource is + * deleted. + * @type int|string $generation + * Output only. A number that monotonically increases every time the user + * modifies the desired state. + * Please note that unlike v1, this is an int64 value. As with most Google + * APIs, its JSON representation will be a `string` instead of an `integer`. + * @type array|\Google\Protobuf\Internal\MapField $labels + * @type array|\Google\Protobuf\Internal\MapField $annotations + * @type \Google\Protobuf\Timestamp $create_time + * Output only. The creation time. + * @type \Google\Protobuf\Timestamp $update_time + * Output only. The last-modified time. + * @type \Google\Protobuf\Timestamp $delete_time + * Output only. The deletion time. + * @type \Google\Protobuf\Timestamp $expire_time + * Output only. For a deleted resource, the time after which it will be + * permamently deleted. + * @type string $creator + * Output only. Email address of the authenticated creator. + * @type string $last_modifier + * Output only. Email address of the last authenticated modifier. + * @type string $client + * Arbitrary identifier for the API client. + * @type string $client_version + * Arbitrary version identifier for the API client. + * @type int $launch_stage + * The launch stage as defined by [Google Cloud Platform + * Launch Stages](https://cloud.google.com/terms/launch-stages). + * Cloud Run supports `ALPHA`, `BETA`, and `GA`. If no value is specified, GA + * is assumed. + * Set the launch stage to a preview stage on input to allow use of preview + * features in that stage. On read (or output), describes whether the + * resource uses preview features. + *

+ * For example, if ALPHA is provided as input, but only BETA and GA-level + * features are used, this field will be BETA on output. + * @type \Google\Cloud\Run\V2\BinaryAuthorization $binary_authorization + * Settings for the Binary Authorization feature. + * @type \Google\Cloud\Run\V2\VpcAccess $vpc_access + * Optional. VPC Access configuration to use for this Revision. For more + * information, visit + * https://cloud.google.com/run/docs/configuring/connecting-vpc. + * @type string $service_account + * @type array<\Google\Cloud\Run\V2\Container>|\Google\Protobuf\Internal\RepeatedField $containers + * Required. Holds the single container that defines the unit of execution for + * this Instance. + * @type array<\Google\Cloud\Run\V2\Volume>|\Google\Protobuf\Internal\RepeatedField $volumes + * A list of Volumes to make available to containers. + * @type string $encryption_key + * A reference to a customer managed encryption key (CMEK) to use to encrypt + * this container image. For more information, go to + * https://cloud.google.com/run/docs/securing/using-cmek + * @type int $encryption_key_revocation_action + * The action to take if the encryption key is revoked. + * @type \Google\Protobuf\Duration $encryption_key_shutdown_duration + * If encryption_key_revocation_action is SHUTDOWN, the duration before + * shutting down all instances. The minimum increment is 1 hour. + * @type \Google\Cloud\Run\V2\NodeSelector $node_selector + * Optional. The node selector for the instance. + * @type bool $gpu_zonal_redundancy_disabled + * Optional. True if GPU zonal redundancy is disabled on this instance. + * @type int $ingress + * Optional. Provides the ingress settings for this Instance. On output, + * returns the currently observed ingress settings, or + * INGRESS_TRAFFIC_UNSPECIFIED if no revision is active. + * @type bool $invoker_iam_disabled + * Optional. Disables IAM permission check for run.routes.invoke for callers + * of this Instance. For more information, visit + * https://cloud.google.com/run/docs/securing/managing-access#invoker_check. + * @type bool $iap_enabled + * Optional. IAP settings on the Instance. + * @type int|string $observed_generation + * Output only. The generation of this Instance currently serving traffic. See + * comments in `reconciling` for additional information on reconciliation + * process in Cloud Run. Please note that unlike v1, this is an int64 value. + * As with most Google APIs, its JSON representation will be a `string` + * instead of an `integer`. + * @type string $log_uri + * Output only. The Google Console URI to obtain logs for the Instance. + * @type \Google\Cloud\Run\V2\Condition $terminal_condition + * Output only. The Condition of this Instance, containing its readiness + * status, and detailed error information in case it did not reach a serving + * state. See comments in `reconciling` for additional information on + * reconciliation process in Cloud Run. + * @type array<\Google\Cloud\Run\V2\Condition>|\Google\Protobuf\Internal\RepeatedField $conditions + * Output only. The Conditions of all other associated sub-resources. They + * contain additional diagnostics information in case the Instance does not + * reach its Serving state. See comments in `reconciling` for additional + * information on reconciliation process in Cloud Run. + * @type array<\Google\Cloud\Run\V2\ContainerStatus>|\Google\Protobuf\Internal\RepeatedField $container_statuses + * Output only. Status information for each of the specified containers. The + * status includes the resolved digest for specified images. + * @type bool $satisfies_pzs + * Output only. Reserved for future use. + * @type array|\Google\Protobuf\Internal\RepeatedField $urls + * Output only. All URLs serving traffic for this Instance. + * @type bool $reconciling + * Output only. Returns true if the Instance is currently being acted upon by + * the system to bring it into the desired state. + * When a new Instance is created, or an existing one is updated, Cloud Run + * will asynchronously perform all necessary steps to bring the Instance to + * the desired serving state. This process is called reconciliation. While + * reconciliation is in process, `observed_generation` will have a transient + * value that might mismatch the intended state. + * Once reconciliation is over (and this field is false), there are two + * possible outcomes: reconciliation succeeded and the serving state matches + * the Instance, or there was an error, and reconciliation failed. This state + * can be found in `terminal_condition.state`. + * @type string $etag + * Optional. A system-generated fingerprint for this version of the + * resource. May be used to detect modification conflict during updates. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Run\V2\Instance::initOnce(); + parent::__construct($data); + } + + /** + * The fully qualified name of this Instance. In CreateInstanceRequest, this + * field is ignored, and instead composed from CreateInstanceRequest.parent + * and CreateInstanceRequest.instance_id. + * Format: + * projects/{project}/locations/{location}/instances/{instance_id} + * + * Generated from protobuf field string name = 1; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * The fully qualified name of this Instance. In CreateInstanceRequest, this + * field is ignored, and instead composed from CreateInstanceRequest.parent + * and CreateInstanceRequest.instance_id. + * Format: + * projects/{project}/locations/{location}/instances/{instance_id} + * + * 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; + } + + /** + * User-provided description of the Instance. This field currently has a + * 512-character limit. + * + * Generated from protobuf field string description = 3; + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * User-provided description of the Instance. This field currently has a + * 512-character limit. + * + * Generated from protobuf field string description = 3; + * @param string $var + * @return $this + */ + public function setDescription($var) + { + GPBUtil::checkString($var, True); + $this->description = $var; + + return $this; + } + + /** + * Output only. Server assigned unique identifier for the trigger. The value + * is a UUID4 string and guaranteed to remain unchanged until the resource is + * deleted. + * + * Generated from protobuf field string uid = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getUid() + { + return $this->uid; + } + + /** + * Output only. Server assigned unique identifier for the trigger. The value + * is a UUID4 string and guaranteed to remain unchanged until the resource is + * deleted. + * + * Generated from protobuf field string uid = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setUid($var) + { + GPBUtil::checkString($var, True); + $this->uid = $var; + + return $this; + } + + /** + * Output only. A number that monotonically increases every time the user + * modifies the desired state. + * Please note that unlike v1, this is an int64 value. As with most Google + * APIs, its JSON representation will be a `string` instead of an `integer`. + * + * Generated from protobuf field int64 generation = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return int|string + */ + public function getGeneration() + { + return $this->generation; + } + + /** + * Output only. A number that monotonically increases every time the user + * modifies the desired state. + * Please note that unlike v1, this is an int64 value. As with most Google + * APIs, its JSON representation will be a `string` instead of an `integer`. + * + * Generated from protobuf field int64 generation = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param int|string $var + * @return $this + */ + public function setGeneration($var) + { + GPBUtil::checkInt64($var); + $this->generation = $var; + + return $this; + } + + /** + * Generated from protobuf field map labels = 6; + * @return \Google\Protobuf\Internal\MapField + */ + public function getLabels() + { + return $this->labels; + } + + /** + * Generated from protobuf field map labels = 6; + * @param array|\Google\Protobuf\Internal\MapField $var + * @return $this + */ + public function setLabels($var) + { + $arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::STRING); + $this->labels = $arr; + + return $this; + } + + /** + * Generated from protobuf field map annotations = 7; + * @return \Google\Protobuf\Internal\MapField + */ + public function getAnnotations() + { + return $this->annotations; + } + + /** + * Generated from protobuf field map annotations = 7; + * @param array|\Google\Protobuf\Internal\MapField $var + * @return $this + */ + public function setAnnotations($var) + { + $arr = GPBUtil::checkMapField($var, \Google\Protobuf\Internal\GPBType::STRING, \Google\Protobuf\Internal\GPBType::STRING); + $this->annotations = $arr; + + return $this; + } + + /** + * Output only. The creation time. + * + * Generated from protobuf field .google.protobuf.Timestamp create_time = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Timestamp|null + */ + public function getCreateTime() + { + return $this->create_time; + } + + public function hasCreateTime() + { + return isset($this->create_time); + } + + public function clearCreateTime() + { + unset($this->create_time); + } + + /** + * Output only. The creation time. + * + * Generated from protobuf field .google.protobuf.Timestamp create_time = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setCreateTime($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->create_time = $var; + + return $this; + } + + /** + * Output only. The last-modified time. + * + * Generated from protobuf field .google.protobuf.Timestamp update_time = 9 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Timestamp|null + */ + public function getUpdateTime() + { + return $this->update_time; + } + + public function hasUpdateTime() + { + return isset($this->update_time); + } + + public function clearUpdateTime() + { + unset($this->update_time); + } + + /** + * Output only. The last-modified time. + * + * Generated from protobuf field .google.protobuf.Timestamp update_time = 9 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setUpdateTime($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->update_time = $var; + + return $this; + } + + /** + * Output only. The deletion time. + * + * Generated from protobuf field .google.protobuf.Timestamp delete_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Timestamp|null + */ + public function getDeleteTime() + { + return $this->delete_time; + } + + public function hasDeleteTime() + { + return isset($this->delete_time); + } + + public function clearDeleteTime() + { + unset($this->delete_time); + } + + /** + * Output only. The deletion time. + * + * Generated from protobuf field .google.protobuf.Timestamp delete_time = 10 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setDeleteTime($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->delete_time = $var; + + return $this; + } + + /** + * Output only. For a deleted resource, the time after which it will be + * permamently deleted. + * + * Generated from protobuf field .google.protobuf.Timestamp expire_time = 11 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Timestamp|null + */ + public function getExpireTime() + { + return $this->expire_time; + } + + public function hasExpireTime() + { + return isset($this->expire_time); + } + + public function clearExpireTime() + { + unset($this->expire_time); + } + + /** + * Output only. For a deleted resource, the time after which it will be + * permamently deleted. + * + * Generated from protobuf field .google.protobuf.Timestamp expire_time = 11 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setExpireTime($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->expire_time = $var; + + return $this; + } + + /** + * Output only. Email address of the authenticated creator. + * + * Generated from protobuf field string creator = 12 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getCreator() + { + return $this->creator; + } + + /** + * Output only. Email address of the authenticated creator. + * + * Generated from protobuf field string creator = 12 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setCreator($var) + { + GPBUtil::checkString($var, True); + $this->creator = $var; + + return $this; + } + + /** + * Output only. Email address of the last authenticated modifier. + * + * Generated from protobuf field string last_modifier = 13 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getLastModifier() + { + return $this->last_modifier; + } + + /** + * Output only. Email address of the last authenticated modifier. + * + * Generated from protobuf field string last_modifier = 13 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setLastModifier($var) + { + GPBUtil::checkString($var, True); + $this->last_modifier = $var; + + return $this; + } + + /** + * Arbitrary identifier for the API client. + * + * Generated from protobuf field string client = 14; + * @return string + */ + public function getClient() + { + return $this->client; + } + + /** + * Arbitrary identifier for the API client. + * + * Generated from protobuf field string client = 14; + * @param string $var + * @return $this + */ + public function setClient($var) + { + GPBUtil::checkString($var, True); + $this->client = $var; + + return $this; + } + + /** + * Arbitrary version identifier for the API client. + * + * Generated from protobuf field string client_version = 15; + * @return string + */ + public function getClientVersion() + { + return $this->client_version; + } + + /** + * Arbitrary version identifier for the API client. + * + * Generated from protobuf field string client_version = 15; + * @param string $var + * @return $this + */ + public function setClientVersion($var) + { + GPBUtil::checkString($var, True); + $this->client_version = $var; + + return $this; + } + + /** + * The launch stage as defined by [Google Cloud Platform + * Launch Stages](https://cloud.google.com/terms/launch-stages). + * Cloud Run supports `ALPHA`, `BETA`, and `GA`. If no value is specified, GA + * is assumed. + * Set the launch stage to a preview stage on input to allow use of preview + * features in that stage. On read (or output), describes whether the + * resource uses preview features. + *

+ * For example, if ALPHA is provided as input, but only BETA and GA-level + * features are used, this field will be BETA on output. + * + * Generated from protobuf field .google.api.LaunchStage launch_stage = 16; + * @return int + */ + public function getLaunchStage() + { + return $this->launch_stage; + } + + /** + * The launch stage as defined by [Google Cloud Platform + * Launch Stages](https://cloud.google.com/terms/launch-stages). + * Cloud Run supports `ALPHA`, `BETA`, and `GA`. If no value is specified, GA + * is assumed. + * Set the launch stage to a preview stage on input to allow use of preview + * features in that stage. On read (or output), describes whether the + * resource uses preview features. + *

+ * For example, if ALPHA is provided as input, but only BETA and GA-level + * features are used, this field will be BETA on output. + * + * Generated from protobuf field .google.api.LaunchStage launch_stage = 16; + * @param int $var + * @return $this + */ + public function setLaunchStage($var) + { + GPBUtil::checkEnum($var, \Google\Api\LaunchStage::class); + $this->launch_stage = $var; + + return $this; + } + + /** + * Settings for the Binary Authorization feature. + * + * Generated from protobuf field .google.cloud.run.v2.BinaryAuthorization binary_authorization = 17; + * @return \Google\Cloud\Run\V2\BinaryAuthorization|null + */ + public function getBinaryAuthorization() + { + return $this->binary_authorization; + } + + public function hasBinaryAuthorization() + { + return isset($this->binary_authorization); + } + + public function clearBinaryAuthorization() + { + unset($this->binary_authorization); + } + + /** + * Settings for the Binary Authorization feature. + * + * Generated from protobuf field .google.cloud.run.v2.BinaryAuthorization binary_authorization = 17; + * @param \Google\Cloud\Run\V2\BinaryAuthorization $var + * @return $this + */ + public function setBinaryAuthorization($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Run\V2\BinaryAuthorization::class); + $this->binary_authorization = $var; + + return $this; + } + + /** + * Optional. VPC Access configuration to use for this Revision. For more + * information, visit + * https://cloud.google.com/run/docs/configuring/connecting-vpc. + * + * Generated from protobuf field .google.cloud.run.v2.VpcAccess vpc_access = 18 [(.google.api.field_behavior) = OPTIONAL]; + * @return \Google\Cloud\Run\V2\VpcAccess|null + */ + public function getVpcAccess() + { + return $this->vpc_access; + } + + public function hasVpcAccess() + { + return isset($this->vpc_access); + } + + public function clearVpcAccess() + { + unset($this->vpc_access); + } + + /** + * Optional. VPC Access configuration to use for this Revision. For more + * information, visit + * https://cloud.google.com/run/docs/configuring/connecting-vpc. + * + * Generated from protobuf field .google.cloud.run.v2.VpcAccess vpc_access = 18 [(.google.api.field_behavior) = OPTIONAL]; + * @param \Google\Cloud\Run\V2\VpcAccess $var + * @return $this + */ + public function setVpcAccess($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Run\V2\VpcAccess::class); + $this->vpc_access = $var; + + return $this; + } + + /** + * Generated from protobuf field string service_account = 19; + * @return string + */ + public function getServiceAccount() + { + return $this->service_account; + } + + /** + * Generated from protobuf field string service_account = 19; + * @param string $var + * @return $this + */ + public function setServiceAccount($var) + { + GPBUtil::checkString($var, True); + $this->service_account = $var; + + return $this; + } + + /** + * Required. Holds the single container that defines the unit of execution for + * this Instance. + * + * Generated from protobuf field repeated .google.cloud.run.v2.Container containers = 20 [(.google.api.field_behavior) = REQUIRED]; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getContainers() + { + return $this->containers; + } + + /** + * Required. Holds the single container that defines the unit of execution for + * this Instance. + * + * Generated from protobuf field repeated .google.cloud.run.v2.Container containers = 20 [(.google.api.field_behavior) = REQUIRED]; + * @param array<\Google\Cloud\Run\V2\Container>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setContainers($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Run\V2\Container::class); + $this->containers = $arr; + + return $this; + } + + /** + * A list of Volumes to make available to containers. + * + * Generated from protobuf field repeated .google.cloud.run.v2.Volume volumes = 21; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getVolumes() + { + return $this->volumes; + } + + /** + * A list of Volumes to make available to containers. + * + * Generated from protobuf field repeated .google.cloud.run.v2.Volume volumes = 21; + * @param array<\Google\Cloud\Run\V2\Volume>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setVolumes($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Run\V2\Volume::class); + $this->volumes = $arr; + + return $this; + } + + /** + * A reference to a customer managed encryption key (CMEK) to use to encrypt + * this container image. For more information, go to + * https://cloud.google.com/run/docs/securing/using-cmek + * + * Generated from protobuf field string encryption_key = 22 [(.google.api.resource_reference) = { + * @return string + */ + public function getEncryptionKey() + { + return $this->encryption_key; + } + + /** + * A reference to a customer managed encryption key (CMEK) to use to encrypt + * this container image. For more information, go to + * https://cloud.google.com/run/docs/securing/using-cmek + * + * Generated from protobuf field string encryption_key = 22 [(.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setEncryptionKey($var) + { + GPBUtil::checkString($var, True); + $this->encryption_key = $var; + + return $this; + } + + /** + * The action to take if the encryption key is revoked. + * + * Generated from protobuf field .google.cloud.run.v2.EncryptionKeyRevocationAction encryption_key_revocation_action = 24; + * @return int + */ + public function getEncryptionKeyRevocationAction() + { + return $this->encryption_key_revocation_action; + } + + /** + * The action to take if the encryption key is revoked. + * + * Generated from protobuf field .google.cloud.run.v2.EncryptionKeyRevocationAction encryption_key_revocation_action = 24; + * @param int $var + * @return $this + */ + public function setEncryptionKeyRevocationAction($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\Run\V2\EncryptionKeyRevocationAction::class); + $this->encryption_key_revocation_action = $var; + + return $this; + } + + /** + * If encryption_key_revocation_action is SHUTDOWN, the duration before + * shutting down all instances. The minimum increment is 1 hour. + * + * Generated from protobuf field .google.protobuf.Duration encryption_key_shutdown_duration = 25; + * @return \Google\Protobuf\Duration|null + */ + public function getEncryptionKeyShutdownDuration() + { + return $this->encryption_key_shutdown_duration; + } + + public function hasEncryptionKeyShutdownDuration() + { + return isset($this->encryption_key_shutdown_duration); + } + + public function clearEncryptionKeyShutdownDuration() + { + unset($this->encryption_key_shutdown_duration); + } + + /** + * If encryption_key_revocation_action is SHUTDOWN, the duration before + * shutting down all instances. The minimum increment is 1 hour. + * + * Generated from protobuf field .google.protobuf.Duration encryption_key_shutdown_duration = 25; + * @param \Google\Protobuf\Duration $var + * @return $this + */ + public function setEncryptionKeyShutdownDuration($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Duration::class); + $this->encryption_key_shutdown_duration = $var; + + return $this; + } + + /** + * Optional. The node selector for the instance. + * + * Generated from protobuf field .google.cloud.run.v2.NodeSelector node_selector = 26 [(.google.api.field_behavior) = OPTIONAL]; + * @return \Google\Cloud\Run\V2\NodeSelector|null + */ + public function getNodeSelector() + { + return $this->node_selector; + } + + public function hasNodeSelector() + { + return isset($this->node_selector); + } + + public function clearNodeSelector() + { + unset($this->node_selector); + } + + /** + * Optional. The node selector for the instance. + * + * Generated from protobuf field .google.cloud.run.v2.NodeSelector node_selector = 26 [(.google.api.field_behavior) = OPTIONAL]; + * @param \Google\Cloud\Run\V2\NodeSelector $var + * @return $this + */ + public function setNodeSelector($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Run\V2\NodeSelector::class); + $this->node_selector = $var; + + return $this; + } + + /** + * Optional. True if GPU zonal redundancy is disabled on this instance. + * + * Generated from protobuf field optional bool gpu_zonal_redundancy_disabled = 27 [(.google.api.field_behavior) = OPTIONAL]; + * @return bool + */ + public function getGpuZonalRedundancyDisabled() + { + return isset($this->gpu_zonal_redundancy_disabled) ? $this->gpu_zonal_redundancy_disabled : false; + } + + public function hasGpuZonalRedundancyDisabled() + { + return isset($this->gpu_zonal_redundancy_disabled); + } + + public function clearGpuZonalRedundancyDisabled() + { + unset($this->gpu_zonal_redundancy_disabled); + } + + /** + * Optional. True if GPU zonal redundancy is disabled on this instance. + * + * Generated from protobuf field optional bool gpu_zonal_redundancy_disabled = 27 [(.google.api.field_behavior) = OPTIONAL]; + * @param bool $var + * @return $this + */ + public function setGpuZonalRedundancyDisabled($var) + { + GPBUtil::checkBool($var); + $this->gpu_zonal_redundancy_disabled = $var; + + return $this; + } + + /** + * Optional. Provides the ingress settings for this Instance. On output, + * returns the currently observed ingress settings, or + * INGRESS_TRAFFIC_UNSPECIFIED if no revision is active. + * + * Generated from protobuf field .google.cloud.run.v2.IngressTraffic ingress = 28 [(.google.api.field_behavior) = OPTIONAL]; + * @return int + */ + public function getIngress() + { + return $this->ingress; + } + + /** + * Optional. Provides the ingress settings for this Instance. On output, + * returns the currently observed ingress settings, or + * INGRESS_TRAFFIC_UNSPECIFIED if no revision is active. + * + * Generated from protobuf field .google.cloud.run.v2.IngressTraffic ingress = 28 [(.google.api.field_behavior) = OPTIONAL]; + * @param int $var + * @return $this + */ + public function setIngress($var) + { + GPBUtil::checkEnum($var, \Google\Cloud\Run\V2\IngressTraffic::class); + $this->ingress = $var; + + return $this; + } + + /** + * Optional. Disables IAM permission check for run.routes.invoke for callers + * of this Instance. For more information, visit + * https://cloud.google.com/run/docs/securing/managing-access#invoker_check. + * + * Generated from protobuf field bool invoker_iam_disabled = 29 [(.google.api.field_behavior) = OPTIONAL]; + * @return bool + */ + public function getInvokerIamDisabled() + { + return $this->invoker_iam_disabled; + } + + /** + * Optional. Disables IAM permission check for run.routes.invoke for callers + * of this Instance. For more information, visit + * https://cloud.google.com/run/docs/securing/managing-access#invoker_check. + * + * Generated from protobuf field bool invoker_iam_disabled = 29 [(.google.api.field_behavior) = OPTIONAL]; + * @param bool $var + * @return $this + */ + public function setInvokerIamDisabled($var) + { + GPBUtil::checkBool($var); + $this->invoker_iam_disabled = $var; + + return $this; + } + + /** + * Optional. IAP settings on the Instance. + * + * Generated from protobuf field bool iap_enabled = 30 [(.google.api.field_behavior) = OPTIONAL]; + * @return bool + */ + public function getIapEnabled() + { + return $this->iap_enabled; + } + + /** + * Optional. IAP settings on the Instance. + * + * Generated from protobuf field bool iap_enabled = 30 [(.google.api.field_behavior) = OPTIONAL]; + * @param bool $var + * @return $this + */ + public function setIapEnabled($var) + { + GPBUtil::checkBool($var); + $this->iap_enabled = $var; + + return $this; + } + + /** + * Output only. The generation of this Instance currently serving traffic. See + * comments in `reconciling` for additional information on reconciliation + * process in Cloud Run. Please note that unlike v1, this is an int64 value. + * As with most Google APIs, its JSON representation will be a `string` + * instead of an `integer`. + * + * Generated from protobuf field int64 observed_generation = 40 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return int|string + */ + public function getObservedGeneration() + { + return $this->observed_generation; + } + + /** + * Output only. The generation of this Instance currently serving traffic. See + * comments in `reconciling` for additional information on reconciliation + * process in Cloud Run. Please note that unlike v1, this is an int64 value. + * As with most Google APIs, its JSON representation will be a `string` + * instead of an `integer`. + * + * Generated from protobuf field int64 observed_generation = 40 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param int|string $var + * @return $this + */ + public function setObservedGeneration($var) + { + GPBUtil::checkInt64($var); + $this->observed_generation = $var; + + return $this; + } + + /** + * Output only. The Google Console URI to obtain logs for the Instance. + * + * Generated from protobuf field string log_uri = 41 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getLogUri() + { + return $this->log_uri; + } + + /** + * Output only. The Google Console URI to obtain logs for the Instance. + * + * Generated from protobuf field string log_uri = 41 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setLogUri($var) + { + GPBUtil::checkString($var, True); + $this->log_uri = $var; + + return $this; + } + + /** + * Output only. The Condition of this Instance, containing its readiness + * status, and detailed error information in case it did not reach a serving + * state. See comments in `reconciling` for additional information on + * reconciliation process in Cloud Run. + * + * Generated from protobuf field .google.cloud.run.v2.Condition terminal_condition = 42 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Cloud\Run\V2\Condition|null + */ + public function getTerminalCondition() + { + return $this->terminal_condition; + } + + public function hasTerminalCondition() + { + return isset($this->terminal_condition); + } + + public function clearTerminalCondition() + { + unset($this->terminal_condition); + } + + /** + * Output only. The Condition of this Instance, containing its readiness + * status, and detailed error information in case it did not reach a serving + * state. See comments in `reconciling` for additional information on + * reconciliation process in Cloud Run. + * + * Generated from protobuf field .google.cloud.run.v2.Condition terminal_condition = 42 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Cloud\Run\V2\Condition $var + * @return $this + */ + public function setTerminalCondition($var) + { + GPBUtil::checkMessage($var, \Google\Cloud\Run\V2\Condition::class); + $this->terminal_condition = $var; + + return $this; + } + + /** + * Output only. The Conditions of all other associated sub-resources. They + * contain additional diagnostics information in case the Instance does not + * reach its Serving state. See comments in `reconciling` for additional + * information on reconciliation process in Cloud Run. + * + * Generated from protobuf field repeated .google.cloud.run.v2.Condition conditions = 43 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getConditions() + { + return $this->conditions; + } + + /** + * Output only. The Conditions of all other associated sub-resources. They + * contain additional diagnostics information in case the Instance does not + * reach its Serving state. See comments in `reconciling` for additional + * information on reconciliation process in Cloud Run. + * + * Generated from protobuf field repeated .google.cloud.run.v2.Condition conditions = 43 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param array<\Google\Cloud\Run\V2\Condition>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setConditions($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Run\V2\Condition::class); + $this->conditions = $arr; + + return $this; + } + + /** + * Output only. Status information for each of the specified containers. The + * status includes the resolved digest for specified images. + * + * Generated from protobuf field repeated .google.cloud.run.v2.ContainerStatus container_statuses = 44 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getContainerStatuses() + { + return $this->container_statuses; + } + + /** + * Output only. Status information for each of the specified containers. The + * status includes the resolved digest for specified images. + * + * Generated from protobuf field repeated .google.cloud.run.v2.ContainerStatus container_statuses = 44 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param array<\Google\Cloud\Run\V2\ContainerStatus>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setContainerStatuses($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Run\V2\ContainerStatus::class); + $this->container_statuses = $arr; + + return $this; + } + + /** + * Output only. Reserved for future use. + * + * Generated from protobuf field bool satisfies_pzs = 46 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return bool + */ + public function getSatisfiesPzs() + { + return $this->satisfies_pzs; + } + + /** + * Output only. Reserved for future use. + * + * Generated from protobuf field bool satisfies_pzs = 46 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param bool $var + * @return $this + */ + public function setSatisfiesPzs($var) + { + GPBUtil::checkBool($var); + $this->satisfies_pzs = $var; + + return $this; + } + + /** + * Output only. All URLs serving traffic for this Instance. + * + * Generated from protobuf field repeated string urls = 45 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getUrls() + { + return $this->urls; + } + + /** + * Output only. All URLs serving traffic for this Instance. + * + * Generated from protobuf field repeated string urls = 45 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param array|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setUrls($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->urls = $arr; + + return $this; + } + + /** + * Output only. Returns true if the Instance is currently being acted upon by + * the system to bring it into the desired state. + * When a new Instance is created, or an existing one is updated, Cloud Run + * will asynchronously perform all necessary steps to bring the Instance to + * the desired serving state. This process is called reconciliation. While + * reconciliation is in process, `observed_generation` will have a transient + * value that might mismatch the intended state. + * Once reconciliation is over (and this field is false), there are two + * possible outcomes: reconciliation succeeded and the serving state matches + * the Instance, or there was an error, and reconciliation failed. This state + * can be found in `terminal_condition.state`. + * + * Generated from protobuf field bool reconciling = 98 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return bool + */ + public function getReconciling() + { + return $this->reconciling; + } + + /** + * Output only. Returns true if the Instance is currently being acted upon by + * the system to bring it into the desired state. + * When a new Instance is created, or an existing one is updated, Cloud Run + * will asynchronously perform all necessary steps to bring the Instance to + * the desired serving state. This process is called reconciliation. While + * reconciliation is in process, `observed_generation` will have a transient + * value that might mismatch the intended state. + * Once reconciliation is over (and this field is false), there are two + * possible outcomes: reconciliation succeeded and the serving state matches + * the Instance, or there was an error, and reconciliation failed. This state + * can be found in `terminal_condition.state`. + * + * Generated from protobuf field bool reconciling = 98 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param bool $var + * @return $this + */ + public function setReconciling($var) + { + GPBUtil::checkBool($var); + $this->reconciling = $var; + + return $this; + } + + /** + * Optional. A system-generated fingerprint for this version of the + * resource. May be used to detect modification conflict during updates. + * + * Generated from protobuf field string etag = 99 [(.google.api.field_behavior) = OPTIONAL]; + * @return string + */ + public function getEtag() + { + return $this->etag; + } + + /** + * Optional. A system-generated fingerprint for this version of the + * resource. May be used to detect modification conflict during updates. + * + * Generated from protobuf field string etag = 99 [(.google.api.field_behavior) = OPTIONAL]; + * @param string $var + * @return $this + */ + public function setEtag($var) + { + GPBUtil::checkString($var, True); + $this->etag = $var; + + return $this; + } + +} + diff --git a/Run/src/V2/ListInstancesRequest.php b/Run/src/V2/ListInstancesRequest.php new file mode 100644 index 000000000000..565a33cd9af0 --- /dev/null +++ b/Run/src/V2/ListInstancesRequest.php @@ -0,0 +1,201 @@ +google.cloud.run.v2.ListInstancesRequest + */ +class ListInstancesRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The location and project to list resources on. + * Format: projects/{project}/locations/{location}, where {project} can be + * project id or number. + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + protected $parent = ''; + /** + * Optional. Maximum number of Instances to return in this call. + * + * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $page_size = 0; + /** + * Optional. A page token received from a previous call to ListInstances. + * All other parameters must match. + * + * Generated from protobuf field string page_token = 3 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $page_token = ''; + /** + * Optional. If true, returns deleted (but unexpired) resources along with + * active ones. + * + * Generated from protobuf field bool show_deleted = 4 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $show_deleted = false; + + /** + * @param string $parent Required. The location and project to list resources on. + * Format: projects/{project}/locations/{location}, where {project} can be + * project id or number. Please see + * {@see InstancesClient::locationName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\ListInstancesRequest + * + * @experimental + */ + public static function build(string $parent): self + { + return (new self()) + ->setParent($parent); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $parent + * Required. The location and project to list resources on. + * Format: projects/{project}/locations/{location}, where {project} can be + * project id or number. + * @type int $page_size + * Optional. Maximum number of Instances to return in this call. + * @type string $page_token + * Optional. A page token received from a previous call to ListInstances. + * All other parameters must match. + * @type bool $show_deleted + * Optional. If true, returns deleted (but unexpired) resources along with + * active ones. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Run\V2\Instance::initOnce(); + parent::__construct($data); + } + + /** + * Required. The location and project to list resources on. + * Format: projects/{project}/locations/{location}, where {project} can be + * project id or number. + * + * 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 location and project to list resources on. + * Format: projects/{project}/locations/{location}, where {project} can be + * project id or number. + * + * 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; + } + + /** + * Optional. Maximum number of Instances to return in this call. + * + * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @return int + */ + public function getPageSize() + { + return $this->page_size; + } + + /** + * Optional. Maximum number of Instances to return in this call. + * + * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @param int $var + * @return $this + */ + public function setPageSize($var) + { + GPBUtil::checkInt32($var); + $this->page_size = $var; + + return $this; + } + + /** + * Optional. A page token received from a previous call to ListInstances. + * All other parameters must match. + * + * Generated from protobuf field string page_token = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @return string + */ + public function getPageToken() + { + return $this->page_token; + } + + /** + * Optional. A page token received from a previous call to ListInstances. + * All other parameters must match. + * + * Generated from protobuf field string page_token = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @param string $var + * @return $this + */ + public function setPageToken($var) + { + GPBUtil::checkString($var, True); + $this->page_token = $var; + + return $this; + } + + /** + * Optional. If true, returns deleted (but unexpired) resources along with + * active ones. + * + * Generated from protobuf field bool show_deleted = 4 [(.google.api.field_behavior) = OPTIONAL]; + * @return bool + */ + public function getShowDeleted() + { + return $this->show_deleted; + } + + /** + * Optional. If true, returns deleted (but unexpired) resources along with + * active ones. + * + * Generated from protobuf field bool show_deleted = 4 [(.google.api.field_behavior) = OPTIONAL]; + * @param bool $var + * @return $this + */ + public function setShowDeleted($var) + { + GPBUtil::checkBool($var); + $this->show_deleted = $var; + + return $this; + } + +} + diff --git a/Run/src/V2/ListInstancesResponse.php b/Run/src/V2/ListInstancesResponse.php new file mode 100644 index 000000000000..a532e1f63d8c --- /dev/null +++ b/Run/src/V2/ListInstancesResponse.php @@ -0,0 +1,105 @@ +google.cloud.run.v2.ListInstancesResponse + */ +class ListInstancesResponse extends \Google\Protobuf\Internal\Message +{ + /** + * The resulting list of Instances. + * + * Generated from protobuf field repeated .google.cloud.run.v2.Instance instances = 1; + */ + private $instances; + /** + * A token indicating there are more items than page_size. Use it in the next + * ListInstances request to continue. + * + * Generated from protobuf field string next_page_token = 2; + */ + protected $next_page_token = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type array<\Google\Cloud\Run\V2\Instance>|\Google\Protobuf\Internal\RepeatedField $instances + * The resulting list of Instances. + * @type string $next_page_token + * A token indicating there are more items than page_size. Use it in the next + * ListInstances request to continue. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Run\V2\Instance::initOnce(); + parent::__construct($data); + } + + /** + * The resulting list of Instances. + * + * Generated from protobuf field repeated .google.cloud.run.v2.Instance instances = 1; + * @return \Google\Protobuf\Internal\RepeatedField + */ + public function getInstances() + { + return $this->instances; + } + + /** + * The resulting list of Instances. + * + * Generated from protobuf field repeated .google.cloud.run.v2.Instance instances = 1; + * @param array<\Google\Cloud\Run\V2\Instance>|\Google\Protobuf\Internal\RepeatedField $var + * @return $this + */ + public function setInstances($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Cloud\Run\V2\Instance::class); + $this->instances = $arr; + + return $this; + } + + /** + * A token indicating there are more items than page_size. Use it in the next + * ListInstances request to continue. + * + * Generated from protobuf field string next_page_token = 2; + * @return string + */ + public function getNextPageToken() + { + return $this->next_page_token; + } + + /** + * A token indicating there are more items than page_size. Use it in the next + * ListInstances request to continue. + * + * 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/Run/src/V2/StartInstanceRequest.php b/Run/src/V2/StartInstanceRequest.php new file mode 100644 index 000000000000..3d6b7a687ee5 --- /dev/null +++ b/Run/src/V2/StartInstanceRequest.php @@ -0,0 +1,172 @@ +google.cloud.run.v2.StartInstanceRequest + */ +class StartInstanceRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The name of the Instance to stop. + * Format: + * `projects/{project}/locations/{location}/instances/{instance}`, + * where `{project}` can be project id or number. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + protected $name = ''; + /** + * Optional. Indicates that the request should be validated without actually + * stopping any resources. + * + * Generated from protobuf field bool validate_only = 2 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $validate_only = false; + /** + * Optional. A system-generated fingerprint for this version of the resource. + * This may be used to detect modification conflict during updates. + * + * Generated from protobuf field string etag = 3 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $etag = ''; + + /** + * @param string $name Required. The name of the Instance to stop. + * Format: + * `projects/{project}/locations/{location}/instances/{instance}`, + * where `{project}` can be project id or number. Please see + * {@see InstancesClient::instanceName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\StartInstanceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The name of the Instance to stop. + * Format: + * `projects/{project}/locations/{location}/instances/{instance}`, + * where `{project}` can be project id or number. + * @type bool $validate_only + * Optional. Indicates that the request should be validated without actually + * stopping any resources. + * @type string $etag + * Optional. A system-generated fingerprint for this version of the resource. + * This may be used to detect modification conflict during updates. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Run\V2\Instance::initOnce(); + parent::__construct($data); + } + + /** + * Required. The name of the Instance to stop. + * Format: + * `projects/{project}/locations/{location}/instances/{instance}`, + * where `{project}` can be project id or number. + * + * 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 name of the Instance to stop. + * Format: + * `projects/{project}/locations/{location}/instances/{instance}`, + * where `{project}` can be project id or number. + * + * 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; + } + + /** + * Optional. Indicates that the request should be validated without actually + * stopping any resources. + * + * Generated from protobuf field bool validate_only = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @return bool + */ + public function getValidateOnly() + { + return $this->validate_only; + } + + /** + * Optional. Indicates that the request should be validated without actually + * stopping any resources. + * + * Generated from protobuf field bool validate_only = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @param bool $var + * @return $this + */ + public function setValidateOnly($var) + { + GPBUtil::checkBool($var); + $this->validate_only = $var; + + return $this; + } + + /** + * Optional. A system-generated fingerprint for this version of the resource. + * This may be used to detect modification conflict during updates. + * + * Generated from protobuf field string etag = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @return string + */ + public function getEtag() + { + return $this->etag; + } + + /** + * Optional. A system-generated fingerprint for this version of the resource. + * This may be used to detect modification conflict during updates. + * + * Generated from protobuf field string etag = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @param string $var + * @return $this + */ + public function setEtag($var) + { + GPBUtil::checkString($var, True); + $this->etag = $var; + + return $this; + } + +} + diff --git a/Run/src/V2/StopInstanceRequest.php b/Run/src/V2/StopInstanceRequest.php new file mode 100644 index 000000000000..ae8eab3cb318 --- /dev/null +++ b/Run/src/V2/StopInstanceRequest.php @@ -0,0 +1,172 @@ +google.cloud.run.v2.StopInstanceRequest + */ +class StopInstanceRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. The name of the Instance to stop. + * Format: + * `projects/{project}/locations/{location}/instances/{instance}`, + * where `{project}` can be project id or number. + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + protected $name = ''; + /** + * Optional. Indicates that the request should be validated without actually + * stopping any resources. + * + * Generated from protobuf field bool validate_only = 2 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $validate_only = false; + /** + * Optional. A system-generated fingerprint for this version of the resource. + * This may be used to detect modification conflict during updates. + * + * Generated from protobuf field string etag = 3 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $etag = ''; + + /** + * @param string $name Required. The name of the Instance to stop. + * Format: + * `projects/{project}/locations/{location}/instances/{instance}`, + * where `{project}` can be project id or number. Please see + * {@see InstancesClient::instanceName()} for help formatting this field. + * + * @return \Google\Cloud\Run\V2\StopInstanceRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. The name of the Instance to stop. + * Format: + * `projects/{project}/locations/{location}/instances/{instance}`, + * where `{project}` can be project id or number. + * @type bool $validate_only + * Optional. Indicates that the request should be validated without actually + * stopping any resources. + * @type string $etag + * Optional. A system-generated fingerprint for this version of the resource. + * This may be used to detect modification conflict during updates. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Cloud\Run\V2\Instance::initOnce(); + parent::__construct($data); + } + + /** + * Required. The name of the Instance to stop. + * Format: + * `projects/{project}/locations/{location}/instances/{instance}`, + * where `{project}` can be project id or number. + * + * 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 name of the Instance to stop. + * Format: + * `projects/{project}/locations/{location}/instances/{instance}`, + * where `{project}` can be project id or number. + * + * 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; + } + + /** + * Optional. Indicates that the request should be validated without actually + * stopping any resources. + * + * Generated from protobuf field bool validate_only = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @return bool + */ + public function getValidateOnly() + { + return $this->validate_only; + } + + /** + * Optional. Indicates that the request should be validated without actually + * stopping any resources. + * + * Generated from protobuf field bool validate_only = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @param bool $var + * @return $this + */ + public function setValidateOnly($var) + { + GPBUtil::checkBool($var); + $this->validate_only = $var; + + return $this; + } + + /** + * Optional. A system-generated fingerprint for this version of the resource. + * This may be used to detect modification conflict during updates. + * + * Generated from protobuf field string etag = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @return string + */ + public function getEtag() + { + return $this->etag; + } + + /** + * Optional. A system-generated fingerprint for this version of the resource. + * This may be used to detect modification conflict during updates. + * + * Generated from protobuf field string etag = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @param string $var + * @return $this + */ + public function setEtag($var) + { + GPBUtil::checkString($var, True); + $this->etag = $var; + + return $this; + } + +} + diff --git a/Run/src/V2/gapic_metadata.json b/Run/src/V2/gapic_metadata.json index a17310d3cc5b..68d37bcf5427 100644 --- a/Run/src/V2/gapic_metadata.json +++ b/Run/src/V2/gapic_metadata.json @@ -48,6 +48,45 @@ } } }, + "Instances": { + "clients": { + "grpc": { + "libraryClient": "InstancesGapicClient", + "rpcs": { + "CreateInstance": { + "methods": [ + "createInstance" + ] + }, + "DeleteInstance": { + "methods": [ + "deleteInstance" + ] + }, + "GetInstance": { + "methods": [ + "getInstance" + ] + }, + "ListInstances": { + "methods": [ + "listInstances" + ] + }, + "StartInstance": { + "methods": [ + "startInstance" + ] + }, + "StopInstance": { + "methods": [ + "stopInstance" + ] + } + } + } + } + }, "Jobs": { "clients": { "grpc": { diff --git a/Run/src/V2/resources/instances_client_config.json b/Run/src/V2/resources/instances_client_config.json new file mode 100644 index 000000000000..823b3772d1b4 --- /dev/null +++ b/Run/src/V2/resources/instances_client_config.json @@ -0,0 +1,52 @@ +{ + "interfaces": { + "google.cloud.run.v2.Instances": { + "retry_codes": { + "no_retry_codes": [] + }, + "retry_params": { + "no_retry_params": { + "initial_retry_delay_millis": 0, + "retry_delay_multiplier": 0.0, + "max_retry_delay_millis": 0, + "initial_rpc_timeout_millis": 0, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 0, + "total_timeout_millis": 0 + } + }, + "methods": { + "CreateInstance": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + }, + "DeleteInstance": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + }, + "GetInstance": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + }, + "ListInstances": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + }, + "StartInstance": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + }, + "StopInstance": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + } + } + } + } +} diff --git a/Run/src/V2/resources/instances_descriptor_config.php b/Run/src/V2/resources/instances_descriptor_config.php new file mode 100644 index 000000000000..5c84f8676c5d --- /dev/null +++ b/Run/src/V2/resources/instances_descriptor_config.php @@ -0,0 +1,151 @@ + [ + 'google.cloud.run.v2.Instances' => [ + 'CreateInstance' => [ + 'longRunning' => [ + 'operationReturnType' => '\Google\Cloud\Run\V2\Instance', + 'metadataReturnType' => '\Google\Cloud\Run\V2\Instance', + 'initialPollDelayMillis' => '500', + 'pollDelayMultiplier' => '1.5', + 'maxPollDelayMillis' => '5000', + 'totalPollTimeoutMillis' => '300000', + ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getParent', + ], + 'matchers' => [], + ], + ], + ], + 'DeleteInstance' => [ + 'longRunning' => [ + 'operationReturnType' => '\Google\Cloud\Run\V2\Instance', + 'metadataReturnType' => '\Google\Cloud\Run\V2\Instance', + 'initialPollDelayMillis' => '500', + 'pollDelayMultiplier' => '1.5', + 'maxPollDelayMillis' => '5000', + 'totalPollTimeoutMillis' => '300000', + ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getName', + ], + 'matchers' => [], + ], + ], + ], + 'StartInstance' => [ + 'longRunning' => [ + 'operationReturnType' => '\Google\Cloud\Run\V2\Instance', + 'metadataReturnType' => '\Google\Cloud\Run\V2\Instance', + 'initialPollDelayMillis' => '500', + 'pollDelayMultiplier' => '1.5', + 'maxPollDelayMillis' => '5000', + 'totalPollTimeoutMillis' => '300000', + ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'StopInstance' => [ + 'longRunning' => [ + 'operationReturnType' => '\Google\Cloud\Run\V2\Instance', + 'metadataReturnType' => '\Google\Cloud\Run\V2\Instance', + 'initialPollDelayMillis' => '500', + 'pollDelayMultiplier' => '1.5', + 'maxPollDelayMillis' => '5000', + 'totalPollTimeoutMillis' => '300000', + ], + 'callType' => \Google\ApiCore\Call::LONGRUNNING_CALL, + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'GetInstance' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Cloud\Run\V2\Instance', + 'headerParams' => [ + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getName', + ], + 'matchers' => [], + ], + ], + ], + 'ListInstances' => [ + 'pageStreaming' => [ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getInstances', + ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Cloud\Run\V2\ListInstancesResponse', + 'headerParams' => [ + [ + 'keyName' => 'location', + 'fieldAccessors' => [ + 'getParent', + ], + 'matchers' => [], + ], + ], + ], + 'templateMap' => [ + 'connector' => 'projects/{project}/locations/{location}/connectors/{connector}', + 'cryptoKey' => 'projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}', + 'instance' => 'projects/{project}/locations/{location}/instances/{instance}', + 'location' => 'projects/{project}/locations/{location}', + 'locationPolicy' => 'locations/{location}/policy', + 'policy' => 'projects/{project}/policy', + 'projectPolicy' => 'projects/{project}/policy', + 'secret' => 'projects/{project}/secrets/{secret}', + 'secretVersion' => 'projects/{project}/secrets/{secret}/versions/{version}', + ], + ], + ], +]; diff --git a/Run/src/V2/resources/instances_rest_client_config.php b/Run/src/V2/resources/instances_rest_client_config.php new file mode 100644 index 000000000000..e8de7e1101b3 --- /dev/null +++ b/Run/src/V2/resources/instances_rest_client_config.php @@ -0,0 +1,148 @@ + [ + 'google.cloud.run.v2.Instances' => [ + 'CreateInstance' => [ + 'method' => 'post', + 'uriTemplate' => '/v2/{parent=projects/*/locations/*}/instances', + 'body' => 'instance', + 'placeholders' => [ + 'parent' => [ + 'getters' => [ + 'getParent', + ], + ], + ], + 'queryParams' => [ + 'instance_id', + ], + ], + 'DeleteInstance' => [ + 'method' => 'delete', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/instances/*}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'GetInstance' => [ + 'method' => 'get', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/instances/*}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'ListInstances' => [ + 'method' => 'get', + 'uriTemplate' => '/v2/{parent=projects/*/locations/*}/instances', + 'placeholders' => [ + 'parent' => [ + 'getters' => [ + 'getParent', + ], + ], + ], + ], + 'StartInstance' => [ + 'method' => 'post', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/instances/*}:start', + 'body' => '*', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'StopInstance' => [ + 'method' => 'post', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/instances/*}:stop', + 'body' => '*', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + ], + 'google.longrunning.Operations' => [ + 'DeleteOperation' => [ + 'method' => 'delete', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/operations/*}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'GetOperation' => [ + 'method' => 'get', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/operations/*}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'ListOperations' => [ + 'method' => 'get', + 'uriTemplate' => '/v2/{name=projects/*/locations/*}/operations', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'WaitOperation' => [ + 'method' => 'post', + 'uriTemplate' => '/v2/{name=projects/*/locations/*/operations/*}:wait', + 'body' => '*', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + ], + ], + 'numericEnums' => true, +]; diff --git a/Run/tests/Unit/V2/Client/InstancesClientTest.php b/Run/tests/Unit/V2/Client/InstancesClientTest.php new file mode 100644 index 000000000000..fd0d7213454d --- /dev/null +++ b/Run/tests/Unit/V2/Client/InstancesClientTest.php @@ -0,0 +1,1004 @@ +getMockBuilder(CredentialsWrapper::class) + ->disableOriginalConstructor() + ->getMock(); + } + + /** @return InstancesClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new InstancesClient($options); + } + + /** @test */ + public function createInstanceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + '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('operations/createInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $serviceAccount = 'serviceAccount-1948028253'; + $encryptionKey = 'encryptionKey-1122344029'; + $gpuZonalRedundancyDisabled = true; + $invokerIamDisabled = false; + $iapEnabled = true; + $observedGeneration = 900833007; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $reconciling = false; + $etag = 'etag3123477'; + $expectedResponse = new Instance(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setEncryptionKey($encryptionKey); + $expectedResponse->setGpuZonalRedundancyDisabled($gpuZonalRedundancyDisabled); + $expectedResponse->setInvokerIamDisabled($invokerIamDisabled); + $expectedResponse->setIapEnabled($iapEnabled); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $instance = new Instance(); + $instanceContainers = []; + $instance->setContainers($instanceContainers); + $instanceId = 'instanceId-2101995259'; + $request = (new CreateInstanceRequest()) + ->setParent($formattedParent) + ->setInstance($instance) + ->setInstanceId($instanceId); + $response = $gapicClient->createInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $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.run.v2.Instances/CreateInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getInstance(); + $this->assertProtobufEquals($instance, $actualValue); + $actualValue = $actualApiRequestObject->getInstanceId(); + $this->assertProtobufEquals($instanceId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $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.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function createInstanceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + '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('operations/createInstanceTest'); + $incompleteOperation->setDone(false); + $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 + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $instance = new Instance(); + $instanceContainers = []; + $instance->setContainers($instanceContainers); + $instanceId = 'instanceId-2101995259'; + $request = (new CreateInstanceRequest()) + ->setParent($formattedParent) + ->setInstance($instance) + ->setInstanceId($instanceId); + $response = $gapicClient->createInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createInstanceTest'); + 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 deleteInstanceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + '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('operations/deleteInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $serviceAccount = 'serviceAccount-1948028253'; + $encryptionKey = 'encryptionKey-1122344029'; + $gpuZonalRedundancyDisabled = true; + $invokerIamDisabled = false; + $iapEnabled = true; + $observedGeneration = 900833007; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $reconciling = false; + $etag2 = 'etag2-1293302904'; + $expectedResponse = new Instance(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setEncryptionKey($encryptionKey); + $expectedResponse->setGpuZonalRedundancyDisabled($gpuZonalRedundancyDisabled); + $expectedResponse->setInvokerIamDisabled($invokerIamDisabled); + $expectedResponse->setIapEnabled($iapEnabled); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setEtag($etag2); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/deleteInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new DeleteInstanceRequest())->setName($formattedName); + $response = $gapicClient->deleteInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $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.run.v2.Instances/DeleteInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $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.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function deleteInstanceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + '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('operations/deleteInstanceTest'); + $incompleteOperation->setDone(false); + $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 + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new DeleteInstanceRequest())->setName($formattedName); + $response = $gapicClient->deleteInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/deleteInstanceTest'); + 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 getInstanceTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $serviceAccount = 'serviceAccount-1948028253'; + $encryptionKey = 'encryptionKey-1122344029'; + $gpuZonalRedundancyDisabled = true; + $invokerIamDisabled = false; + $iapEnabled = true; + $observedGeneration = 900833007; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $reconciling = false; + $etag = 'etag3123477'; + $expectedResponse = new Instance(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setEncryptionKey($encryptionKey); + $expectedResponse->setGpuZonalRedundancyDisabled($gpuZonalRedundancyDisabled); + $expectedResponse->setInvokerIamDisabled($invokerIamDisabled); + $expectedResponse->setIapEnabled($iapEnabled); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setEtag($etag); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new GetInstanceRequest())->setName($formattedName); + $response = $gapicClient->getInstance($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.run.v2.Instances/GetInstance', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getInstanceExceptionTest() + { + $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 + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new GetInstanceRequest())->setName($formattedName); + try { + $gapicClient->getInstance($request); + // 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 listInstancesTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $instancesElement = new Instance(); + $instances = [$instancesElement]; + $expectedResponse = new ListInstancesResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setInstances($instances); + $transport->addResponse($expectedResponse); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListInstancesRequest())->setParent($formattedParent); + $response = $gapicClient->listInstances($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getInstances()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.cloud.run.v2.Instances/ListInstances', $actualFuncCall); + $actualValue = $actualRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function listInstancesExceptionTest() + { + $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 + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $request = (new ListInstancesRequest())->setParent($formattedParent); + try { + $gapicClient->listInstances($request); + // 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 startInstanceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + '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('operations/startInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $serviceAccount = 'serviceAccount-1948028253'; + $encryptionKey = 'encryptionKey-1122344029'; + $gpuZonalRedundancyDisabled = true; + $invokerIamDisabled = false; + $iapEnabled = true; + $observedGeneration = 900833007; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $reconciling = false; + $etag2 = 'etag2-1293302904'; + $expectedResponse = new Instance(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setEncryptionKey($encryptionKey); + $expectedResponse->setGpuZonalRedundancyDisabled($gpuZonalRedundancyDisabled); + $expectedResponse->setInvokerIamDisabled($invokerIamDisabled); + $expectedResponse->setIapEnabled($iapEnabled); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setEtag($etag2); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/startInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new StartInstanceRequest())->setName($formattedName); + $response = $gapicClient->startInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $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.run.v2.Instances/StartInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/startInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $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.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function startInstanceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + '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('operations/startInstanceTest'); + $incompleteOperation->setDone(false); + $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 + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new StartInstanceRequest())->setName($formattedName); + $response = $gapicClient->startInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/startInstanceTest'); + 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 stopInstanceTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + '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('operations/stopInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name2 = 'name2-1052831874'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $serviceAccount = 'serviceAccount-1948028253'; + $encryptionKey = 'encryptionKey-1122344029'; + $gpuZonalRedundancyDisabled = true; + $invokerIamDisabled = false; + $iapEnabled = true; + $observedGeneration = 900833007; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $reconciling = false; + $etag2 = 'etag2-1293302904'; + $expectedResponse = new Instance(); + $expectedResponse->setName($name2); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setEncryptionKey($encryptionKey); + $expectedResponse->setGpuZonalRedundancyDisabled($gpuZonalRedundancyDisabled); + $expectedResponse->setInvokerIamDisabled($invokerIamDisabled); + $expectedResponse->setIapEnabled($iapEnabled); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setEtag($etag2); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/stopInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new StopInstanceRequest())->setName($formattedName); + $response = $gapicClient->stopInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $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.run.v2.Instances/StopInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/stopInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $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.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } + + /** @test */ + public function stopInstanceExceptionTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + '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('operations/stopInstanceTest'); + $incompleteOperation->setDone(false); + $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 + $formattedName = $gapicClient->instanceName('[PROJECT]', '[LOCATION]', '[INSTANCE]'); + $request = (new StopInstanceRequest())->setName($formattedName); + $response = $gapicClient->stopInstance($request); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/stopInstanceTest'); + 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 createInstanceAsyncTest() + { + $operationsTransport = $this->createTransport(); + $operationsClient = new OperationsClient([ + '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('operations/createInstanceTest'); + $incompleteOperation->setDone(false); + $transport->addResponse($incompleteOperation); + $name = 'name3373707'; + $description = 'description-1724546052'; + $uid = 'uid115792'; + $generation = 305703192; + $creator = 'creator1028554796'; + $lastModifier = 'lastModifier-28366240'; + $client = 'client-1357712437'; + $clientVersion = 'clientVersion-1506231196'; + $serviceAccount = 'serviceAccount-1948028253'; + $encryptionKey = 'encryptionKey-1122344029'; + $gpuZonalRedundancyDisabled = true; + $invokerIamDisabled = false; + $iapEnabled = true; + $observedGeneration = 900833007; + $logUri = 'logUri342054385'; + $satisfiesPzs = false; + $reconciling = false; + $etag = 'etag3123477'; + $expectedResponse = new Instance(); + $expectedResponse->setName($name); + $expectedResponse->setDescription($description); + $expectedResponse->setUid($uid); + $expectedResponse->setGeneration($generation); + $expectedResponse->setCreator($creator); + $expectedResponse->setLastModifier($lastModifier); + $expectedResponse->setClient($client); + $expectedResponse->setClientVersion($clientVersion); + $expectedResponse->setServiceAccount($serviceAccount); + $expectedResponse->setEncryptionKey($encryptionKey); + $expectedResponse->setGpuZonalRedundancyDisabled($gpuZonalRedundancyDisabled); + $expectedResponse->setInvokerIamDisabled($invokerIamDisabled); + $expectedResponse->setIapEnabled($iapEnabled); + $expectedResponse->setObservedGeneration($observedGeneration); + $expectedResponse->setLogUri($logUri); + $expectedResponse->setSatisfiesPzs($satisfiesPzs); + $expectedResponse->setReconciling($reconciling); + $expectedResponse->setEtag($etag); + $anyResponse = new Any(); + $anyResponse->setValue($expectedResponse->serializeToString()); + $completeOperation = new Operation(); + $completeOperation->setName('operations/createInstanceTest'); + $completeOperation->setDone(true); + $completeOperation->setResponse($anyResponse); + $operationsTransport->addResponse($completeOperation); + // Mock request + $formattedParent = $gapicClient->locationName('[PROJECT]', '[LOCATION]'); + $instance = new Instance(); + $instanceContainers = []; + $instance->setContainers($instanceContainers); + $instanceId = 'instanceId-2101995259'; + $request = (new CreateInstanceRequest()) + ->setParent($formattedParent) + ->setInstance($instance) + ->setInstanceId($instanceId); + $response = $gapicClient->createInstanceAsync($request)->wait(); + $this->assertFalse($response->isDone()); + $this->assertNull($response->getResult()); + $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.run.v2.Instances/CreateInstance', $actualApiFuncCall); + $actualValue = $actualApiRequestObject->getParent(); + $this->assertProtobufEquals($formattedParent, $actualValue); + $actualValue = $actualApiRequestObject->getInstance(); + $this->assertProtobufEquals($instance, $actualValue); + $actualValue = $actualApiRequestObject->getInstanceId(); + $this->assertProtobufEquals($instanceId, $actualValue); + $expectedOperationsRequestObject = new GetOperationRequest(); + $expectedOperationsRequestObject->setName('operations/createInstanceTest'); + $response->pollUntilComplete([ + 'initialPollDelayMillis' => 1, + ]); + $this->assertTrue($response->isDone()); + $this->assertEquals($expectedResponse, $response->getResult()); + $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.longrunning.Operations/GetOperation', $actualOperationsFuncCall); + $this->assertEquals($expectedOperationsRequestObject, $actualOperationsRequestObject); + $this->assertTrue($transport->isExhausted()); + $this->assertTrue($operationsTransport->isExhausted()); + } +}