Search in sources :

Example 1 with JpomManifest

use of io.jpom.common.JpomManifest in project Jpom by dromara.

the class NodeService method testNode.

/**
 * 测试节点是否可以访问
 *
 * @param nodeModel 节点信息
 */
public void testNode(NodeModel nodeModel) {
    // 
    int timeOut = ObjectUtil.defaultIfNull(nodeModel.getTimeOut(), 0);
    // 检查是否可用默认为5秒,避免太长时间无法连接一直等待
    nodeModel.setTimeOut(5);
    // 
    JsonMessage<Object> objectJsonMessage = NodeForward.requestBySys(nodeModel, NodeUrl.Info, "nodeId", nodeModel.getId());
    JpomManifest jpomManifest = objectJsonMessage.getData(JpomManifest.class);
    Assert.notNull(jpomManifest, "节点连接失败,请检查节点是否在线");
    // 
    nodeModel.setTimeOut(timeOut);
}
Also used : JpomManifest(io.jpom.common.JpomManifest)

Example 2 with JpomManifest

use of io.jpom.common.JpomManifest in project Jpom by dromara.

the class AutoImportLocalNode method findPid.

private static void findPid(String pid) {
    File file = ConfigBean.getInstance().getApplicationJpomInfo(Type.Agent);
    if (!file.exists() || file.isDirectory()) {
        return;
    }
    // 比较进程id
    String json = FileUtil.readString(file, CharsetUtil.CHARSET_UTF_8);
    JpomManifest jpomManifest = JSONObject.parseObject(json, JpomManifest.class);
    if (!pid.equals(String.valueOf(jpomManifest.getPid()))) {
        return;
    }
    // 判断自动授权文件是否存在
    String path = ConfigBean.getInstance().getAgentAutoAuthorizeFile(jpomManifest.getDataPath());
    if (!FileUtil.exist(path)) {
        return;
    }
    json = FileUtil.readString(path, CharsetUtil.CHARSET_UTF_8);
    AgentAutoUser autoUser = JSONObject.parseObject(json, AgentAutoUser.class);
    // 判断授权信息
    // 
    NodeModel nodeModel = new NodeModel();
    nodeModel.setUrl(StrUtil.format("127.0.0.1:{}", jpomManifest.getPort()));
    nodeModel.setName("本机");
    // nodeModel.setProtocol("http");
    // 
    nodeModel.setLoginPwd(autoUser.getAgentPwd());
    nodeModel.setLoginName(autoUser.getAgentName());
    // 
    nodeModel.setOpenStatus(1);
    nodeService.insertNotFill(nodeModel);
    Console.log("Automatically add native node successfully:" + nodeModel.getId());
}
Also used : NodeModel(io.jpom.model.data.NodeModel) JpomManifest(io.jpom.common.JpomManifest) AgentAutoUser(io.jpom.model.system.AgentAutoUser) File(java.io.File)

Example 3 with JpomManifest

use of io.jpom.common.JpomManifest in project Jpom by dromara.

the class BackupInfoService method backupToSql.

/**
 * 备份数据库 SQL 文件
 *
 * @param tableNameList 需要备份的表名称列表,如果是全库备份,则不需要
 */
private void backupToSql(final List<String> tableNameList, BackupTypeEnum backupType) {
    final String fileName = LocalDateTimeUtil.format(LocalDateTimeUtil.now(), DatePattern.PURE_DATETIME_PATTERN);
    // 设置默认备份 SQL 的文件地址
    File file = FileUtil.file(DbConfig.getInstance().dbLocalPath(), Const.BACKUP_DIRECTORY_NAME, fileName + Const.SQL_FILE_SUFFIX);
    final String backupSqlPath = FileUtil.getAbsolutePath(file);
    // 数据源参数
    final String url = DbConfig.getInstance().getDbUrl();
    final String user = dbExtConfig.getUserName();
    final String pass = dbExtConfig.getUserPwd();
    JpomManifest instance = JpomManifest.getInstance();
    // 先构造备份信息插入数据库
    BackupInfoModel backupInfoModel = new BackupInfoModel();
    String timeStamp = instance.getTimeStamp();
    try {
        DateTime parse = DateUtil.parse(timeStamp);
        backupInfoModel.setBaleTimeStamp(parse.getTime());
    } catch (Exception ignored) {
    }
    backupInfoModel.setName(fileName);
    backupInfoModel.setVersion(instance.getVersion());
    backupInfoModel.setBackupType(backupType.getCode());
    backupInfoModel.setFilePath(backupSqlPath);
    this.insert(backupInfoModel);
    // 开启一个子线程去执行任务,任务完成之后修改对应的数据库备份信息
    ThreadUtil.execute(() -> {
        // 修改用的实体类
        BackupInfoModel backupInfo = new BackupInfoModel();
        BeanUtil.copyProperties(backupInfoModel, backupInfo);
        try {
            DefaultSystemLog.getLog().debug("start a new Thread to execute H2 Database backup...start");
            IPlugin plugin = PluginFactory.getPlugin("db-h2");
            Map<String, Object> map = new HashMap<>(10);
            map.put("url", url);
            map.put("user", user);
            map.put("pass", pass);
            map.put("backupSqlPath", backupSqlPath);
            map.put("tableNameList", tableNameList);
            plugin.execute("backupSql", map);
            // h2BackupService.backupSql(url, user, pass, backupSqlPath, tableNameList);
            // 修改备份任务执行完成
            backupInfo.setFileSize(FileUtil.size(file));
            backupInfo.setSha1Sum(SecureUtil.sha1(file));
            backupInfo.setStatus(BackupStatusEnum.SUCCESS.getCode());
            this.update(backupInfo);
            DefaultSystemLog.getLog().debug("start a new Thread to execute H2 Database backup...success");
        } catch (Exception e) {
            // 记录错误日志信息,修改备份任务执行失败
            DefaultSystemLog.getLog().error("start a new Thread to execute H2 Database backup...catch exception...", e);
            backupInfo.setStatus(BackupStatusEnum.FAILED.getCode());
            this.update(backupInfo);
        }
    });
}
Also used : BackupInfoModel(io.jpom.model.data.BackupInfoModel) JpomManifest(io.jpom.common.JpomManifest) HashMap(java.util.HashMap) File(java.io.File) IPlugin(io.jpom.plugin.IPlugin)

Example 4 with JpomManifest

use of io.jpom.common.JpomManifest in project Jpom by dromara.

the class IndexController method status.

/**
 * 返回节点项目状态信息
 *
 * @return array
 */
@RequestMapping(value = "status", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String status() {
    List<NodeProjectInfoModel> nodeProjectInfoModels = projectInfoService.list();
    List<NodeScriptModel> list = nodeScriptServer.list();
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("javaVirtualCount", JvmUtil.getJavaVirtualCount());
    JpomManifest instance = JpomManifest.getInstance();
    jsonObject.put("osName", instance.getOsName());
    jsonObject.put("jpomVersion", instance.getVersion());
    jsonObject.put("javaVersion", SystemUtil.getJavaRuntimeInfo().getVersion());
    // 获取JVM中内存总大小
    long totalMemory = SystemUtil.getTotalMemory();
    jsonObject.put("totalMemory", FileUtil.readableFileSize(totalMemory));
    // 
    long freeMemory = SystemUtil.getFreeMemory();
    jsonObject.put("freeMemory", FileUtil.readableFileSize(freeMemory));
    // 
    jsonObject.put("count", CollUtil.size(nodeProjectInfoModels));
    jsonObject.put("scriptCount", CollUtil.size(list));
    // 运行时间
    jsonObject.put("runTime", instance.getUpTimeStr());
    jsonObject.put("runTimeLong", instance.getUpTime());
    return JsonMessage.getString(200, "", jsonObject);
}
Also used : NodeProjectInfoModel(io.jpom.model.data.NodeProjectInfoModel) NodeScriptModel(io.jpom.model.data.NodeScriptModel) JSONObject(com.alibaba.fastjson.JSONObject) JpomManifest(io.jpom.common.JpomManifest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with JpomManifest

use of io.jpom.common.JpomManifest in project Jpom by dromara.

the class IndexController method info.

@RequestMapping(value = "info", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String info() {
    JpomManifest instance = JpomManifest.getInstance();
    RemoteVersion remoteVersion = RemoteVersion.cacheInfo();
    // 
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("manifest", instance);
    jsonObject.put("remoteVersion", remoteVersion);
    jsonObject.put("pluginSize", PluginFactory.size());
    return JsonMessage.getString(200, "", jsonObject);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JpomManifest(io.jpom.common.JpomManifest) RemoteVersion(io.jpom.common.RemoteVersion) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JpomManifest (io.jpom.common.JpomManifest)5 JSONObject (com.alibaba.fastjson.JSONObject)2 File (java.io.File)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 RemoteVersion (io.jpom.common.RemoteVersion)1 BackupInfoModel (io.jpom.model.data.BackupInfoModel)1 NodeModel (io.jpom.model.data.NodeModel)1 NodeProjectInfoModel (io.jpom.model.data.NodeProjectInfoModel)1 NodeScriptModel (io.jpom.model.data.NodeScriptModel)1 AgentAutoUser (io.jpom.model.system.AgentAutoUser)1 IPlugin (io.jpom.plugin.IPlugin)1 HashMap (java.util.HashMap)1