Search in sources :

Example 61 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class SdxCreateActions method storageValidation.

@Bean(name = "SDX_CREATION_STORAGE_VALIDATION_STATE")
public Action<?, ?> storageValidation() {
    return new AbstractSdxAction<>(SdxEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) throws Exception {
            // When SDX is created as part of re-size flow chain, SDX in payload will not have the correct ID.
            setCorrectSdxIdIfNecessary(context, payload);
            StorageValidationRequest req = new StorageValidationRequest(context);
            sendEvent(context, req.selector(), req);
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return SdxCreateFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) StorageValidationRequest(com.sequenceiq.datalake.flow.create.event.StorageValidationRequest) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 62 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class CertRotationActions method certRotationFinishedAction.

@Bean(name = "CERT_ROTATION_FINISHED_STATE")
public Action<?, ?> certRotationFinishedAction() {
    return new AbstractSdxAction<>(SdxEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Cert rotation is finished");
            certRotationService.finalizeCertRotation(payload.getResourceId());
            SdxEvent event = new SdxEvent(SdxCertRotationEvent.CERT_ROTATION_FINALIZED_EVENT.event(), context);
            sendEvent(context, event);
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return new SdxCertRotationFailedEvent(payload, ex);
        }
    };
}
Also used : SdxCertRotationFailedEvent(com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationFailedEvent) FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 63 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class CertRotationActions method starCertRotationAction.

@Bean(name = "START_CERT_ROTATION_STATE")
public Action<?, ?> starCertRotationAction() {
    return new AbstractSdxAction<>(SdxStartCertRotationEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SdxStartCertRotationEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, SdxStartCertRotationEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Start cert rotation with request: {}", payload.getRequest());
            certRotationService.startCertRotation(context.getSdxId(), payload.getRequest());
            SdxEvent sdxEvent = new SdxEvent(SdxCertRotationEvent.CERT_ROTATION_STARTED_EVENT.event(), payload.getResourceId(), payload.getUserId());
            sendEvent(context, sdxEvent);
        }

        @Override
        protected Object getFailurePayload(SdxStartCertRotationEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return new SdxCertRotationFailedEvent(payload, ex);
        }
    };
}
Also used : SdxCertRotationFailedEvent(com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationFailedEvent) SdxStartCertRotationEvent(com.sequenceiq.datalake.flow.cert.rotation.event.SdxStartCertRotationEvent) FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 64 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class AbstractStackTerminationAction method createFlowContext.

@Override
protected StackTerminationContext createFlowContext(FlowParameters flowParameters, StateContext<StackTerminationState, StackTerminationEvent> stateContext, P payload) {
    Map<Object, Object> variables = stateContext.getExtendedState().getVariables();
    TerminationType terminationType = (TerminationType) variables.getOrDefault(TERMINATION_TYPE, TerminationType.REGULAR);
    Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
    stack.setResources(new HashSet<>(resourceService.getAllByStackId(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()).withOriginalName(stack.getOriginalName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformVariant()).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);
    List<CloudResource> resources = stack.getResources().stream().map(r -> cloudResourceConverter.convert(r)).collect(Collectors.toList());
    return createStackTerminationContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, resources, terminationType);
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Payload(com.sequenceiq.cloudbreak.common.event.Payload) AvailabilityZone.availabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) Location.location(com.sequenceiq.cloudbreak.cloud.model.Location.location) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) ResourceService(com.sequenceiq.cloudbreak.service.resource.ResourceService) StateContext(org.springframework.statemachine.StateContext) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) AbstractStackAction(com.sequenceiq.cloudbreak.core.flow2.AbstractStackAction) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Region.region(com.sequenceiq.cloudbreak.cloud.model.Region.region) FlowParameters(com.sequenceiq.flow.core.FlowParameters) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) TerminationType(com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationType) Collectors(java.util.stream.Collectors) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) Optional(java.util.Optional) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) TerminationType(com.sequenceiq.cloudbreak.reactor.api.event.stack.TerminationType) 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) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Location(com.sequenceiq.cloudbreak.cloud.model.Location)

Example 65 with FlowParameters

use of com.sequenceiq.flow.core.FlowParameters in project cloudbreak by hortonworks.

the class StackImageUpdateActionsTest method setup.

@Before
public void setup() throws CloudbreakImageNotFoundException {
    MockitoAnnotations.initMocks(this);
    when(stateContext.getMessageHeader(HEADERS.FLOW_PARAMETERS.name())).thenReturn(new FlowParameters("flowId", "usercrn", null));
    when(stateContext.getExtendedState()).thenReturn(extendedState);
    when(stateContext.getStateMachine()).thenReturn(stateMachine);
    when(stateMachine.getState()).thenReturn(state);
    when(extendedState.getVariables()).thenReturn(variables);
    when(runningFlows.getFlowChainId(anyString())).thenReturn("flowchainid");
    when(reactorEventFactory.createEvent(any(Map.class), any(Object.class))).thenReturn(new Event("dummy"));
    when(imageService.getImage(anyLong())).thenReturn(image);
    when(tracer.buildSpan(anyString())).thenReturn(spanBuilder);
    when(spanBuilder.addReference(anyString(), any())).thenReturn(spanBuilder);
    when(spanBuilder.ignoreActiveSpan()).thenReturn(spanBuilder);
    when(spanBuilder.start()).thenReturn(span);
    when(tracer.activateSpan(span)).thenReturn(scope);
    when(span.context()).thenReturn(spanContext);
    User user = new User();
    user.setUserId("horton@hortonworks.com");
    user.setUserCrn("testCrn");
    user.setUserName("Alma ur");
    Tenant tenant = new Tenant();
    tenant.setName("hortonworks");
    tenant.setId(1L);
    Workspace workspace = new Workspace();
    workspace.setId(1L);
    workspace.setTenant(tenant);
    Stack stack = new Stack();
    stack.setCreator(user);
    stack.setWorkspace(workspace);
    stack.setId(1L);
    stack.setRegion("region");
    stack.setAvailabilityZone("az");
    stack.setResourceCrn("crn:cdp:datalake:us-west-1:tenant:cluster:1234");
    when(stackService.getByIdWithListsInTransaction(anyLong())).thenReturn(stack);
    when(stackService.getById(anyLong())).thenReturn(stack);
    when(stackUtil.getCloudCredential(stack)).thenReturn(cloudCredential);
    variables.clear();
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) User(com.sequenceiq.cloudbreak.workspace.model.User) Tenant(com.sequenceiq.cloudbreak.workspace.model.Tenant) FlowEvent(com.sequenceiq.flow.core.FlowEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) Event(reactor.bus.Event) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) ImageUpdateEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.ImageUpdateEvent) StackImageUpdateTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackImageUpdateTriggerEvent) Map(java.util.Map) HashMap(java.util.HashMap) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Before(org.junit.Before)

Aggregations

FlowParameters (com.sequenceiq.flow.core.FlowParameters)103 Map (java.util.Map)84 StateContext (org.springframework.statemachine.StateContext)84 Bean (org.springframework.context.annotation.Bean)81 Optional (java.util.Optional)67 SdxContext (com.sequenceiq.datalake.flow.SdxContext)56 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)52 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)31 Flow (com.sequenceiq.flow.core.Flow)28 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)16 Stack (com.sequenceiq.freeipa.entity.Stack)12 List (java.util.List)11 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)10 BeforeEach (org.junit.jupiter.api.BeforeEach)9 Test (org.junit.jupiter.api.Test)9 HashMap (java.util.HashMap)8 PollerStoppedException (com.dyngr.exception.PollerStoppedException)7 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)7 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)7 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)7