This is an automated email from the ASF dual-hosted git repository.
achao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 21118286ee [type:feature] namespace sync (#5672)
21118286ee is described below
commit 21118286ee64e69bf2dcb0ae917117ef1543ac2d
Author: aias00 <[email protected]>
AuthorDate: Thu Sep 26 13:16:04 2024 +0800
[type:feature] namespace sync (#5672)
---
.../org/apache/shenyu/common/dto/MetaData.java | 51 ++++++++++++++++++++--
.../org/apache/shenyu/common/dto/RuleData.java | 40 ++++++++++++++++-
.../org/apache/shenyu/common/dto/MetaDataTest.java | 2 +-
.../shenyu/e2e/model/data/RuleCacheData.java | 44 ++++++++++++++++++-
.../apache/shenyu/plugin/tars/TarsPluginTest.java | 2 +-
.../tars/cache/ApplicationConfigCacheTest.java | 13 +++---
.../tars/handler/TarsMetaDataHandlerTest.java | 3 +-
.../shenyu/plugin/tars/util/PrxInfoUtilTest.java | 3 +-
8 files changed, 140 insertions(+), 18 deletions(-)
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/MetaData.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/MetaData.java
index 720b408c9b..410aa95acf 100644
--- a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/MetaData.java
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/MetaData.java
@@ -42,6 +42,11 @@ public class MetaData {
private String rpcExt;
private Boolean enabled;
+
+ /**
+ * namespaceId.
+ */
+ private String namespaceId;
/**
* no args constructor.
@@ -62,9 +67,10 @@ public class MetaData {
* @param parameterTypes parameterTypes
* @param rpcExt rpcExt
* @param enabled enabled
+ * @param namespaceId namespaceId
*/
public MetaData(final String id, final String appName, final String
contextPath, final String path, final String rpcType, final String serviceName,
- final String methodName, final String parameterTypes,
final String rpcExt, final Boolean enabled) {
+ final String methodName, final String parameterTypes,
final String rpcExt, final Boolean enabled, final String namespaceId) {
this.id = id;
this.appName = appName;
this.contextPath = contextPath;
@@ -75,6 +81,7 @@ public class MetaData {
this.parameterTypes = parameterTypes;
this.rpcExt = rpcExt;
this.enabled = enabled;
+ this.namespaceId = namespaceId;
}
/**
@@ -93,6 +100,7 @@ public class MetaData {
this.parameterTypes = builder.parameterTypes;
this.rpcExt = builder.rpcExt;
this.enabled = builder.enabled;
+ this.namespaceId = builder.namespaceId;
}
/**
@@ -283,7 +291,23 @@ public class MetaData {
public void setEnabled(final Boolean enabled) {
this.enabled = enabled;
}
-
+
+ /**
+ * get namespaceId.
+ * @return namespaceId
+ */
+ public String getNamespaceId() {
+ return namespaceId;
+ }
+
+ /**
+ * set namespaceId.
+ * @param namespaceId namespaceId
+ */
+ public void setNamespaceId(final String namespaceId) {
+ this.namespaceId = namespaceId;
+ }
+
@Override
public boolean equals(final Object o) {
if (this == o) {
@@ -296,12 +320,12 @@ public class MetaData {
return Objects.equals(id, metaData.id) && Objects.equals(appName,
metaData.appName) && Objects.equals(contextPath, metaData.contextPath)
&& Objects.equals(path, metaData.path) &&
Objects.equals(rpcType, metaData.rpcType) && Objects.equals(serviceName,
metaData.serviceName)
&& Objects.equals(methodName, metaData.methodName) &&
Objects.equals(parameterTypes, metaData.parameterTypes)
- && Objects.equals(rpcExt, metaData.rpcExt) &&
Objects.equals(enabled, metaData.enabled);
+ && Objects.equals(rpcExt, metaData.rpcExt) &&
Objects.equals(enabled, metaData.enabled) && Objects.equals(namespaceId,
metaData.namespaceId);
}
@Override
public int hashCode() {
- return Objects.hash(id, appName, contextPath, path, rpcType,
serviceName, methodName, parameterTypes, rpcExt, enabled);
+ return Objects.hash(id, appName, contextPath, path, rpcType,
serviceName, methodName, parameterTypes, rpcExt, enabled, namespaceId);
}
@Override
@@ -336,6 +360,9 @@ public class MetaData {
+ '\''
+ ", enabled="
+ enabled
+ + '\''
+ + ", namespaceId="
+ + namespaceId
+ '}';
}
@@ -403,6 +430,11 @@ public class MetaData {
* enabled.
*/
private Boolean enabled;
+
+ /**
+ * namespaceId.
+ */
+ private String namespaceId;
/**
* no args constructor.
@@ -528,5 +560,16 @@ public class MetaData {
this.enabled = enabled;
return this;
}
+
+ /**
+ * build namespaceId.
+ *
+ * @param namespaceId namespaceId
+ * @return this
+ */
+ public Builder namespaceId(final String namespaceId) {
+ this.namespaceId = namespaceId;
+ return this;
+ }
}
}
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/RuleData.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/RuleData.java
index 62b01c384c..7198a2267d 100644
--- a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/RuleData.java
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/RuleData.java
@@ -59,6 +59,11 @@ public class RuleData {
* match restful.
*/
private Boolean matchRestful;
+
+ /**
+ * namespaceId.
+ */
+ private String namespaceId;
/**
* no args constructor.
@@ -84,6 +89,7 @@ public class RuleData {
this.conditionDataList = builder.conditionDataList;
this.beforeConditionDataList = builder.beforeConditionDataList;
this.matchRestful = builder.matchRestful;
+ this.namespaceId = builder.namespaceId;
}
/**
@@ -331,6 +337,22 @@ public class RuleData {
this.matchRestful = matchRestful;
}
+ /**
+ * get namespaceId.
+ * @return namespaceId
+ */
+ public String getNamespaceId() {
+ return namespaceId;
+ }
+
+ /**
+ * set namespaceId.
+ * @param namespaceId namespaceId
+ */
+ public void setNamespaceId(final String namespaceId) {
+ this.namespaceId = namespaceId;
+ }
+
@Override
public boolean equals(final Object o) {
if (this == o) {
@@ -351,13 +373,14 @@ public class RuleData {
&& Objects.equals(handle, ruleData.handle)
&& Objects.equals(conditionDataList,
ruleData.conditionDataList)
&& Objects.equals(beforeConditionDataList,
ruleData.beforeConditionDataList)
- && Objects.equals(matchRestful, ruleData.matchRestful);
+ && Objects.equals(matchRestful, ruleData.matchRestful)
+ && Objects.equals(namespaceId, ruleData.namespaceId);
}
@Override
public int hashCode() {
return Objects.hash(id, name, pluginName, selectorId, matchMode, sort,
enabled, loged, handle, conditionDataList,
- beforeConditionDataList, matchRestful);
+ beforeConditionDataList, matchRestful, namespaceId);
}
@Override
@@ -421,6 +444,8 @@ public class RuleData {
private List<ConditionData> beforeConditionDataList;
private Boolean matchRestful;
+
+ private String namespaceId;
/**
* no args constructor.
@@ -568,5 +593,16 @@ public class RuleData {
this.matchRestful = matchRestful;
return this;
}
+
+ /**
+ * build namespaceId.
+ *
+ * @param namespaceId namespaceId
+ * @return this
+ */
+ public Builder namespaceId(final String namespaceId) {
+ this.namespaceId = namespaceId;
+ return this;
+ }
}
}
diff --git
a/shenyu-common/src/test/java/org/apache/shenyu/common/dto/MetaDataTest.java
b/shenyu-common/src/test/java/org/apache/shenyu/common/dto/MetaDataTest.java
index 32ebf44f26..e0abda8764 100644
--- a/shenyu-common/src/test/java/org/apache/shenyu/common/dto/MetaDataTest.java
+++ b/shenyu-common/src/test/java/org/apache/shenyu/common/dto/MetaDataTest.java
@@ -36,7 +36,7 @@ public class MetaDataTest {
@Test
public void testUpdateContextPath() {
MetaData metaData = new MetaData("id", "appName", "contextPath",
"path", "rpcType",
- "serviceName", "methodName", "parameterTypes", "rpcExt", true);
+ "serviceName", "methodName", "parameterTypes", "rpcExt", true,
"namespaceId");
metaData.setPath(PATH);
metaData.updateContextPath();
assertEquals(metaData.getContextPath(), CONTEXT_PATH);
diff --git
a/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/RuleCacheData.java
b/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/RuleCacheData.java
index 970420fbf2..2cc8712846 100644
---
a/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/RuleCacheData.java
+++
b/shenyu-e2e/shenyu-e2e-common/src/main/java/org/apache/shenyu/e2e/model/data/RuleCacheData.java
@@ -86,6 +86,11 @@ public class RuleCacheData {
* match restful.
*/
private Boolean matchRestful;
+
+ /**
+ * namespaceId.
+ */
+ private String namespaceId;
/**
* no args constructor.
@@ -111,6 +116,7 @@ public class RuleCacheData {
this.conditionDataList = builder.conditionDataList;
this.beforeConditionDataList = builder.beforeConditionDataList;
this.matchRestful = builder.matchRestful;
+ this.namespaceId = builder.namespaceId;
}
/**
@@ -358,6 +364,24 @@ public class RuleCacheData {
this.matchRestful = matchRestful;
}
+ /**
+ * get namespaceId.
+ *
+ * @return namespaceId
+ */
+ public String getNamespaceId() {
+ return namespaceId;
+ }
+
+ /**
+ * set namespaceId.
+ *
+ * @param namespaceId namespaceId
+ */
+ public void setNamespaceId(final String namespaceId) {
+ this.namespaceId = namespaceId;
+ }
+
@Override
public boolean equals(final Object o) {
if (this == o) {
@@ -378,13 +402,14 @@ public class RuleCacheData {
&& Objects.equals(handle, ruleCacheData.handle)
&& Objects.equals(conditionDataList,
ruleCacheData.conditionDataList)
&& Objects.equals(beforeConditionDataList,
ruleCacheData.beforeConditionDataList)
- && Objects.equals(matchRestful, ruleCacheData.matchRestful);
+ && Objects.equals(matchRestful, ruleCacheData.matchRestful)
+ && Objects.equals(namespaceId, ruleCacheData.namespaceId);
}
@Override
public int hashCode() {
return Objects.hash(id, name, pluginName, selectorId, matchMode, sort,
enabled, loged, handle, conditionDataList,
- beforeConditionDataList, matchRestful);
+ beforeConditionDataList, matchRestful, namespaceId);
}
@Override
@@ -417,6 +442,8 @@ public class RuleCacheData {
+ conditionDataList
+ ", matchRestful="
+ matchRestful
+ + ", namespaceId="
+ + namespaceId
+ '}';
}
@@ -448,6 +475,8 @@ public class RuleCacheData {
private List<ConditionData> beforeConditionDataList;
private Boolean matchRestful;
+
+ private String namespaceId;
/**
* no args constructor.
@@ -595,5 +624,16 @@ public class RuleCacheData {
this.matchRestful = matchRestful;
return this;
}
+
+ /**
+ * build namespaceId.
+ *
+ * @param namespaceId namespaceId
+ * @return this
+ */
+ public Builder namespaceId(final String namespaceId) {
+ this.namespaceId = namespaceId;
+ return this;
+ }
}
}
diff --git
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/TarsPluginTest.java
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/TarsPluginTest.java
index 723d721067..33bcff2972 100644
---
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/TarsPluginTest.java
+++
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/TarsPluginTest.java
@@ -84,7 +84,7 @@ public class TarsPluginTest {
"path", RpcTypeEnum.TARS.getName(), "serviceName", "method1",
"parameterTypes",
"{\"methodInfo\":[{\"methodName\":\"method1\",\"params\":"
+
"[{\"left\":\"java.lang.String\",\"right\":\"param1\"},{\"left\":\"java.lang.String\","
- +
"\"right\":\"param2\"}],\"returnType\":\"java.lang.String\"}]}", false);
+ +
"\"right\":\"param2\"}],\"returnType\":\"java.lang.String\"}]}", false,
Constants.SYS_DEFAULT_NAMESPACE_ID);
ApplicationConfigCache.getInstance().initPrx(metaData);
exchange =
MockServerWebExchange.from(MockServerHttpRequest.get("localhost").build());
tarsPluginUnderTest = new TarsPlugin();
diff --git
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCacheTest.java
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCacheTest.java
index bf65767703..cbf228627e 100644
---
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCacheTest.java
+++
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCacheTest.java
@@ -19,6 +19,7 @@ package org.apache.shenyu.plugin.tars.cache;
import com.qq.tars.protocol.annotation.Servant;
import org.apache.shenyu.common.concurrent.ShenyuThreadFactory;
+import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.enums.RpcTypeEnum;
import org.apache.shenyu.plugin.tars.proxy.TarsInvokePrxList;
@@ -61,7 +62,7 @@ public final class ApplicationConfigCacheTest {
final MetaData metaData = new MetaData("id", "127.0.0.1:8080",
"contextPath",
"path5", RpcTypeEnum.TARS.getName(), "serviceName5", "method1",
- "parameterTypes", rpcExt, false);
+ "parameterTypes", rpcExt, false,
Constants.SYS_DEFAULT_NAMESPACE_ID);
assertThrows(NullPointerException.class, () -> {
applicationConfigCacheUnderTest.initPrx(metaData);
@@ -93,16 +94,16 @@ public final class ApplicationConfigCacheTest {
final MetaData metaData1 = new MetaData("id", "127.0.0.1:8080",
"contextPath",
"path1", RpcTypeEnum.TARS.getName(), "serviceName1", "method1",
- "parameterTypes", rpcExt1, false);
+ "parameterTypes", rpcExt1, false,
Constants.SYS_DEFAULT_NAMESPACE_ID);
final MetaData metaData2 = new MetaData("id", "127.0.0.1:8080",
"contextPath",
"path2", RpcTypeEnum.TARS.getName(), "serviceName2", "method2",
- "parameterTypes", rpcExt2, false);
+ "parameterTypes", rpcExt2, false,
Constants.SYS_DEFAULT_NAMESPACE_ID);
final MetaData metaData3 = new MetaData("id", "127.0.0.1:8080",
"contextPath",
"path3", RpcTypeEnum.TARS.getName(), "serviceName3", "method3",
- "parameterTypes", rpcExt3, false);
+ "parameterTypes", rpcExt3, false,
Constants.SYS_DEFAULT_NAMESPACE_ID);
final MetaData metaData4 = new MetaData("id", "127.0.0.1:8080",
"contextPath",
"path4", RpcTypeEnum.TARS.getName(), "serviceName4", "method4",
- "parameterTypes", rpcExt4, false);
+ "parameterTypes", rpcExt4, false,
Constants.SYS_DEFAULT_NAMESPACE_ID);
List<MetaData> metaDataList = Lists.list(metaData1, metaData2,
metaData3, metaData4);
assertThrows(NullPointerException.class, () -> {
ExecutorService executorService = Executors.newFixedThreadPool(4,
@@ -125,7 +126,7 @@ public final class ApplicationConfigCacheTest {
final MetaData metaData = new MetaData("id", "127.0.0.1:8080",
"contextPath",
"path6", RpcTypeEnum.TARS.getName(), "serviceName6", "method1",
"parameterTypes",
"{\"methodInfo\":[{\"methodName\":\"method1\",\"params\":[{\"left\":\"int\",\"right\":\"param1\"},"
- +
"{\"left\":\"java.lang.Integer\",\"right\":\"param2\"}],\"returnType\":\"java.lang.String\"}]}",
false);
+ +
"{\"left\":\"java.lang.Integer\",\"right\":\"param2\"}],\"returnType\":\"java.lang.String\"}]}",
false, Constants.SYS_DEFAULT_NAMESPACE_ID);
assertThrows(NullPointerException.class, () -> {
applicationConfigCacheUnderTest.initPrx(metaData);
final TarsInvokePrxList result =
applicationConfigCacheUnderTest.get("path6");
diff --git
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/handler/TarsMetaDataHandlerTest.java
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/handler/TarsMetaDataHandlerTest.java
index 71eed8a4c8..3377e785b1 100644
---
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/handler/TarsMetaDataHandlerTest.java
+++
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/handler/TarsMetaDataHandlerTest.java
@@ -17,6 +17,7 @@
package org.apache.shenyu.plugin.tars.handler;
+import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.enums.RpcTypeEnum;
import org.junit.jupiter.api.BeforeEach;
@@ -39,7 +40,7 @@ public class TarsMetaDataHandlerTest {
metaData = new MetaData("id", "127.0.0.1:8080", "contextPath",
"path", RpcTypeEnum.TARS.getName(), "serviceName", "method1",
"parameterTypes",
"{\"methodInfo\":[{\"methodName\":\"method1\",\"params\":[{\"left\":\"int\",\"right\":\"param1\"},"
- +
"{\"left\":\"java.lang.Integer\",\"right\":\"param2\"}],\"returnType\":\"java.lang.String\"}]}",
false);
+ +
"{\"left\":\"java.lang.Integer\",\"right\":\"param2\"}],\"returnType\":\"java.lang.String\"}]}",
false, Constants.SYS_DEFAULT_NAMESPACE_ID);
tarsMetaDataHandler = new TarsMetaDataHandler();
}
diff --git
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/util/PrxInfoUtilTest.java
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/util/PrxInfoUtilTest.java
index 298a714f98..431756bf4d 100644
---
a/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/util/PrxInfoUtilTest.java
+++
b/shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/util/PrxInfoUtilTest.java
@@ -17,6 +17,7 @@
package org.apache.shenyu.plugin.tars.util;
+import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.dto.MetaData;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -53,7 +54,7 @@ public class PrxInfoUtilTest {
public void testGetPrxName() {
final MetaData metaData = new MetaData("id", "appName", "contextPath",
"/path",
"rpcType", "serviceName", "methodName", "parameterTypes",
- "rpcExt", false);
+ "rpcExt", false, Constants.SYS_DEFAULT_NAMESPACE_ID);
final String result = PrxInfoUtil.getPrxName(metaData);
assertEquals("pathmethodNamePrx", result);
}