use of ngse.org.DBUtil in project MSEC by Tencent.
the class AddOddService method exec.
public AddServiceResponse exec(AddServiceRequest request) {
AddServiceResponse response = new AddServiceResponse();
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 added should NOT be empty.");
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")) {
sql = "insert into t_first_level_service( first_level_service_name, type) values(?, 'odd')";
params.add(request.getService_name());
} else {
sql = "insert into t_second_level_service(second_level_service_name, first_level_service_name, type) values(?,?, 'odd')";
params.add(request.getService_name());
params.add(request.getService_parent());
}
try {
int addNum = util.updateByPreparedStatement(sql, params);
if (addNum >= 0) {
response.setAddNum(addNum);
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 AddSecondLevelServiceConfigTag method exec.
public AddSecondLevelServiceConfigTagResponse exec(AddSecondLevelServiceConfigTagRequest request) {
AddSecondLevelServiceConfigTagResponse response = new AddSecondLevelServiceConfigTagResponse();
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.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 || request.getContent() == null || request.getContent().length() < 1) {
response.setMessage("Some request field is 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 filename = SecondLevelServiceConfigTag.getConfigFileName(request.getFirst_level_service_name(), request.getSecond_level_service_name(), request.getTag_name());
if (!SaveConfigContent(filename, request.getContent())) {
response.setMessage("save file failed.");
response.setStatus(100);
return response;
}
//写入端口配置信息
int port = getStandardServicePort(util, request.getFirst_level_service_name(), request.getSecond_level_service_name());
addPortConfig(filename, port);
//插入数据库
String sql;
List<Object> params = new ArrayList<Object>();
sql = "insert into t_config_tag(tag_name, memo, second_level_service_name,first_level_service_name) values(?,?,?,?)";
params.add(request.getTag_name());
if (request.getMemo() == null) {
params.add("");
} else {
params.add(request.getMemo());
}
params.add(request.getSecond_level_service_name());
params.add(request.getFirst_level_service_name());
int addNum = util.updateByPreparedStatement(sql, params);
if (addNum > 0) {
response.setAddNumber(addNum);
response.setMessage("success");
response.setStatus(0);
return response;
} else {
response.setAddNumber(addNum);
response.setMessage("failed to insert table");
response.setStatus(100);
return response;
}
} catch (Exception e) {
response.setMessage("add 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 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();
}
}
use of ngse.org.DBUtil in project MSEC by Tencent.
the class DelIDLTag method exec.
public DelIDLTagResponse exec(IDL request) {
Logger logger = Logger.getLogger(this.getClass().getName());
DelIDLTagResponse response = new DelIDLTagResponse();
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_idl_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 = IDL.getIDLFileName(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 DelIDLTag 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 tag_name from t_idl_tag where first_level_service_name=? and second_level_service_name=?";
List<Object> params = new ArrayList<Object>();
params.add(flsn);
params.add(slsn);
ArrayList<IDL> result = util.findMoreRefResult(sql, params, IDL.class);
for (int i = 0; i < result.size(); i++) {
String tag_name = result.get(i).getTag_name();
sql = "delete from t_idl_tag where tag_name=? and first_level_service_name=? and second_level_service_name=?";
params = new ArrayList<Object>();
params.add(tag_name);
params.add(flsn);
params.add(slsn);
//删除数据库记录
int delNum = util.updateByPreparedStatement(sql, params);
String filename = IDL.getIDLFileName(flsn, slsn, tag_name);
RemoveFile(filename);
}
return "success";
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
} finally {
util.releaseConn();
}
}
Aggregations