use of ngse.org.DBUtil in project MSEC by Tencent.
the class AddNewMachine method exec.
public JsonRPCResponseBase exec(AddNewMachineRequest request) {
JsonRPCResponseBase response = new JsonRPCResponseBase();
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("") || request.getMachine_ip() == null || request.getMachine_ip().equals("")) {
response.setMessage("The name/ip of machine to be added 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 = "insert into t_machine(machine_name, machine_ip,os_version, gcc_version, java_version) values(?,?,?,?,?)";
List<Object> params = new ArrayList<Object>();
params.add(request.getMachine_name());
params.add(request.getMachine_ip());
params.add(request.getOs_version());
params.add(request.getGcc_version());
params.add(request.getJava_version());
try {
int addNum = util.updateByPreparedStatement(sql, params);
if (addNum >= 0) {
response.setMessage("success");
response.setStatus(0);
return response;
}
} catch (SQLException e) {
response.setMessage("add 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 DeleteAlarm 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 DownloadDevGO method doStep1.
private JsonRPCResponseBase doStep1(DevPackage request) {
JsonRPCResponseBase response = new JsonRPCResponseBase();
//把计划保存到session里
HttpSession session = getHttpRequest().getSession();
DBUtil util = new DBUtil();
try {
util.getConnection();
String sql = "select dev_lang from t_second_level_service where first_level_service_name=? and second_level_service_name=?";
ArrayList<Object> params = new ArrayList<Object>();
params.add(request.getFirst_level_service_name());
params.add(request.getSecond_level_service_name());
Map<String, Object> map = util.findSimpleResult(sql, params);
request.setDev_lang((String) map.get("dev_lang"));
} catch (Exception e) {
request.setDev_lang("c++");
} finally {
util.releaseConn();
}
session.setAttribute("DevPackage", request);
response.setMessage("success");
response.setStatus(0);
return response;
}
use of ngse.org.DBUtil in project MSEC by Tencent.
the class DelOddService method exec.
public DelServiceResponse exec(DelServiceRequest request) {
Logger logger = Logger.getLogger(this.getClass().getName());
DelServiceResponse response = new DelServiceResponse();
response.setMessage("unkown error.");
response.setStatus(100);
String result = checkIdentity();
if (!result.equals("success")) {
response.setStatus(99);
response.setMessage(result);
return response;
}
if (request.getService_name() == null || request.getService_name().equals("") || request.getService_level() == null || request.getService_level().equals("")) {
response.setMessage("The name/level of service to be deled should NOT be empty.");
response.setStatus(100);
return response;
}
if (request.getService_parent().equals("RESERVED") && (request.getService_name().equals("log") || request.getService_name().equals("monitor"))) {
response.setMessage("The reserved services can NOT be deleted.");
response.setStatus(100);
return response;
}
if (request.getService_level().equals("second_level") && (request.getService_parent() == null || request.getService_parent().equals(""))) {
response.setMessage("The first level service name 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;
List<Object> params = new ArrayList<Object>();
if (request.getService_level().equals("first_level")) {
//检查一下一级服务下还有没有二级服务,有的话不能删除
if (checkIfHasSecondLevel(request.getService_name(), util) != false) {
response.setMessage("还有二级服务挂靠在该一级服务下,不能删除该服务.");
response.setStatus(100);
return response;
}
sql = "delete from t_first_level_service where first_level_service_name=? ";
logger.info(sql);
params.add(request.getService_name());
} else {
sql = "delete from t_second_level_service where second_level_service_name=? and first_level_service_name=?";
logger.info(sql);
params.add(request.getService_name());
params.add(request.getService_parent());
}
try {
int delNum = util.updateByPreparedStatement(sql, params);
if (delNum == 1) {
if (request.getService_level().equals("second_level")) {
DelOddSecondLevelServiceIPInfo.deleteAll(request.getService_parent(), request.getService_name());
}
response.setDelNum(delNum);
response.setMessage("success");
response.setStatus(0);
return response;
} else {
response.setDelNum(delNum);
response.setMessage("delete record number is " + delNum);
response.setStatus(100);
return response;
}
} catch (SQLException e) {
response.setMessage("del record failed:" + e.toString());
response.setStatus(100);
e.printStackTrace();
return response;
} finally {
util.releaseConn();
}
}
use of ngse.org.DBUtil in project MSEC by Tencent.
the class DelReleasePlan method exec.
public DelReleasePlanResponse exec(ReleasePlan request) {
Logger logger = Logger.getLogger(this.getClass().getName());
DelReleasePlanResponse response = new DelReleasePlanResponse();
response.setMessage("unkown error.");
response.setStatus(100);
String result = checkIdentity();
if (!result.equals("success")) {
response.setStatus(99);
response.setMessage(result);
return response;
}
if (request.getPlan_id() == null || request.getPlan_id().equals("")) {
response.setMessage("Plan ID 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;
List<Object> params = new ArrayList<Object>();
sql = "delete from t_release_plan where plan_id=?";
logger.info(sql);
params.add(request.getPlan_id());
try {
int delNum = util.updateByPreparedStatement(sql, params);
if (delNum == 1) {
response.setDelNumber(delNum);
response.setMessage("success");
response.setStatus(0);
return response;
} else {
response.setDelNumber(delNum);
response.setMessage("delete record number is " + delNum);
response.setStatus(100);
return response;
}
} catch (SQLException e) {
response.setMessage("del record failed:" + e.toString());
response.setStatus(100);
e.printStackTrace();
return response;
} finally {
util.releaseConn();
}
}
Aggregations