Search in sources :

Example 1 with Route

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());
}
Also used : Network(com.google.api.services.compute.model.Network) Route(com.google.api.services.compute.model.Route)

Example 2 with Route

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();
}
Also used : Network(com.google.api.services.compute.model.Network) Operation(com.google.api.services.compute.model.Operation) IOException(java.io.IOException) StepResult(bio.terra.stairway.StepResult) Route(com.google.api.services.compute.model.Route)

Aggregations

Network (com.google.api.services.compute.model.Network)2 Route (com.google.api.services.compute.model.Route)2 StepResult (bio.terra.stairway.StepResult)1 Operation (com.google.api.services.compute.model.Operation)1 IOException (java.io.IOException)1