Search in sources :

Example 1 with StackCreationContext

use of com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext in project cloudbreak by hortonworks.

the class ClusterCreationActions method clusterProxyRegistrationAction.

@Bean(name = "CLUSTER_PROXY_REGISTRATION_STATE")
public Action<?, ?> clusterProxyRegistrationAction() {
    return new AbstractStackCreationAction<>(ProvisionEvent.class) {

        @Inject
        private ClusterProxyEnablementService clusterProxyEnablementService;

        @Override
        protected void prepareExecution(ProvisionEvent payload, Map<Object, Object> variables) {
            super.prepareExecution(payload, variables);
            variables.put(PROVISION_TYPE, payload.getProvisionType());
        }

        @Override
        protected void doExecute(StackCreationContext context, ProvisionEvent payload, Map<Object, Object> variables) {
            if (clusterProxyEnablementService.isClusterProxyApplicable(context.getStack().cloudPlatform())) {
                clusterCreationService.registeringToClusterProxy(context.getStack());
                sendEvent(context);
            } else {
                ClusterProxyRegistrationSuccess clusterProxyRegistrationSuccess = new ClusterProxyRegistrationSuccess(payload.getResourceId());
                sendEvent(context, clusterProxyRegistrationSuccess);
            }
        }

        @Override
        protected Selectable createRequest(StackCreationContext context) {
            return new ClusterProxyRegistrationRequest(context.getStack().getId(), context.getStack().cloudPlatform());
        }
    };
}
Also used : StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) AbstractStackCreationAction(com.sequenceiq.cloudbreak.core.flow2.stack.provision.action.AbstractStackCreationAction) ClusterProxyEnablementService(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyEnablementService) ClusterProxyRegistrationRequest(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ClusterProxyRegistrationRequest) ProvisionEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ProvisionEvent) ClusterProxyRegistrationSuccess(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ClusterProxyRegistrationSuccess) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 2 with StackCreationContext

use of com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext in project cloudbreak by hortonworks.

the class AbstractStackCreationAction method createFlowContext.

@Override
protected StackCreationContext createFlowContext(FlowParameters flowParameters, StateContext<StackCreationState, StackCreationEvent> stateContext, P payload) {
    Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
    stack.setResources(new HashSet<>(resourceService.getAllByStackId(payload.getResourceId())));
    Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
    ProvisionType provisionType = (ProvisionType) variables.getOrDefault(PROVISION_TYPE, ProvisionType.REGULAR);
    MDCBuilder.buildMdcContext(stack);
    Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
    CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformVariant()).withUserName(stack.getCreator().getUserName()).withLocation(location).withWorkspaceId(stack.getWorkspace().getId()).withAccountId(Crn.safeFromString(stack.getResourceCrn()).getAccountId()).withTenantId(stack.getTenant().getId()).build();
    CloudCredential cloudCredential = stackUtil.getCloudCredential(stack);
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    return new StackCreationContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, provisionType);
}
Also used : StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) ProvisionType(com.sequenceiq.cloudbreak.reactor.api.event.stack.ProvisionType) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 3 with StackCreationContext

use of com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext in project cloudbreak by hortonworks.

the class StackCreationActions method tlsSetupAction.

@Bean(name = "TLS_SETUP_STATE")
public Action<?, ?> tlsSetupAction() {
    return new AbstractStackCreationAction<>(GetSSHFingerprintsResult.class) {

        @Override
        protected void doExecute(StackCreationContext context, GetSSHFingerprintsResult payload, Map<Object, Object> variables) throws Exception {
            if (!context.getStack().getTunnel().useCcm()) {
                stackCreationService.setupTls(context);
            }
            StackWithFingerprintsEvent fingerprintsEvent = new StackWithFingerprintsEvent(payload.getResourceId(), payload.getSshFingerprints());
            sendEvent(context, StackCreationEvent.TLS_SETUP_FINISHED_EVENT.event(), fingerprintsEvent);
        }
    };
}
Also used : StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) StackWithFingerprintsEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.StackWithFingerprintsEvent) Map(java.util.Map) GetSSHFingerprintsResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult) Bean(org.springframework.context.annotation.Bean)

Example 4 with StackCreationContext

use of com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext in project cloudbreak by hortonworks.

the class StackCreationActions method prepareImageAction.

@Bean(name = "IMAGESETUP_STATE")
public Action<?, ?> prepareImageAction() {
    return new AbstractStackCreationAction<>(SetupResult.class) {

        @Override
        protected void doExecute(StackCreationContext context, SetupResult payload, Map<Object, Object> variables) {
            stackCreationService.prepareImage(context.getStack(), variables);
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackCreationContext context) {
            try {
                CloudStack cloudStack = cloudStackConverter.convert(context.getStack());
                Image image = imageService.getImage(context.getCloudContext().getId());
                return new PrepareImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, image);
            } catch (CloudbreakImageNotFoundException e) {
                throw new CloudbreakServiceException(e);
            }
        }
    };
}
Also used : SetupResult(com.sequenceiq.cloudbreak.cloud.event.setup.SetupResult) StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Map(java.util.Map) PrepareImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest) Bean(org.springframework.context.annotation.Bean)

Example 5 with StackCreationContext

use of com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext in project cloudbreak by hortonworks.

the class StackCreationActions method getTlsInfoAction.

@Bean(name = "GET_TLS_INFO_STATE")
public Action<?, ?> getTlsInfoAction() {
    return new AbstractStackCreationAction<>(GetTlsInfoResult.class) {

        @Override
        protected void doExecute(StackCreationContext context, GetTlsInfoResult payload, Map<Object, Object> variables) {
            Stack stack = stackCreationService.saveTlsInfo(context, payload.getTlsInfo());
            StackCreationContext newContext = new StackCreationContext(context.getFlowParameters(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
            sendEvent(newContext);
        }

        @Override
        protected Selectable createRequest(StackCreationContext context) {
            Stack stack = context.getStack();
            InstanceMetaData gatewayMetaData = stack.getPrimaryGatewayInstance();
            DetailedEnvironmentResponse environment = environmentClientService.getByCrnAsInternal(stack.getEnvironmentCrn());
            CloudInstance gatewayInstance = metadataConverter.convert(gatewayMetaData, environment, stack.getStackAuthentication());
            return new GetSSHFingerprintsRequest<GetSSHFingerprintsResult>(context.getCloudContext(), context.getCloudCredential(), gatewayInstance);
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) GetTlsInfoResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Map(java.util.Map) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Bean(org.springframework.context.annotation.Bean)

Aggregations

StackCreationContext (com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext)14 Map (java.util.Map)13 Bean (org.springframework.context.annotation.Bean)13 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)7 Optional (java.util.Optional)7 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)6 AbstractStackCreationAction (com.sequenceiq.cloudbreak.core.flow2.stack.provision.action.AbstractStackCreationAction)6 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)6 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)6 GetTlsInfoResult (com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult)4 GetSSHFingerprintsRequest (com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest)3 GetSSHFingerprintsResult (com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult)3 GetTlsInfoRequest (com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoRequest)3 CollectLoadBalancerMetadataResult (com.sequenceiq.cloudbreak.cloud.event.loadbalancer.CollectLoadBalancerMetadataResult)3 CreateCredentialRequest (com.sequenceiq.cloudbreak.cloud.event.resource.CreateCredentialRequest)3 PrepareImageRequest (com.sequenceiq.cloudbreak.cloud.event.setup.PrepareImageRequest)3 SetupResult (com.sequenceiq.cloudbreak.cloud.event.setup.SetupResult)3 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)3 Image (com.sequenceiq.cloudbreak.cloud.model.Image)3 TlsInfo (com.sequenceiq.cloudbreak.cloud.model.TlsInfo)3