Java tutorial
/* Copyright (C) 2006 NTT DATA Corporation This program is free software; you can redistribute it and/or Modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ package com.clustercontrol.monitor.run.factory; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.clustercontrol.bean.HinemosModuleConstant; import com.clustercontrol.bean.PriorityConstant; import com.clustercontrol.fault.HinemosUnknown; import com.clustercontrol.fault.InvalidRole; import com.clustercontrol.fault.MonitorNotFound; import com.clustercontrol.http.model.Page; import com.clustercontrol.http.model.Pattern; import com.clustercontrol.http.model.Variable; import com.clustercontrol.monitor.bean.MonitorFilterInfo; import com.clustercontrol.monitor.run.bean.MonitorTypeConstant; import com.clustercontrol.monitor.run.model.MonitorInfo; import com.clustercontrol.monitor.run.model.MonitorNumericValueInfo; import com.clustercontrol.monitor.run.model.MonitorStringValueInfo; import com.clustercontrol.monitor.run.model.MonitorTruthValueInfo; import com.clustercontrol.monitor.run.util.QueryUtil; import com.clustercontrol.nodemap.bean.ReservedFacilityIdConstant; import com.clustercontrol.notify.session.NotifyControllerBean; import com.clustercontrol.repository.factory.FacilitySelector; import com.clustercontrol.repository.session.RepositoryControllerBean; import com.clustercontrol.snmptrap.model.TrapValueInfo; import com.clustercontrol.snmptrap.model.VarBindPattern; import com.clustercontrol.util.MessageConstant; import com.clustercontrol.util.apllog.AplLogger; /** * ?<BR> * <p> * ??????????? * * @version 4.1.0 * @since 2.0.0 */ public class SelectMonitor { /** ? */ private static Log m_log = LogFactory.getLog(SelectMonitor.class); /** * ?????? * <p> * <ol> * <li>???????</li> * <li>Quartz?/????</li> * <li>???????????{@link #getJudgementInfo()}</li> * <li>?????????????{@link #getCheckInfo()}</li> * </ol> * * @param monitorTypeId ID * @param monitorId ID * @return * @throws MonitorNotFound * @throws HinemosUnknown * @throws InvalidRole * @see com.clustercontrol.monitor.run.ejb.entity.MonitorInfoBean * @see com.clustercontrol.monitor.run.factory.SelectJobKick#getValid(String, String) * @see #getJudgementInfo() * @see #getCheckInfo() */ public MonitorInfo getMonitor(String monitorTypeId, String monitorId) throws MonitorNotFound, HinemosUnknown, InvalidRole { MonitorInfo bean = null; try { // ? bean = QueryUtil.getMonitorInfoPK(monitorId); // ? bean.setNotifyRelationList(new NotifyControllerBean().getNotifyRelation(bean.getNotifyGroupId())); if (bean.getMonitorType() == null) { // ?????? } else if (bean.getMonitorType().equals(MonitorTypeConstant.TYPE_NUMERIC) && bean.getNumericValueInfo() != null) { for (MonitorNumericValueInfo monitorNumericValueInfo : bean.getNumericValueInfo()) { monitorNumericValueInfo = QueryUtil .getMonitorNumericValueInfoPK(monitorNumericValueInfo.getId()); } } else if (bean.getMonitorType().equals(MonitorTypeConstant.TYPE_STRING) && bean.getStringValueInfo() != null) { for (MonitorStringValueInfo monitorStringValueInfo : bean.getStringValueInfo()) { monitorStringValueInfo = QueryUtil.getMonitorStringValueInfoPK(monitorStringValueInfo.getId()); } } else if (bean.getMonitorType().equals(MonitorTypeConstant.TYPE_TRUTH) && bean.getTruthValueInfo() != null) { for (MonitorTruthValueInfo monitorTruthValueInfo : bean.getTruthValueInfo()) { monitorTruthValueInfo = QueryUtil.getMonitorTruthValueInfoPK(monitorTruthValueInfo.getId()); } } else if (bean.getMonitorType().equals(MonitorTypeConstant.TYPE_SCENARIO) && bean.getHttpScenarioCheckInfo() != null && bean.getHttpScenarioCheckInfo().getPages() != null) { for (Page page : bean.getHttpScenarioCheckInfo().getPages()) { page = com.clustercontrol.http.util.QueryUtil.getPagePK(page.getId()); if (page.getPatterns() != null) { for (Pattern pattern : page.getPatterns()) { pattern = com.clustercontrol.http.util.QueryUtil.getPatternPK(pattern.getId()); } } if (page.getVariables() != null) { for (Variable variable : page.getVariables()) { variable = com.clustercontrol.http.util.QueryUtil.getVariablePK(variable.getId()); } } } } else if (bean.getMonitorType().equals(MonitorTypeConstant.TYPE_TRAP) && bean.getTrapCheckInfo() != null && bean.getTrapCheckInfo().getTrapValueInfos() != null) { for (TrapValueInfo trapValueInfo : bean.getTrapCheckInfo().getTrapValueInfos()) { trapValueInfo = com.clustercontrol.snmptrap.util.QueryUtil .getMonitorTrapValueInfoPK(trapValueInfo.getId()); if (trapValueInfo.getVarBindPatterns() != null) { for (VarBindPattern varBindPattern : trapValueInfo.getVarBindPatterns()) { varBindPattern = com.clustercontrol.snmptrap.util.QueryUtil .getMonitorTrapVarbindPatternInfoPK(varBindPattern.getId()); } } } } } catch (MonitorNotFound e) { outputLog(monitorTypeId, monitorId, PriorityConstant.TYPE_WARNING, MessageConstant.MESSAGE_SYS_010_MON); throw e; } catch (InvalidRole e) { outputLog(monitorTypeId, monitorId, PriorityConstant.TYPE_WARNING, MessageConstant.MESSAGE_SYS_010_MON); throw e; } return bean; } /** * ??? * <p> * <ol> * <li>????????</li> * <li>?{@link com.clustercontrol.monitor.run.bean.MonitorTabelDefine}??{@link ArrayList}????</li> * <li>?????????{@link ArrayList}??????<BR> * <dl> * <dt>Object?2?</dt> * <dd>{ 1 {1?, 2?, }, 2{1?, 2?, }, }</dd> * </dl> * </li> * </ol> * * @param monitorTypeId ID * @return Object?2? * @see com.clustercontrol.monitor.run.bean.MonitorTabelDefine * @see #collectionToArray(Collection) */ public ArrayList<MonitorInfo> getMonitorList(String monitorTypeId) { return new ArrayList<>(QueryUtil.getMonitorInfoByMonitorTypeId(monitorTypeId)); } /** * ??? * <p> * <ol> * <li>????????</li> * <li>?{@link com.clustercontrol.monitor.run.bean.MonitorTabelDefine}??{@link ArrayList}????</li> * <li>?????????{@link ArrayList}??????<BR> * <dl> * <dt>Object?2?</dt> * <dd>{ 1 {1?, 2?, }, 2{1?, 2?, }, }</dd> * </dl> * </li> * </ol> * * @param monitorTypeId ID * @return Object?2? * @see com.clustercontrol.monitor.run.bean.MonitorTabelDefine * @see #collectionToArray(Collection) */ public ArrayList<MonitorInfo> getMonitorListObjectPrivilegeModeNONE(String monitorTypeId) { return new ArrayList<>(QueryUtil.getMonitorInfoByMonitorTypeId_NONE(monitorTypeId)); } /** * ??? * <p> * <ol> * <li>???????</li> * <li>?{@link com.clustercontrol.monitor.run.bean.MonitorTabelDefine}??{@link ArrayList}????</li> * <li>?????????{@link ArrayList}??????<BR> * <dl> * <dt>Object?2?</dt> * <dd>{ 1 {1?, 2?, }, 2{1?, 2?, }, }</dd> * </dl> * </li> * </ol> * * @return Object?2? * @throws MonitorNotFound * @throws InvalidRole * @throws HinemosUnknown * @see com.clustercontrol.monitor.run.bean.MonitorTabelDefine * @see #collectionToArray(Collection) */ public ArrayList<MonitorInfo> getMonitorList() throws MonitorNotFound, InvalidRole, HinemosUnknown { m_log.debug("getMonitorList() : start"); ArrayList<MonitorInfo> list = new ArrayList<MonitorInfo>(); try { // ? List<MonitorInfo> ct = QueryUtil.getAllMonitorInfo(); for (MonitorInfo info : ct) { list.add(info); // for debug if (m_log.isDebugEnabled()) { m_log.debug("getMonitorList() : " + "monitorId = " + info.getMonitorId() + ", monitorTypeId = " + info.getMonitorTypeId() + ", monitorType = " + info.getMonitorType() + ", description = " + info.getDescription() + ", facilityId = " + info.getFacilityId() + ", runInterval = " + info.getRunInterval() + ", calendarId = " + info.getCalendarId() + ", failurePriority = " + info.getFailurePriority() + ", notifyGroupId = " + info.getNotifyGroupId() + ", application = " + info.getApplication() + ", monitorFlg = " + info.getMonitorFlg() + ", collectorFlg = " + info.getCollectorFlg() + ", regDate = " + info.getRegDate() + ", updateDate = " + info.getUpdateDate() + ", regUser = " + info.getRegUser() + ", updateUser = " + info.getUpdateUser()); } } } catch (HinemosUnknown e) { outputLog("", "", PriorityConstant.TYPE_WARNING, MessageConstant.MESSAGE_SYS_011_MON); throw e; } m_log.debug("getMonitorList() : end"); return list; } /** * ??? * <p> * <ol> * <li>???????</li> * <li>?{@link com.clustercontrol.monitor.run.bean.MonitorTabelDefine}??{@link ArrayList}????</li> * <li>?????????{@link ArrayList}??????<BR> * <dl> * <dt>Object?2?</dt> * <dd>{ 1 {1?, 2?, }, 2{1?, 2?, }, }</dd> * </dl> * </li> * </ol> * * @return Object?2? * @throws MonitorNotFound * @throws InvalidRole * @throws HinemosUnknown * @see com.clustercontrol.monitor.run.bean.MonitorTabelDefine * @see #collectionToArray(Collection) */ public ArrayList<MonitorInfo> getPerformanceMonitorList() throws MonitorNotFound, InvalidRole, HinemosUnknown { m_log.debug("getMonitorList() : start"); ArrayList<MonitorInfo> list = new ArrayList<MonitorInfo>(); try { // ? List<MonitorInfo> ct = QueryUtil.getAllMonitorInfo(); for (MonitorInfo info : ct) { list.add(info); // for debug if (m_log.isDebugEnabled()) { m_log.debug("getMonitorList() : " + "monitorId = " + info.getMonitorId() + ", monitorTypeId = " + info.getMonitorTypeId() + ", monitorType = " + info.getMonitorType() + ", description = " + info.getDescription() + ", facilityId = " + info.getFacilityId() + ", runInterval = " + info.getRunInterval() + ", calendarId = " + info.getCalendarId() + ", failurePriority = " + info.getFailurePriority() + ", notifyGroupId = " + info.getNotifyGroupId() + ", application = " + info.getApplication() + ", monitorFlg = " + info.getMonitorFlg() + ", collectorFlg = " + info.getCollectorFlg() + ", regDate = " + info.getRegDate() + ", updateDate = " + info.getUpdateDate() + ", regUser = " + info.getRegUser() + ", updateUser = " + info.getUpdateUser()); } } } catch (HinemosUnknown e) { outputLog("", "", PriorityConstant.TYPE_WARNING, MessageConstant.MESSAGE_SYS_011_MON); throw e; } m_log.debug("getMonitorList() : end"); return list; } /** * ???????? * @param condition * @return * @throws HinemosUnknown * @throws InvalidRole * @throws MonitorNotFound */ public ArrayList<MonitorInfo> getMonitorList(MonitorFilterInfo condition) throws HinemosUnknown, InvalidRole, MonitorNotFound { m_log.debug("getMonitorList() condition "); if (m_log.isDebugEnabled()) { if (condition != null) { m_log.debug("getMonitorList() " + "monitorId = " + condition.getMonitorId() + ", monitorTypeId = " + condition.getMonitorTypeId() + ", description = " + condition.getDescription() + ", facilityId = " + condition.getFacilityId() + ", calendarId = " + condition.getCalendarId() + ", regUser = " + condition.getRegUser() + ", regFromDate = " + condition.getRegFromDate() + ", regToDate = " + condition.getRegToDate() + ", updateUser = " + condition.getUpdateUser() + ", updateFromDate = " + condition.getUpdateFromDate() + ", updateToDate = " + condition.getUpdateToDate() + ", monitorFlg = " + condition.getMonitorFlg() + ", collectorFlg = " + condition.getCollectorFlg() + ", ownerRoleId = " + condition.getOwnerRoleId()); } } ArrayList<MonitorInfo> filterList = new ArrayList<MonitorInfo>(); // ??????? if (condition == null) { m_log.debug("getMonitorList() condition is null"); return filterList; } // facilityId???? List<MonitorInfo> entityList = QueryUtil.getMonitorInfoByFilter(condition.getMonitorId(), condition.getMonitorTypeId(), condition.getDescription(), condition.getCalendarId(), condition.getRegUser(), condition.getRegFromDate(), condition.getRegToDate(), condition.getUpdateUser(), condition.getUpdateFromDate(), condition.getUpdateToDate(), condition.getMonitorFlg(), condition.getCollectorFlg(), condition.getOwnerRoleId()); // facilityId??Java?? for (MonitorInfo entity : entityList) { // facilityId if (condition.getFacilityId() != null && !"".equals(condition.getFacilityId()) && entity.getFacilityId() != null) { // FacilitySelector.getNodeFacilityIdList???????????????if if (!ReservedFacilityIdConstant.ROOT_SCOPE.equals(entity.getFacilityId())) { ArrayList<String> searchIdList = FacilitySelector.getNodeFacilityIdList(entity.getFacilityId(), entity.getOwnerRoleId(), RepositoryControllerBean.ALL, false, true); if (!searchIdList.contains(condition.getFacilityId())) { m_log.debug("getMonitorList() continue : collectorFlg target = " + entity.getFacilityId() + ", filter = " + condition.getFacilityId()); continue; } } } m_log.debug("getMonitorList() add display list : target = " + entity.getMonitorId()); filterList.add(entity); } return filterList; } /** * ???? * * @param index ? */ protected void outputLog(String monitorTypeId, String monitorId, int priority, MessageConstant msgCode) { String[] args = { monitorTypeId, monitorId }; AplLogger.put(priority, HinemosModuleConstant.MONITOR, msgCode, args); } }