/*-
* ============LICENSE_START=======================================================
- * ONAP : APP-C
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property.All rights reserved.
+ * ONAP : APPC
* ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * =============================================================================
+ * Modifications Copyright (C) 2018-2019 IBM.
+ * =============================================================================
+ * Modifications Copyright (C) 2018-2019 Ericsson
+ * =============================================================================
* 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
+ * 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.
* See the License for the specific language governing permissions and
* limitations under the License.
+ *
* ============LICENSE_END=========================================================
*/
public class ConfigComponentAdaptor implements SvcLogicAdaptor {
- private static final EELFLogger log = EELFManager.getInstance().getLogger(ConfigComponentAdaptor.class);
+ private static EELFLogger log = EELFManager.getInstance().getLogger(ConfigComponentAdaptor.class);
DebugLog debugLog = new DebugLog();
private String configUrl = null;
private String configUser = null;
private String auditUrl = null;
private String auditUser = null;
private String auditPassword = null;
+
+ public String getConfigUrl() {
+ return configUrl;
+ }
+
+ public String getConfigUser() {
+ return configUser;
+ }
+
+ public String getConfigPassword() {
+ return configPassword;
+ }
+
+ public String getAuditUrl() {
+ return auditUrl;
+ }
+
+ public String getAuditUser() {
+ return auditUser;
+ }
+
+ public String getAuditPassword() {
+ return auditPassword;
+ }
+
+ public String getConfigCallbackUrl() {
+ return configCallbackUrl;
+ }
+
+ public String getAuditCallbackUrl() {
+ return auditCallbackUrl;
+ }
+
private String configCallbackUrl = null;
private String auditCallbackUrl = null;
+ private int DEFAULT_TIMEOUT_GETRUNNING_CLI = 120 * 1000 ;
public ConfigComponentAdaptor(Properties props) {
if (props != null) {
HttpResponse r = new HttpResponse();
r.code = 200;
log.debug("ConfigComponentAdaptor.configure - key = " + key);
- debugLog.printRTAriDebug(fnName, "key = " + key);
+ DebugLog.printRTAriDebug(fnName, "key = " + key);
log.debug("Parameters:");
- debugLog.printRTAriDebug(fnName, "Parameters:");
+ DebugLog.printRTAriDebug(fnName, "Parameters:");
for (String parmName : parameters.keySet()) {
log.debug(" " + parmName + " = " + parameters.get(parmName));
- debugLog.printRTAriDebug(fnName, " " + parmName + " = " + parameters.get(parmName));
+ DebugLog.printRTAriDebug(fnName, " " + parmName + " = " + parameters.get(parmName));
}
String parmval = parameters.get("config-component-configUrl");
String action = parameters.get("action");
String chg = ctx.getAttribute(
- "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name");
+ "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name");
if (chg != null && "prepare".equalsIgnoreCase(action)) {
return prepare(ctx, "CHANGE", "change");
}
}
String scale = ctx.getAttribute(
- "service-data.vnf-config-parameters-list.vnf-config-parameters[0].scale-configuration[0].network-type");
+ "service-data.vnf-config-parameters-list.vnf-config-parameters[0].scale-configuration[0].network-type");
if (scale != null && "prepare".equalsIgnoreCase(action)) {
return prepare(ctx, "CHANGE", "scale");
}
return audit(ctx, "RUNNING");
}
- if ((key.equals("put")) || (key.equals("get"))) {
+ if (("put".equals(key)) || ("get".equals(key))) {
String loginId = parameters.get("loginId");
String host = parameters.get("host");
String password = parameters.get("password");
String fullPathFileName = parameters.get("fullPathFileName");
String data = null;
- SshJcraftWrapper sshJcraftWrapper = new SshJcraftWrapper();
+ SshJcraftWrapper sshJcraftWrapper = getSshJcraftWrapper();
log.debug("SCP: SshJcraftWrapper has been instantiated");
- debugLog.printRTAriDebug(fnName, "SCP: SshJcraftWrapper has been instantiated");
+ DebugLog.printRTAriDebug(fnName, "SCP: SshJcraftWrapper has been instantiated");
try {
if (key.equals("put")) {
data = parameters.get("data");
if (data != null) {
- debugLog.printRTAriDebug(fnName, "Command is for put: Length of data is: " + data.length());
+ DebugLog.printRTAriDebug(fnName, "Command is for put: Length of data is: " + data.length());
InputStream is = new ByteArrayInputStream(data.getBytes());
log.debug("SCP: Doing a put: fullPathFileName=" + fullPathFileName);
- debugLog.printRTAriDebug(fnName, "SCP: Doing a put: fullPathFileName=" + fullPathFileName);
+ DebugLog.printRTAriDebug(fnName, "SCP: Doing a put: fullPathFileName=" + fullPathFileName);
sshJcraftWrapper.put(is, fullPathFileName, host, loginId, password);
try {
- debugLog.printRTAriDebug(fnName, "Sleeping for 180 seconds....");
- Thread.sleep(1000 * 180);
- debugLog.printRTAriDebug(fnName, "Woke up....");
+ DebugLog.printRTAriDebug(fnName, "Sleeping for 180 seconds....");
+ Thread.sleep(1000l * 180);
+ DebugLog.printRTAriDebug(fnName, "Woke up....");
} catch (java.lang.InterruptedException ee) {
boolean ignore = true;
+ Thread.currentThread().interrupt();
}
} else {
r.code = HttpURLConnection.HTTP_INTERNAL_ERROR;
} else // Must be a get
{
log.debug("SCP: Doing a get: fullPathFileName=" + fullPathFileName);
- debugLog.printRTAriDebug(fnName, "SCP: Doing a get: fullPathFileName=" + fullPathFileName);
+ DebugLog.printRTAriDebug(fnName, "SCP: Doing a get: fullPathFileName=" + fullPathFileName);
String response = sshJcraftWrapper.get(fullPathFileName, host, loginId, password);
- debugLog.printRTAriDebug(fnName, "Got the response and putting into the ctx object");
+ DebugLog.printRTAriDebug(fnName, "Got the response and putting into the ctx object");
ctx.setAttribute("fileContents", response);
log.debug("SCP: Closing the SFTP connection");
}
password = EncryptionTool.getInstance().decrypt(password);
String cliCommand = parameters.get("cli");
String portNumber = parameters.get("portNumber");
- SshJcraftWrapper sshJcraftWrapper = new SshJcraftWrapper();
+ SshJcraftWrapper sshJcraftWrapper = getSshJcraftWrapper();
try {
- log.debug("CLI: Attempting to login: host=" + host + " loginId=" + loginId + " password=" + password +
- " portNumber=" + portNumber);
- debugLog.printRTAriDebug(fnName, "CLI: Attempting to login: host=" + host + " loginId=" + loginId +
- " password=" + password + " portNumber=" + portNumber);
+ log.debug("CLI: Attempting to login: host=" + host + " loginId=" + loginId +
+ " portNumber=" + portNumber);
+ DebugLog.printRTAriDebug(fnName, "CLI: Attempting to login: host=" + host + " loginId=" + loginId +
+ " portNumber=" + portNumber);
sshJcraftWrapper.connect(host, loginId, password, Integer.parseInt(portNumber));
DebugLog.printAriDebug(fnName, "Sending 'sdc'");
return (setResponseStatus(ctx, r));
}
if (key.equals("GetCliRunningConfig")) {
- debugLog.printRTAriDebug(fnName, "key was: GetCliRunningConfig: ");
+ DebugLog.printRTAriDebug(fnName, "key was: GetCliRunningConfig: ");
log.debug("key was: GetCliRunningConfig: ");
String User_name = parameters.get("User_name");
String Host_ip_address = parameters.get("Host_ip_address");
Password = EncryptionTool.getInstance().decrypt(Password);
String Port_number = parameters.get("Port_number");
String Get_config_template = parameters.get("Get_config_template");
- SshJcraftWrapper sshJcraftWrapper = new SshJcraftWrapper();
+ SshJcraftWrapper sshJcraftWrapper = getSshJcraftWrapper();
log.debug("GetCliRunningConfig: sshJcraftWrapper was instantiated");
- debugLog.printRTAriDebug(fnName, "GetCliRunningConfig: sshJcraftWrapper was instantiated");
+ DebugLog.printRTAriDebug(fnName, "GetCliRunningConfig: sshJcraftWrapper was instantiated");
try {
DebugLog.printAriDebug(fnName, "GetCliRunningConfig: User_name=" + User_name +
- " Host_ip_address=" + Host_ip_address + " Password=" + Password + " Port_number="
- + Port_number);
+ " Host_ip_address=" + Host_ip_address + " Port_number="
+ + Port_number);
log.debug("GetCliRunningConfig: Attempting to login: Host_ip_address=" + Host_ip_address +
- " User_name=" + User_name + " Password=" + Password + " Port_number=" + Port_number);
+ " User_name=" + User_name + " Port_number=" + Port_number);
StringBuffer sb = new StringBuffer();
String response = "";
String CliResponse = "";
boolean showConfigFlag = false;
sshJcraftWrapper.connect(Host_ip_address,
- User_name,
- Password,
- "",
- 30000,
- Integer.parseInt(Port_number));
+ User_name,
+ Password,
+ "",
+ 30000,
+ Integer.parseInt(Port_number));
DebugLog.printAriDebug(fnName, "GetCliRunningConfig: On the VNF device");
StringTokenizer st = new StringTokenizer(Get_config_template, "\n");
String command = null;
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;
String Contents = parameters.get("Contents");
String netconfHelloCmd = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n <capabilities>\n <capability>urn:ietf:params:netconf:base:1.0</capability>\n <capability>urn:com:ericsson:ebase:1.1.0</capability> </capabilities>\n </hello>";
String terminateConnectionCmd = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <rpc message-id=\"terminateConnection\" xmlns:netconf=\"urn:ietf:params:xml:ns:netconf:base:1.0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n <close-session/> \n </rpc>\n ]]>]]>";
- String commitCmd = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <rpc> <commit/> </rpc>\n ]]>]]>";
+ String commitCmd = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\"> <commit/> </rpc>\n ]]>]]>";
log(fnName,
- "xml-download: User_name=" + User_name + " Host_ip_address=" + Host_ip_address + " Password=" + Password
+ "xml-download: User_name=" + User_name + " Host_ip_address=" + Host_ip_address
+ " Port_number=" + Port_number);
- SshJcraftWrapper sshJcraftWrapper = new SshJcraftWrapper();
+ SshJcraftWrapper sshJcraftWrapper = getSshJcraftWrapper();
try {
sshJcraftWrapper.connect(Host_ip_address,
- User_name,
- Password,
- "]]>]]>",
- 30000,
- Integer.parseInt(Port_number),
- "netconf");
+ User_name,
+ Password,
+ "]]>]]>",
+ 30000,
+ Integer.parseInt(Port_number),
+ "netconf");
String NetconfHelloCmd = netconfHelloCmd;
NetconfHelloCmd = NetconfHelloCmd + "]]>]]>";
log(fnName, "Sending the hello command");
String messageId = "1";
messageId = "\"" + messageId + "\"";
String loadConfigurationString =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id="
- + messageId
- + "> <edit-config> <target> <candidate /> </target> <default-operation>merge</default-operation> <config xmlns:xc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
- + xmlCmd + "</config> </edit-config> </rpc>";
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id="
+ + messageId
+ + "> <edit-config> <target> <candidate /> </target> <default-operation>merge</default-operation> <config xmlns:xc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"
+ + xmlCmd + "</config> </edit-config> </rpc>";
loadConfigurationString = loadConfigurationString + "]]>]]>";
sshJcraftWrapper.send(loadConfigurationString);
DebugLog.printAriDebug(fnName, ":After sending loadConfigurationString");
String netconfHelloCmd = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n <capabilities>\n <capability>urn:ietf:params:netconf:base:1.0</capability>\n <capability>urn:com:ericsson:ebase:1.1.0</capability> </capabilities>\n </hello>";
String terminateConnectionCmd = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <rpc message-id=\"terminateConnection\" xmlns:netconf=\"urn:ietf:params:xml:ns:netconf:base:1.0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n <close-session/> \n </rpc>\n ]]>]]>";
log(fnName,
- "xml-getrunningconfig: User_name=" + User_name + " Host_ip_address=" + Host_ip_address + " Password="
- + Password + " Port_number=" + Port_number);
- SshJcraftWrapper sshJcraftWrapper = new SshJcraftWrapper();
+ "xml-getrunningconfig: User_name=" + User_name + " Host_ip_address=" + Host_ip_address
+ + " Port_number=" + Port_number);
+ SshJcraftWrapper sshJcraftWrapper = getSshJcraftWrapper();
try {
String NetconfHelloCmd = netconfHelloCmd;
sshJcraftWrapper.connect(Host_ip_address,
- User_name,
- Password,
- "]]>]]>",
- 30000,
- Integer.parseInt(Port_number),
- "netconf");
+ User_name,
+ Password,
+ "]]>]]>",
+ 30000,
+ Integer.parseInt(Port_number),
+ "netconf");
NetconfHelloCmd = NetconfHelloCmd + "]]>]]>";
log(fnName, ":Sending the hello command");
sshJcraftWrapper.send(NetconfHelloCmd);
}
}
if (key.equals("DownloadCliConfig")) {
- debugLog.printRTAriDebug(fnName, "key was: DownloadCliConfig: ");
+ DebugLog.printRTAriDebug(fnName, "key was: DownloadCliConfig: ");
log.debug("key was: DownloadCliConfig: ");
String User_name = parameters.get("User_name");
String Host_ip_address = parameters.get("Host_ip_address");
String Download_config_template = parameters.get("Download_config_template");
String Config_contents = parameters.get("Config_contents");
DebugLog.printAriDebug(fnName, "Contents of the 'Config_contents' are: " + Config_contents);
- SshJcraftWrapper sshJcraftWrapper = new SshJcraftWrapper();
+ SshJcraftWrapper sshJcraftWrapper = getSshJcraftWrapper();
log.debug("DownloadCliConfig: sshJcraftWrapper was instantiated");
- debugLog.printRTAriDebug(fnName, "DownloadCliConfig: sshJcraftWrapper was instantiated");
+ DebugLog.printRTAriDebug(fnName, "DownloadCliConfig: sshJcraftWrapper was instantiated");
int timeout = 4 * 60 * 1000;
try {
DebugLog.printAriDebug(fnName, "DownloadCliConfig: User_name=" + User_name +
- " Host_ip_address=" + Host_ip_address + " Password=" + Password + " Port_number="
- + Port_number);
+ " Host_ip_address=" + Host_ip_address + " Port_number="
+ + Port_number);
log.debug("DownloadCliConfig: Attempting to login: Host_ip_address=" + Host_ip_address +
- " User_name=" + User_name + " Password=" + Password + " Port_number=" + Port_number);
+ " User_name=" + User_name + " Port_number=" + Port_number);
StringBuffer sb = new StringBuffer();
String response = "";
String CliResponse = "";
sshJcraftWrapper.connect(Host_ip_address,
- User_name,
- Password,
- "",
- 30000,
- Integer.parseInt(Port_number));
+ User_name,
+ Password,
+ "",
+ 30000,
+ Integer.parseInt(Port_number));
DebugLog.printAriDebug(fnName, "DownloadCliConfig: On the VNF device");
StringTokenizer st = new StringTokenizer(Download_config_template, "\n");
String command = null;
sshJcraftWrapper.send(command);
DebugLog.printAriDebug(fnName, "command has been sent");
} else if ((line.indexOf("Response: Ends_With") != -1) && (
- line.indexOf("Execute_config_contents Response: Ends_With") == -1)) {
+ line.indexOf("Execute_config_contents Response: Ends_With") == -1)) {
DebugLog.printAriDebug(fnName, "Found a Response line: line=" + line);
String delemeter = getStringBetweenQuotes(line);
DebugLog.printAriDebug(fnName, "The delemeter=" + delemeter);
DebugLog.printAriDebug(fnName, "Found a 'Execute_config_contents Response:' line=" + line);
executeConfigContentsDelemeter = getStringBetweenQuotes(line);
DebugLog.printAriDebug(fnName,
- "executeConfigContentsDelemeter=" + executeConfigContentsDelemeter);
+ "executeConfigContentsDelemeter=" + executeConfigContentsDelemeter);
StringTokenizer st2 = new StringTokenizer(Config_contents, "\n");
while (st2.hasMoreTokens()) {
String cmd = st2.nextToken();
DebugLog.printAriDebug(fnName, "Config_contents: cmd=" + cmd);
sshJcraftWrapper.send(cmd);
String tmpResponse = sshJcraftWrapper.receiveUntil(executeConfigContentsDelemeter,
- timeout,
- command);
+ timeout,
+ command);
CliResponse += tmpResponse;
}
}
}
}
- debugLog.printRTAriDebug(fnName, "Unsupported action - " + action);
+ DebugLog.printRTAriDebug(fnName, "Unsupported action - " + action);
log.error("Unsupported action - " + action);
return ConfigStatus.FAILURE;
}
private void log(String fileName, String messg) {
- debugLog.printRTAriDebug(fileName, messg);
+ DebugLog.printRTAriDebug(fileName, messg);
log.debug(fileName + ": " + messg);
}
return input;
}
- private String readFile(String fileName) {
+ protected String readFile(String fileName) {
InputStream is = getClass().getResourceAsStream(fileName);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader in = new BufferedReader(isr);
int i2 = template.indexOf(':', i1 + 9);
if (i2 < 0) {
throw new RuntimeException(
- "Template error: Context variable name followed by : is required after repeat");
+ "Template error: Context variable name followed by : is required after repeat");
}
// Find the closing }, store in i3
private HttpResponse sendXmlRequest(String xmlRequest, String url, String user, String password) {
try {
- Client client = Client.create();
+ Client client = getClient();
client.setConnectTimeout(5000);
WebResource webResource = client.resource(url);
log.info("SENDING...............");
- log.info(xmlRequest);
-
+ if (log.isTraceEnabled()) {
+ log.trace(xmlRequest);
+ }
+ else {
+ if(xmlRequest.length() > 255 ) {
+ log.info(xmlRequest.substring(0, 255));
+ log.info("\n...\n" + xmlRequest.length() +
+ " characters in request, turn on TRACE logging to log entire request");
+ }
+ else {
+ log.info(xmlRequest);
+ }
+ }
String authString = user + ":" + password;
byte[] authEncBytes = Base64.encode(authString);
String authStringEnc = new String(authEncBytes);
authString = "Basic " + authStringEnc;
- ClientResponse response =
- webResource.header("Authorization", authString).accept("UTF-8").type("application/xml").post(
- ClientResponse.class, xmlRequest);
+ ClientResponse response = getClientResponse(webResource, authString, xmlRequest);
int code = response.getStatus();
String message = null;
}
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");
captureText = false;
}
}
- return (sb.toString());
+ runningConfig = sb.toString();
+
+ if (log.isTraceEnabled()) {
+ log.trace("ConfigComponentAdaptor:RunningConfig after trimResponse : " + runningConfig);
+ }
+ else {
+ if (runningConfig.length() > 255) {
+ log.info("ConfigComponentAdaptor:RunningConfig after trimResponse : " +
+ runningConfig.substring(0, 255));
+ log.info("\n...\n" + runningConfig.length() +
+ " characters in config, turn on TRACE logging to log entire config");
+ }
+ else {
+ log.info("ConfigComponentAdaptor:RunningConfig after trimResponse : " +
+ runningConfig);
+ }
+ }
+ log.info("ConfigComponentAdaptor:RunningConfig after trimResponse : " + runningConfig);
+ return runningConfig;
}
public static void main(String args[]) throws Exception {
System.out.println("*************************TRACE 1*****************************");
cca.configure(key, parameters, ctx);
}
-}
+ protected SshJcraftWrapper getSshJcraftWrapper() {
+ return new SshJcraftWrapper();
+ }
+
+ protected Client getClient() {
+ return Client.create();
+ }
+
+ protected ClientResponse getClientResponse(WebResource webResource, String authString, String xmlRequest) {
+ return webResource.header("Authorization", authString).accept("UTF-8").type("application/xml").post(
+ ClientResponse.class, xmlRequest);
+ }
+}