Search in sources :

Example 1 with AwsContext

use of com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext 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;
}
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) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ArrayList(java.util.ArrayList) DescribeFileSystemsRequest(com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsRequest) DescribeFileSystemsResult(com.amazonaws.services.elasticfilesystem.model.DescribeFileSystemsResult) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource)

Example 2 with AwsContext

use of com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext 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());
}
Also used : AwsResourceNameService(com.sequenceiq.cloudbreak.cloud.aws.common.service.AwsResourceNameService) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) CREATED(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.CREATED) AsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor) LoggerFactory(org.slf4j.LoggerFactory) AwsDiskType(com.sequenceiq.common.model.AwsDiskType) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) TagSpecification(com.amazonaws.services.ec2.model.TagSpecification) StringUtils(org.apache.commons.lang3.StringUtils) DeviceNameGenerator(com.sequenceiq.cloudbreak.util.DeviceNameGenerator) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) Future(java.util.concurrent.Future) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) FAILED(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.FAILED) CreateVolumeRequest(com.amazonaws.services.ec2.model.CreateVolumeRequest) Map(java.util.Map) EbsInstanceBlockDeviceSpecification(com.amazonaws.services.ec2.model.EbsInstanceBlockDeviceSpecification) Pair(org.springframework.data.util.Pair) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudVolumeUsageType(com.sequenceiq.cloudbreak.cloud.model.CloudVolumeUsageType) IN_PROGRESS(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.IN_PROGRESS) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) CollectionUtils(org.springframework.util.CollectionUtils) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Optional(java.util.Optional) AwsMethodExecutor(com.sequenceiq.cloudbreak.cloud.aws.common.util.AwsMethodExecutor) NotNull(org.jetbrains.annotations.NotNull) AwsInstanceView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsInstanceView) HashMap(java.util.HashMap) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ResourceRetriever(com.sequenceiq.cloudbreak.cloud.service.ResourceRetriever) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) InstanceBlockDeviceMappingSpecification(com.amazonaws.services.ec2.model.InstanceBlockDeviceMappingSpecification) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) CreateVolumeResult(com.amazonaws.services.ec2.model.CreateVolumeResult) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) AwsContext(com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Subnet(com.amazonaws.services.ec2.model.Subnet) ResourceType(com.sequenceiq.common.api.type.ResourceType) Logger(org.slf4j.Logger) ATTACHED(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.ATTACHED) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) DELETED(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.DELETED) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) ModifyInstanceAttributeResult(com.amazonaws.services.ec2.model.ModifyInstanceAttributeResult) Component(org.springframework.stereotype.Component) PreserveResourceException(com.sequenceiq.cloudbreak.cloud.template.compute.PreserveResourceException) ModifyInstanceAttributeRequest(com.amazonaws.services.ec2.model.ModifyInstanceAttributeRequest) DeleteVolumeRequest(com.amazonaws.services.ec2.model.DeleteVolumeRequest) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) CommonAwsClient(com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient) Collections(java.util.Collections) Volume(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes.Volume) AwsTaggingService(com.sequenceiq.cloudbreak.cloud.aws.common.AwsTaggingService) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) List(java.util.List) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception)

Example 3 with AwsContext

use of com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext 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());
}
Also used : AwsResourceNameService(com.sequenceiq.cloudbreak.cloud.aws.common.service.AwsResourceNameService) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) CREATED(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.CREATED) AsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor) LoggerFactory(org.slf4j.LoggerFactory) AwsDiskType(com.sequenceiq.common.model.AwsDiskType) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) TagSpecification(com.amazonaws.services.ec2.model.TagSpecification) StringUtils(org.apache.commons.lang3.StringUtils) DeviceNameGenerator(com.sequenceiq.cloudbreak.util.DeviceNameGenerator) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) Future(java.util.concurrent.Future) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) FAILED(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.FAILED) CreateVolumeRequest(com.amazonaws.services.ec2.model.CreateVolumeRequest) Map(java.util.Map) EbsInstanceBlockDeviceSpecification(com.amazonaws.services.ec2.model.EbsInstanceBlockDeviceSpecification) Pair(org.springframework.data.util.Pair) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) CloudVolumeUsageType(com.sequenceiq.cloudbreak.cloud.model.CloudVolumeUsageType) IN_PROGRESS(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.IN_PROGRESS) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) CollectionUtils(org.springframework.util.CollectionUtils) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Optional(java.util.Optional) AwsMethodExecutor(com.sequenceiq.cloudbreak.cloud.aws.common.util.AwsMethodExecutor) NotNull(org.jetbrains.annotations.NotNull) AwsInstanceView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsInstanceView) HashMap(java.util.HashMap) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ResourceRetriever(com.sequenceiq.cloudbreak.cloud.service.ResourceRetriever) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) InstanceBlockDeviceMappingSpecification(com.amazonaws.services.ec2.model.InstanceBlockDeviceMappingSpecification) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) CreateVolumeResult(com.amazonaws.services.ec2.model.CreateVolumeResult) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) AwsContext(com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Subnet(com.amazonaws.services.ec2.model.Subnet) ResourceType(com.sequenceiq.common.api.type.ResourceType) Logger(org.slf4j.Logger) ATTACHED(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.ATTACHED) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) DELETED(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus.DELETED) PersistenceNotifier(com.sequenceiq.cloudbreak.cloud.notification.PersistenceNotifier) ModifyInstanceAttributeResult(com.amazonaws.services.ec2.model.ModifyInstanceAttributeResult) Component(org.springframework.stereotype.Component) PreserveResourceException(com.sequenceiq.cloudbreak.cloud.template.compute.PreserveResourceException) ModifyInstanceAttributeRequest(com.amazonaws.services.ec2.model.ModifyInstanceAttributeRequest) DeleteVolumeRequest(com.amazonaws.services.ec2.model.DeleteVolumeRequest) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) CommonAwsClient(com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient) Collections(java.util.Collections) Volume(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes.Volume) AwsTaggingService(com.sequenceiq.cloudbreak.cloud.aws.common.AwsTaggingService) CreateVolumeRequest(com.amazonaws.services.ec2.model.CreateVolumeRequest) CreateVolumeResult(com.amazonaws.services.ec2.model.CreateVolumeResult) ArrayList(java.util.ArrayList) TagSpecification(com.amazonaws.services.ec2.model.TagSpecification) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Volume(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes.Volume) Future(java.util.concurrent.Future) List(java.util.List) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) DeviceNameGenerator(com.sequenceiq.cloudbreak.util.DeviceNameGenerator)

Example 4 with AwsContext

use of com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext in project cloudbreak by hortonworks.

the class CreateResourcesHandler method accept.

@Override
public void accept(Event<CreateResourcesRequest> event) {
    LOGGER.info("Re-create the resources during the AWS migration");
    CreateResourcesRequest request = event.getData();
    try {
        CloudContext cloudContext = request.getCloudContext();
        CloudCredential cloudCredential = request.getCloudCredential();
        CloudStack cloudStack = request.getCloudStack();
        AuthenticatedContext ac = awsAuthenticator.authenticate(cloudContext, cloudCredential);
        Network network = cloudStack.getNetwork();
        AwsContext awsContext = awsContextBuilder.contextInit(cloudContext, ac, network, List.of(), true);
        for (ResourceRecreator resourceRecreator : resourceRecreators) {
            resourceRecreator.recreate(request, awsContext, ac);
        }
        CreateResourcesResult result = new CreateResourcesResult(request.getResourceId());
        request.getResult().onNext(result);
        eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
    } catch (Exception e) {
        LOGGER.error("Cannot re-create the AWS security group during the variant migration", e);
        CreateResourcesResult result = new CreateResourcesResult(e.getMessage(), e, request.getResourceId());
        request.getResult().onNext(result);
        eventBus.notify(AWS_VARIANT_MIGRATION_FAILED_EVENT.event(), new Event<>(event.getHeaders(), result));
    }
}
Also used : ResourceRecreator(com.sequenceiq.cloudbreak.core.flow2.stack.migration.handler.service.ResourceRecreator) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CreateResourcesResult(com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesResult) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Network(com.sequenceiq.cloudbreak.cloud.model.Network) Event(reactor.bus.Event) CreateResourcesRequest(com.sequenceiq.cloudbreak.cloud.event.resource.migration.aws.CreateResourcesRequest) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AwsContext(com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext)

Example 5 with AwsContext

use of com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext 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);
}
Also used : AsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor) AttachVolumeRequest(com.amazonaws.services.ec2.model.AttachVolumeRequest) LoggerFactory(org.slf4j.LoggerFactory) AwsDiskType(com.sequenceiq.common.model.AwsDiskType) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) Inject(javax.inject.Inject) Future(java.util.concurrent.Future) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) 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) Qualifier(org.springframework.beans.factory.annotation.Qualifier) Pair(org.springframework.data.util.Pair) DescribeVolumesRequest(com.amazonaws.services.ec2.model.DescribeVolumesRequest) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) ResourceStatus(com.sequenceiq.cloudbreak.cloud.model.ResourceStatus) ResourceType(com.sequenceiq.common.api.type.ResourceType) Logger(org.slf4j.Logger) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) DescribeVolumesResult(com.amazonaws.services.ec2.model.DescribeVolumesResult) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) Component(org.springframework.stereotype.Component) PreserveResourceException(com.sequenceiq.cloudbreak.cloud.template.compute.PreserveResourceException) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Optional(java.util.Optional) CommonAwsClient(com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient) AmazonClientException(com.amazonaws.AmazonClientException) AttachVolumeRequest(com.amazonaws.services.ec2.model.AttachVolumeRequest) AmazonClientException(com.amazonaws.AmazonClientException) Future(java.util.concurrent.Future) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AmazonEc2Client(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes)

Aggregations

AwsContext (com.sequenceiq.cloudbreak.cloud.aws.common.context.AwsContext)7 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)7 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)7 CommonAwsClient (com.sequenceiq.cloudbreak.cloud.aws.common.CommonAwsClient)6 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)6 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)6 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)6 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)6 Group (com.sequenceiq.cloudbreak.cloud.model.Group)6 Image (com.sequenceiq.cloudbreak.cloud.model.Image)6 CommonStatus (com.sequenceiq.common.api.type.CommonStatus)6 ResourceType (com.sequenceiq.common.api.type.ResourceType)6 List (java.util.List)6 Optional (java.util.Optional)6 Future (java.util.concurrent.Future)6 Function (java.util.function.Function)6 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6