Search in sources :

Example 1 with ConfigBean

use of io.jpom.system.ConfigBean in project Jpom by dromara.

the class ManageEditProjectController method checkParameter.

/**
 * 基础检查
 *
 * @param projectInfo        项目实体
 * @param whitelistDirectory 白名单
 * @param previewData        预检查数据
 */
private void checkParameter(NodeProjectInfoModel projectInfo, String whitelistDirectory, boolean previewData) {
    String id = projectInfo.getId();
    String checkId = StrUtil.replace(id, StrUtil.DASHED, StrUtil.UNDERLINE);
    Validator.validateGeneral(checkId, 2, Const.ID_MAX_LEN, "项目id 长度范围2-20(英文字母 、数字和下划线)");
    Assert.state(!JpomApplication.SYSTEM_ID.equals(id), "项目id " + JpomApplication.SYSTEM_ID + " 关键词被系统占用");
    // 防止和Jpom冲突
    ConfigBean instance = ConfigBean.getInstance();
    Assert.state(!instance.applicationTag.equalsIgnoreCase(id), "当前项目id已经被Jpom占用");
    // 运行模式
    String runMode = getParameter("runMode");
    RunMode runMode1 = RunMode.ClassPath;
    try {
        runMode1 = RunMode.valueOf(runMode);
    } catch (Exception ignored) {
    }
    projectInfo.setRunMode(runMode1);
    // 监测
    if (runMode1 == RunMode.ClassPath || runMode1 == RunMode.JavaExtDirsCp) {
        Assert.hasText(projectInfo.getMainClass(), "ClassPath、JavaExtDirsCp 模式 MainClass必填");
    } else if (runMode1 == RunMode.Jar || runMode1 == RunMode.JarWar) {
        projectInfo.setMainClass(StrUtil.EMPTY);
    }
    if (runMode1 == RunMode.JavaExtDirsCp) {
        Assert.hasText(projectInfo.getJavaExtDirsCp(), "JavaExtDirsCp 模式 javaExtDirsCp必填");
    }
    // 判断是否为分发添加
    String strOutGivingProject = getParameter("outGivingProject");
    boolean outGivingProject = Boolean.parseBoolean(strOutGivingProject);
    projectInfo.setOutGivingProject(outGivingProject);
    if (!previewData) {
        // 不是预检查数据才效验白名单
        if (!whitelistDirectoryService.checkProjectDirectory(whitelistDirectory)) {
            if (outGivingProject) {
                whitelistDirectoryService.addProjectWhiteList(whitelistDirectory);
            } else {
                throw new IllegalArgumentException("请选择正确的项目路径,或者还没有配置白名单");
            }
        }
        String logPath = projectInfo.getLogPath();
        if (StrUtil.isNotEmpty(logPath)) {
            if (!whitelistDirectoryService.checkProjectDirectory(logPath)) {
                if (outGivingProject) {
                    whitelistDirectoryService.addProjectWhiteList(logPath);
                } else {
                    throw new IllegalArgumentException("请填写的项目日志存储路径,或者还没有配置白名单");
                }
            }
        }
    }
    // 
    String lib = projectInfo.getLib();
    Assert.state(StrUtil.isNotEmpty(lib) && !StrUtil.SLASH.equals(lib) && !Validator.isChinese(lib), "项目Jar路径不能为空,不能为顶级目录,不能包含中文");
    Assert.state(checkPathSafe(lib), "项目Jar路径存在提升目录问题");
    // java 程序副本
    if (runMode1 == RunMode.ClassPath || runMode1 == RunMode.Jar || runMode1 == RunMode.JarWar || runMode1 == RunMode.JavaExtDirsCp) {
        String javaCopyIds = getParameter("javaCopyIds");
        if (StrUtil.isEmpty(javaCopyIds)) {
            projectInfo.setJavaCopyItemList(null);
        } else {
            String[] split = StrUtil.splitToArray(javaCopyIds, StrUtil.COMMA);
            List<NodeProjectInfoModel.JavaCopyItem> javaCopyItemList = new ArrayList<>(split.length);
            for (String copyId : split) {
                String jvm = getParameter("jvm_" + copyId);
                String args = getParameter("args_" + copyId);
                // 
                NodeProjectInfoModel.JavaCopyItem javaCopyItem = new NodeProjectInfoModel.JavaCopyItem();
                javaCopyItem.setId(copyId);
                javaCopyItem.setParentId(id);
                javaCopyItem.setModifyTime(DateUtil.now());
                javaCopyItem.setJvm(StrUtil.emptyToDefault(jvm, StrUtil.EMPTY));
                javaCopyItem.setArgs(StrUtil.emptyToDefault(args, StrUtil.EMPTY));
                javaCopyItemList.add(javaCopyItem);
            }
            projectInfo.setJavaCopyItemList(javaCopyItemList);
        }
    } else {
        projectInfo.setJavaCopyItemList(null);
    }
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) RunMode(io.jpom.model.RunMode) ArrayList(java.util.ArrayList) ConfigBean(io.jpom.system.ConfigBean)

Example 2 with ConfigBean

use of io.jpom.system.ConfigBean in project Jpom by dromara.

the class AgentCacheManageController method cache.

/**
 * 缓存信息
 *
 * @return json
 */
@PostMapping(value = "cache", produces = MediaType.APPLICATION_JSON_VALUE)
public String cache() {
    JSONObject jsonObject = new JSONObject();
    // 
    ConfigBean instance = ConfigBean.getInstance();
    File file = instance.getTempPath();
    String fileSize = FileUtil.readableFileSize(FileUtil.size(file));
    jsonObject.put("fileSize", fileSize);
    jsonObject.put("dataSize", FileUtil.readableFileSize(instance.dataSize()));
    File oldJarsPath = JpomManifest.getOldJarsPath();
    jsonObject.put("oldJarsSize", FileUtil.readableFileSize(FileUtil.size(oldJarsPath)));
    // 
    jsonObject.put("pidName", AbstractProjectCommander.PID_JPOM_NAME.size());
    jsonObject.put("pidPort", AbstractProjectCommander.PID_PORT.size());
    int oneLineCount = AgentFileTailWatcher.getOneLineCount();
    jsonObject.put("readFileOnLineCount", oneLineCount);
    jsonObject.put("taskList", CronUtils.list());
    jsonObject.put("pluginSize", PluginFactory.size());
    // 
    WorkspaceEnvVarModel item = agentWorkspaceEnvVarService.getItem(getWorkspaceId());
    if (item != null) {
        Map<String, WorkspaceEnvVarModel.WorkspaceEnvVarItemModel> varData = item.getVarData();
        if (varData != null) {
            jsonObject.put("envVarKeys", varData.keySet());
        }
    }
    // 
    return JsonMessage.getString(200, "ok", jsonObject);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) WorkspaceEnvVarModel(io.jpom.model.system.WorkspaceEnvVarModel) ConfigBean(io.jpom.system.ConfigBean) File(java.io.File) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with ConfigBean

use of io.jpom.system.ConfigBean in project Jpom by dromara.

the class JpomApplicationEvent method onApplicationEvent.

@Override
public void onApplicationEvent(ApplicationEvent event) {
    // 启动最后的预加载
    if (event instanceof ApplicationReadyEvent) {
        // 
        checkPath();
        JpomManifest jpomManifest = JpomManifest.getInstance();
        ConfigBean instance = ConfigBean.getInstance();
        // 清理旧进程新文件
        File dataDir = FileUtil.file(instance.getDataPath());
        List<File> files = FileUtil.loopFiles(dataDir, 1, pathname -> pathname.getName().startsWith("pid."));
        files.forEach(FileUtil::del);
        try {
            this.lockFile(jpomManifest.getPid());
        } catch (IOException e) {
            DefaultSystemLog.getLog().error("lockFile", e);
        }
        // 写入Jpom 信息 、 写入全局信息
        File appJpomFile = instance.getApplicationJpomInfo(JpomApplication.getAppType());
        FileUtil.writeString(jpomManifest.toString(), appJpomFile, CharsetUtil.CHARSET_UTF_8);
        // 检查更新文件
        checkUpdate();
        // 
        if (ApplicationEventLoad.class.isAssignableFrom(JpomApplication.getAppClass())) {
            ApplicationEventLoad eventLoad = (ApplicationEventLoad) SpringUtil.getBean(JpomApplication.getAppClass());
            eventLoad.applicationLoad();
        }
        Console.log("Jpom Successful start preparation. start loading module");
    } else if (event instanceof ContextClosedEvent) {
        // 应用关闭
        this.unLockFile();
        // 
        ConfigBean instance = ConfigBean.getInstance();
        FileUtil.del(instance.getPidFile());
        // 
        File appJpomFile = instance.getApplicationJpomInfo(JpomApplication.getAppType());
        FileUtil.del(appJpomFile);
    }
}
Also used : ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) ApplicationEventLoad(cn.jiangzeyin.common.spring.event.ApplicationEventLoad) ExtConfigBean(io.jpom.system.ExtConfigBean) ConfigBean(io.jpom.system.ConfigBean) IOException(java.io.IOException) File(java.io.File) FileUtil(cn.hutool.core.io.FileUtil) JsonFileUtil(io.jpom.util.JsonFileUtil) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent)

Aggregations

ConfigBean (io.jpom.system.ConfigBean)3 File (java.io.File)2 FileUtil (cn.hutool.core.io.FileUtil)1 ApplicationEventLoad (cn.jiangzeyin.common.spring.event.ApplicationEventLoad)1 JSONObject (com.alibaba.fastjson.JSONObject)1 RunMode (io.jpom.model.RunMode)1 NodeProjectInfoModel (io.jpom.model.data.NodeProjectInfoModel)1 WorkspaceEnvVarModel (io.jpom.model.system.WorkspaceEnvVarModel)1 ExtConfigBean (io.jpom.system.ExtConfigBean)1 JsonFileUtil (io.jpom.util.JsonFileUtil)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)1 ContextClosedEvent (org.springframework.context.event.ContextClosedEvent)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1