Search in sources :

Example 11 with SdxContext

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

the class SdxCmSyncActions method waitForCoreCmSync.

@Bean(name = "CORE_CM_SYNC_IN_PROGRESS_STATE")
public Action<?, ?> waitForCoreCmSync() {
    return new AbstractSdxCmSyncAction<>(SdxEvent.class) {

        @Override
        protected void doExecute(SdxContext context, SdxEvent payload, Map<Object, Object> variables) {
            SdxCmSyncWaitEvent sdxCmSyncWaitEvent = new SdxCmSyncWaitEvent(context);
            sendEvent(context, sdxCmSyncWaitEvent);
        }
    };
}
Also used : SdxCmSyncWaitEvent(com.sequenceiq.datalake.flow.datalake.cmsync.event.SdxCmSyncWaitEvent) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 12 with SdxContext

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

the class DatalakeUpgradeActions method imageChange.

@Bean(name = "DATALAKE_IMAGE_CHANGE_STATE")
public Action<?, ?> imageChange() {
    return new AbstractSdxAction<>(DatalakeImageChangeEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatalakeImageChangeEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Start Datalake upgrade image change for {} ", payload.getResourceId());
            sdxUpgradeService.updateRuntimeVersionFromCloudbreak(payload.getResourceId());
            String catalogName = sdxUpgradeService.getCurrentImageCatalogName(payload.getResourceId());
            UpgradeOptionV4Response upgrade = new UpgradeOptionV4Response().upgrade(new ImageInfoV4Response().imageId(payload.getImageId()).imageCatalogName(catalogName));
            sdxUpgradeService.changeImage(payload.getResourceId(), upgrade);
            sendEvent(context, new DatalakeChangeImageWaitRequest(DATALAKE_IMAGE_CHANGE_IN_PROGRESS_EVENT.event(), context.getSdxId(), context.getUserId(), upgrade));
        }

        @Override
        protected Object getFailurePayload(DatalakeImageChangeEvent 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) UpgradeOptionV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) DatalakeImageChangeEvent(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeImageChangeEvent) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) 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 13 with SdxContext

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

the class DatahubRefreshActions method startDatahubRefreshAction.

@Bean(name = "DATAHUB_REFRESH_START_STATE")
public Action<?, ?> startDatahubRefreshAction() {
    return new AbstractSdxAction<>(DatahubRefreshStartEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, DatahubRefreshStartEvent payload) {
            // Only called as a part of a resize operation so we should update the cluster to reference the newly created one
            SdxCluster sdxCluster = sdxService.getByNameInAccount(payload.getUserId(), payload.getSdxName());
            LOGGER.info("Updating the Sdx-id in context from {} to {}", payload.getResourceId(), sdxCluster.getId());
            SdxContext sdxContext = SdxContext.from(flowParameters, payload);
            sdxContext.setSdxId(sdxCluster.getId());
            return sdxContext;
        }

        @Override
        protected void doExecute(SdxContext context, DatahubRefreshStartEvent payload, Map<Object, Object> variables) throws Exception {
            payload = new DatahubRefreshStartEvent(context.getSdxId(), payload.getSdxName(), payload.getUserId());
            LOGGER.info("Start datahub refresh associated with Sdx: {}", payload.getSdxName());
            SdxCluster sdxCluster = sdxService.getById(context.getSdxId());
            variables.put(SDX, sdxCluster);
            eventSenderService.sendEventAndNotification(sdxCluster, context.getFlowTriggerUserCrn(), ResourceEvent.ENVIRONMENT_RESTART_DATAHUB_STARTED);
            sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.RUNNING, "Datahub refresh in progress", payload.getResourceId());
            sdxRefreshService.refreshAllDatahub(payload.getResourceId());
            sendEvent(context, DatahubRefreshFlowEvent.DATAHUB_REFRESH_IN_PROGRESS_EVENT.selector(), payload);
        }

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

Example 14 with SdxContext

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

the class DatalakeRestoreActions method restoreCouldNotStart.

@Bean(name = "DATALAKE_DATABASE_RESTORE_COULD_NOT_START_STATE")
public Action<?, ?> restoreCouldNotStart() {
    return new AbstractSdxAction<>(DatalakeDatabaseRestoreCouldNotStartEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatalakeDatabaseRestoreCouldNotStartEvent 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);
            String operationId = (String) variables.get(OPERATION_ID);
            sdxBackupRestoreService.updateDatabaseStatusEntry(operationId, SdxOperationStatus.FAILED, exception.getLocalizedMessage());
            sendEvent(context, DATALAKE_DATABASE_RESTORE_FAILURE_HANDLED_EVENT.event(), payload);
        }

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

Example 15 with SdxContext

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

the class DatalakeRestoreActions method databaseRestoreFailed.

@Bean(name = "DATALAKE_DATABASE_RESTORE_FAILED_STATE")
public Action<?, ?> databaseRestoreFailed() {
    return new AbstractSdxAction<>(DatalakeDatabaseRestoreFailedEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatalakeDatabaseRestoreFailedEvent 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);
            String operationId = (String) variables.get(OPERATION_ID);
            sdxBackupRestoreService.updateDatabaseStatusEntry(operationId, SdxOperationStatus.FAILED, exception.getLocalizedMessage());
            Flow flow = getFlow(context.getFlowParameters().getFlowId());
            flow.setFlowFailed(payload.getException());
            sendEvent(context, DATALAKE_DATABASE_RESTORE_FAILURE_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(DatalakeDatabaseRestoreFailedEvent 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) DatalakeDatabaseRestoreFailedEvent(com.sequenceiq.datalake.flow.dr.restore.event.DatalakeDatabaseRestoreFailedEvent) StateContext(org.springframework.statemachine.StateContext) 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)

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