Search in sources :

Example 1 with Get

use of com.google.api.services.compute.Compute.Images.Get in project cloudbreak by hortonworks.

the class GcpProvisionSetup method checkImageStatus.

@Override
public ImageStatusResult checkImageStatus(AuthenticatedContext authenticatedContext, CloudStack stack, com.sequenceiq.cloudbreak.cloud.model.Image image) {
    CloudCredential credential = authenticatedContext.getCloudCredential();
    String projectId = getProjectId(credential);
    String imageName = image.getImageName();
    try {
        Image gcpApiImage = new Image();
        gcpApiImage.setName(getImageName(imageName));
        Compute compute = buildCompute(credential);
        Get getImages = compute.images().get(projectId, gcpApiImage.getName());
        String status = getImages.execute().getStatus();
        LOGGER.info("Status of image {} copy: {}", gcpApiImage.getName(), status);
        if (READY.equals(status)) {
            return new ImageStatusResult(ImageStatus.CREATE_FINISHED, ImageStatusResult.COMPLETED);
        }
    } catch (IOException e) {
        LOGGER.warn("Failed to retrieve image copy status", e);
        return new ImageStatusResult(ImageStatus.CREATE_FAILED, 0);
    }
    return new ImageStatusResult(ImageStatus.IN_PROGRESS, ImageStatusResult.HALF);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) GcpStackUtil.buildCompute(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.buildCompute) Compute(com.google.api.services.compute.Compute) Get(com.google.api.services.compute.Compute.Images.Get) IOException(java.io.IOException) Image(com.google.api.services.compute.model.Image) ImageStatusResult(com.sequenceiq.cloudbreak.common.type.ImageStatusResult)

Aggregations

Compute (com.google.api.services.compute.Compute)1 Get (com.google.api.services.compute.Compute.Images.Get)1 Image (com.google.api.services.compute.model.Image)1 GcpStackUtil.buildCompute (com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.buildCompute)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 ImageStatusResult (com.sequenceiq.cloudbreak.common.type.ImageStatusResult)1 IOException (java.io.IOException)1