[SECIOTSRK-681] *Add health check for server MQ: check dsm host before check url
authorm.dalakov <m.dalakov@samsung.com>
Tue, 7 Nov 2017 16:57:44 +0000 (18:57 +0200)
committerm.dalakov <m.dalakov@samsung.com>
Tue, 7 Nov 2017 16:57:44 +0000 (18:57 +0200)
servers/mq/src/main/java/com/samsung/servermq/HealthCheck.java

index 242c55b..e51982c 100644 (file)
@@ -27,7 +27,6 @@ import static org.iotivity.cloud.util.HealthCheck.checkSocket;
         @PropertySource("classpath:iotivity.properties") })
 public class HealthCheck {
 
-    private static AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
     private static final Logger LOG = Logger.getLogger(HealthCheck.class);
 
     private static void sleep() {
@@ -50,22 +49,20 @@ public class HealthCheck {
                 return true;
             }
         } catch (IOException e) {
-            LOG.debug("checkUrl exception ", e);
+            LOG.debug("checkUrl exception: " + e.getMessage());
         }
         LOG.info(url+" not available...");
         return false;
     }
 
-    private static void checkHost(String prop) {
-        String host = ctx.getEnvironment().getRequiredProperty(prop);
+    private static void checkHost(String host) {
         while (!checkSocket(host)) {
             sleep();
             LOG.info("can not connect to "+host+"...");
         }
     }
 
-    private static void checkDsm(String prop) {
-        String url = ctx.getEnvironment().getRequiredProperty(prop);
+    private static void checkDsm(String url) {
         while (!checkUrl(url)) {
             sleep();
             LOG.info("can not connect to "+url+"...");
@@ -73,11 +70,15 @@ public class HealthCheck {
     }
 
     static void checkDependencies() {
+        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
         ctx.register(HealthCheck.class);
         ctx.refresh();
-        checkHost("iotivity.zookeeper_host");
-        checkHost("iotivity.kafka_host");
-        checkDsm("dsm.host");
+        checkHost(ctx.getEnvironment().getRequiredProperty("iotivity.zookeeper_host"));
+        checkHost(ctx.getEnvironment().getRequiredProperty("iotivity.kafka_host"));
+        String dsmUrl = ctx.getEnvironment().getRequiredProperty("dsm.host");
+        String dsmHost = dsmUrl.replace("http://", "");
+        checkHost(dsmHost);
+        checkDsm(dsmUrl);
     }
 
     /**