Search in sources :

Example 21 with Location

use of com.sequenceiq.cloudbreak.cloud.model.Location in project cloudbreak by hortonworks.

the class ServiceProviderConnectorAdapter method deleteStack.

public void deleteStack(Stack stack, Credential credential) {
    LOGGER.debug("Assembling terminate stack event for stack: {}", stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
    CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
    List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    TerminateStackRequest<TerminateStackResult> terminateRequest = new TerminateStackRequest<>(cloudContext, cloudStack, cloudCredential, resources);
    LOGGER.info("Triggering terminate stack event: {}", terminateRequest);
    eventBus.notify(terminateRequest.selector(), eventFactory.createEvent(terminateRequest));
    try {
        TerminateStackResult res = terminateRequest.await();
        LOGGER.info("Terminate stack result: {}", res);
        if (res.getStatus().equals(EventStatus.FAILED)) {
            if (res.getErrorDetails() != null) {
                LOGGER.error("Failed to terminate the stack", res.getErrorDetails());
                throw new OperationException(res.getErrorDetails());
            }
            throw new OperationException(format("Failed to terminate the stack: %s due to %s", cloudContext, res.getStatusReason()));
        }
    } catch (InterruptedException e) {
        LOGGER.error("Error while terminating the stack", e);
        throw new OperationException(e);
    }
}
Also used : TerminateStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.TerminateStackResult) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) TerminateStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.TerminateStackRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 22 with Location

use of com.sequenceiq.cloudbreak.cloud.model.Location in project cloudbreak by hortonworks.

the class ServiceProviderConnectorAdapter method getTemplate.

public String getTemplate(Stack stack) {
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
    CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
    GetPlatformTemplateRequest getPlatformTemplateRequest = new GetPlatformTemplateRequest(cloudContext, cloudCredential);
    eventBus.notify(getPlatformTemplateRequest.selector(), eventFactory.createEvent(getPlatformTemplateRequest));
    try {
        GetPlatformTemplateResult res = getPlatformTemplateRequest.await();
        LOGGER.info("Get template result: {}", res);
        if (res.getStatus().equals(EventStatus.FAILED)) {
            LOGGER.error("Failed to get template", res.getErrorDetails());
            throw new OperationException(res.getErrorDetails());
        }
        return res.getTemplate();
    } catch (InterruptedException e) {
        LOGGER.error("Error while getting template: " + cloudContext, e);
        throw new OperationException(e);
    }
}
Also used : GetPlatformTemplateResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateResult) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location) GetPlatformTemplateRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateRequest)

Example 23 with Location

use of com.sequenceiq.cloudbreak.cloud.model.Location in project cloudbreak by hortonworks.

the class ServiceProviderMetadataAdapter method collectMetadata.

public List<CloudVmMetaDataStatus> collectMetadata(Stack stack) {
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
    CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
    List<CloudInstance> cloudInstances = cloudStackConverter.buildInstances(stack);
    List<CloudResource> cloudResources = cloudResourceConverter.convert(stack.getResources());
    CollectMetadataRequest cmr = new CollectMetadataRequest(cloudContext, cloudCredential, cloudResources, cloudInstances);
    LOGGER.info("Triggering event: {}", cmr);
    eventBus.notify(CloudPlatformRequest.selector(CollectMetadataRequest.class), eventFactory.createEvent(cmr));
    try {
        CollectMetadataResult res = cmr.await();
        LOGGER.info("Result: {}", res);
        if (res.getErrorDetails() != null) {
            LOGGER.error("Failed to collect metadata", res.getErrorDetails());
            return Collections.emptyList();
        }
        return res.getResults();
    } catch (InterruptedException e) {
        LOGGER.error(format("Error while executing collectMetadata, stack: %s", cloudContext), e);
        throw new OperationException(e);
    }
}
Also used : CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 24 with Location

use of com.sequenceiq.cloudbreak.cloud.model.Location in project cloudbreak by hortonworks.

the class AbstractStackDownscaleAction method createFlowContext.

@Override
protected StackScalingFlowContext createFlowContext(String flowId, StateContext<StackDownscaleState, StackDownscaleEvent> stateContext, P payload) {
    Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
    Stack stack = stackService.getByIdWithLists(payload.getStackId());
    MDCBuilder.buildMdcContext(stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
    CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
    String instanceGroupName = extractInstanceGroupName(payload, variables);
    Set<String> instanceIds = extractInstanceIds(payload, variables, stack);
    Integer adjustment = extractAdjustment(payload, variables);
    CloudStack cloudStack = cloudStackConverter.convertForDownscale(stack, instanceIds);
    return new StackScalingFlowContext(flowId, stack, cloudContext, cloudCredential, cloudStack, instanceGroupName, instanceIds, adjustment);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 25 with Location

use of com.sequenceiq.cloudbreak.cloud.model.Location in project cloudbreak by hortonworks.

the class AbstractStackTerminationAction method createFlowContext.

@Override
protected StackTerminationContext createFlowContext(String flowId, StateContext<StackTerminationState, StackTerminationEvent> stateContext, P payload) {
    Stack stack = stackService.getByIdWithLists(payload.getStackId());
    MDCBuilder.buildMdcContext(stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = new CloudContext(stack.getId(), stack.getName(), stack.cloudPlatform(), stack.getOwner(), stack.getPlatformVariant(), location);
    CloudCredential cloudCredential = credentialConverter.convert(stack.getCredential());
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    List<CloudResource> resources = cloudResourceConverter.convert(stack.getResources());
    return new StackTerminationContext(flowId, stack, cloudContext, cloudCredential, cloudStack, resources);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.Stack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Aggregations

Location (com.sequenceiq.cloudbreak.cloud.model.Location)36 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)31 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)21 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)18 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)17 HashMap (java.util.HashMap)17 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)14 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)14 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)14 Vpc (com.amazonaws.services.ec2.model.Vpc)14 Group (com.sequenceiq.cloudbreak.cloud.model.Group)14 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)14 Network (com.sequenceiq.cloudbreak.cloud.model.Network)14 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)14 Test (org.junit.Test)14 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)8 OperationException (com.sequenceiq.cloudbreak.service.stack.connector.OperationException)8 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)7 ArrayList (java.util.ArrayList)6 Operation (com.google.api.services.compute.model.Operation)5