Search in sources :

Example 1 with SdxStartCertRotationEvent

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

Example 2 with SdxStartCertRotationEvent

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

the class CertRotationServiceTest method testFlowTrigger.

@Test
public void testFlowTrigger() {
    SdxCluster cluster = new SdxCluster();
    cluster.setId(1L);
    cluster.setClusterName("testclustername");
    CertificatesRotationV4Request request = new CertificatesRotationV4Request();
    ArgumentCaptor<SdxStartCertRotationEvent> eventArgumentCaptor = ArgumentCaptor.forClass(SdxStartCertRotationEvent.class);
    FlowIdentifier flowIdentifier = new FlowIdentifier(FlowType.FLOW, "pollid");
    when(flowManager.triggerCertRotation(eventArgumentCaptor.capture(), anyString())).thenReturn(flowIdentifier);
    FlowIdentifier result = ThreadBasedUserCrnProvider.doAs(TEST_USER_CRN, () -> underTest.rotateAutoTlsCertificates(cluster, request));
    assertEquals(flowIdentifier, result);
    SdxStartCertRotationEvent event = eventArgumentCaptor.getValue();
    assertEquals(request, event.getRequest());
    assertEquals(1L, event.getResourceId());
    assertEquals(TEST_USER_CRN, event.getUserId());
}
Also used : SdxStartCertRotationEvent(com.sequenceiq.datalake.flow.cert.rotation.event.SdxStartCertRotationEvent) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Test(org.junit.jupiter.api.Test)

Example 3 with SdxStartCertRotationEvent

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

the class CertRotationService method rotateAutoTlsCertificates.

public FlowIdentifier rotateAutoTlsCertificates(SdxCluster sdxCluster, CertificatesRotationV4Request rotateCertificateRequest) {
    MDCBuilder.buildMdcContext(sdxCluster);
    String initiatorUserCrn = ThreadBasedUserCrnProvider.getUserCrn();
    SdxStartCertRotationEvent event = new SdxStartCertRotationEvent(sdxCluster.getId(), initiatorUserCrn, rotateCertificateRequest);
    return flowManager.triggerCertRotation(event, sdxCluster.getClusterName());
}
Also used : SdxStartCertRotationEvent(com.sequenceiq.datalake.flow.cert.rotation.event.SdxStartCertRotationEvent)

Aggregations

SdxStartCertRotationEvent (com.sequenceiq.datalake.flow.cert.rotation.event.SdxStartCertRotationEvent)3 CertificatesRotationV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)1 SdxCertRotationFailedEvent (com.sequenceiq.datalake.flow.cert.rotation.event.SdxCertRotationFailedEvent)1 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)1 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Test (org.junit.jupiter.api.Test)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1