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);
}
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();
}
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();
}
}
}
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);
}
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);
}
});
}
}
Aggregations