use of com.sequenceiq.flow.reactor.api.handler.HandlerEvent in project cloudbreak by hortonworks.
the class StopStartUpscaleCommissionViaCMHandlerTest method testErrorFromCmHostCollection.
@Test
void testErrorFromCmHostCollection() throws ClusterClientInitException {
int commissionInstanceCount = 5;
List<InstanceMetaData> instancesToCommission = createInstancesToCommission(commissionInstanceCount);
HostGroup hostGroup = createHostGroup(instancesToCommission);
Set<String> hostNames = instancesToCommission.stream().map(i -> i.getDiscoveryFQDN()).collect(Collectors.toSet());
Map<String, InstanceMetaData> cmAvailableHosts = instancesToCommission.stream().collect(Collectors.toMap(i -> i.getDiscoveryFQDN(), i -> i));
Set<String> recommissionedFqdns = cmAvailableHosts.keySet().stream().collect(Collectors.toUnmodifiableSet());
setupPerTestMocks(hostGroup, hostNames, cmAvailableHosts, recommissionedFqdns);
when(clusterCommissionService.collectHostsToCommission(eq(hostGroup), eq(hostNames))).thenThrow(new RuntimeException("collectHostsToCommissionError"));
StopStartUpscaleCommissionViaCMRequest request = new StopStartUpscaleCommissionViaCMRequest(1L, INSTANCE_GROUP_NAME, instancesToCommission, Collections.emptyList());
HandlerEvent handlerEvent = new HandlerEvent(Event.wrap(request));
Selectable selectable = underTest.doAccept(handlerEvent);
assertThat(selectable).isInstanceOf(StopStartUpscaleCommissionViaCMResult.class);
StopStartUpscaleCommissionViaCMResult result = (StopStartUpscaleCommissionViaCMResult) selectable;
assertThat(result.getSuccessfullyCommissionedFqdns()).hasSize(0);
assertThat(result.getNotRecommissionedFqdns()).hasSize(0);
assertThat(result.getErrorDetails().getMessage()).isEqualTo("collectHostsToCommissionError");
assertThat(result.getStatus()).isEqualTo(EventStatus.FAILED);
assertThat(result.selector()).isEqualTo("STOPSTARTUPSCALECOMMISSIONVIACMRESULT_ERROR");
}
use of com.sequenceiq.flow.reactor.api.handler.HandlerEvent in project cloudbreak by hortonworks.
the class CheckFreeIpaExistsHandlerTest method testFreeIpaExists.
@Test
public void testFreeIpaExists() {
Event<CheckFreeIpaExistsEvent> event = new Event<>(new CheckFreeIpaExistsEvent(1L));
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
StackEvent result = (StackEvent) ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.doAccept(new HandlerEvent<>(event)));
assertEquals(KerberosConfigValidationEvent.FREEIPA_EXISTS_EVENT.event(), result.selector());
assertEquals(1L, result.getResourceId());
verify(freeIpaV1Endpoint).describeInternal(ENV_CRN, "1234");
}
use of com.sequenceiq.flow.reactor.api.handler.HandlerEvent 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());
}
use of com.sequenceiq.flow.reactor.api.handler.HandlerEvent 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.flow.reactor.api.handler.HandlerEvent 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());
}
Aggregations