diff options
author | liamfallon <liam.fallon@est.tech> | 2019-06-27 14:58:28 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2019-06-27 14:58:28 +0000 |
commit | fad6fa4890538fe8f4cbb96ae3fb0be6767d28d1 (patch) | |
tree | 34ef945b70297b5bd2171cf84d8b3c700a704830 /examples | |
parent | 5f029543f1e673655af2d2974113069df0b6def0 (diff) |
Fix Sonar/Checkstyle issues in apex-pdp
BBS Java code introduced Sonar issues, these are resolved.
Also fixed checkstyle errors in other classes.
Also fiexed "unexpected type" eclipse errors.
Issue-ID: POLICY-1791
Change-Id: I3931051f0944c6d53745c8dd1db7cca4ee118f1c
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'examples')
6 files changed, 254 insertions, 427 deletions
diff --git a/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java b/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java index 58f07b9da..939b104d1 100644 --- a/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java +++ b/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java @@ -21,25 +21,18 @@ package org.onap.policy.apex.examples.bbs; - - import java.io.BufferedReader; import java.io.ByteArrayInputStream; -import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.StringWriter; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.security.cert.X509Certificate; import java.util.Base64; -import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; @@ -49,6 +42,9 @@ import javax.xml.transform.stream.StreamResult; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; + +import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException; +import org.onap.policy.common.utils.network.NetworkUtil; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; import org.w3c.dom.Document; @@ -60,141 +56,39 @@ import org.xml.sax.InputSource; * The Class WebClient act as rest client for BBS usecase. */ public class WebClient { - private static final XLogger LOGGER = XLoggerFactory.getXLogger(WebClient.class); - /** - * Disable ssl verification. - */ - private static void disableCertificateValidation() { - try { - TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return null; - } - - public void checkClientTrusted(X509Certificate[] certs, String authType) { - } - - public void checkServerTrusted(X509Certificate[] certs, String authType) { - } - } - }; - - - SSLContext sc = SSLContext.getInstance("SSL"); - sc.init(null, trustAllCerts, new java.security.SecureRandom()); - HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - - HostnameVerifier allHostsValid = new HostnameVerifier() { - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - - HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); - } catch (Exception e) { - LOGGER.error("httpsRequest Exception " + e); - } - } + // Duplicated string constants + private static final String BBS_POLICY = "BBS Policy"; /** * Send simple https rest request. * - * @param requestUrl url - * @param requestMethod method eg POST/GET/PUT - * @param outputStr Data - * @param username Simple Username - * @param pass Simple password + * @param requestUrl url + * @param requestMethod method eg POST/GET/PUT + * @param outputStr Data + * @param username Simple Username + * @param pass Simple password * @param contentType http content type - * @param fillApp If required to fill app details - * @param disableSSl If disabling ssl checking - * @return String response message + * @apram secureHttp flag indicating if HTTPS should be used + * @return String response message */ - public String httpsRequest(String requestUrl, String requestMethod, - String outputStr, String username, String pass, - String contentType, boolean fillApp, boolean disableSSl) { + public String httpRequest(String requestUrl, String requestMethod, String outputStr, String username, String pass, + String contentType, boolean secureHttp) { String result = ""; - StringBuffer buffer = new StringBuffer(); + StringBuilder builder = new StringBuilder(); try { LOGGER.info("httpsRequest starts " + requestUrl + " method " + requestMethod); - if (disableSSl) { - disableCertificateValidation(); - } - URL url = new URL(requestUrl); - HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection(); - httpUrlConn.setDoOutput(true); - httpUrlConn.setDoInput(true); - httpUrlConn.setUseCaches(false); - - if ((username != null) && (pass != null)) { - httpUrlConn.setRequestProperty("Authorization", getAuth(username, pass)); - } else { - LOGGER.warn("Authorization information missing"); - } - - httpUrlConn.setRequestProperty("Content-Type", contentType); - httpUrlConn.setRequestProperty("Accept", contentType); - if (fillApp) { - httpUrlConn.setRequestProperty("X-FromAppId", "BBS Policy"); - httpUrlConn.setRequestProperty("X-TransactionId", "BBS Policy"); - } - httpUrlConn.setRequestMethod(requestMethod); + disableCertificateValidation(); - if ("GET".equalsIgnoreCase(requestMethod)) { - httpUrlConn.connect(); - } - - if (null != outputStr) { - OutputStream outputStream = httpUrlConn.getOutputStream(); - outputStream.write(outputStr.getBytes(StandardCharsets.UTF_8)); - outputStream.close(); + URL url = new URL(requestUrl); + HttpURLConnection httpUrlConn = null; + if (secureHttp) { + httpUrlConn = (HttpsURLConnection) url.openConnection(); } - - try (InputStream inputStream = httpUrlConn.getInputStream()) { - try (InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) { - try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { - String str; - while ((str = bufferedReader.readLine()) != null) { - buffer.append(str); - } - } - } - httpUrlConn.disconnect(); - result = buffer.toString(); + else { + httpUrlConn = (HttpURLConnection) url.openConnection(); } - LOGGER.info("httpsRequest success "); - } catch (Exception ce) { - LOGGER.error("httpsRequest Exception " + ce); - } - return result; - } - - /** - * Send simple https rest request. - * - * @param requestUrl url - * @param requestMethod method eg POST/GET/PUT - * @param outputStr Data - * @param username Simple Username - * @param pass Simple password - * @param contentType http content type - * @param fillApp If required to fill app details - * @param disableSSl If disabling ssl checking - * @return String response message - */ - public String httpRequest(String requestUrl, String requestMethod, - String outputStr, String username, String pass, - String contentType, boolean fillApp, boolean disableSSl) { - String result = ""; - StringBuffer buffer = new StringBuffer(); - try { - LOGGER.info("httpRequest starts " + requestUrl + " method " + requestMethod); - if (disableSSl) { - disableCertificateValidation(); - } - URL url = new URL(requestUrl); - HttpURLConnection httpUrlConn = (HttpURLConnection) url.openConnection(); httpUrlConn.setDoOutput(true); httpUrlConn.setDoInput(true); httpUrlConn.setUseCaches(false); @@ -207,10 +101,8 @@ public class WebClient { httpUrlConn.setRequestProperty("Content-Type", contentType); httpUrlConn.setRequestProperty("Accept", contentType); - if (fillApp) { - httpUrlConn.setRequestProperty("X-FromAppId", "BBS Policy"); - httpUrlConn.setRequestProperty("X-TransactionId", "BBS Policy"); - } + httpUrlConn.setRequestProperty("X-FromAppId", BBS_POLICY); + httpUrlConn.setRequestProperty("X-TransactionId", BBS_POLICY); httpUrlConn.setRequestMethod(requestMethod); if ("GET".equalsIgnoreCase(requestMethod)) { @@ -223,17 +115,14 @@ public class WebClient { outputStream.close(); } - try (InputStream inputStream = httpUrlConn.getInputStream()) { - try (InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) { - try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { - String str; - while ((str = bufferedReader.readLine()) != null) { - buffer.append(str); - } - } + try (BufferedReader bufferedReader = + new BufferedReader(new InputStreamReader(httpUrlConn.getInputStream(), StandardCharsets.UTF_8))) { + String str; + while ((str = bufferedReader.readLine()) != null) { + builder.append(str); } httpUrlConn.disconnect(); - result = buffer.toString(); + result = builder.toString(); } LOGGER.info("httpsRequest success "); } catch (Exception ce) { @@ -243,18 +132,6 @@ public class WebClient { } /** - * Return Basic Authentication String. - * - * @param userName UserName - * @param password PassWord - * @return Basic Authentication - */ - private String getAuth(String userName, String password) { - String userCredentials = userName + ":" + password; - return ("Basic " + Base64.getEncoder().encodeToString(userCredentials.getBytes(StandardCharsets.UTF_8))); - } - - /** * Pretty print xml string. * * @param xml Input string @@ -264,21 +141,19 @@ public class WebClient { public String toPrettyString(String xml, int indent) { try { try (ByteArrayInputStream br = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))) { - Document document = DocumentBuilderFactory.newInstance() - .newDocumentBuilder() - .parse(new InputSource(br)); + Document document = + DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(br)); document.normalize(); XPath path = XPathFactory.newInstance().newXPath(); - NodeList nodeList = (NodeList) path.evaluate("//text()[normalize-space()='']", - document, - XPathConstants.NODESET); + NodeList nodeList = + (NodeList) path.evaluate("//text()[normalize-space()='']", document, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); ++i) { Node node = nodeList.item(i); node.getParentNode().removeChild(node); } - + TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setAttribute("indent-number", indent); Transformer transformer = transformerFactory.newTransformer(); @@ -291,7 +166,37 @@ public class WebClient { return stringWriter.toString(); } } catch (Exception e) { - throw new RuntimeException(e); + throw new ApexRuntimeException("pretiffication failed", e); } } + + /** + * Disable ssl verification. + */ + private static void disableCertificateValidation() { + try { + TrustManager[] trustAllCerts = NetworkUtil.getAlwaysTrustingManager(); + + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + + HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true); + + } catch (Exception e) { + LOGGER.error("certificate validation Exception " + e); + } + } + + /** + * Return Basic Authentication String. + * + * @param userName UserName + * @param password PassWord + * @return Basic Authentication + */ + private String getAuth(String userName, String password) { + String userCredentials = userName + ":" + password; + return ("Basic " + Base64.getEncoder().encodeToString(userCredentials.getBytes(StandardCharsets.UTF_8))); + } } diff --git a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js index 419ce4350..6e72e618c 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +33,7 @@ var attachmentPoint = executor.inFields.get("attachmentPoint"); var requestID = executor.inFields.get("requestID"); var serviceInstanceId = executor.inFields.get("serviceInstanceId"); -var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get( - attachmentPoint); +var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get(attachmentPoint); executor.logger.info(NomadicONTContext); var jsonObj; @@ -42,7 +42,6 @@ var aaiUpdateResult = true; var wbClient = Java.type("org.onap.policy.apex.examples.bbs.WebClient"); var client = new wbClient(); - /* Get AAI URL from Configuration file. */ var AAI_URL = "localhost:8080"; var CUSTOMER_ID = requestID; @@ -55,8 +54,7 @@ var results; var putUrl; var service_instance; try { - var br = Files.newBufferedReader(Paths.get( - "/home/apexuser/examples/config/ONAPBBS/config.txt")); + var br = Files.newBufferedReader(Paths.get("/home/apexuser/examples/config/ONAPBBS/config.txt")); var line; while ((line = br.readLine()) != null) { if (line.startsWith("AAI_URL")) { @@ -81,14 +79,12 @@ executor.logger.info("AAI_URL " + AAI_URL); /* Get service instance Id from AAI */ try { - var urlGet = HTTP_PROTOCOL + AAI_URL + - "/aai/" + AAI_VERSION + "/nodes/service-instances/service-instance/" + - SERVICE_INSTANCE_ID + "?format=resource_and_url"; + var urlGet = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/nodes/service-instances/service-instance/" + + SERVICE_INSTANCE_ID + "?format=resource_and_url"; executor.logger.info("Query url" + urlGet); - result = client.httpsRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, - "application/json", true, true); + result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json", true); executor.logger.info("Data received From " + urlGet + " " + result); jsonObj = JSON.parse(result.toString()); @@ -100,9 +96,8 @@ try { service_instance_id = service_instance['service-instance-id']; resource_version = service_instance['resource-version']; relationship_list = service_instance['relationship-list']; - executor.logger.info("After Parse service_instance " + JSON.stringify( - service_instance, null, 4) + "\n url " + putUrl + - "\n Service instace Id " + service_instance_id); + executor.logger.info("After Parse service_instance " + JSON.stringify(service_instance, null, 4) + "\n url " + + putUrl + "\n Service instace Id " + service_instance_id); if (result == "") { aaiUpdateResult = false; @@ -112,21 +107,16 @@ try { aaiUpdateResult = false; } - - /* BBS Policy updates orchestration status of {{bbs-cfs-service-instance-UUID}} [ active --> assigned ] */ var putUpddateServInstance; putUpddateServInstance = service_instance; try { if (aaiUpdateResult == true) { putUpddateServInstance["orchestration-status"] = "active"; - executor.logger.info("ready to putAfter Parse " + JSON.stringify( - putUpddateServInstance, null, 4)); - var urlPut = HTTP_PROTOCOL + AAI_URL + - putUrl + "?resource_version=" + resource_version; - result = client.httpsRequest(urlPut, "PUT", JSON.stringify( - putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD, - "application/json", true, true); + executor.logger.info("ready to putAfter Parse " + JSON.stringify(putUpddateServInstance, null, 4)); + var urlPut = HTTP_PROTOCOL + AAI_URL + putUrl + "?resource_version=" + resource_version; + result = client.httpRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD, + "application/json", true); executor.logger.info("Data received From " + urlPut + " " + result); /* If failure to retrieve data proceed to Failure */ if (result != "") { @@ -138,11 +128,9 @@ try { aaiUpdateResult = false; } -if (!service_instance.hasOwnProperty('input-parameters') || !service_instance - .hasOwnProperty('metadata')) { +if (!service_instance.hasOwnProperty('input-parameters') || !service_instance.hasOwnProperty('metadata')) { aaiUpdateResult = false; - executor.logger.info( - "Validate data failed. input-parameters or metadata is missing"); + executor.logger.info("Validate data failed. input-parameters or metadata is missing"); } /* update logical link in pnf */ @@ -154,25 +142,22 @@ try { var pnfUpdate; var relationShips = relationship_list["relationship"]; - for (var i = 0; i < relationShips.length; i++) { if (relationShips[i]["related-to"] == "pnf") { - var relationship_data = relationShips[i]["relationship-data"]; - for (var j = 0; j < relationship_data.length; j++) { - if (relationship_data[j]["relationship-key"] == "pnf.pnf-name") { + var relationship_data = relationShips[i]["relationship-data"]; + for (var j = 0; j < relationship_data.length; j++) { + if (relationship_data[j]["relationship-key"] == "pnf.pnf-name") { pnfName = relationship_data[j]['relationship-value']; break; - } - } + } + } } } executor.logger.info("pnf-name found " + pnfName); /* 1. Get PNF */ - var urlGetPnf = HTTP_PROTOCOL + AAI_URL + - "/aai/" + AAI_VERSION + "/network/pnfs/pnf/" + pnfName; - pnfResponse = client.httpsRequest(urlGetPnf, "GET", null, AAI_USERNAME, AAI_PASSWORD, - "application/json", true, true); + var urlGetPnf = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/network/pnfs/pnf/" + pnfName; + pnfResponse = client.httpRequest(urlGetPnf, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json", true); executor.logger.info("Data received From " + urlGetPnf + " " + pnfResponse); /* If failure to retrieve data proceed to Failure */ if (result != "") { @@ -181,18 +166,17 @@ try { pnfUpdate = JSON.parse(pnfResponse.toString()); executor.logger.info(JSON.stringify(pnfUpdate, null, 4)); - /*2. Create logical link */ var link_name = attachmentPoint; var logicalLink = { - "link-name": link_name, - "in-maint": false, - "link-type": "attachment-point" - }; - var urlNewLogicalLink = HTTP_PROTOCOL + AAI_URL + - "/aai/" + AAI_VERSION + "/network/logical-links/logical-link/" + link_name; - result = client.httpsRequest(urlNewLogicalLink, "PUT", JSON.stringify(logicalLink), AAI_USERNAME, AAI_PASSWORD, - "application/json", true, true); + "link-name" : link_name, + "in-maint" : false, + "link-type" : "attachment-point" + }; + var urlNewLogicalLink = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + + "/network/logical-links/logical-link/" + link_name; + result = client.httpRequest(urlNewLogicalLink, "PUT", JSON.stringify(logicalLink), AAI_USERNAME, AAI_PASSWORD, + "application/json", true); executor.logger.info("Data received From " + urlNewLogicalLink + " " + result); /* If failure to retrieve data proceed to Failure */ if (result != "") { @@ -202,9 +186,10 @@ try { /*3. Update pnf with new relation*/ for (var i = 0; i < pnfUpdate["relationship-list"]["relationship"].length; i++) { if (pnfUpdate["relationship-list"]["relationship"][i]['related-to'] == 'logical-link') { - pnfUpdate["relationship-list"]["relationship"][i]['related-link'] = "/aai/" + AAI_VERSION + "/network/logical-links/logical-link/" + link_name; + pnfUpdate["relationship-list"]["relationship"][i]['related-link'] = "/aai/" + AAI_VERSION + + "/network/logical-links/logical-link/" + link_name; for (var j = 0; j < pnfUpdate["relationship-list"]["relationship"][i]['relationship-data'].length; j++) { - if (pnfUpdate["relationship-list"]["relationship"][i]['relationship-data'][j]['relationship-key'] == "logical-link.link-name") { + if (pnfUpdate["relationship-list"]["relationship"][i]['relationship-data'][j]['relationship-key'] == "logical-link.link-name") { oldLinkName = pnfUpdate["relationship-list"]["relationship"][i]['relationship-data'][j]['relationship-value']; pnfUpdate["relationship-list"]["relationship"][i]['relationship-data'][j]['relationship-value'] = link_name; break; @@ -215,10 +200,9 @@ try { } executor.logger.info("Put pnf to aai " + JSON.stringify(pnfUpdate, null, 4)); - var urlPutPnf = HTTP_PROTOCOL + AAI_URL + - "/aai/" + AAI_VERSION + "/network/pnfs/pnf/" + pnfName; - result = client.httpsRequest(urlPutPnf, "PUT", JSON.stringify(pnfUpdate), AAI_USERNAME, AAI_PASSWORD, - "application/json", true, true); + var urlPutPnf = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/network/pnfs/pnf/" + pnfName; + result = client.httpRequest(urlPutPnf, "PUT", JSON.stringify(pnfUpdate), AAI_USERNAME, AAI_PASSWORD, + "application/json", true); executor.logger.info("Data received From " + urlPutPnf + " " + result); /* If failure to retrieve data proceed to Failure */ @@ -229,18 +213,19 @@ try { /* Get and Delete the Stale logical link */ var oldLinkResult; var linkResult; - var urlOldLogicalLink = HTTP_PROTOCOL + AAI_URL + - "/aai/" + AAI_VERSION + "/network/logical-links/logical-link/" + oldLinkName; - linkResult = client.httpsRequest(urlOldLogicalLink, "GET", null, AAI_USERNAME, AAI_PASSWORD, - "application/json", true, true); - executor.logger.info("Data received From " + urlOldLogicalLink + " " + linkResult + " " + linkResult.hasOwnProperty("link-name")); + var urlOldLogicalLink = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + + "/network/logical-links/logical-link/" + oldLinkName; + linkResult = client + .httpRequest(urlOldLogicalLink, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json", true); + executor.logger.info("Data received From " + urlOldLogicalLink + " " + linkResult + " " + + linkResult.hasOwnProperty("link-name")); oldLinkResult = JSON.parse(linkResult.toString()); if (oldLinkResult.hasOwnProperty("link-name") == true) { var res_version = oldLinkResult["resource-version"]; var urlDelOldLogicalLink = urlOldLogicalLink + "?resource-version=" + res_version; executor.logger.info("Delete called for " + urlDelOldLogicalLink); - result = client.httpsRequest(urlDelOldLogicalLink, "DELETE", null, AAI_USERNAME, AAI_PASSWORD, - "application/json", true, true); + result = client.httpRequest(urlDelOldLogicalLink, "DELETE", null, AAI_USERNAME, AAI_PASSWORD, + "application/json", true); executor.logger.info("Delete called for " + urlDelOldLogicalLink + " result " + result); } } @@ -262,8 +247,7 @@ if (aaiUpdateResult === true) { executor.outFields.put("requestID", requestID); executor.outFields.put("attachmentPoint", attachmentPoint); -executor.outFields.put("serviceInstanceId", executor.inFields.get( - "serviceInstanceId")); +executor.outFields.put("serviceInstanceId", executor.inFields.get("serviceInstanceId")); var returnValue = executor.isTrue; executor.logger.info(executor.outFields); @@ -278,4 +262,4 @@ function IsValidJSONString(str) { } return true; } -/* Utility functions End */
\ No newline at end of file +/* Utility functions End */ diff --git a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js index 5d18f23b0..7e116f0ea 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,11 +33,10 @@ var attachmentPoint = executor.inFields.get("attachmentPoint"); var requestID = executor.inFields.get("requestID"); var serviceInstanceId = executor.inFields.get("serviceInstanceId"); -var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get( - attachmentPoint); +var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get(attachmentPoint); executor.logger.info(NomadicONTContext); -//Get the AAI URL from configuraiotn file +// Get the AAI URL from configuraiotn file var AAI_URL = "localhost:8080"; var CUSTOMER_ID = requestID; var BBS_CFS_SERVICE_TYPE = "BBS-CFS-Access_Test"; @@ -48,8 +48,7 @@ var client = new wbClient(); var AAI_USERNAME = null; var AAI_PASSWORD = null; try { - var br = Files.newBufferedReader(Paths.get( - "/home/apexuser/examples/config/ONAPBBS/config.txt")); + var br = Files.newBufferedReader(Paths.get("/home/apexuser/examples/config/ONAPBBS/config.txt")); // read line by line var line; while ((line = br.readLine()) != null) { @@ -74,14 +73,12 @@ executor.logger.info("AAI_URL " + AAI_URL); var aaiUpdateResult = true; /* Get service instance Id from AAI */ try { - var urlGet = HTTP_PROTOCOL + AAI_URL + - "/aai/" + AAI_VERSION + "/nodes/service-instances/service-instance/" + - SERVICE_INSTANCE_ID + "?format=resource_and_url"; + var urlGet = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/nodes/service-instances/service-instance/" + + SERVICE_INSTANCE_ID + "?format=resource_and_url"; executor.logger.info("Query url" + urlGet); - result = client.httpsRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, - "application/json", true, true); + result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json", true); executor.logger.info("Data received From " + urlGet + " " + result); jsonObj = JSON.parse(result); @@ -90,9 +87,8 @@ try { results = jsonObj['results'][0]; putUrl = results['url']; service_instance = results['service-instance']; - executor.logger.info("After Parse service_instance " + JSON.stringify( - service_instance, null, 4) + "\n url " + putUrl + - "\n Service instace Id " + SERVICE_INSTANCE_ID); + executor.logger.info("After Parse service_instance " + JSON.stringify(service_instance, null, 4) + "\n url " + + putUrl + "\n Service instace Id " + SERVICE_INSTANCE_ID); if (result == "") { aaiUpdateResult = false; @@ -104,21 +100,17 @@ try { var putUpddateServInstance = service_instance; putUpddateServInstance['orchestration-status'] = "created"; -executor.logger.info(" string" + JSON.stringify(putUpddateServInstance, null, - 4)); +executor.logger.info(" string" + JSON.stringify(putUpddateServInstance, null, 4)); var resource_version = putUpddateServInstance['resource-version']; var putUrl = NomadicONTContext.get("url"); -/*BBS Policy updates {{bbs-cfs-service-instance-UUID}} orchestration-status [ assigned --> created ]*/ +/* BBS Policy updates {{bbs-cfs-service-instance-UUID}} orchestration-status [ assigned --> created ] */ try { if (aaiUpdateResult == true) { - executor.logger.info("ready to putAfter Parse " + JSON.stringify( - putUpddateServInstance, null, 4)); - var urlPut = HTTP_PROTOCOL + AAI_URL + - putUrl + "?resource_version=" + resource_version; - result = client.httpsRequest(urlPut, "PUT", JSON.stringify( - putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD, - "application/json", true, true); + executor.logger.info("ready to putAfter Parse " + JSON.stringify(putUpddateServInstance, null, 4)); + var urlPut = HTTP_PROTOCOL + AAI_URL + putUrl + "?resource_version=" + resource_version; + result = client.httpRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD, + "application/json", true); executor.logger.info("Data received From " + urlPut + " " + result); /* If failure to retrieve data proceed to Failure */ if (result != "") { @@ -139,9 +131,8 @@ if (aaiUpdateResult === true) { executor.outFields.put("requestID", requestID); executor.outFields.put("attachmentPoint", attachmentPoint); -executor.outFields.put("serviceInstanceId", executor.inFields.get( - "serviceInstanceId")); +executor.outFields.put("serviceInstanceId", executor.inFields.get("serviceInstanceId")); var returnValue = executor.isTrue; executor.logger.info(executor.outFields); -executor.logger.info("End Execution AAIServiceCreateTask.js");
\ No newline at end of file +executor.logger.info("End Execution AAIServiceCreateTask.js"); diff --git a/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js b/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js index 55f5a1ba1..d588eaf48 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,8 +39,7 @@ var uuidType = Java.type("java.util.UUID"); var wbClient = Java.type("org.onap.policy.apex.examples.bbs.WebClient"); var client = new wbClient(); -var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get( - attachmentPoint); +var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get(attachmentPoint); var sdncUUID = uuidType.randomUUID(); executor.logger.info(NomadicONTContext); var jsonObj; @@ -50,8 +50,7 @@ var SVC_NOTIFICATION_URL; var putUpddateServInstance = JSON.parse(NomadicONTContext.get("aai_message")); var input_param = JSON.parse(putUpddateServInstance['input-parameters']); try { - var br = Files.newBufferedReader(Paths.get( - "/home/apexuser/examples/config/ONAPBBS/config.txt")); + var br = Files.newBufferedReader(Paths.get("/home/apexuser/examples/config/ONAPBBS/config.txt")); var line; while ((line = br.readLine()) != null) { if (line.startsWith("SDNC_URL")) { @@ -60,8 +59,7 @@ try { } else if (line.startsWith("SVC_NOTIFICATION_URL")) { var str = line.split("="); SVC_NOTIFICATION_URL = str[str.length - 1]; - } - else if (line.startsWith("SDNC_USERNAME")) { + } else if (line.startsWith("SDNC_USERNAME")) { var str = line.split("="); SDNC_USERNAME = str[str.length - 1]; } else if (line.startsWith("SDNC_PASSWORD")) { @@ -79,12 +77,11 @@ var jsonObj; var sdncUpdateResult = true; /* BBS Policy calls SDN-C GR-API to delete AccessConnectivity VF ID */ -/* Prepare Data*/ +/* Prepare Data */ var xmlDeleteAccess = ""; try { - var br = Files.newBufferedReader(Paths.get( - "/home/apexuser/examples/config/ONAPBBS/sdnc_DeleteAccessConnectivityInstance.txt" - )); + var br = Files.newBufferedReader(Paths + .get("/home/apexuser/examples/config/ONAPBBS/sdnc_DeleteAccessConnectivityInstance.txt")); var line; while ((line = br.readLine()) != null) { xmlDeleteAccess += line; @@ -96,56 +93,39 @@ try { /* BBS Policy calls SDN-C GR-API to delete AccessConnectivity */ xmlDeleteAccess = xmlDeleteAccess.replace("svc_request_id_value", sdncUUID); -xmlDeleteAccess = xmlDeleteAccess.replace("svc_notification_url_value", - SVC_NOTIFICATION_URL); +xmlDeleteAccess = xmlDeleteAccess.replace("svc_notification_url_value", SVC_NOTIFICATION_URL); xmlDeleteAccess = xmlDeleteAccess.replace("request_id_value", sdncUUID); xmlDeleteAccess = xmlDeleteAccess.replace("service_id_value", sdncUUID); -xmlDeleteAccess = xmlDeleteAccess.replace("service_instance_id_value", - putUpddateServInstance['service-instance-id']); -xmlDeleteAccess = xmlDeleteAccess.replace("service_type_value", input_param[ - 'service']['serviceType']); -xmlDeleteAccess = xmlDeleteAccess.replace("customer_id_value", input_param[ - 'service']['globalSubscriberId']); -xmlDeleteAccess = xmlDeleteAccess.replace("customer_name_value", input_param[ - 'service']['globalSubscriberId']); - -xmlDeleteAccess = xmlDeleteAccess.replace("srv_info_model_inv_uuid_value", - getResourceInvariantUuid(input_param['service']['parameters'][ - 'resources' - ], 'AccessConnectivity')); -xmlDeleteAccess = xmlDeleteAccess.replace("srv_info_model_custom_uuid_value", - getResourceCustomizationUuid(input_param['service']['parameters'][ - 'resources' - ], 'AccessConnectivity')); -xmlDeleteAccess = xmlDeleteAccess.replace("srv_info_model_uuid_value", - getResourceUuid(input_param['service']['parameters']['resources'], - 'AccessConnectivity')); +xmlDeleteAccess = xmlDeleteAccess.replace("service_instance_id_value", putUpddateServInstance['service-instance-id']); +xmlDeleteAccess = xmlDeleteAccess.replace("service_type_value", input_param['service']['serviceType']); +xmlDeleteAccess = xmlDeleteAccess.replace("customer_id_value", input_param['service']['globalSubscriberId']); +xmlDeleteAccess = xmlDeleteAccess.replace("customer_name_value", input_param['service']['globalSubscriberId']); + +xmlDeleteAccess = xmlDeleteAccess.replace("srv_info_model_inv_uuid_value", getResourceInvariantUuid( + input_param['service']['parameters']['resources'], 'AccessConnectivity')); +xmlDeleteAccess = xmlDeleteAccess.replace("srv_info_model_custom_uuid_value", getResourceCustomizationUuid( + input_param['service']['parameters']['resources'], 'AccessConnectivity')); +xmlDeleteAccess = xmlDeleteAccess.replace("srv_info_model_uuid_value", getResourceUuid( + input_param['service']['parameters']['resources'], 'AccessConnectivity')); xmlDeleteAccess = xmlDeleteAccess.replace("srv_info_model_name_value", "AccessConnectivity"); -xmlDeleteAccess = xmlDeleteAccess.replace("network_info_model_inv_uuid_value", - getResourceInvariantUuid(input_param['service']['parameters'][ - 'resources' - ], 'AccessConnectivity')); -xmlDeleteAccess = xmlDeleteAccess.replace( - "network_info_model_custom_uuid_value", getResourceCustomizationUuid( +xmlDeleteAccess = xmlDeleteAccess.replace("network_info_model_inv_uuid_value", getResourceInvariantUuid( + input_param['service']['parameters']['resources'], 'AccessConnectivity')); +xmlDeleteAccess = xmlDeleteAccess.replace("network_info_model_custom_uuid_value", getResourceCustomizationUuid( + input_param['service']['parameters']['resources'], 'AccessConnectivity')); +xmlDeleteAccess = xmlDeleteAccess.replace("network_info_model_uuid_value", getResourceUuid( input_param['service']['parameters']['resources'], 'AccessConnectivity')); -xmlDeleteAccess = xmlDeleteAccess.replace("network_info_model_uuid_value", - getResourceUuid(input_param['service']['parameters']['resources'], - 'AccessConnectivity')); -xmlDeleteAccess = xmlDeleteAccess.replace("network_info_model_name_value", - "AccessConnectivity"); - -xmlDeleteAccess = xmlDeleteAccess.replace("vendor_value", input_param['service'] - ['parameters']['requestInputs']['ont_ont_manufacturer']); +xmlDeleteAccess = xmlDeleteAccess.replace("network_info_model_name_value", "AccessConnectivity"); + +xmlDeleteAccess = xmlDeleteAccess.replace("vendor_value", + input_param['service']['parameters']['requestInputs']['ont_ont_manufacturer']); xmlDeleteAccess = xmlDeleteAccess.replace("service_id_value", getMetaValue( - putUpddateServInstance['metadata']['metadatum'], - 'controller-service-id')); + putUpddateServInstance['metadata']['metadatum'], 'controller-service-id')); executor.logger.info(client.toPrettyString(xmlDeleteAccess, 4)); try { - var urlPost1 = HTTP_PROTOCOL + SDNC_URL + - "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation"; - result = client.httpRequest(urlPost1, "POST", xmlDeleteAccess, SDNC_USERNAME, SDNC_PASSWORD, - "application/xml", true, true); + var urlPost1 = HTTP_PROTOCOL + SDNC_URL + "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation"; + result = client.httpRequest(urlPost1, "POST", xmlDeleteAccess, SDNC_USERNAME, SDNC_PASSWORD, "application/xml", + false); executor.logger.info("Data received From " + urlPost1 + " " + result); if (result == "") { sdncUpdateResult = false; @@ -155,14 +135,13 @@ try { sdncUpdateResult = false; } -/* BBS Policy calls SDN-C GR-API to create new AccessConnectivity VF */ +/* BBS Policy calls SDN-C GR-API to create new AccessConnectivity VF */ -/* Prepare Data*/ +/* Prepare Data */ var xmlCreateAccess = ""; try { - var br = Files.newBufferedReader(Paths.get( - "/home/apexuser/examples/config/ONAPBBS/sdnc_CreateAccessConnectivityInstance.txt" - )); + var br = Files.newBufferedReader(Paths + .get("/home/apexuser/examples/config/ONAPBBS/sdnc_CreateAccessConnectivityInstance.txt")); var line; while ((line = br.readLine()) != null) { xmlCreateAccess += line; @@ -172,62 +151,47 @@ try { executor.logger.info("Failed to retrieve data " + err); } xmlCreateAccess = xmlCreateAccess.replace("svc_request_id_value", sdncUUID); -xmlCreateAccess = xmlCreateAccess.replace("svc_notification_url_value", - SVC_NOTIFICATION_URL); +xmlCreateAccess = xmlCreateAccess.replace("svc_notification_url_value", SVC_NOTIFICATION_URL); xmlCreateAccess = xmlCreateAccess.replace("request_id_value", requestID); xmlCreateAccess = xmlCreateAccess.replace("service_id_value", sdncUUID); -xmlCreateAccess = xmlCreateAccess.replace("service_instance_id_value", - putUpddateServInstance['service-instance-id']); -xmlCreateAccess = xmlCreateAccess.replace("service_type_value", input_param[ - 'service']['serviceType']); -xmlCreateAccess = xmlCreateAccess.replace("customer_id_value", input_param[ - 'service']['globalSubscriberId']); -xmlCreateAccess = xmlCreateAccess.replace("customer_name_value", input_param[ - 'service']['globalSubscriberId']); - -xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_inv_uuid_value", - getResourceInvariantUuid(input_param['service']['parameters'][ - 'resources' - ], 'AccessConnectivity')); -xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_custom_uuid_value", - getResourceCustomizationUuid(input_param['service']['parameters'][ - 'resources' - ], 'AccessConnectivity')); -xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_uuid_value", - getResourceUuid(input_param['service']['parameters']['resources'], - 'AccessConnectivity')); +xmlCreateAccess = xmlCreateAccess.replace("service_instance_id_value", putUpddateServInstance['service-instance-id']); +xmlCreateAccess = xmlCreateAccess.replace("service_type_value", input_param['service']['serviceType']); +xmlCreateAccess = xmlCreateAccess.replace("customer_id_value", input_param['service']['globalSubscriberId']); +xmlCreateAccess = xmlCreateAccess.replace("customer_name_value", input_param['service']['globalSubscriberId']); + +xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_inv_uuid_value", getResourceInvariantUuid( + input_param['service']['parameters']['resources'], 'AccessConnectivity')); +xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_custom_uuid_value", getResourceCustomizationUuid( + input_param['service']['parameters']['resources'], 'AccessConnectivity')); +xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_uuid_value", getResourceUuid( + input_param['service']['parameters']['resources'], 'AccessConnectivity')); xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_name_value", "AccessConnectivity"); -xmlCreateAccess = xmlCreateAccess.replace("network_info_model_inv_uuid_value", - getResourceInvariantUuid(input_param['service']['parameters'][ - 'resources' - ], 'AccessConnectivity')); -xmlCreateAccess = xmlCreateAccess.replace( - "network_info_model_custom_uuid_value", getResourceCustomizationUuid( +xmlCreateAccess = xmlCreateAccess.replace("network_info_model_inv_uuid_value", getResourceInvariantUuid( + input_param['service']['parameters']['resources'], 'AccessConnectivity')); +xmlCreateAccess = xmlCreateAccess.replace("network_info_model_custom_uuid_value", getResourceCustomizationUuid( + input_param['service']['parameters']['resources'], 'AccessConnectivity')); +xmlCreateAccess = xmlCreateAccess.replace("network_info_model_uuid_value", getResourceUuid( input_param['service']['parameters']['resources'], 'AccessConnectivity')); -xmlCreateAccess = xmlCreateAccess.replace("network_info_model_uuid_value", - getResourceUuid(input_param['service']['parameters']['resources'], - 'AccessConnectivity')); -xmlCreateAccess = xmlCreateAccess.replace("network_info_model_name_value", - "AccessConnectivity"); - -xmlCreateAccess = xmlCreateAccess.replace("vendor_value", input_param['service'] - ['parameters']['requestInputs']['ont_ont_manufacturer']); -xmlCreateAccess = xmlCreateAccess.replace("ont_sn_value", input_param['service'] - ['parameters']['requestInputs']['ont_ont_serial_num']); -xmlCreateAccess = xmlCreateAccess.replace("s_vlan_value", getMetaValue( - putUpddateServInstance['metadata']['metadatum'], 'svlan')); -xmlCreateAccess = xmlCreateAccess.replace("c_vlan_value", getMetaValue( - putUpddateServInstance['metadata']['metadatum'], 'cvlan')); +xmlCreateAccess = xmlCreateAccess.replace("network_info_model_name_value", "AccessConnectivity"); + +xmlCreateAccess = xmlCreateAccess.replace("vendor_value", + input_param['service']['parameters']['requestInputs']['ont_ont_manufacturer']); +xmlCreateAccess = xmlCreateAccess.replace("ont_sn_value", + input_param['service']['parameters']['requestInputs']['ont_ont_serial_num']); +xmlCreateAccess = xmlCreateAccess.replace("s_vlan_value", getMetaValue(putUpddateServInstance['metadata']['metadatum'], + 'svlan')); +xmlCreateAccess = xmlCreateAccess.replace("c_vlan_value", getMetaValue(putUpddateServInstance['metadata']['metadatum'], + 'cvlan')); xmlCreateAccess = xmlCreateAccess.replace("remote_id_value", getMetaValue( - putUpddateServInstance['metadata']['metadatum'], 'remote-id')); + putUpddateServInstance['metadata']['metadatum'], 'remote-id')); executor.logger.info(client.toPrettyString(xmlCreateAccess, 4)); try { if (sdncUpdateResult == true) { - var urlPost2 = HTTP_PROTOCOL + SDNC_URL + - "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation"; - result = client.httpRequest(urlPost2, "POST", xmlCreateAccess, SDNC_USERNAME, SDNC_PASSWORD, - "application/xml", true, true); + var urlPost2 = HTTP_PROTOCOL + SDNC_URL + + "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation"; + result = client.httpRequest(urlPost2, "POST", xmlCreateAccess, SDNC_USERNAME, SDNC_PASSWORD, "application/xml", + false); executor.logger.info("Data received From " + urlPost2 + " " + result); if (result == "") { sdncUpdateResult = false; @@ -238,12 +202,11 @@ try { sdncUpdateResult = false; } -/* BBS Policy calls SDN-C GR-API to create change Internet Profile */ +/* BBS Policy calls SDN-C GR-API to create change Internet Profile */ var xmlChangeProfile = ""; try { - var br = Files.newBufferedReader(Paths.get( - "/home/apexuser/examples/config/ONAPBBS/sdnc_ChangeInternetProfileInstance.txt" - )); + var br = Files.newBufferedReader(Paths + .get("/home/apexuser/examples/config/ONAPBBS/sdnc_ChangeInternetProfileInstance.txt")); var line; while ((line = br.readLine()) != null) { xmlChangeProfile += line; @@ -254,75 +217,56 @@ try { } xmlChangeProfile = xmlChangeProfile.replace("svc_request_id_value", sdncUUID); -xmlChangeProfile = xmlChangeProfile.replace("svc_notification_url_value", - SVC_NOTIFICATION_URL); +xmlChangeProfile = xmlChangeProfile.replace("svc_notification_url_value", SVC_NOTIFICATION_URL); xmlChangeProfile = xmlChangeProfile.replace("request_id_value", requestID); xmlChangeProfile = xmlChangeProfile.replace("service_id_value", sdncUUID); -xmlChangeProfile = xmlChangeProfile.replace("service_instance_id_value", - putUpddateServInstance['service-instance-id']); -xmlChangeProfile = xmlChangeProfile.replace("service_type_value", input_param[ - 'service']['serviceType']); -xmlChangeProfile = xmlChangeProfile.replace("customer_id_value", input_param[ - 'service']['globalSubscriberId']); -xmlChangeProfile = xmlChangeProfile.replace("customer_name_value", input_param[ - 'service']['globalSubscriberId']); - -xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_inv_uuid_value", - getResourceInvariantUuid(input_param['service']['parameters'][ - 'resources' - ], 'InternetProfile')); -xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_custom_uuid_value", - getResourceCustomizationUuid(input_param['service']['parameters'][ - 'resources' - ], 'InternetProfile')); -xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_uuid_value", - getResourceUuid(input_param['service']['parameters']['resources'], - 'InternetProfile')); -xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_name_value", - "InternetProfile"); -xmlCreateAccess = xmlCreateAccess.replace("network_info_model_inv_uuid_value", - getResourceInvariantUuid(input_param['service']['parameters'][ - 'resources' - ], 'InternetProfile')); -xmlCreateAccess = xmlCreateAccess.replace( - "network_info_model_custom_uuid_value", getResourceCustomizationUuid( - input_param['service']['parameters']['resources'], - 'InternetProfile')); -xmlCreateAccess = xmlCreateAccess.replace("network_info_model_uuid_value", - getResourceUuid(input_param['service']['parameters']['resources'], - 'InternetProfile')); -xmlCreateAccess = xmlCreateAccess.replace("network_info_model_name_value", - "InternetProfile"); - -xmlChangeProfile = xmlChangeProfile.replace("vendor_value", input_param[ - 'service']['parameters']['requestInputs']['ont_ont_manufacturer']); +xmlChangeProfile = xmlChangeProfile.replace("service_instance_id_value", putUpddateServInstance['service-instance-id']); +xmlChangeProfile = xmlChangeProfile.replace("service_type_value", input_param['service']['serviceType']); +xmlChangeProfile = xmlChangeProfile.replace("customer_id_value", input_param['service']['globalSubscriberId']); +xmlChangeProfile = xmlChangeProfile.replace("customer_name_value", input_param['service']['globalSubscriberId']); + +xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_inv_uuid_value", getResourceInvariantUuid( + input_param['service']['parameters']['resources'], 'InternetProfile')); +xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_custom_uuid_value", getResourceCustomizationUuid( + input_param['service']['parameters']['resources'], 'InternetProfile')); +xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_uuid_value", getResourceUuid( + input_param['service']['parameters']['resources'], 'InternetProfile')); +xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_name_value", "InternetProfile"); +xmlCreateAccess = xmlCreateAccess.replace("network_info_model_inv_uuid_value", getResourceInvariantUuid( + input_param['service']['parameters']['resources'], 'InternetProfile')); +xmlCreateAccess = xmlCreateAccess.replace("network_info_model_custom_uuid_value", getResourceCustomizationUuid( + input_param['service']['parameters']['resources'], 'InternetProfile')); +xmlCreateAccess = xmlCreateAccess.replace("network_info_model_uuid_value", getResourceUuid( + input_param['service']['parameters']['resources'], 'InternetProfile')); +xmlCreateAccess = xmlCreateAccess.replace("network_info_model_name_value", "InternetProfile"); + +xmlChangeProfile = xmlChangeProfile.replace("vendor_value", + input_param['service']['parameters']['requestInputs']['ont_ont_manufacturer']); xmlChangeProfile = xmlChangeProfile.replace("service_id_value", getMetaValue( - putUpddateServInstance['metadata']['metadatum'], - 'controller-service-id')); + putUpddateServInstance['metadata']['metadatum'], 'controller-service-id')); xmlChangeProfile = xmlChangeProfile.replace("remote_id_value", getMetaValue( - putUpddateServInstance['metadata']['metadatum'], 'remote-id')); -xmlChangeProfile = xmlChangeProfile.replace("ont_sn_value", input_param[ - 'service']['parameters']['requestInputs']['ont_ont_serial_num']); -xmlChangeProfile = xmlChangeProfile.replace("service_type_value", input_param[ - 'service']['serviceType']); -xmlChangeProfile = xmlChangeProfile.replace("mac_value", getMetaValue( - putUpddateServInstance['metadata']['metadatum'], 'rgw-mac-address')); + putUpddateServInstance['metadata']['metadatum'], 'remote-id')); +xmlChangeProfile = xmlChangeProfile.replace("ont_sn_value", + input_param['service']['parameters']['requestInputs']['ont_ont_serial_num']); +xmlChangeProfile = xmlChangeProfile.replace("service_type_value", input_param['service']['serviceType']); +xmlChangeProfile = xmlChangeProfile.replace("mac_value", getMetaValue(putUpddateServInstance['metadata']['metadatum'], + 'rgw-mac-address')); xmlChangeProfile = xmlChangeProfile.replace("up_speed_value", getMetaValue( - putUpddateServInstance['metadata']['metadatum'], 'up-speed')); + putUpddateServInstance['metadata']['metadatum'], 'up-speed')); xmlChangeProfile = xmlChangeProfile.replace("down_speed_value", getMetaValue( - putUpddateServInstance['metadata']['metadatum'], 'down-speed')); + putUpddateServInstance['metadata']['metadatum'], 'down-speed')); xmlChangeProfile = xmlChangeProfile.replace("s_vlan_value", getMetaValue( - putUpddateServInstance['metadata']['metadatum'], 'svlan')); + putUpddateServInstance['metadata']['metadatum'], 'svlan')); xmlChangeProfile = xmlChangeProfile.replace("c_vlan_value", getMetaValue( - putUpddateServInstance['metadata']['metadatum'], 'cvlan')); + putUpddateServInstance['metadata']['metadatum'], 'cvlan')); executor.logger.info(client.toPrettyString(xmlChangeProfile, 4)); try { if (sdncUpdateResult == true) { - var urlPost3 = HTTP_PROTOCOL + SDNC_URL + - "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation"; + var urlPost3 = HTTP_PROTOCOL + SDNC_URL + + "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation"; result = client.httpRequest(urlPost3, "POST", xmlChangeProfile, SDNC_USERNAME, SDNC_PASSWORD, - "application/xml", true, true); + "application/xml", false); executor.logger.info("Data received From " + urlPost3 + " " + result); if (result == "") { sdncUpdateResult = false; @@ -345,8 +289,7 @@ if (sdncUpdateResult === true) { executor.outFields.put("requestID", requestID); executor.outFields.put("attachmentPoint", attachmentPoint); -executor.outFields.put("serviceInstanceId", executor.inFields.get( - "serviceInstanceId")); +executor.outFields.put("serviceInstanceId", executor.inFields.get("serviceInstanceId")); var returnValue = executor.isTrue; executor.logger.info(executor.outFields); @@ -401,4 +344,4 @@ function IsValidJSONString(str) { } return true; } -/* Utility functions End */
\ No newline at end of file +/* Utility functions End */ diff --git a/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js b/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js index 56be83628..90b1b0075 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -83,8 +84,8 @@ try { SERVICE_INSTANCE_ID + "?format=resource_and_url" executor.logger.info("Query url" + urlGet); - result = client.httpsRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, - "application/json", true, true); + result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, + "application/json", true); executor.logger.info("Data received From " + urlGet + " " + result); jsonObj = JSON.parse(result); @@ -122,8 +123,8 @@ try { putUpddateServInstance, null, 4)); var urlPut = HTTP_PROTOCOL + AAI_URL + putUrl + "?resource_version=" + resource_version; - result = client.httpsRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD, - "application/json", true, true); + result = client.httpRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD, + "application/json", true); executor.logger.info("Data received From " + urlPut + " " + result); /* If failure to retrieve data proceed to Failure */ if (result != "") { diff --git a/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java b/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java index 8012c1e30..2ff9435b2 100644 --- a/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java +++ b/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java @@ -21,6 +21,7 @@ package org.onap.policy.apex.examples.bbs; +import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -35,13 +36,15 @@ import org.mockito.Mockito; public class WebClientTest { HttpsURLConnection mockedHttpsUrlConnection; String sampleString = "Response Code :200"; + /** * Set up the mocked REST manager. - * @throws IOException + * + * @throws IOException on I/O errors */ @Before public void setupMockedRest() throws IOException { - mockedHttpsUrlConnection = mock(HttpsURLConnection.class); + mockedHttpsUrlConnection = mock(HttpsURLConnection.class); InputStream inputStream = new ByteArrayInputStream(sampleString.getBytes()); when(mockedHttpsUrlConnection.getInputStream()).thenReturn(inputStream); Mockito.doNothing().when(mockedHttpsUrlConnection).connect(); @@ -50,17 +53,17 @@ public class WebClientTest { @Test public void httpsRequest() { WebClient cl = new WebClient(); - String result = cl.httpsRequest("https://some.random.url/data", "POST", null, - "admin", "admin", "application/json",true, true); - + String result = cl.httpRequest("https://some.random.url/data", "POST", null, "admin", "admin", + "application/json", true); + assertNotNull(result); } @Test public void httpRequest() { WebClient cl = new WebClient(); - String result = cl.httpRequest("http://some.random.url/data", "GET", null, - "admin", "admin", "application/json",true, true); - + String result = + cl.httpRequest("http://some.random.url/data", "GET", null, "admin", "admin", "application/json", false); + assertNotNull(result); } @Test |