Search in sources :

Example 16 with AbstractSdxAction

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

the class DatalakeBackupActions method finishedBackupAction.

@Bean(name = "DATALAKE_BACKUP_FINISHED_STATE")
public Action<?, ?> finishedBackupAction() {
    return new AbstractSdxAction<>(DatalakeBackupSuccessEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatalakeBackupSuccessEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Sdx backup is finalized with sdx id: {}", payload.getResourceId());
            sendEvent(context, DATALAKE_DATABASE_BACKUP_FINALIZED_EVENT.event(), payload);
            SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.RUNNING, ResourceEvent.DATALAKE_BACKUP_FINISHED, "Datalake backup finished, Datalake is running", payload.getResourceId());
            eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.DATALAKE_BACKUP_FINISHED);
            metricService.incrementMetricCounter(MetricType.SDX_BACKUP_FINISHED, sdxCluster);
        }

        @Override
        protected Object getFailurePayload(DatalakeBackupSuccessEvent 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) DatalakeBackupSuccessEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeBackupSuccessEvent) Map(java.util.Map) PollerStoppedException(com.dyngr.exception.PollerStoppedException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 17 with AbstractSdxAction

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

the class DatalakeBackupActions method backupFailed.

@Bean(name = "DATALAKE_BACKUP_FAILED_STATE")
public Action<?, ?> backupFailed() {
    return new AbstractSdxAction<>(DatalakeBackupFailedEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatalakeBackupFailedEvent payload, Map<Object, Object> variables) {
            Exception exception = payload.getException();
            LOGGER.error("Datalake backup failed for datalake with id: {}", payload.getResourceId(), exception);
            SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.RUNNING, ResourceEvent.DATALAKE_BACKUP_FAILED, getFailureReason(variables, exception), payload.getResourceId());
            metricService.incrementMetricCounter(MetricType.SDX_BACKUP_FAILED, sdxCluster);
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(exception);
            eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.DATALAKE_BACKUP_FAILED, List.of(exception.getMessage()));
            sendEvent(context, DATALAKE_BACKUP_FAILURE_HANDLED_EVENT.event(), payload);
        }

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

Example 18 with AbstractSdxAction

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

the class DatalakeBackupActions method databaseBackupFailed.

@Bean(name = "DATALAKE_DATABASE_BACKUP_FAILED_STATE")
public Action<?, ?> databaseBackupFailed() {
    return new AbstractSdxAction<>(DatalakeDatabaseBackupFailedEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatalakeDatabaseBackupFailedEvent payload, Map<Object, Object> variables) {
            Exception exception = payload.getException();
            LOGGER.error("Datalake database backup failed for datalake with id: {}", payload.getResourceId(), exception);
            String operationId = (String) variables.get(OPERATION_ID);
            sdxBackupRestoreService.updateDatabaseStatusEntry(operationId, SdxOperationStatus.FAILED, exception.getLocalizedMessage());
            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(DatalakeDatabaseBackupFailedEvent 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) DatalakeDatabaseBackupFailedEvent(com.sequenceiq.datalake.flow.dr.backup.event.DatalakeDatabaseBackupFailedEvent) StateContext(org.springframework.statemachine.StateContext) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) PollerStoppedException(com.dyngr.exception.PollerStoppedException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 19 with AbstractSdxAction

use of com.sequenceiq.datalake.service.AbstractSdxAction 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 20 with AbstractSdxAction

use of com.sequenceiq.datalake.service.AbstractSdxAction 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)

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