use of com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.PollBindUserCreationEvent in project cloudbreak by hortonworks.
the class KerberosConfigValidationActions method pollBindUserCreationAction.
@Bean(name = "POLL_BIND_USER_CREATION_STATE")
public Action<?, ?> pollBindUserCreationAction() {
return new AbstractStackCreationAction<>(PollBindUserCreationEvent.class) {
@Override
protected void doExecute(StackCreationContext context, PollBindUserCreationEvent payload, Map<Object, Object> variables) {
PollBindUserCreationEvent event = new PollBindUserCreationEvent(payload.getResourceId(), payload.getOperationId(), Crn.safeFromString(context.getStack().getResourceCrn()).getAccountId());
sendEvent(context, event);
}
@Override
protected Object getFailurePayload(PollBindUserCreationEvent payload, Optional<StackCreationContext> flowContext, Exception ex) {
return new StackFailureEvent(KerberosConfigValidationEvent.VALIDATE_KERBEROS_CONFIG_FAILED_EVENT.selector(), payload.getResourceId(), ex);
}
};
}
use of com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.PollBindUserCreationEvent 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()));
}
}
use of com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.PollBindUserCreationEvent 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());
}
use of com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.PollBindUserCreationEvent in project cloudbreak by hortonworks.
the class PollBindUserCreationHandlerTest method testPollingFailed.
@Test
public void testPollingFailed() {
Event<PollBindUserCreationEvent> event = new Event<>(new PollBindUserCreationEvent(1L, "opId", "acc"));
ArgumentCaptor<FreeIpaOperationPollerObject> captor = ArgumentCaptor.forClass(FreeIpaOperationPollerObject.class);
ExtendedPollingResult extendedPollingResult = new ExtendedPollingResult.ExtendedPollingResultBuilder().failure().withException(new Exception("error")).build();
when(freeIpaOperationChecker.pollWithAbsoluteTimeout(any(FreeIpaOperationCheckerTask.class), captor.capture(), anyLong(), anyLong(), anyInt())).thenReturn(extendedPollingResult);
StackFailureEvent result = (StackFailureEvent) underTest.doAccept(new HandlerEvent<>(event));
assertEquals(VALIDATE_KERBEROS_CONFIG_FAILED_EVENT.event(), result.selector());
assertEquals(1L, result.getResourceId());
assertEquals("Bind user creation failed with: error", result.getException().getMessage());
FreeIpaOperationPollerObject pollerObject = captor.getValue();
assertEquals(BIND_USER_CREATE.name(), pollerObject.getOperationType());
assertEquals("opId", pollerObject.getOperationId());
assertEquals(operationV1Endpoint, pollerObject.getOperationV1Endpoint());
}
use of com.sequenceiq.cloudbreak.core.flow2.validate.kerberosconfig.event.PollBindUserCreationEvent in project cloudbreak by hortonworks.
the class PollBindUserCreationHandlerTest method testDefaultFailureEvent.
@Test
public void testDefaultFailureEvent() {
Event<PollBindUserCreationEvent> event = new Event<>(new PollBindUserCreationEvent(1L, "opId", "acc"));
Exception e = new Exception();
StackFailureEvent result = (StackFailureEvent) underTest.defaultFailureEvent(1L, e, event);
assertEquals(VALIDATE_KERBEROS_CONFIG_FAILED_EVENT.event(), result.selector());
assertEquals(1L, result.getResourceId());
assertEquals(e, result.getException());
}
Aggregations