aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Aharoni <pa0916@att.com>2017-08-21 21:28:48 +0300
committerPavel Aharoni <pa0916@att.com>2017-08-21 21:28:48 +0300
commit47cd117386e199c6d4b021b7fcc9e2727ef9bf05 (patch)
tree7962f2e19fa705544fc12fa15e39ac99f39dcbaf
parent4149de4df046df1f3ee334eff211a0f979cf4cc7 (diff)
[SDC-243] jtosca for port mirroring
Change-Id: I4218eb219a2c7d5061a52753f285474bdba0b6cf Signed-off-by: Pavel Aharoni <pa0916@att.com>
-rw-r--r--pom.xml421
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/CapabilityAssignment.java (renamed from src/main/java/org/openecomp/sdc/toscaparser/api/Capability.java)47
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/CapabilityAssignments.java51
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java72
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java61
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/RequirementAssignment.java85
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/RequirementAssignments.java39
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java23
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java43
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/elements/Metadata.java32
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetAttribute.java49
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java71
-rw-r--r--src/main/resources/TOSCA_definition_1_0.yaml6
-rw-r--r--src/main/resources/extensions/nfv/TOSCA_nfv_definition_1_0.yaml6
14 files changed, 587 insertions, 419 deletions
diff --git a/pom.xml b/pom.xml
index 6485d2b..31c6b64 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,212 +1,211 @@
-<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.jtosca</groupId>
- <artifactId>jtosca</artifactId>
- <version>1.1.3-SNAPSHOT</version>
-
- <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/jtosca/${project.version}</sitePath>
- <snapshots.path>snapshots</snapshots.path>
- <releases.path>releases</releases.path>
- <!--<staging.profile.id>176c31dfe190a</staging.profile.id> -->
-
- </properties>
-
- <dependencies>
- <!-- YAML parser -->
- <dependency>
- <groupId>org.yaml</groupId>
- <artifactId>snakeyaml</artifactId>
- <version>1.14</version>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.25</version>
- </dependency>
-
- <!-- <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId>
- <version>1.1.2</version> <scope>test</scope> </dependency> -->
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.12</version>
- </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>jtosca</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>
- </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 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.jtosca</groupId>
+ <artifactId>jtosca</artifactId>
+ <version>1.1.10-SNAPSHOT</version>
+ <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/jtosca/${project.version}</sitePath>
+ <snapshots.path>snapshots</snapshots.path>
+ <releases.path>releases</releases.path>
+ <!--<staging.profile.id>176c31dfe190a</staging.profile.id> -->
+
+ </properties>
+
+ <dependencies>
+ <!-- YAML parser -->
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>1.14</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.25</version>
+ </dependency>
+
+ <!-- <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId>
+ <version>1.1.2</version> <scope>test</scope> </dependency> -->
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ </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>jtosca</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>
+ </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> \ No newline at end of file
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/Capability.java b/src/main/java/org/openecomp/sdc/toscaparser/api/CapabilityAssignment.java
index 09571db..0eaa099 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/Capability.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/CapabilityAssignment.java
@@ -7,20 +7,24 @@ import java.util.Map;
import org.openecomp.sdc.toscaparser.api.elements.CapabilityTypeDef;
import org.openecomp.sdc.toscaparser.api.elements.PropertyDef;
-public class Capability {
+public class CapabilityAssignment {
private String name;
private LinkedHashMap<String,Object> _properties;
private CapabilityTypeDef _definition;
- public Capability(String cname,
- LinkedHashMap<String,Object> cproperties,
- CapabilityTypeDef cdefinition) {
+ public CapabilityAssignment(String cname,
+ LinkedHashMap<String,Object> cproperties,
+ CapabilityTypeDef cdefinition) {
name = cname;
_properties = cproperties;
_definition = cdefinition;
}
-
+
+ /**
+ * Get the properties list for capability
+ * @return list of property objects for capability
+ */
public ArrayList<Property> getPropertiesObjects() {
// Return a list of property objects
ArrayList<Property> properties = new ArrayList<Property>();
@@ -41,7 +45,11 @@ public class Capability {
}
return properties;
}
-
+
+ /**
+ * Get the map of properties
+ * @return map of all properties contains dictionary of property name and property object
+ */
public LinkedHashMap<String,Property> getProperties() {
// Return a dictionary of property name-object pairs
LinkedHashMap<String,Property> npps = new LinkedHashMap<>();
@@ -51,6 +59,11 @@ public class Capability {
return npps;
}
+ /**
+ * Get the property value by name
+ * @param pname - the property name for capability
+ * @return the property value for this name
+ */
public Object getPropertyValue(String pname) {
// Return the value of a given property name
LinkedHashMap<String,Property> props = getProperties();
@@ -60,22 +73,34 @@ public class Capability {
return null;
}
+ /**
+ * Get the name for capability
+ * @return the name for capability
+ */
public String getName() {
return name;
}
-
+
+ /**
+ * Get the definition for capability
+ * @return CapabilityTypeDef - contain definition for capability
+ */
public CapabilityTypeDef getDefinition() {
return _definition;
}
-
- // setter
+
+ /**
+ * Set the property for capability
+ * @param pname - the property name for capability to set
+ * @param pvalue - the property valiue for capability to set
+ */
public void setProperty(String pname,Object pvalue) {
_properties.put(pname,pvalue);
}
@Override
public String toString() {
- return "Capability{" +
+ return "CapabilityAssignment{" +
"name='" + name + '\'' +
", _properties=" + _properties +
", _definition=" + _definition +
@@ -88,7 +113,7 @@ public class Capability {
from toscaparser.properties import Property
-class Capability(object):
+class CapabilityAssignment(object):
'''TOSCA built-in capabilities type.'''
def __init__(self, name, properties, definition):
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/CapabilityAssignments.java b/src/main/java/org/openecomp/sdc/toscaparser/api/CapabilityAssignments.java
new file mode 100644
index 0000000..3397960
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/CapabilityAssignments.java
@@ -0,0 +1,51 @@
+package org.openecomp.sdc.toscaparser.api;
+
+import org.openecomp.sdc.toscaparser.api.CapabilityAssignment;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class CapabilityAssignments {
+
+ private Map<String,CapabilityAssignment> capabilityAssignments;
+
+ public CapabilityAssignments(Map<String,CapabilityAssignment> capabilityAssignments) {
+ this.capabilityAssignments = capabilityAssignments != null ? new HashMap<>(capabilityAssignments) : new HashMap<>();
+ }
+
+ /**
+ * Get all capability assignments for node template.<br>
+ * This object can be either the original one, holding all capability assignments for this node template,or a filtered one, holding a filtered subset.<br>
+ * @return list of capability assignments for the node template. <br>
+ * If there are no capability assignments, empty list is returned.
+ */
+ public List<CapabilityAssignment> getAll() {
+ return new ArrayList<>(capabilityAssignments.values());
+ }
+
+ /**
+ * Filter capability assignments by capability tosca type.
+ * @param type - The tosca type of capability assignments.
+ * @return CapabilityAssignments object, containing capability assignments of this type.<br>
+ * If no such found, filtering will result in an empty collection.
+ */
+ public CapabilityAssignments getCapabilitiesByType(String type) {
+ Map<String,CapabilityAssignment> capabilityAssignmentsMap = capabilityAssignments.entrySet().stream()
+ .filter(cap -> cap.getValue().getDefinition().getType().equals(type)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+
+ return new CapabilityAssignments(capabilityAssignmentsMap);
+ }
+
+ /**
+ * Get capability assignment by capability name.
+ * @param name - The name of capability assignment
+ * @return capability assignment with this name, or null if no such capability assignment was found.
+ */
+ public CapabilityAssignment getCapabilityByName(String name) {
+ return capabilityAssignments.get(name);
+ }
+
+}
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java b/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java
index e896905..9220dac 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java
@@ -2,9 +2,9 @@ package org.openecomp.sdc.toscaparser.api;
import java.util.ArrayList;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.elements.*;
import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
@@ -47,8 +47,8 @@ public abstract class EntityTemplate {
protected StatefulEntityType typeDefinition;
private ArrayList<Property> _properties;
private ArrayList<InterfacesDef> _interfaces;
- private ArrayList<Object> _requirements;
- private ArrayList<Capability> _capabilities;
+ private ArrayList<RequirementAssignment> _requirements;
+ private ArrayList<CapabilityAssignment> _capabilities;
// dummy constructor for subclasses that don't want super
public EntityTemplate() {
@@ -151,18 +151,40 @@ public abstract class EntityTemplate {
}
@SuppressWarnings("unchecked")
- public ArrayList<Object> getRequirements() {
+ public RequirementAssignments getRequirements() {
if(_requirements == null) {
- _requirements = new ArrayList<Object>();
- Object ob = ((EntityType)typeDefinition).getValue(REQUIREMENTS,entityTpl,false);
- if(ob != null) {
- _requirements.addAll((ArrayList<Object>)ob);
- }
-
+ _requirements = _createRequirements();
}
- return _requirements;
+ return new RequirementAssignments(_requirements);
}
+ private ArrayList<RequirementAssignment> _createRequirements() {
+ ArrayList<RequirementAssignment> reqs = new ArrayList<>();
+ ArrayList<Map<String, Object>> requirements = (ArrayList<Map<String, Object>>)
+ typeDefinition.getValue(REQUIREMENTS,entityTpl,false);
+ if(requirements == null) {
+ requirements = new ArrayList<>();
+ }
+ for (Map<String, Object> req: requirements) {
+ for(String reqName: req.keySet()) {
+ Object reqItem = req.get(reqName);
+ if(reqItem instanceof LinkedHashMap) {
+ Object rel = ((LinkedHashMap<String,Object>)reqItem).get("relationship");
+// LinkedHashMap relationship = rel instanceof LinkedHashMap ? (LinkedHashMap) rel : null;
+ String nodeName = ((LinkedHashMap<String,Object>)reqItem).get("node").toString();
+ Object capability = ((LinkedHashMap<String,Object>)reqItem).get("capability");
+ String capabilityString = capability != null ? capability.toString() : null;
+
+ reqs.add(new RequirementAssignment(reqName, nodeName, capabilityString, rel));
+ } else if (reqItem instanceof String) { //short notation
+ String nodeName = String.valueOf(reqItem);
+ reqs.add(new RequirementAssignment(reqName, nodeName));
+ }
+ }
+ }
+ return reqs;
+ }
+
public ArrayList<Property> getPropertiesObjects() {
// Return properties objects for this template
if(_properties ==null) {
@@ -192,7 +214,7 @@ public abstract class EntityTemplate {
return _interfaces;
}
- public ArrayList<Capability> getCapabilitiesObjects() {
+ public ArrayList<CapabilityAssignment> getCapabilitiesObjects() {
// Return capabilities objects for this template
if(_capabilities == null) {
_capabilities = _createCapabilities();
@@ -201,12 +223,12 @@ public abstract class EntityTemplate {
}
- public LinkedHashMap<String,Capability> getCapabilities() {
- LinkedHashMap<String,Capability> caps = new LinkedHashMap<String,Capability>();
- for(Capability cap: getCapabilitiesObjects()) {
+ public CapabilityAssignments getCapabilities() {
+ LinkedHashMap<String,CapabilityAssignment> caps = new LinkedHashMap<String,CapabilityAssignment>();
+ for(CapabilityAssignment cap: getCapabilitiesObjects()) {
caps.put(cap.getName(),cap);
}
- return caps;
+ return new CapabilityAssignments(caps);
}
public boolean isDerivedFrom(String typeStr) {
@@ -226,8 +248,8 @@ public abstract class EntityTemplate {
}
@SuppressWarnings("unchecked")
- private ArrayList<Capability> _createCapabilities() {
- ArrayList<Capability> capability = new ArrayList<Capability>();
+ private ArrayList<CapabilityAssignment> _createCapabilities() {
+ ArrayList<CapabilityAssignment> capability = new ArrayList<CapabilityAssignment>();
LinkedHashMap<String,Object> caps = (LinkedHashMap<String,Object>)
((EntityType)typeDefinition).getValue(CAPABILITIES,entityTpl,true);
if(caps != null) {
@@ -257,7 +279,7 @@ public abstract class EntityTemplate {
if(pp != null) {
properties.putAll(pp);
}
- Capability cap = new Capability(name, properties, c);
+ CapabilityAssignment cap = new CapabilityAssignment(name, properties, c);
capability.add(cap);
}
}
@@ -292,7 +314,7 @@ public abstract class EntityTemplate {
for(Map.Entry<String,Object> me: capabilities.entrySet()) {
String cap = me.getKey();
LinkedHashMap<String,Object> props = (LinkedHashMap<String,Object>)me.getValue();
- Capability capability = getCapability(cap);
+ CapabilityAssignment capability = getCapability(cap);
if(capability == null) {
continue;
}
@@ -485,15 +507,11 @@ public abstract class EntityTemplate {
return interfaces;
}
- public Capability getCapability(String name) {
+ public CapabilityAssignment getCapability(String name) {
// Provide named capability
// :param name: name of capability
// :return: capability object if found, None otherwise
- LinkedHashMap<String,Capability> caps = getCapabilities();
- if(caps != null) {
- return caps.get(name);
- }
- return null;
+ return getCapabilities().getCapabilityByName(name);
}
// getter
@@ -666,7 +684,7 @@ class EntityTemplate(object):
if 'properties' in props and props['properties']:
properties.update(props['properties'])
- cap = Capability(name, properties, c)
+ cap = CapabilityAssignment(name, properties, c)
capability.append(cap)
return capability
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java b/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java
index 11db32b..6606068 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java
@@ -2,6 +2,7 @@ package org.openecomp.sdc.toscaparser.api;
import java.util.ArrayList;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
import org.openecomp.sdc.toscaparser.api.elements.*;
@@ -46,17 +47,14 @@ public class NodeTemplate extends EntityTemplate {
@SuppressWarnings("unchecked")
public LinkedHashMap<RelationshipType,NodeTemplate> getRelationships() {
if(_relationships.isEmpty()) {
- ArrayList<Object> requires = getRequirements();
- if(requires != null && requires instanceof ArrayList) {
- for(Object ro: requires) {
- LinkedHashMap<String,Object> r = (LinkedHashMap<String,Object>)ro;
- for(Map.Entry<String,Object> me: r.entrySet()) {
- LinkedHashMap<RelationshipType,NodeTemplate> explicit = _getExplicitRelationship(r,me.getValue());
- if(explicit != null) {
- // _relationships.putAll(explicit)...
- for(Map.Entry<RelationshipType,NodeTemplate> ee: explicit.entrySet()) {
- _relationships.put(ee.getKey(), ee.getValue());
- }
+ List<RequirementAssignment> requires = getRequirements().getAll();
+ if(requires != null && requires instanceof List) {
+ for(RequirementAssignment r: requires) {
+ LinkedHashMap<RelationshipType,NodeTemplate> explicit = _getExplicitRelationship(r);
+ if(explicit != null) {
+ // _relationships.putAll(explicit)...
+ for(Map.Entry<RelationshipType,NodeTemplate> ee: explicit.entrySet()) {
+ _relationships.put(ee.getKey(), ee.getValue());
}
}
}
@@ -66,7 +64,7 @@ public class NodeTemplate extends EntityTemplate {
}
@SuppressWarnings("unchecked")
- private LinkedHashMap<RelationshipType,NodeTemplate> _getExplicitRelationship(LinkedHashMap<String,Object> req,Object value) {
+ private LinkedHashMap<RelationshipType,NodeTemplate> _getExplicitRelationship(RequirementAssignment req) {
// Handle explicit relationship
// For example,
@@ -75,13 +73,7 @@ public class NodeTemplate extends EntityTemplate {
// relationship: tosca.relationships.HostedOn
LinkedHashMap<RelationshipType,NodeTemplate> explicitRelation = new LinkedHashMap<RelationshipType,NodeTemplate>();
- String node;
- if(value instanceof LinkedHashMap) {
- node = (String)((LinkedHashMap<String,Object>)value).get("node");
- }
- else {
- node = (String)value;
- }
+ String node = req.getNodeTemplateName();
if(node != null && !node.isEmpty()) {
//msg = _('Lookup by TOSCA types is not supported. '
@@ -105,35 +97,33 @@ public class NodeTemplate extends EntityTemplate {
return null;
}
NodeTemplate relatedTpl = new NodeTemplate(node,templates,customDef,null,null);
- Object relationship = null;
+ Object relationship = req.getRelationship();
String relationshipString = null;
- if(value instanceof LinkedHashMap) {
- relationship = ((LinkedHashMap<String,Object>)value).get("relationship");
- // here relationship can be a string or a LHM with 'type':<relationship>
- }
- // check if its type has relationship defined
+// // here relationship can be a string or a LHM with 'type':<relationship>
+
+ // check if its type has relationship defined
if(relationship == null) {
ArrayList<Object> parentReqs = ((NodeType)typeDefinition).getAllRequirements();
if(parentReqs == null) {
ThreadLocalsHolder.getCollector().appendException("ValidationError: parent_req is null");
}
else {
- for(String key: req.keySet()) {
- boolean bFoundRel = false;
+// for(String key: req.keySet()) {
+// boolean bFoundRel = false;
for(Object rdo: parentReqs) {
LinkedHashMap<String,Object> reqDict = (LinkedHashMap<String,Object>)rdo;
- LinkedHashMap<String,Object> relDict = (LinkedHashMap<String,Object>)reqDict.get(key);
+ LinkedHashMap<String,Object> relDict = (LinkedHashMap<String,Object>)reqDict.get(req.getName());
if(relDict != null) {
relationship = relDict.get("relationship");
//BUG-python??? need to break twice?
- bFoundRel = true;
+// bFoundRel = true;
break;
}
}
- if(bFoundRel) {
- break;
- }
- }
+// if(bFoundRel) {
+// break;
+// }
+// }
}
}
@@ -208,8 +198,9 @@ public class NodeTemplate extends EntityTemplate {
}
@SuppressWarnings("unchecked")
- private void _addRelationshipTemplate(LinkedHashMap<String,Object> requirement, String rtype, NodeTemplate source) {
- LinkedHashMap<String,Object> req = (LinkedHashMap<String,Object>)CopyUtils.copyLhmOrAl(requirement);
+ private void _addRelationshipTemplate(RequirementAssignment requirement, String rtype, NodeTemplate source) {
+ LinkedHashMap<String,Object> req = new LinkedHashMap<>();
+ req.put("relationship", CopyUtils.copyLhmOrAl(requirement.getRelationship()));
req.put("type",rtype);
RelationshipTemplate tpl = new RelationshipTemplate(req, rtype, customDef, this, source);
relationshipTpl.add(tpl);
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/RequirementAssignment.java b/src/main/java/org/openecomp/sdc/toscaparser/api/RequirementAssignment.java
new file mode 100644
index 0000000..799a8ee
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/RequirementAssignment.java
@@ -0,0 +1,85 @@
+package org.openecomp.sdc.toscaparser.api;
+
+import java.util.Map;
+
+public class RequirementAssignment {
+
+ private String name;
+ private String nodeName;
+ private String capabilityName;
+ private Object relationship;
+
+ public RequirementAssignment(String reqName, String nodeName) {
+ this.name = reqName;
+ this.nodeName = nodeName;
+ }
+
+ public RequirementAssignment(String reqName, String nodeName, String capabilityName) {
+ this.name = reqName;
+ this.nodeName = nodeName;
+ this.capabilityName = capabilityName;
+ }
+
+ public RequirementAssignment(String reqName, String nodeName, String capabilityName, Object relationship) {
+ this.name = reqName;
+ this.nodeName = nodeName;
+ this.capabilityName = capabilityName;
+ this.relationship = relationship;
+ }
+
+ /**
+ * Get the name for requirement assignment.
+ * @return the name for requirement assignment.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Set the name for requirement
+ * @param name - the name for requirement to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Get the node name for requirement assignment.
+ * @return the node name for requirement
+ */
+ public String getNodeTemplateName() {
+ return nodeName;
+ }
+
+ /**
+ * Set the node name for requirement
+ * @param nodeName - the node name for requirement to set
+ */
+ public void setNodeTemplateName(String nodeName) {
+ this.nodeName = nodeName;
+ }
+
+ /**
+ * Get the capability name for requirement assignment.
+ * @return the capability name for requirement
+ */
+ public String getCapabilityName() {
+ return capabilityName;
+ }
+
+ /**
+ * Set the capability name for requirement assignment.
+ * @param capabilityName - the capability name for requirement to set
+ */
+ public void setCapabilityName(String capabilityName) {
+ this.capabilityName = capabilityName;
+ }
+
+ /**
+ * Get the relationship object for requirement
+ * @return the relationship object for requirement
+ */
+ public Object getRelationship() {
+ return relationship;
+ }
+}
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/RequirementAssignments.java b/src/main/java/org/openecomp/sdc/toscaparser/api/RequirementAssignments.java
new file mode 100644
index 0000000..7991f3c
--- /dev/null
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/RequirementAssignments.java
@@ -0,0 +1,39 @@
+package org.openecomp.sdc.toscaparser.api;
+
+import org.openecomp.sdc.toscaparser.api.RequirementAssignment;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class RequirementAssignments {
+
+ private List<RequirementAssignment> requirementAssignmentList;
+
+ public RequirementAssignments(List<RequirementAssignment> requirementAssignments) {
+ this.requirementAssignmentList = requirementAssignments != null ? new ArrayList<>(requirementAssignments) : new ArrayList<>();
+ }
+
+ /**
+ * Get all requirement assignments for Node Template.<br>
+ * This object can be either the original one, holding all requirement assignments for this node template,or a filtered one, holding a filtered subset.<br>
+ * @return list of requirement assignments for the node template. <br>
+ * If there are no requirement assignments, empty list is returned.
+ */
+ public List<RequirementAssignment> getAll() {
+ return new ArrayList<>(requirementAssignmentList);
+ }
+
+ /**
+ * Filter requirement assignments by requirement name.
+ * @param reqName - The name of requirement
+ * @return RequirementAssignments object, containing requirement assignments of this type.<br>
+ * If no such found, filtering will result in an empty collection.
+ */
+ public RequirementAssignments getRequirementsByName(String reqName) {
+ List<RequirementAssignment> requirementAssignments = requirementAssignmentList.stream()
+ .filter(req -> req.getName().equals(reqName)).collect(Collectors.toList());
+
+ return new RequirementAssignments(requirementAssignments);
+ }
+}
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java b/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java
index b9c2238..a68f9fb 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java
@@ -1,10 +1,7 @@
package org.openecomp.sdc.toscaparser.api;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
+import java.util.*;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.elements.NodeType;
import org.openecomp.sdc.toscaparser.api.elements.PropertyDef;
import org.openecomp.sdc.toscaparser.api.parameters.Input;
@@ -217,13 +214,13 @@ public class SubstitutionMappings {
// The capabilities must be in node template which be mapped.
LinkedHashMap<String,Object> tplsCapabilities =
(LinkedHashMap<String,Object>)subMappingDef.get(CAPABILITIES);
- LinkedHashMap<String,Capability> nodeCapabilities = null;
+ List<CapabilityAssignment> nodeCapabilities = null;
if(subMappedNodeTemplate != null) {
- nodeCapabilities = subMappedNodeTemplate.getCapabilities();
+ nodeCapabilities = subMappedNodeTemplate.getCapabilities().getAll();
}
if(nodeCapabilities != null) {
- for(String cap: nodeCapabilities.keySet()) {
- if(tplsCapabilities != null && tplsCapabilities.get(cap) == null) {
+ for(CapabilityAssignment cap: nodeCapabilities) {
+ if(tplsCapabilities != null && tplsCapabilities.get(cap.getName()) == null) {
; //pass
// ExceptionCollector.appendException(
// UnknownFieldError(what='SubstitutionMappings',
@@ -241,15 +238,13 @@ public class SubstitutionMappings {
// The requirements must be in node template which be mapped.
LinkedHashMap<String,Object> tplsRequirements =
(LinkedHashMap<String,Object>)subMappingDef.get(REQUIREMENTS);
- ArrayList<Object> nodeRequirements = null;
+ List<RequirementAssignment> nodeRequirements = null;
if(subMappedNodeTemplate != null) {
- nodeRequirements = subMappedNodeTemplate.getRequirements();
+ nodeRequirements = subMappedNodeTemplate.getRequirements().getAll();
}
if(nodeRequirements != null) {
- for(Object ro: nodeRequirements) {
- ArrayList<String> al = new ArrayList<String>(
- ((LinkedHashMap<String,Object>)ro).keySet());
- String cap = al.get(0);
+ for(RequirementAssignment ro: nodeRequirements) {
+ String cap = ro.getName();
if(tplsRequirements != null && tplsRequirements.get(cap) == null) {
; //pass
// ExceptionCollector.appendException(
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java b/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java
index 709dc81..afedfdb 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java
@@ -1,11 +1,7 @@
package org.openecomp.sdc.toscaparser.api;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import java.util.*;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.elements.InterfacesDef;
import org.openecomp.sdc.toscaparser.api.elements.NodeType;
import org.openecomp.sdc.toscaparser.api.elements.RelationshipType;
@@ -415,27 +411,20 @@ public class TopologyTemplate {
}
}
}
- if(nt.getRequirements() != null &&
- nt.getRequirements() instanceof ArrayList) {
- for(Object oreq: nt.getRequirements()) {
- LinkedHashMap<String,Object> req = (LinkedHashMap<String,Object>)oreq;
- LinkedHashMap<String,Object> rel = req;
- for(String reqName: req.keySet()) {
- Object reqItem = req.get(reqName);
- if(reqItem instanceof LinkedHashMap) {
- Object t = ((LinkedHashMap<String,Object>)reqItem).get("relationship");
- // it can be a string or a LHM...
- if(t instanceof LinkedHashMap) {
- rel = (LinkedHashMap<String,Object>)t;
- }
- else {
- // we set it to null to fail the next test
- // and avoid the get("proprties")
- rel = null;
- }
- break;
- }
- }
+ if(nt.getRequirements() != null) {
+ for(RequirementAssignment req: nt.getRequirements().getAll()) {
+ LinkedHashMap<String,Object> rel;
+ Object t = req.getRelationship();
+ // it can be a string or a LHM...
+ if(t instanceof LinkedHashMap) {
+ rel = (LinkedHashMap<String,Object>)t;
+ }
+ else {
+ // we set it to null to fail the next test
+ // and avoid the get("proprties")
+ rel = null;
+ }
+
if(rel != null && rel.get("properties") != null) {
LinkedHashMap<String,Object> relprops =
(LinkedHashMap<String,Object>)rel.get("properties");
@@ -448,7 +437,7 @@ public class TopologyTemplate {
}
}
if(nt.getCapabilitiesObjects() != null) {
- for(Capability cap: nt.getCapabilitiesObjects()) {
+ for(CapabilityAssignment cap: nt.getCapabilitiesObjects()) {
if(cap.getPropertiesObjects() != null) {
for(Property prop: cap.getPropertiesObjects()) {
Object propvalue = Function.getFunction(this,nt,prop.getValue(), resolveGetInput);
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/Metadata.java b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/Metadata.java
index 6cf84a5..b153876 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/elements/Metadata.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/elements/Metadata.java
@@ -1,36 +1,34 @@
package org.openecomp.sdc.toscaparser.api.elements;
+import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
+import java.util.stream.Collectors;
public class Metadata {
private final Map<String, Object> metadataMap;
public Metadata(Map<String, Object> metadataMap) {
- this.metadataMap = metadataMap;
+ this.metadataMap = metadataMap != null ? metadataMap : new HashMap<>();
}
public String getValue(String key) {
- return !isEmpty() ? String.valueOf(this.metadataMap.get(key)) : null;
- }
-
- public Map<String, Object> getPropertyMap() {
- if(metadataMap == null){
- return null;
- }
- return new HashMap<>(metadataMap);
- }
-
- public void setValue(String key, Object value) {
- if (!isEmpty()) {
- this.metadataMap.put(key, value);
+
+ Object obj = this.metadataMap.get(key);
+ if (obj != null){
+ return String.valueOf(obj);
}
+ return null;
}
-
- private boolean isEmpty() {
- return this.metadataMap == null || this.metadataMap.size() == 0;
+ /**
+ * Get all properties of a Metadata object.<br>
+ * This object represents the "metadata" section of some entity.
+ * @return all properties of this Metadata, as a key-value.
+ */
+ public Map<String, String> getAllProperties() {
+ return metadataMap.entrySet().stream().map(e-> new AbstractMap.SimpleEntry<String, String>(e.getKey(), String.valueOf(e.getValue()))).collect(Collectors.toMap(Map.Entry::getKey,Map.Entry::getValue));
}
@Override
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetAttribute.java b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetAttribute.java
index 549073b..8a3d0b6 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetAttribute.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetAttribute.java
@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import org.openecomp.sdc.toscaparser.api.*;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.elements.AttributeDef;
import org.openecomp.sdc.toscaparser.api.elements.CapabilityTypeDef;
import org.openecomp.sdc.toscaparser.api.elements.DataType;
@@ -164,22 +163,17 @@ public class GetAttribute extends Function {
if(nodeTemplate != null) {
LinkedHashMap<String,Object> hostedOnRel =
(LinkedHashMap<String,Object>)EntityType.TOSCA_DEF.get(HOSTED_ON);
- for(Object ro: nodeTemplate.getRequirements()) {
- if(ro != null && ro instanceof LinkedHashMap) {
- LinkedHashMap<String,Object> r = (LinkedHashMap<String,Object>)ro;
- for(String requirement: r.keySet()) {
- String targetName = (String)r.get(requirement);
- NodeTemplate targetNode = _findNodeTemplate(targetName);
- NodeType targetType = (NodeType)targetNode.getTypeDefinition();
- for(CapabilityTypeDef capability: targetType.getCapabilitiesObjects()) {
+ for(RequirementAssignment r: nodeTemplate.getRequirements().getAll()) {
+ String targetName = r.getNodeTemplateName();
+ NodeTemplate targetNode = _findNodeTemplate(targetName);
+ NodeType targetType = (NodeType)targetNode.getTypeDefinition();
+ for(CapabilityTypeDef capability: targetType.getCapabilitiesObjects()) {
// if(((ArrayList<String>)hostedOnRel.get("valid_target_types")).contains(capability.getType())) {
- if(capability.inheritsFrom((ArrayList<String>)hostedOnRel.get("valid_target_types"))) {
- if(_attributeExistsInType(targetType)) {
- return targetNode;
- }
- return _findHostContainingAttribute(targetName);
- }
+ if(capability.inheritsFrom((ArrayList<String>)hostedOnRel.get("valid_target_types"))) {
+ if(_attributeExistsInType(targetType)) {
+ return targetNode;
}
+ return _findHostContainingAttribute(targetName);
}
}
}
@@ -246,16 +240,11 @@ public class GetAttribute extends Function {
NodeTemplate nodeTpl = _findNodeTemplate((String)args.get(0));
// Find attribute in node template's requirements
- for(Object ro: nodeTpl.getRequirements()) {
- if(ro != null && ro instanceof LinkedHashMap) {
- LinkedHashMap<String,Object> r = (LinkedHashMap<String,Object>)ro;
- for(String req: r.keySet()) {
- String nodeName = (String)r.get(req);
- if(req.equals(reqOrCap)) {
- NodeTemplate nodeTemplate = _findNodeTemplate(nodeName);
- return _getCapabilityAttribute(nodeTemplate,req,attrName);
- }
- }
+ for(RequirementAssignment r: nodeTpl.getRequirements().getAll()) {
+ String nodeName = r.getNodeTemplateName();
+ if(r.getName().equals(reqOrCap)) {
+ NodeTemplate nodeTemplate = _findNodeTemplate(nodeName);
+ return _getCapabilityAttribute(nodeTemplate,r.getName(),attrName);
}
}
// If requirement was not found, look in node template's capabilities
@@ -266,9 +255,9 @@ public class GetAttribute extends Function {
String capabilityName,
String attrName) {
// Gets a node template capability attribute
- LinkedHashMap<String,Capability> caps = nodeTemplate.getCapabilities();
- if(caps != null && caps.keySet().contains(capabilityName)) {
- Capability cap = caps.get(capabilityName);
+ CapabilityAssignment cap = nodeTemplate.getCapabilities().getCapabilityByName(capabilityName);
+
+ if(cap != null) {
AttributeDef attribute = null;
LinkedHashMap<String,AttributeDef> attrs =
cap.getDefinition().getAttributesDef();
@@ -283,7 +272,7 @@ public class GetAttribute extends Function {
return attribute;
}
String msg = String.format(
- "Requirement/Capability \"%s\" referenced from node template \"%s\" was not found in node template \"%s\"",
+ "Requirement/CapabilityAssignment \"%s\" referenced from node template \"%s\" was not found in node template \"%s\"",
capabilityName,((NodeTemplate)context).getName(),nodeTemplate.getName());
ThreadLocalsHolder.getCollector().appendException("KeyError: " + msg);
return null;
@@ -518,7 +507,7 @@ def _get_capability_attribute(self,
'ntpl1': node_template.name,
'ntpl2': self.context.name}))
return attribute
- msg = _('Requirement/Capability "{0}" referenced from node template '
+ msg = _('Requirement/CapabilityAssignment "{0}" referenced from node template '
'"{1}" was not found in node template "{2}".').format(
capability_name,
self.context.name,
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java
index 71420e8..41495bc 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java
@@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import org.openecomp.sdc.toscaparser.api.*;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
import org.openecomp.sdc.toscaparser.api.elements.CapabilityTypeDef;
import org.openecomp.sdc.toscaparser.api.elements.EntityType;
import org.openecomp.sdc.toscaparser.api.elements.NodeType;
@@ -105,17 +104,12 @@ public class GetProperty extends Function {
return null;
}
// look for property in node template's requirements
- for(Object r: nodeTpl.getRequirements()) {
- if(r instanceof LinkedHashMap) {
- LinkedHashMap<String,Object> rlist = (LinkedHashMap<String,Object>)r;
- for(String req: rlist.keySet()) {
- String nodeName = (String)rlist.get(req);
- if(req.equals(reqOrCap)) {
- NodeTemplate nodeTemplate = _findNodeTemplate(nodeName);
- return _getCapabilityProperty(nodeTemplate,req,propertyName,true);
- }
- }
- }
+ for(RequirementAssignment req: nodeTpl.getRequirements().getAll()) {
+ String nodeName = req.getNodeTemplateName();
+ if(req.getName().equals(reqOrCap)) {
+ NodeTemplate nodeTemplate = _findNodeTemplate(nodeName);
+ return _getCapabilityProperty(nodeTemplate,req.getName(),propertyName,true);
+ }
}
// If requirement was not found, look in node template's capabilities
return _getCapabilityProperty(nodeTpl,reqOrCap,propertyName,true);
@@ -128,9 +122,8 @@ public class GetProperty extends Function {
// Gets a node template capability property
Object property = null;
- LinkedHashMap<String,Capability> caps = nodeTemplate.getCapabilities();
- if(caps != null && caps.get(capabilityName) != null) {
- Capability cap = caps.get(capabilityName);
+ CapabilityAssignment cap = nodeTemplate.getCapabilities().getCapabilityByName(capabilityName);
+ if(cap != null) {
LinkedHashMap<String,Property> props = cap.getProperties();
if(props != null && props.get(propertyName) != null) {
property = ((Property)props.get(propertyName)).getValue();
@@ -144,7 +137,7 @@ public class GetProperty extends Function {
}
if(throwErrors) {
ThreadLocalsHolder.getCollector().appendException(String.format(
- "KeyError: Requirement/Capability \"%s\" referenced from node template \"%s\" was not found in node template \"%s\"",
+ "KeyError: Requirement/CapabilityAssignment \"%s\" referenced from node template \"%s\" was not found in node template \"%s\"",
capabilityName,((NodeTemplate)context).getName(),nodeTemplate.getName()));
}
@@ -262,30 +255,26 @@ public class GetProperty extends Function {
NodeTemplate nodeTemplate = _findNodeTemplate(nodeTemplateName);
LinkedHashMap<String,Object> hostedOnRel = (LinkedHashMap<String,Object>)
EntityType.TOSCA_DEF.get(HOSTED_ON);
- for(Object r: nodeTemplate.getRequirements()) {
- if(r instanceof LinkedHashMap) {
- LinkedHashMap<String,Object> rlist = (LinkedHashMap<String,Object>)r;
- for(String requirement: rlist.keySet()) {
- String targetName = (String)rlist.get(requirement);
- NodeTemplate targetNode = _findNodeTemplate(targetName);
- NodeType targetType = (NodeType)targetNode.getTypeDefinition();
- for(CapabilityTypeDef capDef: targetType.getCapabilitiesObjects()) {
- if(capDef.inheritsFrom((ArrayList<String>)hostedOnRel.get("valid_target_types"))) {
- if(_propertyExistsInType(targetType)) {
- return targetNode;
- }
- // If requirement was not found, look in node
- // template's capabilities
- if(args.size() > 2 &&
- _getCapabilityProperty(targetNode,(String)args.get(1),(String)args.get(2),false) != null) {
- return targetNode;
- }
-
- return _findHostContainingProperty(targetName);
- }
- }
- }
- }
+ for(RequirementAssignment requirement: nodeTemplate.getRequirements().getAll()) {
+ String targetName = requirement.getNodeTemplateName();
+ NodeTemplate targetNode = _findNodeTemplate(targetName);
+ NodeType targetType = (NodeType)targetNode.getTypeDefinition();
+ for(CapabilityTypeDef capDef: targetType.getCapabilitiesObjects()) {
+ if(capDef.inheritsFrom((ArrayList<String>)hostedOnRel.get("valid_target_types"))) {
+ if(_propertyExistsInType(targetType)) {
+ return targetNode;
+ }
+ // If requirement was not found, look in node
+ // template's capabilities
+ if(args.size() > 2 &&
+ _getCapabilityProperty(targetNode,(String)args.get(1),(String)args.get(2),false) != null) {
+ return targetNode;
+ }
+
+ return _findHostContainingProperty(targetName);
+ }
+ }
+
}
return null;
}
@@ -466,7 +455,7 @@ def _get_capability_property(self,
'ntpl1': node_template.name,
'ntpl2': self.context.name}))
return property
- msg = _('Requirement/Capability "{0}" referenced from node template '
+ msg = _('Requirement/CapabilityAssignment "{0}" referenced from node template '
'"{1}" was not found in node template "{2}".').format(
capability_name,
self.context.name,
diff --git a/src/main/resources/TOSCA_definition_1_0.yaml b/src/main/resources/TOSCA_definition_1_0.yaml
index 554b7b6..c5a4d0f 100644
--- a/src/main/resources/TOSCA_definition_1_0.yaml
+++ b/src/main/resources/TOSCA_definition_1_0.yaml
@@ -13,7 +13,7 @@
##########################################################################
# The content of this file reflects TOSCA Simple Profile in YAML version
# 1.0.0. It describes the definition for TOSCA types including Node Type,
-# Relationship Type, Capability Type and Interfaces.
+# Relationship Type, CapabilityAssignment Type and Interfaces.
##########################################################################
tosca_definitions_version: tosca_simple_yaml_1_0
@@ -489,8 +489,8 @@ relationship_types:
valid_target_types: [ tosca.capabilities.network.Bindable ]
##########################################################################
-# Capability Type.
-# A Capability Type is a reusable entity that describes a kind of
+# CapabilityAssignment Type.
+# A CapabilityAssignment Type is a reusable entity that describes a kind of
# capability that a Node Type can declare to expose.
##########################################################################
capability_types:
diff --git a/src/main/resources/extensions/nfv/TOSCA_nfv_definition_1_0.yaml b/src/main/resources/extensions/nfv/TOSCA_nfv_definition_1_0.yaml
index 365d70e..8b08837 100644
--- a/src/main/resources/extensions/nfv/TOSCA_nfv_definition_1_0.yaml
+++ b/src/main/resources/extensions/nfv/TOSCA_nfv_definition_1_0.yaml
@@ -13,7 +13,7 @@
##########################################################################
# The content of this file reflects TOSCA NFV Profile in YAML version
# 1.0.0. It describes the definition for TOSCA NFV types including Node Type,
-# Relationship Type, Capability Type and Interfaces.
+# Relationship Type, CapabilityAssignment Type and Interfaces.
##########################################################################
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
@@ -139,8 +139,8 @@ relationship_types:
valid_target_types: [ tosca.capabilities.nfv.Forwarder]
##########################################################################
-# Capability Type.
-# A Capability Type is a reusable entity that describes a kind of
+# CapabilityAssignment Type.
+# A CapabilityAssignment Type is a reusable entity that describes a kind of
# capability that a Node Type can declare to expose.
##########################################################################