Search in sources :

Example 1 with CapacityDetailInfo

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;
}
Also used : DBUtil(ngse.org.DBUtil) IPPortPair(beans.request.IPPortPair) QueryCapacityDetailResponse(beans.response.QueryCapacityDetailResponse) ArrayList(java.util.ArrayList) CapacityDetailInfo(beans.dbaccess.CapacityDetailInfo) Logger(org.apache.log4j.Logger) AccessZooKeeper(ngse.org.AccessZooKeeper)

Aggregations

CapacityDetailInfo (beans.dbaccess.CapacityDetailInfo)1 IPPortPair (beans.request.IPPortPair)1 QueryCapacityDetailResponse (beans.response.QueryCapacityDetailResponse)1 ArrayList (java.util.ArrayList)1 AccessZooKeeper (ngse.org.AccessZooKeeper)1 DBUtil (ngse.org.DBUtil)1 Logger (org.apache.log4j.Logger)1