@Test public void testEventSentOnErrorNotRecover() { Event<CleanupFreeIpaEvent> cleanupFreeIpaEvent = mock(Event.class); when(cleanupFreeIpaEvent.getData()).thenReturn(new CleanupFreeIpaEvent(1L, Set.of(), Set.of(), false)); when(stackService.get(1L)).thenReturn(new Stack()); doThrow(new RuntimeException()).when(freeIpaCleanupService).cleanupOnScale(any(Stack.class), anySet(), anySet()); underTest.accept(cleanupFreeIpaEvent); verify(eventBus).notify(eq(CLEANUP_FREEIPA_FINISHED_EVENT.event()), any(Event.class)); }
@Override public void accept(Event<CleanupFreeIpaEvent> cleanupFreeIpaEvent) { CleanupFreeIpaEvent event = cleanupFreeIpaEvent.getData(); try { LOGGER.debug("Handle cleanup request for hosts: {} and IPs: {}", event.getHostNames(), event.getIps()); Stack stack = stackService.get(event.getResourceId()); if (event.isRecover()) { LOGGER.debug("Invoke cleanup on recover"); freeIpaCleanupService.cleanupOnRecover(stack, event.getHostNames(), event.getIps()); } else { LOGGER.debug("Invoke cleanup on scale"); freeIpaCleanupService.cleanupOnScale(stack, event.getHostNames(), event.getIps()); } LOGGER.debug("Cleanup finished for hosts: {} and IPs: {}", event.getHostNames(), event.getIps()); } catch (Exception e) { LOGGER.error("FreeIPA cleanup failed for hosts {} and IPs: {}", event.getHostNames(), event.getIps(), e); } finally { CleanupFreeIpaEvent response = new CleanupFreeIpaEvent(CLEANUP_FREEIPA_FINISHED_EVENT.event(), event.getResourceId(), event.getHostNames(), event.getIps(), event.isRecover()); Event<StackEvent> responseEvent = new Event<>(cleanupFreeIpaEvent.getHeaders(), response); eventBus.notify(CLEANUP_FREEIPA_FINISHED_EVENT.event(), responseEvent); } }
CleanupFreeIpaHandler implements EventHandler<CleanupFreeIpaEvent> { @Override public void accept(Event<CleanupFreeIpaEvent> cleanupFreeIpaEvent) { CleanupFreeIpaEvent event = cleanupFreeIpaEvent.getData(); try { LOGGER.debug("Handle cleanup request for hosts: {} and IPs: {}", event.getHostNames(), event.getIps()); Stack stack = stackService.get(event.getResourceId()); if (event.isRecover()) { LOGGER.debug("Invoke cleanup on recover"); freeIpaCleanupService.cleanupOnRecover(stack, event.getHostNames(), event.getIps()); } else { LOGGER.debug("Invoke cleanup on scale"); freeIpaCleanupService.cleanupOnScale(stack, event.getHostNames(), event.getIps()); } LOGGER.debug("Cleanup finished for hosts: {} and IPs: {}", event.getHostNames(), event.getIps()); } catch (Exception e) { LOGGER.error("FreeIPA cleanup failed for hosts {} and IPs: {}", event.getHostNames(), event.getIps(), e); } finally { CleanupFreeIpaEvent response = new CleanupFreeIpaEvent(CLEANUP_FREEIPA_FINISHED_EVENT.event(), event.getResourceId(), event.getHostNames(), event.getIps(), event.isRecover()); Event<StackEvent> responseEvent = new Event<>(cleanupFreeIpaEvent.getHeaders(), response); eventBus.notify(CLEANUP_FREEIPA_FINISHED_EVENT.event(), responseEvent); } } }
CleanupFreeIpaHandler implements EventHandler<CleanupFreeIpaEvent> { @Override public void accept(Event<CleanupFreeIpaEvent> cleanupFreeIpaEvent) { CleanupFreeIpaEvent event = cleanupFreeIpaEvent.getData(); try { LOGGER.debug("Handle cleanup request for hosts: {} and IPs: {}", event.getHostNames(), event.getIps()); Stack stack = stackService.get(event.getResourceId()); if (event.isRecover()) { LOGGER.debug("Invoke cleanup on recover"); freeIpaCleanupService.cleanupOnRecover(stack, event.getHostNames(), event.getIps()); } else { LOGGER.debug("Invoke cleanup on scale"); freeIpaCleanupService.cleanupOnScale(stack, event.getHostNames(), event.getIps()); } LOGGER.debug("Cleanup finished for hosts: {} and IPs: {}", event.getHostNames(), event.getIps()); } catch (Exception e) { LOGGER.error("FreeIPA cleanup failed for hosts {} and IPs: {}", event.getHostNames(), event.getIps(), e); } finally { CleanupFreeIpaEvent response = new CleanupFreeIpaEvent(CLEANUP_FREEIPA_FINISHED_EVENT.event(), event.getResourceId(), event.getHostNames(), event.getIps(), event.isRecover()); Event<StackEvent> responseEvent = new Event<>(cleanupFreeIpaEvent.getHeaders(), response); eventBus.notify(CLEANUP_FREEIPA_FINISHED_EVENT.event(), responseEvent); } }  }
CleanupFreeIpaHandler implements EventHandler<CleanupFreeIpaEvent> { @Override public void accept(Event<CleanupFreeIpaEvent> cleanupFreeIpaEvent) { CleanupFreeIpaEvent event = cleanupFreeIpaEvent.getData(); try { LOGGER.debug("Handle cleanup request for hosts: {} and IPs: {}", event.getHostNames(), event.getIps()); Stack stack = stackService.get(event.getResourceId()); if (event.isRecover()) { LOGGER.debug("Invoke cleanup on recover"); freeIpaCleanupService.cleanupOnRecover(stack, event.getHostNames(), event.getIps()); } else { LOGGER.debug("Invoke cleanup on scale"); freeIpaCleanupService.cleanupOnScale(stack, event.getHostNames(), event.getIps()); } LOGGER.debug("Cleanup finished for hosts: {} and IPs: {}", event.getHostNames(), event.getIps()); } catch (Exception e) { LOGGER.error("FreeIPA cleanup failed for hosts {} and IPs: {}", event.getHostNames(), event.getIps(), e); } finally { CleanupFreeIpaEvent response = new CleanupFreeIpaEvent(CLEANUP_FREEIPA_FINISHED_EVENT.event(), event.getResourceId(), event.getHostNames(), event.getIps(), event.isRecover()); Event<StackEvent> responseEvent = new Event<>(cleanupFreeIpaEvent.getHeaders(), response); eventBus.notify(CLEANUP_FREEIPA_FINISHED_EVENT.event(), responseEvent); } }  @Override String selector(); @Override void accept(Event<CleanupFreeIpaEvent> cleanupFreeIpaEvent); }
CleanupFreeIpaHandler implements EventHandler<CleanupFreeIpaEvent> { @Override public void accept(Event<CleanupFreeIpaEvent> cleanupFreeIpaEvent) { CleanupFreeIpaEvent event = cleanupFreeIpaEvent.getData(); try { LOGGER.debug("Handle cleanup request for hosts: {} and IPs: {}", event.getHostNames(), event.getIps()); Stack stack = stackService.get(event.getResourceId()); if (event.isRecover()) { LOGGER.debug("Invoke cleanup on recover"); freeIpaCleanupService.cleanupOnRecover(stack, event.getHostNames(), event.getIps()); } else { LOGGER.debug("Invoke cleanup on scale"); freeIpaCleanupService.cleanupOnScale(stack, event.getHostNames(), event.getIps()); } LOGGER.debug("Cleanup finished for hosts: {} and IPs: {}", event.getHostNames(), event.getIps()); } catch (Exception e) { LOGGER.error("FreeIPA cleanup failed for hosts {} and IPs: {}", event.getHostNames(), event.getIps(), e); } finally { CleanupFreeIpaEvent response = new CleanupFreeIpaEvent(CLEANUP_FREEIPA_FINISHED_EVENT.event(), event.getResourceId(), event.getHostNames(), event.getIps(), event.isRecover()); Event<StackEvent> responseEvent = new Event<>(cleanupFreeIpaEvent.getHeaders(), response); eventBus.notify(CLEANUP_FREEIPA_FINISHED_EVENT.event(), responseEvent); } }  @Override String selector(); @Override void accept(Event<CleanupFreeIpaEvent> cleanupFreeIpaEvent);  }