@Test public void testDeleteSslTerminationWithCertificateMappings() throws Exception { when(objectMessage.getObject()).thenReturn(messageDataContainer); when(messageDataContainer.getPreviousSslTermination()).thenReturn(previousSslTermination); when(messageDataContainer.getAccountId()).thenReturn(ACCOUNT_ID); when(messageDataContainer.getLoadBalancerId()).thenReturn(LOAD_BALANCER_ID); when(messageDataContainer.getUserName()).thenReturn(USERNAME); when(usageEventCollection.getUsage(lb)).thenReturn(usages); when(loadBalancerService.getWithUserPages(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"); deleteSslTerminationListener.doOnMessage(objectMessage); verify(loadBalancerService).getWithUserPages(LOAD_BALANCER_ID, ACCOUNT_ID); verify(reverseProxyLoadBalancerStmService).removeSslTermination(lb); verify(certificateMappingService, times(2)).deleteByIdAndLoadBalancerId(Matchers.anyInt(), Matchers.anyInt()); for (CertificateMapping cm : lb.getCertificateMappings()) { verify(certificateMappingService).deleteByIdAndLoadBalancerId(cm.getId(), lb.getId()); } verify(sslTerminationService).deleteSslTermination(LOAD_BALANCER_ID, ACCOUNT_ID); verify(usageEventCollection).processUsageEvent(eq(usages), eq(lb), eq(UsageEvent.SSL_OFF), any(Calendar.class)); verify(loadBalancerService).setStatus(lb, LoadBalancerStatus.ACTIVE); verify(notificationService).saveLoadBalancerEvent(USERNAME, ACCOUNT_ID, LOAD_BALANCER_ID, "Load Balancer SSL Termination Successfully Deleted", "Load balancer ssl termination successfully deleted", EventType.DELETE_SSL_TERMINATION, CategoryType.DELETE, EventSeverity.INFO); }
@Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer dataContainer = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; LoadBalancer errorMsgLB = new LoadBalancer(); errorMsgLB.setUserName(dataContainer.getUserName()); errorMsgLB.setId(dataContainer.getLoadBalancerId()); errorMsgLB.setAccountId(dataContainer.getAccountId()); try { dbLoadBalancer = loadBalancerService.getWithUserPages(errorMsgLB.getId(), errorMsgLB.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", errorMsgLB.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(errorMsgLB.getAccountId(), errorMsgLB.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(errorMsgLB); return; } List<SnmpUsage> usages = new ArrayList<SnmpUsage>(); Map<Integer, SnmpUsage> usagesMap = new HashMap<Integer, SnmpUsage>(); try { LOG.info(String.format("Collecting usage BEFORE ssl event for load balancer %s...", dbLoadBalancer.getId())); usages = usageEventCollection.getUsage(dbLoadBalancer); for (SnmpUsage usage : usages) { usagesMap.put(usage.getHostId(), usage); } LOG.info(String.format("Successfully collected usage BEFORE ssl event for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the ssl usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.removeSslTermination(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.removeSslTermination(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%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' ssl termination in Zeus.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(errorMsgLB); Calendar eventTime = Calendar.getInstance(); try { usageEventCollection.collectUsageAndProcessUsageRecords(dbLoadBalancer, UsageEvent.SSL_OFF, eventTime); } catch (UsageEventCollectionException uex) { LOG.error(String.format("Collection and processing of the usage event failed for load balancer: %s " + ":: Exception: %s", dbLoadBalancer.getId(), uex)); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String usageAlertDescription = 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(usageAlertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), usageAlertDescription); } return; } List<SnmpUsage> usages2 = new ArrayList<SnmpUsage>(); Map<Integer, SnmpUsage> usagesMap2 = new HashMap<Integer, SnmpUsage>(); try { LOG.info(String.format("Collecting usage AFTER ssl event for load balancer %s...", dbLoadBalancer.getId())); usages2 = usageEventCollection.getUsage(dbLoadBalancer); for (SnmpUsage usage : usages2) { usagesMap2.put(usage.getHostId(), usage); } LOG.info(String.format("Successfully collected usage AFTER ssl event for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the ssl usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } for (CertificateMapping certificateMapping : dbLoadBalancer.getCertificateMappings()) { try { LOG.info(String.format("Removing certificate '%s' for load balancer %d...", certificateMapping.getId(), dbLoadBalancer.getId())); certificateMappingService.deleteByIdAndLoadBalancerId(certificateMapping.getId(), dbLoadBalancer.getId()); LOG.info(String.format("Successfully removed certificate '%s' for load balancer %d.", certificateMapping.getId(), dbLoadBalancer.getId())); } catch (Exception odne) { LOG.info(String.format("Certificate for host '%s' does not exist for load balancer %d. Ignoring...", certificateMapping.getHostName(), dbLoadBalancer.getId())); } } sslTerminationService.deleteSslTermination(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); Calendar eventTime = Calendar.getInstance(); SslTerminationUsage sslTermUsageHelper = new SslTerminationUsage(); SslTermination currentSslTerm = new SslTermination(); currentSslTerm.setEnabled(false); List<SnmpUsage> usagesToInsert = sslTermUsageHelper.getUsagesToInsert(dbLoadBalancer.getId(), dataContainer.getPreviousSslTermination(), currentSslTerm, usagesMap, usagesMap2); try { usageEventCollection.processUsageEvent(usagesToInsert, dbLoadBalancer, UsageEvent.SSL_OFF, eventTime); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String usageAlertDescription = 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(usageAlertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), usageAlertDescription); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); String atomTitle = "Load Balancer SSL Termination Successfully Deleted"; String atomSummary = "Load balancer ssl termination successfully deleted"; notificationService.saveLoadBalancerEvent(errorMsgLB.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_SSL_TERMINATION, DELETE, INFO); LOG.info(String.format("Load balancer ssl termination '%d' successfully deleted.", dbLoadBalancer.getId())); }
DeleteSslTerminationListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer dataContainer = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; LoadBalancer errorMsgLB = new LoadBalancer(); errorMsgLB.setUserName(dataContainer.getUserName()); errorMsgLB.setId(dataContainer.getLoadBalancerId()); errorMsgLB.setAccountId(dataContainer.getAccountId()); try { dbLoadBalancer = loadBalancerService.getWithUserPages(errorMsgLB.getId(), errorMsgLB.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", errorMsgLB.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(errorMsgLB.getAccountId(), errorMsgLB.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(errorMsgLB); return; } List<SnmpUsage> usages = new ArrayList<SnmpUsage>(); Map<Integer, SnmpUsage> usagesMap = new HashMap<Integer, SnmpUsage>(); try { LOG.info(String.format("Collecting usage BEFORE ssl event for load balancer %s...", dbLoadBalancer.getId())); usages = usageEventCollection.getUsage(dbLoadBalancer); for (SnmpUsage usage : usages) { usagesMap.put(usage.getHostId(), usage); } LOG.info(String.format("Successfully collected usage BEFORE ssl event for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the ssl usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.removeSslTermination(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.removeSslTermination(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%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' ssl termination in Zeus.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(errorMsgLB); Calendar eventTime = Calendar.getInstance(); try { usageEventCollection.collectUsageAndProcessUsageRecords(dbLoadBalancer, UsageEvent.SSL_OFF, eventTime); } catch (UsageEventCollectionException uex) { LOG.error(String.format("Collection and processing of the usage event failed for load balancer: %s " + ":: Exception: %s", dbLoadBalancer.getId(), uex)); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String usageAlertDescription = 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(usageAlertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), usageAlertDescription); } return; } List<SnmpUsage> usages2 = new ArrayList<SnmpUsage>(); Map<Integer, SnmpUsage> usagesMap2 = new HashMap<Integer, SnmpUsage>(); try { LOG.info(String.format("Collecting usage AFTER ssl event for load balancer %s...", dbLoadBalancer.getId())); usages2 = usageEventCollection.getUsage(dbLoadBalancer); for (SnmpUsage usage : usages2) { usagesMap2.put(usage.getHostId(), usage); } LOG.info(String.format("Successfully collected usage AFTER ssl event for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the ssl usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } for (CertificateMapping certificateMapping : dbLoadBalancer.getCertificateMappings()) { try { LOG.info(String.format("Removing certificate '%s' for load balancer %d...", certificateMapping.getId(), dbLoadBalancer.getId())); certificateMappingService.deleteByIdAndLoadBalancerId(certificateMapping.getId(), dbLoadBalancer.getId()); LOG.info(String.format("Successfully removed certificate '%s' for load balancer %d.", certificateMapping.getId(), dbLoadBalancer.getId())); } catch (Exception odne) { LOG.info(String.format("Certificate for host '%s' does not exist for load balancer %d. Ignoring...", certificateMapping.getHostName(), dbLoadBalancer.getId())); } } sslTerminationService.deleteSslTermination(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); Calendar eventTime = Calendar.getInstance(); SslTerminationUsage sslTermUsageHelper = new SslTerminationUsage(); SslTermination currentSslTerm = new SslTermination(); currentSslTerm.setEnabled(false); List<SnmpUsage> usagesToInsert = sslTermUsageHelper.getUsagesToInsert(dbLoadBalancer.getId(), dataContainer.getPreviousSslTermination(), currentSslTerm, usagesMap, usagesMap2); try { usageEventCollection.processUsageEvent(usagesToInsert, dbLoadBalancer, UsageEvent.SSL_OFF, eventTime); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String usageAlertDescription = 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(usageAlertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), usageAlertDescription); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); String atomTitle = "Load Balancer SSL Termination Successfully Deleted"; String atomSummary = "Load balancer ssl termination successfully deleted"; notificationService.saveLoadBalancerEvent(errorMsgLB.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_SSL_TERMINATION, DELETE, INFO); LOG.info(String.format("Load balancer ssl termination '%d' successfully deleted.", dbLoadBalancer.getId())); } }
DeleteSslTerminationListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer dataContainer = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; LoadBalancer errorMsgLB = new LoadBalancer(); errorMsgLB.setUserName(dataContainer.getUserName()); errorMsgLB.setId(dataContainer.getLoadBalancerId()); errorMsgLB.setAccountId(dataContainer.getAccountId()); try { dbLoadBalancer = loadBalancerService.getWithUserPages(errorMsgLB.getId(), errorMsgLB.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", errorMsgLB.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(errorMsgLB.getAccountId(), errorMsgLB.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(errorMsgLB); return; } List<SnmpUsage> usages = new ArrayList<SnmpUsage>(); Map<Integer, SnmpUsage> usagesMap = new HashMap<Integer, SnmpUsage>(); try { LOG.info(String.format("Collecting usage BEFORE ssl event for load balancer %s...", dbLoadBalancer.getId())); usages = usageEventCollection.getUsage(dbLoadBalancer); for (SnmpUsage usage : usages) { usagesMap.put(usage.getHostId(), usage); } LOG.info(String.format("Successfully collected usage BEFORE ssl event for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the ssl usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.removeSslTermination(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.removeSslTermination(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%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' ssl termination in Zeus.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(errorMsgLB); Calendar eventTime = Calendar.getInstance(); try { usageEventCollection.collectUsageAndProcessUsageRecords(dbLoadBalancer, UsageEvent.SSL_OFF, eventTime); } catch (UsageEventCollectionException uex) { LOG.error(String.format("Collection and processing of the usage event failed for load balancer: %s " + ":: Exception: %s", dbLoadBalancer.getId(), uex)); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String usageAlertDescription = 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(usageAlertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), usageAlertDescription); } return; } List<SnmpUsage> usages2 = new ArrayList<SnmpUsage>(); Map<Integer, SnmpUsage> usagesMap2 = new HashMap<Integer, SnmpUsage>(); try { LOG.info(String.format("Collecting usage AFTER ssl event for load balancer %s...", dbLoadBalancer.getId())); usages2 = usageEventCollection.getUsage(dbLoadBalancer); for (SnmpUsage usage : usages2) { usagesMap2.put(usage.getHostId(), usage); } LOG.info(String.format("Successfully collected usage AFTER ssl event for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the ssl usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } for (CertificateMapping certificateMapping : dbLoadBalancer.getCertificateMappings()) { try { LOG.info(String.format("Removing certificate '%s' for load balancer %d...", certificateMapping.getId(), dbLoadBalancer.getId())); certificateMappingService.deleteByIdAndLoadBalancerId(certificateMapping.getId(), dbLoadBalancer.getId()); LOG.info(String.format("Successfully removed certificate '%s' for load balancer %d.", certificateMapping.getId(), dbLoadBalancer.getId())); } catch (Exception odne) { LOG.info(String.format("Certificate for host '%s' does not exist for load balancer %d. Ignoring...", certificateMapping.getHostName(), dbLoadBalancer.getId())); } } sslTerminationService.deleteSslTermination(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); Calendar eventTime = Calendar.getInstance(); SslTerminationUsage sslTermUsageHelper = new SslTerminationUsage(); SslTermination currentSslTerm = new SslTermination(); currentSslTerm.setEnabled(false); List<SnmpUsage> usagesToInsert = sslTermUsageHelper.getUsagesToInsert(dbLoadBalancer.getId(), dataContainer.getPreviousSslTermination(), currentSslTerm, usagesMap, usagesMap2); try { usageEventCollection.processUsageEvent(usagesToInsert, dbLoadBalancer, UsageEvent.SSL_OFF, eventTime); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String usageAlertDescription = 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(usageAlertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), usageAlertDescription); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); String atomTitle = "Load Balancer SSL Termination Successfully Deleted"; String atomSummary = "Load balancer ssl termination successfully deleted"; notificationService.saveLoadBalancerEvent(errorMsgLB.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_SSL_TERMINATION, DELETE, INFO); LOG.info(String.format("Load balancer ssl termination '%d' successfully deleted.", dbLoadBalancer.getId())); }  }
DeleteSslTerminationListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer dataContainer = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; LoadBalancer errorMsgLB = new LoadBalancer(); errorMsgLB.setUserName(dataContainer.getUserName()); errorMsgLB.setId(dataContainer.getLoadBalancerId()); errorMsgLB.setAccountId(dataContainer.getAccountId()); try { dbLoadBalancer = loadBalancerService.getWithUserPages(errorMsgLB.getId(), errorMsgLB.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", errorMsgLB.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(errorMsgLB.getAccountId(), errorMsgLB.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(errorMsgLB); return; } List<SnmpUsage> usages = new ArrayList<SnmpUsage>(); Map<Integer, SnmpUsage> usagesMap = new HashMap<Integer, SnmpUsage>(); try { LOG.info(String.format("Collecting usage BEFORE ssl event for load balancer %s...", dbLoadBalancer.getId())); usages = usageEventCollection.getUsage(dbLoadBalancer); for (SnmpUsage usage : usages) { usagesMap.put(usage.getHostId(), usage); } LOG.info(String.format("Successfully collected usage BEFORE ssl event for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the ssl usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.removeSslTermination(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.removeSslTermination(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%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' ssl termination in Zeus.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(errorMsgLB); Calendar eventTime = Calendar.getInstance(); try { usageEventCollection.collectUsageAndProcessUsageRecords(dbLoadBalancer, UsageEvent.SSL_OFF, eventTime); } catch (UsageEventCollectionException uex) { LOG.error(String.format("Collection and processing of the usage event failed for load balancer: %s " + ":: Exception: %s", dbLoadBalancer.getId(), uex)); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String usageAlertDescription = 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(usageAlertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), usageAlertDescription); } return; } List<SnmpUsage> usages2 = new ArrayList<SnmpUsage>(); Map<Integer, SnmpUsage> usagesMap2 = new HashMap<Integer, SnmpUsage>(); try { LOG.info(String.format("Collecting usage AFTER ssl event for load balancer %s...", dbLoadBalancer.getId())); usages2 = usageEventCollection.getUsage(dbLoadBalancer); for (SnmpUsage usage : usages2) { usagesMap2.put(usage.getHostId(), usage); } LOG.info(String.format("Successfully collected usage AFTER ssl event for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the ssl usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } for (CertificateMapping certificateMapping : dbLoadBalancer.getCertificateMappings()) { try { LOG.info(String.format("Removing certificate '%s' for load balancer %d...", certificateMapping.getId(), dbLoadBalancer.getId())); certificateMappingService.deleteByIdAndLoadBalancerId(certificateMapping.getId(), dbLoadBalancer.getId()); LOG.info(String.format("Successfully removed certificate '%s' for load balancer %d.", certificateMapping.getId(), dbLoadBalancer.getId())); } catch (Exception odne) { LOG.info(String.format("Certificate for host '%s' does not exist for load balancer %d. Ignoring...", certificateMapping.getHostName(), dbLoadBalancer.getId())); } } sslTerminationService.deleteSslTermination(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); Calendar eventTime = Calendar.getInstance(); SslTerminationUsage sslTermUsageHelper = new SslTerminationUsage(); SslTermination currentSslTerm = new SslTermination(); currentSslTerm.setEnabled(false); List<SnmpUsage> usagesToInsert = sslTermUsageHelper.getUsagesToInsert(dbLoadBalancer.getId(), dataContainer.getPreviousSslTermination(), currentSslTerm, usagesMap, usagesMap2); try { usageEventCollection.processUsageEvent(usagesToInsert, dbLoadBalancer, UsageEvent.SSL_OFF, eventTime); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String usageAlertDescription = 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(usageAlertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), usageAlertDescription); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); String atomTitle = "Load Balancer SSL Termination Successfully Deleted"; String atomSummary = "Load balancer ssl termination successfully deleted"; notificationService.saveLoadBalancerEvent(errorMsgLB.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_SSL_TERMINATION, DELETE, INFO); LOG.info(String.format("Load balancer ssl termination '%d' successfully deleted.", dbLoadBalancer.getId())); }  @Override void doOnMessage(final Message message); }
DeleteSslTerminationListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer dataContainer = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; LoadBalancer errorMsgLB = new LoadBalancer(); errorMsgLB.setUserName(dataContainer.getUserName()); errorMsgLB.setId(dataContainer.getLoadBalancerId()); errorMsgLB.setAccountId(dataContainer.getAccountId()); try { dbLoadBalancer = loadBalancerService.getWithUserPages(errorMsgLB.getId(), errorMsgLB.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", errorMsgLB.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(errorMsgLB.getAccountId(), errorMsgLB.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(errorMsgLB); return; } List<SnmpUsage> usages = new ArrayList<SnmpUsage>(); Map<Integer, SnmpUsage> usagesMap = new HashMap<Integer, SnmpUsage>(); try { LOG.info(String.format("Collecting usage BEFORE ssl event for load balancer %s...", dbLoadBalancer.getId())); usages = usageEventCollection.getUsage(dbLoadBalancer); for (SnmpUsage usage : usages) { usagesMap.put(usage.getHostId(), usage); } LOG.info(String.format("Successfully collected usage BEFORE ssl event for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the ssl usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } try { if (isRestAdapter()) { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.removeSslTermination(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%d' in Zeus.", dbLoadBalancer.getId())); } else { LOG.debug(String.format("Deleting load balancer '%d' ssl termination in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.removeSslTermination(dbLoadBalancer); LOG.debug(String.format("Successfully deleted load balancer ssl termination '%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' ssl termination in Zeus.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(errorMsgLB); Calendar eventTime = Calendar.getInstance(); try { usageEventCollection.collectUsageAndProcessUsageRecords(dbLoadBalancer, UsageEvent.SSL_OFF, eventTime); } catch (UsageEventCollectionException uex) { LOG.error(String.format("Collection and processing of the usage event failed for load balancer: %s " + ":: Exception: %s", dbLoadBalancer.getId(), uex)); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String usageAlertDescription = 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(usageAlertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), usageAlertDescription); } return; } List<SnmpUsage> usages2 = new ArrayList<SnmpUsage>(); Map<Integer, SnmpUsage> usagesMap2 = new HashMap<Integer, SnmpUsage>(); try { LOG.info(String.format("Collecting usage AFTER ssl event for load balancer %s...", dbLoadBalancer.getId())); usages2 = usageEventCollection.getUsage(dbLoadBalancer); for (SnmpUsage usage : usages2) { usagesMap2.put(usage.getHostId(), usage); } LOG.info(String.format("Successfully collected usage AFTER ssl event for load balancer %s", dbLoadBalancer.getId())); } catch (UsageEventCollectionException e) { LOG.error(String.format("Collection of the ssl usage event failed for " + "load balancer: %s :: Exception: %s", dbLoadBalancer.getId(), e)); } for (CertificateMapping certificateMapping : dbLoadBalancer.getCertificateMappings()) { try { LOG.info(String.format("Removing certificate '%s' for load balancer %d...", certificateMapping.getId(), dbLoadBalancer.getId())); certificateMappingService.deleteByIdAndLoadBalancerId(certificateMapping.getId(), dbLoadBalancer.getId()); LOG.info(String.format("Successfully removed certificate '%s' for load balancer %d.", certificateMapping.getId(), dbLoadBalancer.getId())); } catch (Exception odne) { LOG.info(String.format("Certificate for host '%s' does not exist for load balancer %d. Ignoring...", certificateMapping.getHostName(), dbLoadBalancer.getId())); } } sslTerminationService.deleteSslTermination(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId()); Calendar eventTime = Calendar.getInstance(); SslTerminationUsage sslTermUsageHelper = new SslTerminationUsage(); SslTermination currentSslTerm = new SslTermination(); currentSslTerm.setEnabled(false); List<SnmpUsage> usagesToInsert = sslTermUsageHelper.getUsagesToInsert(dbLoadBalancer.getId(), dataContainer.getPreviousSslTermination(), currentSslTerm, usagesMap, usagesMap2); try { usageEventCollection.processUsageEvent(usagesToInsert, dbLoadBalancer, UsageEvent.SSL_OFF, eventTime); } catch (Exception exc) { String exceptionStackTrace = Debug.getExtendedStackTrace(exc); String usageAlertDescription = 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(usageAlertDescription); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), exc, USAGE_FAILURE.name(), usageAlertDescription); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); String atomTitle = "Load Balancer SSL Termination Successfully Deleted"; String atomSummary = "Load balancer ssl termination successfully deleted"; notificationService.saveLoadBalancerEvent(errorMsgLB.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_SSL_TERMINATION, DELETE, INFO); LOG.info(String.format("Load balancer ssl termination '%d' successfully deleted.", dbLoadBalancer.getId())); }  @Override void doOnMessage(final Message message);  }