@Test public void testUpdateLoadBalancerWithInvalidMonitor() throws Exception { when(objectMessage.getObject()).thenReturn(lb); when(loadBalancerService.getWithUserPages(LOAD_BALANCER_ID, ACCOUNT_ID)).thenReturn(lb); doThrow(Exception.class).when(reverseProxyLoadBalancerStmService).updateHealthMonitor(lb); when(config.getString(Matchers.<ConfigurationKey>any())).thenReturn("REST"); updateHealthMonitorListener.doOnMessage(objectMessage); verify(reverseProxyLoadBalancerStmService).updateHealthMonitor(lb); verify(loadBalancerService).setStatus(lb, LoadBalancerStatus.ERROR); verify(notificationService).saveAlert(eq(ACCOUNT_ID), eq(LOAD_BALANCER_ID), isA(Exception.class), eq(AlertType.ZEUS_FAILURE.name()), anyString()); verify(notificationService).saveHealthMonitorEvent(eq(USERNAME), eq(ACCOUNT_ID), eq(LOAD_BALANCER_ID), anyInt(), anyString(), anyString(), eq(EventType.UPDATE_HEALTH_MONITOR), eq(CategoryType.UPDATE), eq(EventSeverity.CRITICAL)); }
@Override public void doOnMessage(Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); LoadBalancer queueLb = getLoadbalancerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(queueLb.getId(), queueLb.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", queueLb.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Updating health monitor for load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.updateHealthMonitor(dbLoadBalancer); LOG.debug(String.format("Successfully updated health monitor for load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Updating health monitor for load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.updateHealthMonitor(dbLoadBalancer); LOG.debug(String.format("Successfully updated health monitor for load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error updating health monitor in Zeus for loadbalancer '%d'.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(dbLoadBalancer); return; } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); notificationService.saveHealthMonitorEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), dbLoadBalancer.getHealthMonitor().getId(), UPDATE_MONITOR_TITLE, EntryHelper.createHealthMonitorSummary(dbLoadBalancer), UPDATE_HEALTH_MONITOR, UPDATE, INFO); LOG.info(String.format("Update health monitor operation complete for load balancer '%d'.", dbLoadBalancer.getId())); }
UpdateHealthMonitorListener extends BaseListener { @Override public void doOnMessage(Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); LoadBalancer queueLb = getLoadbalancerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(queueLb.getId(), queueLb.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", queueLb.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Updating health monitor for load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.updateHealthMonitor(dbLoadBalancer); LOG.debug(String.format("Successfully updated health monitor for load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Updating health monitor for load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.updateHealthMonitor(dbLoadBalancer); LOG.debug(String.format("Successfully updated health monitor for load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error updating health monitor in Zeus for loadbalancer '%d'.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(dbLoadBalancer); return; } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); notificationService.saveHealthMonitorEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), dbLoadBalancer.getHealthMonitor().getId(), UPDATE_MONITOR_TITLE, EntryHelper.createHealthMonitorSummary(dbLoadBalancer), UPDATE_HEALTH_MONITOR, UPDATE, INFO); LOG.info(String.format("Update health monitor operation complete for load balancer '%d'.", dbLoadBalancer.getId())); } }
UpdateHealthMonitorListener extends BaseListener { @Override public void doOnMessage(Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); LoadBalancer queueLb = getLoadbalancerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(queueLb.getId(), queueLb.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", queueLb.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Updating health monitor for load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.updateHealthMonitor(dbLoadBalancer); LOG.debug(String.format("Successfully updated health monitor for load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Updating health monitor for load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.updateHealthMonitor(dbLoadBalancer); LOG.debug(String.format("Successfully updated health monitor for load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error updating health monitor in Zeus for loadbalancer '%d'.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(dbLoadBalancer); return; } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); notificationService.saveHealthMonitorEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), dbLoadBalancer.getHealthMonitor().getId(), UPDATE_MONITOR_TITLE, EntryHelper.createHealthMonitorSummary(dbLoadBalancer), UPDATE_HEALTH_MONITOR, UPDATE, INFO); LOG.info(String.format("Update health monitor operation complete for load balancer '%d'.", dbLoadBalancer.getId())); }  }
UpdateHealthMonitorListener extends BaseListener { @Override public void doOnMessage(Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); LoadBalancer queueLb = getLoadbalancerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(queueLb.getId(), queueLb.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", queueLb.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Updating health monitor for load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.updateHealthMonitor(dbLoadBalancer); LOG.debug(String.format("Successfully updated health monitor for load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Updating health monitor for load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.updateHealthMonitor(dbLoadBalancer); LOG.debug(String.format("Successfully updated health monitor for load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error updating health monitor in Zeus for loadbalancer '%d'.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(dbLoadBalancer); return; } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); notificationService.saveHealthMonitorEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), dbLoadBalancer.getHealthMonitor().getId(), UPDATE_MONITOR_TITLE, EntryHelper.createHealthMonitorSummary(dbLoadBalancer), UPDATE_HEALTH_MONITOR, UPDATE, INFO); LOG.info(String.format("Update health monitor operation complete for load balancer '%d'.", dbLoadBalancer.getId())); }  @Override void doOnMessage(Message message); }
UpdateHealthMonitorListener extends BaseListener { @Override public void doOnMessage(Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); LoadBalancer queueLb = getLoadbalancerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(queueLb.getId(), queueLb.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", queueLb.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Updating health monitor for load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.updateHealthMonitor(dbLoadBalancer); LOG.debug(String.format("Successfully updated health monitor for load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Updating health monitor for load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.updateHealthMonitor(dbLoadBalancer); LOG.debug(String.format("Successfully updated health monitor for load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error updating health monitor in Zeus for loadbalancer '%d'.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(dbLoadBalancer); return; } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); notificationService.saveHealthMonitorEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), dbLoadBalancer.getHealthMonitor().getId(), UPDATE_MONITOR_TITLE, EntryHelper.createHealthMonitorSummary(dbLoadBalancer), UPDATE_HEALTH_MONITOR, UPDATE, INFO); LOG.info(String.format("Update health monitor operation complete for load balancer '%d'.", dbLoadBalancer.getId())); }  @Override void doOnMessage(Message message);  }