@Test public void testDeleteInvalidSessionPersistence() throws Exception { when(objectMessage.getObject()).thenReturn(lb); when(loadBalancerService.getWithUserPages(LOAD_BALANCER_ID, ACCOUNT_ID)).thenReturn(lb); doThrow(Exception.class).when(reverseProxyLoadBalancerStmService).updateLoadBalancer(lb, lb); when(config.getString(Matchers.<ConfigurationKey>any())).thenReturn("REST"); deleteSessionPersistenceListener.doOnMessage(objectMessage); verify(reverseProxyLoadBalancerStmService).updateLoadBalancer(lb, lb); 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).saveSessionPersistenceEvent(eq(USERNAME), eq(ACCOUNT_ID), eq(LOAD_BALANCER_ID), anyString(), anyString(), eq(EventType.DELETE_SESSION_PERSISTENCE), eq(CategoryType.DELETE), eq(EventSeverity.CRITICAL)); }
@Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); LoadBalancer queLb = getLoadbalancerFromMessage(message); LoadBalancer dbLoadBalancer; LoadBalancer transportLb; try { dbLoadBalancer = loadBalancerService.getWithUserPages(queLb.getId(), queLb.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", queLb.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(queLb.getAccountId(), queLb.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queLb); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Removing session persistence for load balancer '%d' in STM...", queLb.getId())); queLb.setSessionPersistence(SessionPersistence.NONE); reverseProxyLoadBalancerStmService.updateLoadBalancer(dbLoadBalancer, queLb); LOG.debug(String.format("Successfully removed session persistence for load balancer '%d' in Zeus.", queLb.getId())); } else { LOG.debug(String.format("Removing session persistence for load balancer '%d' in ZXTM...", queLb.getId())); reverseProxyLoadBalancerService.removeSessionPersistence(queLb.getId(), queLb.getAccountId()); LOG.debug(String.format("Successfully removed session persistence for load balancer '%d' in Zeus.", queLb.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing session persistence in Zeus for loadbalancer '%d'.", queLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(queLb.getAccountId(), queLb.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queLb); return; } dbLoadBalancer.setSessionPersistence(SessionPersistence.NONE); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Session Persistence Successfully Deleted"; String atomSummary = "Session persistence successfully deleted"; notificationService.saveSessionPersistenceEvent(queLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_SESSION_PERSISTENCE, DELETE, INFO); LOG.info(String.format("Delete session persistence operation complete for load balancer '%d'.", queLb.getId())); }
DeleteSessionPersistenceListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); LoadBalancer queLb = getLoadbalancerFromMessage(message); LoadBalancer dbLoadBalancer; LoadBalancer transportLb; try { dbLoadBalancer = loadBalancerService.getWithUserPages(queLb.getId(), queLb.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", queLb.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(queLb.getAccountId(), queLb.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queLb); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Removing session persistence for load balancer '%d' in STM...", queLb.getId())); queLb.setSessionPersistence(SessionPersistence.NONE); reverseProxyLoadBalancerStmService.updateLoadBalancer(dbLoadBalancer, queLb); LOG.debug(String.format("Successfully removed session persistence for load balancer '%d' in Zeus.", queLb.getId())); } else { LOG.debug(String.format("Removing session persistence for load balancer '%d' in ZXTM...", queLb.getId())); reverseProxyLoadBalancerService.removeSessionPersistence(queLb.getId(), queLb.getAccountId()); LOG.debug(String.format("Successfully removed session persistence for load balancer '%d' in Zeus.", queLb.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing session persistence in Zeus for loadbalancer '%d'.", queLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(queLb.getAccountId(), queLb.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queLb); return; } dbLoadBalancer.setSessionPersistence(SessionPersistence.NONE); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Session Persistence Successfully Deleted"; String atomSummary = "Session persistence successfully deleted"; notificationService.saveSessionPersistenceEvent(queLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_SESSION_PERSISTENCE, DELETE, INFO); LOG.info(String.format("Delete session persistence operation complete for load balancer '%d'.", queLb.getId())); } }
DeleteSessionPersistenceListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); LoadBalancer queLb = getLoadbalancerFromMessage(message); LoadBalancer dbLoadBalancer; LoadBalancer transportLb; try { dbLoadBalancer = loadBalancerService.getWithUserPages(queLb.getId(), queLb.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", queLb.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(queLb.getAccountId(), queLb.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queLb); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Removing session persistence for load balancer '%d' in STM...", queLb.getId())); queLb.setSessionPersistence(SessionPersistence.NONE); reverseProxyLoadBalancerStmService.updateLoadBalancer(dbLoadBalancer, queLb); LOG.debug(String.format("Successfully removed session persistence for load balancer '%d' in Zeus.", queLb.getId())); } else { LOG.debug(String.format("Removing session persistence for load balancer '%d' in ZXTM...", queLb.getId())); reverseProxyLoadBalancerService.removeSessionPersistence(queLb.getId(), queLb.getAccountId()); LOG.debug(String.format("Successfully removed session persistence for load balancer '%d' in Zeus.", queLb.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing session persistence in Zeus for loadbalancer '%d'.", queLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(queLb.getAccountId(), queLb.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queLb); return; } dbLoadBalancer.setSessionPersistence(SessionPersistence.NONE); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Session Persistence Successfully Deleted"; String atomSummary = "Session persistence successfully deleted"; notificationService.saveSessionPersistenceEvent(queLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_SESSION_PERSISTENCE, DELETE, INFO); LOG.info(String.format("Delete session persistence operation complete for load balancer '%d'.", queLb.getId())); }  }
DeleteSessionPersistenceListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); LoadBalancer queLb = getLoadbalancerFromMessage(message); LoadBalancer dbLoadBalancer; LoadBalancer transportLb; try { dbLoadBalancer = loadBalancerService.getWithUserPages(queLb.getId(), queLb.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", queLb.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(queLb.getAccountId(), queLb.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queLb); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Removing session persistence for load balancer '%d' in STM...", queLb.getId())); queLb.setSessionPersistence(SessionPersistence.NONE); reverseProxyLoadBalancerStmService.updateLoadBalancer(dbLoadBalancer, queLb); LOG.debug(String.format("Successfully removed session persistence for load balancer '%d' in Zeus.", queLb.getId())); } else { LOG.debug(String.format("Removing session persistence for load balancer '%d' in ZXTM...", queLb.getId())); reverseProxyLoadBalancerService.removeSessionPersistence(queLb.getId(), queLb.getAccountId()); LOG.debug(String.format("Successfully removed session persistence for load balancer '%d' in Zeus.", queLb.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing session persistence in Zeus for loadbalancer '%d'.", queLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(queLb.getAccountId(), queLb.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queLb); return; } dbLoadBalancer.setSessionPersistence(SessionPersistence.NONE); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Session Persistence Successfully Deleted"; String atomSummary = "Session persistence successfully deleted"; notificationService.saveSessionPersistenceEvent(queLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_SESSION_PERSISTENCE, DELETE, INFO); LOG.info(String.format("Delete session persistence operation complete for load balancer '%d'.", queLb.getId())); }  @Override void doOnMessage(final Message message); }
DeleteSessionPersistenceListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); LoadBalancer queLb = getLoadbalancerFromMessage(message); LoadBalancer dbLoadBalancer; LoadBalancer transportLb; try { dbLoadBalancer = loadBalancerService.getWithUserPages(queLb.getId(), queLb.getAccountId()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", queLb.getId()); LOG.error(alertDescription, enfe); notificationService.saveAlert(queLb.getAccountId(), queLb.getId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(queLb); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Removing session persistence for load balancer '%d' in STM...", queLb.getId())); queLb.setSessionPersistence(SessionPersistence.NONE); reverseProxyLoadBalancerStmService.updateLoadBalancer(dbLoadBalancer, queLb); LOG.debug(String.format("Successfully removed session persistence for load balancer '%d' in Zeus.", queLb.getId())); } else { LOG.debug(String.format("Removing session persistence for load balancer '%d' in ZXTM...", queLb.getId())); reverseProxyLoadBalancerService.removeSessionPersistence(queLb.getId(), queLb.getAccountId()); LOG.debug(String.format("Successfully removed session persistence for load balancer '%d' in Zeus.", queLb.getId())); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error removing session persistence in Zeus for loadbalancer '%d'.", queLb.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(queLb.getAccountId(), queLb.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queLb); return; } dbLoadBalancer.setSessionPersistence(SessionPersistence.NONE); dbLoadBalancer.setStatus(LoadBalancerStatus.ACTIVE); loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ACTIVE); String atomTitle = "Session Persistence Successfully Deleted"; String atomSummary = "Session persistence successfully deleted"; notificationService.saveSessionPersistenceEvent(queLb.getUserName(), dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), atomTitle, atomSummary, DELETE_SESSION_PERSISTENCE, DELETE, INFO); LOG.info(String.format("Delete session persistence operation complete for load balancer '%d'.", queLb.getId())); }  @Override void doOnMessage(final Message message);  }