use of beans.response.QueryConfigInLBResponse in project MSEC by Tencent.
the class QueryConfigInLB method exec.
public QueryConfigInLBResponse exec(QueryConfigInLBRequest request) {
QueryConfigInLBResponse response = new QueryConfigInLBResponse();
Logger logger = Logger.getLogger(QueryConfigInLB.class);
String svc = request.getFirst_level_service_name() + "/" + request.getSecond_level_service_name();
AccessZooKeeper azk = new AccessZooKeeper();
try {
//读LB系统里的配置信息
byte[] ret = LoadBalance.readOneServiceConfigInfo(azk, svc);
if (ret == null) {
response.setStatus(100);
response.setMessage("read failed.");
return response;
}
String s = new String(ret, Charset.forName("UTF-8"));
logger.error(s);
//json格式解析
ArrayList<IPPortPair> ip_list = new ArrayList<>();
JSONObject obj = new JSONObject(s);
JSONArray arr = obj.getJSONArray("IPInfo");
for (//每一个IP
int i = 0; //每一个IP
i < arr.length(); //每一个IP
++i) {
obj = arr.getJSONObject(i);
JSONArray arr2 = obj.getJSONArray("ports");
for (int j = 0; j < arr2.length(); j++) {
//该IP上的每一个端口
IPPortPair pair = new IPPortPair();
pair.setPort(arr2.getInt(j));
pair.setIp(obj.getString("IP"));
ip_list.add(pair);
}
}
response.setIp_list(ip_list);
response.setStatus(0);
response.setMessage("success");
return response;
} catch (Exception e) {
e.printStackTrace();
response.setStatus(100);
response.setMessage(e.getMessage());
return response;
} finally {
azk.disconnect();
}
}
Aggregations