Search in sources :

Example 1 with UnhealthyInstancesDetectionRequest

use of com.sequenceiq.cloudbreak.reactor.api.event.resource.UnhealthyInstancesDetectionRequest in project cloudbreak by hortonworks.

the class UnhealthyInstancesDetectionHandler method accept.

@Override
public void accept(Event<UnhealthyInstancesDetectionRequest> event) {
    UnhealthyInstancesDetectionRequest request = event.getData();
    UnhealthyInstancesDetectionResult result;
    Long stackId = request.getStackId();
    Stack stack = stackService.getById(stackId);
    try {
        Set<InstanceMetaData> candidateUnhealthyInstances = unhealthyInstanceSelector.selectCandidateUnhealthyInstances(stack.getId());
        if (candidateUnhealthyInstances.isEmpty()) {
            result = new UnhealthyInstancesDetectionResult(request, Collections.emptySet());
        } else {
            Set<String> unhealthyInstances = unhealthyInstancesFinalizer.finalizeUnhealthyInstances(stack, candidateUnhealthyInstances);
            result = new UnhealthyInstancesDetectionResult(request, unhealthyInstances);
        }
    } catch (RuntimeException e) {
        String msg = String.format("Could not get statuses for unhealty instances: %s", e.getMessage());
        LOG.error(msg, e);
        result = new UnhealthyInstancesDetectionResult(msg, e, request);
    }
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
}
Also used : UnhealthyInstancesDetectionResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.UnhealthyInstancesDetectionResult) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) UnhealthyInstancesDetectionRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.UnhealthyInstancesDetectionRequest) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 2 with UnhealthyInstancesDetectionRequest

use of com.sequenceiq.cloudbreak.reactor.api.event.resource.UnhealthyInstancesDetectionRequest in project cloudbreak by hortonworks.

the class UnhealthyInstancesDetectionHandlerTest method shouldCreateResponseWithExactInstances.

@Test
public void shouldCreateResponseWithExactInstances() throws CloudbreakSecuritySetupException {
    long stackId = 1L;
    UnhealthyInstancesDetectionRequest unhealthyInstancesDetectionRequest = new UnhealthyInstancesDetectionRequest(stackId);
    Event event = mock(Event.class);
    when(event.getData()).thenReturn(unhealthyInstancesDetectionRequest);
    Stack stack = mock(Stack.class);
    when(stackService.getById(stackId)).thenReturn(stack);
    Set<InstanceMetaData> unhealthyInstances = new HashSet<>();
    InstanceMetaData imd1 = mock(InstanceMetaData.class);
    InstanceMetaData imd2 = mock(InstanceMetaData.class);
    InstanceMetaData imd3 = mock(InstanceMetaData.class);
    unhealthyInstances.add(imd1);
    unhealthyInstances.add(imd2);
    unhealthyInstances.add(imd3);
    when(candidateUnhealthyInstanceSelector.selectCandidateUnhealthyInstances(stack.getId())).thenReturn(unhealthyInstances);
    Set<String> unhealthyInstanceIds = new HashSet<>();
    unhealthyInstanceIds.add("i-0f1e0605506aaaaaa");
    unhealthyInstanceIds.add("i-0f1e0605506cccccc");
    when(unhealthyInstancesFinalizer.finalizeUnhealthyInstances(stack, unhealthyInstances)).thenReturn(unhealthyInstanceIds);
    unhealthyInstancesDetectionHandler.accept(event);
    verify(eventBus).notify(eq(EventSelectorUtil.selector(UnhealthyInstancesDetectionResult.class)), argThat(new UnhealthyInstancesResultMatcher(unhealthyInstanceIds)));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) Event(reactor.bus.Event) UnhealthyInstancesDetectionRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.UnhealthyInstancesDetectionRequest) Stack(com.sequenceiq.cloudbreak.domain.Stack) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with UnhealthyInstancesDetectionRequest

use of com.sequenceiq.cloudbreak.reactor.api.event.resource.UnhealthyInstancesDetectionRequest in project cloudbreak by hortonworks.

the class UnhealthyInstancesDetectionHandlerTest method shouldNotInvokeFinalizerIfNoCandidateUnhealthyInstancesWereSelected.

@Test
public void shouldNotInvokeFinalizerIfNoCandidateUnhealthyInstancesWereSelected() throws CloudbreakSecuritySetupException {
    long stackId = 1L;
    UnhealthyInstancesDetectionRequest unhealthyInstancesDetectionRequest = new UnhealthyInstancesDetectionRequest(stackId);
    Event event = mock(Event.class);
    when(event.getData()).thenReturn(unhealthyInstancesDetectionRequest);
    Stack stack = mock(Stack.class);
    when(stack.getId()).thenReturn(stackId);
    when(stackService.getById(stackId)).thenReturn(stack);
    when(candidateUnhealthyInstanceSelector.selectCandidateUnhealthyInstances(stackId)).thenReturn(Collections.emptySet());
    unhealthyInstancesDetectionHandler.accept(event);
    verifyZeroInteractions(unhealthyInstancesFinalizer);
    verify(eventBus).notify(eq(EventSelectorUtil.selector(UnhealthyInstancesDetectionResult.class)), argThat(new UnhealthyInstancesResultMatcher(Collections.emptySet())));
}
Also used : Event(reactor.bus.Event) UnhealthyInstancesDetectionRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.UnhealthyInstancesDetectionRequest) Stack(com.sequenceiq.cloudbreak.domain.Stack) Test(org.junit.Test)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.Stack)3 UnhealthyInstancesDetectionRequest (com.sequenceiq.cloudbreak.reactor.api.event.resource.UnhealthyInstancesDetectionRequest)3 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)2 Test (org.junit.Test)2 Event (reactor.bus.Event)2 UnhealthyInstancesDetectionResult (com.sequenceiq.cloudbreak.reactor.api.event.resource.UnhealthyInstancesDetectionResult)1 HashSet (java.util.HashSet)1