Skip to content

Commit

Permalink
[type:feature] namespace sync (#5672)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aias00 authored Sep 26, 2024
1 parent 4b14bb8 commit 2111828
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public class MetaData {
private String rpcExt;

private Boolean enabled;

/**
* namespaceId.
*/
private String namespaceId;

/**
* no args constructor.
Expand All @@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -336,6 +360,9 @@ public String toString() {
+ '\''
+ ", enabled="
+ enabled
+ '\''
+ ", namespaceId="
+ namespaceId
+ '}';
}

Expand Down Expand Up @@ -403,6 +430,11 @@ public static final class Builder {
* enabled.
*/
private Boolean enabled;

/**
* namespaceId.
*/
private String namespaceId;

/**
* no args constructor.
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public class RuleData {
* match restful.
*/
private Boolean matchRestful;

/**
* namespaceId.
*/
private String namespaceId;

/**
* no args constructor.
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -421,6 +444,8 @@ public static final class Builder {
private List<ConditionData> beforeConditionDataList;

private Boolean matchRestful;

private String namespaceId;

/**
* no args constructor.
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public class RuleCacheData {
* match restful.
*/
private Boolean matchRestful;

/**
* namespaceId.
*/
private String namespaceId;

/**
* no args constructor.
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -417,6 +442,8 @@ public String toString() {
+ conditionDataList
+ ", matchRestful="
+ matchRestful
+ ", namespaceId="
+ namespaceId
+ '}';
}

Expand Down Expand Up @@ -448,6 +475,8 @@ public static final class Builder {
private List<ConditionData> beforeConditionDataList;

private Boolean matchRestful;

private String namespaceId;

/**
* no args constructor.
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<MetaData> metaDataList = Lists.list(metaData1, metaData2, metaData3, metaData4);
assertThrows(NullPointerException.class, () -> {
ExecutorService executorService = Executors.newFixedThreadPool(4,
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand Down
Loading

0 comments on commit 2111828

Please sign in to comment.