Search in sources :

Example 6 with CreateBindUserEvent

use of com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent in project cloudbreak by hortonworks.

the class CreateBindUserActions method createKerberosBindUserAction.

@Bean("CREATE_KERBEROS_BIND_USER_STATE")
public Action<?, ?> createKerberosBindUserAction() {
    return new AbstractBindUserCreateAction<>(CreateBindUserEvent.class) {

        @Override
        protected void doExecute(CommonContext context, CreateBindUserEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Sending request to create Kerberos bind user for {}", payload.getSuffix());
            sendEvent(context, new CreateKerberosBindUserEvent(payload));
        }
    };
}
Also used : CreateKerberosBindUserEvent(com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateKerberosBindUserEvent) CommonContext(com.sequenceiq.flow.core.CommonContext) CreateBindUserEvent(com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 7 with CreateBindUserEvent

use of com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent in project cloudbreak by hortonworks.

the class BindUserCreateService method startCreateBindUserFLow.

private Operation startCreateBindUserFLow(String accountId, BindUserCreateRequest request, Long stackId, Operation operation) {
    CreateBindUserEvent event = new CreateBindUserEvent(CREATE_BIND_USER_EVENT.event(), stackId, accountId, operation.getOperationId(), request.getBindUserNameSuffix(), request.getEnvironmentCrn());
    try {
        LOGGER.info("Start CreateBindUserFlow");
        flowManager.notify(CREATE_BIND_USER_EVENT.event(), event);
        LOGGER.info("Started CreateBindUserFlow");
        return operation;
    } catch (Exception e) {
        LOGGER.error("Couldn't start create bind user flow", e);
        return operationService.failOperation(accountId, operation.getOperationId(), "Couldn't start create bind user flow: " + e.getMessage());
    }
}
Also used : CreateBindUserEvent(com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent)

Example 8 with CreateBindUserEvent

use of com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent in project cloudbreak by hortonworks.

the class BindUserCreateServiceTest method testCreateStartedFLowNotified.

@Test
public void testCreateStartedFLowNotified() {
    BindUserCreateRequest request = createRequest();
    Operation operation = new Operation();
    operation.setOperationId("op");
    operation.setStatus(OperationState.RUNNING);
    when(operationService.startOperation(eq(ACCOUNT), eq(OperationType.BIND_USER_CREATE), anyCollection(), anyCollection())).thenReturn(operation);
    OperationStatus operationStatus = new OperationStatus();
    when(operationConverter.convert(operation)).thenReturn(operationStatus);
    OperationStatus response = underTest.createBindUser(ACCOUNT, request);
    assertEquals(operationStatus, response);
    ArgumentCaptor<Acceptable> captor = ArgumentCaptor.forClass(Acceptable.class);
    verify(flowManager).notify(eq(CREATE_BIND_USER_EVENT.event()), captor.capture());
    Acceptable event = captor.getValue();
    assertTrue(event instanceof CreateBindUserEvent);
    CreateBindUserEvent bindUserEvent = (CreateBindUserEvent) event;
    assertEquals(CREATE_BIND_USER_EVENT.event(), bindUserEvent.selector());
    assertEquals(STACK_ID, bindUserEvent.getResourceId());
    assertEquals(ACCOUNT, bindUserEvent.getAccountId());
    assertEquals(operation.getOperationId(), bindUserEvent.getOperationId());
    assertEquals(request.getEnvironmentCrn(), bindUserEvent.getEnvironmentCrn());
    assertEquals(request.getBindUserNameSuffix(), bindUserEvent.getSuffix());
}
Also used : BindUserCreateRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.binduser.BindUserCreateRequest) OperationStatus(com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) CreateBindUserEvent(com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent) Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Example 9 with CreateBindUserEvent

use of com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent in project cloudbreak by hortonworks.

the class KerberosBindUserCreationHandlerTest method testCreated.

@Test
public void testCreated() throws FreeIpaClientException {
    CreateBindUserEvent createBindUserEvent = new CreateBindUserEvent("selector", 1L, "acc", "opid", "suffix", "envcrn");
    CreateKerberosBindUserEvent createKerberosBindUserEvent = new CreateKerberosBindUserEvent(createBindUserEvent);
    HandlerEvent<CreateKerberosBindUserEvent> handlerEvent = new HandlerEvent<>(new Event<>(createKerberosBindUserEvent));
    when(kerberosConfigService.find(createBindUserEvent.getEnvironmentCrn(), createBindUserEvent.getAccountId(), createBindUserEvent.getSuffix())).thenReturn(Optional.empty());
    Stack stack = new Stack();
    when(stackService.getByEnvironmentCrnAndAccountId(createBindUserEvent.getEnvironmentCrn(), createBindUserEvent.getAccountId())).thenReturn(stack);
    Selectable selectable = underTest.doAccept(handlerEvent);
    assertTrue(selectable instanceof CreateBindUserEvent);
    CreateBindUserEvent event = (CreateBindUserEvent) selectable;
    assertEquals(CreateBindUserFlowEvent.CREATE_KERBEROS_BIND_USER_FINISHED_EVENT.event(), event.selector());
    assertEquals(createBindUserEvent.getOperationId(), event.getOperationId());
    assertEquals(createBindUserEvent.getSuffix(), event.getSuffix());
    assertEquals(createBindUserEvent.getAccountId(), event.getAccountId());
    assertEquals(createBindUserEvent.getResourceId(), event.getResourceId());
    verify(stackService).getByEnvironmentCrnAndAccountId(createBindUserEvent.getEnvironmentCrn(), createBindUserEvent.getAccountId());
    verify(kerberosConfigV1Service).createNewKerberosConfig(createBindUserEvent.getEnvironmentCrn(), createBindUserEvent.getSuffix(), stack, true);
}
Also used : CreateKerberosBindUserEvent(com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateKerberosBindUserEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) CreateBindUserEvent(com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 10 with CreateBindUserEvent

use of com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent in project cloudbreak by hortonworks.

the class KerberosBindUserCreationHandlerTest method testDefaultFailureEventCreation.

@Test
public void testDefaultFailureEventCreation() {
    CreateBindUserEvent createBindUserEvent = new CreateBindUserEvent("selector", 1L, "acc", "opid", "suffix", "envcrn");
    CreateKerberosBindUserEvent createKerberosBindUserEvent = new CreateKerberosBindUserEvent(createBindUserEvent);
    Exception exception = new Exception("test");
    Selectable result = underTest.defaultFailureEvent(1L, exception, new Event<>(createKerberosBindUserEvent));
    assertTrue(result instanceof CreateBindUserFailureEvent);
    CreateBindUserFailureEvent failureEvent = (CreateBindUserFailureEvent) result;
    assertEquals(CreateBindUserFlowEvent.CREATE_BIND_USER_FAILED_EVENT.event(), failureEvent.selector());
    assertEquals("Kerberos bind user creation failed for suffix with test", failureEvent.getFailureMessage());
    assertEquals(exception, failureEvent.getException());
}
Also used : CreateKerberosBindUserEvent(com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateKerberosBindUserEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) CreateBindUserFailureEvent(com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserFailureEvent) CreateBindUserEvent(com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Test(org.junit.jupiter.api.Test)

Aggregations

CreateBindUserEvent (com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent)19 Test (org.junit.jupiter.api.Test)9 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)8 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)6 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)6 Stack (com.sequenceiq.freeipa.entity.Stack)6 CreateKerberosBindUserEvent (com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateKerberosBindUserEvent)5 CreateLdapBindUserEvent (com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateLdapBindUserEvent)5 CreateBindUserFailureEvent (com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserFailureEvent)4 CommonContext (com.sequenceiq.flow.core.CommonContext)3 Map (java.util.Map)3 Bean (org.springframework.context.annotation.Bean)3 KerberosConfig (com.sequenceiq.freeipa.kerberos.KerberosConfig)2 LdapConfig (com.sequenceiq.freeipa.ldap.LdapConfig)2 Acceptable (com.sequenceiq.cloudbreak.common.event.Acceptable)1 BindUserCreateRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.binduser.BindUserCreateRequest)1 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)1 OperationStatus (com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus)1 Operation (com.sequenceiq.freeipa.entity.Operation)1 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)1