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 720b408c9bf2..410aa95acf6f 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 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 MetaData(final String id, final String appName, final String contextPath, this.parameterTypes = parameterTypes; this.rpcExt = rpcExt; this.enabled = enabled; + this.namespaceId = namespaceId; } /** @@ -93,6 +100,7 @@ private MetaData(final Builder builder) { this.parameterTypes = builder.parameterTypes; this.rpcExt = builder.rpcExt; this.enabled = builder.enabled; + this.namespaceId = builder.namespaceId; } /** @@ -283,7 +291,23 @@ public Boolean getEnabled() { 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 boolean equals(final Object o) { 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 String toString() { + '\'' + ", enabled=" + enabled + + '\'' + + ", namespaceId=" + + namespaceId + '}'; } @@ -403,6 +430,11 @@ public static final class Builder { * enabled. */ private Boolean enabled; + + /** + * namespaceId. + */ + private String namespaceId; /** * no args constructor. @@ -528,5 +560,16 @@ public Builder enabled(final Boolean enabled) { 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 62b01c384cfa..7198a2267d92 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 @@ private RuleData(final Builder builder) { this.conditionDataList = builder.conditionDataList; this.beforeConditionDataList = builder.beforeConditionDataList; this.matchRestful = builder.matchRestful; + this.namespaceId = builder.namespaceId; } /** @@ -331,6 +337,22 @@ public void setMatchRestful(final Boolean matchRestful) { 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 boolean equals(final Object o) { && 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 static final class Builder { private List beforeConditionDataList; private Boolean matchRestful; + + private String namespaceId; /** * no args constructor. @@ -568,5 +593,16 @@ public Builder matchRestful(final Boolean matchRestful) { 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 32ebf44f2606..e0abda87641f 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 970420fbf269..2cc8712846be 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 @@ private RuleCacheData(final Builder builder) { this.conditionDataList = builder.conditionDataList; this.beforeConditionDataList = builder.beforeConditionDataList; this.matchRestful = builder.matchRestful; + this.namespaceId = builder.namespaceId; } /** @@ -358,6 +364,24 @@ public void setMatchRestful(final Boolean matchRestful) { 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 boolean equals(final Object o) { && 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 String toString() { + conditionDataList + ", matchRestful=" + matchRestful + + ", namespaceId=" + + namespaceId + '}'; } @@ -448,6 +475,8 @@ public static final class Builder { private List beforeConditionDataList; private Boolean matchRestful; + + private String namespaceId; /** * no args constructor. @@ -595,5 +624,16 @@ public Builder matchRestful(final Boolean matchRestful) { 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 723d72106721..33bcff297269 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 void setUp() { "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 bf657677034b..cbf228627eaf 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 @@ 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 void testGet() throws ClassNotFoundException { 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 void testConcurrentInitPrx() { 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 metaDataList = Lists.list(metaData1, metaData2, metaData3, metaData4); assertThrows(NullPointerException.class, () -> { ExecutorService executorService = Executors.newFixedThreadPool(4, @@ -125,7 +126,7 @@ public void testInitPrx() { 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 71eed8a4c8a2..3377e785b114 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 void setUp() { 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 298a714f980d..431756bf4d59 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 void testGetParamClassThrowsClassNotFoundException() throws Exception { 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); }