Search in sources :

Example 36 with AbstractSdxAction

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

the class DatalakeRestoreActions method restoreFailed.

@Bean(name = "DATALAKE_RESTORE_FAILED_STATE")
public Action<?, ?> restoreFailed() {
    return new AbstractSdxAction<>(DatalakeRestoreFailedEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatalakeRestoreFailedEvent payload, Map<Object, Object> variables) {
            Exception exception = payload.getException();
            LOGGER.error("Datalake database restore could not be started for datalake with id: {}", payload.getResourceId(), exception);
            SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.RUNNING, ResourceEvent.DATALAKE_RESTORE_FINISHED, "Datalake is running, Datalake restore failed", payload.getResourceId());
            eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.DATALAKE_RESTORE_FAILED, List.of(exception.getMessage()));
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(payload.getException());
            metricService.incrementMetricCounter(MetricType.SDX_RESTORE_FAILED, sdxCluster);
            sendEvent(context, DATALAKE_RESTORE_FAILURE_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(DatalakeRestoreFailedEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : DatalakeRestoreFailedEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeRestoreFailedEvent) 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) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Flow(com.sequenceiq.flow.core.Flow) Bean(org.springframework.context.annotation.Bean)

Example 37 with AbstractSdxAction

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

the class DatalakeRestoreActions method datalakeFullResoreInProgress.

@Bean(name = "DATALAKE_FULL_RESTORE_IN_PROGRESS_STATE")
public Action<?, ?> datalakeFullResoreInProgress() {
    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 restore is in progress for {} ", payload.getResourceId());
            String operationId = (String) variables.get(OPERATION_ID);
            String restoreId = (String) variables.get(RESTORE_ID);
            SdxCluster sdxCluster = sdxService.getById(payload.getResourceId());
            SdxDatabaseRestoreStatusResponse restoreStatusResponse = sdxBackupRestoreService.getDatabaseRestoreStatus(sdxCluster, operationId);
            if (restoreStatusResponse.getStatus().equals(DatalakeDatabaseDrStatus.INPROGRESS)) {
                sdxBackupRestoreService.updateDatabaseStatusEntry(operationId, SdxOperationStatus.SUCCEEDED, null);
            }
            sendEvent(context, DatalakeFullRestoreWaitRequest.from(context, restoreId));
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeRestoreFailedEvent.from(flowContext, 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) SdxDatabaseRestoreStatusResponse(com.sequenceiq.sdx.api.model.SdxDatabaseRestoreStatusResponse) Map(java.util.Map) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 38 with AbstractSdxAction

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

the class DatalakeUpgradeActions method imageChangeWait.

@Bean(name = "DATALAKE_IMAGE_CHANGE_IN_PROGRESS_STATE")
public Action<?, ?> imageChangeWait() {
    return new AbstractSdxAction<>(DatalakeChangeImageWaitRequest.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatalakeChangeImageWaitRequest payload, Map<Object, Object> variables) {
            LOGGER.info("Datalake upgrade image change is in progress for {} ", payload.getResourceId());
            sendEvent(context, new DatalakeChangeImageWaitRequest(context, payload.getUpgradeOption()));
        }

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

Example 39 with AbstractSdxAction

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

the class DatalakeUpgradeActions method replaceVms.

@Bean(name = "DATALAKE_REPLACE_VMS_STATE")
public Action<?, ?> replaceVms() {
    return new AbstractSdxAction<>(DatalakeVmReplaceEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatalakeVmReplaceEvent payload, Map<Object, Object> variables) {
            if ((boolean) variables.get(REPLACE_VMS_AFTER_UPGRADE)) {
                LOGGER.info("Start Datalake upgrade vm replacement for {} ", payload.getResourceId());
                sdxUpgradeService.upgradeOs(payload.getResourceId());
                sendEvent(context, new SdxEvent(DATALAKE_VM_REPLACE_IN_PROGRESS_EVENT.event(), context));
            } else {
                LOGGER.info("Vm replacement is not required for {} ", payload.getResourceId());
                sendEvent(context, DATALAKE_UPGRADE_SUCCESS_EVENT.event(), new DatalakeUpgradeSuccessEvent(payload.getResourceId(), payload.getUserId()));
            }
        }

        @Override
        protected Object getFailurePayload(DatalakeVmReplaceEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeUpgradeFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) DatalakeVmReplaceEvent(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeVmReplaceEvent) 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) DatalakeUpgradeSuccessEvent(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeUpgradeSuccessEvent) Bean(org.springframework.context.annotation.Bean)

Example 40 with AbstractSdxAction

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

the class DatalakeUpgradeActions method replaceVmsWait.

@Bean(name = "DATALAKE_REPLACE_VMS_IN_PROGRESS_STATE")
public Action<?, ?> replaceVmsWait() {
    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 upgrade vm replacement is in progress for {} ", payload.getResourceId());
            sendEvent(context, new DatalakeVmReplaceWaitRequest(context));
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeUpgradeFailedEvent.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) DatalakeVmReplaceWaitRequest(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeVmReplaceWaitRequest) 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