11111
parent
f65d73f2fb
commit
37afcd0eea
|
@ -12,7 +12,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import redis.clients.jedis.timeseries.TSInfo;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -68,10 +67,10 @@ public class DownloadOssSynchronization implements ApplicationRunner {
|
||||||
ossClient.shutdown();
|
ossClient.shutdown();
|
||||||
//下载完成实现批量批量类加载
|
//下载完成实现批量批量类加载
|
||||||
|
|
||||||
for (OSSObjectSummary objectSummary : objectListing.getObjectSummaries()) {
|
// for (OSSObjectSummary objectSummary : objectListing.getObjectSummaries()) {
|
||||||
String key = objectSummary.getKey();
|
// String key = objectSummary.getKey();
|
||||||
ruleEngineVersionService.loadValueEngineClass(key);
|
// ruleEngineVersionService.loadRuleEngineClass(key);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.muyu.rule.server.controller;
|
package com.muyu.rule.server.controller;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.common.domain.DataValue;
|
import com.muyu.common.domain.DataValue;
|
||||||
|
@ -282,17 +281,7 @@ Object o= versionService.readByOss(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/testEngine/{className}")
|
|
||||||
@Operation(summary = "规则引擎测试", description = "传入规则引擎的类名,和数据,用规则引擎进行测试数据")
|
|
||||||
public Result testEngine(@PathVariable("className") String className,@RequestBody DataValue dataValue){
|
|
||||||
log.info("数据:" + dataValue);
|
|
||||||
//加载对应的规则引擎
|
|
||||||
versionService.loadValueEngineClass(className);
|
|
||||||
//执行对应的规则引擎
|
|
||||||
DataValue value = versionService.testEngine(className, dataValue);
|
|
||||||
|
|
||||||
return Result.success(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过id查询对应的版本
|
* 通过id查询对应的版本
|
||||||
|
@ -309,13 +298,34 @@ public Result<List<RuleEngineVersion>> selectVersionById(@PathVariable("id") Lon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/testEngine/{className}")
|
||||||
|
@Operation(summary = "字段规则引擎测试", description = "传入规则引擎的类名,和数据,用规则引擎进行测试数据")
|
||||||
|
public Result testEngine(@PathVariable("className") String className,@RequestBody DataValue dataValue){
|
||||||
|
log.info("数据:" + dataValue);
|
||||||
|
//加载对应的规则引擎
|
||||||
|
versionService.loadValueEngineClass(className);
|
||||||
|
//执行对应的规则引擎
|
||||||
|
DataValue value = versionService.testEngine(className, dataValue);
|
||||||
|
|
||||||
|
return Result.success(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/rowEngine/{className}")
|
||||||
|
@Operation(summary = "行/记录规则引擎测试", description = "传入规则引擎的类名,和数据,用规则引擎进行测试数据")
|
||||||
|
public Result testEngine(@PathVariable("className") String className,@RequestBody DataValue[] dataValue){
|
||||||
|
log.info("数据:" + dataValue);
|
||||||
|
//加载对应的规则引擎
|
||||||
|
versionService.loadRowEngineClass(className);
|
||||||
|
//执行对应的规则引擎
|
||||||
|
DataValue[] value = versionService.testEngine(className, dataValue);
|
||||||
|
|
||||||
|
return Result.success(value);
|
||||||
|
}
|
||||||
@PostMapping("/DataSetEngine/{className}")
|
@PostMapping("/DataSetEngine/{className}")
|
||||||
|
@Operation(summary = "数据集的规则引擎测试", description = "传入规则引擎的类名,和数据,用规则引擎进行测试数据")
|
||||||
public Result DataSetEngine(@PathVariable("className") String className,@RequestBody DataValue[][] dataValues){
|
public Result DataSetEngine(@PathVariable("className") String className,@RequestBody DataValue[][] dataValues){
|
||||||
|
|
||||||
versionService.loadDateSetEngineClass(className);
|
versionService.loadDataSetEngineClass(className);
|
||||||
|
|
||||||
DataValue[][] testedEngine = versionService.testEngine(className, dataValues);
|
DataValue[][] testedEngine = versionService.testEngine(className, dataValues);
|
||||||
|
|
||||||
|
|
|
@ -65,13 +65,11 @@ public interface RuleEngineVersionService extends IService<RuleEngineVersion> {
|
||||||
* @param className 规则引擎类名
|
* @param className 规则引擎类名
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void loadValueEngineClass(String className);
|
// void loadRuleEngineClass(String className);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String deposit(Integer type);
|
|
||||||
void loadDateSetEngineClass(String className);
|
|
||||||
/**
|
/**
|
||||||
* 测试数据
|
* 测试数据
|
||||||
*
|
*
|
||||||
|
@ -84,4 +82,10 @@ public interface RuleEngineVersionService extends IService<RuleEngineVersion> {
|
||||||
public DataValue[] testEngine(String className, DataValue[] dataValue);
|
public DataValue[] testEngine(String className, DataValue[] dataValue);
|
||||||
|
|
||||||
public DataValue[][] testEngine( String className, DataValue[][] dataValues);
|
public DataValue[][] testEngine( String className, DataValue[][] dataValues);
|
||||||
|
|
||||||
|
void loadValueEngineClass(String className);
|
||||||
|
|
||||||
|
void loadRowEngineClass(String className);
|
||||||
|
|
||||||
|
void loadDataSetEngineClass(String className);
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,11 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
public static final String serverClassPath = "com/muyu/rule/common/engine/";
|
public static final String serverClassPath = "com/muyu/rule/common/engine/";
|
||||||
|
|
||||||
|
|
||||||
//todo
|
/**
|
||||||
|
* 编译
|
||||||
|
* @param className 类名
|
||||||
|
* @param versionClazz 源代码
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void complierClass(String className, String versionClazz) {
|
public void complierClass(String className, String versionClazz) {
|
||||||
log.info("======>" + versionClazz);
|
log.info("======>" + versionClazz);
|
||||||
|
@ -153,7 +157,7 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
InputStream first = null; // 程序的输入 null 用 system.in
|
InputStream first = null; // 程序的输入 null 用 system.in
|
||||||
OutputStream second = null; // 程序的输出 null 用 system.out
|
OutputStream second = null; // 程序的输出 null 用 system.out
|
||||||
OutputStream third = null; // 程序的错误输出 .,null 用 system.err
|
OutputStream third = null; // 程序的错误输出 .,null 用 system.err
|
||||||
// 程序编译参数 注意 我们编译目录是我们的项目目录
|
// 程序编译参数 注意 编译目录是项目的目录
|
||||||
String[] strings = {"-classpath", "home/lib/", "-verbose", "-d", "home/lib/", "home/source/" + className + ".java"};
|
String[] strings = {"-classpath", "home/lib/", "-verbose", "-d", "home/lib/", "home/source/" + className + ".java"};
|
||||||
log.info("规则引擎的编译参数{}[]", Arrays.toString(strings));
|
log.info("规则引擎的编译参数{}[]", Arrays.toString(strings));
|
||||||
// 0 表示成功, 其他表示出现了错误
|
// 0 表示成功, 其他表示出现了错误
|
||||||
|
@ -166,8 +170,6 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
}
|
}
|
||||||
|
|
||||||
OssUtil.ssss(className);
|
OssUtil.ssss(className);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -175,52 +177,20 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
*
|
*
|
||||||
* @param className 规则引擎类名
|
* @param className 规则引擎类名
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void loadValueEngineClass(String className) {
|
|
||||||
|
|
||||||
//查询类是否已加载,避免重复加载规则引擎
|
|
||||||
if (!engineMap.containsKey(className)) {
|
|
||||||
log.info("引擎map集合下没有该实例的规则,进行自定义类加载");
|
|
||||||
|
|
||||||
Object instance = loadMethod(className);
|
|
||||||
//将加载出来引擎实例存入map集合中
|
|
||||||
engineMap.put(className, (BasicEngine<DataValue>) instance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Object loadMethod(String className) {
|
/**
|
||||||
try {
|
* 修改激活
|
||||||
// 假设这是你的外部类文件路径
|
* @param id
|
||||||
String externalClassFilePath =
|
* @param open
|
||||||
importClassAndPackPath + serverClassPath + className + Suffix_CLASS;
|
*/
|
||||||
Path classFilePath = Paths.get(externalClassFilePath);
|
public void updateOpen(Long id, String open) {
|
||||||
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
|
||||||
URL[] urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
|
||||||
|
|
||||||
//创建自定义类加载器
|
UpdateWrapper<RuleEngineVersion> updateWrapper = new UpdateWrapper<>();
|
||||||
ExternalClassLoader externalClassLoader = new ExternalClassLoader(urls);
|
|
||||||
|
|
||||||
//加载类
|
updateWrapper.eq("id", id).set("open", open);
|
||||||
//注意类名必须是完全限定名(包括包名)
|
|
||||||
Class<?> clazz = null;
|
|
||||||
|
|
||||||
clazz = externalClassLoader.loadClassFromPath(classFilePath, className_prefix + className);
|
|
||||||
//创建类的实例
|
|
||||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
|
||||||
return instance;
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (InstantiationException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
this.update(updateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -255,21 +225,8 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
DataValue[] dataValues = basicEngine.get();
|
DataValue[] dataValues = basicEngine.get();
|
||||||
return dataValues;
|
return dataValues;
|
||||||
}
|
}
|
||||||
public void execution(String engineKey,DataValue dataValue){
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String deposit(Integer type) {
|
|
||||||
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataValue[][] testEngine(String className, DataValue[][] dataValues) {
|
public DataValue[][] testEngine(String className, DataValue[][] dataValues) {
|
||||||
|
|
||||||
|
@ -285,32 +242,134 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadDateSetEngineClass(String className) {
|
public void loadValueEngineClass(String className) {
|
||||||
|
|
||||||
|
//查询类是否已加载,避免重复加载规则引擎
|
||||||
|
if (!engineMap.containsKey(className)) {
|
||||||
|
log.info("引擎map集合下没有该实例的规则,进行自定义类加载");
|
||||||
|
try {
|
||||||
|
// 假设这是你的外部类文件路径
|
||||||
|
String externalClassFilePath =
|
||||||
|
importClassAndPackPath + serverClassPath + className + Suffix_CLASS;
|
||||||
|
Path classFilePath = Paths.get(externalClassFilePath);
|
||||||
|
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
||||||
|
URL[] urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
||||||
|
|
||||||
|
//创建自定义类加载器
|
||||||
|
ExternalClassLoader externalClassLoader = new ExternalClassLoader(urls);
|
||||||
|
//加载类
|
||||||
|
//注意类名必须是完全限定名(包括包名)
|
||||||
|
Class<?> clazz = null;
|
||||||
|
clazz = externalClassLoader.loadClassFromPath(classFilePath, className_prefix + className);
|
||||||
|
//创建类的实例
|
||||||
|
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
|
//将加载出来引擎实例存入map集合中
|
||||||
|
|
||||||
|
engineMap.put(className,(BasicEngine<DataValue>) instance);
|
||||||
|
|
||||||
|
} catch (IOException | InvocationTargetException | InstantiationException | IllegalAccessException |
|
||||||
|
NoSuchMethodException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadRowEngineClass(String className) {
|
||||||
|
|
||||||
|
//查询类是否已加载,避免重复加载规则引擎
|
||||||
|
if (!engineRowMap.containsKey(className)) {
|
||||||
|
log.info("引擎map集合下没有该实例的规则,进行自定义类加载");
|
||||||
|
try {
|
||||||
|
// 假设这是你的外部类文件路径
|
||||||
|
String externalClassFilePath =
|
||||||
|
importClassAndPackPath + serverClassPath + className + Suffix_CLASS;
|
||||||
|
Path classFilePath = Paths.get(externalClassFilePath);
|
||||||
|
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
||||||
|
URL[] urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
||||||
|
|
||||||
|
//创建自定义类加载器
|
||||||
|
ExternalClassLoader externalClassLoader = new ExternalClassLoader(urls);
|
||||||
|
|
||||||
|
//加载类
|
||||||
|
//注意类名必须是完全限定名(包括包名)
|
||||||
|
Class<?> clazz = null;
|
||||||
|
|
||||||
|
clazz = externalClassLoader.loadClassFromPath(classFilePath, className_prefix + className);
|
||||||
|
//创建类的实例
|
||||||
|
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
|
//将加载出来引擎实例存入map集合中
|
||||||
|
|
||||||
|
engineRowMap.put(className,(BasicEngine<DataValue[]>) instance);
|
||||||
|
|
||||||
|
} catch (IOException | InvocationTargetException | InstantiationException | IllegalAccessException |
|
||||||
|
NoSuchMethodException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadDataSetEngineClass(String className) {
|
||||||
|
|
||||||
//查询类是否已加载,避免重复加载规则引擎
|
//查询类是否已加载,避免重复加载规则引擎
|
||||||
if (!engineDataSetMap.containsKey(className)) {
|
if (!engineDataSetMap.containsKey(className)) {
|
||||||
log.info("引擎map集合下没有该实例的规则,进行自定义类加载");
|
log.info("引擎map集合下没有该实例的规则,进行自定义类加载");
|
||||||
|
try {
|
||||||
|
// 设置外部类文件路径
|
||||||
|
String externalClassFilePath =
|
||||||
|
importClassAndPackPath + serverClassPath + className + Suffix_CLASS;
|
||||||
|
Path classFilePath = Paths.get(externalClassFilePath);
|
||||||
|
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
||||||
|
URL[] urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
||||||
|
|
||||||
Object instance = loadMethod(className);
|
//创建自定义类加载器
|
||||||
//将加载出来引擎实例存入map集合中
|
ExternalClassLoader externalClassLoader = new ExternalClassLoader(urls);
|
||||||
engineDataSetMap.put(className, (BasicEngine<DataValue[][]>) instance);
|
|
||||||
|
//加载类
|
||||||
|
//注意类名必须是完全限定名(包括包名)
|
||||||
|
Class<?> clazz = null;
|
||||||
|
|
||||||
|
clazz = externalClassLoader.loadClassFromPath(classFilePath, className_prefix + className);
|
||||||
|
//创建类的实例
|
||||||
|
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
|
//将加载出来引擎实例存入map集合中
|
||||||
|
|
||||||
|
engineDataSetMap.put(className,(BasicEngine<DataValue[][]>) instance);
|
||||||
|
|
||||||
|
} catch (IOException | InvocationTargetException | InstantiationException | IllegalAccessException |
|
||||||
|
NoSuchMethodException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改激活
|
|
||||||
*
|
|
||||||
* @param id
|
|
||||||
* @param open
|
|
||||||
*/
|
|
||||||
public void updateOpen(Long id, String open) {
|
|
||||||
|
|
||||||
UpdateWrapper<RuleEngineVersion> updateWrapper = new UpdateWrapper<>();
|
public void execution(String engineKey,DataValue dataValue){
|
||||||
|
|
||||||
updateWrapper.eq("id", id).set("open", open);
|
BasicEngine<DataValue> dataValueBasicEngine = engineMap.get(engineKey);
|
||||||
|
dataValueBasicEngine.set(dataValue);
|
||||||
this.update(updateWrapper);
|
dataValueBasicEngine.execution();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void execution(String engineKey,DataValue[] dataValue){
|
||||||
|
|
||||||
|
BasicEngine<DataValue[]> dataValueBasicEngine = engineRowMap.get(engineKey);
|
||||||
|
dataValueBasicEngine.set(dataValue);
|
||||||
|
dataValueBasicEngine.execution();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void execution(String engineKey,DataValue[][] dataValue){
|
||||||
|
|
||||||
|
BasicEngine<DataValue[][]> dataValueBasicEngine = engineDataSetMap.get(engineKey);
|
||||||
|
dataValueBasicEngine.set(dataValue);
|
||||||
|
dataValueBasicEngine.execution();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue