Search in sources :

Example 1 with Flow

use of com.sequenceiq.cloudbreak.core.flow2.Flow in project cloudbreak by hortonworks.

the class StackTerminationFailureAction method createFlowContext.

@Override
protected StackFailureContext createFlowContext(String flowId, StateContext<StackTerminationState, StackTerminationEvent> stateContext, StackFailureEvent payload) {
    Flow flow = getFlow(flowId);
    StackView stackView = stackService.getByIdView(payload.getStackId());
    MDCBuilder.buildMdcContext(stackView);
    flow.setFlowFailed(payload.getException());
    return new StackFailureContext(flowId, stackView);
}
Also used : StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) Flow(com.sequenceiq.cloudbreak.core.flow2.Flow)

Example 2 with Flow

use of com.sequenceiq.cloudbreak.core.flow2.Flow in project cloudbreak by hortonworks.

the class StackCreationActions method stackCreationFailureAction.

@Bean(name = "STACK_CREATION_FAILED_STATE")
public Action<?, ?> stackCreationFailureAction() {
    return new AbstractStackFailureAction<StackCreationState, StackCreationEvent>() {

        @Override
        protected StackFailureContext createFlowContext(String flowId, StateContext<StackCreationState, StackCreationEvent> stateContext, StackFailureEvent payload) {
            Flow flow = getFlow(flowId);
            StackView stackView = stackService.getByIdView(payload.getStackId());
            MDCBuilder.buildMdcContext(stackView);
            flow.setFlowFailed(payload.getException());
            return new StackFailureContext(flowId, stackView);
        }

        @Override
        protected void doExecute(StackFailureContext context, StackFailureEvent payload, Map<Object, Object> variables) {
            stackCreationService.handleStackCreationFailure(context.getStackView(), payload.getException());
            metricService.incrementMetricCounter(MetricType.STACK_CREATION_FAILED, context.getStackView());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackFailureContext context) {
            return new StackEvent(StackCreationEvent.STACKCREATION_FAILURE_HANDLED_EVENT.event(), context.getStackView().getId());
        }
    };
}
Also used : AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StateContext(org.springframework.statemachine.StateContext) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) Map(java.util.Map) Flow(com.sequenceiq.cloudbreak.core.flow2.Flow) Bean(org.springframework.context.annotation.Bean)

Example 3 with Flow

use of com.sequenceiq.cloudbreak.core.flow2.Flow in project cloudbreak by hortonworks.

the class AbstractFlowConfiguration method createFlow.

@Override
public Flow createFlow(String flowId, Long stackId) {
    StateMachine<S, E> sm = stateMachineFactory.getStateMachine();
    FlowStructuredEventHandler<S, E> fl = applicationContext.getBean(FlowStructuredEventHandler.class, getEdgeConfig().initState, getEdgeConfig().finalState, getClass().getSimpleName(), flowId, stackId);
    Flow flow = new FlowAdapter<>(flowId, sm, new MessageFactory<>(), new StateConverterAdapter<>(stateType), new EventConverterAdapter<>(eventType), (Class<? extends FlowConfiguration<E>>) getClass(), fl);
    sm.addStateListener(fl);
    return flow;
}
Also used : FlowAdapter(com.sequenceiq.cloudbreak.core.flow2.FlowAdapter) Flow(com.sequenceiq.cloudbreak.core.flow2.Flow)

Example 4 with Flow

use of com.sequenceiq.cloudbreak.core.flow2.Flow in project cloudbreak by hortonworks.

the class OfflineStateGenerator method generate.

private void generate() throws Exception {
    StringBuilder builder = new StringBuilder("digraph {\n");
    inject(flowConfiguration, "applicationContext", APP_CONTEXT);
    Flow flow = initializeFlow();
    StateMachine<FlowState, FlowEvent> stateMachine = getStateMachine(flow);
    FlowState init = stateMachine.getInitialState().getId();
    builder.append(generateStartPoint(init, flowConfiguration.getClass().getSimpleName())).append('\n');
    List<Transition<FlowState, FlowEvent>> transitions = (List<Transition<FlowState, FlowEvent>>) stateMachine.getTransitions();
    Map<String, FlowState> transitionsAlreadyDefined = new HashMap<>();
    transitionsAlreadyDefined.put(init.toString(), init);
    while (!transitions.isEmpty()) {
        for (Transition<FlowState, FlowEvent> transition : new ArrayList<>(transitions)) {
            FlowState source = transition.getSource().getId();
            FlowState target = transition.getTarget().getId();
            if (transitionsAlreadyDefined.values().contains(source)) {
                String id = generateTransitionId(source, target, transition.getTrigger().getEvent());
                if (!transitionsAlreadyDefined.keySet().contains(id)) {
                    if (target.action() != null && !transitionsAlreadyDefined.values().contains(target)) {
                        builder.append(generateState(target, target.action().getSimpleName())).append('\n');
                    }
                    builder.append(generateTransition(source, target, transition.getTrigger().getEvent())).append('\n');
                    transitionsAlreadyDefined.put(id, target);
                }
                transitions.remove(transition);
            }
        }
    }
    saveToFile(builder.append('}').toString());
}
Also used : FlowState(com.sequenceiq.cloudbreak.core.flow2.FlowState) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Flow(com.sequenceiq.cloudbreak.core.flow2.Flow) FlowEvent(com.sequenceiq.cloudbreak.core.flow2.FlowEvent) Transition(org.springframework.statemachine.transition.Transition) List(java.util.List) ArrayList(java.util.ArrayList)

Example 5 with Flow

use of com.sequenceiq.cloudbreak.core.flow2.Flow in project cloudbreak by hortonworks.

the class OfflineStateGenerator method initializeFlow.

private Flow initializeFlow() throws Exception {
    ((AbstractFlowConfiguration<?, ?>) flowConfiguration).init();
    Flow flow = flowConfiguration.createFlow("", 0L);
    flow.initialize();
    return flow;
}
Also used : AbstractFlowConfiguration(com.sequenceiq.cloudbreak.core.flow2.config.AbstractFlowConfiguration) Flow(com.sequenceiq.cloudbreak.core.flow2.Flow)

Aggregations

Flow (com.sequenceiq.cloudbreak.core.flow2.Flow)6 StackFailureContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext)2 StackSyncFlowConfig (com.sequenceiq.cloudbreak.core.flow2.stack.sync.StackSyncFlowConfig)2 StackTerminationFlowConfig (com.sequenceiq.cloudbreak.core.flow2.stack.termination.StackTerminationFlowConfig)2 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 Event (reactor.bus.Event)2 JsonReader (com.cedarsoftware.util.io.JsonReader)1 DetailedStackStatus (com.sequenceiq.cloudbreak.api.model.DetailedStackStatus)1 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)1 InstanceGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson)1 Acceptable (com.sequenceiq.cloudbreak.cloud.Acceptable)1 Payload (com.sequenceiq.cloudbreak.cloud.event.Payload)1 FlowAdapter (com.sequenceiq.cloudbreak.core.flow2.FlowAdapter)1 FlowEvent (com.sequenceiq.cloudbreak.core.flow2.FlowEvent)1 FlowState (com.sequenceiq.cloudbreak.core.flow2.FlowState)1 FlowChainHandler (com.sequenceiq.cloudbreak.core.flow2.chain.FlowChainHandler)1 FlowChains (com.sequenceiq.cloudbreak.core.flow2.chain.FlowChains)1