Changes to Config Component Adaptor 37/55437/4
authorBalaji, Ramya (rb111y) <rb111y@att.com>
Tue, 26 Jun 2018 17:44:27 +0000 (13:44 -0400)
committerTakamune Cho <tc012c@att.com>
Fri, 29 Jun 2018 18:03:11 +0000 (18:03 +0000)
Issue-ID: APPC-1014
Change-Id: I1ac95c68df92e39678b64919357333cd1664218d
Signed-off-by: Balaji, Ramya (rb111y) <rb111y@att.com>
appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/ConfigComponentAdaptor.java
appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/SshJcraftWrapper.java
appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java

index 6ff4a86..bffa396 100644 (file)
@@ -56,6 +56,7 @@ private String auditUser = null;
 private String auditPassword = null;
 private String configCallbackUrl = null;
 private String auditCallbackUrl = null;
+private int DEFAULT_TIMEOUT_GETRUNNING_CLI = 120 * 1000 ;
 
 public ConfigComponentAdaptor(Properties props) {
     if (props != null) {
@@ -307,7 +308,9 @@ public ConfigStatus configure(String key, Map<String, String> parameters, SvcLog
                         DebugLog.printAriDebug(fnName, "Found a Response line: line=" + line);
                         String delemeter = getStringBetweenQuotes(line);
                         DebugLog.printAriDebug(fnName, "The delemeter=" + delemeter);
-                        String tmpResponse = sshJcraftWrapper.receiveUntil(delemeter, 30 * 1000, command);
+                        //DEFAULT_TIMEOUT_GETRUNNING_CLI : changed the default time out to 2 mins in 1806
+                        String tmpResponse = sshJcraftWrapper.receiveUntil(delemeter,
+                                             DEFAULT_TIMEOUT_GETRUNNING_CLI, command);
                         response += tmpResponse;
                         if (showConfigFlag) {
                             showConfigFlag = false;
@@ -383,7 +386,7 @@ public ConfigStatus configure(String key, Map<String, String> parameters, SvcLog
             loadConfigurationString = loadConfigurationString + "]]>]]>";
             sshJcraftWrapper.send(loadConfigurationString);
             DebugLog.printAriDebug(fnName, ":After sending loadConfigurationString");
-            response = sshJcraftWrapper.receiveUntil("]]>]]>", 600000, "");
+            response = sshJcraftWrapper.receiveUntil("</rpc-reply>", 600000, "");
             if (response.indexOf("rpc-error") != -1) {
                 DebugLog.printAriDebug(fnName, "Error from device: Response from device had 'rpc-error'");
                 DebugLog.printAriDebug(fnName, "response=\n" + response + "\n");
@@ -393,7 +396,7 @@ public ConfigStatus configure(String key, Map<String, String> parameters, SvcLog
                 DebugLog.printAriDebug(fnName, ":LoadConfiguration was a success, sending commit cmd");
                 sshJcraftWrapper.send(commitCmd);
                 DebugLog.printAriDebug(fnName, ":After sending commitCmd");
-                response = sshJcraftWrapper.receiveUntil("]]>]]>", 180000, "");
+                response = sshJcraftWrapper.receiveUntil("</rpc-reply>", 180000, "");
                 if (response.indexOf("rpc-error") != -1) {
                     DebugLog.printAriDebug(fnName, "Error from device: Response from device had 'rpc-error'");
                     DebugLog.printAriDebug(fnName, "response=\n" + response + "\n");
@@ -950,13 +953,24 @@ public static String _readFile(String fileName) {
 }
 
 private String trimResponse(String response) {
+    log.debug("runningConfig before trimResponse : " + response);
     StringTokenizer line = new StringTokenizer(response, "\n");
     StringBuffer sb = new StringBuffer();
+    String runningConfig = "" ;
     boolean captureText = false;
     while (line.hasMoreTokens()) {
         String token = line.nextToken();
         if (token.indexOf("<configuration xmlns=") != -1) {
             captureText = true;
+        }else if(token.indexOf("<data>") != -1) {
+            log.debug("token-line:with in Data: "+token);
+            captureText = true;
+            continue;
+        }
+
+        if(token.indexOf("</data>") != -1) {
+            log.debug("token-line:with in </data>"+token);
+            captureText = false;
         }
         if (captureText) {
             sb.append(token + "\n");
@@ -965,7 +979,10 @@ private String trimResponse(String response) {
             captureText = false;
         }
     }
-    return (sb.toString());
+    runningConfig = sb.toString();
+
+    log.info("ConfigComponentAdaptor:RunningConfig after trimResponse : " + runningConfig);
+    return runningConfig;
 }
 
 public static void main(String args[]) throws Exception {
index 9aa5f9f..53aaad3 100644 (file)
@@ -710,7 +710,7 @@ public class SshJcraftWrapper {
         debugLog.printRTAriDebug(fn, "Setting routerCmdType to a value of '" + type + "'");
     }
 
-    public String getLastFewLinesOfFile(File file, int linesToRead) throws  IOException {
+    public String getLastFewLinesOfFile(File file, int linesToRead) throws IOException {
         String fn = "SshJcraftWrapper.getLastFewLinesOfFile";
         RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");
         int lines = 0;
index 5346066..a863efb 100644 (file)
@@ -209,6 +209,45 @@ public class ConfigComponentAdaptorTest {
         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
         String result = Whitebox.invokeMethod(cca, "trimResponse", "testData");
         Assert.assertEquals("", result);
+
+
+        String withConfigData = "<data>\n" +
+                "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\">\n" +
+                "<version>1.1X.0</version>\n" +
+                "<groups>\n" +
+                "<name>node0</name>\n" +
+                "</configuration>\n" +
+                "</data>\n" +
+                "</rpc-reply>\n" +
+                "]]>]]>\n" +
+                "";
+        String compareString = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\">\n"
+                + "<version>1.1X.0</version>\n"
+                + "<groups>\n"
+                + "<name>node0</name>\n"
+                + "</configuration>\n";
+
+        String result3 = Whitebox.invokeMethod(cca, "trimResponse", withConfigData);
+        Assert.assertEquals(compareString, result3);
+
+        String withData = "]]>]]>\n" +
+                "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n" +
+                "<data>\n" +
+                "<sgsn-mme xmlns=\"urn:rdns:com:ericsson:oammodel:ericsson-sgsn-mme\">\n" +
+                "<allocation-retention-priority xmlns=\"urn:rdns:com:ericsson:oammodel:ericsson-sgsn-mme\">\n" +
+                "<allocation-retention-priority>1</allocation-retention-priority>\n" +
+                "</allocation-retention-priority>\n" +
+                "</data>\n" +
+                "</rpc-reply>\n" +
+                "]]>]]";
+        String compareStringWithData = "<sgsn-mme xmlns=\"urn:rdns:com:ericsson:oammodel:ericsson-sgsn-mme\">\n" +
+                "<allocation-retention-priority xmlns=\"urn:rdns:com:ericsson:oammodel:ericsson-sgsn-mme\">\n" +
+                "<allocation-retention-priority>1</allocation-retention-priority>\n" +
+                "</allocation-retention-priority>\n";
+        String result2 = Whitebox.invokeMethod(cca, "trimResponse", withData);
+        Assert.assertEquals(compareStringWithData,result2);
+
+
     }
 
     @Test