/** * 根据actionType来获取tair数据库中的信息 * * @return */ public List<AllTairData> findTairInfoByAction(String actionType, String groupName, String date) { Map<String, AllTairData> appTairDataMap = new HashMap<String, AllTairData>(); List<AllTairData> appTairDataList = new ArrayList<AllTairData>(); List<TairInfoPo> tairList = dao.findTairInfoByAction(actionType, groupName, date); for (TairInfoPo po : tairList) { String appName = po.getAppName(); AllTairData appTair = appTairDataMap.get(appName); if (appTair == null) { appTair = new AllTairData(); appTair.setStr(appName); appTairDataMap.put(appName, appTair); } appTair.addData1(po.getData1()); appTair.addData2(po.getData2()); } for (Map.Entry<String, AllTairData> entry : appTairDataMap.entrySet()) { appTairDataList.add(entry.getValue()); } Collections.sort(appTairDataList); if (appTairDataList.size() > 10) { appTairDataList = appTairDataList.subList(0, 9); } return appTairDataList; }
/** * 根据namespace来获取tair数据库中的信息 * * @return map<ip, 每行数据> */ public Map<String, List<TairInfoPo>> findTairInfoByNamespace( String appName, String groupName, String namespace, String date) { Map<String, List<TairInfoPo>> ipTairMap = new HashMap<String, List<TairInfoPo>>(); List<TairInfoPo> tairList = dao.findTairInfoByNamespace(appName, groupName, namespace, date); for (TairInfoPo po : tairList) { List<TairInfoPo> ipTairList = ipTairMap.get(po.getHostIp()); if (ipTairList == null) { ipTairList = new ArrayList<TairInfoPo>(); ipTairMap.put(po.getHostIp(), ipTairList); } ipTairList.add(po); } return ipTairMap; }
/** * 查询此应用所有的tair的信息 * * @param appId * @param date * @return */ public Map<String, Map<String, AllTairData>> findAppTairList(String opsName, String date) { // 将要返回的map // map<actionType, map<groupName, 每组信息> Map<String, Map<String, AllTairData>> tairMap = new TreeMap<String, Map<String, AllTairData>>(); // 数据库中的每条记录 List<TairInfoPo> tairList = new ArrayList<TairInfoPo>(); tairList = dao.findAllTairInfo(opsName, date); // 填充tairMap for (TairInfoPo po : tairList) { String actionType = po.getActionType(); Map<String, AllTairData> allTairDateMap = tairMap.get(actionType); if (allTairDateMap == null) { allTairDateMap = new HashMap<String, AllTairData>(); tairMap.put(actionType, allTairDateMap); } AllTairData allTairDate = allTairDateMap.get(po.getGroupName()); if (allTairDate == null) { allTairDate = new AllTairData(); allTairDateMap.put(po.getGroupName(), allTairDate); } allTairDate.addTairData(po); } // 转化AllTairData中的数据 for (Map.Entry<String, Map<String, AllTairData>> entry : tairMap.entrySet()) { for (Map.Entry<String, AllTairData> entry1 : entry.getValue().entrySet()) { entry1.getValue().convertMap(); entry1.getValue().createAllInfo(); } } return tairMap; }