diff --git a/radar-admin/src/main/java/com/pgmmers/radar/controller/AbstractionApiController.java b/radar-admin/src/main/java/com/pgmmers/radar/controller/AbstractionApiController.java index 7397f1d..084ab54 100644 --- a/radar-admin/src/main/java/com/pgmmers/radar/controller/AbstractionApiController.java +++ b/radar-admin/src/main/java/com/pgmmers/radar/controller/AbstractionApiController.java @@ -18,7 +18,7 @@ import com.pgmmers.radar.service.common.CommonResult; import com.pgmmers.radar.service.engine.PluginServiceV2; import com.pgmmers.radar.service.engine.vo.DataColumnInfo; import com.pgmmers.radar.service.enums.DataType; -import com.pgmmers.radar.service.impl.engine.plugin.PluginManagerV2; +import com.pgmmers.radar.service.impl.engine.plugin.PluginManager; import com.pgmmers.radar.service.model.AbstractionService; import com.pgmmers.radar.service.model.FieldService; import com.pgmmers.radar.service.model.PreItemService; @@ -46,7 +46,7 @@ public class AbstractionApiController { private PreItemService preItemService; @Autowired - private PluginManagerV2 pluginManagerV2; + private PluginManager pluginManager; @GetMapping("/{id}") public CommonResult get(@PathVariable Long id) { @@ -87,7 +87,7 @@ public class AbstractionApiController { List listPreItem = preItemService.listPreItem(modelId); if(listPreItem != null && listPreItem.size()!= 0){ for (PreItemVO preItem : listPreItem) { - PluginServiceV2 pt= pluginManagerV2.pluginServiceMap(preItem.getPlugin()); + PluginServiceV2 pt = pluginManager.pluginServiceMap(preItem.getPlugin()); if (StringUtils.isNotEmpty(pt.getType()) && pt.getType().equals("JSON")) { //load http request data JsonNode json = preItem.getConfigJson(); diff --git a/radar-admin/src/main/java/com/pgmmers/radar/controller/ActivationApiController.java b/radar-admin/src/main/java/com/pgmmers/radar/controller/ActivationApiController.java index 9ba2a44..d4cba0a 100644 --- a/radar-admin/src/main/java/com/pgmmers/radar/controller/ActivationApiController.java +++ b/radar-admin/src/main/java/com/pgmmers/radar/controller/ActivationApiController.java @@ -19,7 +19,7 @@ import com.pgmmers.radar.service.common.CommonResult; import com.pgmmers.radar.service.engine.PluginServiceV2; import com.pgmmers.radar.service.engine.vo.DataColumnInfo; import com.pgmmers.radar.service.enums.DataType; -import com.pgmmers.radar.service.impl.engine.plugin.PluginManagerV2; +import com.pgmmers.radar.service.impl.engine.plugin.PluginManager; import com.pgmmers.radar.service.model.*; import com.pgmmers.radar.vo.model.*; import io.swagger.annotations.Api; @@ -46,7 +46,7 @@ public class ActivationApiController { @Autowired private RuleService ruleService; @Autowired - private PluginManagerV2 pluginManagerV2; + private PluginManager pluginManager; @GetMapping("/{id}") public CommonResult get(@PathVariable Long id) { @@ -79,7 +79,7 @@ public class ActivationApiController { ds = new DataColumnInfo(DataType.PREITEMS.getDesc(), DataType.PREITEMS.getName()); List listPreItem = preItemService.listPreItem(modelId); for (PreItemVO preItem : listPreItem) { - PluginServiceV2 pt = pluginManagerV2.pluginServiceMap(preItem.getPlugin()); + PluginServiceV2 pt = pluginManager.pluginServiceMap(preItem.getPlugin()); if (StringUtils.isNotEmpty(pt.getType()) && pt.getType().equals("JSON")) { //load http request data JsonNode json = preItem.getConfigJson(); diff --git a/radar-admin/src/main/java/com/pgmmers/radar/controller/CommonApiController.java b/radar-admin/src/main/java/com/pgmmers/radar/controller/CommonApiController.java index 65f135a..24d4a6a 100644 --- a/radar-admin/src/main/java/com/pgmmers/radar/controller/CommonApiController.java +++ b/radar-admin/src/main/java/com/pgmmers/radar/controller/CommonApiController.java @@ -15,7 +15,7 @@ import com.alibaba.excel.util.IoUtils; import com.pgmmers.radar.enums.FieldType; import com.pgmmers.radar.service.cache.CacheService; import com.pgmmers.radar.service.common.CommonResult; -import com.pgmmers.radar.service.impl.engine.plugin.PluginManagerV2; +import com.pgmmers.radar.service.impl.engine.plugin.PluginManager; import com.pgmmers.radar.util.CaptchaUtil; import com.pgmmers.radar.util.ZipUtils; import com.pgmmers.radar.vo.common.PluginVO; @@ -53,13 +53,13 @@ public class CommonApiController { @Autowired private CacheService cacheService; @Autowired - private PluginManagerV2 pluginManagerV2; + private PluginManager pluginManager; @GetMapping("/plugins") public CommonResult plugins() { CommonResult result = new CommonResult(); - List plugins = pluginManagerV2.getPluginServiceMap() + List plugins = pluginManager.getPluginServiceMap() .values() .stream() .map(t-> new PluginVO(t.key(),t.pluginName(),t.desc())) diff --git a/radar-admin/src/main/java/com/pgmmers/radar/controller/EventApiController.java b/radar-admin/src/main/java/com/pgmmers/radar/controller/EventApiController.java index c56b99c..2d4a549 100644 --- a/radar-admin/src/main/java/com/pgmmers/radar/controller/EventApiController.java +++ b/radar-admin/src/main/java/com/pgmmers/radar/controller/EventApiController.java @@ -20,7 +20,7 @@ import com.pgmmers.radar.service.common.CommonResult; import com.pgmmers.radar.service.engine.PluginServiceV2; import com.pgmmers.radar.service.engine.vo.DataColumnInfo; import com.pgmmers.radar.service.enums.DataType; -import com.pgmmers.radar.service.impl.engine.plugin.PluginManagerV2; +import com.pgmmers.radar.service.impl.engine.plugin.PluginManager; import com.pgmmers.radar.service.logs.EventService; import com.pgmmers.radar.service.model.ActivationService; import com.pgmmers.radar.service.model.FieldService; @@ -69,7 +69,7 @@ public class EventApiController { @Autowired private RuleService ruleService; @Autowired - private PluginManagerV2 pluginManagerV2; + private PluginManager pluginManager; @PostMapping("/query") @@ -190,7 +190,7 @@ public class EventApiController { if (!itemsIdMap.containsKey(item.getDestField())) { continue; } - PluginServiceV2 plugin = pluginManagerV2.pluginServiceMap(item.getPlugin()); + PluginServiceV2 plugin = pluginManager.pluginServiceMap(item.getPlugin()); String type = plugin.getType(); String meta = plugin.getMeta(); diff --git a/radar-engine/src/main/test/com/pgmmers/radar/dal/PluginTest.java b/radar-engine/src/main/test/com/pgmmers/radar/dal/PluginTest.java index 5d81d2d..95541ad 100644 --- a/radar-engine/src/main/test/com/pgmmers/radar/dal/PluginTest.java +++ b/radar-engine/src/main/test/com/pgmmers/radar/dal/PluginTest.java @@ -5,7 +5,6 @@ import com.pgmmers.radar.EngineApplication; import com.pgmmers.radar.service.engine.PluginServiceV2; import com.pgmmers.radar.service.engine.vo.Location; import com.pgmmers.radar.service.impl.engine.plugin.PluginManager; -import com.pgmmers.radar.service.impl.engine.plugin.PluginManagerV2; import com.pgmmers.radar.vo.model.PreItemVO; import org.junit.Assert; import org.junit.Before; @@ -31,20 +30,17 @@ public class PluginTest { private static final Logger logger = LoggerFactory.getLogger(PluginTest.class); @Autowired - private PluginManagerV2 pluginManagerV2; + private PluginManager pluginManager; - @Test - public void pluginListV2() { - pluginManagerV2.getPluginServiceMap().values() - .stream() - .sorted(Comparator.comparing(PluginServiceV2::key)) - .forEach(t -> logger.info(t.info())); - } @Test @Deprecated public void pluginList() { - PluginManager.pluginServiceMap().values() +// PluginManager.pluginServiceMap().values() +// .stream() +// .sorted(Comparator.comparing(PluginServiceV2::key)) +// .forEach(t -> logger.info(t.info())); + pluginManager.getPluginServiceMap().values() .stream() .sorted(Comparator.comparing(PluginServiceV2::key)) .forEach(t -> logger.info(t.info())); @@ -68,7 +64,8 @@ public class PluginTest { jsonInfo.put("firsName", "aaa"); jsonInfo.put("lastName", "ccc"); String[] sourceField = item.getSourceField().split(","); - PluginServiceV2 pluginServiceV2 = PluginManager.pluginServiceMap().get("ALLINONE"); +// PluginServiceV2 pluginServiceV2 = PluginManager.pluginServiceMap().get("ALLINONE"); + PluginServiceV2 pluginServiceV2 = pluginManager.getPluginServiceMap().get("ALLINONE"); String result = (String) pluginServiceV2 .handle(item, jsonInfo, sourceField); Assert.assertNotNull(result); @@ -82,7 +79,8 @@ public class PluginTest { item.setSourceField("time"); jsonInfo.put("time", System.currentTimeMillis()); String[] sourceField = item.getSourceField().split(","); - PluginServiceV2 pluginServiceV2 = PluginManager.pluginServiceMap().get("DATEFORMAT"); +// PluginServiceV2 pluginServiceV2 = PluginManager.pluginServiceMap().get("DATEFORMAT"); + PluginServiceV2 pluginServiceV2 = pluginManager.getPluginServiceMap().get("DATEFORMAT"); String result = (String) pluginServiceV2 .handle(item, jsonInfo, sourceField); Assert.assertNotNull(result); @@ -102,7 +100,8 @@ public class PluginTest { item.setSourceField("json"); jsonInfo.put("json",""); String[] sourceField = item.getSourceField().split(","); - PluginServiceV2 pluginServiceV2 = PluginManager.pluginServiceMap().get("HTTP_UTIL"); +// PluginServiceV2 pluginServiceV2 = PluginManager.pluginServiceMap().get("HTTP_UTIL"); + PluginServiceV2 pluginServiceV2 = pluginManager.getPluginServiceMap().get("HTTP_UTIL"); JSONObject result = (JSONObject) pluginServiceV2 .handle(item, jsonInfo, sourceField); Assert.assertNotNull(result); @@ -115,7 +114,8 @@ public class PluginTest { item.setSourceField("ip"); jsonInfo.put("ip", "1.1.1.1"); String[] sourceField = item.getSourceField().split(","); - PluginServiceV2 pluginServiceV2 = PluginManager.pluginServiceMap().get("IP2LOCATION"); +// PluginServiceV2 pluginServiceV2 = PluginManager.pluginServiceMap().get("IP2LOCATION"); + PluginServiceV2 pluginServiceV2 = pluginManager.getPluginServiceMap().get("IP2LOCATION"); Location location = (Location) pluginServiceV2 .handle(item, jsonInfo, sourceField); Assert.assertNotNull(location); @@ -128,7 +128,8 @@ public class PluginTest { item.setSourceField("phone"); jsonInfo.put("phone", "18657150000"); String[] sourceField = item.getSourceField().split(","); - PluginServiceV2 pluginServiceV2 = PluginManager.pluginServiceMap().get("MOBILE2LOCATION"); +// PluginServiceV2 pluginServiceV2 = PluginManager.pluginServiceMap().get("MOBILE2LOCATION"); + PluginServiceV2 pluginServiceV2 = pluginManager.getPluginServiceMap().get("MOBILE2LOCATION"); Location location = (Location) pluginServiceV2 .handle(item, jsonInfo, sourceField); Assert.assertNotNull(location); @@ -141,7 +142,8 @@ public class PluginTest { item.setSourceField("time"); jsonInfo.put("time",System.currentTimeMillis()); String[] sourceField = item.getSourceField().split(","); - PluginServiceV2 pluginServiceV2 = PluginManager.pluginServiceMap().get("SENSITIVE_TIME"); +// PluginServiceV2 pluginServiceV2 = PluginManager.pluginServiceMap().get("SENSITIVE_TIME"); + PluginServiceV2 pluginServiceV2 = pluginManager.getPluginServiceMap().get("SENSITIVE_TIME"); String location = (String) pluginServiceV2 .handle(item, jsonInfo, sourceField); Assert.assertNotNull(location); @@ -156,7 +158,8 @@ public class PluginTest { item.setSourceField("phone"); jsonInfo.put("phone", "18657150000"); String[] sourceField = item.getSourceField().split(","); - PluginServiceV2 pluginServiceV2 = PluginManager.pluginServiceMap().get("SUBSTRING"); +// PluginServiceV2 pluginServiceV2 = PluginManager.pluginServiceMap().get("SUBSTRING"); + PluginServiceV2 pluginServiceV2 = pluginManager.getPluginServiceMap().get("SUBSTRING"); String location = (String) pluginServiceV2 .handle(item, jsonInfo, sourceField); Assert.assertNotNull(location); diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/AntiFraudServiceImpl.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/AntiFraudServiceImpl.java index 7fdfecc..4deba6d 100644 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/AntiFraudServiceImpl.java +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/AntiFraudServiceImpl.java @@ -10,7 +10,7 @@ import com.pgmmers.radar.service.engine.vo.AbstractionResult; import com.pgmmers.radar.service.engine.vo.ActivationResult; import com.pgmmers.radar.service.engine.vo.AdaptationResult; import com.pgmmers.radar.service.engine.vo.AntiFraudProcessResult; -import com.pgmmers.radar.service.impl.engine.plugin.PluginManagerV2; +import com.pgmmers.radar.service.impl.engine.plugin.PluginManager; import com.pgmmers.radar.service.model.ModelService; import com.pgmmers.radar.service.model.PreItemService; import com.pgmmers.radar.vo.model.PreItemVO; @@ -47,7 +47,7 @@ public class AntiFraudServiceImpl implements AntiFraudService { private ModelService modelService; @Autowired - private PluginManagerV2 pluginManagerV2; + private PluginManager pluginManager; @Override public CommonResult process(Long modelId, Map> context) { @@ -113,7 +113,7 @@ public class AntiFraudServiceImpl implements AntiFraudService { continue; } String[] sourceField = item.getSourceField().split(","); - Object transfer = pluginManagerV2.pluginServiceMap(item.getPlugin()).handle(item,jsonInfo,sourceField); + Object transfer = pluginManager.pluginServiceMap(item.getPlugin()).handle(item,jsonInfo,sourceField); result.put(item.getDestField(), transfer); } return result; diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/PluginManager.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/PluginManager.java index 25b9335..e75355c 100644 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/PluginManager.java +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/PluginManager.java @@ -1,28 +1,49 @@ package com.pgmmers.radar.service.impl.engine.plugin; import com.pgmmers.radar.service.engine.PluginServiceV2; -import org.springframework.core.io.support.SpringFactoriesLoader; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Service; -import java.util.Comparator; import java.util.Map; -import java.util.stream.Collectors; +import java.util.concurrent.ConcurrentHashMap; -@Deprecated -public class PluginManager { +@Service +public class PluginManager implements ApplicationContextAware { - private PluginManager() { +// private PluginManager() { +// } + +// public static Map pluginServiceMap() { +// return SingletonHolder.pluginServiceMap; +// } + + + private final Map pluginServiceMap = new ConcurrentHashMap<>(); + + public PluginServiceV2 pluginServiceMap(String key){ + return pluginServiceMap.get(key); } - public static Map pluginServiceMap() { - return SingletonHolder.pluginServiceMap; + public Map getPluginServiceMap(){ + return pluginServiceMap; } - private static class SingletonHolder { + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + Map beansOfType = applicationContext.getBeansOfType(PluginServiceV2.class); + pluginServiceMap.putAll(beansOfType); + } + + // 工厂模式实现单例存在不能注入bean问题 + /* private static class SingletonHolder { private static final Map pluginServiceMap = SpringFactoriesLoader .loadFactories(PluginServiceV2.class, null).stream() .sorted(Comparator.comparing(PluginServiceV2::key)) .collect(Collectors.toMap(PluginServiceV2::pluginName, e -> e, (oldValue, newValue) -> newValue)); ; - } + }*/ } diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/PluginManagerV2.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/PluginManagerV2.java deleted file mode 100644 index 8fafd86..0000000 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/PluginManagerV2.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.pgmmers.radar.service.impl.engine.plugin; - -import com.pgmmers.radar.service.engine.PluginServiceV2; -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.stereotype.Service; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * - * @author Model - * @since 2022/1/27 11:29 - */ -@Service -public class PluginManagerV2 implements ApplicationContextAware { - - private final Map pluginServiceMap = new ConcurrentHashMap<>(); - - public PluginServiceV2 pluginServiceMap(String key){ - return pluginServiceMap.get(key); - } - - public Map getPluginServiceMap(){ - return pluginServiceMap; - } - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - Map beansOfType = applicationContext.getBeansOfType(PluginServiceV2.class); - pluginServiceMap.putAll(beansOfType); - } -} diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/model/ModelServiceImpl.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/model/ModelServiceImpl.java index b33e25a..1e2564b 100644 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/model/ModelServiceImpl.java +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/model/ModelServiceImpl.java @@ -14,7 +14,7 @@ import com.pgmmers.radar.service.cache.SubscribeHandle; import com.pgmmers.radar.service.common.CommonResult; import com.pgmmers.radar.service.data.MongoService; import com.pgmmers.radar.service.engine.PluginServiceV2; -import com.pgmmers.radar.service.impl.engine.plugin.PluginManagerV2; +import com.pgmmers.radar.service.impl.engine.plugin.PluginManager; import com.pgmmers.radar.service.model.ModelService; import com.pgmmers.radar.service.search.SearchEngineService; import com.pgmmers.radar.util.JsonUtils; @@ -60,7 +60,7 @@ public class ModelServiceImpl extends BaseLocalCacheService implements ModelServ private MongoService mongoService; @Autowired - private PluginManagerV2 pluginManagerV2; + private PluginManager pluginManager; // 维护GUID到modelId的映射 private Map guidMap; @@ -252,7 +252,7 @@ public class ModelServiceImpl extends BaseLocalCacheService implements ModelServ // pre item mapping JSONObject preItemJson = new JSONObject(); for (PreItemVO item : items) { - PluginServiceV2 plugin = pluginManagerV2.pluginServiceMap(item.getPlugin()); + PluginServiceV2 plugin = pluginManager.pluginServiceMap(item.getPlugin()); String columns = plugin.getMeta(); if (columns == null) { String fieldType = plugin.getType(); diff --git a/radar-service-impl/src/main/resources/META-INF/spring.factories b/radar-service-impl/src/main/resources/META-INF/spring.factories index fd40910..36c7e23 100644 --- a/radar-service-impl/src/main/resources/META-INF/spring.factories +++ b/radar-service-impl/src/main/resources/META-INF/spring.factories @@ -1,4 +1,13 @@ - +# PluginManager reset +#com.pgmmers.radar.service.engine.PluginServiceV2=\ +# com.pgmmers.radar.service.impl.engine.plugin.DATEFORMAT,\ +# com.pgmmers.radar.service.impl.engine.plugin.ALLINONE,\ +# com.pgmmers.radar.service.impl.engine.plugin.GPS2LOCATION,\ +# com.pgmmers.radar.service.impl.engine.plugin.HTTP_UTIL,\ +# com.pgmmers.radar.service.impl.engine.plugin.IP2LOCATION,\ +# com.pgmmers.radar.service.impl.engine.plugin.MOBILE2LOCATION,\ +# com.pgmmers.radar.service.impl.engine.plugin.SENSITIVE_TIME,\ +# com.pgmmers.radar.service.impl.engine.plugin.SUBSTRING