aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Aharoni <pa0916@att.com>2017-06-08 12:26:00 +0300
committerPavel Aharoni <pa0916@att.com>2017-06-08 12:26:00 +0300
commit6b61b88108c5d35efb61cd1006d0a3b9db9d35bf (patch)
tree85c77d3d6e944f58ba6a9b3a5e9ac3778658d5a2
parent9b5e11ba43f82c87623e05671a96a4ce0aedfde7 (diff)
[SDC-30] SDC-TOSCA initial commit
Change-Id: I1048701a6f4a2e14cb37ecc6205b07ffce8af38f Signed-off-by: Pavel Aharoni <pa0916@att.com>
-rw-r--r--.gitignore20
-rw-r--r--.gitreview4
-rw-r--r--LICENSE.TXT21
-rw-r--r--README.md28
-rw-r--r--pom.xml309
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/api/ConformanceLevel.java25
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java336
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/api/Version.java48
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/config/Configuration.java16
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java110
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java46
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java49
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java31
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java20
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java620
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcPropertyNames.java109
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java82
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/impl/Types.java32
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java53
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/utils/SdcToscaUtility.java19
-rw-r--r--src/main/java/org/openecomp/sdc/tosca/parser/utils/YamlToObjectConverter.java123
-rw-r--r--src/main/resources/config/configuration.yaml3
-rw-r--r--src/main/resources/config/error-configuration.yaml18
-rw-r--r--src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java120
-rw-r--r--src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java31
-rw-r--r--src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java143
-rw-r--r--src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java23
-rw-r--r--src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java116
-rw-r--r--src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java84
-rw-r--r--src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java397
-rw-r--r--src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java63
-rw-r--r--src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java132
-rw-r--r--src/test/resources/config/configuration.yaml3
-rw-r--r--src/test/resources/config/error-configuration.yaml18
-rw-r--r--src/test/resources/csars/1service-ServiceWithPorts.csarbin0 -> 47257 bytes
-rw-r--r--src/test/resources/csars/csar-invalid-zip.zip2
-rw-r--r--src/test/resources/csars/service-Renanatst2-csar.csarbin0 -> 321286 bytes
-rw-r--r--src/test/resources/csars/service-ServiceFdnt-csar-0904-2.csarbin0 -> 41437 bytes
-rw-r--r--src/test/resources/csars/service-ServiceFdnt-csar-no-vf.csarbin0 -> 39954 bytes
-rw-r--r--src/test/resources/csars/service-ServiceFdnt-csar-rainy.csarbin0 -> 39892 bytes
-rw-r--r--src/test/resources/csars/service-ServiceFdnt-csar.csarbin0 -> 40171 bytes
-rw-r--r--src/test/resources/csars/service-ServiceFdnt-test-csar.csarbin0 -> 39938 bytes
-rw-r--r--src/test/resources/csars/service-ServiceFdnt-with-allotted.csarbin0 -> 45194 bytes
-rw-r--r--src/test/resources/csars/service-ServiceFdnt-with-get-input.csarbin0 -> 45214 bytes
-rw-r--r--src/test/resources/csars/service-entry-definition-not-defined.csarbin0 -> 45157 bytes
-rw-r--r--src/test/resources/csars/service-invalid-conformence-level.csarbin0 -> 45194 bytes
-rw-r--r--src/test/resources/csars/service-invalid-input-args.csarbin0 -> 106698 bytes
-rw-r--r--src/test/resources/csars/service-invalid-yaml-content-meta.csarbin0 -> 45198 bytes
-rw-r--r--src/test/resources/csars/service-missing-entry-definition.csarbin0 -> 42668 bytes
-rw-r--r--src/test/resources/csars/service-missing-meta-file.csarbin0 -> 44893 bytes
-rw-r--r--version.properties13
51 files changed, 3267 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..59bfdd1
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,20 @@
+# Eclipse
+.classpath
+.project
+.settings/
+
+# Maven
+log/
+target/
+
+# Package Files #
+*.jar
+*.war
+*.ear
+
+# Other
+*.class
+*.orig
+.idea/*
+/bin/
+*.iml
diff --git a/.gitreview b/.gitreview
new file mode 100644
index 0000000..0ff9adf
--- /dev/null
+++ b/.gitreview
@@ -0,0 +1,4 @@
+[gerrit]
+host=gerrit.onap.org
+port=29418
+project=sdc/sdc-tosca.git \ No newline at end of file
diff --git a/LICENSE.TXT b/LICENSE.TXT
new file mode 100644
index 0000000..724329f
--- /dev/null
+++ b/LICENSE.TXT
@@ -0,0 +1,21 @@
+/*
+* ============LICENSE_START==========================================
+* ===================================================================
+* Copyright © 2017 AT&T Intellectual Property.
+* Copyright © 2017 Amdocs
+* 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============================================
+* ECOMP is a trademark and service mark of AT&T Intellectual Property.
+*/ \ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..f66e262
--- /dev/null
+++ b/README.md
@@ -0,0 +1,28 @@
+# OpenECOMP SDC-Tosca
+
+
+---
+---
+
+# Introduction
+
+OpenECOMP SDC-Tosca is delivered as helper JAR that can be used by clients that work with SDC TOSCA CSAR files.
+It parses the CSAR and returns the model object which represents the CSAR contents, through designated function calls with SDC flavour.
+It uses the underlying generic JTOSCA parser.
+
+
+# Compiling OpenECOMP JTOSCA
+
+OpenECOMP SDC-Tosca can be compiled easily using maven command: `mvn clean install`
+The result is JAR file under "target" folder
+
+# Getting Help
+
+*** to be completed on release ***
+
+SDC@lists.openecomp.org
+
+SDC Javadoc and Maven site
+
+*** to be completed on rrelease ***
+
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..5074354
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,309 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.openecomp.sdc.sdc-tosca</groupId>
+ <artifactId>sdc-tosca</artifactId>
+ <name>SDC Tosca Parser</name>
+ <description>SDC Tosca Parser JAR file for use by consumers</description>
+ <version>1.1.31-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <properties>
+
+ <!-- ==================== -->
+ <!-- Generic properties -->
+ <!-- ==================== -->
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <!-- ==================== -->
+ <!-- Versions -->
+ <!-- ==================== -->
+ <!-- Global project version -->
+
+ <!-- Dependencies projects version -->
+ <sonar.skipDesign>true</sonar.skipDesign>
+ <sonar.projectBaseDir>${project.basedir}</sonar.projectBaseDir>
+ <sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
+ <nexus.proxy>https://nexus.onap.org</nexus.proxy>
+ <sitePath>/content/sites/site/org/openecomp/sdc/sdc-tosca/${project.version}</sitePath>
+ <snapshots.path>snapshots</snapshots.path>
+ <releases.path>releases</releases.path>
+ <!--<staging.profile.id>176c31dfe190a</staging.profile.id> -->
+
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.10</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.3.1</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.functionaljava</groupId>
+ <artifactId>functionaljava</artifactId>
+ <version>4.2</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.5</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.9</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <!-- YAML parser -->
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>1.14</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <!-- Apache Commons -->
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.5</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>21.0</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <!-- jtosca Tosca Parser -->
+ <dependency>
+ <groupId>org.openecomp.sdc.jtosca</groupId>
+ <artifactId>jtosca</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ </dependency>
+
+
+ <!-- TEST -->
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlet</artifactId>
+ <scope>test</scope>
+ <version>9.2.10.v20150310</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-webapp</artifactId>
+ <version>9.2.10.v20150310</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!--<dependency> -->
+ <!--<groupId>junit</groupId> -->
+ <!--<artifactId>junit</artifactId> -->
+ <!--<version>4.12</version> -->
+ <!--<scope>test</scope> -->
+ <!--</dependency> -->
+
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>6.11</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>1.10.19</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId>
+ <version>1.1.2</version> <scope>test</scope> </dependency> -->
+
+ </dependencies>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.10.4</version>
+ <configuration>
+ <failOnError>false</failOnError>
+ <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
+ <docletArtifact>
+ <groupId>org.umlgraph</groupId>
+ <artifactId>umlgraph</artifactId>
+ <version>5.6</version>
+ </docletArtifact>
+ <additionalparam>-views</additionalparam>
+ <useStandardDocletOptions>true</useStandardDocletOptions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-site-plugin</artifactId>
+ <version>3.4</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-webdav-jackrabbit</artifactId>
+ <version>2.10</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>0.7.8</version>
+ <executions>
+ <!-- Unit-Tests -->
+ <execution>
+ <id>prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ <configuration>
+ <destFile>${sonar.jacoco.reportPath}</destFile>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- Staging Plugin -->
+ <plugin>
+ <groupId>org.sonatype.plugins</groupId>
+ <artifactId>nexus-staging-maven-plugin</artifactId>
+ <version>1.6.7</version>
+ <extensions>true</extensions>
+ <configuration>
+ <nexusUrl>${nexus.proxy}</nexusUrl>
+ <stagingProfileId>${staging.profile.id}</stagingProfileId>
+ <serverId>ecomp-staging</serverId>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.5.1</version>
+ <inherited>true</inherited>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.10.3</version>
+ <configuration />
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>license-maven-plugin</artifactId>
+ <version>1.10</version>
+ <configuration>
+ <addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>
+ <processStartTag>============LICENSE_START=======================================================</processStartTag>
+ <processEndTag>============LICENSE_END=========================================================</processEndTag>
+ <sectionDelimiter>================================================================================</sectionDelimiter>
+ <licenseName>apache_v2</licenseName>
+ <inceptionYear>2017</inceptionYear>
+ <organizationName>AT&amp;T Intellectual Property. All rights
+ reserved.</organizationName>
+ <projectName>sdc-tosca</projectName>
+ <canUpdateCopyright>true</canUpdateCopyright>
+ <canUpdateDescription>true</canUpdateDescription>
+ <canUpdateLicense>true</canUpdateLicense>
+ <emptyLineAfterHeader>true</emptyLineAfterHeader>
+ <verbose>false</verbose>
+ <includes>
+ <include>**/*.java</include>
+ </includes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>first</id>
+ <goals>
+ <goal>update-file-header</goal>
+ </goals>
+ <!--phase>process-sources</phase -->
+ </execution>
+ </executions>
+ </plugin>
+ <!-- Test -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.19.1</version>
+ <configuration>
+ <includes>
+ <include>**/ToscaParser***Test.class</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>central</id>
+ <name>Official Maven repository</name>
+ <url>http://repo2.maven.org/maven2/</url>
+ </repository>
+ <repository>
+ <id>ecomp-releases</id>
+ <name>Release Repository</name>
+ <url>${nexus.proxy}/content/repositories/releases/</url>
+ </repository>
+ <repository>
+ <id>ecomp-staging</id>
+ <name>Staging Repository</name>
+ <url>${nexus.proxy}/content/repositories/staging/</url>
+ </repository>
+ </repositories>
+
+ <distributionManagement>
+ <repository>
+ <id>ecomp-releases</id>
+ <name>Release Repository</name>
+ <url>${nexus.proxy}/content/repositories/${releases.path}/</url>
+ </repository>
+ <snapshotRepository>
+ <id>ecomp-snapshots</id>
+ <name>Snapshot Repository</name>
+ <url>${nexus.proxy}/content/repositories/${snapshots.path}/</url>
+ </snapshotRepository>
+ <site>
+ <id>ecomp-site</id>
+ <url>dav:${nexus.proxy}${sitePath}</url>
+ </site>
+ </distributionManagement>
+</project>
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/api/ConformanceLevel.java b/src/main/java/org/openecomp/sdc/tosca/parser/api/ConformanceLevel.java
new file mode 100644
index 0000000..a026938
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/api/ConformanceLevel.java
@@ -0,0 +1,25 @@
+package org.openecomp.sdc.tosca.parser.api;
+
+public class ConformanceLevel {
+
+ private String minVersion;
+ private String maxVersion;
+
+ public String getMaxVersion() {
+ return maxVersion;
+ }
+
+ public void setMaxVersion(String maxVersion) {
+ this.maxVersion = maxVersion;
+ }
+
+ public String getMinVersion() {
+ return minVersion;
+ }
+
+ public void setMinVersion(String minVersion) {
+ this.minVersion = minVersion;
+ }
+
+
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java b/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
new file mode 100644
index 0000000..0317595
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
@@ -0,0 +1,336 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * 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=========================================================
+ */
+package org.openecomp.sdc.tosca.parser.api;
+
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.openecomp.sdc.toscaparser.api.Group;
+import org.openecomp.sdc.toscaparser.api.NodeTemplate;
+import org.openecomp.sdc.toscaparser.api.elements.Metadata;
+import org.openecomp.sdc.toscaparser.api.parameters.Input;
+
+
+public interface ISdcCsarHelper {
+
+ /**
+ * Get all node templates by node_type for this CSAR service.
+ *
+ * @param nodeType - the TOSCA type of the node.
+ * @return service node templates of this type.
+ */
+ public List<NodeTemplate> getServiceNodeTemplatesByType(String nodeType);
+
+ /**
+ * Get all node templates for this CSAR service.
+ *
+ * @return service node templates.
+ */
+ public List<NodeTemplate> getServiceNodeTemplates();
+
+ /**
+ * Get groups of a VF with type "org.openecomp.groups.VfModule".
+ *
+ * @param vfCustomizationUuid - customizationUuid of VF instance.
+ * @return list of vfModule groups.
+ */
+ public List<Group> getVfModulesByVf(String vfCustomizationUuid);
+
+
+ /**
+ * Get any property leaf value for node template by full path separated by #.<br>
+ * For example, for node template with this property:<br><br>
+ * network_assignments:<br>
+ &nbsp;&nbsp;ecomp_generated_network_assignment: true<br>
+ &nbsp;&nbsp;is_shared_network: false<br>
+ &nbsp;&nbsp;is_external_network: false<br>
+ &nbsp;&nbsp;ipv4_subnet_default_assignments:<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;use_ipv4: true<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;ip_network_address_plan: 1.2.3.4<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;dhcp_enabled: true<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;ip_version: 4<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;cidr_mask: 24<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;min_subnets_count: 1<br>
+ &nbsp;&nbsp;ipv6_subnet_default_assignments:<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;use_ipv6: false<br><br>
+
+ * calling<br>
+ * getNodeTemplatePropertyLeafValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignments#use_ipv6")<br>
+ * will return "false".
+ * @param nodeTemplate - nodeTemplate where the property should be looked up.
+ * @param pathToPropertyLeafValue - the full path of the required property.
+ * @return the leaf value as String, or null if there's no such property, or it's not a leaf.
+ */
+ public String getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String pathToPropertyLeafValue);
+
+ /**
+ * Get any property leaf value for node template by full path separated by #.<br>
+ * For example, for node template with this property:<br><br>
+ * network_assignments:<br>
+ &nbsp;&nbsp;ecomp_generated_network_assignment: true<br>
+ &nbsp;&nbsp;is_shared_network: false<br>
+ &nbsp;&nbsp;is_external_network: false<br>
+ &nbsp;&nbsp;ipv4_subnet_default_assignments:<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;use_ipv4: true<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;ip_network_address_plan: 1.2.3.4<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;dhcp_enabled: true<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;ip_version: 4<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;cidr_mask: 24<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;min_subnets_count: 1<br>
+ &nbsp;&nbsp;ipv6_subnet_default_assignments:<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;use_ipv6: false<br><br>
+
+ * calling<br>
+ * getNodeTemplatePropertyLeafValue(nodeTemplate, "network_assignments#ipv6_subnet_default_assignments#use_ipv6")<br>
+ * will return "false".
+ * @param nodeTemplate - nodeTemplate where the property should be looked up.
+ * @param pathToPropertyLeafValue - the full path of the required property.
+ * @return the leaf value as Object, or null if there's no such property. It's up to the caller to cast it to a proper type.
+ */
+ public Object getNodeTemplatePropertyAsObject(NodeTemplate nodeTemplate, String pathToPropertyLeafValue);
+
+ /**
+ * Get any property leaf value for a group definition by full path separated by #.
+ * Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for a group.
+ * @param group - group where the property should be looked up.
+ * @param propertyName - the name of the required property.
+ * @return the leaf value as String, or null if there's no such property, or it's not a leaf.
+ */
+ public String getGroupPropertyLeafValue(Group group, String propertyName);
+
+ /**
+ * Get any property value for a group definition by full path separated by #.
+ * Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for a group.
+ * @param group - group where the property should be looked up.
+ * @param propertyName - the name of the required property.
+ * @return the leaf value as Object, or null if there's no such property. It's up to the caller to cast it to a proper type.
+ */
+ public Object getGroupPropertyAsObject(Group group, String propertyName);
+
+ /**
+ * Get all VL node templates of the CSAR service.
+ * @return - all VL node templates.
+ */
+ public List<NodeTemplate> getServiceVlList();
+
+ /**
+ * Get all VF node templates of the CSAR service.
+ * @return - all VF node templates.
+ */
+ public List<NodeTemplate> getServiceVfList();
+
+
+ /**
+ *
+ * Get a property from a metadata object.<br>
+ * This is just sugaring method, same as calling metadata.getMetadataPropertyValue(metadataPropertyName).<br>
+ *
+ * For metadata object representing the below: <br><br>
+ *
+ * metadata:<br>
+ &nbsp;&nbsp;invariantUUID: 4598a404-00e1-42a6-8767-0bda343e2066<br>
+ &nbsp;&nbsp;UUID: e17940d6-42f8-4989-bad0-31de5addc619<br>
+ &nbsp;&nbsp;customizationUUID: 83d086b2-a861-4d3b-aa84-3bfbb9b2ec20<br>
+ &nbsp;&nbsp;version: '0.1'<br>
+ &nbsp;&nbsp;name: vIPR_ATM<br>
+ &nbsp;&nbsp;description: vIPR_ATM<br>
+ &nbsp;&nbsp;type: VF<br>
+ &nbsp;&nbsp;category: category1<br>
+ &nbsp;&nbsp;subcategory: subCategory1<br><br>
+
+ calling<br>
+ getMetadataPropertyValue(metadata,"invariantUUID")<br>
+ will return "4598a404-00e1-42a6-8767-0bda343e2066".
+
+ * @param metadata - metadata object.
+ * @param metadataPropertyName - the name of the metadata property.
+ * @return metadata property value
+ */
+ public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName);
+
+
+ /**
+ * Get input leaf value for the CSAR service, by full path separated by #.<br>
+ * Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for an input full path.
+ * The expected format is "input_name#default[optionally #rest_of_path]"
+ * @param inputLeafValuePath by full path separated by #.
+ * @return input leaf value for the service.
+ */
+ public String getServiceInputLeafValueOfDefault(String inputLeafValuePath);
+
+ /**
+ * Get input leaf value for the CSAR service, by full path separated by #.<br>
+ * Same logic as in {@link #getNodeTemplatePropertyLeafValue(NodeTemplate, String) getNodeTemplatePropertyLeafValue}, only for an input full path.
+ * The expected format is "input_name#default[optionally #rest_of_path]"
+ * @param inputLeafValuePath by full path separated by #.
+ * @return input value for the service as Object. It's up to the caller to cast it to a proper type.
+ */
+ public Object getServiceInputLeafValueOfDefaultAsObject(String inputLeafValuePath);
+
+ /**
+ * Get the type name of the CSAR service's substitution mappings element.<br>
+ *
+ * For the below:<br><br>
+ *
+ * substitution_mappings:<br>
+ &nbsp;&nbsp;type: org.openecomp.services.ViprATM<br>
+
+ calling<br>
+ getServiceSubstitutionMappingsTypeName()<br>
+ will return "org.openecomp.services.ViprATM"
+ * @return - the type name of the CSAR service's substitution mappings element
+ */
+ public String getServiceSubstitutionMappingsTypeName();
+
+ /**
+ * Get the CSAR service metadata
+ * @return - the service metadata object.
+ */
+ public Metadata getServiceMetadata();
+
+ /**
+ * Get the CSAR service metadata as map.
+ * @return - the service metadata object as Map.
+ */
+ public Map<String, Object> getServiceMetadataProperties();
+
+ /**
+ * Get all VFC node templates from a specified VF.
+ * @param vfCustomizationId - customizationUuid of the VF node template.
+ * @return all VFC node templates from a specified VF
+ */
+ public List<NodeTemplate> getVfcListByVf(String vfCustomizationId);
+
+ /**
+ * Get all CP node templates from a specified VF.
+ * @param vfCustomizationId - customizationUuid of the VF node template.
+ * @return all CP node templates from a specified VF
+ */
+ public List<NodeTemplate> getCpListByVf(String vfCustomizationId);
+
+ /**
+ * Get all members of this group definition.<br>
+ *
+ * For example, for this group definition:<br><br>
+ *
+ * ViprAtm..vIPR-ATM-Base..module-0:<br>
+ &nbsp;&nbsp;type: org.openecomp.groups.VfModule<br>
+ &nbsp;&nbsp;.................<br>
+ &nbsp;&nbsp;members: [vIPR_ATM_Ha_Two, vIPR_ATM_Ha_One, vIPR_ATM_OAM_SG, vIPR_ATM_HA_TWO_SG, vIPR_ATM_HA_ONE_SG]<br><br>
+
+ calling<br>
+ getMembersOfVfModule(NoteTemplate vfNodeTemplate, Group group)<br>
+ will return List of the following Node templates in the vfNodeTemplate: "vIPR_ATM_Ha_Two, vIPR_ATM_Ha_One, vIPR_ATM_OAM_SG, vIPR_ATM_HA_TWO_SG, vIPR_ATM_HA_ONE_SG"<br>
+ * @param vf - VF to return the node templates from.
+ * @param vfModule - group to return the members from.
+ * @return node templates from vf with the names as in members section.
+ *
+ */
+ public List<NodeTemplate> getMembersOfVfModule(NodeTemplate vf, Group vfModule);
+
+
+ /**
+ * Get list of node template pairs, where for each pair,<br>
+ * the left node template in pair has requirement with name reqName, <br>
+ * which should be satisfied with respective capability by the right node template in pair.<br>
+ *
+ * For example, if we have the below two node templates in the vIPR VF:<br><br>
+ *
+ * oam_extCP:<br>
+ &nbsp;&nbsp;type: org.openecomp.resources.cp.extCP<br>
+ &nbsp;&nbsp;requirements:<br>
+ &nbsp;&nbsp;&nbsp;&nbsp;- virtualBinding: vipr_atm_firewall<br><br>
+ *
+ * vipr_atm_firewall: <br>
+ &nbsp;&nbsp;type: org.openecomp.resources.vfc.ViprAtm.abstract.nodes.heat.vipr_atm<br>
+ ........<br><br>
+ *
+
+ * calling<br>
+ * getNodeTemplatePairsByReqName(getCpListByVf(viprCustomUuid), getVfcListByVf(viprCustomUuid), "virtualBinding")<br>
+ * will return a list with one Pair - where left element of pair will be "oam_extCP" node template,<br>
+ * and right element will be "vipr_atm_firewall" node template.<br>
+ *
+ * @param listOfReqNodeTemplates - list of node templates in which the "reqName" requirement should be looked.
+ * @param listOfCapNodeTemplates - list of node templates in which the capability matching the "reqName" requirement should be looked.
+ * @param reqName - the name of a requirement definition to match by.
+ * @return pairs of node templates according to described above.
+ */
+ public List<Pair<NodeTemplate,NodeTemplate>> getNodeTemplatePairsByReqName(List<NodeTemplate> listOfReqNodeTemplates, List<NodeTemplate> listOfCapNodeTemplates, String reqName);
+
+ /**
+ * Get all allotted node templates from this service.
+ * @return all allotted node templates from this service.
+ */
+ public List<NodeTemplate> getAllottedResources();
+
+ /**
+ * Get node_type of a node template.<br>
+ *
+ * For this node template:<br>
+ *
+ * vipr_atm_firewall: <br>
+ &nbsp;&nbsp;type: org.openecomp.resources.vfc.ViprAtm.abstract.nodes.heat.vipr_atm<br>
+ ........<br><br>
+ *
+ * the function will return "org.openecomp.resources.vfc.ViprAtm.abstract.nodes.heat.vipr_atm"
+ *
+ * @param nodeTemplate - node template object
+ * @return - node type string.
+ */
+ public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate);
+
+ /**
+ * Get the CSAR service inputs list.
+ * @return - the service inputs list.
+ */
+ public List<Input> getServiceInputs();
+
+
+ /**
+ * Get the conformance level of this CSAR. <br>
+ * The conformance level value of the CSAR is located in csar.meta file at the top level of the CSAR file.<br>
+ * For 1707 CSARs, the conformance level is 3.0.
+ * @return the conformance level of the CSAR.
+ */
+ public String getConformanceLevel();
+
+
+ /**
+ * Get the map of CP-related props from a VFC node template. <br>
+ * Let's say there are 5 CPs related to this VFC. Then the output will look like this: <br><br>
+ * {port_fe1_sigtran={ip_requirements#ip_count_required#count=1, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4, subnetpoolid="subnet_1", network_role_tag="SIGNET_vrf_B1_direct"},<br>
+ * port_fe_cluster={ip_requirements#ip_count_required#count=2, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4},<br>
+ * port_fe_slan={ip_requirements#ip_count_required#count=1, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4},<br>
+ * port_fe_interce={ip_requirements#ip_count_required#count=1, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4},<br>
+ * port_fe_oam={ip_requirements#ip_count_required#count=2, ip_requirements#dhcp_enabled=true, ip_requirements#ip_version=4, subnetpoolid="subnet_2", network_role_tag="Mobility_OAM_protected"}}<br><br>
+ * @param vfc - VFC node template to look for CP-related props.
+ * @return map <b>CP node template name</b> to a map of <b>full path to a property on this CP</b> - <b> value of this property on this CP</b>.
+ */
+ public Map<String, Map<String, Object>> getCpPropertiesFromVfc(NodeTemplate vfc);
+
+ /**
+ * Get customization UUID of a node template
+ * @param nt - node template
+ * @return customization UUID of a node template.
+ */
+ public String getNodeTemplateCustomizationUuid(NodeTemplate nt);
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/api/Version.java b/src/main/java/org/openecomp/sdc/tosca/parser/api/Version.java
new file mode 100644
index 0000000..473e3a8
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/api/Version.java
@@ -0,0 +1,48 @@
+package org.openecomp.sdc.tosca.parser.api;
+
+public class Version implements Comparable<Version> {
+
+ private String version;
+
+ public final String get() {
+ return this.version;
+ }
+
+ public Version(String version) {
+ if(version == null)
+ throw new IllegalArgumentException("Version can not be null");
+ if(!version.matches("[0-9]+(\\.[0-9]+)*"))
+ throw new IllegalArgumentException("Invalid version format");
+ this.version = version;
+ }
+
+ @Override public int compareTo(Version that) {
+ if(that == null)
+ return 1;
+ String[] thisParts = this.get().split("\\.");
+ String[] thatParts = that.get().split("\\.");
+ int length = Math.max(thisParts.length, thatParts.length);
+ for(int i = 0; i < length; i++) {
+ int thisPart = i < thisParts.length ?
+ Integer.parseInt(thisParts[i]) : 0;
+ int thatPart = i < thatParts.length ?
+ Integer.parseInt(thatParts[i]) : 0;
+ if(thisPart < thatPart)
+ return -1;
+ if(thisPart > thatPart)
+ return 1;
+ }
+ return 0;
+ }
+
+ @Override public boolean equals(Object that) {
+ if(this == that)
+ return true;
+ if(that == null)
+ return false;
+ if(this.getClass() != that.getClass())
+ return false;
+ return this.compareTo((Version) that) == 0;
+ }
+
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/config/Configuration.java b/src/main/java/org/openecomp/sdc/tosca/parser/config/Configuration.java
new file mode 100644
index 0000000..1d00d14
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/config/Configuration.java
@@ -0,0 +1,16 @@
+package org.openecomp.sdc.tosca.parser.config;
+
+import org.openecomp.sdc.tosca.parser.api.ConformanceLevel;
+
+public class Configuration {
+
+ private ConformanceLevel conformanceLevel;
+
+ public ConformanceLevel getConformanceLevel() {
+ return conformanceLevel;
+ }
+
+ public void setConformanceLevel(ConformanceLevel conformanceLevel) {
+ this.conformanceLevel = conformanceLevel;
+ }
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java b/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java
new file mode 100644
index 0000000..e83e6aa
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java
@@ -0,0 +1,110 @@
+package org.openecomp.sdc.tosca.parser.config;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+import org.openecomp.sdc.tosca.parser.utils.YamlToObjectConverter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class ConfigurationManager {
+
+ private static Logger log = LoggerFactory.getLogger(ConfigurationManager.class.getName());
+
+ private static final String CONFIGURATION_DIR = "config/";
+ private static volatile ConfigurationManager instance;
+// private Configuration configuration;
+// private ErrorConfiguration errorConfiguration;
+
+ Map<String, Object> configurations = new HashMap<String, Object>();
+
+
+
+ private ConfigurationManager() {
+ initialConfigObjectsFromFiles();
+ }
+
+ private void initialConfigObjectsFromFiles() {
+ loadConfigurationClass(ErrorConfiguration.class);
+ loadConfigurationClass(Configuration.class);
+ }
+
+ private <T> void loadConfigurationClass(Class<T> clazz) {
+ T object = getObjectFromYaml(clazz);
+ configurations.put(clazz.getSimpleName(), object);
+ }
+
+
+ public <T> T getObjectFromYaml(Class<T> className) {
+
+
+ String configFileName = calculateFileName(className);
+
+ URL url = Resources.getResource(CONFIGURATION_DIR + configFileName);
+ String configFileContents = null;
+ try {
+ configFileContents = Resources.toString(url, Charsets.UTF_8);
+ } catch (IOException e) {
+ log.error("ConfigurationManager - Failed to load configuration file");
+ }
+ YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
+ T object = yamlToObjectConverter.convertFromString(configFileContents, className);
+
+ return object;
+ }
+
+
+ public static ConfigurationManager getInstance() {
+ if (instance == null) {
+ synchronized (ConfigurationManager.class) {
+ if (instance == null) {
+ instance = new ConfigurationManager();
+ }
+ }
+ }
+ return instance;
+ }
+
+ private static <T> String calculateFileName(Class<T> className) {
+
+ String[] words = className.getSimpleName().split("(?=\\p{Upper})");
+
+ StringBuilder builder = new StringBuilder();
+
+ // There cannot be a null value returned from "split" - words != null is
+ // redundant
+ // if (words != null) {
+ boolean isFirst = true;
+ for (int i = 0; i < words.length; i++) {
+
+ String word = words[i];
+ if (word != null && !word.isEmpty()) {
+ if (!isFirst) {
+ builder.append("-");
+ } else {
+ isFirst = false;
+ }
+ builder.append(words[i].toLowerCase());
+ }
+ }
+ return builder.toString() + ".yaml";
+
+ /*
+ * } else { return className.getSimpleName().toLowerCase() + Constants.YAML_SUFFIX; }
+ */
+
+ }
+
+ public ErrorConfiguration getErrorConfiguration() {
+ return (ErrorConfiguration) configurations.get((ErrorConfiguration.class.getSimpleName()));
+ }
+
+ public Configuration getConfiguration() {
+ return (Configuration) configurations.get((Configuration.class.getSimpleName()));
+ }
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java b/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java
new file mode 100644
index 0000000..59e8c6d
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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=========================================================
+ */
+
+package org.openecomp.sdc.tosca.parser.config;
+
+import java.util.Map;
+
+public class ErrorConfiguration {
+
+ private Map<String, ErrorInfo> errors;
+
+ public Map<String, ErrorInfo> getErrors() {
+ return errors;
+ }
+
+ public void setErrors(Map<String, ErrorInfo> errors) {
+ this.errors = errors;
+ }
+
+ public ErrorInfo getErrorInfo(String key) {
+ ErrorInfo clone = null;
+ ErrorInfo other = errors.get(key);
+ if (other != null) {
+ clone = new ErrorInfo();
+ clone.cloneData(other);
+ }
+ return clone;
+ }
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java b/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java
new file mode 100644
index 0000000..01df115
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * 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=========================================================
+ */
+
+package org.openecomp.sdc.tosca.parser.config;
+
+public class ErrorInfo {
+
+ private String code;
+ private String message;
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public void cloneData(ErrorInfo other) {
+ this.code = other.getCode();
+ this.message = other.getMessage();
+ }
+
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java b/src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java
new file mode 100644
index 0000000..ce84a9c
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java
@@ -0,0 +1,31 @@
+package org.openecomp.sdc.tosca.parser.config;
+
+import java.util.EnumMap;
+import java.util.Map;
+
+import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes;
+
+public enum SdcToscaParserErrors {
+
+ BAD_FORMAT, CONFORMANCE_LEVEL_ERROR, FILE_NOT_FOUND, GENERAL_ERROR;
+
+ private static final Map<JToscaErrorCodes, SdcToscaParserErrors> JTOSCA_ERRORS =
+ new EnumMap<JToscaErrorCodes, SdcToscaParserErrors>(JToscaErrorCodes.class) {{
+
+ put(JToscaErrorCodes.GENERAL_ERROR, GENERAL_ERROR);
+
+ put(JToscaErrorCodes.PATH_NOT_VALID, FILE_NOT_FOUND);
+ //CSAR contents problems
+ put(JToscaErrorCodes.MISSING_META_FILE, BAD_FORMAT);
+ put(JToscaErrorCodes.INVALID_META_YAML_CONTENT, BAD_FORMAT);
+ put(JToscaErrorCodes.ENTRY_DEFINITION_NOT_DEFINED, BAD_FORMAT);
+ put(JToscaErrorCodes.MISSING_ENTRY_DEFINITION_FILE, BAD_FORMAT);
+ put(JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR, BAD_FORMAT);
+ put(JToscaErrorCodes.INVALID_CSAR_FORMAT, BAD_FORMAT);
+ }};
+
+ public static SdcToscaParserErrors getSdcErrorByJToscaError(JToscaErrorCodes jToscaErrorCode) {
+ return JTOSCA_ERRORS.get(jToscaErrorCode);
+ }
+
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java b/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java
new file mode 100644
index 0000000..a7fd99d
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java
@@ -0,0 +1,20 @@
+package org.openecomp.sdc.tosca.parser.exceptions;
+
+public class SdcToscaParserException extends Exception {
+
+ private static final long serialVersionUID = 626014844866501196L;
+ private String code;
+
+ public SdcToscaParserException(String string, String code) {
+ super(string);
+ this.code = code;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
new file mode 100644
index 0000000..612b896
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
@@ -0,0 +1,620 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * 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=========================================================
+ */
+
+package org.openecomp.sdc.tosca.parser.impl;
+
+import java.util.*;
+import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+//import org.json.JSONObject;
+import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.utils.GeneralUtility;
+import org.openecomp.sdc.tosca.parser.utils.SdcToscaUtility;
+import org.openecomp.sdc.toscaparser.api.Group;
+import org.openecomp.sdc.toscaparser.api.NodeTemplate;
+import org.openecomp.sdc.toscaparser.api.Property;
+import org.openecomp.sdc.toscaparser.api.SubstitutionMappings;
+import org.openecomp.sdc.toscaparser.api.TopologyTemplate;
+import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
+import org.openecomp.sdc.toscaparser.api.elements.Metadata;
+import org.openecomp.sdc.toscaparser.api.elements.NodeType;
+import org.openecomp.sdc.toscaparser.api.functions.Function;
+import org.openecomp.sdc.toscaparser.api.parameters.Input;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID;
+
+public class SdcCsarHelperImpl implements ISdcCsarHelper {
+
+ private static final String PATH_DELIMITER = "#";
+ private static final String PREFIX = "port_";
+ private static final String CUSTOMIZATION_UUID = "customizationUUID";
+ private static Pattern SUFFIX = Pattern.compile("(_network_role_tag|_ip_requirements|_subnetpoolid)$");
+ private ToscaTemplate toscaTemplate;
+ private static Logger log = LoggerFactory.getLogger(SdcCsarHelperImpl.class.getName());
+
+ public SdcCsarHelperImpl(ToscaTemplate toscaTemplate) {
+ this.toscaTemplate = toscaTemplate;
+ }
+
+ @Override
+ //Sunny flow - covered with UT, flat and nested
+ public String getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String leafValuePath) {
+ if (nodeTemplate == null) {
+ log.error("getNodeTemplatePropertyLeafValue - nodeTemplate is null");
+ return null;
+ }
+ if (GeneralUtility.isEmptyString(leafValuePath)) {
+ log.error("getNodeTemplatePropertyLeafValue - leafValuePath is null or empty");
+ return null;
+ }
+ String[] split = getSplittedPath(leafValuePath);
+ LinkedHashMap<String, Property> properties = nodeTemplate.getProperties();
+ Object property = processProperties(split, properties);
+ return property == null || property instanceof Function ? null : String.valueOf(property);
+ }
+
+ @Override
+ public Object getNodeTemplatePropertyAsObject(NodeTemplate nodeTemplate, String leafValuePath) {
+ if (nodeTemplate == null) {
+ log.error("getNodeTemplatePropertyAsObject - nodeTemplate is null");
+ return null;
+ }
+ if (GeneralUtility.isEmptyString(leafValuePath)) {
+ log.error("getNodeTemplatePropertyAsObject - leafValuePath is null or empty");
+ return null;
+ }
+ String[] split = getSplittedPath(leafValuePath);
+ LinkedHashMap<String, Property> properties = nodeTemplate.getProperties();
+ return processProperties(split, properties);
+ }
+
+ public Map<String, Map<String, Object>> getCpPropertiesFromVfc(NodeTemplate vfc) {
+
+ if (vfc == null) {
+ log.error("getCpPropertiesFromVfc - vfc is null");
+ return new HashMap<>();
+ }
+
+ List<String> paths = new ArrayList<>();
+ paths.add("network_role_tag");
+ paths.add("ip_requirements#ip_count_required#count");
+ paths.add("ip_requirements#dhcp_enabled");
+ paths.add("ip_requirements#ip_version");
+ paths.add("subnetpoolid");
+
+ Map<String, Property> props = vfc.getProperties();
+
+ Map<String, Map<String, Object>> cps = new HashMap<>();
+
+ if (props != null) {
+ for (Map.Entry<String, Property> entry : props.entrySet()) {
+ String fullCpName = entry.getKey();
+ Matcher matcher = SUFFIX.matcher(fullCpName);
+
+ if (fullCpName.startsWith(PREFIX) && matcher.find()) {
+ //this is CP - get all it's properties according to paths list
+ String cpName = fullCpName.replaceAll("^(" + PREFIX + ")", "").replaceAll(matcher.group(1), "");
+
+ List<String> propertiesToSearch = paths.stream().filter(i -> i.contains(StringUtils.stripStart(matcher.group(1), "_"))).collect(Collectors.toList());
+ for (String item : propertiesToSearch) {
+ String fullPathToSearch = PREFIX + cpName + "_" + item;
+ Object value = getNodeTemplatePropertyAsObject(vfc, fullPathToSearch);
+ if (value != null) {
+ if (!cps.containsKey(cpName)){
+ cps.put(cpName, new HashMap<>());
+ }
+ cps.get(cpName).put(item, value);
+ }
+
+ }
+ }
+ }
+ }
+
+ return cps;
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public List<NodeTemplate> getServiceVlList() {
+ List<NodeTemplate> serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VL);
+ return serviceVlList;
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public List<NodeTemplate> getServiceVfList() {
+ List<NodeTemplate> serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VF);
+ return serviceVfList;
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName) {
+ if (GeneralUtility.isEmptyString(metadataPropertyName)) {
+ log.error("getMetadataPropertyValue - the metadataPropertyName is null or empty");
+ return null;
+ }
+ if (metadata == null) {
+ log.error("getMetadataPropertyValue - the metadata is null");
+ return null;
+ }
+ String metadataPropertyValue = metadata.getValue(metadataPropertyName);
+ return metadataPropertyValue;
+ }
+
+
+ @Override
+ //Sunny flow - covered with UT
+ public List<NodeTemplate> getServiceNodeTemplatesByType(String nodeType) {
+ if (GeneralUtility.isEmptyString(nodeType)) {
+ log.error("getServiceNodeTemplatesByType - nodeType - is null or empty");
+ return new ArrayList<>();
+ }
+
+ List<NodeTemplate> res = new ArrayList<>();
+ List<NodeTemplate> nodeTemplates = toscaTemplate.getNodeTemplates();
+ for (NodeTemplate nodeTemplate : nodeTemplates) {
+ if (nodeType.equals(nodeTemplate.getTypeDefinition().getType())) {
+ res.add(nodeTemplate);
+ }
+ }
+
+ return res;
+ }
+
+
+ @Override
+ public List<NodeTemplate> getServiceNodeTemplates() {
+ List<NodeTemplate> nodeTemplates = toscaTemplate.getNodeTemplates();
+ return nodeTemplates;
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public List<NodeTemplate> getVfcListByVf(String vfCustomizationId) {
+ if (GeneralUtility.isEmptyString(vfCustomizationId)) {
+ log.error("getVfcListByVf - vfCustomizationId - is null or empty");
+ return new ArrayList<>();
+ }
+
+ List<NodeTemplate> serviceVfList = getServiceVfList();
+ NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId);
+ return getNodeTemplateBySdcType(vfInstance, Types.TYPE_VFC);
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public List<Group> getVfModulesByVf(String vfCustomizationUuid) {
+ List<NodeTemplate> serviceVfList = getServiceVfList();
+ NodeTemplate nodeTemplateByCustomizationUuid = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid);
+ if (nodeTemplateByCustomizationUuid != null) {
+ /*SubstitutionMappings substitutionMappings = nodeTemplateByCustomizationUuid.getSubstitutionMappings();
+ if (substitutionMappings != null){
+ List<Group> groups = substitutionMappings.getGroups();
+ if (groups != null){
+ List<Group> collect = groups.stream().filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType())).collect(Collectors.toList());
+ log.debug("getVfModulesByVf - VfModules are {}", collect);
+ return collect;
+ }
+ }*/
+ String name = nodeTemplateByCustomizationUuid.getName();
+ String normaliseComponentInstanceName = SdcToscaUtility.normaliseComponentInstanceName(name);
+ List<Group> serviceLevelGroups = toscaTemplate.getTopologyTemplate().getGroups();
+ log.debug("getVfModulesByVf - VF node template name {}, normalized name {}. Searching groups on service level starting with VF normalized name...", name, normaliseComponentInstanceName);
+ if (serviceLevelGroups != null) {
+ List<Group> collect = serviceLevelGroups
+ .stream()
+ .filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType()) && x.getName().startsWith(normaliseComponentInstanceName))
+ .collect(Collectors.toList());
+ return collect;
+ }
+ }
+ return new ArrayList<>();
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public String getServiceInputLeafValueOfDefault(String inputLeafValuePath) {
+ if (GeneralUtility.isEmptyString(inputLeafValuePath)) {
+ log.error("getServiceInputLeafValueOfDefault - inputLeafValuePath is null or empty");
+ return null;
+ }
+
+ String[] split = getSplittedPath(inputLeafValuePath);
+ if (split.length < 2 || !split[1].equals("default")) {
+ log.error("getServiceInputLeafValue - inputLeafValuePath should be of format <input name>#default[optionally #<rest of path>] ");
+ return null;
+ }
+
+ List<Input> inputs = toscaTemplate.getInputs();
+ if (inputs != null) {
+ Optional<Input> findFirst = inputs.stream().filter(x -> x.getName().equals(split[0])).findFirst();
+ if (findFirst.isPresent()) {
+ Input input = findFirst.get();
+ Object current = input.getDefault();
+ Object property = iterateProcessPath(2, current, split);
+ return property == null || property instanceof Function? null : String.valueOf(property);
+ }
+ }
+ log.error("getServiceInputLeafValue - value not found");
+ return null;
+ }
+
+ @Override
+ public Object getServiceInputLeafValueOfDefaultAsObject(String inputLeafValuePath) {
+ if (GeneralUtility.isEmptyString(inputLeafValuePath)) {
+ log.error("getServiceInputLeafValueOfDefaultAsObject - inputLeafValuePath is null or empty");
+ return null;
+ }
+
+ String[] split = getSplittedPath(inputLeafValuePath);
+ if (split.length < 2 || !split[1].equals("default")) {
+ log.error("getServiceInputLeafValueOfDefaultAsObject - inputLeafValuePath should be of format <input name>#default[optionally #<rest of path>] ");
+ return null;
+ }
+
+ List<Input> inputs = toscaTemplate.getInputs();
+ if (inputs != null) {
+ Optional<Input> findFirst = inputs.stream().filter(x -> x.getName().equals(split[0])).findFirst();
+ if (findFirst.isPresent()) {
+ Input input = findFirst.get();
+ Object current = input.getDefault();
+ return iterateProcessPath(2, current, split);
+ }
+ }
+ log.error("getServiceInputLeafValueOfDefaultAsObject - value not found");
+ return null;
+ }
+
+ private Object iterateProcessPath(Integer index, Object current, String[] split) {
+ if (current == null) {
+ log.error("iterateProcessPath - this input has no default");
+ return null;
+ }
+ if (split.length > index) {
+ for (int i = index; i < split.length; i++) {
+ if (current instanceof Map) {
+ current = ((Map<String, Object>) current).get(split[i]);
+ } else if (current instanceof List) {
+ current = ((List) current).get(0);
+ i--;
+ }
+ else {
+ log.error("iterateProcessPath - found an unexpected leaf where expected to find a complex type");
+ return null;
+ }
+ }
+ }
+ if (current != null) {
+ return current;
+ }
+ log.error("iterateProcessPath - Path not Found");
+ return null;
+ }
+
+ private String[] getSplittedPath(String inputLeafValuePath) {
+ return inputLeafValuePath.split(PATH_DELIMITER);
+ }
+
+
+ @Override
+ //Sunny flow - covered with UT
+ public String getServiceSubstitutionMappingsTypeName() {
+ SubstitutionMappings substitutionMappings = toscaTemplate.getTopologyTemplate().getSubstitutionMappings();
+ if (substitutionMappings == null) {
+ log.debug("getServiceSubstitutionMappingsTypeName - No Substitution Mappings defined");
+ return null;
+ }
+
+ NodeType nodeType = substitutionMappings.getNodeDefinition();
+ if (nodeType == null) {
+ log.debug("getServiceSubstitutionMappingsTypeName - No Substitution Mappings node defined");
+ return null;
+ }
+
+ return nodeType.getType();
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public Metadata getServiceMetadata() {
+ return toscaTemplate.getMetaData();
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public Map<String, Object> getServiceMetadataProperties() {
+ if (toscaTemplate.getMetaData()==null){
+ return null;
+ }
+ return toscaTemplate.getMetaData().getPropertyMap();
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public List<Input> getServiceInputs() {
+ return toscaTemplate.getInputs();
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public String getGroupPropertyLeafValue(Group group, String leafValuePath) {
+ if (group == null) {
+ log.error("getGroupPropertyLeafValue - group is null");
+ return null;
+ }
+
+ if (GeneralUtility.isEmptyString(leafValuePath)) {
+ log.error("getGroupPropertyLeafValue - leafValuePath is null or empty");
+ return null;
+ }
+
+ String[] split = getSplittedPath(leafValuePath);
+ LinkedHashMap<String, Property> properties = group.getProperties();
+ Object property = processProperties(split, properties);
+ return property == null || property instanceof Function? null : String.valueOf(property);
+ }
+
+ @Override
+ public Object getGroupPropertyAsObject(Group group, String leafValuePath) {
+ if (group == null) {
+ log.error("getGroupPropertyAsObject - group is null");
+ return null;
+ }
+
+ if (GeneralUtility.isEmptyString(leafValuePath)) {
+ log.error("getGroupPropertyAsObject - leafValuePath is null or empty");
+ return null;
+ }
+
+ String[] split = getSplittedPath(leafValuePath);
+ LinkedHashMap<String, Property> properties = group.getProperties();
+ return processProperties(split, properties);
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public List<NodeTemplate> getCpListByVf(String vfCustomizationId) {
+ List<NodeTemplate> cpList = new ArrayList<>();
+ if (GeneralUtility.isEmptyString(vfCustomizationId)) {
+ log.error("getCpListByVf vfCustomizationId string is empty");
+ return cpList;
+ }
+
+ List<NodeTemplate> serviceVfList = getServiceVfList();
+ if (serviceVfList == null || serviceVfList.size() == 0) {
+ log.error("getCpListByVf Vfs not exist for vfCustomizationId {}", vfCustomizationId);
+ return cpList;
+ }
+ NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId);
+ if (vfInstance == null) {
+ log.debug("getCpListByVf vf list is null");
+ return cpList;
+ }
+ cpList = getNodeTemplateBySdcType(vfInstance, Types.TYPE_CP);
+ if (cpList == null || cpList.size() == 0)
+ log.debug("getCpListByVf cps not exist for vfCustomizationId {}", vfCustomizationId);
+ return cpList;
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public List<NodeTemplate> getMembersOfVfModule(NodeTemplate vf, Group serviceLevelVfModule) {
+ if (vf == null) {
+ log.error("getMembersOfVfModule - vf is null");
+ return new ArrayList<>();
+ }
+
+ if (serviceLevelVfModule == null || serviceLevelVfModule.getMetadata() == null || serviceLevelVfModule.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID) == null) {
+ log.error("getMembersOfVfModule - vfModule or its metadata is null. Cannot match a VF group based on invariantUuid from missing metadata.");
+ return new ArrayList<>();
+ }
+
+
+ SubstitutionMappings substitutionMappings = vf.getSubMappingToscaTemplate();
+ if (substitutionMappings != null) {
+ List<Group> groups = substitutionMappings.getGroups();
+ if (groups != null) {
+ Optional<Group> findFirst = groups
+ .stream()
+ .filter(x -> (x.getMetadata() != null && serviceLevelVfModule.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID).equals(x.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)))).findFirst();
+ if (findFirst.isPresent()) {
+ List<String> members = findFirst.get().getMembers();
+ if (members != null) {
+ List<NodeTemplate> collect = substitutionMappings.getNodeTemplates().stream().filter(x -> members.contains(x.getName())).collect(Collectors.toList());
+ return collect;
+ }
+ }
+ }
+ }
+ return new ArrayList<>();
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public List<Pair<NodeTemplate, NodeTemplate>> getNodeTemplatePairsByReqName(
+ List<NodeTemplate> listOfReqNodeTemplates, List<NodeTemplate> listOfCapNodeTemplates, String reqName) {
+ if (listOfReqNodeTemplates == null || listOfCapNodeTemplates == null || reqName == null) {
+ //TODO error message
+ return new ArrayList<>();
+ }
+
+ List<Pair<NodeTemplate, NodeTemplate>> pairsList = new ArrayList<>();
+
+ if (listOfReqNodeTemplates != null) {
+ for (NodeTemplate reqNodeTemplate : listOfReqNodeTemplates) {
+ List<Object> requirements = reqNodeTemplate.getRequirements();
+ for (Object reqEntry : requirements) {
+ LinkedHashMap<String, Object> reqEntryHash = (LinkedHashMap<String, Object>) reqEntry;
+ Map<String, Object> reqEntryMap = (Map<String, Object>) reqEntryHash.get(reqName);
+ if (reqEntryMap != null) {
+ Object node = reqEntryMap.get("node");
+ if (node != null) {
+ String nodeString = (String) node;
+ Optional<NodeTemplate> findFirst = listOfCapNodeTemplates.stream().filter(x -> x.getName().equals(nodeString)).findFirst();
+ if (findFirst.isPresent()) {
+ pairsList.add(new ImmutablePair<NodeTemplate, NodeTemplate>(reqNodeTemplate, findFirst.get()));
+ }
+ }
+ }
+ }
+ }
+ }
+ return pairsList;
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ //TODO constant strings
+ public List<NodeTemplate> getAllottedResources() {
+ List<NodeTemplate> nodeTemplates = null;
+ nodeTemplates = toscaTemplate.getTopologyTemplate().getNodeTemplates();
+ if (nodeTemplates.isEmpty()) {
+ log.error("getAllottedResources nodeTemplates not exist");
+ }
+ nodeTemplates = nodeTemplates.stream().filter(
+ x -> x.getMetaData() != null && x.getMetaData().getValue("category").equals("Allotted Resource"))
+ .collect(Collectors.toList());
+ if (nodeTemplates.isEmpty()) {
+ log.debug("getAllottedResources - allotted resources not exist");
+ } else {
+ }
+
+ return nodeTemplates;
+ }
+
+ @Override
+ //Sunny flow - covered with UT
+ public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate) {
+ if (nodeTemplate == null) {
+
+ log.error("getTypeOfNodeTemplate nodeTemplate is null");
+ return null;
+ }
+ return nodeTemplate.getTypeDefinition().getType();
+ }
+
+ @Override
+ public String getConformanceLevel() {
+ LinkedHashMap<String, Object> csarMeta = toscaTemplate.getMetaProperties("csar.meta");
+ if (csarMeta == null){
+ log.warn("No csar.meta file is found in CSAR - this file should hold the conformance level of the CSAR. This might be OK for older CSARs.");
+ return null;
+ }
+
+ Object conformanceLevel = csarMeta.get("SDC-TOSCA-Definitions-Version");
+ if (conformanceLevel != null){
+ String confLevelStr = conformanceLevel.toString();
+ log.debug("CSAR conformance level is {}", confLevelStr);
+ return confLevelStr;
+ } else {
+ log.error("Invalid csar.meta file - no entry found for SDC-TOSCA-Definitions-Version key. This entry should hold the conformance level.");
+ return null;
+ }
+ }
+
+
+ @Override
+ public String getNodeTemplateCustomizationUuid(NodeTemplate nt) {
+ String res = null;
+ if (nt != null && nt.getMetaData() != null){
+ res = nt.getMetaData().getValue(CUSTOMIZATION_UUID);
+ } else {
+ log.error("Node template or its metadata is null");
+ }
+ return res;
+ }
+
+ /************************************* helper functions ***********************************/
+ private List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate nodeTemplate, String sdcType) {
+ if (nodeTemplate == null) {
+ log.error("getNodeTemplateBySdcType - nodeTemplate is null or empty");
+ return new ArrayList<>();
+ }
+
+ if (GeneralUtility.isEmptyString(sdcType)) {
+ log.error("getNodeTemplateBySdcType - sdcType is null or empty");
+ return new ArrayList<>();
+ }
+
+ SubstitutionMappings substitutionMappings = nodeTemplate.getSubMappingToscaTemplate();
+
+ if (substitutionMappings != null) {
+ List<NodeTemplate> nodeTemplates = substitutionMappings.getNodeTemplates();
+ if (nodeTemplates != null && nodeTemplates.size() > 0)
+ return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList());
+ else
+ log.debug("getNodeTemplateBySdcType - SubstitutionMappings' node Templates not exist");
+ } else
+ log.debug("getNodeTemplateBySdcType - SubstitutionMappings not exist");
+
+ return new ArrayList<>();
+ }
+
+ private List<NodeTemplate> getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, String sdcType) {
+ if (GeneralUtility.isEmptyString(sdcType)) {
+ log.error("getNodeTemplateBySdcType - sdcType is null or empty");
+ return new ArrayList<>();
+ }
+
+ if (topologyTemplate == null) {
+ log.error("getNodeTemplateBySdcType - topologyTemplate is null");
+ return new ArrayList<>();
+ }
+
+ List<NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates();
+
+ if (nodeTemplates != null && nodeTemplates.size() > 0)
+ return nodeTemplates.stream().filter(x -> (x.getMetaData() != null && sdcType.equals(x.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)))).collect(Collectors.toList());
+
+ log.debug("getNodeTemplateBySdcType - topologyTemplate's nodeTemplates not exist");
+ return new ArrayList<>();
+ }
+
+ //Assumed to be unique property for the list
+ private NodeTemplate getNodeTemplateByCustomizationUuid(List<NodeTemplate> nodeTemplates, String customizationId) {
+ Optional<NodeTemplate> findFirst = nodeTemplates.stream().filter(x -> (x.getMetaData() != null && customizationId.equals(x.getMetaData().getValue(PROPERTY_NAME_CUSTOMIZATIONUUID)))).findFirst();
+ return findFirst.isPresent() ? findFirst.get() : null;
+ }
+
+ private Object processProperties(String[] split, LinkedHashMap<String, Property> properties) {
+ Optional<Entry<String, Property>> findFirst = properties.entrySet().stream().filter(x -> x.getKey().equals(split[0])).findFirst();
+ if (findFirst.isPresent()) {
+ Property property = findFirst.get().getValue();
+ Object current = property.getValue();
+ return iterateProcessPath(1, current, split);
+ }
+ String propName = (split != null && split.length > 0 ? split[0] : null);
+ log.error("processProperties - property {} not found", propName);
+ return null;
+ }
+
+
+
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcPropertyNames.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcPropertyNames.java
new file mode 100644
index 0000000..7d34c6f
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcPropertyNames.java
@@ -0,0 +1,109 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * 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=========================================================
+ */
+
+package org.openecomp.sdc.tosca.parser.impl;
+
+public class SdcPropertyNames {
+ public static String PROPERTY_NAME_INVARIANTUUID = "invariantUUID";
+ public static String PROPERTY_NAME_UUID = "UUID";
+ public static String PROPERTY_NAME_CUSTOMIZATIONUUID = "customizationUUID";
+ public static String PROPERTY_NAME_VERSION = "version";
+
+ //Groups metadata
+ public static String PROPERTY_NAME_VFMODULEMODELINVARIANTUUID = "vfModuleModelInvariantUUID";
+ public static String PROPERTY_NAME_VFMODULEMODELUUID = "vfModuleModelUUID";
+ public static String PROPERTY_NAME_VFMODULECUSTOMIZATIONUUID = "vfModuleCustomizationUUID";
+ public static String PROPERTY_NAME_VFMODULEMODELVERSION = "vfModuleModelVersion";
+ public static String PROPERTY_NAME_VFMODULEMODELNAME = "vfModuleModelName";
+
+ //Groups properties
+ public static String PROPERTY_NAME_VFMODULETYPE = "vf_module_type";
+ public static String PROPERTY_NAME_VFMODULELABEL = "vf_module_label";
+ public static String PROPERTY_NAME_MINVFMODULEINSTANCES = "min_vf_module_instances";
+ public static String PROPERTY_NAME_MAXVFMODULEINSTANCES = "max_vf_module_instances";
+ public static String PROPERTY_NAME_INITIALCOUNT = "initial_count";
+
+
+ public static String PROPERTY_NAME_DESCRIPTION = "description";
+ public static String PROPERTY_NAME_TYPE = "type";
+ public static String PROPERTY_NAME_CATEGORY = "category";
+ public static String PROPERTY_NAME_SUBCATEGORY = "subcategory";
+ public static String PROPERTY_NAME_RESOURCEVENDOR = "resourceVendor";
+ public static String PROPERTY_NAME_RESOURCEVENDORRELEASE = "resourceVendorRelease";
+ //VFC
+ public static String PROPERTY_NAME_NFCCODE = "nfc_code";
+ public static String PROPERTY_NAME_VMTYPETAG = "vm_type_tag";
+ public static String PROPERTY_NAME_VMTYPE = "vm_type";
+ public static String PROPERTY_NAME_VFCNAMING_ECOMPGENERATEDNAMING="vfc_naming#ecomp_generated_naming";
+ public static String PROPERTY_NAME_VFCNAMING_NAMINGPOLICY="vfc_naming#naming_policy";
+ //VF
+ public static String PROPERTY_NAME_NFTYPE = "nf_type";
+ public static String PROPERTY_NAME_NFROLE = "nf_role";
+ public static String PROPERTY_NAME_NFFUNCTION = "nf_function";
+ public static String PROPERTY_NAME_NFCODE = "nf_code";
+ public static String PROPERTY_NAME_MININSTANCES = "min_instances";
+ public static String PROPERTY_NAME_MAXINSTANCES = "max_instances";
+ public static String PROPERTY_NAME_AVAILABILITYZONEMAXCOUNT = "availability_zone_max_count";
+ public static String PROPERTY_NAME_AVAILABILITYZONECOUNT = "availability_zone_count";
+ public static String PROPERTY_NAME_NAME = "name";
+ public static String PROPERTY_NAME_VNFECOMPNAMING_ECOMPGENERATEDNAMING="vnf_ecomp_naming#ecomp_generated_naming";
+ public static String PROPERTY_NAME_VNFECOMPNAMING_NAMINGPOLICY="vnf_ecomp_naming#naming_policy";
+ public static String PROPERTY_NAME_ECOMPGENERATEDVMASSIGNMENTS = "ecomp_generated_vm_assignments";
+ //Service
+ public static String PROPERTY_NAME_SERVICENAMING_DEFAULT_ECOMPGENERATEDNAMING="service_naming#default#ecomp_generated_naming";
+ public static String PROPERTY_NAME_SERVICENAMING_DEFAULT_NAMINGPOLICY="service_naming#default#naming_policy";
+ //VL
+ public static String PROPERTY_NAME_NETWORKTYPE="network_type";
+ public static String PROPERTY_NAME_NETWORKROLE="network_role";
+ public static String PROPERTY_NAME_NETWORKROLETAG="network_role_tag";
+ public static String PROPERTY_NAME_NETWORKTECHNOLOGY="network_technology";
+ public static String PROPERTY_NAME_NETWORKSCOPE="network_scope";
+ public static String PROPERTY_NAME_NETWORKECOMPNAMING_ECOMPGENERATEDNAMING="network_ecomp_naming#ecomp_generated_naming";
+ public static String PROPERTY_NAME_NETWORKECOMPNAMING_NAMINGPOLICY="network_ecomp_naming#naming_policy";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_ISSHAREDNETWORK="network_assignments#is_shared_network";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_ISEXTERNALNETWORK="network_assignments#is_external_network";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_ECOMPGENERATEDNETWORKASSIGNMENT="network_assignments#ecomp_generated_network_assignment";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_USEIPV4="network_assignments#ipv4_subnet_default_assignments#use_ipv4";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_IPNETWORKADDRESSPLAN="network_assignments#ipv4_subnet_default_assignments#ip_network_address_plan";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_DHCPENABLED="network_assignments#ipv4_subnet_default_assignments#dhcp_enabled";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_IPVERSION="network_assignments#ipv4_subnet_default_assignments#ip_version";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_CIDRMASK="network_assignments#ipv4_subnet_default_assignments#cidr_mask";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV4SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT="network_assignments#ipv4_subnet_default_assignments#min_subnets_count";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_USEIPV6="network_assignments#ipv6_subnet_default_assignments#use_ipv6";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_IPNETWORKADDRESSPLAN="network_assignments#ipv6_subnet_default_assignments#ip_network_address_plan";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_DHCPENABLED="network_assignments#ipv6_subnet_default_assignments#dhcp_enabled";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_IPVERSION="network_assignments#ipv6_subnet_default_assignments#ip_version";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_CIDRMASK="network_assignments#ipv6_subnet_default_assignments#cidr_mask";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_IPV6SUBNETDEFAULTASSIGNMENTS_MINSUBNETSCOUNT="network_assignments#ipv6_subnet_default_assignments#min_subnets_count";
+
+ /*public static String PROPERTY_NAME_NETWORKASSIGNMENTS_PROVIDERNETWORK_ISPROVIDERNETWORK="network_assignments#provider_network#is_provider_network";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_PROVIDERNETWORK_PHYSICALNETWORKNAME="network_assignments#provider_network#physical_network_name";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_PROVIDERNETWORK_NUMA="network_assignments#provider_network#numa";
+ public static String PROPERTY_NAME_NETWORKASSIGNMENTS_PROVIDERNETWORK_PNICINSTANCE="network_assignments#provider_network#pnic_instance";
+ */
+
+ public static String PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK="provider_network#is_provider_network";
+ public static String PROPERTY_NAME_PROVIDERNETWORK_PHYSICALNETWORKNAME="provider_network#physical_network_name";
+ public static String PROPERTY_NAME_PROVIDERNETWORK_NUMA="provider_network#numa";
+ public static String PROPERTY_NAME_PROVIDERNETWORK_PNICINSTANCE="provider_network#pnic_instance";
+
+ public static String PROPERTY_NAME_NETWORKFLOWS_ISBOUNDTOVPN="network_flows#is_bound_to_vpn";
+ public static String PROPERTY_NAME_NETWORKFLOWS_VPNBINDING="network_flows#vpn_binding";
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
new file mode 100644
index 0000000..2ddde1f
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
@@ -0,0 +1,82 @@
+package org.openecomp.sdc.tosca.parser.impl;
+
+import org.openecomp.sdc.tosca.parser.api.ConformanceLevel;
+import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.config.*;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.tosca.parser.utils.GeneralUtility;
+import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
+import org.openecomp.sdc.toscaparser.api.common.JToscaException;
+import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes;
+
+public class SdcToscaParserFactory {
+
+ private static volatile SdcToscaParserFactory instance;
+ private static Configuration configuration;
+ private static ErrorConfiguration errorConfiguration;
+
+ private SdcToscaParserFactory() {
+
+ }
+
+ /**
+ * Get an SdcToscaParserFactory instance.
+ * @return SdcToscaParserFactory instance.
+ */
+ public static SdcToscaParserFactory getInstance() {
+ if (instance == null) {
+ synchronized (SdcToscaParserFactory.class) {
+ if (instance == null) {
+ instance = new SdcToscaParserFactory();
+ configuration = ConfigurationManager.getInstance().getConfiguration();
+ errorConfiguration = ConfigurationManager.getInstance().getErrorConfiguration();
+ }
+ }
+ }
+ return instance;
+ }
+
+ /**
+ * Get an ISdcCsarHelper object for this CSAR file.
+ *
+ * @param csarPath - the absolute path to CSAR file.
+ * @return ISdcCsarHelper object.
+ * @throws SdcToscaParserException - in case the path or CSAR are invalid.
+ */
+ public ISdcCsarHelper getSdcCsarHelper(String csarPath) throws SdcToscaParserException {
+ synchronized (SdcToscaParserFactory.class) {
+ ToscaTemplate tosca = null;
+ try {
+ tosca = new ToscaTemplate(csarPath, null, true, null);
+ } catch (JToscaException e) {
+ throwSdcToscaParserException(e);
+ }
+ SdcCsarHelperImpl sdcCsarHelperImpl = new SdcCsarHelperImpl(tosca);
+ validateCsarVersion(sdcCsarHelperImpl.getConformanceLevel());
+ return sdcCsarHelperImpl;
+ }
+ }
+
+ private void validateCsarVersion(String cSarVersion) throws SdcToscaParserException {
+ ConformanceLevel level = configuration.getConformanceLevel();
+ String minVersion = level.getMinVersion();
+ String maxVersion = level.getMaxVersion();
+ if (cSarVersion != null) {
+ if ((GeneralUtility.conformanceLevelCompare(cSarVersion, minVersion) < 0) || (GeneralUtility.conformanceLevelCompare(cSarVersion, maxVersion) > 0)) {
+ throwConformanceLevelException(minVersion, maxVersion);
+ }
+ } else {
+ throwConformanceLevelException(minVersion, maxVersion);
+ }
+ }
+
+ private void throwConformanceLevelException(String minVersion, String maxVersion) throws SdcToscaParserException {
+ ErrorInfo errorInfo = errorConfiguration.getErrorInfo(SdcToscaParserErrors.CONFORMANCE_LEVEL_ERROR.toString());
+ throw new SdcToscaParserException(String.format(errorInfo.getMessage(), minVersion, maxVersion), errorInfo.getCode());
+ }
+
+ private void throwSdcToscaParserException(JToscaException e) throws SdcToscaParserException {
+ ErrorInfo errorInfo = errorConfiguration.getErrorInfo(SdcToscaParserErrors.getSdcErrorByJToscaError(JToscaErrorCodes.getByCode(e.getCode())).toString());
+ throw new SdcToscaParserException(errorInfo.getMessage(), errorInfo.getCode());
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/impl/Types.java b/src/main/java/org/openecomp/sdc/tosca/parser/impl/Types.java
new file mode 100644
index 0000000..9e71476
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/impl/Types.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * 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=========================================================
+ */
+
+package org.openecomp.sdc.tosca.parser.impl;
+
+public class Types {
+ public static String TYPE_VFMODULE = "org.openecomp.groups.VfModule";
+
+ // types found under metadata, type property
+ public static String TYPE_CP = "CP";
+ public static String TYPE_VL = "VL";
+ public static String TYPE_VF = "VF";
+ public static String TYPE_VFC = "VFC";
+ public static String TYPE_SERVICE = "Service";
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java b/src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java
new file mode 100644
index 0000000..84150f6
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/utils/GeneralUtility.java
@@ -0,0 +1,53 @@
+package org.openecomp.sdc.tosca.parser.utils;
+
+import java.util.Arrays;
+
+public class GeneralUtility {
+
+ public static boolean isEmptyString(String str) {
+ return str == null || str.trim().isEmpty();
+ }
+
+
+ /**
+ * Compares two version strings.
+ * <p>
+ * Use this instead of String.compareTo() for a non-lexicographical
+ * comparison that works for version strings. e.g. "1.10".compareTo("1.6").
+ *
+ * @param str1 a string of ordinal numbers separated by decimal points.
+ * @param str2 a string of ordinal numbers separated by decimal points.
+ * @return The result is a negative integer if str1 is _numerically_ less than str2.
+ * The result is a positive integer if str1 is _numerically_ greater than str2.
+ * The result is zero if the strings are _numerically_ equal.
+ * It does not work if "1.10" is supposed to be equal to "1.10.0".
+ */
+ public static int conformanceLevelCompare(String str1, String str2) {
+ String[] vals1 = str1.split("\\.");
+ String[] vals2 = str2.split("\\.");
+ int i = 0;
+ // set index to first non-equal ordinal or length of shortest version string
+ while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) {
+ i++;
+ }
+ // compare first non-equal ordinal number
+ if (i < vals1.length && i < vals2.length) {
+ int diff = Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i]));
+ return Integer.signum(diff);
+ }
+ //in case of 0 after the . e.g: "3" = "3.0" or "3.0.0.0" = "3.0"
+ str2 = str2.substring(i).replace(".", "");
+ str1 = str1.substring(i).replace(".", "");
+ if ((!(str1.equals(""))) && Integer.valueOf(str1) == 0){
+ vals1 = Arrays.copyOf(vals1, i);
+ }
+ if ((!(str2.equals(""))) && Integer.valueOf(str2) == 0){
+ vals2 = Arrays.copyOf(vals2, i);
+ }
+
+ // the strings are equal or one string is a substring of the other
+ // e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4"
+ return Integer.signum(vals1.length - vals2.length);
+ }
+
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/utils/SdcToscaUtility.java b/src/main/java/org/openecomp/sdc/tosca/parser/utils/SdcToscaUtility.java
new file mode 100644
index 0000000..77f7d55
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/utils/SdcToscaUtility.java
@@ -0,0 +1,19 @@
+package org.openecomp.sdc.tosca.parser.utils;
+
+import java.util.regex.Pattern;
+
+public class SdcToscaUtility {
+
+ public final static Pattern COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN = Pattern.compile("[\\.\\-]+");
+
+ public static String normaliseComponentInstanceName(String name) {
+ String normalizedName = name.toLowerCase();
+ normalizedName = COMPONENT_INSTANCE_NAME_DELIMETER_PATTERN.matcher(normalizedName).replaceAll(" ");
+ String[] split = normalizedName.split(" ");
+ StringBuffer sb = new StringBuffer();
+ for (String splitElement : split) {
+ sb.append(splitElement);
+ }
+ return sb.toString();
+ }
+}
diff --git a/src/main/java/org/openecomp/sdc/tosca/parser/utils/YamlToObjectConverter.java b/src/main/java/org/openecomp/sdc/tosca/parser/utils/YamlToObjectConverter.java
new file mode 100644
index 0000000..44444d2
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/tosca/parser/utils/YamlToObjectConverter.java
@@ -0,0 +1,123 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * 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=========================================================
+ */
+
+package org.openecomp.sdc.tosca.parser.utils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+
+public class YamlToObjectConverter {
+
+ private static Logger log = LoggerFactory
+ .getLogger(YamlToObjectConverter.class.getName());
+
+ private static HashMap<String, Yaml> yamls = new HashMap<String, Yaml>();
+
+ private static Yaml defaultYaml = new Yaml();
+
+ private static <T> Yaml getYamlByClassName(Class<T> className) {
+
+ Yaml yaml = yamls.get(className.getName());
+ if (yaml == null) {
+ yaml = defaultYaml;
+ }
+
+ return yaml;
+ }
+
+ public <T> T convert(String dirPath, Class<T> className,
+ String configFileName) {
+
+ T config = null;
+
+ try {
+
+ String fullFileName = dirPath + File.separator + configFileName;
+
+ config = convert(fullFileName, className);
+
+ } catch (Exception e) {
+ log.error("Failed to convert yaml file " + configFileName
+ + " to object.", e);
+ }
+
+ return config;
+ }
+
+ public <T> T convert(String fullFileName, Class<T> className) {
+
+ T config = null;
+
+ Yaml yaml = getYamlByClassName(className);
+
+ InputStream in = null;
+ try {
+
+ File f = new File(fullFileName);
+ if (false == f.exists()) {
+ log.warn("The file " + fullFileName
+ + " cannot be found. Ignore reading configuration.");
+ return null;
+ }
+ in = Files.newInputStream(Paths.get(fullFileName));
+
+ config = yaml.loadAs(in, className);
+
+ // System.out.println(config.toString());
+ } catch (Exception e) {
+ log.error("Failed to convert yaml file " + fullFileName
+ + " to object.", e);
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ return config;
+ }
+
+ public <T> T convertFromString(String yamlContents, Class<T> className) {
+
+ T config = null;
+
+ Yaml yaml = getYamlByClassName(className);
+
+ try {
+ config = yaml.loadAs(yamlContents, className);
+ } catch (Exception e){
+ log.error("Failed to convert YAML {} to object." , yamlContents, e);
+ }
+
+ return config;
+ }
+}
diff --git a/src/main/resources/config/configuration.yaml b/src/main/resources/config/configuration.yaml
new file mode 100644
index 0000000..379e962
--- /dev/null
+++ b/src/main/resources/config/configuration.yaml
@@ -0,0 +1,3 @@
+conformanceLevel:
+ minVersion: '3.0'
+ maxVersion: '3.0' \ No newline at end of file
diff --git a/src/main/resources/config/error-configuration.yaml b/src/main/resources/config/error-configuration.yaml
new file mode 100644
index 0000000..3febd33
--- /dev/null
+++ b/src/main/resources/config/error-configuration.yaml
@@ -0,0 +1,18 @@
+# Errors
+errors:
+ FILE_NOT_FOUND: {
+ code: TP0001,
+ message: "Error: CSAR file not found."
+ }
+ BAD_FORMAT: {
+ code: TP0002,
+ message: "Error: CSAR file bad format. Check the log for details."
+ }
+ CONFORMANCE_LEVEL_ERROR: {
+ code: TP0003,
+ message: "Error: CSAR version is unsupported. Parser supports versions %s to %s."
+ }
+ GENERAL_ERROR: {
+ code: TP0004,
+ message: "Error: an unexpected internal error occured."
+ } \ No newline at end of file
diff --git a/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java b/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java
new file mode 100644
index 0000000..7ea231c
--- /dev/null
+++ b/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java
@@ -0,0 +1,120 @@
+package org.openecomp.sdc.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory;
+import org.openecomp.sdc.toscaparser.api.common.JToscaException;
+import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+
+public abstract class SdcToscaParserBasicTest {
+
+ public static final String VF_CUSTOMIZATION_UUID = "56179cd8-de4a-4c38-919b-bbc4452d2d73";
+ static SdcToscaParserFactory factory;
+ static ISdcCsarHelper rainyCsarHelperSingleVf;
+ static ISdcCsarHelper rainyCsarHelperMultiVfs;
+ static ISdcCsarHelper fdntCsarHelper;
+ static ISdcCsarHelper complexCps;
+ static ISdcCsarHelper fdntCsarHelperWithInputs;
+ static Map<String, HashMap<String, List<String>>> fdntCsarHelper_Data;
+
+ @BeforeClass
+ public static void init() throws SdcToscaParserException, JToscaException, IOException {
+
+ factory = SdcToscaParserFactory.getInstance();
+ fdntCsarHelper = getCsarHelper("csars/service-ServiceFdnt-with-allotted.csar");
+ rainyCsarHelperMultiVfs = getCsarHelper("csars/service-ServiceFdnt-csar-rainy.csar");
+ rainyCsarHelperSingleVf = getCsarHelper("csars/service-ServiceFdnt-csar.csar");
+ complexCps = getCsarHelper("csars/service-Renanatst2-csar.csar");
+ fdntCsarHelperWithInputs = getCsarHelper("csars/service-ServiceFdnt-with-get-input.csar");
+
+ fdntCsarHelper_Data = new HashMap<String, HashMap<String, List<String>>>(){
+ {
+ HashMap<String, List<String>> FDNT ;
+
+ FDNT = new HashMap<String, List<String>>();
+ FDNT.put("VF Name", Arrays.asList("FDNT 1"));
+ FDNT.put("capabilities", Arrays.asList(
+ "dnt_fw_rhrg.binding_DNT_FW_INT_DNS_TRUSTED_RVMI",
+ "dnt_fw_rhrg.host_DNT_FW_SERVER",
+ "dnt_fw_rhrg.binding_DNT_FW_CORE_DIRECT_RVMI",
+ "dnt_fw_rhrg.scalable_DNT_FW_SERVER",
+ "dnt_fw_rhrg.endpoint_DNT_FW_SERVER",
+ "dnt_fw_rhrg.binding_DNT_FW_INTERNET_DNS_DIRECT_RVMI",
+ "dnt_fw_rhrg.os_DNT_FW_SERVER",
+ "dnt_fw_rhrg.feature",
+ "dnt_fw_rhrg.binding_DNT_FW_OAM_PROTECTED_RVMI",
+ "dnt_fw_rhrg.binding_DNT_FW_SERVER",
+ "dnt_fw_rhrg.binding_DNT_FW_NIMBUS_HSL_RVMI",
+ "dnt_fw_rsg_si_1.feature"));
+ FDNT.put("requirements", Arrays.asList(
+ "DNT_FW_RSG_SI_1.dependency",
+ "DNT_FW_RHRG.dependency",
+ "DNT_FW_RHRG.link_DNT_FW_INTERNET_DNS_DIRECT_RVMI",
+ "DNT_FW_RHRG.link_DNT_FW_CORE_DIRECT_RVMI",
+ "DNT_FW_RHRG.link_DNT_FW_OAM_PROTECTED_RVMI",
+ "DNT_FW_RHRG.link_DNT_FW_INT_DNS_TRUSTED_RVMI",
+ "DNT_FW_RHRG.link_DNT_FW_NIMBUS_HSL_RVMI",
+ "DNT_FW_RSG_SI_1.port",
+ "DNT_FW_RHRG.local_storage_DNT_FW_SERVER"));
+ FDNT.put("capabilitiesTypes", Arrays.asList(
+ "tosca.capabilities.network.Bindable",
+ "tosca.capabilities.OperatingSystem",
+ "tosca.capabilities.network.Bindable",
+ "tosca.capabilities.Scalable",
+ "tosca.capabilities.Endpoint.Admin",
+ "tosca.capabilities.network.Bindable",
+ "tosca.capabilities.network.Bindable",
+ "tosca.capabilities.network.Bindable",
+ "tosca.capabilities.Node",
+ "tosca.capabilities.Container",
+ "tosca.nodes.SoftwareComponent",
+ "tosca.capabilities.network.Bindable"));
+ FDNT.put("capabilityProperties", Arrays.asList(
+ "dnt_fw_rhrg.binding_DNT_FW_INT_DNS_TRUSTED_RVMI:none",
+ "dnt_fw_rhrg.host_DNT_FW_SERVER:num_cpus,integer,false;",
+ "dnt_fw_rhrg.binding_DNT_FW_CORE_DIRECT_RVMI",
+ "dnt_fw_rhrg.scalable_DNT_FW_SERVER",
+ "dnt_fw_rhrg.endpoint_DNT_FW_SERVER",
+ "dnt_fw_rhrg.binding_DNT_FW_INTERNET_DNS_DIRECT_RVMI",
+ "dnt_fw_rhrg.os_DNT_FW_SERVER",
+ "dnt_fw_rhrg.feature",
+ "dnt_fw_rhrg.binding_DNT_FW_OAM_PROTECTED_RVMI",
+ "dnt_fw_rhrg.binding_DNT_FW_SERVER",
+ "dnt_fw_rhrg.binding_DNT_FW_NIMBUS_HSL_RVMI",
+ "dnt_fw_rsg_si_1.feature"));
+
+
+ put("FDNT", FDNT);
+ }
+ };
+ };
+
+ protected static ISdcCsarHelper getCsarHelper(String path) throws SdcToscaParserException {
+ System.out.println("Parsing CSAR "+path+"...");
+ String fileStr1 = SdcToscaParserBasicTest.class.getClassLoader().getResource(path).getFile();
+ File file1 = new File(fileStr1);
+ ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath());
+ return sdcCsarHelper;
+ }
+
+ @BeforeMethod
+ public void setupTest(Method method) {
+ System.out.println("#### Starting Test " + method.getName() + " ###########");
+ }
+
+ @AfterMethod
+ public void tearDown(Method method){
+ System.out.println("#### Ended test " + method.getName() + " ###########");
+ }
+}
diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java
new file mode 100644
index 0000000..8c96303
--- /dev/null
+++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java
@@ -0,0 +1,31 @@
+package org.openecomp.sdc.impl;
+
+import org.openecomp.sdc.tosca.parser.config.ErrorConfiguration;
+import org.testng.annotations.Test;
+import org.openecomp.sdc.tosca.parser.config.Configuration;
+import org.openecomp.sdc.tosca.parser.config.ConfigurationManager;
+
+import java.io.IOException;
+
+import static org.testng.Assert.assertNotNull;
+
+public class ToscaParserConfigurationTest extends SdcToscaParserBasicTest {
+
+ @Test
+ public void testConfigurationConformanceLevel() throws IOException {
+ Configuration config = ConfigurationManager.getInstance().getConfiguration();
+ assertNotNull(config);
+ assertNotNull(config.getConformanceLevel());
+ assertNotNull(config.getConformanceLevel().getMaxVersion());
+ assertNotNull(config.getConformanceLevel().getMinVersion());
+ }
+
+
+ @Test
+ public void testErrorConfigurations() throws IOException {
+ ErrorConfiguration errorConfig = ConfigurationManager.getInstance().getErrorConfiguration();
+ assertNotNull(errorConfig);
+ assertNotNull(errorConfig.getErrors());
+ }
+
+}
diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java
new file mode 100644
index 0000000..8451a58
--- /dev/null
+++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java
@@ -0,0 +1,143 @@
+package org.openecomp.sdc.impl;
+
+import org.testng.annotations.Test;
+import static org.testng.Assert.*;
+
+import java.io.File;
+
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes;
+
+
+/*put(JToscaErrorCodes.GENERAL_ERROR, GENERAL_ERROR);
+
+put(JToscaErrorCodes.PATH_NOT_VALID, FILE_NOT_FOUND);
+//CSAR contents problems
+put(JToscaErrorCodes.MISSING_META_FILE, BAD_FORMAT);
+put(JToscaErrorCodes.INVALID_META_YAML_CONTENT, BAD_FORMAT);
+put(JToscaErrorCodes.ENTRY_DEFINITION_NOT_DEFINED, BAD_FORMAT);
+put(JToscaErrorCodes.MISSING_ENTRY_DEFINITION_FILE, BAD_FORMAT);
+put(JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR, BAD_FORMAT);
+
+ MISSING_META_FILE("JT1001"),
+/* INVALID_META_YAML_CONTENT("JT1002"),
+/* ENTRY_DEFINITION_NOT_DEFINED("JT1003"),
+/* MISSING_ENTRY_DEFINITION_FILE("JT1004"),
+/* GENERAL_ERROR("JT1005"),
+/* PATH_NOT_VALID("JT1006"),
+/* CSAR_TOSCA_VALIDATION_ERROR("JT1007");
+
+*/
+
+/*
+ *
+ * # Errors
+errors:
+ FILE_NOT_FOUND: {
+ code: TP0001,
+ message: "Error: CSAR file not found."
+ }
+ BAD_FORMAT: {
+ code: TP0002,
+ message: "Error: CSAR file bad format. Check the log for details."
+ }
+ CONFORMANCE_LEVEL_ERROR: {
+ code: TP0003,
+ message: "Error: CSAR version is unsupported. Parser supports versions %s to %s."
+ }
+ GENERAL_ERROR: {
+ code: TP0004,
+ message: "Error: an unexpected internal error occured."
+ }
+ *
+ */
+
+public class ToscaParserErrorHandlingTest extends SdcToscaParserBasicTest {
+
+
+ @Test
+ public void testMissingMetadata(){
+ String csarPath = "csars/service-missing-meta-file.csar";
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ testThrowable(captureThrowable, "TP0002");
+ }
+
+
+ @Test
+ public void testInvalidYamlContentMeta(){
+ String csarPath = "csars/service-invalid-yaml-content-meta.csar";
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ testThrowable(captureThrowable, "TP0002");
+ }
+
+ @Test
+ public void testEntryDefinitionNotDefined(){
+ String csarPath = "csars/service-entry-definition-not-defined.csar";
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ testThrowable(captureThrowable, "TP0002");
+ }
+
+ @Test
+ public void testMissingEntryDefinitionFile(){
+ String csarPath = "csars/service-missing-entry-definition.csar";
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ testThrowable(captureThrowable, "TP0002");
+ }
+
+ //@Test - PA - there are currently no critical erros in JTosca
+ public void tesValidationError(){
+ String csarPath = "csars/service-invalid-input-args.csar";
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ testThrowable(captureThrowable, "TP0002");
+ }
+
+ @Test
+ public void testInValidConformanceLevelError(){
+ String csarPath = "csars/service-invalid-conformence-level.csar";
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ testThrowable(captureThrowable, "TP0003");
+ }
+
+ @Test
+ public void testFileNotFound(){
+ Throwable captureThrowable = captureThrowable("csars/XXX.csar");
+ testThrowable(captureThrowable, "TP0001");
+ }
+
+ @Test
+ public void testInvalidCsarFormat(){
+ String csarPath = "csars/csar-invalid-zip.zip";
+ String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile();
+ File file = new File(fileLocationString);
+ Throwable captureThrowable = captureThrowable(file.getAbsolutePath());
+ testThrowable(captureThrowable, "TP0002");
+ }
+
+ private static void testThrowable(Throwable captureThrowable, String expectedCode) {
+ assertNotNull(captureThrowable);
+ assertTrue(captureThrowable instanceof SdcToscaParserException, "Error thrown is of type "+captureThrowable.getClass().getSimpleName());
+ assertEquals(((SdcToscaParserException)captureThrowable).getCode(), expectedCode);
+ }
+
+ public static Throwable captureThrowable(String csarPath) {
+ Throwable result = null;
+ try {
+ factory.getSdcCsarHelper(csarPath);
+ } catch( Throwable throwable ) {
+ result = throwable;
+ }
+ return result;
+ }
+}
diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java
new file mode 100644
index 0000000..9f349ae
--- /dev/null
+++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java
@@ -0,0 +1,23 @@
+package org.openecomp.sdc.impl;
+
+import org.testng.annotations.Test;
+import org.openecomp.sdc.tosca.parser.utils.GeneralUtility;
+
+import static org.testng.Assert.assertTrue;
+
+public class ToscaParserGeneralUtilTest extends SdcToscaParserBasicTest {
+
+ @Test
+ public void testVersionCompare() {
+ assertTrue(GeneralUtility.conformanceLevelCompare("2", "3.0") < 0);
+ assertTrue(GeneralUtility.conformanceLevelCompare("0.5", "0.5") == 0);
+ assertTrue(GeneralUtility.conformanceLevelCompare("0.5", "0.6") < 0);
+ assertTrue(GeneralUtility.conformanceLevelCompare("1.5", "2.6") < 0);
+ assertTrue(GeneralUtility.conformanceLevelCompare("0.2", "0.1") > 0);
+ assertTrue(GeneralUtility.conformanceLevelCompare("2", "1.15") > 0);
+ assertTrue(GeneralUtility.conformanceLevelCompare("2", "2.0.0") == 0);
+ assertTrue(GeneralUtility.conformanceLevelCompare("2.0", "2.0.0.0") == 0);
+ assertTrue(GeneralUtility.conformanceLevelCompare("2.", "2.0.0.0") == 0);
+ assertTrue(GeneralUtility.conformanceLevelCompare("2.0", "2.0.0.2") < 0);
+ }
+}
diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java
new file mode 100644
index 0000000..d7321d1
--- /dev/null
+++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java
@@ -0,0 +1,116 @@
+package org.openecomp.sdc.impl;
+
+import org.testng.annotations.Test;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.toscaparser.api.Group;
+import org.openecomp.sdc.toscaparser.api.elements.Metadata;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.testng.Assert.*;
+
+public class ToscaParserGroupTest extends SdcToscaParserBasicTest{
+
+ //region getVfModulesByVf
+ @Test
+ public void testVfModulesFromVf(){
+ List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
+ assertEquals(2, vfModulesByVf.size());
+ for (Group group : vfModulesByVf){
+ assertTrue(group.getName().startsWith("fdnt1"));
+ assertNotNull(group.getMetadata());
+ assertNotNull(group.getMetadata().getValue("vfModuleCustomizationUUID"));
+ }
+ }
+
+ @Test
+ public void testGetGroupMetadata(){
+ List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
+ boolean found = false;
+ for (Group group : vfModulesByVf){
+ if (group.getName().equals("fdnt1..Fdnt..base_stsi_dnt_frwl..module-0")){
+ found = true;
+ Metadata metadata = group.getMetadata();
+ assertNotNull(metadata);
+ assertEquals("b458f4ef-ede2-403d-9605-d08c9398b6ee", metadata.getValue("vfModuleModelCustomizationUUID"));
+ }
+ }
+ assertTrue(found);
+ }
+
+ @Test
+ public void testGetGroupEmptyMetadata(){
+ List<Group> vfModulesByVf = rainyCsarHelperMultiVfs.getVfModulesByVf("56179cd8-de4a-4c38-919b-bbc4452d2d72");
+ boolean found = false;
+ for (Group group : vfModulesByVf){
+ if (group.getName().equals("fdnt1..Fdnt..base_stsi_dnt_frwl..module-0")){
+ found = true;
+ Metadata metadata = group.getMetadata();
+ assertNull(metadata);
+ }
+ }
+ assertTrue(found);
+ }
+
+ @Test
+ public void testGetVfModuleNonExisitingVf() {
+ List<Group> vfModulesByVf = rainyCsarHelperSingleVf.getVfModulesByVf("dummy");
+ assertNotNull(vfModulesByVf);
+ assertEquals(0, vfModulesByVf.size());
+ }
+
+ @Test
+ public void testGetVfModuleNullVf() {
+ List<Group> vfModulesByVf = rainyCsarHelperSingleVf.getVfModulesByVf(null);
+ assertNotNull(vfModulesByVf);
+ assertEquals(0, vfModulesByVf.size());
+ }
+ //endregion
+
+ //region getGroupPropertyLeafValue
+ @Test
+ public void testGroupFlatProperty() throws SdcToscaParserException {
+ List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
+ String volumeGroup = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), "volume_group");
+ assertEquals("false", volumeGroup);
+ }
+
+// @Test
+// public void testGroupFlatGetInputProperty() throws SdcToscaParserException {
+// List<Group> vfModulesByVf = fdntCsarHelperWithInputs.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
+// String volumeGroup = fdntCsarHelperWithInputs.getGroupPropertyLeafValue(vfModulesByVf.get(1), "volume_group");
+// assertEquals("false", volumeGroup);
+// }
+
+ @Test
+ public void testGroupPropertyLeafValueByNullProperty() {
+ List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
+ String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), null);
+ assertNull(groupProperty);
+ }
+
+ @Test
+ public void testGroupPropertyLeafValueByDummyProperty() {
+ List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
+ String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(vfModulesByVf.get(0), "XXX");
+ assertNull(groupProperty);
+ }
+
+ @Test
+ public void testGroupPropertyLeafValueByNullGroup() {
+ String groupProperty = fdntCsarHelper.getGroupPropertyLeafValue(null, "volume_group");
+ assertNull(groupProperty);
+ }
+ //endregion
+
+ //region getGroupPropertyAsObject
+ @Test
+ public void testGetGroupPropertyAsObject() {
+ List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
+ Object volumeGroup = fdntCsarHelper.getGroupPropertyAsObject(vfModulesByVf.get(0), "volume_group");
+ assertEquals(false, volumeGroup);
+ }
+ //getGroupPropertyAsObject
+
+}
diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java
new file mode 100644
index 0000000..cd80f3a
--- /dev/null
+++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java
@@ -0,0 +1,84 @@
+package org.openecomp.sdc.impl;
+
+import org.testng.annotations.Test;
+import org.openecomp.sdc.toscaparser.api.elements.Metadata;
+
+import java.util.Map;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+
+public class ToscaParserMetadataTest extends SdcToscaParserBasicTest {
+
+ //region getServiceMetadata
+ @Test
+ public void testGetServiceMetadata() {
+ Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata();
+ assertNotNull(serviceMetadata);
+ assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", serviceMetadata.getValue("invariantUUID"));
+ assertEquals("Service FDNT", serviceMetadata.getValue("name"));
+ assertEquals("true", String.valueOf(serviceMetadata.getValue("serviceEcompNaming")));
+ }
+
+ @Test
+ public void testServiceMetadata() {
+ Metadata metadata = rainyCsarHelperSingleVf.getServiceMetadata();
+ assertNull(metadata);
+ }
+ //endregion
+
+ //region getMetadataPropertyValue
+ @Test
+ public void testGetMetadataProperty(){
+ Metadata serviceMetadata = fdntCsarHelper.getServiceMetadata();
+ String metadataPropertyValue = fdntCsarHelper.getMetadataPropertyValue(serviceMetadata, "invariantUUID");
+ assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", metadataPropertyValue);
+ }
+
+ @Test
+ public void testGetNullMetadataPropertyValue() {
+ String value = rainyCsarHelperMultiVfs.getMetadataPropertyValue(null, "XXX");
+ assertNull(value);
+ }
+
+ @Test
+ public void testGetMetadataByNullPropertyValue() {
+ Metadata metadata = rainyCsarHelperMultiVfs.getServiceMetadata();
+ String value = rainyCsarHelperMultiVfs.getMetadataPropertyValue(metadata, null);
+ assertNull(value);
+ }
+
+ @Test
+ public void testGetMetadataByEmptyPropertyValue() {
+ Metadata metadata = rainyCsarHelperMultiVfs.getServiceMetadata();
+ String value = rainyCsarHelperMultiVfs.getMetadataPropertyValue(metadata, "");
+ assertNull(value);
+ }
+ //endregion
+
+ //region getConformanceLevel
+ @Test
+ public void testSunnyGetConformanceLevel() {
+ String conformanceLevel = fdntCsarHelper.getConformanceLevel();
+ assertNotNull(conformanceLevel);
+ assertEquals("3.0", conformanceLevel);
+ }
+ //endregion
+
+ //region getServiceMetadataProperties
+ @Test
+ public void testNullServiceMetadataPropertiesMap() {
+ Map<String, Object> metadata = rainyCsarHelperSingleVf.getServiceMetadataProperties();
+ assertNull(metadata);
+ }
+
+ @Test
+ public void testServiceMetadataPropertiesMap() {
+ Map<String, Object> metadata = fdntCsarHelper.getServiceMetadataProperties();
+ assertNotNull(metadata);
+ assertEquals(metadata.size(),9);
+ assertEquals(metadata.get("namingPolicy"),"test");
+ }
+ //endregion
+}
diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
new file mode 100644
index 0000000..42a6bd4
--- /dev/null
+++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java
@@ -0,0 +1,397 @@
+package org.openecomp.sdc.impl;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.lang3.tuple.Pair;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.toscaparser.api.Group;
+import org.openecomp.sdc.toscaparser.api.NodeTemplate;
+import org.testng.annotations.Test;
+
+public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest {
+
+ //region getServiceVfList
+ @Test
+ public void testNumberOfVfSunnyFlow() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList();
+ assertNotNull(serviceVfList);
+ assertEquals(2, serviceVfList.size());
+ }
+
+ @Test
+ public void testGetNodeTemplateCustomizationUuid(){
+ List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList();
+ boolean found = false;
+ for (NodeTemplate nt : serviceVfList){
+ if (nt.getName().equals("FDNT 1")){
+ found = true;
+ assertEquals(fdntCsarHelper.getNodeTemplateCustomizationUuid(nt), "56179cd8-de4a-4c38-919b-bbc4452d2d73");
+ }
+ }
+ assertTrue(found);
+ }
+
+ @Test
+ public void testSingleVFWithNotMetadata() throws SdcToscaParserException {
+ //If there is no metadata on VF level - There is no VF's because the type is taken from metadata values.
+ List<NodeTemplate> serviceVfList = rainyCsarHelperSingleVf.getServiceVfList();
+ assertNotNull(serviceVfList);
+ assertEquals(0, serviceVfList.size());
+ }
+ //endregion
+
+ //region getNodeTemplatePropertyLeafValue
+ @Test
+ public void testNodeTemplateFlatProperty() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList();
+ assertEquals("2", fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "availability_zone_max_count"));
+ assertEquals("3", fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "max_instances"));
+ assertEquals("some code", fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_naming_code"));
+ }
+
+ @Test
+ public void testNodeTemplateFlatFunctionProperty() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = fdntCsarHelperWithInputs.getServiceVfList();
+ assertEquals(null, fdntCsarHelperWithInputs.getNodeTemplatePropertyLeafValue(serviceVfList.get(1), "target_network_role"));
+ }
+
+ @Test
+ public void testNodeTemplateNestedProperty() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVlList = fdntCsarHelper.getServiceVlList();
+ NodeTemplate nodeTemplate = serviceVlList.get(0);
+ //System.out.println("node template " + nodeTemplate.toString());
+ assertEquals("24", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "network_assignments#ipv4_subnet_default_assignment#cidr_mask"));
+ assertEquals("7a6520b-9982354-ee82992c-105720", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "network_flows#vpn_binding"));
+ }
+
+ @Test
+ public void testNodeTemplateNestedPropertyFromInput() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList();
+ NodeTemplate nodeTemplate = serviceVfList.get(0);
+ //System.out.println("node template " + nodeTemplate.toString());
+ assertEquals("true", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming#ecomp_generated_naming"));
+ assertEquals("FDNT_instance_VF_2", fdntCsarHelper.getNodeTemplatePropertyLeafValue(nodeTemplate, "nf_naming#naming_policy"));
+ }
+
+ @Test
+ public void testNodeTemplateNestedPropertyNotExists() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList();
+ String nodeTemplatePropertyLeafValue = fdntCsarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_role#nf_naming#kuku");
+ assertNull(nodeTemplatePropertyLeafValue);
+ }
+
+ @Test
+ public void testNodeTemplateFlatPropertyByNotFoundProperty() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = rainyCsarHelperMultiVfs.getServiceVfList();
+ String nodeTemplatePropertyLeafValue = rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "XXXX");
+ assertNull(nodeTemplatePropertyLeafValue);
+ }
+
+ @Test
+ public void testNodeTemplateFlatPropertyByNullProperty() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = rainyCsarHelperMultiVfs.getServiceVfList();
+ String nodeTemplatePropertyLeafValue = rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), null);
+ assertNull(nodeTemplatePropertyLeafValue);
+ }
+
+ @Test
+ public void testNodeTemplateFlatPropertyByNullNodeTemplate() throws SdcToscaParserException {
+ String nodeTemplatePropertyLeafValue = rainyCsarHelperMultiVfs.getNodeTemplatePropertyLeafValue(null, "availability_zone_max_count");
+ assertNull(nodeTemplatePropertyLeafValue);
+ }
+ //endregion
+
+ //region getServiceVlList
+ @Test
+ public void testServiceVl() {
+ List<NodeTemplate> vlList = fdntCsarHelper.getServiceVlList();
+ assertEquals(1, vlList.size());
+ assertEquals("exVL", vlList.get(0).getName());
+ }
+
+ @Test
+ public void testNumberOfVLRainyFlow() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVlList = rainyCsarHelperMultiVfs.getServiceVlList();
+ assertNotNull(serviceVlList);
+ assertEquals(0, serviceVlList.size());
+ }
+ //endregion
+
+ //region getServiceNodeTemplatesByType
+ @Test
+ public void testServiceNodeTemplatesByType() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceNodeTemplatesByType("org.openecomp.resource.vf.Fdnt");
+ assertNotNull(serviceVfList);
+ assertEquals(1, serviceVfList.size());
+ }
+
+ @Test
+ public void testServiceNodeTemplatesByNull() {
+ List<NodeTemplate> nodeTemplates = rainyCsarHelperMultiVfs.getServiceNodeTemplatesByType(null);
+ assertNotNull(nodeTemplates);
+ assertEquals(0, nodeTemplates.size());
+ }
+
+ @Test
+ public void testServiceNodeTemplatesByNotFoundProperty() {
+ List<NodeTemplate> nodeTemplates = rainyCsarHelperMultiVfs.getServiceNodeTemplatesByType("XXX");
+ assertNotNull(nodeTemplates);
+ assertEquals(0, nodeTemplates.size());
+ }
+ //endregion
+
+ //region getTypeOfNodeTemplate
+ @Test
+ public void testGetTypeOfNodeTemplate() {
+ List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList();
+ String typeOfNodeTemplate = fdntCsarHelper.getTypeOfNodeTemplate(serviceVfList.get(0));
+ assertEquals("org.openecomp.resource.vf.Fdnt", typeOfNodeTemplate);
+ }
+
+ @Test
+ public void testGetTypeOfNullNodeTemplate() {
+ String typeOfNodeTemplate = rainyCsarHelperMultiVfs.getTypeOfNodeTemplate(null);
+ assertNull(typeOfNodeTemplate);
+ }
+ //endregion
+
+ //region getAllottedResources
+ @Test
+ public void testGetAllottedResources() {
+ List<NodeTemplate> allottedResources = fdntCsarHelper.getAllottedResources();
+ assertEquals(1, allottedResources.size());
+ }
+
+ @Test
+ public void testGetAllottedResourcesZero() {
+ List<NodeTemplate> allottedResources = rainyCsarHelperMultiVfs.getAllottedResources();
+ assertNotNull(allottedResources);
+ assertEquals(0, allottedResources.size());
+ }
+ //endregion
+
+ //region getVfcListByVf
+ @Test
+ public void testGetVfcFromVf() {
+ List<NodeTemplate> vfcListByVf = fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID);
+ assertEquals(2, vfcListByVf.size());
+ }
+
+ @Test
+ public void testVfcListByNull() {
+ List<NodeTemplate> vfcList = rainyCsarHelperMultiVfs.getVfcListByVf(null);
+ assertNotNull(vfcList);
+ assertEquals(0, vfcList.size());
+ }
+
+ @Test
+ public void testVfcListByNotFoundProperty() {
+ List<NodeTemplate> vfcList = rainyCsarHelperMultiVfs.getVfcListByVf("XXX");
+ assertNotNull(vfcList);
+ assertEquals(0, vfcList.size());
+ }
+ //endregion
+
+ //region getCpListByVf
+ @Test
+ public void testGetCpFromVf() {
+ List<NodeTemplate> cpListByVf = fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID);
+ assertEquals(1, cpListByVf.size());
+ NodeTemplate nodeTemplate = cpListByVf.get(0);
+ assertEquals("DNT_PORT", nodeTemplate.getName());
+ }
+
+ @Test
+ public void testGetCpFromVfByNullId() {
+ List<NodeTemplate> cpListByVf = rainyCsarHelperMultiVfs.getCpListByVf(null);
+ assertNotNull(cpListByVf);
+ assertEquals(0, cpListByVf.size());
+ }
+
+ @Test
+ public void testGetCpFromVfXxx() {
+ List<NodeTemplate> cpListByVf = rainyCsarHelperMultiVfs.getCpListByVf("XXXXX");
+ assertNotNull(cpListByVf);
+ assertEquals(0, cpListByVf.size());
+ }
+ //endregion
+
+ //region getNodeTemplatePairsByReqName
+ @Test
+ public void testGetNodeTemplatePairsByReqName() {
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "binding");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(1, nodeTemplatePairsByReqName.size());
+ Pair<NodeTemplate, NodeTemplate> pair = nodeTemplatePairsByReqName.get(0);
+ NodeTemplate cp = pair.getLeft();
+ NodeTemplate vfc = pair.getRight();
+ assertEquals("DNT_PORT", cp.getName());
+ assertEquals("DNT_FW_RHRG", vfc.getName());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithNullVF() {
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(
+ null, fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "binding");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithEmptyVF() {
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(
+ new ArrayList<>(), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "binding");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithNullCap() {
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(
+ fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), null, "binding");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithEmptyCap() {
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(
+ fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), new ArrayList<>(), "binding");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithNullReq() {
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(
+ fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), null);
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+
+ @Test
+ public void testGetNodeTemplatePairsByReqNameWithDummyReq() {
+
+ List<Pair<NodeTemplate, NodeTemplate>> nodeTemplatePairsByReqName = fdntCsarHelper.getNodeTemplatePairsByReqName(
+ fdntCsarHelper.getCpListByVf(VF_CUSTOMIZATION_UUID), fdntCsarHelper.getVfcListByVf(VF_CUSTOMIZATION_UUID), "XXX");
+ assertNotNull(nodeTemplatePairsByReqName);
+ assertEquals(0, nodeTemplatePairsByReqName.size());
+ }
+ //endregion
+
+ //region getMembersOfVfModule
+ @Test
+ public void testGetMembersOfVfModule() {
+ NodeTemplate vf = fdntCsarHelper.getServiceVfList().get(0);
+ List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
+ assertEquals(2, vfModulesByVf.size());
+ for (Group group : vfModulesByVf) {
+ List<NodeTemplate> membersOfVfModule = fdntCsarHelper.getMembersOfVfModule(vf, group);
+ assertNotNull(membersOfVfModule);
+ if (group.getName().equals("fdnt1..Fdnt..base_stsi_dnt_frwl..module-0")) {
+ assertEquals(1, membersOfVfModule.size());
+ NodeTemplate nodeTemplate = membersOfVfModule.get(0);
+ assertEquals("DNT_FW_RSG_SI_1", nodeTemplate.getName());
+ } else {
+ assertEquals("fdnt1..Fdnt..mod_vmsi_dnt_fw_parent..module-1", group.getName());
+ assertEquals(1, membersOfVfModule.size());
+ NodeTemplate nodeTemplate = membersOfVfModule.get(0);
+ assertEquals("DNT_FW_RHRG", nodeTemplate.getName());
+ }
+ }
+ }
+
+ @Test
+ public void testMembersOfVfModuleByNullVf() {
+ List<Group> vfModulesByVf = fdntCsarHelper.getVfModulesByVf(VF_CUSTOMIZATION_UUID);
+ List<NodeTemplate> nodeTemplates = fdntCsarHelper.getMembersOfVfModule(null, vfModulesByVf.get(0));
+ assertNotNull(nodeTemplates);
+ assertEquals(0, nodeTemplates.size());
+ }
+
+ @Test
+ public void testMembersOfVfModuleByNullGroup() {
+ List<NodeTemplate> serviceVfList = rainyCsarHelperMultiVfs.getServiceVfList();
+ List<NodeTemplate> nodeTemplates = rainyCsarHelperMultiVfs.getMembersOfVfModule(serviceVfList.get(0), null);
+ assertNotNull(nodeTemplates);
+ assertEquals(0, nodeTemplates.size());
+ }
+ //endregion
+
+ //region getCpPropertiesFromVfc
+ @Test
+ public void testGetCpPropertiesFromVfc() {
+ List<NodeTemplate> vfcs = complexCps.getVfcListByVf("f999e2ca-72c0-42d3-9b11-13f2122fb8ef");
+ boolean isChecked = false;
+ boolean isChecked1 = false;
+ for (int i = 0; i < vfcs.size(); i++) {
+
+ if(vfcs.get(i).getName().equalsIgnoreCase("abstract_ddc"))
+ {
+ isChecked = true;
+ Map<String, Map<String, Object>> cps = complexCps.getCpPropertiesFromVfc(vfcs.get(i));
+
+ assertEquals(3,cps.size());
+
+ assertEquals(new Integer(1), cps.get("ddc_int_imbl__port").get("ip_requirements#ip_count_required#count"));
+ assertEquals(new Boolean(true), cps.get("ddc_int_imbl__port").get("ip_requirements#dhcp_enabled"));
+ assertEquals(new Integer(6), cps.get("ddc_int_imbl__port").get("ip_requirements#ip_version"));
+ assertEquals(null, cps.get("ddc_int_imbl__port").get("subnetpoolid"));
+
+ //assertEquals("\"int_imsp\"", cps.get("mon_ist_imsp__port").get("network_role_tag"));
+
+ }
+
+ if(vfcs.get(i).getName().equalsIgnoreCase("abstract_mda"))
+ {
+ isChecked1 = true;
+ Map<String, Map<String, Object>> cps1 = complexCps.getCpPropertiesFromVfc(vfcs.get(i));
+
+ assertEquals(new Integer(4), cps1.get("mda_int_imsp__port").get("ip_requirements#ip_version"));
+ assertEquals(null, cps1.get("mda_int_imsp__port").get("ip_requirements#ip_count_required#count"));
+
+ }
+
+ }
+ assertTrue(isChecked);
+ assertTrue(isChecked1);
+ }
+
+
+ @Test
+ public void testGetCpPropertiesFromVfcForNullVFC() {
+ Map<String, Map<String, Object>> cps = complexCps.getCpPropertiesFromVfc(null);
+ assertNotNull(cps);
+ assertEquals(0, cps.size());
+ }
+ //endregion
+
+ //region getNodeTemplatePropertyAsObject
+ @Test
+ public void testGetNodeTemplatePropertyAsObject() {
+ List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList();
+ assertEquals("2", fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "availability_zone_max_count"));
+ assertEquals(3, fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "max_instances"));
+ assertEquals("some code", fdntCsarHelper.getNodeTemplatePropertyAsObject(serviceVfList.get(0), "nf_naming_code"));
+ }
+ //endregion
+
+ //region getServiceNodeTemplates
+ @Test
+ public void testServiceNodeTemplates() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceNodeTemplates();
+ assertNotNull(serviceVfList);
+ assertEquals(3, serviceVfList.size());
+ assertEquals(serviceVfList.get(2).getName(), "exVL");
+ }
+ //endregion
+
+}
diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java
new file mode 100644
index 0000000..ea5c2ef
--- /dev/null
+++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java
@@ -0,0 +1,63 @@
+package org.openecomp.sdc.impl;
+
+import org.testng.annotations.Test;
+import org.openecomp.sdc.toscaparser.api.parameters.Input;
+
+import java.util.List;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+
+public class ToscaParserServiceInputTest extends SdcToscaParserBasicTest {
+
+ //region getServiceInputs
+ @Test
+ public void testGetServiceInputs(){
+ List<Input> serviceInputs = fdntCsarHelper.getServiceInputs();
+ assertNotNull(serviceInputs);
+ assertEquals(1, serviceInputs.size());
+ }
+
+ @Test
+ public void testServiceInputs() {
+ List<Input> inputs = rainyCsarHelperSingleVf.getServiceInputs();
+ assertNotNull(inputs);
+ assertEquals(0, inputs.size());
+ }
+ //endregion
+
+ //region getServiceInputLeafValueOfDefault
+ @Test
+ public void testGetServiceInputLeafValue(){
+ String serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default");
+ assertEquals("test service naming", serviceInputLeafValue);
+ }
+
+// @Test
+// public void testGetServiceInputLeafValueWithGetInput(){
+// String serviceInputLeafValue = fdntCsarHelperWithInputs.getServiceInputLeafValueOfDefault("my_input#default");
+// assertEquals(null, serviceInputLeafValue);
+// }
+
+ @Test
+ public void testGetServiceInputLeafValueNotExists(){
+ String serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default#kuku");
+ assertNull(serviceInputLeafValue);
+ }
+
+ @Test
+ public void testGetServiceInputLeafValueNull(){
+ String serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault(null);
+ assertNull(serviceInputLeafValue);
+ }
+ //endregion
+
+ //region getServiceInputLeafValueOfDefaultAsObject
+ @Test
+ public void testGetServiceInputLeafValueOfDefaultAsObject() {
+ Object serviceInputLeafValue = fdntCsarHelper.getServiceInputLeafValueOfDefault("service_naming#default");
+ assertEquals("test service naming", serviceInputLeafValue);
+ }
+ //endregion
+}
diff --git a/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java b/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java
new file mode 100644
index 0000000..6461a92
--- /dev/null
+++ b/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java
@@ -0,0 +1,132 @@
+package org.openecomp.sdc.impl;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.toscaparser.api.Capability;
+import org.openecomp.sdc.toscaparser.api.NodeTemplate;
+import org.openecomp.sdc.toscaparser.api.elements.CapabilityTypeDef;
+//import org.testng.ReporterConfig.Property;
+import org.testng.annotations.Test;
+import org.openecomp.sdc.toscaparser.api.Property;
+
+//import static org.junit.Assert.assertEquals;
+//import static org.junit.Assert.assertNull;
+
+public class ToscaParserSubsMappingsTest extends SdcToscaParserBasicTest {
+
+ //region getServiceSubstitutionMappingsTypeName
+ @Test
+ public void testGetServiceSubstitutionMappingsTypeName() {
+ String serviceSubstitutionMappingsTypeName = fdntCsarHelper.getServiceSubstitutionMappingsTypeName();
+ assertEquals("org.openecomp.service.ServiceFdnt", serviceSubstitutionMappingsTypeName);
+ }
+
+ @Test
+ public void testServiceSubstitutionMappingsTypeName() {
+ String substitutionMappingsTypeName = rainyCsarHelperMultiVfs.getServiceSubstitutionMappingsTypeName();
+ assertNull(substitutionMappingsTypeName);
+ }
+ //endregion
+
+ //Added by QA - Check for Capabilities in VF level (Capabilities QTY and Names).
+ //@Test // - BUG 283369
+ public void testCapabilitiesofVFNames_QTY() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList();
+ String sName = serviceVfList.get(0).getName();
+ assertEquals(sName,fdntCsarHelper_Data.get("FDNT").get("VF Name").get(0));
+ LinkedHashMap<String, Capability> lCapabilitys = serviceVfList.get(0).getCapabilities();
+ List<String> CPkeys = new ArrayList<>(lCapabilitys.keySet());
+ List<String> CapabilitiesNames = new ArrayList<String>(CPkeys.size());
+
+ for (int i = 0; i < CPkeys.size(); i++) {
+
+ Capability cCp = lCapabilitys.get(CPkeys.get(i));
+
+ CapabilitiesNames.add(cCp.getName());
+
+ assertEquals(CPkeys.get(i).toLowerCase(), CapabilitiesNames.get(i).toLowerCase());// Compare keys to values, Should it be checked as Case sensitive????
+
+ //System.out.println(String.format("Value of key: %s , Value of capability: %s", keys.get(i).toLowerCase(), Capabilities.get(i).toLowerCase()));
+ //System.out.println(String.format("Value of key: %s , Value of capability: %s", ActualValues.get(i).toLowerCase(), Capabilities.get(i).toLowerCase()));
+ //System.out.println(String.format("*******%d*******",i));
+ }
+
+ for (int i = 0; i < CPkeys.size(); i++) {
+ assertEquals(true, CapabilitiesNames.stream().map(String::toLowerCase).collect(Collectors.toList()).contains(fdntCsarHelper_Data.get("FDNT").get("capabilities").get(i).toLowerCase())); // Compare capabilities predefined list to actual one.
+ }
+
+ assertEquals(fdntCsarHelper_Data.get("FDNT").get("capabilities").size(), CapabilitiesNames.size()); // Compare capabilities qty expected vs actual
+ }
+
+ //Added by QA - Check for Capabilities in VF level (Capabilities Types and Properties).
+ //@Test
+ public void testCapabilitiesofVFTypes_Properties() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList();
+ String sName = serviceVfList.get(0).getName();
+ assertEquals(sName,fdntCsarHelper_Data.get("FDNT").get("VF Name").get(0));
+ LinkedHashMap<String, Capability> lCapabilitys = serviceVfList.get(0).getCapabilities();
+
+ List<String> CPkeys = new ArrayList<>(lCapabilitys.keySet());
+ List<String> CPPropkeys = new ArrayList<>(lCapabilitys.keySet());
+ List<String> CapabilitiesTypes = new ArrayList<String>(CPkeys.size());
+
+ //int iKeysSize = keys.size(); //for debug
+
+ for (int i = 0; i < CPkeys.size(); i++) {
+
+ Capability cCp = lCapabilitys.get(CPkeys.get(i));
+ CapabilityTypeDef CpDef = cCp.getDefinition();
+ CapabilitiesTypes.add(CpDef.getType());
+
+ //LinkedHashMap<String,Object> lProperties = cCp.getDefinition().getProperties();
+ LinkedHashMap<String, Property> lPropertiesR = cCp.getProperties();
+
+ List<String> CP_Propkeys = new ArrayList<>(lPropertiesR.keySet());
+
+ for (int j = 0; j < CP_Propkeys.size(); j++) {
+
+ Property p = lPropertiesR.get(CP_Propkeys.get(j));
+
+ if(p != null){
+ String sPType = p.getType();
+ Boolean bPRequired = p.isRequired();
+
+ System.out.println(sPType + " " + bPRequired);
+
+ }
+
+ }
+
+ }
+
+ for (int i = 0; i < CPkeys.size(); i++) {
+
+ }
+
+ assertEquals(fdntCsarHelper_Data.get("FDNT").get("capabilitiesTypes").size(), CapabilitiesTypes.size()); // Compare capabilities qty expected vs actual
+ }
+
+ //@Test // - BUG 283387
+ public void testRequirmentsofVF() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = fdntCsarHelper.getServiceVfList();
+ String sName = serviceVfList.get(0).getName();
+ assertEquals(sName,"FDNT 1");
+
+ List<String> ActualReqsValues = new ArrayList<>(Arrays.asList( ));
+
+ ArrayList<Object> lRequirements = serviceVfList.get(0).getRequirements();
+
+ assertEquals(fdntCsarHelper_Data.get("FDNT").get("requirements").size(),lRequirements.size()); //
+
+ // Continue from here after bug is fixed ! ! ! ! - Test the Requirements values
+ }
+
+}
diff --git a/src/test/resources/config/configuration.yaml b/src/test/resources/config/configuration.yaml
new file mode 100644
index 0000000..379e962
--- /dev/null
+++ b/src/test/resources/config/configuration.yaml
@@ -0,0 +1,3 @@
+conformanceLevel:
+ minVersion: '3.0'
+ maxVersion: '3.0' \ No newline at end of file
diff --git a/src/test/resources/config/error-configuration.yaml b/src/test/resources/config/error-configuration.yaml
new file mode 100644
index 0000000..3febd33
--- /dev/null
+++ b/src/test/resources/config/error-configuration.yaml
@@ -0,0 +1,18 @@
+# Errors
+errors:
+ FILE_NOT_FOUND: {
+ code: TP0001,
+ message: "Error: CSAR file not found."
+ }
+ BAD_FORMAT: {
+ code: TP0002,
+ message: "Error: CSAR file bad format. Check the log for details."
+ }
+ CONFORMANCE_LEVEL_ERROR: {
+ code: TP0003,
+ message: "Error: CSAR version is unsupported. Parser supports versions %s to %s."
+ }
+ GENERAL_ERROR: {
+ code: TP0004,
+ message: "Error: an unexpected internal error occured."
+ } \ No newline at end of file
diff --git a/src/test/resources/csars/1service-ServiceWithPorts.csar b/src/test/resources/csars/1service-ServiceWithPorts.csar
new file mode 100644
index 0000000..fa6577b
--- /dev/null
+++ b/src/test/resources/csars/1service-ServiceWithPorts.csar
Binary files differ
diff --git a/src/test/resources/csars/csar-invalid-zip.zip b/src/test/resources/csars/csar-invalid-zip.zip
new file mode 100644
index 0000000..04de055
--- /dev/null
+++ b/src/test/resources/csars/csar-invalid-zip.zip
@@ -0,0 +1,2 @@
+SDC-TOSCA-Meta-File-Version: 1.0
+SDC-TOSCA-Definitions-Version: 2.0
diff --git a/src/test/resources/csars/service-Renanatst2-csar.csar b/src/test/resources/csars/service-Renanatst2-csar.csar
new file mode 100644
index 0000000..37baffb
--- /dev/null
+++ b/src/test/resources/csars/service-Renanatst2-csar.csar
Binary files differ
diff --git a/src/test/resources/csars/service-ServiceFdnt-csar-0904-2.csar b/src/test/resources/csars/service-ServiceFdnt-csar-0904-2.csar
new file mode 100644
index 0000000..4f57b71
--- /dev/null
+++ b/src/test/resources/csars/service-ServiceFdnt-csar-0904-2.csar
Binary files differ
diff --git a/src/test/resources/csars/service-ServiceFdnt-csar-no-vf.csar b/src/test/resources/csars/service-ServiceFdnt-csar-no-vf.csar
new file mode 100644
index 0000000..c35baf5
--- /dev/null
+++ b/src/test/resources/csars/service-ServiceFdnt-csar-no-vf.csar
Binary files differ
diff --git a/src/test/resources/csars/service-ServiceFdnt-csar-rainy.csar b/src/test/resources/csars/service-ServiceFdnt-csar-rainy.csar
new file mode 100644
index 0000000..f3b3a46
--- /dev/null
+++ b/src/test/resources/csars/service-ServiceFdnt-csar-rainy.csar
Binary files differ
diff --git a/src/test/resources/csars/service-ServiceFdnt-csar.csar b/src/test/resources/csars/service-ServiceFdnt-csar.csar
new file mode 100644
index 0000000..983dc9b
--- /dev/null
+++ b/src/test/resources/csars/service-ServiceFdnt-csar.csar
Binary files differ
diff --git a/src/test/resources/csars/service-ServiceFdnt-test-csar.csar b/src/test/resources/csars/service-ServiceFdnt-test-csar.csar
new file mode 100644
index 0000000..5a364cd
--- /dev/null
+++ b/src/test/resources/csars/service-ServiceFdnt-test-csar.csar
Binary files differ
diff --git a/src/test/resources/csars/service-ServiceFdnt-with-allotted.csar b/src/test/resources/csars/service-ServiceFdnt-with-allotted.csar
new file mode 100644
index 0000000..ef6d03e
--- /dev/null
+++ b/src/test/resources/csars/service-ServiceFdnt-with-allotted.csar
Binary files differ
diff --git a/src/test/resources/csars/service-ServiceFdnt-with-get-input.csar b/src/test/resources/csars/service-ServiceFdnt-with-get-input.csar
new file mode 100644
index 0000000..53aea49
--- /dev/null
+++ b/src/test/resources/csars/service-ServiceFdnt-with-get-input.csar
Binary files differ
diff --git a/src/test/resources/csars/service-entry-definition-not-defined.csar b/src/test/resources/csars/service-entry-definition-not-defined.csar
new file mode 100644
index 0000000..47e65b6
--- /dev/null
+++ b/src/test/resources/csars/service-entry-definition-not-defined.csar
Binary files differ
diff --git a/src/test/resources/csars/service-invalid-conformence-level.csar b/src/test/resources/csars/service-invalid-conformence-level.csar
new file mode 100644
index 0000000..12621f0
--- /dev/null
+++ b/src/test/resources/csars/service-invalid-conformence-level.csar
Binary files differ
diff --git a/src/test/resources/csars/service-invalid-input-args.csar b/src/test/resources/csars/service-invalid-input-args.csar
new file mode 100644
index 0000000..22f9970
--- /dev/null
+++ b/src/test/resources/csars/service-invalid-input-args.csar
Binary files differ
diff --git a/src/test/resources/csars/service-invalid-yaml-content-meta.csar b/src/test/resources/csars/service-invalid-yaml-content-meta.csar
new file mode 100644
index 0000000..f77af6f
--- /dev/null
+++ b/src/test/resources/csars/service-invalid-yaml-content-meta.csar
Binary files differ
diff --git a/src/test/resources/csars/service-missing-entry-definition.csar b/src/test/resources/csars/service-missing-entry-definition.csar
new file mode 100644
index 0000000..8fd1962
--- /dev/null
+++ b/src/test/resources/csars/service-missing-entry-definition.csar
Binary files differ
diff --git a/src/test/resources/csars/service-missing-meta-file.csar b/src/test/resources/csars/service-missing-meta-file.csar
new file mode 100644
index 0000000..79348db
--- /dev/null
+++ b/src/test/resources/csars/service-missing-meta-file.csar
Binary files differ
diff --git a/version.properties b/version.properties
new file mode 100644
index 0000000..0424f62
--- /dev/null
+++ b/version.properties
@@ -0,0 +1,13 @@
+###########################################################
+# Versioning variables
+# Note that these variables cannot be structured (e.g. : version.release or version.snapshot etc... )
+# because they are used in Jenkins, whose plug-in doesn't support
+
+major=1
+minor=1
+patch=0
+
+base_version=${major}.${minor}.${patch}
+
+release_version=${base_version}
+snapshot_version=${base_version}-SNAPSHOT