use of com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent in project cloudbreak by hortonworks.
the class KerberosBindUserCreationHandlerTest method testCreateFailed.
@Test
public void testCreateFailed() 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);
when(kerberosConfigV1Service.createNewKerberosConfig(createBindUserEvent.getEnvironmentCrn(), createBindUserEvent.getSuffix(), stack, true)).thenThrow(new FreeIpaClientException("test"));
Selectable selectable = underTest.doAccept(handlerEvent);
assertTrue(selectable instanceof CreateBindUserEvent);
CreateBindUserEvent event = (CreateBindUserEvent) selectable;
assertEquals(CreateBindUserFlowEvent.CREATE_BIND_USER_FAILED_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);
}
use of com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent in project cloudbreak by hortonworks.
the class LdapBindUserCreationHandlerTest method testDefaultFailureEventCreation.
@Test
public void testDefaultFailureEventCreation() {
CreateBindUserEvent createBindUserEvent = new CreateBindUserEvent("selector", 1L, "acc", "opid", "suffix", "envcrn");
CreateLdapBindUserEvent createLdapBindUserEvent = new CreateLdapBindUserEvent(createBindUserEvent);
Exception exception = new Exception("test");
Selectable result = underTest.defaultFailureEvent(1L, exception, new Event<>(createLdapBindUserEvent));
assertTrue(result instanceof CreateBindUserFailureEvent);
CreateBindUserFailureEvent failureEvent = (CreateBindUserFailureEvent) result;
assertEquals(CreateBindUserFlowEvent.CREATE_BIND_USER_FAILED_EVENT.event(), failureEvent.selector());
assertEquals("LDAP bind user creation failed for suffix with test", failureEvent.getFailureMessage());
assertEquals(exception, failureEvent.getException());
}
use of com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent in project cloudbreak by hortonworks.
the class LdapBindUserCreationHandler method defaultFailureEvent.
@Override
protected Selectable defaultFailureEvent(Long resourceId, Exception e, Event<CreateLdapBindUserEvent> event) {
CreateBindUserEvent eventData = event.getData();
String failureMsg = String.format("LDAP bind user creation failed for %s with %s", eventData.getSuffix(), e.getMessage());
return new CreateBindUserFailureEvent(CreateBindUserFlowEvent.CREATE_BIND_USER_FAILED_EVENT.event(), eventData, failureMsg, e);
}
use of com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent in project cloudbreak by hortonworks.
the class LdapBindUserCreationHandler method createLdapBindUSer.
private Selectable createLdapBindUSer(Event<CreateLdapBindUserEvent> event, CreateBindUserEvent data) {
Stack stack = stackService.getByEnvironmentCrnAndAccountId(data.getEnvironmentCrn(), data.getAccountId());
MDCBuilder.buildMdcContext(stack);
LOGGER.info("Create LDAP bind user for [{}]", data.getSuffix());
try {
ldapConfigV1Service.createNewLdapConfig(data.getEnvironmentCrn(), data.getSuffix(), stack, true);
return new CreateBindUserEvent(CreateBindUserFlowEvent.CREATE_LDAP_BIND_USER_FINISHED_EVENT.event(), data);
} catch (FreeIpaClientException e) {
LOGGER.error("Couldn't create LDAP bind user: {}", data, e);
return defaultFailureEvent(data.getResourceId(), e, event);
}
}
use of com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent in project cloudbreak by hortonworks.
the class LdapBindUserCreationHandler method doAccept.
@Override
protected Selectable doAccept(HandlerEvent<CreateLdapBindUserEvent> event) {
CreateBindUserEvent data = event.getData();
Optional<LdapConfig> ldapConfig = ldapConfigService.find(data.getEnvironmentCrn(), data.getAccountId(), data.getSuffix());
if (ldapConfig.isPresent()) {
LOGGER.info("LDAP configuration already exists: {}", ldapConfig.get());
return new CreateBindUserEvent(CreateBindUserFlowEvent.CREATE_LDAP_BIND_USER_FINISHED_EVENT.event(), data);
} else {
return createLdapBindUSer(event.getEvent(), data);
}
}
Aggregations