diff options
Diffstat (limited to 'appc-config/appc-config-adaptor')
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<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 { 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 = "<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 |