use of com.google.api.services.compute.Compute.Disks.Insert 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;
}
use of com.google.api.services.compute.Compute.Disks.Insert 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());
}
}
Aggregations