Add retry to ueb-listener 81/17681/1
authorDan Timoney <dtimoney@att.com>
Mon, 9 Oct 2017 14:02:22 +0000 (10:02 -0400)
committerDan Timoney <dtimoney@att.com>
Mon, 9 Oct 2017 14:02:22 +0000 (10:02 -0400)
Added retry mechanism to ueb-listener to handle case where
ueb-listener comes up before DMaap or SDC.

Change-Id: I0d96bd1fe4d3d0fdb5e01d9f42304b54bea0a550
Issue-ID: CCSDK-112
Signed-off-by: Dan Timoney <dtimoney@att.com>
ueb-listener/src/assembly/assemble_zip.xml
ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebClient.java
ueb-listener/src/main/java/org/onap/ccsdk/sli/northbound/uebclient/SdncUebConfiguration.java
ueb-listener/src/test/resources/ueb-listener.properties

index 97a229d..7a21aca 100644 (file)
@@ -8,9 +8,9 @@
   Licensed 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.
@@ -34,7 +34,7 @@
 
        <fileSets>
                <fileSet>
-                       <directory>src/main/bin</directory>
+                       <directory>src/main/scripts</directory>
                        <outputDirectory>bin</outputDirectory>
                </fileSet>
                <fileSet>
index d298904..1d1f476 100644 (file)
@@ -39,6 +39,7 @@ public class SdncUebClient {
 
                SdncUebCallback cb = new SdncUebCallback(client, config);
 
+
                LOG.info("Scanning for local distribution artifacts before starting client");
                cb.deployDownloadedFiles(null, null, null);
 
@@ -48,13 +49,39 @@ public class SdncUebClient {
 
                LOG.info("Initialized ASDC distribution client - results = {}", result.getDistributionMessageResult());
 
-               if (result.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) {
-                       LOG.info("Starting client...");
-                       IDistributionClientResult start = client.start();
-                       LOG.info("Client startup result = {}", start.getDistributionMessageResult());
+               long startTm = System.currentTimeMillis();
+               int sleepTm = config.getPollingInterval() * 1000;
+               long maxWaitTm = config.getClientStartupTimeout() * 1000;
+
+               boolean keepWaiting = true;
+
+               while (keepWaiting) {
+                       if (result.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) {
+                               LOG.info("Starting client...");
+                               try {
+                                       IDistributionClientResult start = client.start();
+                                       LOG.info("Client startup result = {}", start.getDistributionMessageResult());
+                                       keepWaiting = false;
+                               } catch(Exception e) {
+                                       LOG.info("Client startup failure", e);
+                               }
+
+                               if (System.currentTimeMillis() - startTm < maxWaitTm) {
+                                       keepWaiting = false;
+                               } else {
+
+                                       try {
+                                               Thread.sleep(sleepTm);
+                                       } catch (InterruptedException e) {
+                                               // Ignore
+                                       }
+                               }
+                       }
+
                }
 
 
+
        }
 
 }
index 75cb9c9..bf7dc88 100644 (file)
@@ -46,6 +46,7 @@ public class SdncUebConfiguration implements IConfiguration{
        private String password = null;
        private int pollingInterval = 30;
        private int pollingTimeout = 15;
+       private int clientStartupTimeout = 900;
        private List<String> relevantArtifactTypes = null;
        private String user = null;
 
@@ -154,6 +155,14 @@ public class SdncUebConfiguration implements IConfiguration{
                        }
                }
 
+               curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.client-startup-timeout");
+               if ((curval != null) && (curval.length() > 0)) {
+                       try {
+                               clientStartupTimeout = Integer.parseInt(curval);
+                       } catch (Exception e) {
+                               LOG.warn("Illegal value for org.onap.ccsdk.sli.northbound.uebclient.polling-timeout ({}) ", curval, e);
+                       }
+               }
                curval = props.getProperty("org.onap.ccsdk.sli.northbound.uebclient.relevant-artifact-types");
                if ((curval != null) && (curval.length() > 0)) {
                        String[] artifactTypes = curval.split(",");
@@ -225,6 +234,10 @@ public class SdncUebConfiguration implements IConfiguration{
                return relevantArtifactTypes;
        }
 
+       public int getClientStartupTimeout() {
+               return clientStartupTimeout;
+       }
+
        @Override
        public String getUser() {
                return user;
index 4b9886e..35c3805 100755 (executable)
@@ -12,6 +12,7 @@ org.onap.ccsdk.sli.northbound.uebclient.spool.incoming=src/test/resources/incomi
 org.onap.ccsdk.sli.northbound.uebclient.spool.archive=src/test/resources/archive
 org.onap.ccsdk.sli.northbound.uebclient.polling-interval=30
 org.onap.ccsdk.sli.northbound.uebclient.polling-timeout=15
+org.onap.ccsdk.sli.northbound.uebclient.client-startup-timeout=60
 org.onap.ccsdk.sli.northbound.uebclient.relevant-artifact-types=YANG_XML,VF_LICENSE,TOSCA_TEMPLATE,TOSCA_CSAR,UCPE_LAYER_2_CONFIGURATION
 org.onap.ccsdk.sli.northbound.uebclient.activate-server-tls-auth=false
 org.onap.ccsdk.sli.northbound.uebclient.keystore-path=