Skip to content

Commit ba24dd2

Browse files
authored
feat(ServiceDirectory): upgrade to v2 (GoogleCloudPlatform#2113)
1 parent 9d68de7 commit ba24dd2

10 files changed

+66
-26
lines changed

servicedirectory/composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{
22
"require": {
3-
"google/cloud-service-directory": "^1.0.0"
3+
"google/cloud-service-directory": "^2.0.0"
4+
},
5+
"require-dev": {
6+
"google/cloud-tools": "^0.15.0",
7+
"friendsofphp/php-cs-fixer": "^3.21"
48
}
59
}

servicedirectory/src/create_endpoint.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
namespace Google\Cloud\Samples\ServiceDirectory;
2020

2121
// [START servicedirectory_create_endpoint]
22-
use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient;
23-
use Google\Cloud\ServiceDirectory\V1beta1\Endpoint;
22+
use Google\Cloud\ServiceDirectory\V1\Client\RegistrationServiceClient;
23+
use Google\Cloud\ServiceDirectory\V1\CreateEndpointRequest;
24+
use Google\Cloud\ServiceDirectory\V1\Endpoint;
2425

2526
/**
2627
* @param string $projectId Your Cloud project ID
@@ -50,7 +51,11 @@ function create_endpoint(
5051

5152
// Run request.
5253
$serviceName = RegistrationServiceClient::serviceName($projectId, $locationId, $namespaceId, $serviceId);
53-
$endpoint = $client->createEndpoint($serviceName, $endpointId, $endpointObject);
54+
$createEndpointRequest = (new CreateEndpointRequest())
55+
->setParent($serviceName)
56+
->setEndpointId($endpointId)
57+
->setEndpoint($endpointObject);
58+
$endpoint = $client->createEndpoint($createEndpointRequest);
5459

5560
// Print results.
5661
printf('Created Endpoint: %s' . PHP_EOL, $endpoint->getName());

servicedirectory/src/create_namespace.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
namespace Google\Cloud\Samples\ServiceDirectory;
2020

2121
// [START servicedirectory_create_namespace]
22-
use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient;
23-
use Google\Cloud\ServiceDirectory\V1beta1\PBNamespace;
22+
use Google\Cloud\ServiceDirectory\V1\Client\RegistrationServiceClient;
23+
use Google\Cloud\ServiceDirectory\V1\CreateNamespaceRequest;
24+
use Google\Cloud\ServiceDirectory\V1\PBNamespace;
2425

2526
/**
2627
* @param string $projectId Your Cloud project ID
@@ -37,7 +38,11 @@ function create_namespace(
3738

3839
// Run request.
3940
$locationName = RegistrationServiceClient::locationName($projectId, $locationId);
40-
$namespace = $client->createNamespace($locationName, $namespaceId, new PBNamespace());
41+
$createNamespaceRequest = (new CreateNamespaceRequest())
42+
->setParent($locationName)
43+
->setNamespaceId($namespaceId)
44+
->setNamespace(new PBNamespace());
45+
$namespace = $client->createNamespace($createNamespaceRequest);
4146

4247
// Print results.
4348
printf('Created Namespace: %s' . PHP_EOL, $namespace->getName());

servicedirectory/src/create_service.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
namespace Google\Cloud\Samples\ServiceDirectory;
2020

2121
// [START servicedirectory_create_service]
22-
use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient;
23-
use Google\Cloud\ServiceDirectory\V1beta1\Service;
22+
use Google\Cloud\ServiceDirectory\V1\Client\RegistrationServiceClient;
23+
use Google\Cloud\ServiceDirectory\V1\CreateServiceRequest;
24+
use Google\Cloud\ServiceDirectory\V1\Service;
2425

2526
/**
2627
* @param string $projectId Your Cloud project ID
@@ -39,7 +40,11 @@ function create_service(
3940

4041
// Run request.
4142
$namespaceName = RegistrationServiceClient::namespaceName($projectId, $locationId, $namespaceId);
42-
$service = $client->createService($namespaceName, $serviceId, new Service());
43+
$createServiceRequest = (new CreateServiceRequest())
44+
->setParent($namespaceName)
45+
->setServiceId($serviceId)
46+
->setService(new Service());
47+
$service = $client->createService($createServiceRequest);
4348

4449
// Print results.
4550
printf('Created Service: %s' . PHP_EOL, $service->getName());

servicedirectory/src/delete_endpoint.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
namespace Google\Cloud\Samples\ServiceDirectory;
2020

2121
// [START servicedirectory_delete_endpoint]
22-
use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient;
22+
use Google\Cloud\ServiceDirectory\V1\Client\RegistrationServiceClient;
23+
use Google\Cloud\ServiceDirectory\V1\DeleteEndpointRequest;
2324

2425
/**
2526
* @param string $projectId Your Cloud project ID
@@ -40,7 +41,9 @@ function delete_endpoint(
4041

4142
// Run request.
4243
$endpointName = RegistrationServiceClient::endpointName($projectId, $locationId, $namespaceId, $serviceId, $endpointId);
43-
$endpoint = $client->deleteEndpoint($endpointName);
44+
$deleteEndpointRequest = (new DeleteEndpointRequest())
45+
->setName($endpointName);
46+
$client->deleteEndpoint($deleteEndpointRequest);
4447

4548
// Print results.
4649
printf('Deleted Endpoint: %s' . PHP_EOL, $endpointName);

servicedirectory/src/delete_namespace.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
namespace Google\Cloud\Samples\ServiceDirectory;
2020

2121
// [START servicedirectory_delete_namespace]
22-
use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient;
22+
use Google\Cloud\ServiceDirectory\V1\Client\RegistrationServiceClient;
23+
use Google\Cloud\ServiceDirectory\V1\DeleteNamespaceRequest;
2324

2425
/**
2526
* @param string $projectId Your Cloud project ID
@@ -36,7 +37,9 @@ function delete_namespace(
3637

3738
// Run request.
3839
$namespaceName = RegistrationServiceClient::namespaceName($projectId, $locationId, $namespaceId);
39-
$client->deleteNamespace($namespaceName);
40+
$deleteNamespaceRequest = (new DeleteNamespaceRequest())
41+
->setName($namespaceName);
42+
$client->deleteNamespace($deleteNamespaceRequest);
4043

4144
// Print results.
4245
printf('Deleted Namespace: %s' . PHP_EOL, $namespaceName);

servicedirectory/src/delete_service.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
namespace Google\Cloud\Samples\ServiceDirectory;
2020

2121
// [START servicedirectory_delete_service]
22-
use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient;
22+
use Google\Cloud\ServiceDirectory\V1\Client\RegistrationServiceClient;
23+
use Google\Cloud\ServiceDirectory\V1\DeleteServiceRequest;
2324

2425
/**
2526
* @param string $projectId Your Cloud project ID
@@ -38,7 +39,9 @@ function delete_service(
3839

3940
// Run request.
4041
$serviceName = RegistrationServiceClient::serviceName($projectId, $locationId, $namespaceId, $serviceId);
41-
$client->deleteService($serviceName);
42+
$deleteServiceRequest = (new DeleteServiceRequest())
43+
->setName($serviceName);
44+
$client->deleteService($deleteServiceRequest);
4245

4346
// Print results.
4447
printf('Deleted Service: %s' . PHP_EOL, $serviceName);

servicedirectory/src/quickstart.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
list($_, $projectId, $locationId) = $argv;
2525

2626
// [START servicedirectory_quickstart]
27-
use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient;
27+
use Google\Cloud\ServiceDirectory\V1\Client\RegistrationServiceClient;
28+
use Google\Cloud\ServiceDirectory\V1\ListNamespacesRequest;
2829

2930
/** Uncomment and populate these variables in your code */
3031
// $projectId = '[YOUR_PROJECT_ID]';
@@ -35,7 +36,9 @@
3536

3637
// Run request.
3738
$locationName = RegistrationServiceClient::locationName($projectId, $locationId);
38-
$pagedResponse = $client->listNamespaces($locationName);
39+
$listNamespacesRequest = (new ListNamespacesRequest())
40+
->setParent($locationName);
41+
$pagedResponse = $client->listNamespaces($listNamespacesRequest);
3942

4043
// Iterate over each namespace and print its name.
4144
print('Namespaces: ' . PHP_EOL);

servicedirectory/src/resolve_service.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
namespace Google\Cloud\Samples\ServiceDirectory;
2020

2121
// [START servicedirectory_resolve_service]
22-
use Google\Cloud\ServiceDirectory\V1beta1\LookupServiceClient;
23-
use Google\Cloud\ServiceDirectory\V1beta1\Service;
22+
use Google\Cloud\ServiceDirectory\V1\Client\LookupServiceClient;
23+
use Google\Cloud\ServiceDirectory\V1\ResolveServiceRequest;
24+
use Google\Cloud\ServiceDirectory\V1\Service;
2425

2526
/**
2627
* @param string $projectId Your Cloud project ID
@@ -39,7 +40,9 @@ function resolve_service(
3940

4041
// Run request.
4142
$serviceName = LookupServiceClient::serviceName($projectId, $locationId, $namespaceId, $serviceId);
42-
$service = $client->resolveService($serviceName)->getService();
43+
$resolveServiceRequest = (new ResolveServiceRequest())
44+
->setName($serviceName);
45+
$service = $client->resolveService($resolveServiceRequest)->getService();
4346

4447
// Print results.
4548
printf('Resolved Service: %s' . PHP_EOL, $service->getName());

servicedirectory/test/servicedirectoryTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
*/
1818
namespace Google\Cloud\Samples\ServiceDirectory;
1919

20-
use Google\Cloud\ServiceDirectory\V1beta1\Endpoint;
21-
use Google\Cloud\ServiceDirectory\V1beta1\RegistrationServiceClient;
22-
use Google\Cloud\ServiceDirectory\V1beta1\Service;
20+
use Google\Cloud\ServiceDirectory\V1\Client\RegistrationServiceClient;
21+
use Google\Cloud\ServiceDirectory\V1\DeleteNamespaceRequest;
22+
use Google\Cloud\ServiceDirectory\V1\Endpoint;
23+
use Google\Cloud\ServiceDirectory\V1\ListNamespacesRequest;
24+
use Google\Cloud\ServiceDirectory\V1\Service;
2325
use Google\Cloud\TestUtils\TestTrait;
2426
use PHPUnit\Framework\TestCase;
2527

@@ -36,9 +38,13 @@ public static function tearDownAfterClass(): void
3638
{
3739
// Delete any namespaces created during the tests.
3840
$client = new RegistrationServiceClient();
39-
$pagedResponse = $client->listNamespaces(RegistrationServiceClient::locationName(self::$projectId, self::$locationId));
41+
$listNamespacesRequest = (new ListNamespacesRequest())
42+
->setParent(RegistrationServiceClient::locationName(self::$projectId, self::$locationId));
43+
$pagedResponse = $client->listNamespaces($listNamespacesRequest);
4044
foreach ($pagedResponse->iterateAllElements() as $namespace_pb) {
41-
$client->deleteNamespace($namespace_pb->getName());
45+
$deleteNamespaceRequest = (new DeleteNamespaceRequest())
46+
->setName($namespace_pb->getName());
47+
$client->deleteNamespace($deleteNamespaceRequest);
4248
}
4349
}
4450

0 commit comments

Comments
 (0)