You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2021/03/26 02:17:12 UTC

[servicecomb-java-chassis] branch master updated: [SCB-2241] fix microservice.basePaths data type bug (#2319)

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 f3408ce  [SCB-2241] fix microservice.basePaths data type bug (#2319)
f3408ce is described below

commit f3408ce5ffcb56a20f87e12d750f49c43b3b8a9b
Author: wujimin <wu...@huawei.com>
AuthorDate: Fri Mar 26 10:17:05 2021 +0800

    [SCB-2241] fix microservice.basePaths data type bug (#2319)
---
 .../registry/config/ConfigurePropertyUtils.java       | 19 ++++++++++---------
 .../bizkeeper/HystrixPropertiesStrategyExt.java       | 13 +++++--------
 .../config/TestConfigurePropertyUtils.java            |  4 ++--
 3 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/config/ConfigurePropertyUtils.java b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/config/ConfigurePropertyUtils.java
index 6c4c54a..7a9f38b 100644
--- a/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/config/ConfigurePropertyUtils.java
+++ b/foundations/foundation-registry/src/main/java/org/apache/servicecomb/registry/config/ConfigurePropertyUtils.java
@@ -17,7 +17,6 @@
 
 package org.apache.servicecomb.registry.config;
 
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -30,8 +29,11 @@ import org.apache.servicecomb.foundation.common.utils.ClassLoaderScopeContext;
 import org.apache.servicecomb.registry.api.registry.BasePath;
 import org.apache.servicecomb.registry.definition.DefinitionConst;
 
+import com.fasterxml.jackson.databind.type.TypeFactory;
 import com.netflix.config.DynamicPropertyFactory;
 
+import io.vertx.core.json.jackson.DatabindCodec;
+
 public final class ConfigurePropertyUtils {
   private ConfigurePropertyUtils() {
   }
@@ -60,15 +62,14 @@ public final class ConfigurePropertyUtils {
     return propertiesMap;
   }
 
-  @SuppressWarnings("unchecked")
   public static List<BasePath> getMicroservicePaths(Configuration configuration) {
-    List<BasePath> basePaths = new ArrayList<>();
-    for (Object path : BootStrapProperties.readServicePaths(configuration)) {
-      BasePath basePath = new BasePath();
-      Map<String, ?> pathMap = (Map<String, ?>) path;
-      basePath.setPath(buildPath((String) pathMap.get("path")));
-      basePath.setProperty((Map<String, String>) pathMap.get("property"));
-      basePaths.add(basePath);
+    List<Object> configPaths = BootStrapProperties.readServicePaths(configuration);
+    List<BasePath> basePaths = DatabindCodec.mapper().convertValue(
+        configPaths,
+        TypeFactory.defaultInstance().constructCollectionType(List.class, BasePath.class)
+    );
+    for (BasePath basePath : basePaths) {
+      basePath.setPath(buildPath(basePath.getPath()));
     }
     return basePaths;
   }
diff --git a/handlers/handler-bizkeeper/src/main/java/org/apache/servicecomb/bizkeeper/HystrixPropertiesStrategyExt.java b/handlers/handler-bizkeeper/src/main/java/org/apache/servicecomb/bizkeeper/HystrixPropertiesStrategyExt.java
index a766e71..c862d11 100644
--- a/handlers/handler-bizkeeper/src/main/java/org/apache/servicecomb/bizkeeper/HystrixPropertiesStrategyExt.java
+++ b/handlers/handler-bizkeeper/src/main/java/org/apache/servicecomb/bizkeeper/HystrixPropertiesStrategyExt.java
@@ -18,7 +18,8 @@
 package org.apache.servicecomb.bizkeeper;
 
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.servicecomb.foundation.common.concurrent.ConcurrentHashMapEx;
 
 import com.netflix.hystrix.HystrixCommandKey;
 import com.netflix.hystrix.HystrixCommandProperties;
@@ -36,7 +37,7 @@ public final class HystrixPropertiesStrategyExt extends HystrixPropertiesStrateg
 
   private static final HystrixPropertiesStrategyExt INSTANCE = new HystrixPropertiesStrategyExt();
 
-  private final Map<String, HystrixCommandProperties> commandPropertiesMap = new ConcurrentHashMap<>();
+  private final Map<String, HystrixCommandProperties> commandPropertiesMap = new ConcurrentHashMapEx<>();
 
   private HystrixPropertiesStrategyExt() {
   }
@@ -47,11 +48,7 @@ public final class HystrixPropertiesStrategyExt extends HystrixPropertiesStrateg
 
   @Override
   public HystrixCommandProperties getCommandProperties(HystrixCommandKey commandKey, Setter builder) {
-    HystrixCommandProperties commandProperties = commandPropertiesMap.get(commandKey.name());
-    if (commandProperties == null) {
-      commandProperties = new HystrixCommandPropertiesExt(commandKey, builder);
-      commandPropertiesMap.putIfAbsent(commandKey.name(), commandProperties);
-    }
-    return commandProperties;
+    return commandPropertiesMap.computeIfAbsent(commandKey.name(),
+        key -> new HystrixCommandPropertiesExt(commandKey, builder));
   }
 }
diff --git a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/config/TestConfigurePropertyUtils.java b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/config/TestConfigurePropertyUtils.java
index bc759be..d5f2c4d 100644
--- a/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/config/TestConfigurePropertyUtils.java
+++ b/service-registry/registry-service-center/src/test/java/org/apache/servicecomb/serviceregistry/config/TestConfigurePropertyUtils.java
@@ -45,13 +45,13 @@ public class TestConfigurePropertyUtils {
     List<BasePath> paths = ConfigurePropertyUtils.getMicroservicePaths(configuration);
     Assert.assertEquals(2, paths.size());
     Assert.assertEquals(paths.get(0).getPath(), "/test1/testpath");
-    Assert.assertEquals(paths.get(0).getProperty().get("checksession"), false);
+    Assert.assertEquals(paths.get(0).getProperty().get("checksession"), "false");
 
     ClassLoaderScopeContext.setClassLoaderScopeProperty(DefinitionConst.URL_PREFIX, "/webroot");
     paths = ConfigurePropertyUtils.getMicroservicePaths(configuration);
     Assert.assertEquals(2, paths.size());
     Assert.assertEquals(paths.get(0).getPath(), "/webroot/test1/testpath");
-    Assert.assertEquals(paths.get(0).getProperty().get("checksession"), false);
+    Assert.assertEquals(paths.get(0).getProperty().get("checksession"), "false");
     ClassLoaderScopeContext.clearClassLoaderScopeProperty();
   }
 }