@Test public void testEmptyList() throws SQLException { List <HealthCheckVO> hcs = new ArrayList<HealthCheckVO>(); hcs.clear(); MailSenderUtil.sendMailForHealthCheckVos(hcs); }
public static void sendMailForHealthCheckVos(List<HealthCheckVO> stsChgList) throws SQLException{ logger.info("************** STARTED Mail Sending **************"); if(stsChgList.size() == 0){ logger.info("************** END Mail Sending - No Status change**************"); return; } Set<Integer> parentAndCompIdSet = getParentAndCompIdSet(stsChgList); List<SubscriptionVO> subscriptionVOs = DBQueryUtil.getAllSubscriptions(parentAndCompIdSet); PropertyUtil prop = PropertyUtil.getInstance(); String mailTemplate = prop.getValue(SurveillerConstants.MAIL_MESSAGE_TEMPLATE); String mailSubjectTemplate = prop.getValue(SurveillerConstants.MAIL_SUBJECT_TEMPLATE); if(!stsChgList.isEmpty()){ for(HealthCheckVO hVo : stsChgList){ for(SubscriptionVO sVo : subscriptionVOs){ if(isSubscriptionForComponent(hVo, sVo)){ String mailMsg = mailTemplate; String mailSub = mailSubjectTemplate; mailSub = mailSub.replace("<EnvironmentName>", hVo.getEnvironmentName()); mailSub = mailSub.replace("<RegionName>", hVo.getRegionName()); mailSub = mailSub.replace("<Status>", hVo.getStatus().getStatus().getStatusDesc()); String serviceName = hVo.getComponent().getParentComponentName() + "/" + hVo.getComponent().getComponentName(); mailSub = mailSub.replace("<ServiceName>", serviceName); mailMsg = mailMsg.replace("<parent_component_name>", hVo.getComponent().getParentComponentName()); mailMsg = mailMsg.replace("<component_name>", hVo.getComponent().getComponentName()); mailMsg = mailMsg.replace("<status>", hVo.getStatus().getStatus().getStatusDesc()); mailMsg = mailMsg.replace("<message>", hVo.getFailureStatusMessage()); mailMsg = mailMsg.replace("<EnvironmentName>", hVo.getEnvironmentName()); mailMsg = mailMsg.replace("<RegionName>", hVo.getRegionName()); logger.debug("Subject: " + mailSub + "\nMessage: " + mailMsg); switch (sVo.getSubscriptionType()) { case SurveillerConstants.SUBSCRIPTION_TYPE_EMAIL: MailSenderUtil.sendMail(mailMsg, sVo.getSubscriptionValue(), mailSub); break; case SurveillerConstants.SUBSCRIPTION_TYPE_SLACK_WEB_HOOK: try { MailSenderUtil.sendSlackAlertByWebHook(hVo, sVo.getSubscriptionValue(), mailSub); } catch (IOException e) { logger.error("Error in Senting Slack Message. URL = " + sVo.getSubscriptionValue(), e); } break; case SurveillerConstants.SUBSCRIPTION_TYPE_SLACK_CHANNEL: MailSenderUtil.sendMessageToSlackChannel(hVo, sVo.getSubscriptionValue(), mailSub); break; default: break; } } } } } logger.info("************** END OF Mail Sending **************"); }
MailSenderUtil { public static void sendMailForHealthCheckVos(List<HealthCheckVO> stsChgList) throws SQLException{ logger.info("************** STARTED Mail Sending **************"); if(stsChgList.size() == 0){ logger.info("************** END Mail Sending - No Status change**************"); return; } Set<Integer> parentAndCompIdSet = getParentAndCompIdSet(stsChgList); List<SubscriptionVO> subscriptionVOs = DBQueryUtil.getAllSubscriptions(parentAndCompIdSet); PropertyUtil prop = PropertyUtil.getInstance(); String mailTemplate = prop.getValue(SurveillerConstants.MAIL_MESSAGE_TEMPLATE); String mailSubjectTemplate = prop.getValue(SurveillerConstants.MAIL_SUBJECT_TEMPLATE); if(!stsChgList.isEmpty()){ for(HealthCheckVO hVo : stsChgList){ for(SubscriptionVO sVo : subscriptionVOs){ if(isSubscriptionForComponent(hVo, sVo)){ String mailMsg = mailTemplate; String mailSub = mailSubjectTemplate; mailSub = mailSub.replace("<EnvironmentName>", hVo.getEnvironmentName()); mailSub = mailSub.replace("<RegionName>", hVo.getRegionName()); mailSub = mailSub.replace("<Status>", hVo.getStatus().getStatus().getStatusDesc()); String serviceName = hVo.getComponent().getParentComponentName() + "/" + hVo.getComponent().getComponentName(); mailSub = mailSub.replace("<ServiceName>", serviceName); mailMsg = mailMsg.replace("<parent_component_name>", hVo.getComponent().getParentComponentName()); mailMsg = mailMsg.replace("<component_name>", hVo.getComponent().getComponentName()); mailMsg = mailMsg.replace("<status>", hVo.getStatus().getStatus().getStatusDesc()); mailMsg = mailMsg.replace("<message>", hVo.getFailureStatusMessage()); mailMsg = mailMsg.replace("<EnvironmentName>", hVo.getEnvironmentName()); mailMsg = mailMsg.replace("<RegionName>", hVo.getRegionName()); logger.debug("Subject: " + mailSub + "\nMessage: " + mailMsg); switch (sVo.getSubscriptionType()) { case SurveillerConstants.SUBSCRIPTION_TYPE_EMAIL: MailSenderUtil.sendMail(mailMsg, sVo.getSubscriptionValue(), mailSub); break; case SurveillerConstants.SUBSCRIPTION_TYPE_SLACK_WEB_HOOK: try { MailSenderUtil.sendSlackAlertByWebHook(hVo, sVo.getSubscriptionValue(), mailSub); } catch (IOException e) { logger.error("Error in Senting Slack Message. URL = " + sVo.getSubscriptionValue(), e); } break; case SurveillerConstants.SUBSCRIPTION_TYPE_SLACK_CHANNEL: MailSenderUtil.sendMessageToSlackChannel(hVo, sVo.getSubscriptionValue(), mailSub); break; default: break; } } } } } logger.info("************** END OF Mail Sending **************"); } }
MailSenderUtil { public static void sendMailForHealthCheckVos(List<HealthCheckVO> stsChgList) throws SQLException{ logger.info("************** STARTED Mail Sending **************"); if(stsChgList.size() == 0){ logger.info("************** END Mail Sending - No Status change**************"); return; } Set<Integer> parentAndCompIdSet = getParentAndCompIdSet(stsChgList); List<SubscriptionVO> subscriptionVOs = DBQueryUtil.getAllSubscriptions(parentAndCompIdSet); PropertyUtil prop = PropertyUtil.getInstance(); String mailTemplate = prop.getValue(SurveillerConstants.MAIL_MESSAGE_TEMPLATE); String mailSubjectTemplate = prop.getValue(SurveillerConstants.MAIL_SUBJECT_TEMPLATE); if(!stsChgList.isEmpty()){ for(HealthCheckVO hVo : stsChgList){ for(SubscriptionVO sVo : subscriptionVOs){ if(isSubscriptionForComponent(hVo, sVo)){ String mailMsg = mailTemplate; String mailSub = mailSubjectTemplate; mailSub = mailSub.replace("<EnvironmentName>", hVo.getEnvironmentName()); mailSub = mailSub.replace("<RegionName>", hVo.getRegionName()); mailSub = mailSub.replace("<Status>", hVo.getStatus().getStatus().getStatusDesc()); String serviceName = hVo.getComponent().getParentComponentName() + "/" + hVo.getComponent().getComponentName(); mailSub = mailSub.replace("<ServiceName>", serviceName); mailMsg = mailMsg.replace("<parent_component_name>", hVo.getComponent().getParentComponentName()); mailMsg = mailMsg.replace("<component_name>", hVo.getComponent().getComponentName()); mailMsg = mailMsg.replace("<status>", hVo.getStatus().getStatus().getStatusDesc()); mailMsg = mailMsg.replace("<message>", hVo.getFailureStatusMessage()); mailMsg = mailMsg.replace("<EnvironmentName>", hVo.getEnvironmentName()); mailMsg = mailMsg.replace("<RegionName>", hVo.getRegionName()); logger.debug("Subject: " + mailSub + "\nMessage: " + mailMsg); switch (sVo.getSubscriptionType()) { case SurveillerConstants.SUBSCRIPTION_TYPE_EMAIL: MailSenderUtil.sendMail(mailMsg, sVo.getSubscriptionValue(), mailSub); break; case SurveillerConstants.SUBSCRIPTION_TYPE_SLACK_WEB_HOOK: try { MailSenderUtil.sendSlackAlertByWebHook(hVo, sVo.getSubscriptionValue(), mailSub); } catch (IOException e) { logger.error("Error in Senting Slack Message. URL = " + sVo.getSubscriptionValue(), e); } break; case SurveillerConstants.SUBSCRIPTION_TYPE_SLACK_CHANNEL: MailSenderUtil.sendMessageToSlackChannel(hVo, sVo.getSubscriptionValue(), mailSub); break; default: break; } } } } } logger.info("************** END OF Mail Sending **************"); } private  MailSenderUtil(); }
MailSenderUtil { public static void sendMailForHealthCheckVos(List<HealthCheckVO> stsChgList) throws SQLException{ logger.info("************** STARTED Mail Sending **************"); if(stsChgList.size() == 0){ logger.info("************** END Mail Sending - No Status change**************"); return; } Set<Integer> parentAndCompIdSet = getParentAndCompIdSet(stsChgList); List<SubscriptionVO> subscriptionVOs = DBQueryUtil.getAllSubscriptions(parentAndCompIdSet); PropertyUtil prop = PropertyUtil.getInstance(); String mailTemplate = prop.getValue(SurveillerConstants.MAIL_MESSAGE_TEMPLATE); String mailSubjectTemplate = prop.getValue(SurveillerConstants.MAIL_SUBJECT_TEMPLATE); if(!stsChgList.isEmpty()){ for(HealthCheckVO hVo : stsChgList){ for(SubscriptionVO sVo : subscriptionVOs){ if(isSubscriptionForComponent(hVo, sVo)){ String mailMsg = mailTemplate; String mailSub = mailSubjectTemplate; mailSub = mailSub.replace("<EnvironmentName>", hVo.getEnvironmentName()); mailSub = mailSub.replace("<RegionName>", hVo.getRegionName()); mailSub = mailSub.replace("<Status>", hVo.getStatus().getStatus().getStatusDesc()); String serviceName = hVo.getComponent().getParentComponentName() + "/" + hVo.getComponent().getComponentName(); mailSub = mailSub.replace("<ServiceName>", serviceName); mailMsg = mailMsg.replace("<parent_component_name>", hVo.getComponent().getParentComponentName()); mailMsg = mailMsg.replace("<component_name>", hVo.getComponent().getComponentName()); mailMsg = mailMsg.replace("<status>", hVo.getStatus().getStatus().getStatusDesc()); mailMsg = mailMsg.replace("<message>", hVo.getFailureStatusMessage()); mailMsg = mailMsg.replace("<EnvironmentName>", hVo.getEnvironmentName()); mailMsg = mailMsg.replace("<RegionName>", hVo.getRegionName()); logger.debug("Subject: " + mailSub + "\nMessage: " + mailMsg); switch (sVo.getSubscriptionType()) { case SurveillerConstants.SUBSCRIPTION_TYPE_EMAIL: MailSenderUtil.sendMail(mailMsg, sVo.getSubscriptionValue(), mailSub); break; case SurveillerConstants.SUBSCRIPTION_TYPE_SLACK_WEB_HOOK: try { MailSenderUtil.sendSlackAlertByWebHook(hVo, sVo.getSubscriptionValue(), mailSub); } catch (IOException e) { logger.error("Error in Senting Slack Message. URL = " + sVo.getSubscriptionValue(), e); } break; case SurveillerConstants.SUBSCRIPTION_TYPE_SLACK_CHANNEL: MailSenderUtil.sendMessageToSlackChannel(hVo, sVo.getSubscriptionValue(), mailSub); break; default: break; } } } } } logger.info("************** END OF Mail Sending **************"); } private  MailSenderUtil(); static void sendMailForHealthCheckVos(List<HealthCheckVO> stsChgList); static void sendMessageToSlackChannel(HealthCheckVO hVo, String slackChannelName, String subject); static void sendMail(String messageText, String toMail, String subject); }
MailSenderUtil { public static void sendMailForHealthCheckVos(List<HealthCheckVO> stsChgList) throws SQLException{ logger.info("************** STARTED Mail Sending **************"); if(stsChgList.size() == 0){ logger.info("************** END Mail Sending - No Status change**************"); return; } Set<Integer> parentAndCompIdSet = getParentAndCompIdSet(stsChgList); List<SubscriptionVO> subscriptionVOs = DBQueryUtil.getAllSubscriptions(parentAndCompIdSet); PropertyUtil prop = PropertyUtil.getInstance(); String mailTemplate = prop.getValue(SurveillerConstants.MAIL_MESSAGE_TEMPLATE); String mailSubjectTemplate = prop.getValue(SurveillerConstants.MAIL_SUBJECT_TEMPLATE); if(!stsChgList.isEmpty()){ for(HealthCheckVO hVo : stsChgList){ for(SubscriptionVO sVo : subscriptionVOs){ if(isSubscriptionForComponent(hVo, sVo)){ String mailMsg = mailTemplate; String mailSub = mailSubjectTemplate; mailSub = mailSub.replace("<EnvironmentName>", hVo.getEnvironmentName()); mailSub = mailSub.replace("<RegionName>", hVo.getRegionName()); mailSub = mailSub.replace("<Status>", hVo.getStatus().getStatus().getStatusDesc()); String serviceName = hVo.getComponent().getParentComponentName() + "/" + hVo.getComponent().getComponentName(); mailSub = mailSub.replace("<ServiceName>", serviceName); mailMsg = mailMsg.replace("<parent_component_name>", hVo.getComponent().getParentComponentName()); mailMsg = mailMsg.replace("<component_name>", hVo.getComponent().getComponentName()); mailMsg = mailMsg.replace("<status>", hVo.getStatus().getStatus().getStatusDesc()); mailMsg = mailMsg.replace("<message>", hVo.getFailureStatusMessage()); mailMsg = mailMsg.replace("<EnvironmentName>", hVo.getEnvironmentName()); mailMsg = mailMsg.replace("<RegionName>", hVo.getRegionName()); logger.debug("Subject: " + mailSub + "\nMessage: " + mailMsg); switch (sVo.getSubscriptionType()) { case SurveillerConstants.SUBSCRIPTION_TYPE_EMAIL: MailSenderUtil.sendMail(mailMsg, sVo.getSubscriptionValue(), mailSub); break; case SurveillerConstants.SUBSCRIPTION_TYPE_SLACK_WEB_HOOK: try { MailSenderUtil.sendSlackAlertByWebHook(hVo, sVo.getSubscriptionValue(), mailSub); } catch (IOException e) { logger.error("Error in Senting Slack Message. URL = " + sVo.getSubscriptionValue(), e); } break; case SurveillerConstants.SUBSCRIPTION_TYPE_SLACK_CHANNEL: MailSenderUtil.sendMessageToSlackChannel(hVo, sVo.getSubscriptionValue(), mailSub); break; default: break; } } } } } logger.info("************** END OF Mail Sending **************"); } private  MailSenderUtil(); static void sendMailForHealthCheckVos(List<HealthCheckVO> stsChgList); static void sendMessageToSlackChannel(HealthCheckVO hVo, String slackChannelName, String subject); static void sendMail(String messageText, String toMail, String subject);  }