@Test public void testUpdateLoadBalancerWithInvalidLBErrorFile() throws Exception { when(objectMessage.getObject()).thenReturn(messageDataContainer); when(messageDataContainer.getAccountId()).thenReturn(ACCOUNT_ID); when(messageDataContainer.getLoadBalancerId()).thenReturn(LOAD_BALANCER_ID); when(messageDataContainer.getClusterId()).thenReturn(null); when(messageDataContainer.getUserName()).thenReturn(USERNAME); when(messageDataContainer.getErrorFileContents()).thenReturn(ERROR_FILE_CONTENT); when(loadBalancerService.getWithUserPages(LOAD_BALANCER_ID, ACCOUNT_ID)).thenThrow(EntityNotFoundException.class); Assert.assertNull(lb.getUserName()); updateErrorFileListener.doOnMessage(objectMessage); verify(notificationService).saveAlert(eq(ACCOUNT_ID), eq(LOAD_BALANCER_ID), isA(EntityNotFoundException.class), anyString(), anyString()); verify(loadBalancerStatusHistoryService).save(ACCOUNT_ID, LOAD_BALANCER_ID, LoadBalancerStatus.ERROR); }
@Override public void doOnMessage(Message message) throws Exception { String msg = String.format("Inside %s.doMessage", this.getClass().getName()); LOG.info(msg); MessageDataContainer data = getDataContainerFromMessage(message); String content = data.getErrorFileContents(); Integer aid = data.getAccountId(); Integer lid = data.getLoadBalancerId(); Integer clusterId = data.getClusterId(); String userName = data.getUserName(); LoadBalancer dbLoadBalancer = null; if (aid != null && lid != null) { try { LOG.debug("Grabbing loadbalancer..."); dbLoadBalancer = loadBalancerService.getWithUserPages(lid, aid); dbLoadBalancer.setUserName(userName); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", lid); LOG.error(alertDescription, enfe); notificationService.saveAlert(aid, lid, enfe, DATABASE_FAILURE.name(), alertDescription); loadBalancerStatusHistoryService.save(aid, lid, LoadBalancerStatus.ERROR); return; } try { if (isRestAdapter()) { LOG.debug("Attempting to set error file in STM...calling setErrorFile"); reverseProxyLoadBalancerStmService.setErrorFile(dbLoadBalancer, content); LOG.debug("Successfully updated error file in zeus."); } else { LOG.debug("Attempting to set error file in ZXTM...calling setErrorFile"); reverseProxyLoadBalancerService.setErrorFile(dbLoadBalancer, content); LOG.debug("Successfully updated error file in zeus."); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String tmpMsg = String.format("Error setting Errorfile for %d_%d", aid, lid); LOG.error(tmpMsg, e); notificationService.saveAlert(aid, lid, e, AlertType.ZEUS_FAILURE.name(), msg); sendErrorToEventResource(dbLoadBalancer); } } else if (clusterId != null) { try { if (isRestAdapter()) { LOG.debug("Attempting to upload default error file in STM...calling uploadDefaultErrorFile"); reverseProxyLoadBalancerStmService.uploadDefaultErrorFile(clusterId, content); LOG.debug("Successfully uploaded default error file in zeus."); } else { LOG.debug("Attempting to upload default error file in ZXTM...calling uploadDefaultErrorFile"); reverseProxyLoadBalancerService.uploadDefaultErrorFile(clusterId, content); LOG.debug("Successfully uploaded default error file in zeus."); } } catch (Exception e) { String tmpMsg = String.format("Error uploading default error file..."); LOG.error(tmpMsg, e); notificationService.saveAlert(null, null, e, AlertType.ZEUS_FAILURE.name(), msg); } } }
UpdateErrorFileListener extends BaseListener { @Override public void doOnMessage(Message message) throws Exception { String msg = String.format("Inside %s.doMessage", this.getClass().getName()); LOG.info(msg); MessageDataContainer data = getDataContainerFromMessage(message); String content = data.getErrorFileContents(); Integer aid = data.getAccountId(); Integer lid = data.getLoadBalancerId(); Integer clusterId = data.getClusterId(); String userName = data.getUserName(); LoadBalancer dbLoadBalancer = null; if (aid != null && lid != null) { try { LOG.debug("Grabbing loadbalancer..."); dbLoadBalancer = loadBalancerService.getWithUserPages(lid, aid); dbLoadBalancer.setUserName(userName); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", lid); LOG.error(alertDescription, enfe); notificationService.saveAlert(aid, lid, enfe, DATABASE_FAILURE.name(), alertDescription); loadBalancerStatusHistoryService.save(aid, lid, LoadBalancerStatus.ERROR); return; } try { if (isRestAdapter()) { LOG.debug("Attempting to set error file in STM...calling setErrorFile"); reverseProxyLoadBalancerStmService.setErrorFile(dbLoadBalancer, content); LOG.debug("Successfully updated error file in zeus."); } else { LOG.debug("Attempting to set error file in ZXTM...calling setErrorFile"); reverseProxyLoadBalancerService.setErrorFile(dbLoadBalancer, content); LOG.debug("Successfully updated error file in zeus."); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String tmpMsg = String.format("Error setting Errorfile for %d_%d", aid, lid); LOG.error(tmpMsg, e); notificationService.saveAlert(aid, lid, e, AlertType.ZEUS_FAILURE.name(), msg); sendErrorToEventResource(dbLoadBalancer); } } else if (clusterId != null) { try { if (isRestAdapter()) { LOG.debug("Attempting to upload default error file in STM...calling uploadDefaultErrorFile"); reverseProxyLoadBalancerStmService.uploadDefaultErrorFile(clusterId, content); LOG.debug("Successfully uploaded default error file in zeus."); } else { LOG.debug("Attempting to upload default error file in ZXTM...calling uploadDefaultErrorFile"); reverseProxyLoadBalancerService.uploadDefaultErrorFile(clusterId, content); LOG.debug("Successfully uploaded default error file in zeus."); } } catch (Exception e) { String tmpMsg = String.format("Error uploading default error file..."); LOG.error(tmpMsg, e); notificationService.saveAlert(null, null, e, AlertType.ZEUS_FAILURE.name(), msg); } } } }
UpdateErrorFileListener extends BaseListener { @Override public void doOnMessage(Message message) throws Exception { String msg = String.format("Inside %s.doMessage", this.getClass().getName()); LOG.info(msg); MessageDataContainer data = getDataContainerFromMessage(message); String content = data.getErrorFileContents(); Integer aid = data.getAccountId(); Integer lid = data.getLoadBalancerId(); Integer clusterId = data.getClusterId(); String userName = data.getUserName(); LoadBalancer dbLoadBalancer = null; if (aid != null && lid != null) { try { LOG.debug("Grabbing loadbalancer..."); dbLoadBalancer = loadBalancerService.getWithUserPages(lid, aid); dbLoadBalancer.setUserName(userName); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", lid); LOG.error(alertDescription, enfe); notificationService.saveAlert(aid, lid, enfe, DATABASE_FAILURE.name(), alertDescription); loadBalancerStatusHistoryService.save(aid, lid, LoadBalancerStatus.ERROR); return; } try { if (isRestAdapter()) { LOG.debug("Attempting to set error file in STM...calling setErrorFile"); reverseProxyLoadBalancerStmService.setErrorFile(dbLoadBalancer, content); LOG.debug("Successfully updated error file in zeus."); } else { LOG.debug("Attempting to set error file in ZXTM...calling setErrorFile"); reverseProxyLoadBalancerService.setErrorFile(dbLoadBalancer, content); LOG.debug("Successfully updated error file in zeus."); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String tmpMsg = String.format("Error setting Errorfile for %d_%d", aid, lid); LOG.error(tmpMsg, e); notificationService.saveAlert(aid, lid, e, AlertType.ZEUS_FAILURE.name(), msg); sendErrorToEventResource(dbLoadBalancer); } } else if (clusterId != null) { try { if (isRestAdapter()) { LOG.debug("Attempting to upload default error file in STM...calling uploadDefaultErrorFile"); reverseProxyLoadBalancerStmService.uploadDefaultErrorFile(clusterId, content); LOG.debug("Successfully uploaded default error file in zeus."); } else { LOG.debug("Attempting to upload default error file in ZXTM...calling uploadDefaultErrorFile"); reverseProxyLoadBalancerService.uploadDefaultErrorFile(clusterId, content); LOG.debug("Successfully uploaded default error file in zeus."); } } catch (Exception e) { String tmpMsg = String.format("Error uploading default error file..."); LOG.error(tmpMsg, e); notificationService.saveAlert(null, null, e, AlertType.ZEUS_FAILURE.name(), msg); } } }  }
UpdateErrorFileListener extends BaseListener { @Override public void doOnMessage(Message message) throws Exception { String msg = String.format("Inside %s.doMessage", this.getClass().getName()); LOG.info(msg); MessageDataContainer data = getDataContainerFromMessage(message); String content = data.getErrorFileContents(); Integer aid = data.getAccountId(); Integer lid = data.getLoadBalancerId(); Integer clusterId = data.getClusterId(); String userName = data.getUserName(); LoadBalancer dbLoadBalancer = null; if (aid != null && lid != null) { try { LOG.debug("Grabbing loadbalancer..."); dbLoadBalancer = loadBalancerService.getWithUserPages(lid, aid); dbLoadBalancer.setUserName(userName); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", lid); LOG.error(alertDescription, enfe); notificationService.saveAlert(aid, lid, enfe, DATABASE_FAILURE.name(), alertDescription); loadBalancerStatusHistoryService.save(aid, lid, LoadBalancerStatus.ERROR); return; } try { if (isRestAdapter()) { LOG.debug("Attempting to set error file in STM...calling setErrorFile"); reverseProxyLoadBalancerStmService.setErrorFile(dbLoadBalancer, content); LOG.debug("Successfully updated error file in zeus."); } else { LOG.debug("Attempting to set error file in ZXTM...calling setErrorFile"); reverseProxyLoadBalancerService.setErrorFile(dbLoadBalancer, content); LOG.debug("Successfully updated error file in zeus."); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String tmpMsg = String.format("Error setting Errorfile for %d_%d", aid, lid); LOG.error(tmpMsg, e); notificationService.saveAlert(aid, lid, e, AlertType.ZEUS_FAILURE.name(), msg); sendErrorToEventResource(dbLoadBalancer); } } else if (clusterId != null) { try { if (isRestAdapter()) { LOG.debug("Attempting to upload default error file in STM...calling uploadDefaultErrorFile"); reverseProxyLoadBalancerStmService.uploadDefaultErrorFile(clusterId, content); LOG.debug("Successfully uploaded default error file in zeus."); } else { LOG.debug("Attempting to upload default error file in ZXTM...calling uploadDefaultErrorFile"); reverseProxyLoadBalancerService.uploadDefaultErrorFile(clusterId, content); LOG.debug("Successfully uploaded default error file in zeus."); } } catch (Exception e) { String tmpMsg = String.format("Error uploading default error file..."); LOG.error(tmpMsg, e); notificationService.saveAlert(null, null, e, AlertType.ZEUS_FAILURE.name(), msg); } } }  @Override void doOnMessage(Message message); }
UpdateErrorFileListener extends BaseListener { @Override public void doOnMessage(Message message) throws Exception { String msg = String.format("Inside %s.doMessage", this.getClass().getName()); LOG.info(msg); MessageDataContainer data = getDataContainerFromMessage(message); String content = data.getErrorFileContents(); Integer aid = data.getAccountId(); Integer lid = data.getLoadBalancerId(); Integer clusterId = data.getClusterId(); String userName = data.getUserName(); LoadBalancer dbLoadBalancer = null; if (aid != null && lid != null) { try { LOG.debug("Grabbing loadbalancer..."); dbLoadBalancer = loadBalancerService.getWithUserPages(lid, aid); dbLoadBalancer.setUserName(userName); } catch (EntityNotFoundException enfe) { String alertDescription = String.format("Load balancer '%d' not found in database.", lid); LOG.error(alertDescription, enfe); notificationService.saveAlert(aid, lid, enfe, DATABASE_FAILURE.name(), alertDescription); loadBalancerStatusHistoryService.save(aid, lid, LoadBalancerStatus.ERROR); return; } try { if (isRestAdapter()) { LOG.debug("Attempting to set error file in STM...calling setErrorFile"); reverseProxyLoadBalancerStmService.setErrorFile(dbLoadBalancer, content); LOG.debug("Successfully updated error file in zeus."); } else { LOG.debug("Attempting to set error file in ZXTM...calling setErrorFile"); reverseProxyLoadBalancerService.setErrorFile(dbLoadBalancer, content); LOG.debug("Successfully updated error file in zeus."); } loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ACTIVE); } catch (Exception e) { loadBalancerService.setStatus(dbLoadBalancer, LoadBalancerStatus.ERROR); String tmpMsg = String.format("Error setting Errorfile for %d_%d", aid, lid); LOG.error(tmpMsg, e); notificationService.saveAlert(aid, lid, e, AlertType.ZEUS_FAILURE.name(), msg); sendErrorToEventResource(dbLoadBalancer); } } else if (clusterId != null) { try { if (isRestAdapter()) { LOG.debug("Attempting to upload default error file in STM...calling uploadDefaultErrorFile"); reverseProxyLoadBalancerStmService.uploadDefaultErrorFile(clusterId, content); LOG.debug("Successfully uploaded default error file in zeus."); } else { LOG.debug("Attempting to upload default error file in ZXTM...calling uploadDefaultErrorFile"); reverseProxyLoadBalancerService.uploadDefaultErrorFile(clusterId, content); LOG.debug("Successfully uploaded default error file in zeus."); } } catch (Exception e) { String tmpMsg = String.format("Error uploading default error file..."); LOG.error(tmpMsg, e); notificationService.saveAlert(null, null, e, AlertType.ZEUS_FAILURE.name(), msg); } } }  @Override void doOnMessage(Message message);  }