Skip to content

Commit

Permalink
Add changes for grpc only clients and fix comment for the php doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Hectorhammett committed Apr 25, 2024
1 parent 573609c commit 09cb59a
Show file tree
Hide file tree
Showing 23 changed files with 131 additions and 3,030 deletions.
4 changes: 3 additions & 1 deletion rules_php_gapic/php_gapic.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def php_gapic_srcjar(
rest_numeric_enums = False,
generate_snippets = True,
# Supported values validated and specified in src/Utils/MigrationMode.php.
migration_mode = "PRE_MIGRATION_SURFACE_ONLY",
migration_mode = "PRE_MIGRATION_SURFACE_ONLY",
generator_binary = Label("//rules_php_gapic:php_gapic_generator_binary"),
**kwargs):
plugin_file_args = {}
Expand All @@ -71,6 +71,8 @@ def php_gapic_srcjar(
transport = "grpc+rest"
if transport != "grpc+rest" and transport != "rest" and transport != "grpc":
fail("Error: Only 'grpc+rest', 'rest' or `grpc` transports are supported")
if transport == "grpc" and migration_mode != "NEW_SURFACE_ONLY":
fail("Error: 'grpc' transport is only supported with 'NEW_SURFACE_ONLY' migration mode")

# Set plugin arguments.
plugin_args = ["metadata"] # Generate the gapic_metadata.json file.
Expand Down
2 changes: 1 addition & 1 deletion src/Generation/GapicClientGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ private function getClientDefaults(): PhpClassMember

// TODO: Consolidate setting all the known array values together.
// We do this here to maintain the existing sensible ordering.
if ($this->serviceDetails->transportType !== Transport::REST) {
if ($this->serviceDetails->transportType === Transport::GRPC_REST) {
$clientDefaultValues['gcpApiConfigPath'] =
AST::concat(AST::__DIR__, "/../resources/{$this->serviceDetails->grpcConfigFilename}");
}
Expand Down
10 changes: 5 additions & 5 deletions src/Generation/GapicClientV2Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ private function getClientDefaults(): PhpClassMember

// TODO: Consolidate setting all the known array values together.
// We do this here to maintain the existing sensible ordering.
if ($this->serviceDetails->transportType === Transport::GRPC_REST) {
if ($this->serviceDetails->transportType !== Transport::REST) {
$clientDefaultValues['gcpApiConfigPath'] =
AST::concat(AST::__DIR__, "/../resources/{$this->serviceDetails->grpcConfigFilename}");
}
Expand Down Expand Up @@ -548,16 +548,16 @@ private function construct(): PhpClassMember
AST::call(
$ctx->type(
Type::fromName(
Transport::isRestOnly($transportType) ?
Transport::isRestOnly($transportType) ?
RestTransport::class :
GrpcTransport::class
),
true
),
AST::method('build')
)(),
Transport::isGRPCRest($transportType) ? 'and' : '',
Transport::isGRPCRest($transportType) ?
Transport::isGrpcRest($transportType) ? 'and' : '',
Transport::isGrpcRest($transportType) ?
AST::call(
$ctx->type(
Type::fromName(RestTransport::class),
Expand All @@ -566,7 +566,7 @@ private function construct(): PhpClassMember
AST::method('build')
)()
: '',
Transport::isGRPCRest($transportType) ? 'methods ' : 'method ',
Transport::isGrpcRest($transportType) ? 'methods ' : 'method ',
'for the supported options.'
);
return AST::method('__construct')
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function isGrpcOnly(int $transport): bool
return Transport::compareTransports(Transport::GRPC, $transport);
}

public static function isGRPCRest(int $transport): bool
public static function isGrpcRest(int $transport): bool
{
return Transport::compareTransports(Transport::GRPC_REST, $transport);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ php_gapic_library(
gapic_yaml = "apis/redis/v1/redis_gapic.yaml",
grpc_service_config = "@com_google_googleapis//google/cloud/redis/v1:redis_grpc_service_config.json",
service_yaml = "@com_google_googleapis//google/cloud/redis/v1:redis_v1.yaml",
migration_mode = "MIGRATION_MODE_UNSPECIFIED",
migration_mode = "NEW_SURFACE_ONLY",
transport = "grpc",
deps = [
":redis_php_grpc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START redis_v1_generated_CloudRedis_CreateInstance_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Redis\V1\CloudRedisClient;
use Google\Cloud\Redis\V1\Client\CloudRedisClient;
use Google\Cloud\Redis\V1\CreateInstanceRequest;
use Google\Cloud\Redis\V1\Instance;
use Google\Cloud\Redis\V1\Instance\Tier;
use Google\Rpc\Status;
Expand Down Expand Up @@ -80,16 +81,20 @@ function create_instance_sample(
// Create a client.
$cloudRedisClient = new CloudRedisClient();

// Prepare any non-scalar elements to be passed along with the request.
// Prepare the request message.
$instance = (new Instance())
->setName($instanceName)
->setTier($instanceTier)
->setMemorySizeGb($instanceMemorySizeGb);
$request = (new CreateInstanceRequest())
->setParent($formattedParent)
->setInstanceId($instanceId)
->setInstance($instance);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $cloudRedisClient->createInstance($formattedParent, $instanceId, $instance);
$response = $cloudRedisClient->createInstance($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START redis_v1_generated_CloudRedis_DeleteInstance_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Redis\V1\CloudRedisClient;
use Google\Cloud\Redis\V1\Client\CloudRedisClient;
use Google\Cloud\Redis\V1\DeleteInstanceRequest;
use Google\Rpc\Status;

/**
Expand All @@ -42,10 +43,14 @@ function delete_instance_sample(string $formattedName): void
// Create a client.
$cloudRedisClient = new CloudRedisClient();

// Prepare the request message.
$request = (new DeleteInstanceRequest())
->setName($formattedName);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $cloudRedisClient->deleteInstance($formattedName);
$response = $cloudRedisClient->deleteInstance($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START redis_v1_generated_CloudRedis_ExportInstance_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Redis\V1\CloudRedisClient;
use Google\Cloud\Redis\V1\Client\CloudRedisClient;
use Google\Cloud\Redis\V1\ExportInstanceRequest;
use Google\Cloud\Redis\V1\Instance;
use Google\Cloud\Redis\V1\OutputConfig;
use Google\Rpc\Status;
Expand All @@ -47,13 +48,16 @@ function export_instance_sample(string $name): void
// Create a client.
$cloudRedisClient = new CloudRedisClient();

// Prepare any non-scalar elements to be passed along with the request.
// Prepare the request message.
$outputConfig = new OutputConfig();
$request = (new ExportInstanceRequest())
->setName($name)
->setOutputConfig($outputConfig);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $cloudRedisClient->exportInstance($name, $outputConfig);
$response = $cloudRedisClient->exportInstance($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START redis_v1_generated_CloudRedis_FailoverInstance_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Redis\V1\CloudRedisClient;
use Google\Cloud\Redis\V1\Client\CloudRedisClient;
use Google\Cloud\Redis\V1\FailoverInstanceRequest;
use Google\Cloud\Redis\V1\Instance;
use Google\Rpc\Status;

Expand All @@ -43,10 +44,14 @@ function failover_instance_sample(string $formattedName): void
// Create a client.
$cloudRedisClient = new CloudRedisClient();

// Prepare the request message.
$request = (new FailoverInstanceRequest())
->setName($formattedName);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $cloudRedisClient->failoverInstance($formattedName);
$response = $cloudRedisClient->failoverInstance($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

// [START redis_v1_generated_CloudRedis_GetInstance_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Redis\V1\CloudRedisClient;
use Google\Cloud\Redis\V1\Client\CloudRedisClient;
use Google\Cloud\Redis\V1\GetInstanceRequest;
use Google\Cloud\Redis\V1\Instance;

/**
Expand All @@ -40,10 +41,14 @@ function get_instance_sample(string $formattedName): void
// Create a client.
$cloudRedisClient = new CloudRedisClient();

// Prepare the request message.
$request = (new GetInstanceRequest())
->setName($formattedName);

// Call the API and handle any network failures.
try {
/** @var Instance $response */
$response = $cloudRedisClient->getInstance($formattedName);
$response = $cloudRedisClient->getInstance($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

// [START redis_v1_generated_CloudRedis_GetInstanceAuthString_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Redis\V1\CloudRedisClient;
use Google\Cloud\Redis\V1\Client\CloudRedisClient;
use Google\Cloud\Redis\V1\GetInstanceAuthStringRequest;
use Google\Cloud\Redis\V1\InstanceAuthString;

/**
Expand All @@ -42,10 +43,14 @@ function get_instance_auth_string_sample(string $formattedName): void
// Create a client.
$cloudRedisClient = new CloudRedisClient();

// Prepare the request message.
$request = (new GetInstanceAuthStringRequest())
->setName($formattedName);

// Call the API and handle any network failures.
try {
/** @var InstanceAuthString $response */
$response = $cloudRedisClient->getInstanceAuthString($formattedName);
$response = $cloudRedisClient->getInstanceAuthString($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@

// [START redis_v1_generated_CloudRedis_GetLocation_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Location\GetLocationRequest;
use Google\Cloud\Location\Location;
use Google\Cloud\Redis\V1\CloudRedisClient;
use Google\Cloud\Redis\V1\Client\CloudRedisClient;

/**
* Gets information about a location.
Expand All @@ -41,10 +42,13 @@ function get_location_sample(): void
// Create a client.
$cloudRedisClient = new CloudRedisClient();

// Prepare the request message.
$request = new GetLocationRequest();

// Call the API and handle any network failures.
try {
/** @var Location $response */
$response = $cloudRedisClient->getLocation();
$response = $cloudRedisClient->getLocation($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
// [START redis_v1_generated_CloudRedis_ImportInstance_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Redis\V1\CloudRedisClient;
use Google\Cloud\Redis\V1\Client\CloudRedisClient;
use Google\Cloud\Redis\V1\ImportInstanceRequest;
use Google\Cloud\Redis\V1\InputConfig;
use Google\Cloud\Redis\V1\Instance;
use Google\Rpc\Status;
Expand All @@ -49,13 +50,16 @@ function import_instance_sample(string $name): void
// Create a client.
$cloudRedisClient = new CloudRedisClient();

// Prepare any non-scalar elements to be passed along with the request.
// Prepare the request message.
$inputConfig = new InputConfig();
$request = (new ImportInstanceRequest())
->setName($name)
->setInputConfig($inputConfig);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $cloudRedisClient->importInstance($name, $inputConfig);
$response = $cloudRedisClient->importInstance($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
// [START redis_v1_generated_CloudRedis_ListInstances_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Redis\V1\CloudRedisClient;
use Google\Cloud\Redis\V1\Client\CloudRedisClient;
use Google\Cloud\Redis\V1\Instance;
use Google\Cloud\Redis\V1\ListInstancesRequest;

/**
* Lists all Redis instances owned by a project in either the specified
Expand All @@ -49,10 +50,14 @@ function list_instances_sample(string $formattedParent): void
// Create a client.
$cloudRedisClient = new CloudRedisClient();

// Prepare the request message.
$request = (new ListInstancesRequest())
->setParent($formattedParent);

// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $cloudRedisClient->listInstances($formattedParent);
$response = $cloudRedisClient->listInstances($request);

/** @var Instance $element */
foreach ($response as $element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
// [START redis_v1_generated_CloudRedis_ListLocations_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Location\ListLocationsRequest;
use Google\Cloud\Location\Location;
use Google\Cloud\Redis\V1\CloudRedisClient;
use Google\Cloud\Redis\V1\Client\CloudRedisClient;

/**
* Lists information about the supported locations for this service.
Expand All @@ -42,10 +43,13 @@ function list_locations_sample(): void
// Create a client.
$cloudRedisClient = new CloudRedisClient();

// Prepare the request message.
$request = new ListLocationsRequest();

// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $cloudRedisClient->listLocations();
$response = $cloudRedisClient->listLocations($request);

/** @var Location $element */
foreach ($response as $element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
// [START redis_v1_generated_CloudRedis_RescheduleMaintenance_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Redis\V1\CloudRedisClient;
use Google\Cloud\Redis\V1\Client\CloudRedisClient;
use Google\Cloud\Redis\V1\Instance;
use Google\Cloud\Redis\V1\RescheduleMaintenanceRequest;
use Google\Cloud\Redis\V1\RescheduleMaintenanceRequest\RescheduleType;
use Google\Rpc\Status;

Expand All @@ -46,10 +47,15 @@ function reschedule_maintenance_sample(string $formattedName, int $rescheduleTyp
// Create a client.
$cloudRedisClient = new CloudRedisClient();

// Prepare the request message.
$request = (new RescheduleMaintenanceRequest())
->setName($formattedName)
->setRescheduleType($rescheduleType);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $cloudRedisClient->rescheduleMaintenance($formattedName, $rescheduleType);
$response = $cloudRedisClient->rescheduleMaintenance($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
Expand Down

0 comments on commit 09cb59a

Please sign in to comment.