use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class AzureVolumeResourceBuilderTest method buildTestWhenVolumeSetExistsAndRequestedAndNewDiskAndNoDiskEncryptionSetId.
@Test
void buildTestWhenVolumeSetExistsAndRequestedAndNewDiskAndNoDiskEncryptionSetId() throws Exception {
initAsyncTaskExecutor();
ArrayList<VolumeSetAttributes.Volume> volumes = new ArrayList<>();
volumes.add(new VolumeSetAttributes.Volume(VOLUME_ID, DEVICE, VOLUME_SIZE, VOLUME_TYPE, CloudVolumeUsageType.GENERAL));
CloudResource volumeSetResource = CloudResource.builder().type(ResourceType.AZURE_VOLUMESET).status(CommonStatus.REQUESTED).params(Map.of(CloudResource.ATTRIBUTES, new VolumeSetAttributes(AVAILABILITY_ZONE, true, FSTAB, volumes, VOLUME_SIZE, VOLUME_TYPE))).name(VOLUME_NAME).build();
when(azureClient.createManagedDisk(VOLUME_ID, VOLUME_SIZE, AzureDiskType.STANDARD_SSD_LRS, REGION, RESOURCE_GROUP, Map.of(), null)).thenReturn(disk);
List<CloudResource> result = underTest.build(context, cloudInstance, PRIVATE_ID, auth, group, List.of(volumeSetResource), cloudStack);
assertThat(result).isNotNull();
assertThat(result).hasSize(1);
verifyVolumeSetResource(result.get(0), DISK_ID, DEVICE_DEV_SDC);
}
use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class AzureVolumeResourceBuilderTest method buildTestWhenVolumeSetExistsAndCreated.
@Test
void buildTestWhenVolumeSetExistsAndCreated() throws Exception {
ArrayList<VolumeSetAttributes.Volume> volumes = new ArrayList<>();
volumes.add(new VolumeSetAttributes.Volume(VOLUME_ID, DEVICE, VOLUME_SIZE, VOLUME_TYPE, CloudVolumeUsageType.GENERAL));
CloudResource volumeSetResource = CloudResource.builder().type(ResourceType.AZURE_VOLUMESET).status(CommonStatus.CREATED).params(Map.of(CloudResource.ATTRIBUTES, new VolumeSetAttributes(AVAILABILITY_ZONE, true, FSTAB, volumes, VOLUME_SIZE, VOLUME_TYPE))).name(VOLUME_NAME).build();
List<CloudResource> result = underTest.build(context, cloudInstance, PRIVATE_ID, auth, group, List.of(volumeSetResource), cloudStack);
verify(azureClient, never()).createManagedDisk(anyString(), anyInt(), any(AzureDiskType.class), anyString(), anyString(), anyMap(), anyString());
assertThat(result).isNotNull();
assertThat(result).hasSize(1);
verifyVolumeSetResource(result.get(0), VOLUME_ID, DEVICE);
}
use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class GcpAttachedDiskResourceBuilder method delete.
@Override
public CloudResource delete(GcpContext context, AuthenticatedContext auth, CloudResource resource) throws Exception {
VolumeSetAttributes volumeSetAttributes = resource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class);
if (!volumeSetAttributes.getDeleteOnTermination()) {
resource.setStatus(CommonStatus.DETACHED);
volumeSetAttributes.setDeleteOnTermination(Boolean.TRUE);
resource.putParameter(CloudResource.ATTRIBUTES, volumeSetAttributes);
resourceNotifier.notifyUpdate(resource, auth.getCloudContext());
throw new InterruptedException("Resource will be preserved for later reattachment.");
}
List<String> operations = new ArrayList<>();
List<String> syncedOperations = Collections.synchronizedList(operations);
Collection<Future<Void>> futures = new ArrayList<>();
for (VolumeSetAttributes.Volume volume : volumeSetAttributes.getVolumes()) {
Future<Void> submit = intermediateBuilderExecutor.submit(() -> {
try {
LOGGER.info("Going to delete volume [id: {}] from project [id: {}] in the following availability zone: {}", volume.getId(), context.getProjectId(), volumeSetAttributes.getAvailabilityZone());
Operation operation = context.getCompute().disks().delete(context.getProjectId(), volumeSetAttributes.getAvailabilityZone(), volume.getId()).execute();
syncedOperations.add(operation.getName());
if (operation.getHttpErrorStatusCode() != null) {
String message = String.format("%s [code: %d, message: %s, error: %s]", VOLUME_DELETION_FAILED_BASE_MSG, operation.getHttpErrorStatusCode(), operation.getHttpErrorMessage(), operation.getError());
LOGGER.warn(message);
throw new GcpResourceException(operation.getHttpErrorMessage(), resourceType(), volume.getId());
}
} catch (TokenResponseException e) {
logVolumeDeletionProblem(e);
gcpStackUtil.getMissingServiceAccountKeyError(e, context.getProjectId());
} catch (GoogleJsonResponseException e) {
logVolumeDeletionProblem(e);
exceptionHandler(e, resource.getName(), resourceType());
} catch (IOException e) {
logVolumeDeletionProblem(e);
throw new GcpResourceException(e.getMessage(), e);
}
return null;
});
futures.add(submit);
}
for (Future<Void> future : futures) {
future.get();
}
resource.putParameter(OPERATION_ID, operations);
return resource;
}
use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class GcpDiskResourceBuilder method delete.
@Override
public CloudResource delete(GcpContext context, AuthenticatedContext auth, CloudResource resource) throws Exception {
String resourceName = resource.getName();
VolumeSetAttributes volumeSetAttributes = resource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class);
String zone;
if (volumeSetAttributes != null && volumeSetAttributes.getAvailabilityZone() != null) {
zone = volumeSetAttributes.getAvailabilityZone();
} else {
zone = context.getLocation().getAvailabilityZone().value();
}
try {
LOGGER.info("Creating operation to delete disk [name: {}] in project [id: {}] in the following availability zone: {}", resourceName, context.getProjectId(), zone);
Operation operation = context.getCompute().disks().delete(context.getProjectId(), zone, resourceName).execute();
return createOperationAwareCloudResource(resource, operation);
} catch (GoogleJsonResponseException e) {
exceptionHandler(e, resourceName, resourceType());
}
return null;
}
use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class AwsAttachmentResourceBuilder method build.
@Override
public List<CloudResource> build(AwsContext context, CloudInstance cloudInstance, long privateId, AuthenticatedContext auth, Group group, List<CloudResource> buildableResource, CloudStack cloudStack) throws Exception {
LOGGER.debug("Attach volumes to instance");
CloudResource instance = buildableResource.stream().filter(cloudResource -> cloudResource.getType().equals(ResourceType.AWS_INSTANCE)).findFirst().orElseThrow(() -> new AwsResourceException("Instance resource not found"));
Optional<CloudResource> volumeSetOpt = buildableResource.stream().filter(cloudResource -> cloudResource.getType().equals(ResourceType.AWS_VOLUMESET)).findFirst();
if (volumeSetOpt.isEmpty()) {
LOGGER.debug("No volumes to attach");
return List.of();
}
CloudResource volumeSet = volumeSetOpt.get();
AmazonEc2Client client = getAmazonEc2Client(auth);
VolumeSetAttributes volumeSetAttributes = volumeSet.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class);
LOGGER.debug("Creating attach volume requests and submitting to executor for stack '{}', group '{}'", auth.getCloudContext().getName(), group.getName());
List<Future<?>> futures = volumeSetAttributes.getVolumes().stream().filter(volume -> !StringUtils.equals(AwsDiskType.Ephemeral.value(), volume.getType())).map(volume -> new AttachVolumeRequest().withInstanceId(instance.getInstanceId()).withVolumeId(volume.getId()).withDevice(volume.getDevice())).map(request -> intermediateBuilderExecutor.submit(() -> client.attachVolume(request))).collect(Collectors.toList());
LOGGER.debug("Waiting for attach volumes request");
for (Future<?> future : futures) {
try {
future.get();
} catch (AmazonClientException e) {
LOGGER.error("Attach was unsuccesful. Group: {}, Volume: {} Instance: {}, AWS error: {}", group.getName(), instance.getName(), volumeSet.getName(), e.getMessage());
throw e;
}
}
LOGGER.debug("Attach volume requests sent");
volumeSet.setInstanceId(instance.getInstanceId());
volumeSet.setStatus(CommonStatus.CREATED);
return List.of(volumeSet);
}
Aggregations