use of msec.org.DBUtil in project MSEC by Tencent.
the class ESHelper method updateStatus.
private void updateStatus(String status) {
Logger logger = Logger.getLogger(InstallServerProc.class);
DBUtil util = new DBUtil();
if (util.getConnection() == null) {
return;
}
try {
String sql = "update t_install_plan set status=? where plan_id=?";
List<Object> params = new ArrayList<Object>();
params.add(status);
params.add(cluster_info.getPlan_id());
int updNum = util.updateByPreparedStatement(sql, params);
if (updNum < 0) {
return;
}
} catch (Exception e) {
logger.error(e);
logger.error(e);
return;
} finally {
util.releaseConn();
}
}
use of msec.org.DBUtil in project MSEC by Tencent.
the class AddService method exec.
public AddServiceResponse exec(AddServiceRequest request) throws UnsupportedEncodingException {
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_name().equals("RESERVED") || request.getService_level() == null || request.getService_level().equals("") || request.getService_level().equals("")) {
response.setMessage("The name/level of service to be added should NOT be empty or RESERVED.");
response.setStatus(100);
return response;
}
if (request.getService_name().contains(".")) {
response.setMessage("The name of service to be added should NOT contains \".\".");
response.setStatus(100);
return response;
}
if (request.getService_name().getBytes("UTF-8").length >= 64) {
response.setMessage("The length of the name of service to be added should NOT be larger than 64 bytes.");
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(?, 'standard')";
params.add(request.getService_name());
} else {
sql = "insert into t_second_level_service(second_level_service_name, first_level_service_name, status) values(?,?,'OK')";
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 msec.org.DBUtil in project MSEC by Tencent.
the class DelService 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_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_service_info where second_level_service_name=? and first_level_service_name=?";
params.add(request.getService_name());
params.add(request.getService_parent());
try {
util.updateByPreparedStatement(sql, params);
} catch (SQLException e) {
response.setMessage("del record failed:" + e.toString());
response.setStatus(100);
e.printStackTrace();
util.releaseConn();
return response;
}
sql = "delete from t_second_level_service where second_level_service_name=? and first_level_service_name=?";
params.clear();
logger.info(sql);
params.add(request.getService_name());
params.add(request.getService_parent());
}
try {
int delNum = util.updateByPreparedStatement(sql, params);
if (delNum == 1) {
//相关的一些信息也应该删除掉,例如IP、config、IDL等等
if (request.getService_level().equals("second_level")) {
}
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 msec.org.DBUtil in project MSEC by Tencent.
the class GetPlanDetail method exec.
public GetPlanDetailResponse exec(GetPlanDetailRequest request) {
GetPlanDetailResponse resp = new GetPlanDetailResponse();
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;
}
JedisHelper helper = null;
List<ServerInfo> serverList;
int copy_num = 0;
ArrayList<String> ip_port_list = new ArrayList<>();
try {
String sql;
List<Object> params = new ArrayList<Object>();
String plan_id = request.getPlan_id();
if (request.getPlan_id() == null || request.getPlan_id().isEmpty()) {
resp.setStatus(101);
resp.setMessage("parameter error!");
return resp;
} else {
sql = "select ip, port, set_id, group_id, memory, master, status from t_install_plan where plan_id=? and first_level_service_name=? and second_level_service_name=? order by set_id asc, group_id asc, master desc";
params.clear();
params.add(request.getPlan_id());
params.add(request.getFirst_level_service_name());
params.add(request.getSecond_level_service_name());
try {
serverList = util.findMoreRefResult(sql, params, ServerInfo.class);
} catch (Exception e) {
resp.setStatus(100);
resp.setMessage("db query exception!");
e.printStackTrace();
return resp;
}
}
if (serverList.size() == 0) {
resp.setStatus(100);
resp.setMessage("plan id error!");
return resp;
}
boolean finished = true;
for (ServerInfo server : serverList) {
if (!server.getStatus().startsWith("Done")) {
if (server.getStatus().startsWith("[ERROR]")) {
finished = true;
break;
} else {
//in progress...
finished = false;
}
}
}
resp.setFinished(finished);
resp.setServers((ArrayList<ServerInfo>) serverList);
resp.setMessage("success");
resp.setStatus(0);
return resp;
} finally {
util.releaseConn();
}
}
use of msec.org.DBUtil in project MSEC by Tencent.
the class GetPlanList method exec.
public GetPlanListResponse exec(GetPlanListRequest request) {
GetPlanListResponse resp = new GetPlanListResponse();
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<PlanInfo> planList;
HashMap<String, String> plan_status_map = new HashMap<>();
ArrayList<PlanInfo> plans = new ArrayList<>();
try {
String sql = "select plan_id, operation, status from t_install_plan where first_level_service_name=? and second_level_service_name=?" + " and create_time>=? and create_time<=? group by plan_id, operation, status order by plan_id desc";
List<Object> params = new ArrayList<Object>();
params.add(request.getFirst_level_service_name());
params.add(request.getSecond_level_service_name());
params.add(request.getBegin_date() + " 00:00:00");
params.add(request.getEnd_date() + " 23:59:59");
planList = util.findMoreRefResult(sql, params, PlanInfo.class);
for (PlanInfo plan : planList) {
String status = plan_status_map.get(plan.getPlan_id());
if (status == null) {
if (plan.getStatus().startsWith("Done")) {
plan_status_map.put(plan.getPlan_id(), status_ok);
} else if (plan.getStatus().startsWith("[ERROR]")) {
plan_status_map.put(plan.getPlan_id(), status_error);
} else {
plan_status_map.put(plan.getPlan_id(), status_ip);
}
} else {
//ERROR > In Progress > Done.
if (!plan.getStatus().startsWith("Done")) {
if (!status.equals(status_error)) {
if (plan.getStatus().startsWith("[ERROR]")) {
plan_status_map.put(plan.getPlan_id(), status_error);
} else {
//in progress
if (status.equals(status_ok)) {
plan_status_map.put(plan.getPlan_id(), status_ip);
}
}
}
}
}
}
for (PlanInfo plan : planList) {
String status = plan_status_map.remove(plan.getPlan_id());
if (status != null) {
if (plan.getOperation().equals("add")) {
plan.setOperation(op_add);
} else if (plan.getOperation().equals("del")) {
plan.setOperation(op_remove);
} else {
plan.setOperation(op_recover);
}
plan.setStatus(status);
plans.add(plan);
}
}
} catch (Exception e) {
resp.setStatus(100);
resp.setMessage("db query exception!");
e.printStackTrace();
return resp;
} finally {
util.releaseConn();
}
resp.setPlans(plans);
resp.setMessage("success");
resp.setStatus(0);
return resp;
}
Aggregations