Search in sources :

Example 31 with AbstractSdxAction

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

the class SdxCmSyncActions method cmSyncFailedAction.

@Bean(name = "SDX_CM_SYNC_FAILED_STATE")
public Action<?, ?> cmSyncFailedAction() {
    return new AbstractSdxAction<>(SdxCmSyncFailedEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxCmSyncFailedEvent payload, Map<Object, Object> variables) throws Exception {
            LOGGER.info("Sdx cm sync failure, error: ", payload.getException());
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(payload.getException());
            sendEvent(context, SDX_CM_SYNC_FAILED_HANDLED_EVENT.event(), payload);
        }

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

Example 32 with AbstractSdxAction

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

the class SdxCreateActions method storageValidation.

@Bean(name = "SDX_CREATION_STORAGE_VALIDATION_STATE")
public Action<?, ?> storageValidation() {
    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 {
            // When SDX is created as part of re-size flow chain, SDX in payload will not have the correct ID.
            setCorrectSdxIdIfNecessary(context, payload);
            StorageValidationRequest req = new StorageValidationRequest(context);
            sendEvent(context, req.selector(), req);
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return SdxCreateFailedEvent.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) StorageValidationRequest(com.sequenceiq.datalake.flow.create.event.StorageValidationRequest) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 33 with AbstractSdxAction

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

the class CertRotationActions method certRotationFinishedAction.

@Bean(name = "CERT_ROTATION_FINISHED_STATE")
public Action<?, ?> certRotationFinishedAction() {
    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("Cert rotation is finished");
            certRotationService.finalizeCertRotation(payload.getResourceId());
            SdxEvent event = new SdxEvent(SdxCertRotationEvent.CERT_ROTATION_FINALIZED_EVENT.event(), context);
            sendEvent(context, event);
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return new SdxCertRotationFailedEvent(payload, ex);
        }
    };
}
Also used : SdxCertRotationFailedEvent(com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationFailedEvent) 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 34 with AbstractSdxAction

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

the class CertRotationActions method starCertRotationAction.

@Bean(name = "START_CERT_ROTATION_STATE")
public Action<?, ?> starCertRotationAction() {
    return new AbstractSdxAction<>(SdxStartCertRotationEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxStartCertRotationEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Start cert rotation with request: {}", payload.getRequest());
            certRotationService.startCertRotation(context.getSdxId(), payload.getRequest());
            SdxEvent sdxEvent = new SdxEvent(SdxCertRotationEvent.CERT_ROTATION_STARTED_EVENT.event(), payload.getResourceId(), payload.getUserId());
            sendEvent(context, sdxEvent);
        }

        @Override
        protected Object getFailurePayload(SdxStartCertRotationEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return new SdxCertRotationFailedEvent(payload, ex);
        }
    };
}
Also used : SdxCertRotationFailedEvent(com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationFailedEvent) SdxStartCertRotationEvent(com.sequenceiq.datalake.flow.cert.rotation.event.SdxStartCertRotationEvent) 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 35 with AbstractSdxAction

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

the class DatalakeRestoreActions method datalakeRestoreInProgress.

@Bean(name = "DATALAKE_DATABASE_RESTORE_IN_PROGRESS_STATE")
public Action<?, ?> datalakeRestoreInProgress() {
    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("Datalake database restore is in progress for {} ", payload.getResourceId());
            String operationId = (String) variables.get(OPERATION_ID);
            sdxBackupRestoreService.updateDatabaseStatusEntry(operationId, SdxOperationStatus.INPROGRESS, null);
            SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.DATALAKE_RESTORE_INPROGRESS, ResourceEvent.DATALAKE_RESTORE_IN_PROGRESS, "Datalake restore in progress", payload.getResourceId());
            eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.DATALAKE_RESTORE_IN_PROGRESS);
            metricService.incrementMetricCounter(MetricType.SDX_RESTORE_REQUESTED, sdxCluster);
            sendEvent(context, DatalakeDatabaseRestoreWaitRequest.from(context, operationId));
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeDatabaseRestoreFailedEvent.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) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) 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