use of beans.dbaccess.CapacityDetailInfo in project MSEC by Tencent.
the class QueryCapacityDetail method exec.
public QueryCapacityDetailResponse exec(CapacityRequest request) {
Logger logger = Logger.getLogger("QueryCapacityDetail");
QueryCapacityDetailResponse resp = new QueryCapacityDetailResponse();
String result = checkIdentity();
if (!result.equals("success")) {
resp.setStatus(99);
resp.setMessage(result);
return resp;
}
DBUtil util = new DBUtil();
if (util.getConnection() == null) {
resp.setStatus(100);
resp.setMessage("db connect failed!");
return resp;
}
ArrayList<CapacityDetailInfo> capacities = new ArrayList<CapacityDetailInfo>();
AccessZooKeeper azk = new AccessZooKeeper();
try {
//该服务的所有ip
ArrayList<IPPortPair> iplist = LoadBalance.getIPPortInfoByServiceName(request.getFirst_level_service_name(), request.getSecond_level_service_name(), util);
if (iplist == null) {
resp.setMessage("failed to get ip list for " + request.getFirst_level_service_name() + "." + request.getSecond_level_service_name());
resp.setStatus(100);
return resp;
}
//获取每一个ip的负载信息
int j;
for (j = 0; j < iplist.size(); j++) {
IPPortPair ip = iplist.get(j);
String svcname = request.getFirst_level_service_name() + "/" + request.getSecond_level_service_name();
try {
int load = LoadBalance.readOneServiceLoadInfo(azk, svcname, ip.getIp());
if (load >= 0) {
CapacityDetailInfo c = new CapacityDetailInfo();
c.setIp(ip.getIp());
c.setLoad_level(load);
capacities.add(c);
}
} catch (Exception e) {
e.printStackTrace();
resp.setMessage(e.getMessage());
resp.setStatus(100);
return resp;
}
}
} finally {
util.releaseConn();
azk.disconnect();
}
resp.setInfo(capacities);
resp.setMessage("success");
resp.setStatus(0);
return resp;
}
Aggregations