This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new 9185b8c [SCB-1407] handler-router decoupled spi (#1458)
9185b8c is described below
commit 9185b8c6515c63a75da26d4bb83e0ab2d41d45c1
Author: GuoYL <[email protected]>
AuthorDate: Thu Dec 19 15:27:49 2019 +0800
[SCB-1407] handler-router decoupled spi (#1458)
---
.../router/{constom => custom}/MicroserviceCache.java | 2 +-
.../router/{match => custom}/RouterHeaderFilterExt.java | 2 +-
.../router/{constom => custom}/RouterInvokeFilter.java | 2 +-
.../{constom => custom}/RouterServerListFilter.java | 15 ++++++++++++++-
.../{constom => custom}/ServiceCombCanaryDistributer.java | 2 +-
.../servicecomb/router/match/RouterRuleMatcher.java | 10 ----------
6 files changed, 18 insertions(+), 15 deletions(-)
diff --git
a/handlers/handler-router/src/main/java/org/apache/servicecomb/router/constom/MicroserviceCache.java
b/handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/MicroserviceCache.java
similarity index 96%
rename from
handlers/handler-router/src/main/java/org/apache/servicecomb/router/constom/MicroserviceCache.java
rename to
handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/MicroserviceCache.java
index ea7315b..6bae943 100644
---
a/handlers/handler-router/src/main/java/org/apache/servicecomb/router/constom/MicroserviceCache.java
+++
b/handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/MicroserviceCache.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicecomb.router.constom;
+package org.apache.servicecomb.router.custom;
import java.util.HashMap;
import java.util.Map;
diff --git
a/handlers/handler-router/src/main/java/org/apache/servicecomb/router/match/RouterHeaderFilterExt.java
b/handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/RouterHeaderFilterExt.java
similarity index 95%
rename from
handlers/handler-router/src/main/java/org/apache/servicecomb/router/match/RouterHeaderFilterExt.java
rename to
handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/RouterHeaderFilterExt.java
index 46af635..a3bb71c 100644
---
a/handlers/handler-router/src/main/java/org/apache/servicecomb/router/match/RouterHeaderFilterExt.java
+++
b/handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/RouterHeaderFilterExt.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicecomb.router.match;
+package org.apache.servicecomb.router.custom;
import java.util.Map;
diff --git
a/handlers/handler-router/src/main/java/org/apache/servicecomb/router/constom/RouterInvokeFilter.java
b/handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/RouterInvokeFilter.java
similarity index 99%
rename from
handlers/handler-router/src/main/java/org/apache/servicecomb/router/constom/RouterInvokeFilter.java
rename to
handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/RouterInvokeFilter.java
index b6a63f1..e97a7e9 100644
---
a/handlers/handler-router/src/main/java/org/apache/servicecomb/router/constom/RouterInvokeFilter.java
+++
b/handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/RouterInvokeFilter.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicecomb.router.constom;
+package org.apache.servicecomb.router.custom;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.netflix.config.DynamicStringProperty;
diff --git
a/handlers/handler-router/src/main/java/org/apache/servicecomb/router/constom/RouterServerListFilter.java
b/handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/RouterServerListFilter.java
similarity index 87%
rename from
handlers/handler-router/src/main/java/org/apache/servicecomb/router/constom/RouterServerListFilter.java
rename to
handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/RouterServerListFilter.java
index b258b69..9cfee90 100644
---
a/handlers/handler-router/src/main/java/org/apache/servicecomb/router/constom/RouterServerListFilter.java
+++
b/handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/RouterServerListFilter.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicecomb.router.constom;
+package org.apache.servicecomb.router.custom;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -24,6 +24,7 @@ import java.util.Map;
import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.foundation.common.utils.JsonUtils;
+import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.loadbalance.ServerListFilterExt;
import org.apache.servicecomb.loadbalance.ServiceCombServer;
import com.netflix.config.DynamicPropertyFactory;
@@ -57,11 +58,23 @@ public class RouterServerListFilter implements
ServerListFilterExt {
Invocation invocation) {
String targetServiceName = invocation.getMicroserviceName();
Map<String, String> headers = addHeaders(invocation);
+ headers = filterHeaders(headers);
return RouterFilter
.getFilteredListOfServers(list, targetServiceName, headers,
distributer);
}
+ private Map<String, String> filterHeaders(Map<String, String> headers) {
+ List<RouterHeaderFilterExt> filters = SPIServiceUtils
+ .loadSortedService(RouterHeaderFilterExt.class);
+ for (RouterHeaderFilterExt filterExt : filters) {
+ if (filterExt.enabled()) {
+ headers = filterExt.doFilter(headers);
+ }
+ }
+ return headers;
+ }
+
private Map<String, String> addHeaders(Invocation invocation) {
Map<String, String> headers = new HashMap<>();
if (invocation.getContext(ROUTER_HEADER) != null) {
diff --git
a/handlers/handler-router/src/main/java/org/apache/servicecomb/router/constom/ServiceCombCanaryDistributer.java
b/handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/ServiceCombCanaryDistributer.java
similarity index 96%
rename from
handlers/handler-router/src/main/java/org/apache/servicecomb/router/constom/ServiceCombCanaryDistributer.java
rename to
handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/ServiceCombCanaryDistributer.java
index fa0e23b..c692cb9 100644
---
a/handlers/handler-router/src/main/java/org/apache/servicecomb/router/constom/ServiceCombCanaryDistributer.java
+++
b/handlers/handler-router/src/main/java/org/apache/servicecomb/router/custom/ServiceCombCanaryDistributer.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicecomb.router.constom;
+package org.apache.servicecomb.router.custom;
import org.apache.servicecomb.loadbalance.ServiceCombServer;
import org.apache.servicecomb.router.distribute.AbstractRouterDistributor;
diff --git
a/handlers/handler-router/src/main/java/org/apache/servicecomb/router/match/RouterRuleMatcher.java
b/handlers/handler-router/src/main/java/org/apache/servicecomb/router/match/RouterRuleMatcher.java
index 7225303..f5b5546 100644
---
a/handlers/handler-router/src/main/java/org/apache/servicecomb/router/match/RouterRuleMatcher.java
+++
b/handlers/handler-router/src/main/java/org/apache/servicecomb/router/match/RouterRuleMatcher.java
@@ -16,9 +16,7 @@
*/
package org.apache.servicecomb.router.match;
-import java.util.List;
import java.util.Map;
-import org.apache.servicecomb.foundation.common.utils.SPIServiceUtils;
import org.apache.servicecomb.router.cache.RouterRuleCache;
import org.apache.servicecomb.router.model.PolicyRuleItem;
@@ -28,12 +26,9 @@ import org.apache.servicecomb.router.model.PolicyRuleItem;
**/
public class RouterRuleMatcher {
- private List<RouterHeaderFilterExt> filters;
-
private static RouterRuleMatcher instance = new RouterRuleMatcher();
private RouterRuleMatcher() {
- this.filters =
SPIServiceUtils.loadSortedService(RouterHeaderFilterExt.class);
}
/**
@@ -43,11 +38,6 @@ public class RouterRuleMatcher {
* @return
*/
public PolicyRuleItem match(String serviceName, Map<String, String>
invokeHeader) {
- for (RouterHeaderFilterExt filterExt : filters) {
- if (filterExt.enabled()) {
- invokeHeader = filterExt.doFilter(invokeHeader);
- }
- }
for (PolicyRuleItem rule :
RouterRuleCache.getServiceInfoCacheMap().get(serviceName)
.getAllrule()) {
if (rule.getMatch() == null || rule.getMatch().match(invokeHeader)) {