Search in sources :

Example 1 with NodeModel

use of io.jpom.model.data.NodeModel in project Jpom by dromara.

the class NodeService method unLock.

/**
 * 解锁分配工作空间
 *
 * @param id          节点ID
 * @param workspaceId 工作空间
 */
public void unLock(String id, String workspaceId) {
    NodeModel nodeModel = super.getByKey(id);
    Assert.notNull(nodeModel, "没有对应对节点");
    // 
    WorkspaceModel workspaceModel = workspaceService.getByKey(workspaceId);
    Assert.notNull(workspaceModel, "没有对应对工作空间");
    NodeModel nodeModel1 = new NodeModel();
    nodeModel1.setId(id);
    nodeModel1.setWorkspaceId(workspaceId);
    nodeModel1.setUnLockType(StrUtil.EMPTY);
    nodeModel1.setOpenStatus(1);
    super.update(nodeModel1);
}
Also used : WorkspaceModel(io.jpom.model.data.WorkspaceModel) NodeModel(io.jpom.model.data.NodeModel)

Example 2 with NodeModel

use of io.jpom.model.data.NodeModel in project Jpom by dromara.

the class NodeService method existsByUrl.

public boolean existsByUrl(String url, String workspaceId, String id) {
    // Entity entity = Entity.create();
    // entity.set("url", nodeModel.getUrl());
    // entity.set("workspaceId", workspaceId);
    // if (StrUtil.isNotEmpty(id)) {
    // entity.set("id", StrUtil.format(" <> {}", id));
    // }
    // boolean exists = super.exists(entity);
    // Assert.state(!exists, "对应的节点已经存在啦");
    // 可能出现错误
    NodeModel nodeModel1 = new NodeModel();
    nodeModel1.setUrl(url);
    nodeModel1.setWorkspaceId(workspaceId);
    List<NodeModel> nodeModels = ObjectUtil.defaultIfNull(super.listByBean(nodeModel1), Collections.EMPTY_LIST);
    Optional<NodeModel> any = nodeModels.stream().filter(nodeModel2 -> !StrUtil.equals(id, nodeModel2.getId())).findAny();
    return any.isPresent();
}
Also used : ObjectUtil(cn.hutool.core.util.ObjectUtil) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) ServletUtil(cn.hutool.extra.servlet.ServletUtil) JsonMessage(cn.jiangzeyin.common.JsonMessage) HttpServletRequest(javax.servlet.http.HttpServletRequest) Service(org.springframework.stereotype.Service) BaseGroupService(io.jpom.service.h2db.BaseGroupService) WorkspaceModel(io.jpom.model.data.WorkspaceModel) WorkspaceService(io.jpom.service.system.WorkspaceService) NodeForward(io.jpom.common.forward.NodeForward) SshService(io.jpom.service.node.ssh.SshService) NodeModel(io.jpom.model.data.NodeModel) SpringUtil(cn.jiangzeyin.common.spring.SpringUtil) Collectors(java.util.stream.Collectors) NodeUrl(io.jpom.common.forward.NodeUrl) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) JpomManifest(io.jpom.common.JpomManifest) Const(io.jpom.common.Const) SshModel(io.jpom.model.data.SshModel) Optional(java.util.Optional) Entity(cn.hutool.db.Entity) UserModel(io.jpom.model.data.UserModel) Collections(java.util.Collections) BaseServerController(io.jpom.common.BaseServerController) Validator(cn.hutool.core.lang.Validator) Assert(org.springframework.util.Assert) NodeModel(io.jpom.model.data.NodeModel)

Example 3 with NodeModel

use of io.jpom.model.data.NodeModel in project Jpom by dromara.

the class NodeService method update.

/**
 * 修改 节点
 *
 * @param request 请求对象
 */
public void update(HttpServletRequest request, boolean autoReg) {
    String type = request.getParameter("type");
    boolean create = "add".equalsIgnoreCase(type);
    // 创建对象
    NodeModel nodeModel = ServletUtil.toBean(request, NodeModel.class, true);
    String id = nodeModel.getId();
    if (StrUtil.isNotEmpty(id)) {
        String checkId = StrUtil.replace(id, StrUtil.DASHED, StrUtil.UNDERLINE);
        Validator.validateGeneral(checkId, 2, Const.ID_MAX_LEN, "节点id不能为空并且2-50(英文字母 、数字和下划线)");
    }
    Assert.hasText(nodeModel.getName(), "节点名称 不能为空");
    NodeModel existsNode = super.getByKey(id);
    String workspaceId;
    if (autoReg) {
        if (create) {
            Assert.isNull(existsNode, "对应的节点 id 已经存在啦");
            // 绑定到默认工作空间
            workspaceId = Const.WORKSPACE_DEFAULT_ID;
        } else {
            Assert.notNull(existsNode, "对应的节点不存在");
            workspaceId = existsNode.getWorkspaceId();
        }
    } else {
        workspaceId = this.getCheckUserWorkspace(request);
    }
    nodeModel.setWorkspaceId(workspaceId);
    // nodeModel.setProtocol(StrUtil.emptyToDefault(nodeModel.getProtocol(), "http"));
    {
        // 节点地址 重复
        boolean exists = this.existsByUrl(nodeModel.getUrl(), nodeModel.getWorkspaceId(), id);
        Assert.state(!exists, "对应的节点已经存在啦");
    }
    // 判断 ssh
    String sshId = nodeModel.getSshId();
    if (StrUtil.isNotEmpty(sshId)) {
        SshModel byKey = sshService.getByKey(sshId, request);
        Assert.notNull(byKey, "对应的 SSH 不存在");
        List<NodeModel> nodeBySshId = this.getNodeBySshId(sshId);
        nodeBySshId = ObjectUtil.defaultIfNull(nodeBySshId, Collections.EMPTY_LIST);
        Optional<NodeModel> any = nodeBySshId.stream().filter(nodeModel2 -> !StrUtil.equals(id, nodeModel2.getId())).findAny();
        Assert.state(!any.isPresent(), "对应的SSH已经被其他节点绑定啦");
    }
    if (nodeModel.isOpenStatus()) {
        // 
        this.checkLockType(existsNode);
        this.testNode(nodeModel);
    }
    try {
        if (autoReg) {
            BaseServerController.resetInfo(UserModel.EMPTY);
        }
        if (create) {
            if (autoReg) {
                // 自动注册节点默认关闭
                nodeModel.setOpenStatus(0);
                // 默认锁定 (原因未分配工作空间)
                nodeModel.setUnLockType("unassignedWorkspace");
            }
            this.insert(nodeModel);
            // 同步项目
            ProjectInfoCacheService projectInfoCacheService = SpringUtil.getBean(ProjectInfoCacheService.class);
            projectInfoCacheService.syncNode(nodeModel);
        } else {
            this.update(nodeModel);
        }
    } finally {
        if (autoReg) {
            BaseServerController.removeEmpty();
        }
    }
}
Also used : ObjectUtil(cn.hutool.core.util.ObjectUtil) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) ServletUtil(cn.hutool.extra.servlet.ServletUtil) JsonMessage(cn.jiangzeyin.common.JsonMessage) HttpServletRequest(javax.servlet.http.HttpServletRequest) Service(org.springframework.stereotype.Service) BaseGroupService(io.jpom.service.h2db.BaseGroupService) WorkspaceModel(io.jpom.model.data.WorkspaceModel) WorkspaceService(io.jpom.service.system.WorkspaceService) NodeForward(io.jpom.common.forward.NodeForward) SshService(io.jpom.service.node.ssh.SshService) NodeModel(io.jpom.model.data.NodeModel) SpringUtil(cn.jiangzeyin.common.spring.SpringUtil) Collectors(java.util.stream.Collectors) NodeUrl(io.jpom.common.forward.NodeUrl) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) JpomManifest(io.jpom.common.JpomManifest) Const(io.jpom.common.Const) SshModel(io.jpom.model.data.SshModel) Optional(java.util.Optional) Entity(cn.hutool.db.Entity) UserModel(io.jpom.model.data.UserModel) Collections(java.util.Collections) BaseServerController(io.jpom.common.BaseServerController) Validator(cn.hutool.core.lang.Validator) Assert(org.springframework.util.Assert) NodeModel(io.jpom.model.data.NodeModel) SshModel(io.jpom.model.data.SshModel)

Example 4 with NodeModel

use of io.jpom.model.data.NodeModel in project Jpom by dromara.

the class NodeService method getNodeBySshId.

public List<NodeModel> getNodeBySshId(String sshId) {
    NodeModel nodeModel = new NodeModel();
    nodeModel.setSshId(sshId);
    return super.listByBean(nodeModel);
}
Also used : NodeModel(io.jpom.model.data.NodeModel)

Example 5 with NodeModel

use of io.jpom.model.data.NodeModel in project Jpom by dromara.

the class NodeUpdateHandler method pullNodeList.

private void pullNodeList(WebSocketSession session, String ids) {
    List<String> split = StrUtil.split(ids, StrUtil.COMMA);
    List<NodeModel> nodeModelList = nodeService.listById(split);
    if (nodeModelList == null) {
        this.onError(session, "没有查询到节点信息:" + ids);
        return;
    }
    for (NodeModel model : nodeModelList) {
        NodeClient nodeClient = clientMap.get(model.getId());
        if (nodeClient != null) {
            // 
            nodeClient.close();
        }
        Map<String, Object> attributes = session.getAttributes();
        String url = NodeForward.getSocketUrl(model, NodeUrl.NodeUpdate, (UserModel) attributes.get("userInfo"));
        // 连接节点
        ThreadUtil.execute(() -> {
            try {
                NodeClient client = new NodeClient(url, model, session);
                clientMap.put(model.getId(), client);
            } catch (Exception e) {
                DefaultSystemLog.getLog().error("创建插件端连接失败", e);
            }
        });
    }
}
Also used : NodeModel(io.jpom.model.data.NodeModel) NodeClient(io.jpom.socket.client.NodeClient) JSONObject(com.alibaba.fastjson.JSONObject) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

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