use of ngse.org.DBUtil in project MSEC by Tencent.
the class QuerySecondLevelServiceList method exec.
public QuerySecondLevelServiceListResponse exec(QuerySecondLevelServiceListRequest request) {
QuerySecondLevelServiceListResponse resp = new QuerySecondLevelServiceListResponse();
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<SecondLevelService> serviceList;
String sql = "select first_level_service_name, second_level_service_name from t_second_level_service where type='standard' ";
List<Object> params = new ArrayList<Object>();
try {
serviceList = util.findMoreRefResult(sql, params, SecondLevelService.class);
} catch (Exception e) {
resp.setStatus(100);
resp.setMessage("db query exception!");
e.printStackTrace();
return resp;
} finally {
util.releaseConn();
}
resp.setService_list((ArrayList<SecondLevelService>) serviceList);
resp.setMessage("success");
resp.setStatus(0);
return resp;
}
use of ngse.org.DBUtil 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.DBUtil in project MSEC by Tencent.
the class QueryAlarmList method initMonitorIPAndPort.
public static void initMonitorIPAndPort() throws Exception {
DBUtil util = new DBUtil();
Logger logger = Logger.getLogger(MonitorBySvcOrIP.class);
try {
if (util.getConnection() == null) {
Exception e = new Exception("connect db failed.");
throw e;
}
String sql = sql = "select ip,port from t_second_level_service_ipinfo where second_level_service_name='monitor' and " + "first_level_service_name='RESERVED' and status='enabled'";
ArrayList<OddSecondLevelServiceIPInfo> list = util.findMoreRefResult(sql, null, OddSecondLevelServiceIPInfo.class);
if (list == null || list.size() < 1) {
throw new Exception("no db record exists.");
}
monitor_server_ip = list.get(0).getIp();
//为什么加1,是个很长的故事,源于monitor的开发者将读写分离成两个端口
monitor_server_port = list.get(0).getPort().intValue() + 1;
logger.info(String.format("monitor server:%s:%d", monitor_server_ip, monitor_server_port));
} finally {
util.releaseConn();
}
}
use of ngse.org.DBUtil in project MSEC by Tencent.
the class DeleteAlarmSetting method initMonitorIPAndPort.
public static void initMonitorIPAndPort() throws Exception {
DBUtil util = new DBUtil();
Logger logger = Logger.getLogger(MonitorBySvcOrIP.class);
try {
if (util.getConnection() == null) {
Exception e = new Exception("connect db failed.");
throw e;
}
String sql = sql = "select ip,port from t_second_level_service_ipinfo where second_level_service_name='monitor' and " + "first_level_service_name='RESERVED' and status='enabled'";
ArrayList<OddSecondLevelServiceIPInfo> list = util.findMoreRefResult(sql, null, OddSecondLevelServiceIPInfo.class);
if (list == null || list.size() < 1) {
throw new Exception("no db record exists.");
}
monitor_server_ip = list.get(0).getIp();
//为什么加1,是个很长的故事,源于monitor的开发者将读写分离成两个端口
monitor_server_port = list.get(0).getPort().intValue() + 1;
logger.info(String.format("monitor server:%s:%d", monitor_server_ip, monitor_server_port));
} finally {
util.releaseConn();
}
}
use of ngse.org.DBUtil in project MSEC by Tencent.
the class AddOddSecondLevelServiceIPInfo method exec.
public AddOddSecondLevelServiceIPInfoResponse exec(OddSecondLevelServiceIPInfo request) {
AddOddSecondLevelServiceIPInfoResponse response = new AddOddSecondLevelServiceIPInfoResponse();
response.setMessage("unkown error.");
response.setStatus(100);
String result = checkIdentity();
if (!result.equals("success")) {
response.setStatus(99);
response.setMessage(result);
return response;
}
if (request.getIp() == null || request.getIp().equals("") || request.getSecond_level_service_name() == null || request.getSecond_level_service_name().equals("")) {
response.setMessage("Some request field is empty.");
response.setStatus(100);
return response;
}
ArrayList<String> ips = Tools.splitBySemicolon(request.getIp());
if (ips == null || ips.size() == 0) {
response.setMessage("IP 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;
}
ArrayList<IPPortPair> addedIP = new ArrayList<IPPortPair>();
try {
for (int i = 0; i < ips.size(); ++i) {
String s = ips.get(i);
int index = s.indexOf(":");
if (index <= 0 || index == (s.length() - 1)) {
continue;
}
String ip = s.substring(0, index);
int port = Integer.valueOf(s.substring(index + 1));
String sql;
List<Object> params = new ArrayList<Object>();
sql = "insert into t_second_level_service_ipinfo(ip,port,status, second_level_service_name,first_level_service_name, comm_proto) values(?,?,?,?,?,?)";
params.add(ip);
params.add(port);
params.add("disabled");
params.add(request.getSecond_level_service_name());
params.add(request.getFirst_level_service_name());
params.add(request.getComm_proto());
try {
int addNum = util.updateByPreparedStatement(sql, params);
if (addNum >= 0) {
IPPortPair pair = new IPPortPair();
pair.setIp(ip);
pair.setPort(port);
pair.setStatus("disabled");
addedIP.add(pair);
} else {
response.setMessage("failed to insert table");
response.setStatus(100);
return response;
}
} catch (SQLException e) {
response.setMessage("add record failed:" + e.toString());
response.setStatus(100);
e.printStackTrace();
return response;
}
}
response.setMessage("success");
response.setStatus(0);
response.setAddedIPs(addedIP);
return response;
} finally {
util.releaseConn();
}
}
Aggregations