Search in sources :

Example 1 with SdxStartCertRenewalEvent

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

the class CertRenewalServiceTest method testCertRenewalTriggering.

@Test
public void testCertRenewalTriggering() {
    when(sdxCluster.getId()).thenReturn(1L);
    when(sdxCluster.getClusterName()).thenReturn("cluster");
    underTest.triggerRenewCertificate(sdxCluster, "userCrn");
    verify(sdxReactorFlowManager).triggerCertRenewal(captor.capture(), anyString());
    SdxStartCertRenewalEvent renewalEvent = captor.getValue();
    assertEquals("userCrn", renewalEvent.getUserId());
    assertEquals(1L, renewalEvent.getResourceId());
}
Also used : SdxStartCertRenewalEvent(com.sequenceiq.datalake.flow.cert.renew.event.SdxStartCertRenewalEvent) Test(org.junit.jupiter.api.Test)

Example 2 with SdxStartCertRenewalEvent

use of com.sequenceiq.datalake.flow.cert.renew.event.SdxStartCertRenewalEvent 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 3 with SdxStartCertRenewalEvent

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

the class CertRenewalServiceTest method testInternalCertRenewalTriggering.

@Test
public void testInternalCertRenewalTriggering() {
    when(sdxCluster.getId()).thenReturn(1L);
    when(sdxCluster.getClusterName()).thenReturn("cluster");
    when(sdxCluster.getInitiatorUserCrn()).thenReturn("userCrn");
    underTest.triggerInternalRenewCertificate(sdxCluster);
    verify(sdxReactorFlowManager).triggerCertRenewal(captor.capture(), anyString());
    SdxStartCertRenewalEvent renewalEvent = captor.getValue();
    assertEquals("userCrn", renewalEvent.getUserId());
    assertEquals(1L, renewalEvent.getResourceId());
}
Also used : SdxStartCertRenewalEvent(com.sequenceiq.datalake.flow.cert.renew.event.SdxStartCertRenewalEvent) Test(org.junit.jupiter.api.Test)

Aggregations

SdxStartCertRenewalEvent (com.sequenceiq.datalake.flow.cert.renew.event.SdxStartCertRenewalEvent)3 Test (org.junit.jupiter.api.Test)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)1 SdxCertRenewalFailedEvent (com.sequenceiq.datalake.flow.cert.renew.event.SdxCertRenewalFailedEvent)1 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1