Search in sources :

Example 21 with StackContext

use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.

the class AbstractUserDataUpdateAction method createFlowContext.

@Override
protected StackContext createFlowContext(FlowParameters flowParameters, StateContext<UpdateUserDataState, UpdateUserDataEvents> stateContext, P payload) {
    Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
    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()).withLocation(location).withUserName(stack.getOwner()).withAccountId(stack.getAccountId()).build();
    CloudCredential cloudCredential = credentialConverter.convert(credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn()));
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    return new StackContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.freeipa.entity.Stack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 22 with StackContext

use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.

the class UserDataUpdateActions method updateUserData.

@Bean(name = "UPDATE_USERDATA_STATE")
public AbstractUserDataUpdateAction<?> updateUserData() {
    return new AbstractUserDataUpdateAction<>(UserDataUpdateRequest.class) {

        @Override
        protected void doExecute(StackContext context, UserDataUpdateRequest payload, Map<Object, Object> variables) throws Exception {
            LOGGER.info("Recreate userdata for new freeipa instances");
            setOperationId(variables, payload.getOperationId());
            setChainedAction(variables, payload.isChained());
            setFinalChain(variables, payload.isFinal());
            sendEvent(context, new UserDataUpdateRequest(context.getStack().getId(), payload.getOldTunnel()));
        }

        @Override
        protected Object getFailurePayload(UserDataUpdateRequest payload, Optional<StackContext> flowContext, Exception ex) {
            return new UserDataUpdateFailed(payload.getResourceId(), ex);
        }
    };
}
Also used : Optional(java.util.Optional) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) UserDataUpdateRequest(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateRequest) UserDataUpdateFailed(com.sequenceiq.freeipa.flow.stack.update.event.UserDataUpdateFailed) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 23 with StackContext

use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.

the class AbstractStackProvisionAction method createFlowContext.

@Override
protected StackContext createFlowContext(FlowParameters flowParameters, StateContext<StackProvisionState, StackProvisionEvent> stateContext, P payload) {
    Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
    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()).withLocation(location).withUserName(stack.getOwner()).withAccountId(stack.getAccountId()).build();
    CloudCredential cloudCredential = credentialConverter.convert(credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn()));
    CloudStack cloudStack = cloudStackConverter.convert(stack);
    return new StackContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.freeipa.entity.Stack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 24 with StackContext

use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.

the class StackProvisionActions method prepareImageAction.

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

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

        @Override
        protected Selectable createRequest(StackContext context) {
            CloudStack cloudStack = cloudStackConverter.convert(context.getStack());
            Image image = imageConverter.convert(imageService.getByStack(context.getStack()));
            return new PrepareImageRequest<>(context.getCloudContext(), context.getCloudCredential(), cloudStack, image);
        }
    };
}
Also used : SetupResult(com.sequenceiq.cloudbreak.cloud.event.setup.SetupResult) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) 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 25 with StackContext

use of com.sequenceiq.freeipa.flow.stack.StackContext in project cloudbreak by hortonworks.

the class StackProvisionActions method collectMetadataAction.

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

        @Override
        protected void doExecute(StackContext context, CollectMetadataResult payload, Map<Object, Object> variables) {
            Stack stack = stackProvisionService.setupMetadata(context, payload);
            StackContext newContext = new StackContext(context.getFlowParameters(), stack, context.getCloudContext(), context.getCloudCredential(), context.getCloudStack());
            if (newContext.getStack().getTunnel().useCcm()) {
                GetTlsInfoResult getTlsInfoResult = new GetTlsInfoResult(context.getCloudContext().getId(), new TlsInfo(true));
                sendEvent(newContext, getTlsInfoResult.selector(), getTlsInfoResult);
            } else {
                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.freeipa.flow.stack.StackContext) TlsInfo(com.sequenceiq.cloudbreak.cloud.model.TlsInfo) GetTlsInfoResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoResult) 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.freeipa.entity.Stack) GetTlsInfoRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetTlsInfoRequest) Bean(org.springframework.context.annotation.Bean)

Aggregations

StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)57 Map (java.util.Map)49 Bean (org.springframework.context.annotation.Bean)48 Stack (com.sequenceiq.freeipa.entity.Stack)45 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)30 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)30 FlowParameters (com.sequenceiq.flow.core.FlowParameters)11 List (java.util.List)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)10 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)10 ClientErrorException (javax.ws.rs.ClientErrorException)10 EnvironmentEndpoint (com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint)9 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)9 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)9 Collectors (java.util.stream.Collectors)9 Inject (javax.inject.Inject)9 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)8 Flow (com.sequenceiq.flow.core.Flow)8 Configuration (org.springframework.context.annotation.Configuration)8 Action (org.springframework.statemachine.action.Action)8