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();
}
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();
}
}
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();
}
}
Aggregations