@Test public void testDeleteValidLoadBalancerWithoutSSL() throws Exception { lb.setSslTermination(null); when(objectMessage.getObject()).thenReturn(lb); when(loadBalancerService.getWithUserPages(LOAD_BALANCER_ID, ACCOUNT_ID)).thenReturn(lb); when(usageEventCollection.getUsage(lb)).thenReturn(usages); when(loadBalancerService.pseudoDelete(lb)).thenReturn(lb); when(config.getString(Matchers.<ConfigurationKey>any())).thenReturn("REST"); deleteLoadBalancerListener.doOnMessage(objectMessage); verify(usageEventCollection).getUsage(lb); verify(reverseProxyLoadBalancerStmService).deleteLoadBalancer(lb); verify(loadBalancerService).pseudoDelete(lb); verify(loadBalancerStatusHistoryService).save(ACCOUNT_ID, LOAD_BALANCER_ID, LoadBalancerStatus.DELETED); verify(notificationService).saveLoadBalancerEvent(eq(USERNAME), eq(ACCOUNT_ID), eq(LOAD_BALANCER_ID), anyString(), anyString(), eq(EventType.DELETE_LOADBALANCER), eq(CategoryType.DELETE), eq(EventSeverity.INFO)); }
@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; } List<SnmpUsage> usages = new ArrayList<SnmpUsage>(); try { LOG.info(String.format("Collecting DELETE_LOADBALANCER usage for load balancer %s...", dbLoadBalancer.getId())); usages = usageEventCollection.getUsage(dbLoadBalancer); LOG.info(String.format("Successfully collected DELETE_LOADBALANCER usage for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the DELETE_LOADBALANCER usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.deleteLoadBalancer(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.deleteLoadBalancer(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); LOG.error(String.format("LoadBalancer status before error was: '%s'", dbLoadBalancer.getStatus())); String alertDescription = String.format("Error deleting loadbalancer '%d' in Zeus.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } if (dbLoadBalancer.hasSsl()) { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in database...", dbLoadBalancer.getId())); sslTerminationService.deleteSslTermination(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%d' in database.", dbLoadBalancer.getId())); } dbLoadBalancer = loadBalancerService.pseudoDelete(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.DELETED); String atomTitle = "Load Balancer Successfully Deleted"; String atomSummary = "Load balancer successfully deleted"; notificationService.saveLoadBalancerEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_LOADBALANCER, DELETE, INFO); Calendar eventTime = Calendar.getInstance(); LOG.info(String.format("Processing DELETE_LOADBALANCER usage for load balancer %s...", dbLoadBalancer.getId())); try { usageEventCollection.processUsageEvent(usages, dbLoadBalancer, UsageEvent.DELETE_LOADBALANCER, eventTime); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String alertDescription = String.format("An error occurred while processing the usage for an event on loadbalancer %d: \n%s\n\n%s", dbLoadBalancer.getId(), exc.getMessage(), exceptionStackTrace); LOG.error(alertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), alertDescription); } LOG.info(String.format("Completed processing DELETE_LOADBALANCER usage for load balancer %s", dbLoadBalancer.getId())); LOG.info(String.format("Load balancer '%d' successfully deleted.", dbLoadBalancer.getId())); }
DeleteLoadBalancerListener 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; } List<SnmpUsage> usages = new ArrayList<SnmpUsage>(); try { LOG.info(String.format("Collecting DELETE_LOADBALANCER usage for load balancer %s...", dbLoadBalancer.getId())); usages = usageEventCollection.getUsage(dbLoadBalancer); LOG.info(String.format("Successfully collected DELETE_LOADBALANCER usage for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the DELETE_LOADBALANCER usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.deleteLoadBalancer(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.deleteLoadBalancer(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); LOG.error(String.format("LoadBalancer status before error was: '%s'", dbLoadBalancer.getStatus())); String alertDescription = String.format("Error deleting loadbalancer '%d' in Zeus.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } if (dbLoadBalancer.hasSsl()) { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in database...", dbLoadBalancer.getId())); sslTerminationService.deleteSslTermination(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%d' in database.", dbLoadBalancer.getId())); } dbLoadBalancer = loadBalancerService.pseudoDelete(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.DELETED); String atomTitle = "Load Balancer Successfully Deleted"; String atomSummary = "Load balancer successfully deleted"; notificationService.saveLoadBalancerEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_LOADBALANCER, DELETE, INFO); Calendar eventTime = Calendar.getInstance(); LOG.info(String.format("Processing DELETE_LOADBALANCER usage for load balancer %s...", dbLoadBalancer.getId())); try { usageEventCollection.processUsageEvent(usages, dbLoadBalancer, UsageEvent.DELETE_LOADBALANCER, eventTime); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String alertDescription = String.format("An error occurred while processing the usage for an event on loadbalancer %d: \n%s\n\n%s", dbLoadBalancer.getId(), exc.getMessage(), exceptionStackTrace); LOG.error(alertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), alertDescription); } LOG.info(String.format("Completed processing DELETE_LOADBALANCER usage for load balancer %s", dbLoadBalancer.getId())); LOG.info(String.format("Load balancer '%d' successfully deleted.", dbLoadBalancer.getId())); } }
DeleteLoadBalancerListener 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; } List<SnmpUsage> usages = new ArrayList<SnmpUsage>(); try { LOG.info(String.format("Collecting DELETE_LOADBALANCER usage for load balancer %s...", dbLoadBalancer.getId())); usages = usageEventCollection.getUsage(dbLoadBalancer); LOG.info(String.format("Successfully collected DELETE_LOADBALANCER usage for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the DELETE_LOADBALANCER usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.deleteLoadBalancer(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.deleteLoadBalancer(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); LOG.error(String.format("LoadBalancer status before error was: '%s'", dbLoadBalancer.getStatus())); String alertDescription = String.format("Error deleting loadbalancer '%d' in Zeus.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } if (dbLoadBalancer.hasSsl()) { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in database...", dbLoadBalancer.getId())); sslTerminationService.deleteSslTermination(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%d' in database.", dbLoadBalancer.getId())); } dbLoadBalancer = loadBalancerService.pseudoDelete(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.DELETED); String atomTitle = "Load Balancer Successfully Deleted"; String atomSummary = "Load balancer successfully deleted"; notificationService.saveLoadBalancerEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_LOADBALANCER, DELETE, INFO); Calendar eventTime = Calendar.getInstance(); LOG.info(String.format("Processing DELETE_LOADBALANCER usage for load balancer %s...", dbLoadBalancer.getId())); try { usageEventCollection.processUsageEvent(usages, dbLoadBalancer, UsageEvent.DELETE_LOADBALANCER, eventTime); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String alertDescription = String.format("An error occurred while processing the usage for an event on loadbalancer %d: \n%s\n\n%s", dbLoadBalancer.getId(), exc.getMessage(), exceptionStackTrace); LOG.error(alertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), alertDescription); } LOG.info(String.format("Completed processing DELETE_LOADBALANCER usage for load balancer %s", dbLoadBalancer.getId())); LOG.info(String.format("Load balancer '%d' successfully deleted.", dbLoadBalancer.getId())); }  }
DeleteLoadBalancerListener 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; } List<SnmpUsage> usages = new ArrayList<SnmpUsage>(); try { LOG.info(String.format("Collecting DELETE_LOADBALANCER usage for load balancer %s...", dbLoadBalancer.getId())); usages = usageEventCollection.getUsage(dbLoadBalancer); LOG.info(String.format("Successfully collected DELETE_LOADBALANCER usage for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the DELETE_LOADBALANCER usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.deleteLoadBalancer(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.deleteLoadBalancer(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); LOG.error(String.format("LoadBalancer status before error was: '%s'", dbLoadBalancer.getStatus())); String alertDescription = String.format("Error deleting loadbalancer '%d' in Zeus.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } if (dbLoadBalancer.hasSsl()) { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in database...", dbLoadBalancer.getId())); sslTerminationService.deleteSslTermination(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%d' in database.", dbLoadBalancer.getId())); } dbLoadBalancer = loadBalancerService.pseudoDelete(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.DELETED); String atomTitle = "Load Balancer Successfully Deleted"; String atomSummary = "Load balancer successfully deleted"; notificationService.saveLoadBalancerEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_LOADBALANCER, DELETE, INFO); Calendar eventTime = Calendar.getInstance(); LOG.info(String.format("Processing DELETE_LOADBALANCER usage for load balancer %s...", dbLoadBalancer.getId())); try { usageEventCollection.processUsageEvent(usages, dbLoadBalancer, UsageEvent.DELETE_LOADBALANCER, eventTime); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String alertDescription = String.format("An error occurred while processing the usage for an event on loadbalancer %d: \n%s\n\n%s", dbLoadBalancer.getId(), exc.getMessage(), exceptionStackTrace); LOG.error(alertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), alertDescription); } LOG.info(String.format("Completed processing DELETE_LOADBALANCER usage for load balancer %s", dbLoadBalancer.getId())); LOG.info(String.format("Load balancer '%d' successfully deleted.", dbLoadBalancer.getId())); }  @Override void doOnMessage(final Message message); }
DeleteLoadBalancerListener 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; } List<SnmpUsage> usages = new ArrayList<SnmpUsage>(); try { LOG.info(String.format("Collecting DELETE_LOADBALANCER usage for load balancer %s...", dbLoadBalancer.getId())); usages = usageEventCollection.getUsage(dbLoadBalancer); LOG.info(String.format("Successfully collected DELETE_LOADBALANCER usage for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the DELETE_LOADBALANCER usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.deleteLoadBalancer(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.deleteLoadBalancer(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer '%d' in Zeus.", dbLoadBalancer.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); LOG.error(String.format("LoadBalancer status before error was: '%s'", dbLoadBalancer.getStatus())); String alertDescription = String.format("Error deleting loadbalancer '%d' in Zeus.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); return; } if (dbLoadBalancer.hasSsl()) { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in database...", dbLoadBalancer.getId())); sslTerminationService.deleteSslTermination(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%d' in database.", dbLoadBalancer.getId())); } dbLoadBalancer = loadBalancerService.pseudoDelete(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.DELETED); String atomTitle = "Load Balancer Successfully Deleted"; String atomSummary = "Load balancer successfully deleted"; notificationService.saveLoadBalancerEvent(queueLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_LOADBALANCER, DELETE, INFO); Calendar eventTime = Calendar.getInstance(); LOG.info(String.format("Processing DELETE_LOADBALANCER usage for load balancer %s...", dbLoadBalancer.getId())); try { usageEventCollection.processUsageEvent(usages, dbLoadBalancer, UsageEvent.DELETE_LOADBALANCER, eventTime); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String alertDescription = String.format("An error occurred while processing the usage for an event on loadbalancer %d: \n%s\n\n%s", dbLoadBalancer.getId(), exc.getMessage(), exceptionStackTrace); LOG.error(alertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), alertDescription); } LOG.info(String.format("Completed processing DELETE_LOADBALANCER usage for load balancer %s", dbLoadBalancer.getId())); LOG.info(String.format("Load balancer '%d' successfully deleted.", dbLoadBalancer.getId())); }  @Override void doOnMessage(final Message message);  }