Search in sources :

Example 96 with Operation

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();
}
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

Operation (com.google.api.services.compute.model.Operation)96 Compute (com.google.api.services.compute.Compute)40 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)37 IOException (java.io.IOException)37 GcpResourceException (com.sequenceiq.cloudbreak.cloud.gcp.GcpResourceException)23 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)21 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)17 Instance (com.google.api.services.compute.model.Instance)15 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)15 AutoScalingData (org.apache.druid.indexing.overlord.autoscaling.AutoScalingData)14 GcpContext (com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext)12 InstanceGroupManagersListManagedInstancesResponse (com.google.api.services.compute.model.InstanceGroupManagersListManagedInstancesResponse)10 Location (com.sequenceiq.cloudbreak.cloud.model.Location)10 HashMap (java.util.HashMap)10 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)9 Disk (com.google.api.services.compute.model.Disk)8 InstanceGroupManagersDeleteInstancesRequest (com.google.api.services.compute.model.InstanceGroupManagersDeleteInstancesRequest)8 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)8