Search in sources :

Example 16 with Tuple

use of cn.hutool.core.lang.Tuple in project Jpom by dromara.

the class RepositoryController method editRepository.

/**
 * edit
 *
 * @param repositoryModelReq 仓库实体
 * @return json
 */
@PostMapping(value = "/build/repository/edit")
@Feature(method = MethodFeature.EDIT)
public Object editRepository(RepositoryModel repositoryModelReq) {
    this.checkInfo(repositoryModelReq);
    // 检查 rsa 私钥
    boolean andUpdateSshKey = this.checkAndUpdateSshKey(repositoryModelReq);
    Assert.state(andUpdateSshKey, "rsa 私钥文件不存在或者有误");
    if (repositoryModelReq.getRepoType() == RepositoryModel.RepoType.Git.getCode()) {
        RepositoryModel repositoryModel = repositoryService.getByKey(repositoryModelReq.getId(), false);
        if (repositoryModel != null) {
            repositoryModelReq.setRsaPrv(StrUtil.emptyToDefault(repositoryModelReq.getRsaPrv(), repositoryModel.getRsaPrv()));
            repositoryModelReq.setPassword(StrUtil.emptyToDefault(repositoryModelReq.getPassword(), repositoryModel.getPassword()));
        }
        // 验证 git 仓库信息
        try {
            IPlugin plugin = PluginFactory.getPlugin("git-clone");
            Map<String, Object> map = repositoryModelReq.toMap();
            Tuple branchAndTagList = (Tuple) plugin.execute("branchAndTagList", map);
        // Tuple tuple = GitUtil.getBranchAndTagList(repositoryModelReq);
        } catch (JpomRuntimeException jpomRuntimeException) {
            throw jpomRuntimeException;
        } catch (Exception e) {
            DefaultSystemLog.getLog().warn("获取仓库分支失败", e);
            return JsonMessage.toJson(500, "无法连接此仓库," + e.getMessage());
        }
    }
    if (StrUtil.isEmpty(repositoryModelReq.getId())) {
        // insert data
        repositoryService.insert(repositoryModelReq);
    } else {
        // update data
        // repositoryModelReq.setWorkspaceId(repositoryService.getCheckUserWorkspace(getRequest()));
        repositoryService.updateById(repositoryModelReq, getRequest());
    }
    return JsonMessage.toJson(200, "操作成功");
}
Also used : JpomRuntimeException(io.jpom.system.JpomRuntimeException) JSONObject(com.alibaba.fastjson.JSONObject) RepositoryModel(io.jpom.model.data.RepositoryModel) Tuple(cn.hutool.core.lang.Tuple) JpomRuntimeException(io.jpom.system.JpomRuntimeException) PostMapping(org.springframework.web.bind.annotation.PostMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Example 17 with Tuple

use of cn.hutool.core.lang.Tuple in project Jpom by dromara.

the class OutGivingProjectEditController method doData.

/**
 * 处理页面数据
 *
 * @param outGivingModel 分发实体
 * @param edit           是否为编辑模式
 */
private List<Tuple> doData(OutGivingModel outGivingModel, boolean edit) {
    outGivingModel.setName(getParameter("name"));
    Assert.hasText(outGivingModel.getName(), "分发名称不能为空");
    // 
    int intervalTime = getParameterInt("intervalTime", 10);
    outGivingModel.setIntervalTime(intervalTime);
    outGivingModel.setClearOld(Convert.toBool(getParameter("clearOld"), false));
    // 
    String nodeIdsStr = getParameter("nodeIds");
    List<String> nodeIds = StrUtil.splitTrim(nodeIdsStr, StrUtil.COMMA);
    // List<NodeModel> nodeModelList = nodeService.listByWorkspace(getRequest());
    Assert.notEmpty(nodeIds, "没有任何节点信息");
    // 
    String afterOpt = getParameter("afterOpt");
    AfterOpt afterOpt1 = BaseEnum.getEnum(AfterOpt.class, Convert.toInt(afterOpt, 0));
    Assert.notNull(afterOpt1, "请选择分发后的操作");
    outGivingModel.setAfterOpt(afterOpt1.getCode());
    JSONObject defData = getDefData(outGivingModel, edit);
    UserModel userModel = getUser();
    // 
    List<OutGivingModel> outGivingModels = outGivingServer.list();
    List<OutGivingNodeProject> outGivingNodeProjects = new ArrayList<>();
    OutGivingNodeProject outGivingNodeProject;
    // 
    // Iterator<NodeModel> iterator = nodeModelList.iterator();
    List<Tuple> tuples = new ArrayList<>();
    for (String nodeId : nodeIds) {
        NodeModel nodeModel = nodeService.getByKey(nodeId);
        Assert.notNull(nodeModel, "对应的节点不存在");
        // 判断项目是否已经被使用过啦
        if (outGivingModels != null) {
            for (OutGivingModel outGivingModel1 : outGivingModels) {
                if (outGivingModel1.getId().equalsIgnoreCase(outGivingModel.getId())) {
                    continue;
                }
                Assert.state(!outGivingModel1.checkContains(nodeModel.getId(), outGivingModel.getId()), "已经存在相同的分发项目:" + outGivingModel.getId());
            }
        }
        outGivingNodeProject = outGivingModel.getNodeProject(nodeModel.getId(), outGivingModel.getId());
        if (outGivingNodeProject == null) {
            outGivingNodeProject = new OutGivingNodeProject();
        }
        outGivingNodeProject.setNodeId(nodeModel.getId());
        outGivingNodeProject.setProjectId(outGivingModel.getId());
        outGivingNodeProjects.add(outGivingNodeProject);
        // 检查数据
        JSONObject allData = defData.clone();
        String token = getParameter(StrUtil.format("{}_token", nodeModel.getId()));
        allData.put("token", token);
        String jvm = getParameter(StrUtil.format("{}_jvm", nodeModel.getId()));
        allData.put("jvm", jvm);
        String args = getParameter(StrUtil.format("{}_args", nodeModel.getId()));
        allData.put("args", args);
        String autoStart = getParameter(StrUtil.format("{}_autoStart", nodeModel.getId()));
        allData.put("autoStart", Convert.toBool(autoStart, false));
        // 项目副本
        String javaCopyIds = getParameter(StrUtil.format("{}_javaCopyIds", nodeModel.getId()));
        allData.put("javaCopyIds", javaCopyIds);
        if (StrUtil.isNotEmpty(javaCopyIds)) {
            String[] split = StrUtil.splitToArray(javaCopyIds, StrUtil.COMMA);
            for (String copyId : split) {
                String copyJvm = getParameter(StrUtil.format("{}_jvm_{}", nodeModel.getId(), copyId));
                String copyArgs = getParameter(StrUtil.format("{}_args_{}", nodeModel.getId(), copyId));
                allData.put("jvm_" + copyId, copyJvm);
                allData.put("args_" + copyId, copyArgs);
            }
        }
        JsonMessage<String> jsonMessage = this.sendData(nodeModel, userModel, allData, false);
        Assert.state(jsonMessage.getCode() == HttpStatus.HTTP_OK, nodeModel.getName() + "节点失败:" + jsonMessage.getMsg());
        tuples.add(new Tuple(nodeModel, allData));
    }
    // 删除已经删除的项目
    deleteProject(outGivingModel, outGivingNodeProjects, userModel);
    outGivingModel.outGivingNodeProjectList(outGivingNodeProjects);
    return tuples;
}
Also used : ArrayList(java.util.ArrayList) AfterOpt(io.jpom.model.AfterOpt) JSONObject(com.alibaba.fastjson.JSONObject) Tuple(cn.hutool.core.lang.Tuple)

Example 18 with Tuple

use of cn.hutool.core.lang.Tuple in project Jpom by dromara.

the class SshInstallAgentController method uploadAgent.

@RequestMapping(value = "upload_agent.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
@SystemPermission
public String uploadAgent() throws Exception {
    ServerConfigBean instance = ServerConfigBean.getInstance();
    String tempFilePath = instance.getUserTempPath().getAbsolutePath();
    MultipartFileBuilder multipartFileBuilder = createMultipart().setFileExt("zip").addFieldName("file").setSavePath(tempFilePath);
    String filePath = multipartFileBuilder.save();
    File tempAgent = FileUtil.file(tempFilePath, "temp_agent");
    FileUtil.del(tempAgent);
    // 解析压缩包
    File jarFile = JpomManifest.zipFileFind(filePath, Type.Agent, FileUtil.getAbsolutePath(tempAgent));
    // 验证文件是否正确
    JsonMessage<Tuple> tupleJsonMessage = JpomManifest.checkJpomJar(FileUtil.getAbsolutePath(jarFile), Type.Agent, false);
    Assert.state(tupleJsonMessage.getCode() == 200, tupleJsonMessage::getMsg);
    // 
    File outFle = FileUtil.file(tempFilePath, Type.Agent.name() + "_" + IdUtil.fastSimpleUUID());
    try {
        this.unZipGetTag(filePath, outFle);
        // 保存插件包
        File agentZipPath = instance.getAgentZipPath();
        FileUtil.copy(FileUtil.file(filePath), agentZipPath, true);
        return JsonMessage.getString(200, "上传成功");
    } finally {
        FileUtil.del(filePath);
        FileUtil.del(jarFile);
    }
}
Also used : MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) ZipFile(java.util.zip.ZipFile) File(java.io.File) ServerConfigBean(io.jpom.system.ServerConfigBean) Tuple(cn.hutool.core.lang.Tuple) SystemPermission(io.jpom.permission.SystemPermission) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with Tuple

use of cn.hutool.core.lang.Tuple in project Jpom by dromara.

the class NodeUpdateController method uploadAgent.

@RequestMapping(value = "upload_agent", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@SystemPermission
@Feature(method = MethodFeature.UPLOAD)
public String uploadAgent() throws IOException {
    String saveDir = ServerConfigBean.getInstance().getAgentPath().getAbsolutePath();
    MultipartFileBuilder multipartFileBuilder = createMultipart();
    multipartFileBuilder.setFileExt("jar", "zip").addFieldName("file").setUseOriginalFilename(true).setSavePath(saveDir);
    String path = multipartFileBuilder.save();
    // 解析压缩包
    File file = JpomManifest.zipFileFind(path, Type.Agent, saveDir);
    path = FileUtil.getAbsolutePath(file);
    // 基础检查
    JsonMessage<Tuple> error = JpomManifest.checkJpomJar(path, Type.Agent, false);
    if (error.getCode() != HttpStatus.HTTP_OK) {
        FileUtil.del(path);
        return error.toString();
    }
    // 保存文件
    this.saveAgentFile(error.getData());
    return JsonMessage.getString(200, "上传成功");
}
Also used : MultipartFileBuilder(cn.jiangzeyin.controller.multipart.MultipartFileBuilder) File(java.io.File) Tuple(cn.hutool.core.lang.Tuple) SystemPermission(io.jpom.permission.SystemPermission) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with Tuple

use of cn.hutool.core.lang.Tuple in project Jpom by dromara.

the class NodeUpdateController method downloadRemote.

/**
 * 远程下载
 *
 * @return json
 * @see RemoteVersion
 */
@GetMapping(value = "download_remote.json", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.REMOTE_DOWNLOAD)
public String downloadRemote() throws IOException {
    String saveDir = ServerConfigBean.getInstance().getAgentPath().getAbsolutePath();
    Tuple download = RemoteVersion.download(saveDir, Type.Agent, false);
    // 保存文件
    this.saveAgentFile(download);
    return JsonMessage.getString(200, "下载成功");
}
Also used : Tuple(cn.hutool.core.lang.Tuple) GetMapping(org.springframework.web.bind.annotation.GetMapping) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Aggregations

Tuple (cn.hutool.core.lang.Tuple)22 File (java.io.File)8 JSONObject (com.alibaba.fastjson.JSONObject)6 ClassFeature (io.jpom.permission.ClassFeature)6 Feature (io.jpom.permission.Feature)6 MethodFeature (io.jpom.permission.MethodFeature)6 ZipFile (java.util.zip.ZipFile)4 MultipartFileBuilder (cn.jiangzeyin.controller.multipart.MultipartFileBuilder)3 RepositoryModel (io.jpom.model.data.RepositoryModel)2 SystemPermission (io.jpom.permission.SystemPermission)2 JpomRuntimeException (io.jpom.system.JpomRuntimeException)2 ServerConfigBean (io.jpom.system.ServerConfigBean)2 IOException (java.io.IOException)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 JarFile (java.util.jar.JarFile)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 JarClassLoader (cn.hutool.core.lang.JarClassLoader)1