11111
parent
9ccaf7a424
commit
0a1f212b7c
|
@ -1,4 +1,4 @@
|
|||
package com.muyu.rule.server.scan;
|
||||
package com.muyu.rule.server;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
|
@ -9,6 +9,9 @@ package com.muyu.rule.server.scan;
|
|||
*/
|
||||
public class EngineConfig {
|
||||
|
||||
public static Object executionMethodName;
|
||||
|
||||
|
||||
/**
|
||||
* 包名称
|
||||
*/
|
||||
|
@ -18,7 +21,7 @@ public class EngineConfig {
|
|||
* 本地目录名称
|
||||
*/
|
||||
|
||||
private String location ="F:\\临时\\2021年5月28日\\";
|
||||
private String location ="E:\\临时\\2021年5月28日\\";
|
||||
|
||||
|
||||
public String getPack() {
|
|
@ -1,10 +1,9 @@
|
|||
package com.muyu.rule.server.scan;
|
||||
package com.muyu.rule.server;
|
||||
|
||||
|
||||
import com.muyu.rule.server.complie.SourceCodeComplier;
|
||||
import com.muyu.rule.server.load.JavaBinaryClassLoader;
|
||||
import com.muyu.rule.server.pool.container.EngineContainer;
|
||||
import com.muyu.rule.server.scan.EngineConfig;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
|
@ -3,6 +3,7 @@ package com.muyu.rule.server.controller;
|
|||
import com.muyu.common.core.domain.Result;
|
||||
|
||||
import com.muyu.rule.common.domain.RuleEngine;
|
||||
import com.muyu.rule.common.domain.RuleRegion;
|
||||
import com.muyu.rule.common.domain.req.EtlRuleAddReq;
|
||||
import com.muyu.rule.common.domain.req.EtlRuleListReq;
|
||||
import com.muyu.rule.common.domain.req.EtlRuleUpdReq;
|
||||
|
@ -69,6 +70,7 @@ public class EtlRuleController {
|
|||
@PostMapping
|
||||
@Operation(summary = "规则引擎的添加", description = "添加规则引擎的,添加成功后可以对规则引擎进行维护")
|
||||
public Result<RuleEngine> add(@RequestBody EtlRuleAddReq etlRule){
|
||||
|
||||
etlRuleService.save(RuleEngine.addBuild(etlRule));
|
||||
return Result.success();
|
||||
}
|
||||
|
@ -101,6 +103,15 @@ public class EtlRuleController {
|
|||
}
|
||||
|
||||
|
||||
@PostMapping("/findAllRuleRegion")
|
||||
public Result<List<RuleRegion>> findAllRuleRegion(){
|
||||
|
||||
|
||||
List<RuleRegion> list = etlRuleService.findAllRuleRegion();
|
||||
|
||||
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package com.muyu.rule.server.execution;
|
||||
|
||||
import com.muyu.rule.common.domain.RuleEngine;
|
||||
import com.muyu.rule.common.domain.RuleRegion;
|
||||
import com.muyu.rule.server.load.JavaBinaryClassLoader;
|
||||
import com.muyu.rule.server.pool.container.EngineContainer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.server
|
||||
* @Project:cloud-etl-rule
|
||||
* @name:EngineExecution
|
||||
* @Date:2024/8/22 23:31
|
||||
*/
|
||||
public class EngineExecution {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(JavaBinaryClassLoader.class);
|
||||
|
||||
|
||||
public static Object engineExe(String engineKey, Map<String,Object> params){
|
||||
|
||||
Object instance = EngineContainer.getInstanceMap(engineKey);
|
||||
List<String > methodEngineParams = EngineContainer.getMethodEngineParamMap(engineKey);
|
||||
Method method = EngineContainer.getMethodMap(engineKey);
|
||||
|
||||
try{
|
||||
int methodEngineParamsLength = methodEngineParams.size();
|
||||
Object[] objects = new Object[methodEngineParamsLength];
|
||||
for (int i = 0; i < methodEngineParamsLength; i++) {
|
||||
objects[i] = params.get(methodEngineParams.get(i));
|
||||
}
|
||||
log.info("规则引擎 [{}] 调用参数 [{}]",engineKey, Arrays.toString(objects));
|
||||
Object invoke = method.invoke(instance, objects);
|
||||
log.info("规则引擎 [{}] 调用结果,[{}]",engineKey,invoke);
|
||||
|
||||
return invoke;
|
||||
}catch (IllegalAccessException e){
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -2,7 +2,11 @@ package com.muyu.rule.server.mapper;
|
|||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.rule.common.domain.RuleEngine;
|
||||
import com.muyu.rule.common.domain.RuleRegion;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
|
@ -15,4 +19,6 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
public interface EtlRuleMapper extends BaseMapper<RuleEngine> {
|
||||
|
||||
|
||||
@Select("select region_id,region_name from rule_region")
|
||||
List<RuleRegion> findAllRuleRegion();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,19 @@
|
|||
package com.muyu.rule.server.pool.container;
|
||||
|
||||
import com.muyu.rule.server.EngineConfig;
|
||||
import com.muyu.rule.server.annotation.EngineParam;
|
||||
import com.muyu.rule.server.load.JavaBinaryClassLoader;
|
||||
import com.muyu.rule.server.pool.RuleEngineException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.server
|
||||
|
@ -8,69 +22,96 @@ package com.muyu.rule.server.pool.container;
|
|||
* @Date:2024/8/22 22:32
|
||||
*/
|
||||
public class EngineContainer {
|
||||
public static void loadEngineInstance(String key, Class<?> value) {
|
||||
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(JavaBinaryClassLoader.class);
|
||||
|
||||
private static Map<String ,Object> methodMap = new ConcurrentHashMap<>(16);
|
||||
|
||||
private static Map<String ,Object> classMap = new ConcurrentHashMap<>(16);
|
||||
|
||||
private static Map<String ,Object> instanceMap = new ConcurrentHashMap<>(16);
|
||||
|
||||
|
||||
|
||||
|
||||
public static void loadEngineInstance(String engineKey,Class<?> clazz){
|
||||
|
||||
|
||||
Method method = findMethodByClass(EngineConfig.executionMethodName,clazz);
|
||||
|
||||
if (method ==null){
|
||||
log.info("初始化规则引擎 -> {} 失败 缺少 {} 方法",engineKey,EngineConfig.executionMethodName);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
instanceMap.put(engineKey,clazz.newInstance());
|
||||
} catch (InstantiationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
//
|
||||
// private static final Logger log = LoggerFactory.getLogger(JavaBinaryClassLoader.class);
|
||||
//
|
||||
// private static Map<String ,Object> instanceMap = new ConcurrentHashMap<>(16);
|
||||
//
|
||||
//
|
||||
//
|
||||
//public static void loadEngineInstance(String engineKey,Class<?> clazz){
|
||||
//
|
||||
//
|
||||
// Method method = findMethodByClass(EngineConfig.executionMethodName,clazz);
|
||||
//
|
||||
// if (method ==null){
|
||||
// log.info("初始化规则引擎 -> {} 失败 缺少 {} 方法",engineKey,EngineConfig.executionMethodName);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// instanceMap.put(engineKey,clazz.newInstance());
|
||||
// } catch (InstantiationException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// } catch (IllegalAccessException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// classMap.put(engineKey,clazz);
|
||||
// methodMap.put(engineKey,method);
|
||||
// Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
// Annotation[][] parameterAnnotations = method.getParameterAnnotations();
|
||||
// //获取参数
|
||||
// ArrayList<String> engineParams = new ArrayList<>();
|
||||
//
|
||||
// int parameterTypeLength = parameterTypes.length;
|
||||
// for (int i = 0; i < parameterTypeLength; i++) {
|
||||
// Annotation[] paramAnn = parameterAnnotations[i];
|
||||
// if (paramAnn.length == 0){
|
||||
// throw new RuleEngineException("请给所有参数填写注释!");
|
||||
// }
|
||||
// if (paramAnn.length>1){
|
||||
// throw new RuleEngineException("参数仅支持一个注释!");
|
||||
// }
|
||||
// EngineParam engineParam =null;
|
||||
// if (paramAnn[0] instanceof EngineParam){
|
||||
// engineParam = (EngineParam) paramAnn[0];
|
||||
// }
|
||||
//
|
||||
// if (engineParam ==null){
|
||||
// throw new RuleEngineException("请使用EngineParam注解");
|
||||
// } else if (engineParam.name() == null) {
|
||||
// throw new RuleEngineException("engineParam -- name 不可为null");
|
||||
// }
|
||||
// engineParams.add(engineParam.name());
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
||||
|
||||
classMap.put(engineKey,clazz);
|
||||
methodMap.put(engineKey,method);
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
|
||||
//获取参数
|
||||
ArrayList<String> engineParams = new ArrayList<>();
|
||||
|
||||
int parameterTypeLength = parameterTypes.length;
|
||||
for (int i = 0; i < parameterTypeLength; i++) {
|
||||
Annotation[] paramAnn = parameterAnnotations[i];
|
||||
if (paramAnn.length == 0){
|
||||
throw new RuleEngineException("请给所有参数填写注释!");
|
||||
}
|
||||
if (paramAnn.length>1){
|
||||
throw new RuleEngineException("参数仅支持一个注释!");
|
||||
}
|
||||
EngineParam engineParam =null;
|
||||
if (paramAnn[0] instanceof EngineParam){
|
||||
engineParam = (EngineParam) paramAnn[0];
|
||||
}
|
||||
|
||||
if (engineParam ==null){
|
||||
throw new RuleEngineException("请使用EngineParam注解");
|
||||
} else if (engineParam.name() == null) {
|
||||
throw new RuleEngineException("engineParam -- name 不可为null");
|
||||
}
|
||||
engineParams.add(engineParam.name());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static Method findMethodByClass(Object executionMethodName, Class<?> clazz) {
|
||||
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static List<String> getMethodEngineParamMap(String engineKey) {
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static Object getInstanceMap(String engineKey) {
|
||||
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static Method getMethodMap(String engineKey) {
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
package com.muyu.rule.server.scan;
|
||||
|
||||
import com.muyu.rule.server.load.JavaBinaryClassLoader;
|
||||
import com.muyu.rule.server.pool.container.EngineContainer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.server
|
||||
* @Project:cloud-etl-rule
|
||||
* @name:EngineExecution
|
||||
* @Date:2024/8/22 23:31
|
||||
*/
|
||||
public class EngineExecution {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(JavaBinaryClassLoader.class);
|
||||
|
||||
//
|
||||
//public static Object engineExe(String engineKey, Map<String,Object> params){
|
||||
//
|
||||
// Object instance = EngineContainer.getInstanceMap(engineKey);
|
||||
// List<String > methodEngineParams = EngineContainer.getMethodEngineParamMap(engineKey);
|
||||
// Method method = EngineContainer.getMethodMap(engineKey);
|
||||
//
|
||||
// try{
|
||||
// int methodEngineParamsLength = methodEngineParams.size();
|
||||
// Object[] objects = new Object[methodEngineParamsLength];
|
||||
// for (int i = 0; i < methodEngineParamsLength; i++) {
|
||||
// objects[i] = params.get(methodEngineParams.get(i));
|
||||
// }
|
||||
//log.info("规则引擎 [{}] 调用参数 [{}]",engineKey, Arrays.toString(objects));
|
||||
// Object invoke = method.invoke(instance, objects);
|
||||
// log.info("规则引擎 [{}] 调用结果,[{}]",engineKey,invoke);
|
||||
//
|
||||
// return invoke;
|
||||
// }catch (IllegalAccessException e){
|
||||
// throw new RuntimeException(e);
|
||||
// } catch (InvocationTargetException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package com.muyu.rule.server.scan;
|
||||
|
||||
import com.muyu.rule.server.load.JavaBinaryClassLoader;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -15,12 +14,11 @@ import java.io.FilenameFilter;
|
|||
* @name:JavaCodeScan
|
||||
* @Date:2024/8/22 21:11
|
||||
*/
|
||||
@Log4j2
|
||||
|
||||
public class JavaCodeScan {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(JavaBinaryClassLoader.class);
|
||||
|
||||
|
||||
private static final String JAVA_SOURCE_SUF = ".java";
|
||||
private static final String JAVA_BINARY_SUF = ".class";
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.rule.server.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.rule.common.domain.RuleEngine;
|
||||
import com.muyu.rule.common.domain.RuleRegion;
|
||||
import com.muyu.rule.common.domain.req.EtlRuleListReq;
|
||||
import com.muyu.rule.common.domain.resp.EtlRuleResp;
|
||||
|
||||
|
@ -40,4 +41,13 @@ public interface EtlRuleService extends IService<RuleEngine> {
|
|||
*/
|
||||
|
||||
List<EtlRuleResp> selectList(EtlRuleListReq req);
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有的规则作用域
|
||||
* @return
|
||||
*/
|
||||
|
||||
List<RuleRegion> findAllRuleRegion();
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.rule.common.domain.RuleEngine;
|
||||
import com.muyu.rule.common.domain.RuleRegion;
|
||||
import com.muyu.rule.common.domain.req.EtlRuleListReq;
|
||||
import com.muyu.rule.common.domain.resp.EtlRuleResp;
|
||||
import com.muyu.rule.server.mapper.EtlRuleMapper;
|
||||
|
@ -78,16 +79,16 @@ public class EtlRuleServiceImpl extends ServiceImpl<EtlRuleMapper, RuleEngine>
|
|||
return respList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RuleRegion> findAllRuleRegion() {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return etlRuleMapper.findAllRuleRegion();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue