@Test public void testCreateNodesWithInvalidNodes() throws Exception { when(objectMessage.getObject()).thenReturn(lb); when(loadBalancerService.getWithUserPages(LOAD_BALANCER_ID, ACCOUNT_ID)).thenReturn(lb); when(config.getString(Matchers.<ConfigurationKey>any())).thenReturn("REST"); doThrow(Exception.class).when(reverseProxyLoadBalancerStmService).setNodes(lb); createNodesListener.doOnMessage(objectMessage); verify(reverseProxyLoadBalancerStmService).setNodes(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).saveNodeEvent(eq(USERNAME), eq(ACCOUNT_ID), eq(LOAD_BALANCER_ID), eq(NODE_ID), anyString(), anyString(), eq(EventType.CREATE_NODE), eq(CategoryType.CREATE), eq(EventSeverity.CRITICAL)); }
@Override public void doOnMessage(final 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("Setting nodes in STM..."); reverseProxyLoadBalancerStmService.setNodes(dbLoadBalancer); LOG.debug("Nodes successfully set."); } else { LOG.debug("Setting nodes in ZXTM..."); reverseProxyLoadBalancerService.setNodes(dbLoadBalancer); LOG.debug("Nodes successfully set."); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = "Error setting nodes in Zeus for loadbalancer #" + dbLoadBalancer.getId(); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); NodesHelper.setNodesToStatus(queueLb, dbLoadBalancer, NodeStatus.ONLINE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); for (Node dbNode : dbLoadBalancer.getNodes()) { for (Node queueNode : queueLb.getNodes()) { if (queueNode.getIpAddress().equals(dbNode.getIpAddress()) && queueNode.getPort().equals(dbNode.getPort())) notificationService.saveNodeEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), dbNode.getId(), CREATE_NODE_TITLE, EntryHelper.createNodeSummary(dbNode), CREATE_NODE, CREATE, INFO); } } LOG.info(String.format("Create nodes operation successfully completed for load balancer '%d'", dbLoadBalancer.getId())); }
CreateNodesListener extends BaseListener { @Override public void doOnMessage(final 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("Setting nodes in STM..."); reverseProxyLoadBalancerStmService.setNodes(dbLoadBalancer); LOG.debug("Nodes successfully set."); } else { LOG.debug("Setting nodes in ZXTM..."); reverseProxyLoadBalancerService.setNodes(dbLoadBalancer); LOG.debug("Nodes successfully set."); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = "Error setting nodes in Zeus for loadbalancer #" + dbLoadBalancer.getId(); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); NodesHelper.setNodesToStatus(queueLb, dbLoadBalancer, NodeStatus.ONLINE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); for (Node dbNode : dbLoadBalancer.getNodes()) { for (Node queueNode : queueLb.getNodes()) { if (queueNode.getIpAddress().equals(dbNode.getIpAddress()) && queueNode.getPort().equals(dbNode.getPort())) notificationService.saveNodeEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), dbNode.getId(), CREATE_NODE_TITLE, EntryHelper.createNodeSummary(dbNode), CREATE_NODE, CREATE, INFO); } } LOG.info(String.format("Create nodes operation successfully completed for load balancer '%d'", dbLoadBalancer.getId())); } }
CreateNodesListener extends BaseListener { @Override public void doOnMessage(final 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("Setting nodes in STM..."); reverseProxyLoadBalancerStmService.setNodes(dbLoadBalancer); LOG.debug("Nodes successfully set."); } else { LOG.debug("Setting nodes in ZXTM..."); reverseProxyLoadBalancerService.setNodes(dbLoadBalancer); LOG.debug("Nodes successfully set."); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = "Error setting nodes in Zeus for loadbalancer #" + dbLoadBalancer.getId(); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); NodesHelper.setNodesToStatus(queueLb, dbLoadBalancer, NodeStatus.ONLINE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); for (Node dbNode : dbLoadBalancer.getNodes()) { for (Node queueNode : queueLb.getNodes()) { if (queueNode.getIpAddress().equals(dbNode.getIpAddress()) && queueNode.getPort().equals(dbNode.getPort())) notificationService.saveNodeEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), dbNode.getId(), CREATE_NODE_TITLE, EntryHelper.createNodeSummary(dbNode), CREATE_NODE, CREATE, INFO); } } LOG.info(String.format("Create nodes operation successfully completed for load balancer '%d'", dbLoadBalancer.getId())); }  }
CreateNodesListener extends BaseListener { @Override public void doOnMessage(final 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("Setting nodes in STM..."); reverseProxyLoadBalancerStmService.setNodes(dbLoadBalancer); LOG.debug("Nodes successfully set."); } else { LOG.debug("Setting nodes in ZXTM..."); reverseProxyLoadBalancerService.setNodes(dbLoadBalancer); LOG.debug("Nodes successfully set."); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = "Error setting nodes in Zeus for loadbalancer #" + dbLoadBalancer.getId(); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); NodesHelper.setNodesToStatus(queueLb, dbLoadBalancer, NodeStatus.ONLINE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); for (Node dbNode : dbLoadBalancer.getNodes()) { for (Node queueNode : queueLb.getNodes()) { if (queueNode.getIpAddress().equals(dbNode.getIpAddress()) && queueNode.getPort().equals(dbNode.getPort())) notificationService.saveNodeEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), dbNode.getId(), CREATE_NODE_TITLE, EntryHelper.createNodeSummary(dbNode), CREATE_NODE, CREATE, INFO); } } LOG.info(String.format("Create nodes operation successfully completed for load balancer '%d'", dbLoadBalancer.getId())); }  @Override void doOnMessage(final Message message); }
CreateNodesListener extends BaseListener { @Override public void doOnMessage(final 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("Setting nodes in STM..."); reverseProxyLoadBalancerStmService.setNodes(dbLoadBalancer); LOG.debug("Nodes successfully set."); } else { LOG.debug("Setting nodes in ZXTM..."); reverseProxyLoadBalancerService.setNodes(dbLoadBalancer); LOG.debug("Nodes successfully set."); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = "Error setting nodes in Zeus for loadbalancer #" + dbLoadBalancer.getId(); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); NodesHelper.setNodesToStatus(queueLb, dbLoadBalancer, NodeStatus.ONLINE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); for (Node dbNode : dbLoadBalancer.getNodes()) { for (Node queueNode : queueLb.getNodes()) { if (queueNode.getIpAddress().equals(dbNode.getIpAddress()) && queueNode.getPort().equals(dbNode.getPort())) notificationService.saveNodeEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), dbNode.getId(), CREATE_NODE_TITLE, EntryHelper.createNodeSummary(dbNode), CREATE_NODE, CREATE, INFO); } } LOG.info(String.format("Create nodes operation successfully completed for load balancer '%d'", dbLoadBalancer.getId())); }  @Override void doOnMessage(final Message message);  }