use of ngse.org.AccessZooKeeper in project MSEC by Tencent.
the class RefreshOddCapacity method exec.
public JsonRPCResponseBase exec(CapacityRequest request) {
JsonRPCResponseBase response = new JsonRPCResponseBase();
String result = checkIdentity();
if (!result.equals("success")) {
response.setStatus(99);
response.setMessage(result);
return response;
}
Logger logger = Logger.getLogger(RefreshOddCapacity.class);
//把ip列表刷新到LB的服务器里并下发给各个客户端
AccessZooKeeper azk = new AccessZooKeeper();
DBUtil util = new DBUtil();
if (util.getConnection() == null) {
response.setStatus(100);
response.setMessage("db connect failed");
return response;
}
try {
//step2: 获得该服务下所有enabled的IP,写入LB系统
ArrayList<IPPortPair> ips = LoadBalance.getIPPortInfoByServiceName(request.getFirst_level_service_name(), request.getSecond_level_service_name(), util);
if (ips == null) {
response.setStatus(100);
response.setMessage("get ip info from db failed");
return response;
}
logger.info("get enabled IP, they will be write to LB server, number:" + ips.size());
result = LoadBalance.writeOneServiceConfigInfo(azk, request.getFirst_level_service_name() + "/" + request.getSecond_level_service_name(), false, ips);
if (result == null || !result.equals("success")) {
response.setStatus(100);
response.setMessage(result);
return response;
}
logger.info("write into LB server successfully.");
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();
util.releaseConn();
}
}
use of ngse.org.AccessZooKeeper 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