diff options
| author | doufenghu <[email protected]> | 2023-12-22 09:59:44 +0800 |
|---|---|---|
| committer | doufenghu <[email protected]> | 2023-12-22 09:59:44 +0800 |
| commit | 2257feeee39e71d5dade02e7e4d47ca144f75bad (patch) | |
| tree | 3716a3bcfe6cc1144f52a6526bd5bd1ab4f8220e /groot-common | |
| parent | 24e4df2fb59645879be600eb4ca99656c577f2c9 (diff) | |
[Improve][Config]优化配置加载方式。在命令行启动时,通过增加默认参数的方式加载全局配置文件和UDF配置。
Diffstat (limited to 'groot-common')
10 files changed, 62 insertions, 66 deletions
diff --git a/groot-common/src/main/java/com/geedgenetworks/common/Constants.java b/groot-common/src/main/java/com/geedgenetworks/common/Constants.java index 1a7d88f..0fe904b 100644 --- a/groot-common/src/main/java/com/geedgenetworks/common/Constants.java +++ b/groot-common/src/main/java/com/geedgenetworks/common/Constants.java @@ -28,18 +28,20 @@ public final class Constants { public static final String SYSPROP_GROOTSTREAM_CONFIG = "grootstream.config"; - public static final String HAZELCAST_GROOTSTREAM_CONF_FILE_PREFIX = "grootstream"; + public static final String HAZELCAST_GROOTSTREAM_CONFIG_FILE_PREFIX = "grootstream"; + public static final String HAZELCAST_GROOTSTREAM_CONFIG_DEFAULT = "grootstream.yaml"; + /** * The default port number for the cluster auto-discovery mechanism's multicast communication. */ public static final int DEFAULT_GROOTSTREAM_MULTICAST_PORT = 53326; - public static final String HAZELCAST_GROOTSTREAM_DEFAULT_YAML = "grootstream.yaml"; - public static final String GROOTSTREAM_CLUSTER_NAME = "gt:impl:grootStreamServer"; - public static final String MAPPING_GROOTSTREAM_UDF = "groot-platform-udf"; + public static final String GROOTSTREAM_CLUSTER_NAME = "gt:impl:grootStreamServer"; - public static final String MAPPING_GROOTSTREAM_UDF_DEFAULT_PLUGIN = "groot-platform-udf.plugin"; + public static final String SYSPROP_UDF_PLUGIN_CONFIG = "udf.config"; + public static final String HAZELCAST_UDF_PLUGIN_CONFIG_FILE_PREFIX = "udf"; + public static final String HAZELCAST_UDF_PLUGIN_CONFIG_DEFAULT = "udf.plugins"; diff --git a/groot-common/src/main/java/com/geedgenetworks/common/config/ConfigProvider.java b/groot-common/src/main/java/com/geedgenetworks/common/config/ConfigProvider.java index 497ff16..d7f7381 100644 --- a/groot-common/src/main/java/com/geedgenetworks/common/config/ConfigProvider.java +++ b/groot-common/src/main/java/com/geedgenetworks/common/config/ConfigProvider.java @@ -26,23 +26,23 @@ public class ConfigProvider { } public static GrootStreamConfig locateAndGetGrootStreamConfig(Properties properties) { - YamlGrootStreamConfigLocator yamlConfigLocator = new YamlGrootStreamConfigLocator(); + GrootStreamConfigLocator yamlConfigLocator = new GrootStreamConfigLocator(); GrootStreamConfig config; validateSuffixInSystemProperty(Constants.SYSPROP_GROOTSTREAM_CONFIG); if (yamlConfigLocator.locateFromSystemProperty()) { // 1. Try loading YAML config if provided in system property and start job specific properties - config = new YamlGrootStreamConfigBuilder(yamlConfigLocator) + config = new GrootStreamConfigBuilder(yamlConfigLocator) .setProperties(properties) .build(); } else if (yamlConfigLocator.locateInWorkDirOrOnClasspath()) { // 2. Try loading YAML config from the working directory or from the classpath - config = new YamlGrootStreamConfigBuilder(yamlConfigLocator) + config = new GrootStreamConfigBuilder(yamlConfigLocator) .setProperties(properties) .build(); } else { // 3. Loading the default YAML configuration file yamlConfigLocator.locateDefault(); - config = new YamlGrootStreamConfigBuilder(yamlConfigLocator) + config = new GrootStreamConfigBuilder(yamlConfigLocator) .setProperties(properties) .build(); } @@ -58,7 +58,7 @@ public class ConfigProvider { if (isNullOrEmptyAfterTrim(source)) { throw new IllegalArgumentException("Config string cannot be null or empty"); } - config = new YamlGrootStreamConfigBuilder(new ByteArrayInputStream(source.getBytes())) + config = new GrootStreamConfigBuilder(new ByteArrayInputStream(source.getBytes())) .setProperties(properties) .build(); return config; @@ -70,7 +70,6 @@ public class ConfigProvider { ClientConfig config; YamlClientConfigLocator yamlConfigLocator = new YamlClientConfigLocator(); - if (yamlConfigLocator.locateFromSystemProperty()) { // 1. Try loading config if provided in system property, and it is an YAML file config = new YamlClientConfigBuilder(yamlConfigLocator.getIn()).build(); @@ -119,30 +118,28 @@ public class ConfigProvider { return config; } - public static List<String> locateAndGetMappingConfig(Properties properties) { + public static List<String> locateAndGetUDFPluginConfig(Properties properties) { List<String> config; - MappingUdfGrootStreamConfigLocator mappingGrootStreamConfigLocator = new MappingUdfGrootStreamConfigLocator(); - if (mappingGrootStreamConfigLocator.locateFromSystemProperty()) { - // 1. Try loading config if provided in system property, and it is an YAML file - - + UDFPluginConfigLocator udfPluginConfigLocator = new UDFPluginConfigLocator(); + if (udfPluginConfigLocator.locateFromSystemProperty()) { + // 1. Try loading config if provided in system property config = - new MappingUdfGrootStreamConfigBuilder(mappingGrootStreamConfigLocator.getIn()) + new UDFPluginConfigBuilder(udfPluginConfigLocator.getIn()) .setProperties(properties) .build(); - } else if (mappingGrootStreamConfigLocator.locateInWorkDirOrOnClasspath()) { - // 2. Try loading YAML config from the working directory or from the classpath + } else if (udfPluginConfigLocator.locateInWorkDirOrOnClasspath()) { + // 2. Try loading config from the working directory or from the classpath config = - new MappingUdfGrootStreamConfigBuilder(mappingGrootStreamConfigLocator.getIn()) + new UDFPluginConfigBuilder(udfPluginConfigLocator.getIn()) .setProperties(properties) .build(); } else { - // 3. Loading the default YAML configuration file - mappingGrootStreamConfigLocator.locateDefault(); + // 3. Loading the default configuration file + udfPluginConfigLocator.locateDefault(); config = - new MappingUdfGrootStreamConfigBuilder(mappingGrootStreamConfigLocator.getIn()) + new UDFPluginConfigBuilder(udfPluginConfigLocator.getIn()) .setProperties(properties) .build(); } diff --git a/groot-common/src/main/java/com/geedgenetworks/common/config/GrootStreamConfig.java b/groot-common/src/main/java/com/geedgenetworks/common/config/GrootStreamConfig.java index ac61c46..00d8319 100644 --- a/groot-common/src/main/java/com/geedgenetworks/common/config/GrootStreamConfig.java +++ b/groot-common/src/main/java/com/geedgenetworks/common/config/GrootStreamConfig.java @@ -13,7 +13,7 @@ public class GrootStreamConfig { private Config hazelcastConfig; - private List<String> udfMappingConfig; + private List<String> udfPluginConfig; static { String value = grootStreamHome(); @@ -58,11 +58,11 @@ public class GrootStreamConfig { } - public List<String> getUdfMappingConfig() { - return udfMappingConfig; + public List<String> getUDFPluginConfig() { + return udfPluginConfig; } - public void setUdfMappingConfig(List<String> udfMappingConfig) { - this.udfMappingConfig = udfMappingConfig; + public void setUDFPluginConfig(List<String> udfPluginConfig) { + this.udfPluginConfig = udfPluginConfig; } } diff --git a/groot-common/src/main/java/com/geedgenetworks/common/config/YamlGrootStreamConfigBuilder.java b/groot-common/src/main/java/com/geedgenetworks/common/config/GrootStreamConfigBuilder.java index 104eb9b..83d7b87 100644 --- a/groot-common/src/main/java/com/geedgenetworks/common/config/YamlGrootStreamConfigBuilder.java +++ b/groot-common/src/main/java/com/geedgenetworks/common/config/GrootStreamConfigBuilder.java @@ -13,27 +13,25 @@ import org.w3c.dom.Node; import java.io.InputStream; import java.util.Properties; - -import static com.geedgenetworks.common.config.ConfigProvider.locateAndGetMappingConfig; import static com.hazelcast.internal.config.yaml.W3cDomUtil.asW3cNode; -public class YamlGrootStreamConfigBuilder extends AbstractYamlConfigBuilder { +public class GrootStreamConfigBuilder extends AbstractYamlConfigBuilder { private final InputStream in; - public YamlGrootStreamConfigBuilder() { - this((YamlGrootStreamConfigLocator) null); + public GrootStreamConfigBuilder() { + this((GrootStreamConfigLocator) null); } - public YamlGrootStreamConfigBuilder(YamlGrootStreamConfigLocator locator) { + public GrootStreamConfigBuilder(GrootStreamConfigLocator locator) { if (locator == null) { - locator = new YamlGrootStreamConfigLocator(); + locator = new GrootStreamConfigLocator(); locator.locateEverywhere(); } this.in = locator.getIn(); } - public YamlGrootStreamConfigBuilder(@NonNull InputStream inputStream) { + public GrootStreamConfigBuilder(@NonNull InputStream inputStream) { this.in = inputStream; } @@ -53,7 +51,7 @@ public class YamlGrootStreamConfigBuilder extends AbstractYamlConfigBuilder { throw ExceptionUtil.rethrow(e); } config.setHazelcastConfig(ConfigProvider.locateAndGetMemberConfig(getProperties())); - config.setUdfMappingConfig(ConfigProvider.locateAndGetMappingConfig(getProperties())); + config.setUDFPluginConfig(ConfigProvider.locateAndGetUDFPluginConfig(getProperties())); return config; } @@ -78,9 +76,9 @@ public class YamlGrootStreamConfigBuilder extends AbstractYamlConfigBuilder { replaceVariables(w3cRootNode); importDocuments(grootStreamRoot); - new YamlGrootStreamDomConfigProcessor(true, config).buildConfig(w3cRootNode); + new GrootStreamDomConfigProcessor(true, config).buildConfig(w3cRootNode); } - public YamlGrootStreamConfigBuilder setProperties(Properties properties) { + public GrootStreamConfigBuilder setProperties(Properties properties) { if (properties == null) { properties = System.getProperties(); } diff --git a/groot-common/src/main/java/com/geedgenetworks/common/config/YamlGrootStreamConfigLocator.java b/groot-common/src/main/java/com/geedgenetworks/common/config/GrootStreamConfigLocator.java index bb4e939..3962324 100644 --- a/groot-common/src/main/java/com/geedgenetworks/common/config/YamlGrootStreamConfigLocator.java +++ b/groot-common/src/main/java/com/geedgenetworks/common/config/GrootStreamConfigLocator.java @@ -5,9 +5,9 @@ import com.hazelcast.internal.config.AbstractConfigLocator; import static com.hazelcast.internal.config.DeclarativeConfigUtil.YAML_ACCEPTED_SUFFIXES; -public final class YamlGrootStreamConfigLocator extends AbstractConfigLocator { +public final class GrootStreamConfigLocator extends AbstractConfigLocator { - public YamlGrootStreamConfigLocator() { + public GrootStreamConfigLocator() { } @Override public boolean locateFromSystemProperty() { @@ -23,18 +23,18 @@ public final class YamlGrootStreamConfigLocator extends AbstractConfigLocator { @Override protected boolean locateInWorkDir() { return loadFromWorkingDirectory( - Constants.HAZELCAST_GROOTSTREAM_CONF_FILE_PREFIX, YAML_ACCEPTED_SUFFIXES); + Constants.HAZELCAST_GROOTSTREAM_CONFIG_FILE_PREFIX, YAML_ACCEPTED_SUFFIXES); } @Override protected boolean locateOnClasspath() { return loadConfigurationFromClasspath( - Constants.HAZELCAST_GROOTSTREAM_CONF_FILE_PREFIX, YAML_ACCEPTED_SUFFIXES); + Constants.HAZELCAST_GROOTSTREAM_CONFIG_FILE_PREFIX, YAML_ACCEPTED_SUFFIXES); } @Override public boolean locateDefault() { - loadDefaultConfigurationFromClasspath(Constants.HAZELCAST_GROOTSTREAM_DEFAULT_YAML); + loadDefaultConfigurationFromClasspath(Constants.HAZELCAST_GROOTSTREAM_CONFIG_DEFAULT); return true; } } diff --git a/groot-common/src/main/java/com/geedgenetworks/common/config/YamlGrootStreamDomConfigProcessor.java b/groot-common/src/main/java/com/geedgenetworks/common/config/GrootStreamDomConfigProcessor.java index cc48e6c..61c4855 100644 --- a/groot-common/src/main/java/com/geedgenetworks/common/config/YamlGrootStreamDomConfigProcessor.java +++ b/groot-common/src/main/java/com/geedgenetworks/common/config/GrootStreamDomConfigProcessor.java @@ -1,6 +1,5 @@ package com.geedgenetworks.common.config; -import com.hazelcast.config.InvalidConfigurationException; import com.hazelcast.internal.config.AbstractDomConfigProcessor; import com.hazelcast.logging.ILogger; import com.hazelcast.logging.Logger; @@ -13,12 +12,12 @@ import java.util.Map; import static com.hazelcast.internal.config.DomConfigHelper.*; -public class YamlGrootStreamDomConfigProcessor extends AbstractDomConfigProcessor { - private static final ILogger LOGGER = Logger.getLogger(YamlGrootStreamDomConfigProcessor.class); +public class GrootStreamDomConfigProcessor extends AbstractDomConfigProcessor { + private static final ILogger LOGGER = Logger.getLogger(GrootStreamDomConfigProcessor.class); private final GrootStreamConfig config; - YamlGrootStreamDomConfigProcessor(boolean domLevel3, GrootStreamConfig config) { + GrootStreamDomConfigProcessor(boolean domLevel3, GrootStreamConfig config) { super(domLevel3); this.config = config; } diff --git a/groot-common/src/main/java/com/geedgenetworks/common/config/MappingUdfGrootStreamConfigBuilder.java b/groot-common/src/main/java/com/geedgenetworks/common/config/UDFPluginConfigBuilder.java index fb87546..67e0a5a 100644 --- a/groot-common/src/main/java/com/geedgenetworks/common/config/MappingUdfGrootStreamConfigBuilder.java +++ b/groot-common/src/main/java/com/geedgenetworks/common/config/UDFPluginConfigBuilder.java @@ -12,22 +12,22 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; -public class MappingUdfGrootStreamConfigBuilder extends AbstractConfigBuilder { +public class UDFPluginConfigBuilder extends AbstractConfigBuilder { private final InputStream in; private Properties properties = System.getProperties(); - public MappingUdfGrootStreamConfigBuilder() { - this((MappingUdfGrootStreamConfigLocator) null); + public UDFPluginConfigBuilder() { + this((UDFPluginConfigLocator) null); } - public MappingUdfGrootStreamConfigBuilder(MappingUdfGrootStreamConfigLocator locator) { + public UDFPluginConfigBuilder(UDFPluginConfigLocator locator) { if (locator == null) { - locator = new MappingUdfGrootStreamConfigLocator(); + locator = new UDFPluginConfigLocator(); locator.locateEverywhere(); } this.in = locator.getIn(); } - public MappingUdfGrootStreamConfigBuilder(InputStream inputStream) { + public UDFPluginConfigBuilder(InputStream inputStream) { Preconditions.checkTrue(inputStream != null, "inputStream can't be null"); this.in = inputStream; } @@ -53,7 +53,7 @@ public class MappingUdfGrootStreamConfigBuilder extends AbstractConfigBuilder { return in; } - public MappingUdfGrootStreamConfigBuilder setProperties(Properties properties) { + public UDFPluginConfigBuilder setProperties(Properties properties) { this.properties = properties; return this; } diff --git a/groot-common/src/main/java/com/geedgenetworks/common/config/MappingUdfGrootStreamConfigLocator.java b/groot-common/src/main/java/com/geedgenetworks/common/config/UDFPluginConfigLocator.java index 5bccc7e..49da576 100644 --- a/groot-common/src/main/java/com/geedgenetworks/common/config/MappingUdfGrootStreamConfigLocator.java +++ b/groot-common/src/main/java/com/geedgenetworks/common/config/UDFPluginConfigLocator.java @@ -9,39 +9,39 @@ import java.util.Collection; import java.util.Collections; @Slf4j -public final class MappingUdfGrootStreamConfigLocator extends AbstractConfigLocator { +public final class UDFPluginConfigLocator extends AbstractConfigLocator { - public static Collection<String> ALL_ACCEPTED_SUFFIXES =Collections.unmodifiableList(Arrays.asList("plugin")); + public static Collection<String> ALL_ACCEPTED_SUFFIXES = Collections.unmodifiableList(Arrays.asList("plugins")); - public MappingUdfGrootStreamConfigLocator() { + public UDFPluginConfigLocator() { } @Override public boolean locateFromSystemProperty() { - return loadFromSystemProperty(Constants.MAPPING_GROOTSTREAM_UDF, ALL_ACCEPTED_SUFFIXES); + return loadFromSystemProperty(Constants.SYSPROP_UDF_PLUGIN_CONFIG, ALL_ACCEPTED_SUFFIXES); } @Override protected boolean locateFromSystemPropertyOrFailOnUnacceptedSuffix() { return loadFromSystemPropertyOrFailOnUnacceptedSuffix( - Constants.MAPPING_GROOTSTREAM_UDF, ALL_ACCEPTED_SUFFIXES); + Constants.SYSPROP_UDF_PLUGIN_CONFIG, ALL_ACCEPTED_SUFFIXES); } @Override protected boolean locateInWorkDir() { return loadFromWorkingDirectory( - Constants.MAPPING_GROOTSTREAM_UDF, ALL_ACCEPTED_SUFFIXES); + Constants.HAZELCAST_UDF_PLUGIN_CONFIG_FILE_PREFIX, ALL_ACCEPTED_SUFFIXES); } @Override protected boolean locateOnClasspath() { return loadConfigurationFromClasspath( - Constants.MAPPING_GROOTSTREAM_UDF, ALL_ACCEPTED_SUFFIXES); + Constants.HAZELCAST_UDF_PLUGIN_CONFIG_FILE_PREFIX, ALL_ACCEPTED_SUFFIXES); } @Override public boolean locateDefault() { - loadDefaultConfigurationFromClasspath(Constants.MAPPING_GROOTSTREAM_UDF_DEFAULT_PLUGIN); + loadDefaultConfigurationFromClasspath(Constants.HAZELCAST_UDF_PLUGIN_CONFIG_DEFAULT); return true; } } diff --git a/groot-common/src/main/resources/groot-platform-udf.plugin b/groot-common/src/main/resources/udf.plugins index d22c057..d22c057 100644 --- a/groot-common/src/main/resources/groot-platform-udf.plugin +++ b/groot-common/src/main/resources/udf.plugins diff --git a/groot-common/src/test/java/com/geedgenetworks/common/config/YamlGrootStreamConfigParserTest.java b/groot-common/src/test/java/com/geedgenetworks/common/config/YamlGrootStreamConfigParserTest.java index c5f729e..6e42ae4 100644 --- a/groot-common/src/test/java/com/geedgenetworks/common/config/YamlGrootStreamConfigParserTest.java +++ b/groot-common/src/test/java/com/geedgenetworks/common/config/YamlGrootStreamConfigParserTest.java @@ -7,11 +7,11 @@ public class YamlGrootStreamConfigParserTest { @Test public void testGrootStreamConfig() { - YamlGrootStreamConfigLocator yamlConfigLocator = new YamlGrootStreamConfigLocator(); + GrootStreamConfigLocator yamlConfigLocator = new GrootStreamConfigLocator(); GrootStreamConfig config; if (yamlConfigLocator.locateInWorkDirOrOnClasspath()) { // 2. Try loading YAML config from the working directory or from the classpath - config = new YamlGrootStreamConfigBuilder(yamlConfigLocator).setProperties(null).build(); + config = new GrootStreamConfigBuilder(yamlConfigLocator).setProperties(null).build(); } else { throw new RuntimeException("can't find yaml in resources"); } |
