diff --git a/web/src/main/java/com/navercorp/pinpoint/web/alarm/AlarmReader.java b/web/src/main/java/com/navercorp/pinpoint/web/alarm/AlarmReader.java index 071a4e769..7dd6a8b3d 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/alarm/AlarmReader.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/alarm/AlarmReader.java @@ -1,113 +1,114 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.alarm; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Queue; - -import org.springframework.batch.core.ExitStatus; -import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.StepExecutionListener; -import org.springframework.batch.item.ItemReader; -import org.springframework.beans.factory.annotation.Autowired; - -import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; -import com.navercorp.pinpoint.web.alarm.checker.AlarmChecker; -import com.navercorp.pinpoint.web.alarm.collector.DataCollector; -import com.navercorp.pinpoint.web.alarm.vo.Rule; -import com.navercorp.pinpoint.web.dao.AlarmResourceDao; -import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; -import com.navercorp.pinpoint.web.vo.Application; - -/** - * @author minwoo.jung - */ -public class AlarmReader implements ItemReader, StepExecutionListener { - - @Autowired - private DataCollectorFactory dataCollectorFactory; - - @Autowired - private ApplicationIndexDao applicationIndexDao; - - @Autowired - private AlarmResourceDao alarmResourceDao; - - private final Queue checkers = new LinkedList(); - - public AlarmReader() { - } - - protected AlarmReader(DataCollectorFactory dataCollectorFactory, ApplicationIndexDao applicationIndexDao, AlarmResourceDao alarmResourceDao) { - this.dataCollectorFactory = dataCollectorFactory; - this.applicationIndexDao = applicationIndexDao; - this.alarmResourceDao = alarmResourceDao; - } - - public AlarmChecker read() { - return checkers.poll(); - } - - @Override - public void beforeStep(StepExecution stepExecution) { - List applicationList = applicationIndexDao.selectAllApplicationNames(); - int appSize = applicationList.size(); - int partitionNumber = (Integer) stepExecution.getExecutionContext().get(AlarmPartitioner.PARTITION_NUMBER); - int from = (partitionNumber - 1) * AlarmPartitioner.APP_COUNT; - int to = partitionNumber * AlarmPartitioner.APP_COUNT; - - if (appSize < from) { - return; - } - if (appSize < to) { - to = appSize; - } - - - for(int i = from; i < to; i++) { - addChecker(applicationList.get(i)); - } - } - - private void addChecker(Application application) { - List rules = alarmResourceDao.selectAppRule(application.getName()); - long timeSlotEndTime = System.currentTimeMillis(); - Map collectorMap = new HashMap(); - - for (Rule rule : rules) { - CheckerCategory checkerCategory = CheckerCategory.getValue(rule.getCheckerName()); - DataCollector collector = collectorMap.get(checkerCategory.getDataCollectorCategory()); - - if(collector == null) { - collector = dataCollectorFactory.createDataCollector(checkerCategory, application, timeSlotEndTime); - collectorMap.put(collector.getDataCollectorCategory(), collector); - } - - AlarmChecker checker = checkerCategory.createChecker(collector, rule); - checkers.add(checker); - } - - } - - @Override - public ExitStatus afterStep(StepExecution stepExecution) { - return null; - } -} +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.alarm; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; + +import org.springframework.batch.core.ExitStatus; +import org.springframework.batch.core.StepExecution; +import org.springframework.batch.core.StepExecutionListener; +import org.springframework.batch.item.ItemReader; +import org.springframework.beans.factory.annotation.Autowired; + +import com.navercorp.pinpoint.web.alarm.DataCollectorFactory.DataCollectorCategory; +import com.navercorp.pinpoint.web.alarm.checker.AlarmChecker; +import com.navercorp.pinpoint.web.alarm.collector.DataCollector; +import com.navercorp.pinpoint.web.alarm.vo.Rule; +import com.navercorp.pinpoint.web.dao.AlarmDao; +import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; +import com.navercorp.pinpoint.web.service.AlarmService; +import com.navercorp.pinpoint.web.vo.Application; + +/** + * @author minwoo.jung + */ +public class AlarmReader implements ItemReader, StepExecutionListener { + + @Autowired + private DataCollectorFactory dataCollectorFactory; + + @Autowired + private ApplicationIndexDao applicationIndexDao; + + @Autowired + private AlarmService alarmService; + + private final Queue checkers = new LinkedList(); + + public AlarmReader() { + } + + protected AlarmReader(DataCollectorFactory dataCollectorFactory, ApplicationIndexDao applicationIndexDao, AlarmService alarmService) { + this.dataCollectorFactory = dataCollectorFactory; + this.applicationIndexDao = applicationIndexDao; + this.alarmService = alarmService; + } + + public AlarmChecker read() { + return checkers.poll(); + } + + @Override + public void beforeStep(StepExecution stepExecution) { + List applicationList = applicationIndexDao.selectAllApplicationNames(); + int appSize = applicationList.size(); + int partitionNumber = (Integer) stepExecution.getExecutionContext().get(AlarmPartitioner.PARTITION_NUMBER); + int from = (partitionNumber - 1) * AlarmPartitioner.APP_COUNT; + int to = partitionNumber * AlarmPartitioner.APP_COUNT; + + if (appSize < from) { + return; + } + if (appSize < to) { + to = appSize; + } + + + for(int i = from; i < to; i++) { + addChecker(applicationList.get(i)); + } + } + + private void addChecker(Application application) { + List rules = alarmService.selectRuleByApplicationId(application.getName()); + long timeSlotEndTime = System.currentTimeMillis(); + Map collectorMap = new HashMap(); + + for (Rule rule : rules) { + CheckerCategory checkerCategory = CheckerCategory.getValue(rule.getCheckerName()); + DataCollector collector = collectorMap.get(checkerCategory.getDataCollectorCategory()); + + if(collector == null) { + collector = dataCollectorFactory.createDataCollector(checkerCategory, application, timeSlotEndTime); + collectorMap.put(collector.getDataCollectorCategory(), collector); + } + + AlarmChecker checker = checkerCategory.createChecker(collector, rule); + checkers.add(checker); + } + + } + + @Override + public ExitStatus afterStep(StepExecution stepExecution) { + return null; + } +} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/AlarmRuleController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/AlarmRuleController.java deleted file mode 100644 index bdffae5a6..000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/controller/AlarmRuleController.java +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.controller; - -import java.util.LinkedList; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -import com.navercorp.pinpoint.web.alarm.CheckerCategory; -import com.navercorp.pinpoint.web.alarm.vo.AlarmEmp; -import com.navercorp.pinpoint.web.alarm.vo.Rule; -import com.navercorp.pinpoint.web.dao.mysql.MySqlAlarmResourceDao; -import com.navercorp.pinpoint.web.service.CommonService; -import com.navercorp.pinpoint.web.vo.Application; - -/** - * @author minwoo.jung - */ -@Controller -public class AlarmRuleController { - - @Autowired - private MySqlAlarmResourceDao dao; - - @Autowired - private CommonService commonService; - - @RequestMapping(value = "/alarmGroupList") - public List alarmGroupList() { - return dao.selectEmpGroupName(); - } - - @RequestMapping(value = "/alarmGroup/getMember") - public ModelAndView getMember(String groupName) { - ModelAndView mv = new ModelAndView(); - - if (groupName != null) { - List members = dao.selectEmpGroupMember(groupName); - mv.addObject("groupMember", members); - } - - List groupNameList = alarmGroupList(); - mv.addObject("groupNameList", groupNameList); - - mv.setViewName("alarm/empGroup"); - - return mv; - } - - public static class EmpGroup { - private List emps; - - public List getEmps() { - return emps; - } - - public void setEmps(List emps) { - this.emps = emps; - } - } - - private List removeEmptyEmp(List emps) { - List newEmps = new LinkedList(); - - for(AlarmEmp emp : emps) { - if (emp.getGroupName() != null && emp.getEmpId() != null) { - if (!emp.getGroupName().isEmpty() && !emp.getEmpId().isEmpty()) { - newEmps.add(emp); - } - } - } - - return newEmps; - } - - @RequestMapping(value = "/alarmGroup/insertMember") - public String insertMember(EmpGroup empGroup) { - List emps = removeEmptyEmp(empGroup.getEmps()); - dao.insertEmpGroupMember(emps); - return "redirect:/alarmGroup/getMember.pinpoint?groupName=" + emps.get(0).getGroupName(); - } - - @RequestMapping(value = "/alarmGroup/deleteMember") - public String deleteMember(EmpGroup empGroup) { - dao.deleteEmpGroupMember(empGroup.getEmps().get(0).getGroupName()); - return "redirect:/alarmGroup/getMember.pinpoint?groupName=" + empGroup.getEmps().get(0).getGroupName(); - } - - @RequestMapping(value = "/alarmGroup/updateMember") - public String updateMember(EmpGroup empGroup) { - List emps = removeEmptyEmp(empGroup.getEmps()); - dao.deleteEmpGroupMember(emps.get(0).getGroupName()); - dao.insertEmpGroupMember(emps); - return "redirect:/alarmGroup/getMember.pinpoint?groupName=" + emps.get(0).getGroupName(); - } - - @RequestMapping(value = "/alarmRule/ruleNameList") - public List getAlarmRuleNames() { - return CheckerCategory.getNames(); - } - - @RequestMapping(value = "/alarmRule/getRule") - public ModelAndView getRule(String applicationName) { - ModelAndView mv = new ModelAndView(); - - if (applicationName != null) { - List ruleList = dao.selectAppRule(applicationName); - mv.addObject("ruleList", ruleList); - } - - List applicationList = commonService.selectAllApplicationNames(); - List applicationNameList = new LinkedList(); - - for(Application application : applicationList) { - applicationNameList.add(application.getName()); - } - - mv.addObject("applicationNameList", applicationNameList); - mv.addObject("empGroupNameList", alarmGroupList()); - mv.addObject("checkerNameList", getAlarmRuleNames()); - mv.setViewName("alarm/rule"); - return mv; - } - - public static class RuleGroup { - private List ruleList; - - public List getRuleList() { - return ruleList; - } - - public void setRuleList(List ruleList) { - this.ruleList = ruleList; - } - } - - private List removeEmptyRule(List ruleList) { - List newRuleList = new LinkedList(); - - for(Rule rule : ruleList) { - if (rule.getApplicationId() != null && !rule.getApplicationId().isEmpty()) { - if (rule.getThreshold() >= 0) { - newRuleList.add(rule); - } - } - } - - return newRuleList; - } - - @RequestMapping(value = "/alarmRule/insertRule") - public String insertRule(RuleGroup ruleGroup) { - List ruleList = removeEmptyRule(ruleGroup.getRuleList()); - dao.insertAppRule(ruleList); - return "redirect:/alarmRule/getRule.pinpoint?applicationName=" + ruleList.get(0).getApplicationId(); - } - - @RequestMapping(value = "/alarmRule/deleteRule") - public String deleteRule(RuleGroup ruleGroup) { - dao.deleteAppRule(ruleGroup.getRuleList().get(0).getApplicationId()); - return "redirect:/alarmRule/getRule.pinpoint?applicationName=" + ruleGroup.getRuleList().get(0).getApplicationId(); - } - - @RequestMapping(value = "/alarmRule/updateRule") - public String updateRule(RuleGroup ruleGroup) { - List ruleList = removeEmptyRule(ruleGroup.getRuleList()); - dao.deleteAppRule(ruleList.get(0).getApplicationId()); - dao.insertAppRule(ruleList); - return "redirect:/alarmRule/getRule.pinpoint?applicationName=" + ruleGroup.getRuleList().get(0).getApplicationId(); - } - -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/AlarmDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/AlarmDao.java index 86332d66c..4e466c084 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/AlarmDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/AlarmDao.java @@ -31,7 +31,8 @@ public interface AlarmDao { void deleteRuleByUserGroupId(String userGroupId); List selectRuleByUserGroupId(String userGroupId); + + List selectRuleByApplicationId(String applicationId); void updateRule(Rule rule); - } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/AlarmResourceDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/AlarmResourceDao.java deleted file mode 100644 index 23d8bbaa1..000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/AlarmResourceDao.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.dao; - -import java.util.List; - -import com.navercorp.pinpoint.web.alarm.vo.AlarmEmp; -import com.navercorp.pinpoint.web.alarm.vo.Rule; - - -public interface AlarmResourceDao { - - List selectAppRule(String applicationName); - - void insertAppRule(List rules); - - void deleteAppRule(String applicationName); - - List selectEmpGroupPhoneNumber(String empGroup); - - List selectEmpGroupEmail(String empGroup); - - List selectEmpGroupName(); - - List selectEmpGroupMember(String alarmGroup); - - void insertEmpGroupMember(List emps); - - void deleteEmpGroupMember(String groupName); -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/UserGroupDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/UserGroupDao.java index 827021740..c8ff0c946 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/UserGroupDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/UserGroupDao.java @@ -40,4 +40,8 @@ public interface UserGroupDao { void updateMember(UserGroupMember userGroupMember); + List selectPhoneNumberOfMember(String userGroupId); + + List selectEmailOfMember(String userGroupId); + } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MySqlAlarmResourceDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MySqlAlarmResourceDao.java deleted file mode 100644 index b8bece44b..000000000 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MySqlAlarmResourceDao.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.dao.mysql; - -import java.util.List; - -import org.mybatis.spring.SqlSessionTemplate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Repository; - -import com.navercorp.pinpoint.web.alarm.vo.AlarmEmp; -import com.navercorp.pinpoint.web.alarm.vo.Rule; -import com.navercorp.pinpoint.web.dao.AlarmResourceDao; - -@Repository -public class MySqlAlarmResourceDao implements AlarmResourceDao { - - private static final String NAMESPACE = AlarmResourceDao.class.getPackage().getName() + "." + AlarmResourceDao.class.getSimpleName() + "."; - - @Autowired - @Qualifier("sqlSessionTemplate") - private SqlSessionTemplate sqlSessionTemplate; - - public SqlSessionTemplate getSqlSessionTemplate() { - return sqlSessionTemplate; - } - - public List selectAppRule(String applicationName) { - return getSqlSessionTemplate().selectList(NAMESPACE + "selectRules", applicationName); - } - - public void insertAppRule(List rules) { - getSqlSessionTemplate().selectList(NAMESPACE + "insertAppRule", rules); - } - - public void deleteAppRule(String applicationName) { - getSqlSessionTemplate().selectList(NAMESPACE + "deleteAppRule", applicationName); - } - - public List selectEmpGroupPhoneNumber(String empGroup) { - return getSqlSessionTemplate().selectList(NAMESPACE + "selectEmpGroupPhoneNumber", empGroup); - } - - public List selectEmpGroupEmail(String empGroup) { - return getSqlSessionTemplate().selectList(NAMESPACE + "selectEmpGroupEmail", empGroup); - } - - public List selectEmpGroupName() { - return getSqlSessionTemplate().selectList(NAMESPACE + "selectAlarmGroupList"); - } - - public List selectEmpGroupMember(String alarmGroup) { - return getSqlSessionTemplate().selectList(NAMESPACE + "selectAlarmGroupMember", alarmGroup); - } - - public void insertEmpGroupMember(List emps) { - getSqlSessionTemplate().insert(NAMESPACE + "insertAlarmGroupMember", emps); - } - - public void deleteEmpGroupMember(String groupName) { - getSqlSessionTemplate().insert(NAMESPACE + "deleteAlarmGroupMember", groupName); - } -} diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlAlarmDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlAlarmDao.java index 98284c0f5..d20ea7f94 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlAlarmDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlAlarmDao.java @@ -57,10 +57,14 @@ public class MysqlAlarmDao implements AlarmDao { public List selectRuleByUserGroupId(String userGroupId) { return sqlSessionTemplate.selectList(NAMESPACE + "selectRuleByUserGroupId", userGroupId); } + + @Override + public List selectRuleByApplicationId(String applicationId) { + return sqlSessionTemplate.selectList(NAMESPACE + "selectRuleByApplicationId", applicationId); + } @Override public void updateRule(Rule rule) { sqlSessionTemplate.update(NAMESPACE + "updateRule", rule); } - } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlUserGroupDao.java b/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlUserGroupDao.java index dca22f572..f96ce5e3e 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlUserGroupDao.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/dao/mysql/MysqlUserGroupDao.java @@ -81,5 +81,15 @@ public class MysqlUserGroupDao implements UserGroupDao { public void updateMember(UserGroupMember userGroupMember) { sqlSessionTemplate.delete(NAMESPACE + "updateMember", userGroupMember); } + + @Override + public List selectPhoneNumberOfMember(String userGroupId) { + return sqlSessionTemplate.selectList(NAMESPACE + "selectPhoneNumberOfMember", userGroupId); + } + + @Override + public List selectEmailOfMember(String userGroupId) { + return sqlSessionTemplate.selectList(NAMESPACE + "selectEmailOfMember", userGroupId); + } } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AlarmService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AlarmService.java index 887ec426b..61d8edc56 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AlarmService.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AlarmService.java @@ -30,6 +30,9 @@ public interface AlarmService { List selectRuleByUserGroupId(String userGroupId); + List selectRuleByApplicationId(String applicationId); + void updateRule(Rule rule); + } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AlarmServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AlarmServiceImpl.java index bff6ebfba..473048aaa 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AlarmServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AlarmServiceImpl.java @@ -48,9 +48,15 @@ public class AlarmServiceImpl implements AlarmService { return alarmDao.selectRuleByUserGroupId(userGroupId); } + @Override + public List selectRuleByApplicationId(String applicationId) { + return alarmDao.selectRuleByApplicationId(applicationId); + } + @Override public void updateRule(Rule rule) { alarmDao.updateRule(rule); } + } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupService.java index 1f73517f6..86ae1cf46 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupService.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupService.java @@ -40,4 +40,8 @@ public interface UserGroupService { void updateMember(UserGroupMember userGroupMember); + List selectPhoneNumberOfMember(String userGroupId); + + List selectEmailOfMember(String userGroupId); + } diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupServiceImpl.java index 2ca7ba43e..edaf06488 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/UserGroupServiceImpl.java @@ -73,6 +73,18 @@ public class UserGroupServiceImpl implements UserGroupService { public void updateMember(UserGroupMember userGroupMember) { userGroupDao.updateMember(userGroupMember); } + + @Override + public List selectPhoneNumberOfMember(String userGroupId) { + return userGroupDao.selectPhoneNumberOfMember(userGroupId); + } + + @Override + public List selectEmailOfMember(String userGroupId) { + return userGroupDao.selectEmailOfMember(userGroupId); + } + + } diff --git a/web/src/main/resources/mapper/Alarm2Mapper.xml b/web/src/main/resources/mapper/Alarm2Mapper.xml index 0a054ac0d..64a77013b 100644 --- a/web/src/main/resources/mapper/Alarm2Mapper.xml +++ b/web/src/main/resources/mapper/Alarm2Mapper.xml @@ -2,25 +2,11 @@ - - - - INSERT INTO alarm_rule(application_id, checker_name, threshold, user_group_id, sms_send, email_send, notes) - VALUES - - (#{rule.applicationId}, #{rule.checkerName}, #{rule.threshold}, #{rule.userGroupId}, #{rule.smsSend}, #{rule.emailSend}, #{rule.notes}) - - - - - DELETE - FROM alarm_rule - WHERE application_id = #{applicationId} - + + + + + + + + + + + + + - + + + + + - - - INSERT INTO alarm_group(group_name, emp_id) - VALUES - - (#{alarmEmp.groupName}, #{alarmEmp.empId}) - - + + + + - - DELETE - FROM alarm_group - WHERE group_name = #{group_name} - + + + + + + + + + + + + + + + + + + + diff --git a/web/src/main/resources/mapper/AlarmMapper.xml b/web/src/main/resources/mapper/AlarmMapper.xml index ea4bbee65..3d31e3e12 100644 --- a/web/src/main/resources/mapper/AlarmMapper.xml +++ b/web/src/main/resources/mapper/AlarmMapper.xml @@ -26,6 +26,12 @@ FROM alarm_rule WHERE user_group_id = #{userGroupId} + + UPDATE alarm_rule diff --git a/web/src/main/resources/mapper/UserGroupMapper.xml b/web/src/main/resources/mapper/UserGroupMapper.xml index b44079e89..4000f9c9e 100644 --- a/web/src/main/resources/mapper/UserGroupMapper.xml +++ b/web/src/main/resources/mapper/UserGroupMapper.xml @@ -48,4 +48,25 @@ WHERE number = #{number} + + + + + diff --git a/web/src/test/java/com/navercorp/pinpoint/web/alarm/ReaderTest.java b/web/src/test/java/com/navercorp/pinpoint/web/alarm/ReaderTest.java index d464fcffe..ca30735c7 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/alarm/ReaderTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/alarm/ReaderTest.java @@ -1,153 +1,149 @@ -/* - * Copyright 2014 NAVER Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.navercorp.pinpoint.web.alarm; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.springframework.batch.core.StepExecution; -import org.springframework.batch.item.ExecutionContext; - -import com.navercorp.pinpoint.common.trace.ServiceType; -import com.navercorp.pinpoint.web.alarm.AlarmPartitioner; -import com.navercorp.pinpoint.web.alarm.AlarmReader; -import com.navercorp.pinpoint.web.alarm.CheckerCategory; -import com.navercorp.pinpoint.web.alarm.DataCollectorFactory; -import com.navercorp.pinpoint.web.alarm.collector.DataCollector; -import com.navercorp.pinpoint.web.alarm.collector.ResponseTimeDataCollector; -import com.navercorp.pinpoint.web.alarm.vo.Rule; -import com.navercorp.pinpoint.web.dao.AlarmResourceDao; -import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; -import com.navercorp.pinpoint.web.dao.mysql.MySqlAlarmResourceDao; -import com.navercorp.pinpoint.web.vo.Application; - -public class ReaderTest { - - private static ApplicationIndexDao applicationIndexDao; - private static AlarmResourceDao alarmResourceDao; - private static DataCollectorFactory dataCollectorFactory; - private static final String APP_NAME = "app"; - - @Test - public void readTest() { - StepExecution stepExecution = new StepExecution("alarmStep", null); - ExecutionContext executionContext = new ExecutionContext(); - executionContext.put(AlarmPartitioner.PARTITION_NUMBER, 1); - stepExecution.setExecutionContext(executionContext); - - AlarmReader reader = new AlarmReader(dataCollectorFactory, applicationIndexDao, alarmResourceDao); - - reader.beforeStep(stepExecution); - - for(int i = 0; i < 5; i++) { - assertNotNull(reader.read()); - } - - assertNull(reader.read()); - } - - @Test - public void readTest2() { - StepExecution stepExecution = new StepExecution("alarmStep", null); - ExecutionContext executionContext = new ExecutionContext(); - executionContext.put(AlarmPartitioner.PARTITION_NUMBER, 2); - stepExecution.setExecutionContext(executionContext); - - AlarmReader reader = new AlarmReader(dataCollectorFactory, applicationIndexDao, alarmResourceDao); - - reader.beforeStep(stepExecution); - - for(int i = 0; i < 2; i++) { - assertNotNull(reader.read()); - } - - assertNull(reader.read()); - } - - @Test - public void readTest3() { - StepExecution stepExecution = new StepExecution("alarmStep", null); - ExecutionContext executionContext = new ExecutionContext(); - executionContext.put(AlarmPartitioner.PARTITION_NUMBER, 2); - stepExecution.setExecutionContext(executionContext); - - MySqlAlarmResourceDao alarmResourceDao = new MySqlAlarmResourceDao() { - @Override - public java.util.List selectAppRule(String applicationName) { - return new LinkedList(); - } - }; - - AlarmReader reader = new AlarmReader(dataCollectorFactory, applicationIndexDao, alarmResourceDao); - reader.beforeStep(stepExecution); - assertNull(reader.read()); - } - - @BeforeClass - public static void beforeClass() { - applicationIndexDao = new ApplicationIndexDao() { - - @Override - public List selectAllApplicationNames() { - List apps = new LinkedList(); - - for(int i = 0; i < 7; i++) { - apps.add(new Application(APP_NAME + i, ServiceType.STAND_ALONE)); - } - return apps; - } - - @Override public List selectAgentIds(String applicationName) {return null;} - @Override public void deleteApplicationName(String applicationName) { } - @Override public void deleteAgentId(String applicationName, String agentId) {} - - }; - - alarmResourceDao = new MySqlAlarmResourceDao() { - private Map ruleMap ; - - { - ruleMap = new HashMap(); - - for(int i = 0; i <=6; i++) { - ruleMap.put(APP_NAME + i, new Rule(APP_NAME + i, CheckerCategory.SLOW_COUNT.getName(), 76, "testGroup", false, false, "")); - } - } - - @Override - public java.util.List selectAppRule(String applicationName) { - List rules = new LinkedList(); - rules.add(ruleMap.get(applicationName)); - return rules; - } - }; - - dataCollectorFactory = new DataCollectorFactory() { - @Override - public DataCollector createDataCollector(CheckerCategory checker, Application application, long timeSlotEndTime) { - return new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, null, null, 0, 0); - } - }; - } -} +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.alarm; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.springframework.batch.core.StepExecution; +import org.springframework.batch.item.ExecutionContext; + +import com.navercorp.pinpoint.common.trace.ServiceType; +import com.navercorp.pinpoint.web.alarm.collector.DataCollector; +import com.navercorp.pinpoint.web.alarm.collector.ResponseTimeDataCollector; +import com.navercorp.pinpoint.web.alarm.vo.Rule; +import com.navercorp.pinpoint.web.dao.ApplicationIndexDao; +import com.navercorp.pinpoint.web.service.AlarmService; +import com.navercorp.pinpoint.web.service.AlarmServiceImpl; +import com.navercorp.pinpoint.web.vo.Application; + +public class ReaderTest { + + private static ApplicationIndexDao applicationIndexDao; + private static AlarmService alarmService; + private static DataCollectorFactory dataCollectorFactory; + private static final String APP_NAME = "app"; + + @Test + public void readTest() { + StepExecution stepExecution = new StepExecution("alarmStep", null); + ExecutionContext executionContext = new ExecutionContext(); + executionContext.put(AlarmPartitioner.PARTITION_NUMBER, 1); + stepExecution.setExecutionContext(executionContext); + + AlarmReader reader = new AlarmReader(dataCollectorFactory, applicationIndexDao, alarmService); + + reader.beforeStep(stepExecution); + + for(int i = 0; i < 5; i++) { + assertNotNull(reader.read()); + } + + assertNull(reader.read()); + } + + @Test + public void readTest2() { + StepExecution stepExecution = new StepExecution("alarmStep", null); + ExecutionContext executionContext = new ExecutionContext(); + executionContext.put(AlarmPartitioner.PARTITION_NUMBER, 2); + stepExecution.setExecutionContext(executionContext); + + AlarmReader reader = new AlarmReader(dataCollectorFactory, applicationIndexDao, alarmService); + + reader.beforeStep(stepExecution); + + for(int i = 0; i < 2; i++) { + assertNotNull(reader.read()); + } + + assertNull(reader.read()); + } + + @Test + public void readTest3() { + StepExecution stepExecution = new StepExecution("alarmStep", null); + ExecutionContext executionContext = new ExecutionContext(); + executionContext.put(AlarmPartitioner.PARTITION_NUMBER, 2); + stepExecution.setExecutionContext(executionContext); + + AlarmServiceImpl alarmService = new AlarmServiceImpl() { + @Override + public java.util.List selectRuleByApplicationId(String applicationId) { + return new LinkedList(); + }; + }; + + AlarmReader reader = new AlarmReader(dataCollectorFactory, applicationIndexDao, alarmService); + reader.beforeStep(stepExecution); + assertNull(reader.read()); + } + + @BeforeClass + public static void beforeClass() { + applicationIndexDao = new ApplicationIndexDao() { + + @Override + public List selectAllApplicationNames() { + List apps = new LinkedList(); + + for(int i = 0; i < 7; i++) { + apps.add(new Application(APP_NAME + i, ServiceType.STAND_ALONE)); + } + return apps; + } + + @Override public List selectAgentIds(String applicationName) {return null;} + @Override public void deleteApplicationName(String applicationName) { } + @Override public void deleteAgentId(String applicationName, String agentId) {} + + }; + + alarmService = new AlarmServiceImpl() { + private Map ruleMap ; + + { + ruleMap = new HashMap(); + + for(int i = 0; i <=6; i++) { + ruleMap.put(APP_NAME + i, new Rule(APP_NAME + i, CheckerCategory.SLOW_COUNT.getName(), 76, "testGroup", false, false, "")); + } + } + + @Override + public List selectRuleByApplicationId(String applicationId) { + List rules = new LinkedList(); + rules.add(ruleMap.get(applicationId)); + return rules; + } + }; + + dataCollectorFactory = new DataCollectorFactory() { + @Override + public DataCollector createDataCollector(CheckerCategory checker, Application application, long timeSlotEndTime) { + return new ResponseTimeDataCollector(DataCollectorCategory.RESPONSE_TIME, null, null, 0, 0); + } + }; + } +}