use of ngse.org.DBUtil in project MSEC by Tencent.
the class DelMachine method exec.
public DelMachineResponse exec(DelMachineRequest request) {
DelMachineResponse response = new DelMachineResponse();
response.setMessage("unkown error.");
response.setStatus(100);
String result = checkIdentity();
if (!result.equals("success")) {
response.setStatus(99);
response.setMessage(result);
return response;
}
if (request.getMachine_name() == null || request.getMachine_name().equals("")) {
response.setMessage("The name of machine to be deleted should NOT be empty.");
response.setStatus(100);
return response;
}
DBUtil util = new DBUtil();
if (util.getConnection() == null) {
response.setMessage("DB connect failed.");
response.setStatus(100);
return response;
}
String sql = "delete from t_machine where machine_name=?";
List<Object> params = new ArrayList<Object>();
params.add(request.getMachine_name());
try {
int delNum = util.updateByPreparedStatement(sql, params);
if (delNum >= 0) {
response.setMessage("success");
response.setDeleteNumber(delNum);
response.setStatus(0);
return response;
}
} catch (SQLException e) {
response.setMessage("Delete record failed:" + e.toString());
response.setStatus(100);
e.printStackTrace();
return response;
} finally {
util.releaseConn();
}
return response;
}
use of ngse.org.DBUtil in project MSEC by Tencent.
the class DelOddSecondLevelServiceIPInfo method exec.
public DelOddSecondLevelServiceIPInfoResponse exec(DelOddSecondLevelServiceIPInfoRequest request) {
DelOddSecondLevelServiceIPInfoResponse response = new DelOddSecondLevelServiceIPInfoResponse();
response.setMessage("unkown error.");
response.setStatus(100);
String result = checkIdentity();
if (!result.equals("success")) {
response.setStatus(99);
response.setMessage(result);
return response;
}
if (request.getIps() == null || request.getIps().length == 0) {
response.setMessage("IP /port to be deleted should NOT be empty.");
response.setStatus(100);
return response;
}
DBUtil util = new DBUtil();
if (util.getConnection() == null) {
response.setMessage("DB connect failed.");
response.setStatus(100);
return response;
}
try {
for (int i = 0; i < request.getIps().length; ++i) {
String sql = "delete from t_second_level_service_ipinfo where ip=? and port=? and status='disabled'";
List<Object> params = new ArrayList<Object>();
params.add(request.getIps()[i].getIp());
params.add(request.getIps()[i].getPort());
try {
int delNum = util.updateByPreparedStatement(sql, params);
if (delNum <= 0) {
response.setMessage("delete record number is " + delNum);
response.setDelNumber(delNum);
response.setStatus(100);
return response;
}
} catch (SQLException e) {
response.setMessage("Delete record failed:" + e.toString());
response.setStatus(100);
e.printStackTrace();
return response;
}
}
response.setMessage("success");
response.setStatus(0);
return response;
} finally {
util.releaseConn();
}
}
use of ngse.org.DBUtil in project MSEC by Tencent.
the class QueryBusinessLog method getBusiLogSrvIPPort.
public static ArrayList<IPPortPair> getBusiLogSrvIPPort() {
DBUtil util = new DBUtil();
try {
if (util.getConnection() == null) {
return null;
}
String sql = sql = "select ip,port from t_second_level_service_ipinfo where second_level_service_name='log' " + "and first_level_service_name='RESERVED' and status='enabled'";
ArrayList<IPPortPair> list = util.findMoreRefResult(sql, null, IPPortPair.class);
return list;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
util.releaseConn();
}
}
use of ngse.org.DBUtil 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.DBUtil 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;
}
Aggregations