use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class BaseNodeService method listPageNode.
public PageResultDto<T> listPageNode(HttpServletRequest request) {
// 验证工作空间权限
Map<String, String> paramMap = ServletUtil.getParamMap(request);
String workspaceId = this.getCheckUserWorkspace(request);
paramMap.put("workspaceId", workspaceId);
// 验证节点
String nodeId = paramMap.get(BaseServerController.NODE_ID);
Assert.notNull(nodeId, "没有选择节点ID");
NodeService nodeService = SpringUtil.getBean(NodeService.class);
NodeModel nodeModel = nodeService.getByKey(nodeId);
Assert.notNull(nodeModel, "不存在对应的节点");
paramMap.put("nodeId", nodeId);
return super.listPage(paramMap);
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class OutGivingProjectController method getItemData.
@RequestMapping(value = "getItemData.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String getItemData(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "id error") String id) {
HttpServletRequest request = getRequest();
String workspaceId = outGivingServer.getCheckUserWorkspace(request);
OutGivingModel outGivingServerItem = outGivingServer.getByKey(id, request);
Objects.requireNonNull(outGivingServerItem, "没有数据");
List<OutGivingNodeProject> outGivingNodeProjectList = outGivingServerItem.outGivingNodeProjectList();
List<JSONObject> collect = outGivingNodeProjectList.stream().map(outGivingNodeProject -> {
NodeModel nodeModel = nodeService.getByKey(outGivingNodeProject.getNodeId());
JSONObject jsonObject = new JSONObject();
jsonObject.put("nodeId", outGivingNodeProject.getNodeId());
jsonObject.put("projectId", outGivingNodeProject.getProjectId());
jsonObject.put("nodeName", nodeModel.getName());
jsonObject.put("id", BaseNodeModel.fullId(workspaceId, outGivingNodeProject.getNodeId(), outGivingNodeProject.getProjectId()));
// set projectStatus property
// NodeModel node = nodeService.getItem(outGivingNodeProject.getNodeId());
// Project Status: data.pid > 0 means running
JSONObject projectStatus = JsonMessage.toJson(200, "success");
if (nodeModel.isOpenStatus()) {
JSONObject projectInfo = null;
try {
projectInfo = projectInfoCacheService.getItem(nodeModel, outGivingNodeProject.getProjectId());
projectStatus = NodeForward.requestBySys(nodeModel, NodeUrl.Manage_GetProjectStatus, "id", outGivingNodeProject.getProjectId()).toJson();
} catch (Exception e) {
jsonObject.put("errorMsg", "error " + e.getMessage());
}
if (projectInfo != null) {
jsonObject.put("projectName", projectInfo.getString("name"));
}
} else {
jsonObject.put("errorMsg", "节点未启用");
}
JSONObject data = projectStatus.getJSONObject("data");
if (data != null && data.getInteger("pId") != null) {
jsonObject.put("projectStatus", data.getIntValue("pId") > 0);
} else {
jsonObject.put("projectStatus", false);
}
jsonObject.put("outGivingStatus", outGivingNodeProject.getStatusMsg());
jsonObject.put("outGivingResult", outGivingNodeProject.getResult());
jsonObject.put("lastTime", outGivingNodeProject.getLastOutGivingTime());
return jsonObject;
}).collect(Collectors.toList());
return JsonMessage.getString(200, "", collect);
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class ScriptController method syncNodeScript.
private void syncNodeScript(ScriptModel scriptModel, String oldNode) {
List<String> oldNodeIds = StrUtil.splitTrim(oldNode, StrUtil.COMMA);
List<String> newNodeIds = StrUtil.splitTrim(scriptModel.getNodeIds(), StrUtil.COMMA);
Collection<String> delNode = CollUtil.subtract(oldNodeIds, newNodeIds);
UserModel user = getUser();
// 删除
this.syncDelNodeScript(scriptModel, user, delNode);
// 更新
for (String newNodeId : newNodeIds) {
NodeModel byKey = nodeService.getByKey(newNodeId, getRequest());
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", scriptModel.getId());
jsonObject.put("type", "sync");
jsonObject.put("context", scriptModel.getContext());
jsonObject.put("autoExecCron", scriptModel.getAutoExecCron());
jsonObject.put("defArgs", scriptModel.getDefArgs());
jsonObject.put("description", scriptModel.getDescription());
jsonObject.put("name", scriptModel.getName());
jsonObject.put("workspaceId", scriptModel.getWorkspaceId());
JsonMessage<String> request = NodeForward.request(byKey, NodeUrl.Script_Save, user, jsonObject);
Assert.state(request.getCode() == 200, "处理 " + byKey.getName() + " 节点同步脚本失败" + request.getMsg());
nodeScriptServer.syncNode(byKey);
}
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class SshController method del.
@PostMapping(value = "del.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String del(@ValidatorItem(value = ValidatorRule.NOT_BLANK) String id) {
HttpServletRequest request = getRequest();
boolean checkSsh = buildInfoService.checkReleaseMethodByLike(id, request, BuildReleaseMethod.Ssh);
Assert.state(!checkSsh, "当前ssh存在构建项,不能删除");
// 判断是否绑定节点
List<NodeModel> nodeBySshId = nodeService.getNodeBySshId(id);
Assert.state(CollUtil.isEmpty(nodeBySshId), "当前ssh被节点绑定,不能删除");
sshService.delByKey(id, request);
//
int logCount = sshTerminalExecuteLogService.delByWorkspace(request, entity -> entity.set("sshId", id));
return JsonMessage.getString(200, "操作成功");
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class SshController method checkAgent.
/**
* 检查 ssh 是否安装插件端
*
* @param ids ids
* @return json
*/
@GetMapping(value = "check_agent.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String checkAgent(String ids) {
List<SshModel> sshModels = sshService.listById(StrUtil.split(ids, StrUtil.COMMA), getRequest());
Assert.notEmpty(sshModels, "没有任何节点信息");
JSONObject result = new JSONObject();
for (SshModel sshModel : sshModels) {
List<NodeModel> nodeBySshId = nodeService.getNodeBySshId(sshModel.getId());
JSONObject data = new JSONObject();
NodeModel nodeModel = CollUtil.getFirst(nodeBySshId);
SshModel model = sshService.getByKey(sshModel.getId(), false);
try {
if (nodeModel == null) {
Integer pid = sshService.checkSshRunPid(model, Type.Agent.getTag());
data.put("pid", ObjectUtil.defaultIfNull(pid, 0));
data.put("ok", true);
} else {
data.put("nodeId", nodeModel.getId());
data.put("nodeName", nodeModel.getName());
}
//
String javaVersion = sshService.checkCommand(model, "java");
data.put("javaVersion", javaVersion);
} catch (Exception e) {
DefaultSystemLog.getLog().error("检查运行状态异常:{}", e.getMessage());
data.put("error", e.getMessage());
}
result.put(sshModel.getId(), data);
}
return JsonMessage.getString(200, "", result);
}
Aggregations