Skip to content

Commit c2af2d4

Browse files
authored
[ISSUE #4812] Set up Admin Endpoints v2 (#4813)
* Remove redundant overloaded methods * Simplify write() result param * Add writeJson(); Add PUT; Add JavaDoc * Rename EventHttpHandler to EventMeshHttpHandler * Correct server thread name * Clean up messy & non-hierarchical overloading * No need to set headers manually any more * Set up v1&v2 endpoints * Set up v1&v2 response dto * Introduce fastjson2 * Fix fastjson2 "level too large : 2048" error caused by IPAddress * Correct @ConfigField naming * Return properties format json key * Add format option to query string * Introduce Result * Reduce duplicate builder code * Fix all checkstyle warnings in eventmesh-runtime * Add known dependency
1 parent f45141d commit c2af2d4

File tree

68 files changed

+858
-748
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+858
-748
lines changed

Diff for: build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,8 @@ subprojects {
569569
dependency "org.projectlombok:lombok:1.18.22"
570570
dependency "com.github.seancfoley:ipaddress:5.3.3"
571571
dependency "javax.annotation:javax.annotation-api:1.3.2"
572-
dependency "com.alibaba:fastjson:1.2.83"
572+
dependency "com.alibaba:fastjson:1.2.83" // TODO migrate to fastjson2
573+
dependency "com.alibaba.fastjson2:fastjson2:2.0.48"
573574

574575
dependency "software.amazon.awssdk:s3:2.20.29"
575576
dependency "com.github.rholder:guava-retrying:2.0.0"

Diff for: eventmesh-common/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ dependencies {
3030
api "io.cloudevents:cloudevents-core"
3131
api "io.cloudevents:cloudevents-json-jackson"
3232

33+
api "com.alibaba.fastjson2:fastjson2"
34+
3335
implementation "org.apache.logging.log4j:log4j-api"
3436
implementation "org.apache.logging.log4j:log4j-core"
3537
implementation "org.apache.logging.log4j:log4j-slf4j2-impl"

Diff for: eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java

+26-26
Original file line numberDiff line numberDiff line change
@@ -37,82 +37,82 @@
3737
@Config(prefix = "eventMesh")
3838
public class CommonConfiguration {
3939

40-
@ConfigFiled(field = "sysid", beNumber = true, notEmpty = true)
40+
@ConfigField(field = "sysid", beNumber = true, notEmpty = true)
4141
private String sysID = "5477";
4242

43-
@ConfigFiled(field = "server.env", notEmpty = true)
43+
@ConfigField(field = "server.env", notEmpty = true)
4444
private String eventMeshEnv = "P";
4545

46-
@ConfigFiled(field = "server.idc", notEmpty = true)
46+
@ConfigField(field = "server.idc", notEmpty = true)
4747
private String eventMeshIDC = "FT";
4848

49-
@ConfigFiled(field = "server.name", notEmpty = true)
49+
@ConfigField(field = "server.name", notEmpty = true)
5050
private String eventMeshName = "";
5151

52-
@ConfigFiled(field = "server.cluster", notEmpty = true)
52+
@ConfigField(field = "server.cluster", notEmpty = true)
5353
private String eventMeshCluster = "LS";
5454

55-
@ConfigFiled(field = "server.hostIp", reload = true)
55+
@ConfigField(field = "server.hostIp", reload = true)
5656
private String eventMeshServerIp = null;
5757

58-
@ConfigFiled(field = "metaStorage.plugin.server-addr", notEmpty = true)
58+
@ConfigField(field = "metaStorage.plugin.server-addr", notEmpty = true)
5959
private String metaStorageAddr = "";
6060

61-
@ConfigFiled(field = "metaStorage.plugin.type", notEmpty = true)
61+
@ConfigField(field = "metaStorage.plugin.type", notEmpty = true)
6262
private String eventMeshMetaStoragePluginType = "nacos";
6363

64-
@ConfigFiled(field = "metaStorage.plugin.username")
64+
@ConfigField(field = "metaStorage.plugin.username")
6565
private String eventMeshMetaStoragePluginUsername = "";
6666

67-
@ConfigFiled(field = "metaStorage.plugin.password")
67+
@ConfigField(field = "metaStorage.plugin.password")
6868
private String eventMeshMetaStoragePluginPassword = "";
6969

70-
@ConfigFiled(field = "metaStorage.plugin.metaStorageIntervalInMills")
70+
@ConfigField(field = "metaStorage.plugin.metaStorageIntervalInMills")
7171
private Integer eventMeshMetaStorageIntervalInMills = 10 * 1000;
7272

73-
@ConfigFiled(field = "metaStorage.plugin.fetchMetaStorageAddrIntervalInMills")
73+
@ConfigField(field = "metaStorage.plugin.fetchMetaStorageAddrIntervalInMills")
7474
private Integer eventMeshFetchMetaStorageAddrInterval = 10 * 1000;
7575

76-
@ConfigFiled(field = "metaStorage.plugin.enabled")
76+
@ConfigField(field = "metaStorage.plugin.enabled")
7777
private boolean eventMeshServerMetaStorageEnable = false;
7878

79-
@ConfigFiled(field = "trace.plugin", notEmpty = true)
79+
@ConfigField(field = "trace.plugin", notEmpty = true)
8080
private String eventMeshTracePluginType;
8181

82-
@ConfigFiled(field = "metrics.plugin", notEmpty = true)
82+
@ConfigField(field = "metrics.plugin", notEmpty = true)
8383
private List<String> eventMeshMetricsPluginType;
8484

85-
@ConfigFiled(field = "security.plugin.type", notEmpty = true)
85+
@ConfigField(field = "security.plugin.type", notEmpty = true)
8686
private String eventMeshSecurityPluginType = "security";
8787

88-
@ConfigFiled(field = "connector.plugin.type", notEmpty = true)
88+
@ConfigField(field = "connector.plugin.type", notEmpty = true)
8989
private String eventMeshConnectorPluginType = "rocketmq";
9090

91-
@ConfigFiled(field = "storage.plugin.type", notEmpty = true)
91+
@ConfigField(field = "storage.plugin.type", notEmpty = true)
9292
private String eventMeshStoragePluginType = "rocketmq";
9393

94-
@ConfigFiled(field = "security.validation.type.token", notEmpty = true)
94+
@ConfigField(field = "security.validation.type.token", notEmpty = true)
9595
private boolean eventMeshSecurityValidateTypeToken = false;
9696

97-
@ConfigFiled(field = "server.trace.enabled")
97+
@ConfigField(field = "server.trace.enabled")
9898
private boolean eventMeshServerTraceEnable = false;
9999

100-
@ConfigFiled(field = "server.security.enabled")
100+
@ConfigField(field = "server.security.enabled")
101101
private boolean eventMeshServerSecurityEnable = false;
102102

103-
@ConfigFiled(field = "security.publickey")
103+
@ConfigField(field = "security.publickey")
104104
private String eventMeshSecurityPublickey = "";
105105

106-
@ConfigFiled(field = "server.provide.protocols", reload = true)
106+
@ConfigField(field = "server.provide.protocols", reload = true)
107107
private List<String> eventMeshProvideServerProtocols;
108108

109-
@ConfigFiled(reload = true)
109+
@ConfigField(reload = true)
110110
private String eventMeshWebhookOrigin;
111111

112-
@ConfigFiled(reload = true)
112+
@ConfigField(reload = true)
113113
private String meshGroup;
114114

115-
@ConfigFiled(field = "server.retry.plugin.type")
115+
@ConfigField(field = "server.retry.plugin.type")
116116
private String eventMeshRetryPluginType = Constants.DEFAULT;
117117

118118
public void reload() {

Diff for: eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigFiled.java renamed to eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigField.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
@Retention(RetentionPolicy.RUNTIME)
3131
@Target({ElementType.TYPE, ElementType.FIELD})
32-
public @interface ConfigFiled {
32+
public @interface ConfigField {
3333

3434
/**
3535
* @return The key name of the configuration file

Diff for: eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/ConvertValue.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.eventmesh.common.config.convert;
1919

20-
import org.apache.eventmesh.common.config.ConfigFiled;
20+
import org.apache.eventmesh.common.config.ConfigField;
2121

2222
import org.apache.commons.lang3.StringUtils;
2323

@@ -44,7 +44,7 @@ default boolean canHandleNullValue() {
4444
/**
4545
* @return The value converter needs
4646
*/
47-
default Object processFieldValue(ConvertInfo convertInfo, String key, ConfigFiled configFiled) {
47+
default Object processFieldValue(ConvertInfo convertInfo, String key, ConfigField configField) {
4848
Properties properties = convertInfo.getProperties();
4949
String value = properties.getProperty(key);
5050

@@ -54,14 +54,14 @@ default Object processFieldValue(ConvertInfo convertInfo, String key, ConfigFile
5454

5555
value = value.trim();
5656

57-
boolean findEnv = configFiled.findEnv();
58-
String fieldName = configFiled.field();
57+
boolean findEnv = configField.findEnv();
58+
String fieldName = configField.field();
5959

6060
if (StringUtils.isBlank(value) && !StringUtils.isBlank(fieldName) && findEnv) {
6161
value = Optional.ofNullable(System.getProperty(fieldName)).orElse(System.getenv(fieldName));
6262
}
6363

64-
if (StringUtils.isBlank(value) && configFiled.notEmpty()) {
64+
if (StringUtils.isBlank(value) && configField.notEmpty()) {
6565
throw new RuntimeException(key + " can't be empty!");
6666
}
6767

Diff for: eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/ConverterMap.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.eventmesh.common.config.convert;
1919

20-
import org.apache.eventmesh.common.config.ConfigFiled;
20+
import org.apache.eventmesh.common.config.ConfigField;
2121
import org.apache.eventmesh.common.config.convert.converter.BaseDataTypeConverter;
2222
import org.apache.eventmesh.common.config.convert.converter.DateConverter;
2323
import org.apache.eventmesh.common.config.convert.converter.EnumConverter;
@@ -96,9 +96,9 @@ public static void register(ConvertValue<?> convertValue, Class<?>... clazzs) {
9696
*/
9797
public static ConvertValue<?> getFieldConverter(Field field) {
9898
Class<?> clazz = field.getType();
99-
ConfigFiled configFiled = field.getAnnotation(ConfigFiled.class);
99+
ConfigField configField = field.getAnnotation(ConfigField.class);
100100

101-
Class<?> converter1 = configFiled.converter();
101+
Class<?> converter1 = configField.converter();
102102
if (!converter1.equals(ConvertValue.DefaultConverter.class)) {
103103
if (!classToConverter.containsKey(converter1)) {
104104
try {

Diff for: eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/converter/ObjectConverter.java

+18-18
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.apache.eventmesh.common.config.convert.converter;
1919

2020
import org.apache.eventmesh.common.config.Config;
21-
import org.apache.eventmesh.common.config.ConfigFiled;
21+
import org.apache.eventmesh.common.config.ConfigField;
2222
import org.apache.eventmesh.common.config.ConfigInfo;
2323
import org.apache.eventmesh.common.config.convert.ConvertInfo;
2424
import org.apache.eventmesh.common.config.convert.ConvertValue;
@@ -110,26 +110,26 @@ private void setValue() throws Exception {
110110
field.setAccessible(true);
111111

112112
ConvertInfo convertInfo = this.convertInfo;
113-
ConfigFiled configFiled = field.getAnnotation(ConfigFiled.class);
114-
if (Objects.isNull(configFiled)) {
113+
ConfigField configField = field.getAnnotation(ConfigField.class);
114+
if (Objects.isNull(configField)) {
115115
continue;
116116
}
117117

118-
String key = this.buildKey(configFiled);
119-
needReload = this.checkNeedReload(needReload, configFiled);
118+
String key = this.buildKey(configField);
119+
needReload = this.checkNeedReload(needReload, configField);
120120

121121
ConvertValue<?> convertValue = ConverterMap.getFieldConverter(field);
122-
Object fieldValue = convertValue.processFieldValue(convertInfo, key, configFiled);
122+
Object fieldValue = convertValue.processFieldValue(convertInfo, key, configField);
123123

124-
if (!checkFieldValueBefore(configFiled, key, convertValue, fieldValue)) {
124+
if (!checkFieldValueBefore(configField, key, convertValue, fieldValue)) {
125125
continue;
126126
}
127127
convertInfo.setValue(fieldValue);
128128
convertInfo.setField(field);
129129
convertInfo.setKey(key);
130130
Object convertedValue = convertValue.convert(convertInfo);
131131

132-
if (!checkFieldValueAfter(configFiled, key, convertedValue)) {
132+
if (!checkFieldValueAfter(configField, key, convertedValue)) {
133133
continue;
134134
}
135135
field.set(object, convertedValue);
@@ -155,16 +155,16 @@ private void reloadConfigIfNeed(boolean needReload) throws NoSuchMethodException
155155
}
156156
}
157157

158-
private boolean checkFieldValueAfter(ConfigFiled configFiled, String key, Object convertedValue) {
158+
private boolean checkFieldValueAfter(ConfigField configField, String key, Object convertedValue) {
159159
if (Objects.isNull(convertedValue)) {
160-
if (configFiled.notNull()) {
160+
if (configField.notNull()) {
161161
throw new RuntimeException(key + " can not be null!");
162162
}
163163

164164
return false;
165165
}
166166

167-
if (configFiled.beNumber()) {
167+
if (configField.beNumber()) {
168168
if (!StringUtils.isNumeric(String.valueOf(convertedValue))) {
169169
throw new RuntimeException(key + " must be number!");
170170
}
@@ -173,9 +173,9 @@ private boolean checkFieldValueAfter(ConfigFiled configFiled, String key, Object
173173
return true;
174174
}
175175

176-
private boolean checkFieldValueBefore(ConfigFiled configFiled, String key, ConvertValue<?> convertValue, Object fieldValue) {
176+
private boolean checkFieldValueBefore(ConfigField configField, String key, ConvertValue<?> convertValue, Object fieldValue) {
177177
if (Objects.isNull(fieldValue) && !convertValue.canHandleNullValue()) {
178-
if (configFiled.notNull()) {
178+
if (configField.notNull()) {
179179
throw new RuntimeException(key + " can not be null!");
180180
}
181181

@@ -185,8 +185,8 @@ private boolean checkFieldValueBefore(ConfigFiled configFiled, String key, Conve
185185
return true;
186186
}
187187

188-
private boolean checkNeedReload(boolean needReload, ConfigFiled configFiled) {
189-
if (!needReload && configFiled != null && configFiled.reload()) {
188+
private boolean checkNeedReload(boolean needReload, ConfigField configField) {
189+
if (!needReload && configField != null && configField.reload()) {
190190
needReload = Boolean.TRUE;
191191
}
192192

@@ -201,14 +201,14 @@ private boolean checkNeedReload(boolean needReload, ConfigFiled configFiled) {
201201
return needReload;
202202
}
203203

204-
private String buildKey(ConfigFiled configFiled) {
204+
private String buildKey(ConfigField configField) {
205205
String key;
206206
StringBuilder keyPrefix = new StringBuilder(Objects.isNull(prefix) ? "" : prefix);
207207

208-
if (configFiled == null || configFiled.field().isEmpty() && keyPrefix.length() > 0) {
208+
if (configField == null || configField.field().isEmpty() && keyPrefix.length() > 0) {
209209
key = keyPrefix.deleteCharAt(keyPrefix.length() - 1).toString();
210210
} else {
211-
key = keyPrefix.append(configFiled.field()).toString();
211+
key = keyPrefix.append(configField.field()).toString();
212212
}
213213

214214
return key;

Diff for: eventmesh-common/src/main/java/org/apache/eventmesh/common/config/convert/converter/PropertiesConverter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.eventmesh.common.config.convert.converter;
1919

20-
import org.apache.eventmesh.common.config.ConfigFiled;
20+
import org.apache.eventmesh.common.config.ConfigField;
2121
import org.apache.eventmesh.common.config.convert.ConvertInfo;
2222
import org.apache.eventmesh.common.config.convert.ConvertValue;
2323
import org.apache.eventmesh.common.utils.PropertiesUtils;
@@ -41,7 +41,7 @@ public Properties convert(ConvertInfo convertInfo) {
4141
}
4242

4343
@Override
44-
public Object processFieldValue(ConvertInfo convertInfo, String prefix, ConfigFiled configFiled) {
44+
public Object processFieldValue(ConvertInfo convertInfo, String prefix, ConfigField configField) {
4545
Properties properties = convertInfo.getProperties();
4646

4747
if (StringUtils.isBlank(prefix)) {

Diff for: eventmesh-meta/eventmesh-meta-consul/src/main/java/org/apache/eventmesh/meta/consul/config/ConsulTLSConfig.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.apache.eventmesh.meta.consul.config;
1919

2020
import org.apache.eventmesh.common.config.Config;
21-
import org.apache.eventmesh.common.config.ConfigFiled;
21+
import org.apache.eventmesh.common.config.ConfigField;
2222
import org.apache.eventmesh.common.config.convert.converter.EnumConverter;
2323

2424
import com.ecwid.consul.transport.TLSConfig.KeyStoreInstanceType;
@@ -31,19 +31,19 @@
3131
@Config(prefix = "eventMesh.registry.consul.tls")
3232
public class ConsulTLSConfig {
3333

34-
@ConfigFiled(field = "keyStoreInstanceType", converter = EnumConverter.class)
34+
@ConfigField(field = "keyStoreInstanceType", converter = EnumConverter.class)
3535
private KeyStoreInstanceType keyStoreInstanceType;
3636

37-
@ConfigFiled(field = "certificatePath")
37+
@ConfigField(field = "certificatePath")
3838
private String certificatePath;
3939

40-
@ConfigFiled(field = "certificatePassword")
40+
@ConfigField(field = "certificatePassword")
4141
private String certificatePassword;
4242

43-
@ConfigFiled(field = "keyStorePath")
43+
@ConfigField(field = "keyStorePath")
4444
private String keyStorePath;
4545

46-
@ConfigFiled(field = "keyStorePassword")
46+
@ConfigField(field = "keyStorePassword")
4747
private String keyStorePassword;
4848

4949
}

Diff for: eventmesh-meta/eventmesh-meta-nacos/src/main/java/org/apache/eventmesh/meta/nacos/config/NacosMetaStorageConfiguration.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package org.apache.eventmesh.meta.nacos.config;
1919

2020
import org.apache.eventmesh.common.config.Config;
21-
import org.apache.eventmesh.common.config.ConfigFiled;
21+
import org.apache.eventmesh.common.config.ConfigField;
2222

2323
import com.alibaba.nacos.api.PropertyKeyConst;
2424
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
@@ -31,31 +31,31 @@
3131
@Config(prefix = "eventMesh.metaStorage.nacos")
3232
public class NacosMetaStorageConfiguration {
3333

34-
@ConfigFiled(field = PropertyKeyConst.ENDPOINT)
34+
@ConfigField(field = PropertyKeyConst.ENDPOINT)
3535
private String endpoint;
3636

37-
@ConfigFiled(field = PropertyKeyConst.ENDPOINT_PORT)
37+
@ConfigField(field = PropertyKeyConst.ENDPOINT_PORT)
3838
private String endpointPort;
3939

40-
@ConfigFiled(field = PropertyKeyConst.ACCESS_KEY)
40+
@ConfigField(field = PropertyKeyConst.ACCESS_KEY)
4141
private String accessKey;
4242

43-
@ConfigFiled(field = PropertyKeyConst.SECRET_KEY)
43+
@ConfigField(field = PropertyKeyConst.SECRET_KEY)
4444
private String secretKey;
4545

46-
@ConfigFiled(field = PropertyKeyConst.CLUSTER_NAME)
46+
@ConfigField(field = PropertyKeyConst.CLUSTER_NAME)
4747
private String clusterName;
4848

49-
@ConfigFiled(field = PropertyKeyConst.NAMESPACE)
49+
@ConfigField(field = PropertyKeyConst.NAMESPACE)
5050
private String namespace;
5151

52-
@ConfigFiled(field = PropertyKeyConst.NAMING_POLLING_THREAD_COUNT)
52+
@ConfigField(field = PropertyKeyConst.NAMING_POLLING_THREAD_COUNT)
5353
private Integer pollingThreadCount = Runtime.getRuntime().availableProcessors() / 2 + 1;
5454

55-
@ConfigFiled(field = UtilAndComs.NACOS_NAMING_LOG_NAME)
55+
@ConfigField(field = UtilAndComs.NACOS_NAMING_LOG_NAME)
5656
private String logFileName;
5757

58-
@ConfigFiled(field = UtilAndComs.NACOS_NAMING_LOG_LEVEL)
58+
@ConfigField(field = UtilAndComs.NACOS_NAMING_LOG_LEVEL)
5959
private String logLevel;
6060

6161
}

0 commit comments

Comments
 (0)