use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes.Volume in project cloudbreak by hortonworks.
the class AwsVolumeResourceBuilder method checkResources.
@Override
protected List<CloudResourceStatus> checkResources(ResourceType type, AwsContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
AmazonEc2Client client = getAmazonEC2Client(auth);
Pair<List<String>, List<CloudResource>> volumes = volumeResourceCollector.getVolumeIdsByVolumeResources(resources, resourceType(), volumeSetAttributes());
DescribeVolumesRequest describeVolumesRequest = new DescribeVolumesRequest(volumes.getFirst());
LOGGER.debug("Going to describe volume(s) with id(s): [{}]", String.join(",", describeVolumesRequest.getVolumeIds()));
AtomicReference<ResourceStatus> volumeSetStatus = new AtomicReference<>();
try {
DescribeVolumesResult result = client.describeVolumes(describeVolumesRequest);
volumeSetStatus.set(getResourceStatus(result));
} catch (AmazonEC2Exception e) {
if (!"InvalidVolume.NotFound".equals(e.getErrorCode())) {
throw e;
}
LOGGER.info("The volume doesn't need to be deleted as it does not exist on the provider side. Reason: {}", e.getMessage());
volumeSetStatus.set(DELETED);
}
LOGGER.debug("[{}] volume set status is {}", String.join(",", volumes.getFirst()), volumeSetStatus);
return volumes.getSecond().stream().map(resource -> new CloudResourceStatus(resource, volumeSetStatus.get())).collect(Collectors.toList());
}
use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes.Volume in project cloudbreak by hortonworks.
the class AwsVolumeResourceBuilder method build.
@Override
public List<CloudResource> build(AwsContext context, CloudInstance instance, long privateId, AuthenticatedContext auth, Group group, List<CloudResource> buildableResource, CloudStack cloudStack) throws Exception {
LOGGER.debug("Create volumes on provider: {}", buildableResource.stream().map(CloudResource::getName).collect(Collectors.toList()));
AmazonEc2Client client = getAmazonEC2Client(auth);
Map<String, List<Volume>> volumeSetMap = Collections.synchronizedMap(new HashMap<>());
List<Future<?>> futures = new ArrayList<>();
boolean encryptedVolume = isEncryptedVolumeRequested(group);
String volumeEncryptionKey = getVolumeEncryptionKey(group, encryptedVolume);
TagSpecification tagSpecification = new TagSpecification().withResourceType(com.amazonaws.services.ec2.model.ResourceType.Volume).withTags(awsTaggingService.prepareEc2Tags(cloudStack.getTags()));
List<CloudResource> requestedResources = buildableResource.stream().filter(cloudResource -> CommonStatus.REQUESTED.equals(cloudResource.getStatus())).collect(Collectors.toList());
Long ephemeralCount = getEphemeralCount(group);
LOGGER.debug("Start creating data volumes for stack: '{}' group: '{}'", auth.getCloudContext().getName(), group.getName());
for (CloudResource resource : requestedResources) {
volumeSetMap.put(resource.getName(), Collections.synchronizedList(new ArrayList<>()));
VolumeSetAttributes volumeSet = resource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class);
DeviceNameGenerator generator = new DeviceNameGenerator(DEVICE_NAME_TEMPLATE, ephemeralCount.intValue());
futures.addAll(volumeSet.getVolumes().stream().map(createVolumeRequest(encryptedVolume, volumeEncryptionKey, tagSpecification, volumeSet)).map(requestWithUsage -> intermediateBuilderExecutor.submit(() -> {
CreateVolumeRequest request = requestWithUsage.getFirst();
CreateVolumeResult result = client.createVolume(request);
String volumeId = result.getVolume().getVolumeId();
Volume volume = new Volume(volumeId, generator.next(), request.getSize(), request.getVolumeType(), requestWithUsage.getSecond());
volumeSetMap.get(resource.getName()).add(volume);
})).collect(Collectors.toList()));
}
LOGGER.debug("Waiting for volumes creation requests");
for (Future<?> future : futures) {
future.get();
}
LOGGER.debug("Volume creation requests sent");
String defaultAvailabilityZone = auth.getCloudContext().getLocation().getAvailabilityZone().value();
return requestedResources.stream().peek(resource -> {
List<Volume> volumes = volumeSetMap.get(resource.getName());
if (!CollectionUtils.isEmpty(volumes)) {
resource.getParameter(CloudResource.ATTRIBUTES, VolumeSetAttributes.class).setVolumes(volumes);
}
}).map(copyResourceWithCreatedStatus(defaultAvailabilityZone)).collect(Collectors.toList());
}
use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes.Volume in project cloudbreak by hortonworks.
the class AwsVolumeResourceBuilder method create.
@Override
public List<CloudResource> create(AwsContext context, CloudInstance instance, long privateId, AuthenticatedContext auth, Group group, Image image) {
LOGGER.debug("Create volume resources for {} in group: {}", instance.getInstanceId(), group.getName());
InstanceTemplate template = group.getReferenceInstanceTemplate();
if (CollectionUtils.isEmpty(template.getVolumes())) {
LOGGER.debug("No volume requested in group: {}", group.getName());
return List.of();
}
List<CloudResource> computeResources = context.getComputeResources(privateId);
Optional<CloudResource> reattachableVolumeSet = computeResources.stream().filter(resource -> ResourceType.AWS_VOLUMESET.equals(resource.getType())).findFirst();
if (reattachableVolumeSet.isEmpty()) {
reattachableVolumeSet = fetchCloudResourceFromDBIfAvailable(privateId, auth, group, computeResources);
} else {
LOGGER.debug("Reattachable volumeset found: {}", reattachableVolumeSet.get());
}
String subnetId = getSubnetId(context, instance);
Optional<String> availabilityZone = getAvailabilityZone(context, instance);
return List.of(reattachableVolumeSet.orElseGet(createVolumeSet(privateId, auth, group, subnetId, availabilityZone)));
}
Aggregations