@Test public void testDeleteNodes() throws Exception { when(objectMessage.getObject()).thenReturn(messageDataContainer); when(messageDataContainer.getAccountId()).thenReturn(ACCOUNT_ID); when(messageDataContainer.getLoadBalancerId()).thenReturn(LOAD_BALANCER_ID); when(messageDataContainer.getUserName()).thenReturn(USERNAME); when(messageDataContainer.getIds()).thenReturn(doomedNodeIds); when(nodeService.getNodesByIds(doomedNodeIds)).thenReturn(doomedNodes); when(loadBalancerService.get(LOAD_BALANCER_ID, ACCOUNT_ID)).thenReturn(lb); when(loadBalancerService.getWithUserPages(LOAD_BALANCER_ID, ACCOUNT_ID)).thenReturn(lb); when(config.getString(Matchers.<ConfigurationKey>any())).thenReturn("REST"); deleteNodesListener.doOnMessage(objectMessage); verify(loadBalancerService).getWithUserPages(LOAD_BALANCER_ID, ACCOUNT_ID); verify(loadBalancerService).get(LOAD_BALANCER_ID, ACCOUNT_ID); verify(messageDataContainer).getIds(); verify(nodeService).getNodesByIds(doomedNodeIds); verify(reverseProxyLoadBalancerStmService).removeNodes(lb, doomedNodes); verify(nodeService).delNodes(lb, doomedNodes); Assert.assertEquals(lb.getStatus(), LoadBalancerStatus.ACTIVE); verify(loadBalancerService).update(lb); verify(loadBalancerStatusHistoryService).save(ACCOUNT_ID, LOAD_BALANCER_ID, LoadBalancerStatus.ACTIVE); verify(notificationService, times(2)).saveNodeEvent(eq(USERNAME), eq(ACCOUNT_ID), eq(LOAD_BALANCER_ID), anyInt(), anyString(), anyString(), eq(EventType.DELETE_NODE), eq(CategoryType.DELETE), eq(EventSeverity.INFO)); }
@Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer msg = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(msg.getLoadBalancerId(), msg.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", msg.getLoadBalancerId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(msg.getAccountId(), msg.getLoadBalancerId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(msg); return; } List<Integer> doomedNodeIds = msg.getIds(); List<Node> doomedNodes = nodeService.getNodesByIds(doomedNodeIds); String doomedIdsStr = StringConverter.integersAsString(doomedNodeIds); try { if (isRestAdapter()) { LOG.debug(String.format("Removing nodes '[%s]' from load balancer '%d' in STM...", doomedIdsStr, msg.getLoadBalancerId())); reverseProxyLoadBalancerStmService.removeNodes(dbLoadBalancer, doomedNodes); dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, doomedNodes); LOG.debug(String.format("Successfully removed nodes '[%s]' from load balancer '%d' in Zeus.", doomedIdsStr, msg.getLoadBalancerId())); } else { LOG.debug(String.format("Removing nodes '[%s]' from load balancer '%d' in ZXTM...", doomedIdsStr, msg.getLoadBalancerId())); dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, doomedNodes); reverseProxyLoadBalancerService.setNodesPriorities(ZxtmNameBuilder.genVSName(dbLoadBalancer), dbLoadBalancer); reverseProxyLoadBalancerService.removeNodes(msg.getLoadBalancerId(), msg.getAccountId(), doomedNodes); LOG.debug(String.format("Successfully removed nodes '[%s]' from load balancer '%d' in Zeus.", doomedIdsStr, msg.getLoadBalancerId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing nodes '%s' in Zeus for loadbalancer '%d'.", doomedIdsStr, msg.getLoadBalancerId()); LOG.error(alertDescription, e); notificationService.saveAlert(msg.getAccountId(), msg.getLoadBalancerId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(msg, doomedNodeIds); return; } dbLoadBalancer = loadBalancerService.get(msg.getLoadBalancerId(), msg.getAccountId()); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Nodes Successfully Deleted"; String atomSummary = "Nodes successfully deleted"; for (Integer doomedNodeId : doomedNodeIds) { notificationService.saveNodeEvent(msg.getUserName(), msg.getAccountId(), msg.getLoadBalancerId(), doomedNodeId, atomTitle, atomSummary, DELETE_NODE, DELETE, INFO); } LOG.info(String.format("Delete node operation complete for load balancer '%d'.", msg.getLoadBalancerId())); }
DeleteNodesListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer msg = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(msg.getLoadBalancerId(), msg.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", msg.getLoadBalancerId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(msg.getAccountId(), msg.getLoadBalancerId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(msg); return; } List<Integer> doomedNodeIds = msg.getIds(); List<Node> doomedNodes = nodeService.getNodesByIds(doomedNodeIds); String doomedIdsStr = StringConverter.integersAsString(doomedNodeIds); try { if (isRestAdapter()) { LOG.debug(String.format("Removing nodes '[%s]' from load balancer '%d' in STM...", doomedIdsStr, msg.getLoadBalancerId())); reverseProxyLoadBalancerStmService.removeNodes(dbLoadBalancer, doomedNodes); dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, doomedNodes); LOG.debug(String.format("Successfully removed nodes '[%s]' from load balancer '%d' in Zeus.", doomedIdsStr, msg.getLoadBalancerId())); } else { LOG.debug(String.format("Removing nodes '[%s]' from load balancer '%d' in ZXTM...", doomedIdsStr, msg.getLoadBalancerId())); dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, doomedNodes); reverseProxyLoadBalancerService.setNodesPriorities(ZxtmNameBuilder.genVSName(dbLoadBalancer), dbLoadBalancer); reverseProxyLoadBalancerService.removeNodes(msg.getLoadBalancerId(), msg.getAccountId(), doomedNodes); LOG.debug(String.format("Successfully removed nodes '[%s]' from load balancer '%d' in Zeus.", doomedIdsStr, msg.getLoadBalancerId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing nodes '%s' in Zeus for loadbalancer '%d'.", doomedIdsStr, msg.getLoadBalancerId()); LOG.error(alertDescription, e); notificationService.saveAlert(msg.getAccountId(), msg.getLoadBalancerId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(msg, doomedNodeIds); return; } dbLoadBalancer = loadBalancerService.get(msg.getLoadBalancerId(), msg.getAccountId()); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Nodes Successfully Deleted"; String atomSummary = "Nodes successfully deleted"; for (Integer doomedNodeId : doomedNodeIds) { notificationService.saveNodeEvent(msg.getUserName(), msg.getAccountId(), msg.getLoadBalancerId(), doomedNodeId, atomTitle, atomSummary, DELETE_NODE, DELETE, INFO); } LOG.info(String.format("Delete node operation complete for load balancer '%d'.", msg.getLoadBalancerId())); } }
DeleteNodesListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer msg = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(msg.getLoadBalancerId(), msg.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", msg.getLoadBalancerId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(msg.getAccountId(), msg.getLoadBalancerId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(msg); return; } List<Integer> doomedNodeIds = msg.getIds(); List<Node> doomedNodes = nodeService.getNodesByIds(doomedNodeIds); String doomedIdsStr = StringConverter.integersAsString(doomedNodeIds); try { if (isRestAdapter()) { LOG.debug(String.format("Removing nodes '[%s]' from load balancer '%d' in STM...", doomedIdsStr, msg.getLoadBalancerId())); reverseProxyLoadBalancerStmService.removeNodes(dbLoadBalancer, doomedNodes); dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, doomedNodes); LOG.debug(String.format("Successfully removed nodes '[%s]' from load balancer '%d' in Zeus.", doomedIdsStr, msg.getLoadBalancerId())); } else { LOG.debug(String.format("Removing nodes '[%s]' from load balancer '%d' in ZXTM...", doomedIdsStr, msg.getLoadBalancerId())); dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, doomedNodes); reverseProxyLoadBalancerService.setNodesPriorities(ZxtmNameBuilder.genVSName(dbLoadBalancer), dbLoadBalancer); reverseProxyLoadBalancerService.removeNodes(msg.getLoadBalancerId(), msg.getAccountId(), doomedNodes); LOG.debug(String.format("Successfully removed nodes '[%s]' from load balancer '%d' in Zeus.", doomedIdsStr, msg.getLoadBalancerId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing nodes '%s' in Zeus for loadbalancer '%d'.", doomedIdsStr, msg.getLoadBalancerId()); LOG.error(alertDescription, e); notificationService.saveAlert(msg.getAccountId(), msg.getLoadBalancerId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(msg, doomedNodeIds); return; } dbLoadBalancer = loadBalancerService.get(msg.getLoadBalancerId(), msg.getAccountId()); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Nodes Successfully Deleted"; String atomSummary = "Nodes successfully deleted"; for (Integer doomedNodeId : doomedNodeIds) { notificationService.saveNodeEvent(msg.getUserName(), msg.getAccountId(), msg.getLoadBalancerId(), doomedNodeId, atomTitle, atomSummary, DELETE_NODE, DELETE, INFO); } LOG.info(String.format("Delete node operation complete for load balancer '%d'.", msg.getLoadBalancerId())); }  }
DeleteNodesListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer msg = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(msg.getLoadBalancerId(), msg.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", msg.getLoadBalancerId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(msg.getAccountId(), msg.getLoadBalancerId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(msg); return; } List<Integer> doomedNodeIds = msg.getIds(); List<Node> doomedNodes = nodeService.getNodesByIds(doomedNodeIds); String doomedIdsStr = StringConverter.integersAsString(doomedNodeIds); try { if (isRestAdapter()) { LOG.debug(String.format("Removing nodes '[%s]' from load balancer '%d' in STM...", doomedIdsStr, msg.getLoadBalancerId())); reverseProxyLoadBalancerStmService.removeNodes(dbLoadBalancer, doomedNodes); dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, doomedNodes); LOG.debug(String.format("Successfully removed nodes '[%s]' from load balancer '%d' in Zeus.", doomedIdsStr, msg.getLoadBalancerId())); } else { LOG.debug(String.format("Removing nodes '[%s]' from load balancer '%d' in ZXTM...", doomedIdsStr, msg.getLoadBalancerId())); dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, doomedNodes); reverseProxyLoadBalancerService.setNodesPriorities(ZxtmNameBuilder.genVSName(dbLoadBalancer), dbLoadBalancer); reverseProxyLoadBalancerService.removeNodes(msg.getLoadBalancerId(), msg.getAccountId(), doomedNodes); LOG.debug(String.format("Successfully removed nodes '[%s]' from load balancer '%d' in Zeus.", doomedIdsStr, msg.getLoadBalancerId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing nodes '%s' in Zeus for loadbalancer '%d'.", doomedIdsStr, msg.getLoadBalancerId()); LOG.error(alertDescription, e); notificationService.saveAlert(msg.getAccountId(), msg.getLoadBalancerId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(msg, doomedNodeIds); return; } dbLoadBalancer = loadBalancerService.get(msg.getLoadBalancerId(), msg.getAccountId()); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Nodes Successfully Deleted"; String atomSummary = "Nodes successfully deleted"; for (Integer doomedNodeId : doomedNodeIds) { notificationService.saveNodeEvent(msg.getUserName(), msg.getAccountId(), msg.getLoadBalancerId(), doomedNodeId, atomTitle, atomSummary, DELETE_NODE, DELETE, INFO); } LOG.info(String.format("Delete node operation complete for load balancer '%d'.", msg.getLoadBalancerId())); }  @Override void doOnMessage(final Message message); }
DeleteNodesListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer msg = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(msg.getLoadBalancerId(), msg.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", msg.getLoadBalancerId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(msg.getAccountId(), msg.getLoadBalancerId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(msg); return; } List<Integer> doomedNodeIds = msg.getIds(); List<Node> doomedNodes = nodeService.getNodesByIds(doomedNodeIds); String doomedIdsStr = StringConverter.integersAsString(doomedNodeIds); try { if (isRestAdapter()) { LOG.debug(String.format("Removing nodes '[%s]' from load balancer '%d' in STM...", doomedIdsStr, msg.getLoadBalancerId())); reverseProxyLoadBalancerStmService.removeNodes(dbLoadBalancer, doomedNodes); dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, doomedNodes); LOG.debug(String.format("Successfully removed nodes '[%s]' from load balancer '%d' in Zeus.", doomedIdsStr, msg.getLoadBalancerId())); } else { LOG.debug(String.format("Removing nodes '[%s]' from load balancer '%d' in ZXTM...", doomedIdsStr, msg.getLoadBalancerId())); dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, doomedNodes); reverseProxyLoadBalancerService.setNodesPriorities(ZxtmNameBuilder.genVSName(dbLoadBalancer), dbLoadBalancer); reverseProxyLoadBalancerService.removeNodes(msg.getLoadBalancerId(), msg.getAccountId(), doomedNodes); LOG.debug(String.format("Successfully removed nodes '[%s]' from load balancer '%d' in Zeus.", doomedIdsStr, msg.getLoadBalancerId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing nodes '%s' in Zeus for loadbalancer '%d'.", doomedIdsStr, msg.getLoadBalancerId()); LOG.error(alertDescription, e); notificationService.saveAlert(msg.getAccountId(), msg.getLoadBalancerId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(msg, doomedNodeIds); return; } dbLoadBalancer = loadBalancerService.get(msg.getLoadBalancerId(), msg.getAccountId()); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Nodes Successfully Deleted"; String atomSummary = "Nodes successfully deleted"; for (Integer doomedNodeId : doomedNodeIds) { notificationService.saveNodeEvent(msg.getUserName(), msg.getAccountId(), msg.getLoadBalancerId(), doomedNodeId, atomTitle, atomSummary, DELETE_NODE, DELETE, INFO); } LOG.info(String.format("Delete node operation complete for load balancer '%d'.", msg.getLoadBalancerId())); }  @Override void doOnMessage(final Message message);  }