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));
}
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)));
}
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())));
}
Aggregations