Search in sources :

Example 1 with ValidateKerberosConfigEvent

use of com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.ValidateKerberosConfigEvent in project cloudbreak by hortonworks.

the class PollBindUserCreationHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<PollBindUserCreationEvent> event) {
    PollBindUserCreationEvent data = event.getData();
    FreeIpaOperationPollerObject operationPollerObject = new FreeIpaOperationPollerObject(data.getOperationId(), OperationType.BIND_USER_CREATE.name(), operationV1Endpoint, data.getAccountId(), regionAwareInternalCrnGeneratorFactory);
    ExtendedPollingResult result = freeIpaOperationChecker.pollWithAbsoluteTimeout(new FreeIpaOperationCheckerTask<>(), operationPollerObject, pollIntervalMilliSec, pollWaitTimeSec, pollMaxError);
    if (result.isSuccess()) {
        return new ValidateKerberosConfigEvent(VALIDATE_KERBEROS_CONFIG_EXISTS_EVENT.event(), data.getResourceId(), true);
    } else {
        StringBuilder errorMessage = new StringBuilder("Bind user creation failed");
        if (result.getException() != null) {
            errorMessage.append(" with: ");
            errorMessage.append(result.getException().getMessage());
        }
        return new StackFailureEvent(VALIDATE_KERBEROS_CONFIG_FAILED_EVENT.event(), data.getResourceId(), new Exception(errorMessage.toString()));
    }
}
Also used : FreeIpaOperationPollerObject(com.sequenceiq.cloudbreak.service.freeipa.FreeIpaOperationPollerObject) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) PollBindUserCreationEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.PollBindUserCreationEvent) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) ValidateKerberosConfigEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.ValidateKerberosConfigEvent)

Example 2 with ValidateKerberosConfigEvent

use of com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.ValidateKerberosConfigEvent in project cloudbreak by hortonworks.

the class CheckFreeIpaExistsHandlerTest method testFreeIpaDontExists.

@Test
public void testFreeIpaDontExists() {
    Event<CheckFreeIpaExistsEvent> event = new Event<>(new CheckFreeIpaExistsEvent(1L));
    when(freeIpaV1Endpoint.describeInternal(ENV_CRN, "1234")).thenThrow(new NotFoundException());
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    ValidateKerberosConfigEvent result = (ValidateKerberosConfigEvent) ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.doAccept(new HandlerEvent<>(event)));
    assertEquals(KerberosConfigValidationEvent.VALIDATE_KERBEROS_CONFIG_EXISTS_EVENT.event(), result.selector());
    assertEquals(1L, result.getResourceId());
    assertFalse(result.doesFreeipaExistsForEnv());
}
Also used : CheckFreeIpaExistsEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.CheckFreeIpaExistsEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) CheckFreeIpaExistsEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.CheckFreeIpaExistsEvent) Event(reactor.bus.Event) KerberosConfigValidationEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.config.KerberosConfigValidationEvent) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) ValidateKerberosConfigEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.ValidateKerberosConfigEvent) NotFoundException(javax.ws.rs.NotFoundException) ValidateKerberosConfigEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.ValidateKerberosConfigEvent) Test(org.junit.jupiter.api.Test)

Example 3 with ValidateKerberosConfigEvent

use of com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.ValidateKerberosConfigEvent in project cloudbreak by hortonworks.

the class PollBindUserCreationHandlerTest method testPollingSuccessful.

@Test
public void testPollingSuccessful() {
    Event<PollBindUserCreationEvent> event = new Event<>(new PollBindUserCreationEvent(1L, "opId", "acc"));
    ArgumentCaptor<FreeIpaOperationPollerObject> captor = ArgumentCaptor.forClass(FreeIpaOperationPollerObject.class);
    ExtendedPollingResult extendedPollingResult = new ExtendedPollingResult.ExtendedPollingResultBuilder().success().build();
    when(freeIpaOperationChecker.pollWithAbsoluteTimeout(any(FreeIpaOperationCheckerTask.class), captor.capture(), anyLong(), anyLong(), anyInt())).thenReturn(extendedPollingResult);
    ValidateKerberosConfigEvent result = (ValidateKerberosConfigEvent) underTest.doAccept(new HandlerEvent<>(event));
    assertEquals(VALIDATE_KERBEROS_CONFIG_EXISTS_EVENT.event(), result.selector());
    assertEquals(1L, result.getResourceId());
    assertTrue(result.doesFreeipaExistsForEnv());
    FreeIpaOperationPollerObject pollerObject = captor.getValue();
    assertEquals(BIND_USER_CREATE.name(), pollerObject.getOperationType());
    assertEquals("opId", pollerObject.getOperationId());
    assertEquals(operationV1Endpoint, pollerObject.getOperationV1Endpoint());
}
Also used : FreeIpaOperationPollerObject(com.sequenceiq.cloudbreak.service.freeipa.FreeIpaOperationPollerObject) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) Event(reactor.bus.Event) PollBindUserCreationEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.PollBindUserCreationEvent) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) ValidateKerberosConfigEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.ValidateKerberosConfigEvent) PollBindUserCreationEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.PollBindUserCreationEvent) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) FreeIpaOperationCheckerTask(com.sequenceiq.cloudbreak.service.freeipa.FreeIpaOperationCheckerTask) ValidateKerberosConfigEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.ValidateKerberosConfigEvent) Test(org.junit.jupiter.api.Test)

Example 4 with ValidateKerberosConfigEvent

use of com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.ValidateKerberosConfigEvent in project cloudbreak by hortonworks.

the class KerberosConfigValidationActions method kerberosConfigValidationAction.

@Bean(name = "VALIDATE_KERBEROS_CONFIG_STATE")
public Action<?, ?> kerberosConfigValidationAction() {
    return new AbstractStackCreationAction<>(ValidateKerberosConfigEvent.class) {

        @Override
        protected void doExecute(StackCreationContext context, ValidateKerberosConfigEvent payload, Map<Object, Object> variables) {
            decorateStackWithCustomDomainIfAdOrIpaJoinable(context.getStack());
            Cluster cluster = context.getStack().getCluster();
            if ((cluster != null && Boolean.TRUE.equals(cluster.getAutoTlsEnabled())) || payload.doesFreeipaExistsForEnv()) {
                boolean hasFreeIpaKerberosConfig = clusterCreationEnvironmentValidator.hasFreeIpaKerberosConfig(context.getStack());
                if (!hasFreeIpaKerberosConfig) {
                    throw new IllegalStateException("AutoTLS works only with FreeIPA. No FreeIPA Kerberos configuration is found.");
                }
            }
            sendEvent(context, KerberosConfigValidationEvent.VALIDATE_KERBEROS_CONFIG_FINISHED_EVENT.selector(), payload);
        }

        @Override
        protected Object getFailurePayload(ValidateKerberosConfigEvent payload, Optional<StackCreationContext> flowContext, Exception ex) {
            return new StackFailureEvent(KerberosConfigValidationEvent.VALIDATE_KERBEROS_CONFIG_FAILED_EVENT.selector(), payload.getResourceId(), ex);
        }

        private void decorateStackWithCustomDomainIfAdOrIpaJoinable(Stack stack) {
            Optional<KerberosConfig> kerberosConfig = measure(() -> kerberosConfigService.get(stack.getEnvironmentCrn(), stack.getName()), LOGGER, "kerberosConfigService get {} ms");
            if (kerberosConfig.isPresent() && StringUtils.isNotBlank(kerberosConfig.get().getDomain())) {
                LOGGER.info("Setting custom domain [{}] for cluster [{}]", kerberosConfig.get().getDomain(), stack.getName());
                stack.setCustomDomain(kerberosConfig.get().getDomain());
                stackService.save(stack);
            } else {
                LOGGER.info("No kerberos config or no  custom domain found");
            }
        }
    };
}
Also used : StackCreationContext(com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext) AbstractStackCreationAction(com.sequenceiq.cloudbreak.core.flow2.stack.provision.action.AbstractStackCreationAction) Optional(java.util.Optional) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) KerberosConfig(com.sequenceiq.cloudbreak.dto.KerberosConfig) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ValidateKerberosConfigEvent(com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.ValidateKerberosConfigEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

ValidateKerberosConfigEvent (com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.ValidateKerberosConfigEvent)4 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)4 PollBindUserCreationEvent (com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.PollBindUserCreationEvent)2 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)2 FreeIpaOperationPollerObject (com.sequenceiq.cloudbreak.service.freeipa.FreeIpaOperationPollerObject)2 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)2 Test (org.junit.jupiter.api.Test)2 Event (reactor.bus.Event)2 AbstractStackCreationAction (com.sequenceiq.cloudbreak.core.flow2.stack.provision.action.AbstractStackCreationAction)1 StackCreationContext (com.sequenceiq.cloudbreak.core.flow2.stack.start.StackCreationContext)1 KerberosConfigValidationEvent (com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.config.KerberosConfigValidationEvent)1 CheckFreeIpaExistsEvent (com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.CheckFreeIpaExistsEvent)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1 KerberosConfig (com.sequenceiq.cloudbreak.dto.KerberosConfig)1 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)1 FreeIpaOperationCheckerTask (com.sequenceiq.cloudbreak.service.freeipa.FreeIpaOperationCheckerTask)1 Map (java.util.Map)1 Optional (java.util.Optional)1 NotFoundException (javax.ws.rs.NotFoundException)1