Search in sources :

Example 1 with SdxEvent

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

the class SdxDetachActions method sdxAttachNewCluster.

@Bean(name = "SDX_ATTACH_NEW_CLUSTER_STATE")
public Action<?, ?> sdxAttachNewCluster() {
    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 {
            SdxCluster detachedCluster = (SdxCluster) variables.get(DETACHED_SDX);
            sdxDetachService.markAsDetached(detachedCluster.getId());
            eventSenderService.notifyEvent(detachedCluster, context, ResourceEvent.SDX_DETACH_FINISHED);
            LOGGER.info("Detaching of SDX with ID {} finished.", detachedCluster.getId());
            if (!((boolean) variables.get(IS_DETACH_DURING_RECOVERY))) {
                SdxCluster resizedCluster = (SdxCluster) variables.get(RESIZED_SDX);
                LOGGER.info("Attaching of SDX cluster with ID {} in progress.", resizedCluster.getId());
                MDCBuilder.buildMdcContext(resizedCluster);
                resizedCluster = sdxAttachService.saveSdxAndAssignResourceOwnerRole(resizedCluster);
                sdxAttachService.markAsAttached(resizedCluster);
                LOGGER.info("Attaching of SDX cluster with ID {} is complete.", resizedCluster.getId());
                context.setSdxId(resizedCluster.getId());
            }
            sendEvent(context, SDX_ATTACH_NEW_CLUSTER_SUCCESS_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception e) {
            LOGGER.error("Failed to attach new cluster during detach.", e);
            return SdxDetachFailedEvent.from(payload, e);
        }
    };
}
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) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 2 with SdxEvent

use of com.sequenceiq.datalake.flow.SdxEvent 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 3 with SdxEvent

use of com.sequenceiq.datalake.flow.SdxEvent 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 4 with SdxEvent

use of com.sequenceiq.datalake.flow.SdxEvent 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 5 with SdxEvent

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

the class SdxCmSyncWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<SdxCmSyncWaitEvent> event) {
    LOGGER.debug("Entering handler for calling sync CM and parcel versions from CM server");
    SdxCmSyncWaitEvent sdxCmSyncWaitEvent = event.getData();
    try {
        SdxCluster sdxCluster = sdxService.getById(sdxCmSyncWaitEvent.getResourceId());
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES).withStopPollingIfExceptionOccurred(true);
        sdxWaitService.waitForCloudbreakFlow(sdxCluster, pollingConfig, "Sync cm");
        return new SdxEvent(SDX_CM_SYNC_FINISHED_EVENT.event(), event.getData().getResourceId(), event.getData().getUserId());
    } catch (SdxWaitException e) {
        LOGGER.warn("Error happened during waiting for syncing CM and parcel versions from a datalake CM to component table {}, error: ", sdxCmSyncWaitEvent.getResourceId(), e);
        return new SdxCmSyncFailedEvent(sdxCmSyncWaitEvent.getResourceId(), sdxCmSyncWaitEvent.getUserId(), e);
    }
}
Also used : SdxCmSyncWaitEvent(com.sequenceiq.datalake.flow.datalake.cmsync.event.SdxCmSyncWaitEvent) SdxWaitException(com.sequenceiq.datalake.service.sdx.flowwait.exception.SdxWaitException) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) SdxCmSyncFailedEvent(com.sequenceiq.datalake.flow.datalake.cmsync.event.SdxCmSyncFailedEvent) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig)

Aggregations

SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)24 SdxContext (com.sequenceiq.datalake.flow.SdxContext)18 Map (java.util.Map)18 Bean (org.springframework.context.annotation.Bean)18 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)16 FlowParameters (com.sequenceiq.flow.core.FlowParameters)16 Optional (java.util.Optional)16 StateContext (org.springframework.statemachine.StateContext)16 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)7 PollerStoppedException (com.dyngr.exception.PollerStoppedException)6 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)5 PollerException (com.dyngr.exception.PollerException)4 UserBreakException (com.dyngr.exception.UserBreakException)4 SdxCertRenewalFailedEvent (com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent)4 SdxCertRotationFailedEvent (com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationFailedEvent)4 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)4 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)2 SdxCmSyncWaitEvent (com.sequenceiq.datalake.flow.datalake.cmsync.event.SdxCmSyncWaitEvent)2 DatalakeStatusUpdateException (com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException)2