From f392eb16a6f0014d51b8072a0b4e0fc8f234036c Mon Sep 17 00:00:00 2001 From: "Balaji, Ramya (rb111y)" Date: Tue, 26 Jun 2018 13:44:27 -0400 Subject: [PATCH] Changes to Config Component Adaptor Issue-ID: APPC-1014 Change-Id: I1ac95c68df92e39678b64919357333cd1664218d Signed-off-by: Balaji, Ramya (rb111y) --- .../appc/ccadaptor/ConfigComponentAdaptor.java | 25 +++++++++++--- .../org/onap/appc/ccadaptor/SshJcraftWrapper.java | 2 +- .../appc/ccadaptor/ConfigComponentAdaptorTest.java | 39 ++++++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/ConfigComponentAdaptor.java b/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/ConfigComponentAdaptor.java index 6ff4a8688..bffa396d2 100644 --- a/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/ConfigComponentAdaptor.java +++ b/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/ConfigComponentAdaptor.java @@ -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 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 parameters, SvcLog loadConfigurationString = loadConfigurationString + "]]>]]>"; sshJcraftWrapper.send(loadConfigurationString); DebugLog.printAriDebug(fnName, ":After sending loadConfigurationString"); - response = sshJcraftWrapper.receiveUntil("]]>]]>", 600000, ""); + response = sshJcraftWrapper.receiveUntil("", 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 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("", 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("") != -1) { + log.debug("token-line:with in Data: "+token); + captureText = true; + continue; + } + + if(token.indexOf("") != -1) { + log.debug("token-line:with in "+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 { diff --git a/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/SshJcraftWrapper.java b/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/SshJcraftWrapper.java index 9aa5f9fbf..53aaad331 100644 --- a/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/SshJcraftWrapper.java +++ b/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/SshJcraftWrapper.java @@ -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; diff --git a/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java b/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java index 534606670..a863efbf6 100644 --- a/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java +++ b/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java @@ -209,6 +209,45 @@ public class ConfigComponentAdaptorTest { ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props); String result = Whitebox.invokeMethod(cca, "trimResponse", "testData"); Assert.assertEquals("", result); + + + String withConfigData = "\n" + + "\n" + + "1.1X.0\n" + + "\n" + + "node0\n" + + "\n" + + "\n" + + "\n" + + "]]>]]>\n" + + ""; + String compareString = "\n" + + "1.1X.0\n" + + "\n" + + "node0\n" + + "\n"; + + String result3 = Whitebox.invokeMethod(cca, "trimResponse", withConfigData); + Assert.assertEquals(compareString, result3); + + String withData = "]]>]]>\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "1\n" + + "\n" + + "\n" + + "\n" + + "]]>]]"; + String compareStringWithData = "\n" + + "\n" + + "1\n" + + "\n"; + String result2 = Whitebox.invokeMethod(cca, "trimResponse", withData); + Assert.assertEquals(compareStringWithData,result2); + + } @Test -- 2.16.6