@Test public void testDeleteInvalidAccessList() 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).deleteAccessList(eq(lb), anyList()); deleteAccessListListener.doOnMessage(objectMessage); verify(reverseProxyLoadBalancerStmService).deleteAccessList(eq(lb), anyList()); 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).saveAccessListEvent(eq(USERNAME), eq(ACCOUNT_ID), eq(LOAD_BALANCER_ID), anyInt(), anyString(), anyString(), eq(EventType.DELETE_ACCESS_LIST), eq(CategoryType.DELETE), 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 ex) { String alertDescription = String.format("Load balancer '%d' not found in database.", queueLb.getId()); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), ex, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, queueLb.getAccessLists()); return; } List<Integer> accessListsToDelete = new ArrayList<Integer>(); for (AccessList item : queueLb.getAccessLists()) { accessListsToDelete.add(item.getId()); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting access list for load balancer '%s' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.deleteAccessList(dbLoadBalancer, accessListsToDelete); LOG.debug(String.format("Access list successfully deleted for load balancer '%s' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting access list for load balancer '%s' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.deleteAccessList(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); LOG.debug(String.format("Access list successfully deleted for load balancer '%s' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error deleting access list in Zeus for loadbalancer '%d'.", queueLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, queueLb.getAccessLists()); return; } String atomTitle = "Network Item Successfully Deleted"; for (Integer id : accessListsToDelete) { String atomSummary = String.format("Network Item '%d' successfully deleted", id); notificationService.saveAccessListEvent(queueLb.getUserName(), queueLb.getAccountId(), queueLb.getId(), id, atomTitle, atomSummary, DELETE_ACCESS_LIST, DELETE, INFO); LOG.debug(String.format("Removing access list item '%d' from database...", id)); } Set<AccessList> saveList = new HashSet<AccessList>(); for (AccessList item : dbLoadBalancer.getAccessLists()) { if (!accessListsToDelete.contains(item.getId())) { saveList.add(item); } } dbLoadBalancer.setAccessLists(saveList); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); }
DeleteAccessListListener 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 ex) { String alertDescription = String.format("Load balancer '%d' not found in database.", queueLb.getId()); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), ex, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, queueLb.getAccessLists()); return; } List<Integer> accessListsToDelete = new ArrayList<Integer>(); for (AccessList item : queueLb.getAccessLists()) { accessListsToDelete.add(item.getId()); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting access list for load balancer '%s' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.deleteAccessList(dbLoadBalancer, accessListsToDelete); LOG.debug(String.format("Access list successfully deleted for load balancer '%s' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting access list for load balancer '%s' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.deleteAccessList(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); LOG.debug(String.format("Access list successfully deleted for load balancer '%s' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error deleting access list in Zeus for loadbalancer '%d'.", queueLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, queueLb.getAccessLists()); return; } String atomTitle = "Network Item Successfully Deleted"; for (Integer id : accessListsToDelete) { String atomSummary = String.format("Network Item '%d' successfully deleted", id); notificationService.saveAccessListEvent(queueLb.getUserName(), queueLb.getAccountId(), queueLb.getId(), id, atomTitle, atomSummary, DELETE_ACCESS_LIST, DELETE, INFO); LOG.debug(String.format("Removing access list item '%d' from database...", id)); } Set<AccessList> saveList = new HashSet<AccessList>(); for (AccessList item : dbLoadBalancer.getAccessLists()) { if (!accessListsToDelete.contains(item.getId())) { saveList.add(item); } } dbLoadBalancer.setAccessLists(saveList); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); } }
DeleteAccessListListener 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 ex) { String alertDescription = String.format("Load balancer '%d' not found in database.", queueLb.getId()); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), ex, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, queueLb.getAccessLists()); return; } List<Integer> accessListsToDelete = new ArrayList<Integer>(); for (AccessList item : queueLb.getAccessLists()) { accessListsToDelete.add(item.getId()); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting access list for load balancer '%s' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.deleteAccessList(dbLoadBalancer, accessListsToDelete); LOG.debug(String.format("Access list successfully deleted for load balancer '%s' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting access list for load balancer '%s' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.deleteAccessList(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); LOG.debug(String.format("Access list successfully deleted for load balancer '%s' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error deleting access list in Zeus for loadbalancer '%d'.", queueLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, queueLb.getAccessLists()); return; } String atomTitle = "Network Item Successfully Deleted"; for (Integer id : accessListsToDelete) { String atomSummary = String.format("Network Item '%d' successfully deleted", id); notificationService.saveAccessListEvent(queueLb.getUserName(), queueLb.getAccountId(), queueLb.getId(), id, atomTitle, atomSummary, DELETE_ACCESS_LIST, DELETE, INFO); LOG.debug(String.format("Removing access list item '%d' from database...", id)); } Set<AccessList> saveList = new HashSet<AccessList>(); for (AccessList item : dbLoadBalancer.getAccessLists()) { if (!accessListsToDelete.contains(item.getId())) { saveList.add(item); } } dbLoadBalancer.setAccessLists(saveList); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); }  }
DeleteAccessListListener 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 ex) { String alertDescription = String.format("Load balancer '%d' not found in database.", queueLb.getId()); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), ex, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, queueLb.getAccessLists()); return; } List<Integer> accessListsToDelete = new ArrayList<Integer>(); for (AccessList item : queueLb.getAccessLists()) { accessListsToDelete.add(item.getId()); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting access list for load balancer '%s' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.deleteAccessList(dbLoadBalancer, accessListsToDelete); LOG.debug(String.format("Access list successfully deleted for load balancer '%s' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting access list for load balancer '%s' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.deleteAccessList(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); LOG.debug(String.format("Access list successfully deleted for load balancer '%s' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error deleting access list in Zeus for loadbalancer '%d'.", queueLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, queueLb.getAccessLists()); return; } String atomTitle = "Network Item Successfully Deleted"; for (Integer id : accessListsToDelete) { String atomSummary = String.format("Network Item '%d' successfully deleted", id); notificationService.saveAccessListEvent(queueLb.getUserName(), queueLb.getAccountId(), queueLb.getId(), id, atomTitle, atomSummary, DELETE_ACCESS_LIST, DELETE, INFO); LOG.debug(String.format("Removing access list item '%d' from database...", id)); } Set<AccessList> saveList = new HashSet<AccessList>(); for (AccessList item : dbLoadBalancer.getAccessLists()) { if (!accessListsToDelete.contains(item.getId())) { saveList.add(item); } } dbLoadBalancer.setAccessLists(saveList); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); }  @Override void doOnMessage(Message message); }
DeleteAccessListListener 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 ex) { String alertDescription = String.format("Load balancer '%d' not found in database.", queueLb.getId()); notificationService.saveAlert(queueLb.getAccountId(), queueLb.getId(), ex, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, queueLb.getAccessLists()); return; } List<Integer> accessListsToDelete = new ArrayList<Integer>(); for (AccessList item : queueLb.getAccessLists()) { accessListsToDelete.add(item.getId()); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting access list for load balancer '%s' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.deleteAccessList(dbLoadBalancer, accessListsToDelete); LOG.debug(String.format("Access list successfully deleted for load balancer '%s' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting access list for load balancer '%s' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.deleteAccessList(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); LOG.debug(String.format("Access list successfully deleted for load balancer '%s' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error deleting access list in Zeus for loadbalancer '%d'.", queueLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb, queueLb.getAccessLists()); return; } String atomTitle = "Network Item Successfully Deleted"; for (Integer id : accessListsToDelete) { String atomSummary = String.format("Network Item '%d' successfully deleted", id); notificationService.saveAccessListEvent(queueLb.getUserName(), queueLb.getAccountId(), queueLb.getId(), id, atomTitle, atomSummary, DELETE_ACCESS_LIST, DELETE, INFO); LOG.debug(String.format("Removing access list item '%d' from database...", id)); } Set<AccessList> saveList = new HashSet<AccessList>(); for (AccessList item : dbLoadBalancer.getAccessLists()) { if (!accessListsToDelete.contains(item.getId())) { saveList.add(item); } } dbLoadBalancer.setAccessLists(saveList); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); }  @Override void doOnMessage(Message message);  }