use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEfsClient in project cloudbreak by hortonworks.
the class AwsEfsResourceBuilder method checkResources.
@Override
protected List<CloudResourceStatus> checkResources(ResourceType type, AwsContext context, AuthenticatedContext auth, Iterable<CloudResource> resources) {
AmazonEfsClient client = getAmazonEfsClient(auth);
List<CloudResource> efsResources = StreamSupport.stream(resources.spliterator(), false).filter(r -> r.getType().equals(resourceType())).collect(Collectors.toList());
List<String> efsIds = new ArrayList<>();
List<CloudResourceStatus> cloudResourceStatusList = new ArrayList<>();
for (CloudResource efsResource : efsResources) {
CloudEfsAttributes efsAttributes = efsResource.getParameter(CloudResource.ATTRIBUTES, CloudEfsAttributes.class);
String efsId = efsAttributes.getFileSystemId();
efsIds.add(efsId);
DescribeFileSystemsRequest request = new DescribeFileSystemsRequest().withFileSystemId(efsId);
DescribeFileSystemsResult result = client.describeFileSystems(request);
List<CloudResourceStatus> efsStatusList = getResourceStatus(efsResource, efsId, result);
cloudResourceStatusList.addAll(efsStatusList);
}
LOGGER.debug("got EFS status for [{}]", String.join(",", efsIds));
return cloudResourceStatusList;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEfsClient 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.client.AmazonEfsClient in project cloudbreak by hortonworks.
the class AwsEfsResourceBuilder method delete.
@Override
public CloudResource delete(AwsContext context, AuthenticatedContext auth, CloudResource resource) throws InterruptedException {
//
// https://docs.aws.amazon.com/efs/latest/ug/wt1-clean-up.html
// To delete an EFS instance, need the following steps
// 1. Terminate the EC2 instances that mount on this EFS. The caller of this function has to make sure it is done before calling this function
// 2. Delete the mount targets of this EFS.
// 3. (Optional) Delete the security group of each mount target. AWS does not charge for security groups
// 4. (Optional) Delete the security group of the EC2 instances at step 1. The mount target's security group has a rule that references
// the EC2 security group. Therefore, we cannot first delete the EC2 instance's security group.
// 5. Actually delete the EFS
//
AmazonEfsClient client = getAmazonEfsClient(auth);
CloudEfsAttributes efsAttributes = resource.getParameter(CloudResource.ATTRIBUTES, CloudEfsAttributes.class);
String efsId = efsAttributes.getFileSystemId();
DescribeFileSystemsRequest request = new DescribeFileSystemsRequest().withFileSystemId(efsId);
DescribeFileSystemsResult result = client.describeFileSystems(request);
List<FileSystemDescription> efsDescriptions = result.getFileSystems();
for (FileSystemDescription efsDescription : efsDescriptions) {
LifeCycleState efsLifeCycleState = LifeCycleState.fromValue(efsDescription.getLifeCycleState());
if (LifeCycleState.DELETED.equals(efsLifeCycleState) || LifeCycleState.DELETING.equals(efsLifeCycleState)) {
LOGGER.debug("The given AWS EFS's [name: {}] lifecycle state was [{}] hence we are going to skip any delete operation over this resource", efsDescription.getName(), efsLifeCycleState);
continue;
}
if (efsDescription.getNumberOfMountTargets() > 0) {
DescribeMountTargetsRequest mtRequest = new DescribeMountTargetsRequest().withFileSystemId(efsId);
DescribeMountTargetsResult mtResult = client.describeMountTargets(mtRequest);
List<MountTargetDescription> mountTargetDescriptionList = mtResult.getMountTargets();
// Only delete the mount targets.
for (MountTargetDescription mtDescription : mountTargetDescriptionList) {
DeleteMountTargetRequest mtDelRequest = new DeleteMountTargetRequest().withMountTargetId(mtDescription.getMountTargetId());
LOGGER.debug("About to delete AWS EFS mount target that has the following id: {}", mtDescription.getMountTargetId());
client.deleteMountTarget(mtDelRequest);
}
// TODO: delete the security groups in the future
}
DeleteFileSystemRequest efsDelRequest = new DeleteFileSystemRequest().withFileSystemId(efsId);
client.deleteFileSystem(efsDelRequest);
}
return null;
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEfsClient in project cloudbreak by hortonworks.
the class AwsLaunchTest method launchStackWithEfs.
@Test
public void launchStackWithEfs() throws Exception {
setup();
setupRetryService();
setupFreemarkerTemplateProcessing();
setupDescribeStacksResponses();
setupDescribeImagesResponse();
setupDescribeStackResourceResponse();
setupAutoscalingResponses();
setupDescribeInstancesResponse();
setupCreateVolumeResponse();
setupDescribeVolumeResponse();
setupDescribeSubnetResponse();
setupDescribePrefixListsResponse();
setupCreateFileSystem();
setupDescribeFileSystems();
setupDescribeMountTargets();
setupDeleteMountTarget();
setupDeleteFileSystem();
InMemoryStateStore.putStack(1L, PollGroup.POLLABLE);
AuthenticatedContext authenticatedContext = componentTestUtil.getAuthenticatedContext();
authenticatedContext.putParameter(AmazonEc2Client.class, amazonEc2Client);
authenticatedContext.putParameter(AmazonElasticFileSystemClient.class, amazonElasticFileSystemClient);
authenticatedContext.putParameter(AmazonEfsClient.class, amazonEfsClient);
awsResourceConnector.launch(authenticatedContext, componentTestUtil.getStackForLaunch(InstanceStatus.CREATE_REQUESTED, InstanceStatus.CREATE_REQUESTED), persistenceNotifier, new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, Long.MAX_VALUE));
// assert
verify(persistenceNotifier).notifyAllocation(argThat(cloudResource -> ResourceType.AWS_VPC.equals(cloudResource.getType())), any());
verify(persistenceNotifier, times(2)).notifyAllocation(argThat(cloudResource -> ResourceType.AWS_VOLUMESET.equals(cloudResource.getType())), any());
verify(persistenceNotifier).notifyAllocation(argThat(cloudResource -> ResourceType.AWS_SUBNET.equals(cloudResource.getType())), any());
verify(persistenceNotifier).notifyAllocation(argThat(cloudResource -> ResourceType.CLOUDFORMATION_STACK.equals(cloudResource.getType())), any());
InOrder inOrder = inOrder(amazonElasticFileSystemClient, amazonEfsClient, amazonCloudFormationClient, amazonEc2Client);
inOrder.verify(amazonEc2Client).describeImages(any());
inOrder.verify(amazonCloudFormationClient).createStack(any());
inOrder.verify(amazonEc2Client, times(2)).createVolume(any());
inOrder.verify(amazonEc2Client, times(2)).attachVolume(any());
inOrder.verify(amazonEc2Client, never()).describePrefixLists();
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEfsClient in project cloudbreak by hortonworks.
the class CloudFormationStackUtil method getEfsByFileSystemId.
public FileSystemDescription getEfsByFileSystemId(AuthenticatedContext ac, String fileSystemId) {
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonEfsClient amazonEfsClient = awsClient.createElasticFileSystemClient(new AwsCredentialView(ac.getCloudCredential()), region);
DescribeFileSystemsResult efsResult = amazonEfsClient.describeFileSystems(new DescribeFileSystemsRequest().withFileSystemId(fileSystemId));
return efsResult.getFileSystems().get(0);
}
Aggregations