Search in sources :

Example 71 with HandlerEvent

use of com.sequenceiq.flow.reactor.api.handler.HandlerEvent in project cloudbreak by hortonworks.

the class ValidateInstancesHealthHandlerTest method testUnHealthy.

@Test
public void testUnHealthy() throws FreeIpaClientException {
    Stack stack = new Stack();
    stack.setId(1L);
    when(stackService.getStackById(1L)).thenReturn(stack);
    List<String> instanceIds = List.of("im1", "im2");
    InstanceMetaData im1 = new InstanceMetaData();
    im1.setInstanceId("im1");
    im1.setDiscoveryFQDN("im1Fqdn");
    InstanceMetaData im2 = new InstanceMetaData();
    im2.setInstanceId("im2");
    im2.setDiscoveryFQDN("im2Fqdn");
    when(instanceMetaDataService.getNotTerminatedByInstanceIds(1L, instanceIds)).thenReturn(Set.of(im1, im2));
    when(healthService.getInstanceHealthDetails(stack, im1)).thenReturn(createHealthyNodeDetail(im1));
    NodeHealthDetails unhealthy = createHealthyNodeDetail(im2);
    unhealthy.setStatus(InstanceStatus.UNHEALTHY);
    unhealthy.setIssues(List.of("bad"));
    when(healthService.getInstanceHealthDetails(stack, im2)).thenReturn(unhealthy);
    ValidateInstancesHealthEvent validateInstancesHealthEvent = new ValidateInstancesHealthEvent(1L, instanceIds);
    UpscaleFailureEvent result = (UpscaleFailureEvent) underTest.doAccept(new HandlerEvent<>(new Event<>(validateInstancesHealthEvent)));
    assertEquals(1L, result.getResourceId());
    assertEquals(PHASE, result.getFailedPhase());
    assertTrue(result.getSuccess().contains("im1"));
    assertEquals(1, result.getFailureDetails().size());
    assertEquals("bad", result.getFailureDetails().get("im2"));
    assertEquals("Unhealthy instances found: [im2]", result.getException().getMessage());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) UpscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) NodeHealthDetails(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.NodeHealthDetails) ValidateInstancesHealthEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 72 with HandlerEvent

use of com.sequenceiq.flow.reactor.api.handler.HandlerEvent in project cloudbreak by hortonworks.

the class ValidateInstancesHealthHandlerTest method testHealthy.

@Test
public void testHealthy() throws FreeIpaClientException {
    Stack stack = new Stack();
    stack.setId(1L);
    when(stackService.getStackById(1L)).thenReturn(stack);
    List<String> instanceIds = List.of("im1", "im2");
    InstanceMetaData im1 = new InstanceMetaData();
    im1.setInstanceId("im1");
    im1.setDiscoveryFQDN("im1Fqdn");
    InstanceMetaData im2 = new InstanceMetaData();
    im2.setInstanceId("im2");
    im2.setDiscoveryFQDN("im2Fqdn");
    when(instanceMetaDataService.getNotTerminatedByInstanceIds(1L, instanceIds)).thenReturn(Set.of(im1, im2));
    when(healthService.getInstanceHealthDetails(stack, im1)).thenReturn(createHealthyNodeDetail(im1));
    when(healthService.getInstanceHealthDetails(stack, im2)).thenReturn(createHealthyNodeDetail(im2));
    StackEvent result = (StackEvent) underTest.doAccept(new HandlerEvent<>(new Event<>(new ValidateInstancesHealthEvent(1L, instanceIds))));
    assertEquals(UPSCALE_VALIDATE_NEW_INSTANCES_HEALTH_FINISHED_EVENT.event(), result.selector());
    assertEquals(1L, result.getResourceId());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) ValidateInstancesHealthEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 73 with HandlerEvent

use of com.sequenceiq.flow.reactor.api.handler.HandlerEvent in project cloudbreak by hortonworks.

the class DiagnosticsUpgradeTelemetryHandlerTest method testDoAcceptOnError.

@Test
public void testDoAcceptOnError() throws CloudbreakOrchestratorFailedException {
    // GIVEN
    doThrow(new CloudbreakOrchestratorFailedException("ex")).when(telemetryUpgradeService).upgradeTelemetryComponent(anyLong(), any(), any());
    // WHEN
    DiagnosticsCollectionEvent event = new DiagnosticsCollectionEvent(UPGRADE_DIAGNOSTICS_EVENT.selector(), STACK_ID, "crn", new DiagnosticParameters());
    DiagnosticsFlowException result = assertThrows(DiagnosticsFlowException.class, () -> underTest.doAccept(new HandlerEvent<>(new Event<>(event))));
    // THEN
    assertTrue(result.getMessage().contains("Error during diagnostics operation: Upgrade telemetry"));
}
Also used : CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) DiagnosticParameters(com.sequenceiq.common.model.diagnostics.DiagnosticParameters) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) DiagnosticsCollectionEvent(com.sequenceiq.freeipa.flow.freeipa.diagnostics.event.DiagnosticsCollectionEvent) DiagnosticsFlowException(com.sequenceiq.freeipa.flow.freeipa.diagnostics.DiagnosticsFlowException) Test(org.junit.jupiter.api.Test)

Example 74 with HandlerEvent

use of com.sequenceiq.flow.reactor.api.handler.HandlerEvent in project cloudbreak by hortonworks.

the class DiagnosticsVmPreFlightCheckHandlerTest method testDoAccept.

@Test
public void testDoAccept() throws CloudbreakOrchestratorFailedException {
    // GIVEN
    doNothing().when(diagnosticsOperationsService).vmPreflightCheck(anyLong(), any());
    // WHEN
    DiagnosticsCollectionEvent event = new DiagnosticsCollectionEvent(VM_PREFLIGHT_CHECK_DIAGNOSTICS_EVENT.selector(), STACK_ID, "crn", new DiagnosticParameters());
    underTest.doAccept(new HandlerEvent<>(new Event<>(event)));
    // THEN
    verify(diagnosticsOperationsService, times(1)).vmPreflightCheck(anyLong(), any());
}
Also used : DiagnosticParameters(com.sequenceiq.common.model.diagnostics.DiagnosticParameters) DiagnosticsCollectionEvent(com.sequenceiq.freeipa.flow.freeipa.diagnostics.event.DiagnosticsCollectionEvent) Event(reactor.bus.Event) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) DiagnosticsCollectionEvent(com.sequenceiq.freeipa.flow.freeipa.diagnostics.event.DiagnosticsCollectionEvent) Test(org.junit.jupiter.api.Test)

Example 75 with HandlerEvent

use of com.sequenceiq.flow.reactor.api.handler.HandlerEvent in project cloudbreak by hortonworks.

the class KerberosBindUserCreationHandlerTest method testEventSentIfConfigAlreadyExists.

@Test
public void testEventSentIfConfigAlreadyExists() {
    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.of(new KerberosConfig()));
    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());
    verifyNoInteractions(stackService);
    verifyNoInteractions(kerberosConfigV1Service);
}
Also used : CreateKerberosBindUserEvent(com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateKerberosBindUserEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) KerberosConfig(com.sequenceiq.freeipa.kerberos.KerberosConfig) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) CreateBindUserEvent(com.sequenceiq.freeipa.flow.freeipa.binduser.create.event.CreateBindUserEvent) Test(org.junit.jupiter.api.Test)

Aggregations

HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)85 Test (org.junit.jupiter.api.Test)77 Event (reactor.bus.Event)49 DiagnosticParameters (com.sequenceiq.common.model.diagnostics.DiagnosticParameters)45 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)27 DiagnosticsCollectionEvent (com.sequenceiq.freeipa.flow.freeipa.diagnostics.event.DiagnosticsCollectionEvent)23 DiagnosticsCollectionEvent (com.sequenceiq.cloudbreak.core.flow2.diagnostics.event.DiagnosticsCollectionEvent)22 Set (java.util.Set)20 CloudbreakOrchestratorFailedException (com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException)19 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)18 Collectors (java.util.stream.Collectors)18 List (java.util.List)17 Map (java.util.Map)17 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)16 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)16 CloudbreakFlowMessageService (com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService)15 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)15 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)15 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)15 ClusterApiConnectors (com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors)15