aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2019-04-29 11:43:01 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-29 11:43:01 +0000
commitb267849e414baddb1c14a4be29fc06d9703ed944 (patch)
tree1a06182611f78fcc53e9d09fe9b106c045feb234
parentf6da9a3bafb6f4c30e7bb3accd4e17fdaaf5ce92 (diff)
parentad178d97b872542a57356dd0b24493d3fd4d925f (diff)
Merge "ONAP BBS: Apex Nomadic ONT bug fixes"
-rw-r--r--examples/examples-onap-bbs/pom.xml5
-rw-r--r--examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java296
-rw-r--r--examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/package-info.java21
-rw-r--r--examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/config.txt6
-rw-r--r--examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_ChangeInternetProfileInstance.txt147
-rw-r--r--examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_CreateAccessConnectivityInstance.txt99
-rw-r--r--examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_DeleteAccessConnectivityInstance.txt79
-rw-r--r--examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js110
-rw-r--r--examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js141
-rw-r--r--examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js2
-rw-r--r--examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js3
-rw-r--r--examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js1
-rw-r--r--examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js140
-rw-r--r--examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js24
-rw-r--r--examples/examples-onap-bbs/src/main/resources/policy/NomadicONTPolicyModel.apex4
-rw-r--r--examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java74
16 files changed, 714 insertions, 438 deletions
diff --git a/examples/examples-onap-bbs/pom.xml b/examples/examples-onap-bbs/pom.xml
index c45d808f7..29f073052 100644
--- a/examples/examples-onap-bbs/pom.xml
+++ b/examples/examples-onap-bbs/pom.xml
@@ -95,6 +95,11 @@
<artifactId>events</artifactId>
<version>${version.policy.models}</version>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
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
new file mode 100644
index 000000000..09b3fc47b
--- /dev/null
+++ b/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java
@@ -0,0 +1,296 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei. All rights reserved.
+ * ================================================================================
+ * 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
+ *
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+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.util.Base64;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+import java.security.cert.X509Certificate;
+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;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathFactory;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+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);
+ }
+ }
+
+ /**
+ * 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 httpsRequest(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("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);
+
+ if ("GET".equalsIgnoreCase(requestMethod)) {
+ httpUrlConn.connect();
+ }
+
+ if (null != outputStr) {
+ OutputStream outputStream = httpUrlConn.getOutputStream();
+ outputStream.write(outputStr.getBytes(StandardCharsets.UTF_8));
+ 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);
+ }
+ }
+ }
+ httpUrlConn.disconnect();
+ result = buffer.toString();
+ }
+ 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);
+
+ 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);
+
+ if ("GET".equalsIgnoreCase(requestMethod)) {
+ httpUrlConn.connect();
+ }
+
+ if (null != outputStr) {
+ OutputStream outputStream = httpUrlConn.getOutputStream();
+ outputStream.write(outputStr.getBytes(StandardCharsets.UTF_8));
+ 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);
+ }
+ }
+ }
+ httpUrlConn.disconnect();
+ result = buffer.toString();
+ }
+ LOGGER.info("httpsRequest success ");
+ } catch (Exception ce) {
+ LOGGER.error("httpsRequest Exception " + ce);
+ }
+ return result;
+ }
+
+ /**
+ * 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
+ * @param indent Indent number
+ * @return Indented xml string
+ */
+ 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.normalize();
+ XPath path = XPathFactory.newInstance().newXPath();
+ 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();
+ transformer.setOutputProperty(OutputKeys.ENCODING, StandardCharsets.UTF_8.name());
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+
+ StringWriter stringWriter = new StringWriter();
+ transformer.transform(new DOMSource(document), new StreamResult(stringWriter));
+ return stringWriter.toString();
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/package-info.java b/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/package-info.java
new file mode 100644
index 000000000..9e24032f0
--- /dev/null
+++ b/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/package-info.java
@@ -0,0 +1,21 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei. All rights reserved.
+ * ================================================================================
+ * 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
+ *
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.examples.bbs;
diff --git a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/config.txt b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/config.txt
index 794398be4..d132aa2f3 100644
--- a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/config.txt
+++ b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/config.txt
@@ -1,3 +1,7 @@
AAI_URL=aai.api.simpledemo.openecomp.org:30233
-SDNC_URL=aai.api.simpledemo.openecomp.org:8443
+AAI_USERNAME=AAI
+AAI_PASSWORD=AAI
+SDNC_URL=sdnc.api.simpledemo.onap.org:30202
+SDNC_USERNAME=admin
+SDNC_PASSWORD=Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U
SVC_NOTIFICATION_URL=http://c1.vm1.mso.simpledemo.openecomp.org:8080 \ No newline at end of file
diff --git a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_ChangeInternetProfileInstance.txt b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_ChangeInternetProfileInstance.txt
index 2304e5739..193e3bb2d 100644
--- a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_ChangeInternetProfileInstance.txt
+++ b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_ChangeInternetProfileInstance.txt
@@ -1,81 +1,80 @@
-<input>
- <sdnc-request-header>
- <svc-request-id>svc_request_id_value</svc-request-id>
- <svc-action>update</svc-action>
- <svc-notification-url>svc_notification_url_value</svc-notification-url>
- </sdnc-request-header>
- <request-information>
- <request-id>request_id_value</request-id>
- <request-action>ChangeInternetProfileInstance</request-action>
- <source>null</source>
- <notification-url></notification-url>
- <order-number></order-number>
- <order-version></order-version>
- </request-information>
- <service-information>
- <service-id>service_id_value</service-id>
- <service-instance-id>service_instance_id_value</service-instance-id>
- <subscription-service-type>service_type_value</subscription-service-type>
- <global-customer-id>customer_id_value</global-customer-id>
- <subscriber-name>customer_name_value</subscriber-name>
- <onap-model-information>
- <model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid>
+<input xmlns="org:onap:sdnc:northbound:generic-resource">
+ <sdnc-request-header>
+ <svc-request-id>svc_request_id_value</svc-request-id>
+ <svc-action>update</svc-action>
+ <svc-notification-url>svc_notification_url_value</svc-notification-url>
+ </sdnc-request-header>
+ <request-information>
+ <request-id>request_id_value</request-id>
+ <request-action>ChangeInternetProfileInstance</request-action>
+ <source>null</source>
+ <notification-url></notification-url>
+ <order-number></order-number>
+ <order-version></order-version>
+ </request-information>
+ <service-information>
+ <service-id>service_id_value</service-id>
+ <service-instance-id>service_instance_id_value</service-instance-id>
+ <subscription-service-type>service_type_value</subscription-service-type>
+ <global-customer-id>customer_id_value</global-customer-id>
+ <subscriber-name>customer_name_value</subscriber-name>
+ <onap-model-information>
+ <model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid>
<model-customization-uuid>srv_info_model_custom_uuid_value</model-customization-uuid>
<model-uuid>srv_info_model_uuid_value</model-uuid>
<model-name>srv_info_model_name_value</model-name>
- </onap-model-information>
- </service-information>
- <network-information>
- <onap-model-information>
- <model-invariant-uuid>network_info_model_inv_uuid_value</model-invariant-uuid>
+ </onap-model-information>
+ </service-information>
+ <network-information>
+ <onap-model-information>
+ <model-invariant-uuid>network_info_model_inv_uuid_value</model-invariant-uuid>
<model-customization-uuid>network_info_model_custom_uuid_value</model-customization-uuid>
<model-uuid>network_info_model_uuid_value</model-uuid>
<model-name>network_info_model_name_value</model-name>
- </onap-model-information>
- </network-information>
- <network-request-input>
- <network-input-parameters>
- <param>
- <name>vendor</name>
- <value>vendor_value</value>
- </param>
- <param>
- <name>service_id</name>
- <value>service_id_value</value>
- </param>
- <param>
- <name>access_id</name>
- <value>access_id_value</value>
- </param>
- <param>
- <name>ont_sn</name>
- <value>ont_sn_value</value>
- </param>
- <param>
- <name>service_type</name>
- <value>service_type_value</value>
- </param>
- <param>
- <name>mac</name>
- <value>mac_value</value>
- </param>
- <param>
- <name>up_speed</name>
- <value>up_speed_value</value>
- </param>
- <param>
- <name>down_speed</name>
- <value>down_speed_value</value>
- </param>
- <param>
- <name>s_vlan</name>
- <value>s_vlan_value</value>
- </param>
- <param>
- <name>c_vlan</name>
- <value>c_vlan_value</value>
- </param>
- </network-input-parameters>
- </network-request-input>
- <_xmlns>org:onap:sdnc:northbound:generic-resource</_xmlns>
+ </onap-model-information>
+ </network-information>
+ <network-request-input>
+ <network-input-parameters>
+ <param>
+ <name>vendor</name>
+ <value>vendor_value</value>
+ </param>
+ <param>
+ <name>service_id</name>
+ <value>service_id_value</value>
+ </param>
+ <param>
+ <name>access_id</name>
+ <value>access_id_value</value>
+ </param>
+ <param>
+ <name>ont_sn</name>
+ <value>ont_sn_value</value>
+ </param>
+ <param>
+ <name>service_type</name>
+ <value>service_type_value</value>
+ </param>
+ <param>
+ <name>mac</name>
+ <value>mac_value</value>
+ </param>
+ <param>
+ <name>up_speed</name>
+ <value>up_speed_value</value>
+ </param>
+ <param>
+ <name>down_speed</name>
+ <value>down_speed_value</value>
+ </param>
+ <param>
+ <name>s_vlan</name>
+ <value>s_vlan_value</value>
+ </param>
+ <param>
+ <name>c_vlan</name>
+ <value>c_vlan_value</value>
+ </param>
+ </network-input-parameters>
+ </network-request-input>
</input>
diff --git a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_CreateAccessConnectivityInstance.txt b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_CreateAccessConnectivityInstance.txt
index 7410c0bc6..9168ff17d 100644
--- a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_CreateAccessConnectivityInstance.txt
+++ b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_CreateAccessConnectivityInstance.txt
@@ -1,61 +1,60 @@
-<input>
- <sdnc-request-header>
- <svc-request-id>svc_request_id_value</svc-request-id>
- <svc-action>create</svc-action>
- <svc-notification-url>svc_notification_url_value</svc-notification-url>
- </sdnc-request-header>
- <request-information>
- <request-id>request_id_value</request-id>
- <request-action>CreateAccessConnectivityInstance</request-action>
- <source>null</source>
- <notification-url></notification-url>
- <order-number></order-number>
- <order-version></order-version>
- </request-information>
- <service-information>
- <service-id>service_id_value</service-id>
+<input xmlns="org:onap:sdnc:northbound:generic-resource">
+ <sdnc-request-header>
+ <svc-request-id>svc_request_id_value</svc-request-id>
+ <svc-action>create</svc-action>
+ <svc-notification-url>svc_notification_url_value</svc-notification-url>
+ </sdnc-request-header>
+ <request-information>
+ <request-id>request_id_value</request-id>
+ <request-action>CreateAccessConnectivityInstance</request-action>
+ <source>null</source>
+ <notification-url></notification-url>
+ <order-number></order-number>
+ <order-version></order-version>
+ </request-information>
+ <service-information>
+ <service-id>service_id_value</service-id>
<service-instance-id>service_instance_id_value</service-instance-id>
<subscription-service-type>service_type_value</subscription-service-type>
<global-customer-id>customer_id_value</global-customer-id>
<subscriber-name>customer_name_value</subscriber-name>
- <onap-model-information>
- <model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid>
+ <onap-model-information>
+ <model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid>
<model-customization-uuid>srv_info_model_custom_uuid_value</model-customization-uuid>
<model-uuid>srv_info_model_uuid_value</model-uuid>
<model-name>srv_info_model_name_value</model-name>
- </onap-model-information>
- </service-information>
- <network-information>
- <onap-model-information>
- <model-invariant-uuid>network_info_model_inv_uuid_value</model-invariant-uuid>
+ </onap-model-information>
+ </service-information>
+ <network-information>
+ <onap-model-information>
+ <model-invariant-uuid>network_info_model_inv_uuid_value</model-invariant-uuid>
<model-customization-uuid>network_info_model_custom_uuid_value</model-customization-uuid>
<model-uuid>network_info_model_uuid_value</model-uuid>
<model-name>network_info_model_name_value</model-name>
- </onap-model-information>
- </network-information>
- <network-request-input>
- <network-input-parameters>
- <param>
- <name>vendor</name>
- <value>vendor_value</value>
- </param>
- <param>
- <name>ONTSN</name>
- <value>ont_sn_value</value>
- </param>
- <param>
- <name>CVLAN</name>
- <value>c_vlan_value</value>
- </param>
- <param>
- <name>SVLAN</name>
- <value>s_vlan_value</value>
- </param>
- <param>
- <name>accessID</name>
- <value>access_id_value</value>
- </param>
- </network-input-parameters>
- </network-request-input>
- <_xmlns>org:onap:sdnc:northbound:generic-resource</_xmlns>
+ </onap-model-information>
+ </network-information>
+ <network-request-input>
+ <network-input-parameters>
+ <param>
+ <name>vendor</name>
+ <value>vendor_value</value>
+ </param>
+ <param>
+ <name>ONTSN</name>
+ <value>ont_sn_value</value>
+ </param>
+ <param>
+ <name>CVLAN</name>
+ <value>c_vlan_value</value>
+ </param>
+ <param>
+ <name>SVLAN</name>
+ <value>s_vlan_value</value>
+ </param>
+ <param>
+ <name>accessID</name>
+ <value>access_id_value</value>
+ </param>
+ </network-input-parameters>
+ </network-request-input>
</input>
diff --git a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_DeleteAccessConnectivityInstance.txt b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_DeleteAccessConnectivityInstance.txt
index e464e2ee1..a3fe0bd4d 100644
--- a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_DeleteAccessConnectivityInstance.txt
+++ b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_DeleteAccessConnectivityInstance.txt
@@ -1,49 +1,48 @@
-<input>
- <sdnc-request-header>
- <svc-request-id>svc_request_id_value</svc-request-id>
- <svc-action>delete</svc-action>
- <svc-notification-url>svc_notification_url_value</svc-notification-url>
- </sdnc-request-header>
- <request-information>
- <request-id>request_id_value</request-id>
- <request-action>DeleteAccessConnectivityInstance</request-action>
- <source>null</source>
- <notification-url></notification-url>
- <order-number></order-number>
- <order-version></order-version>
- </request-information>
- <service-information>
- <service-id>service_id_value</service-id>
+<input xmlns="org:onap:sdnc:northbound:generic-resource">
+ <sdnc-request-header>
+ <svc-request-id>svc_request_id_value</svc-request-id>
+ <svc-action>delete</svc-action>
+ <svc-notification-url>svc_notification_url_value</svc-notification-url>
+ </sdnc-request-header>
+ <request-information>
+ <request-id>request_id_value</request-id>
+ <request-action>DeleteAccessConnectivityInstance</request-action>
+ <source>null</source>
+ <notification-url></notification-url>
+ <order-number></order-number>
+ <order-version></order-version>
+ </request-information>
+ <service-information>
+ <service-id>service_id_value</service-id>
<service-instance-id>service_instance_id_value</service-instance-id>
<subscription-service-type>service_type_value</subscription-service-type>
<global-customer-id>customer_id_value</global-customer-id>
<subscriber-name>customer_name_value</subscriber-name>
- <onap-model-information>
- <model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid>
- <model-customization-uuid>srv_info_model_custom_uuid_value</model-customization-uuid>
- <model-uuid>srv_info_model_uuid_value</model-uuid>
- <model-name>srv_info_model_name_value</model-name>
- </onap-model-information>
- </service-information>
- <network-information>
- <onap-model-information>
+ <onap-model-information>
+ <model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid>
+ <model-customization-uuid>srv_info_model_custom_uuid_value</model-customization-uuid>
+ <model-uuid>srv_info_model_uuid_value</model-uuid>
+ <model-name>srv_info_model_name_value</model-name>
+ </onap-model-information>
+ </service-information>
+ <network-information>
+ <onap-model-information>
<model-invariant-uuid>network_info_model_inv_uuid_value</model-invariant-uuid>
<model-customization-uuid>network_info_model_custom_uuid_value</model-customization-uuid>
<model-uuid>network_info_model_uuid_value</model-uuid>
<model-name>network_info_model_name_value</model-name>
- </onap-model-information>
- </network-information>
- <network-request-input>
- <network-input-parameters>
- <param>
- <name>vendor</name>
- <value>vendor_value</value>
- </param>
- <param>
- <name>serviceID</name>
- <value>serviceID_value</value>
- </param>
- </network-input-parameters>
- </network-request-input>
- <_xmlns>org:onap:sdnc:northbound:generic-resource</_xmlns>
+ </onap-model-information>
+ </network-information>
+ <network-request-input>
+ <network-input-parameters>
+ <param>
+ <name>vendor</name>
+ <value>vendor_value</value>
+ </param>
+ <param>
+ <name>serviceID</name>
+ <value>serviceID_value</value>
+ </param>
+ </network-input-parameters>
+ </network-request-input>
</input>
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 744b6d48b..9d38db1b4 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js
@@ -39,6 +39,10 @@ executor.logger.info(NomadicONTContext);
var jsonObj;
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;
@@ -52,13 +56,17 @@ var service_instance;
try {
var br = Files.newBufferedReader(Paths.get(
"/home/apexuser/examples/config/ONAPBBS/config.txt"));
- // read line by line
var line;
while ((line = br.readLine()) != null) {
if (line.startsWith("AAI_URL")) {
var str = line.split("=");
AAI_URL = str[str.length - 1];
- break;
+ } else if (line.startsWith("AAI_USERNAME")) {
+ var str = line.split("=");
+ AAI_USERNAME = str[str.length - 1];
+ } else if (line.startsWith("AAI_PASSWORD")) {
+ var str = line.split("=");
+ AAI_PASSWORD = str[str.length - 1];
}
}
} catch (err) {
@@ -72,21 +80,25 @@ try {
var urlGet = HTTP_PROTOCOL + AAI_URL +
"/aai/v14/nodes/service-instances/service-instance/" +
SERVICE_INSTANCE_ID + "?format=resource_and_url";
- executor.logger.info("Query url" + urlGet);
- result = httpGet(urlGet).data;
- executor.logger.info("Data received From " + urlGet + " " + result.toString());
- jsonObj = JSON.parse(result);
+ executor.logger.info("Query url" + urlGet);
+ result = client.httpsRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD,
+ "application/json", true, true);
+ executor.logger.info("Data received From " + urlGet + " " + result);
+ jsonObj = JSON.parse(result.toString());
+ executor.logger.info(JSON.stringify(jsonObj, null, 4));
/* Retrieve the service instance id */
- results = jsonObj['results'];
- putUrl = results["url"];
- service_instance = results["service-instance"];
+ results = jsonObj['results'][0];
+ putUrl = results['url'];
+ service_instance = results['service-instance'];
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 " + JSON.stringify(jsonObj, null, 4));
+ 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;
@@ -106,13 +118,12 @@ try {
putUpddateServInstance, null, 4));
var urlPut = HTTP_PROTOCOL + AAI_URL +
putUrl + "?resource_version=" + resource_version;
- result = httpPut(urlPut, JSON.stringify(putUpddateServInstance)).data;
- executor.logger.info("Data received From " + urlPut + " " + result.toString());
- jsonObj = JSON.parse(result);
- executor.logger.info("After Parse " + JSON.stringify(jsonObj, null, 4));
-
+ result = client.httpsRequest(urlPut, "PUT", JSON.stringify(
+ putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD,
+ "application/json", true, true);
+ executor.logger.info("Data received From " + urlPut + " " + result);
/* If failure to retrieve data proceed to Failure */
- if (result == "") {
+ if (result != "") {
aaiUpdateResult = false;
}
}
@@ -121,12 +132,20 @@ try {
aaiUpdateResult = false;
}
+if (!service_instance.hasOwnProperty('input-parameters') || !service_instance
+ .hasOwnProperty('metadata')) {
+ aaiUpdateResult = false;
+ executor.logger.info(
+ "Validate data failed. input-parameters or metadata is missing");
+}
/* If Success then Fill output schema */
if (aaiUpdateResult === true) {
+ executor.outFields.put("result", "SUCCESS");
NomadicONTContext.put("result", "SUCCESS");
NomadicONTContext.put("aai_message", JSON.stringify(service_instance));
NomadicONTContext.put("url", putUrl);
} else {
+ executor.outFields.put("result", "FAILURE");
NomadicONTContext.put("result", "FAILURE");
}
@@ -139,60 +158,13 @@ var returnValue = executor.isTrue;
executor.logger.info(executor.outFields);
executor.logger.info("End Execution AAIServiceAssignedTask.js");
-
/* Utility functions Begin */
-function httpGet(theUrl) {
- var con = new java.net.URL(theUrl).openConnection();
- con.requestMethod = "GET";
- return asResponse(con);
-}
-
-function httpPost(theUrl, data, contentType) {
- contentType = contentType || "application/json";
- var con = new java.net.URL(theUrl).openConnection();
- con.requestMethod = "POST";
- con.setRequestProperty("Content-Type", contentType);
- con.doOutput = true;
- write(con.outputStream, data);
- return asResponse(con);
-}
-
-function httpPut(theUrl, data, contentType) {
- contentType = contentType || "application/json";
- var con = new java.net.URL(theUrl).openConnection();
- con.requestMethod = "PUT";
- con.setRequestProperty("Content-Type", contentType);
- con.doOutput = true;
- write(con.outputStream, data);
- return asResponse(con);
-}
-
-function asResponse(con) {
- var d = read(con.inputStream);
- return {
- data: d,
- statusCode: con.resultCode
- };
-}
-
-function write(outputStream, data) {
- var wr = new java.io.DataOutputStream(outputStream);
- wr.writeBytes(data);
- wr.flush();
- wr.close();
-}
-
-function read(inputStream) {
- var inReader = new java.io.BufferedReader(new java.io.InputStreamReader(
- inputStream));
- var inputLine;
- var result = new java.lang.StringBuffer();
-
- while ((inputLine = inReader.readLine()) != null) {
- result.append(inputLine);
+function IsValidJSONString(str) {
+ try {
+ JSON.parse(str);
+ } catch (e) {
+ return false;
}
- inReader.close();
- return result.toString();
+ return true;
}
-
/* Utility functions End */ \ No newline at end of file
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 9ddc91e8c..ac409ed2d 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js
@@ -32,13 +32,20 @@ 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);
+executor.logger.info(NomadicONTContext);
+
//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";
-var SERVICE_INSTANCE_UUID = serviceInstanceId;
+var SERVICE_INSTANCE_ID = serviceInstanceId;
var HTTP_PROTOCOL = "https://";
-
+var wbClient = Java.type("org.onap.policy.apex.examples.bbs.WebClient");
+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"));
@@ -48,32 +55,57 @@ try {
if (line.startsWith("AAI_URL")) {
var str = line.split("=");
AAI_URL = str[str.length - 1];
- break;
+ } else if (line.startsWith("AAI_USERNAME")) {
+ var str = line.split("=");
+ AAI_USERNAME = str[str.length - 1];
+ } else if (line.startsWith("AAI_PASSWORD")) {
+ var str = line.split("=");
+ AAI_PASSWORD = str[str.length - 1];
}
-
}
} catch (err) {
executor.logger.info("Failed to retrieve data " + err);
}
executor.logger.info("AAI_URL " + AAI_URL);
+var aaiUpdateResult = true;
+/* Get service instance Id from AAI */
+try {
+ var urlGet = HTTP_PROTOCOL + AAI_URL +
+ "/aai/v14/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);
+ executor.logger.info("Data received From " + urlGet + " " + result);
+ jsonObj = JSON.parse(result);
+
+ executor.logger.info(JSON.stringify(jsonObj, null, 4));
+ /* Retrieve the service instance id */
+ 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);
+
+ if (result == "") {
+ aaiUpdateResult = false;
+ }
+} catch (err) {
+ executor.logger.info("Failed to retrieve data " + err);
+ aaiUpdateResult = false;
+}
-
-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);
-executor.logger.info(NomadicONTContext);
-
-var putUpddateServInstance = JSON.parse(NomadicONTContext.get("aai_message"));
-
+var putUpddateServInstance = service_instance;
putUpddateServInstance['orchestration-status'] = "created";
-executor.logger.info(" string" + JSON.stringify(putUpddateServInstance, null, 4));
+if (putUpddateServInstance.hasOwnProperty('input-parameters'))
+ delete putUpddateServInstance['input-parameters'];
+executor.logger.info(" string" + JSON.stringify(putUpddateServInstance, null,
+ 4));
var resource_version = putUpddateServInstance['resource-version'];
var putUrl = NomadicONTContext.get("url");
-var aaiUpdateResult = true;
-
/*BBS Policy updates {{bbs-cfs-service-instance-UUID}} orchestration-status [ assigned --> created ]*/
try {
@@ -82,13 +114,12 @@ try {
putUpddateServInstance, null, 4));
var urlPut = HTTP_PROTOCOL + AAI_URL +
putUrl + "?resource_version=" + resource_version;
- result = httpPut(urlPut, JSON.stringify(putUpddateServInstance)).data;
- executor.logger.info("Data received From " + urlPut + " " + result.toString());
- jsonObj = JSON.parse(result);
- executor.logger.info("After Parse " + JSON.stringify(jsonObj, null, 4));
-
+ result = client.httpsRequest(urlPut, "PUT", JSON.stringify(
+ putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD,
+ "application/json", true, true);
+ executor.logger.info("Data received From " + urlPut + " " + result);
/* If failure to retrieve data proceed to Failure */
- if (result == "") {
+ if (result != "") {
aaiUpdateResult = false;
}
}
@@ -101,8 +132,8 @@ if (aaiUpdateResult === true) {
NomadicONTContext.put("result", "SUCCESS");
} else {
NomadicONTContext.put("result", "FAILURE");
-}
+}
executor.outFields.put("requestID", requestID);
executor.outFields.put("attachmentPoint", attachmentPoint);
@@ -111,62 +142,4 @@ executor.outFields.put("serviceInstanceId", executor.inFields.get(
var returnValue = executor.isTrue;
executor.logger.info(executor.outFields);
-executor.logger.info("End Execution AAIServiceCreateTask.js");
-
-/* Utility functions Begin */
-
-function httpGet(theUrl) {
- var con = new java.net.URL(theUrl).openConnection();
- con.requestMethod = "GET";
- return asResponse(con);
-}
-
-function httpPost(theUrl, data, contentType) {
- contentType = contentType || "application/json";
- var con = new java.net.URL(theUrl).openConnection();
- con.requestMethod = "POST";
- con.setRequestProperty("Content-Type", contentType);
- con.doOutput = true;
- write(con.outputStream, data);
- return asResponse(con);
-}
-
-function httpPut(theUrl, data, contentType) {
- contentType = contentType || "application/json";
- var con = new java.net.URL(theUrl).openConnection();
- con.requestMethod = "PUT";
- con.setRequestProperty("Content-Type", contentType);
- con.doOutput = true;
- write(con.outputStream, data);
- return asResponse(con);
-}
-
-function asResponse(con) {
- var d = read(con.inputStream);
- return {
- data: d,
- statusCode: con.resultCode
- };
-}
-
-function write(outputStream, data) {
- var wr = new java.io.DataOutputStream(outputStream);
- wr.writeBytes(data);
- wr.flush();
- wr.close();
-}
-
-function read(inputStream) {
- var inReader = new java.io.BufferedReader(new java.io.InputStreamReader(
- inputStream));
- var inputLine;
- var result = new java.lang.StringBuffer();
-
- while ((inputLine = inReader.readLine()) != null) {
- result.append(inputLine);
- }
- inReader.close();
- return result.toString();
-}
-
-/* Utility functions End */ \ No newline at end of file
+executor.logger.info("End Execution AAIServiceCreateTask.js"); \ No newline at end of file
diff --git a/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js b/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js
index 7ba674553..946d956b1 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js
@@ -21,7 +21,5 @@ executor.logger.info("Begin Execution ErrorResourceUpdateLogTask.js");
executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);
-executor.logger.info(executor.outFields);
-
var returnValue = executor.isTrue;
executor.logger.info("End Execution ErrorResourceUpdateLogTask.js");
diff --git a/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js b/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js
index 6e609b1cc..810903a28 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js
@@ -28,9 +28,6 @@ var attachmentPoint = executor.inFields.get("attachmentPoint");
var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get(
attachmentPoint);
-executor.logger.info(executor.outFields);
-executor.logger.info(executor.inFields);
-
result = NomadicONTContext.get("result");
if (result === "SUCCESS") {
diff --git a/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js b/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js
index 214a76fe8..3abd75071 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js
@@ -28,7 +28,6 @@ var attachmentPoint = executor.inFields.get("attachmentPoint");
var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get(
attachmentPoint);
-executor.logger.info(executor.outFields);
executor.logger.info(executor.inFields);
result = NomadicONTContext.get("result");
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 033d778be..60d4efed9 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js
@@ -26,7 +26,6 @@ importClass(java.nio.file.Paths);
importPackage(org.json.XML);
-
executor.logger.info("Begin Execution SdncResourceUpdateTask.js");
executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);
@@ -36,7 +35,8 @@ var requestID = executor.inFields.get("requestID");
var serviceInstanceId = executor.inFields.get("serviceInstanceId");
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);
@@ -45,39 +45,39 @@ executor.logger.info(NomadicONTContext);
var jsonObj;
var aaiUpdateResult = true;
var SDNC_URL = "localhost:8080";
-var HTTP_PROTOCOL ="https://"
+var HTTP_PROTOCOL = "http://"
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"));
- // read line by line
var line;
while ((line = br.readLine()) != null) {
if (line.startsWith("SDNC_URL")) {
var str = line.split("=");
SDNC_URL = str[str.length - 1];
- break;
} else if (line.startsWith("SVC_NOTIFICATION_URL")) {
var str = line.split("=");
SVC_NOTIFICATION_URL = str[str.length - 1];
- break;
+ }
+ else if (line.startsWith("SDNC_USERNAME")) {
+ var str = line.split("=");
+ SDNC_USERNAME = str[str.length - 1];
+ } else if (line.startsWith("SDNC_PASSWORD")) {
+ var str = line.split("=");
+ SDNC_PASSWORD = str[str.length - 1];
}
}
} catch (err) {
executor.logger.info("Failed to retrieve data " + err);
}
executor.logger.info("SDNC_URL " + SDNC_URL);
-executor.logger.info("input param " + JSON.stringify(input_param,
- null, 4));
var result;
var jsonObj;
var sdncUpdateResult = true;
-
-
/* BBS Policy calls SDN-C GR-API to delete AccessConnectivity VF ID */
/* Prepare Data*/
var xmlDeleteAccess = "";
@@ -85,7 +85,6 @@ try {
var br = Files.newBufferedReader(Paths.get(
"/home/apexuser/examples/config/ONAPBBS/sdnc_DeleteAccessConnectivityInstance.txt"
));
- // read line by line
var line;
while ((line = br.readLine()) != null) {
xmlDeleteAccess += line;
@@ -140,16 +139,14 @@ xmlDeleteAccess = xmlDeleteAccess.replace("vendor_value", input_param['service']
xmlDeleteAccess = xmlDeleteAccess.replace("service_id_value", getMetaValue(
putUpddateServInstance['metadata']['metadatum'],
'controller-service-id'));
-executor.logger.info("Delete Access Prfile " + xmlDeleteAccess);
+executor.logger.info(client.toPrettyString(xmlDeleteAccess, 4));
try {
var urlPost1 = HTTP_PROTOCOL + SDNC_URL +
"/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation";
- result = httpDelete(urlPost1, xmlDeleteAccess, "application/xml").data;
- executor.logger.info("Data received From " + urlPost1 + " " + result.toString());
- jsonObj = JSON.parse(result);
- executor.logger.info("After Parse " + jsonObj.toString());
-
+ result = client.httpRequest(urlPost1, "POST", xmlDeleteAccess, SDNC_USERNAME, SDNC_PASSWORD,
+ "application/xml", true, true);
+ executor.logger.info("Data received From " + urlPost1 + " " + result);
if (result == "") {
sdncUpdateResult = false;
}
@@ -158,7 +155,6 @@ try {
sdncUpdateResult = false;
}
-
/* BBS Policy calls SDN-C GR-API to create new AccessConnectivity VF */
/* Prepare Data*/
@@ -167,7 +163,6 @@ try {
var br = Files.newBufferedReader(Paths.get(
"/home/apexuser/examples/config/ONAPBBS/sdnc_CreateAccessConnectivityInstance.txt"
));
- // read line by line
var line;
while ((line = br.readLine()) != null) {
xmlCreateAccess += line;
@@ -190,7 +185,6 @@ xmlCreateAccess = xmlCreateAccess.replace("customer_id_value", input_param[
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'
@@ -226,18 +220,17 @@ xmlCreateAccess = xmlCreateAccess.replace("c_vlan_value", getMetaValue(
putUpddateServInstance['metadata']['metadatum'], 'cvlan'));
xmlCreateAccess = xmlCreateAccess.replace("access_id_value", getMetaValue(
putUpddateServInstance['metadata']['metadatum'], 'remote-id'));
-executor.logger.info("Create Access Prfile " + xmlCreateAccess);
+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 = httpPost(urlPost2, xmlCreateAccess, "application/xml").data;
- executor.logger.info("Data received From " + urlPost2 + " " + result.toString());
- jsonObj = JSON.parse(result);
- executor.logger.info("After Parse " + jsonObj.toString());
-
+ result = client.httpRequest(urlPost2, "POST", xmlCreateAccess, SDNC_USERNAME, SDNC_PASSWORD,
+ "application/xml", true, true);
+ executor.logger.info("Data received From " + urlPost2 + " " + result);
if (result == "") {
- sdncUpdateResult = false;
+ sdncUpdateResult = false;
}
}
} catch (err) {
@@ -245,15 +238,12 @@ try {
sdncUpdateResult = false;
}
-
-
/* 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"
));
- // read line by line
var line;
while ((line = br.readLine()) != null) {
xmlChangeProfile += line;
@@ -304,7 +294,6 @@ xmlCreateAccess = xmlCreateAccess.replace("network_info_model_uuid_value",
xmlCreateAccess = xmlCreateAccess.replace("network_info_model_name_value",
"EdgeInternetProfile");
-
xmlChangeProfile = xmlChangeProfile.replace("vendor_value", input_param[
'service']['parameters']['requestInputs']['ont_ont_manufacturer']);
xmlChangeProfile = xmlChangeProfile.replace("service_id_value", getMetaValue(
@@ -326,16 +315,15 @@ xmlChangeProfile = xmlChangeProfile.replace("s_vlan_value", getMetaValue(
putUpddateServInstance['metadata']['metadatum'], 'svlan'));
xmlChangeProfile = xmlChangeProfile.replace("c_vlan_value", getMetaValue(
putUpddateServInstance['metadata']['metadatum'], 'cvlan'));
-executor.logger.info("Change Internet Profile " + xmlChangeProfile);
+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";
- result = httpPost(urlPost3, xmlChangeProfile, "application/xml").data;
- executor.logger.info("Data received From " + urlPost3 + " " + result.toString());
- jsonObj = JSON.parse(result);
- executor.logger.info("After Parse " + jsonObj.toString());
-
+ 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);
+ executor.logger.info("Data received From " + urlPost3 + " " + result);
if (result == "") {
sdncUpdateResult = false;
}
@@ -345,16 +333,16 @@ try {
sdncUpdateResult = false;
}
-
/* If Success then Fill output schema */
if (sdncUpdateResult === true) {
NomadicONTContext.put("result", "SUCCESS");
+ executor.outFields.put("result", "SUCCESS");
} else {
NomadicONTContext.put("result", "FAILURE");
+ executor.outFields.put("result", "FAILURE");
}
-
executor.outFields.put("requestID", requestID);
executor.outFields.put("attachmentPoint", attachmentPoint);
executor.outFields.put("serviceInstanceId", executor.inFields.get(
@@ -364,7 +352,6 @@ var returnValue = executor.isTrue;
executor.logger.info(executor.outFields);
executor.logger.info("End Execution SdncResourceUpdateTask.js");
-
function getMetaValue(metaJson, metaname) {
for (var i = 0; i < metaJson.length; i++) {
if (metaJson[i]['metaname'] == metaname) {
@@ -406,67 +393,12 @@ function getResourceCustomizationUuid(resJson, resourceName) {
}
/* Utility functions Begin */
-function httpGet(theUrl) {
- var con = new java.net.URL(theUrl).openConnection();
- con.requestMethod = "GET";
- return asresult(con);
-}
-
-function httpPost(theUrl, data, contentType) {
- contentType = contentType || "application/json";
- var con = new java.net.URL(theUrl).openConnection();
- con.requestMethod = "POST";
- con.setRequestProperty("Content-Type", contentType);
- con.doOutput = true;
- write(con.outputStream, data);
- return asresult(con);
-}
-
-function httpDelete(theUrl, data, contentType) {
- contentType = contentType || "application/json";
- var con = new java.net.URL(theUrl).openConnection();
- con.requestMethod = "DELETE";
- con.setRequestProperty("Content-Type", contentType);
- con.doOutput = true;
- write(con.outputStream, data);
- return asresult(con);
-}
-
-function httpPut(theUrl, data, contentType) {
- contentType = contentType || "application/json";
- var con = new java.net.URL(theUrl).openConnection();
- con.requestMethod = "PUT";
- con.setRequestProperty("Content-Type", contentType);
- con.doOutput = true;
- write(con.outputStream, data);
- return asresult(con);
-}
-
-function asresult(con) {
- var d = read(con.inputStream);
- return {
- data: d,
- statusCode: con.resultCode
- };
-}
-
-function write(outputStream, data) {
- var wr = new java.io.DataOutputStream(outputStream);
- wr.writeBytes(data);
- wr.flush();
- wr.close();
-}
-
-function read(inputStream) {
- var inReader = new java.io.BufferedReader(new java.io.InputStreamReader(
- inputStream));
- var inputLine;
- var result = new java.lang.StringBuffer();
-
- while ((inputLine = inReader.readLine()) != null) {
- result.append(inputLine);
- }
- inReader.close();
- return result.toString();
+function IsValidJSONString(str) {
+ try {
+ JSON.parse(str);
+ } catch (e) {
+ return false;
}
- /* Utility functions End */ \ No newline at end of file
+ return true;
+}
+/* Utility functions End */ \ No newline at end of file
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 62c280531..86e4dfe1c 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js
@@ -37,6 +37,8 @@ var requestID = clEvent.getRequestId();
var jsonObj;
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";
@@ -50,15 +52,19 @@ var service_instance;
try {
var br = Files.newBufferedReader(Paths.get(
"/home/apexuser/examples/config/ONAPBBS/config.txt"));
- // read line by line
var line;
while ((line = br.readLine()) != null) {
if (line.startsWith("AAI_URL")) {
var str = line.split("=");
AAI_URL = str[str.length - 1];
- break;
+ } else if (line.startsWith("AAI_USERNAME")) {
+ var str = line.split("=");
+ AAI_USERNAME = str[str.length - 1];
+ } else if (line.startsWith("AAI_PASSWORD")) {
+ var str = line.split("=");
+ AAI_PASSWORD = str[str.length - 1];
+ }
}
- }
} catch (err) {
executor.logger.info("Failed to retrieve data " + err);
}
@@ -73,7 +79,7 @@ try {
executor.logger.info("Query url" + urlGet);
result = httpGet(urlGet).data;
- executor.logger.info("Data received From " + urlGet + " " + result.toString());
+ executor.logger.info("Data received From " + urlGet + " " + result);
jsonObj = JSON.parse(result);
@@ -102,13 +108,11 @@ try {
putUpddateServInstance, null, 4));
var urlPut = HTTP_PROTOCOL + AAI_URL +
putUrl + "?resource_version=" + resource_version;
- result = httpPut(urlPut, JSON.stringify(putUpddateServInstance)).data;
- executor.logger.info("Data received From " + urlPut + " " + result.toString());
- jsonObj = JSON.parse(result);
- executor.logger.info("After Parse " + JSON.stringify(jsonObj, null, 4));
-
+ result = client.httpsRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD,
+ "application/json", true, true);
+ executor.logger.info("Data received From " + urlPut + " " + result);
/* If failure to retrieve data proceed to Failure */
- if (result == "") {
+ if (result != "") {
aaiUpdateResult = false;
}
}
diff --git a/examples/examples-onap-bbs/src/main/resources/policy/NomadicONTPolicyModel.apex b/examples/examples-onap-bbs/src/main/resources/policy/NomadicONTPolicyModel.apex
index 108459eca..242eed478 100644
--- a/examples/examples-onap-bbs/src/main/resources/policy/NomadicONTPolicyModel.apex
+++ b/examples/examples-onap-bbs/src/main/resources/policy/NomadicONTPolicyModel.apex
@@ -49,11 +49,13 @@ event parameter create name=AAI_SERVICE_ASSIGNED parName=attachmentPoint sch
event parameter create name=AAI_SERVICE_ASSIGNED parName=serviceInstanceId schemaName=SimpleStringType optional=true
event create name=SDNC_RESOURCE_UPDATE version=1.0.0 nameSpace=org.onap.policy.apex.onap.bbs source=APEX target=APEX
+event parameter create name=SDNC_RESOURCE_UPDATE parName=result schemaName=SimpleStringType
event parameter create name=SDNC_RESOURCE_UPDATE parName=requestID schemaName=UUIDType
event parameter create name=SDNC_RESOURCE_UPDATE parName=attachmentPoint schemaName=SimpleStringType
event parameter create name=SDNC_RESOURCE_UPDATE parName=serviceInstanceId schemaName=SimpleStringType optional=true
event create name=AAI_SERVICE_CREATE version=1.0.0 nameSpace=org.onap.policy.apex.onap.bbs source=APEX target=APEX
+event parameter create name=AAI_SERVICE_CREATE parName=result schemaName=SimpleStringType
event parameter create name=AAI_SERVICE_CREATE parName=requestID schemaName=UUIDType
event parameter create name=AAI_SERVICE_CREATE parName=attachmentPoint schemaName=SimpleStringType
event parameter create name=AAI_SERVICE_CREATE parName=serviceInstanceId schemaName=SimpleStringType optional=true
@@ -106,6 +108,7 @@ task inputfield create name=AAIServiceAssignedTask fieldName=serviceInstanceId
task outputfield create name=AAIServiceAssignedTask fieldName=requestID schemaName=UUIDType
task outputfield create name=AAIServiceAssignedTask fieldName=attachmentPoint schemaName=SimpleStringType
task outputfield create name=AAIServiceAssignedTask fieldName=serviceInstanceId schemaName=SimpleStringType optional=true
+task outputfield create name=AAIServiceAssignedTask fieldName=result schemaName=SimpleStringType
task contextref create name=AAIServiceAssignedTask albumName=NomadicONTContextAlbum
@@ -133,6 +136,7 @@ task inputfield create name=SdncResourceUpdateTask fieldName=serviceInstanceId
task outputfield create name=SdncResourceUpdateTask fieldName=requestID schemaName=UUIDType
task outputfield create name=SdncResourceUpdateTask fieldName=attachmentPoint schemaName=SimpleStringType
task outputfield create name=SdncResourceUpdateTask fieldName=serviceInstanceId schemaName=SimpleStringType optional=true
+task outputfield create name=SdncResourceUpdateTask fieldName=result schemaName=SimpleStringType
task contextref create name=SdncResourceUpdateTask albumName=NomadicONTContextAlbum
task logic create name=SdncResourceUpdateTask logicFlavour=JAVASCRIPT logic=LS
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
new file mode 100644
index 000000000..b447803ef
--- /dev/null
+++ b/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 huawei. All rights reserved.
+ * ================================================================================
+ * 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
+ *
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.examples.bbs;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import javax.net.ssl.HttpsURLConnection;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class WebClientTest {
+ HttpsURLConnection mockedHttpsURLConnection;
+ String sampleString = "Response Code :200";
+ /**
+ * Set up the mocked REST manager.
+ */
+ @Before
+ public void setupMockedRest() {
+ mockedHttpsURLConnection = mock(HttpsURLConnection.class);
+ InputStream iStream = new ByteArrayInputStream(sampleString.getBytes());
+ try {
+ when(mockedHttpsURLConnection.getInputStream()).thenReturn(iStream);
+ Mockito.doNothing().when(mockedHttpsURLConnection).connect();
+ }catch (Exception e) {
+ }
+
+ }
+
+ @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);
+
+ }
+
+ @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);
+
+ }
+
+ @Test
+ public void toPrettyString() {
+ String xmlSample = "<input xmlns=\"org:onap:sdnc:northbound:generic-resource\">" +
+ "<sdnc-request-header> <svc-action>update</svc-action> </sdnc-request-header></input>";
+ WebClient cl = new WebClient();
+ cl.toPrettyString(xmlSample, 4);
+ }
+}