@Test void testBuildWithVerySmallRootVolumeSize() throws Exception { int rootVolumeSize = Integer.MIN_VALUE; Group group = createGroup(rootVolumeSize); List<CloudResource> build = underTest.build(context, privateId, auth, group, buildableResource, cloudStack); assertNotNull(build); verify(disks).insert(anyString(), anyString(), argThat(argument -> argument.getSizeGb().equals((long) rootVolumeSize))); verify(insert, times(1)).execute(); }
@Override public List<CloudResource> build(GcpContext context, long privateId, AuthenticatedContext auth, Group group, List<CloudResource> buildableResources, CloudStack cloudStack) throws Exception { String projectId = context.getProjectId(); Location location = context.getLocation(); Disk disk = new Disk(); disk.setSizeGb((long) group.getRootVolumeSize()); disk.setName(buildableResources.get(0).getName()); disk.setKind(GcpDiskType.HDD.getUrl(projectId, location.getAvailabilityZone())); InstanceTemplate template = group.getReferenceInstanceTemplate(); gcpDiskEncryptionService.addEncryptionKeyToDisk(template, disk); Map<String, String> customTags = new HashMap<>(); customTags.putAll(cloudStack.getTags()); disk.setLabels(customTags); Insert insDisk = context.getCompute().disks().insert(projectId, location.getAvailabilityZone().value(), disk); insDisk.setSourceImage(GcpStackUtil.getAmbariImage(projectId, cloudStack.getImage().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()); } }
GcpDiskResourceBuilder extends AbstractGcpComputeBuilder { @Override public List<CloudResource> build(GcpContext context, long privateId, AuthenticatedContext auth, Group group, List<CloudResource> buildableResources, CloudStack cloudStack) throws Exception { String projectId = context.getProjectId(); Location location = context.getLocation(); Disk disk = new Disk(); disk.setSizeGb((long) group.getRootVolumeSize()); disk.setName(buildableResources.get(0).getName()); disk.setKind(GcpDiskType.HDD.getUrl(projectId, location.getAvailabilityZone())); InstanceTemplate template = group.getReferenceInstanceTemplate(); gcpDiskEncryptionService.addEncryptionKeyToDisk(template, disk); Map<String, String> customTags = new HashMap<>(); customTags.putAll(cloudStack.getTags()); disk.setLabels(customTags); Insert insDisk = context.getCompute().disks().insert(projectId, location.getAvailabilityZone().value(), disk); insDisk.setSourceImage(GcpStackUtil.getAmbariImage(projectId, cloudStack.getImage().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()); } } }
GcpDiskResourceBuilder extends AbstractGcpComputeBuilder { @Override public List<CloudResource> build(GcpContext context, long privateId, AuthenticatedContext auth, Group group, List<CloudResource> buildableResources, CloudStack cloudStack) throws Exception { String projectId = context.getProjectId(); Location location = context.getLocation(); Disk disk = new Disk(); disk.setSizeGb((long) group.getRootVolumeSize()); disk.setName(buildableResources.get(0).getName()); disk.setKind(GcpDiskType.HDD.getUrl(projectId, location.getAvailabilityZone())); InstanceTemplate template = group.getReferenceInstanceTemplate(); gcpDiskEncryptionService.addEncryptionKeyToDisk(template, disk); Map<String, String> customTags = new HashMap<>(); customTags.putAll(cloudStack.getTags()); disk.setLabels(customTags); Insert insDisk = context.getCompute().disks().insert(projectId, location.getAvailabilityZone().value(), disk); insDisk.setSourceImage(GcpStackUtil.getAmbariImage(projectId, cloudStack.getImage().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()); } }  }
GcpDiskResourceBuilder extends AbstractGcpComputeBuilder { @Override public List<CloudResource> build(GcpContext context, long privateId, AuthenticatedContext auth, Group group, List<CloudResource> buildableResources, CloudStack cloudStack) throws Exception { String projectId = context.getProjectId(); Location location = context.getLocation(); Disk disk = new Disk(); disk.setSizeGb((long) group.getRootVolumeSize()); disk.setName(buildableResources.get(0).getName()); disk.setKind(GcpDiskType.HDD.getUrl(projectId, location.getAvailabilityZone())); InstanceTemplate template = group.getReferenceInstanceTemplate(); gcpDiskEncryptionService.addEncryptionKeyToDisk(template, disk); Map<String, String> customTags = new HashMap<>(); customTags.putAll(cloudStack.getTags()); disk.setLabels(customTags); Insert insDisk = context.getCompute().disks().insert(projectId, location.getAvailabilityZone().value(), disk); insDisk.setSourceImage(GcpStackUtil.getAmbariImage(projectId, cloudStack.getImage().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()); } }  @Override List<CloudResource> create(GcpContext context, long privateId, AuthenticatedContext auth, Group group, Image image); @Override List<CloudResource> build(GcpContext context, long privateId, AuthenticatedContext auth, Group group,
            List<CloudResource> buildableResources, CloudStack cloudStack); @Override CloudResource delete(GcpContext context, AuthenticatedContext auth, CloudResource resource); @Override ResourceType resourceType(); @Override int order(); }
GcpDiskResourceBuilder extends AbstractGcpComputeBuilder { @Override public List<CloudResource> build(GcpContext context, long privateId, AuthenticatedContext auth, Group group, List<CloudResource> buildableResources, CloudStack cloudStack) throws Exception { String projectId = context.getProjectId(); Location location = context.getLocation(); Disk disk = new Disk(); disk.setSizeGb((long) group.getRootVolumeSize()); disk.setName(buildableResources.get(0).getName()); disk.setKind(GcpDiskType.HDD.getUrl(projectId, location.getAvailabilityZone())); InstanceTemplate template = group.getReferenceInstanceTemplate(); gcpDiskEncryptionService.addEncryptionKeyToDisk(template, disk); Map<String, String> customTags = new HashMap<>(); customTags.putAll(cloudStack.getTags()); disk.setLabels(customTags); Insert insDisk = context.getCompute().disks().insert(projectId, location.getAvailabilityZone().value(), disk); insDisk.setSourceImage(GcpStackUtil.getAmbariImage(projectId, cloudStack.getImage().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()); } }  @Override List<CloudResource> create(GcpContext context, long privateId, AuthenticatedContext auth, Group group, Image image); @Override List<CloudResource> build(GcpContext context, long privateId, AuthenticatedContext auth, Group group,
            List<CloudResource> buildableResources, CloudStack cloudStack); @Override CloudResource delete(GcpContext context, AuthenticatedContext auth, CloudResource resource); @Override ResourceType resourceType(); @Override int order();  }