@Test public void testAddInvalidVirtualIp() throws Exception { MessageDataContainer messageDataContainer = new MessageDataContainer(); messageDataContainer.setLoadBalancerId(LOAD_BALANCER_ID); messageDataContainer.setNewVipIds(newVipIds); when(config.getString(Matchers.<ConfigurationKey>any())).thenReturn("REST"); when(objectMessage.getObject()).thenReturn(messageDataContainer); when(loadBalancerService.getWithUserPages(LOAD_BALANCER_ID)).thenReturn(lb); doThrow(Exception.class).when(reverseProxyLoadBalancerStmService).addVirtualIps(LOAD_BALANCER_ID, ACCOUNT_ID, lb); addVirtualIpListener.doOnMessage(objectMessage); verify(reverseProxyLoadBalancerStmService).addVirtualIps(LOAD_BALANCER_ID, ACCOUNT_ID, 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).saveVirtualIpEvent(eq(USERNAME), eq(ACCOUNT_ID), eq(LOAD_BALANCER_ID), eq(VIP_ID), anyString(), anyString(), eq(EventType.UPDATE_LOADBALANCER), eq(CategoryType.CREATE), eq(EventSeverity.CRITICAL)); }
@Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer dataContainer = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(dataContainer.getLoadBalancerId()); if (dataContainer.getAccountId() == null) dataContainer.setAccountId(dbLoadBalancer.getAccountId()); if (dataContainer.getUserName() == null) dataContainer.setUserName(dbLoadBalancer.getUserName()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", dataContainer.getLoadBalancerId()); LOG.error(alertDescription, enfe); if (dataContainer.getUserName() == null) dataContainer.setUserName(""); if (dataContainer.getAccountId() == null) dataContainer.setAccountId(0); notificationService.saveAlert(dataContainer.getAccountId(), dataContainer.getLoadBalancerId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(dataContainer); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Adding Virtual ip to load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.addVirtualIps(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId(), dbLoadBalancer); LOG.debug("Successfully added virtual ip in Zeus."); } else { LOG.debug(String.format("Adding Virtual ip to load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.addVirtualIps(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId(), dbLoadBalancer); LOG.debug("Successfully added virtual ip in Zeus."); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error adding virtual ip in Zeus for loadbalancer '%d'.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(dataContainer); return; } Calendar eventTime = Calendar.getInstance(); try { usageEventCollection.collectUsageAndProcessUsageRecords(dbLoadBalancer, UsageEvent.CREATE_VIRTUAL_IP, 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 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); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); for (Integer newVipId : dataContainer.getNewVipIds()) { notificationService.saveVirtualIpEvent(dataContainer.getUserName(), dataContainer.getAccountId(), dataContainer.getLoadBalancerId(), newVipId, CREATE_VIP_TITLE, EntryHelper.createVirtualIpSummary(), EventType.CREATE_VIRTUAL_IP, CREATE, INFO); } LOG.info(String.format("Add virtual ip operation complete for load balancer '%d'.", dbLoadBalancer.getId())); }
AddVirtualIpListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer dataContainer = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(dataContainer.getLoadBalancerId()); if (dataContainer.getAccountId() == null) dataContainer.setAccountId(dbLoadBalancer.getAccountId()); if (dataContainer.getUserName() == null) dataContainer.setUserName(dbLoadBalancer.getUserName()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", dataContainer.getLoadBalancerId()); LOG.error(alertDescription, enfe); if (dataContainer.getUserName() == null) dataContainer.setUserName(""); if (dataContainer.getAccountId() == null) dataContainer.setAccountId(0); notificationService.saveAlert(dataContainer.getAccountId(), dataContainer.getLoadBalancerId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(dataContainer); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Adding Virtual ip to load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.addVirtualIps(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId(), dbLoadBalancer); LOG.debug("Successfully added virtual ip in Zeus."); } else { LOG.debug(String.format("Adding Virtual ip to load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.addVirtualIps(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId(), dbLoadBalancer); LOG.debug("Successfully added virtual ip in Zeus."); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error adding virtual ip in Zeus for loadbalancer '%d'.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(dataContainer); return; } Calendar eventTime = Calendar.getInstance(); try { usageEventCollection.collectUsageAndProcessUsageRecords(dbLoadBalancer, UsageEvent.CREATE_VIRTUAL_IP, 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 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); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); for (Integer newVipId : dataContainer.getNewVipIds()) { notificationService.saveVirtualIpEvent(dataContainer.getUserName(), dataContainer.getAccountId(), dataContainer.getLoadBalancerId(), newVipId, CREATE_VIP_TITLE, EntryHelper.createVirtualIpSummary(), EventType.CREATE_VIRTUAL_IP, CREATE, INFO); } LOG.info(String.format("Add virtual ip operation complete for load balancer '%d'.", dbLoadBalancer.getId())); } }
AddVirtualIpListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer dataContainer = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(dataContainer.getLoadBalancerId()); if (dataContainer.getAccountId() == null) dataContainer.setAccountId(dbLoadBalancer.getAccountId()); if (dataContainer.getUserName() == null) dataContainer.setUserName(dbLoadBalancer.getUserName()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", dataContainer.getLoadBalancerId()); LOG.error(alertDescription, enfe); if (dataContainer.getUserName() == null) dataContainer.setUserName(""); if (dataContainer.getAccountId() == null) dataContainer.setAccountId(0); notificationService.saveAlert(dataContainer.getAccountId(), dataContainer.getLoadBalancerId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(dataContainer); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Adding Virtual ip to load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.addVirtualIps(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId(), dbLoadBalancer); LOG.debug("Successfully added virtual ip in Zeus."); } else { LOG.debug(String.format("Adding Virtual ip to load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.addVirtualIps(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId(), dbLoadBalancer); LOG.debug("Successfully added virtual ip in Zeus."); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error adding virtual ip in Zeus for loadbalancer '%d'.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(dataContainer); return; } Calendar eventTime = Calendar.getInstance(); try { usageEventCollection.collectUsageAndProcessUsageRecords(dbLoadBalancer, UsageEvent.CREATE_VIRTUAL_IP, 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 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); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); for (Integer newVipId : dataContainer.getNewVipIds()) { notificationService.saveVirtualIpEvent(dataContainer.getUserName(), dataContainer.getAccountId(), dataContainer.getLoadBalancerId(), newVipId, CREATE_VIP_TITLE, EntryHelper.createVirtualIpSummary(), EventType.CREATE_VIRTUAL_IP, CREATE, INFO); } LOG.info(String.format("Add virtual ip operation complete for load balancer '%d'.", dbLoadBalancer.getId())); }  }
AddVirtualIpListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer dataContainer = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(dataContainer.getLoadBalancerId()); if (dataContainer.getAccountId() == null) dataContainer.setAccountId(dbLoadBalancer.getAccountId()); if (dataContainer.getUserName() == null) dataContainer.setUserName(dbLoadBalancer.getUserName()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", dataContainer.getLoadBalancerId()); LOG.error(alertDescription, enfe); if (dataContainer.getUserName() == null) dataContainer.setUserName(""); if (dataContainer.getAccountId() == null) dataContainer.setAccountId(0); notificationService.saveAlert(dataContainer.getAccountId(), dataContainer.getLoadBalancerId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(dataContainer); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Adding Virtual ip to load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.addVirtualIps(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId(), dbLoadBalancer); LOG.debug("Successfully added virtual ip in Zeus."); } else { LOG.debug(String.format("Adding Virtual ip to load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.addVirtualIps(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId(), dbLoadBalancer); LOG.debug("Successfully added virtual ip in Zeus."); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error adding virtual ip in Zeus for loadbalancer '%d'.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(dataContainer); return; } Calendar eventTime = Calendar.getInstance(); try { usageEventCollection.collectUsageAndProcessUsageRecords(dbLoadBalancer, UsageEvent.CREATE_VIRTUAL_IP, 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 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); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); for (Integer newVipId : dataContainer.getNewVipIds()) { notificationService.saveVirtualIpEvent(dataContainer.getUserName(), dataContainer.getAccountId(), dataContainer.getLoadBalancerId(), newVipId, CREATE_VIP_TITLE, EntryHelper.createVirtualIpSummary(), EventType.CREATE_VIRTUAL_IP, CREATE, INFO); } LOG.info(String.format("Add virtual ip operation complete for load balancer '%d'.", dbLoadBalancer.getId())); }  @Override void doOnMessage(final Message message); }
AddVirtualIpListener extends BaseListener { @Override public void doOnMessage(final Message message) throws Exception { LOG.debug("Entering " + getClass()); LOG.debug(message); MessageDataContainer dataContainer = getDataContainerFromMessage(message); LoadBalancer dbLoadBalancer; try { dbLoadBalancer = loadBalancerService.getWithUserPages(dataContainer.getLoadBalancerId()); if (dataContainer.getAccountId() == null) dataContainer.setAccountId(dbLoadBalancer.getAccountId()); if (dataContainer.getUserName() == null) dataContainer.setUserName(dbLoadBalancer.getUserName()); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", dataContainer.getLoadBalancerId()); LOG.error(alertDescription, enfe); if (dataContainer.getUserName() == null) dataContainer.setUserName(""); if (dataContainer.getAccountId() == null) dataContainer.setAccountId(0); notificationService.saveAlert(dataContainer.getAccountId(), dataContainer.getLoadBalancerId(), enfe, DATABASE_FAILURE.name(), alertDescription); sendErrorToEventResource(dataContainer); return; } try { if (isRestAdapter()) { LOG.debug(String.format("Adding Virtual ip to load balancer '%d' in STM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerStmService.addVirtualIps(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId(), dbLoadBalancer); LOG.debug("Successfully added virtual ip in Zeus."); } else { LOG.debug(String.format("Adding Virtual ip to load balancer '%d' in ZXTM...", dbLoadBalancer.getId())); reverseProxyLoadBalancerService.addVirtualIps(dbLoadBalancer.getId(), dbLoadBalancer.getAccountId(), dbLoadBalancer); LOG.debug("Successfully added virtual ip in Zeus."); } } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String alertDescription = String.format("Error adding virtual ip in Zeus for loadbalancer '%d'.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(dataContainer); return; } Calendar eventTime = Calendar.getInstance(); try { usageEventCollection.collectUsageAndProcessUsageRecords(dbLoadBalancer, UsageEvent.CREATE_VIRTUAL_IP, 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 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); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); for (Integer newVipId : dataContainer.getNewVipIds()) { notificationService.saveVirtualIpEvent(dataContainer.getUserName(), dataContainer.getAccountId(), dataContainer.getLoadBalancerId(), newVipId, CREATE_VIP_TITLE, EntryHelper.createVirtualIpSummary(), EventType.CREATE_VIRTUAL_IP, CREATE, INFO); } LOG.info(String.format("Add virtual ip operation complete for load balancer '%d'.", dbLoadBalancer.getId())); }  @Override void doOnMessage(final Message message);  }