use of ngse.org.DBUtil in project MSEC by Tencent.
the class DelSecondLevelServiceConfigTag method exec.
public DelSecondLevelServiceConfigTagResponse exec(DelSecondLevelServiceConfigTagRequest request) {
Logger logger = Logger.getLogger(this.getClass().getName());
DelSecondLevelServiceConfigTagResponse response = new DelSecondLevelServiceConfigTagResponse();
response.setMessage("unkown error.");
response.setStatus(100);
String result = checkIdentity();
if (!result.equals("success")) {
response.setStatus(99);
response.setMessage(result);
return response;
}
if (request.getTag_name() == null || request.getTag_name().equals("") || request.getSecond_level_service_name() == null || request.getSecond_level_service_name().equals("") || request.getFirst_level_service_name() == null || request.getFirst_level_service_name().equals("")) {
response.setMessage("tag name and 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 = "delete from t_config_tag where tag_name=? and first_level_service_name=? and second_level_service_name=?";
List<Object> params = new ArrayList<Object>();
params.add(request.getTag_name());
params.add(request.getFirst_level_service_name());
params.add(request.getSecond_level_service_name());
try {
int delNum = util.updateByPreparedStatement(sql, params);
String filename = SecondLevelServiceConfigTag.getConfigFileName(request.getFirst_level_service_name(), request.getSecond_level_service_name(), request.getTag_name());
logger.error("delte file:" + filename);
RemoveFile(filename);
if (delNum > 0) {
response.setMessage("success");
response.setDelNumber(delNum);
response.setStatus(0);
return response;
} else {
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;
} finally {
util.releaseConn();
}
}
use of ngse.org.DBUtil in project MSEC by Tencent.
the class DelSecondLevelServiceIPInfo method exec.
public DelSecondLevelServiceIPInfoResponse exec(DelSecondLevelServiceIPInfoRequest request) {
DelSecondLevelServiceIPInfoResponse response = new DelSecondLevelServiceIPInfoResponse();
response.setMessage("unkown error.");
response.setStatus(100);
String result = checkIdentity();
if (!result.equals("success")) {
response.setStatus(99);
response.setMessage(result);
return response;
}
if (request.getIpToDel() == null || request.getIpToDel().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 {
int total = 0;
IPPortPair[] ipToDel = request.getIpToDel();
for (int i = 0; i < ipToDel.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(ipToDel[i].getIp());
params.add(ipToDel[i].getPort());
try {
int delNum = util.updateByPreparedStatement(sql, params);
if (delNum > 0) {
total += delNum;
continue;
} else {
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.setDelNumber(total);
response.setStatus(0);
return response;
} finally {
util.releaseConn();
}
}
use of ngse.org.DBUtil in project MSEC by Tencent.
the class DelSharedobject method exec.
public DelSharedobjectResponse exec(SharedobjectTag request) {
Logger logger = Logger.getLogger(this.getClass().getName());
DelSharedobjectResponse response = new DelSharedobjectResponse();
response.setMessage("unkown error.");
response.setStatus(100);
String result = checkIdentity();
if (!result.equals("success")) {
response.setStatus(99);
response.setMessage(result);
return response;
}
if (request.getTag_name() == null || request.getTag_name().equals("") || request.getSecond_level_service_name() == null || request.getSecond_level_service_name().equals("") || request.getFirst_level_service_name() == null || request.getFirst_level_service_name().equals("")) {
response.setMessage("tag name and 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;
}
try {
String sql = "delete from t_sharedobject_tag where tag_name=? and first_level_service_name=? and second_level_service_name=?";
List<Object> params = new ArrayList<Object>();
params.add(request.getTag_name());
params.add(request.getFirst_level_service_name());
params.add(request.getSecond_level_service_name());
int delNum = util.updateByPreparedStatement(sql, params);
String filename = SharedobjectTag.getSharedobjectName(request.getFirst_level_service_name(), request.getSecond_level_service_name(), request.getTag_name(), "so");
logger.error("delte file:" + filename);
RemoveFile(filename);
if (delNum > 0) {
response.setMessage("success");
response.setDelNumber(delNum);
response.setStatus(0);
return response;
} else {
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;
} finally {
util.releaseConn();
}
}
use of ngse.org.DBUtil 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.DBUtil in project MSEC by Tencent.
the class DelLibraryFile method deleteAll.
public static String deleteAll(String flsn, String slsn) {
DBUtil util = new DBUtil();
if (util.getConnection() == null) {
return "DB connect failed.";
}
try {
String sql = "select file_name from t_library_file where first_level_service_name=? and second_level_service_name=?";
List<Object> params = new ArrayList<Object>();
params.add(flsn);
params.add(slsn);
ArrayList<LibraryFile> result = util.findMoreRefResult(sql, params, LibraryFile.class);
for (int i = 0; i < result.size(); i++) {
String file_name = result.get(i).getFile_name();
sql = "delete from t_library_file where file_name=? and first_level_service_name=? and second_level_service_name=?";
params = new ArrayList<Object>();
params.add(file_name);
params.add(flsn);
params.add(slsn);
//删除数据库记录
int delNum = util.updateByPreparedStatement(sql, params);
String filename = LibraryFile.getLibraryFileName(flsn, slsn, file_name);
RemoveFile(filename);
}
return "success";
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
} finally {
util.releaseConn();
}
}
Aggregations