Search in sources :

Example 81 with FlowParameters

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

the class DatalakeBackupActions method triggerDatalakeBackup.

@Bean(name = "DATALAKE_TRIGGERING_BACKUP_STATE")
public Action<?, ?> triggerDatalakeBackup() {
    return new AbstractSdxAction<>(DatalakeTriggerBackupEvent.class) {

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

        @Override
        protected void prepareExecution(DatalakeTriggerBackupEvent payload, Map<Object, Object> variables) {
            variables.put(OPERATION_ID, payload.getDrStatus().getOperationId());
            variables.put(REASON, payload.getReason().name());
            super.prepareExecution(payload, variables);
        }

        @Override
        protected void doExecute(SdxContext context, DatalakeTriggerBackupEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Triggering data lake backup for {}", payload.getResourceId());
            SdxCluster sdxCluster = sdxService.getById(payload.getResourceId());
            eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.DATALAKE_BACKUP_IN_PROGRESS);
            DatalakeBackupStatusResponse backupStatusResponse = sdxBackupRestoreService.triggerDatalakeBackup(payload.getResourceId(), payload.getBackupLocation(), payload.getBackupName(), payload.getUserId());
            variables.put(BACKUP_ID, backupStatusResponse.getBackupId());
            variables.put(OPERATION_ID, backupStatusResponse.getBackupId());
            payload.getDrStatus().setOperationId(backupStatusResponse.getBackupId());
            if (!backupStatusResponse.failed()) {
                sendEvent(context, DatalakeDatabaseBackupStartEvent.from(payload, backupStatusResponse.getBackupId()));
            } else {
                sendEvent(context, DATALAKE_BACKUP_FAILED_EVENT.event(), payload);
            }
        }

        @Override
        protected Object getFailurePayload(DatalakeTriggerBackupEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeBackupFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) DatalakeBackupStatusResponse(com.sequenceiq.cloudbreak.datalakedr.model.DatalakeBackupStatusResponse) StateContext(org.springframework.statemachine.StateContext) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) PollerStoppedException(com.dyngr.exception.PollerStoppedException) DatalakeTriggerBackupEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeTriggerBackupEvent) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 82 with FlowParameters

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

the class SdxCmDiagnosticsActions method startCmDiagnosticsCollection.

@Bean(name = "CM_DIAGNOSTICS_COLLECTION_START_STATE")
public Action<?, ?> startCmDiagnosticsCollection() {
    return new AbstractSdxAction<>(SdxCmDiagnosticsCollectionEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxCmDiagnosticsCollectionEvent payload, Map<Object, Object> variables) {
            LOGGER.debug("Start CM based diagnostics collection for sdx cluster with id: {}", context.getSdxId());
            FlowIdentifier flowIdentifier = diagnosticsFlowService.startCmDiagnosticsCollection(payload.getProperties());
            SdxCmDiagnosticsCollectionEvent event = new SdxCmDiagnosticsCollectionEvent(payload.getResourceId(), payload.getUserId(), payload.getProperties(), flowIdentifier);
            sendEvent(context, SDX_CM_DIAGNOSTICS_COLLECTION_IN_PROGRESS_EVENT.event(), event);
        }

        @Override
        protected Object getFailurePayload(SdxCmDiagnosticsCollectionEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return SdxCmDiagnosticsFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) SdxCmDiagnosticsCollectionEvent(com.sequenceiq.datalake.flow.diagnostics.event.SdxCmDiagnosticsCollectionEvent) StateContext(org.springframework.statemachine.StateContext) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 83 with FlowParameters

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

Example 84 with FlowParameters

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

the class DatalakeRestoreActionsTest method testRestoreWithNoFlowChain.

@Test
public void testRestoreWithNoFlowChain() throws Exception {
    when(sdxBackupRestoreService.triggerDatalakeRestore(eq(OLD_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(), 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.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(OLD_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)

Example 85 with FlowParameters

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

the class DatahubRefreshActionsTest method testStartTriggersCall.

@Test
public void testStartTriggersCall() throws Exception {
    DatahubRefreshStartEvent event = new DatahubRefreshStartEvent(SDX_ID, SDX_NAME, USER_CRN);
    AbstractAction action = (AbstractAction) underTest.startDatahubRefreshAction();
    initActionPrivateFields(action);
    AbstractActionTestSupport testSupport = new AbstractActionTestSupport(action);
    SdxContext context = SdxContext.from(new FlowParameters(FLOW_ID, USER_CRN, null), event);
    testSupport.doExecute(context, event, new HashMap());
    ArgumentCaptor<DatahubRefreshStartEvent> captor = ArgumentCaptor.forClass(DatahubRefreshStartEvent.class);
    verify(reactorEventFactory, times(1)).createEvent(any(), captor.capture());
    DatahubRefreshStartEvent captorValue = captor.getValue();
    Assertions.assertEquals(SDX_NAME, captorValue.getSdxName());
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) HashMap(java.util.HashMap) AbstractActionTestSupport(com.sequenceiq.flow.core.AbstractActionTestSupport) AbstractAction(com.sequenceiq.flow.core.AbstractAction) DatahubRefreshStartEvent(com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshStartEvent) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Test(org.junit.jupiter.api.Test)

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