Search in sources :

Example 1 with NodeService

use of io.jpom.service.node.NodeService in project Jpom by dromara.

the class WorkspaceService method convertNullWorkspaceId.

/**
 * 将没有工作空间ID 的数据添加默认值
 */
public void convertNullWorkspaceId() {
    Set<Class<?>> classes = ClassUtil.scanPackage("io.jpom.model", BaseWorkspaceModel.class::isAssignableFrom);
    for (Class<?> aClass : classes) {
        TableName tableName = aClass.getAnnotation(TableName.class);
        if (tableName == null) {
            continue;
        }
        String sql = "update " + tableName.value() + " set workspaceId=? where workspaceId is null";
        NodeService nodeService = SpringUtil.getBean(NodeService.class);
        int execute = nodeService.execute(sql, Const.WORKSPACE_DEFAULT_ID);
        if (execute > 0) {
            DefaultSystemLog.getLog().info("convertNullWorkspaceId {} {}", tableName.value(), execute);
        }
    }
}
Also used : TableName(io.jpom.service.h2db.TableName) BaseWorkspaceModel(io.jpom.model.BaseWorkspaceModel) NodeService(io.jpom.service.node.NodeService)

Example 2 with NodeService

use of io.jpom.service.node.NodeService 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 3 with NodeService

use of io.jpom.service.node.NodeService in project Jpom by dromara.

the class ReleaseManage method doProject.

/**
 * 发布项目
 */
private void doProject() {
    // AfterOpt afterOpt, boolean clearOld, boolean diffSync
    AfterOpt afterOpt = BaseEnum.getEnum(AfterOpt.class, this.buildExtraModule.getAfterOpt(), AfterOpt.No);
    boolean clearOld = this.buildExtraModule.isClearOld();
    boolean diffSync = this.buildExtraModule.isDiffSync();
    String releaseMethodDataId = this.buildExtraModule.getReleaseMethodDataId();
    String[] strings = StrUtil.splitToArray(releaseMethodDataId, CharPool.COLON);
    if (ArrayUtil.length(strings) != 2) {
        throw new IllegalArgumentException(releaseMethodDataId + " error");
    }
    NodeService nodeService = SpringUtil.getBean(NodeService.class);
    NodeModel nodeModel = nodeService.getByKey(strings[0]);
    Objects.requireNonNull(nodeModel, "节点不存在");
    String projectId = strings[1];
    if (diffSync) {
        this.diffSyncProject(nodeModel, projectId, afterOpt, clearOld);
        return;
    }
    File zipFile = BuildUtil.isDirPackage(this.resultFile);
    boolean unZip = true;
    if (zipFile == null) {
        zipFile = this.resultFile;
        unZip = false;
    }
    JsonMessage<String> jsonMessage = OutGivingRun.fileUpload(zipFile, null, projectId, unZip, afterOpt, nodeModel, this.userModel, clearOld);
    if (jsonMessage.getCode() == HttpStatus.HTTP_OK) {
        logRecorder.info("发布项目包成功:" + jsonMessage);
    } else {
        throw new JpomRuntimeException("发布项目包失败:" + jsonMessage);
    }
}
Also used : NodeModel(io.jpom.model.data.NodeModel) NodeService(io.jpom.service.node.NodeService) JpomRuntimeException(io.jpom.system.JpomRuntimeException) AfterOpt(io.jpom.model.AfterOpt) File(java.io.File)

Example 4 with NodeService

use of io.jpom.service.node.NodeService in project Jpom by dromara.

the class NodeForward method getSocketUrl.

/**
 * 获取节点socket 信息
 *
 * @param nodeModel 节点信息
 * @param nodeUrl   url
 * @return url
 */
public static String getSocketUrl(NodeModel nodeModel, NodeUrl nodeUrl, UserModel userInfo, Object... parameters) {
    String ws;
    if ("https".equalsIgnoreCase(nodeModel.getProtocol())) {
        ws = "wss";
    } else {
        ws = "ws";
    }
    if (StrUtil.isEmpty(nodeModel.getLoginPwd())) {
        NodeService nodeService = SpringUtil.getBean(NodeService.class);
        NodeModel model = nodeService.getByKey(nodeModel.getId(), false);
        nodeModel.setLoginPwd(model.getLoginPwd());
        nodeModel.setLoginName(model.getLoginName());
    }
    UrlQuery urlQuery = new UrlQuery();
    urlQuery.add(ConfigBean.JPOM_AGENT_AUTHORIZE, nodeModel.toAuthorize());
    // 
    String optUser = userInfo.getId();
    optUser = URLUtil.encode(optUser);
    urlQuery.add("optUser", optUser);
    if (ArrayUtil.isNotEmpty(parameters)) {
        for (int i = 0; i < parameters.length; i += 2) {
            Object parameter = parameters[i + 1];
            String value = Convert.toStr(parameter, StrUtil.EMPTY);
            urlQuery.add(parameters[i].toString(), URLUtil.encode(value));
        }
    }
    // 兼容旧版本-节点升级 @author jzy
    urlQuery.add("name", URLUtil.encode(nodeModel.getLoginName()));
    urlQuery.add("password", URLUtil.encode(nodeModel.getLoginPwd()));
    String format = StrUtil.format("{}://{}{}?{}", ws, nodeModel.getUrl(), nodeUrl.getUrl(), urlQuery.toString());
    DefaultSystemLog.getLog().debug("web socket url:{}", format);
    return format;
}
Also used : NodeModel(io.jpom.model.data.NodeModel) NodeService(io.jpom.service.node.NodeService) UrlQuery(cn.hutool.core.net.url.UrlQuery) JSONObject(com.alibaba.fastjson.JSONObject)

Example 5 with NodeService

use of io.jpom.service.node.NodeService in project Jpom by dromara.

the class NodeForward method addUser.

/**
 * 添加agent 授权信息header
 *
 * @param httpRequest request
 * @param nodeModel   节点
 * @param userModel   用户
 */
private static void addUser(HttpRequest httpRequest, NodeModel nodeModel, NodeUrl nodeUrl, UserModel userModel) {
    // 判断开启状态
    if (!nodeModel.isOpenStatus()) {
        throw new AgentException(nodeModel.getName() + "节点未启用");
    }
    if (userModel != null) {
        httpRequest.header(ConfigBean.JPOM_SERVER_USER_NAME, URLUtil.encode(userModel.getId()));
    // httpRequest.header(ConfigBean.JPOM_SERVER_SYSTEM_USER_ROLE, userModel.getUserRole(nodeModel).name());
    }
    if (StrUtil.isEmpty(nodeModel.getLoginPwd())) {
        NodeService nodeService = SpringUtil.getBean(NodeService.class);
        NodeModel model = nodeService.getByKey(nodeModel.getId(), false);
        nodeModel.setLoginPwd(model.getLoginPwd());
        nodeModel.setLoginName(model.getLoginName());
    }
    httpRequest.header(ConfigBean.JPOM_AGENT_AUTHORIZE, nodeModel.toAuthorize());
    httpRequest.header(Const.WORKSPACEID_REQ_HEADER, nodeModel.getWorkspaceId());
    // 
    int timeOut = nodeModel.getTimeOut();
    if (nodeUrl.getTimeOut() != -1 && timeOut > 0) {
        // 
        timeOut = Math.max(timeOut, 2);
        httpRequest.timeout(timeOut * 1000);
    }
}
Also used : NodeModel(io.jpom.model.data.NodeModel) AgentException(io.jpom.system.AgentException) NodeService(io.jpom.service.node.NodeService)

Aggregations

NodeService (io.jpom.service.node.NodeService)8 NodeModel (io.jpom.model.data.NodeModel)6 File (java.io.File)2 UrlQuery (cn.hutool.core.net.url.UrlQuery)1 PreLoadMethod (cn.jiangzeyin.common.PreLoadMethod)1 JSON (com.alibaba.fastjson.JSON)1 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 AfterOpt (io.jpom.model.AfterOpt)1 BaseNodeModel (io.jpom.model.BaseNodeModel)1 BaseWorkspaceModel (io.jpom.model.BaseWorkspaceModel)1 BackupInfoService (io.jpom.service.dblog.BackupInfoService)1 TableName (io.jpom.service.h2db.TableName)1 NodeScriptServer (io.jpom.service.node.script.NodeScriptServer)1 AgentException (io.jpom.system.AgentException)1 JpomRuntimeException (io.jpom.system.JpomRuntimeException)1