use of com.google.api.services.compute.model.Operation in project terra-resource-buffer by DataBiosphere.
the class CreateRouteStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) throws RetryException {
if (!usePrivateGoogleAccess(gcpProjectConfig)) {
return StepResult.getStepResultSuccess();
}
String projectId = flightContext.getWorkingMap().get(GOOGLE_PROJECT_ID, String.class);
try {
// Network is already created and checked in previous step so here won't be empty.
// If we got NPE, that means something went wrong with GCP, fine to just throw NPE here.
Network network = getResource(() -> computeCow.networks().get(projectId, NETWORK_NAME).execute(), 404).get();
Route route = new Route().setName(ROUTE_NAME).setDestRange(RESTRICTED_GOOGLE_IP_ADDRESS).setNetwork(network.getSelfLink()).setNextHopGateway("projects/" + projectId + DEFAULT_GATEWAY);
Optional<Operation> insertOperation = createResourceAndIgnoreConflict(() -> computeCow.routes().insert(projectId, route).execute());
if (insertOperation.isPresent()) {
OperationCow<?> operation = computeCow.globalOperations().operationCow(projectId, insertOperation.get());
pollUntilSuccess(operation, Duration.ofSeconds(3), Duration.ofMinutes(5));
}
} catch (IOException | InterruptedException e) {
logger.info("Error when creating route", e);
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
return StepResult.getStepResultSuccess();
}
Aggregations