Search in sources :

Example 11 with NodeModel

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);
}
Also used : BaseNodeModel(io.jpom.model.BaseNodeModel) NodeModel(io.jpom.model.data.NodeModel) NodeService(io.jpom.service.node.NodeService)

Example 12 with NodeModel

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) ServerWhitelist(io.jpom.model.data.ServerWhitelist) ServerConfigBean(io.jpom.system.ServerConfigBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Feature(io.jpom.permission.Feature) ProjectInfoCacheService(io.jpom.service.node.ProjectInfoCacheService) JsonMessage(cn.jiangzeyin.common.JsonMessage) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpUtil(cn.hutool.http.HttpUtil) BaseEnum(io.jpom.model.BaseEnum) OutGivingRun(io.jpom.outgiving.OutGivingRun) BaseNodeModel(io.jpom.model.BaseNodeModel) OutGivingServer(io.jpom.service.node.OutGivingServer) MethodFeature(io.jpom.permission.MethodFeature) NodeForward(io.jpom.common.forward.NodeForward) ClassFeature(io.jpom.permission.ClassFeature) MediaType(org.springframework.http.MediaType) NodeModel(io.jpom.model.data.NodeModel) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Set(java.util.Set) IOException(java.io.IOException) AfterOpt(io.jpom.model.AfterOpt) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) File(java.io.File) BooleanUtil(cn.hutool.core.util.BooleanUtil) OutGivingModel(io.jpom.model.data.OutGivingModel) NodeUrl(io.jpom.common.forward.NodeUrl) Objects(java.util.Objects) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) ValidatorRule(cn.jiangzeyin.common.validator.ValidatorRule) List(java.util.List) ValidatorItem(cn.jiangzeyin.common.validator.ValidatorItem) StringUtil(io.jpom.util.StringUtil) Convert(cn.hutool.core.convert.Convert) ConfigBean(io.jpom.system.ConfigBean) FileUtil(cn.hutool.core.io.FileUtil) JSONObject(com.alibaba.fastjson.JSONObject) BaseServerController(io.jpom.common.BaseServerController) Assert(org.springframework.util.Assert) BaseNodeModel(io.jpom.model.BaseNodeModel) NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) OutGivingNodeProject(io.jpom.model.data.OutGivingNodeProject) OutGivingModel(io.jpom.model.data.OutGivingModel) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with NodeModel

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);
    }
}
Also used : UserModel(io.jpom.model.data.UserModel) NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject)

Example 14 with NodeModel

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, "操作成功");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) NodeModel(io.jpom.model.data.NodeModel) PostMapping(org.springframework.web.bind.annotation.PostMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 15 with NodeModel

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);
}
Also used : NodeModel(io.jpom.model.data.NodeModel) JSONObject(com.alibaba.fastjson.JSONObject) SshModel(io.jpom.model.data.SshModel) GetMapping(org.springframework.web.bind.annotation.GetMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Aggregations

NodeModel (io.jpom.model.data.NodeModel)64 JSONObject (com.alibaba.fastjson.JSONObject)27 Feature (io.jpom.permission.Feature)23 MethodFeature (io.jpom.permission.MethodFeature)23 ClassFeature (io.jpom.permission.ClassFeature)22 UserModel (io.jpom.model.data.UserModel)17 StrUtil (cn.hutool.core.util.StrUtil)12 NodeService (io.jpom.service.node.NodeService)12 Collectors (java.util.stream.Collectors)12 JsonMessage (cn.jiangzeyin.common.JsonMessage)11 List (java.util.List)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 CollUtil (cn.hutool.core.collection.CollUtil)9 DefaultSystemLog (cn.jiangzeyin.common.DefaultSystemLog)9 NodeForward (io.jpom.common.forward.NodeForward)8 NodeUrl (io.jpom.common.forward.NodeUrl)8 Assert (org.springframework.util.Assert)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 JSONArray (com.alibaba.fastjson.JSONArray)7 BaseServerController (io.jpom.common.BaseServerController)7