diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yml similarity index 100% rename from .github/workflows/docker.yaml rename to .github/workflows/docker.yml diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 728d32adfa..33f64c5cca 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -31,7 +31,7 @@ jobs: stale: runs-on: ubuntu-latest steps: - - uses: actions/stale@v9 + - uses: actions/stale@v8 with: days-before-issue-stale: 90 days-before-pr-stale: 60 @@ -47,3 +47,4 @@ jobs: exempt-issue-labels: 'pinned,discussion,help wanted,WIP,weopen-star,GLCC,summer of code' exempt-pr-labels: 'help wanted,dependencies' exempt-all-milestones: true # Exempt all issues/PRs with milestones from stale + operations-per-run: 30 diff --git a/build.gradle b/build.gradle index f55ef5acfe..de0602f084 100644 --- a/build.gradle +++ b/build.gradle @@ -569,7 +569,7 @@ subprojects { dependency "org.projectlombok:lombok:1.18.22" dependency "com.github.seancfoley:ipaddress:5.3.3" dependency "javax.annotation:javax.annotation-api:1.3.2" - dependency "com.alibaba:fastjson:1.2.83" + dependency "com.alibaba.fastjson2:fastjson2:2.0.48" dependency "software.amazon.awssdk:s3:2.20.29" dependency "com.github.rholder:guava-retrying:2.0.0" diff --git a/eventmesh-common/build.gradle b/eventmesh-common/build.gradle index fd7a6e1ee6..a6dc2cd269 100644 --- a/eventmesh-common/build.gradle +++ b/eventmesh-common/build.gradle @@ -30,6 +30,8 @@ dependencies { api "io.cloudevents:cloudevents-core" api "io.cloudevents:cloudevents-json-jackson" + api "com.alibaba.fastjson2:fastjson2" + implementation "org.apache.logging.log4j:log4j-api" implementation "org.apache.logging.log4j:log4j-core" implementation "org.apache.logging.log4j:log4j-slf4j2-impl" diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/EventMeshThreadFactory.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/EventMeshThreadFactory.java index 0442ef1286..d18ec5a048 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/EventMeshThreadFactory.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/EventMeshThreadFactory.java @@ -67,12 +67,12 @@ public EventMeshThreadFactory(final String threadNamePrefix) { public Thread newThread(@Nonnull final Runnable runnable) { StringBuilder threadName = new StringBuilder(threadNamePrefix); - if (null != threadIndex) { + if (threadIndex != null) { threadName.append("-").append(threadIndex.incrementAndGet()); } Thread thread = new Thread(runnable, threadName.toString()); thread.setDaemon(daemon); - if (null != priority) { + if (priority != null) { thread.setPriority(priority); } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java index ca20e2b330..688f828609 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java @@ -34,94 +34,85 @@ @Config(prefix = "eventMesh") public class CommonConfiguration { - @ConfigFiled(field = "sysid", beNumber = true, notEmpty = true) + @ConfigField(field = "sysid", beNumber = true, notEmpty = true) private String sysID = "5477"; - @ConfigFiled(field = "server.env", notEmpty = true) + @ConfigField(field = "server.env", notEmpty = true) private String eventMeshEnv = "P"; - @ConfigFiled(field = "server.idc", notEmpty = true) + @ConfigField(field = "server.idc", notEmpty = true) private String eventMeshIDC = "FT"; - @ConfigFiled(field = "server.name", notEmpty = true) + @ConfigField(field = "server.name", notEmpty = true) private String eventMeshName = ""; - @ConfigFiled(field = "server.cluster", notEmpty = true) + @ConfigField(field = "server.cluster", notEmpty = true) private String eventMeshCluster = "LS"; - @ConfigFiled(field = "server.hostIp", reload = true) + @ConfigField(field = "server.hostIp", reload = true) private String eventMeshServerIp = null; - @ConfigFiled(field = "metaStorage.plugin.server-addr", notEmpty = true) + @ConfigField(field = "metaStorage.plugin.server-addr", notEmpty = true) private String metaStorageAddr = ""; - @ConfigFiled(field = "metaStorage.plugin.type", notEmpty = true) + @ConfigField(field = "metaStorage.plugin.type", notEmpty = true) private String eventMeshMetaStoragePluginType = "nacos"; - @ConfigFiled(field = "metaStorage.plugin.username") + @ConfigField(field = "metaStorage.plugin.username") private String eventMeshMetaStoragePluginUsername = ""; - @ConfigFiled(field = "metaStorage.plugin.password") + @ConfigField(field = "metaStorage.plugin.password") private String eventMeshMetaStoragePluginPassword = ""; - @ConfigFiled(field = "metaStorage.plugin.metaStorageIntervalInMills") - private Integer eventMeshMetaStorageIntervalInMills = 10 * 1000; - - @ConfigFiled(field = "metaStorage.plugin.fetchMetaStorageAddrIntervalInMills") - private Integer eventMeshFetchMetaStorageAddrInterval = 10 * 1000; - - @ConfigFiled(field = "metaStorage.plugin.enabled") + @ConfigField(field = "metaStorage.plugin.enabled") private boolean eventMeshServerMetaStorageEnable = false; - @ConfigFiled(field = "trace.plugin", notEmpty = true) + @ConfigField(field = "trace.plugin", notEmpty = true) private String eventMeshTracePluginType; - @ConfigFiled(field = "metrics.plugin", notEmpty = true) + @ConfigField(field = "metrics.plugin", notEmpty = true) private List eventMeshMetricsPluginType; - @ConfigFiled(field = "security.plugin.type", notEmpty = true) + @ConfigField(field = "security.plugin.type", notEmpty = true) private String eventMeshSecurityPluginType = "security"; - @ConfigFiled(field = "connector.plugin.type", notEmpty = true) - private String eventMeshConnectorPluginType = "rocketmq"; - - @ConfigFiled(field = "storage.plugin.type", notEmpty = true) - private String eventMeshStoragePluginType = "rocketmq"; + @ConfigField(field = "storage.plugin.type", notEmpty = true) + private String eventMeshStoragePluginType = "standalone"; - @ConfigFiled(field = "security.validation.type.token", notEmpty = true) + @ConfigField(field = "security.validation.type.token", notEmpty = true) private boolean eventMeshSecurityValidateTypeToken = false; - @ConfigFiled(field = "server.trace.enabled") + @ConfigField(field = "server.trace.enabled") private boolean eventMeshServerTraceEnable = false; - @ConfigFiled(field = "server.security.enabled") + @ConfigField(field = "server.security.enabled") private boolean eventMeshServerSecurityEnable = false; - @ConfigFiled(field = "security.publickey") + @ConfigField(field = "security.publickey") private String eventMeshSecurityPublickey = ""; - @ConfigFiled(field = "server.provide.protocols", reload = true) + @ConfigField(field = "server.provide.protocols", reload = true) private List eventMeshProvideServerProtocols; - @ConfigFiled(reload = true) + @ConfigField(reload = true) private String eventMeshWebhookOrigin; - @ConfigFiled(reload = true) + @ConfigField(reload = true) private String meshGroup; - @ConfigFiled(field = "server.retry.plugin.type") + @ConfigField(field = "server.retry.plugin.type") private String eventMeshRetryPluginType = Constants.DEFAULT; - @ConfigFiled(field = "registry.plugin.server-addr", notEmpty = true) + @ConfigField(field = "registry.plugin.server-addr", notEmpty = true) private String registryAddr = ""; - @ConfigFiled(field = "registry.plugin.type", notEmpty = true) + @ConfigField(field = "registry.plugin.type", notEmpty = true) private String eventMeshRegistryPluginType = "nacos"; - @ConfigFiled(field = "registry.plugin.username") + @ConfigField(field = "registry.plugin.username") private String eventMeshRegistryPluginUsername = ""; - @ConfigFiled(field = "registry.plugin.password") + @ConfigField(field = "registry.plugin.password") private String eventMeshRegistryPluginPassword = ""; public void reload() { diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigFiled.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigField.java similarity index 98% rename from eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigFiled.java rename to eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigField.java index d7c398e2db..aecdf23003 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigFiled.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigField.java @@ -29,7 +29,7 @@ */ @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.FIELD}) -public @interface ConfigFiled { +public @interface ConfigField { /** * @return The key name of the configuration file diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/ConvertValue.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/ConvertValue.java index e3870759d0..8b1372199e 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/ConvertValue.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/ConvertValue.java @@ -17,7 +17,7 @@ package org.apache.eventmesh.common.config.convert; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import org.apache.commons.lang3.StringUtils; @@ -44,7 +44,7 @@ default boolean canHandleNullValue() { /** * @return The value converter needs */ - default Object processFieldValue(ConvertInfo convertInfo, String key, ConfigFiled configFiled) { + default Object processFieldValue(ConvertInfo convertInfo, String key, ConfigField configField) { Properties properties = convertInfo.getProperties(); String value = properties.getProperty(key); @@ -54,14 +54,14 @@ default Object processFieldValue(ConvertInfo convertInfo, String key, ConfigFile value = value.trim(); - boolean findEnv = configFiled.findEnv(); - String fieldName = configFiled.field(); + boolean findEnv = configField.findEnv(); + String fieldName = configField.field(); if (StringUtils.isBlank(value) && !StringUtils.isBlank(fieldName) && findEnv) { value = Optional.ofNullable(System.getProperty(fieldName)).orElse(System.getenv(fieldName)); } - if (StringUtils.isBlank(value) && configFiled.notEmpty()) { + if (StringUtils.isBlank(value) && configField.notEmpty()) { throw new RuntimeException(key + " can't be empty!"); } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/ConverterMap.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/ConverterMap.java index 1fa1bced57..48d8c83ee8 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/ConverterMap.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/ConverterMap.java @@ -17,7 +17,7 @@ package org.apache.eventmesh.common.config.convert; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import org.apache.eventmesh.common.config.convert.converter.BaseDataTypeConverter; import org.apache.eventmesh.common.config.convert.converter.DateConverter; import org.apache.eventmesh.common.config.convert.converter.EnumConverter; @@ -96,9 +96,9 @@ public static void register(ConvertValue convertValue, Class... clazzs) { */ public static ConvertValue getFieldConverter(Field field) { Class clazz = field.getType(); - ConfigFiled configFiled = field.getAnnotation(ConfigFiled.class); + ConfigField configField = field.getAnnotation(ConfigField.class); - Class converter1 = configFiled.converter(); + Class converter1 = configField.converter(); if (!converter1.equals(ConvertValue.DefaultConverter.class)) { if (!classToConverter.containsKey(converter1)) { try { diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/converter/ObjectConverter.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/converter/ObjectConverter.java index 6e118851e2..3c91ee0692 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/converter/ObjectConverter.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/converter/ObjectConverter.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.common.config.convert.converter; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import org.apache.eventmesh.common.config.ConfigInfo; import org.apache.eventmesh.common.config.convert.ConvertInfo; import org.apache.eventmesh.common.config.convert.ConvertValue; @@ -110,18 +110,18 @@ private void setValue() throws Exception { field.setAccessible(true); ConvertInfo convertInfo = this.convertInfo; - ConfigFiled configFiled = field.getAnnotation(ConfigFiled.class); - if (Objects.isNull(configFiled)) { + ConfigField configField = field.getAnnotation(ConfigField.class); + if (Objects.isNull(configField)) { continue; } - String key = this.buildKey(configFiled); - needReload = this.checkNeedReload(needReload, configFiled); + String key = this.buildKey(configField); + needReload = this.checkNeedReload(needReload, configField); ConvertValue convertValue = ConverterMap.getFieldConverter(field); - Object fieldValue = convertValue.processFieldValue(convertInfo, key, configFiled); + Object fieldValue = convertValue.processFieldValue(convertInfo, key, configField); - if (!checkFieldValueBefore(configFiled, key, convertValue, fieldValue)) { + if (!checkFieldValueBefore(configField, key, convertValue, fieldValue)) { continue; } convertInfo.setValue(fieldValue); @@ -129,7 +129,7 @@ private void setValue() throws Exception { convertInfo.setKey(key); Object convertedValue = convertValue.convert(convertInfo); - if (!checkFieldValueAfter(configFiled, key, convertedValue)) { + if (!checkFieldValueAfter(configField, key, convertedValue)) { continue; } field.set(object, convertedValue); @@ -155,16 +155,16 @@ private void reloadConfigIfNeed(boolean needReload) throws NoSuchMethodException } } - private boolean checkFieldValueAfter(ConfigFiled configFiled, String key, Object convertedValue) { + private boolean checkFieldValueAfter(ConfigField configField, String key, Object convertedValue) { if (Objects.isNull(convertedValue)) { - if (configFiled.notNull()) { + if (configField.notNull()) { throw new RuntimeException(key + " can not be null!"); } return false; } - if (configFiled.beNumber()) { + if (configField.beNumber()) { if (!StringUtils.isNumeric(String.valueOf(convertedValue))) { throw new RuntimeException(key + " must be number!"); } @@ -173,9 +173,9 @@ private boolean checkFieldValueAfter(ConfigFiled configFiled, String key, Object return true; } - private boolean checkFieldValueBefore(ConfigFiled configFiled, String key, ConvertValue convertValue, Object fieldValue) { + private boolean checkFieldValueBefore(ConfigField configField, String key, ConvertValue convertValue, Object fieldValue) { if (Objects.isNull(fieldValue) && !convertValue.canHandleNullValue()) { - if (configFiled.notNull()) { + if (configField.notNull()) { throw new RuntimeException(key + " can not be null!"); } @@ -185,8 +185,8 @@ private boolean checkFieldValueBefore(ConfigFiled configFiled, String key, Conve return true; } - private boolean checkNeedReload(boolean needReload, ConfigFiled configFiled) { - if (!needReload && configFiled != null && configFiled.reload()) { + private boolean checkNeedReload(boolean needReload, ConfigField configField) { + if (!needReload && configField != null && configField.reload()) { needReload = Boolean.TRUE; } @@ -201,14 +201,14 @@ private boolean checkNeedReload(boolean needReload, ConfigFiled configFiled) { return needReload; } - private String buildKey(ConfigFiled configFiled) { + private String buildKey(ConfigField configField) { String key; StringBuilder keyPrefix = new StringBuilder(Objects.isNull(prefix) ? "" : prefix); - if (configFiled == null || configFiled.field().isEmpty() && keyPrefix.length() > 0) { + if (configField == null || configField.field().isEmpty() && keyPrefix.length() > 0) { key = keyPrefix.deleteCharAt(keyPrefix.length() - 1).toString(); } else { - key = keyPrefix.append(configFiled.field()).toString(); + key = keyPrefix.append(configField.field()).toString(); } return key; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/converter/PropertiesConverter.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/converter/PropertiesConverter.java index e4dbf470df..7c58fccdc3 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/converter/PropertiesConverter.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/converter/PropertiesConverter.java @@ -17,7 +17,7 @@ package org.apache.eventmesh.common.config.convert.converter; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import org.apache.eventmesh.common.config.convert.ConvertInfo; import org.apache.eventmesh.common.config.convert.ConvertValue; import org.apache.eventmesh.common.utils.PropertiesUtils; @@ -41,7 +41,7 @@ public Properties convert(ConvertInfo convertInfo) { } @Override - public Object processFieldValue(ConvertInfo convertInfo, String prefix, ConfigFiled configFiled) { + public Object processFieldValue(ConvertInfo convertInfo, String prefix, ConfigField configField) { Properties properties = convertInfo.getProperties(); if (StringUtils.isBlank(prefix)) { diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/config/CommonConfigurationTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/config/CommonConfigurationTest.java index 11265522a7..fb1ebc1635 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/config/CommonConfigurationTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/config/CommonConfigurationTest.java @@ -45,7 +45,6 @@ public void testGetCommonConfiguration() { Assertions.assertEquals("cluster-succeed!!!", config.getEventMeshCluster()); Assertions.assertEquals("name-succeed!!!", config.getEventMeshName()); Assertions.assertEquals("816", config.getSysID()); - // Assertions.assertEquals("connector-succeed!!!", config.getEventMeshConnectorPluginType()); Assertions.assertEquals("storage-succeed!!!", config.getEventMeshStoragePluginType()); Assertions.assertEquals("storage-succeed!!!", config.getEventMeshStoragePluginType()); Assertions.assertEquals("security-succeed!!!", config.getEventMeshSecurityPluginType()); @@ -55,9 +54,6 @@ public void testGetCommonConfiguration() { Assertions.assertEquals("username-succeed!!!", config.getEventMeshMetaStoragePluginUsername()); Assertions.assertEquals("password-succeed!!!", config.getEventMeshMetaStoragePluginPassword()); - Assertions.assertEquals(Integer.valueOf(816), config.getEventMeshMetaStorageIntervalInMills()); - Assertions.assertEquals(Integer.valueOf(1816), config.getEventMeshFetchMetaStorageAddrInterval()); - List list = new ArrayList<>(); list.add("metrics-succeed1!!!"); list.add("metrics-succeed2!!!"); diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/SystemUtilsTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/SystemUtilsTest.java index b941fee1d4..32f4ae946e 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/SystemUtilsTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/SystemUtilsTest.java @@ -24,7 +24,7 @@ public class SystemUtilsTest { @Test public void isLinuxPlatform() { - if (null != SystemUtils.OS_NAME && SystemUtils.OS_NAME.toLowerCase().contains("linux")) { + if (SystemUtils.OS_NAME != null && SystemUtils.OS_NAME.toLowerCase().contains("linux")) { Assertions.assertTrue(SystemUtils.isLinuxPlatform()); Assertions.assertFalse(SystemUtils.isWindowsPlatform()); } @@ -32,7 +32,7 @@ public void isLinuxPlatform() { @Test public void isWindowsPlatform() { - if (null != SystemUtils.OS_NAME && SystemUtils.OS_NAME.toLowerCase().contains("windows")) { + if (SystemUtils.OS_NAME != null && SystemUtils.OS_NAME.toLowerCase().contains("windows")) { Assertions.assertFalse(SystemUtils.isLinuxPlatform()); Assertions.assertTrue(SystemUtils.isWindowsPlatform()); } diff --git a/eventmesh-common/src/test/resources/configuration.properties b/eventmesh-common/src/test/resources/configuration.properties index f80bb7db01..f53a7680f0 100644 --- a/eventmesh-common/src/test/resources/configuration.properties +++ b/eventmesh-common/src/test/resources/configuration.properties @@ -20,13 +20,10 @@ eventMesh.sysid=816 eventMesh.server.cluster=cluster-succeed!!! eventMesh.server.name=name-succeed!!! eventMesh.server.hostIp=hostIp-succeed!!! -eventMesh.connector.plugin.type=connector-succeed!!! eventMesh.storage.plugin.type=storage-succeed!!! eventMesh.security.plugin.type=security-succeed!!! eventMesh.metaStorage.plugin.type=metaStorage-succeed!!! eventMesh.trace.plugin=trace-succeed!!! -eventMesh.metaStorage.plugin.metaStorageIntervalInMills=816 -eventMesh.metaStorage.plugin.fetchMetaStorageAddrIntervalInMills=1816 eventMesh.metrics.plugin=metrics-succeed1!!!,metrics-succeed2!!!,metrics-succeed3!!! eventMesh.metaStorage.plugin.server-addr=server-addr-succeed1!!! diff --git a/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/dialect/AbstractGeneralDatabaseDialect.java b/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/dialect/AbstractGeneralDatabaseDialect.java index 64bde49935..0a7463a187 100644 --- a/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/dialect/AbstractGeneralDatabaseDialect.java +++ b/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/dialect/AbstractGeneralDatabaseDialect.java @@ -146,7 +146,7 @@ protected void registerType(Type type) { @Override public String getTypeName(Dialect hibernateDialect, Column column) { Type type = this.getType(column); - if (null != type) { + if (type != null) { return type.getTypeName(column); } Long length = Optional.ofNullable(column.getColumnLength()).orElse(0L); diff --git a/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/source/dialect/antlr4/mysql/listener/CreateTableParserListener.java b/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/source/dialect/antlr4/mysql/listener/CreateTableParserListener.java index c24f885d75..4e30da93f9 100644 --- a/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/source/dialect/antlr4/mysql/listener/CreateTableParserListener.java +++ b/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/source/dialect/antlr4/mysql/listener/CreateTableParserListener.java @@ -166,7 +166,7 @@ public void enterTableOptionCharset(TableOptionCharsetContext ctx) { @Override public void enterTableOptionAutoIncrement(TableOptionAutoIncrementContext ctx) { DecimalLiteralContext decimalLiteralContext = ctx.decimalLiteral(); - if (null != decimalLiteralContext) { + if (decimalLiteralContext != null) { String autoIncrementNumber = Antlr4Utils.getText(decimalLiteralContext); this.tableEditor.withOption(MysqlTableOptions.AUTO_INCREMENT, autoIncrementNumber); } diff --git a/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/source/dialect/cdc/mysql/MysqlCdcEngine.java b/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/source/dialect/cdc/mysql/MysqlCdcEngine.java index 645e5c9eca..5650c3d0cc 100644 --- a/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/source/dialect/cdc/mysql/MysqlCdcEngine.java +++ b/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/source/dialect/cdc/mysql/MysqlCdcEngine.java @@ -392,7 +392,7 @@ private void enableGtidHandle() { EventMeshGtidSet purgedServerEventMeshGtidSet = new EventMeshGtidSet(purgedServerGtid); EventMeshGtidSet filteredEventMeshGtidSet = filterGtidSet(context, executedEventMeshGtidSet, purgedServerEventMeshGtidSet); - if (null != filteredEventMeshGtidSet) { + if (filteredEventMeshGtidSet != null) { client.setGtidSet(filteredEventMeshGtidSet.toString()); this.context.completedGtidSet(filteredEventMeshGtidSet.toString()); localGtidSet = new com.github.shyiko.mysql.binlog.GtidSet(filteredEventMeshGtidSet.toString()); @@ -645,7 +645,7 @@ private void handleCdcDmlData(MysqlJdbcContext context, MysqlSourceMateData sour schema.addKeys(tableSchema.getPrimaryKey().getColumnNames()); Pair beforePair = Optional.ofNullable(pair.getLeft()).orElse(new Pair<>()); Serializable[] beforeRows = beforePair.getLeft(); - if (null != beforeRows && beforeRows.length != 0) { + if (beforeRows != null && beforeRows.length != 0) { BitSet includedColumns = beforePair.getRight(); Map beforeValues = new HashMap<>(beforeRows.length); for (int index = 0; index < columnsSize; ++index) { @@ -663,7 +663,7 @@ private void handleCdcDmlData(MysqlJdbcContext context, MysqlSourceMateData sour Pair afterPair = Optional.ofNullable(pair.getRight()).orElse(new Pair<>()); Serializable[] afterRows = afterPair.getLeft(); - if (null != afterRows && afterRows.length != 0) { + if (afterRows != null && afterRows.length != 0) { BitSet includedColumns = afterPair.getRight(); Map afterValues = new HashMap<>(afterRows.length); for (int index = 0; index < columnsSize; ++index) { diff --git a/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/table/catalog/Table.java b/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/table/catalog/Table.java index c475227248..158ffc81da 100644 --- a/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/table/catalog/Table.java +++ b/eventmesh-connectors/eventmesh-connector-jdbc/src/main/java/org/apache/eventmesh/connector/jdbc/table/catalog/Table.java @@ -48,7 +48,7 @@ public Table(TableId tableId, PrimaryKey primaryKey, List uniqueKeys, this.primaryKey = primaryKey; this.uniqueKeys = uniqueKeys; this.comment = comment; - if (null != options) { + if (options != null) { this.options.putAll(options); } } diff --git a/eventmesh-connectors/eventmesh-connector-lark/src/main/java/org/apache/eventmesh/connector/lark/sink/ImServiceHandler.java b/eventmesh-connectors/eventmesh-connector-lark/src/main/java/org/apache/eventmesh/connector/lark/sink/ImServiceHandler.java index 4797d58ef9..75e51e690b 100644 --- a/eventmesh-connectors/eventmesh-connector-lark/src/main/java/org/apache/eventmesh/connector/lark/sink/ImServiceHandler.java +++ b/eventmesh-connectors/eventmesh-connector-lark/src/main/java/org/apache/eventmesh/connector/lark/sink/ImServiceHandler.java @@ -313,12 +313,12 @@ private String createInteractiveContent(ConnectRecord connectRecord, String titl private boolean needAtAll(ConnectRecord connectRecord) { String atAll = connectRecord.getExtension(ConnectRecordExtensionKeys.AT_ALL_4_LARK); - return null != atAll && !"null".equals(atAll) && Boolean.parseBoolean(atAll); + return atAll != null && !"null".equals(atAll) && Boolean.parseBoolean(atAll); } private String needAtUser(ConnectRecord connectRecord) { String atUsers = connectRecord.getExtension(ConnectRecordExtensionKeys.AT_USERS_4_LARK); - return null != atUsers && !"null".equals(atUsers) ? atUsers : ""; + return atUsers != null && !"null".equals(atUsers) ? atUsers : ""; } /** diff --git a/eventmesh-connectors/eventmesh-connector-prometheus/build.gradle b/eventmesh-connectors/eventmesh-connector-prometheus/build.gradle index d92797a8c4..9650575803 100644 --- a/eventmesh-connectors/eventmesh-connector-prometheus/build.gradle +++ b/eventmesh-connectors/eventmesh-connector-prometheus/build.gradle @@ -19,7 +19,7 @@ dependencies { implementation project(":eventmesh-openconnect:eventmesh-openconnect-java") implementation 'org.apache.httpcomponents:httpclient' implementation 'com.github.rholder:guava-retrying' - implementation 'com.alibaba:fastjson' + implementation 'com.alibaba.fastjson2:fastjson2' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' } \ No newline at end of file diff --git a/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/source/connector/PrometheusSourceConnector.java b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/source/connector/PrometheusSourceConnector.java index 0fe5c87576..2c75f394fc 100644 --- a/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/source/connector/PrometheusSourceConnector.java +++ b/eventmesh-connectors/eventmesh-connector-prometheus/src/main/java/org/apache/eventmesh/connector/prometheus/source/connector/PrometheusSourceConnector.java @@ -44,8 +44,8 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.github.rholder.retry.Attempt; import com.github.rholder.retry.RetryListener; import com.github.rholder.retry.Retryer; diff --git a/eventmesh-connectors/eventmesh-connector-rabbitmq/src/main/java/org/apache/eventmesh/connector/rabbitmq/client/RabbitmqClient.java b/eventmesh-connectors/eventmesh-connector-rabbitmq/src/main/java/org/apache/eventmesh/connector/rabbitmq/client/RabbitmqClient.java index 34cda9620e..1f324b5847 100644 --- a/eventmesh-connectors/eventmesh-connector-rabbitmq/src/main/java/org/apache/eventmesh/connector/rabbitmq/client/RabbitmqClient.java +++ b/eventmesh-connectors/eventmesh-connector-rabbitmq/src/main/java/org/apache/eventmesh/connector/rabbitmq/client/RabbitmqClient.java @@ -120,7 +120,7 @@ public void unbinding(Channel channel, String exchangeName, String routingKey, S * @param connection connection */ public void closeConnection(Connection connection) { - if (null != connection) { + if (connection != null) { try { connection.close(); } catch (Exception ex) { @@ -135,7 +135,7 @@ public void closeConnection(Connection connection) { * @param channel channel */ public void closeChannel(Channel channel) { - if (null != channel) { + if (channel != null) { try { channel.close(); } catch (Exception ex) { diff --git a/eventmesh-connectors/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/sink/connector/RocketMQSinkConnector.java b/eventmesh-connectors/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/sink/connector/RocketMQSinkConnector.java index a63d92d7f5..9eb23f9318 100644 --- a/eventmesh-connectors/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/sink/connector/RocketMQSinkConnector.java +++ b/eventmesh-connectors/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/sink/connector/RocketMQSinkConnector.java @@ -18,6 +18,7 @@ package org.apache.eventmesh.connector.rocketmq.sink.connector; import org.apache.eventmesh.connector.rocketmq.sink.config.RocketMQSinkConfig; +import org.apache.eventmesh.openconnect.api.ConnectorCreateService; import org.apache.eventmesh.openconnect.api.config.Config; import org.apache.eventmesh.openconnect.api.connector.ConnectorContext; import org.apache.eventmesh.openconnect.api.connector.SinkConnectorContext; @@ -34,7 +35,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -public class RocketMQSinkConnector implements Sink { +public class RocketMQSinkConnector implements Sink, ConnectorCreateService { private RocketMQSinkConfig sinkConfig; @@ -108,4 +109,9 @@ public Message convertRecordToMessage(ConnectRecord connectRecord) { } return message; } + + @Override + public Sink create() { + return new RocketMQSinkConnector(); + } } diff --git a/eventmesh-connectors/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/source/connector/RocketMQSourceConnector.java b/eventmesh-connectors/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/source/connector/RocketMQSourceConnector.java index 8023be479f..ab2bcd92a7 100644 --- a/eventmesh-connectors/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/source/connector/RocketMQSourceConnector.java +++ b/eventmesh-connectors/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/source/connector/RocketMQSourceConnector.java @@ -18,6 +18,7 @@ package org.apache.eventmesh.connector.rocketmq.source.connector; import org.apache.eventmesh.connector.rocketmq.source.config.RocketMQSourceConfig; +import org.apache.eventmesh.openconnect.api.ConnectorCreateService; import org.apache.eventmesh.openconnect.api.config.Config; import org.apache.eventmesh.openconnect.api.connector.ConnectorContext; import org.apache.eventmesh.openconnect.api.connector.SourceConnectorContext; @@ -60,7 +61,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -public class RocketMQSourceConnector implements Source { +public class RocketMQSourceConnector implements Source, ConnectorCreateService { private RocketMQSourceConfig sourceConfig; @@ -301,4 +302,9 @@ public void commitOffset(MessageQueue mq, long canCommitOffset) { commitOffset.add(new AtomicLong(nextBeginOffset)); prepareCommitOffset.put(mq, commitOffset); } + + @Override + public Source create() { + return new RocketMQSourceConnector(); + } } diff --git a/eventmesh-connectors/eventmesh-connector-wechat/build.gradle b/eventmesh-connectors/eventmesh-connector-wechat/build.gradle index c791524485..9a73345d1d 100644 --- a/eventmesh-connectors/eventmesh-connector-wechat/build.gradle +++ b/eventmesh-connectors/eventmesh-connector-wechat/build.gradle @@ -26,7 +26,7 @@ dependencies { implementation project(":eventmesh-sdks:eventmesh-sdk-java") implementation project(":eventmesh-openconnect:eventmesh-openconnect-java") - implementation 'com.alibaba:fastjson' + implementation 'com.alibaba.fastjson2:fastjson2' implementation 'com.google.guava:guava' implementation 'com.squareup.okhttp3:okhttp' diff --git a/eventmesh-connectors/eventmesh-connector-wechat/src/main/java/org/apache/eventmesh/connector/wechat/sink/connector/WeChatSinkConnector.java b/eventmesh-connectors/eventmesh-connector-wechat/src/main/java/org/apache/eventmesh/connector/wechat/sink/connector/WeChatSinkConnector.java index 1d1c3258cb..ac66ec45cc 100644 --- a/eventmesh-connectors/eventmesh-connector-wechat/src/main/java/org/apache/eventmesh/connector/wechat/sink/connector/WeChatSinkConnector.java +++ b/eventmesh-connectors/eventmesh-connector-wechat/src/main/java/org/apache/eventmesh/connector/wechat/sink/connector/WeChatSinkConnector.java @@ -32,8 +32,8 @@ import java.util.Objects; import java.util.concurrent.TimeUnit; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; diff --git a/eventmesh-meta/eventmesh-meta-consul/src/main/java/org/apache/eventmesh/meta/consul/config/ConsulTLSConfig.java b/eventmesh-meta/eventmesh-meta-consul/src/main/java/org/apache/eventmesh/meta/consul/config/ConsulTLSConfig.java index 1664a014dd..f63e520861 100644 --- a/eventmesh-meta/eventmesh-meta-consul/src/main/java/org/apache/eventmesh/meta/consul/config/ConsulTLSConfig.java +++ b/eventmesh-meta/eventmesh-meta-consul/src/main/java/org/apache/eventmesh/meta/consul/config/ConsulTLSConfig.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.meta.consul.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import org.apache.eventmesh.common.config.convert.converter.EnumConverter; import com.ecwid.consul.transport.TLSConfig.KeyStoreInstanceType; @@ -31,19 +31,19 @@ @Config(prefix = "eventMesh.registry.consul.tls") public class ConsulTLSConfig { - @ConfigFiled(field = "keyStoreInstanceType", converter = EnumConverter.class) + @ConfigField(field = "keyStoreInstanceType", converter = EnumConverter.class) private KeyStoreInstanceType keyStoreInstanceType; - @ConfigFiled(field = "certificatePath") + @ConfigField(field = "certificatePath") private String certificatePath; - @ConfigFiled(field = "certificatePassword") + @ConfigField(field = "certificatePassword") private String certificatePassword; - @ConfigFiled(field = "keyStorePath") + @ConfigField(field = "keyStorePath") private String keyStorePath; - @ConfigFiled(field = "keyStorePassword") + @ConfigField(field = "keyStorePassword") private String keyStorePassword; } diff --git a/eventmesh-meta/eventmesh-meta-consul/src/main/java/org/apache/eventmesh/meta/consul/service/ConsulMetaService.java b/eventmesh-meta/eventmesh-meta-consul/src/main/java/org/apache/eventmesh/meta/consul/service/ConsulMetaService.java index 2d9b921efb..a3849d2cc8 100644 --- a/eventmesh-meta/eventmesh-meta-consul/src/main/java/org/apache/eventmesh/meta/consul/service/ConsulMetaService.java +++ b/eventmesh-meta/eventmesh-meta-consul/src/main/java/org/apache/eventmesh/meta/consul/service/ConsulMetaService.java @@ -72,7 +72,7 @@ public void init() throws MetaException { if (initStatus.compareAndSet(false, true)) { for (String key : ConfigurationContextUtil.KEYS) { CommonConfiguration commonConfiguration = ConfigurationContextUtil.get(key); - if (null != commonConfiguration) { + if (commonConfiguration != null) { String metaStorageAddr = commonConfiguration.getMetaStorageAddr(); if (StringUtils.isBlank(metaStorageAddr)) { throw new MetaException("namesrvAddr cannot be null"); diff --git a/eventmesh-meta/eventmesh-meta-nacos/src/main/java/org/apache/eventmesh/meta/nacos/config/NacosMetaStorageConfiguration.java b/eventmesh-meta/eventmesh-meta-nacos/src/main/java/org/apache/eventmesh/meta/nacos/config/NacosMetaStorageConfiguration.java index 67e51d2d9e..d6de51ca8b 100644 --- a/eventmesh-meta/eventmesh-meta-nacos/src/main/java/org/apache/eventmesh/meta/nacos/config/NacosMetaStorageConfiguration.java +++ b/eventmesh-meta/eventmesh-meta-nacos/src/main/java/org/apache/eventmesh/meta/nacos/config/NacosMetaStorageConfiguration.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.meta.nacos.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.client.naming.utils.UtilAndComs; @@ -31,31 +31,31 @@ @Config(prefix = "eventMesh.metaStorage.nacos") public class NacosMetaStorageConfiguration { - @ConfigFiled(field = PropertyKeyConst.ENDPOINT) + @ConfigField(field = PropertyKeyConst.ENDPOINT) private String endpoint; - @ConfigFiled(field = PropertyKeyConst.ENDPOINT_PORT) + @ConfigField(field = PropertyKeyConst.ENDPOINT_PORT) private String endpointPort; - @ConfigFiled(field = PropertyKeyConst.ACCESS_KEY) + @ConfigField(field = PropertyKeyConst.ACCESS_KEY) private String accessKey; - @ConfigFiled(field = PropertyKeyConst.SECRET_KEY) + @ConfigField(field = PropertyKeyConst.SECRET_KEY) private String secretKey; - @ConfigFiled(field = PropertyKeyConst.CLUSTER_NAME) + @ConfigField(field = PropertyKeyConst.CLUSTER_NAME) private String clusterName; - @ConfigFiled(field = PropertyKeyConst.NAMESPACE) + @ConfigField(field = PropertyKeyConst.NAMESPACE) private String namespace; - @ConfigFiled(field = PropertyKeyConst.NAMING_POLLING_THREAD_COUNT) + @ConfigField(field = PropertyKeyConst.NAMING_POLLING_THREAD_COUNT) private Integer pollingThreadCount = Runtime.getRuntime().availableProcessors() / 2 + 1; - @ConfigFiled(field = UtilAndComs.NACOS_NAMING_LOG_NAME) + @ConfigField(field = UtilAndComs.NACOS_NAMING_LOG_NAME) private String logFileName; - @ConfigFiled(field = UtilAndComs.NACOS_NAMING_LOG_LEVEL) + @ConfigField(field = UtilAndComs.NACOS_NAMING_LOG_LEVEL) private String logLevel; } diff --git a/eventmesh-meta/eventmesh-meta-zookeeper/src/main/java/org/apache/eventmesh/meta/zookeeper/config/ZKRegistryConfiguration.java b/eventmesh-meta/eventmesh-meta-zookeeper/src/main/java/org/apache/eventmesh/meta/zookeeper/config/ZKRegistryConfiguration.java index bec8faae7e..7e6f743c89 100644 --- a/eventmesh-meta/eventmesh-meta-zookeeper/src/main/java/org/apache/eventmesh/meta/zookeeper/config/ZKRegistryConfiguration.java +++ b/eventmesh-meta/eventmesh-meta-zookeeper/src/main/java/org/apache/eventmesh/meta/zookeeper/config/ZKRegistryConfiguration.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.meta.zookeeper.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import lombok.Data; import lombok.NoArgsConstructor; @@ -28,38 +28,38 @@ @Config(prefix = "eventMesh.registry.zookeeper") public class ZKRegistryConfiguration { - @ConfigFiled(field = "scheme") + @ConfigField(field = "scheme") private String scheme; - @ConfigFiled(field = "auth") + @ConfigField(field = "auth") private String auth; - @ConfigFiled(field = "connectionTimeoutMs") + @ConfigField(field = "connectionTimeoutMs") private Integer connectionTimeoutMs = 5000; - @ConfigFiled(field = "sessionTimeoutMs") + @ConfigField(field = "sessionTimeoutMs") private Integer sessionTimeoutMs = 40000; // Fully qualified name of RetryPolicy implementation - @ConfigFiled(field = "retryPolicy.class") + @ConfigField(field = "retryPolicy.class") private String retryPolicyClass; - @ConfigFiled(field = "retryPolicy.baseSleepTimeMs") + @ConfigField(field = "retryPolicy.baseSleepTimeMs") private Integer baseSleepTimeMs = 1000; - @ConfigFiled(field = "retryPolicy.maxRetries") + @ConfigField(field = "retryPolicy.maxRetries") private Integer maxRetries = 5; - @ConfigFiled(field = "retryPolicy.maxSleepTimeMs") + @ConfigField(field = "retryPolicy.maxSleepTimeMs") private Integer maxSleepTimeMs = 5000; - @ConfigFiled(field = "retryPolicy.retryIntervalMs") + @ConfigField(field = "retryPolicy.retryIntervalMs") private Integer retryIntervalTimeMs = 1000; - @ConfigFiled(field = "retryPolicy.nTimes") + @ConfigField(field = "retryPolicy.nTimes") private Integer retryNTimes = 10; - @ConfigFiled(field = "retryPolicy.sleepMsBetweenRetries") + @ConfigField(field = "retryPolicy.sleepMsBetweenRetries") private Integer sleepMsBetweenRetries = 1000; } diff --git a/eventmesh-meta/eventmesh-meta-zookeeper/src/main/java/org/apache/eventmesh/meta/zookeeper/service/ZookeeperMetaService.java b/eventmesh-meta/eventmesh-meta-zookeeper/src/main/java/org/apache/eventmesh/meta/zookeeper/service/ZookeeperMetaService.java index 359e7427f0..18520feb4d 100644 --- a/eventmesh-meta/eventmesh-meta-zookeeper/src/main/java/org/apache/eventmesh/meta/zookeeper/service/ZookeeperMetaService.java +++ b/eventmesh-meta/eventmesh-meta-zookeeper/src/main/java/org/apache/eventmesh/meta/zookeeper/service/ZookeeperMetaService.java @@ -175,7 +175,7 @@ public void shutdown() throws MetaException { if (!startStatus.compareAndSet(true, false)) { return; } - if (null != zkClient) { + if (zkClient != null) { zkClient.close(); } log.info("ZookeeperRegistryService closed"); diff --git a/eventmesh-metrics-plugin/eventmesh-metrics-prometheus/src/main/java/org/apache/eventmesh/metrics/prometheus/config/PrometheusConfiguration.java b/eventmesh-metrics-plugin/eventmesh-metrics-prometheus/src/main/java/org/apache/eventmesh/metrics/prometheus/config/PrometheusConfiguration.java index 63e5688302..e2d684f04b 100644 --- a/eventmesh-metrics-plugin/eventmesh-metrics-prometheus/src/main/java/org/apache/eventmesh/metrics/prometheus/config/PrometheusConfiguration.java +++ b/eventmesh-metrics-plugin/eventmesh-metrics-prometheus/src/main/java/org/apache/eventmesh/metrics/prometheus/config/PrometheusConfiguration.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.metrics.prometheus.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import lombok.Data; @@ -26,6 +26,6 @@ @Config(prefix = "eventMesh.metrics.prometheus", path = "classPath://prometheus.properties") public class PrometheusConfiguration { - @ConfigFiled(field = "port") + @ConfigField(field = "port") private int eventMeshPrometheusPort = 19090; } diff --git a/eventmesh-openconnect/eventmesh-openconnect-java/src/main/java/org/apache/eventmesh/openconnect/api/factory/ConnectorPluginFactory.java b/eventmesh-openconnect/eventmesh-openconnect-java/src/main/java/org/apache/eventmesh/openconnect/api/factory/ConnectorPluginFactory.java new file mode 100644 index 0000000000..7a6f2e0a9c --- /dev/null +++ b/eventmesh-openconnect/eventmesh-openconnect-java/src/main/java/org/apache/eventmesh/openconnect/api/factory/ConnectorPluginFactory.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.eventmesh.openconnect.api.factory; + +import org.apache.eventmesh.openconnect.api.ConnectorCreateService; +import org.apache.eventmesh.openconnect.api.connector.SinkConnector; +import org.apache.eventmesh.openconnect.api.connector.SourceConnector; +import org.apache.eventmesh.spi.EventMeshExtensionFactory; + + +/** + * The factory to get connector {@link SourceConnector} and {@link SinkConnector} + */ +public class ConnectorPluginFactory { + + /** + * Get ConnectorCreateService instance by plugin name + * + * @param connectorPluginName plugin name + * @return ConnectorCreateService instance + */ + public static ConnectorCreateService createConnector(String connectorPluginName) { + return EventMeshExtensionFactory.getExtension(ConnectorCreateService.class, connectorPluginName); + } + +} diff --git a/eventmesh-openconnect/eventmesh-openconnect-java/src/main/java/org/apache/eventmesh/openconnect/util/ConfigUtil.java b/eventmesh-openconnect/eventmesh-openconnect-java/src/main/java/org/apache/eventmesh/openconnect/util/ConfigUtil.java index 93b2ba9582..13f1d74f6b 100644 --- a/eventmesh-openconnect/eventmesh-openconnect-java/src/main/java/org/apache/eventmesh/openconnect/util/ConfigUtil.java +++ b/eventmesh-openconnect/eventmesh-openconnect-java/src/main/java/org/apache/eventmesh/openconnect/util/ConfigUtil.java @@ -25,6 +25,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.net.URL; +import java.util.Map; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; @@ -67,6 +68,11 @@ public static T parse(Class c, String filePathName) throws Exception { return objectMapper.readValue(url, c); } + public static T parse(Map map, Class c) throws Exception { + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.convertValue(map, c); + } + private static Config parseSourceConfig(Class c) throws Exception { String configFile = System.getProperty(Constants.ENV_SOURCE_CONFIG_FILE, System.getenv(Constants.ENV_SOURCE_CONFIG_FILE)); if (configFile == null || configFile.isEmpty()) { diff --git a/eventmesh-operator/config/samples/eventmesh_v1_runtime.yaml b/eventmesh-operator/config/samples/eventmesh_v1_runtime.yaml index ee94d606fb..fc640aa639 100644 --- a/eventmesh-operator/config/samples/eventmesh_v1_runtime.yaml +++ b/eventmesh-operator/config/samples/eventmesh_v1_runtime.yaml @@ -35,11 +35,13 @@ data: eventMesh.server.cluster=COMMON eventMesh.server.name=EVENTMESH-runtime eventMesh.sysid=0000 + eventMesh.server.tcp.port=10000 eventMesh.server.http.port=10105 eventMesh.server.grpc.port=10205 + # HTTP Admin Server + eventMesh.server.admin.http.port=10106 ########################## eventMesh tcp configuration ############################ eventMesh.server.tcp.enabled=true - eventMesh.server.tcp.port=10000 eventMesh.server.tcp.readerIdleSeconds=120 eventMesh.server.tcp.writerIdleSeconds=120 eventMesh.server.tcp.allIdleSeconds=120 @@ -69,13 +71,6 @@ data: eventMesh.server.retry.async.pushRetryDelayInMills=500 eventMesh.server.retry.sync.pushRetryDelayInMills=500 eventMesh.server.retry.pushRetryQueueSize=10000 - #admin - eventMesh.server.admin.http.port=10106 - #metaStorage - eventMesh.server.metaStorage.metaStorageIntervalInMills=10000 - eventMesh.server.metaStorage.fetchMetaStorageAddrIntervalInMills=20000 - #auto-ack - #eventMesh.server.defibus.client.comsumeTimeoutInMin=5 #sleep interval between closing client of different group in server graceful shutdown eventMesh.server.gracefulShutdown.sleepIntervalInMills=1000 @@ -85,9 +80,6 @@ data: eventMesh.server.blacklist.ipv4=0.0.0.0/8,127.0.0.0/8,169.254.0.0/16,255.255.255.255/32 eventMesh.server.blacklist.ipv6=::/128,::1/128,ff00::/8 - #connector plugin - eventMesh.connector.plugin.type=standalone - #storage plugin eventMesh.storage.plugin.type=standalone diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-http/src/main/java/org/apache/eventmesh/protocol/http/HttpProtocolAdaptor.java b/eventmesh-protocol-plugin/eventmesh-protocol-http/src/main/java/org/apache/eventmesh/protocol/http/HttpProtocolAdaptor.java index a232781ff6..08c4718825 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-http/src/main/java/org/apache/eventmesh/protocol/http/HttpProtocolAdaptor.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-http/src/main/java/org/apache/eventmesh/protocol/http/HttpProtocolAdaptor.java @@ -97,7 +97,7 @@ public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws Prot } httpEventWrapper.setSysHeaderMap(sysHeaderMap); // ce data - if (null != cloudEvent.getData()) { + if (cloudEvent.getData() != null) { Map dataContentMap = JsonUtils.parseTypeReferenceObject( new String(Objects.requireNonNull(cloudEvent.getData()).toBytes(), Constants.DEFAULT_CHARSET), new TypeReference>() { diff --git a/eventmesh-runtime-v2/build.gradle b/eventmesh-runtime-v2/build.gradle new file mode 100644 index 0000000000..a04d127116 --- /dev/null +++ b/eventmesh-runtime-v2/build.gradle @@ -0,0 +1,26 @@ +plugins { + id 'java' +} + +group 'org.apache.eventmesh' +version '1.10.0-release' + +repositories { + mavenCentral() +} + +dependencies { + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + + implementation project(":eventmesh-openconnect:eventmesh-openconnect-java") + implementation project(":eventmesh-common") + implementation project(":eventmesh-meta:eventmesh-meta-api") + implementation project(":eventmesh-meta:eventmesh-meta-nacos") + + implementation "io.grpc:grpc-core" + implementation "io.grpc:grpc-protobuf" + implementation "io.grpc:grpc-stub" + implementation "io.grpc:grpc-netty" + implementation "io.grpc:grpc-netty-shaded" +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/Runtime.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/Runtime.java new file mode 100644 index 0000000000..dc372510d7 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/Runtime.java @@ -0,0 +1,11 @@ +package org.apache.eventmesh.runtime; + +public interface Runtime { + + void init() throws Exception; + + void start() throws Exception; + + void stop() throws Exception; + +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/RuntimeFactory.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/RuntimeFactory.java new file mode 100644 index 0000000000..ad27133297 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/RuntimeFactory.java @@ -0,0 +1,9 @@ +package org.apache.eventmesh.runtime; + +public interface RuntimeFactory extends AutoCloseable { + + void init() throws Exception; + + Runtime createRuntime(RuntimeInstanceConfig runtimeInstanceConfig); + +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/RuntimeInstanceConfig.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/RuntimeInstanceConfig.java new file mode 100644 index 0000000000..ab2938ac21 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/RuntimeInstanceConfig.java @@ -0,0 +1,33 @@ +package org.apache.eventmesh.runtime; + +import org.apache.eventmesh.common.config.Config; + +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@Config(path = "classPath://runtime.yaml") +public class RuntimeInstanceConfig { + + private String registryServerAddr; + + private String registryPluginType; + + private String storagePluginType; + + private String runtimeInstanceId; + + private String runtimeInstanceName; + + private String runtimeInstanceDesc; + + private String runtimeInstanceType; + + private String runtimeInstanceVersion; + + private String runtimeInstanceConfig; + + private String runtimeInstanceStatus; + +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/boot/RuntimeInstance.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/boot/RuntimeInstance.java new file mode 100644 index 0000000000..9c481463a4 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/boot/RuntimeInstance.java @@ -0,0 +1,100 @@ +package org.apache.eventmesh.runtime.boot; + +import org.apache.eventmesh.runtime.Runtime; +import org.apache.eventmesh.runtime.RuntimeFactory; +import org.apache.eventmesh.runtime.RuntimeInstanceConfig; +import org.apache.eventmesh.runtime.meta.MetaStorage; +import org.apache.eventmesh.runtime.rpc.AdminBiStreamServiceGrpc; +import org.apache.eventmesh.runtime.rpc.AdminBiStreamServiceGrpc.AdminBiStreamServiceStub; +import org.apache.eventmesh.runtime.rpc.Payload; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import io.grpc.stub.StreamObserver; + +import com.google.protobuf.Any; +import com.google.protobuf.StringValue; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class RuntimeInstance { + + private String adminServerAddr = "localhost"; + + private int adminServerPort = 50051; + + private ManagedChannel channel; + + private AdminBiStreamServiceStub adminStub; + + StreamObserver responseObserver; + + StreamObserver requestObserver; + + private MetaStorage metaStorage; + + private Runtime runtime; + + private RuntimeFactory runtimeFactory; + + private RuntimeInstanceConfig runtimeInstanceConfig; + + public RuntimeInstance(RuntimeInstanceConfig runtimeInstanceConfig) { + this.runtimeInstanceConfig = runtimeInstanceConfig; + this.metaStorage = MetaStorage.getInstance(runtimeInstanceConfig.getRegistryPluginType()); + } + + public void init () { + metaStorage.init(); + + } + + public void start() { + metaStorage.start(); + + // TODO:从registry发现admin server地址列表 + + // 创建gRPC通道 + channel = ManagedChannelBuilder.forAddress(adminServerAddr, adminServerPort) + .usePlaintext() + .build(); + + adminStub = AdminBiStreamServiceGrpc.newStub(channel); + + responseObserver = new StreamObserver() { + @Override + public void onNext(Payload response) { + log.info("runtime receive message: {} ", response); + } + + @Override + public void onError(Throwable t) { + log.error("runtime receive error message: {}", t.getMessage()); + } + + @Override + public void onCompleted() { + log.info("runtime finished receive message and completed"); + } + }; + + requestObserver = adminStub.invokeBiStream(responseObserver); + StringValue stringValue = StringValue.newBuilder().setValue("test").build(); + Any test = Any.pack(stringValue); + // 发送请求 + for (int i = 0; i < 10; i++) { + Payload request = Payload.newBuilder() + .setBody(test) + .build(); + requestObserver.onNext(request); + } + + } + + public void shutdown(){ + requestObserver.onCompleted(); + channel.shutdown(); + } + +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/boot/RuntimeInstanceStarter.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/boot/RuntimeInstanceStarter.java new file mode 100644 index 0000000000..bea493b757 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/boot/RuntimeInstanceStarter.java @@ -0,0 +1,54 @@ +package org.apache.eventmesh.runtime.boot; + +import org.apache.eventmesh.common.config.ConfigService; +import org.apache.eventmesh.runtime.RuntimeInstanceConfig; +import org.apache.eventmesh.runtime.rpc.AdminBiStreamServiceGrpc; +import org.apache.eventmesh.runtime.rpc.AdminBiStreamServiceGrpc.AdminBiStreamServiceStub; +import org.apache.eventmesh.runtime.rpc.Payload; +import org.apache.eventmesh.runtime.util.BannerUtil; + +import java.io.File; + +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import io.grpc.stub.StreamObserver; + +import com.google.protobuf.Any; +import com.google.protobuf.StringValue; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class RuntimeInstanceStarter { + + public static void main(String[] args) { + // TODO:加载配置,从环境变量中拿到JobID,并去Admin获取Job配置 + // TODO:启动grpc server,连接META获取Admin地址,上报心跳 + // TODO:添加shutDownHook + + try { + RuntimeInstanceConfig runtimeInstanceConfig = ConfigService.getInstance().buildConfigInstance(RuntimeInstanceConfig.class); + RuntimeInstance runtimeInstance = new RuntimeInstance(runtimeInstanceConfig); + BannerUtil.generateBanner(); + runtimeInstance.init(); + runtimeInstance.start(); + + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + log.info("runtime shutting down hook begin."); + long start = System.currentTimeMillis(); + runtimeInstance.shutdown(); + long end = System.currentTimeMillis(); + + log.info("runtime shutdown cost {}ms", end - start); + } catch (Exception e) { + log.error("exception when shutdown.", e); + } + })); + } catch (Throwable e) { + log.error("runtime start fail.", e); + System.exit(-1); + } + + } +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/connector/ConnectorRuntime.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/connector/ConnectorRuntime.java new file mode 100644 index 0000000000..20b3d03787 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/connector/ConnectorRuntime.java @@ -0,0 +1,115 @@ +package org.apache.eventmesh.runtime.connector; + +import org.apache.eventmesh.common.ThreadPoolFactory; +import org.apache.eventmesh.openconnect.api.ConnectorCreateService; +import org.apache.eventmesh.openconnect.api.config.Config; +import org.apache.eventmesh.openconnect.api.config.SinkConfig; +import org.apache.eventmesh.openconnect.api.config.SourceConfig; +import org.apache.eventmesh.openconnect.api.connector.Connector; +import org.apache.eventmesh.openconnect.api.connector.ConnectorContext; +import org.apache.eventmesh.openconnect.api.connector.SinkConnectorContext; +import org.apache.eventmesh.openconnect.api.connector.SourceConnectorContext; +import org.apache.eventmesh.openconnect.api.factory.ConnectorPluginFactory; +import org.apache.eventmesh.openconnect.api.sink.Sink; +import org.apache.eventmesh.openconnect.api.source.Source; +import org.apache.eventmesh.openconnect.offsetmgmt.api.data.ConnectRecord; +import org.apache.eventmesh.openconnect.util.ConfigUtil; +import org.apache.eventmesh.runtime.Runtime; +import org.apache.eventmesh.runtime.RuntimeInstanceConfig; + +import java.util.List; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class ConnectorRuntime implements Runtime { + + private RuntimeInstanceConfig runtimeInstanceConfig; + + private ConnectorRuntimeConfig connectorRuntimeConfig; + + private Source sourceConnector; + + private Sink sinkConnector; + + private final ExecutorService sourceService = + ThreadPoolFactory.createSingleExecutor("eventMesh-sourceService"); + + private final ExecutorService startService = + ThreadPoolFactory.createSingleExecutor("eventMesh-sourceWorker-startService"); + + private BlockingQueue queue; + + private volatile boolean isRunning = false; + + + public ConnectorRuntime(RuntimeInstanceConfig runtimeInstanceConfig) { + this.runtimeInstanceConfig = runtimeInstanceConfig; + this.queue = new LinkedBlockingQueue<>(1000); + } + + @Override + public void init() throws Exception { + ConnectorCreateService sourceConnectorCreateService = ConnectorPluginFactory.createConnector( + connectorRuntimeConfig.getSourceConnectorType()); + sourceConnector = (Source)sourceConnectorCreateService.create(); + + SourceConfig sourceConfig = (SourceConfig) ConfigUtil.parse(connectorRuntimeConfig.getSourceConnectorConfig(), sourceConnector.configClass()); + SourceConnectorContext sourceConnectorContext = new SourceConnectorContext(); + sourceConnectorContext.setSourceConfig(sourceConfig); +// sourceConnectorContext.setOffsetStorageReader(offsetStorageReader); + + sourceConnector.init(sourceConnectorContext); + + ConnectorCreateService sinkConnectorCreateService = ConnectorPluginFactory.createConnector(connectorRuntimeConfig.getSinkConnectorType()); + sinkConnector = (Sink)sinkConnectorCreateService.create(); + + SinkConfig sinkConfig = (SinkConfig) ConfigUtil.parse(connectorRuntimeConfig.getSinkConnectorConfig(), sinkConnector.configClass()); + SinkConnectorContext sinkConnectorContext = new SinkConnectorContext(); + sinkConnectorContext.setSinkConfig(sinkConfig); + sinkConnector.init(sinkConnectorContext); + } + + @Override + public void start() throws Exception { + +// sourceConnector.start(); +// sourceConnector.poll(); +// start offsetMgmtService +// offsetManagementService.start(); + isRunning = true; +// pollService.execute(this::startPollAndSend); + + sourceService.execute( + () -> { + try { + startSourceConnector(); + } catch (Exception e) { + log.error("source connector [{}] start fail", sourceConnector.name(), e); +// this.stop(); + } + }); + + + } + + @Override + public void stop() throws Exception { + + } + + private void startSourceConnector() throws Exception { + sourceConnector.start(); + while (isRunning) { + List connectorRecordList = sourceConnector.poll(); + if (connectorRecordList != null && !connectorRecordList.isEmpty()) { + for (ConnectRecord record : connectorRecordList) { + queue.put(record); + } + } + } + } +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/connector/ConnectorRuntimeConfig.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/connector/ConnectorRuntimeConfig.java new file mode 100644 index 0000000000..426645faed --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/connector/ConnectorRuntimeConfig.java @@ -0,0 +1,26 @@ +package org.apache.eventmesh.runtime.connector; + +import java.util.Map; + +import lombok.Data; + +@Data +public class ConnectorRuntimeConfig { + + private String connectorName; + + private String connectorRuntimeInstanceId; + + private String sourceConnectorType; + + private String sourceConnectorDesc; + + private Map sourceConnectorConfig; + + private String sinkConnectorType; + + private String sinkConnectorDesc; + + private Map sinkConnectorConfig; + +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/connector/ConnectorRuntimeFactory.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/connector/ConnectorRuntimeFactory.java new file mode 100644 index 0000000000..fb179952bd --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/connector/ConnectorRuntimeFactory.java @@ -0,0 +1,23 @@ +package org.apache.eventmesh.runtime.connector; + +import org.apache.eventmesh.runtime.Runtime; +import org.apache.eventmesh.runtime.RuntimeFactory; +import org.apache.eventmesh.runtime.RuntimeInstanceConfig; + +public class ConnectorRuntimeFactory implements RuntimeFactory { + + @Override + public void init() throws Exception { + + } + + @Override + public Runtime createRuntime(RuntimeInstanceConfig runtimeInstanceConfig) { + return new ConnectorRuntime(runtimeInstanceConfig); + } + + @Override + public void close() throws Exception { + + } +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/function/FunctionRuntime.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/function/FunctionRuntime.java new file mode 100644 index 0000000000..152580807c --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/function/FunctionRuntime.java @@ -0,0 +1,21 @@ +package org.apache.eventmesh.runtime.function; + +import org.apache.eventmesh.runtime.Runtime; + +public class FunctionRuntime implements Runtime { + + @Override + public void init() throws Exception { + + } + + @Override + public void start() throws Exception { + + } + + @Override + public void stop() throws Exception { + + } +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/function/FunctionRuntimeConfig.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/function/FunctionRuntimeConfig.java new file mode 100644 index 0000000000..9777446579 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/function/FunctionRuntimeConfig.java @@ -0,0 +1,4 @@ +package org.apache.eventmesh.runtime.function; + +public class FunctionRuntimeConfig { +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/function/FunctionRuntimeFactory.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/function/FunctionRuntimeFactory.java new file mode 100644 index 0000000000..c3b9916f76 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/function/FunctionRuntimeFactory.java @@ -0,0 +1,24 @@ +package org.apache.eventmesh.runtime.function; + +import org.apache.eventmesh.runtime.Runtime; +import org.apache.eventmesh.runtime.RuntimeFactory; +import org.apache.eventmesh.runtime.RuntimeInstanceConfig; + +public class FunctionRuntimeFactory implements RuntimeFactory { + + @Override + public void init() throws Exception { + + } + + @Override + public Runtime createRuntime(RuntimeInstanceConfig runtimeInstanceConfig) { + return null; + } + + @Override + public void close() throws Exception { + + } + +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/manager/ConnectorManager.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/manager/ConnectorManager.java new file mode 100644 index 0000000000..d711388689 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/manager/ConnectorManager.java @@ -0,0 +1,4 @@ +package org.apache.eventmesh.runtime.manager; + +public class ConnectorManager { +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/manager/FunctionManager.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/manager/FunctionManager.java new file mode 100644 index 0000000000..d3b7c1540c --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/manager/FunctionManager.java @@ -0,0 +1,4 @@ +package org.apache.eventmesh.runtime.manager; + +public class FunctionManager { +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/manager/MeshManager.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/manager/MeshManager.java new file mode 100644 index 0000000000..7102fe2204 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/manager/MeshManager.java @@ -0,0 +1,4 @@ +package org.apache.eventmesh.runtime.manager; + +public class MeshManager { +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/mesh/MeshRuntime.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/mesh/MeshRuntime.java new file mode 100644 index 0000000000..941fb74fc2 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/mesh/MeshRuntime.java @@ -0,0 +1,21 @@ +package org.apache.eventmesh.runtime.mesh; + +import org.apache.eventmesh.runtime.Runtime; + +public class MeshRuntime implements Runtime { + + @Override + public void init() throws Exception { + + } + + @Override + public void start() throws Exception { + + } + + @Override + public void stop() throws Exception { + + } +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/mesh/MeshRuntimeConfig.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/mesh/MeshRuntimeConfig.java new file mode 100644 index 0000000000..dd6a6be017 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/mesh/MeshRuntimeConfig.java @@ -0,0 +1,4 @@ +package org.apache.eventmesh.runtime.mesh; + +public class MeshRuntimeConfig { +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/mesh/MeshRuntimeFactory.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/mesh/MeshRuntimeFactory.java new file mode 100644 index 0000000000..5217051bbd --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/mesh/MeshRuntimeFactory.java @@ -0,0 +1,24 @@ +package org.apache.eventmesh.runtime.mesh; + +import org.apache.eventmesh.runtime.Runtime; +import org.apache.eventmesh.runtime.RuntimeFactory; +import org.apache.eventmesh.runtime.RuntimeInstanceConfig; + +public class MeshRuntimeFactory implements RuntimeFactory { + + @Override + public void init() throws Exception { + + } + + @Override + public Runtime createRuntime(RuntimeInstanceConfig runtimeInstanceConfig) { + return null; + } + + @Override + public void close() throws Exception { + + } + +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/meta/MetaStorage.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/meta/MetaStorage.java new file mode 100644 index 0000000000..41da6994f7 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/meta/MetaStorage.java @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.eventmesh.runtime.meta; + +import org.apache.eventmesh.api.exception.MetaException; +import org.apache.eventmesh.api.meta.MetaService; +import org.apache.eventmesh.api.meta.MetaServiceListener; +import org.apache.eventmesh.api.meta.bo.EventMeshAppSubTopicInfo; +import org.apache.eventmesh.api.meta.bo.EventMeshServicePubTopicInfo; +import org.apache.eventmesh.api.meta.dto.EventMeshDataInfo; +import org.apache.eventmesh.api.meta.dto.EventMeshRegisterInfo; +import org.apache.eventmesh.api.meta.dto.EventMeshUnRegisterInfo; +import org.apache.eventmesh.spi.EventMeshExtensionFactory; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class MetaStorage { + + private static final Map META_CACHE = new HashMap<>(16); + + private MetaService metaService; + + private final AtomicBoolean inited = new AtomicBoolean(false); + + private final AtomicBoolean started = new AtomicBoolean(false); + + private final AtomicBoolean shutdown = new AtomicBoolean(false); + + private MetaStorage() { + + } + + public static MetaStorage getInstance(String metaPluginType) { + return META_CACHE.computeIfAbsent(metaPluginType, MetaStorage::metaStorageBuilder); + } + + private static MetaStorage metaStorageBuilder(String metaPluginType) { + MetaService metaServiceExt = EventMeshExtensionFactory.getExtension(MetaService.class, metaPluginType); + if (metaServiceExt == null) { + String errorMsg = "can't load the metaService plugin, please check."; + log.error(errorMsg); + throw new RuntimeException(errorMsg); + } + MetaStorage metaStorage = new MetaStorage(); + metaStorage.metaService = metaServiceExt; + + return metaStorage; + } + + public void init() throws MetaException { + if (!inited.compareAndSet(false, true)) { + return; + } + metaService.init(); + } + + public void start() throws MetaException { + if (!started.compareAndSet(false, true)) { + return; + } + metaService.start(); + } + + public void shutdown() throws MetaException { + inited.compareAndSet(true, false); + started.compareAndSet(true, false); + if (!shutdown.compareAndSet(false, true)) { + return; + } + synchronized (this) { + metaService.shutdown(); + } + } + + public List findEventMeshInfoByCluster(String clusterName) throws MetaException { + return metaService.findEventMeshInfoByCluster(clusterName); + } + + public List findAllEventMeshInfo() throws MetaException { + return metaService.findAllEventMeshInfo(); + } + + public Map> findEventMeshClientDistributionData(String clusterName, String group, String purpose) + throws MetaException { + return metaService.findEventMeshClientDistributionData(clusterName, group, purpose); + } + + public void registerMetadata(Map metadata) { + metaService.registerMetadata(metadata); + } + + public void updateMetaData(Map metadata) { + metaService.updateMetaData(metadata); + } + + public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws MetaException { + return metaService.register(eventMeshRegisterInfo); + } + + public boolean unRegister(EventMeshUnRegisterInfo eventMeshUnRegisterInfo) throws MetaException { + return metaService.unRegister(eventMeshUnRegisterInfo); + } + + public List findEventMeshServicePubTopicInfos() throws Exception { + return metaService.findEventMeshServicePubTopicInfos(); + } + + public EventMeshAppSubTopicInfo findEventMeshAppSubTopicInfo(String group) throws Exception { + return metaService.findEventMeshAppSubTopicInfoByGroup(group); + } + + public Map getMetaData(String key, boolean fuzzyEnabled) { + return metaService.getMetaData(key, fuzzyEnabled); + } + + public void getMetaDataWithListener(MetaServiceListener metaServiceListener, String key) throws Exception { + metaService.getMetaDataWithListener(metaServiceListener, key); + } + + public AtomicBoolean getInited() { + return inited; + } + + public AtomicBoolean getStarted() { + return started; + } +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/AdminBiStreamServiceGrpc.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/AdminBiStreamServiceGrpc.java new file mode 100644 index 0000000000..2d591b0486 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/AdminBiStreamServiceGrpc.java @@ -0,0 +1,260 @@ +package org.apache.eventmesh.runtime.rpc; + +import static io.grpc.MethodDescriptor.generateFullMethodName; + +/** + */ +@javax.annotation.Generated( + value = "by gRPC proto compiler (version 1.40.0)", + comments = "Source: event_mesh_admin_service.proto") +@io.grpc.stub.annotations.GrpcGenerated +public final class AdminBiStreamServiceGrpc { + + private AdminBiStreamServiceGrpc() {} + + public static final String SERVICE_NAME = "AdminBiStreamService"; + + // Static method descriptors that strictly reflect the proto. + private static volatile io.grpc.MethodDescriptor getInvokeBiStreamMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "invokeBiStream", + requestType = Payload.class, + responseType = Payload.class, + methodType = io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) + public static io.grpc.MethodDescriptor getInvokeBiStreamMethod() { + io.grpc.MethodDescriptor getInvokeBiStreamMethod; + if ((getInvokeBiStreamMethod = AdminBiStreamServiceGrpc.getInvokeBiStreamMethod) == null) { + synchronized (AdminBiStreamServiceGrpc.class) { + if ((getInvokeBiStreamMethod = AdminBiStreamServiceGrpc.getInvokeBiStreamMethod) == null) { + AdminBiStreamServiceGrpc.getInvokeBiStreamMethod = getInvokeBiStreamMethod = + io.grpc.MethodDescriptor.newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "invokeBiStream")) + .setSampledToLocalTracing(true) + .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + Payload.getDefaultInstance())) + .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + Payload.getDefaultInstance())) + .setSchemaDescriptor(new AdminBiStreamServiceMethodDescriptorSupplier("invokeBiStream")) + .build(); + } + } + } + return getInvokeBiStreamMethod; + } + + /** + * Creates a new async stub that supports all call types for the service + */ + public static AdminBiStreamServiceStub newStub(io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @Override + public AdminBiStreamServiceStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new AdminBiStreamServiceStub(channel, callOptions); + } + }; + return AdminBiStreamServiceStub.newStub(factory, channel); + } + + /** + * Creates a new blocking-style stub that supports unary and streaming output calls on the service + */ + public static AdminBiStreamServiceBlockingStub newBlockingStub( + io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @Override + public AdminBiStreamServiceBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new AdminBiStreamServiceBlockingStub(channel, callOptions); + } + }; + return AdminBiStreamServiceBlockingStub.newStub(factory, channel); + } + + /** + * Creates a new ListenableFuture-style stub that supports unary calls on the service + */ + public static AdminBiStreamServiceFutureStub newFutureStub( + io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @Override + public AdminBiStreamServiceFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new AdminBiStreamServiceFutureStub(channel, callOptions); + } + }; + return AdminBiStreamServiceFutureStub.newStub(factory, channel); + } + + /** + */ + public static abstract class AdminBiStreamServiceImplBase implements io.grpc.BindableService { + + /** + */ + public io.grpc.stub.StreamObserver invokeBiStream( + io.grpc.stub.StreamObserver responseObserver) { + return io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall(getInvokeBiStreamMethod(), responseObserver); + } + + @Override public final io.grpc.ServerServiceDefinition bindService() { + return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) + .addMethod( + getInvokeBiStreamMethod(), + io.grpc.stub.ServerCalls.asyncBidiStreamingCall( + new MethodHandlers< + Payload, + Payload>( + this, METHODID_INVOKE_BI_STREAM))) + .build(); + } + } + + /** + */ + public static final class AdminBiStreamServiceStub extends io.grpc.stub.AbstractAsyncStub { + private AdminBiStreamServiceStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @Override + protected AdminBiStreamServiceStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new AdminBiStreamServiceStub(channel, callOptions); + } + + /** + */ + public io.grpc.stub.StreamObserver invokeBiStream( + io.grpc.stub.StreamObserver responseObserver) { + return io.grpc.stub.ClientCalls.asyncBidiStreamingCall( + getChannel().newCall(getInvokeBiStreamMethod(), getCallOptions()), responseObserver); + } + } + + /** + */ + public static final class AdminBiStreamServiceBlockingStub extends io.grpc.stub.AbstractBlockingStub { + private AdminBiStreamServiceBlockingStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @Override + protected AdminBiStreamServiceBlockingStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new AdminBiStreamServiceBlockingStub(channel, callOptions); + } + } + + /** + */ + public static final class AdminBiStreamServiceFutureStub extends io.grpc.stub.AbstractFutureStub { + private AdminBiStreamServiceFutureStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @Override + protected AdminBiStreamServiceFutureStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new AdminBiStreamServiceFutureStub(channel, callOptions); + } + } + + private static final int METHODID_INVOKE_BI_STREAM = 0; + + private static final class MethodHandlers implements + io.grpc.stub.ServerCalls.UnaryMethod, + io.grpc.stub.ServerCalls.ServerStreamingMethod, + io.grpc.stub.ServerCalls.ClientStreamingMethod, + io.grpc.stub.ServerCalls.BidiStreamingMethod { + private final AdminBiStreamServiceImplBase serviceImpl; + private final int methodId; + + MethodHandlers(AdminBiStreamServiceImplBase serviceImpl, int methodId) { + this.serviceImpl = serviceImpl; + this.methodId = methodId; + } + + @Override + @SuppressWarnings("unchecked") + public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + default: + throw new AssertionError(); + } + } + + @Override + @SuppressWarnings("unchecked") + public io.grpc.stub.StreamObserver invoke( + io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + case METHODID_INVOKE_BI_STREAM: + return (io.grpc.stub.StreamObserver) serviceImpl.invokeBiStream( + (io.grpc.stub.StreamObserver) responseObserver); + default: + throw new AssertionError(); + } + } + } + + private static abstract class AdminBiStreamServiceBaseDescriptorSupplier + implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier { + AdminBiStreamServiceBaseDescriptorSupplier() {} + + @Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return EventMeshAdminService.getDescriptor(); + } + + @Override + public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() { + return getFileDescriptor().findServiceByName("AdminBiStreamService"); + } + } + + private static final class AdminBiStreamServiceFileDescriptorSupplier + extends AdminBiStreamServiceBaseDescriptorSupplier { + AdminBiStreamServiceFileDescriptorSupplier() {} + } + + private static final class AdminBiStreamServiceMethodDescriptorSupplier + extends AdminBiStreamServiceBaseDescriptorSupplier + implements io.grpc.protobuf.ProtoMethodDescriptorSupplier { + private final String methodName; + + AdminBiStreamServiceMethodDescriptorSupplier(String methodName) { + this.methodName = methodName; + } + + @Override + public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() { + return getServiceDescriptor().findMethodByName(methodName); + } + } + + private static volatile io.grpc.ServiceDescriptor serviceDescriptor; + + public static io.grpc.ServiceDescriptor getServiceDescriptor() { + io.grpc.ServiceDescriptor result = serviceDescriptor; + if (result == null) { + synchronized (AdminBiStreamServiceGrpc.class) { + result = serviceDescriptor; + if (result == null) { + serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) + .setSchemaDescriptor(new AdminBiStreamServiceFileDescriptorSupplier()) + .addMethod(getInvokeBiStreamMethod()) + .build(); + } + } + } + return result; + } +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/AdminServiceGrpc.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/AdminServiceGrpc.java new file mode 100644 index 0000000000..d6c17139f3 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/AdminServiceGrpc.java @@ -0,0 +1,276 @@ +package org.apache.eventmesh.runtime.rpc; + +import static io.grpc.MethodDescriptor.generateFullMethodName; + +/** + */ +@javax.annotation.Generated( + value = "by gRPC proto compiler (version 1.40.0)", + comments = "Source: event_mesh_admin_service.proto") +@io.grpc.stub.annotations.GrpcGenerated +public final class AdminServiceGrpc { + + private AdminServiceGrpc() {} + + public static final String SERVICE_NAME = "AdminService"; + + // Static method descriptors that strictly reflect the proto. + private static volatile io.grpc.MethodDescriptor getInvokeMethod; + + @io.grpc.stub.annotations.RpcMethod( + fullMethodName = SERVICE_NAME + '/' + "invoke", + requestType = Payload.class, + responseType = Payload.class, + methodType = io.grpc.MethodDescriptor.MethodType.UNARY) + public static io.grpc.MethodDescriptor getInvokeMethod() { + io.grpc.MethodDescriptor getInvokeMethod; + if ((getInvokeMethod = AdminServiceGrpc.getInvokeMethod) == null) { + synchronized (AdminServiceGrpc.class) { + if ((getInvokeMethod = AdminServiceGrpc.getInvokeMethod) == null) { + AdminServiceGrpc.getInvokeMethod = getInvokeMethod = + io.grpc.MethodDescriptor.newBuilder() + .setType(io.grpc.MethodDescriptor.MethodType.UNARY) + .setFullMethodName(generateFullMethodName(SERVICE_NAME, "invoke")) + .setSampledToLocalTracing(true) + .setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + Payload.getDefaultInstance())) + .setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller( + Payload.getDefaultInstance())) + .setSchemaDescriptor(new AdminServiceMethodDescriptorSupplier("invoke")) + .build(); + } + } + } + return getInvokeMethod; + } + + /** + * Creates a new async stub that supports all call types for the service + */ + public static AdminServiceStub newStub(io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @Override + public AdminServiceStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new AdminServiceStub(channel, callOptions); + } + }; + return AdminServiceStub.newStub(factory, channel); + } + + /** + * Creates a new blocking-style stub that supports unary and streaming output calls on the service + */ + public static AdminServiceBlockingStub newBlockingStub( + io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @Override + public AdminServiceBlockingStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new AdminServiceBlockingStub(channel, callOptions); + } + }; + return AdminServiceBlockingStub.newStub(factory, channel); + } + + /** + * Creates a new ListenableFuture-style stub that supports unary calls on the service + */ + public static AdminServiceFutureStub newFutureStub( + io.grpc.Channel channel) { + io.grpc.stub.AbstractStub.StubFactory factory = + new io.grpc.stub.AbstractStub.StubFactory() { + @Override + public AdminServiceFutureStub newStub(io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new AdminServiceFutureStub(channel, callOptions); + } + }; + return AdminServiceFutureStub.newStub(factory, channel); + } + + /** + */ + public static abstract class AdminServiceImplBase implements io.grpc.BindableService { + + /** + */ + public void invoke(Payload request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getInvokeMethod(), responseObserver); + } + + @Override public final io.grpc.ServerServiceDefinition bindService() { + return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor()) + .addMethod( + getInvokeMethod(), + io.grpc.stub.ServerCalls.asyncUnaryCall( + new MethodHandlers< + Payload, + Payload>( + this, METHODID_INVOKE))) + .build(); + } + } + + /** + */ + public static final class AdminServiceStub extends io.grpc.stub.AbstractAsyncStub { + private AdminServiceStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @Override + protected AdminServiceStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new AdminServiceStub(channel, callOptions); + } + + /** + */ + public void invoke(Payload request, + io.grpc.stub.StreamObserver responseObserver) { + io.grpc.stub.ClientCalls.asyncUnaryCall( + getChannel().newCall(getInvokeMethod(), getCallOptions()), request, responseObserver); + } + } + + /** + */ + public static final class AdminServiceBlockingStub extends io.grpc.stub.AbstractBlockingStub { + private AdminServiceBlockingStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @Override + protected AdminServiceBlockingStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new AdminServiceBlockingStub(channel, callOptions); + } + + /** + */ + public Payload invoke(Payload request) { + return io.grpc.stub.ClientCalls.blockingUnaryCall( + getChannel(), getInvokeMethod(), getCallOptions(), request); + } + } + + /** + */ + public static final class AdminServiceFutureStub extends io.grpc.stub.AbstractFutureStub { + private AdminServiceFutureStub( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + super(channel, callOptions); + } + + @Override + protected AdminServiceFutureStub build( + io.grpc.Channel channel, io.grpc.CallOptions callOptions) { + return new AdminServiceFutureStub(channel, callOptions); + } + + /** + */ + public com.google.common.util.concurrent.ListenableFuture invoke( + Payload request) { + return io.grpc.stub.ClientCalls.futureUnaryCall( + getChannel().newCall(getInvokeMethod(), getCallOptions()), request); + } + } + + private static final int METHODID_INVOKE = 0; + + private static final class MethodHandlers implements + io.grpc.stub.ServerCalls.UnaryMethod, + io.grpc.stub.ServerCalls.ServerStreamingMethod, + io.grpc.stub.ServerCalls.ClientStreamingMethod, + io.grpc.stub.ServerCalls.BidiStreamingMethod { + private final AdminServiceImplBase serviceImpl; + private final int methodId; + + MethodHandlers(AdminServiceImplBase serviceImpl, int methodId) { + this.serviceImpl = serviceImpl; + this.methodId = methodId; + } + + @Override + @SuppressWarnings("unchecked") + public void invoke(Req request, io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + case METHODID_INVOKE: + serviceImpl.invoke((Payload) request, + (io.grpc.stub.StreamObserver) responseObserver); + break; + default: + throw new AssertionError(); + } + } + + @Override + @SuppressWarnings("unchecked") + public io.grpc.stub.StreamObserver invoke( + io.grpc.stub.StreamObserver responseObserver) { + switch (methodId) { + default: + throw new AssertionError(); + } + } + } + + private static abstract class AdminServiceBaseDescriptorSupplier + implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier { + AdminServiceBaseDescriptorSupplier() {} + + @Override + public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() { + return EventMeshAdminService.getDescriptor(); + } + + @Override + public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() { + return getFileDescriptor().findServiceByName("AdminService"); + } + } + + private static final class AdminServiceFileDescriptorSupplier + extends AdminServiceBaseDescriptorSupplier { + AdminServiceFileDescriptorSupplier() {} + } + + private static final class AdminServiceMethodDescriptorSupplier + extends AdminServiceBaseDescriptorSupplier + implements io.grpc.protobuf.ProtoMethodDescriptorSupplier { + private final String methodName; + + AdminServiceMethodDescriptorSupplier(String methodName) { + this.methodName = methodName; + } + + @Override + public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() { + return getServiceDescriptor().findMethodByName(methodName); + } + } + + private static volatile io.grpc.ServiceDescriptor serviceDescriptor; + + public static io.grpc.ServiceDescriptor getServiceDescriptor() { + io.grpc.ServiceDescriptor result = serviceDescriptor; + if (result == null) { + synchronized (AdminServiceGrpc.class) { + result = serviceDescriptor; + if (result == null) { + serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME) + .setSchemaDescriptor(new AdminServiceFileDescriptorSupplier()) + .addMethod(getInvokeMethod()) + .build(); + } + } + } + return result; + } +} diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/EventMeshAdminService.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/EventMeshAdminService.java similarity index 94% rename from eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/EventMeshAdminService.java rename to eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/EventMeshAdminService.java index 3c2e81217c..f188113ce4 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/EventMeshAdminService.java +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/EventMeshAdminService.java @@ -1,4 +1,4 @@ -package org.apache.eventmesh.common.grpc;// Generated by the protocol buffer compiler. DO NOT EDIT! +package org.apache.eventmesh.runtime.rpc;// Generated by the protocol buffer compiler. DO NOT EDIT! // source: event_mesh_admin_service.proto public final class EventMeshAdminService { @@ -43,9 +43,9 @@ public static void registerAllExtensions( "alue\030\002 \001(\t:\0028\001\"J\n\007Payload\022\033\n\010metadata\030\002 " + "\001(\0132\t.Metadata\022\"\n\004body\030\003 \001(\0132\024.google.pr" + "otobuf.Any2B\n\024AdminBiStreamService\022*\n\016in" + - "vokeBiStream\022\010.Payload\032\010.Payload\"\000(\0010\00124" + - "\n\014AdminService\022$\n\014invokeStream\022\010.Payload" + - "\032\010.Payload\"\000B\002P\001b\006proto3" + "vokeBiStream\022\010.Payload\032\010.Payload\"\000(\0010\0012." + + "\n\014AdminService\022\036\n\006invoke\022\010.Payload\032\010.Pay" + + "load\"\000B\002P\001b\006proto3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/Metadata.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/Metadata.java similarity index 99% rename from eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/Metadata.java rename to eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/Metadata.java index 6361ee252b..37773945f4 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/Metadata.java +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/Metadata.java @@ -1,4 +1,4 @@ -package org.apache.eventmesh.common.grpc;// Generated by the protocol buffer compiler. DO NOT EDIT! +package org.apache.eventmesh.runtime.rpc;// Generated by the protocol buffer compiler. DO NOT EDIT! // source: event_mesh_admin_service.proto /** @@ -7,7 +7,7 @@ public final class Metadata extends com.google.protobuf.GeneratedMessageV3 implements // @@protoc_insertion_point(message_implements:Metadata) - MetadataOrBuilder { + MetadataOrBuilder { private static final long serialVersionUID = 0L; // Use Metadata.newBuilder() to construct. private Metadata(com.google.protobuf.GeneratedMessageV3.Builder builder) { @@ -412,7 +412,7 @@ protected Builder newBuilderForType( public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder implements // @@protoc_insertion_point(builder_implements:Metadata) - MetadataOrBuilder { + MetadataOrBuilder { public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() { return EventMeshAdminService.internal_static_Metadata_descriptor; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/MetadataOrBuilder.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/MetadataOrBuilder.java similarity index 94% rename from eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/MetadataOrBuilder.java rename to eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/MetadataOrBuilder.java index efed0c02a6..30a3fd5ec4 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/MetadataOrBuilder.java +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/MetadataOrBuilder.java @@ -1,4 +1,4 @@ -package org.apache.eventmesh.common.grpc;// Generated by the protocol buffer compiler. DO NOT EDIT! +package org.apache.eventmesh.runtime.rpc;// Generated by the protocol buffer compiler. DO NOT EDIT! // source: event_mesh_admin_service.proto public interface MetadataOrBuilder extends diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/Payload.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/Payload.java similarity index 99% rename from eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/Payload.java rename to eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/Payload.java index a23fcc9781..30d7af8f02 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/Payload.java +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/Payload.java @@ -1,4 +1,4 @@ -package org.apache.eventmesh.common.grpc;// Generated by the protocol buffer compiler. DO NOT EDIT! +package org.apache.eventmesh.runtime.rpc;// Generated by the protocol buffer compiler. DO NOT EDIT! // source: event_mesh_admin_service.proto /** diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/PayloadOrBuilder.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/PayloadOrBuilder.java similarity index 93% rename from eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/PayloadOrBuilder.java rename to eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/PayloadOrBuilder.java index 77c9680200..7c4c530640 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/grpc/PayloadOrBuilder.java +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/rpc/PayloadOrBuilder.java @@ -1,4 +1,4 @@ -package org.apache.eventmesh.common.grpc;// Generated by the protocol buffer compiler. DO NOT EDIT! +package org.apache.eventmesh.runtime.rpc;// Generated by the protocol buffer compiler. DO NOT EDIT! // source: event_mesh_admin_service.proto public interface PayloadOrBuilder extends diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/util/BannerUtil.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/util/BannerUtil.java new file mode 100644 index 0000000000..2569494189 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/util/BannerUtil.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.eventmesh.runtime.util; + +import lombok.extern.slf4j.Slf4j; + +/** + * EventMesh banner util + */ +@Slf4j +public class BannerUtil { + + private static final String LOGO = + " EMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEME EMEMEMEME EMEMEMEME " + System.lineSeparator() + + " EMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEME EMEMEMEMEMEMEMEME EMEMEMEMEMEMEMEMEM " + System.lineSeparator() + + " EMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEM EMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEME " + System.lineSeparator() + + "EMEMEMEMEMEM EMEMEMEMEM EMEMEMEMEMEMEMEME EMEMEMEMEME" + System.lineSeparator() + + "EMEMEMEME EMEMEMEMEM EMEMEMEMEMEME EMEMEMEME" + System.lineSeparator() + + "EMEMEME EMEMEMEMEM EMEME EMEMEMEM" + System.lineSeparator() + + "EMEMEME EMEMEMEMEM EMEMEME" + System.lineSeparator() + + "EMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEM EMEMEMEMEM EMEMEME" + System.lineSeparator() + + "EMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEM EMEMEMEMEM EMEMEME" + System.lineSeparator() + + "EMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEM EMEMEMEMEM EMEMEME" + System.lineSeparator() + + "EMEMEME EMEMEMEMEM EMEMEME" + System.lineSeparator() + + "EMEMEME EMEMEMEMEM EMEMEME" + System.lineSeparator() + + "EMEMEMEME EMEMEMEMEM EMEMEMEME" + System.lineSeparator() + + "EMEMEMEMEMEM EMEMEMEMEM EMEMEMEMEMEM" + System.lineSeparator() + + " EMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEME EMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEM " + System.lineSeparator() + + " EMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEM EMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEME " + System.lineSeparator() + + " MEMEMEMEMEMEMEMEMEMEMEMEMEMEME EMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEMEME"; + + private static final String LOGONAME = + " ____ _ __ __ _ " + System.lineSeparator() + + " / ____|_ _____ _ __ | |_| \\/ | ___ ___| |__ " + System.lineSeparator() + + " | __|\\ \\ / / _ | '_ \\| __| |\\/| |/ _ |/ __| '_ \\ " + System.lineSeparator() + + " | |___ \\ V / __| | | | |_| | | | __|\\__ \\ | | |" + System.lineSeparator() + + " \\ ____| \\_/ \\___|_| |_|\\__|_| |_|\\___||___/_| |_|"; + + public static void generateBanner() { + String banner = + System.lineSeparator() + + System.lineSeparator() + + LOGO + + System.lineSeparator() + + LOGONAME + + System.lineSeparator(); + if (log.isInfoEnabled()) { + log.info(banner); + } else { + System.out.print(banner); + } + } + +} diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/util/RuntimeUtils.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/util/RuntimeUtils.java new file mode 100644 index 0000000000..33843e6570 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/util/RuntimeUtils.java @@ -0,0 +1,4 @@ +package org.apache.eventmesh.runtime.util; + +public class RuntimeUtils { +} diff --git a/eventmesh-runtime-v2/src/main/proto/event_mesh_admin_service.proto b/eventmesh-runtime-v2/src/main/proto/event_mesh_admin_service.proto new file mode 100644 index 0000000000..84b0ddf2ce --- /dev/null +++ b/eventmesh-runtime-v2/src/main/proto/event_mesh_admin_service.proto @@ -0,0 +1,25 @@ +syntax="proto3"; + +import "google/protobuf/any.proto"; + +option java_multiple_files=true; + +message Metadata { + string type = 3; + map headers = 7; +} + + +message Payload { + Metadata metadata = 2; + google.protobuf.Any body = 3; +} + +service AdminBiStreamService { + rpc invokeBiStream(stream Payload) returns (stream Payload){} +} + +service AdminService { + rpc invoke(Payload) returns (Payload){} +} + diff --git a/eventmesh-runtime-v2/src/main/resources/runtime.yaml b/eventmesh-runtime-v2/src/main/resources/runtime.yaml new file mode 100644 index 0000000000..28a3981e67 --- /dev/null +++ b/eventmesh-runtime-v2/src/main/resources/runtime.yaml @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +registryServerAddr: 127.0.0.1:8085 +registryPluginType: nacos +storagePluginType: memory diff --git a/eventmesh-runtime/build.gradle b/eventmesh-runtime/build.gradle index eef0bb2f92..95924faad4 100644 --- a/eventmesh-runtime/build.gradle +++ b/eventmesh-runtime/build.gradle @@ -27,7 +27,7 @@ dependencies { implementation "org.apache.httpcomponents:httpclient" implementation 'io.netty:netty-all' - implementation "com.alibaba:fastjson" + implementation "com.alibaba.fastjson2:fastjson2" implementation 'com.github.seancfoley:ipaddress' diff --git a/eventmesh-runtime/conf/eventmesh.properties b/eventmesh-runtime/conf/eventmesh.properties index cabe3f9bc5..91a422fa4c 100644 --- a/eventmesh-runtime/conf/eventmesh.properties +++ b/eventmesh-runtime/conf/eventmesh.properties @@ -21,11 +21,14 @@ eventMesh.server.provide.protocols=HTTP,TCP,GRPC eventMesh.server.cluster=COMMON eventMesh.server.name=EVENTMESH-runtime eventMesh.sysid=0000 +eventMesh.server.tcp.port=10000 eventMesh.server.http.port=10105 eventMesh.server.grpc.port=10205 +# HTTP Admin Server +eventMesh.server.admin.http.port=10106 + ########################## EventMesh TCP Configuration ########################## eventMesh.server.tcp.enabled=true -eventMesh.server.tcp.port=10000 eventMesh.server.tcp.readerIdleSeconds=120 eventMesh.server.tcp.writerIdleSeconds=120 eventMesh.server.tcp.allIdleSeconds=120 @@ -57,14 +60,6 @@ eventMesh.server.retry.sync.pushRetryDelayInMills=500 eventMesh.server.retry.pushRetryQueueSize=10000 eventMesh.server.retry.plugin.type=default -# runtime admin -eventMesh.server.admin.http.port=10106 -# metaStorage -eventMesh.server.metaStorage.metaStorageIntervalInMills=10000 -eventMesh.server.metaStorage.fetchMetaStorageAddrIntervalInMills=20000 -# auto-ack -#eventMesh.server.defibus.client.comsumeTimeoutInMin=5 - # sleep interval between closing client of different group in server graceful shutdown eventMesh.server.gracefulShutdown.sleepIntervalInMills=1000 eventMesh.server.rebalanceRedirect.sleepIntervalInMills=200 @@ -73,9 +68,7 @@ eventMesh.server.rebalanceRedirect.sleepIntervalInMills=200 eventMesh.server.blacklist.ipv4=0.0.0.0/8,127.0.0.0/8,169.254.0.0/16,255.255.255.255/32 eventMesh.server.blacklist.ipv6=::/128,::1/128,ff00::/8 -# connector plugin -eventMesh.connector.plugin.type=standalone - +########################## EventMesh Plugin Configuration ########################## # storage plugin eventMesh.storage.plugin.type=standalone @@ -91,6 +84,7 @@ eventMesh.metaStorage.plugin.type=nacos eventMesh.metaStorage.plugin.server-addr=127.0.0.1:8848 eventMesh.metaStorage.plugin.username=nacos eventMesh.metaStorage.plugin.password=nacos + # metaStorage plugin: nacos #eventMesh.metaStorage.nacos.endpoint= #eventMesh.metaStorage.nacos.accessKey= @@ -137,9 +131,9 @@ eventMesh.trace.plugin=zipkin eventMesh.webHook.admin.start=true # Webhook event configuration storage mode. Currently, only file and nacos are supported eventMesh.webHook.operationMode=file -# The file storage path of the file storage mode. If #{eventmeshhome} is written, it is in the eventmesh root directory +# The file storage path of the file storage mode. If #{eventMeshHome} is written, it is in the EventMesh root directory eventMesh.webHook.fileMode.filePath= #{eventMeshHome}/webhook -# Nacos storage mode, and the configuration naming rule is eventmesh webHook. nacosMode. {nacos native configuration key} please see the specific configuration [nacos github api](https://github.com/alibaba/nacos/blob/develop/api/src/main/java/com/alibaba/nacos/api/SystemPropertyKeyConst.java) +# Nacos storage mode, and the configuration naming rule is EventMesh webHook. nacosMode. {nacos native configuration key} please see the specific configuration [nacos github api](https://github.com/alibaba/nacos/blob/develop/api/src/main/java/com/alibaba/nacos/api/SystemPropertyKeyConst.java) ## Address of Nacos eventMesh.webHook.nacosMode.serverAddr=127.0.0.1:8848 # Webhook CloudEvent sending mode. This property is the same as the eventMesh.storage.plugin.type configuration. diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AbstractHttpHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AbstractHttpHandler.java index 30c81446c5..0b0a6afedf 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AbstractHttpHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AbstractHttpHandler.java @@ -18,99 +18,76 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.enums.HttpMethod; +import org.apache.eventmesh.runtime.admin.response.Result; import org.apache.eventmesh.runtime.constants.EventMeshConstants; -import org.apache.eventmesh.runtime.util.HttpRequestUtil; import org.apache.eventmesh.runtime.util.HttpResponseUtils; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.HttpVersion; -import io.netty.util.AsciiString; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONWriter; import lombok.Data; @Data public abstract class AbstractHttpHandler implements HttpHandler { - protected void write(ChannelHandlerContext ctx, byte[] result) { - ctx.writeAndFlush(HttpResponseUtils.getHttpResponse(result, ctx, HttpHeaderValues.TEXT_HTML)).addListener(ChannelFutureListener.CLOSE); - } - - protected void write(ChannelHandlerContext ctx, HttpResponse response) { - ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); + protected void writeText(ChannelHandlerContext ctx, String text) { + HttpHeaders responseHeaders = HttpResponseUtils.buildDefaultHttpHeaders(HttpHeaderValues.TEXT_HTML); + write(ctx, HttpResponseUtils.buildHttpResponse(text, ctx, responseHeaders, HttpResponseStatus.OK)); } - protected void write(ChannelHandlerContext ctx, byte[] result, AsciiString headerValue, HttpResponseStatus httpResponseStatus) { - ctx.writeAndFlush(HttpResponseUtils.getHttpResponse(result, ctx, headerValue, httpResponseStatus)).addListener(ChannelFutureListener.CLOSE); + /** + * Return given JSON String with given {@link HttpResponseStatus}. + */ + protected void writeJson(ChannelHandlerContext ctx, String json, HttpResponseStatus status) { + HttpHeaders responseHeaders = HttpResponseUtils.buildDefaultHttpHeaders(HttpHeaderValues.APPLICATION_JSON); + write(ctx, HttpResponseUtils.buildHttpResponse(json, ctx, responseHeaders, status)); } - protected void write401(ChannelHandlerContext ctx) { - DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.UNAUTHORIZED); - ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); + /** + * Return given JSON String with status {@link HttpResponseStatus#OK}. + */ + protected void writeJson(ChannelHandlerContext ctx, String json) { + writeJson(ctx, json, HttpResponseStatus.OK); } - protected void writeSuccess(ChannelHandlerContext ctx) { - HttpHeaders responseHeaders = new DefaultHttpHeaders(); - responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); - DefaultFullHttpResponse response = - new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.EMPTY_BUFFER, responseHeaders, responseHeaders); - ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); + /** + * Serialize given data into the JSON String of {@link Result} and return with status {@link HttpResponseStatus#OK}. + */ + protected void writeSuccess(ChannelHandlerContext ctx, Object data) { + Result result = Result.success(data); + String json = JSON.toJSONString(result, JSONWriter.Feature.WriteNulls); + writeJson(ctx, json); } - protected void writeSuccess(ChannelHandlerContext ctx, DefaultHttpHeaders responseHeaders) { - DefaultFullHttpResponse response = - new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.EMPTY_BUFFER, responseHeaders, responseHeaders); - ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); + /** + * Wrap given message to {@link Result} and return with status {@link HttpResponseStatus#BAD_REQUEST}. + */ + protected void writeBadRequest(ChannelHandlerContext ctx, String message) { + Result result = new Result<>(message); + String json = JSON.toJSONString(result, JSONWriter.Feature.WriteNulls); + writeJson(ctx, json, HttpResponseStatus.BAD_REQUEST); } - protected void preflight(ChannelHandlerContext ctx) { - HttpHeaders responseHeaders = new DefaultHttpHeaders(); - responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); - responseHeaders.add(EventMeshConstants.HANDLER_METHODS, "*"); - responseHeaders.add(EventMeshConstants.HANDLER_HEADERS, "*"); - responseHeaders.add(EventMeshConstants.HANDLER_AGE, EventMeshConstants.MAX_AGE); - DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.EMPTY_BUFFER, - responseHeaders, responseHeaders); - write(ctx, response); + protected void writeUnauthorized(ChannelHandlerContext ctx, String message) { + Result result = new Result<>(message); + String json = JSON.toJSONString(result, JSONWriter.Feature.WriteNulls); + writeJson(ctx, json, HttpResponseStatus.UNAUTHORIZED); } /** - * Converts a query string to a map of key-value pairs. - *

- * This method takes a query string and parses it to create a map of key-value pairs, where each key and value are extracted from the query string - * separated by '='. - *

- * If the query string is null, an empty map is returned. - * - * @param query the query string to convert to a map - * @return a map containing the key-value pairs from the query string + * Use {@link HttpResponseUtils#buildHttpResponse} to build {@link HttpResponse} param. */ - protected Map queryToMap(String query) { - if (query == null) { - return new HashMap<>(); - } - Map result = new HashMap<>(); - for (String param : query.split("&")) { - String[] entry = param.split("="); - if (entry.length > 1) { - result.put(entry[0], entry[1]); - } else { - result.put(entry[0], ""); - } - } - return result; + protected void write(ChannelHandlerContext ctx, HttpResponse response) { + ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); } @Override @@ -125,25 +102,47 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex case POST: post(httpRequest, ctx); break; + case PUT: + put(httpRequest, ctx); + break; case DELETE: delete(httpRequest, ctx); break; - default: // do nothing + default: + // do nothing break; } } - protected void post(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + protected void preflight(ChannelHandlerContext ctx) { + HttpHeaders responseHeaders = new DefaultHttpHeaders(); + responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); + responseHeaders.add(EventMeshConstants.HANDLER_METHODS, "*"); + responseHeaders.add(EventMeshConstants.HANDLER_HEADERS, "*"); + responseHeaders.add(EventMeshConstants.HANDLER_AGE, EventMeshConstants.MAX_AGE); + write(ctx, HttpResponseUtils.buildHttpResponse("", ctx, responseHeaders, HttpResponseStatus.OK)); } - protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + // Override this method in subclass } - protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + /** + * Add new resource. + */ + protected void post(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + // Override this method in subclass + } + + /** + * Update resource, should be idempotent. + */ + protected void put(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + // Override this method in subclass } - protected Map parseHttpRequestBody(final HttpRequest httpRequest) throws IOException { - return HttpRequestUtil.parseHttpRequestBody(httpRequest, null, null); + protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + // Override this method in subclass } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AdminHandlerManager.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AdminHandlerManager.java index 744990e740..4f81584b9d 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AdminHandlerManager.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AdminHandlerManager.java @@ -17,11 +17,35 @@ package org.apache.eventmesh.runtime.admin.handler; +import org.apache.eventmesh.runtime.admin.handler.v1.ConfigurationHandlerV1; +import org.apache.eventmesh.runtime.admin.handler.v1.DeleteWebHookConfigHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.EventHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.GrpcClientHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.HTTPClientHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.InsertWebHookConfigHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.MetaHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.MetricsHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.QueryRecommendEventMeshHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.QueryWebHookConfigByIdHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.QueryWebHookConfigByManufacturerHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.RedirectClientByIpPortHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.RedirectClientByPathHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.RedirectClientBySubSystemHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.RejectAllClientHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.RejectClientByIpPortHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.RejectClientBySubSystemHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.ShowClientBySystemHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.ShowClientHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.ShowListenClientByTopicHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.TCPClientHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.TopicHandler; +import org.apache.eventmesh.runtime.admin.handler.v1.UpdateWebHookConfigHandler; +import org.apache.eventmesh.runtime.admin.handler.v2.ConfigurationHandler; import org.apache.eventmesh.runtime.boot.EventMeshGrpcServer; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; import org.apache.eventmesh.runtime.boot.EventMeshServer; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.meta.MetaStorage; import org.apache.eventmesh.webhook.admin.AdminWebHookConfigOperationManager; import org.apache.eventmesh.webhook.api.WebHookConfigOperation; @@ -55,6 +79,7 @@ public AdminHandlerManager(EventMeshServer eventMeshServer) { } public void registerHttpHandler() { + // v1 endpoints initHandler(new ShowClientHandler(eventMeshTCPServer)); initHandler(new ShowClientBySystemHandler(eventMeshTCPServer)); initHandler(new RejectAllClientHandler(eventMeshTCPServer)); @@ -68,7 +93,7 @@ public void registerHttpHandler() { initHandler(new TCPClientHandler(eventMeshTCPServer)); initHandler(new HTTPClientHandler(eventMeshHTTPServer)); initHandler(new GrpcClientHandler(eventMeshGrpcServer)); - initHandler(new ConfigurationHandler( + initHandler(new ConfigurationHandlerV1( eventMeshTCPServer.getEventMeshTCPConfiguration(), eventMeshHTTPServer.getEventMeshHttpConfiguration(), eventMeshGrpcServer.getEventMeshGrpcConfiguration())); @@ -84,11 +109,17 @@ public void registerHttpHandler() { initHandler(new QueryWebHookConfigByIdHandler(webHookConfigOperation)); initHandler(new QueryWebHookConfigByManufacturerHandler(webHookConfigOperation)); } + + // v2 endpoints + initHandler(new ConfigurationHandler( + eventMeshTCPServer.getEventMeshTCPConfiguration(), + eventMeshHTTPServer.getEventMeshHttpConfiguration(), + eventMeshGrpcServer.getEventMeshGrpcConfiguration())); } private void initHandler(HttpHandler httpHandler) { - EventHttpHandler eventHttpHandler = httpHandler.getClass().getAnnotation(EventHttpHandler.class); - httpHandlerMap.putIfAbsent(eventHttpHandler.path(), httpHandler); + EventMeshHttpHandler eventMeshHttpHandler = httpHandler.getClass().getAnnotation(EventMeshHttpHandler.class); + httpHandlerMap.putIfAbsent(eventMeshHttpHandler.path(), httpHandler); } public Optional getHttpHandler(String path) { diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ConfigurationHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ConfigurationHandlerV1.java similarity index 76% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ConfigurationHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ConfigurationHandlerV1.java index 8a7d3d7ce8..d9c5c6bb8e 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ConfigurationHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ConfigurationHandlerV1.java @@ -15,26 +15,18 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.runtime.admin.response.GetConfigurationResponse; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; +import org.apache.eventmesh.runtime.admin.response.v1.GetConfigurationResponse; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.configuration.EventMeshGrpcConfiguration; import org.apache.eventmesh.runtime.configuration.EventMeshHTTPConfiguration; import org.apache.eventmesh.runtime.configuration.EventMeshTCPConfiguration; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; -import org.apache.eventmesh.runtime.util.HttpResponseUtils; - -import java.util.Objects; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.DefaultHttpHeaders; -import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; import lombok.extern.slf4j.Slf4j; @@ -43,13 +35,15 @@ *

* This handler is responsible for retrieving the current configuration information of the EventMesh node, including service name, service * environment, and listening ports for various protocols. + *

+ * TODO The path of endpoints under v1 package shall be changed to {@code /v1/configuration} with Next.js EventMesh Dashboard. * * @see AbstractHttpHandler */ @Slf4j -@EventHttpHandler(path = "/configuration") -public class ConfigurationHandler extends AbstractHttpHandler { +@EventMeshHttpHandler(path = "/configuration") +public class ConfigurationHandlerV1 extends AbstractHttpHandler { private final EventMeshTCPConfiguration eventMeshTCPConfiguration; private final EventMeshHTTPConfiguration eventMeshHTTPConfiguration; @@ -62,7 +56,7 @@ public class ConfigurationHandler extends AbstractHttpHandler { * @param eventMeshHTTPConfiguration the HTTP configuration for EventMesh * @param eventMeshGrpcConfiguration the gRPC configuration for EventMesh */ - public ConfigurationHandler( + public ConfigurationHandlerV1( EventMeshTCPConfiguration eventMeshTCPConfiguration, EventMeshHTTPConfiguration eventMeshHTTPConfiguration, EventMeshGrpcConfiguration eventMeshGrpcConfiguration) { @@ -74,9 +68,6 @@ public ConfigurationHandler( @Override protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - HttpHeaders responseHeaders = new DefaultHttpHeaders(); - responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); - responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); GetConfigurationResponse getConfigurationResponse = new GetConfigurationResponse( eventMeshTCPConfiguration.getSysID(), eventMeshTCPConfiguration.getMetaStorageAddr(), @@ -97,9 +88,6 @@ protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex eventMeshGrpcConfiguration.getGrpcServerPort(), eventMeshGrpcConfiguration.isEventMeshServerUseTls()); String result = JsonUtils.toJSONString(getConfigurationResponse); - HttpResponse httpResponse = - HttpResponseUtils.getHttpResponse(Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET), ctx, responseHeaders, - HttpResponseStatus.OK); - write(ctx, httpResponse); + writeJson(ctx, result); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/DeleteWebHookConfigHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/DeleteWebHookConfigHandler.java similarity index 89% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/DeleteWebHookConfigHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/DeleteWebHookConfigHandler.java index feb73094c8..390ed38bc4 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/DeleteWebHookConfigHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/DeleteWebHookConfigHandler.java @@ -15,11 +15,12 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; +import org.apache.eventmesh.runtime.util.HttpRequestUtil; import org.apache.eventmesh.webhook.api.WebHookConfig; import org.apache.eventmesh.webhook.api.WebHookConfigOperation; @@ -54,7 +55,7 @@ @SuppressWarnings("restriction") @Slf4j -@EventHttpHandler(path = "/webhook/deleteWebHookConfig") +@EventMeshHttpHandler(path = "/webhook/deleteWebHookConfig") public class DeleteWebHookConfigHandler extends AbstractHttpHandler { private final WebHookConfigOperation operation; @@ -69,14 +70,13 @@ public DeleteWebHookConfigHandler(WebHookConfigOperation operation) { @Override public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - Map body = parseHttpRequestBody(httpRequest); + Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); // Resolve to WebHookConfig WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); // Delete the existing WebHookConfig Integer code = operation.deleteWebHookConfig(webHookConfig); // operating result String result = 1 == code ? "deleteWebHookConfig Succeed!" : "deleteWebHookConfig Failed!"; - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); - + writeText(ctx, result); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/EventHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/EventHandler.java similarity index 85% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/EventHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/EventHandler.java index 9e4dcadc3f..4e1fe4a03a 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/EventHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/EventHandler.java @@ -15,12 +15,14 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.plugin.MQAdminWrapper; +import org.apache.eventmesh.runtime.util.HttpRequestUtil; import java.net.URI; import java.nio.charset.StandardCharsets; @@ -53,7 +55,7 @@ */ @Slf4j -@EventHttpHandler(path = "/event") +@EventMeshHttpHandler(path = "/event") public class EventHandler extends AbstractHttpHandler { private final MQAdminWrapper admin; @@ -79,11 +81,11 @@ protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); String queryString = URI.create(httpRequest.uri()).getQuery(); - if (queryString == null || "".equals(queryString)) { - write401(ctx); + if (queryString == null || queryString.isEmpty()) { + writeUnauthorized(ctx, ""); return; } - Map queryMap = queryToMap(queryString); + Map queryMap = HttpRequestUtil.queryStringToMap(queryString); String topicName = queryMap.get("topicName"); int offset = Integer.parseInt(queryMap.get("offset")); int length = Integer.parseInt(queryMap.get("length")); @@ -97,18 +99,20 @@ protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex .serialize(event); eventJsonList.add(new String(serializedEvent, StandardCharsets.UTF_8)); } + String result = JsonUtils.toJSONString(eventJsonList); + writeJson(ctx, result); } @Override protected void post(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); - String request = JsonUtils.toJSONString(parseHttpRequestBody(httpRequest)); + String request = JsonUtils.toJSONString(HttpRequestUtil.parseHttpRequestBody(httpRequest)); byte[] rawRequest = request.getBytes(StandardCharsets.UTF_8); CloudEvent event = Objects.requireNonNull(EventFormatProvider .getInstance() .resolveFormat(JsonFormat.CONTENT_TYPE)).deserialize(rawRequest); admin.publish(event); - writeSuccess(ctx); + writeText(ctx, ""); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/GrpcClientHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/GrpcClientHandler.java similarity index 79% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/GrpcClientHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/GrpcClientHandler.java index 3712defd1a..af48aea960 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/GrpcClientHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/GrpcClientHandler.java @@ -15,18 +15,17 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.JsonUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; import org.apache.eventmesh.runtime.admin.request.DeleteGrpcClientRequest; -import org.apache.eventmesh.runtime.admin.response.GetClientResponse; +import org.apache.eventmesh.runtime.admin.response.v1.GetClientResponse; import org.apache.eventmesh.runtime.boot.EventMeshGrpcServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.core.protocol.grpc.consumer.ConsumerManager; import org.apache.eventmesh.runtime.core.protocol.grpc.consumer.consumergroup.ConsumerGroupClient; -import org.apache.eventmesh.runtime.util.HttpResponseUtils; +import org.apache.eventmesh.runtime.util.HttpRequestUtil; import java.util.ArrayList; import java.util.List; @@ -35,11 +34,7 @@ import java.util.Optional; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.DefaultHttpHeaders; -import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; import lombok.extern.slf4j.Slf4j; @@ -53,7 +48,7 @@ */ @Slf4j -@EventHttpHandler(path = "/client/grpc") +@EventMeshHttpHandler(path = "/client/grpc") public class GrpcClientHandler extends AbstractHttpHandler { private final EventMeshGrpcServer eventMeshGrpcServer; @@ -71,7 +66,7 @@ public GrpcClientHandler( @Override protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - Map body = parseHttpRequestBody(httpRequest); + Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); DeleteGrpcClientRequest deleteGrpcClientRequest = JsonUtils.mapToObject(body, DeleteGrpcClientRequest.class); String url = Objects.requireNonNull(deleteGrpcClientRequest).getUrl(); @@ -86,16 +81,11 @@ protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws } } } - DefaultHttpHeaders responseHeaders = new DefaultHttpHeaders(); - responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); - writeSuccess(ctx, responseHeaders); + writeText(ctx, ""); } @Override protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - HttpHeaders responseHeaders = new DefaultHttpHeaders(); - responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); - responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); // Get the list of gRPC clients List getClientResponseList = new ArrayList<>(); @@ -129,10 +119,7 @@ protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex }); // Convert getClientResponseList to JSON and send the response String result = JsonUtils.toJSONString(getClientResponseList); - HttpResponse httpResponse = - HttpResponseUtils.getHttpResponse(Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET), ctx, responseHeaders, - HttpResponseStatus.OK); - write(ctx, httpResponse); + writeJson(ctx, result); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/HTTPClientHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/HTTPClientHandler.java similarity index 81% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/HTTPClientHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/HTTPClientHandler.java index f4e8eb7369..2a72241949 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/HTTPClientHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/HTTPClientHandler.java @@ -15,17 +15,17 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.JsonUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; import org.apache.eventmesh.runtime.admin.request.DeleteHTTPClientRequest; -import org.apache.eventmesh.runtime.admin.response.GetClientResponse; +import org.apache.eventmesh.runtime.admin.response.v1.GetClientResponse; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.http.processor.inf.Client; -import org.apache.eventmesh.runtime.util.HttpResponseUtils; +import org.apache.eventmesh.runtime.util.HttpRequestUtil; import java.util.ArrayList; import java.util.List; @@ -34,11 +34,7 @@ import java.util.Optional; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.DefaultHttpHeaders; -import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; import lombok.extern.slf4j.Slf4j; @@ -52,7 +48,7 @@ */ @Slf4j -@EventHttpHandler(path = "/client/http") +@EventMeshHttpHandler(path = "/client/http") public class HTTPClientHandler extends AbstractHttpHandler { private final EventMeshHTTPServer eventMeshHTTPServer; @@ -69,7 +65,7 @@ public HTTPClientHandler( } protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - Map body = parseHttpRequestBody(httpRequest); + Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); if (!Objects.isNull(body)) { DeleteHTTPClientRequest deleteHTTPClientRequest = JsonUtils.mapToObject(body, DeleteHTTPClientRequest.class); String url = Objects.requireNonNull(deleteHTTPClientRequest).getUrl(); @@ -79,7 +75,7 @@ protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws clientList.removeIf(client -> Objects.equals(client.getUrl(), url)); } // Set the response headers and send a 200 status code empty response - writeSuccess(ctx); + writeText(ctx, ""); } } @@ -92,11 +88,6 @@ protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws * @throws Exception if an I/O error occurs while handling the request */ protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - HttpHeaders responseHeaders = new DefaultHttpHeaders(); - // Set the response headers - responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); - responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); - // Get the list of HTTP clients List getClientResponseList = new ArrayList<>(); @@ -131,10 +122,6 @@ protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex // Convert getClientResponseList to JSON and send the response String result = JsonUtils.toJSONString(getClientResponseList); - HttpResponse httpResponse = - HttpResponseUtils.getHttpResponse(Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET), ctx, responseHeaders, - HttpResponseStatus.OK); - write(ctx, httpResponse); - + writeJson(ctx, result); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/InsertWebHookConfigHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/InsertWebHookConfigHandler.java similarity index 89% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/InsertWebHookConfigHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/InsertWebHookConfigHandler.java index ce01838a7e..140decba92 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/InsertWebHookConfigHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/InsertWebHookConfigHandler.java @@ -15,11 +15,12 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; +import org.apache.eventmesh.runtime.util.HttpRequestUtil; import org.apache.eventmesh.webhook.api.WebHookConfig; import org.apache.eventmesh.webhook.api.WebHookConfigOperation; @@ -55,7 +56,7 @@ @SuppressWarnings("restriction") @Slf4j -@EventHttpHandler(path = "/webhook/insertWebHookConfig") +@EventMeshHttpHandler(path = "/webhook/insertWebHookConfig") public class InsertWebHookConfigHandler extends AbstractHttpHandler { private final WebHookConfigOperation operation; @@ -75,16 +76,14 @@ public InsertWebHookConfigHandler(WebHookConfigOperation operation) { * * @throws Exception if an I/O error occurs while handling the request */ - @Override public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - Map body = parseHttpRequestBody(httpRequest); + Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); // Add the WebHookConfig if no existing duplicate configuration is found Integer code = operation.insertWebHookConfig(webHookConfig); // operating result String result = 1 == code ? "insertWebHookConfig Succeed!" : "insertWebHookConfig Failed!"; - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); - + writeText(ctx, result); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/MetaHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/MetaHandler.java similarity index 70% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/MetaHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/MetaHandler.java index 77e995b7fd..7e10906630 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/MetaHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/MetaHandler.java @@ -15,29 +15,22 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; import org.apache.eventmesh.api.meta.dto.EventMeshDataInfo; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.runtime.admin.response.GetRegistryResponse; -import org.apache.eventmesh.runtime.common.EventHttpHandler; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; +import org.apache.eventmesh.runtime.admin.response.v1.GetRegistryResponse; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.meta.MetaStorage; -import org.apache.eventmesh.runtime.util.HttpResponseUtils; import java.io.IOException; import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import java.util.Objects; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.DefaultHttpHeaders; -import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; import lombok.extern.slf4j.Slf4j; @@ -51,7 +44,7 @@ */ @Slf4j -@EventHttpHandler(path = "/meta") +@EventMeshHttpHandler(path = "/meta") public class MetaHandler extends AbstractHttpHandler { private final MetaStorage eventMeshMetaStorage; @@ -66,9 +59,6 @@ public MetaHandler(MetaStorage eventMeshMetaStorage) { @Override protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws IOException { - HttpHeaders responseHeaders = new DefaultHttpHeaders(); - responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); - responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); try { List getRegistryResponseList = new ArrayList<>(); List eventMeshDataInfos = eventMeshMetaStorage.findAllEventMeshInfo(); @@ -83,19 +73,11 @@ protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws IO } getRegistryResponseList.sort(Comparator.comparing(GetRegistryResponse::getEventMeshClusterName)); String result = JsonUtils.toJSONString(getRegistryResponseList); - HttpResponse httpResponse = - HttpResponseUtils.getHttpResponse(Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET), ctx, responseHeaders, - HttpResponseStatus.OK); - write(ctx, httpResponse); + writeJson(ctx, result); } catch (NullPointerException e) { // registry not initialized, return empty list String result = JsonUtils.toJSONString(new ArrayList<>()); - HttpResponse httpResponse = - HttpResponseUtils.getHttpResponse(Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET), ctx, responseHeaders, - HttpResponseStatus.OK); - write(ctx, httpResponse); + writeJson(ctx, result); } - } - } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/MetricsHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/MetricsHandler.java old mode 100755 new mode 100644 similarity index 80% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/MetricsHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/MetricsHandler.java index cf2e46ecc6..2a63f8f581 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/MetricsHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/MetricsHandler.java @@ -15,28 +15,21 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.metrics.api.model.HttpSummaryMetrics; import org.apache.eventmesh.metrics.api.model.TcpSummaryMetrics; -import org.apache.eventmesh.runtime.admin.response.GetMetricsResponse; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; +import org.apache.eventmesh.runtime.admin.response.v1.GetMetricsResponse; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; -import org.apache.eventmesh.runtime.util.HttpResponseUtils; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import java.io.IOException; -import java.util.Objects; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.DefaultHttpHeaders; -import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; import lombok.extern.slf4j.Slf4j; @@ -49,7 +42,7 @@ */ @Slf4j -@EventHttpHandler(path = "/metrics") +@EventMeshHttpHandler(path = "/metrics") public class MetricsHandler extends AbstractHttpHandler { private final HttpSummaryMetrics httpSummaryMetrics; @@ -70,9 +63,6 @@ public MetricsHandler(EventMeshHTTPServer eventMeshHTTPServer, @Override protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws IOException { - HttpHeaders responseHeaders = new DefaultHttpHeaders(); - responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); - responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); GetMetricsResponse getMetricsResponse = new GetMetricsResponse( httpSummaryMetrics.maxHTTPTPS(), httpSummaryMetrics.avgHTTPTPS(), @@ -116,9 +106,6 @@ protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws IO tcpSummaryMetrics.getAllConnections(), tcpSummaryMetrics.getSubTopicNum()); String result = JsonUtils.toJSONString(getMetricsResponse); - HttpResponse httpResponse = - HttpResponseUtils.getHttpResponse(Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET), ctx, responseHeaders, - HttpResponseStatus.OK); - write(ctx, httpResponse); + writeJson(ctx, result); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryRecommendEventMeshHandler.java similarity index 91% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryRecommendEventMeshHandler.java index 1688d387db..f9aabc84b1 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryRecommendEventMeshHandler.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.NetUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend.EventMeshRecommendImpl; import org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend.EventMeshRecommendStrategy; @@ -50,7 +50,7 @@ * @see AbstractHttpHandler */ @Slf4j -@EventHttpHandler(path = "/eventMesh/recommend") +@EventMeshHttpHandler(path = "/eventMesh/recommend") public class QueryRecommendEventMeshHandler extends AbstractHttpHandler { private final EventMeshTCPServer eventMeshTCPServer; @@ -79,7 +79,7 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex // Check the validity of the parameters if (StringUtils.isBlank(group) || StringUtils.isBlank(purpose)) { result = "params illegal!"; - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, result); return; } @@ -88,6 +88,6 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex String recommendEventMeshResult = eventMeshRecommendStrategy.calculateRecommendEventMesh(group, purpose); result = (recommendEventMeshResult == null) ? "null" : recommendEventMeshResult; log.info("recommend eventmesh:{},group:{},purpose:{}", result, group, purpose); - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, result); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByIdHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryWebHookConfigByIdHandler.java similarity index 78% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByIdHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryWebHookConfigByIdHandler.java index 58a2438bea..97e2c29e2a 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByIdHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryWebHookConfigByIdHandler.java @@ -15,13 +15,12 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.runtime.common.EventHttpHandler; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; -import org.apache.eventmesh.runtime.util.HttpResponseUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; +import org.apache.eventmesh.runtime.util.HttpRequestUtil; import org.apache.eventmesh.webhook.api.WebHookConfig; import org.apache.eventmesh.webhook.api.WebHookConfigOperation; @@ -29,11 +28,7 @@ import java.util.Objects; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.DefaultHttpHeaders; -import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; import lombok.extern.slf4j.Slf4j; @@ -68,7 +63,7 @@ @SuppressWarnings("restriction") @Slf4j -@EventHttpHandler(path = "/webhook/queryWebHookConfigById") +@EventMeshHttpHandler(path = "/webhook/queryWebHookConfigById") public class QueryWebHookConfigByIdHandler extends AbstractHttpHandler { private final WebHookConfigOperation operation; @@ -85,20 +80,14 @@ public QueryWebHookConfigByIdHandler(WebHookConfigOperation operation) { @Override public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - HttpHeaders responseHeaders = new DefaultHttpHeaders(); - responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); - responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); // Resolve to WebHookConfig - Map body = parseHttpRequestBody(httpRequest); + Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); if (!Objects.isNull(body)) { WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); // Retrieve the WebHookConfig by callback path WebHookConfig result = operation.queryWebHookConfigById(webHookConfig); // operating result String json = JsonUtils.toJSONString(result); - HttpResponse httpResponse = - HttpResponseUtils.getHttpResponse(Objects.requireNonNull(json).getBytes(Constants.DEFAULT_CHARSET), ctx, responseHeaders, - HttpResponseStatus.OK); - write(ctx, httpResponse); + writeJson(ctx, json); } throw new Exception(); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByManufacturerHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryWebHookConfigByManufacturerHandler.java similarity index 78% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByManufacturerHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryWebHookConfigByManufacturerHandler.java index 9b484f6a1f..063cd6fd05 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByManufacturerHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/QueryWebHookConfigByManufacturerHandler.java @@ -15,13 +15,12 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.runtime.common.EventHttpHandler; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; -import org.apache.eventmesh.runtime.util.HttpResponseUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; +import org.apache.eventmesh.runtime.util.HttpRequestUtil; import org.apache.eventmesh.webhook.api.WebHookConfig; import org.apache.eventmesh.webhook.api.WebHookConfigOperation; @@ -30,11 +29,7 @@ import java.util.Objects; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.DefaultHttpHeaders; -import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; import lombok.extern.slf4j.Slf4j; @@ -63,7 +58,7 @@ @SuppressWarnings("restriction") @Slf4j -@EventHttpHandler(path = "/webhook/queryWebHookConfigByManufacturer") +@EventMeshHttpHandler(path = "/webhook/queryWebHookConfigByManufacturer") public class QueryWebHookConfigByManufacturerHandler extends AbstractHttpHandler { private final transient WebHookConfigOperation operation; @@ -82,11 +77,8 @@ public QueryWebHookConfigByManufacturerHandler(WebHookConfigOperation operation) @Override public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - HttpHeaders responseHeaders = new DefaultHttpHeaders(); - responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); - responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); // Resolve to WebHookConfig - Map body = parseHttpRequestBody(httpRequest); + Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); Integer pageNum = Integer.valueOf(body.get("pageNum").toString()); @@ -95,9 +87,6 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex // Retrieve the WebHookConfig list by manufacturer name List listWebHookConfig = operation.queryWebHookConfigByManufacturer(webHookConfig, pageNum, pageSize); // operating result String result = JsonUtils.toJSONString(listWebHookConfig); - HttpResponse httpResponse = - HttpResponseUtils.getHttpResponse(Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET), ctx, responseHeaders, - HttpResponseStatus.OK); - write(ctx, httpResponse); + writeJson(ctx, result); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RedirectClientByIpPortHandler.java similarity index 88% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RedirectClientByIpPortHandler.java index d2805112a4..33922456f1 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RedirectClientByIpPortHandler.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.NetUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; @@ -57,7 +57,7 @@ */ @Slf4j -@EventHttpHandler(path = "/clientManage/redirectClientByIpPort") +@EventMeshHttpHandler(path = "/clientManage/redirectClientByIpPort") public class RedirectClientByIpPortHandler extends AbstractHttpHandler { private final EventMeshTCPServer eventMeshTCPServer; @@ -88,7 +88,7 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex || StringUtils.isBlank(destEventMeshIp) || StringUtils.isBlank(destEventMeshPort) || !StringUtils.isNumeric(destEventMeshPort)) { result = "params illegal!"; - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, result); return; } log.info("redirectClientByIpPort in admin,ip:{},port:{},destIp:{},destPort:{}====================", ip, @@ -114,20 +114,17 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex } } catch (Exception e) { log.error("clientManage|redirectClientByIpPort|fail|ip={}|port={}|destEventMeshIp" - + - "={}|destEventMeshPort={}", ip, port, destEventMeshIp, destEventMeshPort, e); + + "={}|destEventMeshPort={}", ip, port, destEventMeshIp, destEventMeshPort, e); result = String.format("redirectClientByIpPort fail! sessionMap size {%d}, {clientIp=%s clientPort=%s " - + - "destEventMeshIp=%s destEventMeshPort=%s}, result {%s}, errorMsg : %s", + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s}, errorMsg : %s", sessionMap.size(), ip, port, destEventMeshIp, destEventMeshPort, redirectResult, e.getMessage()); - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, result); return; } // Serialize the result of redirection into output stream result = String.format("redirectClientByIpPort success! sessionMap size {%d}, {ip=%s port=%s " - + - "destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ", + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ", sessionMap.size(), ip, port, destEventMeshIp, destEventMeshPort, redirectResult); - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, result); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RedirectClientByPathHandler.java similarity index 86% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RedirectClientByPathHandler.java index fc5ad6f2d9..54b089ce54 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RedirectClientByPathHandler.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.NetUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; @@ -56,7 +56,7 @@ */ @Slf4j -@EventHttpHandler(path = "/clientManage/redirectClientByPath") +@EventMeshHttpHandler(path = "/clientManage/redirectClientByPath") public class RedirectClientByPathHandler extends AbstractHttpHandler { private final EventMeshTCPServer eventMeshTCPServer; @@ -83,10 +83,9 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex // Check the validity of the parameters if (StringUtils.isBlank(path) || StringUtils.isBlank(destEventMeshIp) - || StringUtils.isBlank(destEventMeshPort) - || !StringUtils.isNumeric(destEventMeshPort)) { + || StringUtils.isBlank(destEventMeshPort) || !StringUtils.isNumeric(destEventMeshPort)) { result = "params illegal!"; - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, result); return; } log.info("redirectClientByPath in admin,path:{},destIp:{},destPort:{}====================", path, @@ -111,20 +110,16 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex } } catch (Exception e) { log.error("clientManage|redirectClientByPath|fail|path={}|destEventMeshIp" - + - "={}|destEventMeshPort={}", path, destEventMeshIp, destEventMeshPort, e); + + "={}|destEventMeshPort={}", path, destEventMeshIp, destEventMeshPort, e); result = String.format("redirectClientByPath fail! sessionMap size {%d}, {path=%s " - + - "destEventMeshIp=%s destEventMeshPort=%s}, result {%s}, errorMsg : %s", + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s}, errorMsg : %s", sessionMap.size(), path, destEventMeshIp, destEventMeshPort, redirectResult, e.getMessage()); - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, result); return; } result = String.format("redirectClientByPath success! sessionMap size {%d}, {path=%s " - + - "destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ", + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ", sessionMap.size(), path, destEventMeshIp, destEventMeshPort, redirectResult); - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); - + writeText(ctx, result); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RedirectClientBySubSystemHandler.java similarity index 88% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RedirectClientBySubSystemHandler.java index c7b959ece3..0aff5fe8b7 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RedirectClientBySubSystemHandler.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.NetUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; @@ -56,7 +56,7 @@ */ @Slf4j -@EventHttpHandler(path = "/clientManage/redirectClientBySubSystem") +@EventMeshHttpHandler(path = "/clientManage/redirectClientBySubSystem") public class RedirectClientBySubSystemHandler extends AbstractHttpHandler { private final transient EventMeshTCPServer eventMeshTCPServer; @@ -83,7 +83,7 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex if (!StringUtils.isNumeric(subSystem) || StringUtils.isBlank(destEventMeshIp) || StringUtils.isBlank(destEventMeshPort) || !StringUtils.isNumeric(destEventMeshPort)) { - write(ctx, "params illegal!".getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, "params illegal!"); return; } log.info("redirectClientBySubSystem in admin,subsys:{},destIp:{},destPort:{}====================", @@ -111,15 +111,13 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex log.error("clientManage|redirectClientBySubSystem|fail|subSystem={}|destEventMeshIp" + "={}|destEventMeshPort={}", subSystem, destEventMeshIp, destEventMeshPort, e); - write(ctx, String.format("redirectClientBySubSystem fail! sessionMap size {%d}, {subSystem=%s " + writeText(ctx, String.format("redirectClientBySubSystem fail! sessionMap size {%d}, {subSystem=%s " + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s}, errorMsg : %s", - sessionMap.size(), subSystem, destEventMeshIp, destEventMeshPort, redirectResult, e.getMessage()) - .getBytes(Constants.DEFAULT_CHARSET)); + sessionMap.size(), subSystem, destEventMeshIp, destEventMeshPort, redirectResult, e.getMessage())); return; } - write(ctx, String.format("redirectClientBySubSystem success! sessionMap size {%d}, {subSystem=%s " + writeText(ctx, String.format("redirectClientBySubSystem success! sessionMap size {%d}, {subSystem=%s " + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ", - sessionMap.size(), subSystem, destEventMeshIp, destEventMeshPort, redirectResult) - .getBytes(Constants.DEFAULT_CHARSET)); + sessionMap.size(), subSystem, destEventMeshIp, destEventMeshPort, redirectResult)); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RejectAllClientHandler.java similarity index 85% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RejectAllClientHandler.java index 614c30f600..bc139b3938 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RejectAllClientHandler.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.NetUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; @@ -48,7 +48,7 @@ */ @Slf4j -@EventHttpHandler(path = "/clientManage/rejectAllClient") +@EventMeshHttpHandler(path = "/clientManage/rejectAllClient") public class RejectAllClientHandler extends AbstractHttpHandler { private final transient EventMeshTCPServer eventMeshTCPServer; @@ -84,13 +84,11 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex } } catch (Exception e) { log.error("clientManage rejectAllClient fail", e); - write(ctx, String.format("rejectAllClient fail! sessionMap size {%d}, had reject {%s}, errorMsg : %s", - sessionMap.size(), NetUtils.addressToString(successRemoteAddrs), e.getMessage()) - .getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, String.format("rejectAllClient fail! sessionMap size {%d}, had reject {%s}, errorMsg : %s", + sessionMap.size(), NetUtils.addressToString(successRemoteAddrs), e.getMessage())); return; } - write(ctx, String.format("rejectAllClient success! sessionMap size {%d}, had reject {%s}", sessionMap.size(), - NetUtils.addressToString(successRemoteAddrs)) - .getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, String.format("rejectAllClient success! sessionMap size {%d}, had reject {%s}", + sessionMap.size(), NetUtils.addressToString(successRemoteAddrs))); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RejectClientByIpPortHandler.java similarity index 92% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RejectClientByIpPortHandler.java index d9ce5f574e..6d6165785e 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RejectClientByIpPortHandler.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.NetUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; @@ -59,7 +59,7 @@ */ @Slf4j -@EventHttpHandler(path = "/clientManage/rejectClientByIpPort") +@EventMeshHttpHandler(path = "/clientManage/rejectClientByIpPort") public class RejectClientByIpPortHandler extends AbstractHttpHandler { private final EventMeshTCPServer eventMeshTCPServer; @@ -86,14 +86,14 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex // Check the validity of the parameters if (StringUtils.isBlank(ip) || StringUtils.isBlank(port)) { result = "params illegal!"; - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, result); return; } log.info("rejectClientByIpPort in admin,ip:{},port:{}====================", ip, port); // Retrieve the mapping between Sessions and their corresponding client address ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); - final List successRemoteAddrs = new ArrayList(); + final List successRemoteAddrs = new ArrayList<>(); try { if (!sessionMap.isEmpty()) { // Iterate through the sessionMap to find matching sessions where the remote client address matches the given IP and port @@ -113,12 +113,11 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex log.error("clientManage|rejectClientByIpPort|fail|ip={}|port={}", ip, port, e); result = String.format("rejectClientByIpPort fail! {ip=%s port=%s}, had reject {%s}, errorMsg : %s", ip, port, NetUtils.addressToString(successRemoteAddrs), e.getMessage()); - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, result); return; } result = String.format("rejectClientByIpPort success! {ip=%s port=%s}, had reject {%s}", ip, port, NetUtils.addressToString(successRemoteAddrs)); - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); - + writeText(ctx, result); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RejectClientBySubSystemHandler.java similarity index 93% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RejectClientBySubSystemHandler.java index 4ff18caf96..ac8a8814e6 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/RejectClientBySubSystemHandler.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.NetUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; @@ -56,7 +56,7 @@ * @see AbstractHttpHandler */ -@EventHttpHandler(path = "/clientManage/rejectClientBySubSystem") +@EventMeshHttpHandler(path = "/clientManage/rejectClientBySubSystem") @Slf4j public class RejectClientBySubSystemHandler extends AbstractHttpHandler { @@ -94,7 +94,7 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex // Check the validity of the parameters if (StringUtils.isBlank(subSystem)) { result = "params illegal!"; - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, result); return; } @@ -124,15 +124,13 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex + "subSystemId=%s}, errorMsg : %s", sessionMap.size(), printClients(successRemoteAddrs), subSystem, e.getMessage()); - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, result); return; } // Serialize the successfully rejected client addresses into output stream result = String.format("rejectClientBySubSystem success! sessionMap size {%d}, had reject {%s} , {" + "subSystemId=%s}", sessionMap.size(), printClients(successRemoteAddrs), subSystem); - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); - - + writeText(ctx, result); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ShowClientBySystemHandler.java similarity index 90% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ShowClientBySystemHandler.java index 9d2c84bc11..491789ceb3 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ShowClientBySystemHandler.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.common.utils.NetUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; @@ -49,7 +49,7 @@ */ @Slf4j -@EventHttpHandler(path = "/clientManage/showClientBySystem") +@EventMeshHttpHandler(path = "/clientManage/showClientBySystem") public class ShowClientBySystemHandler extends AbstractHttpHandler { private final EventMeshTCPServer eventMeshTCPServer; @@ -84,14 +84,11 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex if (session.getClient().getSubsystem().equals(subSystem)) { UserAgent userAgent = session.getClient(); result.append(String.format("pid=%s | ip=%s | port=%s | path=%s | purpose=%s", - userAgent.getPid(), userAgent.getHost(), userAgent.getPort(), - userAgent.getPath(), userAgent.getPurpose())) + userAgent.getPid(), userAgent.getHost(), userAgent.getPort(), userAgent.getPath(), userAgent.getPurpose())) .append(newLine); } } } - write(ctx, result.toString().getBytes(Constants.DEFAULT_CHARSET)); - + writeText(ctx, result.toString()); } - } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ShowClientHandler.java similarity index 90% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ShowClientHandler.java index 9699a13835..fc288ba7e6 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ShowClientHandler.java @@ -15,11 +15,11 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; @@ -43,7 +43,7 @@ */ @Slf4j -@EventHttpHandler(path = "/clientManage/showClient") +@EventMeshHttpHandler(path = "/clientManage/showClient") public class ShowClientHandler extends AbstractHttpHandler { private final EventMeshTCPServer eventMeshTCPServer; @@ -66,7 +66,7 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); // Store the subsystem and the corresponding client count. - HashMap statMap = new HashMap(); + HashMap statMap = new HashMap<>(); Map sessionMap = clientSessionGroupMapping.getSessionMap(); if (!sessionMap.isEmpty()) { @@ -84,6 +84,6 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex result.append(String.format("System=%s | ClientNum=%d", entry.getKey(), entry.getValue().intValue())).append(newLine); } } - write(ctx, result.toString().getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, result.toString()); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ShowListenClientByTopicHandler.java similarity index 93% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ShowListenClientByTopicHandler.java index 412ae5e5ba..266ffbc06d 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/ShowListenClientByTopicHandler.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.common.utils.NetUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientGroupWrapper; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; @@ -49,7 +49,7 @@ */ @Slf4j -@EventHttpHandler(path = "/clientManage/showListenClientByTopic") +@EventMeshHttpHandler(path = "/clientManage/showListenClientByTopic") public class ShowListenClientByTopicHandler extends AbstractHttpHandler { private final EventMeshTCPServer eventMeshTCPServer; @@ -93,7 +93,6 @@ public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex } } } - write(ctx, result.toString().getBytes(Constants.DEFAULT_CHARSET)); - + writeText(ctx, result.toString()); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TCPClientHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/TCPClientHandler.java similarity index 83% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TCPClientHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/TCPClientHandler.java index a4da5bf94c..429ce426ed 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TCPClientHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/TCPClientHandler.java @@ -15,20 +15,19 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.common.utils.JsonUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; import org.apache.eventmesh.runtime.admin.request.DeleteTCPClientRequest; -import org.apache.eventmesh.runtime.admin.response.GetClientResponse; +import org.apache.eventmesh.runtime.admin.response.v1.GetClientResponse; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.common.EventHttpHandler; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; -import org.apache.eventmesh.runtime.util.HttpResponseUtils; +import org.apache.eventmesh.runtime.util.HttpRequestUtil; import java.net.InetSocketAddress; import java.util.ArrayList; @@ -39,11 +38,7 @@ import java.util.concurrent.ConcurrentHashMap; import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.DefaultHttpHeaders; -import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; import lombok.extern.slf4j.Slf4j; @@ -57,7 +52,7 @@ */ @Slf4j -@EventHttpHandler(path = "/client/tcp") +@EventMeshHttpHandler(path = "/client/tcp") public class TCPClientHandler extends AbstractHttpHandler { private final EventMeshTCPServer eventMeshTCPServer; @@ -76,7 +71,7 @@ public TCPClientHandler( @Override protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { // Parse the request body string into a DeleteTCPClientRequest object - Map body = parseHttpRequestBody(httpRequest); + Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); DeleteTCPClientRequest deleteTCPClientRequest = JsonUtils.mapToObject(body, DeleteTCPClientRequest.class); String host = Objects.requireNonNull(deleteTCPClientRequest).getHost(); @@ -98,16 +93,11 @@ protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws } // Set the response headers and send a 200 status code empty response - writeSuccess(ctx); - + writeText(ctx, ""); } @Override protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - // Set the response headers - HttpHeaders responseHeaders = new DefaultHttpHeaders(); - responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); - responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); // Get the list of connected TCP clients ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); Map sessionMap = clientSessionGroupMapping.getSessionMap(); @@ -140,10 +130,6 @@ protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Ex // Convert getClientResponseList to JSON and send the response String result = JsonUtils.toJSONString(getClientResponseList); - HttpResponse httpResponse = - HttpResponseUtils.getHttpResponse(Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET), ctx, responseHeaders, - HttpResponseStatus.OK); - write(ctx, httpResponse); - + writeJson(ctx, result); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TopicHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/TopicHandler.java similarity index 79% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TopicHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/TopicHandler.java index c30533d535..b536150354 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TopicHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/TopicHandler.java @@ -15,17 +15,17 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; import org.apache.eventmesh.api.admin.TopicProperties; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.JsonUtils; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; import org.apache.eventmesh.runtime.admin.request.CreateTopicRequest; import org.apache.eventmesh.runtime.admin.request.DeleteTopicRequest; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.plugin.MQAdminWrapper; -import org.apache.eventmesh.runtime.util.HttpResponseUtils; +import org.apache.eventmesh.runtime.util.HttpRequestUtil; import java.util.List; import java.util.Map; @@ -35,8 +35,6 @@ import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; import lombok.extern.slf4j.Slf4j; @@ -54,7 +52,7 @@ */ @Slf4j -@EventHttpHandler(path = "/topic") +@EventMeshHttpHandler(path = "/topic") public class TopicHandler extends AbstractHttpHandler { private final MQAdminWrapper admin; @@ -77,21 +75,14 @@ public TopicHandler( @Override protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - HttpHeaders responseHeaders = new DefaultHttpHeaders(); - responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); - responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); List topicList = admin.getTopic(); String result = JsonUtils.toJSONString(topicList); - HttpResponse httpResponse = - HttpResponseUtils.getHttpResponse(Objects.requireNonNull(result).getBytes(Constants.DEFAULT_CHARSET), ctx, responseHeaders, - HttpResponseStatus.OK); - write(ctx, httpResponse); - + writeJson(ctx, result); } @Override protected void post(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - Map body = parseHttpRequestBody(httpRequest); + Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); @@ -99,13 +90,12 @@ protected void post(HttpRequest httpRequest, ChannelHandlerContext ctx) throws E CreateTopicRequest createTopicRequest = JsonUtils.mapToObject(body, CreateTopicRequest.class); String topicName = Objects.requireNonNull(createTopicRequest).getName(); admin.createTopic(topicName); - writeSuccess(ctx); - + writeText(ctx, ""); } @Override protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - Map body = parseHttpRequestBody(httpRequest); + Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); @@ -113,8 +103,6 @@ protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws DeleteTopicRequest deleteTopicRequest = JsonUtils.mapToObject(body, DeleteTopicRequest.class); String topicName = Objects.requireNonNull(deleteTopicRequest).getName(); admin.deleteTopic(topicName); - writeSuccess(ctx); - + writeText(ctx, ""); } - } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/UpdateWebHookConfigHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/UpdateWebHookConfigHandler.java similarity index 89% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/UpdateWebHookConfigHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/UpdateWebHookConfigHandler.java index a842c84e65..ab0c1192d1 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/UpdateWebHookConfigHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v1/UpdateWebHookConfigHandler.java @@ -15,11 +15,12 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.handler; +package org.apache.eventmesh.runtime.admin.handler.v1; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.runtime.common.EventHttpHandler; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; +import org.apache.eventmesh.runtime.util.HttpRequestUtil; import org.apache.eventmesh.webhook.api.WebHookConfig; import org.apache.eventmesh.webhook.api.WebHookConfigOperation; @@ -56,7 +57,7 @@ @SuppressWarnings("restriction") @Slf4j -@EventHttpHandler(path = "/webhook/updateWebHookConfig") +@EventMeshHttpHandler(path = "/webhook/updateWebHookConfig") public class UpdateWebHookConfigHandler extends AbstractHttpHandler { private final WebHookConfigOperation operation; @@ -73,13 +74,13 @@ public UpdateWebHookConfigHandler(WebHookConfigOperation operation) { @Override public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { - Map body = parseHttpRequestBody(httpRequest); + Map body = HttpRequestUtil.parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); // Resolve to WebHookConfig WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); // Update the existing WebHookConfig Integer code = operation.updateWebHookConfig(webHookConfig); // operating result String result = 1 == code ? "updateWebHookConfig Succeed!" : "updateWebHookConfig Failed!"; - write(ctx, result.getBytes(Constants.DEFAULT_CHARSET)); + writeText(ctx, result); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v2/ConfigurationHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v2/ConfigurationHandler.java new file mode 100644 index 0000000000..ce16b95749 --- /dev/null +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/v2/ConfigurationHandler.java @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.eventmesh.runtime.admin.handler.v2; + +import org.apache.eventmesh.common.config.CommonConfiguration; +import org.apache.eventmesh.common.config.Config; +import org.apache.eventmesh.common.config.ConfigField; +import org.apache.eventmesh.runtime.admin.handler.AbstractHttpHandler; +import org.apache.eventmesh.runtime.admin.response.Result; +import org.apache.eventmesh.runtime.admin.response.v2.GetConfigurationResponse; +import org.apache.eventmesh.runtime.common.EventMeshHttpHandler; +import org.apache.eventmesh.runtime.configuration.EventMeshGrpcConfiguration; +import org.apache.eventmesh.runtime.configuration.EventMeshHTTPConfiguration; +import org.apache.eventmesh.runtime.configuration.EventMeshTCPConfiguration; +import org.apache.eventmesh.runtime.util.HttpRequestUtil; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.HttpRequest; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.filter.Filter; +import com.alibaba.fastjson2.filter.NameFilter; +import com.alibaba.fastjson2.filter.ValueFilter; + +import lombok.extern.slf4j.Slf4j; + +import inet.ipaddr.IPAddress; + +/** + * This class handles the {@code /v2/configuration} endpoint, corresponding to the {@code eventmesh-dashboard} path {@code /}. + *

+ * This handler is responsible for retrieving the current configuration information of the EventMesh node, including service name, service + * environment, and listening ports for various protocols. + */ + +@Slf4j +@EventMeshHttpHandler(path = "/v2/configuration") +public class ConfigurationHandler extends AbstractHttpHandler { + + private final EventMeshTCPConfiguration eventMeshTCPConfiguration; + private final EventMeshHTTPConfiguration eventMeshHTTPConfiguration; + private final EventMeshGrpcConfiguration eventMeshGrpcConfiguration; + + /** + * Constructs a new instance with the provided configurations. + * + * @param eventMeshTCPConfiguration the TCP configuration for EventMesh + * @param eventMeshHTTPConfiguration the HTTP configuration for EventMesh + * @param eventMeshGrpcConfiguration the gRPC configuration for EventMesh + */ + public ConfigurationHandler( + EventMeshTCPConfiguration eventMeshTCPConfiguration, + EventMeshHTTPConfiguration eventMeshHTTPConfiguration, + EventMeshGrpcConfiguration eventMeshGrpcConfiguration) { + super(); + this.eventMeshTCPConfiguration = eventMeshTCPConfiguration; + this.eventMeshHTTPConfiguration = eventMeshHTTPConfiguration; + this.eventMeshGrpcConfiguration = eventMeshGrpcConfiguration; + } + + /** + * Parameters: + *

    + *
  • + * {@code format}: String; Optional, DefaultValue: {@code properties}, SelectableValue: {@code bean}. + *

    When {@code properties}, the field names are returned in Properties format; + *

    When {@code bean}, the field names themselves are used as json keys. + *

  • + *
+ */ + @Override + protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) { + String format = HttpRequestUtil.getQueryParam(httpRequest, "format", "properties"); + + Filter[] filters; + if (format.equals("properties")) { + filters = new Filter[] {new ConfigFieldFilter(), new IPAddressToStringFilter()}; + } else if (format.equals("bean")) { + filters = new Filter[] {new IPAddressToStringFilter()}; + } else { + log.warn("Invalid format param: {}", format); + writeBadRequest(ctx, "Invalid format param: " + format); + return; + } + + GetConfigurationResponse getConfigurationResponse = new GetConfigurationResponse( + eventMeshTCPConfiguration, + eventMeshHTTPConfiguration, + eventMeshGrpcConfiguration + ); + String json = JSON.toJSONString(Result.success(getConfigurationResponse), filters); + writeJson(ctx, json); + } + + /** + * For each member of {@link EventMeshTCPConfiguration}, {@link EventMeshHTTPConfiguration}, and {@link EventMeshGrpcConfiguration}, + * the value of the {@link ConfigField} annotation for each field is obtained through reflection, + * and then concatenated with the configuration prefix in the {@link Config} annotation to serve as the JSON key for this field. + *

+ * When the {@code name} is a member that only exists in the superclass, it will be searched for in the {@link CommonConfiguration} class. + *

+ * If a field does not have a {@link ConfigField} annotation or the value of the {@link ConfigField} annotation is empty, + * this field will be added to the JSON with the field name as the key, rather than in properties format. + */ + static class ConfigFieldFilter implements NameFilter { + @Override + public String process(Object object, String name, Object value) { + try { + Field field = findFieldInClassHierarchy(object.getClass(), name); + if (field != null && field.isAnnotationPresent(ConfigField.class)) { + ConfigField configField = field.getAnnotation(ConfigField.class); + String fieldAnnotationValue = configField.field(); + if (!fieldAnnotationValue.isEmpty()) { + Config config = object.getClass().getAnnotation(Config.class); + String prefix = config.prefix(); + return prefix + "." + fieldAnnotationValue; + } + } + } catch (NoSuchFieldException e) { + log.error("Failed to get field {} from object {}", name, object, e); + } + return name; + } + + private Field findFieldInClassHierarchy(Class clazz, String fieldName) throws NoSuchFieldException { + try { + return clazz.getDeclaredField(fieldName); + } catch (NoSuchFieldException e) { + Class superclass = clazz.getSuperclass(); + if (superclass == null) { + throw e; + } else { + return findFieldInClassHierarchy(superclass, fieldName); + } + } + } + } + + /** + * {@link IPAddress} can't be serialized directly by FastJSON, + * so this filter converts {@link IPAddress} objects to their string representation. + */ + static class IPAddressToStringFilter implements ValueFilter { + @Override + public Object apply(Object object, String name, Object value) { + if (name.equals("eventMeshIpv4BlackList") || name.equals("eventMeshIpv6BlackList")) { + if (value instanceof List) { + List ipList = new ArrayList<>(); + for (Object o : (List) value) { + if (o instanceof IPAddress) { + ipList.add(((IPAddress) o).toNormalizedString()); + } + } + return ipList; + } + } + return value; + } + } +} diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/Error.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/Result.java similarity index 65% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/Error.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/Result.java index 4b03a07ba8..f8ba718e94 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/Error.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/Result.java @@ -17,22 +17,35 @@ package org.apache.eventmesh.runtime.admin.response; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * A RESTful response DTO. + */ @Data -public class Error { +@NoArgsConstructor +@AllArgsConstructor +public class Result { - private String message; + private T data; - private String stackTrace; + private String message; - @JsonCreator - public Error(@JsonProperty("message") String message, @JsonProperty("stackTrace") String stackTrace) { - super(); + public Result(String message) { this.message = message; - this.stackTrace = stackTrace; + } + + /** + * The request is valid and the result is wrapped in {@link Result}. + */ + public static Result success() { + return new Result<>("Success"); + } + + public static Result success(T data) { + return new Result<>(data, "Success"); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/GetClientResponse.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetClientResponse.java similarity index 97% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/GetClientResponse.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetClientResponse.java index 8093704c56..42c21a0d5f 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/GetClientResponse.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetClientResponse.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.response; +package org.apache.eventmesh.runtime.admin.response.v1; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/GetConfigurationResponse.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetConfigurationResponse.java similarity index 98% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/GetConfigurationResponse.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetConfigurationResponse.java index b381c2f651..47cceabcac 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/GetConfigurationResponse.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetConfigurationResponse.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.response; +package org.apache.eventmesh.runtime.admin.response.v1; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/GetMetricsResponse.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetMetricsResponse.java old mode 100755 new mode 100644 similarity index 99% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/GetMetricsResponse.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetMetricsResponse.java index 268aedc0f9..df95eabdbb --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/GetMetricsResponse.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetMetricsResponse.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.response; +package org.apache.eventmesh.runtime.admin.response.v1; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/GetRegistryResponse.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetRegistryResponse.java old mode 100755 new mode 100644 similarity index 96% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/GetRegistryResponse.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetRegistryResponse.java index 8416076a33..698b6458d0 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/GetRegistryResponse.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v1/GetRegistryResponse.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.response; +package org.apache.eventmesh.runtime.admin.response.v1; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/utils/HttpExchangeUtils.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v2/GetConfigurationResponse.java similarity index 54% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/utils/HttpExchangeUtils.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v2/GetConfigurationResponse.java index 67479c8c2f..40161cca73 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/utils/HttpExchangeUtils.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/response/v2/GetConfigurationResponse.java @@ -15,27 +15,22 @@ * limitations under the License. */ -package org.apache.eventmesh.runtime.admin.utils; +package org.apache.eventmesh.runtime.admin.response.v2; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; +import org.apache.eventmesh.runtime.configuration.EventMeshGrpcConfiguration; +import org.apache.eventmesh.runtime.configuration.EventMeshHTTPConfiguration; +import org.apache.eventmesh.runtime.configuration.EventMeshTCPConfiguration; -public class HttpExchangeUtils { +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; - public static String streamToString(InputStream stream) throws IOException { - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) { +@Data +@NoArgsConstructor +@AllArgsConstructor +public class GetConfigurationResponse { - StringBuilder buffer = new StringBuilder(); - int b; - - while ((b = bufferedReader.read()) != -1) { - buffer.append((char) b); - } - - return buffer.toString(); - } - } + private EventMeshTCPConfiguration eventMeshTCPConfiguration; + private EventMeshHTTPConfiguration eventMeshHTTPConfiguration; + private EventMeshGrpcConfiguration eventMeshGrpcConfiguration; } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbstractHTTPServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbstractHTTPServer.java index 8dd9525170..5065b73a01 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbstractHTTPServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbstractHTTPServer.java @@ -451,11 +451,11 @@ public void channelReadComplete(final ChannelHandlerContext ctx) throws Exceptio @Override public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) { - if (null != cause) { + if (cause != null) { log.error("", cause); } - if (null != ctx) { + if (ctx != null) { ctx.close(); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshAdminServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshAdminServer.java index f7b16baa51..4abba74a54 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshAdminServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshAdminServer.java @@ -17,9 +17,6 @@ package org.apache.eventmesh.runtime.boot; -import static org.apache.eventmesh.runtime.util.HttpResponseUtils.getHttpResponse; - -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.runtime.admin.handler.AdminHandlerManager; import org.apache.eventmesh.runtime.admin.handler.HttpHandler; import org.apache.eventmesh.runtime.util.HttpResponseUtils; @@ -63,7 +60,7 @@ public EventMeshAdminServer(EventMeshServer eventMeshServer) { @Override public void init() throws Exception { - super.init("eventMesh-admin-http"); + super.init("eventMesh-admin"); adminHandlerManager.registerHttpHandler(); } @@ -92,7 +89,7 @@ public void start() throws Exception { } System.exit(-1); } - }, "EventMesh-http-server"); + }, "EventMesh-admin-server"); thread.setDaemon(true); thread.start(); started.compareAndSet(false, true); @@ -105,13 +102,10 @@ public void parseHttpRequest(ChannelHandlerContext ctx, HttpRequest httpRequest) if (httpHandlerOpt.isPresent()) { try { httpHandlerOpt.get().handle(httpRequest, ctx); - return; } catch (Exception e) { log.error("admin server channelRead error", e); - ctx.writeAndFlush( - getHttpResponse(Objects.requireNonNull(e.getMessage()).getBytes(Constants.DEFAULT_CHARSET), - ctx, HttpHeaderValues.APPLICATION_JSON, - HttpResponseStatus.INTERNAL_SERVER_ERROR)).addListener(ChannelFutureListener.CLOSE); + ctx.writeAndFlush(HttpResponseUtils.buildHttpResponse(Objects.requireNonNull(e.getMessage()), ctx, + HttpHeaderValues.APPLICATION_JSON, HttpResponseStatus.INTERNAL_SERVER_ERROR)).addListener(ChannelFutureListener.CLOSE); } } else { ctx.writeAndFlush(HttpResponseUtils.createNotFound()).addListener(ChannelFutureListener.CLOSE); @@ -120,7 +114,6 @@ public void parseHttpRequest(ChannelHandlerContext ctx, HttpRequest httpRequest) private class AdminServerInitializer extends ChannelInitializer { - @Override protected void initChannel(final SocketChannel channel) { final ChannelPipeline pipeline = channel.pipeline(); @@ -133,11 +126,10 @@ protected void initChannel(final SocketChannel channel) { new SimpleChannelInboundHandler() { @Override - protected void channelRead0(ChannelHandlerContext ctx, HttpRequest msg) throws Exception { + protected void channelRead0(ChannelHandlerContext ctx, HttpRequest msg) { parseHttpRequest(ctx, msg); } }); } } - } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java index 26e727406b..3b33a71b8f 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java @@ -27,7 +27,6 @@ import org.apache.eventmesh.common.utils.ConfigurationContextUtil; import org.apache.eventmesh.runtime.acl.Acl; import org.apache.eventmesh.runtime.common.ServiceState; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.http.producer.ProducerTopicManager; import org.apache.eventmesh.runtime.meta.MetaStorage; import org.apache.eventmesh.runtime.storage.StorageResource; @@ -139,13 +138,10 @@ public void init() throws Exception { adminBootstrap.init(); } - final String eventStore = System.getProperty(EventMeshConstants.EVENT_STORE_PROPERTIES, System.getenv(EventMeshConstants.EVENT_STORE_ENV)); - - log.info("eventStore : {}", eventStore); producerTopicManager = new ProducerTopicManager(this); producerTopicManager.init(); - serviceState = ServiceState.INITED; + serviceState = ServiceState.INITED; log.info(SERVER_STATE_MSG, serviceState); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/HTTPThreadPoolGroup.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/HTTPThreadPoolGroup.java index 4c675a0f85..bf6c740b56 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/HTTPThreadPoolGroup.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/HTTPThreadPoolGroup.java @@ -73,7 +73,7 @@ public void initThreadPool() { new LinkedBlockingQueue<>(eventMeshHttpConfiguration.getEventMeshServerClientManageBlockQSize()), "eventMesh-clientManage", true); - // The runtimeAdminExecutor here is for the runtime.admin package and has nothing to do with the eventmesh-admin module. + // The runtimeAdminExecutor here is for the runtime.admin package. runtimeAdminExecutor = ThreadPoolFactory.createThreadPoolExecutor( eventMeshHttpConfiguration.getEventMeshServerAdminThreadNum(), eventMeshHttpConfiguration.getEventMeshServerAdminThreadNum(), @@ -82,8 +82,7 @@ public void initThreadPool() { replyMsgExecutor = ThreadPoolFactory.createThreadPoolExecutor( eventMeshHttpConfiguration.getEventMeshServerReplyMsgThreadNum(), eventMeshHttpConfiguration.getEventMeshServerReplyMsgThreadNum(), - new LinkedBlockingQueue<>(100), - "eventMesh-replyMsg", true); + new LinkedBlockingQueue<>(100), "eventMesh-replyMsg", true); webhookExecutor = ThreadPoolFactory.createThreadPoolExecutor( eventMeshHttpConfiguration.getEventMeshServerWebhookThreadNum(), diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/common/EventHttpHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/common/EventMeshHttpHandler.java similarity index 96% rename from eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/common/EventHttpHandler.java rename to eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/common/EventMeshHttpHandler.java index 25c2bcbd56..dd30f65e6a 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/common/EventHttpHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/common/EventMeshHttpHandler.java @@ -26,7 +26,7 @@ @Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) -public @interface EventHttpHandler { +public @interface EventMeshHttpHandler { /** * request path diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshGrpcConfiguration.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshGrpcConfiguration.java index eee723aaa1..cf08f27553 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshGrpcConfiguration.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshGrpcConfiguration.java @@ -19,7 +19,7 @@ import org.apache.eventmesh.common.config.CommonConfiguration; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import org.apache.eventmesh.common.utils.IPUtils; import lombok.Data; @@ -32,76 +32,76 @@ @Config(prefix = "eventMesh.server") public class EventMeshGrpcConfiguration extends CommonConfiguration { - @ConfigFiled(field = "grpc.port", notNull = true, beNumber = true) + @ConfigField(field = "grpc.port", notNull = true, beNumber = true) private int grpcServerPort = 10205; - @ConfigFiled(field = "session.expiredInMills") + @ConfigField(field = "session.expiredInMills") private int eventMeshSessionExpiredInMills = 60000; - @ConfigFiled(field = "batchmsg.batch.enabled") + @ConfigField(field = "batchmsg.batch.enabled") private boolean eventMeshServerBatchMsgBatchEnabled = Boolean.TRUE; - @ConfigFiled(field = "batchmsg.threads.num") + @ConfigField(field = "batchmsg.threads.num") private int eventMeshServerBatchMsgThreadNum = 10; - @ConfigFiled(field = "sendmsg.threads.num") + @ConfigField(field = "sendmsg.threads.num") private int eventMeshServerSendMsgThreadNum = 8; - @ConfigFiled(field = "pushmsg.threads.num") + @ConfigField(field = "pushmsg.threads.num") private int eventMeshServerPushMsgThreadNum = 8; - @ConfigFiled(field = "replymsg.threads.num") + @ConfigField(field = "replymsg.threads.num") private int eventMeshServerReplyMsgThreadNum = 8; - @ConfigFiled(field = "clientmanage.threads.num") + @ConfigField(field = "clientmanage.threads.num") private int eventMeshServerSubscribeMsgThreadNum = 4; - @ConfigFiled(field = "metaStorage.threads.num") + @ConfigField(field = "metaStorage.threads.num") private int eventMeshServerMetaStorageThreadNum = 10; - @ConfigFiled(field = "admin.threads.num") + @ConfigField(field = "admin.threads.num") private int eventMeshServerAdminThreadNum = 2; - @ConfigFiled(field = "retry.threads.num") + @ConfigField(field = "retry.threads.num") private int eventMeshServerRetryThreadNum = 2; - @ConfigFiled(field = "pull.metaStorage.interval") + @ConfigField(field = "pull.metaStorage.interval") private int eventMeshServerPullMetaStorageInterval = 30000; - @ConfigFiled(field = "async.accumulation.threshold") + @ConfigField(field = "async.accumulation.threshold") private int eventMeshServerAsyncAccumulationThreshold = 1000; - @ConfigFiled(field = "retry.blockQ.size") + @ConfigField(field = "retry.blockQ.size") private int eventMeshServerRetryBlockQueueSize = 10000; - @ConfigFiled(field = "batchmsg.blockQ.size") + @ConfigField(field = "batchmsg.blockQ.size") private int eventMeshServerBatchBlockQueueSize = 1000; - @ConfigFiled(field = "sendmsg.blockQ.size") + @ConfigField(field = "sendmsg.blockQ.size") private int eventMeshServerSendMsgBlockQueueSize = 1000; - @ConfigFiled(field = "pushmsg.blockQ.size") + @ConfigField(field = "pushmsg.blockQ.size") private int eventMeshServerPushMsgBlockQueueSize = 1000; - @ConfigFiled(field = "clientM.blockQ.size") + @ConfigField(field = "clientM.blockQ.size") private int eventMeshServerSubscribeMsgBlockQueueSize = 1000; - @ConfigFiled(field = "busy.check.interval") + @ConfigField(field = "busy.check.interval") private int eventMeshServerBusyCheckInterval = 1000; - @ConfigFiled(field = "consumer.enabled") + @ConfigField(field = "consumer.enabled") private boolean eventMeshServerConsumerEnabled = false; - @ConfigFiled(field = "useTls.enabled") + @ConfigField(field = "useTls.enabled") private boolean eventMeshServerUseTls = false; - @ConfigFiled(field = "batchmsg.reqNumPerSecond") + @ConfigField(field = "batchmsg.reqNumPerSecond") private int eventMeshBatchMsgRequestNumPerSecond = 20000; - @ConfigFiled(field = "http.msgReqnumPerSecond") + @ConfigField(field = "http.msgReqnumPerSecond") private int eventMeshMsgReqNumPerSecond = 15000; - @ConfigFiled(field = "", reload = true) + @ConfigField(field = "", reload = true) private String eventMeshIp; public void reload() { diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfiguration.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfiguration.java index a7ed9b26fe..b0fa18df4c 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfiguration.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfiguration.java @@ -19,7 +19,7 @@ import org.apache.eventmesh.common.config.CommonConfiguration; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import java.util.Collections; import java.util.List; @@ -36,100 +36,100 @@ @Config(prefix = "eventMesh.server") public class EventMeshHTTPConfiguration extends CommonConfiguration { - @ConfigFiled(field = "http.port", notNull = true, beNumber = true) + @ConfigField(field = "http.port", notNull = true, beNumber = true) private int httpServerPort = 10105; - @ConfigFiled(field = "batchmsg.batch.enabled") + @ConfigField(field = "batchmsg.batch.enabled") private boolean eventMeshServerBatchMsgBatchEnabled = Boolean.TRUE; - @ConfigFiled(field = "batchmsg.threads.num") + @ConfigField(field = "batchmsg.threads.num") private int eventMeshServerBatchMsgThreadNum = 10; - @ConfigFiled(field = "sendmsg.threads.num") + @ConfigField(field = "sendmsg.threads.num") private int eventMeshServerSendMsgThreadNum = 8; - @ConfigFiled(field = "remotemsg.threads.num") + @ConfigField(field = "remotemsg.threads.num") private int eventMeshServerRemoteMsgThreadNum = 8; - @ConfigFiled(field = "pushmsg.threads.num") + @ConfigField(field = "pushmsg.threads.num") private int eventMeshServerPushMsgThreadNum = 8; - @ConfigFiled(field = "replymsg.threads.num") + @ConfigField(field = "replymsg.threads.num") private int eventMeshServerReplyMsgThreadNum = 8; - @ConfigFiled(field = "clientmanage.threads.num") + @ConfigField(field = "clientmanage.threads.num") private int eventMeshServerClientManageThreadNum = 4; - @ConfigFiled(field = "metaStorage.threads.num") + @ConfigField(field = "metaStorage.threads.num") private int eventMeshServerMetaStorageThreadNum = 10; - @ConfigFiled(field = "admin.threads.num") + @ConfigField(field = "admin.threads.num") private int eventMeshServerAdminThreadNum = 2; - @ConfigFiled(field = "retry.threads.num") + @ConfigField(field = "retry.threads.num") private int eventMeshServerRetryThreadNum = 2; - @ConfigFiled(field = "") + @ConfigField(field = "") private int eventMeshServerWebhookThreadNum = 4; - @ConfigFiled(field = "pull.metaStorage.interval") + @ConfigField(field = "pull.metaStorage.interval") private int eventMeshServerPullMetaStorageInterval = 30000; - @ConfigFiled(field = "async.accumulation.threshold") + @ConfigField(field = "async.accumulation.threshold") private int eventMeshServerAsyncAccumulationThreshold = 1000; - @ConfigFiled(field = "retry.blockQ.size") + @ConfigField(field = "retry.blockQ.size") private int eventMeshServerRetryBlockQSize = 10000; - @ConfigFiled(field = "batchmsg.blockQ.size") + @ConfigField(field = "batchmsg.blockQ.size") private int eventMeshServerBatchBlockQSize = 1000; - @ConfigFiled(field = "sendmsg.blockQ.size") + @ConfigField(field = "sendmsg.blockQ.size") private int eventMeshServerSendMsgBlockQSize = 1000; - @ConfigFiled(field = "") + @ConfigField(field = "") private int eventMeshServerRemoteMsgBlockQSize = 1000; - @ConfigFiled(field = "pushmsg.blockQ.size") + @ConfigField(field = "pushmsg.blockQ.size") private int eventMeshServerPushMsgBlockQSize = 1000; - @ConfigFiled(field = "clientM.blockQ.size") + @ConfigField(field = "clientM.blockQ.size") private int eventMeshServerClientManageBlockQSize = 1000; - @ConfigFiled(field = "busy.check.interval") + @ConfigField(field = "busy.check.interval") private int eventMeshServerBusyCheckInterval = 1000; - @ConfigFiled(field = "consumer.enabled") + @ConfigField(field = "consumer.enabled") private boolean eventMeshServerConsumerEnabled = false; - @ConfigFiled(field = "useTls.enabled") + @ConfigField(field = "useTls.enabled") private boolean eventMeshServerUseTls = false; - @ConfigFiled(field = "ssl.protocol") + @ConfigField(field = "ssl.protocol") private String eventMeshServerSSLProtocol = "TLSv1.1"; - @ConfigFiled(field = "ssl.cer") + @ConfigField(field = "ssl.cer") private String eventMeshServerSSLCer = "sChat2.jks"; - @ConfigFiled(field = "ssl.pass") + @ConfigField(field = "ssl.pass") private String eventMeshServerSSLPass = "sNetty"; - @ConfigFiled(field = "http.msgReqnumPerSecond") + @ConfigField(field = "http.msgReqnumPerSecond") private int eventMeshHttpMsgReqNumPerSecond = 15000; - @ConfigFiled(field = "batchmsg.reqNumPerSecond") + @ConfigField(field = "batchmsg.reqNumPerSecond") private int eventMeshBatchMsgRequestNumPerSecond = 20000; - @ConfigFiled(field = "maxEventSize") + @ConfigField(field = "maxEventSize") private int eventMeshEventSize = 1000; - @ConfigFiled(field = "maxEventBatchSize") + @ConfigField(field = "maxEventBatchSize") private int eventMeshEventBatchSize = 10; - @ConfigFiled(field = "blacklist.ipv4") + @ConfigField(field = "blacklist.ipv4") private List eventMeshIpv4BlackList = Collections.emptyList(); - @ConfigFiled(field = "blacklist.ipv6") + @ConfigField(field = "blacklist.ipv6") private List eventMeshIpv6BlackList = Collections.emptyList(); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfiguration.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfiguration.java index 84871b582c..891f986167 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfiguration.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfiguration.java @@ -19,7 +19,7 @@ import org.apache.eventmesh.common.config.CommonConfiguration; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import lombok.AllArgsConstructor; import lombok.Data; @@ -32,105 +32,105 @@ @Config(prefix = "eventMesh.server") public class EventMeshTCPConfiguration extends CommonConfiguration { - @ConfigFiled(field = "tcp.port") + @ConfigField(field = "tcp.port") private int eventMeshTcpServerPort = 10000; - @ConfigFiled(field = "tcp.allIdleSeconds") + @ConfigField(field = "tcp.allIdleSeconds") private int eventMeshTcpIdleAllSeconds = 60; - @ConfigFiled(field = "tcp.writerIdleSeconds") + @ConfigField(field = "tcp.writerIdleSeconds") private int eventMeshTcpIdleWriteSeconds = 60; - @ConfigFiled(field = "tcp.readerIdleSeconds") + @ConfigField(field = "tcp.readerIdleSeconds") private int eventMeshTcpIdleReadSeconds = 60; - @ConfigFiled(field = "tcp.msgReqnumPerSecond") + @ConfigField(field = "tcp.msgReqnumPerSecond") private Integer eventMeshTcpMsgReqnumPerSecond = 15000; /** * TCP Server allows max client num */ - @ConfigFiled(field = "tcp.clientMaxNum") + @ConfigField(field = "tcp.clientMaxNum") private int eventMeshTcpClientMaxNum = 10000; // ======================================= New add config ================================= - @ConfigFiled(field = "global.scheduler") + @ConfigField(field = "global.scheduler") private int eventMeshTcpGlobalScheduler = 5; - @ConfigFiled(field = "tcp.taskHandleExecutorPoolSize") + @ConfigField(field = "tcp.taskHandleExecutorPoolSize") private int eventMeshTcpTaskHandleExecutorPoolSize = 2 * Runtime.getRuntime().availableProcessors(); - @ConfigFiled(field = "tcp.sendExecutorPoolSize") + @ConfigField(field = "tcp.sendExecutorPoolSize") private int eventMeshTcpMsgSendExecutorPoolSize = 2 * Runtime.getRuntime().availableProcessors(); - @ConfigFiled(field = "tcp.replyExecutorPoolSize") + @ConfigField(field = "tcp.replyExecutorPoolSize") private int eventMeshTcpMsgReplyExecutorPoolSize = 2 * Runtime.getRuntime().availableProcessors(); - @ConfigFiled(field = "tcp.ackExecutorPoolSize") + @ConfigField(field = "tcp.ackExecutorPoolSize") private int eventMeshTcpMsgAckExecutorPoolSize = 2 * Runtime.getRuntime().availableProcessors(); - @ConfigFiled(field = "tcp.taskHandleExecutorQueueSize") + @ConfigField(field = "tcp.taskHandleExecutorQueueSize") private int eventMeshTcpTaskHandleExecutorQueueSize = 10000; - @ConfigFiled(field = "tcp.sendExecutorQueueSize") + @ConfigField(field = "tcp.sendExecutorQueueSize") private int eventMeshTcpMsgSendExecutorQueueSize = 10000; - @ConfigFiled(field = "tcp.replyExecutorQueueSize") + @ConfigField(field = "tcp.replyExecutorQueueSize") private int eventMeshTcpMsgReplyExecutorQueueSize = 10000; - @ConfigFiled(field = "tcp.ackExecutorQueueSize") + @ConfigField(field = "tcp.ackExecutorQueueSize") private int eventMeshTcpMsgAckExecutorQueueSize = 10000; - @ConfigFiled(field = "tcp.msgDownStreamExecutorPoolSize") + @ConfigField(field = "tcp.msgDownStreamExecutorPoolSize") private int eventMeshTcpMsgDownStreamExecutorPoolSize = Math.max(Runtime.getRuntime().availableProcessors(), 8); - @ConfigFiled(field = "session.expiredInMills") + @ConfigField(field = "session.expiredInMills") private int eventMeshTcpSessionExpiredInMills = 60000; - @ConfigFiled(field = "session.upstreamBufferSize") + @ConfigField(field = "session.upstreamBufferSize") private int eventMeshTcpSessionUpstreamBufferSize = 100; - @ConfigFiled(field = "retry.async.pushRetryTimes") + @ConfigField(field = "retry.async.pushRetryTimes") private int eventMeshTcpMsgAsyncRetryTimes = 3; - @ConfigFiled(field = "retry.sync.pushRetryTimes") + @ConfigField(field = "retry.sync.pushRetryTimes") private int eventMeshTcpMsgSyncRetryTimes = 1; - @ConfigFiled(field = "retry.sync.pushRetryDelayInMills") + @ConfigField(field = "retry.sync.pushRetryDelayInMills") private int eventMeshTcpMsgRetrySyncDelayInMills = 500; - @ConfigFiled(field = "retry.async.pushRetryDelayInMills") + @ConfigField(field = "retry.async.pushRetryDelayInMills") private int eventMeshTcpMsgRetryAsyncDelayInMills = 500; - @ConfigFiled(field = "retry.pushRetryQueueSize") + @ConfigField(field = "retry.pushRetryQueueSize") private int eventMeshTcpMsgRetryQueueSize = 10000; - @ConfigFiled(field = "tcp.RebalanceIntervalInMills") + @ConfigField(field = "tcp.RebalanceIntervalInMills") private Integer eventMeshTcpRebalanceIntervalInMills = 30 * 1000; - @ConfigFiled(field = "admin.http.port") + @ConfigField(field = "admin.http.port") private int eventMeshServerAdminPort = 10106; - @ConfigFiled(field = "tcp.sendBack.enabled") + @ConfigField(field = "tcp.sendBack.enabled") private boolean eventMeshTcpSendBackEnabled = Boolean.TRUE; - @ConfigFiled(field = "tcp.SendBackMaxTimes") + @ConfigField(field = "tcp.SendBackMaxTimes") private int eventMeshTcpSendBackMaxTimes = 3; - @ConfigFiled(field = "tcp.pushFailIsolateTimeInMills") + @ConfigField(field = "tcp.pushFailIsolateTimeInMills") private int eventMeshTcpPushFailIsolateTimeInMills = 30 * 1000; - @ConfigFiled(field = "gracefulShutdown.sleepIntervalInMills") + @ConfigField(field = "gracefulShutdown.sleepIntervalInMills") private int gracefulShutdownSleepIntervalInMills = 1000; - @ConfigFiled(field = "rebalanceRedirect.sleepIntervalInM") + @ConfigField(field = "rebalanceRedirect.sleepIntervalInM") private int sleepIntervalInRebalanceRedirectMills = 200; - @ConfigFiled(field = "maxEventSize") + @ConfigField(field = "maxEventSize") private int eventMeshEventSize = 1000; - @ConfigFiled(field = "maxEventBatchSize") + @ConfigField(field = "maxEventBatchSize") private int eventMeshEventBatchSize = 10; private final TrafficShapingConfig gtc = new TrafficShapingConfig(0, 10_000, 1_000, 2_000); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/EventMeshConstants.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/EventMeshConstants.java index 4196572ccb..2830ae9596 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/EventMeshConstants.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/EventMeshConstants.java @@ -21,10 +21,6 @@ public class EventMeshConstants { - public static final String EVENT_STORE_PROPERTIES = "eventstore"; - - public static final String EVENT_STORE_ENV = "EVENT_STORE"; - public static final String PROTOCOL_HTTP = "http"; public static final String PROTOCOL_TCP = "tcp"; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQProducerWrapper.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQProducerWrapper.java index f0a50dcc05..84b0079f4b 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQProducerWrapper.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQProducerWrapper.java @@ -91,5 +91,4 @@ public boolean reply(final CloudEvent cloudEvent, final SendCallback sendCallbac public Producer getMeshMQProducer() { return meshMQProducer; } - } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQWrapper.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQWrapper.java index 6edf93f530..e0828d460f 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQWrapper.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQWrapper.java @@ -17,29 +17,11 @@ package org.apache.eventmesh.runtime.core.plugin; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; - -import org.apache.commons.lang3.StringUtils; - import java.util.concurrent.atomic.AtomicBoolean; public abstract class MQWrapper { - public static final String EVENT_STORE_DEFIBUS = "defibus"; - - public static String CURRENT_EVENT_STORE = EVENT_STORE_DEFIBUS; - - public static final String EVENT_STORE_CONF = System.getProperty(EventMeshConstants.EVENT_STORE_PROPERTIES, - System.getenv(EventMeshConstants.EVENT_STORE_ENV)); - - static { - if (StringUtils.isNotBlank(EVENT_STORE_CONF)) { - CURRENT_EVENT_STORE = EVENT_STORE_CONF; - } - } - public AtomicBoolean started = new AtomicBoolean(Boolean.FALSE); public AtomicBoolean inited = new AtomicBoolean(Boolean.FALSE); - } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/CreateTopicProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/CreateTopicProcessor.java index 3f364e9fa3..64a5ddfd90 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/CreateTopicProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/CreateTopicProcessor.java @@ -65,8 +65,6 @@ public void handler(HandlerService.HandlerSpecific handlerSpecific, HttpRequest final ChannelHandlerContext ctx = handlerSpecific.getCtx(); final HttpEventWrapper requestWrapper = asyncContext.getRequest(); - HttpEventWrapper responseWrapper; - HTTP_LOGGER.info("uri={}|{}|client2eventMesh|from={}|to={}", requestWrapper.getRequestURI(), EventMeshConstants.PROTOCOL_HTTP, RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); @@ -90,6 +88,8 @@ public void handler(HandlerService.HandlerSpecific handlerSpecific, HttpRequest new TypeReference>() { }); + HttpEventWrapper responseWrapper; + if (requestBodyMap.get("topic") == null || StringUtils.isBlank(requestBodyMap.get("topic").toString())) { Map responseBodyMap = new HashMap<>(); responseBodyMap.put("retCode", EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode()); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/DeleteTopicProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/DeleteTopicProcessor.java index be426c0fcd..0def2507f1 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/DeleteTopicProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/DeleteTopicProcessor.java @@ -67,8 +67,6 @@ public void handler(HandlerService.HandlerSpecific handlerSpecific, HttpRequest final ChannelHandlerContext ctx = handlerSpecific.getCtx(); final HttpEventWrapper requestWrapper = asyncContext.getRequest(); - HttpEventWrapper responseWrapper; - HTTP_LOGGER.info("uri={}|{}|client2eventMesh|from={}|to={}", requestWrapper.getRequestURI(), EventMeshConstants.PROTOCOL_HTTP, RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); @@ -92,6 +90,8 @@ public void handler(HandlerService.HandlerSpecific handlerSpecific, HttpRequest new TypeReference>() { }); + HttpEventWrapper responseWrapper; + if (requestBodyMap.get("topic") == null || StringUtils.isBlank(requestBodyMap.get("topic").toString())) { Map responseBodyMap = new HashMap<>(); responseBodyMap.put("retCode", EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode()); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/HandlerService.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/HandlerService.java index 58149fc423..b68ea2f648 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/HandlerService.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/HandlerService.java @@ -278,7 +278,6 @@ public void run() { } ProcessorWrapper processorWrapper = HandlerService.this.httpProcessorMap.get(processorKey); try { - this.preHandler(); if (processorWrapper.httpProcessor instanceof AsyncHttpProcessor) { // set actual async request HttpEventWrapper httpEventWrapper = parseHttpRequest(request); @@ -289,10 +288,10 @@ public void run() { response = processorWrapper.httpProcessor.handler(request); if (processorWrapper.httpProcessor instanceof ShortHttpProcessor) { - this.postHandler(ConnectionType.SHORT_LIVED); + this.postHandlerWithTimeCostRecord(ConnectionType.SHORT_LIVED); return; } - this.postHandler(ConnectionType.PERSISTENT); + this.postHandlerWithTimeCostRecord(ConnectionType.PERSISTENT); } catch (Throwable e) { exception = e; // todo: according exception to generate response @@ -301,6 +300,12 @@ public void run() { } } + private void postHandlerWithTimeCostRecord(ConnectionType type) { + metrics.getSummaryMetrics().recordHTTPReqResTimeCost(System.currentTimeMillis() - requestTime); + HTTP_LOGGER.debug("{}", response); + postHandler(type); + } + private void postHandler(ConnectionType type) { metrics.getSummaryMetrics().recordHTTPRequest(); HTTP_LOGGER.debug("{}", request); @@ -315,10 +320,6 @@ private void postHandler(ConnectionType type) { } } - private void preHandler() { - metrics.getSummaryMetrics().recordHTTPReqResTimeCost(System.currentTimeMillis() - requestTime); - HTTP_LOGGER.debug("{}", response); - } private void error() { log.error(this.exception.getMessage(), this.exception); @@ -328,14 +329,6 @@ private void error() { HandlerService.this.sendResponse(ctx, this.request, this.response); } - public void setResponseJsonBody(String body) { - this.sendResponse(HttpResponseUtils.setResponseJsonBody(body, ctx)); - } - - public void setResponseTextBody(String body) { - this.sendResponse(HttpResponseUtils.setResponseTextBody(body, ctx)); - } - public void sendResponse(HttpResponse response) { this.response = response; this.postHandler(ConnectionType.PERSISTENT); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/producer/EventMeshProducer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/producer/EventMeshProducer.java index bd27d6933d..749695d4c7 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/producer/EventMeshProducer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/producer/EventMeshProducer.java @@ -65,7 +65,6 @@ public synchronized void init(CommonConfiguration configuration, keyValue.put(EventMeshConstants.INSTANCE_NAME, EventMeshUtil.buildMeshClientID( producerGroupConfig.getGroupName(), configuration.getEventMeshCluster())); - // TODO for defibus keyValue.put(EventMeshConstants.EVENT_MESH_IDC, configuration.getEventMeshIDC()); mqProducerWrapper = new MQProducerWrapper( configuration.getEventMeshStoragePluginType()); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientGroupWrapper.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientGroupWrapper.java index f5a6f748e4..8b4ce0a4e1 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientGroupWrapper.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientGroupWrapper.java @@ -289,7 +289,6 @@ public synchronized void startClientGroupProducer() throws Exception { .buildMeshTcpClientID(sysId, EventMeshConstants.PURPOSE_PUB_UPPER_CASE, eventMeshTCPConfiguration.getEventMeshCluster())); - // TODO for defibus keyValue.put(EventMeshConstants.EVENT_MESH_IDC, eventMeshTCPConfiguration.getEventMeshIDC()); mqProducerWrapper.init(keyValue); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/Session.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/Session.java index 37c5a1e372..e2e36690a6 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/Session.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/Session.java @@ -238,15 +238,15 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = 1001; // primeNumber - if (null != client) { + if (client != null) { result += 31 * result + Objects.hash(client); } - if (null != context) { + if (context != null) { result += 31 * result + Objects.hash(context); } - if (null != sessionState) { + if (sessionState != null) { result += 31 * result + Objects.hash(sessionState); } return result; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpRequestUtil.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpRequestUtil.java index ecfcd0e198..afa43ba6b4 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpRequestUtil.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpRequestUtil.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.function.Consumer; @@ -51,12 +52,16 @@ public static Map parseHttpRequestBody(final HttpRequest htt } else if (io.netty.handler.codec.http.HttpMethod.POST.equals(httpRequest.method())) { decodeHttpRequestBody(httpRequest, httpRequestBody); } - if (Objects.isNull(t)) { + if (!Objects.isNull(end)) { end.accept(t); } return httpRequestBody; } + public static Map parseHttpRequestBody(final HttpRequest httpRequest) throws IOException { + return parseHttpRequestBody(httpRequest, null, null); + } + private static void decodeHttpRequestBody(HttpRequest httpRequest, Map httpRequestBody) throws IOException { final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(DEFAULT_HTTP_DATA_FACTORY, httpRequest); for (final InterfaceHttpData param : decoder.getBodyHttpDatas()) { @@ -68,4 +73,47 @@ private static void decodeHttpRequestBody(HttpRequest httpRequest, Map + * This method takes a query string and parses it to create a map of key-value pairs, where each key and value are extracted from the query string + * separated by '='. + *

+ * If the query string is null, an empty map is returned. + * + * @param queryString the query string to convert to a map + * @return a map containing the key-value pairs from the query string + */ + public static Map queryStringToMap(String queryString) { + if (queryString == null) { + return new HashMap<>(); + } + Map result = new HashMap<>(); + for (String param : queryString.split("&")) { + String[] entry = param.split("="); + if (entry.length > 1) { + result.put(entry[0], entry[1]); + } else { + result.put(entry[0], ""); + } + } + return result; + } + + /** + * Get the value of a query parameter in URI query string. + */ + public static String getQueryParam(HttpRequest httpRequest, String key, String defaultValue) { + List values = new QueryStringDecoder(httpRequest.uri()).parameters().get(key); + return values != null ? values.get(0) : defaultValue; + } + + /** + * Get the value of a query parameter in body. + */ + public static String getBodyParam(HttpRequest httpRequest, String key) throws IOException { + HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(httpRequest); + Attribute attribute = (Attribute) decoder.getBodyHttpData(key); + return attribute.getValue(); + } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpResponseUtils.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpResponseUtils.java index 0db7e58c30..b24cfeab89 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpResponseUtils.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpResponseUtils.java @@ -18,13 +18,13 @@ package org.apache.eventmesh.runtime.util; import org.apache.eventmesh.common.Constants; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; @@ -33,59 +33,51 @@ public class HttpResponseUtils { + /** + * @return Empty response with 200 status code. + */ public static HttpResponse createSuccess() { return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); } + /** + * @return Empty response with 404 status code. + */ public static HttpResponse createNotFound() { return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND); } + /** + * @return Empty response with 500 status code. + */ public static HttpResponse createInternalServerError() { return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR); } - private static ByteBuf createByteBuf(ChannelHandlerContext ctx, String body) { - byte[] bytes = body.getBytes(Constants.DEFAULT_CHARSET); - return createByteBuf(ctx, bytes); - } - - private static ByteBuf createByteBuf(ChannelHandlerContext ctx, byte[] bytes) { - ByteBuf byteBuf = ctx.alloc().buffer(bytes.length); - byteBuf.writeBytes(bytes); - return byteBuf; - } - - public static HttpResponse setResponseJsonBody(String body, ChannelHandlerContext ctx) { - return getHttpResponse(body, ctx, HttpHeaderValues.APPLICATION_JSON); - - } - - public static HttpResponse setResponseTextBody(String body, ChannelHandlerContext ctx) { - return getHttpResponse(body, ctx, HttpHeaderValues.TEXT_HTML); - } - - public static HttpResponse getHttpResponse(String body, ChannelHandlerContext ctx, AsciiString headerValue) { + /** + * Only one header is set: {@link HttpHeaderNames#CONTENT_TYPE} with the provided {@code headerValue}. + */ + public static HttpResponse buildHttpResponse(String body, ChannelHandlerContext ctx, AsciiString headerValue, HttpResponseStatus status) { HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(HttpHeaderNames.CONTENT_TYPE, headerValue); - return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, createByteBuf(ctx, body), - responseHeaders, responseHeaders); + return buildHttpResponse(body, ctx, responseHeaders, status); } - public static HttpResponse getHttpResponse(byte[] bytes, ChannelHandlerContext ctx, AsciiString headerValue) { - return getHttpResponse(bytes, ctx, headerValue, HttpResponseStatus.OK); + public static HttpResponse buildHttpResponse(String body, ChannelHandlerContext ctx, HttpHeaders responseHeaders, HttpResponseStatus status) { + return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, createByteBuf(ctx, body), responseHeaders, responseHeaders); } - public static HttpResponse getHttpResponse(byte[] bytes, ChannelHandlerContext ctx, AsciiString headerValue, HttpResponseStatus status) { + public static HttpHeaders buildDefaultHttpHeaders(AsciiString contentType) { HttpHeaders responseHeaders = new DefaultHttpHeaders(); - responseHeaders.add(HttpHeaderNames.CONTENT_TYPE, headerValue); - return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, createByteBuf(ctx, bytes), - responseHeaders, responseHeaders); + responseHeaders.add(HttpHeaderNames.CONTENT_TYPE, contentType); + responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); + return responseHeaders; } - public static HttpResponse getHttpResponse(byte[] bytes, ChannelHandlerContext ctx, HttpHeaders responseHeaders, HttpResponseStatus status) { - return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, createByteBuf(ctx, bytes), - responseHeaders, responseHeaders); + private static ByteBuf createByteBuf(ChannelHandlerContext ctx, String body) { + byte[] bytes = body.getBytes(Constants.DEFAULT_CHARSET); + ByteBuf byteBuf = ctx.alloc().buffer(bytes.length); + byteBuf.writeBytes(bytes); + return byteBuf; } - } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpTinyClient.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpTinyClient.java index 38d3019de3..24142a6821 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpTinyClient.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpTinyClient.java @@ -80,7 +80,7 @@ private static String encodingParams(Collection paramValues, String enco } private static void setHeaders(HttpURLConnection conn, Collection headers, String encoding) { - if (null != headers) { + if (headers != null) { for (Iterator iter = headers.iterator(); iter.hasNext();) { conn.addRequestProperty(iter.next(), iter.next()); } @@ -116,7 +116,7 @@ public static HttpResult httpPost(String url, List headers, List return new HttpResult(respCode, resp); } finally { - if (null != conn) { + if (conn != null) { conn.disconnect(); } } diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/EventHandlerTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/EventHandlerTest.java new file mode 100644 index 0000000000..1df3386bea --- /dev/null +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/EventHandlerTest.java @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.eventmesh.runtime.admin.handler; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; + +import org.apache.eventmesh.runtime.admin.handler.v1.EventHandler; +import org.apache.eventmesh.runtime.boot.EventMeshServer; +import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; +import org.apache.eventmesh.runtime.core.plugin.MQAdminWrapper; +import org.apache.eventmesh.runtime.mock.MockCloudEvent; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; + +import io.cloudevents.CloudEvent; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.embedded.EmbeddedChannel; +import io.netty.handler.codec.http.DefaultFullHttpRequest; +import io.netty.handler.codec.http.FullHttpRequest; +import io.netty.handler.codec.http.HttpMethod; +import io.netty.handler.codec.http.HttpObjectAggregator; +import io.netty.handler.codec.http.HttpRequest; +import io.netty.handler.codec.http.HttpRequestDecoder; +import io.netty.handler.codec.http.HttpResponseEncoder; +import io.netty.handler.codec.http.HttpVersion; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@ExtendWith(MockitoExtension.class) +public class EventHandlerTest { + + public static String storagePlugin = "standalone"; + + EmbeddedChannel embeddedChannel; + + AdminHandlerManager adminHandlerManager; + + @Mock + EventMeshServer eventMeshServer; + + @Mock + EventMeshTCPServer eventMeshTCPServer; + + @Spy + EventHandler eventHandler = new EventHandler(storagePlugin); + + @Mock + MQAdminWrapper mockAdmin; + + List result = new ArrayList<>(); + + Method initHandler; + + @BeforeEach + public void init() throws Exception { + result.add(new MockCloudEvent()); + when(eventMeshServer.getEventMeshTCPServer()).thenReturn(eventMeshTCPServer); + adminHandlerManager = new AdminHandlerManager(eventMeshServer); + Field admin = EventHandler.class.getDeclaredField("admin"); + admin.setAccessible(true); + admin.set(eventHandler, mockAdmin); + embeddedChannel = new EmbeddedChannel( + new HttpRequestDecoder(), + new HttpResponseEncoder(), + new HttpObjectAggregator(Integer.MAX_VALUE), + new SimpleChannelInboundHandler() { + @Override + protected void channelRead0(ChannelHandlerContext ctx, HttpRequest msg) throws Exception { + String uriStr = msg.uri(); + URI uri = URI.create(uriStr); + adminHandlerManager.getHttpHandler(uri.getPath()).get().handle(msg, ctx); + } + }); + initHandler = AdminHandlerManager.class.getDeclaredMethod("initHandler", HttpHandler.class); + initHandler.setAccessible(true); + initHandler.invoke(adminHandlerManager, eventHandler); + } + + @Test + public void testGet() throws Exception { + when(mockAdmin.getEvent(anyString(), anyInt(), anyInt())).thenReturn(result); + FullHttpRequest httpRequest = new DefaultFullHttpRequest( + HttpVersion.HTTP_1_1, HttpMethod.GET, "/event?topicName=123&offset=0&length=1"); + embeddedChannel.writeInbound(httpRequest); + boolean finish = embeddedChannel.finish(); + assertTrue(finish); + ByteBuf byteBuf = null; + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(1024); + while ((byteBuf = embeddedChannel.readOutbound()) != null) { + byte[] data = new byte[byteBuf.readableBytes()]; + byteBuf.readBytes(data); + byteArrayOutputStream.write(data); + } + ; + String response = new String(byteArrayOutputStream.toByteArray(), "UTF-8"); + String responseBody = response.split("\\r?\\n\\r?\\n")[1]; + JsonNode jsonNode = new ObjectMapper().readTree(responseBody); + assertTrue(jsonNode.get(0).asText().contains("mockData")); + } + + @Test + public void testPost() throws IOException { + FullHttpRequest httpRequest = new DefaultFullHttpRequest( + HttpVersion.HTTP_1_1, HttpMethod.POST, "/event", Unpooled.copiedBuffer( + ("specversion=1.0&id=cd7c0d63-6c7c-4300-9f4e-ceb51f46b1b1&source" + + "=/&type=cloudevents&datacontenttype=application/cloudevents+json&subject=test&ttl=4000").getBytes())); + embeddedChannel.writeInbound(httpRequest); + ByteBuf byteBuf = embeddedChannel.readOutbound(); + byte[] data = new byte[byteBuf.readableBytes()]; + byteBuf.readBytes(data); + String response = new String(data, "UTF-8"); + String[] requestMessage = response.split("\r\n"); + assertEquals("HTTP/1.1 200 OK", requestMessage[0].toString()); + } +} diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/boot/EventMeshServerTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/boot/EventMeshServerTest.java index 3d7cfdf877..c546d38e3b 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/boot/EventMeshServerTest.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/boot/EventMeshServerTest.java @@ -93,7 +93,6 @@ private void assertCommonConfig(CommonConfiguration config) { Assertions.assertEquals("cluster-succeed!!!", config.getEventMeshCluster()); Assertions.assertEquals("name-succeed!!!", config.getEventMeshName()); Assertions.assertEquals("816", config.getSysID()); - Assertions.assertEquals("connector-succeed!!!", config.getEventMeshConnectorPluginType()); Assertions.assertEquals("storage-succeed!!!", config.getEventMeshStoragePluginType()); Assertions.assertEquals("security-succeed!!!", config.getEventMeshSecurityPluginType()); Assertions.assertEquals("metaStorage-succeed!!!", config.getEventMeshMetaStoragePluginType()); diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/UserAgentUtils.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/UserAgentUtils.java index 2602c85384..500008dd7e 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/UserAgentUtils.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/UserAgentUtils.java @@ -43,8 +43,6 @@ public static UserAgent createPubUserAgent() { public static UserAgent createUserAgent() { UserAgent userAgent = new UserAgent(); userAgent.setSubsystem("5123"); - // userAgent.setPid(UtilAll.getPid()); - // userAgent.setHost(RemotingUtil.getLocalAddress()); userAgent.setVersion("2.0.8"); userAgent.setUsername("username"); userAgent.setPassword("1234"); @@ -54,13 +52,11 @@ public static UserAgent createUserAgent() { public static UserAgent createSubUserAgent() { UserAgent userAgent = new UserAgent(); userAgent.setSubsystem("5243"); - // userAgent.setPid(UtilAll.getPid()); - // userAgent.setHost(RemotingUtil.getLocalAddress()); userAgent.setPort(8888); userAgent.setVersion("2.0.8"); userAgent.setUsername("username"); userAgent.setPassword("1234"); - userAgent.setPath("/data/app/defibus-acl/"); + userAgent.setPath("/data/app/acl/"); userAgent.setPurpose(EventMeshConstants.PURPOSE_SUB); return userAgent; } diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshGrpcConfigurationTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshGrpcConfigurationTest.java index b27b7c5f9f..6b206167dc 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshGrpcConfigurationTest.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshGrpcConfigurationTest.java @@ -72,7 +72,6 @@ private void assertCommonConfig(CommonConfiguration config) { Assertions.assertEquals("cluster-succeed!!!", config.getEventMeshCluster()); Assertions.assertEquals("name-succeed!!!", config.getEventMeshName()); Assertions.assertEquals("816", config.getSysID()); - Assertions.assertEquals("connector-succeed!!!", config.getEventMeshConnectorPluginType()); Assertions.assertEquals("storage-succeed!!!", config.getEventMeshStoragePluginType()); Assertions.assertEquals("security-succeed!!!", config.getEventMeshSecurityPluginType()); Assertions.assertEquals("metaStorage-succeed!!!", config.getEventMeshMetaStoragePluginType()); diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfigurationTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfigurationTest.java index 0965744121..d522ff5519 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfigurationTest.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfigurationTest.java @@ -87,7 +87,6 @@ private void assertCommonConfig(CommonConfiguration config) { Assertions.assertEquals("cluster-succeed!!!", config.getEventMeshCluster()); Assertions.assertEquals("name-succeed!!!", config.getEventMeshName()); Assertions.assertEquals("816", config.getSysID()); - Assertions.assertEquals("connector-succeed!!!", config.getEventMeshConnectorPluginType()); Assertions.assertEquals("storage-succeed!!!", config.getEventMeshStoragePluginType()); Assertions.assertEquals("security-succeed!!!", config.getEventMeshSecurityPluginType()); Assertions.assertEquals("metaStorage-succeed!!!", config.getEventMeshMetaStoragePluginType()); diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfigurationTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfigurationTest.java index c16a073d56..1501cf1b5d 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfigurationTest.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfigurationTest.java @@ -74,7 +74,6 @@ private void assertCommonConfig(CommonConfiguration config) { Assertions.assertEquals("cluster-succeed!!!", config.getEventMeshCluster()); Assertions.assertEquals("name-succeed!!!", config.getEventMeshName()); Assertions.assertEquals("816", config.getSysID()); - Assertions.assertEquals("connector-succeed!!!", config.getEventMeshConnectorPluginType()); Assertions.assertEquals("storage-succeed!!!", config.getEventMeshStoragePluginType()); Assertions.assertEquals("security-succeed!!!", config.getEventMeshSecurityPluginType()); Assertions.assertEquals("metaStorage-succeed!!!", config.getEventMeshMetaStoragePluginType()); diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/mock/MockCloudEvent.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/mock/MockCloudEvent.java new file mode 100644 index 0000000000..ff114d18c6 --- /dev/null +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/mock/MockCloudEvent.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.eventmesh.runtime.mock; + +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.time.OffsetDateTime; +import java.util.Collections; +import java.util.Set; + +import io.cloudevents.CloudEvent; +import io.cloudevents.CloudEventData; +import io.cloudevents.SpecVersion; +import io.cloudevents.core.data.BytesCloudEventData; + +public class MockCloudEvent implements CloudEvent { + + @Override + public CloudEventData getData() { + return BytesCloudEventData.wrap("mockData".getBytes(StandardCharsets.UTF_8)); + } + + @Override + public SpecVersion getSpecVersion() { + return SpecVersion.V1; + } + + @Override + public String getId() { + return "mockId"; + } + + @Override + public String getType() { + return "mockType"; + } + + @Override + public URI getSource() { + return URI.create("mockSource"); + } + + @Override + public String getDataContentType() { + return null; + } + + @Override + public URI getDataSchema() { + return URI.create("mockDataSchema"); + } + + @Override + public String getSubject() { + return "mockSubject"; + } + + @Override + public OffsetDateTime getTime() { + return null; + } + + @Override + public Object getAttribute(String attributeName) throws IllegalArgumentException { + return null; + } + + @Override + public Object getExtension(String extensionName) { + return null; + } + + @Override + public Set getExtensionNames() { + return Collections.emptySet(); + } +} diff --git a/eventmesh-runtime/src/test/resources/configuration.properties b/eventmesh-runtime/src/test/resources/configuration.properties index 71ad34e19f..70ff82e05c 100644 --- a/eventmesh-runtime/src/test/resources/configuration.properties +++ b/eventmesh-runtime/src/test/resources/configuration.properties @@ -22,7 +22,6 @@ eventMesh.sysid=816 eventMesh.server.cluster=cluster-succeed!!! eventMesh.server.name=name-succeed!!! eventMesh.server.hostIp=hostIp-succeed!!! -eventMesh.connector.plugin.type=connector-succeed!!! eventMesh.storage.plugin.type=storage-succeed!!! eventMesh.security.plugin.type=security-succeed!!! eventMesh.trace.plugin=trace-succeed!!! @@ -33,8 +32,6 @@ eventMesh.metaStorage.plugin.server-addr=server-addr-succeed1!!! eventMesh.metaStorage.plugin.enabled=true eventMesh.metaStorage.plugin.username=username-succeed!!! eventMesh.metaStorage.plugin.password=password-succeed!!! -eventMesh.metaStorage.plugin.registerIntervalInMills=816 -eventMesh.metaStorage.plugin.fetchRegistryAddrIntervalInMills=1816 eventMesh.server.security.enabled=true eventMesh.server.trace.enabled=true diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumer.java b/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumer.java index 6ceefbe762..623ca1c6fe 100644 --- a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumer.java +++ b/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/EventMeshGrpcConsumer.java @@ -87,8 +87,7 @@ public EventMeshGrpcConsumer(final EventMeshGrpcClientConfig clientConfig) { } public void init() { - this.channel = ManagedChannelBuilder.forAddress(clientConfig.getServerAddr(), clientConfig.getServerPort()).usePlaintext() - .build(); + this.channel = ManagedChannelBuilder.forAddress(clientConfig.getServerAddr(), clientConfig.getServerPort()).usePlaintext().build(); this.consumerClient = ConsumerServiceGrpc.newBlockingStub(channel); this.consumerAsyncClient = ConsumerServiceGrpc.newStub(channel); this.heartbeatClient = HeartbeatServiceGrpc.newBlockingStub(channel); @@ -125,8 +124,8 @@ public void subscribe(final List subscriptionItems) { addSubscription(subscriptionItems, SDK_STREAM_URL, GrpcType.STREAM); - CloudEvent subscription = EventMeshCloudEventBuilder.buildEventSubscription(clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, null, - subscriptionItems); + CloudEvent subscription = EventMeshCloudEventBuilder.buildEventSubscription( + clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, null, subscriptionItems); synchronized (this) { if (subStreamHandler == null) { subStreamHandler = new SubStreamHandler<>(consumerAsyncClient, clientConfig, listener); @@ -137,8 +136,8 @@ public void subscribe(final List subscriptionItems) { } private Response subscribeWebhook(List subscriptionItems, String url) { - final CloudEvent subscription = EventMeshCloudEventBuilder.buildEventSubscription(clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, - url, subscriptionItems); + final CloudEvent subscription = EventMeshCloudEventBuilder.buildEventSubscription( + clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, url, subscriptionItems); try { CloudEvent response = consumerClient.subscribe(subscription); log.info("Received response:{}", response); @@ -169,8 +168,8 @@ public Response unsubscribe(final List subscriptionItems, fina removeSubscription(subscriptionItems); - final CloudEvent cloudEvent = EventMeshCloudEventBuilder.buildEventSubscription(clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, url, - subscriptionItems); + final CloudEvent cloudEvent = EventMeshCloudEventBuilder.buildEventSubscription( + clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, url, subscriptionItems); try { final CloudEvent response = consumerClient.unsubscribe(cloudEvent); log.info("Received response:{}", response); @@ -191,8 +190,8 @@ public Response unsubscribe(final List subscriptionItems) { removeSubscription(subscriptionItems); - final CloudEvent cloudEvent = EventMeshCloudEventBuilder.buildEventSubscription(clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, null, - subscriptionItems); + final CloudEvent cloudEvent = EventMeshCloudEventBuilder.buildEventSubscription( + clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, null, subscriptionItems); try { final CloudEvent response = consumerClient.unsubscribe(cloudEvent); @@ -277,14 +276,12 @@ private void resubscribe() { subscriptionGroup.forEach((url, items) -> { if (isStreamSub.get()) { - CloudEvent subscription = EventMeshCloudEventBuilder.buildEventSubscription(clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, - url, - items); + CloudEvent subscription = EventMeshCloudEventBuilder.buildEventSubscription( + clientConfig, EventMeshProtocolType.EVENT_MESH_MESSAGE, url, items); subStreamHandler.sendSubscription(subscription); } else { subscribeWebhook(items, url); } - }); } @@ -303,6 +300,7 @@ public void close() { } } + @Data private static class SubscriptionInfo { private transient SubscriptionItem subscriptionItem; @@ -314,25 +312,5 @@ private static class SubscriptionInfo { this.url = url; this.grpcType = grpcType; } - - public GrpcType getGrpcType() { - return grpcType; - } - - public SubscriptionItem getSubscriptionItem() { - return subscriptionItem; - } - - public void setSubscriptionItem(final SubscriptionItem subscriptionItem) { - this.subscriptionItem = subscriptionItem; - } - - public String getUrl() { - return url; - } - - public void setUrl(final String url) { - this.url = url; - } } } diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/SubStreamHandler.java b/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/SubStreamHandler.java index d34a0c79b1..59436be08f 100644 --- a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/SubStreamHandler.java +++ b/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/consumer/SubStreamHandler.java @@ -96,12 +96,12 @@ public void onNext(final CloudEvent message) { @Override public void onError(final Throwable t) { log.error("Received Server side error", t); + close(); } @Override public void onCompleted() { log.info("Finished receiving messages from server."); - close(); } }; } @@ -134,7 +134,6 @@ public void close() { } latch.countDown(); - log.info("SubStreamHandler closed."); } @@ -145,6 +144,7 @@ private void senderOnNext(final CloudEvent subscription) { } } catch (Exception e) { log.error("StreamObserver Error onNext", e); + close(); } } diff --git a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilder.java b/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilder.java index f7ab40c20a..5621b41e0f 100644 --- a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilder.java +++ b/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/grpc/util/EventMeshCloudEventBuilder.java @@ -157,7 +157,7 @@ private static CloudEvent switchEventMeshMessage2EventMeshCloudEvent(EventMeshMe CloudEventAttributeValue.newBuilder().setCeString(Constants.PROTOCOL_DESC_GRPC_CLOUD_EVENT).build()); attributeValueMap.put(ProtocolKey.PRODUCERGROUP, CloudEventAttributeValue.newBuilder().setCeString(clientConfig.getProducerGroup()).build()); - if (null != message.getTopic()) { + if (message.getTopic() != null) { attributeValueMap.put(ProtocolKey.SUBJECT, CloudEventAttributeValue.newBuilder().setCeString(message.getTopic()).build()); } attributeValueMap.put(ProtocolKey.DATA_CONTENT_TYPE, CloudEventAttributeValue.newBuilder().setCeString("text/plain").build()); diff --git a/eventmesh-security-plugin/eventmesh-security-auth-http-basic/src/main/java/org/apache/eventmesh/auth/http/basic/config/AuthConfigs.java b/eventmesh-security-plugin/eventmesh-security-auth-http-basic/src/main/java/org/apache/eventmesh/auth/http/basic/config/AuthConfigs.java index d9441c3a9a..f1d56d4e7f 100644 --- a/eventmesh-security-plugin/eventmesh-security-auth-http-basic/src/main/java/org/apache/eventmesh/auth/http/basic/config/AuthConfigs.java +++ b/eventmesh-security-plugin/eventmesh-security-auth-http-basic/src/main/java/org/apache/eventmesh/auth/http/basic/config/AuthConfigs.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.auth.http.basic.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import lombok.Data; @@ -26,9 +26,9 @@ @Config(prefix = "auth", path = "classPath://auth-http-basic.properties") public class AuthConfigs { - @ConfigFiled(field = "username") + @ConfigField(field = "username") private String username; - @ConfigFiled(field = "password") + @ConfigField(field = "password") public String password; } diff --git a/eventmesh-storage-plugin/eventmesh-storage-kafka/src/main/java/org/apache/eventmesh/storage/kafka/config/ClientConfiguration.java b/eventmesh-storage-plugin/eventmesh-storage-kafka/src/main/java/org/apache/eventmesh/storage/kafka/config/ClientConfiguration.java index 2e92877ec0..0eff16ec7c 100644 --- a/eventmesh-storage-plugin/eventmesh-storage-kafka/src/main/java/org/apache/eventmesh/storage/kafka/config/ClientConfiguration.java +++ b/eventmesh-storage-plugin/eventmesh-storage-kafka/src/main/java/org/apache/eventmesh/storage/kafka/config/ClientConfiguration.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.storage.kafka.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import lombok.AllArgsConstructor; import lombok.Builder; @@ -32,75 +32,75 @@ @AllArgsConstructor public class ClientConfiguration { - @ConfigFiled(field = "namesrvAddr", notEmpty = true) + @ConfigField(field = "namesrvAddr", notEmpty = true) @Builder.Default private String namesrvAddr = ""; - @ConfigFiled(field = "username") + @ConfigField(field = "username") @Builder.Default private String clientUserName = "username"; - @ConfigFiled(field = "password") + @ConfigField(field = "password") @Builder.Default private String clientPass = "password"; - @ConfigFiled(field = "num.partitions") + @ConfigField(field = "num.partitions") @Builder.Default private int partitions = 1; - @ConfigFiled(field = "num.replicationFactors") + @ConfigField(field = "num.replicationFactors") @Builder.Default private short replicationFactors = 1; - @ConfigFiled(field = "client.consumeThreadMin") + @ConfigField(field = "client.consumeThreadMin") @Builder.Default private Integer consumeThreadMin = 2; - @ConfigFiled(field = "client.consumeThreadMax") + @ConfigField(field = "client.consumeThreadMax") @Builder.Default private Integer consumeThreadMax = 2; - @ConfigFiled(field = "client.consumeThreadPoolQueueSize") + @ConfigField(field = "client.consumeThreadPoolQueueSize") @Builder.Default private Integer consumeQueueSize = 10000; - @ConfigFiled(field = "client.pullBatchSize") + @ConfigField(field = "client.pullBatchSize") @Builder.Default private Integer pullBatchSize = 32; - @ConfigFiled(field = "client.ackwindow") + @ConfigField(field = "client.ackwindow") @Builder.Default private Integer ackWindow = 1000; - @ConfigFiled(field = "client.pubwindow") + @ConfigField(field = "client.pubwindow") @Builder.Default private Integer pubWindow = 100; - @ConfigFiled(field = "client.comsumeTimeoutInMin") + @ConfigField(field = "client.comsumeTimeoutInMin") @Builder.Default private long consumeTimeout = 0L; - @ConfigFiled(field = "client.pollNameServerInterval") + @ConfigField(field = "client.pollNameServerInterval") @Builder.Default private Integer pollNameServerInterval = 10 * 1000; - @ConfigFiled(field = "client.heartbeatBrokerInterval") + @ConfigField(field = "client.heartbeatBrokerInterval") @Builder.Default private Integer heartbeatBrokerInterval = 30 * 1000; - @ConfigFiled(field = "client.rebalanceInterval") + @ConfigField(field = "client.rebalanceInterval") @Builder.Default private Integer rebalanceInterval = 20 * 1000; - @ConfigFiled(field = "cluster") + @ConfigField(field = "cluster") @Builder.Default private String clusterName = ""; - @ConfigFiled(field = "accessKey") + @ConfigField(field = "accessKey") @Builder.Default private String accessKey = ""; - @ConfigFiled(field = "secretKey") + @ConfigField(field = "secretKey") @Builder.Default private String secretKey = ""; } diff --git a/eventmesh-storage-plugin/eventmesh-storage-pulsar/src/main/java/org/apache/eventmesh/storage/pulsar/config/ClientConfiguration.java b/eventmesh-storage-plugin/eventmesh-storage-pulsar/src/main/java/org/apache/eventmesh/storage/pulsar/config/ClientConfiguration.java index 855faf80c8..f84628cf05 100644 --- a/eventmesh-storage-plugin/eventmesh-storage-pulsar/src/main/java/org/apache/eventmesh/storage/pulsar/config/ClientConfiguration.java +++ b/eventmesh-storage-plugin/eventmesh-storage-pulsar/src/main/java/org/apache/eventmesh/storage/pulsar/config/ClientConfiguration.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.storage.pulsar.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import lombok.Getter; import lombok.Setter; @@ -28,19 +28,19 @@ @Config(prefix = "eventMesh.server.pulsar", path = "classPath://pulsar-client.properties") public class ClientConfiguration { - @ConfigFiled(field = "service") + @ConfigField(field = "service") private String serviceAddr; - @ConfigFiled(field = "authPlugin") + @ConfigField(field = "authPlugin") private String authPlugin; - @ConfigFiled(field = "authParams") + @ConfigField(field = "authParams") private String authParams; /* * the full format of topic needs a prefix, but the prefix cannot be passed in the url when the topic is carried * */ - @ConfigFiled(field = "topicPrefix") + @ConfigField(field = "topicPrefix") private String topicPrefix; } \ No newline at end of file diff --git a/eventmesh-storage-plugin/eventmesh-storage-rabbitmq/src/main/java/org/apache/eventmesh/storage/rabbitmq/client/RabbitmqClient.java b/eventmesh-storage-plugin/eventmesh-storage-rabbitmq/src/main/java/org/apache/eventmesh/storage/rabbitmq/client/RabbitmqClient.java index 4e44c77fe3..678ba0884d 100644 --- a/eventmesh-storage-plugin/eventmesh-storage-rabbitmq/src/main/java/org/apache/eventmesh/storage/rabbitmq/client/RabbitmqClient.java +++ b/eventmesh-storage-plugin/eventmesh-storage-rabbitmq/src/main/java/org/apache/eventmesh/storage/rabbitmq/client/RabbitmqClient.java @@ -120,7 +120,7 @@ public void unbinding(Channel channel, String exchangeName, String routingKey, S * @param connection connection */ public void closeConnection(Connection connection) { - if (null != connection) { + if (connection != null) { try { connection.close(); } catch (Exception ex) { @@ -135,7 +135,7 @@ public void closeConnection(Connection connection) { * @param channel channel */ public void closeChannel(Channel channel) { - if (null != channel) { + if (channel != null) { try { channel.close(); } catch (Exception ex) { diff --git a/eventmesh-storage-plugin/eventmesh-storage-rabbitmq/src/main/java/org/apache/eventmesh/storage/rabbitmq/config/ConfigurationHolder.java b/eventmesh-storage-plugin/eventmesh-storage-rabbitmq/src/main/java/org/apache/eventmesh/storage/rabbitmq/config/ConfigurationHolder.java index 1bd1f6dc11..890e7d6d0d 100644 --- a/eventmesh-storage-plugin/eventmesh-storage-rabbitmq/src/main/java/org/apache/eventmesh/storage/rabbitmq/config/ConfigurationHolder.java +++ b/eventmesh-storage-plugin/eventmesh-storage-rabbitmq/src/main/java/org/apache/eventmesh/storage/rabbitmq/config/ConfigurationHolder.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.storage.rabbitmq.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import com.rabbitmq.client.BuiltinExchangeType; @@ -28,39 +28,39 @@ @Config(prefix = "eventMesh.server.rabbitmq", path = "classPath://rabbitmq-client.properties") public class ConfigurationHolder { - @ConfigFiled(field = "host") + @ConfigField(field = "host") private String host; - @ConfigFiled(field = "port") + @ConfigField(field = "port") private int port; - @ConfigFiled(field = "username") + @ConfigField(field = "username") private String username; - @ConfigFiled(field = "passwd") + @ConfigField(field = "passwd") private String passwd; - @ConfigFiled(field = "virtualHost") + @ConfigField(field = "virtualHost") private String virtualHost; - @ConfigFiled(field = "exchangeType") + @ConfigField(field = "exchangeType") private BuiltinExchangeType exchangeType; - @ConfigFiled(field = "exchangeName") + @ConfigField(field = "exchangeName") private String exchangeName; - @ConfigFiled(field = "routingKey") + @ConfigField(field = "routingKey") private String routingKey; - @ConfigFiled(field = "queueName") + @ConfigField(field = "queueName") private String queueName; - @ConfigFiled(field = "autoAck") + @ConfigField(field = "autoAck") private boolean autoAck; - @ConfigFiled(field = "mgmt.port") + @ConfigField(field = "mgmt.port") private int mgmtPort; - @ConfigFiled(field = "mgmt.protocol") + @ConfigField(field = "mgmt.protocol") private String mgmtProtocol; } diff --git a/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/java/org/apache/eventmesh/storage/redis/config/RedisProperties.java b/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/java/org/apache/eventmesh/storage/redis/config/RedisProperties.java index dd01837397..a478e7a70f 100644 --- a/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/java/org/apache/eventmesh/storage/redis/config/RedisProperties.java +++ b/eventmesh-storage-plugin/eventmesh-storage-redis/src/main/java/org/apache/eventmesh/storage/redis/config/RedisProperties.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.storage.redis.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import java.util.Properties; @@ -31,31 +31,31 @@ public class RedisProperties { /** * The redis server configuration to be used. */ - @ConfigFiled(field = "serverType") + @ConfigField(field = "serverType") private ServerType serverType = ServerType.SINGLE; /** * The master server name used by Redis Sentinel servers and master change monitoring task. */ - @ConfigFiled(field = "serverMasterName") + @ConfigField(field = "serverMasterName") private String serverMasterName = "master"; /** * The address of the redis server following format -- host1:port1,host2:port2,…… */ - @ConfigFiled(field = "serverAddress") + @ConfigField(field = "serverAddress") private String serverAddress; /** * The password for redis authentication. */ - @ConfigFiled(field = "serverPassword") + @ConfigField(field = "serverPassword") private String serverPassword; /** * The redisson options, redisson properties prefix is `eventMesh.server.redis.redisson` */ - @ConfigFiled(field = "redisson") + @ConfigField(field = "redisson") private Properties redissonProperties; public enum ServerType { diff --git a/eventmesh-storage-plugin/eventmesh-storage-rocketmq/src/main/java/org/apache/eventmesh/storage/rocketmq/config/ClientConfiguration.java b/eventmesh-storage-plugin/eventmesh-storage-rocketmq/src/main/java/org/apache/eventmesh/storage/rocketmq/config/ClientConfiguration.java index 04654a6b3e..b1748de895 100644 --- a/eventmesh-storage-plugin/eventmesh-storage-rocketmq/src/main/java/org/apache/eventmesh/storage/rocketmq/config/ClientConfiguration.java +++ b/eventmesh-storage-plugin/eventmesh-storage-rocketmq/src/main/java/org/apache/eventmesh/storage/rocketmq/config/ClientConfiguration.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.storage.rocketmq.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import lombok.AllArgsConstructor; import lombok.Builder; @@ -32,67 +32,67 @@ @NoArgsConstructor public class ClientConfiguration { - @ConfigFiled(field = "namesrvAddr", notEmpty = true) + @ConfigField(field = "namesrvAddr", notEmpty = true) @Builder.Default private String namesrvAddr = ""; - @ConfigFiled(field = "username") + @ConfigField(field = "username") @Builder.Default private String clientUserName = "username"; - @ConfigFiled(field = "password") + @ConfigField(field = "password") @Builder.Default private String clientPass = "password"; - @ConfigFiled(field = "client.consumeThreadMin") + @ConfigField(field = "client.consumeThreadMin") @Builder.Default private Integer consumeThreadMin = 2; - @ConfigFiled(field = "client.consumeThreadMax") + @ConfigField(field = "client.consumeThreadMax") @Builder.Default private Integer consumeThreadMax = 2; - @ConfigFiled(field = "client.consumeThreadPoolQueueSize") + @ConfigField(field = "client.consumeThreadPoolQueueSize") @Builder.Default private Integer consumeQueueSize = 10000; - @ConfigFiled(field = "client.pullBatchSize") + @ConfigField(field = "client.pullBatchSize") @Builder.Default private Integer pullBatchSize = 32; - @ConfigFiled(field = "client.ackwindow") + @ConfigField(field = "client.ackwindow") @Builder.Default private Integer ackWindow = 1000; - @ConfigFiled(field = "client.pubwindow") + @ConfigField(field = "client.pubwindow") @Builder.Default private Integer pubWindow = 100; - @ConfigFiled(field = "client.comsumeTimeoutInMin") + @ConfigField(field = "client.comsumeTimeoutInMin") @Builder.Default private long consumeTimeout = 0L; - @ConfigFiled(field = "client.pollNameServerInterval") + @ConfigField(field = "client.pollNameServerInterval") @Builder.Default private Integer pollNameServerInterval = 10 * 1000; - @ConfigFiled(field = "client.heartbeatBrokerInterval") + @ConfigField(field = "client.heartbeatBrokerInterval") @Builder.Default private Integer heartbeatBrokerInterval = 30 * 1000; - @ConfigFiled(field = "client.rebalanceInterval") + @ConfigField(field = "client.rebalanceInterval") @Builder.Default private Integer rebalanceInterval = 20 * 1000; - @ConfigFiled(field = "cluster") + @ConfigField(field = "cluster") @Builder.Default private String clusterName = ""; - @ConfigFiled(field = "accessKey") + @ConfigField(field = "accessKey") @Builder.Default private String accessKey = ""; - @ConfigFiled(field = "secretKey") + @ConfigField(field = "secretKey") @Builder.Default private String secretKey = ""; } diff --git a/eventmesh-trace-plugin/eventmesh-trace-api/src/main/java/org/apache/eventmesh/trace/api/config/ExporterConfiguration.java b/eventmesh-trace-plugin/eventmesh-trace-api/src/main/java/org/apache/eventmesh/trace/api/config/ExporterConfiguration.java index b59eed4431..ab42241e0a 100644 --- a/eventmesh-trace-plugin/eventmesh-trace-api/src/main/java/org/apache/eventmesh/trace/api/config/ExporterConfiguration.java +++ b/eventmesh-trace-plugin/eventmesh-trace-api/src/main/java/org/apache/eventmesh/trace/api/config/ExporterConfiguration.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.trace.api.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import lombok.Data; @@ -29,15 +29,15 @@ @Config(prefix = "eventmesh.trace", path = "classPath://exporter.properties") public class ExporterConfiguration { - @ConfigFiled(field = "max.export.size") + @ConfigField(field = "max.export.size") private int eventMeshTraceMaxExportSize = 512; - @ConfigFiled(field = "max.queue.size") + @ConfigField(field = "max.queue.size") private int eventMeshTraceMaxQueueSize = 2048; - @ConfigFiled(field = "export.timeout") + @ConfigField(field = "export.timeout") private int eventMeshTraceExportTimeout = 30; - @ConfigFiled(field = "export.interval") + @ConfigField(field = "export.interval") private int eventMeshTraceExportInterval = 5; } diff --git a/eventmesh-trace-plugin/eventmesh-trace-jaeger/src/main/java/org/apache/eventmesh/trace/jaeger/config/JaegerConfiguration.java b/eventmesh-trace-plugin/eventmesh-trace-jaeger/src/main/java/org/apache/eventmesh/trace/jaeger/config/JaegerConfiguration.java index 1e60ca665f..2284a4f22c 100644 --- a/eventmesh-trace-plugin/eventmesh-trace-jaeger/src/main/java/org/apache/eventmesh/trace/jaeger/config/JaegerConfiguration.java +++ b/eventmesh-trace-plugin/eventmesh-trace-jaeger/src/main/java/org/apache/eventmesh/trace/jaeger/config/JaegerConfiguration.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.trace.jaeger.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import lombok.Data; @@ -26,9 +26,9 @@ @Config(prefix = "eventmesh.trace.jaeger", path = "classPath://jaeger.properties") public class JaegerConfiguration { - @ConfigFiled(field = "ip", notEmpty = true) + @ConfigField(field = "ip", notEmpty = true) private String eventMeshJaegerIp = "localhost"; - @ConfigFiled(field = "port", notEmpty = true) + @ConfigField(field = "port", notEmpty = true) private int eventMeshJaegerPort = 14250; } \ No newline at end of file diff --git a/eventmesh-trace-plugin/eventmesh-trace-pinpoint/src/main/java/org/apache/eventmesh/trace/pinpoint/config/PinpointConfiguration.java b/eventmesh-trace-plugin/eventmesh-trace-pinpoint/src/main/java/org/apache/eventmesh/trace/pinpoint/config/PinpointConfiguration.java index 8ffe6655fc..dd29412521 100644 --- a/eventmesh-trace-plugin/eventmesh-trace-pinpoint/src/main/java/org/apache/eventmesh/trace/pinpoint/config/PinpointConfiguration.java +++ b/eventmesh-trace-plugin/eventmesh-trace-pinpoint/src/main/java/org/apache/eventmesh/trace/pinpoint/config/PinpointConfiguration.java @@ -19,7 +19,7 @@ import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import org.apache.eventmesh.common.exception.JsonException; import org.apache.eventmesh.common.utils.RandomStringUtils; @@ -37,16 +37,16 @@ @Config(prefix = "eventmesh.trace.pinpoint", path = "classPath://pinpoint.properties") public final class PinpointConfiguration { - @ConfigFiled(field = "agentId", reload = true) + @ConfigField(field = "agentId", reload = true) private String agentId; - @ConfigFiled(field = "agentName", reload = true) + @ConfigField(field = "agentName", reload = true) private String agentName; - @ConfigFiled(field = "applicationName", findEnv = true, notNull = true) + @ConfigField(field = "applicationName", findEnv = true, notNull = true) private String applicationName; - @ConfigFiled(field = "", reload = true) + @ConfigField(field = "", reload = true) private Properties grpcTransportProperties; private GrpcTransportConfig grpcTransportConfig; diff --git a/eventmesh-trace-plugin/eventmesh-trace-zipkin/src/main/java/org/apache/eventmesh/trace/zipkin/config/ZipkinConfiguration.java b/eventmesh-trace-plugin/eventmesh-trace-zipkin/src/main/java/org/apache/eventmesh/trace/zipkin/config/ZipkinConfiguration.java index fcc2ac0dec..ed24036878 100644 --- a/eventmesh-trace-plugin/eventmesh-trace-zipkin/src/main/java/org/apache/eventmesh/trace/zipkin/config/ZipkinConfiguration.java +++ b/eventmesh-trace-plugin/eventmesh-trace-zipkin/src/main/java/org/apache/eventmesh/trace/zipkin/config/ZipkinConfiguration.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.trace.zipkin.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import lombok.Data; @@ -30,9 +30,9 @@ @Config(prefix = "eventmesh.trace.zipkin", path = "classPath://zipkin.properties") public class ZipkinConfiguration { - @ConfigFiled(field = "ip", notNull = true) + @ConfigField(field = "ip", notNull = true) private String eventMeshZipkinIP = "localhost"; - @ConfigFiled(field = "port") + @ConfigField(field = "port") private int eventMeshZipkinPort = 9411; } diff --git a/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/config/AdminConfiguration.java b/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/config/AdminConfiguration.java index 93327d54bf..1bbba42fe8 100644 --- a/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/config/AdminConfiguration.java +++ b/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/config/AdminConfiguration.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.webhook.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import java.util.Properties; @@ -28,13 +28,13 @@ @Config(prefix = "eventMesh.webHook") public class AdminConfiguration { - @ConfigFiled(field = "admin.start") + @ConfigField(field = "admin.start") private boolean adminStart = false; - @ConfigFiled(field = "operationMode") + @ConfigField(field = "operationMode") private String operationMode; - @ConfigFiled(field = "", reload = true) + @ConfigField(field = "", reload = true) private Properties operationProperties; public void reload() { diff --git a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/config/ReceiveConfiguration.java b/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/config/ReceiveConfiguration.java index 3d3004c5ce..fef6cee41b 100644 --- a/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/config/ReceiveConfiguration.java +++ b/eventmesh-webhook/eventmesh-webhook-receive/src/main/java/org/apache/eventmesh/webhook/receive/config/ReceiveConfiguration.java @@ -18,7 +18,7 @@ package org.apache.eventmesh.webhook.receive.config; import org.apache.eventmesh.common.config.Config; -import org.apache.eventmesh.common.config.ConfigFiled; +import org.apache.eventmesh.common.config.ConfigField; import java.util.Properties; @@ -28,16 +28,16 @@ @Config(prefix = "eventMesh.webHook") public class ReceiveConfiguration { - @ConfigFiled(field = "producer.storage") + @ConfigField(field = "producer.storage") private String storagePluginType; - @ConfigFiled(field = "operationMode") + @ConfigField(field = "operationMode") private String operationMode; - @ConfigFiled(field = "fileMode.filePath") + @ConfigField(field = "fileMode.filePath") private String filePath; - @ConfigFiled(field = "", reload = true) + @ConfigField(field = "", reload = true) private Properties operationProperties; public void reload() { diff --git a/settings.gradle b/settings.gradle index ec1eb4c5ec..32d2c2e261 100644 --- a/settings.gradle +++ b/settings.gradle @@ -126,6 +126,7 @@ include 'eventmesh-webhook:eventmesh-webhook-receive' include 'eventmesh-retry' include 'eventmesh-retry:eventmesh-retry-api' include 'eventmesh-retry:eventmesh-retry-rocketmq' +include 'eventmesh-runtime-v2' include 'eventmesh-admin-server' include 'eventmesh-registry' include 'eventmesh-registry:eventmesh-registry-api' diff --git a/tools/dependency-check/known-dependencies.txt b/tools/dependency-check/known-dependencies.txt index ccf34353e3..b30ca5d5ed 100644 --- a/tools/dependency-check/known-dependencies.txt +++ b/tools/dependency-check/known-dependencies.txt @@ -78,7 +78,8 @@ endpoints-spi-2.20.29.jar error_prone_annotations-2.9.0.jar eventstream-1.0.1.jar failureaccess-1.0.1.jar -fastjson-1.2.83.jar +fastjson-1.2.69_noneautotype.jar +fastjson2-2.0.48.jar gateway-dingtalk-1.0.2.jar google-auth-library-credentials-0.22.2.jar grpc-api-1.43.2.jar diff --git a/tools/third-party-licenses/LICENSE b/tools/third-party-licenses/LICENSE index de086f4883..20c482188e 100644 --- a/tools/third-party-licenses/LICENSE +++ b/tools/third-party-licenses/LICENSE @@ -251,7 +251,7 @@ The text of each license is also included at licenses/LICENSE-[project].txt. error_prone_annotations 2.7.1: https://github.com/google/error-prone, Apache 2.0 failureaccess 1.0.1: https://github.com/google/guava, Apache 2.0 listenablefuture 9999.0-empty-to-avoid-conflict-with-guava: https://github.com/google/guava, Apache 2.0 - fastjson 1.2.83: https://github.com/alibaba/fastjson, Apache 2.0 + fastjson2 2.0.48: https://github.com/alibaba/fastjson2, Apache 2.0 guava 31.0.1-jre: https://github.com/google/guava, Apache 2.0 gateway-dingtalk 1.0.2: https://github.com/aliyun/alibabacloud-gateway, Apache 2.0 guice 4.2.2: https://github.com/google/guice, Apache 2.0