Search in sources :

Example 1 with FlowParameters

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

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

the class DatalakeRecoveryBringupActions method datalakeRecoveryBringupFailedAction.

@Bean(name = "RECOVERY_BRINGUP_FAILED_STATE")
public Action<?, ?> datalakeRecoveryBringupFailedAction() {
    return new AbstractDatalakeRecoveryBringupAction<>(DatalakeRecoverySetupNewInstancesFailedEvent.class) {

        @Override
        protected DatalakeRecoveryBringupContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatalakeRecoverySetupNewInstancesFailedEvent payload) {
            Exception exception = payload.getException();
            Long stackId = payload.getResourceId();
            Flow flow = getFlow(flowParameters.getFlowId());
            StackView stackView = stackService.getViewByIdWithoutAuth(stackId);
            MDCBuilder.buildMdcContext(stackView);
            flow.setFlowFailed(exception);
            LOGGER.error("Datalake recovery failed for stack with id: {}", stackId, exception);
            return DatalakeRecoveryBringupContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(DatalakeRecoveryBringupContext context, DatalakeRecoverySetupNewInstancesFailedEvent payload, Map<Object, Object> variables) {
            datalakeRecoveryBringupStatusService.handleDatalakeRecoveryBringupFailure(context.getStackId(), payload.getException().getMessage(), payload.getDetailedStatus());
            sendEvent(context, RECOVERY_BRINGUP_FAIL_HANDLED_EVENT.event(), payload);
        }
    };
}
Also used : DatalakeRecoverySetupNewInstancesFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.recovery.bringup.DatalakeRecoverySetupNewInstancesFailedEvent) FlowParameters(com.sequenceiq.flow.core.FlowParameters) StateContext(org.springframework.statemachine.StateContext) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) Map(java.util.Map) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Example 3 with FlowParameters

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

the class ClusterUpgradeActions method clusterUpgradeFailedAction.

@Bean(name = "CLUSTER_UPGRADE_FAILED_STATE")
public Action<?, ?> clusterUpgradeFailedAction() {
    return new AbstractClusterUpgradeAction<>(ClusterUpgradeFailedEvent.class) {

        @Value("${cb.upgrade.failure.sync.sdx.enabled}")
        private boolean syncAfterFailureEnabled;

        @Override
        protected ClusterUpgradeContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, ClusterUpgradeFailedEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            Stack stack = stackService.getById(payload.getResourceId());
            MDCBuilder.buildMdcContext(stack);
            flow.setFlowFailed(payload.getException());
            return ClusterUpgradeContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(ClusterUpgradeContext context, ClusterUpgradeFailedEvent payload, Map<Object, Object> variables) {
            clusterUpgradeService.handleUpgradeClusterFailure(context.getStackId(), payload.getException().getMessage(), payload.getDetailedStatus());
            if (syncAfterFailureEnabled) {
                LOGGER.debug("Starting syncing parcel and CM version from CM to DB.");
                try {
                    Set<Image> candidateImages = new HashSet<>();
                    Optional.ofNullable(getCurrentImage(variables)).ifPresent(si -> candidateImages.add(si.getImage()));
                    Optional.ofNullable(getTargetImage(variables)).ifPresent(si -> candidateImages.add(si.getImage()));
                    ClusterUpgradeFailedCmSyncRequest cmSyncRequest = new ClusterUpgradeFailedCmSyncRequest(payload.getResourceId(), payload.getException(), payload.getDetailedStatus(), candidateImages);
                    sendEvent(context, cmSyncRequest);
                } catch (Exception e) {
                    LOGGER.warn("Error starting syncing CM version to DB, syncing skipped: ", e);
                    sendEvent(context, new ClusterUpgradeFailHandledRequest(payload.getResourceId(), payload.getException(), payload.getDetailedStatus()));
                }
            } else {
                LOGGER.debug("Syncing from CM to DB is not enabled.");
                sendEvent(context, new ClusterUpgradeFailHandledRequest(payload.getResourceId(), payload.getException(), payload.getDetailedStatus()));
            }
        }

        @Override
        protected Object getFailurePayload(ClusterUpgradeFailedEvent payload, Optional<ClusterUpgradeContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) ClusterUpgradeFailedEvent(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedEvent) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ClusterUpgradeFailedCmSyncRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailedCmSyncRequest) Flow(com.sequenceiq.flow.core.Flow) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) FlowParameters(com.sequenceiq.flow.core.FlowParameters) ClusterUpgradeFailHandledRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.upgrade.ClusterUpgradeFailHandledRequest) Map(java.util.Map) HashSet(java.util.HashSet) Bean(org.springframework.context.annotation.Bean)

Example 4 with FlowParameters

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

the class ExternalDatabaseStopActions method externalDatabaseStopFailureAction.

@Bean(name = "EXTERNAL_DATABASE_STOP_FAILED_STATE")
public Action<?, ?> externalDatabaseStopFailureAction() {
    return new AbstractExternalDatabaseStopAction<>(StopExternalDatabaseFailed.class) {

        @Override
        protected void doExecute(ExternalDatabaseContext context, StopExternalDatabaseFailed payload, Map<Object, Object> variables) {
            stackUpdaterService.updateStatus(context.getStack().getId(), DetailedStackStatus.EXTERNAL_DATABASE_STOP_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_STOP_FAILED, payload.getException().getMessage());
            getMetricService().incrementMetricCounter(MetricType.EXTERNAL_DATABASE_STOP_FAILED, context.getStack());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(ExternalDatabaseContext context) {
            return new StackEvent(ExternalDatabaseStopEvent.EXTERNAL_DATABASE_STOP_FAILURE_HANDLED_EVENT.event(), context.getStack().getId());
        }

        @Override
        protected void beforeReturnFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseStopState, ExternalDatabaseStopEvent> stateContext, StopExternalDatabaseFailed payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            super.beforeReturnFlowContext(flowParameters, stateContext, payload);
        }
    };
}
Also used : AbstractExternalDatabaseStopAction(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.stop.action.AbstractExternalDatabaseStopAction) StopExternalDatabaseFailed(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.StopExternalDatabaseFailed) FlowParameters(com.sequenceiq.flow.core.FlowParameters) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StateContext(org.springframework.statemachine.StateContext) ExternalDatabaseContext(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext) Map(java.util.Map) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Example 5 with FlowParameters

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

the class ExternalDatabaseTerminationActions method externalDatabaseTerminationFailureAction.

@Bean(name = "EXTERNAL_DATABASE_TERMINATION_FAILED_STATE")
public Action<?, ?> externalDatabaseTerminationFailureAction() {
    return new AbstractExternalDatabaseTerminationAction<>(TerminateExternalDatabaseFailed.class) {

        @Override
        protected void doExecute(ExternalDatabaseContext context, TerminateExternalDatabaseFailed payload, Map<Object, Object> variables) {
            stackUpdaterService.updateStatus(context.getStack().getId(), DetailedStackStatus.DELETE_FAILED, ResourceEvent.CLUSTER_EXTERNAL_DATABASE_DELETION_FAILED, payload.getException().getMessage());
            getMetricService().incrementMetricCounter(MetricType.EXTERNAL_DATABASE_TERMINATION_FAILED, context.getStack());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(ExternalDatabaseContext context) {
            return new StackEvent(ExternalDatabaseTerminationEvent.EXTERNAL_DATABASE_TERMINATION_FAILURE_HANDLED_EVENT.event(), context.getStack().getId());
        }

        @Override
        protected void beforeReturnFlowContext(FlowParameters flowParameters, StateContext<ExternalDatabaseTerminationState, ExternalDatabaseTerminationEvent> stateContext, TerminateExternalDatabaseFailed payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            super.beforeReturnFlowContext(flowParameters, stateContext, payload);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StateContext(org.springframework.statemachine.StateContext) ExternalDatabaseContext(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.ExternalDatabaseContext) AbstractExternalDatabaseTerminationAction(com.sequenceiq.cloudbreak.core.flow2.externaldatabase.terminate.action.AbstractExternalDatabaseTerminationAction) TerminateExternalDatabaseFailed(com.sequenceiq.cloudbreak.reactor.api.event.externaldatabase.TerminateExternalDatabaseFailed) Map(java.util.Map) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

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