Search in sources :

Example 1 with PreLoadMethod

use of cn.jiangzeyin.common.PreLoadMethod in project Jpom by dromara.

the class AutoStartProject method start.

@PreLoadMethod
private static void start() {
    ProjectInfoService projectInfoService = SpringUtil.getBean(ProjectInfoService.class);
    List<NodeProjectInfoModel> list = projectInfoService.list();
    if (CollUtil.isEmpty(list)) {
        return;
    }
    list = list.stream().filter(nodeProjectInfoModel -> nodeProjectInfoModel.getAutoStart() != null && nodeProjectInfoModel.getAutoStart()).collect(Collectors.toList());
    List<NodeProjectInfoModel> finalList = list;
    ThreadUtil.execute(() -> {
        AbstractProjectCommander instance = AbstractProjectCommander.getInstance();
        for (NodeProjectInfoModel nodeProjectInfoModel : finalList) {
            try {
                if (!instance.isRun(nodeProjectInfoModel, null)) {
                    instance.start(nodeProjectInfoModel, null);
                }
                List<NodeProjectInfoModel.JavaCopyItem> javaCopyItemList = nodeProjectInfoModel.getJavaCopyItemList();
                if (javaCopyItemList != null) {
                    for (NodeProjectInfoModel.JavaCopyItem javaCopyItem : javaCopyItemList) {
                        if (!instance.isRun(nodeProjectInfoModel, javaCopyItem)) {
                            instance.start(nodeProjectInfoModel, javaCopyItem);
                        }
                    }
                }
            } catch (Exception e) {
                DefaultSystemLog.getLog().warn("自动启动项目失败:{} {}", nodeProjectInfoModel.getId(), e.getMessage());
            }
        }
    });
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) ProjectInfoService(io.jpom.service.manage.ProjectInfoService) AbstractProjectCommander(io.jpom.common.commander.AbstractProjectCommander) PreLoadMethod(cn.jiangzeyin.common.PreLoadMethod)

Example 2 with PreLoadMethod

use of cn.jiangzeyin.common.PreLoadMethod in project Jpom by dromara.

the class CheckPath method clearTemp.

@PreLoadMethod(4)
private static void clearTemp() {
    File file = ConfigBean.getInstance().getTempPath();
    /**
     * @author Hotstrip
     * use Hutool's FileUtil.del method just put file as param not file's path
     * or else,  may be return Accessdenied exception
     */
    try {
        FileUtil.del(file);
    } catch (Exception e) {
        // Try again  jzy 2021-07-31
        DefaultSystemLog.getLog().warn("Attempt to delete temporary folder failed, try to handle read-only permission:{}", e.getMessage());
        List<File> files = FileUtil.loopFiles(file);
        long count = files.stream().map(file12 -> file12.setWritable(true)).filter(aBoolean -> aBoolean).count();
        DefaultSystemLog.getLog().warn("Cumulative number of files in temporary folder: {}, number of successful processing:{}", CollUtil.size(files), count);
        try {
            FileUtil.del(file.toPath());
        } catch (Exception e1) {
            e1.addSuppressed(e);
            boolean causedBy = ExceptionUtil.isCausedBy(e1, AccessDeniedException.class);
            if (causedBy) {
                DefaultSystemLog.getLog().error("清除临时文件失败,请手动清理:" + FileUtil.getAbsolutePath(file), e);
                return;
            }
            DefaultSystemLog.getLog().error("清除临时文件失败,请检查目录:" + FileUtil.getAbsolutePath(file), e);
        }
    }
}
Also used : Arrays(java.util.Arrays) ExceptionUtil(cn.hutool.core.exceptions.ExceptionUtil) ObjectUtil(cn.hutool.core.util.ObjectUtil) DefaultSystemLog(cn.jiangzeyin.common.DefaultSystemLog) HttpMethod(org.springframework.http.HttpMethod) JvmUtil(io.jpom.util.JvmUtil) File(java.io.File) PreLoadClass(cn.jiangzeyin.common.PreLoadClass) CollUtil(cn.hutool.core.collection.CollUtil) HttpServletRequest(javax.servlet.http.HttpServletRequest) List(java.util.List) JpomManifest(io.jpom.common.JpomManifest) PreLoadMethod(cn.jiangzeyin.common.PreLoadMethod) JpomApplication(io.jpom.JpomApplication) Map(java.util.Map) ConfigBean(io.jpom.system.ConfigBean) FileUtil(cn.hutool.core.io.FileUtil) ExtConfigBean(io.jpom.system.ExtConfigBean) AccessDeniedException(java.nio.file.AccessDeniedException) List(java.util.List) File(java.io.File) AccessDeniedException(java.nio.file.AccessDeniedException) PreLoadMethod(cn.jiangzeyin.common.PreLoadMethod)

Example 3 with PreLoadMethod

use of cn.jiangzeyin.common.PreLoadMethod in project Jpom by dromara.

the class AutoImportLocalNode method install.

@PreLoadMethod
private static void install() {
    File file = FileUtil.file(ConfigBean.getInstance().getDataPath(), ServerConfigBean.INSTALL);
    if (file.exists()) {
        return;
    }
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("installId", IdUtil.fastSimpleUUID());
    jsonObject.put("installTime", DateTime.now().toString());
    jsonObject.put("desc", "请勿删除此文件,服务端安装id和插件端互通关联");
    JsonFileUtil.saveJson(file.getAbsolutePath(), jsonObject);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) File(java.io.File) PreLoadMethod(cn.jiangzeyin.common.PreLoadMethod)

Example 4 with PreLoadMethod

use of cn.jiangzeyin.common.PreLoadMethod in project Jpom by dromara.

the class ConsoleStartSuccess method success.

/**
 * 输出启动成功的 日志
 */
@PreLoadMethod(value = Integer.MAX_VALUE)
private static void success() {
    Type type = JpomManifest.getInstance().getType();
    int port = ConfigBean.getInstance().getPort();
    String localhostStr = NetUtil.getLocalhostStr();
    String url = StrUtil.format("http://{}:{}", localhostStr, port);
    if (type == Type.Server) {
        Console.log("{} Successfully started,Can use happily => {} 【The current address is for reference only】", type, url);
    } else if (type == Type.Agent) {
        Console.log("{} Successfully started,Please go to the server to configure and use,Current node address => {} 【The current address is for reference only】", type, url);
    }
}
Also used : Type(io.jpom.common.Type) PreLoadMethod(cn.jiangzeyin.common.PreLoadMethod)

Example 5 with PreLoadMethod

use of cn.jiangzeyin.common.PreLoadMethod in project Jpom by dromara.

the class AutoRegSeverNode method reg.

/**
 * 向服务端注册插件端
 */
@PreLoadMethod
private static void reg() {
    AgentExtConfigBean instance = AgentExtConfigBean.getInstance();
    String agentId = instance.getAgentId();
    String serverUrl = instance.getServerUrl();
    if (StrUtil.isEmpty(agentId) || StrUtil.isEmpty(serverUrl)) {
        // 如果二者缺一不注册
        return;
    }
    String oldInstallId = null;
    File file = FileUtil.file(ConfigBean.getInstance().getDataPath(), AgentConfigBean.SERVER_ID);
    JSONObject serverJson = null;
    if (file.exists()) {
        try {
            serverJson = (JSONObject) JsonFileUtil.readJson(file.getAbsolutePath());
        } catch (FileNotFoundException e) {
            serverJson = new JSONObject();
        }
        oldInstallId = serverJson.getString("installId");
    }
    HttpRequest installRequest = instance.createServerRequest(ServerOpenApi.INSTALL_ID);
    String body1 = installRequest.execute().body();
    JsonMessage jsonMessage = JSON.parseObject(body1, JsonMessage.class);
    if (jsonMessage.getCode() != HttpStatus.HTTP_OK) {
        DefaultSystemLog.getLog().error("获取Server 安装id失败:" + jsonMessage);
        return;
    }
    String installId = jsonMessage.dataToString();
    boolean eqInstall = StrUtil.equals(oldInstallId, installId);
    // 
    URL url = URLUtil.toUrlForHttp(instance.getAgentUrl());
    String protocol = url.getProtocol();
    HttpRequest serverRequest = instance.createServerRequest(ServerOpenApi.UPDATE_NODE_INFO);
    serverRequest.form("id", agentId);
    serverRequest.form("name", "节点:" + agentId);
    serverRequest.form("openStatus", 1);
    serverRequest.form("protocol", protocol);
    serverRequest.form("url", url.getHost() + CharPool.COLON + url.getPort());
    AgentAuthorize agentAuthorize = AgentAuthorize.getInstance();
    serverRequest.form("loginName", agentAuthorize.getAgentName());
    serverRequest.form("loginPwd", agentAuthorize.getAgentPwd());
    serverRequest.form("type", eqInstall ? "update" : "add");
    String body = serverRequest.execute().body();
    DefaultSystemLog.getLog().info("自动注册Server:" + body);
    JsonMessage regJsonMessage = JSON.parseObject(body, JsonMessage.class);
    if (regJsonMessage.getCode() == HttpStatus.HTTP_OK) {
        if (serverJson == null) {
            serverJson = new JSONObject();
        }
        if (!eqInstall) {
            serverJson.put("installId", installId);
            serverJson.put("regTime", DateTime.now().toString());
        } else {
            serverJson.put("updateTime", DateTime.now().toString());
        }
        JsonFileUtil.saveJson(file.getAbsolutePath(), serverJson);
    } else {
        DefaultSystemLog.getLog().error("自动注册插件端失败:{}", body);
    }
}
Also used : HttpRequest(cn.hutool.http.HttpRequest) JSONObject(com.alibaba.fastjson.JSONObject) AgentAuthorize(io.jpom.system.AgentAuthorize) JsonMessage(cn.jiangzeyin.common.JsonMessage) FileNotFoundException(java.io.FileNotFoundException) AgentExtConfigBean(io.jpom.system.AgentExtConfigBean) File(java.io.File) URL(java.net.URL) PreLoadMethod(cn.jiangzeyin.common.PreLoadMethod)

Aggregations

PreLoadMethod (cn.jiangzeyin.common.PreLoadMethod)9 File (java.io.File)4 DefaultSystemLog (cn.jiangzeyin.common.DefaultSystemLog)2 PreLoadClass (cn.jiangzeyin.common.PreLoadClass)2 JSONObject (com.alibaba.fastjson.JSONObject)2 JpomManifest (io.jpom.common.JpomManifest)2 Arrays (java.util.Arrays)2 CollUtil (cn.hutool.core.collection.CollUtil)1 ExceptionUtil (cn.hutool.core.exceptions.ExceptionUtil)1 FileUtil (cn.hutool.core.io.FileUtil)1 IoUtil (cn.hutool.core.io.IoUtil)1 Console (cn.hutool.core.lang.Console)1 CharsetUtil (cn.hutool.core.util.CharsetUtil)1 ObjectUtil (cn.hutool.core.util.ObjectUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 SecureUtil (cn.hutool.crypto.SecureUtil)1 Db (cn.hutool.db.Db)1 DSFactory (cn.hutool.db.ds.DSFactory)1 GlobalDSFactory (cn.hutool.db.ds.GlobalDSFactory)1 SqlLog (cn.hutool.db.sql.SqlLog)1