Search in sources :

Example 1 with SdxCertRotationFailedEvent

use of com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationFailedEvent in project cloudbreak by hortonworks.

the class CertRotationActions method certRotationInProgressAction.

@Bean(name = "CERT_ROTATION_IN_PROGRESS_STATE")
public Action<?, ?> certRotationInProgressAction() {
    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 in progress. Start waiting to finish");
            SdxCertRotationWaitEvent event = new SdxCertRotationWaitEvent(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) SdxCertRotationWaitEvent(com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationWaitEvent) 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 SdxCertRotationFailedEvent

use of com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationFailedEvent in project cloudbreak by hortonworks.

the class SdxCertRotationWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<SdxCertRotationWaitEvent> event) {
    SdxEvent sdxEvent = event.getData();
    Long sdxId = sdxEvent.getResourceId();
    String userId = sdxEvent.getUserId();
    Selectable response;
    try {
        LOGGER.debug("Start polling stack cert rotation process for id: {}", sdxId);
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
        certRotationService.waitForCloudbreakClusterCertRotation(sdxId, pollingConfig);
        response = new SdxEvent(SdxCertRotationEvent.CERT_ROTATION_FINISHED_EVENT.event(), sdxId, userId);
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Cert rotation polling exited before timeout. Cause: ", userBreakException);
        response = new SdxCertRotationFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Cert rotation poller stopped for stack: {}", sdxId);
        response = new SdxCertRotationFailedEvent(sdxId, userId, new PollerStoppedException("Datalake cert rotation timed out after " + durationInMinutes + " minutes"));
    } catch (PollerException exception) {
        LOGGER.error("Cert rotation polling failed for stack: {}", sdxId);
        response = new SdxCertRotationFailedEvent(sdxId, userId, exception);
    }
    return response;
}
Also used : SdxCertRotationFailedEvent(com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationFailedEvent) UserBreakException(com.dyngr.exception.UserBreakException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) SdxEvent(com.sequenceiq.datalake.flow.SdxEvent) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 3 with SdxCertRotationFailedEvent

use of com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationFailedEvent 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 4 with SdxCertRotationFailedEvent

use of com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationFailedEvent 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)

Aggregations

SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)4 SdxCertRotationFailedEvent (com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationFailedEvent)4 SdxContext (com.sequenceiq.datalake.flow.SdxContext)3 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)3 FlowParameters (com.sequenceiq.flow.core.FlowParameters)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Bean (org.springframework.context.annotation.Bean)3 StateContext (org.springframework.statemachine.StateContext)3 PollerException (com.dyngr.exception.PollerException)1 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 UserBreakException (com.dyngr.exception.UserBreakException)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 SdxCertRotationWaitEvent (com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationWaitEvent)1 SdxStartCertRotationEvent (com.sequenceiq.datalake.flow.cert.rotation.event.SdxStartCertRotationEvent)1 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)1