Search in sources :

Example 1 with AbstractAction

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

the class EnvClustersDeleteActionsTest method configureAction.

private Action<?, ?> configureAction(Supplier<Action<?, ?>> actionSupplier) {
    Action<?, ?> action = actionSupplier.get();
    assertThat(action).isNotNull();
    setActionPrivateFields(action);
    AbstractAction abstractAction = (AbstractAction) action;
    abstractAction.setFailureEvent(failureEvent);
    return action;
}
Also used : AbstractAction(com.sequenceiq.flow.core.AbstractAction)

Example 2 with AbstractAction

use of com.sequenceiq.flow.core.AbstractAction 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)

Example 3 with AbstractAction

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

the class ExternalDatabaseCreationActionsTest method configureAction.

private Action<?, ?> configureAction(Supplier<Action<?, ?>> actionSupplier) {
    Action<?, ?> action = actionSupplier.get();
    assertThat(action).isNotNull();
    setActionPrivateFields(action);
    AbstractAction abstractAction = (AbstractAction) action;
    abstractAction.setFailureEvent(failureEvent);
    return action;
}
Also used : AbstractAction(com.sequenceiq.flow.core.AbstractAction)

Example 4 with AbstractAction

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

the class ExternalDatabaseStopActionsTest method configureAction.

private Action<?, ?> configureAction(Supplier<Action<?, ?>> actionSupplier) {
    Action<?, ?> action = actionSupplier.get();
    assertThat(action).isNotNull();
    setActionPrivateFields(action);
    AbstractAction abstractAction = (AbstractAction) action;
    abstractAction.setFailureEvent(failureEvent);
    return action;
}
Also used : AbstractAction(com.sequenceiq.flow.core.AbstractAction)

Example 5 with AbstractAction

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

the class DatalakeRestoreActionsTest method testGetNewSdxIdForResizeDoExecute.

@Test
public void testGetNewSdxIdForResizeDoExecute() throws Exception {
    when(sdxBackupRestoreService.triggerDatalakeRestore(eq(NEW_SDX_ID), any(), any(), eq(USER_CRN))).thenReturn(new DatalakeRestoreStatusResponse(BACKUP_ID, RESTORE_ID, State.STARTED, Optional.empty()));
    DatalakeTriggerRestoreEvent event = new DatalakeTriggerRestoreEvent(DATALAKE_TRIGGER_RESTORE_EVENT.event(), NEW_SDX_ID, DATALAKE_NAME, USER_CRN, null, BACKUP_LOCATION, null, DatalakeRestoreFailureReason.RESTORE_ON_RESIZE);
    AbstractAction action = (AbstractAction) underTest.triggerDatalakeRestore();
    initActionPrivateFields(action);
    AbstractActionTestSupport testSupport = new AbstractActionTestSupport(action);
    SdxContext context = SdxContext.from(new FlowParameters(FLOW_ID, FLOW_ID, null), event);
    testSupport.doExecute(context, event, new HashMap());
    ArgumentCaptor<DatalakeDatabaseRestoreStartEvent> captor = ArgumentCaptor.forClass(DatalakeDatabaseRestoreStartEvent.class);
    verify(reactorEventFactory, times(1)).createEvent(any(), captor.capture());
    DatalakeDatabaseRestoreStartEvent captorValue = captor.getValue();
    Assertions.assertEquals(NEW_SDX_ID, captorValue.getResourceId());
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) DatalakeTriggerRestoreEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent) HashMap(java.util.HashMap) AbstractActionTestSupport(com.sequenceiq.flow.core.AbstractActionTestSupport) DatalakeDatabaseRestoreStartEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreStartEvent) AbstractAction(com.sequenceiq.flow.core.AbstractAction) DatalakeRestoreStatusResponse(com.sequenceiq.cloudbreak.datalakedr.model.DatalakeRestoreStatusResponse) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Test(org.junit.jupiter.api.Test)

Aggregations

AbstractAction (com.sequenceiq.flow.core.AbstractAction)15 FlowParameters (com.sequenceiq.flow.core.FlowParameters)6 SdxContext (com.sequenceiq.datalake.flow.SdxContext)4 AbstractActionTestSupport (com.sequenceiq.flow.core.AbstractActionTestSupport)4 Test (org.junit.jupiter.api.Test)4 DatalakeTriggerRestoreEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent)3 HashMap (java.util.HashMap)3 DatalakeRestoreStatusResponse (com.sequenceiq.cloudbreak.datalakedr.model.DatalakeRestoreStatusResponse)2 DatalakeDatabaseRestoreStartEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreStartEvent)2 Flow (com.sequenceiq.flow.core.Flow)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Bean (org.springframework.context.annotation.Bean)2 StateContext (org.springframework.statemachine.StateContext)2 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)1 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)1 ClusterUpgradeContext (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.ClusterUpgradeContext)1 ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.config.ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent)1 ClusterUpgradeValidationFailureEvent (com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationFailureEvent)1 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)1