adjust msb integration 57/67657/2
authorQuoc-Nghia Nguyen <quocnghia.nguyen@orange.com>
Wed, 19 Sep 2018 09:16:06 +0000 (11:16 +0200)
committerQuoc-Nghia Nguyen <quocnghia.nguyen@orange.com>
Wed, 19 Sep 2018 11:06:27 +0000 (13:06 +0200)
Change-Id: Ie74c85404935652548d682f33c3b52c819a81c2b
Issue-ID: EXTAPI-90
Signed-off-by: Quoc-Nghia Nguyen <quocnghia.nguyen@orange.com>
.env
src/main/java/org/onap/nbi/ServiceRegisterRunner.java
src/main/resources/application.properties
src/test/resources/application.properties

diff --git a/.env b/.env
index 0aba3a4..71c1433 100644 (file)
--- a/.env
+++ b/.env
@@ -47,14 +47,6 @@ SO_API_ID=SO
 
 # MSB
 MSB_ENABLED=false
-MSB_DISCOVERY_HOST=msb_discovery
-MSB_SERVICE_HOST=
-MSB_SERVICE_PORT=8080
-MSB_SERVICE_NAME=nbi
-MSB_SERVICE_CUSTOM_PATH=
-MSB_SERVICE_PROTOCOL=REST
-MSB_SERVICE_VISUAL_RANGE=1
-MSB_SERVICE_ENABLE_SSL=false
 
 # MONGO
 SPRING_DATA_MONGODB_HOST=localhost
index 5e0c711..8c10e56 100644 (file)
@@ -46,6 +46,12 @@ public class ServiceRegisterRunner implements CommandLineRunner {
     @Value("${msb.discovery.port}")
     private int DISCOVERY_PORT;
 
+    @Value("${msb.discovery.retry}")
+    private int RETRY;
+
+    @Value("${msb.discovery.retry_interval}")
+    private int RETRY_INTERVAL;
+
     @Value("${msb.service.host}")
     private String SERVICE_HOST;
 
@@ -75,7 +81,10 @@ public class ServiceRegisterRunner implements CommandLineRunner {
 
     @Override
     public void run(String... strings) throws Exception {
-        if (!IS_ENABLED) return;
+        if (!IS_ENABLED) {
+            logger.info("Registration with msb discovery is not enabled");
+            return;
+        }
 
         MicroServiceInfo msinfo = new MicroServiceInfo();
         msinfo.setServiceName(SERVICE_NAME);
@@ -99,21 +108,34 @@ public class ServiceRegisterRunner implements CommandLineRunner {
         msinfo.setNodes(nodes);
 
         logger.info(
-                "Register this service with msb discovery (" + DISCOVERY_HOST + ":" + DISCOVERY_PORT + "):\n"
+                "Registering with msb discovery (" + DISCOVERY_HOST + ":" + DISCOVERY_PORT + "):\n"
                         + " - host: [" + thisNode.getIp() + "]\n"
                         + " - port: [" + thisNode.getPort() + "]\n"
                         + " - name: [" + msinfo.getServiceName() + "]\n"
                         + " - version: [" + msinfo.getVersion() + "]\n"
                         + " - url: [" + msinfo.getUrl() + "]\n"
                         + " - path: [" + msinfo.getPath() + "]\n"
-                        + " - protocol: [" + msinfo.getProtocol() + "]\n"
+                        + " - protocol: [" + msinfo.getProtocol() + "]g\n"
                         + " - visualRange: [" + msinfo.getVisualRange() + "]\n"
                         + " - enableSSL: [" + SERVICE_ENABLE_SSL + "]\n"
         );
 
-        MSBServiceClient msbClient = new MSBServiceClient(DISCOVERY_HOST, DISCOVERY_PORT);
-        MicroServiceFullInfo microServiceFullInfo = msbClient.registerMicroServiceInfo(msinfo);
-
-        logger.debug("microServiceFullInfo = {}", microServiceFullInfo.toString());
+        int attempt = 0;
+        while (true) {
+            attempt += 1;
+            try {
+                logger.info("Registration with msb discovery (attempt {}/{})", attempt, RETRY);
+                MSBServiceClient msbClient = new MSBServiceClient(DISCOVERY_HOST, DISCOVERY_PORT);
+                MicroServiceFullInfo microServiceFullInfo = msbClient.registerMicroServiceInfo(msinfo);
+                logger.debug("Registration with msb discovery done, microServiceFullInfo = {}", microServiceFullInfo.toString());
+                break;
+            } catch (Exception ex) {
+                if (attempt == RETRY) {
+                    throw new Exception("Registration with msb discovery FAILED");
+                }
+            }
+            logger.info("Registration with msb discovery (attempt {}/{}) FAILED. Sleep {}ms", attempt, RETRY, RETRY_INTERVAL);
+            Thread.sleep(RETRY_INTERVAL);
+        }
     }
 }
index c6289fa..a6184f0 100644 (file)
@@ -58,6 +58,8 @@ so.project.name=Project-generic
 msb.enabled=true
 msb.discovery.host=msb_discovery
 msb.discovery.port=10081
+msb.discovery.retry=5
+msb.discovery.retry_interval=5000
 msb.service.host=
 msb.service.name=nbi
 msb.service.custom_path=
index 2dc0a70..bcd8fb9 100644 (file)
@@ -58,6 +58,8 @@ so.project.name=Project-generic
 msb.enabled=false
 msb.discovery.host=msb_discovery
 msb.discovery.port=10081
+msb.discovery.retry=5
+msb.discovery.retry_interval=5000
 msb.service.host=
 msb.service.name=nbi
 msb.service.custom_path=