use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class SshInstallAgentController method installAgentSubmit.
@RequestMapping(value = "installAgentSubmit.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
@SystemPermission
public String installAgentSubmit(@ValidatorItem(value = ValidatorRule.NOT_BLANK) String id, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "节点数据") String nodeData, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "安装路径") String path) throws Exception {
//
SshModel sshModel = sshService.getByKey(id, false);
Objects.requireNonNull(sshModel, "没有找到对应ssh");
// 判断输入的节点信息
NodeModel nodeModel = this.getNodeModel(nodeData, sshModel);
//
ServerConfigBean instance = ServerConfigBean.getInstance();
String tempFilePath = instance.getUserTempPath().getAbsolutePath();
JSONObject agentFile = this.getAgentFile();
String filePath = agentFile.getString("path");
//
File outFle = FileUtil.file(tempFilePath, Type.Agent.name() + "_" + IdUtil.fastSimpleUUID());
try {
String tag = this.unZipGetTag(filePath, outFle);
//
this.readNodeAuthorize(outFle, nodeModel);
// 查询远程是否运行
Assert.state(!sshService.checkSshRun(sshModel, tag), "对应服务器中已经存在 Jpom 插件端,不需要再次安装啦");
// 上传文件到服务器
sshService.uploadDir(sshModel, path, outFle);
//
String shPtah = FileUtil.normalize(path + StrUtil.SLASH + Type.Agent.name() + ".sh");
String chmod = getParameter("chmod");
if (StrUtil.isEmptyOrUndefined(chmod)) {
chmod = StrUtil.EMPTY;
} else {
chmod = StrUtil.format("{} {} && ", chmod, shPtah);
}
String command = StrUtil.format("{}bash {} start upgrade", chmod, shPtah);
String result = sshService.exec(sshModel, command);
DefaultSystemLog.getLog().debug("ssh install agent node {} {}", command, result);
// 休眠 5 秒, 尝试 5 次
int waitCount = getParameterInt("waitCount", 5);
this.loopCheck(waitCount, nodeModel, sshModel, path, result);
// 绑定关系
nodeModel.setSshId(sshModel.getId());
nodeService.insert(nodeModel);
//
return JsonMessage.getString(200, "操作成功:" + result);
} finally {
// 清理资源
FileUtil.del(outFle);
}
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class NodeProjectInfoController method syncProject.
/**
* 同步节点项目
*
* @return json
*/
@GetMapping(value = "sync_project", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(cls = ClassFeature.PROJECT, method = MethodFeature.DEL)
public String syncProject(String nodeId) {
NodeModel nodeModel = nodeService.getByKey(nodeId);
Assert.notNull(nodeModel, "对应的节点不存在");
int count = projectInfoCacheService.delCache(nodeId, getRequest());
String msg = projectInfoCacheService.syncExecuteNode(nodeModel);
return JsonMessage.getString(200, "主动清除:" + count + StrUtil.SPACE + msg);
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class NodeUpdateController method confirmFastInstall.
@GetMapping(value = "confirm_fast_install.json", produces = MediaType.APPLICATION_JSON_VALUE)
public String confirmFastInstall(@ValidatorItem String id, @ValidatorItem String ip, int port) {
JSONObject receiveCache = NodeInfoController.getReceiveCache(id);
Assert.notNull(receiveCache, "没有对应的缓存信息");
JSONArray jsonArray = receiveCache.getJSONArray("canUseNode");
Assert.notEmpty(jsonArray, "没有对应的缓存信息:-1");
Optional<NodeModel> any = jsonArray.stream().map(o -> {
if (o instanceof NodeModel) {
return (NodeModel) o;
}
JSONObject jsonObject = (JSONObject) o;
return jsonObject.toJavaObject(NodeModel.class);
}).filter(nodeModel -> StrUtil.equals(nodeModel.getUrl(), StrUtil.format("{}:{}", ip, port))).findAny();
Assert.state(any.isPresent(), "ip 地址信息不正确");
NodeModel nodeModel = any.get();
try {
nodeService.testNode(nodeModel);
} catch (Exception e) {
DefaultSystemLog.getLog().warn("测试结果:{} {}", nodeModel.getUrl(), e.getMessage());
return JsonMessage.getString(500, "节点连接失败:" + e.getMessage());
}
// 插入
boolean exists = nodeService.existsByUrl(nodeModel.getUrl(), nodeModel.getWorkspaceId(), null);
Assert.state(!exists, "对应的节点已经存在拉:" + nodeModel.getUrl());
nodeService.insert(nodeModel);
// 更新结果
receiveCache.put("type", "success");
return JsonMessage.getString(200, "安装成功", NodeInfoController.listReceiveCache(null));
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class EditProjectController method saveProject.
/**
* 保存项目
*
* @param id id
* @return json
*/
@RequestMapping(value = "saveProject", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String saveProject(String id) {
// 防止和Jpom冲突
if (StrUtil.isNotEmpty(ConfigBean.getInstance().applicationTag) && ConfigBean.getInstance().applicationTag.equalsIgnoreCase(id)) {
return JsonMessage.getString(401, "当前项目id已经被Jpom占用");
}
NodeModel node = getNode();
JsonMessage<Object> request = NodeForward.request(node, getRequest(), NodeUrl.Manage_SaveProject);
if (request.getCode() == HttpStatus.OK.value()) {
projectInfoCacheService.syncNode(node, id);
}
return request.toString();
}
use of io.jpom.model.data.NodeModel in project Jpom by dromara.
the class ProjectManageControl method deleteProject.
/**
* 删除项目
*
* @param id id
* @return json
*/
@PostMapping(value = "deleteProject", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String deleteProject(@ValidatorItem(value = ValidatorRule.NOT_BLANK) String id, String copyId) {
NodeModel nodeModel = getNode();
HttpServletRequest servletRequest = getRequest();
if (StrUtil.isEmpty(copyId)) {
// 检查节点分发
List<OutGivingModel> outGivingModels = outGivingServer.listByWorkspace(servletRequest);
if (outGivingModels != null) {
boolean match = outGivingModels.stream().anyMatch(outGivingModel -> outGivingModel.checkContains(nodeModel.getId(), id));
Assert.state(!match, "当前项目存在节点分发,不能直接删除");
// for (OutGivingModel outGivingModel : outGivingModels) {
// if (outGivingModel.checkContains(nodeModel.getId(), id)) {
// return JsonMessage.getString(405, "当前项目存在节点分发,不能直接删除");
// }
// }
}
//
List<MonitorModel> monitorModels = monitorService.listByWorkspace(servletRequest);
if (monitorModels != null) {
boolean match = monitorModels.stream().anyMatch(monitorModel -> monitorModel.checkNodeProject(nodeModel.getId(), id));
// if (monitorService.checkProject(nodeModel.getId(), id)) {
// return JsonMessage.getString(405, );
// }
Assert.state(!match, "当前项目存在监控项,不能直接删除");
}
boolean releaseMethod = buildService.checkReleaseMethod(nodeModel.getId() + StrUtil.COLON + id, servletRequest, BuildReleaseMethod.Project);
Assert.state(!releaseMethod, "当前项目存在构建项,不能直接删除");
}
JsonMessage<Object> request = NodeForward.request(nodeModel, servletRequest, NodeUrl.Manage_DeleteProject);
if (request.getCode() == HttpStatus.OK.value()) {
//
projectInfoCacheService.syncNode(nodeModel);
}
return request.toString();
}
Aggregations