Search in sources :

Example 1 with SleepFailedEvent

use of com.sequenceiq.flow.component.sleep.event.SleepFailedEvent in project cloudbreak by hortonworks.

the class SleepFlow method sleepFailed.

@Bean("SLEEP_FAILED_STATE")
public Action<?, ?> sleepFailed() {
    return new AbstractAction<>(SleepFailedEvent.class) {

        @Override
        protected CommonContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, SleepFailedEvent payload) {
            return new CommonContext(flowParameters);
        }

        @Override
        protected void doExecute(CommonContext context, SleepFailedEvent payload, Map<Object, Object> variables) throws Exception {
            LOGGER.info("Sleep fail handled!");
            Flow flow = getFlow(context.getFlowId());
            flow.setFlowFailed(new Exception(payload.getReason()));
            sendEvent(context, SleepEvent.SLEEP_FAIL_HANDLED_EVENT.selector(), payload);
        }

        @Override
        protected Object getFailurePayload(SleepFailedEvent payload, Optional<CommonContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) Optional(java.util.Optional) SleepFailedEvent(com.sequenceiq.flow.component.sleep.event.SleepFailedEvent) CommonContext(com.sequenceiq.flow.core.CommonContext) StateContext(org.springframework.statemachine.StateContext) AbstractAction(com.sequenceiq.flow.core.AbstractAction) Map(java.util.Map) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Aggregations

SleepFailedEvent (com.sequenceiq.flow.component.sleep.event.SleepFailedEvent)1 AbstractAction (com.sequenceiq.flow.core.AbstractAction)1 CommonContext (com.sequenceiq.flow.core.CommonContext)1 Flow (com.sequenceiq.flow.core.Flow)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1