Search in sources :

Example 1 with Disk

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

the class DiskInfo method toPb.

Disk toPb() {
    Disk diskPb = configuration.toPb();
    if (generatedId != null) {
        diskPb.setId(new BigInteger(generatedId));
    }
    if (creationTimestamp != null) {
        diskPb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
    }
    diskPb.setZone(diskId.getZoneId().getSelfLink());
    if (creationStatus != null) {
        diskPb.setStatus(creationStatus.toString());
    }
    diskPb.setName(diskId.getDisk());
    diskPb.setDescription(description);
    diskPb.setSelfLink(diskId.getSelfLink());
    if (licenses != null) {
        diskPb.setLicenses(Lists.transform(licenses, LicenseId.TO_URL_FUNCTION));
    }
    if (attachedInstances != null) {
        diskPb.setUsers(Lists.transform(attachedInstances, InstanceId.TO_URL_FUNCTION));
    }
    if (lastAttachTimestamp != null) {
        diskPb.setLastAttachTimestamp(TIMESTAMP_FORMATTER.print(lastAttachTimestamp));
    }
    if (lastDetachTimestamp != null) {
        diskPb.setLastDetachTimestamp(TIMESTAMP_FORMATTER.print(lastDetachTimestamp));
    }
    return diskPb;
}
Also used : BigInteger(java.math.BigInteger) Disk(com.google.api.services.compute.model.Disk)

Example 2 with Disk

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

the class HttpComputeRpc method listDisks.

@Override
public Tuple<String, Iterable<Disk>> listDisks(Map<Option, ?> options) {
    try {
        DiskAggregatedList aggregatedList = compute.disks().aggregatedList(this.options.getProjectId()).setFilter(Option.FILTER.getString(options)).setMaxResults(Option.MAX_RESULTS.getLong(options)).setPageToken(Option.PAGE_TOKEN.getString(options)).execute();
        ImmutableList.Builder<Disk> builder = ImmutableList.builder();
        Map<String, DisksScopedList> scopedList = aggregatedList.getItems();
        if (scopedList != null) {
            for (DisksScopedList disksScopedList : scopedList.values()) {
                if (disksScopedList.getDisks() != null) {
                    builder.addAll(disksScopedList.getDisks());
                }
            }
        }
        return Tuple.<String, Iterable<Disk>>of(aggregatedList.getNextPageToken(), builder.build());
    } catch (IOException ex) {
        throw translate(ex);
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) DiskAggregatedList(com.google.api.services.compute.model.DiskAggregatedList) IOException(java.io.IOException) AttachedDisk(com.google.api.services.compute.model.AttachedDisk) Disk(com.google.api.services.compute.model.Disk) DisksScopedList(com.google.api.services.compute.model.DisksScopedList)

Example 3 with Disk

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

the class GcpAttachedDiskResourceBuilder method build.

@Override
public List<CloudResource> build(GcpContext context, long privateId, AuthenticatedContext auth, Group group, Image image, List<CloudResource> buildableResource, Map<String, String> tags) throws Exception {
    CloudInstance instance = group.getReferenceInstanceConfiguration();
    InstanceTemplate template = instance.getTemplate();
    Volume volume = template.getVolumes().get(0);
    List<CloudResource> resources = new ArrayList<>();
    List<CloudResource> syncedResources = Collections.synchronizedList(resources);
    String projectId = context.getProjectId();
    Location location = context.getLocation();
    Compute compute = context.getCompute();
    Collection<Future<Void>> futures = new ArrayList<>();
    for (CloudResource cloudResource : buildableResource) {
        Disk disk = createDisk(volume, projectId, location.getAvailabilityZone(), cloudResource.getName(), tags);
        Future<Void> submit = intermediateBuilderExecutor.submit(() -> {
            Insert insDisk = compute.disks().insert(projectId, location.getAvailabilityZone().value(), disk);
            try {
                Operation operation = insDisk.execute();
                syncedResources.add(createOperationAwareCloudResource(cloudResource, operation));
                if (operation.getHttpErrorStatusCode() != null) {
                    throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), cloudResource.getName());
                }
            } catch (GoogleJsonResponseException e) {
                throw new GcpResourceException(checkException(e), resourceType(), cloudResource.getName());
            }
            return null;
        });
        futures.add(submit);
    }
    for (Future<Void> future : futures) {
        future.get();
    }
    return resources;
}
Also used : ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Operation(com.google.api.services.compute.model.Operation) Insert(com.google.api.services.compute.Compute.Disks.Insert) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) Compute(com.google.api.services.compute.Compute) Future(java.util.concurrent.Future) GcpResourceException(com.sequenceiq.cloudbreak.cloud.gcp.GcpResourceException) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Disk(com.google.api.services.compute.model.Disk) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 4 with Disk

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

the class GcpAttachedDiskResourceBuilder method createDisk.

private Disk createDisk(Volume volume, String projectId, AvailabilityZone availabilityZone, String resourceName, Map<String, String> tags) {
    Disk disk = new Disk();
    disk.setSizeGb((long) volume.getSize());
    disk.setName(resourceName);
    disk.setType(GcpDiskType.getUrl(projectId, availabilityZone, volume.getType()));
    Map<String, String> customTags = new HashMap<>();
    customTags.putAll(tags);
    customTags.putAll(defaultCostTaggingService.prepareDiskTagging());
    disk.setLabels(customTags);
    return disk;
}
Also used : HashMap(java.util.HashMap) Disk(com.google.api.services.compute.model.Disk)

Example 5 with Disk

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

the class GcpDiskResourceBuilder method build.

@Override
public List<CloudResource> build(GcpContext context, long privateId, AuthenticatedContext auth, Group group, Image image, List<CloudResource> buildableResources, Map<String, String> tags) throws Exception {
    String projectId = context.getProjectId();
    Location location = context.getLocation();
    Disk disk = new Disk();
    disk.setSizeGb(DEFAULT_ROOT_DISK_SIZE);
    disk.setName(buildableResources.get(0).getName());
    disk.setKind(GcpDiskType.HDD.getUrl(projectId, location.getAvailabilityZone()));
    Map<String, String> customTags = new HashMap<>();
    customTags.putAll(tags);
    customTags.putAll(defaultCostTaggingService.prepareDiskTagging());
    disk.setLabels(customTags);
    Insert insDisk = context.getCompute().disks().insert(projectId, location.getAvailabilityZone().value(), disk);
    insDisk.setSourceImage(GcpStackUtil.getAmbariImage(projectId, image.getImageName()));
    try {
        Operation operation = insDisk.execute();
        if (operation.getHttpErrorStatusCode() != null) {
            throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), buildableResources.get(0).getName());
        }
        return Collections.singletonList(createOperationAwareCloudResource(buildableResources.get(0), operation));
    } catch (GoogleJsonResponseException e) {
        throw new GcpResourceException(checkException(e), resourceType(), buildableResources.get(0).getName());
    }
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) HashMap(java.util.HashMap) GcpResourceException(com.sequenceiq.cloudbreak.cloud.gcp.GcpResourceException) Operation(com.google.api.services.compute.model.Operation) Insert(com.google.api.services.compute.Compute.Disks.Insert) Disk(com.google.api.services.compute.model.Disk) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

Disk (com.google.api.services.compute.model.Disk)8 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)2 Insert (com.google.api.services.compute.Compute.Disks.Insert)2 AttachedDisk (com.google.api.services.compute.model.AttachedDisk)2 Operation (com.google.api.services.compute.model.Operation)2 GcpResourceException (com.sequenceiq.cloudbreak.cloud.gcp.GcpResourceException)2 Location (com.sequenceiq.cloudbreak.cloud.model.Location)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Compute (com.google.api.services.compute.Compute)1 DiskAggregatedList (com.google.api.services.compute.model.DiskAggregatedList)1 DiskList (com.google.api.services.compute.model.DiskList)1 DisksScopedList (com.google.api.services.compute.model.DisksScopedList)1 ImmutableList (com.google.common.collect.ImmutableList)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)1 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1