Search in sources :

Example 6 with Tuple

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

the class JpomManifest method init.

private static void init() {
    if (JPOM_MANIFEST == null) {
        synchronized (JpomManifest.class) {
            if (JPOM_MANIFEST == null) {
                JPOM_MANIFEST = new JpomManifest();
                File jarFile = getRunPath();
                Tuple jarVersion = getJarVersion(jarFile);
                if (jarVersion != null) {
                    JPOM_MANIFEST.setVersion(jarVersion.get(0));
                    JPOM_MANIFEST.setTimeStamp(jarVersion.get(1));
                }
                JPOM_MANIFEST.setJarFile(FileUtil.getAbsolutePath(jarFile));
                // 
                JPOM_MANIFEST.randomId = IdUtil.fastSimpleUUID();
            }
            String jpomTag = StrUtil.format("Jpom {}/{}", JPOM_MANIFEST.getType(), JPOM_MANIFEST.getVersion());
            GlobalHeaders.INSTANCE.header(Header.USER_AGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36 " + jpomTag, true);
        }
    }
}
Also used : JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) Tuple(cn.hutool.core.lang.Tuple)

Example 7 with Tuple

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

the class RemoteVersion method upgrade.

/**
 * 升级
 *
 * @param savePath 下载文件保存路径
 * @param consumer 执行申请前回调
 * @throws IOException 异常
 */
public static void upgrade(String savePath, Consumer<Tuple> consumer) throws IOException {
    Type type = JpomManifest.getInstance().getType();
    // 下载
    Tuple data = download(savePath, type);
    File file = data.get(3);
    // 基础检查
    String path = FileUtil.getAbsolutePath(file);
    String version = data.get(0);
    JpomManifest.releaseJar(path, version);
    // 
    if (consumer != null) {
        consumer.accept(data);
    }
    JpomApplication.restart();
}
Also used : File(java.io.File) Tuple(cn.hutool.core.lang.Tuple)

Example 8 with Tuple

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

the class AbstractProjectCommander method runDsl.

private String runDsl(NodeProjectInfoModel nodeProjectInfoModel, String opt, Function<DslYmlDto.BaseProcess, String> function) {
    Tuple dslProcess = nodeProjectInfoModel.getDslProcess(opt);
    String errorMsg = dslProcess.get(0);
    if (errorMsg != null) {
        return errorMsg;
    }
    DslYmlDto.BaseProcess process = dslProcess.get(1);
    if (process == null) {
        return "yml 未配置 运行管理 " + opt;
    }
    return function.apply(process);
// String log = nodeProjectInfoModel.getAbsoluteLog(null);
// return DslScriptBuilder.run(process, log);
}
Also used : DslYmlDto(io.jpom.model.data.DslYmlDto) Tuple(cn.hutool.core.lang.Tuple)

Example 9 with Tuple

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

the class SshInstallAgentController method getAgentFile.

private JSONObject getAgentFile() throws IOException {
    ServerConfigBean instance = ServerConfigBean.getInstance();
    File agentZipPath = instance.getAgentZipPath();
    Assert.state(FileUtil.exist(agentZipPath), "插件包文件不存在,需要重新上传");
    String tempFilePath = instance.getUserTempPath().getAbsolutePath();
    // 
    File tempAgent = FileUtil.file(tempFilePath, "temp_agent");
    FileUtil.del(tempAgent);
    try {
        // 解析压缩包
        File jarFile = JpomManifest.zipFileFind(FileUtil.getAbsolutePath(agentZipPath), Type.Agent, FileUtil.getAbsolutePath(tempAgent));
        // 获取包内容
        JsonMessage<Tuple> tupleJsonMessage = JpomManifest.checkJpomJar(FileUtil.getAbsolutePath(jarFile), Type.Agent, false);
        Assert.state(tupleJsonMessage.getCode() == 200, tupleJsonMessage::getMsg);
        Tuple data = tupleJsonMessage.getData();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("version", data.get(0));
        jsonObject.put("timeStamp", data.get(1));
        jsonObject.put("path", FileUtil.getAbsolutePath(agentZipPath));
        return jsonObject;
    } finally {
        FileUtil.del(tempAgent);
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) ZipFile(java.util.zip.ZipFile) File(java.io.File) ServerConfigBean(io.jpom.system.ServerConfigBean) Tuple(cn.hutool.core.lang.Tuple)

Example 10 with Tuple

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

the class OutGivingProjectEditController method saveNodeData.

/**
 * 保存节点项目数据
 *
 * @param outGivingModel 节点分发项目
 * @param edit           是否为编辑模式
 * @return 错误信息
 */
private String saveNodeData(OutGivingModel outGivingModel, List<Tuple> tuples, boolean edit) {
    // if () {
    // if (!edit) {
    // outGivingServer.delByKey(outGivingModel.getId());
    // }
    // return JsonMessage.getString(405, "数据异常,请重新操作");
    // }
    UserModel userModel = getUser();
    List<Tuple> success = new ArrayList<>();
    boolean fail = false;
    try {
        for (Tuple tuple : tuples) {
            NodeModel nodeModel = tuple.get(0);
            JSONObject data = tuple.get(1);
            // 
            JsonMessage<String> jsonMessage = this.sendData(nodeModel, userModel, data, true);
            if (jsonMessage.getCode() != HttpStatus.HTTP_OK) {
                if (!edit) {
                    fail = true;
                    outGivingServer.delByKey(outGivingModel.getId());
                }
                return JsonMessage.getString(406, nodeModel.getName() + "节点失败:" + jsonMessage.getMsg());
            }
            success.add(tuple);
            // 同步项目信息
            projectInfoCacheService.syncNode(nodeModel, outGivingModel.getId());
        }
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("保存分发项目失败", e);
        if (!edit) {
            fail = true;
            outGivingServer.delByKey(outGivingModel.getId());
        }
        return JsonMessage.getString(500, "保存节点数据失败:" + e.getMessage());
    } finally {
        if (fail) {
            try {
                for (Tuple entry : success) {
                    deleteNodeProject(entry.get(0), userModel, outGivingModel.getId());
                }
            } catch (Exception e) {
                DefaultSystemLog.getLog().error("还原项目失败", e);
            }
        }
    }
    return null;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) ArrayList(java.util.ArrayList) Tuple(cn.hutool.core.lang.Tuple)

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