Added some debug info
[holmes/common.git] / holmes-actions / src / main / java / org / onap / holmes / common / utils / MsbRegister.java
index ff5b48a..018da17 100644 (file)
@@ -36,7 +36,7 @@ import static org.onap.holmes.common.utils.JerseyClient.PROTOCOL_HTTPS;
 public class MsbRegister {
     private static final Logger log = LoggerFactory.getLogger(MsbRegister.class);
 
-    private JerseyClient client = new JerseyClient();
+    private JerseyClient client = JerseyClient.newInstance();
 
     public MsbRegister() {
     }
@@ -48,28 +48,33 @@ public class MsbRegister {
                 && msbAddrInfo[1].equals("443");
 
         log.info("Start to register Holmes Service to MSB...");
+        log.info("Registration information: {}", GsonUtil.beanToJson(msinfo));
 
         MicroServiceFullInfo microServiceFullInfo = null;
         int retry = 0;
         int interval = 5;
         while (null == microServiceFullInfo && retry < 20) {
-            log.info("Holmes Service Registration. Retry: " + retry++);
-
-            microServiceFullInfo = client
-                    .header("Accept", MediaType.APPLICATION_JSON)
-                    .queryParam("createOrUpdate", true)
-                    .post(String.format("%s://%s:%s/api/microservices/v1/services",
-                            isHttpsEnabled ? PROTOCOL_HTTPS : PROTOCOL_HTTP, msbAddrInfo[0], msbAddrInfo[1]),
-                            Entity.entity(msinfo, MediaType.APPLICATION_JSON),
-                            MicroServiceFullInfo.class);
-
-            if (null == microServiceFullInfo) {
-                log.warn(String.format("Failed to register the service to MSB. Sleep %ds and try again.", interval));
-                threadSleep(TimeUnit.SECONDS.toSeconds(interval));
-                interval += 5;
-            } else {
-                log.info("Registration succeeded!");
-                break;
+            try {
+                log.info("Holmes Service Registration. Retry: " + retry++);
+
+                microServiceFullInfo = client
+                        .header("Accept", MediaType.APPLICATION_JSON)
+                        .queryParam("createOrUpdate", true)
+                        .post(String.format("%s://%s:%s/api/microservices/v1/services",
+                                isHttpsEnabled ? PROTOCOL_HTTPS : PROTOCOL_HTTP, msbAddrInfo[0], msbAddrInfo[1]),
+                                Entity.entity(msinfo, MediaType.APPLICATION_JSON),
+                                MicroServiceFullInfo.class);
+
+                if (null == microServiceFullInfo) {
+                    log.warn(String.format("Failed to register the service to MSB. Sleep %ds and try again.", interval));
+                    threadSleep(TimeUnit.SECONDS.toSeconds(interval));
+                    interval += 5;
+                } else {
+                    log.info("Registration succeeded!");
+                    break;
+                }
+            } catch (Exception e) {
+                log.warn("Unexpected exception: " + e.getMessage(), e);
             }
         }