class 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);
        }
    }

}