Search in sources :

Example 31 with CloudStack

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

the class StackCreationActions method collectMetadataAction.

@Bean(name = "COLLECTMETADATA_STATE")
public Action<?, ?> collectMetadataAction() {
    return new AbstractStackCreationAction<CollectMetadataResult>(CollectMetadataResult.class) {

        @Override
        protected void doExecute(StackContext context, CollectMetadataResult payload, Map<Object, Object> variables) {
            Stack stack = stackCreationService.setupMetadata(context, payload);
            StackContext newContext = new StackContext(context.getFlowId(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
            sendEvent(newContext);
        }

        @Override
        protected Selectable createRequest(StackContext context) {
            CloudStack cloudStack = cloudStackConverter.convert(context.getStack());
            return new GetTlsInfoRequest<GetTlsInfoResult>(context.getCloudContext(), context.getCloudCredential(), cloudStack);
        }
    };
}
Also used : StackContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackContext) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Map(java.util.Map) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.Stack) GetTlsInfoRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoRequest) Bean(org.springframework.context.annotation.Bean)

Example 32 with CloudStack

use of com.sequenceiq.cloudbreak.cloud.model.CloudStack 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 33 with CloudStack

use of com.sequenceiq.cloudbreak.cloud.model.CloudStack 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)

Example 34 with CloudStack

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

the class AbstractInstanceTerminationAction method createFlowContext.

@Override
protected InstanceTerminationContext createFlowContext(String flowId, StateContext<InstanceTerminationState, InstanceTerminationEvent> 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());
    Set<String> instanceIds = payload.getInstanceIds();
    CloudStack cloudStack = cloudStackConverter.convert(stack, instanceIds);
    List<CloudResource> cloudResources = cloudResourceConverter.convert(stack.getResources());
    List<InstanceMetaData> instanceMetaDataList = new ArrayList<>();
    List<CloudInstance> cloudInstances = new ArrayList<>();
    for (String instanceId : instanceIds) {
        InstanceMetaData instanceMetaData = instanceMetaDataRepository.findByInstanceId(stack.getId(), instanceId);
        CloudInstance cloudInstance = metadataConverter.convert(instanceMetaData);
        instanceMetaDataList.add(instanceMetaData);
        cloudInstances.add(cloudInstance);
    }
    return new InstanceTerminationContext(flowId, stack, cloudContext, cloudCredential, cloudStack, cloudResources, cloudInstances, instanceMetaDataList);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 35 with CloudStack

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

the class GetTlsInfoHandler method accept.

@Override
public void accept(Event<GetTlsInfoRequest> getTlsInfoRequestEvent) {
    LOGGER.info("Received event: {}", getTlsInfoRequestEvent);
    GetTlsInfoRequest<?> tlsInfoRequest = getTlsInfoRequestEvent.getData();
    try {
        CloudContext cloudContext = tlsInfoRequest.getCloudContext();
        CloudCredential cloudCredential = tlsInfoRequest.getCloudCredential();
        CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        CloudStack cloudStack = tlsInfoRequest.getCloudStack();
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, cloudCredential);
        TlsInfo tlsInfo = connector.resources().getTlsInfo(ac, cloudStack);
        GetTlsInfoResult getTlsInfoResult = new GetTlsInfoResult(tlsInfoRequest, tlsInfo);
        tlsInfoRequest.getResult().onNext(getTlsInfoResult);
        eventBus.notify(getTlsInfoResult.selector(), new Event<>(getTlsInfoRequestEvent.getHeaders(), getTlsInfoResult));
        LOGGER.info("GetTlsInfoHandler finished.");
    } catch (RuntimeException e) {
        String errorMsg = "Failed to get Tls info from cloud connector!";
        LOGGER.error(errorMsg, e);
        GetTlsInfoResult failure = new GetTlsInfoResult(errorMsg, e, tlsInfoRequest);
        tlsInfoRequest.getResult().onNext(failure);
        eventBus.notify(failure.selector(), new Event<>(getTlsInfoRequestEvent.getHeaders(), failure));
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) TlsInfo(com.sequenceiq.cloudbreak.cloud.model.TlsInfo) GetTlsInfoResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult) Event(reactor.bus.Event) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack)

Aggregations

CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)53 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)43 Group (com.sequenceiq.cloudbreak.cloud.model.Group)36 Network (com.sequenceiq.cloudbreak.cloud.model.Network)35 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)34 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)33 HashMap (java.util.HashMap)33 Test (org.junit.Test)31 Location (com.sequenceiq.cloudbreak.cloud.model.Location)21 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)20 Matchers.containsString (org.hamcrest.Matchers.containsString)18 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)17 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)17 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)15 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)15 Vpc (com.amazonaws.services.ec2.model.Vpc)15 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)14 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)8 ArrayList (java.util.ArrayList)8 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)7