@Test public void testCreateInvalidLoadBalancer() throws Exception { when(objectMessage.getObject()).thenReturn(lb); when(loadBalancerService.getWithUserPages(LOAD_BALANCER_ID, ACCOUNT_ID)).thenReturn(lb); doThrow(Exception.class).when(reverseProxyLoadBalancerStmService).createLoadBalancer(lb); when(config.getString(Matchers.<ConfigurationKey>any())).thenReturn("REST"); createLoadBalancerListener.doOnMessage(objectMessage); verify(reverseProxyLoadBalancerStmService).createLoadBalancer(lb); Assert.assertEquals(lb.getStatus(), LoadBalancerStatus.ERROR); Assert.assertTrue(checkNodeHelper(lb.getNodes(), NodeStatus.OFFLINE)); verify(loadBalancerService).update(lb); verify(notificationService).saveAlert(eq(ACCOUNT_ID), eq(LOAD_BALANCER_ID), isA(Exception.class), eq(AlertType.ZEUS_FAILURE.name()), anyString()); verify(loadBalancerStatusHistoryService).save(ACCOUNT_ID, LOAD_BALANCER_ID, LoadBalancerStatus.ERROR); verify(usageEventCollection).processZeroUsageEvent(eq(lb), eq(UsageEvent.CREATE_LOADBALANCER), Matchers.any(Calendar.class)); }
@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; } try { if (isRestAdapter()) { LOG.debug("Creating load balancer in STM..."); reverseProxyLoadBalancerStmService.createLoadBalancer(dbLoadBalancer); LOG.debug("Successfully created a load balancer in STM."); } else { LOG.debug("Creating load balancer in ZXTM..."); reverseProxyLoadBalancerService.createLoadBalancer(dbLoadBalancer); LOG.debug("Successfully created a load balancer in ZXTM."); } } catch (Exception e) { dbLoadBalancer.setStatus(ERROR); NodesHelper.setNodesToStatus(dbLoadBalancer, OFFLINE); loadBalancerService.update(dbLoadBalancer); String alertDescription = String.format("An error occurred while creating loadbalancer '%d' in STM.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ERROR); Calendar usageEventTime = Calendar.getInstance(); try { usageEventCollection.processZeroUsageEvent(dbLoadBalancer, UsageEvent.CREATE_LOADBALANCER, usageEventTime); } catch (UsageEventCollectionException uex) { LOG.error(String.format("Collection and processing of the usage event failed for load balancer: %s " + ":: Exception: %s", dbLoadBalancer.getId(), uex)); } return; } Calendar usageEventTime = Calendar.getInstance(); try { usageEventCollection.processZeroUsageEvent(dbLoadBalancer, UsageEvent.CREATE_LOADBALANCER, usageEventTime); } 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); } dbLoadBalancer.setStatus(ACTIVE); NodesHelper.setNodesToStatus(dbLoadBalancer, ONLINE); dbLoadBalancer.setProvisioned(usageEventTime); dbLoadBalancer = loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(queueLb.getAccountId(), queueLb.getId(), LoadBalancerStatus.ACTIVE); addAtomEntryForLoadBalancer(queueLb, dbLoadBalancer); addAtomEntriesForNodes(queueLb, dbLoadBalancer); addAtomEntriesForVips(queueLb, dbLoadBalancer); addAtomEntryForHealthMonitor(queueLb, dbLoadBalancer); addAtomEntryForSessionPersistence(queueLb, dbLoadBalancer); addAtomEntryForConnectionLogging(queueLb, dbLoadBalancer); addAtomEntryForConnectionLimit(queueLb, dbLoadBalancer); addAtomEntriesForAccessList(queueLb, dbLoadBalancer); LOG.info(String.format("Created load balancer '%d' successfully.", dbLoadBalancer.getId())); }
CreateLoadBalancerListener 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; } try { if (isRestAdapter()) { LOG.debug("Creating load balancer in STM..."); reverseProxyLoadBalancerStmService.createLoadBalancer(dbLoadBalancer); LOG.debug("Successfully created a load balancer in STM."); } else { LOG.debug("Creating load balancer in ZXTM..."); reverseProxyLoadBalancerService.createLoadBalancer(dbLoadBalancer); LOG.debug("Successfully created a load balancer in ZXTM."); } } catch (Exception e) { dbLoadBalancer.setStatus(ERROR); NodesHelper.setNodesToStatus(dbLoadBalancer, OFFLINE); loadBalancerService.update(dbLoadBalancer); String alertDescription = String.format("An error occurred while creating loadbalancer '%d' in STM.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ERROR); Calendar usageEventTime = Calendar.getInstance(); try { usageEventCollection.processZeroUsageEvent(dbLoadBalancer, UsageEvent.CREATE_LOADBALANCER, usageEventTime); } catch (UsageEventCollectionException uex) { LOG.error(String.format("Collection and processing of the usage event failed for load balancer: %s " + ":: Exception: %s", dbLoadBalancer.getId(), uex)); } return; } Calendar usageEventTime = Calendar.getInstance(); try { usageEventCollection.processZeroUsageEvent(dbLoadBalancer, UsageEvent.CREATE_LOADBALANCER, usageEventTime); } 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); } dbLoadBalancer.setStatus(ACTIVE); NodesHelper.setNodesToStatus(dbLoadBalancer, ONLINE); dbLoadBalancer.setProvisioned(usageEventTime); dbLoadBalancer = loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(queueLb.getAccountId(), queueLb.getId(), LoadBalancerStatus.ACTIVE); addAtomEntryForLoadBalancer(queueLb, dbLoadBalancer); addAtomEntriesForNodes(queueLb, dbLoadBalancer); addAtomEntriesForVips(queueLb, dbLoadBalancer); addAtomEntryForHealthMonitor(queueLb, dbLoadBalancer); addAtomEntryForSessionPersistence(queueLb, dbLoadBalancer); addAtomEntryForConnectionLogging(queueLb, dbLoadBalancer); addAtomEntryForConnectionLimit(queueLb, dbLoadBalancer); addAtomEntriesForAccessList(queueLb, dbLoadBalancer); LOG.info(String.format("Created load balancer '%d' successfully.", dbLoadBalancer.getId())); } }
CreateLoadBalancerListener 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; } try { if (isRestAdapter()) { LOG.debug("Creating load balancer in STM..."); reverseProxyLoadBalancerStmService.createLoadBalancer(dbLoadBalancer); LOG.debug("Successfully created a load balancer in STM."); } else { LOG.debug("Creating load balancer in ZXTM..."); reverseProxyLoadBalancerService.createLoadBalancer(dbLoadBalancer); LOG.debug("Successfully created a load balancer in ZXTM."); } } catch (Exception e) { dbLoadBalancer.setStatus(ERROR); NodesHelper.setNodesToStatus(dbLoadBalancer, OFFLINE); loadBalancerService.update(dbLoadBalancer); String alertDescription = String.format("An error occurred while creating loadbalancer '%d' in STM.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ERROR); Calendar usageEventTime = Calendar.getInstance(); try { usageEventCollection.processZeroUsageEvent(dbLoadBalancer, UsageEvent.CREATE_LOADBALANCER, usageEventTime); } catch (UsageEventCollectionException uex) { LOG.error(String.format("Collection and processing of the usage event failed for load balancer: %s " + ":: Exception: %s", dbLoadBalancer.getId(), uex)); } return; } Calendar usageEventTime = Calendar.getInstance(); try { usageEventCollection.processZeroUsageEvent(dbLoadBalancer, UsageEvent.CREATE_LOADBALANCER, usageEventTime); } 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); } dbLoadBalancer.setStatus(ACTIVE); NodesHelper.setNodesToStatus(dbLoadBalancer, ONLINE); dbLoadBalancer.setProvisioned(usageEventTime); dbLoadBalancer = loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(queueLb.getAccountId(), queueLb.getId(), LoadBalancerStatus.ACTIVE); addAtomEntryForLoadBalancer(queueLb, dbLoadBalancer); addAtomEntriesForNodes(queueLb, dbLoadBalancer); addAtomEntriesForVips(queueLb, dbLoadBalancer); addAtomEntryForHealthMonitor(queueLb, dbLoadBalancer); addAtomEntryForSessionPersistence(queueLb, dbLoadBalancer); addAtomEntryForConnectionLogging(queueLb, dbLoadBalancer); addAtomEntryForConnectionLimit(queueLb, dbLoadBalancer); addAtomEntriesForAccessList(queueLb, dbLoadBalancer); LOG.info(String.format("Created load balancer '%d' successfully.", dbLoadBalancer.getId())); }  }
CreateLoadBalancerListener 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; } try { if (isRestAdapter()) { LOG.debug("Creating load balancer in STM..."); reverseProxyLoadBalancerStmService.createLoadBalancer(dbLoadBalancer); LOG.debug("Successfully created a load balancer in STM."); } else { LOG.debug("Creating load balancer in ZXTM..."); reverseProxyLoadBalancerService.createLoadBalancer(dbLoadBalancer); LOG.debug("Successfully created a load balancer in ZXTM."); } } catch (Exception e) { dbLoadBalancer.setStatus(ERROR); NodesHelper.setNodesToStatus(dbLoadBalancer, OFFLINE); loadBalancerService.update(dbLoadBalancer); String alertDescription = String.format("An error occurred while creating loadbalancer '%d' in STM.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ERROR); Calendar usageEventTime = Calendar.getInstance(); try { usageEventCollection.processZeroUsageEvent(dbLoadBalancer, UsageEvent.CREATE_LOADBALANCER, usageEventTime); } catch (UsageEventCollectionException uex) { LOG.error(String.format("Collection and processing of the usage event failed for load balancer: %s " + ":: Exception: %s", dbLoadBalancer.getId(), uex)); } return; } Calendar usageEventTime = Calendar.getInstance(); try { usageEventCollection.processZeroUsageEvent(dbLoadBalancer, UsageEvent.CREATE_LOADBALANCER, usageEventTime); } 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); } dbLoadBalancer.setStatus(ACTIVE); NodesHelper.setNodesToStatus(dbLoadBalancer, ONLINE); dbLoadBalancer.setProvisioned(usageEventTime); dbLoadBalancer = loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(queueLb.getAccountId(), queueLb.getId(), LoadBalancerStatus.ACTIVE); addAtomEntryForLoadBalancer(queueLb, dbLoadBalancer); addAtomEntriesForNodes(queueLb, dbLoadBalancer); addAtomEntriesForVips(queueLb, dbLoadBalancer); addAtomEntryForHealthMonitor(queueLb, dbLoadBalancer); addAtomEntryForSessionPersistence(queueLb, dbLoadBalancer); addAtomEntryForConnectionLogging(queueLb, dbLoadBalancer); addAtomEntryForConnectionLimit(queueLb, dbLoadBalancer); addAtomEntriesForAccessList(queueLb, dbLoadBalancer); LOG.info(String.format("Created load balancer '%d' successfully.", dbLoadBalancer.getId())); }  @Override void doOnMessage(final Message message); }
CreateLoadBalancerListener 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; } try { if (isRestAdapter()) { LOG.debug("Creating load balancer in STM..."); reverseProxyLoadBalancerStmService.createLoadBalancer(dbLoadBalancer); LOG.debug("Successfully created a load balancer in STM."); } else { LOG.debug("Creating load balancer in ZXTM..."); reverseProxyLoadBalancerService.createLoadBalancer(dbLoadBalancer); LOG.debug("Successfully created a load balancer in ZXTM."); } } catch (Exception e) { dbLoadBalancer.setStatus(ERROR); NodesHelper.setNodesToStatus(dbLoadBalancer, OFFLINE); loadBalancerService.update(dbLoadBalancer); String alertDescription = String.format("An error occurred while creating loadbalancer '%d' in STM.", dbLoadBalancer.getId()); LOG.error(alertDescription, e); notificationService.saveAlert(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), e, ZEUS_FAILURE.name(), alertDescription); sendErrorToEventResource(queueLb); loadBalancerStatusHistoryService.save(dbLoadBalancer.getAccountId(), dbLoadBalancer.getId(), LoadBalancerStatus.ERROR); Calendar usageEventTime = Calendar.getInstance(); try { usageEventCollection.processZeroUsageEvent(dbLoadBalancer, UsageEvent.CREATE_LOADBALANCER, usageEventTime); } catch (UsageEventCollectionException uex) { LOG.error(String.format("Collection and processing of the usage event failed for load balancer: %s " + ":: Exception: %s", dbLoadBalancer.getId(), uex)); } return; } Calendar usageEventTime = Calendar.getInstance(); try { usageEventCollection.processZeroUsageEvent(dbLoadBalancer, UsageEvent.CREATE_LOADBALANCER, usageEventTime); } 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); } dbLoadBalancer.setStatus(ACTIVE); NodesHelper.setNodesToStatus(dbLoadBalancer, ONLINE); dbLoadBalancer.setProvisioned(usageEventTime); dbLoadBalancer = loadBalancerService.update(dbLoadBalancer); loadBalancerStatusHistoryService.save(queueLb.getAccountId(), queueLb.getId(), LoadBalancerStatus.ACTIVE); addAtomEntryForLoadBalancer(queueLb, dbLoadBalancer); addAtomEntriesForNodes(queueLb, dbLoadBalancer); addAtomEntriesForVips(queueLb, dbLoadBalancer); addAtomEntryForHealthMonitor(queueLb, dbLoadBalancer); addAtomEntryForSessionPersistence(queueLb, dbLoadBalancer); addAtomEntryForConnectionLogging(queueLb, dbLoadBalancer); addAtomEntryForConnectionLimit(queueLb, dbLoadBalancer); addAtomEntriesForAccessList(queueLb, dbLoadBalancer); LOG.info(String.format("Created load balancer '%d' successfully.", dbLoadBalancer.getId())); }  @Override void doOnMessage(final Message message);  }