Search in sources :

Example 6 with SdxContext

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

the class StartDatahubActions method startDatahubStartAction.

@Bean(name = "START_DATAHUB_STATE")
public Action<?, ?> startDatahubStartAction() {
    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 {
            LOGGER.info("Execute start datahub for sdx: {}", payload.getResourceId());
            String userId = payload.getUserId();
            Long resourceId = payload.getResourceId();
            try {
                sdxStartService.startAllDatahubs(resourceId);
                sendEvent(context, new SdxEvent(START_DATAHUB_IN_PROGRESS_EVENT.event(), resourceId, userId));
            } catch (Exception e) {
                LOGGER.error("Failed to start datahub, sdx: {}, user: {}", resourceId, userId, e);
                sendEvent(context, new SdxEvent(START_DATAHUB_FAILED_EVENT.event(), resourceId, userId));
            }
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return StartDatahubFailedEvent.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) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 7 with SdxContext

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

the class SdxCmSyncActions method callCoreCmSync.

@Bean(name = "CORE_CM_SYNC_STATE")
public Action<?, ?> callCoreCmSync() {
    return new AbstractSdxCmSyncAction<>(SdxCmSyncStartEvent.class) {

        @Override
        protected void doExecute(SdxContext context, SdxCmSyncStartEvent payload, Map<Object, Object> variables) throws Exception {
            LOGGER.debug("Calling cm sync on core");
            sdxCmSyncService.callCmSync(payload.getResourceId());
            sendEvent(context, new SdxEvent(SDX_CM_SYNC_IN_PROGRESS_EVENT.event(), context));
        }
    };
}
Also used : SdxCmSyncStartEvent(com.sequenceiq.datalake.flow.datalake.cmsync.event.SdxCmSyncStartEvent) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 8 with SdxContext

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

the class SdxDeleteActions method finishedAction.

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

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

        @Override
        protected void doExecute(SdxContext context, RdsDeletionSuccessEvent payload, Map<Object, Object> variables) throws Exception {
            Long datalakeId = payload.getResourceId();
            LOGGER.info("Datalake delete finalized: {}", datalakeId);
            SdxCluster sdxCluster = sdxService.getById(datalakeId);
            if (sdxCluster != null) {
                metricService.incrementMetricCounter(MetricType.SDX_DELETION_FINISHED, sdxCluster);
            }
            eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_DELETION_FINISHED);
            sendEvent(context, SDX_DELETE_FINALIZED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(RdsDeletionSuccessEvent 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) RdsDeletionSuccessEvent(com.sequenceiq.datalake.flow.delete.event.RdsDeletionSuccessEvent) Map(java.util.Map) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 9 with SdxContext

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

the class SdxDeleteActions method failedAction.

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

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

        @Override
        protected void doExecute(SdxContext context, SdxDeletionFailedEvent payload, Map<Object, Object> variables) throws Exception {
            Exception exception = payload.getException();
            String statusReason = "Datalake deletion failed";
            String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(exception);
            if (StringUtils.hasText(errorMessage)) {
                statusReason = statusReason + ". " + errorMessage;
            } else if (exception.getMessage() != null) {
                statusReason = statusReason + ". " + exception.getMessage();
            }
            LOGGER.error(statusReason, exception);
            try {
                SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.DELETE_FAILED, statusReason, payload.getResourceId());
                metricService.incrementMetricCounter(MetricType.SDX_DELETION_FAILED, sdxCluster);
                if (sdxCluster.isDetached()) {
                    eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.SDX_DETACHED_CLUSTER_DELETION_FAILED, List.of(sdxCluster.getClusterName()));
                } else {
                    eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_DELETION_FAILED);
                }
            } catch (NotFoundException notFoundException) {
                LOGGER.info("Can not set status to SDX_DELETION_FAILED because data lake was not found");
            }
            sendEvent(context, SDX_DELETE_FAILED_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxDeletionFailedEvent 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) SdxDeletionFailedEvent(com.sequenceiq.datalake.flow.delete.event.SdxDeletionFailedEvent) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Map(java.util.Map) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 10 with SdxContext

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

the class SdxDiagnosticsActions method startDiagnosticsCollection.

@Bean(name = "DIAGNOSTICS_COLLECTION_START_STATE")
public Action<?, ?> startDiagnosticsCollection() {
    return new AbstractSdxAction<>(SdxDiagnosticsCollectionEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxDiagnosticsCollectionEvent payload, Map<Object, Object> variables) {
            LOGGER.debug("Start diagnostics collection for sdx cluster with id: {}", context.getSdxId());
            payload.getProperties().put(DIAGNOSTICS_UUID_PARAM, context.getFlowId());
            FlowIdentifier flowIdentifier = diagnosticsFlowService.startDiagnosticsCollection(payload.getProperties());
            SdxDiagnosticsCollectionEvent event = new SdxDiagnosticsCollectionEvent(payload.getResourceId(), payload.getUserId(), payload.getProperties(), flowIdentifier);
            sendEvent(context, SDX_DIAGNOSTICS_COLLECTION_IN_PROGRESS_EVENT.event(), event);
        }

        @Override
        protected Object getFailurePayload(SdxDiagnosticsCollectionEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return SdxDiagnosticsFailedEvent.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) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) SdxDiagnosticsCollectionEvent(com.sequenceiq.datalake.flow.diagnostics.event.SdxDiagnosticsCollectionEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) 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