private static Page<Instance> listInstances(
final ComputeOptions serviceOptions, final Map<ComputeRpc.Option, ?> optionsMap) {
try {
Tuple<String, Iterable<com.google.api.services.compute.model.Instance>> result =
runWithRetries(
new Callable<
Tuple<String, Iterable<com.google.api.services.compute.model.Instance>>>() {
@Override
public Tuple<String, Iterable<com.google.api.services.compute.model.Instance>>
call() {
return serviceOptions.getComputeRpcV1().listInstances(optionsMap);
}
},
serviceOptions.getRetrySettings(),
EXCEPTION_HANDLER,
serviceOptions.getClock());
String cursor = result.x();
Iterable<Instance> instances =
Iterables.transform(
result.y() == null
? ImmutableList.<com.google.api.services.compute.model.Instance>of()
: result.y(),
instanceFromPb(serviceOptions));
return new PageImpl<>(
new AggregatedInstancePageFetcher(serviceOptions, cursor, optionsMap), cursor, instances);
} catch (RetryHelper.RetryHelperException e) {
throw ComputeException.translateAndThrow(e);
}
}