@Override public Response path(Request request) { //返回密码文件的路径... return Response.response(request).setSuccess(true) .setExitCode(ExitCode.SUCCESS_EXIT.getValue()) .setMessage(Constants.JOBX_HOME) .end(); }
@Override public Response execute(final Request request) { String command = request.getParams().getString(Constants.PARAM_COMMAND_KEY); String pid = request.getParams().getString(Constants.PARAM_PID_KEY); Integer timeout = request.getTimeOut(); String execUser = request.getParams().getString(Constants.PARAM_EXECUSER_KEY); if (logger.isInfoEnabled()) { logger.info("[JobX]:execute:{},pid:{}", command, pid); } Response response = Response.response(request); JobXProcess jobXProcess = new JobXProcess(command,timeout,pid,execUser); processMap.put(pid,jobXProcess); try { response.setExitCode(jobXProcess.start()); }catch (Exception e) { response.setExitCode(-1); }finally { String message = jobXProcess.getLogMessage(); response.setMessage(message); response.end(); jobXProcess.deleteExecShell(); //todo 得确保server和agent是连接的状态才可以清理log... jobXProcess.deleteLog(); processMap.remove(pid); } return response; }
@Override public Response macId(Request request) { String guid = getMacId(); Response response = Response.response(request).end(); if (notEmpty(guid)) { return response.setMessage(guid).setSuccess(true).setExitCode(ExitCode.SUCCESS_EXIT.getValue()); } return response.setSuccess(false).setExitCode(ExitCode.ERROR_EXIT.getValue()); }
@Override public Response proxy(Request request) { if (this.client == null) { this.client = ExtensionLoader.load(Client.class); } String proxyHost = request.getParams().getString(Constants.PARAM_PROXYHOST_KEY); String proxyPort = request.getParams().getString(Constants.PARAM_PROXYPORT_KEY); String proxyAction = request.getParams().getString(Constants.PARAM_PROXYACTION_KEY); String proxyPassword = request.getParams().getString(Constants.PARAM_PROXYPASSWORD_KEY); //其他参数.... String proxyParams = request.getParams().getString(Constants.PARAM_PROXYPARAMS_KEY); HashMap<String, Object> params = new HashMap<String, Object>(0); if (CommonUtils.notEmpty(proxyParams)) { params = (HashMap<String, Object>) JSON.parse(proxyParams); } Request proxyReq = Request.request(proxyHost, toInt(proxyPort), Action.findByName(proxyAction), proxyPassword, request.getTimeOut(), null).setParams(params); Response response; try { response = this.client.sentSync(proxyReq); } catch (Exception e) { e.printStackTrace(); response = Response.response(request); response.setExitCode(ExitCode.ERROR_EXIT.getValue()) .setMessage("[JobX]:proxy error:" + e.getLocalizedMessage()) .setSuccess(false) .end(); } return response; }
.setResult(result) .setExitCode(ExitCode.ERROR_PASSWORD.getValue()) .setMessage(ExitCode.ERROR_PASSWORD.getDescription()) .end();
@Override public Response password(Request request) { String newPassword = request.getParams().getString(Constants.PARAM_NEWPASSWORD_KEY); Response response = Response.response(request); if (isEmpty(newPassword)) { return response.setSuccess(false).setExitCode(ExitCode.SUCCESS_EXIT.getValue()).setMessage("密码不能为空").end(); } //把老的注册删除 unRegister(request.getHost(),request.getPort()); SystemPropertyUtils.setProperty(Constants.PARAM_JOBX_PASSWORD_KEY, newPassword); IOUtils.writeText(Constants.JOBX_PASSWORD_FILE, newPassword, Constants.CHARSET_UTF8); //最新密码信息注册进来 register(request.getHost(),request.getPort()); return response.setSuccess(true).setExitCode(ExitCode.SUCCESS_EXIT.getValue()).end(); }