Search in sources :

Example 1 with ScriptModel

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();
    }
}
Also used : UserModel(io.jpom.model.data.UserModel) ScriptModel(io.jpom.model.script.ScriptModel) ScriptExecuteLogModel(io.jpom.model.script.ScriptExecuteLogModel)

Example 2 with ScriptModel

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());
}
Also used : ScriptModel(io.jpom.model.script.ScriptModel) ScriptExecuteLogServer(io.jpom.service.script.ScriptExecuteLogServer) ScriptServer(io.jpom.service.script.ScriptServer)

Example 3 with ScriptModel

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, "修改成功");
}
Also used : ScriptModel(io.jpom.model.script.ScriptModel) HttpServletRequest(javax.servlet.http.HttpServletRequest) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ScriptModel

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, "删除成功");
}
Also used : ScriptModel(io.jpom.model.script.ScriptModel) File(java.io.File) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with ScriptModel

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);
}
Also used : ScriptModel(io.jpom.model.script.ScriptModel) JSONObject(com.alibaba.fastjson.JSONObject) File(java.io.File) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ScriptModel (io.jpom.model.script.ScriptModel)7 ClassFeature (io.jpom.permission.ClassFeature)5 Feature (io.jpom.permission.Feature)5 MethodFeature (io.jpom.permission.MethodFeature)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 File (java.io.File)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 JSONObject (com.alibaba.fastjson.JSONObject)1 UserModel (io.jpom.model.data.UserModel)1 ScriptExecuteLogModel (io.jpom.model.script.ScriptExecuteLogModel)1 ScriptExecuteLogServer (io.jpom.service.script.ScriptExecuteLogServer)1 ScriptServer (io.jpom.service.script.ScriptServer)1