Search in sources :

Example 1 with SdxContext

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

the class DatalakeBackupActions method datalakeBackup.

@Bean(name = "DATALAKE_DATABASE_BACKUP_START_STATE")
public Action<?, ?> datalakeBackup() {
    return new AbstractSdxAction<>(DatalakeDatabaseBackupStartEvent.class) {

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

        @Override
        protected void prepareExecution(DatalakeDatabaseBackupStartEvent payload, Map<Object, Object> variables) {
            super.prepareExecution(payload, variables);
            if (!variables.containsKey(OPERATION_ID)) {
                variables.put(OPERATION_ID, payload.getDrStatus().getOperationId());
            }
            if (!variables.containsKey(BACKUP_ID)) {
                variables.put(BACKUP_ID, payload.getBackupRequest().getBackupId());
            }
        }

        @Override
        protected void doExecute(SdxContext context, DatalakeDatabaseBackupStartEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Datalake database backup has been started for {}", payload.getResourceId());
            SdxCluster sdxCluster = sdxService.getById(payload.getResourceId());
            eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.DATALAKE_DATABASE_BACKUP);
            sdxBackupRestoreService.databaseBackup(payload.getDrStatus(), payload.getResourceId(), payload.getBackupRequest());
            sendEvent(context, DATALAKE_DATABASE_BACKUP_IN_PROGRESS_EVENT.event(), payload);
        }

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

Example 2 with SdxContext

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

the class SdxDetachActions method sdxAttachNewClusterFailedAction.

@Bean(name = "SDX_ATTACH_NEW_CLUSTER_FAILED_STATE")
public Action<?, ?> sdxAttachNewClusterFailedAction() {
    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) throws Exception {
            SdxCluster clusterToReattach = (SdxCluster) variables.get(DETACHED_SDX);
            clusterToReattach = sdxAttachService.reattachDetachedSdxCluster(clusterToReattach);
            LOGGER.info("Successfully restored detached SDX with ID {}.", 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 recover from detach of SDX with ID {}.", 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 3 with SdxContext

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

the class SdxDetachActions method sdxDetachCluster.

@Bean(name = "SDX_DETACH_CLUSTER_STATE")
public Action<?, ?> sdxDetachCluster() {
    return new AbstractSdxAction<>(SdxStartDetachEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxStartDetachEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Detaching of SDX with ID {} in progress.", payload.getResourceId());
            SdxCluster detached = sdxDetachService.detachCluster(payload.getResourceId(), payload.isDetachDuringRecovery());
            variables.put(RESIZED_SDX, payload.getSdxCluster());
            variables.put(DETACHED_SDX, detached);
            variables.put(IS_DETACH_DURING_RECOVERY, payload.isDetachDuringRecovery());
            eventSenderService.sendEventAndNotification(detached, context.getFlowTriggerUserCrn(), ResourceEvent.SDX_DETACH_STARTED, List.of(detached.getClusterName()));
            sendEvent(context, SDX_DETACH_CLUSTER_SUCCESS_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxStartDetachEvent payload, Optional<SdxContext> flowContext, Exception e) {
            return SdxDetachFailedEvent.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) SdxStartDetachEvent(com.sequenceiq.datalake.flow.detach.event.SdxStartDetachEvent) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 4 with SdxContext

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

the class SdxDetachActions method sdxAttachNewCluster.

@Bean(name = "SDX_ATTACH_NEW_CLUSTER_STATE")
public Action<?, ?> sdxAttachNewCluster() {
    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) throws Exception {
            SdxCluster detachedCluster = (SdxCluster) variables.get(DETACHED_SDX);
            sdxDetachService.markAsDetached(detachedCluster.getId());
            eventSenderService.notifyEvent(detachedCluster, context, ResourceEvent.SDX_DETACH_FINISHED);
            LOGGER.info("Detaching of SDX with ID {} finished.", detachedCluster.getId());
            if (!((boolean) variables.get(IS_DETACH_DURING_RECOVERY))) {
                SdxCluster resizedCluster = (SdxCluster) variables.get(RESIZED_SDX);
                LOGGER.info("Attaching of SDX cluster with ID {} in progress.", resizedCluster.getId());
                MDCBuilder.buildMdcContext(resizedCluster);
                resizedCluster = sdxAttachService.saveSdxAndAssignResourceOwnerRole(resizedCluster);
                sdxAttachService.markAsAttached(resizedCluster);
                LOGGER.info("Attaching of SDX cluster with ID {} is complete.", resizedCluster.getId());
                context.setSdxId(resizedCluster.getId());
            }
            sendEvent(context, SDX_ATTACH_NEW_CLUSTER_SUCCESS_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception e) {
            LOGGER.error("Failed to attach new cluster during detach.", e);
            return SdxDetachFailedEvent.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) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 5 with SdxContext

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

the class StartDatahubActions method failedAction.

@Bean(name = "START_DATAHUB_FAILED_STATE")
public Action<?, ?> failedAction() {
    return new AbstractSdxAction<>(StartDatahubFailedEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, StartDatahubFailedEvent payload, Map<Object, Object> variables) throws Exception {
            Exception exception = payload.getException();
            DatalakeStatusEnum failedStatus = DatalakeStatusEnum.START_FAILED;
            LOGGER.info("Update SDX status to {} for resource: {}", failedStatus, payload.getResourceId(), exception);
            String statusReason = "Datahub start failed";
            if (exception.getMessage() != null) {
                statusReason = exception.getMessage();
            }
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(payload.getException());
            sdxStatusService.setStatusForDatalakeAndNotify(failedStatus, statusReason, payload.getResourceId());
            sendEvent(context, START_DATAHUB_HANDLED_EVENT.event(), payload);
        }

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

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