mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-11-30 10:58:14 +08:00
修护未加载到tools.jar判断
This commit is contained in:
parent
a338c4614d
commit
8297866ce4
@ -10,6 +10,7 @@
|
||||
### 解决BUG、优化功能
|
||||
|
||||
1. 【Server】节点分发需要节点数大于二(感谢@Sawyer)
|
||||
2. 修护未加载到tools.jar判断(感谢@java-磊)
|
||||
|
||||
-----------------------------------------------------------
|
||||
|
||||
|
@ -5,12 +5,12 @@
|
||||
<parent>
|
||||
<artifactId>jpom-parent</artifactId>
|
||||
<groupId>io.jpom</groupId>
|
||||
<version>2.4.4</version>
|
||||
<version>2.4.5</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>agent</artifactId>
|
||||
<version>2.4.4</version>
|
||||
<version>2.4.5</version>
|
||||
<name>Jpom 插件端</name>
|
||||
<properties>
|
||||
<start-class>io.jpom.JpomAgentApplication</start-class>
|
||||
|
@ -218,7 +218,7 @@ public abstract class AbstractProjectCommander {
|
||||
try (JarFile jarFile1 = new JarFile(jarFile)) {
|
||||
Manifest manifest = jarFile1.getManifest();
|
||||
Attributes attributes = manifest.getMainAttributes();
|
||||
String mainClass = attributes.getValue("Main-Class");
|
||||
String mainClass = attributes.getValue(Attributes.Name.MAIN_CLASS);
|
||||
if (mainClass == null) {
|
||||
return jarFile.getAbsolutePath() + "中没有找到对应的MainClass属性";
|
||||
}
|
||||
|
@ -5,13 +5,13 @@
|
||||
<parent>
|
||||
<artifactId>jpom-parent</artifactId>
|
||||
<groupId>io.jpom</groupId>
|
||||
<version>2.4.4</version>
|
||||
<version>2.4.5</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<name>Jpom 公共模块</name>
|
||||
<artifactId>common</artifactId>
|
||||
<version>2.4.4</version>
|
||||
<version>2.4.5</version>
|
||||
|
||||
<dependencies>
|
||||
<!-- 文件编码识别-->
|
||||
|
@ -226,7 +226,7 @@ public class JpomManifest {
|
||||
try (JarFile jarFile1 = new JarFile(jarFile)) {
|
||||
Manifest manifest = jarFile1.getManifest();
|
||||
Attributes attributes = manifest.getMainAttributes();
|
||||
String mainClass = attributes.getValue("Main-Class");
|
||||
String mainClass = attributes.getValue(Attributes.Name.MAIN_CLASS);
|
||||
if (mainClass == null) {
|
||||
return new JsonMessage(405, "清单文件中没有找到对应的MainClass属性");
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
package io.jpom.system.init;
|
||||
|
||||
import cn.jiangzeyin.common.DefaultSystemLog;
|
||||
import io.jpom.JpomApplication;
|
||||
import io.jpom.common.JpomManifest;
|
||||
import io.jpom.util.JvmUtil;
|
||||
import sun.jvmstat.monitor.MonitoredVm;
|
||||
import sun.jvmstat.monitor.VmIdentifier;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author bwcx_jzy
|
||||
* @date 2019/9/5
|
||||
*/
|
||||
class CheckDuplicateRun {
|
||||
|
||||
static void check() {
|
||||
try {
|
||||
Class appClass = JpomApplication.getAppClass();
|
||||
String pid = String.valueOf(JpomManifest.getInstance().getPid());
|
||||
List<MonitoredVm> monitoredVms = JvmUtil.listMainClass(appClass.getName());
|
||||
monitoredVms.forEach(monitoredVm -> {
|
||||
VmIdentifier vmIdentifier = monitoredVm.getVmIdentifier();
|
||||
if (pid.equals(vmIdentifier.getUserInfo())) {
|
||||
return;
|
||||
}
|
||||
DefaultSystemLog.LOG().info("Jpom 程序建议一个机器上只运行一个对应的程序:" + JpomApplication.getAppType() + " pid:" + vmIdentifier.getUserInfo());
|
||||
});
|
||||
} catch (Exception e) {
|
||||
DefaultSystemLog.ERROR().error("检查异常", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,19 +5,12 @@ import cn.hutool.core.util.ClassUtil;
|
||||
import cn.jiangzeyin.common.DefaultSystemLog;
|
||||
import cn.jiangzeyin.common.PreLoadClass;
|
||||
import cn.jiangzeyin.common.PreLoadMethod;
|
||||
import io.jpom.JpomApplication;
|
||||
import io.jpom.common.JpomManifest;
|
||||
import io.jpom.system.ConfigBean;
|
||||
import io.jpom.system.ExtConfigBean;
|
||||
import io.jpom.util.JvmUtil;
|
||||
import sun.jvmstat.monitor.MonitorException;
|
||||
import sun.jvmstat.monitor.MonitoredVm;
|
||||
import sun.jvmstat.monitor.VmIdentifier;
|
||||
import io.jpom.util.StringUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据目录权限检查
|
||||
@ -33,14 +26,14 @@ public class CheckPath {
|
||||
private static final String[] CLASS_NAME = new String[]{"sun.jvmstat.monitor.MonitorException", "com.sun.tools.attach.VirtualMachine"};
|
||||
|
||||
|
||||
@PreLoadMethod(2)
|
||||
@PreLoadMethod(1)
|
||||
private static void checkToolsJar() {
|
||||
try {
|
||||
for (String item : CLASS_NAME) {
|
||||
ClassUtil.loadClass(item, false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
File file = JvmUtil.getToolsJar();
|
||||
File file = StringUtil.getToolsJar();
|
||||
if (file.exists() && file.isFile()) {
|
||||
DefaultSystemLog.ERROR().error("Jpom未能正常加载tools.jar,请检查当前系统环境变量是否配置:JAVA_HOME,或者检查Jpom管理命令是否正确", e);
|
||||
} else {
|
||||
@ -55,21 +48,7 @@ public class CheckPath {
|
||||
*/
|
||||
@PreLoadMethod(2)
|
||||
private static void checkDuplicateRun() {
|
||||
Class appClass = JpomApplication.getAppClass();
|
||||
List<MonitoredVm> monitoredVms;
|
||||
try {
|
||||
String pid = String.valueOf(JpomManifest.getInstance().getPid());
|
||||
monitoredVms = JvmUtil.listMainClass(appClass.getName());
|
||||
monitoredVms.forEach(monitoredVm -> {
|
||||
VmIdentifier vmIdentifier = monitoredVm.getVmIdentifier();
|
||||
if (pid.equals(vmIdentifier.getUserInfo())) {
|
||||
return;
|
||||
}
|
||||
DefaultSystemLog.LOG().info("Jpom 程序建议一个机器上只运行一个对应的程序:" + JpomApplication.getAppType());
|
||||
|
||||
});
|
||||
} catch (MonitorException | URISyntaxException ignored) {
|
||||
}
|
||||
CheckDuplicateRun.check();
|
||||
}
|
||||
|
||||
@PreLoadMethod(3)
|
||||
|
@ -25,6 +25,9 @@ import java.lang.reflect.Method;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
/**
|
||||
* jvm jmx 工具
|
||||
@ -285,16 +288,6 @@ public class JvmUtil {
|
||||
throw new JpomRuntimeException("JDK中" + file.getAbsolutePath() + " 文件不存在");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取jdk 中的tools jar文件路径
|
||||
*
|
||||
* @return file
|
||||
*/
|
||||
public static File getToolsJar() {
|
||||
File file = new File(SystemUtil.getJavaRuntimeInfo().getHomeDir());
|
||||
return new File(file.getParentFile(), "lib/tools.jar");
|
||||
}
|
||||
|
||||
/**
|
||||
* 工具指定的 mainClass 获取对应所有的的 MonitoredVm对象
|
||||
*
|
||||
@ -313,11 +306,28 @@ public class JvmUtil {
|
||||
MonitoredVm vm = local.getMonitoredVm(new VmIdentifier("//" + process));
|
||||
// 获取类名
|
||||
String processName = MonitoredVmUtil.mainClass(vm, true);
|
||||
if (!mainClass.equals(processName)) {
|
||||
continue;
|
||||
}
|
||||
if (mainClass.equals(processName) || checkFile(processName, mainClass)) {
|
||||
monitoredVms.add(vm);
|
||||
}
|
||||
}
|
||||
return monitoredVms;
|
||||
}
|
||||
|
||||
private static boolean checkFile(String fileName, String mainClass) {
|
||||
try {
|
||||
File file = FileUtil.file(fileName);
|
||||
if (!file.exists() || file.isDirectory()) {
|
||||
return false;
|
||||
}
|
||||
try (JarFile jarFile1 = new JarFile(file)) {
|
||||
Manifest manifest = jarFile1.getManifest();
|
||||
Attributes attributes = manifest.getMainAttributes();
|
||||
String jarMainClass = attributes.getValue(Attributes.Name.MAIN_CLASS);
|
||||
String jarStartClass = attributes.getValue("Start-Class");
|
||||
return StrUtil.equals(mainClass, jarMainClass) || StrUtil.equals(mainClass, jarStartClass);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package io.jpom.util;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.system.SystemUtil;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@ -77,4 +78,14 @@ public class StringUtil {
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取jdk 中的tools jar文件路径
|
||||
*
|
||||
* @return file
|
||||
*/
|
||||
public static File getToolsJar() {
|
||||
File file = new File(SystemUtil.getJavaRuntimeInfo().getHomeDir());
|
||||
return new File(file.getParentFile(), "lib/tools.jar");
|
||||
}
|
||||
}
|
||||
|
@ -17,20 +17,20 @@ public class ContiPerTest {
|
||||
@Rule
|
||||
public ContiPerfRule i = new ContiPerfRule();
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
@PerfTest(invocations = 200000000, threads = 16)
|
||||
public void test1() throws Exception {
|
||||
IdUtil.fastSimpleUUID();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
@PerfTest(invocations = 200000000, threads = 16)
|
||||
public void test2() throws Exception {
|
||||
UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
// @Test
|
||||
@PerfTest(invocations = 20000, threads = 16)
|
||||
public void testHttp() {
|
||||
HttpUtil.createGet("https://baidu.com")
|
||||
|
@ -5,13 +5,13 @@
|
||||
<parent>
|
||||
<artifactId>jpom-parent</artifactId>
|
||||
<groupId>io.jpom</groupId>
|
||||
<version>2.4.4</version>
|
||||
<version>2.4.5</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<name>Jpom 服务端</name>
|
||||
<artifactId>server</artifactId>
|
||||
<version>2.4.4</version>
|
||||
<version>2.4.5</version>
|
||||
<properties>
|
||||
<start-class>io.jpom.JpomServerApplication</start-class>
|
||||
</properties>
|
||||
|
@ -16,7 +16,7 @@ import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
* @author jiangzeyin
|
||||
* @date 2017/9/14
|
||||
*/
|
||||
@SpringBootApplication(scanBasePackages = {"io.jpom"})
|
||||
@SpringBootApplication
|
||||
@ServletComponentScan
|
||||
@EnableCommonBoot
|
||||
public class JpomServerApplication implements ApplicationEventLoad {
|
||||
|
@ -29,10 +29,9 @@ public class NodeInfoController extends AbstractController {
|
||||
* @param model 节点对象
|
||||
* @param type 操作类型
|
||||
* @return json
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
@RequestMapping(value = ServerOpenApi.UPDATE_NODE_INFO, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
public String update(NodeModel model, String type) throws Exception {
|
||||
public String update(NodeModel model, String type) {
|
||||
if ("add".equalsIgnoreCase(type)) {
|
||||
return nodeService.addNode(model, getRequest());
|
||||
} else {
|
||||
|
@ -101,7 +101,7 @@ public class NodeService extends BaseOperService<NodeModel> implements BaseDynam
|
||||
return JsonMessage.getString(200, "操作成功");
|
||||
}
|
||||
|
||||
public String updateNode(NodeModel nodeModel) throws Exception {
|
||||
public String updateNode(NodeModel nodeModel) {
|
||||
NodeModel exit = getItem(nodeModel.getId());
|
||||
if (exit == null) {
|
||||
return JsonMessage.getString(405, "节点不存在");
|
||||
|
Loading…
Reference in New Issue
Block a user