From 7dbb6441c95aa5691a59dc918f864b4bf4e2e2ed Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Tue, 18 Jul 2017 20:35:53 -0400 Subject: [CCSDK-6] Populate seed code Add seed code for sli/plugins repository Changed groupId to org.onap.ccsdk.sli.plugins Updated to compile against CCSDK version of SLI Change-Id: Ib392530ea79b8544087692964bd65179896aa595 Signed-off-by: Dan Timoney --- .../provider/src/test/resources/test.json | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 restapi-call-node/provider/src/test/resources/test.json (limited to 'restapi-call-node/provider/src/test/resources/test.json') diff --git a/restapi-call-node/provider/src/test/resources/test.json b/restapi-call-node/provider/src/test/resources/test.json new file mode 100644 index 000000000..885e66028 --- /dev/null +++ b/restapi-call-node/provider/src/test/resources/test.json @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + */ + +{ + "equipment-data": [ + { + "server-count": "4", + "max-server-speed": "1600000", + "number-primary-servers": "2", + "equipment-id": "Server1", + "server-model": "Unknown", + "server-id": "Server1" + } + ], + "resource-state": { + "threshold-value": "1600000", + "last-added": "1605000", + "used": "1605000", + "limit-value": "1920000" + }, + "resource-rule": { + "endpoint-position": "VCE-Cust", + "soft-limit-expression": "0.6 * max-server-speed * number-primary-servers", + "resource-name": "Bandwidth", + "service-model": "DUMMY", + "hard-limit-expression": "max-server-speed * number-primary-servers", + "equipment-level": "Server" + }, + "message": "The provisioned access bandwidth is at or exceeds 50% of the total server capacity." +} -- cgit 1.2.3-korg From 9042880234791fbe2e0ef033091ba93cb7f088f5 Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Wed, 23 Aug 2017 11:47:08 -0700 Subject: Conform ccsdk/sli/plugins to ONAP Style Per ONAP Style Guide: 1. Convert tabs to 4 spaces. 2. Break lines to be less than 120 characters 3. Clean ecomp references 4. Remove extraneous spaces Issue-Id: CCSDK-1 Change-Id: I5638326170aa3ab26774b373ab573643840e97ab Signed-off-by: Marcus G K Williams --- README.md | 4 +- pom.xml | 226 ++-- properties-node/features/pom.xml | 238 ++-- .../features/src/main/resources/features.xml | 22 +- properties-node/installer/pom.xml | 254 ++-- .../src/assembly/assemble_installer_zip.xml | 58 +- .../src/assembly/assemble_mvnrepo_zip.xml | 38 +- .../src/main/resources/scripts/install-feature.sh | 6 +- properties-node/pom.xml | 68 +- properties-node/provider/pom.xml | 152 +-- .../ccsdk/sli/plugins/prop/PropertiesNode.java | 100 +- .../META-INF/spring/properties-node-context.xml | 4 +- .../spring/properties-node-osgi-context.xml | 8 +- restapi-call-node/pom.xml | 66 +- restapi-call-node/provider/pom.xml | 176 +-- .../ccsdk/sli/plugins/restapicall/JsonParser.java | 96 +- .../sli/plugins/restapicall/RestapiCallNode.java | 1297 ++++++++++---------- .../ccsdk/sli/plugins/restapicall/RetryPolicy.java | 3 +- .../ccsdk/sli/plugins/restapicall/XmlJsonUtil.java | 676 +++++----- .../ccsdk/sli/plugins/restapicall/XmlParser.java | 236 ++-- .../META-INF/spring/restapi-call-node-context.xml | 30 +- .../spring/restapi-call-node-osgi-context.xml | 8 +- .../src/main/resources/default-ueb-message.json | 12 +- .../main/resources/northbound-api-template.json | 42 +- .../src/main/resources/northbound-api-template.xml | 2 +- .../sli/plugins/restapicall/TestJsonParser.java | 44 +- .../plugins/restapicall/TestRestapiCallNode.java | 100 +- .../sli/plugins/restapicall/TestXmlJsonUtil.java | 115 +- .../sli/plugins/restapicall/TestXmlParser.java | 58 +- .../provider/src/test/resources/test.json | 50 +- .../provider/src/test/resources/test.xml | 280 ++--- .../provider/src/test/resources/test3.xml | 116 +- 32 files changed, 2316 insertions(+), 2269 deletions(-) (limited to 'restapi-call-node/provider/src/test/resources/test.json') diff --git a/README.md b/README.md index 4e733caff..3ad2eae11 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -This source repository contains the code for the SDN Controller plugins. +This source repository contains the code for the CCSDK plugins. To compile this code: -1. Make sure your local Maven settings file ($HOME/.m2/settings.xml) contains references to the OpenECOMP repositories and OpenDaylight repositories. See example-settings.xml for an example. +1. Make sure your local Maven settings file ($HOME/.m2/settings.xml) contains references to the ONAP repositories and OpenDaylight repositories. See example-settings.xml for an example. 2. To compile, run "mvn clean install". diff --git a/pom.xml b/pom.xml index 4af5fb508..71303b796 100755 --- a/pom.xml +++ b/pom.xml @@ -1,118 +1,118 @@ - - - org.onap.ccsdk.parent - odlparent-carbon-sr1 - 0.0.1-SNAPSHOT - - - 4.0.0 - pom - org.onap.ccsdk.sli.plugins - sdnc-plugins - - SDN-C Java Plugins - https://wiki.onap.org - The SDN-C core components contains the SLI, dblib and root pom - - - - JIRA - https://jira.onap.org/ - - - - - scm:git:ssh://git@${onap.git.host}/ccsdk/sli/plugins.git - scm:git:ssh://${onap.git.host}:${onap.git.port}/${onap.git.project}/ccsdk/sli/plugins.git - ${onap.git.protocol}://${onap.git.host}/projects/${onap.git.project}/repos/ccsdk/sli/plugins/browse - HEAD - - - - Jenkins - https://jenkins.onap.org - - - - - - sdnc-javadoc - dav:https://${onap.nexus.host}/content/sites/site/org/onap/sdnc/plugins/${project.artifactId}/${project.version} - - - - - - blackduck - - - blackduck-scan - - - - - - com.blackducksoftware.integration - hub-maven-plugin - 1.4.0 - false - - ${project.name} - ${project.basedir} - - - - create-bdio-file - package - - createHubOutput - - - - - - - - - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.17 - - true - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - https://${onap.nexus.host} - ${onap.nexus.staging.profile-id} - ${onap.nexus.staging.server-id} - - - - - - - properties-node - restapi-call-node - - - AT&T - - 0.1.0-SNAPSHOT + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + + org.onap.ccsdk.parent + odlparent-carbon-sr1 + 0.0.1-SNAPSHOT + + + 4.0.0 + pom + org.onap.ccsdk.sli.plugins + sdnc-plugins + + SDN-C Java Plugins + https://wiki.onap.org + The SDN-C core components contains the SLI, dblib and root pom + + + + JIRA + https://jira.onap.org/ + + + + + scm:git:ssh://git@${onap.git.host}/ccsdk/sli/plugins.git + scm:git:ssh://${onap.git.host}:${onap.git.port}/${onap.git.project}/ccsdk/sli/plugins.git + ${onap.git.protocol}://${onap.git.host}/projects/${onap.git.project}/repos/ccsdk/sli/plugins/browse + HEAD + + + + Jenkins + https://jenkins.onap.org + + + + + + sdnc-javadoc + dav:https://${onap.nexus.host}/content/sites/site/org/onap/sdnc/plugins/${project.artifactId}/${project.version} + + + + + + blackduck + + + blackduck-scan + + + + + + com.blackducksoftware.integration + hub-maven-plugin + 1.4.0 + false + + ${project.name} + ${project.basedir} + + + + create-bdio-file + package + + createHubOutput + + + + + + + + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.17 + + true + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + https://${onap.nexus.host} + ${onap.nexus.staging.profile-id} + ${onap.nexus.staging.server-id} + + + + + + + properties-node + restapi-call-node + + + AT&T + + 0.1.0-SNAPSHOT diff --git a/properties-node/features/pom.xml b/properties-node/features/pom.xml index d23d9979c..5573d1e7a 100755 --- a/properties-node/features/pom.xml +++ b/properties-node/features/pom.xml @@ -1,135 +1,135 @@ - 4.0.0 - - properties-node - org.onap.ccsdk.sli.plugins - 0.1.0-SNAPSHOT - - org.onap.ccsdk.sli.plugins - 0.1.0-SNAPSHOT - properties-node-features - Properties Node - Features + 4.0.0 + + properties-node + org.onap.ccsdk.sli.plugins + 0.1.0-SNAPSHOT + + org.onap.ccsdk.sli.plugins + 0.1.0-SNAPSHOT + properties-node-features + Properties Node - Features - jar + jar - + - - org.onap.ccsdk.sli.plugins - properties-node-provider - ${project.version} - + + org.onap.ccsdk.sli.plugins + properties-node-provider + ${project.version} + - - commons-lang - commons-lang - 2.6 - compile - + + commons-lang + commons-lang + 2.6 + compile + - - org.opendaylight.mdsal - features-mdsal - ${odl.mdsal.features.version} - features - xml + + org.opendaylight.mdsal + features-mdsal + ${odl.mdsal.features.version} + features + xml - runtime - + runtime + - - - org.opendaylight.controller - opendaylight-karaf-empty - ${odl.karaf.empty.distro.version} - zip - + + + org.opendaylight.controller + opendaylight-karaf-empty + ${odl.karaf.empty.distro.version} + zip + - - - org.opendaylight.odlparent - features-test - ${odl.commons.opendaylight.version} - test - + + + org.opendaylight.odlparent + features-test + ${odl.commons.opendaylight.version} + test + - - org.opendaylight.yangtools - features-yangtools - ${odl.yangtools.version} - features - xml - runtime - - + + org.opendaylight.yangtools + features-yangtools + ${odl.yangtools.version} + features + xml + runtime + + - - - - true - src/main/resources - - - - - org.apache.maven.plugins - maven-resources-plugin - - - filter - - resources - - generate-resources - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - attach-artifacts - - attach-artifact - - package - - - - ${project.build.directory}/classes/${features.file} - xml - features - - - - - - - - + org.apache.maven.plugins + maven-surefire-plugin + 2.16 + + + org.opendaylight.controller + opendaylight-karaf-empty + ${odl.karaf.empty.distro.version} + + + org.opendaylight.yangtools:features-test + + + + --> + + org.codehaus.mojo + build-helper-maven-plugin + + + attach-artifacts + + attach-artifact + + package + + + + ${project.build.directory}/classes/${features.file} + xml + features + + + + + + + + diff --git a/properties-node/features/src/main/resources/features.xml b/properties-node/features/src/main/resources/features.xml index 5f0d7b55d..96f37a9e0 100644 --- a/properties-node/features/src/main/resources/features.xml +++ b/properties-node/features/src/main/resources/features.xml @@ -22,18 +22,18 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0"> - mvn:org.opendaylight.mdsal/features-mdsal/${odl.mdsal.features.version}/xml/features + mvn:org.opendaylight.mdsal/features-mdsal/${odl.mdsal.features.version}/xml/features - - sdnc-sli - spring - spring-dm - mvn:org.onap.ccsdk.sli.plugins/properties-node-provider/${project.version} - - + + sdnc-sli + spring + spring-dm + mvn:org.onap.ccsdk.sli.plugins/properties-node-provider/${project.version} + + diff --git a/properties-node/installer/pom.xml b/properties-node/installer/pom.xml index 7e6ae1740..570eced79 100755 --- a/properties-node/installer/pom.xml +++ b/properties-node/installer/pom.xml @@ -1,139 +1,139 @@ - 4.0.0 - - properties-node - org.onap.ccsdk.sli.plugins - 0.1.0-SNAPSHOT - - properties-node-installer - Properties node - Karaf Installer - pom + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + properties-node + org.onap.ccsdk.sli.plugins + 0.1.0-SNAPSHOT + + properties-node-installer + Properties node - Karaf Installer + pom - - sdnc-properties-node - sdnc-properties-node - mvn:org.onap.ccsdk.sli.plugins/properties-node-features/${project.version}/xml/features - false - + + sdnc-properties-node + sdnc-properties-node + mvn:org.onap.ccsdk.sli.plugins/properties-node-features/${project.version}/xml/features + false + - + - - org.onap.ccsdk.sli.plugins - properties-node-features - ${project.version} - features - xml - - - * - * - - - + + org.onap.ccsdk.sli.plugins + properties-node-features + ${project.version} + features + xml + + + * + * + + + - - org.onap.ccsdk.sli.plugins - properties-node-provider - ${project.version} - + + org.onap.ccsdk.sli.plugins + properties-node-provider + ${project.version} + - + - - - - maven-assembly-plugin - 2.6 - - - maven-repo-zip - - single - - package - - false - stage/${application.name}-${project.version} - - src/assembly/assemble_mvnrepo_zip.xml - - false - - - - installer-zip - - single - - package - - true - ${application.name}-${project.version}-installer - - src/assembly/assemble_installer_zip.xml - - false - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-dependencies - - copy-dependencies - - prepare-package - - false - ${project.build.directory}/assembly/system - false - true - true - true - false - false - org.onap.ccsdk.sli - sli-common,sli-provider,dblib-provider - provided - - - - - - maven-resources-plugin - 2.6 - - - copy-version - - copy-resources - - validate - - ${basedir}/target/stage - - - src/main/resources/scripts - - install-feature.sh - - true - - - - + + + + maven-assembly-plugin + 2.6 + + + maven-repo-zip + + single + + package + + false + stage/${application.name}-${project.version} + + src/assembly/assemble_mvnrepo_zip.xml + + false + + + + installer-zip + + single + + package + + true + ${application.name}-${project.version}-installer + + src/assembly/assemble_installer_zip.xml + + false + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + + copy-dependencies + + prepare-package + + false + ${project.build.directory}/assembly/system + false + true + true + true + false + false + org.onap.ccsdk.sli + sli-common,sli-provider,dblib-provider + provided + + + + + + maven-resources-plugin + 2.6 + + + copy-version + + copy-resources + + validate + + ${basedir}/target/stage + + + src/main/resources/scripts + + install-feature.sh + + true + + + + - - + + - - + + diff --git a/properties-node/installer/src/assembly/assemble_installer_zip.xml b/properties-node/installer/src/assembly/assemble_installer_zip.xml index 3bed4b5ef..b6fd65582 100644 --- a/properties-node/installer/src/assembly/assemble_installer_zip.xml +++ b/properties-node/installer/src/assembly/assemble_installer_zip.xml @@ -22,37 +22,37 @@ - installer_zip - - zip - + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> + installer_zip + + zip + - - false + + false - - - target/stage/ - ${application.name} - 755 - - *.sh - - - - target/stage/ - ${application.name} - 644 - - *.sh - - - + + + target/stage/ + ${application.name} + 755 + + *.sh + + + + target/stage/ + ${application.name} + 644 + + *.sh + + + diff --git a/properties-node/installer/src/assembly/assemble_mvnrepo_zip.xml b/properties-node/installer/src/assembly/assemble_mvnrepo_zip.xml index cb56f2cd4..2ee224477 100644 --- a/properties-node/installer/src/assembly/assemble_mvnrepo_zip.xml +++ b/properties-node/installer/src/assembly/assemble_mvnrepo_zip.xml @@ -22,27 +22,27 @@ - mvnrepo_zip - - zip - + xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd"> + mvnrepo_zip + + zip + - - false + + false - - - target/assembly/ - . - - - - + + + target/assembly/ + . + + + + diff --git a/properties-node/installer/src/main/resources/scripts/install-feature.sh b/properties-node/installer/src/main/resources/scripts/install-feature.sh index e986764b9..df03392c8 100644 --- a/properties-node/installer/src/main/resources/scripts/install-feature.sh +++ b/properties-node/installer/src/main/resources/scripts/install-feature.sh @@ -30,10 +30,10 @@ REPOZIP=${INSTALLERDIR}/${features.boot}-${project.version}.zip if [ -f ${REPOZIP} ] then - unzip -d ${ODL_HOME} ${REPOZIP} + unzip -d ${ODL_HOME} ${REPOZIP} else - echo "ERROR : repo zip ($REPOZIP) not found" - exit 1 + echo "ERROR : repo zip ($REPOZIP) not found" + exit 1 fi ${ODL_KARAF_CLIENT} ${ODL_KARAF_CLIENT_OPTS} feature:repo-add ${features.repositories} diff --git a/properties-node/pom.xml b/properties-node/pom.xml index 44d89f924..066db5e08 100755 --- a/properties-node/pom.xml +++ b/properties-node/pom.xml @@ -1,43 +1,43 @@ - - org.onap.ccsdk.sli.plugins - sdnc-plugins - 0.1.0-SNAPSHOT - + + org.onap.ccsdk.sli.plugins + sdnc-plugins + 0.1.0-SNAPSHOT + - 4.0.0 - pom + 4.0.0 + pom - org.onap.ccsdk.sli.plugins - properties-node - 0.1.0-SNAPSHOT + org.onap.ccsdk.sli.plugins + properties-node + 0.1.0-SNAPSHOT - Properties Node - This is an implementation of DG Execute Node that reads property file and - puts the properties in the DG context + Properties Node + This is an implementation of DG Execute Node that reads property file and + puts the properties in the DG context - - - - org.onap.ccsdk.sli.plugins - properties-node-features - features - xml - ${project.version} - - - org.onap.ccsdk.sli.plugins - properties-node-provider - ${project.version} - - - + + + + org.onap.ccsdk.sli.plugins + properties-node-features + features + xml + ${project.version} + + + org.onap.ccsdk.sli.plugins + properties-node-provider + ${project.version} + + + - - provider - features - installer - + + provider + features + installer + diff --git a/properties-node/provider/pom.xml b/properties-node/provider/pom.xml index 1c5eff74c..a5249d98b 100755 --- a/properties-node/provider/pom.xml +++ b/properties-node/provider/pom.xml @@ -1,89 +1,89 @@ - 4.0.0 - - org.onap.ccsdk.sli.plugins - properties-node - 0.1.0-SNAPSHOT - - org.onap.ccsdk.sli.plugins - 0.1.0-SNAPSHOT - properties-node-provider - bundle - Properties Node - Provider - http://maven.apache.org - - UTF-8 - - - - junit - junit - test - - - org.springframework - spring-test - ${spring.version} - test - - - org.onap.ccsdk.sli.core - sli-common - ${sdnctl.sli.version} - compile - - - org.onap.ccsdk.sli.core - sli-provider - ${sdnctl.sli.version} - compile - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.slf4j - jcl-over-slf4j - ${slf4j.version} - - - org.springframework - spring-beans - ${spring.version} - - - org.springframework - spring-context - ${spring.version} - - + 4.0.0 + + org.onap.ccsdk.sli.plugins + properties-node + 0.1.0-SNAPSHOT + + org.onap.ccsdk.sli.plugins + 0.1.0-SNAPSHOT + properties-node-provider + bundle + Properties Node - Provider + http://maven.apache.org + + UTF-8 + + + + junit + junit + test + + + org.springframework + spring-test + ${spring.version} + test + + + org.onap.ccsdk.sli.core + sli-common + ${sdnctl.sli.version} + compile + + + org.onap.ccsdk.sli.core + sli-provider + ${sdnctl.sli.version} + compile + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + org.springframework + spring-beans + ${spring.version} + + + org.springframework + spring-context + ${spring.version} + + - - + + - - org.apache.felix - maven-bundle-plugin - true - - - org.onap.ccsdk.sli.prop - org.onap.ccsdk.sli.prop - * - + + org.apache.felix + maven-bundle-plugin + true + + + org.onap.ccsdk.sli.prop + org.onap.ccsdk.sli.prop + * + - + - + - + - + diff --git a/properties-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/prop/PropertiesNode.java b/properties-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/prop/PropertiesNode.java index 165b706be..b4886d552 100644 --- a/properties-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/prop/PropertiesNode.java +++ b/properties-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/prop/PropertiesNode.java @@ -35,63 +35,63 @@ import org.slf4j.LoggerFactory; public class PropertiesNode implements SvcLogicJavaPlugin { - private static final Logger log = LoggerFactory.getLogger(PropertiesNode.class); + private static final Logger log = LoggerFactory.getLogger(PropertiesNode.class); - public void readProperties(Map paramMap, SvcLogicContext ctx) throws SvcLogicException { - String fileName = parseParam(paramMap, "fileName", true, null); - String contextPrefix = parseParam(paramMap, "contextPrefix", false, null); + public void readProperties(Map paramMap, SvcLogicContext ctx) throws SvcLogicException { + String fileName = parseParam(paramMap, "fileName", true, null); + String contextPrefix = parseParam(paramMap, "contextPrefix", false, null); - try { - Properties pp = new Properties(); - InputStream in = new FileInputStream(fileName); - pp.load(in); - for (Object key : pp.keySet()) { - String pfx = contextPrefix != null ? contextPrefix + '.' : ""; - String name = (String) key; - String value = pp.getProperty(name); - if (value != null && value.trim().length() > 0) { - ctx.setAttribute(pfx + name, value.trim()); - log.info("+++ " + pfx + name + ": [" + value + "]"); - } - } - } catch (IOException e) { - throw new SvcLogicException("Cannot read property file: " + fileName + ": " + e.getMessage(), e); - } - } + try { + Properties pp = new Properties(); + InputStream in = new FileInputStream(fileName); + pp.load(in); + for (Object key : pp.keySet()) { + String pfx = contextPrefix != null ? contextPrefix + '.' : ""; + String name = (String) key; + String value = pp.getProperty(name); + if (value != null && value.trim().length() > 0) { + ctx.setAttribute(pfx + name, value.trim()); + log.info("+++ " + pfx + name + ": [" + value + "]"); + } + } + } catch (IOException e) { + throw new SvcLogicException("Cannot read property file: " + fileName + ": " + e.getMessage(), e); + } + } - private String parseParam(Map paramMap, String name, boolean required, String def) - throws SvcLogicException { - String s = paramMap.get(name); + private String parseParam(Map paramMap, String name, boolean required, String def) + throws SvcLogicException { + String s = paramMap.get(name); - if (s == null || s.trim().length() == 0) { - if (!required) - return def; - throw new SvcLogicException("Parameter " + name + " is required in PropertiesNode"); - } + if (s == null || s.trim().length() == 0) { + if (!required) + return def; + throw new SvcLogicException("Parameter " + name + " is required in PropertiesNode"); + } - s = s.trim(); - String value = ""; - int i = 0; - int i1 = s.indexOf('%'); - while (i1 >= 0) { - int i2 = s.indexOf('%', i1 + 1); - if (i2 < 0) - throw new SvcLogicException("Cannot parse parameter " + name + ": " + s + ": no matching %"); + s = s.trim(); + String value = ""; + int i = 0; + int i1 = s.indexOf('%'); + while (i1 >= 0) { + int i2 = s.indexOf('%', i1 + 1); + if (i2 < 0) + throw new SvcLogicException("Cannot parse parameter " + name + ": " + s + ": no matching %"); - String varName = s.substring(i1 + 1, i2); - String varValue = System.getenv(varName); - if (varValue == null) - varValue = ""; + String varName = s.substring(i1 + 1, i2); + String varValue = System.getenv(varName); + if (varValue == null) + varValue = ""; - value += s.substring(i, i1); - value += varValue; + value += s.substring(i, i1); + value += varValue; - i = i2 + 1; - i1 = s.indexOf('%', i); - } - value += s.substring(i); + i = i2 + 1; + i1 = s.indexOf('%', i); + } + value += s.substring(i); - log.info("Parameter " + name + ": " + value); - return value; - } + log.info("Parameter " + name + ": " + value); + return value; + } } diff --git a/properties-node/provider/src/main/resources/META-INF/spring/properties-node-context.xml b/properties-node/provider/src/main/resources/META-INF/spring/properties-node-context.xml index fd7ace8a5..52d1cd96a 100644 --- a/properties-node/provider/src/main/resources/META-INF/spring/properties-node-context.xml +++ b/properties-node/provider/src/main/resources/META-INF/spring/properties-node-context.xml @@ -26,7 +26,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - - + + diff --git a/properties-node/provider/src/main/resources/META-INF/spring/properties-node-osgi-context.xml b/properties-node/provider/src/main/resources/META-INF/spring/properties-node-osgi-context.xml index 19275fc9d..a46e37c7b 100644 --- a/properties-node/provider/src/main/resources/META-INF/spring/properties-node-osgi-context.xml +++ b/properties-node/provider/src/main/resources/META-INF/spring/properties-node-osgi-context.xml @@ -21,12 +21,12 @@ --> - + diff --git a/restapi-call-node/pom.xml b/restapi-call-node/pom.xml index e201c2708..7e1886f43 100755 --- a/restapi-call-node/pom.xml +++ b/restapi-call-node/pom.xml @@ -1,42 +1,42 @@ - - org.onap.ccsdk.sli.plugins - sdnc-plugins - 0.1.0-SNAPSHOT - + + org.onap.ccsdk.sli.plugins + sdnc-plugins + 0.1.0-SNAPSHOT + - 4.0.0 - pom + 4.0.0 + pom - org.onap.ccsdk.sli.plugins - restapi-call-node - 0.1.0-SNAPSHOT + org.onap.ccsdk.sli.plugins + restapi-call-node + 0.1.0-SNAPSHOT - RESTAPI Call Node - This is an implementation of DG Execute Node that makes a call to an external REST API + RESTAPI Call Node + This is an implementation of DG Execute Node that makes a call to an external REST API - - - - org.onap.ccsdk.sli.plugins - restapi-call-node-features - features - xml - ${project.version} - - - org.onap.ccsdk.sli.plugins - restapi-call-node-provider - ${project.version} - - - + + + + org.onap.ccsdk.sli.plugins + restapi-call-node-features + features + xml + ${project.version} + + + org.onap.ccsdk.sli.plugins + restapi-call-node-provider + ${project.version} + + + - - provider - features - installer - + + provider + features + installer + diff --git a/restapi-call-node/provider/pom.xml b/restapi-call-node/provider/pom.xml index 0d695bb26..ca3f004a0 100755 --- a/restapi-call-node/provider/pom.xml +++ b/restapi-call-node/provider/pom.xml @@ -1,101 +1,101 @@ - 4.0.0 - - org.onap.ccsdk.sli.plugins - restapi-call-node - 0.1.0-SNAPSHOT - - org.onap.ccsdk.sli.plugins - restapi-call-node-provider - 0.1.0-SNAPSHOT - bundle - RESTAPI Call Node - Provider - http://maven.apache.org - - UTF-8 - - - - junit - junit - test - - - org.springframework - spring-test - ${spring.version} - test - - - org.onap.ccsdk.sli.core - sli-common - ${sdnctl.sli.version} - compile - - - org.onap.ccsdk.sli.core - sli-provider - ${sdnctl.sli.version} - compile - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.slf4j - jcl-over-slf4j - ${slf4j.version} - - - org.springframework - spring-beans - ${spring.version} - - - org.springframework - spring-context - ${spring.version} - - - com.sun.jersey - jersey-client - ${jersey.version} - provided - - - org.codehaus.jettison - jettison - ${jettison.version} - provided - - + 4.0.0 + + org.onap.ccsdk.sli.plugins + restapi-call-node + 0.1.0-SNAPSHOT + + org.onap.ccsdk.sli.plugins + restapi-call-node-provider + 0.1.0-SNAPSHOT + bundle + RESTAPI Call Node - Provider + http://maven.apache.org + + UTF-8 + + + + junit + junit + test + + + org.springframework + spring-test + ${spring.version} + test + + + org.onap.ccsdk.sli.core + sli-common + ${sdnctl.sli.version} + compile + + + org.onap.ccsdk.sli.core + sli-provider + ${sdnctl.sli.version} + compile + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + org.springframework + spring-beans + ${spring.version} + + + org.springframework + spring-context + ${spring.version} + + + com.sun.jersey + jersey-client + ${jersey.version} + provided + + + org.codehaus.jettison + jettison + ${jettison.version} + provided + + - - + + - - org.apache.felix - maven-bundle-plugin - true - - - org.onap.ccsdk.sli.restapicall - org.onap.ccsdk.sli.plugins.restapicall - * - + + org.apache.felix + maven-bundle-plugin + true + + + org.onap.ccsdk.sli.restapicall + org.onap.ccsdk.sli.plugins.restapicall + * + - + - + - + - + diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/JsonParser.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/JsonParser.java index f22aa0b39..4de4a34d7 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/JsonParser.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/JsonParser.java @@ -34,52 +34,52 @@ import org.slf4j.LoggerFactory; public class JsonParser { - private static final Logger log = LoggerFactory.getLogger(JsonParser.class); - - @SuppressWarnings("unchecked") - public static Map convertToProperties(String s) throws JSONException { - JSONObject json = new JSONObject(s); - - Map wm = new HashMap(); - Iterator ii = json.keys(); - while (ii.hasNext()) { - String key1 = ii.next(); - wm.put(key1, json.get(key1)); - } - - Map mm = new HashMap(); - - while (!wm.isEmpty()) - for (String key : new ArrayList<>(wm.keySet())) { - Object o = wm.get(key); - wm.remove(key); - - if (o instanceof Boolean || o instanceof Number || o instanceof String) { - mm.put(key, o.toString()); - - log.info("Added property: " + key + ": " + o.toString()); - } - - else if (o instanceof JSONObject) { - JSONObject jo = (JSONObject) o; - Iterator i = jo.keys(); - while (i.hasNext()) { - String key1 = i.next(); - wm.put(key + "." + key1, jo.get(key1)); - } - } - - else if (o instanceof JSONArray) { - JSONArray ja = (JSONArray) o; - mm.put(key + "_length", String.valueOf(ja.length())); - - log.info("Added property: " + key + "_length" + ": " + String.valueOf(ja.length())); - - for (int i = 0; i < ja.length(); i++) - wm.put(key + '[' + i + ']', ja.get(i)); - } - } - - return mm; - } + private static final Logger log = LoggerFactory.getLogger(JsonParser.class); + + @SuppressWarnings("unchecked") + public static Map convertToProperties(String s) throws JSONException { + JSONObject json = new JSONObject(s); + + Map wm = new HashMap(); + Iterator ii = json.keys(); + while (ii.hasNext()) { + String key1 = ii.next(); + wm.put(key1, json.get(key1)); + } + + Map mm = new HashMap(); + + while (!wm.isEmpty()) + for (String key : new ArrayList<>(wm.keySet())) { + Object o = wm.get(key); + wm.remove(key); + + if (o instanceof Boolean || o instanceof Number || o instanceof String) { + mm.put(key, o.toString()); + + log.info("Added property: " + key + ": " + o.toString()); + } + + else if (o instanceof JSONObject) { + JSONObject jo = (JSONObject) o; + Iterator i = jo.keys(); + while (i.hasNext()) { + String key1 = i.next(); + wm.put(key + "." + key1, jo.get(key1)); + } + } + + else if (o instanceof JSONArray) { + JSONArray ja = (JSONArray) o; + mm.put(key + "_length", String.valueOf(ja.length())); + + log.info("Added property: " + key + "_length" + ": " + String.valueOf(ja.length())); + + for (int i = 0; i < ja.length(); i++) + wm.put(key + '[' + i + ']', ja.get(i)); + } + } + + return mm; + } } diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java index ef3145552..fb7722686 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java @@ -61,25 +61,25 @@ import com.sun.jersey.client.urlconnection.HTTPSProperties; public class RestapiCallNode implements SvcLogicJavaPlugin { - private static final Logger log = LoggerFactory.getLogger(RestapiCallNode.class); + private static final Logger log = LoggerFactory.getLogger(RestapiCallNode.class); - private String uebServers; - private String defaultUebTemplateFileName = "/opt/bvc/restapi/templates/default-ueb-message.json"; - protected RetryPolicyStore retryPolicyStore; + private String uebServers; + private String defaultUebTemplateFileName = "/opt/bvc/restapi/templates/default-ueb-message.json"; + protected RetryPolicyStore retryPolicyStore; - protected RetryPolicyStore getRetryPolicyStore() { - return retryPolicyStore; - } + protected RetryPolicyStore getRetryPolicyStore() { + return retryPolicyStore; + } - public void setRetryPolicyStore(RetryPolicyStore retryPolicyStore) { - this.retryPolicyStore = retryPolicyStore; - } + public void setRetryPolicyStore(RetryPolicyStore retryPolicyStore) { + this.retryPolicyStore = retryPolicyStore; + } - public RestapiCallNode() { + public RestapiCallNode() { - } + } - /** + /** * Allows Directed Graphs the ability to interact with REST APIs. * @param parameters HashMap of parameters passed by the DG to this function * @@ -106,654 +106,655 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { * @since 11.0.2 * @see String#split(String, int) */ - public void sendRequest(Map paramMap, SvcLogicContext ctx) throws SvcLogicException { - sendRequest(paramMap, ctx, null); - } - - public void sendRequest(Map paramMap, SvcLogicContext ctx, Integer retryCount) - throws SvcLogicException { - - RetryPolicy retryPolicy = null; - HttpResponse r = null; - try { - Parameters p = getParameters(paramMap); - if (p.partner != null) { - retryPolicy = retryPolicyStore.getRetryPolicy(p.partner); - } - String pp = p.responsePrefix != null ? p.responsePrefix + '.' : ""; - - String req = null; - if (p.templateFileName != null) { - String reqTemplate = readFile(p.templateFileName); - req = buildXmlJsonRequest(ctx, reqTemplate, p.format); - } - r = sendHttpRequest(req, p); - setResponseStatus(ctx, p.responsePrefix, r); - - if (p.dumpHeaders && r.headers != null) { + public void sendRequest(Map paramMap, SvcLogicContext ctx) throws SvcLogicException { + sendRequest(paramMap, ctx, null); + } + + public void sendRequest(Map paramMap, SvcLogicContext ctx, Integer retryCount) + throws SvcLogicException { + + RetryPolicy retryPolicy = null; + HttpResponse r = null; + try { + Parameters p = getParameters(paramMap); + if (p.partner != null) { + retryPolicy = retryPolicyStore.getRetryPolicy(p.partner); + } + String pp = p.responsePrefix != null ? p.responsePrefix + '.' : ""; + + String req = null; + if (p.templateFileName != null) { + String reqTemplate = readFile(p.templateFileName); + req = buildXmlJsonRequest(ctx, reqTemplate, p.format); + } + r = sendHttpRequest(req, p); + setResponseStatus(ctx, p.responsePrefix, r); + + if (p.dumpHeaders && r.headers != null) { for (Entry> a : r.headers.entrySet()) { ctx.setAttribute(pp + "header." + a.getKey(), StringUtils.join(a.getValue(), ",")); } } - if (r.body != null && r.body.trim().length() > 0) { - ctx.setAttribute(pp + "httpResponse", r.body); - - if (p.convertResponse) { - Map mm = null; - if (p.format == Format.XML) - mm = XmlParser.convertToProperties(r.body, p.listNameList); - else if (p.format == Format.JSON) - mm = JsonParser.convertToProperties(r.body); - - if (mm != null) - for (String key : mm.keySet()) - ctx.setAttribute(pp + key, mm.get(key)); - } - } - } catch (Exception e) { - boolean shouldRetry = false; - if (e.getCause() instanceof java.net.SocketException) { - shouldRetry = true; - } - - log.error("Error sending the request: " + e.getMessage(), e); - String prefix = parseParam(paramMap, "responsePrefix", false, null); - if (retryPolicy == null || shouldRetry == false) { - setFailureResponseStatus(ctx, prefix, e.getMessage(), r); - } else { - if (retryCount == null) { - retryCount = 0; - } - String retryMessage = retryCount + " attempts were made out of " + retryPolicy.getMaximumRetries() + - " maximum retries."; - log.debug(retryMessage); - try { - retryCount = retryCount + 1; - if (retryCount < retryPolicy.getMaximumRetries() + 1) { - URI uri = new URI(paramMap.get("restapiUrl")); - String hostname = uri.getHost(); - String retryString = retryPolicy.getNextHostName((uri.toString())); - URI uriTwo = new URI(retryString); - URI retryUri = UriBuilder.fromUri(uri).host(uriTwo.getHost()).port(uriTwo.getPort()).scheme( - uriTwo.getScheme()).build(); - paramMap.put("restapiUrl", retryUri.toString()); - log.debug("URL was set to " + retryUri.toString()); - log.debug("Failed to communicate with host " + hostname + - ". Request will be re-attempted using the host " + retryString + "."); - log.debug("This is retry attempt " + retryCount + " out of " + retryPolicy.getMaximumRetries()); - sendRequest(paramMap, ctx, retryCount); - } else { - log.debug("Maximum retries reached, calling setFailureResponseStatus."); - setFailureResponseStatus(ctx, prefix, e.getMessage(), r); - } - } catch (Exception ex) { - log.error("Could not attempt retry.", ex); - String retryErrorMessage = - "Retry attempt has failed. No further retry shall be attempted, calling setFailureResponseStatus."; - setFailureResponseStatus(ctx, prefix, retryErrorMessage, r); - } - } - } - - if (r != null && r.code >= 300) - throw new SvcLogicException(String.valueOf(r.code) + ": " + r.message); - } - - protected Parameters getParameters(Map paramMap) throws SvcLogicException { - Parameters p = new Parameters(); - p.templateFileName = parseParam(paramMap, "templateFileName", false, null); - p.restapiUrl = parseParam(paramMap, "restapiUrl", true, null); - p.restapiUser = parseParam(paramMap, "restapiUser", false, null); - p.restapiPassword = parseParam(paramMap, "restapiPassword", false, null); - p.contentType = parseParam(paramMap, "contentType", false, null); - p.format = Format.fromString(parseParam(paramMap, "format", false, "json")); - p.httpMethod = HttpMethod.fromString(parseParam(paramMap, "httpMethod", false, "post")); - p.responsePrefix = parseParam(paramMap, "responsePrefix", false, null); - p.listNameList = getListNameList(paramMap); - String skipSendingStr = paramMap.get("skipSending"); - p.skipSending = skipSendingStr != null && skipSendingStr.equalsIgnoreCase("true"); - p.convertResponse = Boolean.valueOf(parseParam(paramMap, "convertResponse", false, "true")); - p.trustStoreFileName = parseParam(paramMap, "trustStoreFileName", false, null); - p.trustStorePassword = parseParam(paramMap, "trustStorePassword", false, null); - p.keyStoreFileName = parseParam(paramMap, "keyStoreFileName", false, null); - p.keyStorePassword = parseParam(paramMap, "keyStorePassword", false, null); - p.ssl = p.trustStoreFileName != null && p.trustStorePassword != null && p.keyStoreFileName != null && - p.keyStorePassword != null; - p.customHttpHeaders = parseParam(paramMap, "customHttpHeaders", false, null); - p.partner = parseParam(paramMap, "partner", false, null); - p.dumpHeaders = Boolean.valueOf(parseParam(paramMap, "dumpHeaders", false, null)); - return p; - } - - protected Set getListNameList(Map paramMap) { - Set ll = new HashSet(); - for (String key : paramMap.keySet()) - if (key.startsWith("listName")) - ll.add(paramMap.get(key)); - return ll; - } - - protected String parseParam(Map paramMap, String name, boolean required, String def) - throws SvcLogicException { - String s = paramMap.get(name); - - if (s == null || s.trim().length() == 0) { - if (!required) - return def; - throw new SvcLogicException("Parameter " + name + " is required in RestapiCallNode"); - } - - s = s.trim(); - String value = ""; - int i = 0; - int i1 = s.indexOf('%'); - while (i1 >= 0) { - int i2 = s.indexOf('%', i1 + 1); - if (i2 < 0) - break; - - String varName = s.substring(i1 + 1, i2); - String varValue = System.getenv(varName); - if (varValue == null) - varValue = "%" + varName + "%"; - - value += s.substring(i, i1); - value += varValue; - - i = i2 + 1; - i1 = s.indexOf('%', i); - } - value += s.substring(i); - - log.info("Parameter " + name + ": [" + value + "]"); - return value; - } - - protected String buildXmlJsonRequest(SvcLogicContext ctx, String template, Format format) { - log.info("Building " + format + " started"); - long t1 = System.currentTimeMillis(); - - template = expandRepeats(ctx, template, 1); - - Map mm = new HashMap<>(); - for (String s : ctx.getAttributeKeySet()) - mm.put(s, ctx.getAttribute(s)); - - StringBuilder ss = new StringBuilder(); - int i = 0; - while (i < template.length()) { - int i1 = template.indexOf("${", i); - if (i1 < 0) { - ss.append(template.substring(i)); - break; - } - - int i2 = template.indexOf('}', i1 + 2); - if (i2 < 0) - throw new RuntimeException("Template error: Matching } not found"); - - String var1 = template.substring(i1 + 2, i2); - String value1 = format == Format.XML ? XmlJsonUtil.getXml(mm, var1) : XmlJsonUtil.getJson(mm, var1); - // log.info(" " + var1 + ": " + value1); - if (value1 == null || value1.trim().length() == 0) { - // delete the whole element (line) - int i3 = template.lastIndexOf('\n', i1); - if (i3 < 0) - i3 = 0; - int i4 = template.indexOf('\n', i1); - if (i4 < 0) - i4 = template.length(); - - if (i < i3) - ss.append(template.substring(i, i3)); - i = i4; - } else { - ss.append(template.substring(i, i1)).append(value1); - i = i2 + 1; - } - } - - String req = format == Format.XML - ? XmlJsonUtil.removeEmptyStructXml(ss.toString()) : XmlJsonUtil.removeEmptyStructJson(ss.toString()); - - if (format == Format.JSON) - req = XmlJsonUtil.removeLastCommaJson(req); - - long t2 = System.currentTimeMillis(); - log.info("Building " + format + " completed. Time: " + (t2 - t1)); - - return req; - } - - protected String expandRepeats(SvcLogicContext ctx, String template, int level) { - StringBuilder newTemplate = new StringBuilder(); - int k = 0; - while (k < template.length()) { - int i1 = template.indexOf("${repeat:", k); - if (i1 < 0) { - newTemplate.append(template.substring(k)); - break; - } - - int i2 = template.indexOf(':', i1 + 9); - if (i2 < 0) - throw new RuntimeException( - "Template error: Context variable name followed by : is required after repeat"); - - // Find the closing }, store in i3 - int nn = 1; - int i3 = -1; - int i = i2; - while (nn > 0 && i < template.length()) { - i3 = template.indexOf('}', i); - if (i3 < 0) - throw new RuntimeException("Template error: Matching } not found"); - int i32 = template.indexOf('{', i); - if (i32 >= 0 && i32 < i3) { - nn++; - i = i32 + 1; - } else { - nn--; - i = i3 + 1; - } - } - - String var1 = template.substring(i1 + 9, i2); - String value1 = ctx.getAttribute(var1); - log.info(" " + var1 + ": " + value1); - int n = 0; - try { - n = Integer.parseInt(value1); - } catch (Exception e) { - n = 0; - } - - newTemplate.append(template.substring(k, i1)); - - String rpt = template.substring(i2 + 1, i3); - - for (int ii = 0; ii < n; ii++) { - String ss = rpt.replaceAll("\\[\\$\\{" + level + "\\}\\]", "[" + ii + "]"); - if (ii == n - 1 && ss.trim().endsWith(",")) { - int i4 = ss.lastIndexOf(','); - if (i4 > 0) - ss = ss.substring(0, i4) + ss.substring(i4 + 1); - } - newTemplate.append(ss); - } - - k = i3 + 1; - } - - if (k == 0) - return newTemplate.toString(); - - return expandRepeats(ctx, newTemplate.toString(), level + 1); - } - - protected String readFile(String fileName) throws Exception { - byte[] encoded = Files.readAllBytes(Paths.get(fileName)); - return new String(encoded, "UTF-8"); - } - - protected HttpResponse sendHttpRequest(String request, Parameters p) throws Exception { - ClientConfig config = new DefaultClientConfig(); - SSLContext ssl = null; - if (p.ssl && p.restapiUrl.startsWith("https")) - ssl = createSSLContext(p); - if (ssl != null) { - HostnameVerifier hostnameVerifier = new HostnameVerifier() { - - @Override - public boolean verify(String hostname, SSLSession session) { - return true; - } - }; - - config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, - new HTTPSProperties(hostnameVerifier, ssl)); - } - - logProperties(config.getProperties()); - - Client client = Client.create(config); - client.setConnectTimeout(5000); - if (p.restapiUser != null) - client.addFilter(new HTTPBasicAuthFilter(p.restapiUser, p.restapiPassword)); - WebResource webResource = client.resource(p.restapiUrl); - - log.info("Sending request:"); - log.info(request); - long t1 = System.currentTimeMillis(); - - HttpResponse r = new HttpResponse(); - r.code = 200; - - if (!p.skipSending) { - String tt = p.format == Format.XML ? "application/xml" : "application/json"; - String tt1 = tt + ";charset=UTF-8"; - if (p.contentType != null) { - tt = p.contentType; - tt1 = p.contentType; - } - - WebResource.Builder webResourceBuilder = webResource.accept(tt).type(tt1); + if (r.body != null && r.body.trim().length() > 0) { + ctx.setAttribute(pp + "httpResponse", r.body); + + if (p.convertResponse) { + Map mm = null; + if (p.format == Format.XML) + mm = XmlParser.convertToProperties(r.body, p.listNameList); + else if (p.format == Format.JSON) + mm = JsonParser.convertToProperties(r.body); + + if (mm != null) + for (String key : mm.keySet()) + ctx.setAttribute(pp + key, mm.get(key)); + } + } + } catch (Exception e) { + boolean shouldRetry = false; + if (e.getCause() instanceof java.net.SocketException) { + shouldRetry = true; + } + + log.error("Error sending the request: " + e.getMessage(), e); + String prefix = parseParam(paramMap, "responsePrefix", false, null); + if (retryPolicy == null || shouldRetry == false) { + setFailureResponseStatus(ctx, prefix, e.getMessage(), r); + } else { + if (retryCount == null) { + retryCount = 0; + } + String retryMessage = retryCount + " attempts were made out of " + retryPolicy.getMaximumRetries() + + " maximum retries."; + log.debug(retryMessage); + try { + retryCount = retryCount + 1; + if (retryCount < retryPolicy.getMaximumRetries() + 1) { + URI uri = new URI(paramMap.get("restapiUrl")); + String hostname = uri.getHost(); + String retryString = retryPolicy.getNextHostName((uri.toString())); + URI uriTwo = new URI(retryString); + URI retryUri = UriBuilder.fromUri(uri).host(uriTwo.getHost()).port(uriTwo.getPort()).scheme( + uriTwo.getScheme()).build(); + paramMap.put("restapiUrl", retryUri.toString()); + log.debug("URL was set to " + retryUri.toString()); + log.debug("Failed to communicate with host " + hostname + + ". Request will be re-attempted using the host " + retryString + "."); + log.debug("This is retry attempt " + retryCount + " out of " + retryPolicy.getMaximumRetries()); + sendRequest(paramMap, ctx, retryCount); + } else { + log.debug("Maximum retries reached, calling setFailureResponseStatus."); + setFailureResponseStatus(ctx, prefix, e.getMessage(), r); + } + } catch (Exception ex) { + log.error("Could not attempt retry.", ex); + String retryErrorMessage = + "Retry attempt has failed. No further retry shall be attempted, calling setFailureResponseStatus."; + setFailureResponseStatus(ctx, prefix, retryErrorMessage, r); + } + } + } + + if (r != null && r.code >= 300) + throw new SvcLogicException(String.valueOf(r.code) + ": " + r.message); + } + + protected Parameters getParameters(Map paramMap) throws SvcLogicException { + Parameters p = new Parameters(); + p.templateFileName = parseParam(paramMap, "templateFileName", false, null); + p.restapiUrl = parseParam(paramMap, "restapiUrl", true, null); + p.restapiUser = parseParam(paramMap, "restapiUser", false, null); + p.restapiPassword = parseParam(paramMap, "restapiPassword", false, null); + p.contentType = parseParam(paramMap, "contentType", false, null); + p.format = Format.fromString(parseParam(paramMap, "format", false, "json")); + p.httpMethod = HttpMethod.fromString(parseParam(paramMap, "httpMethod", false, "post")); + p.responsePrefix = parseParam(paramMap, "responsePrefix", false, null); + p.listNameList = getListNameList(paramMap); + String skipSendingStr = paramMap.get("skipSending"); + p.skipSending = skipSendingStr != null && skipSendingStr.equalsIgnoreCase("true"); + p.convertResponse = Boolean.valueOf(parseParam(paramMap, "convertResponse", false, "true")); + p.trustStoreFileName = parseParam(paramMap, "trustStoreFileName", false, null); + p.trustStorePassword = parseParam(paramMap, "trustStorePassword", false, null); + p.keyStoreFileName = parseParam(paramMap, "keyStoreFileName", false, null); + p.keyStorePassword = parseParam(paramMap, "keyStorePassword", false, null); + p.ssl = p.trustStoreFileName != null && p.trustStorePassword != null && p.keyStoreFileName != null && + p.keyStorePassword != null; + p.customHttpHeaders = parseParam(paramMap, "customHttpHeaders", false, null); + p.partner = parseParam(paramMap, "partner", false, null); + p.dumpHeaders = Boolean.valueOf(parseParam(paramMap, "dumpHeaders", false, null)); + return p; + } + + protected Set getListNameList(Map paramMap) { + Set ll = new HashSet(); + for (String key : paramMap.keySet()) + if (key.startsWith("listName")) + ll.add(paramMap.get(key)); + return ll; + } + + protected String parseParam(Map paramMap, String name, boolean required, String def) + throws SvcLogicException { + String s = paramMap.get(name); + + if (s == null || s.trim().length() == 0) { + if (!required) + return def; + throw new SvcLogicException("Parameter " + name + " is required in RestapiCallNode"); + } + + s = s.trim(); + String value = ""; + int i = 0; + int i1 = s.indexOf('%'); + while (i1 >= 0) { + int i2 = s.indexOf('%', i1 + 1); + if (i2 < 0) + break; + + String varName = s.substring(i1 + 1, i2); + String varValue = System.getenv(varName); + if (varValue == null) + varValue = "%" + varName + "%"; + + value += s.substring(i, i1); + value += varValue; + + i = i2 + 1; + i1 = s.indexOf('%', i); + } + value += s.substring(i); + + log.info("Parameter " + name + ": [" + value + "]"); + return value; + } + + protected String buildXmlJsonRequest(SvcLogicContext ctx, String template, Format format) { + log.info("Building " + format + " started"); + long t1 = System.currentTimeMillis(); + + template = expandRepeats(ctx, template, 1); + + Map mm = new HashMap<>(); + for (String s : ctx.getAttributeKeySet()) + mm.put(s, ctx.getAttribute(s)); + + StringBuilder ss = new StringBuilder(); + int i = 0; + while (i < template.length()) { + int i1 = template.indexOf("${", i); + if (i1 < 0) { + ss.append(template.substring(i)); + break; + } + + int i2 = template.indexOf('}', i1 + 2); + if (i2 < 0) + throw new RuntimeException("Template error: Matching } not found"); + + String var1 = template.substring(i1 + 2, i2); + String value1 = format == Format.XML ? XmlJsonUtil.getXml(mm, var1) : XmlJsonUtil.getJson(mm, var1); + // log.info(" " + var1 + ": " + value1); + if (value1 == null || value1.trim().length() == 0) { + // delete the whole element (line) + int i3 = template.lastIndexOf('\n', i1); + if (i3 < 0) + i3 = 0; + int i4 = template.indexOf('\n', i1); + if (i4 < 0) + i4 = template.length(); + + if (i < i3) + ss.append(template.substring(i, i3)); + i = i4; + } else { + ss.append(template.substring(i, i1)).append(value1); + i = i2 + 1; + } + } + + String req = format == Format.XML + ? XmlJsonUtil.removeEmptyStructXml(ss.toString()) : XmlJsonUtil.removeEmptyStructJson(ss.toString()); + + if (format == Format.JSON) + req = XmlJsonUtil.removeLastCommaJson(req); + + long t2 = System.currentTimeMillis(); + log.info("Building " + format + " completed. Time: " + (t2 - t1)); + + return req; + } + + protected String expandRepeats(SvcLogicContext ctx, String template, int level) { + StringBuilder newTemplate = new StringBuilder(); + int k = 0; + while (k < template.length()) { + int i1 = template.indexOf("${repeat:", k); + if (i1 < 0) { + newTemplate.append(template.substring(k)); + break; + } + + int i2 = template.indexOf(':', i1 + 9); + if (i2 < 0) + throw new RuntimeException( + "Template error: Context variable name followed by : is required after repeat"); + + // Find the closing }, store in i3 + int nn = 1; + int i3 = -1; + int i = i2; + while (nn > 0 && i < template.length()) { + i3 = template.indexOf('}', i); + if (i3 < 0) + throw new RuntimeException("Template error: Matching } not found"); + int i32 = template.indexOf('{', i); + if (i32 >= 0 && i32 < i3) { + nn++; + i = i32 + 1; + } else { + nn--; + i = i3 + 1; + } + } + + String var1 = template.substring(i1 + 9, i2); + String value1 = ctx.getAttribute(var1); + log.info(" " + var1 + ": " + value1); + int n = 0; + try { + n = Integer.parseInt(value1); + } catch (Exception e) { + n = 0; + } + + newTemplate.append(template.substring(k, i1)); + + String rpt = template.substring(i2 + 1, i3); + + for (int ii = 0; ii < n; ii++) { + String ss = rpt.replaceAll("\\[\\$\\{" + level + "\\}\\]", "[" + ii + "]"); + if (ii == n - 1 && ss.trim().endsWith(",")) { + int i4 = ss.lastIndexOf(','); + if (i4 > 0) + ss = ss.substring(0, i4) + ss.substring(i4 + 1); + } + newTemplate.append(ss); + } + + k = i3 + 1; + } + + if (k == 0) + return newTemplate.toString(); + + return expandRepeats(ctx, newTemplate.toString(), level + 1); + } + + protected String readFile(String fileName) throws Exception { + byte[] encoded = Files.readAllBytes(Paths.get(fileName)); + return new String(encoded, "UTF-8"); + } + + protected HttpResponse sendHttpRequest(String request, Parameters p) throws Exception { + ClientConfig config = new DefaultClientConfig(); + SSLContext ssl = null; + if (p.ssl && p.restapiUrl.startsWith("https")) + ssl = createSSLContext(p); + if (ssl != null) { + HostnameVerifier hostnameVerifier = new HostnameVerifier() { + + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + + config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, + new HTTPSProperties(hostnameVerifier, ssl)); + } + + logProperties(config.getProperties()); + + Client client = Client.create(config); + client.setConnectTimeout(5000); + if (p.restapiUser != null) + client.addFilter(new HTTPBasicAuthFilter(p.restapiUser, p.restapiPassword)); + WebResource webResource = client.resource(p.restapiUrl); + + log.info("Sending request:"); + log.info(request); + long t1 = System.currentTimeMillis(); + + HttpResponse r = new HttpResponse(); + r.code = 200; + + if (!p.skipSending) { + String tt = p.format == Format.XML ? "application/xml" : "application/json"; + String tt1 = tt + ";charset=UTF-8"; + if (p.contentType != null) { + tt = p.contentType; + tt1 = p.contentType; + } + + WebResource.Builder webResourceBuilder = webResource.accept(tt).type(tt1); if (p.customHttpHeaders != null && p.customHttpHeaders.length() > 0) { String[] keyValuePairs = p.customHttpHeaders.split(","); for (String singlePair : keyValuePairs) { int equalPosition = singlePair.indexOf('='); - webResourceBuilder.header(singlePair.substring(0, equalPosition), singlePair.substring(equalPosition + 1, singlePair.length())); + webResourceBuilder.header(singlePair.substring(0, equalPosition), + singlePair.substring(equalPosition + 1, singlePair.length())); } } webResourceBuilder.header("X-ECOMP-RequestID",org.slf4j.MDC.get("X-ECOMP-RequestID")); - ClientResponse response = webResourceBuilder.method(p.httpMethod.toString(), ClientResponse.class, request); - - r.code = response.getStatus(); - r.headers = response.getHeaders(); - EntityTag etag = response.getEntityTag(); - if (etag != null) - r.message = etag.getValue(); - if (response.hasEntity() && r.code != 204) - r.body = response.getEntity(String.class); - } - - long t2 = System.currentTimeMillis(); - log.info("Response received. Time: " + (t2 - t1)); - log.info("HTTP response code: " + r.code); - log.info("HTTP response message: " + r.message); - logHeaders(r.headers); - log.info("HTTP response: " + r.body); - - return r; - } - - protected SSLContext createSSLContext(Parameters p) { - try { - System.setProperty("jsse.enableSNIExtension", "false"); - System.setProperty("javax.net.ssl.trustStore", p.trustStoreFileName); - System.setProperty("javax.net.ssl.trustStorePassword", p.trustStorePassword); - - HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { - - @Override - public boolean verify(String string, SSLSession ssls) { - return true; - } - }); - - KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); - FileInputStream in = new FileInputStream(p.keyStoreFileName); - KeyStore ks = KeyStore.getInstance("PKCS12"); - char[] pwd = p.keyStorePassword.toCharArray(); - ks.load(in, pwd); - kmf.init(ks, pwd); - - SSLContext ctx = SSLContext.getInstance("TLS"); - ctx.init(kmf.getKeyManagers(), null, null); - return ctx; - } catch (Exception e) { - log.error("Error creating SSLContext: " + e.getMessage(), e); - } - return null; - } - - protected void setFailureResponseStatus(SvcLogicContext ctx, String prefix, String errorMessage, HttpResponse r) { - r = new HttpResponse(); - r.code = 500; - r.message = errorMessage; - String pp = prefix != null ? prefix + '.' : ""; - ctx.setAttribute(pp + "response-code", String.valueOf(r.code)); - ctx.setAttribute(pp + "response-message", r.message); - } - - protected void setResponseStatus(SvcLogicContext ctx, String prefix, HttpResponse r) { - String pp = prefix != null ? prefix + '.' : ""; - ctx.setAttribute(pp + "response-code", String.valueOf(r.code)); - ctx.setAttribute(pp + "response-message", r.message); - } - - public void sendFile(Map paramMap, SvcLogicContext ctx) throws SvcLogicException { - HttpResponse r = null; - try { - FileParam p = getFileParameters(paramMap); - byte[] data = Files.readAllBytes(Paths.get(p.fileName)); - - r = sendHttpData(data, p); - setResponseStatus(ctx, p.responsePrefix, r); - - } catch (Exception e) { - log.error("Error sending the request: " + e.getMessage(), e); - - r = new HttpResponse(); - r.code = 500; - r.message = e.getMessage(); - String prefix = parseParam(paramMap, "responsePrefix", false, null); - setResponseStatus(ctx, prefix, r); - } - - if (r != null && r.code >= 300) - throw new SvcLogicException(String.valueOf(r.code) + ": " + r.message); - } - - private static class FileParam { - - public String fileName; - public String url; - public String user; - public String password; - public HttpMethod httpMethod; - public String responsePrefix; - public boolean skipSending; - } - - private FileParam getFileParameters(Map paramMap) throws SvcLogicException { - FileParam p = new FileParam(); - p.fileName = parseParam(paramMap, "fileName", true, null); - p.url = parseParam(paramMap, "url", true, null); - p.user = parseParam(paramMap, "user", false, null); - p.password = parseParam(paramMap, "password", false, null); - p.httpMethod = HttpMethod.fromString(parseParam(paramMap, "httpMethod", false, "post")); - p.responsePrefix = parseParam(paramMap, "responsePrefix", false, null); - String skipSendingStr = paramMap.get("skipSending"); - p.skipSending = skipSendingStr != null && skipSendingStr.equalsIgnoreCase("true"); - return p; - } - - protected HttpResponse sendHttpData(byte[] data, FileParam p) { - Client client = Client.create(); - client.setConnectTimeout(5000); - client.setFollowRedirects(true); - if (p.user != null) - client.addFilter(new HTTPBasicAuthFilter(p.user, p.password)); - WebResource webResource = client.resource(p.url); - - log.info("Sending file"); - long t1 = System.currentTimeMillis(); - - HttpResponse r = new HttpResponse(); - r.code = 200; - - if (!p.skipSending) { - String tt = "application/octet-stream"; - - ClientResponse response = null; - if (p.httpMethod == HttpMethod.POST) - response = webResource.accept(tt).type(tt).post(ClientResponse.class, data); - else if (p.httpMethod == HttpMethod.PUT) - response = webResource.accept(tt).type(tt).put(ClientResponse.class, data); - - r.code = response.getStatus(); - r.headers = response.getHeaders(); - EntityTag etag = response.getEntityTag(); - if (etag != null) - r.message = etag.getValue(); - if (response.hasEntity() && r.code != 204) - r.body = response.getEntity(String.class); - - if (r.code == 301) { - String newUrl = response.getHeaders().getFirst("Location"); - - log.info("Got response code 301. Sending same request to URL: " + newUrl); - - webResource = client.resource(newUrl); - - if (p.httpMethod == HttpMethod.POST) - response = webResource.accept(tt).type(tt).post(ClientResponse.class, data); - else if (p.httpMethod == HttpMethod.PUT) - response = webResource.accept(tt).type(tt).put(ClientResponse.class, data); - - r.code = response.getStatus(); - etag = response.getEntityTag(); - if (etag != null) - r.message = etag.getValue(); - if (response.hasEntity() && r.code != 204) - r.body = response.getEntity(String.class); - } - } - - long t2 = System.currentTimeMillis(); - log.info("Response received. Time: " + (t2 - t1)); - log.info("HTTP response code: " + r.code); - log.info("HTTP response message: " + r.message); - logHeaders(r.headers); - log.info("HTTP response: " + r.body); - - return r; - } - - public void postMessageOnUeb(Map paramMap, SvcLogicContext ctx) throws SvcLogicException { - HttpResponse r = null; - try { - UebParam p = getUebParameters(paramMap); - - String pp = p.responsePrefix != null ? p.responsePrefix + '.' : ""; - - String req = null; - - if (p.templateFileName == null) { - log.info("No template file name specified. Using default UEB template: " + defaultUebTemplateFileName); - p.templateFileName = defaultUebTemplateFileName; - } - - String reqTemplate = readFile(p.templateFileName); - reqTemplate = reqTemplate.replaceAll("rootVarName", p.rootVarName); - req = buildXmlJsonRequest(ctx, reqTemplate, Format.JSON); - - r = postOnUeb(req, p); - setResponseStatus(ctx, p.responsePrefix, r); - if (r.body != null) - ctx.setAttribute(pp + "httpResponse", r.body); - - } catch (Exception e) { - log.error("Error sending the request: " + e.getMessage(), e); - - r = new HttpResponse(); - r.code = 500; - r.message = e.getMessage(); - String prefix = parseParam(paramMap, "responsePrefix", false, null); - setResponseStatus(ctx, prefix, r); - } - - if (r != null && r.code >= 300) - throw new SvcLogicException(String.valueOf(r.code) + ": " + r.message); - } - - private static class UebParam { - - public String topic; - public String templateFileName; - public String rootVarName; - public String responsePrefix; - public boolean skipSending; - } - - private UebParam getUebParameters(Map paramMap) throws SvcLogicException { - UebParam p = new UebParam(); - p.topic = parseParam(paramMap, "topic", true, null); - p.templateFileName = parseParam(paramMap, "templateFileName", false, null); - p.rootVarName = parseParam(paramMap, "rootVarName", false, null); - p.responsePrefix = parseParam(paramMap, "responsePrefix", false, null); - String skipSendingStr = paramMap.get("skipSending"); - p.skipSending = skipSendingStr != null && skipSendingStr.equalsIgnoreCase("true"); - return p; - } - - protected HttpResponse postOnUeb(String request, UebParam p) throws Exception { - String[] urls = uebServers.split(" "); - for (int i = 0; i < urls.length; i++) { - if (!urls[i].endsWith("/")) - urls[i] += "/"; - urls[i] += "events/" + p.topic; - } - - Client client = Client.create(); - client.setConnectTimeout(5000); - WebResource webResource = client.resource(urls[0]); - - log.info("UEB URL: " + urls[0]); - log.info("Sending request:"); - log.info(request); - long t1 = System.currentTimeMillis(); - - HttpResponse r = new HttpResponse(); - r.code = 200; - - if (!p.skipSending) { - String tt = "application/json"; - String tt1 = tt + ";charset=UTF-8"; - - ClientResponse response = webResource.accept(tt).type(tt1).post(ClientResponse.class, request); - - r.code = response.getStatus(); - r.headers = response.getHeaders(); - if (response.hasEntity()) - r.body = response.getEntity(String.class); - } - - long t2 = System.currentTimeMillis(); - log.info("Response received. Time: " + (t2 - t1)); - log.info("HTTP response code: " + r.code); - logHeaders(r.headers); - log.info("HTTP response:\n" + r.body); - - return r; - } - - protected void logProperties(Map mm) { - List ll = new ArrayList<>(); - for (Object o : mm.keySet()) - ll.add((String) o); - Collections.sort(ll); - - log.info("Properties:"); - for (String name : ll) - log.info("--- " + name + ": " + String.valueOf(mm.get(name))); - } - - protected void logHeaders(MultivaluedMap mm) { - log.info("HTTP response headers:"); - - if (mm == null) - return; - - List ll = new ArrayList<>(); - for (Object o : mm.keySet()) - ll.add((String) o); - Collections.sort(ll); - - for (String name : ll) - log.info("--- " + name + ": " + String.valueOf(mm.get(name))); - } - - public void setUebServers(String uebServers) { - this.uebServers = uebServers; - } - - public void setDefaultUebTemplateFileName(String defaultUebTemplateFileName) { - this.defaultUebTemplateFileName = defaultUebTemplateFileName; - } + ClientResponse response = webResourceBuilder.method(p.httpMethod.toString(), ClientResponse.class, request); + + r.code = response.getStatus(); + r.headers = response.getHeaders(); + EntityTag etag = response.getEntityTag(); + if (etag != null) + r.message = etag.getValue(); + if (response.hasEntity() && r.code != 204) + r.body = response.getEntity(String.class); + } + + long t2 = System.currentTimeMillis(); + log.info("Response received. Time: " + (t2 - t1)); + log.info("HTTP response code: " + r.code); + log.info("HTTP response message: " + r.message); + logHeaders(r.headers); + log.info("HTTP response: " + r.body); + + return r; + } + + protected SSLContext createSSLContext(Parameters p) { + try { + System.setProperty("jsse.enableSNIExtension", "false"); + System.setProperty("javax.net.ssl.trustStore", p.trustStoreFileName); + System.setProperty("javax.net.ssl.trustStorePassword", p.trustStorePassword); + + HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { + + @Override + public boolean verify(String string, SSLSession ssls) { + return true; + } + }); + + KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); + FileInputStream in = new FileInputStream(p.keyStoreFileName); + KeyStore ks = KeyStore.getInstance("PKCS12"); + char[] pwd = p.keyStorePassword.toCharArray(); + ks.load(in, pwd); + kmf.init(ks, pwd); + + SSLContext ctx = SSLContext.getInstance("TLS"); + ctx.init(kmf.getKeyManagers(), null, null); + return ctx; + } catch (Exception e) { + log.error("Error creating SSLContext: " + e.getMessage(), e); + } + return null; + } + + protected void setFailureResponseStatus(SvcLogicContext ctx, String prefix, String errorMessage, HttpResponse r) { + r = new HttpResponse(); + r.code = 500; + r.message = errorMessage; + String pp = prefix != null ? prefix + '.' : ""; + ctx.setAttribute(pp + "response-code", String.valueOf(r.code)); + ctx.setAttribute(pp + "response-message", r.message); + } + + protected void setResponseStatus(SvcLogicContext ctx, String prefix, HttpResponse r) { + String pp = prefix != null ? prefix + '.' : ""; + ctx.setAttribute(pp + "response-code", String.valueOf(r.code)); + ctx.setAttribute(pp + "response-message", r.message); + } + + public void sendFile(Map paramMap, SvcLogicContext ctx) throws SvcLogicException { + HttpResponse r = null; + try { + FileParam p = getFileParameters(paramMap); + byte[] data = Files.readAllBytes(Paths.get(p.fileName)); + + r = sendHttpData(data, p); + setResponseStatus(ctx, p.responsePrefix, r); + + } catch (Exception e) { + log.error("Error sending the request: " + e.getMessage(), e); + + r = new HttpResponse(); + r.code = 500; + r.message = e.getMessage(); + String prefix = parseParam(paramMap, "responsePrefix", false, null); + setResponseStatus(ctx, prefix, r); + } + + if (r != null && r.code >= 300) + throw new SvcLogicException(String.valueOf(r.code) + ": " + r.message); + } + + private static class FileParam { + + public String fileName; + public String url; + public String user; + public String password; + public HttpMethod httpMethod; + public String responsePrefix; + public boolean skipSending; + } + + private FileParam getFileParameters(Map paramMap) throws SvcLogicException { + FileParam p = new FileParam(); + p.fileName = parseParam(paramMap, "fileName", true, null); + p.url = parseParam(paramMap, "url", true, null); + p.user = parseParam(paramMap, "user", false, null); + p.password = parseParam(paramMap, "password", false, null); + p.httpMethod = HttpMethod.fromString(parseParam(paramMap, "httpMethod", false, "post")); + p.responsePrefix = parseParam(paramMap, "responsePrefix", false, null); + String skipSendingStr = paramMap.get("skipSending"); + p.skipSending = skipSendingStr != null && skipSendingStr.equalsIgnoreCase("true"); + return p; + } + + protected HttpResponse sendHttpData(byte[] data, FileParam p) { + Client client = Client.create(); + client.setConnectTimeout(5000); + client.setFollowRedirects(true); + if (p.user != null) + client.addFilter(new HTTPBasicAuthFilter(p.user, p.password)); + WebResource webResource = client.resource(p.url); + + log.info("Sending file"); + long t1 = System.currentTimeMillis(); + + HttpResponse r = new HttpResponse(); + r.code = 200; + + if (!p.skipSending) { + String tt = "application/octet-stream"; + + ClientResponse response = null; + if (p.httpMethod == HttpMethod.POST) + response = webResource.accept(tt).type(tt).post(ClientResponse.class, data); + else if (p.httpMethod == HttpMethod.PUT) + response = webResource.accept(tt).type(tt).put(ClientResponse.class, data); + + r.code = response.getStatus(); + r.headers = response.getHeaders(); + EntityTag etag = response.getEntityTag(); + if (etag != null) + r.message = etag.getValue(); + if (response.hasEntity() && r.code != 204) + r.body = response.getEntity(String.class); + + if (r.code == 301) { + String newUrl = response.getHeaders().getFirst("Location"); + + log.info("Got response code 301. Sending same request to URL: " + newUrl); + + webResource = client.resource(newUrl); + + if (p.httpMethod == HttpMethod.POST) + response = webResource.accept(tt).type(tt).post(ClientResponse.class, data); + else if (p.httpMethod == HttpMethod.PUT) + response = webResource.accept(tt).type(tt).put(ClientResponse.class, data); + + r.code = response.getStatus(); + etag = response.getEntityTag(); + if (etag != null) + r.message = etag.getValue(); + if (response.hasEntity() && r.code != 204) + r.body = response.getEntity(String.class); + } + } + + long t2 = System.currentTimeMillis(); + log.info("Response received. Time: " + (t2 - t1)); + log.info("HTTP response code: " + r.code); + log.info("HTTP response message: " + r.message); + logHeaders(r.headers); + log.info("HTTP response: " + r.body); + + return r; + } + + public void postMessageOnUeb(Map paramMap, SvcLogicContext ctx) throws SvcLogicException { + HttpResponse r = null; + try { + UebParam p = getUebParameters(paramMap); + + String pp = p.responsePrefix != null ? p.responsePrefix + '.' : ""; + + String req = null; + + if (p.templateFileName == null) { + log.info("No template file name specified. Using default UEB template: " + defaultUebTemplateFileName); + p.templateFileName = defaultUebTemplateFileName; + } + + String reqTemplate = readFile(p.templateFileName); + reqTemplate = reqTemplate.replaceAll("rootVarName", p.rootVarName); + req = buildXmlJsonRequest(ctx, reqTemplate, Format.JSON); + + r = postOnUeb(req, p); + setResponseStatus(ctx, p.responsePrefix, r); + if (r.body != null) + ctx.setAttribute(pp + "httpResponse", r.body); + + } catch (Exception e) { + log.error("Error sending the request: " + e.getMessage(), e); + + r = new HttpResponse(); + r.code = 500; + r.message = e.getMessage(); + String prefix = parseParam(paramMap, "responsePrefix", false, null); + setResponseStatus(ctx, prefix, r); + } + + if (r != null && r.code >= 300) + throw new SvcLogicException(String.valueOf(r.code) + ": " + r.message); + } + + private static class UebParam { + + public String topic; + public String templateFileName; + public String rootVarName; + public String responsePrefix; + public boolean skipSending; + } + + private UebParam getUebParameters(Map paramMap) throws SvcLogicException { + UebParam p = new UebParam(); + p.topic = parseParam(paramMap, "topic", true, null); + p.templateFileName = parseParam(paramMap, "templateFileName", false, null); + p.rootVarName = parseParam(paramMap, "rootVarName", false, null); + p.responsePrefix = parseParam(paramMap, "responsePrefix", false, null); + String skipSendingStr = paramMap.get("skipSending"); + p.skipSending = skipSendingStr != null && skipSendingStr.equalsIgnoreCase("true"); + return p; + } + + protected HttpResponse postOnUeb(String request, UebParam p) throws Exception { + String[] urls = uebServers.split(" "); + for (int i = 0; i < urls.length; i++) { + if (!urls[i].endsWith("/")) + urls[i] += "/"; + urls[i] += "events/" + p.topic; + } + + Client client = Client.create(); + client.setConnectTimeout(5000); + WebResource webResource = client.resource(urls[0]); + + log.info("UEB URL: " + urls[0]); + log.info("Sending request:"); + log.info(request); + long t1 = System.currentTimeMillis(); + + HttpResponse r = new HttpResponse(); + r.code = 200; + + if (!p.skipSending) { + String tt = "application/json"; + String tt1 = tt + ";charset=UTF-8"; + + ClientResponse response = webResource.accept(tt).type(tt1).post(ClientResponse.class, request); + + r.code = response.getStatus(); + r.headers = response.getHeaders(); + if (response.hasEntity()) + r.body = response.getEntity(String.class); + } + + long t2 = System.currentTimeMillis(); + log.info("Response received. Time: " + (t2 - t1)); + log.info("HTTP response code: " + r.code); + logHeaders(r.headers); + log.info("HTTP response:\n" + r.body); + + return r; + } + + protected void logProperties(Map mm) { + List ll = new ArrayList<>(); + for (Object o : mm.keySet()) + ll.add((String) o); + Collections.sort(ll); + + log.info("Properties:"); + for (String name : ll) + log.info("--- " + name + ": " + String.valueOf(mm.get(name))); + } + + protected void logHeaders(MultivaluedMap mm) { + log.info("HTTP response headers:"); + + if (mm == null) + return; + + List ll = new ArrayList<>(); + for (Object o : mm.keySet()) + ll.add((String) o); + Collections.sort(ll); + + for (String name : ll) + log.info("--- " + name + ": " + String.valueOf(mm.get(name))); + } + + public void setUebServers(String uebServers) { + this.uebServers = uebServers; + } + + public void setDefaultUebTemplateFileName(String defaultUebTemplateFileName) { + this.defaultUebTemplateFileName = defaultUebTemplateFileName; + } } diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RetryPolicy.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RetryPolicy.java index 69334a969..5cee07791 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RetryPolicy.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RetryPolicy.java @@ -40,7 +40,8 @@ public class RetryPolicy { } if(position == null){ - throw new RetryException("No match found for the provided uri[" + uri + "] so the next host name could not be retreived"); + throw new RetryException("No match found for the provided uri[" + uri + "] " + + "so the next host name could not be retreived"); } position++; diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java index 2fa3fa541..16b9f519f 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java @@ -31,342 +31,342 @@ import org.slf4j.LoggerFactory; public class XmlJsonUtil { - private static final Logger log = LoggerFactory.getLogger(XmlJsonUtil.class); - - public static String getXml(Map varmap, String var) { - boolean escape = true; - if (var.startsWith("'")) { - var = var.substring(1); - escape = false; - } - - Object o = createStructure(varmap, var); - return generateXml(o, 0, escape); - } - - public static String getJson(Map varmap, String var) { - boolean escape = true; - if (var.startsWith("'")) { - var = var.substring(1); - escape = false; - } - - Object o = createStructure(varmap, var); - return generateJson(o, escape); - } - - private static Object createStructure(Map flatmap, String var) { - if (flatmap.containsKey(var)) { - if (var.endsWith("_length") || var.endsWith("].key")) - return null; - return flatmap.get(var); - } - - Map mm = new HashMap<>(); - for (String k : flatmap.keySet()) - if (k.startsWith(var + ".")) { - int i1 = k.indexOf('.', var.length() + 1); - int i2 = k.indexOf('[', var.length() + 1); - int i3 = k.length(); - if (i1 > 0 && i1 < i3) - i3 = i1; - if (i2 > 0 && i2 < i3) - i3 = i2; - String k1 = k.substring(var.length() + 1, i3); - String var1 = k.substring(0, i3); - if (!mm.containsKey(k1)) { - Object str = createStructure(flatmap, var1); - if (str != null && (!(str instanceof String) || ((String) str).trim().length() > 0)) - mm.put(k1, str); - } - } - if (!mm.isEmpty()) - return mm; - - boolean arrayFound = false; - for (String k : flatmap.keySet()) - if (k.startsWith(var + "[")) { - arrayFound = true; - break; - } - - if (arrayFound) { - List ll = new ArrayList<>(); - - int length = Integer.MAX_VALUE; - String lengthStr = flatmap.get(var + "_length"); - if (lengthStr != null) { - try { - length = Integer.parseInt(lengthStr); - } catch (Exception e) { - log.warn("Invalid number for " + var + "_length:" + lengthStr); - } - } - - for (int i = 0; i < length; i++) { - Object v = createStructure(flatmap, var + '[' + i + ']'); - if (v == null) - break; - ll.add(v); - } - - if (!ll.isEmpty()) - return ll; - } - - return null; - } - - @SuppressWarnings("unchecked") - private static String generateXml(Object o, int indent, boolean escape) { - if (o == null) - return null; - - if (o instanceof String) - return escape ? escapeXml((String) o) : (String) o;; - - if (o instanceof Map) { - StringBuilder ss = new StringBuilder(); - Map mm = (Map) o; - for (String k : mm.keySet()) { - Object v = mm.get(k); - if (v instanceof String) { - String s = escape ? escapeXml((String) v) : (String) v; - ss.append(pad(indent)).append('<').append(k).append('>'); - ss.append(s); - ss.append("').append('\n'); - } else if (v instanceof Map) { - ss.append(pad(indent)).append('<').append(k).append('>').append('\n'); - ss.append(generateXml(v, indent + 1, escape)); - ss.append(pad(indent)).append("').append('\n'); - } else if (v instanceof List) { - List ll = (List) v; - for (Object o1 : ll) { - ss.append(pad(indent)).append('<').append(k).append('>').append('\n'); - ss.append(generateXml(o1, indent + 1, escape)); - ss.append(pad(indent)).append("').append('\n'); - } - } - } - return ss.toString(); - } - - return null; - } - - private static String generateJson(Object o, boolean escape) { - if (o == null) - return null; - - StringBuilder ss = new StringBuilder(); - generateJson(ss, o, 0, false, escape); - return ss.toString(); - } - - @SuppressWarnings("unchecked") - private static void generateJson(StringBuilder ss, Object o, int indent, boolean padFirst, boolean escape) { - if (o instanceof String) { - String s = escape ? escapeJson((String) o) : (String) o; - if (padFirst) - ss.append(pad(indent)); - ss.append('"').append(s).append('"'); - return; - } - - if (o instanceof Map) { - Map mm = (Map) o; - - if (padFirst) - ss.append(pad(indent)); - ss.append("{\n"); - - boolean first = true; - for (String k : mm.keySet()) { - if (!first) - ss.append(",\n"); - first = false; - - Object v = mm.get(k); - ss.append(pad(indent + 1)).append('"').append(k).append("\": "); - generateJson(ss, v, indent + 1, false, escape); - } - - ss.append("\n"); - ss.append(pad(indent)).append('}'); - - return; - } - - if (o instanceof List) { - List ll = (List) o; - - if (padFirst) - ss.append(pad(indent)); - ss.append("[\n"); - - boolean first = true; - for (Object o1 : ll) { - if (!first) - ss.append(",\n"); - first = false; - - generateJson(ss, o1, indent + 1, true, escape); - } - - ss.append("\n"); - ss.append(pad(indent)).append(']'); - } - } - - public static String removeLastCommaJson(String s) { - StringBuilder sb = new StringBuilder(); - int k = 0; - int start = 0; - while (k < s.length()) { - int i11 = s.indexOf('}', k); - int i12 = s.indexOf(']', k); - int i1 = -1; - if (i11 < 0) - i1 = i12; - else if (i12 < 0) - i1 = i11; - else - i1 = i11 < i12 ? i11 : i12; - if (i1 < 0) - break; - - int i2 = s.lastIndexOf(',', i1); - if (i2 < 0) { - k = i1 + 1; - continue; - } - - String between = s.substring(i2 + 1, i1); - if (between.trim().length() > 0) { - k = i1 + 1; - continue; - } - - sb.append(s.substring(start, i2)); - start = i2 + 1; - k = i1 + 1; - } - - sb.append(s.substring(start, s.length())); - - return sb.toString(); - } - - public static String removeEmptyStructJson(String s) { - int k = 0; - while (k < s.length()) { - boolean curly = true; - int i11 = s.indexOf('{', k); - int i12 = s.indexOf('[', k); - int i1 = -1; - if (i11 < 0) { - i1 = i12; - curly = false; - } else if (i12 < 0) - i1 = i11; - else - if (i11 < i12) - i1 = i11; - else { - i1 = i12; - curly = false; - } - - if (i1 >= 0) { - int i2 = curly ? s.indexOf('}', i1) : s.indexOf(']', i1); - if (i2 > 0) { - String value = s.substring(i1 + 1, i2); - if (value.trim().length() == 0) { - int i4 = s.lastIndexOf('\n', i1); - if (i4 < 0) - i4 = 0; - int i5 = s.indexOf('\n', i2); - if (i5 < 0) - i5 = s.length(); - - s = s.substring(0, i4) + s.substring(i5); - k = 0; - } else - k = i1 + 1; - } else - break; - } else - break; - } - - return s; - } - - public static String removeEmptyStructXml(String s) { - int k = 0; - while (k < s.length()) { - int i1 = s.indexOf('<', k); - if (i1 < 0 || i1 == s.length() - 1) - break; - - char c1 = s.charAt(i1 + 1); - if (c1 == '?' || c1 == '!') { - k = i1 + 2; - continue; - } - - int i2 = s.indexOf('>', i1); - if (i2 < 0) { - k = i1 + 1; - continue; - } - - String closingTag = " 0) { - k = i2 + 1; - continue; - } - - int i4 = s.lastIndexOf('\n', i1); - if (i4 < 0) - i4 = 0; - int i5 = s.indexOf('\n', i3); - if (i5 < 0) - i5 = s.length(); - - s = s.substring(0, i4) + s.substring(i5); - k = 0; - } - - return s; - } - - private static String escapeXml(String v) { - String s = v.replaceAll("&", "&"); - s = s.replaceAll("<", "<"); - s = s.replaceAll("'", "'"); - s = s.replaceAll("\"", """); - s = s.replaceAll(">", ">"); - return s; - } - - private static String escapeJson(String v) { - String s = v.replaceAll("\\\\", "\\\\\\\\"); - s = s.replaceAll("\"", "\\\\\""); - return s; - } - - private static String pad(int n) { - String s = ""; - for (int i = 0; i < n; i++) - s += '\t'; - return s; - } + private static final Logger log = LoggerFactory.getLogger(XmlJsonUtil.class); + + public static String getXml(Map varmap, String var) { + boolean escape = true; + if (var.startsWith("'")) { + var = var.substring(1); + escape = false; + } + + Object o = createStructure(varmap, var); + return generateXml(o, 0, escape); + } + + public static String getJson(Map varmap, String var) { + boolean escape = true; + if (var.startsWith("'")) { + var = var.substring(1); + escape = false; + } + + Object o = createStructure(varmap, var); + return generateJson(o, escape); + } + + private static Object createStructure(Map flatmap, String var) { + if (flatmap.containsKey(var)) { + if (var.endsWith("_length") || var.endsWith("].key")) + return null; + return flatmap.get(var); + } + + Map mm = new HashMap<>(); + for (String k : flatmap.keySet()) + if (k.startsWith(var + ".")) { + int i1 = k.indexOf('.', var.length() + 1); + int i2 = k.indexOf('[', var.length() + 1); + int i3 = k.length(); + if (i1 > 0 && i1 < i3) + i3 = i1; + if (i2 > 0 && i2 < i3) + i3 = i2; + String k1 = k.substring(var.length() + 1, i3); + String var1 = k.substring(0, i3); + if (!mm.containsKey(k1)) { + Object str = createStructure(flatmap, var1); + if (str != null && (!(str instanceof String) || ((String) str).trim().length() > 0)) + mm.put(k1, str); + } + } + if (!mm.isEmpty()) + return mm; + + boolean arrayFound = false; + for (String k : flatmap.keySet()) + if (k.startsWith(var + "[")) { + arrayFound = true; + break; + } + + if (arrayFound) { + List ll = new ArrayList<>(); + + int length = Integer.MAX_VALUE; + String lengthStr = flatmap.get(var + "_length"); + if (lengthStr != null) { + try { + length = Integer.parseInt(lengthStr); + } catch (Exception e) { + log.warn("Invalid number for " + var + "_length:" + lengthStr); + } + } + + for (int i = 0; i < length; i++) { + Object v = createStructure(flatmap, var + '[' + i + ']'); + if (v == null) + break; + ll.add(v); + } + + if (!ll.isEmpty()) + return ll; + } + + return null; + } + + @SuppressWarnings("unchecked") + private static String generateXml(Object o, int indent, boolean escape) { + if (o == null) + return null; + + if (o instanceof String) + return escape ? escapeXml((String) o) : (String) o;; + + if (o instanceof Map) { + StringBuilder ss = new StringBuilder(); + Map mm = (Map) o; + for (String k : mm.keySet()) { + Object v = mm.get(k); + if (v instanceof String) { + String s = escape ? escapeXml((String) v) : (String) v; + ss.append(pad(indent)).append('<').append(k).append('>'); + ss.append(s); + ss.append("').append('\n'); + } else if (v instanceof Map) { + ss.append(pad(indent)).append('<').append(k).append('>').append('\n'); + ss.append(generateXml(v, indent + 1, escape)); + ss.append(pad(indent)).append("').append('\n'); + } else if (v instanceof List) { + List ll = (List) v; + for (Object o1 : ll) { + ss.append(pad(indent)).append('<').append(k).append('>').append('\n'); + ss.append(generateXml(o1, indent + 1, escape)); + ss.append(pad(indent)).append("').append('\n'); + } + } + } + return ss.toString(); + } + + return null; + } + + private static String generateJson(Object o, boolean escape) { + if (o == null) + return null; + + StringBuilder ss = new StringBuilder(); + generateJson(ss, o, 0, false, escape); + return ss.toString(); + } + + @SuppressWarnings("unchecked") + private static void generateJson(StringBuilder ss, Object o, int indent, boolean padFirst, boolean escape) { + if (o instanceof String) { + String s = escape ? escapeJson((String) o) : (String) o; + if (padFirst) + ss.append(pad(indent)); + ss.append('"').append(s).append('"'); + return; + } + + if (o instanceof Map) { + Map mm = (Map) o; + + if (padFirst) + ss.append(pad(indent)); + ss.append("{\n"); + + boolean first = true; + for (String k : mm.keySet()) { + if (!first) + ss.append(",\n"); + first = false; + + Object v = mm.get(k); + ss.append(pad(indent + 1)).append('"').append(k).append("\": "); + generateJson(ss, v, indent + 1, false, escape); + } + + ss.append("\n"); + ss.append(pad(indent)).append('}'); + + return; + } + + if (o instanceof List) { + List ll = (List) o; + + if (padFirst) + ss.append(pad(indent)); + ss.append("[\n"); + + boolean first = true; + for (Object o1 : ll) { + if (!first) + ss.append(",\n"); + first = false; + + generateJson(ss, o1, indent + 1, true, escape); + } + + ss.append("\n"); + ss.append(pad(indent)).append(']'); + } + } + + public static String removeLastCommaJson(String s) { + StringBuilder sb = new StringBuilder(); + int k = 0; + int start = 0; + while (k < s.length()) { + int i11 = s.indexOf('}', k); + int i12 = s.indexOf(']', k); + int i1 = -1; + if (i11 < 0) + i1 = i12; + else if (i12 < 0) + i1 = i11; + else + i1 = i11 < i12 ? i11 : i12; + if (i1 < 0) + break; + + int i2 = s.lastIndexOf(',', i1); + if (i2 < 0) { + k = i1 + 1; + continue; + } + + String between = s.substring(i2 + 1, i1); + if (between.trim().length() > 0) { + k = i1 + 1; + continue; + } + + sb.append(s.substring(start, i2)); + start = i2 + 1; + k = i1 + 1; + } + + sb.append(s.substring(start, s.length())); + + return sb.toString(); + } + + public static String removeEmptyStructJson(String s) { + int k = 0; + while (k < s.length()) { + boolean curly = true; + int i11 = s.indexOf('{', k); + int i12 = s.indexOf('[', k); + int i1 = -1; + if (i11 < 0) { + i1 = i12; + curly = false; + } else if (i12 < 0) + i1 = i11; + else + if (i11 < i12) + i1 = i11; + else { + i1 = i12; + curly = false; + } + + if (i1 >= 0) { + int i2 = curly ? s.indexOf('}', i1) : s.indexOf(']', i1); + if (i2 > 0) { + String value = s.substring(i1 + 1, i2); + if (value.trim().length() == 0) { + int i4 = s.lastIndexOf('\n', i1); + if (i4 < 0) + i4 = 0; + int i5 = s.indexOf('\n', i2); + if (i5 < 0) + i5 = s.length(); + + s = s.substring(0, i4) + s.substring(i5); + k = 0; + } else + k = i1 + 1; + } else + break; + } else + break; + } + + return s; + } + + public static String removeEmptyStructXml(String s) { + int k = 0; + while (k < s.length()) { + int i1 = s.indexOf('<', k); + if (i1 < 0 || i1 == s.length() - 1) + break; + + char c1 = s.charAt(i1 + 1); + if (c1 == '?' || c1 == '!') { + k = i1 + 2; + continue; + } + + int i2 = s.indexOf('>', i1); + if (i2 < 0) { + k = i1 + 1; + continue; + } + + String closingTag = " 0) { + k = i2 + 1; + continue; + } + + int i4 = s.lastIndexOf('\n', i1); + if (i4 < 0) + i4 = 0; + int i5 = s.indexOf('\n', i3); + if (i5 < 0) + i5 = s.length(); + + s = s.substring(0, i4) + s.substring(i5); + k = 0; + } + + return s; + } + + private static String escapeXml(String v) { + String s = v.replaceAll("&", "&"); + s = s.replaceAll("<", "<"); + s = s.replaceAll("'", "'"); + s = s.replaceAll("\"", """); + s = s.replaceAll(">", ">"); + return s; + } + + private static String escapeJson(String v) { + String s = v.replaceAll("\\\\", "\\\\\\\\"); + s = s.replaceAll("\"", "\\\\\""); + return s; + } + + private static String pad(int n) { + String s = ""; + for (int i = 0; i < n; i++) + s += '\t'; + return s; + } } diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlParser.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlParser.java index 8f3febcaf..85c9dc018 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlParser.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlParser.java @@ -39,122 +39,122 @@ import org.xml.sax.helpers.DefaultHandler; public class XmlParser { - private static final Logger log = LoggerFactory.getLogger(XmlParser.class); - - public static Map convertToProperties(String s, Set listNameList) { - Handler handler = new Handler(listNameList); - try { - SAXParserFactory factory = SAXParserFactory.newInstance(); - SAXParser saxParser = factory.newSAXParser(); - InputStream in = new ByteArrayInputStream(s.getBytes()); - saxParser.parse(in, handler); - } catch (Exception e) { - e.printStackTrace(); - } - - return handler.getProperties(); - } - - private static class Handler extends DefaultHandler { - - private Set listNameList; - - private Map properties = new HashMap<>(); - - public Map getProperties() { - return properties; - } - - public Handler(Set listNameList) { - super(); - this.listNameList = listNameList; - if (this.listNameList == null) - this.listNameList = new HashSet(); - } - - String currentName = ""; - String currentValue = ""; - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) - throws SAXException { - super.startElement(uri, localName, qName, attributes); - - String name = localName; - if (name == null || name.trim().length() == 0) - name = qName; - int i2 = name.indexOf(':'); - if (i2 >= 0) - name = name.substring(i2 + 1); - - if (currentName.length() > 0) - currentName += '.'; - currentName += name; - - String listName = removeIndexes(currentName); - - if (listNameList.contains(listName)) { - int len = getInt(properties, currentName + "_length"); - properties.put(currentName + "_length", String.valueOf(len + 1)); - currentName += "[" + len + "]"; - } - } - - @Override - public void endElement(String uri, String localName, String qName) throws SAXException { - super.endElement(uri, localName, qName); - - String name = localName; - if (name == null || name.trim().length() == 0) - name = qName; - int i2 = name.indexOf(':'); - if (i2 >= 0) - name = name.substring(i2 + 1); - - if (currentValue.trim().length() > 0) { - currentValue = currentValue.trim(); - properties.put(currentName, currentValue); - - log.info("Added property: " + currentName + ": " + currentValue); - - currentValue = ""; - } - - int i1 = currentName.lastIndexOf("." + name); - if (i1 <= 0) - currentName = ""; - else - currentName = currentName.substring(0, i1); - } - - @Override - public void characters(char[] ch, int start, int length) throws SAXException { - super.characters(ch, start, length); - - String value = new String(ch, start, length); - currentValue += value; - } - - private static int getInt(Map mm, String name) { - String s = mm.get(name); - if (s == null) - return 0; - return Integer.parseInt(s); - } - - private String removeIndexes(String currentName) { - String s = ""; - boolean add = true; - for (int i = 0; i < currentName.length(); i++) { - char c = currentName.charAt(i); - if (c == '[') - add = false; - else if (c == ']') - add = true; - else if (add) - s += c; - } - return s; - } - } + private static final Logger log = LoggerFactory.getLogger(XmlParser.class); + + public static Map convertToProperties(String s, Set listNameList) { + Handler handler = new Handler(listNameList); + try { + SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParser saxParser = factory.newSAXParser(); + InputStream in = new ByteArrayInputStream(s.getBytes()); + saxParser.parse(in, handler); + } catch (Exception e) { + e.printStackTrace(); + } + + return handler.getProperties(); + } + + private static class Handler extends DefaultHandler { + + private Set listNameList; + + private Map properties = new HashMap<>(); + + public Map getProperties() { + return properties; + } + + public Handler(Set listNameList) { + super(); + this.listNameList = listNameList; + if (this.listNameList == null) + this.listNameList = new HashSet(); + } + + String currentName = ""; + String currentValue = ""; + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + super.startElement(uri, localName, qName, attributes); + + String name = localName; + if (name == null || name.trim().length() == 0) + name = qName; + int i2 = name.indexOf(':'); + if (i2 >= 0) + name = name.substring(i2 + 1); + + if (currentName.length() > 0) + currentName += '.'; + currentName += name; + + String listName = removeIndexes(currentName); + + if (listNameList.contains(listName)) { + int len = getInt(properties, currentName + "_length"); + properties.put(currentName + "_length", String.valueOf(len + 1)); + currentName += "[" + len + "]"; + } + } + + @Override + public void endElement(String uri, String localName, String qName) throws SAXException { + super.endElement(uri, localName, qName); + + String name = localName; + if (name == null || name.trim().length() == 0) + name = qName; + int i2 = name.indexOf(':'); + if (i2 >= 0) + name = name.substring(i2 + 1); + + if (currentValue.trim().length() > 0) { + currentValue = currentValue.trim(); + properties.put(currentName, currentValue); + + log.info("Added property: " + currentName + ": " + currentValue); + + currentValue = ""; + } + + int i1 = currentName.lastIndexOf("." + name); + if (i1 <= 0) + currentName = ""; + else + currentName = currentName.substring(0, i1); + } + + @Override + public void characters(char[] ch, int start, int length) throws SAXException { + super.characters(ch, start, length); + + String value = new String(ch, start, length); + currentValue += value; + } + + private static int getInt(Map mm, String name) { + String s = mm.get(name); + if (s == null) + return 0; + return Integer.parseInt(s); + } + + private String removeIndexes(String currentName) { + String s = ""; + boolean add = true; + for (int i = 0; i < currentName.length(); i++) { + char c = currentName.charAt(i); + if (c == '[') + add = false; + else if (c == ']') + add = true; + else if (add) + s += c; + } + return s; + } + } } diff --git a/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-context.xml b/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-context.xml index 25ce0120a..87850624c 100644 --- a/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-context.xml +++ b/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-context.xml @@ -24,26 +24,26 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - - - + + + file:${SDNC_CONFIG_DIR}/ueb.properties file:${SDNC_CONFIG_DIR}/dme2.properties - - - - + + + + - + - - - - + + + + - - - + + + diff --git a/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-osgi-context.xml b/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-osgi-context.xml index 8f34005d5..2f1e4dbde 100644 --- a/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-osgi-context.xml +++ b/restapi-call-node/provider/src/main/resources/META-INF/spring/restapi-call-node-osgi-context.xml @@ -21,12 +21,12 @@ --> - + diff --git a/restapi-call-node/provider/src/main/resources/default-ueb-message.json b/restapi-call-node/provider/src/main/resources/default-ueb-message.json index 4b1aa0386..6ef6be7f6 100644 --- a/restapi-call-node/provider/src/main/resources/default-ueb-message.json +++ b/restapi-call-node/provider/src/main/resources/default-ueb-message.json @@ -20,13 +20,13 @@ */ { - "event":{ - "header":{ - "eventSource":"sdn-c" - }, - "body": + "event":{ + "header":{ + "eventSource":"sdn-c" + }, + "body": ${rootVarName} - } + } } diff --git a/restapi-call-node/provider/src/main/resources/northbound-api-template.json b/restapi-call-node/provider/src/main/resources/northbound-api-template.json index d48c41ce9..73a61b636 100644 --- a/restapi-call-node/provider/src/main/resources/northbound-api-template.json +++ b/restapi-call-node/provider/src/main/resources/northbound-api-template.json @@ -19,25 +19,25 @@ * ============LICENSE_END========================================================= */ -{ -"input": - { - "sdnc-request-header":{ - "svc-request-id": ${service-topology-operation-input.sdnc-request-header.svc-request-id}, - "svc-notification-url": ${service-topology-operation-input.sdnc-request-header.svc-notification-url} - }, - "request-information":{ - "request-id": ${service-topology-operation-input.request-information.request-id}, - "request-action": ${service-topology-operation-input.request-information.request-action}, - "request-sub-action": ${service-topology-operation-input.request-information.request-sub-action}, - "source": ${service-topology-operation-input.request-information.source}, - "notification-url": ${service-topology-operation-input.request-information.notification-url} - }, - "service-information":{ - "service-type": ${service-topology-operation-input.service-information.service-type}, - "service-instance-id": ${service-topology-operation-input.service-information.service-instance-id}, - "subscriber-name": ${service-topology-operation-input.service-information.subscriber-name}, - "subscriber-global-id": ${service-topology-operation-input.service-information.subscriber-global-id} - } +{ +"input": + { + "sdnc-request-header":{ + "svc-request-id": ${service-topology-operation-input.sdnc-request-header.svc-request-id}, + "svc-notification-url": ${service-topology-operation-input.sdnc-request-header.svc-notification-url} + }, + "request-information":{ + "request-id": ${service-topology-operation-input.request-information.request-id}, + "request-action": ${service-topology-operation-input.request-information.request-action}, + "request-sub-action": ${service-topology-operation-input.request-information.request-sub-action}, + "source": ${service-topology-operation-input.request-information.source}, + "notification-url": ${service-topology-operation-input.request-information.notification-url} + }, + "service-information":{ + "service-type": ${service-topology-operation-input.service-information.service-type}, + "service-instance-id": ${service-topology-operation-input.service-information.service-instance-id}, + "subscriber-name": ${service-topology-operation-input.service-information.subscriber-name}, + "subscriber-global-id": ${service-topology-operation-input.service-information.subscriber-global-id} + } } - + diff --git a/restapi-call-node/provider/src/main/resources/northbound-api-template.xml b/restapi-call-node/provider/src/main/resources/northbound-api-template.xml index 5c2b9ad9a..aea0625c1 100644 --- a/restapi-call-node/provider/src/main/resources/northbound-api-template.xml +++ b/restapi-call-node/provider/src/main/resources/northbound-api-template.xml @@ -37,7 +37,7 @@ ${service-topology-operation-input.service-information.service-type} ${service-topology-operation-input.service-information.subscriber-global-id} ${service-topology-operation-input.service-information.subscriber-name} - + ${'northbound-anyData} diff --git a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java index 107e8c88e..dbca5ad7b 100644 --- a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java +++ b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java @@ -35,31 +35,33 @@ import org.slf4j.LoggerFactory; public class TestJsonParser { - private static final Logger log = LoggerFactory.getLogger(TestJsonParser.class); + private static final Logger log = LoggerFactory.getLogger(TestJsonParser.class); - @Test - public void test() throws Exception { - BufferedReader in = new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream("test.json"))); - String ss = ""; - String line = null; - while ((line = in.readLine()) != null) - ss += line + '\n'; + @Test + public void test() throws Exception { + BufferedReader in = new BufferedReader( + new InputStreamReader(ClassLoader.getSystemResourceAsStream("test.json")) + ); + String ss = ""; + String line = null; + while ((line = in.readLine()) != null) + ss += line + '\n'; - Map mm = JsonParser.convertToProperties(ss); + Map mm = JsonParser.convertToProperties(ss); - logProperties(mm); + logProperties(mm); - in.close(); - } + in.close(); + } - private void logProperties(Map mm) { - List ll = new ArrayList<>(); - for (Object o : mm.keySet()) - ll.add((String) o); - Collections.sort(ll); + private void logProperties(Map mm) { + List ll = new ArrayList<>(); + for (Object o : mm.keySet()) + ll.add((String) o); + Collections.sort(ll); - log.info("Properties:"); - for (String name : ll) - log.info("--- " + name + ": " + mm.get(name)); - } + log.info("Properties:"); + for (String name : ll) + log.info("--- " + name + ": " + mm.get(name)); + } } diff --git a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java index 5b03bff47..ff9714809 100644 --- a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java +++ b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java @@ -32,61 +32,61 @@ import org.slf4j.LoggerFactory; public class TestRestapiCallNode { - private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class); + private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class); - @Test - public void testDelete() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); + @Test + public void testDelete() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); - Map p = new HashMap(); - p.put("restapiUrl", "https://echo.getpostman.com/delete"); - p.put("restapiUser", "user1"); - p.put("restapiPassword", "pwd1"); - p.put("httpMethod", "delete"); - p.put("skipSending", "true"); + Map p = new HashMap(); + p.put("restapiUrl", "https://echo.getpostman.com/delete"); + p.put("restapiUser", "user1"); + p.put("restapiPassword", "pwd1"); + p.put("httpMethod", "delete"); + p.put("skipSending", "true"); - RestapiCallNode rcn = new RestapiCallNode(); - rcn.sendRequest(p, ctx); - } + RestapiCallNode rcn = new RestapiCallNode(); + rcn.sendRequest(p, ctx); + } - @Test - public void testJsonTemplate() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3"); - ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123"); - ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete"); - ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0"); - ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New"); - ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New"); - ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1"); - ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci"); - ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123"); - ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete"); - ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0"); - ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New"); - ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New"); - ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1"); - ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci"); - ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123"); - ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete"); - ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0"); - ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New"); - ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New"); - ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1"); - ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci"); + @Test + public void testJsonTemplate() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3"); + ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123"); + ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete"); + ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0"); + ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New"); + ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New"); + ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1"); + ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci"); + ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123"); + ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete"); + ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0"); + ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New"); + ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New"); + ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1"); + ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci"); + ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123"); + ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete"); + ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0"); + ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New"); + ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New"); + ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1"); + ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci"); - Map p = new HashMap(); - p.put("templateFileName", "src/test/resources/test-template.json"); - p.put("restapiUrl", "http://echo.getpostman.com"); - p.put("restapiUser", "user1"); - p.put("restapiPassword", "abc123"); - p.put("format", "json"); - p.put("httpMethod", "post"); - p.put("responsePrefix", "response"); - p.put("skipSending", "true"); + Map p = new HashMap(); + p.put("templateFileName", "src/test/resources/test-template.json"); + p.put("restapiUrl", "http://echo.getpostman.com"); + p.put("restapiUser", "user1"); + p.put("restapiPassword", "abc123"); + p.put("format", "json"); + p.put("httpMethod", "post"); + p.put("responsePrefix", "response"); + p.put("skipSending", "true"); - RestapiCallNode rcn = new RestapiCallNode(); - rcn.sendRequest(p, ctx); - } + RestapiCallNode rcn = new RestapiCallNode(); + rcn.sendRequest(p, ctx); + } } diff --git a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlJsonUtil.java b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlJsonUtil.java index ad1c34e90..579d194d5 100644 --- a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlJsonUtil.java +++ b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlJsonUtil.java @@ -40,57 +40,98 @@ public class TestXmlJsonUtil { Map mm = new HashMap<>(); mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].vnf-type", "N-SBG"); mm.put("service-data.service-information.service-instance-id", "someinstance001"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].dns-server-ip-address", "10.11.12.13"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].escf-domain-name", "hclab.atttest.com"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].snmp-target-v3_length", "2"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].snmp-target-v3[0].snmp-target-v3-id", "1"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].snmp-target-v3[0].snmp-target-ip-address", "127.0.0.1"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].snmp-target-v3[0].snmp-security-level", "NO_AUTH_NO_PRIV"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].snmp-target-v3[1].snmp-target-v3-id", "2"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].snmp-target-v3[1].snmp-target-ip-address", "192.168.1.8"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].snmp-target-v3[1].snmp-security-level", "NO_AUTH_NO_PRIV"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].dns-ip-address-1", "2001:1890:1001:2224::1"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].dns-ip-address-2", "2001:1890:1001:2424::1"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].diameter-rf-realm-name", "uvp.els-an.att.net"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].diameter-rf-peer-ip-address", "192.168.1.66"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].bgf-controller-ip-address", "192.168.1.186"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].bgf-control-link-name", "mg3/69@192.168.1.226"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].rf-interface-nexthop-ip-address", "10.111.108.150"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].rf-mated-pair-ip-address", "10.111.108.146"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].dns-server-ip-address", "10.11.12.13"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].escf-domain-name", "hclab.atttest.com"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].snmp-target-v3_length", "2"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].snmp-target-v3[0].snmp-target-v3-id", "1"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].snmp-target-v3[0].snmp-target-ip-address", "127.0.0.1"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].snmp-target-v3[0].snmp-security-level", "NO_AUTH_NO_PRIV"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].snmp-target-v3[1].snmp-target-v3-id", "2"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].snmp-target-v3[1].snmp-target-ip-address", "192.168.1.8"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].snmp-target-v3[1].snmp-security-level", "NO_AUTH_NO_PRIV"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].dns-ip-address-1", "2001:1890:1001:2224::1"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].dns-ip-address-2", "2001:1890:1001:2424::1"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].diameter-rf-realm-name", "uvp.els-an.att.net"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].diameter-rf-peer-ip-address", "192.168.1.66"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].bgf-controller-ip-address", "192.168.1.186"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].bgf-control-link-name", "mg3/69@192.168.1.226"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].rf-interface-nexthop-ip-address", "10.111.108.150"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].rf-mated-pair-ip-address", "10.111.108.146"); mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf_length", "4"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[0].network-name", "UvpbUgnAccess1"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[0].sip-pa-termination-ip-address", "10.111.108.146"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].access-net-pcscf[0].network-name", "UvpbUgnAccess1"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].access-net-pcscf[0].sip-pa-termination-ip-address", "10.111.108.146"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[1].network-name", "MIS"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[1].proactive-transcoding-profile", "trinity-transcodingProfile"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[1].next-hop-ip-address", "10.111.108.158"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[1].subnet-mask-length", "10.111.108.154"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].access-net-pcscf[1].network-name", "MIS"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].access-net-pcscf[1].proactive-transcoding-profile", + "trinity-transcodingProfile"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].access-net-pcscf[1].next-hop-ip-address", "10.111.108.158"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].access-net-pcscf[1].subnet-mask-length", "10.111.108.154"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[2].network-name", "AVPN1"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[2].proactive-transcoding-profile", "trinity-transcodingProfile"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[2].next-hop-ip-address", "10.111.108.166"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[2].subnet-mask-length", "10.111.108.162"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].access-net-pcscf[2].network-name", "AVPN1"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].access-net-pcscf[2].proactive-transcoding-profile", + "trinity-transcodingProfile"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].access-net-pcscf[2].next-hop-ip-address", "10.111.108.166"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].access-net-pcscf[2].subnet-mask-length", "10.111.108.162"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[3].network-name", "AVPN1"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[3].proactive-transcoding-profile", "trinity-transcodingProfile"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[3].next-hop-ip-address", "10.129.108.166"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[3].subnet-mask-length", "10.129.108.162"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].access-net-pcscf[3].network-name", "AVPN1"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].access-net-pcscf[3].proactive-transcoding-profile", + "trinity-transcodingProfile"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].access-net-pcscf[3].next-hop-ip-address", "10.129.108.166"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].access-net-pcscf[3].subnet-mask-length", "10.129.108.162"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].core-net-pcscf_length", "1"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].core-net-pcscf_length", "1"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].core-net-pcscf[0].network-name", "Core"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].core-net-pcscf[0].next-hop-ip-address", "10.111.108.142"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].core-net-pcscf[0].sip-pa-termination-ip-address", "10.111.108.138"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].core-net-pcscf[0].network-name", "Core"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].core-net-pcscf[0].next-hop-ip-address", "10.111.108.142"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].core-net-pcscf[0].sip-pa-termination-ip-address", "10.111.108.138"); - mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].mated-pair-fully-qualified-domain-name", "mt1nj01sbg01pyl-mt1nj01sbg02pyl.ar1ga.uvp.els-an.att.net"); + mm.put("service-data.vnf-config-parameters-list." + + "vnf-config-parameters[0].mated-pair-fully-qualified-domain-name", + "mt1nj01sbg01pyl-mt1nj01sbg02pyl.ar1ga.uvp.els-an.att.net"); mm.put("service-data.appc-request-header.svc-request-id", "SOMESERVICEREQUEST123451000"); mm.put("service-data.vnf-config-information.vnf-host-ip-address", "192.168.13.151"); mm.put("service-data.vnf-config-information.vendor", "Netconf"); - mm.put("service-data.vnf-config-information.escape-test", "blah blah \"xxx&nnn<>\\'\"there>blah<&''\"\"123\\\\\\'''blah blah &"); + mm.put("service-data.vnf-config-information.escape-test", + "blah blah \"xxx&nnn<>\\'\"there>blah<&''\"\"123\\\\\\'''blah blah &"); String ss = XmlJsonUtil.getXml(mm, "service-data.vnf-config-parameters-list"); log.info(ss); diff --git a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java index 6d506ccec..544d259e0 100644 --- a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java +++ b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java @@ -37,39 +37,41 @@ import org.slf4j.LoggerFactory; public class TestXmlParser { - private static final Logger log = LoggerFactory.getLogger(TestXmlParser.class); + private static final Logger log = LoggerFactory.getLogger(TestXmlParser.class); - @Test - public void test() throws Exception { - BufferedReader in = new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream("test3.xml"))); - String ss = ""; - String line = null; - while ((line = in.readLine()) != null) - ss += line + '\n'; + @Test + public void test() throws Exception { + BufferedReader in = new BufferedReader( + new InputStreamReader(ClassLoader.getSystemResourceAsStream("test3.xml")) + ); + String ss = ""; + String line = null; + while ((line = in.readLine()) != null) + ss += line + '\n'; - Set listNameList = new HashSet(); - listNameList.add("project.dependencies.dependency"); - listNameList.add("project.build.plugins.plugin"); - listNameList.add("project.build.plugins.plugin.executions.execution"); - listNameList.add("project.build.pluginManagement.plugins.plugin"); - listNameList.add( - "project.build.pluginManagement.plugins.plugin.configuration.lifecycleMappingMetadata.pluginExecutions.pluginExecution"); + Set listNameList = new HashSet(); + listNameList.add("project.dependencies.dependency"); + listNameList.add("project.build.plugins.plugin"); + listNameList.add("project.build.plugins.plugin.executions.execution"); + listNameList.add("project.build.pluginManagement.plugins.plugin"); + listNameList.add("project.build.pluginManagement." + + "plugins.plugin.configuration.lifecycleMappingMetadata.pluginExecutions.pluginExecution"); - Map mm = XmlParser.convertToProperties(ss, listNameList); + Map mm = XmlParser.convertToProperties(ss, listNameList); - logProperties(mm); + logProperties(mm); - in.close(); - } + in.close(); + } - private void logProperties(Map mm) { - List ll = new ArrayList<>(); - for (Object o : mm.keySet()) - ll.add((String) o); - Collections.sort(ll); + private void logProperties(Map mm) { + List ll = new ArrayList<>(); + for (Object o : mm.keySet()) + ll.add((String) o); + Collections.sort(ll); - log.info("Properties:"); - for (String name : ll) - log.info("--- " + name + ": " + mm.get(name)); - } + log.info("Properties:"); + for (String name : ll) + log.info("--- " + name + ": " + mm.get(name)); + } } diff --git a/restapi-call-node/provider/src/test/resources/test.json b/restapi-call-node/provider/src/test/resources/test.json index 885e66028..a34f7e2a0 100644 --- a/restapi-call-node/provider/src/test/resources/test.json +++ b/restapi-call-node/provider/src/test/resources/test.json @@ -20,29 +20,29 @@ */ { - "equipment-data": [ - { - "server-count": "4", - "max-server-speed": "1600000", - "number-primary-servers": "2", - "equipment-id": "Server1", - "server-model": "Unknown", - "server-id": "Server1" - } - ], - "resource-state": { - "threshold-value": "1600000", - "last-added": "1605000", - "used": "1605000", - "limit-value": "1920000" - }, - "resource-rule": { - "endpoint-position": "VCE-Cust", - "soft-limit-expression": "0.6 * max-server-speed * number-primary-servers", - "resource-name": "Bandwidth", - "service-model": "DUMMY", - "hard-limit-expression": "max-server-speed * number-primary-servers", - "equipment-level": "Server" - }, - "message": "The provisioned access bandwidth is at or exceeds 50% of the total server capacity." + "equipment-data": [ + { + "server-count": "4", + "max-server-speed": "1600000", + "number-primary-servers": "2", + "equipment-id": "Server1", + "server-model": "Unknown", + "server-id": "Server1" + } + ], + "resource-state": { + "threshold-value": "1600000", + "last-added": "1605000", + "used": "1605000", + "limit-value": "1920000" + }, + "resource-rule": { + "endpoint-position": "VCE-Cust", + "soft-limit-expression": "0.6 * max-server-speed * number-primary-servers", + "resource-name": "Bandwidth", + "service-model": "DUMMY", + "hard-limit-expression": "max-server-speed * number-primary-servers", + "equipment-level": "Server" + }, + "message": "The provisioned access bandwidth is at or exceeds 50% of the total server capacity." } diff --git a/restapi-call-node/provider/src/test/resources/test.xml b/restapi-call-node/provider/src/test/resources/test.xml index 391c9b3e0..b60b5356e 100644 --- a/restapi-call-node/provider/src/test/resources/test.xml +++ b/restapi-call-node/provider/src/test/resources/test.xml @@ -21,152 +21,152 @@ --> - 4.0.0 - - org.onap.ccsdk.sli.plugins - restapi-call-node - 6.0.0-SNAPSHOT - - restapi-call-node-provider - bundle - RESTAPI Call Node - Provider - http://maven.apache.org - - UTF-8 - - - - junit - junit - test - - - org.springframework - spring-test - 3.1.4.RELEASE - test - - - org.onap.ccsdk.sli - sli-common - compile - - - org.onap.ccsdk.sli - sli-provider - compile - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.slf4j - jcl-over-slf4j - ${slf4j.version} - - - org.springframework - spring-beans - 3.1.4.RELEASE - - - org.springframework - spring-context - 3.1.4.RELEASE - - - xerces - xerces - 2.4.0 - provided - - - com.sun.jersey - jersey-client - 1.17 - - - commons-codec - commons-codec - - + 4.0.0 + + org.onap.ccsdk.sli.plugins + restapi-call-node + 6.0.0-SNAPSHOT + + restapi-call-node-provider + bundle + RESTAPI Call Node - Provider + http://maven.apache.org + + UTF-8 + + + + junit + junit + test + + + org.springframework + spring-test + 3.1.4.RELEASE + test + + + org.onap.ccsdk.sli + sli-common + compile + + + org.onap.ccsdk.sli + sli-provider + compile + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + org.springframework + spring-beans + 3.1.4.RELEASE + + + org.springframework + spring-context + 3.1.4.RELEASE + + + xerces + xerces + 2.4.0 + provided + + + com.sun.jersey + jersey-client + 1.17 + + + commons-codec + commons-codec + + - - - - com.brocade.developer - providermodule-plugin - - org.onap.ccsdk.sli.plugins - restapi-call-node - - - - process-sources - - process - - - - + + + + com.brocade.developer + providermodule-plugin + + org.onap.ccsdk.sli.plugins + restapi-call-node + + + + process-sources + + process + + + + - - org.apache.felix - maven-bundle-plugin - true - - - org.onap.ccsdk.sli.plugins.restapicall - org.onap.ccsdk.sli.plugins.restapicall - * - + + org.apache.felix + maven-bundle-plugin + true + + + org.onap.ccsdk.sli.plugins.restapicall + org.onap.ccsdk.sli.plugins.restapicall + * + - ${project.basedir}/src/main/resources/META-INF + ${project.basedir}/src/main/resources/META-INF - + - + - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - com.brocade.developer - - - providermodule-plugin - - - [1.2.0.100-SNAPSHOT,) - - - process - - - - - - - - - - - - - + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + com.brocade.developer + + + providermodule-plugin + + + [1.2.0.100-SNAPSHOT,) + + + process + + + + + + + + + + + + + diff --git a/restapi-call-node/provider/src/test/resources/test3.xml b/restapi-call-node/provider/src/test/resources/test3.xml index 809a208eb..ade412681 100644 --- a/restapi-call-node/provider/src/test/resources/test3.xml +++ b/restapi-call-node/provider/src/test/resources/test3.xml @@ -21,62 +21,62 @@ --> - - ICOREPVC-81114561 - - VPNL811182 - 811182 - 21302:811182 - SET_BVOIP_IN - SET6_BVOIP_IN - SET6_DSU - SET_DSU - SET6_MANAGED - SET_MANAGED - SET_LOVRF_COMMUNITY - SET_RESET_LP - - AG_MAX_MCASTROUTES - - - - BGP4_PROTOCOL - v4 - gp_21302:811182 - - AG_L3VPN_EBGP - - - AG_MAX_PREFIX - - - AG_BGP_UNMANAGED - - - AG_BFD_BGP_3000 - - - - BGP4_PROTOCOL - v6 - gp6_21302:811182 - - AG6_L3VPN_EBGP - - - AG6_MAX_PREFIX - - - AG6_BGP_UNMANAGED - - - AG6_BFD_BGP_3000 - - - - 200 - Success - Y + xmlns:ns2="http://onap.org/prov/vpn/schema/v2"> + + ICOREPVC-81114561 + + VPNL811182 + 811182 + 21302:811182 + SET_BVOIP_IN + SET6_BVOIP_IN + SET6_DSU + SET_DSU + SET6_MANAGED + SET_MANAGED + SET_LOVRF_COMMUNITY + SET_RESET_LP + + AG_MAX_MCASTROUTES + + + + BGP4_PROTOCOL + v4 + gp_21302:811182 + + AG_L3VPN_EBGP + + + AG_MAX_PREFIX + + + AG_BGP_UNMANAGED + + + AG_BFD_BGP_3000 + + + + BGP4_PROTOCOL + v6 + gp6_21302:811182 + + AG6_L3VPN_EBGP + + + AG6_MAX_PREFIX + + + AG6_BGP_UNMANAGED + + + AG6_BFD_BGP_3000 + + + + 200 + Success + Y - + -- cgit 1.2.3-korg From 02e1594ffee2231523d0486a5d8b590ff09581df Mon Sep 17 00:00:00 2001 From: Gaurav Agrawal Date: Tue, 19 Sep 2017 17:40:54 +0530 Subject: Refinements to RestApiCall plugin Changes includes: 1) Check for null in JsonParser.convertToProperties() which can otherwise result in null pointer exception 2) Use logger built-in string formatting rather then string concatenation 3) Use StringBuilder for multiple string concatenations 4) Making utility classes final and defines private constructor for them 5) Added testcases/testpoints https://sonar.onap.org/component_issues/index?id=org.onap.ccsdk.sli.plugins%3Accsdk-sli-plugins#resolved=false|severities=CRITICAL Change-Id: Ic047b6d0369827a38a98c52e8365f1fe7266840f Issue-Id: CCSDK-67 Signed-off-by: Gaurav Agrawal --- .../ccsdk/sli/plugins/restapicall/JsonParser.java | 85 ++++++++++++---------- .../ccsdk/sli/plugins/restapicall/XmlJsonUtil.java | 14 ++-- .../ccsdk/sli/plugins/restapicall/XmlParser.java | 62 +++++++++------- .../sli/plugins/restapicall/TestJsonParser.java | 20 +++-- .../sli/plugins/restapicall/TestXmlParser.java | 10 +-- .../provider/src/test/resources/test.json | 5 +- 6 files changed, 114 insertions(+), 82 deletions(-) (limited to 'restapi-call-node/provider/src/test/resources/test.json') diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/JsonParser.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/JsonParser.java index f2867f5a3..4a1dfef50 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/JsonParser.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/JsonParser.java @@ -21,6 +21,8 @@ package org.onap.ccsdk.sli.plugins.restapicall; +import static com.google.common.base.Preconditions.checkNotNull; + import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -29,57 +31,64 @@ import java.util.Map; import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class JsonParser { +public final class JsonParser { private static final Logger log = LoggerFactory.getLogger(JsonParser.class); - @SuppressWarnings("unchecked") - public static Map convertToProperties(String s) throws JSONException { - JSONObject json = new JSONObject(s); - - Map wm = new HashMap<>(); - Iterator ii = json.keys(); - while (ii.hasNext()) { - String key1 = ii.next(); - wm.put(key1, json.get(key1)); - } - - Map mm = new HashMap<>(); + private JsonParser() { + // Preventing instantiation of the same. + } - while (!wm.isEmpty()) - for (String key : new ArrayList<>(wm.keySet())) { - Object o = wm.get(key); - wm.remove(key); + @SuppressWarnings("unchecked") + public static Map convertToProperties(String s) + throws SvcLogicException { + + checkNotNull(s, "Input should not be null."); + + try { + JSONObject json = new JSONObject(s); + Map wm = new HashMap<>(); + Iterator ii = json.keys(); + while (ii.hasNext()) { + String key1 = ii.next(); + wm.put(key1, json.get(key1)); + } - if (o instanceof Boolean || o instanceof Number || o instanceof String) { - mm.put(key, o.toString()); + Map mm = new HashMap<>(); - log.info("Added property: " + key + ": " + o.toString()); - } + while (!wm.isEmpty()) + for (String key : new ArrayList<>(wm.keySet())) { + Object o = wm.get(key); + wm.remove(key); - else if (o instanceof JSONObject) { - JSONObject jo = (JSONObject) o; - Iterator i = jo.keys(); - while (i.hasNext()) { - String key1 = i.next(); - wm.put(key + "." + key1, jo.get(key1)); - } - } + if (o instanceof Boolean || o instanceof Number || o instanceof String) { + mm.put(key, o.toString()); - else if (o instanceof JSONArray) { - JSONArray ja = (JSONArray) o; - mm.put(key + "_length", String.valueOf(ja.length())); + log.info("Added property: {} : {}", key, o.toString()); + } else if (o instanceof JSONObject) { + JSONObject jo = (JSONObject) o; + Iterator i = jo.keys(); + while (i.hasNext()) { + String key1 = i.next(); + wm.put(key + "." + key1, jo.get(key1)); + } + } else if (o instanceof JSONArray) { + JSONArray ja = (JSONArray) o; + mm.put(key + "_length", String.valueOf(ja.length())); - log.info("Added property: " + key + "_length" + ": " + String.valueOf(ja.length())); + log.info("Added property: {}_length: {}", key, String.valueOf(ja.length())); - for (int i = 0; i < ja.length(); i++) - wm.put(key + '[' + i + ']', ja.get(i)); + for (int i = 0; i < ja.length(); i++) + wm.put(key + '[' + i + ']', ja.get(i)); + } } - } - - return mm; + return mm; + } catch (JSONException e) { + throw new SvcLogicException("Unable to convert JSON to properties" + e.getLocalizedMessage(), e); + } } } diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java index e80ca5081..b94f0a638 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlJsonUtil.java @@ -29,10 +29,14 @@ import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class XmlJsonUtil { +public final class XmlJsonUtil { private static final Logger log = LoggerFactory.getLogger(XmlJsonUtil.class); + private XmlJsonUtil() { + // Preventing instantiation of the same. + } + public static String getXml(Map varmap, String var) { boolean escape = true; if (var.startsWith("'")) { @@ -99,7 +103,7 @@ public class XmlJsonUtil { try { length = Integer.parseInt(lengthStr); } catch (Exception e) { - log.warn("Invalid number for " + var + "_length:" + lengthStr); + log.warn("Invalid number for {}_length:{}", var, lengthStr); } } @@ -364,9 +368,9 @@ public class XmlJsonUtil { } private static String pad(int n) { - String s = ""; + StringBuilder s = new StringBuilder(); for (int i = 0; i < n; i++) - s += Character.toString('\t'); - return s; + s.append(Character.toString('\t')); + return s.toString(); } } diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlParser.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlParser.java index 61b0e31d4..7ef776da1 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlParser.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/XmlParser.java @@ -21,37 +21,49 @@ package org.onap.ccsdk.sli.plugins.restapicall; +import static com.google.common.base.Preconditions.checkNotNull; + import java.io.ByteArrayInputStream; +import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; -public class XmlParser { +public final class XmlParser { private static final Logger log = LoggerFactory.getLogger(XmlParser.class); - public static Map convertToProperties(String s, Set listNameList) { + private XmlParser() { + // Preventing instantiation of the same. + } + + public static Map convertToProperties(String s, Set listNameList) + throws SvcLogicException { + + checkNotNull(s, "Input should not be null."); + Handler handler = new Handler(listNameList); try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); InputStream in = new ByteArrayInputStream(s.getBytes()); saxParser.parse(in, handler); - } catch (Exception e) { - e.printStackTrace(); + } catch (ParserConfigurationException | IOException | SAXException e) { + throw new SvcLogicException("Unable to convert XML to properties" + e.getLocalizedMessage(), e); } - return handler.getProperties(); } @@ -72,8 +84,8 @@ public class XmlParser { this.listNameList = new HashSet<>(); } - String currentName = ""; - String currentValue = ""; + StringBuilder currentName = new StringBuilder(); + StringBuilder currentValue = new StringBuilder(); @Override public void startElement(String uri, String localName, String qName, Attributes attributes) @@ -88,15 +100,16 @@ public class XmlParser { name = name.substring(i2 + 1); if (currentName.length() > 0) - currentName += Character.toString('.'); - currentName += name; + currentName.append(Character.toString('.')); + currentName.append(name); - String listName = removeIndexes(currentName); + String listName = removeIndexes(currentName.toString()); if (listNameList.contains(listName)) { - int len = getInt(properties, currentName + "_length"); - properties.put(currentName + "_length", String.valueOf(len + 1)); - currentName += "[" + len + "]"; + String n = currentName.toString() + "_length"; + int len = getInt(properties, n); + properties.put(n, String.valueOf(len + 1)); + currentName.append("[").append(len).append("]"); } } @@ -111,20 +124,19 @@ public class XmlParser { if (i2 >= 0) name = name.substring(i2 + 1); - if (currentValue.trim().length() > 0) { - currentValue = currentValue.trim(); - properties.put(currentName, currentValue); - - log.info("Added property: " + currentName + ": " + currentValue); + String s = currentValue.toString().trim(); + if (s.length() > 0) { + properties.put(currentName.toString(), s); - currentValue = ""; + log.info("Added property: {} : {}", currentName, s); + currentValue = new StringBuilder(); } int i1 = currentName.lastIndexOf("." + name); if (i1 <= 0) - currentName = ""; + currentName = new StringBuilder(); else - currentName = currentName.substring(0, i1); + currentName = new StringBuilder(currentName.substring(0, i1)); } @Override @@ -132,7 +144,7 @@ public class XmlParser { super.characters(ch, start, length); String value = new String(ch, start, length); - currentValue += value; + currentValue.append(value); } private static int getInt(Map mm, String name) { @@ -143,7 +155,7 @@ public class XmlParser { } private String removeIndexes(String currentName) { - String s = ""; + StringBuilder b = new StringBuilder(); boolean add = true; for (int i = 0; i < currentName.length(); i++) { char c = currentName.charAt(i); @@ -152,9 +164,9 @@ public class XmlParser { else if (c == ']') add = true; else if (add) - s += Character.toString(c); + b.append(Character.toString(c)); } - return s; + return b.toString(); } } } diff --git a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java index dbca5ad7b..5526be81f 100644 --- a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java +++ b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java @@ -22,6 +22,7 @@ package jtest.org.onap.ccsdk.sli.plugins.restapicall; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; @@ -29,6 +30,7 @@ import java.util.List; import java.util.Map; import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.onap.ccsdk.sli.plugins.restapicall.JsonParser; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,30 +40,34 @@ public class TestJsonParser { private static final Logger log = LoggerFactory.getLogger(TestJsonParser.class); @Test - public void test() throws Exception { + public void test() throws SvcLogicException, IOException { BufferedReader in = new BufferedReader( new InputStreamReader(ClassLoader.getSystemResourceAsStream("test.json")) ); - String ss = ""; - String line = null; + StringBuilder b = new StringBuilder(); + String line; while ((line = in.readLine()) != null) - ss += line + '\n'; + b.append(line).append('\n'); - Map mm = JsonParser.convertToProperties(ss); + Map mm = JsonParser.convertToProperties(b.toString()); logProperties(mm); in.close(); } + @Test(expected = NullPointerException.class) + public void testNullString() throws SvcLogicException { + JsonParser.convertToProperties(null); + } + private void logProperties(Map mm) { List ll = new ArrayList<>(); for (Object o : mm.keySet()) ll.add((String) o); Collections.sort(ll); - log.info("Properties:"); for (String name : ll) - log.info("--- " + name + ": " + mm.get(name)); + log.info("--- {}: {}", name, mm.get(name)); } } diff --git a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java index 544d259e0..e8567d591 100644 --- a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java +++ b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java @@ -44,10 +44,10 @@ public class TestXmlParser { BufferedReader in = new BufferedReader( new InputStreamReader(ClassLoader.getSystemResourceAsStream("test3.xml")) ); - String ss = ""; - String line = null; + StringBuilder b = new StringBuilder(); + String line; while ((line = in.readLine()) != null) - ss += line + '\n'; + b.append(line).append('\n'); Set listNameList = new HashSet(); listNameList.add("project.dependencies.dependency"); @@ -57,10 +57,8 @@ public class TestXmlParser { listNameList.add("project.build.pluginManagement." + "plugins.plugin.configuration.lifecycleMappingMetadata.pluginExecutions.pluginExecution"); - Map mm = XmlParser.convertToProperties(ss, listNameList); - + Map mm = XmlParser.convertToProperties(b.toString(), listNameList); logProperties(mm); - in.close(); } diff --git a/restapi-call-node/provider/src/test/resources/test.json b/restapi-call-node/provider/src/test/resources/test.json index a34f7e2a0..b48eb6b43 100644 --- a/restapi-call-node/provider/src/test/resources/test.json +++ b/restapi-call-node/provider/src/test/resources/test.json @@ -27,7 +27,10 @@ "number-primary-servers": "2", "equipment-id": "Server1", "server-model": "Unknown", - "server-id": "Server1" + "server-id": "Server1", + "test-node" : { + "test-inner-node" : "Test-Value" + } } ], "resource-state": { -- cgit 1.2.3-korg From c185a9bf56303dc4ad9feb4ba5b6227a038f4153 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Thu, 19 Dec 2019 11:07:59 -0500 Subject: Fixing JSONParser for JSONArray element Refactoring Related JUnit and fixing test JSON Files Change-Id: I1cd7ba04f53798e4b3f5451de6bfed24054d3ea5 Issue-ID: CCSDK-2008 Signed-off-by: Singal, Kapil (ks220y) --- .../ccsdk/sli/plugins/restapicall/JsonParser.java | 57 ++++++++++++++-------- .../src/main/resources/actokentemplate.json | 21 -------- .../src/main/resources/default-ueb-message.json | 21 -------- .../src/main/resources/get-multicast-data.json | 21 -------- .../main/resources/l2-dci-connects-template.json | 18 ------- .../main/resources/l3-dci-connects-template.json | 20 -------- .../src/main/resources/l3smsitetemplate.json | 21 -------- .../src/main/resources/l3smvpntemplate.json | 21 -------- .../src/main/resources/l3smvrftemplate.json | 21 -------- .../main/resources/northbound-api-template.json | 21 -------- ...iguration-notification-northbound-template.json | 21 -------- .../src/main/resources/sptn-l3vpn-template.json | 21 -------- .../update-vpe-data-with-apply-group.json | 21 -------- .../src/main/resources/vnf-information-update.json | 21 -------- .../src/main/resources/vpn-allocation-request.json | 21 -------- .../src/main/resources/vpn-information-update.json | 25 +--------- ...service-configuration-information-template.json | 25 +--------- .../resources/vrf-update-vlan-status-template.json | 21 -------- .../provider/src/main/resources/vrf-update.json | 25 +--------- .../sli/plugins/restapicall/TestJsonParser.java | 18 ++----- .../plugins/restapicall/TestRestapiCallNode.java | 15 +++--- .../src/test/resources/actokentemplate.json | 21 -------- .../test/resources/l2-dci-connects-template.json | 18 ------- .../test/resources/l3-dci-connects-template.json | 20 -------- .../src/test/resources/l3smsitetemplate.json | 21 -------- .../src/test/resources/l3smvpntemplate.json | 21 -------- .../src/test/resources/l3smvrftemplate.json | 21 -------- .../provider/src/test/resources/test-template.json | 21 -------- .../provider/src/test/resources/test.json | 21 -------- 29 files changed, 56 insertions(+), 584 deletions(-) (limited to 'restapi-call-node/provider/src/test/resources/test.json') diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/JsonParser.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/JsonParser.java index 910baf52b..4c3ba7f8e 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/JsonParser.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/JsonParser.java @@ -10,7 +10,7 @@ * 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. @@ -21,13 +21,10 @@ package org.onap.ccsdk.sli.plugins.restapicall; -import static com.google.common.base.Preconditions.checkNotNull; - import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Map; - import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; @@ -35,6 +32,8 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static com.google.common.base.Preconditions.checkNotNull; + public final class JsonParser { private static final Logger log = LoggerFactory.getLogger(JsonParser.class); @@ -45,34 +44,51 @@ public final class JsonParser { @SuppressWarnings("unchecked") public static Map convertToProperties(String s) - throws SvcLogicException { + throws SvcLogicException { checkNotNull(s, "Input should not be null."); try { - JSONObject json = null; + Map wm = new HashMap<>(); + String topLvlArrLength = null; + JSONObject json; + JSONArray jsonArr; //support top level list in json response if (s.startsWith("[")) { - JSONArray jsonArr = new JSONArray(s); - json = jsonArr.getJSONObject(0); + jsonArr = new JSONArray(s); + topLvlArrLength = String.valueOf(jsonArr.length()); + for (int i = 0, length = jsonArr.length(); i < length; i++) { + json = jsonArr.getJSONObject(i); + Iterator ii = json.keys(); + while (ii.hasNext()) { + String key = ii.next(); + String key1 = "[" + i + "]." + key; + String[] subKey = key1.split(":"); + if (subKey.length == 2) { + wm.put(subKey[1], json.get(key)); + } else { + wm.put(key1, json.get(key)); + } + } + } } else { json = new JSONObject(s); - } - - Map wm = new HashMap<>(); - Iterator ii = json.keys(); - while (ii.hasNext()) { - String key1 = ii.next(); - String[] subKey = key1.split(":"); - if (subKey.length == 2) { - wm.put(subKey[1], json.get(key1)); - } else { - wm.put(key1, json.get(key1)); + Iterator ii = json.keys(); + while (ii.hasNext()) { + String key1 = ii.next(); + String[] subKey = key1.split(":"); + if (subKey.length == 2) { + wm.put(subKey[1], json.get(key1)); + } else { + wm.put(key1, json.get(key1)); + } } } Map mm = new HashMap<>(); - + if (topLvlArrLength != null) { + mm.put("_length", topLvlArrLength); + } while (!wm.isEmpty()) { for (String key : new ArrayList<>(wm.keySet())) { Object o = wm.get(key); @@ -111,4 +127,5 @@ public final class JsonParser { throw new SvcLogicException("Unable to convert JSON to properties" + e.getLocalizedMessage(), e); } } + } diff --git a/restapi-call-node/provider/src/main/resources/actokentemplate.json b/restapi-call-node/provider/src/main/resources/actokentemplate.json index 31bf0ee2b..02e62400f 100644 --- a/restapi-call-node/provider/src/main/resources/actokentemplate.json +++ b/restapi-call-node/provider/src/main/resources/actokentemplate.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "userName": ${prop.sdncRestApi.thirdpartySdnc.user}, "password": ${prop.sdncRestApi.thirdpartySdnc.password} diff --git a/restapi-call-node/provider/src/main/resources/default-ueb-message.json b/restapi-call-node/provider/src/main/resources/default-ueb-message.json index 6ef6be7f6..484d872f5 100644 --- a/restapi-call-node/provider/src/main/resources/default-ueb-message.json +++ b/restapi-call-node/provider/src/main/resources/default-ueb-message.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "event":{ "header":{ diff --git a/restapi-call-node/provider/src/main/resources/get-multicast-data.json b/restapi-call-node/provider/src/main/resources/get-multicast-data.json index f6155ee32..3b9997f64 100644 --- a/restapi-call-node/provider/src/main/resources/get-multicast-data.json +++ b/restapi-call-node/provider/src/main/resources/get-multicast-data.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "input": { "sdnc-request-header": { diff --git a/restapi-call-node/provider/src/main/resources/l2-dci-connects-template.json b/restapi-call-node/provider/src/main/resources/l2-dci-connects-template.json index f18075686..e0896bbaa 100644 --- a/restapi-call-node/provider/src/main/resources/l2-dci-connects-template.json +++ b/restapi-call-node/provider/src/main/resources/l2-dci-connects-template.json @@ -1,21 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SDN-C - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - { "l2-dci-connect": { "id": ${prop.dci-connects.id}, diff --git a/restapi-call-node/provider/src/main/resources/l3-dci-connects-template.json b/restapi-call-node/provider/src/main/resources/l3-dci-connects-template.json index c011b077b..41df794fd 100644 --- a/restapi-call-node/provider/src/main/resources/l3-dci-connects-template.json +++ b/restapi-call-node/provider/src/main/resources/l3-dci-connects-template.json @@ -1,23 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SDN-C - * ================================================================================ - * Copyright (C) 2017 Intel Corp. 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. - * ============LICENSE_END========================================================= - */ - { "l3-dci-connect": { "id": ${prop.dci-connects.id}, diff --git a/restapi-call-node/provider/src/main/resources/l3smsitetemplate.json b/restapi-call-node/provider/src/main/resources/l3smsitetemplate.json index 016879c3c..8f8156698 100644 --- a/restapi-call-node/provider/src/main/resources/l3smsitetemplate.json +++ b/restapi-call-node/provider/src/main/resources/l3smsitetemplate.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "site":[ { diff --git a/restapi-call-node/provider/src/main/resources/l3smvpntemplate.json b/restapi-call-node/provider/src/main/resources/l3smvpntemplate.json index 67f127ce9..30f30a24f 100644 --- a/restapi-call-node/provider/src/main/resources/l3smvpntemplate.json +++ b/restapi-call-node/provider/src/main/resources/l3smvpntemplate.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "vpn-service": [ { diff --git a/restapi-call-node/provider/src/main/resources/l3smvrftemplate.json b/restapi-call-node/provider/src/main/resources/l3smvrftemplate.json index 732af278c..52359a7fd 100644 --- a/restapi-call-node/provider/src/main/resources/l3smvrftemplate.json +++ b/restapi-call-node/provider/src/main/resources/l3smvrftemplate.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "vrf-attribute": [ { diff --git a/restapi-call-node/provider/src/main/resources/northbound-api-template.json b/restapi-call-node/provider/src/main/resources/northbound-api-template.json index 73a61b636..f185c8f5d 100644 --- a/restapi-call-node/provider/src/main/resources/northbound-api-template.json +++ b/restapi-call-node/provider/src/main/resources/northbound-api-template.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "input": { diff --git a/restapi-call-node/provider/src/main/resources/service-configuration-notification-northbound-template.json b/restapi-call-node/provider/src/main/resources/service-configuration-notification-northbound-template.json index 0cb7d0b06..c64661720 100644 --- a/restapi-call-node/provider/src/main/resources/service-configuration-notification-northbound-template.json +++ b/restapi-call-node/provider/src/main/resources/service-configuration-notification-northbound-template.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "input": { "svc-request-id": ${service-configuration-notification-input.svc-request-id}, diff --git a/restapi-call-node/provider/src/main/resources/sptn-l3vpn-template.json b/restapi-call-node/provider/src/main/resources/sptn-l3vpn-template.json index 9e1e92068..e850cb9a0 100644 --- a/restapi-call-node/provider/src/main/resources/sptn-l3vpn-template.json +++ b/restapi-call-node/provider/src/main/resources/sptn-l3vpn-template.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "snc-l3vpn": { "-xmlns": "urn:chinamobile:l3vpn", diff --git a/restapi-call-node/provider/src/main/resources/update-vpe-data-with-apply-group.json b/restapi-call-node/provider/src/main/resources/update-vpe-data-with-apply-group.json index a82a6b4a6..979857521 100644 --- a/restapi-call-node/provider/src/main/resources/update-vpe-data-with-apply-group.json +++ b/restapi-call-node/provider/src/main/resources/update-vpe-data-with-apply-group.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "vrf-export-details": [ ${repeat:restapi-result.ApplyGroupResponse.ApplyGroupResponseData[0].VrfDetails.VrfExport_length: diff --git a/restapi-call-node/provider/src/main/resources/vnf-information-update.json b/restapi-call-node/provider/src/main/resources/vnf-information-update.json index 425f0f3d7..d554624c7 100644 --- a/restapi-call-node/provider/src/main/resources/vnf-information-update.json +++ b/restapi-call-node/provider/src/main/resources/vnf-information-update.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "generic-vnf-service" :${vnf-service.generic-vnf-service} } diff --git a/restapi-call-node/provider/src/main/resources/vpn-allocation-request.json b/restapi-call-node/provider/src/main/resources/vpn-allocation-request.json index 6c8427495..7a689bd5c 100644 --- a/restapi-call-node/provider/src/main/resources/vpn-allocation-request.json +++ b/restapi-call-node/provider/src/main/resources/vpn-allocation-request.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "AllocateVpnResourcesRequest": { "message-id": "${service-data.oper-status.modify-timestamp}", diff --git a/restapi-call-node/provider/src/main/resources/vpn-information-update.json b/restapi-call-node/provider/src/main/resources/vpn-information-update.json index 7977066bd..3ac16e291 100644 --- a/restapi-call-node/provider/src/main/resources/vpn-information-update.json +++ b/restapi-call-node/provider/src/main/resources/vpn-information-update.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - -{ -"vpn-information" :${vpe-vpn-service.vpn-information} +{ +"vpn-information" :${vpe-vpn-service.vpn-information} } diff --git a/restapi-call-node/provider/src/main/resources/vrf-service-configuration-information-template.json b/restapi-call-node/provider/src/main/resources/vrf-service-configuration-information-template.json index f7e843246..c6defb405 100644 --- a/restapi-call-node/provider/src/main/resources/vrf-service-configuration-information-template.json +++ b/restapi-call-node/provider/src/main/resources/vrf-service-configuration-information-template.json @@ -1,32 +1,11 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "input": { - + "e2e-vpn-key": ${service-data.avpn-logicalchannel-information.e2e-vpn-id}, "logical-channel-id": ${service-data.service-information.service-instance-id}, "vpe-name": ${service-data.avpn-logicalchannel-information.evc-endpoint-information.vpe-name}, "rpc-action": ${tmp.rpc-action}, - + "vpn-information": ${vpe-vpn-service.vpn-information}, "vrf-details": ${vpe-vpn-service.vpn-information.vrf-details}, "vrf-vlan-resources": { diff --git a/restapi-call-node/provider/src/main/resources/vrf-update-vlan-status-template.json b/restapi-call-node/provider/src/main/resources/vrf-update-vlan-status-template.json index 7a6cab35e..f6381256f 100644 --- a/restapi-call-node/provider/src/main/resources/vrf-update-vlan-status-template.json +++ b/restapi-call-node/provider/src/main/resources/vrf-update-vlan-status-template.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "input": { "e2e-vpn-key": ${service-data.avpn-logicalchannel-information.e2e-vpn-id}, diff --git a/restapi-call-node/provider/src/main/resources/vrf-update.json b/restapi-call-node/provider/src/main/resources/vrf-update.json index 778e4b294..cdaef4d82 100644 --- a/restapi-call-node/provider/src/main/resources/vrf-update.json +++ b/restapi-call-node/provider/src/main/resources/vrf-update.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "vpn-vame": ${allocate-vpn-resource-notification-input.vpn-data[0].vpn-name}, "vpn-id": ${allocate-vpn-resource-notification-input.vpn-data[0].vpn-id}, @@ -63,7 +42,7 @@ "spoke-routes": { "route-target": ${allocate-vpn-resource-notification-input.vpn-data[0].spoke-route-target.route-target} }, - + "route-target-details": [ ${repeat:allocate-vpn-resource-notification-input.vpn-data[0].route-target-details_length: { @@ -72,6 +51,6 @@ } } ], - + "e2e-vpn-key": ${allocate-vpn-resource-notification-input.vpn-data[0].e2e-vpn-id} } diff --git a/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java b/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java index 21b66b221..569719d6c 100644 --- a/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java +++ b/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java @@ -8,9 +8,9 @@ * 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. @@ -68,14 +68,7 @@ public class TestJsonParser { String path = "src/test/resources/ArrayMenu.json"; String content = new String(Files.readAllBytes(Paths.get(path))); Map mm = JsonParser.convertToProperties(content); - assertEquals("plain", mm.get("name")); - assertEquals("true", mm.get("vegetarian")); - assertEquals("1", mm.get("id")); - assertEquals("1000", mm.get("calories")); - assertEquals("pizza", mm.get("type")); - - // The below statements are how I expected it to work, but it does not work this way -/* + assertEquals("1000", mm.get("[0].calories")); assertEquals("1", mm.get("[0].id")); assertEquals("plain", mm.get("[0].name")); @@ -104,7 +97,6 @@ public class TestJsonParser { assertEquals("pizza", mm.get("[2].type")); assertEquals("true", mm.get("[2].vegetarian")); assertEquals("3", mm.get("_length")); -*/ } @Test @@ -222,8 +214,8 @@ public class TestJsonParser { // Break the embedded json object into properties mm = JsonParser.convertToProperties(mm.get("input.parameters[0].value")); - assertEquals("0.2.0.0/16", mm.get("id")); - // assertEquals("ge04::/64", mm.get("id")); this second value gets lost + assertEquals("0.2.0.0/16", mm.get("[0].id")); + assertEquals("ge04::/64", mm.get("[1].id")); } } diff --git a/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java b/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java index 0704d297a..8cabaadcf 100755 --- a/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java +++ b/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java @@ -29,15 +29,11 @@ import java.util.HashMap; import java.util.Map; import org.codehaus.jettison.json.JSONObject; -import org.glassfish.grizzly.http.server.HttpServer; -import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; -import org.glassfish.jersey.media.multipart.MultiPartFeature; -import org.glassfish.jersey.server.ResourceConfig; +import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,6 +42,11 @@ public class TestRestapiCallNode { @SuppressWarnings("unused") private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class); + @Before + public void init() { + System.setProperty("SDNC_CONFIG_DIR", "src/test/resources"); + } + @Test public void testDelete() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); @@ -476,7 +477,7 @@ public class TestRestapiCallNode { assertEquals(partnerTwoUsername,details.username); assertEquals(partnerTwoPassword,details.password); assertNull(rcn.partnerStore.get("partnerThree")); - + //In this scenario the caller expects username, password and url to be picked up from the partners json Map paramMap = new HashMap(); paramMap.put("partner", partnerTwoKey); @@ -497,7 +498,7 @@ public class TestRestapiCallNode { assertEquals(partnerTwoPassword,p.restapiPassword); assertEquals("http://localhost:7002/networking/v1/instance/3",p.restapiUrl); } - + @Test public void retryPolicyBean() throws Exception { Integer retries = 3; diff --git a/restapi-call-node/provider/src/test/resources/actokentemplate.json b/restapi-call-node/provider/src/test/resources/actokentemplate.json index 31bf0ee2b..02e62400f 100644 --- a/restapi-call-node/provider/src/test/resources/actokentemplate.json +++ b/restapi-call-node/provider/src/test/resources/actokentemplate.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "userName": ${prop.sdncRestApi.thirdpartySdnc.user}, "password": ${prop.sdncRestApi.thirdpartySdnc.password} diff --git a/restapi-call-node/provider/src/test/resources/l2-dci-connects-template.json b/restapi-call-node/provider/src/test/resources/l2-dci-connects-template.json index f18075686..e0896bbaa 100644 --- a/restapi-call-node/provider/src/test/resources/l2-dci-connects-template.json +++ b/restapi-call-node/provider/src/test/resources/l2-dci-connects-template.json @@ -1,21 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SDN-C - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - { "l2-dci-connect": { "id": ${prop.dci-connects.id}, diff --git a/restapi-call-node/provider/src/test/resources/l3-dci-connects-template.json b/restapi-call-node/provider/src/test/resources/l3-dci-connects-template.json index c011b077b..41df794fd 100644 --- a/restapi-call-node/provider/src/test/resources/l3-dci-connects-template.json +++ b/restapi-call-node/provider/src/test/resources/l3-dci-connects-template.json @@ -1,23 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SDN-C - * ================================================================================ - * Copyright (C) 2017 Intel Corp. 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. - * ============LICENSE_END========================================================= - */ - { "l3-dci-connect": { "id": ${prop.dci-connects.id}, diff --git a/restapi-call-node/provider/src/test/resources/l3smsitetemplate.json b/restapi-call-node/provider/src/test/resources/l3smsitetemplate.json index 016879c3c..8f8156698 100644 --- a/restapi-call-node/provider/src/test/resources/l3smsitetemplate.json +++ b/restapi-call-node/provider/src/test/resources/l3smsitetemplate.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "site":[ { diff --git a/restapi-call-node/provider/src/test/resources/l3smvpntemplate.json b/restapi-call-node/provider/src/test/resources/l3smvpntemplate.json index 67f127ce9..30f30a24f 100644 --- a/restapi-call-node/provider/src/test/resources/l3smvpntemplate.json +++ b/restapi-call-node/provider/src/test/resources/l3smvpntemplate.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "vpn-service": [ { diff --git a/restapi-call-node/provider/src/test/resources/l3smvrftemplate.json b/restapi-call-node/provider/src/test/resources/l3smvrftemplate.json index 732af278c..52359a7fd 100644 --- a/restapi-call-node/provider/src/test/resources/l3smvrftemplate.json +++ b/restapi-call-node/provider/src/test/resources/l3smvrftemplate.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "vrf-attribute": [ { diff --git a/restapi-call-node/provider/src/test/resources/test-template.json b/restapi-call-node/provider/src/test/resources/test-template.json index faefef31e..ae519a731 100644 --- a/restapi-call-node/provider/src/test/resources/test-template.json +++ b/restapi-call-node/provider/src/test/resources/test-template.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "sdn-circuit-request": [ ${repeat:tmp.sdn-circuit-req-row_length: diff --git a/restapi-call-node/provider/src/test/resources/test.json b/restapi-call-node/provider/src/test/resources/test.json index b48eb6b43..75155393c 100644 --- a/restapi-call-node/provider/src/test/resources/test.json +++ b/restapi-call-node/provider/src/test/resources/test.json @@ -1,24 +1,3 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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. - * ============LICENSE_END========================================================= - */ - { "equipment-data": [ { -- cgit 1.2.3-korg