use of ngse.org.AccessZooKeeper in project MSEC by Tencent.
the class ChangeOddCapacity method exec.
public JsonRPCResponseBase exec(ChangeOddCapacityRequest request) {
JsonRPCResponseBase response = new JsonRPCResponseBase();
String result = checkIdentity();
if (!result.equals("success")) {
response.setStatus(99);
response.setMessage(result);
return response;
}
Logger logger = Logger.getLogger(ChangeOddCapacity.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 {
//step1:更新扩缩容的IP的状态
if (//扩容
request.getAction_type().equals("expand")) {
updateIPStatus(request, true, util);
} else // 缩容
{
updateIPStatus(request, false, util);
}
logger.info("update matchine's status OK, matchine Numbers:" + request.getIp_list().size());
//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 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;
}
use of ngse.org.AccessZooKeeper in project MSEC by Tencent.
the class QueryCapacityList method exec.
public QueryCapacityListResponse exec(CapacityRequest request) {
Logger logger = Logger.getLogger("QueryCapacityList");
QueryCapacityListResponse resp = new QueryCapacityListResponse();
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;
}
List<CapacityBaseInfo> capacities = new ArrayList<CapacityBaseInfo>();
AccessZooKeeper azk = new AccessZooKeeper();
try {
if (request.getFirst_level_service_name() == null || request.getFirst_level_service_name().length() < 1 || request.getSecond_level_service_name() == null || request.getSecond_level_service_name().length() < 1) {
//所有服务
ArrayList<SecondLevelService> svcList = LoadBalance.getAllService(util);
if (svcList == null) {
resp.setMessage("failed to get all service list");
resp.setStatus(100);
return resp;
}
for (int i = 0; i < svcList.size(); i++) {
//每一个服务
SecondLevelService svc = svcList.get(i);
if (!svc.getType().equals("standard")) {
continue;
}
//用户可能指定了一级服务名进行过滤,即只查看该一级服务下所有二级服务的情况
if (request.getFirst_level_service_name() != null && request.getFirst_level_service_name().length() > 0) {
if (!svc.getFirst_level_service_name().equals(request.getFirst_level_service_name())) {
continue;
}
}
CapacityBaseInfo c = new CapacityBaseInfo();
//该服务的所有ip
ArrayList<IPPortPair> iplist = LoadBalance.getIPPortInfoByServiceName(svc.getFirst_level_service_name(), svc.getSecond_level_service_name(), util);
if (iplist == null) {
resp.setMessage("failed to get ip list for " + svc.getFirst_level_service_name() + "." + svc.getSecond_level_service_name());
resp.setStatus(100);
return resp;
}
c.setIp_count(iplist.size());
c.setFirst_level_service_name(svc.getFirst_level_service_name());
c.setSecond_level_service_name(svc.getSecond_level_service_name());
//获取每一个ip的负载信息
int sum = 0;
int count = 0;
int j;
for (j = 0; j < iplist.size(); j++) {
IPPortPair ip = iplist.get(j);
String svcname = svc.getFirst_level_service_name() + "/" + svc.getSecond_level_service_name();
try {
int load = LoadBalance.readOneServiceLoadInfo(azk, svcname, ip.getIp());
if (load >= 0) {
sum += load;
count++;
}
} catch (Exception e) {
e.printStackTrace();
resp.setMessage(e.getMessage());
resp.setStatus(100);
return resp;
}
}
c.setIp_report_num(count);
if (count > 0) {
c.setLoad_level(sum / count);
} else {
c.setLoad_level(0);
}
capacities.add(c);
}
} else {
CapacityBaseInfo c = new CapacityBaseInfo();
//该服务的所有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;
}
c.setIp_count(iplist.size());
c.setFirst_level_service_name(request.getFirst_level_service_name());
c.setSecond_level_service_name(request.getSecond_level_service_name());
//获取每一个ip的负载信息
int sum = 0;
int count = 0;
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) {
sum += load;
count++;
}
} catch (Exception e) {
e.printStackTrace();
resp.setMessage(e.getMessage());
resp.setStatus(100);
return resp;
}
}
c.setIp_report_num(count);
if (count > 0) {
c.setLoad_level(sum / count);
} else {
c.setLoad_level(0);
}
capacities.add(c);
}
} finally {
util.releaseConn();
azk.disconnect();
}
resp.setCapacity_list((ArrayList<CapacityBaseInfo>) capacities);
resp.setMessage("success");
resp.setStatus(0);
return resp;
}
use of ngse.org.AccessZooKeeper in project MSEC by Tencent.
the class RefreshCapacity 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(RefreshCapacity.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(), true, ips);
if (result == null || !result.equals("success")) {
response.setStatus(100);
response.setMessage(result);
return response;
}
logger.info("write into LB server successfully.");
//step3: 更新涉及到的IP为key的配置信息
ArrayList<String> whiteNameList = new ArrayList<>();
for (int i = 0; i < ips.size(); i++) {
whiteNameList.add(ips.get(i).getIp());
}
logger.info("update the IP-key information in LB server");
result = LoadBalance.writeIPConfigInfo(azk, whiteNameList);
if (result == null || !result.equals("success")) {
response.setStatus(100);
response.setMessage(result);
return response;
}
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 ChangeCapacity method exec.
public JsonRPCResponseBase exec(ChangeCapacityRequest request) {
JsonRPCResponseBase response = new JsonRPCResponseBase();
String result = checkIdentity();
if (!result.equals("success")) {
response.setStatus(99);
response.setMessage(result);
return response;
}
Logger logger = Logger.getLogger(ChangeCapacity.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 {
//step1:更新扩缩容的IP的状态
if (//扩容
request.getAction_type().equals("expand")) {
updateIPStatus(request, true, util);
} else // 缩容
{
updateIPStatus(request, false, util);
}
logger.info("update matchine's status OK, matchine Numbers:" + request.getIp_list().size());
//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(), true, ips);
if (result == null || !result.equals("success")) {
response.setStatus(100);
response.setMessage(result);
return response;
}
logger.info("write into LB server successfully.");
//step3: 更新涉及到的IP为key的配置信息
ArrayList<String> whiteNameList = new ArrayList<>();
for (int i = 0; i < request.getIp_list().size(); i++) {
whiteNameList.add(request.getIp_list().get(i).getIp());
}
logger.info("update the IP-key information in LB server");
result = LoadBalance.writeIPConfigInfo(azk, whiteNameList);
if (result == null || !result.equals("success")) {
response.setStatus(100);
response.setMessage(result);
return response;
}
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();
}
}
Aggregations