@Test public void testDeleteInvalidNode() throws Exception { when(objectMessage.getObject()).thenReturn(lb); when(loadBalancerService.getWithUserPages(LOAD_BALANCER_ID, ACCOUNT_ID)).thenReturn(lb); doThrow(Exception.class).when(reverseProxyLoadBalancerStmService).removeNode(lb, nodeToDelete); when(config.getString(Matchers.<ConfigurationKey>any())).thenReturn("REST"); deleteNodeListener.doOnMessage(objectMessage); verify(reverseProxyLoadBalancerStmService).removeNode(lb, nodeToDelete); verify(loadBalancerService).setStatusForOp(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(nodeToDelete.getId()), anyString(), anyString(), eq(EventType.DELETE_NODE), eq(CategoryType.DELETE), eq(EventSeverity.CRITICAL)); }
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; } Node nodeToDelete = queueLb.getNodes().iterator().next(); for (Node node : dbLoadBalancer.getNodes()) { if (node.getId().equals(nodeToDelete.getId())) { nodeToDelete = node; break; } } try { if (isRestAdapter()) { LOG.debug(String.format("Removing node '%d' from load balancer '%d' in STM...", nodeToDelete.getId(), queueLb.getId())); reverseProxyLoadBalancerStmService.removeNode(dbLoadBalancer, nodeToDelete); LOG.debug(String.format("Successfully removed node '%d' from load balancer '%d' in STM.", nodeToDelete.getId(), queueLb.getId())); } else { LOG.debug(String.format("Removing node '%d' from load balancer '%d' in ZXTM...", nodeToDelete.getId(), queueLb.getId())); reverseProxyLoadBalancerService.setNodesPriorities(ZxtmNameBuilder.genVSName(dbLoadBalancer), dbLoadBalancer); reverseProxyLoadBalancerService.removeNode(queueLb.getId(), queueLb.getAccountId(), nodeToDelete); LOG.debug(String.format("Successfully removed node '%d' from load balancer '%d' in Zeus.", nodeToDelete.getId(), queueLb.getId())); } } catch (Exception e) { loadBalancerService.setStatusForOp(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing node '%d' in Zeus for loadbalancer '%d'.", nodeToDelete.getId(), queueLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, nodeToDelete); return; } dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, Arrays.asList(nodeToDelete)); loadBalancerService.setStatusForOp(dbLoadBalancer, LoadBalancerStatus.ACTIVE); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Node Successfully Deleted"; String atomSummary = "Node successfully deleted"; notificationService.saveNodeEvent(queueLb.getUserName(), queueLb.getAccountId(), queueLb.getId(), nodeToDelete.getId(), atomTitle, atomSummary, DELETE_NODE, DELETE, INFO); LOG.info(String.format("Delete node operation complete for load balancer '%d'.", queueLb.getId())); }
DeleteNodeListener extends BaseListener { 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; } Node nodeToDelete = queueLb.getNodes().iterator().next(); for (Node node : dbLoadBalancer.getNodes()) { if (node.getId().equals(nodeToDelete.getId())) { nodeToDelete = node; break; } } try { if (isRestAdapter()) { LOG.debug(String.format("Removing node '%d' from load balancer '%d' in STM...", nodeToDelete.getId(), queueLb.getId())); reverseProxyLoadBalancerStmService.removeNode(dbLoadBalancer, nodeToDelete); LOG.debug(String.format("Successfully removed node '%d' from load balancer '%d' in STM.", nodeToDelete.getId(), queueLb.getId())); } else { LOG.debug(String.format("Removing node '%d' from load balancer '%d' in ZXTM...", nodeToDelete.getId(), queueLb.getId())); reverseProxyLoadBalancerService.setNodesPriorities(ZxtmNameBuilder.genVSName(dbLoadBalancer), dbLoadBalancer); reverseProxyLoadBalancerService.removeNode(queueLb.getId(), queueLb.getAccountId(), nodeToDelete); LOG.debug(String.format("Successfully removed node '%d' from load balancer '%d' in Zeus.", nodeToDelete.getId(), queueLb.getId())); } } catch (Exception e) { loadBalancerService.setStatusForOp(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing node '%d' in Zeus for loadbalancer '%d'.", nodeToDelete.getId(), queueLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, nodeToDelete); return; } dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, Arrays.asList(nodeToDelete)); loadBalancerService.setStatusForOp(dbLoadBalancer, LoadBalancerStatus.ACTIVE); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Node Successfully Deleted"; String atomSummary = "Node successfully deleted"; notificationService.saveNodeEvent(queueLb.getUserName(), queueLb.getAccountId(), queueLb.getId(), nodeToDelete.getId(), atomTitle, atomSummary, DELETE_NODE, DELETE, INFO); LOG.info(String.format("Delete node operation complete for load balancer '%d'.", queueLb.getId())); } }
DeleteNodeListener extends BaseListener { 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; } Node nodeToDelete = queueLb.getNodes().iterator().next(); for (Node node : dbLoadBalancer.getNodes()) { if (node.getId().equals(nodeToDelete.getId())) { nodeToDelete = node; break; } } try { if (isRestAdapter()) { LOG.debug(String.format("Removing node '%d' from load balancer '%d' in STM...", nodeToDelete.getId(), queueLb.getId())); reverseProxyLoadBalancerStmService.removeNode(dbLoadBalancer, nodeToDelete); LOG.debug(String.format("Successfully removed node '%d' from load balancer '%d' in STM.", nodeToDelete.getId(), queueLb.getId())); } else { LOG.debug(String.format("Removing node '%d' from load balancer '%d' in ZXTM...", nodeToDelete.getId(), queueLb.getId())); reverseProxyLoadBalancerService.setNodesPriorities(ZxtmNameBuilder.genVSName(dbLoadBalancer), dbLoadBalancer); reverseProxyLoadBalancerService.removeNode(queueLb.getId(), queueLb.getAccountId(), nodeToDelete); LOG.debug(String.format("Successfully removed node '%d' from load balancer '%d' in Zeus.", nodeToDelete.getId(), queueLb.getId())); } } catch (Exception e) { loadBalancerService.setStatusForOp(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing node '%d' in Zeus for loadbalancer '%d'.", nodeToDelete.getId(), queueLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, nodeToDelete); return; } dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, Arrays.asList(nodeToDelete)); loadBalancerService.setStatusForOp(dbLoadBalancer, LoadBalancerStatus.ACTIVE); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Node Successfully Deleted"; String atomSummary = "Node successfully deleted"; notificationService.saveNodeEvent(queueLb.getUserName(), queueLb.getAccountId(), queueLb.getId(), nodeToDelete.getId(), atomTitle, atomSummary, DELETE_NODE, DELETE, INFO); LOG.info(String.format("Delete node operation complete for load balancer '%d'.", queueLb.getId())); }  }
DeleteNodeListener extends BaseListener { 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; } Node nodeToDelete = queueLb.getNodes().iterator().next(); for (Node node : dbLoadBalancer.getNodes()) { if (node.getId().equals(nodeToDelete.getId())) { nodeToDelete = node; break; } } try { if (isRestAdapter()) { LOG.debug(String.format("Removing node '%d' from load balancer '%d' in STM...", nodeToDelete.getId(), queueLb.getId())); reverseProxyLoadBalancerStmService.removeNode(dbLoadBalancer, nodeToDelete); LOG.debug(String.format("Successfully removed node '%d' from load balancer '%d' in STM.", nodeToDelete.getId(), queueLb.getId())); } else { LOG.debug(String.format("Removing node '%d' from load balancer '%d' in ZXTM...", nodeToDelete.getId(), queueLb.getId())); reverseProxyLoadBalancerService.setNodesPriorities(ZxtmNameBuilder.genVSName(dbLoadBalancer), dbLoadBalancer); reverseProxyLoadBalancerService.removeNode(queueLb.getId(), queueLb.getAccountId(), nodeToDelete); LOG.debug(String.format("Successfully removed node '%d' from load balancer '%d' in Zeus.", nodeToDelete.getId(), queueLb.getId())); } } catch (Exception e) { loadBalancerService.setStatusForOp(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing node '%d' in Zeus for loadbalancer '%d'.", nodeToDelete.getId(), queueLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, nodeToDelete); return; } dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, Arrays.asList(nodeToDelete)); loadBalancerService.setStatusForOp(dbLoadBalancer, LoadBalancerStatus.ACTIVE); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Node Successfully Deleted"; String atomSummary = "Node successfully deleted"; notificationService.saveNodeEvent(queueLb.getUserName(), queueLb.getAccountId(), queueLb.getId(), nodeToDelete.getId(), atomTitle, atomSummary, DELETE_NODE, DELETE, INFO); LOG.info(String.format("Delete node operation complete for load balancer '%d'.", queueLb.getId())); }  void doOnMessage(final Message message); }
DeleteNodeListener extends BaseListener { 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; } Node nodeToDelete = queueLb.getNodes().iterator().next(); for (Node node : dbLoadBalancer.getNodes()) { if (node.getId().equals(nodeToDelete.getId())) { nodeToDelete = node; break; } } try { if (isRestAdapter()) { LOG.debug(String.format("Removing node '%d' from load balancer '%d' in STM...", nodeToDelete.getId(), queueLb.getId())); reverseProxyLoadBalancerStmService.removeNode(dbLoadBalancer, nodeToDelete); LOG.debug(String.format("Successfully removed node '%d' from load balancer '%d' in STM.", nodeToDelete.getId(), queueLb.getId())); } else { LOG.debug(String.format("Removing node '%d' from load balancer '%d' in ZXTM...", nodeToDelete.getId(), queueLb.getId())); reverseProxyLoadBalancerService.setNodesPriorities(ZxtmNameBuilder.genVSName(dbLoadBalancer), dbLoadBalancer); reverseProxyLoadBalancerService.removeNode(queueLb.getId(), queueLb.getAccountId(), nodeToDelete); LOG.debug(String.format("Successfully removed node '%d' from load balancer '%d' in Zeus.", nodeToDelete.getId(), queueLb.getId())); } } catch (Exception e) { loadBalancerService.setStatusForOp(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing node '%d' in Zeus for loadbalancer '%d'.", nodeToDelete.getId(), queueLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, nodeToDelete); return; } dbLoadBalancer = nodeService.delNodes(dbLoadBalancer, Arrays.asList(nodeToDelete)); loadBalancerService.setStatusForOp(dbLoadBalancer, LoadBalancerStatus.ACTIVE); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Node Successfully Deleted"; String atomSummary = "Node successfully deleted"; notificationService.saveNodeEvent(queueLb.getUserName(), queueLb.getAccountId(), queueLb.getId(), nodeToDelete.getId(), atomTitle, atomSummary, DELETE_NODE, DELETE, INFO); LOG.info(String.format("Delete node operation complete for load balancer '%d'.", queueLb.getId())); }  void doOnMessage(final Message message);  }