use of io.jpom.model.data.NodeScriptModel in project Jpom by dromara.
the class NodeScriptServer method deleteItem.
@Override
public void deleteItem(String id) {
NodeScriptModel nodeScriptModel = getItem(id);
if (nodeScriptModel != null) {
FileUtil.del(nodeScriptModel.getFile(true).getParentFile());
}
super.deleteItem(id);
String taskId = "script:" + id;
CronUtils.remove(taskId);
}
use of io.jpom.model.data.NodeScriptModel in project Jpom by dromara.
the class ScriptController method upload.
@RequestMapping(value = "upload.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String upload() throws IOException {
MultipartFileBuilder multipartFileBuilder = createMultipart().addFieldName("file").setFileExt("bat", "sh");
multipartFileBuilder.setSavePath(AgentConfigBean.getInstance().getTempPathName());
multipartFileBuilder.setUseOriginalFilename(true);
String path = multipartFileBuilder.save();
File file = FileUtil.file(path);
String context = FileUtil.readString(path, ExtConfigBean.getInstance().getConsoleLogCharset());
Assert.hasText(context, "脚本内容为空");
String name = file.getName();
String id = SecureUtil.sha1(name);
NodeScriptModel eModel = nodeScriptServer.getItem(id);
if (eModel != null) {
return JsonMessage.getString(405, "对应脚本模板已经存在啦");
}
eModel = new NodeScriptModel();
eModel.setId(id);
eModel.setName(name);
eModel.setWorkspaceId(getWorkspaceId());
eModel.setContext(context);
file = eModel.getFile(true);
if (file.exists() || file.isDirectory()) {
return JsonMessage.getString(405, "当地id路径文件已经存在来,请修改");
}
nodeScriptServer.addItem(eModel);
return JsonMessage.getString(200, "导入成功");
}
use of io.jpom.model.data.NodeScriptModel in project Jpom by dromara.
the class IndexController method status.
/**
* 返回节点项目状态信息
*
* @return array
*/
@RequestMapping(value = "status", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String status() {
List<NodeProjectInfoModel> nodeProjectInfoModels = projectInfoService.list();
List<NodeScriptModel> list = nodeScriptServer.list();
JSONObject jsonObject = new JSONObject();
jsonObject.put("javaVirtualCount", JvmUtil.getJavaVirtualCount());
JpomManifest instance = JpomManifest.getInstance();
jsonObject.put("osName", instance.getOsName());
jsonObject.put("jpomVersion", instance.getVersion());
jsonObject.put("javaVersion", SystemUtil.getJavaRuntimeInfo().getVersion());
// 获取JVM中内存总大小
long totalMemory = SystemUtil.getTotalMemory();
jsonObject.put("totalMemory", FileUtil.readableFileSize(totalMemory));
//
long freeMemory = SystemUtil.getFreeMemory();
jsonObject.put("freeMemory", FileUtil.readableFileSize(freeMemory));
//
jsonObject.put("count", CollUtil.size(nodeProjectInfoModels));
jsonObject.put("scriptCount", CollUtil.size(list));
// 运行时间
jsonObject.put("runTime", instance.getUpTimeStr());
jsonObject.put("runTimeLong", instance.getUpTime());
return JsonMessage.getString(200, "", jsonObject);
}
use of io.jpom.model.data.NodeScriptModel in project Jpom by dromara.
the class DslScriptBuilder method create.
private static DslScriptBuilder create(DslYmlDto.BaseProcess scriptProcess, NodeProjectInfoModel nodeProjectInfoModel, String log) {
NodeScriptServer nodeScriptServer = SpringUtil.getBean(NodeScriptServer.class);
String scriptId = scriptProcess.getScriptId();
NodeScriptModel item = nodeScriptServer.getItem(scriptId);
File scriptFile;
if (item == null) {
scriptFile = FileUtil.file(nodeProjectInfoModel.allLib(), scriptId);
if (!FileUtil.isFile(scriptFile)) {
return null;
}
} else {
scriptFile = DslScriptBuilder.initScriptFile(item, nodeProjectInfoModel);
}
DslScriptBuilder builder = new DslScriptBuilder(scriptProcess.getScriptArgs(), log);
builder.setEnvironment(DslScriptBuilder.environment(nodeProjectInfoModel));
builder.setScriptFile(scriptFile);
return builder;
}
use of io.jpom.model.data.NodeScriptModel in project Jpom by dromara.
the class ScriptController method getNowLog.
/**
* 获取的日志
*
* @param id id
* @param executeId 执行ID
* @param line 需要获取的行号
* @return json
*/
@RequestMapping(value = "log", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String getNowLog(@ValidatorItem() String id, @ValidatorItem() String executeId, @ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "line") int line) {
NodeScriptModel item = nodeScriptServer.getItem(id);
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