use of io.jpom.model.script.ScriptModel in project Jpom by dromara.
the class ServerScriptHandler method createLog.
/**
* 创建执行日志
*
* @param attributes 参数属性
* @return 执行ID
*/
private String createLog(Map<String, Object> attributes, ScriptModel scriptModel) {
UserModel userModel = (UserModel) attributes.get("userInfo");
//
try {
BaseServerController.resetInfo(userModel);
//
ScriptModel scriptCacheModel = new ScriptModel();
scriptCacheModel.setId(scriptModel.getId());
scriptCacheModel.setLastRunUser(userModel.getId());
nodeScriptServer.update(scriptCacheModel);
//
ScriptExecuteLogModel scriptExecuteLogCacheModel = logServer.create(scriptModel, 0);
return scriptExecuteLogCacheModel.getId();
} finally {
BaseServerController.removeAll();
}
}
use of io.jpom.model.script.ScriptModel in project Jpom by dromara.
the class ServerScriptHandler method init.
@Override
protected void init(WebSocketSession session, Map<String, Object> attributes) throws URISyntaxException, IOException {
super.init(session, attributes);
//
this.logServer = SpringUtil.getBean(ScriptExecuteLogServer.class);
this.nodeScriptServer = SpringUtil.getBean(ScriptServer.class);
ScriptModel scriptModel = (ScriptModel) attributes.get("dataItem");
this.sendMsg(session, "连接成功:" + scriptModel.getName());
}
use of io.jpom.model.script.ScriptModel in project Jpom by dromara.
the class ScriptController method save.
@RequestMapping(value = "save.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String save(String id, @ValidatorItem String context, @ValidatorItem String name, String autoExecCron, String defArgs, String description, String nodeIds) {
ScriptModel scriptModel = new ScriptModel();
scriptModel.setId(id);
scriptModel.setContext(context);
scriptModel.setName(name);
scriptModel.setNodeIds(nodeIds);
scriptModel.setDescription(description);
scriptModel.setDefArgs(defArgs);
Assert.hasText(scriptModel.getContext(), "内容为空");
//
scriptModel.setAutoExecCron(this.checkCron(autoExecCron));
//
String oldNodeIds = null;
if (StrUtil.isEmpty(id)) {
scriptServer.insert(scriptModel);
} else {
HttpServletRequest request = getRequest();
ScriptModel byKey = scriptServer.getByKey(id, request);
Assert.notNull(byKey, "没有对应的数据");
oldNodeIds = byKey.getNodeIds();
scriptServer.updateById(scriptModel, request);
}
this.syncNodeScript(scriptModel, oldNodeIds);
return JsonMessage.getString(200, "修改成功");
}
use of io.jpom.model.script.ScriptModel in project Jpom by dromara.
the class ScriptLogController method delLog.
/**
* 删除日志
*
* @param id id
* @param executeId 执行ID
* @return json
*/
@RequestMapping(value = "del_log", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String delLog(@ValidatorItem() String id, @ValidatorItem() String executeId) {
ScriptModel item = scriptServer.getByKey(id, getRequest());
Assert.notNull(item, "没有对应数据");
File logFile = item.logFile(executeId);
boolean fastDel = CommandUtil.systemFastDel(logFile);
Assert.state(!fastDel, "删除日志文件失败");
scriptExecuteLogServer.delByKey(executeId);
return JsonMessage.getString(200, "删除成功");
}
use of io.jpom.model.script.ScriptModel in project Jpom by dromara.
the class ScriptLogController method getNowLog.
/**
* 获取的日志
*
* @param id id
* @param executeId 执行ID
* @param line 需要获取的行号
* @return json
*/
@RequestMapping(value = "log", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String getNowLog(@ValidatorItem() String id, @ValidatorItem() String executeId, @ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "line") int line) {
ScriptModel item = scriptServer.getByKey(id, getRequest());
Assert.notNull(item, "没有对应数据");
File logFile = item.logFile(executeId);
Assert.state(FileUtil.isFile(logFile), "日志文件错误");
JSONObject data = FileUtils.readLogFile(logFile, line);
// 运行中
data.put("run", ScriptProcessBuilder.isRun(executeId));
return JsonMessage.getString(200, "ok", data);
}
Aggregations