Search in sources :

Example 1 with ValidateInstancesHealthEvent

use of com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent in project cloudbreak by hortonworks.

the class ValidateInstancesHealthHandler method fetchInstancesHealth.

private List<NodeHealthDetails> fetchInstancesHealth(ValidateInstancesHealthEvent event) {
    Stack stack = stackService.getStackById(event.getResourceId());
    MDCBuilder.buildMdcContext(stack);
    Set<InstanceMetaData> instanceMetaDatas = instanceMetaDataService.getNotTerminatedByInstanceIds(stack.getId(), event.getInstanceIds());
    List<NodeHealthDetails> healthDetails = instanceMetaDatas.stream().map(im -> getInstanceHealthDetails(stack, im)).collect(Collectors.toList());
    LOGGER.info("Fetched healthdetails for instances {} - {}", event.getInstanceIds(), healthDetails);
    return healthDetails;
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) LoggerFactory(org.slf4j.LoggerFactory) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) UpscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent) Inject(javax.inject.Inject) FreeIpaInstanceHealthDetailsService(com.sequenceiq.freeipa.service.stack.FreeIpaInstanceHealthDetailsService) ExceptionCatcherEventHandler(com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler) Event(reactor.bus.Event) Map(java.util.Map) StackService(com.sequenceiq.freeipa.service.stack.StackService) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) InstanceMetaDataService(com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService) Logger(org.slf4j.Logger) ValidateInstancesHealthEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent) UPSCALE_VALIDATE_NEW_INSTANCES_HEALTH_FINISHED_EVENT(com.sequenceiq.freeipa.flow.freeipa.upscale.UpscaleFlowEvent.UPSCALE_VALIDATE_NEW_INSTANCES_HEALTH_FINISHED_EVENT) Set(java.util.Set) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) NodeHealthDetails(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.NodeHealthDetails) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) Joiner(com.google.common.base.Joiner) NodeHealthDetails(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.NodeHealthDetails) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 2 with ValidateInstancesHealthEvent

use of com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent in project cloudbreak by hortonworks.

the class ValidateInstancesHealthHandlerTest method testExceptionDuringHealthCheck.

@Test
public void testExceptionDuringHealthCheck() 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)).thenThrow(new FreeIpaClientException("nono"));
    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("nono", 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) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) ValidateInstancesHealthEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 3 with ValidateInstancesHealthEvent

use of com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent 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 4 with ValidateInstancesHealthEvent

use of com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent in project cloudbreak by hortonworks.

the class ValidateInstancesHealthHandlerTest method testDefaultFailureEvent.

@Test
public void testDefaultFailureEvent() {
    Exception e = new Exception("puff");
    Event<ValidateInstancesHealthEvent> event = new Event<>(new ValidateInstancesHealthEvent(3L, List.of()));
    UpscaleFailureEvent result = (UpscaleFailureEvent) underTest.defaultFailureEvent(2L, e, event);
    assertEquals(e, result.getException());
    assertEquals(2L, result.getResourceId());
    assertEquals(PHASE, result.getFailedPhase());
}
Also used : UpscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent) UpscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent) Event(reactor.bus.Event) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) ValidateInstancesHealthEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) ValidateInstancesHealthEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Test(org.junit.jupiter.api.Test)

Example 5 with ValidateInstancesHealthEvent

use of com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent 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)

Aggregations

HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)5 ValidateInstancesHealthEvent (com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent)5 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)4 Stack (com.sequenceiq.freeipa.entity.Stack)4 UpscaleFailureEvent (com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent)4 Test (org.junit.jupiter.api.Test)4 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)3 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)3 NodeHealthDetails (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.health.NodeHealthDetails)2 Event (reactor.bus.Event)2 Joiner (com.google.common.base.Joiner)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)1 EventSelectorUtil (com.sequenceiq.flow.event.EventSelectorUtil)1 ExceptionCatcherEventHandler (com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler)1 InstanceStatus (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus)1 UPSCALE_VALIDATE_NEW_INSTANCES_HEALTH_FINISHED_EVENT (com.sequenceiq.freeipa.flow.freeipa.upscale.UpscaleFlowEvent.UPSCALE_VALIDATE_NEW_INSTANCES_HEALTH_FINISHED_EVENT)1 FreeIpaInstanceHealthDetailsService (com.sequenceiq.freeipa.service.stack.FreeIpaInstanceHealthDetailsService)1 StackService (com.sequenceiq.freeipa.service.stack.StackService)1 InstanceMetaDataService (com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService)1