Search in sources :

Example 41 with AbstractSdxAction

use of com.sequenceiq.datalake.service.AbstractSdxAction in project cloudbreak by hortonworks.

the class DatahubRefreshActions method datahubRefreshInProgressAction.

@Bean(name = "DATAHUB_REFRESH_IN_PROGRESS_STATE")
public Action<?, ?> datahubRefreshInProgressAction() {
    return new AbstractSdxAction<>(DatahubRefreshStartEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatahubRefreshStartEvent payload, Map<Object, Object> variables) throws Exception {
            LOGGER.info("Datahub refresh in progress for: {}", payload.getResourceId());
            sendEvent(context, new DatahubRefreshWaitEvent(payload.getResourceId(), payload.getUserId()));
        }

        @Override
        protected Object getFailurePayload(DatahubRefreshStartEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return new DatahubRefreshFailedEvent(payload.getResourceId(), payload.getUserId(), ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) DatahubRefreshWaitEvent(com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshWaitEvent) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) DatahubRefreshFailedEvent(com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshFailedEvent) StateContext(org.springframework.statemachine.StateContext) Map(java.util.Map) DatahubRefreshStartEvent(com.sequenceiq.datalake.flow.refresh.event.DatahubRefreshStartEvent) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 42 with AbstractSdxAction

use of com.sequenceiq.datalake.service.AbstractSdxAction in project cloudbreak by hortonworks.

the class DatalakeBackupActions method backupCouldNotStart.

@Bean(name = "DATALAKE_DATABASE_BACKUP_COULD_NOT_START_STATE")
public Action<?, ?> backupCouldNotStart() {
    return new AbstractSdxAction<>(DatalakeDatabaseBackupCouldNotStartEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatalakeDatabaseBackupCouldNotStartEvent payload, Map<Object, Object> variables) {
            Exception exception = payload.getException();
            LOGGER.error("Datalake database backup could not be started for datalake with id: {}", payload.getResourceId(), exception);
            String operationId = (String) variables.get(OPERATION_ID);
            sdxBackupRestoreService.updateDatabaseStatusEntry(operationId, SdxOperationStatus.FAILED, payload.getException().getMessage());
            SdxCluster sdxCluster = sdxService.getById(payload.getResourceId());
            eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.DATALAKE_DATABASE_BACKUP_FAILED);
            sendEvent(context, DATALAKE_DATABASE_BACKUP_FAILURE_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(DatalakeDatabaseBackupCouldNotStartEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeDatabaseBackupFailedEvent.from(payload, ex);
        }
    };
}
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) DatalakeDatabaseBackupCouldNotStartEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeDatabaseBackupCouldNotStartEvent) Map(java.util.Map) PollerStoppedException(com.dyngr.exception.PollerStoppedException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 43 with AbstractSdxAction

use of com.sequenceiq.datalake.service.AbstractSdxAction in project cloudbreak by hortonworks.

the class SdxDetachActions method sdxDetachExternalDBFailedAction.

@Bean(name = "SDX_DETACH_EXTERNAL_DB_FAILED_STATE")
public Action<?, ?> sdxDetachExternalDBFailedAction() {
    return new AbstractSdxAction<>(SdxDetachFailedEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxDetachFailedEvent payload, Map<Object, Object> variables) {
            if (!((boolean) variables.get(IS_DETACH_DURING_RECOVERY))) {
                SdxCluster detached = (SdxCluster) variables.get(DETACHED_SDX);
                LOGGER.error("Failed to detach external DB of SDX with ID: {}. Attempting to restore it.", detached.getId());
                String detachedName = detached.getClusterName();
                SdxCluster reattached = sdxAttachService.reattachCluster(detached);
                sdxAttachService.reattachStack(reattached, detachedName);
                LOGGER.info("Successfully restored detached SDX with ID {} which failed to detach its external database.", reattached.getId());
            }
            sendEvent(context, SDX_DETACH_FAILED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxDetachFailedEvent payload, Optional<SdxContext> flowContext, Exception e) {
            LOGGER.error("Failed to reattach SDX with ID {} which failed to detach its external database.", payload.getResourceId());
            return payload;
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxDetachFailedEvent(com.sequenceiq.datalake.flow.detach.event.SdxDetachFailedEvent) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 44 with AbstractSdxAction

use of com.sequenceiq.datalake.service.AbstractSdxAction in project cloudbreak by hortonworks.

the class SdxDetachActions method sdxDetachStackFailedAction.

@Bean(name = "SDX_DETACH_STACK_FAILED_STATE")
public Action<?, ?> sdxDetachStackFailedAction() {
    return new AbstractSdxAction<>(SdxDetachFailedEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxDetachFailedEvent payload, Map<Object, Object> variables) {
            if (!((boolean) variables.get(IS_DETACH_DURING_RECOVERY))) {
                SdxCluster clusterToReattach = (SdxCluster) variables.get(DETACHED_SDX);
                LOGGER.error("Failed to detach stack of SDX with ID: {}. Attempting to restore it.", clusterToReattach.getId());
                clusterToReattach = sdxAttachService.reattachCluster(clusterToReattach);
                LOGGER.info("Successfully restored detached SDX with ID {} which failed to detach its stack.", clusterToReattach.getId());
            }
            sendEvent(context, SDX_DETACH_FAILED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxDetachFailedEvent payload, Optional<SdxContext> flowContext, Exception e) {
            LOGGER.error("Failed to reattach SDX with ID {} which failed to detach its stack.", payload.getResourceId());
            return payload;
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxDetachFailedEvent(com.sequenceiq.datalake.flow.detach.event.SdxDetachFailedEvent) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 45 with AbstractSdxAction

use of com.sequenceiq.datalake.service.AbstractSdxAction in project cloudbreak by hortonworks.

the class SdxDetachRecoveryActions method sdxDetachRecoveryAction.

@Bean(name = "SDX_DETACH_RECOVERY_STATE")
public Action<?, ?> sdxDetachRecoveryAction() {
    return new AbstractSdxAction<>(SdxStartDetachRecoveryEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxStartDetachRecoveryEvent payload, Map<Object, Object> variables) throws Exception {
            SdxCluster clusterToReattach = sdxService.getById(payload.getResourceId());
            clusterToReattach = sdxAttachService.reattachDetachedSdxCluster(clusterToReattach);
            LOGGER.info("Successfully restored detached SDX with ID {}.", clusterToReattach.getId());
            sendEvent(context, SDX_DETACH_RECOVERY_SUCCESS_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxStartDetachRecoveryEvent payload, Optional<SdxContext> flowContext, Exception e) {
            LOGGER.error("Failed to recover from detach of SDX with ID {}.", payload.getResourceId());
            return SdxDetachRecoveryFailedEvent.from(payload, e);
        }
    };
}
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) Map(java.util.Map) SdxStartDetachRecoveryEvent(com.sequenceiq.datalake.flow.detach.event.SdxStartDetachRecoveryEvent) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Aggregations

SdxContext (com.sequenceiq.datalake.flow.SdxContext)52 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)52 FlowParameters (com.sequenceiq.flow.core.FlowParameters)52 Map (java.util.Map)52 Optional (java.util.Optional)52 Bean (org.springframework.context.annotation.Bean)52 StateContext (org.springframework.statemachine.StateContext)52 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)29 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)16 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)6 DatalakeStatusEnum (com.sequenceiq.datalake.entity.DatalakeStatusEnum)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 SdxFailedEvent (com.sequenceiq.datalake.flow.SdxFailedEvent)2 DatalakeChangeImageWaitRequest (com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeChangeImageWaitRequest)2