You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by wu...@apache.org on 2018/01/10 07:38:24 UTC

[incubator-servicecomb-java-chassis] branch master updated (cd6baf1 -> 1909b0c)

This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git.


    from cd6baf1  SCB-36 use enum to store configuration actions
     new ca84f17  SCB-166 add health check implement
     new 900e87f  SCB-166 add health check sample
     new de94e02  SCB-166 fix bug
     new b32d4fb  SCB-166 fix pr
     new 52dc7e6  SCB-166 fix pr comment
     new c70ab10  SCB-166 modify auto registration with spring boot
     new 7bf4def  SCB-166 remove metrics perf samples
     new 6066c05  SCB-166 resolve conflict
     new 4eaf6cd  SCB-166 rebase and fix pr comment
     new a835386  SCB-166 fix ci failed
     new eb23f0f  SCB-166 rebase and fix
     new 1403d57  SCB-166 rebase and fix
     new 1909b0c  SCB-166 rename field isHealthy -> healthy

The 13 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../common/DefaultHealthCheckExtraData.java        | 53 ++++++-------
 ...nvocationMetric.java => HealthCheckResult.java} | 39 +++++++---
 .../servicecomb/metrics/common/HealthChecker.java  |  8 +-
 .../metrics/common/HealthCheckerPublisher.java     |  8 +-
 .../health/DefaultMicroserviceHealthChecker.java   | 67 ++++++++++++++++
 .../core/publish/DefaultHealthCheckerManager.java  | 73 ++++++++++++++++++
 ...her.java => DefaultHealthCheckerPublisher.java} | 35 ++++-----
 .../metrics/core/publish/HealthCheckerManager.java | 16 ++--
 .../metrics/core/TestHealthCheckerManager.java     | 88 ++++++++++++++++++++++
 .../metrics/core/TestHealthCheckerPublisher.java   | 59 +++++++++++++++
 .../pom.xml                                        | 24 +++---
 .../CustomHealthCheckerAnnotation.java             | 17 +++--
 .../ExtendHealthCheckApplication.java}             |  7 +-
 .../extendhealthcheck/MySqlHealthChecker.java      | 54 +++++++++++++
 .../SomeServiceWithHealthCheckerManager.java}      | 23 +++---
 .../src/main/resources/microservice.yaml           |  7 +-
 .../metrics-write-file-log4j2-springboot/pom.xml   | 10 ---
 samples/pom.xml                                    |  1 +
 18 files changed, 466 insertions(+), 123 deletions(-)
 copy service-registry/src/main/java/io/servicecomb/serviceregistry/api/MicroserviceKey.java => metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/DefaultHealthCheckExtraData.java (58%)
 copy metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/{InvocationMetric.java => HealthCheckResult.java} (55%)
 copy core/src/main/java/io/servicecomb/core/ProducerProvider.java => metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthChecker.java (89%)
 copy samples/metrics-write-file-sample/metrics-write-file/src/main/java/io/servicecomb/samples/mwf/FileContentFormatter.java => metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckerPublisher.java (82%)
 create mode 100644 metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
 create mode 100644 metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
 copy metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/{DefaultMetricsPublisher.java => DefaultHealthCheckerPublisher.java} (62%)
 copy core/src/test/java/io/servicecomb/core/definition/MicroServicePropertyExtendedStub.java => metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/HealthCheckerManager.java (72%)
 create mode 100644 metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
 create mode 100644 metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerPublisher.java
 copy samples/{config-apollo-sample => metrics-extend-healthcheck}/pom.xml (80%)
 copy providers/provider-pojo/src/main/java/io/servicecomb/provider/pojo/PojoConsumerProvider.java => samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthCheckerAnnotation.java (67%)
 copy samples/{bmi/calculator/src/main/java/io/servicecomb/samples/bmi/CalculatorApplication.java => metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/ExtendHealthCheckApplication.java} (86%)
 create mode 100644 samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/MySqlHealthChecker.java
 copy samples/{metrics-write-file-sample/metrics-write-file/src/main/java/io/servicecomb/samples/mwf/MetricsBootListener.java => metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/SomeServiceWithHealthCheckerManager.java} (63%)
 copy samples/{bmi/webapp => metrics-extend-healthcheck}/src/main/resources/microservice.yaml (93%)

-- 
To stop receiving notification emails like this one, please contact
['"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>'].

[incubator-servicecomb-java-chassis] 09/13: SCB-166 rebase and fix pr comment

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 4eaf6cda32717c07d29fa210593859989e95f69e
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Tue Jan 9 16:37:57 2018 +0800

    SCB-166 rebase and fix pr comment
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../core/publish/DefaultHealthCheckerManager.java  |  17 +-
 .../metrics/core/TestHealthCheckerManager.java     | 221 +--------------------
 .../SomeServiceWithHealthCheckerManager.java       |  36 ++++
 3 files changed, 53 insertions(+), 221 deletions(-)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
index 667b02a..71e9f1a 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
@@ -19,6 +19,7 @@ package io.servicecomb.metrics.core.publish;
 
 import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
 
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
@@ -27,7 +28,6 @@ import java.util.stream.Collectors;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.ApplicationContext;
 import org.springframework.stereotype.Component;
 
 import io.servicecomb.metrics.common.HealthCheckResult;
@@ -42,20 +42,15 @@ public class DefaultHealthCheckerManager implements HealthCheckerManager {
 
   private final Map<String, HealthChecker> healthCheckers;
 
-  private ApplicationContext context;
-
-  @Autowired
-  public DefaultHealthCheckerManager(ApplicationContext context) {
-    this.context = context;
+  @Autowired(required = false)
+  public DefaultHealthCheckerManager(List<HealthChecker> springHealthCheckers) {
     this.healthCheckers = new ConcurrentHashMap<>();
     HealthChecker defaultHealthChecker = new DefaultMicroserviceHealthChecker();
     this.healthCheckers.put(defaultHealthChecker.getName(), defaultHealthChecker);
 
-    for (String beanName : context.getBeanDefinitionNames()) {
-      Class<?> beanClass = context.getType(beanName);
-      if (HealthChecker.class.isAssignableFrom(beanClass)) {
-        Object bean = context.getBean(beanName);
-        this.healthCheckers.put(((HealthChecker) bean).getName(), (HealthChecker) bean);
+    if (springHealthCheckers != null && !springHealthCheckers.isEmpty()) {
+      for (HealthChecker checker : springHealthCheckers) {
+        this.healthCheckers.put(checker.getName(), checker);
       }
     }
   }
diff --git a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
index 9101fd1..74f65cf 100644
--- a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
+++ b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
@@ -18,29 +18,19 @@
 package io.servicecomb.metrics.core;
 
 import java.io.IOException;
-import java.lang.annotation.Annotation;
-import java.util.Locale;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 import org.junit.Assert;
 import org.junit.Test;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationEvent;
-import org.springframework.context.MessageSourceResolvable;
-import org.springframework.context.NoSuchMessageException;
-import org.springframework.core.ResolvableType;
-import org.springframework.core.env.Environment;
-import org.springframework.core.io.Resource;
 
 import com.google.common.collect.Lists;
 
 import io.servicecomb.foundation.common.utils.JsonUtils;
 import io.servicecomb.metrics.common.DefaultHealthCheckExtraData;
 import io.servicecomb.metrics.common.HealthCheckResult;
+import io.servicecomb.metrics.common.HealthChecker;
 import io.servicecomb.metrics.core.publish.DefaultHealthCheckerManager;
 import io.servicecomb.metrics.core.publish.HealthCheckerManager;
 import io.servicecomb.serviceregistry.RegistryUtils;
@@ -77,209 +67,20 @@ public class TestHealthCheckerManager {
       }
     };
 
-    HealthCheckerManager manager = new DefaultHealthCheckerManager(new ApplicationContext() {
+    List<HealthChecker> checkers = new ArrayList<>();
+    checkers.add(new HealthChecker() {
       @Override
-      public String getId() {
-        return null;
+      public String getName() {
+        return "custom";
       }
 
       @Override
-      public String getApplicationName() {
-        return null;
-      }
-
-      @Override
-      public String getDisplayName() {
-        return null;
-      }
-
-      @Override
-      public long getStartupDate() {
-        return 0;
-      }
-
-      @Override
-      public ApplicationContext getParent() {
-        return null;
-      }
-
-      @Override
-      public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException {
-        return null;
-      }
-
-      @Override
-      public BeanFactory getParentBeanFactory() {
-        return null;
-      }
-
-      @Override
-      public boolean containsLocalBean(String s) {
-        return false;
-      }
-
-      @Override
-      public boolean containsBeanDefinition(String s) {
-        return false;
-      }
-
-      @Override
-      public int getBeanDefinitionCount() {
-        return 0;
-      }
-
-      @Override
-      public String[] getBeanDefinitionNames() {
-        return new String[0];
-      }
-
-      @Override
-      public String[] getBeanNamesForType(ResolvableType resolvableType) {
-        return new String[0];
-      }
-
-      @Override
-      public String[] getBeanNamesForType(Class<?> aClass) {
-        return new String[0];
-      }
-
-      @Override
-      public String[] getBeanNamesForType(Class<?> aClass, boolean b, boolean b1) {
-        return new String[0];
-      }
-
-      @Override
-      public <T> Map<String, T> getBeansOfType(Class<T> aClass) throws BeansException {
-        return null;
-      }
-
-      @Override
-      public <T> Map<String, T> getBeansOfType(Class<T> aClass, boolean b, boolean b1) throws BeansException {
-        return null;
-      }
-
-      @Override
-      public String[] getBeanNamesForAnnotation(Class<? extends Annotation> aClass) {
-        return new String[0];
-      }
-
-      @Override
-      public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> aClass) throws BeansException {
-        return null;
-      }
-
-      @Override
-      public <A extends Annotation> A findAnnotationOnBean(String s, Class<A> aClass)
-          throws NoSuchBeanDefinitionException {
-        return null;
-      }
-
-      @Override
-      public Object getBean(String s) throws BeansException {
-        return null;
-      }
-
-      @Override
-      public <T> T getBean(String s, Class<T> aClass) throws BeansException {
-        return null;
-      }
-
-      @Override
-      public <T> T getBean(Class<T> aClass) throws BeansException {
-        return null;
-      }
-
-      @Override
-      public Object getBean(String s, Object... objects) throws BeansException {
-        return null;
-      }
-
-      @Override
-      public <T> T getBean(Class<T> aClass, Object... objects) throws BeansException {
-        return null;
-      }
-
-      @Override
-      public boolean containsBean(String s) {
-        return false;
-      }
-
-      @Override
-      public boolean isSingleton(String s) throws NoSuchBeanDefinitionException {
-        return false;
-      }
-
-      @Override
-      public boolean isPrototype(String s) throws NoSuchBeanDefinitionException {
-        return false;
-      }
-
-      @Override
-      public boolean isTypeMatch(String s, ResolvableType resolvableType) throws NoSuchBeanDefinitionException {
-        return false;
-      }
-
-      @Override
-      public boolean isTypeMatch(String s, Class<?> aClass) throws NoSuchBeanDefinitionException {
-        return false;
-      }
-
-      @Override
-      public Class<?> getType(String s) throws NoSuchBeanDefinitionException {
-        return null;
-      }
-
-      @Override
-      public String[] getAliases(String s) {
-        return new String[0];
-      }
-
-      @Override
-      public void publishEvent(ApplicationEvent applicationEvent) {
-
-      }
-
-      @Override
-      public void publishEvent(Object o) {
-
-      }
-
-      @Override
-      public String getMessage(String s, Object[] objects, String s1, Locale locale) {
-        return null;
-      }
-
-      @Override
-      public String getMessage(String s, Object[] objects, Locale locale) throws NoSuchMessageException {
-        return null;
-      }
-
-      @Override
-      public String getMessage(MessageSourceResolvable messageSourceResolvable, Locale locale)
-          throws NoSuchMessageException {
-        return null;
-      }
-
-      @Override
-      public Environment getEnvironment() {
-        return null;
-      }
-
-      @Override
-      public Resource[] getResources(String s) throws IOException {
-        return new Resource[0];
-      }
-
-      @Override
-      public Resource getResource(String s) {
-        return null;
-      }
-
-      @Override
-      public ClassLoader getClassLoader() {
-        return null;
+      public HealthCheckResult check() {
+        return new HealthCheckResult(true, "", "");
       }
     });
+
+    HealthCheckerManager manager = new DefaultHealthCheckerManager(checkers);
     Map<String, HealthCheckResult> results = manager.check();
 
     Assert.assertTrue(results.get("default").isHealthy());
diff --git a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/SomeServiceWithHealthCheckerManager.java b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/SomeServiceWithHealthCheckerManager.java
new file mode 100644
index 0000000..43871b1
--- /dev/null
+++ b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/SomeServiceWithHealthCheckerManager.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.servicecomb.samples.metrics.extendhealthcheck;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import io.servicecomb.metrics.core.publish.HealthCheckerManager;
+
+@Service
+public class SomeServiceWithHealthCheckerManager {
+
+  private final HealthCheckerManager manager;
+
+  @Autowired
+  public SomeServiceWithHealthCheckerManager(HealthCheckerManager manager) {
+    this.manager = manager;
+
+    this.manager.register(new MySqlHealthChecker());
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 04/13: SCB-166 fix pr

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit b32d4fb155bb1a83aa45c14fe86f6bd19b3c1e00
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Sat Jan 6 11:06:35 2018 +0800

    SCB-166 fix pr
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../java/io/servicecomb/metrics/common/Health.java | 18 +++-------
 metrics/metrics-core/pom.xml                       |  4 +++
 .../health/DefaultMicroserviceHealthChecker.java   |  5 ++-
 .../core/publish/DefaultHealthCheckerManager.java  | 39 ++++++++++++++++++++++
 ...ker.java => CustomHealthCheckerAnnotation.java} |  8 +++--
 ...mHealthChecker.java => MySqlHealthChecker.java} | 26 +++++++++++++--
 .../metrics/extendhealthcheck/SimpleService.java   |  2 +-
 7 files changed, 81 insertions(+), 21 deletions(-)

diff --git a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthChecker.java b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/Health.java
similarity index 63%
copy from samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthChecker.java
copy to metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/Health.java
index 1960de8..eb8c59f 100644
--- a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthChecker.java
+++ b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/Health.java
@@ -15,20 +15,12 @@
  * limitations under the License.
  */
 
-package io.servicecomb.samples.metrics.extendhealthcheck;
+package io.servicecomb.metrics.common;
 
-import io.servicecomb.metrics.common.HealthCheckResult;
-import io.servicecomb.metrics.common.HealthChecker;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
 
-public class CustomHealthChecker implements HealthChecker {
-  @Override
-  public String getName() {
-    return "custom";
-  }
+@Target(value = {ElementType.TYPE})
+public @interface Health {
 
-  @Override
-  public HealthCheckResult check() {
-    //add your health check code here
-    return new HealthCheckResult(true, "demo health check", "no extra data");
-  }
 }
diff --git a/metrics/metrics-core/pom.xml b/metrics/metrics-core/pom.xml
index 2566bbe..17115e4 100644
--- a/metrics/metrics-core/pom.xml
+++ b/metrics/metrics-core/pom.xml
@@ -47,6 +47,10 @@
       <artifactId>slf4j-log4j12</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-core</artifactId>
+    </dependency>
   </dependencies>
 
 </project>
\ No newline at end of file
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
index f4fe4c1..df2d81e 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
@@ -17,6 +17,8 @@
 
 package io.servicecomb.metrics.core.health;
 
+import javax.ws.rs.core.Response.Status;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -27,6 +29,7 @@ import io.servicecomb.metrics.common.HealthChecker;
 import io.servicecomb.serviceregistry.RegistryUtils;
 import io.servicecomb.serviceregistry.api.registry.Microservice;
 import io.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import io.servicecomb.swagger.invocation.exception.InvocationException;
 
 public class DefaultMicroserviceHealthChecker implements HealthChecker {
 
@@ -56,7 +59,7 @@ public class DefaultMicroserviceHealthChecker implements HealthChecker {
     } catch (Exception e) {
       String error = "unable load microservice info from RegistryUtils";
       logger.error(error, e);
-      return error;
+      throw new InvocationException(Status.INTERNAL_SERVER_ERROR, error);
     }
   }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
index 0393ab9..9cb5cb3 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
@@ -19,13 +19,21 @@ package io.servicecomb.metrics.core.publish;
 
 import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
+import org.springframework.core.type.filter.AnnotationTypeFilter;
 import org.springframework.stereotype.Component;
 
+import io.servicecomb.metrics.common.Health;
 import io.servicecomb.metrics.common.HealthCheckResult;
 import io.servicecomb.metrics.common.HealthChecker;
 import io.servicecomb.metrics.core.health.DefaultMicroserviceHealthChecker;
@@ -33,12 +41,19 @@ import io.servicecomb.swagger.invocation.exception.InvocationException;
 
 @Component
 public class DefaultHealthCheckerManager implements HealthCheckerManager {
+
+  private static Logger logger = LoggerFactory.getLogger(DefaultHealthCheckerManager.class);
+
   private final Map<String, HealthChecker> healthCheckers;
 
   public DefaultHealthCheckerManager() {
     this.healthCheckers = new ConcurrentHashMap<>();
     HealthChecker defaultHealthChecker = new DefaultMicroserviceHealthChecker();
     this.healthCheckers.put(defaultHealthChecker.getName(), defaultHealthChecker);
+
+    for (HealthChecker checker : getAllAnnotationHealthChecker()) {
+      this.healthCheckers.put(checker.getName(), checker);
+    }
   }
 
   @Override
@@ -59,4 +74,28 @@ public class DefaultHealthCheckerManager implements HealthCheckerManager {
     }
     throw new InvocationException(BAD_REQUEST, "HealthChecker name : " + name + " unregister");
   }
+
+  private List<HealthChecker> getAllAnnotationHealthChecker() {
+    List<HealthChecker> checkers = new ArrayList<>();
+    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
+    scanner.addIncludeFilter(new AnnotationTypeFilter(Health.class));
+    for (BeanDefinition definition : scanner.findCandidateComponents("./")) {
+      try {
+        Class<?> beanClass = Class.forName(definition.getBeanClassName());
+        if (HealthChecker.class.isAssignableFrom(beanClass)) {
+          try {
+            checkers.add((HealthChecker) beanClass.getConstructor(null).newInstance());
+          } catch (Exception e) {
+            logger.error("construct health check class failed", e);
+          }
+        } else {
+          logger.error(
+              "health annotation class:" + definition.getBeanClassName() + " not implement HealthChecker interface");
+        }
+      } catch (ClassNotFoundException e) {
+        logger.error("health check class not found", e);
+      }
+    }
+    return checkers;
+  }
 }
diff --git a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthChecker.java b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthCheckerAnnotation.java
similarity index 81%
copy from samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthChecker.java
copy to samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthCheckerAnnotation.java
index 1960de8..6816abd 100644
--- a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthChecker.java
+++ b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthCheckerAnnotation.java
@@ -17,10 +17,13 @@
 
 package io.servicecomb.samples.metrics.extendhealthcheck;
 
+import io.servicecomb.metrics.common.Health;
 import io.servicecomb.metrics.common.HealthCheckResult;
 import io.servicecomb.metrics.common.HealthChecker;
 
-public class CustomHealthChecker implements HealthChecker {
+//this health check will auto register because Health Annotation
+@Health
+public class CustomHealthCheckerAnnotation implements HealthChecker {
   @Override
   public String getName() {
     return "custom";
@@ -28,7 +31,6 @@ public class CustomHealthChecker implements HealthChecker {
 
   @Override
   public HealthCheckResult check() {
-    //add your health check code here
-    return new HealthCheckResult(true, "demo health check", "no extra data");
+    return new HealthCheckResult(true, "custom", "no extra data");
   }
 }
diff --git a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthChecker.java b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/MySqlHealthChecker.java
similarity index 59%
rename from samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthChecker.java
rename to samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/MySqlHealthChecker.java
index 1960de8..620857d 100644
--- a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthChecker.java
+++ b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/MySqlHealthChecker.java
@@ -17,18 +17,38 @@
 
 package io.servicecomb.samples.metrics.extendhealthcheck;
 
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
 import io.servicecomb.metrics.common.HealthCheckResult;
 import io.servicecomb.metrics.common.HealthChecker;
 
-public class CustomHealthChecker implements HealthChecker {
+//this is a demo health checker for mysql
+public class MySqlHealthChecker implements HealthChecker {
   @Override
   public String getName() {
-    return "custom";
+    return "mysql";
   }
 
   @Override
   public HealthCheckResult check() {
     //add your health check code here
-    return new HealthCheckResult(true, "demo health check", "no extra data");
+    Connection connection = null;
+    try {
+      connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_db?useSSL=false", "root", "pwd");
+      return new HealthCheckResult(true, "local mysql health check", "");
+    } catch (SQLException e) {
+      e.printStackTrace();
+      return new HealthCheckResult(false, "local mysql health check", e.toString());
+    } finally {
+      if (connection != null) {
+        try {
+          connection.close();
+        } catch (SQLException e) {
+          e.printStackTrace();
+        }
+      }
+    }
   }
 }
diff --git a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/SimpleService.java b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/SimpleService.java
index 5e24cb2..a25cdba 100644
--- a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/SimpleService.java
+++ b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/SimpleService.java
@@ -38,7 +38,7 @@ public class SimpleService {
     this.manager = manager;
 
     //register your custom health check
-    this.manager.register(new CustomHealthChecker());
+    this.manager.register(new MySqlHealthChecker());
   }
 
   @GetMapping(path = "/f")

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 08/13: SCB-166 resolve conflict

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 6066c0591b08d520f3bcb1dd2a7f84af77bd3b36
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Tue Jan 9 15:12:25 2018 +0800

    SCB-166 resolve conflict
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 metrics/metrics-extension/pom.xml | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/metrics/metrics-extension/pom.xml b/metrics/metrics-extension/pom.xml
new file mode 100644
index 0000000..a597152
--- /dev/null
+++ b/metrics/metrics-extension/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>metrics</artifactId>
+    <groupId>io.servicecomb</groupId>
+    <version>0.6.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>metrics-integration</artifactId>
+  <packaging>pom</packaging>
+
+</project>
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 12/13: SCB-166 rebase and fix

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 1403d571b18cdbe1fb0d12787332ed0cb15395fd
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Wed Jan 10 14:39:11 2018 +0800

    SCB-166 rebase and fix
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../metrics-write-file-log4j2-springboot/pom.xml                         | 1 +
 1 file changed, 1 insertion(+)

diff --git a/samples/metrics-write-file-sample/metrics-write-file-log4j2-springboot/pom.xml b/samples/metrics-write-file-sample/metrics-write-file-log4j2-springboot/pom.xml
index bae5e61..130b0d5 100644
--- a/samples/metrics-write-file-sample/metrics-write-file-log4j2-springboot/pom.xml
+++ b/samples/metrics-write-file-sample/metrics-write-file-log4j2-springboot/pom.xml
@@ -70,3 +70,4 @@
     </dependency>
 
   </dependencies>
+</project>
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 03/13: SCB-166 fix bug

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit de94e02128bcb3c977aa18151d462b87900f9733
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Thu Jan 4 19:26:38 2018 +0800

    SCB-166 fix bug
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../core/health/DefaultMicroserviceHealthChecker.java    | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
index 6a0945e..f4fe4c1 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
@@ -17,9 +17,9 @@
 
 package io.servicecomb.metrics.core.health;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import io.servicecomb.foundation.common.exceptions.ServiceCombException;
 import io.servicecomb.foundation.common.utils.JsonUtils;
 import io.servicecomb.metrics.common.DefaultHealthCheckExtraData;
 import io.servicecomb.metrics.common.HealthCheckResult;
@@ -30,6 +30,8 @@ import io.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
 
 public class DefaultMicroserviceHealthChecker implements HealthChecker {
 
+  private static Logger logger = LoggerFactory.getLogger(DefaultMicroserviceHealthChecker.class);
+
   @Override
   public String getName() {
     return "default";
@@ -42,10 +44,6 @@ public class DefaultMicroserviceHealthChecker implements HealthChecker {
 
   private String getExtraData() {
     try {
-      if (RegistryUtils.getServiceRegistry() == null) {
-        RegistryUtils.init();
-      }
-
       Microservice microservice = RegistryUtils.getMicroservice();
       MicroserviceInstance instance = RegistryUtils.getMicroserviceInstance();
       return JsonUtils.writeValueAsString(new DefaultHealthCheckExtraData(
@@ -55,8 +53,10 @@ public class DefaultMicroserviceHealthChecker implements HealthChecker {
           microservice.getServiceName(),
           microservice.getVersion(),
           String.join(",", instance.getEndpoints())));
-    } catch (JsonProcessingException e) {
-      throw new ServiceCombException("unable load microservice info for healthchecker", e);
+    } catch (Exception e) {
+      String error = "unable load microservice info from RegistryUtils";
+      logger.error(error, e);
+      return error;
     }
   }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 10/13: SCB-166 fix ci failed

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit a8353865e3945593efb3021df42681e22c9952ed
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Tue Jan 9 17:32:24 2018 +0800

    SCB-166 fix ci failed
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../core/health/DefaultMicroserviceHealthChecker.java       |  2 ++
 .../metrics/core/publish/DefaultHealthCheckerManager.java   |  3 ---
 .../servicecomb/metrics/core/TestHealthCheckerManager.java  | 13 ++-----------
 3 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
index df2d81e..ec0d1e2 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
@@ -21,6 +21,7 @@ import javax.ws.rs.core.Response.Status;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
 
 import io.servicecomb.foundation.common.utils.JsonUtils;
 import io.servicecomb.metrics.common.DefaultHealthCheckExtraData;
@@ -31,6 +32,7 @@ import io.servicecomb.serviceregistry.api.registry.Microservice;
 import io.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
 import io.servicecomb.swagger.invocation.exception.InvocationException;
 
+@Component
 public class DefaultMicroserviceHealthChecker implements HealthChecker {
 
   private static Logger logger = LoggerFactory.getLogger(DefaultMicroserviceHealthChecker.class);
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
index 71e9f1a..f83d209 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
@@ -45,9 +45,6 @@ public class DefaultHealthCheckerManager implements HealthCheckerManager {
   @Autowired(required = false)
   public DefaultHealthCheckerManager(List<HealthChecker> springHealthCheckers) {
     this.healthCheckers = new ConcurrentHashMap<>();
-    HealthChecker defaultHealthChecker = new DefaultMicroserviceHealthChecker();
-    this.healthCheckers.put(defaultHealthChecker.getName(), defaultHealthChecker);
-
     if (springHealthCheckers != null && !springHealthCheckers.isEmpty()) {
       for (HealthChecker checker : springHealthCheckers) {
         this.healthCheckers.put(checker.getName(), checker);
diff --git a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
index 74f65cf..80c16f5 100644
--- a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
+++ b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
@@ -31,6 +31,7 @@ import io.servicecomb.foundation.common.utils.JsonUtils;
 import io.servicecomb.metrics.common.DefaultHealthCheckExtraData;
 import io.servicecomb.metrics.common.HealthCheckResult;
 import io.servicecomb.metrics.common.HealthChecker;
+import io.servicecomb.metrics.core.health.DefaultMicroserviceHealthChecker;
 import io.servicecomb.metrics.core.publish.DefaultHealthCheckerManager;
 import io.servicecomb.metrics.core.publish.HealthCheckerManager;
 import io.servicecomb.serviceregistry.RegistryUtils;
@@ -68,17 +69,7 @@ public class TestHealthCheckerManager {
     };
 
     List<HealthChecker> checkers = new ArrayList<>();
-    checkers.add(new HealthChecker() {
-      @Override
-      public String getName() {
-        return "custom";
-      }
-
-      @Override
-      public HealthCheckResult check() {
-        return new HealthCheckResult(true, "", "");
-      }
-    });
+    checkers.add(new DefaultMicroserviceHealthChecker());
 
     HealthCheckerManager manager = new DefaultHealthCheckerManager(checkers);
     Map<String, HealthCheckResult> results = manager.check();

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 13/13: SCB-166 rename field isHealthy -> healthy

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 1909b0c2df431adb6edb9010e299f1746b189277
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Wed Jan 10 15:01:49 2018 +0800

    SCB-166 rename field isHealthy -> healthy
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../java/io/servicecomb/metrics/common/HealthCheckResult.java     | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckResult.java b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckResult.java
index 022250e..168991b 100644
--- a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckResult.java
+++ b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckResult.java
@@ -18,7 +18,7 @@
 package io.servicecomb.metrics.common;
 
 public class HealthCheckResult {
-  private boolean isHealthy;
+  private boolean healthy;
 
   private String information;
 
@@ -28,7 +28,7 @@ public class HealthCheckResult {
   private long timestamp;
 
   public boolean isHealthy() {
-    return isHealthy;
+    return healthy;
   }
 
   public String getInformation() {
@@ -46,9 +46,9 @@ public class HealthCheckResult {
   public HealthCheckResult() {
   }
 
-  public HealthCheckResult(boolean isHealthy, String information, String extraData) {
+  public HealthCheckResult(boolean healthy, String information, String extraData) {
     this();
-    this.isHealthy = isHealthy;
+    this.healthy = healthy;
     this.information = information;
     this.extraData = extraData;
     this.timestamp = System.currentTimeMillis();

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 02/13: SCB-166 add health check sample

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 900e87f76a9018d9baffad0a8936f0eccaeea05a
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Thu Jan 4 18:56:13 2018 +0800

    SCB-166 add health check sample
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../health/DefaultMicroserviceHealthChecker.java   | 28 ++++++------
 .../publish/DefaultHealthCheckerPublisher.java     |  2 +-
 samples/metrics-extend-healthcheck/pom.xml         | 53 ++++++++++++++++++++++
 .../extendhealthcheck/CustomHealthChecker.java     | 34 ++++++++++++++
 .../ExtendHealthCheckApplication.java              | 31 +++++++++++++
 .../metrics/extendhealthcheck/SimpleService.java   | 48 ++++++++++++++++++++
 .../src/main/resources/microservice.yaml           | 30 ++++++++++++
 samples/pom.xml                                    |  1 +
 8 files changed, 213 insertions(+), 14 deletions(-)

diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
index 1e96b11..6a0945e 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
@@ -30,13 +30,25 @@ import io.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
 
 public class DefaultMicroserviceHealthChecker implements HealthChecker {
 
-  private final String extraData;
+  @Override
+  public String getName() {
+    return "default";
+  }
 
-  public DefaultMicroserviceHealthChecker() {
+  @Override
+  public HealthCheckResult check() {
+    return new HealthCheckResult(true, "", getExtraData());
+  }
+
+  private String getExtraData() {
     try {
+      if (RegistryUtils.getServiceRegistry() == null) {
+        RegistryUtils.init();
+      }
+
       Microservice microservice = RegistryUtils.getMicroservice();
       MicroserviceInstance instance = RegistryUtils.getMicroserviceInstance();
-      extraData = JsonUtils.writeValueAsString(new DefaultHealthCheckExtraData(
+      return JsonUtils.writeValueAsString(new DefaultHealthCheckExtraData(
           instance.getInstanceId(),
           instance.getHostName(),
           microservice.getAppId(),
@@ -47,14 +59,4 @@ public class DefaultMicroserviceHealthChecker implements HealthChecker {
       throw new ServiceCombException("unable load microservice info for healthchecker", e);
     }
   }
-
-  @Override
-  public String getName() {
-    return "default";
-  }
-
-  @Override
-  public HealthCheckResult check() {
-    return new HealthCheckResult(true, "", extraData);
-  }
 }
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerPublisher.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerPublisher.java
index 69eb6b1..814a9e2 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerPublisher.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerPublisher.java
@@ -30,7 +30,7 @@ import io.servicecomb.provider.rest.common.RestSchema;
 import io.swagger.annotations.ApiResponse;
 import io.swagger.annotations.ApiResponses;
 
-@RestSchema(schemaId = "metricsEndpoint")
+@RestSchema(schemaId = "healthEndpoint")
 @RequestMapping(path = "/health")
 public class DefaultHealthCheckerPublisher implements HealthCheckerPublisher {
 
diff --git a/samples/metrics-extend-healthcheck/pom.xml b/samples/metrics-extend-healthcheck/pom.xml
new file mode 100644
index 0000000..c955c89
--- /dev/null
+++ b/samples/metrics-extend-healthcheck/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>samples</artifactId>
+    <groupId>io.servicecomb.samples</groupId>
+    <version>0.6.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>metrics-extend-healthcheck</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>io.servicecomb</groupId>
+      <artifactId>spring-boot-starter-provider</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate-validator</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>io.servicecomb</groupId>
+      <artifactId>metrics-core</artifactId>
+    </dependency>
+  </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthChecker.java b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthChecker.java
new file mode 100644
index 0000000..1960de8
--- /dev/null
+++ b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthChecker.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.servicecomb.samples.metrics.extendhealthcheck;
+
+import io.servicecomb.metrics.common.HealthCheckResult;
+import io.servicecomb.metrics.common.HealthChecker;
+
+public class CustomHealthChecker implements HealthChecker {
+  @Override
+  public String getName() {
+    return "custom";
+  }
+
+  @Override
+  public HealthCheckResult check() {
+    //add your health check code here
+    return new HealthCheckResult(true, "demo health check", "no extra data");
+  }
+}
diff --git a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/ExtendHealthCheckApplication.java b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/ExtendHealthCheckApplication.java
new file mode 100644
index 0000000..45521b0
--- /dev/null
+++ b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/ExtendHealthCheckApplication.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.servicecomb.samples.metrics.extendhealthcheck;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+import io.servicecomb.springboot.starter.provider.EnableServiceComb;
+
+@SpringBootApplication
+@EnableServiceComb
+public class ExtendHealthCheckApplication {
+  public static void main(String[] args) {
+    SpringApplication.run(ExtendHealthCheckApplication.class, args);
+  }
+}
diff --git a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/SimpleService.java b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/SimpleService.java
new file mode 100644
index 0000000..5e24cb2
--- /dev/null
+++ b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/SimpleService.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.servicecomb.samples.metrics.extendhealthcheck;
+
+import java.util.UUID;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import io.servicecomb.metrics.core.publish.HealthCheckerManager;
+import io.servicecomb.provider.rest.common.RestSchema;
+
+//simple service sim
+@RestSchema(schemaId = "demoServiceEndpoint")
+@RequestMapping(path = "/")
+public class SimpleService {
+
+  private final HealthCheckerManager manager;
+
+  @Autowired
+  public SimpleService(HealthCheckerManager manager) {
+    this.manager = manager;
+
+    //register your custom health check
+    this.manager.register(new CustomHealthChecker());
+  }
+
+  @GetMapping(path = "/f")
+  public String fun() {
+    return UUID.randomUUID().toString();
+  }
+}
\ No newline at end of file
diff --git a/samples/metrics-extend-healthcheck/src/main/resources/microservice.yaml b/samples/metrics-extend-healthcheck/src/main/resources/microservice.yaml
new file mode 100644
index 0000000..524e785
--- /dev/null
+++ b/samples/metrics-extend-healthcheck/src/main/resources/microservice.yaml
@@ -0,0 +1,30 @@
+#
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements.  See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You under the Apache License, Version 2.0
+## (the "License"); you may not use this file except in compliance with
+## the License.  You may obtain a copy of the License at
+##
+##      http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+## ---------------------------------------------------------------------------
+
+# all interconnected microservices must belong to an application wth the same ID
+APPLICATION_ID: metrics
+service_description:
+# name of the declaring microservice
+  name: metricsHealthCheckDemo
+  version: 0.0.1
+cse:
+  service:
+    registry:
+      address: http://127.0.0.1:30100
+  rest:
+    address: 0.0.0.0:7777
\ No newline at end of file
diff --git a/samples/pom.xml b/samples/pom.xml
index 1d735dd..4a78e78 100644
--- a/samples/pom.xml
+++ b/samples/pom.xml
@@ -34,6 +34,7 @@
     <module>auth-sample</module>
     <module>bmi</module>
     <module>metrics-write-file-sample</module>
+    <module>metrics-extend-healthcheck</module>
     <module>config-apollo-sample</module>
   </modules>
 

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 06/13: SCB-166 modify auto registration with spring boot

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit c70ab10d341ff34934a76904099247c305245576
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Tue Jan 9 10:09:01 2018 +0800

    SCB-166 modify auto registration with spring boot
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../java/io/servicecomb/metrics/common/Health.java |  26 ---
 .../core/publish/DefaultHealthCheckerManager.java  |  46 ++---
 .../metrics/core/TestHealthCheckerManager.java     | 217 ++++++++++++++++++++-
 .../CustomHealthCheckerAnnotation.java             |   7 +-
 4 files changed, 233 insertions(+), 63 deletions(-)

diff --git a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/Health.java b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/Health.java
deleted file mode 100644
index eb8c59f..0000000
--- a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/Health.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.servicecomb.metrics.common;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Target;
-
-@Target(value = {ElementType.TYPE})
-public @interface Health {
-
-}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
index 9cb5cb3..667b02a 100644
--- a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
@@ -19,8 +19,6 @@ package io.servicecomb.metrics.core.publish;
 
 import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.ConcurrentHashMap;
@@ -28,12 +26,10 @@ import java.util.stream.Collectors;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
-import org.springframework.core.type.filter.AnnotationTypeFilter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
 import org.springframework.stereotype.Component;
 
-import io.servicecomb.metrics.common.Health;
 import io.servicecomb.metrics.common.HealthCheckResult;
 import io.servicecomb.metrics.common.HealthChecker;
 import io.servicecomb.metrics.core.health.DefaultMicroserviceHealthChecker;
@@ -46,13 +42,21 @@ public class DefaultHealthCheckerManager implements HealthCheckerManager {
 
   private final Map<String, HealthChecker> healthCheckers;
 
-  public DefaultHealthCheckerManager() {
+  private ApplicationContext context;
+
+  @Autowired
+  public DefaultHealthCheckerManager(ApplicationContext context) {
+    this.context = context;
     this.healthCheckers = new ConcurrentHashMap<>();
     HealthChecker defaultHealthChecker = new DefaultMicroserviceHealthChecker();
     this.healthCheckers.put(defaultHealthChecker.getName(), defaultHealthChecker);
 
-    for (HealthChecker checker : getAllAnnotationHealthChecker()) {
-      this.healthCheckers.put(checker.getName(), checker);
+    for (String beanName : context.getBeanDefinitionNames()) {
+      Class<?> beanClass = context.getType(beanName);
+      if (HealthChecker.class.isAssignableFrom(beanClass)) {
+        Object bean = context.getBean(beanName);
+        this.healthCheckers.put(((HealthChecker) bean).getName(), (HealthChecker) bean);
+      }
     }
   }
 
@@ -74,28 +78,4 @@ public class DefaultHealthCheckerManager implements HealthCheckerManager {
     }
     throw new InvocationException(BAD_REQUEST, "HealthChecker name : " + name + " unregister");
   }
-
-  private List<HealthChecker> getAllAnnotationHealthChecker() {
-    List<HealthChecker> checkers = new ArrayList<>();
-    ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
-    scanner.addIncludeFilter(new AnnotationTypeFilter(Health.class));
-    for (BeanDefinition definition : scanner.findCandidateComponents("./")) {
-      try {
-        Class<?> beanClass = Class.forName(definition.getBeanClassName());
-        if (HealthChecker.class.isAssignableFrom(beanClass)) {
-          try {
-            checkers.add((HealthChecker) beanClass.getConstructor(null).newInstance());
-          } catch (Exception e) {
-            logger.error("construct health check class failed", e);
-          }
-        } else {
-          logger.error(
-              "health annotation class:" + definition.getBeanClassName() + " not implement HealthChecker interface");
-        }
-      } catch (ClassNotFoundException e) {
-        logger.error("health check class not found", e);
-      }
-    }
-    return checkers;
-  }
 }
diff --git a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
index db0fa35..9101fd1 100644
--- a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
+++ b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
@@ -18,10 +18,23 @@
 package io.servicecomb.metrics.core;
 
 import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.util.Locale;
 import java.util.Map;
 
 import org.junit.Assert;
 import org.junit.Test;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.MessageSourceResolvable;
+import org.springframework.context.NoSuchMessageException;
+import org.springframework.core.ResolvableType;
+import org.springframework.core.env.Environment;
+import org.springframework.core.io.Resource;
 
 import com.google.common.collect.Lists;
 
@@ -64,7 +77,209 @@ public class TestHealthCheckerManager {
       }
     };
 
-    HealthCheckerManager manager = new DefaultHealthCheckerManager();
+    HealthCheckerManager manager = new DefaultHealthCheckerManager(new ApplicationContext() {
+      @Override
+      public String getId() {
+        return null;
+      }
+
+      @Override
+      public String getApplicationName() {
+        return null;
+      }
+
+      @Override
+      public String getDisplayName() {
+        return null;
+      }
+
+      @Override
+      public long getStartupDate() {
+        return 0;
+      }
+
+      @Override
+      public ApplicationContext getParent() {
+        return null;
+      }
+
+      @Override
+      public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException {
+        return null;
+      }
+
+      @Override
+      public BeanFactory getParentBeanFactory() {
+        return null;
+      }
+
+      @Override
+      public boolean containsLocalBean(String s) {
+        return false;
+      }
+
+      @Override
+      public boolean containsBeanDefinition(String s) {
+        return false;
+      }
+
+      @Override
+      public int getBeanDefinitionCount() {
+        return 0;
+      }
+
+      @Override
+      public String[] getBeanDefinitionNames() {
+        return new String[0];
+      }
+
+      @Override
+      public String[] getBeanNamesForType(ResolvableType resolvableType) {
+        return new String[0];
+      }
+
+      @Override
+      public String[] getBeanNamesForType(Class<?> aClass) {
+        return new String[0];
+      }
+
+      @Override
+      public String[] getBeanNamesForType(Class<?> aClass, boolean b, boolean b1) {
+        return new String[0];
+      }
+
+      @Override
+      public <T> Map<String, T> getBeansOfType(Class<T> aClass) throws BeansException {
+        return null;
+      }
+
+      @Override
+      public <T> Map<String, T> getBeansOfType(Class<T> aClass, boolean b, boolean b1) throws BeansException {
+        return null;
+      }
+
+      @Override
+      public String[] getBeanNamesForAnnotation(Class<? extends Annotation> aClass) {
+        return new String[0];
+      }
+
+      @Override
+      public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> aClass) throws BeansException {
+        return null;
+      }
+
+      @Override
+      public <A extends Annotation> A findAnnotationOnBean(String s, Class<A> aClass)
+          throws NoSuchBeanDefinitionException {
+        return null;
+      }
+
+      @Override
+      public Object getBean(String s) throws BeansException {
+        return null;
+      }
+
+      @Override
+      public <T> T getBean(String s, Class<T> aClass) throws BeansException {
+        return null;
+      }
+
+      @Override
+      public <T> T getBean(Class<T> aClass) throws BeansException {
+        return null;
+      }
+
+      @Override
+      public Object getBean(String s, Object... objects) throws BeansException {
+        return null;
+      }
+
+      @Override
+      public <T> T getBean(Class<T> aClass, Object... objects) throws BeansException {
+        return null;
+      }
+
+      @Override
+      public boolean containsBean(String s) {
+        return false;
+      }
+
+      @Override
+      public boolean isSingleton(String s) throws NoSuchBeanDefinitionException {
+        return false;
+      }
+
+      @Override
+      public boolean isPrototype(String s) throws NoSuchBeanDefinitionException {
+        return false;
+      }
+
+      @Override
+      public boolean isTypeMatch(String s, ResolvableType resolvableType) throws NoSuchBeanDefinitionException {
+        return false;
+      }
+
+      @Override
+      public boolean isTypeMatch(String s, Class<?> aClass) throws NoSuchBeanDefinitionException {
+        return false;
+      }
+
+      @Override
+      public Class<?> getType(String s) throws NoSuchBeanDefinitionException {
+        return null;
+      }
+
+      @Override
+      public String[] getAliases(String s) {
+        return new String[0];
+      }
+
+      @Override
+      public void publishEvent(ApplicationEvent applicationEvent) {
+
+      }
+
+      @Override
+      public void publishEvent(Object o) {
+
+      }
+
+      @Override
+      public String getMessage(String s, Object[] objects, String s1, Locale locale) {
+        return null;
+      }
+
+      @Override
+      public String getMessage(String s, Object[] objects, Locale locale) throws NoSuchMessageException {
+        return null;
+      }
+
+      @Override
+      public String getMessage(MessageSourceResolvable messageSourceResolvable, Locale locale)
+          throws NoSuchMessageException {
+        return null;
+      }
+
+      @Override
+      public Environment getEnvironment() {
+        return null;
+      }
+
+      @Override
+      public Resource[] getResources(String s) throws IOException {
+        return new Resource[0];
+      }
+
+      @Override
+      public Resource getResource(String s) {
+        return null;
+      }
+
+      @Override
+      public ClassLoader getClassLoader() {
+        return null;
+      }
+    });
     Map<String, HealthCheckResult> results = manager.check();
 
     Assert.assertTrue(results.get("default").isHealthy());
diff --git a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthCheckerAnnotation.java b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthCheckerAnnotation.java
index 6816abd..ba6fb7a 100644
--- a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthCheckerAnnotation.java
+++ b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/CustomHealthCheckerAnnotation.java
@@ -17,12 +17,13 @@
 
 package io.servicecomb.samples.metrics.extendhealthcheck;
 
-import io.servicecomb.metrics.common.Health;
+import org.springframework.stereotype.Component;
+
 import io.servicecomb.metrics.common.HealthCheckResult;
 import io.servicecomb.metrics.common.HealthChecker;
 
-//this health check will auto register because Health Annotation
-@Health
+//this health check will auto register because spring bean annotation
+@Component
 public class CustomHealthCheckerAnnotation implements HealthChecker {
   @Override
   public String getName() {

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 07/13: SCB-166 remove metrics perf samples

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 7bf4defbbdf5707fb32f966ba5528aad3494e597
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Tue Jan 9 11:13:56 2018 +0800

    SCB-166 remove metrics perf samples
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 metrics/metrics-extension/pom.xml                  | 32 ---------------
 .../metrics/extendhealthcheck/SimpleService.java   | 48 ----------------------
 .../metrics-write-file-log4j2-springboot/pom.xml   | 11 -----
 3 files changed, 91 deletions(-)

diff --git a/metrics/metrics-extension/pom.xml b/metrics/metrics-extension/pom.xml
deleted file mode 100644
index bdbe4f3..0000000
--- a/metrics/metrics-extension/pom.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  ~ Licensed to the Apache Software Foundation (ASF) under one or more
-  ~ contributor license agreements.  See the NOTICE file distributed with
-  ~ this work for additional information regarding copyright ownership.
-  ~ The ASF licenses this file to You under the Apache License, Version 2.0
-  ~ (the "License"); you may not use this file except in compliance with
-  ~ the License.  You may obtain a copy of the License at
-  ~
-  ~     http://www.apache.org/licenses/LICENSE-2.0
-  ~
-  ~ Unless required by applicable law or agreed to in writing, software
-  ~ distributed under the License is distributed on an "AS IS" BASIS,
-  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  ~ See the License for the specific language governing permissions and
-  ~ limitations under the License.
-  -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-  <parent>
-    <artifactId>metrics</artifactId>
-    <groupId>io.servicecomb</groupId>
-    <version>0.6.0-SNAPSHOT</version>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-
-  <artifactId>metrics-extension</artifactId>
-  <packaging>pom</packaging>
-
-</project>
\ No newline at end of file
diff --git a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/SimpleService.java b/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/SimpleService.java
deleted file mode 100644
index a25cdba..0000000
--- a/samples/metrics-extend-healthcheck/src/main/java/io/servicecomb/samples/metrics/extendhealthcheck/SimpleService.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.servicecomb.samples.metrics.extendhealthcheck;
-
-import java.util.UUID;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import io.servicecomb.metrics.core.publish.HealthCheckerManager;
-import io.servicecomb.provider.rest.common.RestSchema;
-
-//simple service sim
-@RestSchema(schemaId = "demoServiceEndpoint")
-@RequestMapping(path = "/")
-public class SimpleService {
-
-  private final HealthCheckerManager manager;
-
-  @Autowired
-  public SimpleService(HealthCheckerManager manager) {
-    this.manager = manager;
-
-    //register your custom health check
-    this.manager.register(new MySqlHealthChecker());
-  }
-
-  @GetMapping(path = "/f")
-  public String fun() {
-    return UUID.randomUUID().toString();
-  }
-}
\ No newline at end of file
diff --git a/samples/metrics-write-file-sample/metrics-write-file-log4j2-springboot/pom.xml b/samples/metrics-write-file-sample/metrics-write-file-log4j2-springboot/pom.xml
index ee79782..bae5e61 100644
--- a/samples/metrics-write-file-sample/metrics-write-file-log4j2-springboot/pom.xml
+++ b/samples/metrics-write-file-sample/metrics-write-file-log4j2-springboot/pom.xml
@@ -70,14 +70,3 @@
     </dependency>
 
   </dependencies>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.springframework.boot</groupId>
-        <artifactId>spring-boot-maven-plugin</artifactId>
-      </plugin>
-    </plugins>
-  </build>
-
-</project>
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 01/13: SCB-166 add health check implement

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit ca84f1708aa09e0599c079ea1e12e7d1e718d5aa
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Thu Jan 4 17:58:27 2018 +0800

    SCB-166 add health check implement
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../common/DefaultHealthCheckExtraData.java        | 69 ++++++++++++++++++
 .../metrics/common/HealthCheckResult.java          | 56 +++++++++++++++
 .../servicecomb/metrics/common/HealthChecker.java  | 24 +++++++
 .../metrics/common/HealthCheckerPublisher.java     | 26 +++++++
 .../health/DefaultMicroserviceHealthChecker.java   | 60 ++++++++++++++++
 .../core/publish/DefaultHealthCheckerManager.java  | 62 +++++++++++++++++
 .../publish/DefaultHealthCheckerPublisher.java     | 59 ++++++++++++++++
 .../metrics/core/publish/HealthCheckerManager.java | 31 +++++++++
 .../metrics/core/TestHealthCheckerManager.java     | 81 ++++++++++++++++++++++
 .../metrics/core/TestHealthCheckerPublisher.java   | 59 ++++++++++++++++
 10 files changed, 527 insertions(+)

diff --git a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/DefaultHealthCheckExtraData.java b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/DefaultHealthCheckExtraData.java
new file mode 100644
index 0000000..aa2c9b4
--- /dev/null
+++ b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/DefaultHealthCheckExtraData.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.servicecomb.metrics.common;
+
+public class DefaultHealthCheckExtraData {
+  private String instanceId;
+
+  private String hostName;
+
+  private String appId;
+
+  private String serviceName;
+
+  private String serviceVersion;
+
+  private String endpoints;
+
+  public String getInstanceId() {
+    return instanceId;
+  }
+
+  public String getHostName() {
+    return hostName;
+  }
+
+  public String getAppId() {
+    return appId;
+  }
+
+  public String getServiceName() {
+    return serviceName;
+  }
+
+  public String getServiceVersion() {
+    return serviceVersion;
+  }
+
+  public String getEndpoints() {
+    return endpoints;
+  }
+
+  public DefaultHealthCheckExtraData() {
+  }
+
+  public DefaultHealthCheckExtraData(String instanceId, String hostName, String appId, String serviceName,
+      String serviceVersion, String endpoints) {
+    this.instanceId = instanceId;
+    this.hostName = hostName;
+    this.appId = appId;
+    this.serviceName = serviceName;
+    this.serviceVersion = serviceVersion;
+    this.endpoints = endpoints;
+  }
+}
diff --git a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckResult.java b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckResult.java
new file mode 100644
index 0000000..b44d8df
--- /dev/null
+++ b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckResult.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.servicecomb.metrics.common;
+
+public class HealthCheckResult {
+  private boolean isHealth;
+
+  private String information;
+
+  //unsupport object or generic type,so string..
+  private String extraData;
+
+  private long timestamp;
+
+  public boolean isHealth() {
+    return isHealth;
+  }
+
+  public String getInformation() {
+    return information;
+  }
+
+  public String getExtraData() {
+    return extraData;
+  }
+
+  public long getTimestamp() {
+    return timestamp;
+  }
+
+  public HealthCheckResult() {
+  }
+
+  public HealthCheckResult(boolean isHealth, String information, String extraData) {
+    this();
+    this.isHealth = isHealth;
+    this.information = information;
+    this.extraData = extraData;
+    this.timestamp = System.currentTimeMillis();
+  }
+}
diff --git a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthChecker.java b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthChecker.java
new file mode 100644
index 0000000..69025e1
--- /dev/null
+++ b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthChecker.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.servicecomb.metrics.common;
+
+public interface HealthChecker {
+  String getName();
+
+  HealthCheckResult check();
+}
diff --git a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckerPublisher.java b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckerPublisher.java
new file mode 100644
index 0000000..68aacca
--- /dev/null
+++ b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckerPublisher.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.servicecomb.metrics.common;
+
+import java.util.Map;
+
+public interface HealthCheckerPublisher {
+  Map<String, HealthCheckResult> health();
+
+  HealthCheckResult healthWithName(String name);
+}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
new file mode 100644
index 0000000..1e96b11
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/health/DefaultMicroserviceHealthChecker.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.servicecomb.metrics.core.health;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+import io.servicecomb.foundation.common.exceptions.ServiceCombException;
+import io.servicecomb.foundation.common.utils.JsonUtils;
+import io.servicecomb.metrics.common.DefaultHealthCheckExtraData;
+import io.servicecomb.metrics.common.HealthCheckResult;
+import io.servicecomb.metrics.common.HealthChecker;
+import io.servicecomb.serviceregistry.RegistryUtils;
+import io.servicecomb.serviceregistry.api.registry.Microservice;
+import io.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+
+public class DefaultMicroserviceHealthChecker implements HealthChecker {
+
+  private final String extraData;
+
+  public DefaultMicroserviceHealthChecker() {
+    try {
+      Microservice microservice = RegistryUtils.getMicroservice();
+      MicroserviceInstance instance = RegistryUtils.getMicroserviceInstance();
+      extraData = JsonUtils.writeValueAsString(new DefaultHealthCheckExtraData(
+          instance.getInstanceId(),
+          instance.getHostName(),
+          microservice.getAppId(),
+          microservice.getServiceName(),
+          microservice.getVersion(),
+          String.join(",", instance.getEndpoints())));
+    } catch (JsonProcessingException e) {
+      throw new ServiceCombException("unable load microservice info for healthchecker", e);
+    }
+  }
+
+  @Override
+  public String getName() {
+    return "default";
+  }
+
+  @Override
+  public HealthCheckResult check() {
+    return new HealthCheckResult(true, "", extraData);
+  }
+}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
new file mode 100644
index 0000000..0393ab9
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerManager.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.servicecomb.metrics.core.publish;
+
+import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+import org.springframework.stereotype.Component;
+
+import io.servicecomb.metrics.common.HealthCheckResult;
+import io.servicecomb.metrics.common.HealthChecker;
+import io.servicecomb.metrics.core.health.DefaultMicroserviceHealthChecker;
+import io.servicecomb.swagger.invocation.exception.InvocationException;
+
+@Component
+public class DefaultHealthCheckerManager implements HealthCheckerManager {
+  private final Map<String, HealthChecker> healthCheckers;
+
+  public DefaultHealthCheckerManager() {
+    this.healthCheckers = new ConcurrentHashMap<>();
+    HealthChecker defaultHealthChecker = new DefaultMicroserviceHealthChecker();
+    this.healthCheckers.put(defaultHealthChecker.getName(), defaultHealthChecker);
+  }
+
+  @Override
+  public void register(HealthChecker checker) {
+    healthCheckers.put(checker.getName(), checker);
+  }
+
+  @Override
+  public Map<String, HealthCheckResult> check() {
+    return healthCheckers.entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> e.getValue().check()));
+  }
+
+  @Override
+  public HealthCheckResult check(String name) {
+    HealthChecker checker = healthCheckers.get(name);
+    if (checker != null) {
+      return checker.check();
+    }
+    throw new InvocationException(BAD_REQUEST, "HealthChecker name : " + name + " unregister");
+  }
+}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerPublisher.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerPublisher.java
new file mode 100644
index 0000000..69eb6b1
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/DefaultHealthCheckerPublisher.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.servicecomb.metrics.core.publish;
+
+import java.util.Map;
+
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+import io.servicecomb.metrics.common.HealthCheckResult;
+import io.servicecomb.metrics.common.HealthCheckerPublisher;
+import io.servicecomb.provider.rest.common.RestSchema;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+@RestSchema(schemaId = "metricsEndpoint")
+@RequestMapping(path = "/health")
+public class DefaultHealthCheckerPublisher implements HealthCheckerPublisher {
+
+  private final HealthCheckerManager manager;
+
+  public DefaultHealthCheckerPublisher(HealthCheckerManager manager) {
+    this.manager = manager;
+  }
+
+  @RequestMapping(path = "/", method = RequestMethod.GET)
+  @CrossOrigin
+  @Override
+  public Map<String, HealthCheckResult> health() {
+    return manager.check();
+  }
+
+  @ApiResponses({
+      @ApiResponse(code = 400, response = String.class, message = "illegal request content"),
+  })
+  @RequestMapping(path = "/{name}", method = RequestMethod.GET)
+  @CrossOrigin
+  @Override
+  public HealthCheckResult healthWithName(@PathVariable(name = "name") String name) {
+    return manager.check(name);
+  }
+}
diff --git a/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/HealthCheckerManager.java b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/HealthCheckerManager.java
new file mode 100644
index 0000000..693a7fd
--- /dev/null
+++ b/metrics/metrics-core/src/main/java/io/servicecomb/metrics/core/publish/HealthCheckerManager.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.servicecomb.metrics.core.publish;
+
+import java.util.Map;
+
+import io.servicecomb.metrics.common.HealthCheckResult;
+import io.servicecomb.metrics.common.HealthChecker;
+
+public interface HealthCheckerManager {
+  void register(HealthChecker checker);
+
+  Map<String,HealthCheckResult> check();
+
+  HealthCheckResult check(String name);
+}
diff --git a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
new file mode 100644
index 0000000..4beaf66
--- /dev/null
+++ b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.servicecomb.metrics.core;
+
+import java.io.IOException;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.google.common.collect.Lists;
+
+import io.servicecomb.foundation.common.utils.JsonUtils;
+import io.servicecomb.metrics.common.DefaultHealthCheckExtraData;
+import io.servicecomb.metrics.common.HealthCheckResult;
+import io.servicecomb.metrics.core.publish.DefaultHealthCheckerManager;
+import io.servicecomb.metrics.core.publish.HealthCheckerManager;
+import io.servicecomb.serviceregistry.RegistryUtils;
+import io.servicecomb.serviceregistry.api.registry.Microservice;
+import io.servicecomb.serviceregistry.api.registry.MicroserviceInstance;
+import mockit.Expectations;
+
+public class TestHealthCheckerManager {
+
+  @Test
+  public void testRegistry() throws IOException {
+
+    Microservice microservice = new Microservice();
+    microservice.setAppId("appId");
+    microservice.setServiceName("serviceName");
+    microservice.setVersion("0.0.1");
+
+    MicroserviceInstance microserviceInstance = new MicroserviceInstance();
+    microserviceInstance.setEndpoints(Lists.newArrayList("127.0.0.1", "192.168.0.100"));
+    microserviceInstance.setInstanceId("001");
+    microserviceInstance.setHostName("localhost");
+
+    new Expectations(RegistryUtils.class) {
+      {
+        RegistryUtils.getMicroservice();
+        result = microservice;
+      }
+    };
+
+    new Expectations(RegistryUtils.class) {
+      {
+        RegistryUtils.getMicroserviceInstance();
+        result = microserviceInstance;
+      }
+    };
+
+    HealthCheckerManager manager = new DefaultHealthCheckerManager();
+    Map<String, HealthCheckResult> results = manager.check();
+
+    Assert.assertTrue(results.get("default").isHealth());
+
+    DefaultHealthCheckExtraData data = JsonUtils.OBJ_MAPPER
+        .readValue(results.get("default").getExtraData(), DefaultHealthCheckExtraData.class);
+    Assert.assertTrue(data.getAppId().equals("appId"));
+    Assert.assertTrue(data.getServiceName().equals("serviceName"));
+    Assert.assertTrue(data.getServiceVersion().equals("0.0.1"));
+    Assert.assertTrue(data.getInstanceId().equals("001"));
+    Assert.assertTrue(data.getHostName().equals("localhost"));
+    Assert.assertTrue(data.getEndpoints().equals("127.0.0.1,192.168.0.100"));
+  }
+}
diff --git a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerPublisher.java b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerPublisher.java
new file mode 100644
index 0000000..44978df
--- /dev/null
+++ b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerPublisher.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.servicecomb.metrics.core;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+import io.servicecomb.foundation.common.utils.JsonUtils;
+import io.servicecomb.metrics.common.HealthCheckResult;
+import io.servicecomb.metrics.common.HealthCheckerPublisher;
+import io.servicecomb.metrics.core.publish.DefaultHealthCheckerPublisher;
+import io.servicecomb.metrics.core.publish.HealthCheckerManager;
+
+public class TestHealthCheckerPublisher {
+
+  @Test
+  public void testPublisher() throws JsonProcessingException {
+    HealthCheckerManager manager = mock(HealthCheckerManager.class);
+
+    Map<String, HealthCheckResult> results = new HashMap<>();
+    HealthCheckResult result = new HealthCheckResult(true, "ok", "extra");
+    results.put("default", result);
+
+    when(manager.check()).thenReturn(results);
+    when(manager.check("default")).thenReturn(result);
+
+    HealthCheckerPublisher publisher = new DefaultHealthCheckerPublisher(manager);
+    Map<String, HealthCheckResult> content = publisher.health();
+    Assert.assertTrue(JsonUtils.writeValueAsString(content.get("default"))
+        .equals(JsonUtils.writeValueAsString(result)));
+
+    HealthCheckResult checkResult = publisher.healthWithName("default");
+    Assert.assertTrue(JsonUtils.writeValueAsString(checkResult)
+        .equals(JsonUtils.writeValueAsString(result)));
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 11/13: SCB-166 rebase and fix

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit eb23f0f13bcdd8acc017ce20cca8cdc028043162
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Tue Jan 9 17:46:57 2018 +0800

    SCB-166 rebase and fix
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 metrics/metrics-extension/pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/metrics/metrics-extension/pom.xml b/metrics/metrics-extension/pom.xml
index a597152..bdbe4f3 100644
--- a/metrics/metrics-extension/pom.xml
+++ b/metrics/metrics-extension/pom.xml
@@ -26,7 +26,7 @@
   </parent>
   <modelVersion>4.0.0</modelVersion>
 
-  <artifactId>metrics-integration</artifactId>
+  <artifactId>metrics-extension</artifactId>
   <packaging>pom</packaging>
 
 </project>
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.

[incubator-servicecomb-java-chassis] 05/13: SCB-166 fix pr comment

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 52dc7e67d6933601059b703f636901b0d9b77a27
Author: zhengyangyong <ya...@huawei.com>
AuthorDate: Mon Jan 8 12:55:13 2018 +0800

    SCB-166 fix pr comment
    
    Signed-off-by: zhengyangyong <ya...@huawei.com>
---
 .../java/io/servicecomb/metrics/common/HealthCheckResult.java  | 10 +++++-----
 metrics/metrics-core/pom.xml                                   |  4 ----
 .../io/servicecomb/metrics/core/TestHealthCheckerManager.java  |  2 +-
 3 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckResult.java b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckResult.java
index b44d8df..022250e 100644
--- a/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckResult.java
+++ b/metrics/metrics-common/src/main/java/io/servicecomb/metrics/common/HealthCheckResult.java
@@ -18,7 +18,7 @@
 package io.servicecomb.metrics.common;
 
 public class HealthCheckResult {
-  private boolean isHealth;
+  private boolean isHealthy;
 
   private String information;
 
@@ -27,8 +27,8 @@ public class HealthCheckResult {
 
   private long timestamp;
 
-  public boolean isHealth() {
-    return isHealth;
+  public boolean isHealthy() {
+    return isHealthy;
   }
 
   public String getInformation() {
@@ -46,9 +46,9 @@ public class HealthCheckResult {
   public HealthCheckResult() {
   }
 
-  public HealthCheckResult(boolean isHealth, String information, String extraData) {
+  public HealthCheckResult(boolean isHealthy, String information, String extraData) {
     this();
-    this.isHealth = isHealth;
+    this.isHealthy = isHealthy;
     this.information = information;
     this.extraData = extraData;
     this.timestamp = System.currentTimeMillis();
diff --git a/metrics/metrics-core/pom.xml b/metrics/metrics-core/pom.xml
index 17115e4..2566bbe 100644
--- a/metrics/metrics-core/pom.xml
+++ b/metrics/metrics-core/pom.xml
@@ -47,10 +47,6 @@
       <artifactId>slf4j-log4j12</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-core</artifactId>
-    </dependency>
   </dependencies>
 
 </project>
\ No newline at end of file
diff --git a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
index 4beaf66..db0fa35 100644
--- a/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
+++ b/metrics/metrics-core/src/test/java/io/servicecomb/metrics/core/TestHealthCheckerManager.java
@@ -67,7 +67,7 @@ public class TestHealthCheckerManager {
     HealthCheckerManager manager = new DefaultHealthCheckerManager();
     Map<String, HealthCheckResult> results = manager.check();
 
-    Assert.assertTrue(results.get("default").isHealth());
+    Assert.assertTrue(results.get("default").isHealthy());
 
     DefaultHealthCheckExtraData data = JsonUtils.OBJ_MAPPER
         .readValue(results.get("default").getExtraData(), DefaultHealthCheckExtraData.class);

-- 
To stop receiving notification emails like this one, please contact
"commits@servicecomb.apache.org" <co...@servicecomb.apache.org>.