Search in sources :

Example 1 with CreateFileSystemResult

use of com.amazonaws.services.elasticfilesystem.model.CreateFileSystemResult 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());
}
Also used : AmazonEfsClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEfsClient) DescribeMountTargetsResult(com.amazonaws.services.elasticfilesystem.model.DescribeMountTargetsResult) AmazonElasticFileSystemException(com.amazonaws.services.elasticfilesystem.model.AmazonElasticFileSystemException) AsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AmazonEfsClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEfsClient) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Future(java.util.concurrent.Future) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) AwsContext(com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) StreamSupport(java.util.stream.StreamSupport) DescribeMountTargetsRequest(com.amazonaws.services.elasticfilesystem.model.DescribeMountTargetsRequest) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) ResourceType(com.sequenceiq.common.api.type.ResourceType) Logger(org.slf4j.Logger) CreateFileSystemRequest(com.amazonaws.services.elasticfilesystem.model.CreateFileSystemRequest) DescribeFileSystemsResult(com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsResult) FileSystemDescription(com.amazonaws.services.elasticfilesystem.model.FileSystemDescription) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Collection(java.util.Collection) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) DescribeFileSystemsRequest(com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsRequest) Tag(com.amazonaws.services.elasticfilesystem.model.Tag) Collectors(java.util.stream.Collectors) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CreateFileSystemResult(com.amazonaws.services.elasticfilesystem.model.CreateFileSystemResult) List(java.util.List) Component(org.springframework.stereotype.Component) DeleteMountTargetRequest(com.amazonaws.services.elasticfilesystem.model.DeleteMountTargetRequest) LifeCycleState(com.sequenceiq.cloudbreak.cloud.model.filesystem.efs.LifeCycleState) MountTargetDescription(com.amazonaws.services.elasticfilesystem.model.MountTargetDescription) CloudEfsAttributes(com.sequenceiq.cloudbreak.cloud.model.CloudEfsAttributes) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Optional(java.util.Optional) DeleteFileSystemRequest(com.amazonaws.services.elasticfilesystem.model.DeleteFileSystemRequest) CommonAwsClient(com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient) Collections(java.util.Collections) AwsTaggingService(com.sequenceiq.cloudbreak.cloud.aws.common.AwsTaggingService) StringUtils(org.springframework.util.StringUtils) CloudEfsAttributes(com.sequenceiq.cloudbreak.cloud.model.CloudEfsAttributes) ArrayList(java.util.ArrayList) CreateFileSystemResult(com.amazonaws.services.elasticfilesystem.model.CreateFileSystemResult) Future(java.util.concurrent.Future) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 2 with CreateFileSystemResult

use of com.amazonaws.services.elasticfilesystem.model.CreateFileSystemResult in project cloudbreak by hortonworks.

the class AwsLaunchTest method setupCreateFileSystem.

private void setupCreateFileSystem() {
    String fileSystemId = EFS_FILESYSTEM_ID + efsIdIndex;
    efsIdIndex++;
    CreateFileSystemResult createFileSystemResult = new CreateFileSystemResult().withFileSystemId(fileSystemId).withName(fileSystemId).withLifeCycleState("creating");
    when(amazonElasticFileSystemClient.createFileSystem(any())).thenReturn(createFileSystemResult);
    when(amazonEfsClient.createFileSystem(any())).thenReturn(createFileSystemResult);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CreateFileSystemResult(com.amazonaws.services.elasticfilesystem.model.CreateFileSystemResult)

Aggregations

CreateFileSystemResult (com.amazonaws.services.elasticfilesystem.model.CreateFileSystemResult)2 AmazonElasticFileSystemException (com.amazonaws.services.elasticfilesystem.model.AmazonElasticFileSystemException)1 CreateFileSystemRequest (com.amazonaws.services.elasticfilesystem.model.CreateFileSystemRequest)1 DeleteFileSystemRequest (com.amazonaws.services.elasticfilesystem.model.DeleteFileSystemRequest)1 DeleteMountTargetRequest (com.amazonaws.services.elasticfilesystem.model.DeleteMountTargetRequest)1 DescribeFileSystemsRequest (com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsRequest)1 DescribeFileSystemsResult (com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsResult)1 DescribeMountTargetsRequest (com.amazonaws.services.elasticfilesystem.model.DescribeMountTargetsRequest)1 DescribeMountTargetsResult (com.amazonaws.services.elasticfilesystem.model.DescribeMountTargetsResult)1 FileSystemDescription (com.amazonaws.services.elasticfilesystem.model.FileSystemDescription)1 MountTargetDescription (com.amazonaws.services.elasticfilesystem.model.MountTargetDescription)1 Tag (com.amazonaws.services.elasticfilesystem.model.Tag)1 AwsTaggingService (com.sequenceiq.cloudbreak.cloud.aws.common.AwsTaggingService)1 CommonAwsClient (com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient)1 AmazonEfsClient (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEfsClient)1 AwsContext (com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudEfsAttributes (com.sequenceiq.cloudbreak.cloud.model.CloudEfsAttributes)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1