Skip to content

Commit 5239a01

Browse files
feat!: [Compute] add pagination for RPCs which missed them (#1101) (#8608)
* chore(php): set Compute migration_mode to NEW_SURFACE_ONLY (#1101) Source-Link: googleapis/googleapis@5caeec4 Source-Link: googleapis/googleapis-gen@acec3f3 Copy-Tag: eyJwIjoiQ29tcHV0ZS8uT3dsQm90LnlhbWwiLCJoIjoiYWNlYzNmMzZkNmM4NGJhMzdlNTY0M2ZiMDVmOTllMGFiZTQwOTcyMiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent f52c090 commit 5239a01

202 files changed

Lines changed: 2509 additions & 624 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Compute/samples/V1/InterconnectAttachmentGroupsClient/list.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
// [START compute_v1_generated_InterconnectAttachmentGroups_List_sync]
2626
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\PagedListResponse;
2728
use Google\Cloud\Compute\V1\Client\InterconnectAttachmentGroupsClient;
28-
use Google\Cloud\Compute\V1\InterconnectAttachmentGroupsListResponse;
2929
use Google\Cloud\Compute\V1\ListInterconnectAttachmentGroupsRequest;
3030

3131
/**
@@ -44,9 +44,12 @@ function list_sample(string $project): void
4444

4545
// Call the API and handle any network failures.
4646
try {
47-
/** @var InterconnectAttachmentGroupsListResponse $response */
47+
/** @var PagedListResponse $response */
4848
$response = $interconnectAttachmentGroupsClient->list($request);
49-
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
49+
50+
foreach ($response as $element) {
51+
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
52+
}
5053
} catch (ApiException $ex) {
5154
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
5255
}

Compute/samples/V1/InterconnectGroupsClient/list.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
// [START compute_v1_generated_InterconnectGroups_List_sync]
2626
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\PagedListResponse;
2728
use Google\Cloud\Compute\V1\Client\InterconnectGroupsClient;
28-
use Google\Cloud\Compute\V1\InterconnectGroupsListResponse;
2929
use Google\Cloud\Compute\V1\ListInterconnectGroupsRequest;
3030

3131
/**
@@ -44,9 +44,12 @@ function list_sample(string $project): void
4444

4545
// Call the API and handle any network failures.
4646
try {
47-
/** @var InterconnectGroupsListResponse $response */
47+
/** @var PagedListResponse $response */
4848
$response = $interconnectGroupsClient->list($request);
49-
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
49+
50+
foreach ($response as $element) {
51+
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
52+
}
5053
} catch (ApiException $ex) {
5154
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
5255
}

Compute/samples/V1/NetworkProfilesClient/list.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
// [START compute_v1_generated_NetworkProfiles_List_sync]
2626
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\PagedListResponse;
2728
use Google\Cloud\Compute\V1\Client\NetworkProfilesClient;
2829
use Google\Cloud\Compute\V1\ListNetworkProfilesRequest;
29-
use Google\Cloud\Compute\V1\NetworkProfilesListResponse;
3030

3131
/**
3232
* Retrieves a list of network profiles available to the specified project.
@@ -44,9 +44,12 @@ function list_sample(string $project): void
4444

4545
// Call the API and handle any network failures.
4646
try {
47-
/** @var NetworkProfilesListResponse $response */
47+
/** @var PagedListResponse $response */
4848
$response = $networkProfilesClient->list($request);
49-
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
49+
50+
foreach ($response as $element) {
51+
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
52+
}
5053
} catch (ApiException $ex) {
5154
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
5255
}

Compute/samples/V1/RoutersClient/list_bgp_routes.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
// [START compute_v1_generated_Routers_ListBgpRoutes_sync]
2626
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\PagedListResponse;
2728
use Google\Cloud\Compute\V1\Client\RoutersClient;
2829
use Google\Cloud\Compute\V1\ListBgpRoutesRoutersRequest;
29-
use Google\Cloud\Compute\V1\RoutersListBgpRoutes;
3030

3131
/**
3232
* Retrieves a list of router bgp routes available to the specified project.
@@ -48,9 +48,12 @@ function list_bgp_routes_sample(string $project, string $region, string $router)
4848

4949
// Call the API and handle any network failures.
5050
try {
51-
/** @var RoutersListBgpRoutes $response */
51+
/** @var PagedListResponse $response */
5252
$response = $routersClient->listBgpRoutes($request);
53-
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
53+
54+
foreach ($response as $element) {
55+
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
56+
}
5457
} catch (ApiException $ex) {
5558
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
5659
}

Compute/samples/V1/RoutersClient/list_route_policies.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
// [START compute_v1_generated_Routers_ListRoutePolicies_sync]
2626
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\PagedListResponse;
2728
use Google\Cloud\Compute\V1\Client\RoutersClient;
2829
use Google\Cloud\Compute\V1\ListRoutePoliciesRoutersRequest;
29-
use Google\Cloud\Compute\V1\RoutersListRoutePolicies;
3030

3131
/**
3232
* Retrieves a list of router route policy subresources available to the specified project.
@@ -48,9 +48,12 @@ function list_route_policies_sample(string $project, string $region, string $rou
4848

4949
// Call the API and handle any network failures.
5050
try {
51-
/** @var RoutersListRoutePolicies $response */
51+
/** @var PagedListResponse $response */
5252
$response = $routersClient->listRoutePolicies($request);
53-
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
53+
54+
foreach ($response as $element) {
55+
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
56+
}
5457
} catch (ApiException $ex) {
5558
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
5659
}

Compute/samples/V1/StoragePoolsClient/list.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
// [START compute_v1_generated_StoragePools_List_sync]
2626
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\PagedListResponse;
2728
use Google\Cloud\Compute\V1\Client\StoragePoolsClient;
2829
use Google\Cloud\Compute\V1\ListStoragePoolsRequest;
29-
use Google\Cloud\Compute\V1\StoragePoolList;
3030

3131
/**
3232
* Retrieves a list of storage pools contained within the specified zone.
@@ -46,9 +46,12 @@ function list_sample(string $project, string $zone): void
4646

4747
// Call the API and handle any network failures.
4848
try {
49-
/** @var StoragePoolList $response */
49+
/** @var PagedListResponse $response */
5050
$response = $storagePoolsClient->list($request);
51-
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
51+
52+
foreach ($response as $element) {
53+
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
54+
}
5255
} catch (ApiException $ex) {
5356
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
5457
}

Compute/samples/V1/StoragePoolsClient/list_disks.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
// [START compute_v1_generated_StoragePools_ListDisks_sync]
2626
use Google\ApiCore\ApiException;
27+
use Google\ApiCore\PagedListResponse;
2728
use Google\Cloud\Compute\V1\Client\StoragePoolsClient;
2829
use Google\Cloud\Compute\V1\ListDisksStoragePoolsRequest;
29-
use Google\Cloud\Compute\V1\StoragePoolListDisks;
3030

3131
/**
3232
* Lists the disks in a specified storage pool.
@@ -48,9 +48,12 @@ function list_disks_sample(string $project, string $storagePool, string $zone):
4848

4949
// Call the API and handle any network failures.
5050
try {
51-
/** @var StoragePoolListDisks $response */
51+
/** @var PagedListResponse $response */
5252
$response = $storagePoolsClient->listDisks($request);
53-
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
53+
54+
foreach ($response as $element) {
55+
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
56+
}
5457
} catch (ApiException $ex) {
5558
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
5659
}

Compute/src/V1/Client/AcceleratorTypesClient.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Google\ApiCore\ApiException;
2828
use Google\ApiCore\CredentialsWrapper;
2929
use Google\ApiCore\GapicClientTrait;
30+
use Google\ApiCore\Options\ClientOptions;
3031
use Google\ApiCore\PagedListResponse;
3132
use Google\ApiCore\RetrySettings;
3233
use Google\ApiCore\Transport\TransportInterface;
@@ -118,7 +119,7 @@ private static function supportedTransports()
118119
/**
119120
* Constructor.
120121
*
121-
* @param array $options {
122+
* @param array|ClientOptions $options {
122123
* Optional. Options for configuring the service API wrapper.
123124
*
124125
* @type string $apiEndpoint
@@ -171,11 +172,13 @@ private static function supportedTransports()
171172
* @type false|LoggerInterface $logger
172173
* A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the
173174
* 'GOOGLE_SDK_PHP_LOGGING' environment flag
175+
* @type string $universeDomain
176+
* The service domain for the client. Defaults to 'googleapis.com'.
174177
* }
175178
*
176179
* @throws ValidationException
177180
*/
178-
public function __construct(array $options = [])
181+
public function __construct(array|ClientOptions $options = [])
179182
{
180183
$clientOptions = $this->buildClientOptions($options);
181184
$this->setClientOptions($clientOptions);

Compute/src/V1/Client/AddressesClient.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Google\ApiCore\CredentialsWrapper;
2929
use Google\ApiCore\GapicClientTrait;
3030
use Google\ApiCore\OperationResponse;
31+
use Google\ApiCore\Options\ClientOptions;
3132
use Google\ApiCore\PagedListResponse;
3233
use Google\ApiCore\RetrySettings;
3334
use Google\ApiCore\Transport\TransportInterface;
@@ -40,7 +41,6 @@
4041
use Google\Cloud\Compute\V1\InsertAddressRequest;
4142
use Google\Cloud\Compute\V1\ListAddressesRequest;
4243
use Google\Cloud\Compute\V1\MoveAddressRequest;
43-
use Google\Cloud\Compute\V1\RegionOperationsClient;
4444
use Google\Cloud\Compute\V1\SetLabelsAddressRequest;
4545
use Google\Cloud\Compute\V1\TestIamPermissionsAddressRequest;
4646
use Google\Cloud\Compute\V1\TestPermissionsResponse;
@@ -109,7 +109,6 @@ private static function getClientDefaults()
109109
'restClientConfigPath' => __DIR__ . '/../resources/addresses_rest_client_config.php',
110110
],
111111
],
112-
'operationsClientClass' => RegionOperationsClient::class,
113112
];
114113
}
115114

@@ -172,16 +171,35 @@ private function getDefaultOperationDescriptor()
172171
*/
173172
public function resumeOperation($operationName, $methodName = null)
174173
{
175-
$options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : $this->getDefaultOperationDescriptor();
174+
$options = $this->descriptors[$methodName]['longRunning'] ?? $this->getDefaultOperationDescriptor();
176175
$operation = new OperationResponse($operationName, $this->getOperationsClient(), $options);
177176
$operation->reload();
178177
return $operation;
179178
}
180179

180+
/**
181+
* Create the default operation client for the service.
182+
*
183+
* @param array $options ClientOptions for the client.
184+
*
185+
* @return RegionOperationsClient
186+
*/
187+
private function createOperationsClient(array $options)
188+
{
189+
// Unset client-specific configuration options
190+
unset($options['serviceName'], $options['clientConfig'], $options['descriptorsConfigPath']);
191+
192+
if (isset($options['operationsClient'])) {
193+
return $options['operationsClient'];
194+
}
195+
196+
return new RegionOperationsClient($options);
197+
}
198+
181199
/**
182200
* Constructor.
183201
*
184-
* @param array $options {
202+
* @param array|ClientOptions $options {
185203
* Optional. Options for configuring the service API wrapper.
186204
*
187205
* @type string $apiEndpoint
@@ -234,11 +252,13 @@ public function resumeOperation($operationName, $methodName = null)
234252
* @type false|LoggerInterface $logger
235253
* A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the
236254
* 'GOOGLE_SDK_PHP_LOGGING' environment flag
255+
* @type string $universeDomain
256+
* The service domain for the client. Defaults to 'googleapis.com'.
237257
* }
238258
*
239259
* @throws ValidationException
240260
*/
241-
public function __construct(array $options = [])
261+
public function __construct(array|ClientOptions $options = [])
242262
{
243263
$clientOptions = $this->buildClientOptions($options);
244264
$this->setClientOptions($clientOptions);

Compute/src/V1/Client/AutoscalersClient.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Google\ApiCore\CredentialsWrapper;
2929
use Google\ApiCore\GapicClientTrait;
3030
use Google\ApiCore\OperationResponse;
31+
use Google\ApiCore\Options\ClientOptions;
3132
use Google\ApiCore\PagedListResponse;
3233
use Google\ApiCore\RetrySettings;
3334
use Google\ApiCore\Transport\TransportInterface;
@@ -41,7 +42,6 @@
4142
use Google\Cloud\Compute\V1\ListAutoscalersRequest;
4243
use Google\Cloud\Compute\V1\PatchAutoscalerRequest;
4344
use Google\Cloud\Compute\V1\UpdateAutoscalerRequest;
44-
use Google\Cloud\Compute\V1\ZoneOperationsClient;
4545
use GuzzleHttp\Promise\PromiseInterface;
4646
use Psr\Log\LoggerInterface;
4747

@@ -106,7 +106,6 @@ private static function getClientDefaults()
106106
'restClientConfigPath' => __DIR__ . '/../resources/autoscalers_rest_client_config.php',
107107
],
108108
],
109-
'operationsClientClass' => ZoneOperationsClient::class,
110109
];
111110
}
112111

@@ -169,16 +168,35 @@ private function getDefaultOperationDescriptor()
169168
*/
170169
public function resumeOperation($operationName, $methodName = null)
171170
{
172-
$options = isset($this->descriptors[$methodName]['longRunning']) ? $this->descriptors[$methodName]['longRunning'] : $this->getDefaultOperationDescriptor();
171+
$options = $this->descriptors[$methodName]['longRunning'] ?? $this->getDefaultOperationDescriptor();
173172
$operation = new OperationResponse($operationName, $this->getOperationsClient(), $options);
174173
$operation->reload();
175174
return $operation;
176175
}
177176

177+
/**
178+
* Create the default operation client for the service.
179+
*
180+
* @param array $options ClientOptions for the client.
181+
*
182+
* @return ZoneOperationsClient
183+
*/
184+
private function createOperationsClient(array $options)
185+
{
186+
// Unset client-specific configuration options
187+
unset($options['serviceName'], $options['clientConfig'], $options['descriptorsConfigPath']);
188+
189+
if (isset($options['operationsClient'])) {
190+
return $options['operationsClient'];
191+
}
192+
193+
return new ZoneOperationsClient($options);
194+
}
195+
178196
/**
179197
* Constructor.
180198
*
181-
* @param array $options {
199+
* @param array|ClientOptions $options {
182200
* Optional. Options for configuring the service API wrapper.
183201
*
184202
* @type string $apiEndpoint
@@ -231,11 +249,13 @@ public function resumeOperation($operationName, $methodName = null)
231249
* @type false|LoggerInterface $logger
232250
* A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the
233251
* 'GOOGLE_SDK_PHP_LOGGING' environment flag
252+
* @type string $universeDomain
253+
* The service domain for the client. Defaults to 'googleapis.com'.
234254
* }
235255
*
236256
* @throws ValidationException
237257
*/
238-
public function __construct(array $options = [])
258+
public function __construct(array|ClientOptions $options = [])
239259
{
240260
$clientOptions = $this->buildClientOptions($options);
241261
$this->setClientOptions($clientOptions);

0 commit comments

Comments
 (0)