Search in sources :

Example 1 with SdxCertRenewalFailedEvent

use of com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent in project cloudbreak by hortonworks.

the class CertRenewalActions method certRenewFinishedAction.

@Bean(name = "CERT_RENEWAL_FINISHED_STATE")
public Action<?, ?> certRenewFinishedAction() {
    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("Cert renewal is finished");
            certRenewalService.finalizeCertRenewal(payload.getResourceId());
            SdxEvent event = new SdxEvent(SdxCertRenewalEvent.CERT_RENEWAL_FINALIZED_EVENT.event(), context);
            sendEvent(context, event);
        }

        @Override
        protected Object getFailurePayload(SdxEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return new SdxCertRenewalFailedEvent(payload, ex.getMessage());
        }
    };
}
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) SdxCertRenewalFailedEvent(com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 2 with SdxCertRenewalFailedEvent

use of com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent in project cloudbreak by hortonworks.

the class SdxCertRenewWaitHandler method doAccept.

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

Example 3 with SdxCertRenewalFailedEvent

use of com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent in project cloudbreak by hortonworks.

the class CertRenewalActions method startCertRenewAction.

@Bean(name = "START_CERT_RENEWAL_STATE")
public Action<?, ?> startCertRenewAction() {
    return new AbstractSdxAction<>(SdxStartCertRenewalEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, SdxStartCertRenewalEvent payload, Map<Object, Object> variables) throws Exception {
            LOGGER.info("Start cert renewal.");
            SdxCluster sdxCluster = sdxService.getById(payload.getResourceId());
            if (payload.isInternal()) {
                certRenewalService.renewInternalCertificate(sdxCluster);
            } else {
                certRenewalService.renewCertificate(sdxCluster, payload.getUserId());
            }
            SdxEvent sdxEvent = new SdxEvent(SdxCertRenewalEvent.CERT_RENEWAL_STARTED_EVENT.event(), payload.getResourceId(), payload.getUserId());
            sendEvent(context, sdxEvent);
        }

        @Override
        protected Object getFailurePayload(SdxStartCertRenewalEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return new SdxCertRenewalFailedEvent(payload, ex.getMessage());
        }
    };
}
Also used : SdxStartCertRenewalEvent(com.sequenceiq.datalake.flow.cert.renew.event.SdxStartCertRenewalEvent) 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) SdxCertRenewalFailedEvent(com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 4 with SdxCertRenewalFailedEvent

use of com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent in project cloudbreak by hortonworks.

the class CertRenewalActions method certRenewInProgressAction.

@Bean(name = "CERT_RENEWAL_IN_PROGRESS_STATE")
public Action<?, ?> certRenewInProgressAction() {
    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("Cert renewal is in progress. Start waiting to finish.");
            sendEvent(context, new SdxCertRenewalWaitEvent(context));
        }

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

Aggregations

SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)4 SdxCertRenewalFailedEvent (com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent)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 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxCertRenewalWaitEvent (com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalWaitEvent)1 SdxStartCertRenewalEvent (com.sequenceiq.datalake.flow.cert.renew.event.SdxStartCertRenewalEvent)1 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)1