use of com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext in project cloudbreak by hortonworks.
the class AwsEfsResourceBuilder 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 EFS on provider" + buildableResource.stream().map(CloudResource::getName).collect(Collectors.toList()));
AmazonEfsClient client = getAmazonEfsClient(auth);
Map<String, CloudEfsAttributes> efsSetMap = Collections.synchronizedMap(new HashMap<>());
List<Future<?>> futures = new ArrayList<>();
List<CloudResource> requestedResources = buildableResource.stream().filter(cloudResource -> CommonStatus.REQUESTED.equals(cloudResource.getStatus())).collect(Collectors.toList());
LOGGER.debug("Start creating EFS for stack: '{}' group: '{}'", auth.getCloudContext().getName(), group.getName());
futures.addAll(requestedResources.stream().map(requestedResource -> creatEfsRequest(requestedResource, cloudStack, efsSetMap)).map(request -> intermediateBuilderExecutor.submit(() -> {
CreateFileSystemResult result = client.createFileSystem(request);
CloudEfsAttributes resultAttributes = getResultEfsAttributes(request, result, efsSetMap);
efsSetMap.put(resultAttributes.getName(), resultAttributes);
})).collect(Collectors.toList()));
LOGGER.debug("Waiting for EFS creation requests");
for (Future<?> future : futures) {
future.get();
}
LOGGER.debug("EFS creation requests sent");
return buildableResource.stream().peek(resource -> {
CloudEfsAttributes resultEfsAttributes = efsSetMap.getOrDefault(resource.getName(), null);
if (resultEfsAttributes != null) {
CloudEfsAttributes resourceEfsAttributes = resource.getParameter(CloudResource.ATTRIBUTES, CloudEfsAttributes.class);
resourceEfsAttributes.setFileSystemId(resultEfsAttributes.getFileSystemId());
resourceEfsAttributes.setFileState(resultEfsAttributes.getFileState());
}
}).map(copyResourceWithCreatedStatus()).collect(Collectors.toList());
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext 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