use of com.google.api.services.compute.model.Route in project terra-resource-buffer by DataBiosphere.
the class CreateProjectFlightIntegrationTest method assertRouteExists.
private void assertRouteExists(Project project) throws Exception {
String projectId = project.getProjectId();
Network network = computeCow.networks().get(project.getProjectId(), NETWORK_NAME).execute();
Route route = computeCow.routes().get(projectId, ROUTE_NAME).execute();
assertEquals(RESTRICTED_GOOGLE_IP_ADDRESS, route.getDestRange());
assertEquals("https://www.googleapis.com/compute/v1/projects/" + projectId + DEFAULT_GATEWAY, route.getNextHopGateway());
assertEquals(network.getSelfLink(), route.getNetwork());
}
use of com.google.api.services.compute.model.Route 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