Search in sources :

Example 21 with SdxContext

use of com.sequenceiq.datalake.flow.SdxContext in project cloudbreak by hortonworks.

the class DatalakeBackupActions method datalakeFullBackupInProgress.

@Bean(name = "DATALAKE_FULL_BACKUP_IN_PROGRESS_STATE")
public Action<?, ?> datalakeFullBackupInProgress() {
    return new AbstractSdxAction<>(SdxEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Full datalake backup is in progress for {} ", payload.getResourceId());
            String operationId = (String) variables.get(OPERATION_ID);
            String backupId = (String) variables.get(BACKUP_ID);
            SdxCluster sdxCluster = sdxService.getById(payload.getResourceId());
            eventSenderService.sendEventAndNotification(sdxCluster, ThreadBasedUserCrnProvider.getUserCrn(), DATALAKE_DATABASE_BACKUP_FINISHED);
            SdxDatabaseBackupStatusResponse backupStatusResponse = sdxBackupRestoreService.getDatabaseBackupStatus(sdxCluster, operationId);
            if (backupStatusResponse.getStatus().equals(DatalakeDatabaseDrStatus.INPROGRESS)) {
                sdxBackupRestoreService.updateDatabaseStatusEntry(operationId, SdxOperationStatus.SUCCEEDED, null);
            }
            sendEvent(context, DatalakeFullBackupWaitRequest.from(context, backupId));
        }

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

Example 22 with SdxContext

use of com.sequenceiq.datalake.flow.SdxContext in project cloudbreak by hortonworks.

the class SdxRepairActions method finishedAction.

@Bean(name = "SDX_REPAIR_FINISHED_STATE")
public Action<?, ?> finishedAction() {
    return new AbstractSdxAction<>(SdxRepairSuccessEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxRepairSuccessEvent payload, Map<Object, Object> variables) throws Exception {
            LOGGER.info("Datalake repair finalized: {}", payload.getResourceId());
            SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.RUNNING, ResourceEvent.SDX_REPAIR_FINISHED, "Repair finished, Datalake is running", payload.getResourceId());
            metricService.incrementMetricCounter(MetricType.SDX_REPAIR_FINISHED, sdxCluster);
            jobService.schedule(sdxCluster.getId(), SdxClusterJobAdapter.class);
            sendEvent(context, SDX_REPAIR_FINALIZED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxRepairSuccessEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxRepairSuccessEvent(com.sequenceiq.datalake.flow.repair.event.SdxRepairSuccessEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 23 with SdxContext

use of com.sequenceiq.datalake.flow.SdxContext in project cloudbreak by hortonworks.

the class SdxRepairActions method sdxRepairStarted.

@Bean(name = "SDX_REPAIR_START_STATE")
public Action<?, ?> sdxRepairStarted() {
    return new AbstractSdxAction<>(SdxRepairStartEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxRepairStartEvent payload, Map<Object, Object> variables) throws Exception {
            LOGGER.info("Start repair flow for Datalake: {}", payload.getResourceId());
            SdxRepairStartRequest request = new SdxRepairStartRequest(payload.getResourceId(), payload.getUserId(), payload.getRepairSettings());
            sendEvent(context, request.selector(), request);
        }

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

Example 24 with SdxContext

use of com.sequenceiq.datalake.flow.SdxContext in project cloudbreak by hortonworks.

the class UpgradeCcmActions method finishedAction.

@Bean(name = "UPGRADE_CCM_FINISHED_STATE")
public Action<?, ?> finishedAction() {
    return new AbstractUpgradeCcmSdxAction<>(UpgradeCcmSuccessEvent.class) {

        @Override
        protected void doExecute(SdxContext context, UpgradeCcmSuccessEvent payload, Map<Object, Object> variables) {
            LOGGER.info("CCM upgrade finalized for SDX: {}", payload.getResourceId());
            SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.RUNNING, "Cluster Connectivity Manager upgrade completed successfully", payload.getResourceId());
            metricService.incrementMetricCounter(MetricType.UPGRADE_CCM_FINISHED, sdxCluster);
            sendEvent(context, UPGRADE_CCM_FINALIZED_EVENT.event(), payload);
        }
    };
}
Also used : UpgradeCcmSuccessEvent(com.sequenceiq.datalake.flow.upgrade.ccm.event.UpgradeCcmSuccessEvent) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 25 with SdxContext

use of com.sequenceiq.datalake.flow.SdxContext 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

SdxContext (com.sequenceiq.datalake.flow.SdxContext)61 Map (java.util.Map)57 Bean (org.springframework.context.annotation.Bean)57 FlowParameters (com.sequenceiq.flow.core.FlowParameters)56 Optional (java.util.Optional)53 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)52 StateContext (org.springframework.statemachine.StateContext)52 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)32 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)18 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)8 Flow (com.sequenceiq.flow.core.Flow)8 PollerStoppedException (com.dyngr.exception.PollerStoppedException)7 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)7 DatalakeStatusUpdateException (com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException)5 DatalakeStatusEnum (com.sequenceiq.datalake.entity.DatalakeStatusEnum)4 DatalakeTriggerRestoreEvent (com.sequenceiq.datalake.flow.dr.restore.event.DatalakeTriggerRestoreEvent)4 DatalakeRestoreStatusResponse (com.sequenceiq.cloudbreak.datalakedr.model.DatalakeRestoreStatusResponse)3 SdxCertRenewalFailedEvent (com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent)3 SdxCertRotationFailedEvent (com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationFailedEvent)3 SdxDetachFailedEvent (com.sequenceiq.datalake.flow.detach.event.SdxDetachFailedEvent)3