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