use of ngse.org.JsonRPCResponseBase 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.JsonRPCResponseBase in project MSEC by Tencent.
the class DownloadDevGO method doStep2.
private JsonRPCResponseBase doStep2(DevPackage request) {
JsonRPCResponseBase response = new JsonRPCResponseBase();
Logger logger = Logger.getLogger(DownloadDevGO.class);
HttpSession session = getHttpRequest().getSession();
DevPackage plan = (DevPackage) session.getAttribute("DevPackage");
if (plan == null) {
plan = new DevPackage();
session.setAttribute("DevPackage", plan);
}
//制作tar包,这里还是同步的在当前线程完成,必要的话可以用另外一个
//线程异步的完成。
logger.info("begin making dev package...");
PackDevFile packDevFile = new PackDevFile(plan, getServlet().getServletContext());
packDevFile.run();
if (!packDevFile.getResultString().equals("success")) {
response.setMessage(packDevFile.getResultString());
response.setStatus(100);
return response;
}
String fileName = packDevFile.getOutputFileName();
logger.info("dev package path:" + fileName);
File f = new File(fileName);
String length = String.format("%d", f.length());
//将文件内容直接返回,注意MIME 类型,且exec函数应该返回null
getHttpResponse().setHeader("Content-disposition", "attachment;filename=" + new File(fileName).getName());
// set the MIME type.
getHttpResponse().setContentType("application/x-gzip-compressed");
getHttpResponse().setHeader("Content_Length", length);
try {
ServletOutputStream out = getHttpResponse().getOutputStream();
FileInputStream fileInputStream = new FileInputStream(f);
byte[] buf = new byte[10240];
while (true) {
int len = fileInputStream.read(buf);
if (len <= 0) {
break;
}
out.write(buf, 0, len);
}
out.flush();
out.close();
fileInputStream.close();
f.delete();
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
use of ngse.org.JsonRPCResponseBase 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.JsonRPCResponseBase in project MSEC by Tencent.
the class DownloadDevGO method exec.
public JsonRPCResponseBase exec(DevPackage request) {
JsonRPCResponseBase response = new JsonRPCResponseBase();
String result = checkIdentity();
if (!result.equals("success")) {
response.setStatus(99);
response.setMessage(result);
return response;
}
if (request.getSecond_level_service_name() == null || request.getSecond_level_service_name().length() < 1 || request.getFirst_level_service_name() == null || request.getFirst_level_service_name().length() < 1 || request.getStep_number() == null) {
response.setMessage("input is invalid");
response.setStatus(100);
return response;
}
if (request.getStep_number() == 1) {
return doStep1(request);
}
if (request.getStep_number() == 2) {
return doStep2(request);
}
response.setMessage("success");
response.setStatus(0);
return response;
}
use of ngse.org.JsonRPCResponseBase 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();
}
}
Aggregations