Search in sources :

Example 1 with Image

use of com.google.api.services.compute.model.Image in project google-cloud-java by GoogleCloudPlatform.

the class StorageImageConfiguration method toPb.

@Override
Image toPb() {
    Image.RawDisk rawDiskPb = new Image.RawDisk();
    rawDiskPb.setSource(source);
    rawDiskPb.setSha1Checksum(sha1);
    if (containerType != null) {
        rawDiskPb.setContainerType(containerType.name());
    }
    Image imagePb = super.toPb();
    return imagePb.setRawDisk(rawDiskPb);
}
Also used : Image(com.google.api.services.compute.model.Image)

Example 2 with Image

use of com.google.api.services.compute.model.Image in project google-cloud-java by GoogleCloudPlatform.

the class ImageInfo method toPb.

Image toPb() {
    Image imagePb = configuration.toPb();
    if (generatedId != null) {
        imagePb.setId(new BigInteger(generatedId));
    }
    if (creationTimestamp != null) {
        imagePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
    }
    imagePb.setName(imageId.getImage());
    imagePb.setDescription(description);
    imagePb.setSelfLink(imageId.getSelfLink());
    if (status != null) {
        imagePb.setStatus(status.name());
    }
    imagePb.setDiskSizeGb(diskSizeGb);
    if (licenses != null) {
        imagePb.setLicenses(Lists.transform(licenses, LicenseId.TO_URL_FUNCTION));
    }
    if (deprecationStatus != null) {
        imagePb.setDeprecated(deprecationStatus.toPb());
    }
    return imagePb;
}
Also used : BigInteger(java.math.BigInteger) Image(com.google.api.services.compute.model.Image)

Example 3 with Image

use of com.google.api.services.compute.model.Image 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)

Example 4 with Image

use of com.google.api.services.compute.model.Image in project cloudbreak by hortonworks.

the class GcpProvisionSetup method prepareImage.

@Override
public void prepareImage(AuthenticatedContext authenticatedContext, CloudStack stack, com.sequenceiq.cloudbreak.cloud.model.Image image) {
    CloudCredential credential = authenticatedContext.getCloudCredential();
    CloudContext cloudContext = authenticatedContext.getCloudContext();
    try {
        String projectId = getProjectId(credential);
        String imageName = image.getImageName();
        Compute compute = buildCompute(credential);
        ImageList list = compute.images().list(projectId).execute();
        if (!containsSpecificImage(list, imageName)) {
            Storage storage = buildStorage(credential, cloudContext.getName());
            Bucket bucket = new Bucket();
            bucket.setName(String.format("%s-%s-%d", projectId, cloudContext.getName(), cloudContext.getId()));
            bucket.setStorageClass("STANDARD");
            try {
                Buckets.Insert ins = storage.buckets().insert(projectId, bucket);
                ins.execute();
            } catch (GoogleJsonResponseException ex) {
                if (ex.getStatusCode() != HttpStatus.SC_CONFLICT) {
                    throw ex;
                }
            }
            String tarName = getTarName(imageName);
            Copy copy = storage.objects().copy(getBucket(imageName), tarName, bucket.getName(), tarName, new StorageObject());
            copy.execute();
            Image gcpApiImage = new Image();
            gcpApiImage.setName(getImageName(imageName));
            RawDisk rawDisk = new RawDisk();
            rawDisk.setSource(String.format("http://storage.googleapis.com/%s/%s", bucket.getName(), tarName));
            gcpApiImage.setRawDisk(rawDisk);
            Insert ins = compute.images().insert(projectId, gcpApiImage);
            ins.execute();
        }
    } catch (Exception e) {
        Long stackId = cloudContext.getId();
        String msg = String.format("Error occurred on %s stack during the setup: %s", stackId, e.getMessage());
        LOGGER.error(msg, e);
        throw new CloudConnectorException(msg, e);
    }
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Image(com.google.api.services.compute.model.Image) Insert(com.google.api.services.compute.Compute.Images.Insert) Buckets(com.google.api.services.storage.Storage.Buckets) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException) ImageList(com.google.api.services.compute.model.ImageList) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Storage(com.google.api.services.storage.Storage) GcpStackUtil.buildStorage(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.buildStorage) GcpStackUtil.getBucket(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.getBucket) Bucket(com.google.api.services.storage.model.Bucket) Copy(com.google.api.services.storage.Storage.Objects.Copy) GcpStackUtil.buildCompute(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.buildCompute) Compute(com.google.api.services.compute.Compute) RawDisk(com.google.api.services.compute.model.Image.RawDisk)

Example 5 with Image

use of com.google.api.services.compute.model.Image in project platformlayer by platformlayer.

the class GoogleComputeClient method listImages.

private Iterable<Image> listImages(String projectId) throws OpsException {
    List<Image> ret = Lists.newArrayList();
    ImageList imageList;
    try {
        log.debug("Listing images in project " + projectId);
        imageList = compute.images().list(projectId).execute();
    } catch (IOException e) {
        throw new OpsException("Error listing images", e);
    }
    if (imageList.getItems() != null) {
        ret.addAll(imageList.getItems());
    }
    return ret;
}
Also used : OpsException(org.platformlayer.ops.OpsException) IOException(java.io.IOException) Image(com.google.api.services.compute.model.Image) ImageList(com.google.api.services.compute.model.ImageList)

Aggregations

Image (com.google.api.services.compute.model.Image)9 IOException (java.io.IOException)5 ImageList (com.google.api.services.compute.model.ImageList)3 Compute (com.google.api.services.compute.Compute)2 GcpStackUtil.buildCompute (com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil.buildCompute)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 OpsException (org.platformlayer.ops.OpsException)2 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)1 Get (com.google.api.services.compute.Compute.Images.Get)1 Insert (com.google.api.services.compute.Compute.Images.Insert)1 AccessConfig (com.google.api.services.compute.model.AccessConfig)1 RawDisk (com.google.api.services.compute.model.Image.RawDisk)1 Instance (com.google.api.services.compute.model.Instance)1 MachineType (com.google.api.services.compute.model.MachineType)1 Metadata (com.google.api.services.compute.model.Metadata)1 Items (com.google.api.services.compute.model.Metadata.Items)1 NetworkInterface (com.google.api.services.compute.model.NetworkInterface)1 Operation (com.google.api.services.compute.model.Operation)1 Storage (com.google.api.services.storage.Storage)1 Buckets (com.google.api.services.storage.Storage.Buckets)1