Search in sources :

Example 1 with ScriptExecuteLogCacheModel

use of io.jpom.model.node.ScriptExecuteLogCacheModel in project Jpom by dromara.

the class NodeScriptLogController method del.

/**
 * 删除日志
 *
 * @param id        模版ID
 * @param executeId 日志ID
 * @return json
 */
@RequestMapping(value = "del", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String del(@ValidatorItem String id, String executeId) {
    NodeModel node = getNode();
    ScriptExecuteLogCacheModel scriptExecuteLogCacheModel = new ScriptExecuteLogCacheModel();
    scriptExecuteLogCacheModel.setId(executeId);
    scriptExecuteLogCacheModel.setScriptId(id);
    scriptExecuteLogCacheModel.setNodeId(node.getId());
    ScriptExecuteLogCacheModel executeLogModel = nodeScriptExecuteLogServer.queryByBean(scriptExecuteLogCacheModel);
    Assert.notNull(executeLogModel, "没有对应的执行日志");
    JsonMessage<Object> request = NodeForward.request(node, getRequest(), NodeUrl.SCRIPT_DEL_LOG);
    if (request.getCode() == HttpStatus.OK.value()) {
        nodeScriptExecuteLogServer.delByKey(executeId);
    }
    return request.toString();
}
Also used : NodeModel(io.jpom.model.data.NodeModel) ScriptExecuteLogCacheModel(io.jpom.model.node.ScriptExecuteLogCacheModel) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ScriptExecuteLogCacheModel

use of io.jpom.model.node.ScriptExecuteLogCacheModel in project Jpom by dromara.

the class NodeScriptExecuteLogServer method syncExecuteNodeInc.

/**
 * 同步执行 同步节点信息(增量)
 *
 * @param nodeModel 节点信息
 * @return json
 */
public Collection<String> syncExecuteNodeInc(NodeModel nodeModel) {
    String nodeModelName = nodeModel.getName();
    if (!nodeModel.isOpenStatus()) {
        DefaultSystemLog.getLog().debug("{} 节点未启用", nodeModelName);
        return null;
    }
    try {
        JSONArray jsonArray = this.getLitDataArray(nodeModel);
        if (CollUtil.isEmpty(jsonArray)) {
            // 
            return null;
        }
        // 
        List<ScriptExecuteLogCacheModel> models = jsonArray.toJavaList(this.tClass).stream().filter(item -> {
            // 检查对应的工作空间 是否存在
            return workspaceService.exists(new WorkspaceModel(item.getWorkspaceId()));
        }).filter(item -> {
            // 避免重复同步
            return StrUtil.equals(nodeModel.getWorkspaceId(), item.getWorkspaceId());
        }).collect(Collectors.toList());
        // 设置 临时缓存,便于放行检查
        BaseServerController.resetInfo(UserModel.EMPTY);
        // 
        models.forEach(NodeScriptExecuteLogServer.super::upsert);
        String format = StrUtil.format("{} 节点拉取到 {} 个执行记录,更新 {} 个执行记录", nodeModelName, CollUtil.size(jsonArray), CollUtil.size(models));
        DefaultSystemLog.getLog().debug(format);
        return models.stream().map(BaseDbModel::getId).collect(Collectors.toList());
    } catch (Exception e) {
        this.checkException(e, nodeModelName);
        return null;
    } finally {
        BaseServerController.removeEmpty();
    }
}
Also used : WorkspaceService(io.jpom.service.system.WorkspaceService) NodeForward(io.jpom.common.forward.NodeForward) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) Collection(java.util.Collection) BaseNodeService(io.jpom.service.h2db.BaseNodeService) Collectors(java.util.stream.Collectors) io.jpom.model.data(io.jpom.model.data) NodeUrl(io.jpom.common.forward.NodeUrl) JsonMessage(cn.jiangzeyin.common.JsonMessage) JSONArray(com.alibaba.fastjson.JSONArray) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) Service(org.springframework.stereotype.Service) NodeService(io.jpom.service.node.NodeService) JSONObject(com.alibaba.fastjson.JSONObject) ScriptExecuteLogCacheModel(io.jpom.model.node.ScriptExecuteLogCacheModel) BaseServerController(io.jpom.common.BaseServerController) HttpStatus(cn.hutool.http.HttpStatus) BaseDbModel(io.jpom.model.BaseDbModel) JSONArray(com.alibaba.fastjson.JSONArray) ScriptExecuteLogCacheModel(io.jpom.model.node.ScriptExecuteLogCacheModel)

Example 3 with ScriptExecuteLogCacheModel

use of io.jpom.model.node.ScriptExecuteLogCacheModel in project Jpom by dromara.

the class NodeScriptHandler method createLog.

/**
 * 创建执行日志
 *
 * @param attributes 参数属性
 * @return 执行ID
 */
private String createLog(Map<String, Object> attributes) {
    NodeModel nodeInfo = (NodeModel) attributes.get("nodeInfo");
    UserModel userModel = (UserModel) attributes.get("userInfo");
    ScriptCacheModel dataItem = (ScriptCacheModel) attributes.get("dataItem");
    NodeScriptExecuteLogServer logServer = SpringUtil.getBean(NodeScriptExecuteLogServer.class);
    NodeScriptServer nodeScriptServer = SpringUtil.getBean(NodeScriptServer.class);
    // 
    try {
        BaseServerController.resetInfo(userModel);
        // 
        ScriptCacheModel scriptCacheModel = new ScriptCacheModel();
        scriptCacheModel.setId(dataItem.getId());
        scriptCacheModel.setLastRunUser(userModel.getId());
        nodeScriptServer.update(scriptCacheModel);
        // 
        ScriptExecuteLogCacheModel scriptExecuteLogCacheModel = new ScriptExecuteLogCacheModel();
        scriptExecuteLogCacheModel.setScriptId(dataItem.getScriptId());
        scriptExecuteLogCacheModel.setNodeId(nodeInfo.getId());
        scriptExecuteLogCacheModel.setScriptName(dataItem.getName());
        scriptExecuteLogCacheModel.setTriggerExecType(0);
        scriptExecuteLogCacheModel.setWorkspaceId(nodeInfo.getWorkspaceId());
        logServer.insert(scriptExecuteLogCacheModel);
        return scriptExecuteLogCacheModel.getId();
    } finally {
        BaseServerController.removeAll();
    }
}
Also used : UserModel(io.jpom.model.data.UserModel) NodeModel(io.jpom.model.data.NodeModel) NodeScriptServer(io.jpom.service.node.script.NodeScriptServer) NodeScriptExecuteLogServer(io.jpom.service.node.script.NodeScriptExecuteLogServer) ScriptExecuteLogCacheModel(io.jpom.model.node.ScriptExecuteLogCacheModel) ScriptCacheModel(io.jpom.model.node.ScriptCacheModel)

Aggregations

ScriptExecuteLogCacheModel (io.jpom.model.node.ScriptExecuteLogCacheModel)3 NodeModel (io.jpom.model.data.NodeModel)2 CollUtil (cn.hutool.core.collection.CollUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 HttpStatus (cn.hutool.http.HttpStatus)1 DefaultSystemLog (cn.jiangzeyin.common.DefaultSystemLog)1 JsonMessage (cn.jiangzeyin.common.JsonMessage)1 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 BaseServerController (io.jpom.common.BaseServerController)1 NodeForward (io.jpom.common.forward.NodeForward)1 NodeUrl (io.jpom.common.forward.NodeUrl)1 BaseDbModel (io.jpom.model.BaseDbModel)1 io.jpom.model.data (io.jpom.model.data)1 UserModel (io.jpom.model.data.UserModel)1 ScriptCacheModel (io.jpom.model.node.ScriptCacheModel)1 ClassFeature (io.jpom.permission.ClassFeature)1 Feature (io.jpom.permission.Feature)1 MethodFeature (io.jpom.permission.MethodFeature)1 BaseNodeService (io.jpom.service.h2db.BaseNodeService)1