Search in sources :

Example 6 with AbstractAction

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

the class UpgradeCcmActionsTest 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 7 with AbstractAction

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

the class ClusterUpgradeValidationActions method clusterUpgradeValidationFailed.

@Bean(name = "CLUSTER_UPGRADE_VALIDATION_FAILED_STATE")
public Action<?, ?> clusterUpgradeValidationFailed() {
    return new AbstractAction<ClusterUpgradeValidationState, ClusterUpgradeValidationStateSelectors, ClusterUpgradeContext, ClusterUpgradeValidationFailureEvent>(ClusterUpgradeValidationFailureEvent.class) {

        @Inject
        private CloudbreakMessagesService messagesService;

        @Inject
        private StackUpdater stackUpdater;

        @Override
        protected ClusterUpgradeContext createFlowContext(FlowParameters flowParameters, StateContext<ClusterUpgradeValidationState, ClusterUpgradeValidationStateSelectors> stateContext, ClusterUpgradeValidationFailureEvent payload) {
            StackView stackView = stackService.getViewByIdWithoutAuth(payload.getResourceId());
            MDCBuilder.buildMdcContext(stackView);
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            return ClusterUpgradeContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(ClusterUpgradeContext context, ClusterUpgradeValidationFailureEvent payload, Map<Object, Object> variables) {
            String errorMessage = payload.getException().getMessage();
            Long resourceId = payload.getResourceId();
            LOGGER.debug("Cluster upgrade validation failed with validation error: {}", errorMessage);
            ResourceEvent validationFailedResourceEvent = ResourceEvent.CLUSTER_UPGRADE_VALIDATION_FAILED;
            cloudbreakEventService.fireCloudbreakEvent(resourceId, UPDATE_FAILED.name(), validationFailedResourceEvent, List.of(errorMessage));
            String reason = messagesService.getMessage(validationFailedResourceEvent.getMessage(), List.of(errorMessage));
            stackUpdater.updateStackStatus(resourceId, DetailedStackStatus.AVAILABLE, reason);
            sendEvent(context, HANDLED_FAILED_CLUSTER_UPGRADE_VALIDATION_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(ClusterUpgradeValidationFailureEvent payload, Optional<ClusterUpgradeContext> flowContext, Exception ex) {
            LOGGER.warn("No failure payload in case of CLUSTER_UPGRADE_VALIDATION_FAILED_STATE. This should not happen.", ex);
            return null;
        }

        @Override
        protected void initPayloadConverterMap(List<PayloadConverter<ClusterUpgradeValidationFailureEvent>> payloadConverters) {
            payloadConverters.add(new ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent());
        }
    };
}
Also used : StackUpdater(com.sequenceiq.cloudbreak.service.StackUpdater) ClusterUpgradeContext(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.ClusterUpgradeContext) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Flow(com.sequenceiq.flow.core.Flow) FlowParameters(com.sequenceiq.flow.core.FlowParameters) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) List(java.util.List) ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.config.ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) AbstractAction(com.sequenceiq.flow.core.AbstractAction) Map(java.util.Map) ClusterUpgradeValidationFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeValidationFailureEvent) ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.config.ClusterUpgradeUpdateCheckFailedToClusterUpgradeValidationFailureEvent) Bean(org.springframework.context.annotation.Bean)

Example 8 with AbstractAction

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

the class ExternalDatabaseTerminationActionsTest 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 9 with AbstractAction

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

the class ExternalDatabaseStartActionsTest 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 10 with AbstractAction

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

the class DatalakeRestoreActionsTest method testGetNewSdxIdForResizeCreateFlowContext.

@Test
public void testGetNewSdxIdForResizeCreateFlowContext() throws Exception {
    SdxCluster sdxCluster = genCluster();
    FlowParameters flowParameters = new FlowParameters(FLOW_ID, null, null);
    when(sdxService.getByNameInAccount(eq(USER_CRN), eq(DATALAKE_NAME))).thenReturn(sdxCluster);
    when(flowLogService.getLastFlowLog(anyString())).thenReturn(Optional.of(new FlowLog()));
    FlowChainLog flowChainLog = new FlowChainLog();
    flowChainLog.setFlowChainType(DatalakeResizeFlowEventChainFactory.class.getSimpleName());
    when(flowChainLogService.findFirstByFlowChainIdOrderByCreatedDesc(any())).thenReturn(Optional.of(flowChainLog));
    DatalakeTriggerRestoreEvent event = new DatalakeTriggerRestoreEvent(DATALAKE_TRIGGER_RESTORE_EVENT.event(), OLD_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) testSupport.createFlowContext(flowParameters, null, event);
    Assert.assertEquals(NEW_SDX_ID, context.getSdxId());
    Assert.assertEquals(USER_CRN, context.getUserId());
    Assert.assertEquals(FLOW_ID, context.getFlowId());
    Assert.assertEquals(NEW_SDX_ID, event.getDrStatus().getSdxClusterId());
    flowChainLog.setFlowChainType(DatalakeUpgradeFlowEventChainFactory.class.getSimpleName());
    context = (SdxContext) testSupport.createFlowContext(flowParameters, null, event);
    Assert.assertEquals(OLD_SDX_ID, context.getSdxId());
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) DatalakeTriggerRestoreEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent) DatalakeUpgradeFlowEventChainFactory(com.sequenceiq.datalake.flow.chain.DatalakeUpgradeFlowEventChainFactory) FlowLog(com.sequenceiq.flow.domain.FlowLog) AbstractActionTestSupport(com.sequenceiq.flow.core.AbstractActionTestSupport) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) DatalakeResizeFlowEventChainFactory(com.sequenceiq.datalake.flow.chain.DatalakeResizeFlowEventChainFactory) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog) AbstractAction(com.sequenceiq.flow.core.AbstractAction) 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