aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jython-tosca-parser/pom.xml2
-rw-r--r--jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java17
-rw-r--r--jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java6
-rw-r--r--jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java81
-rw-r--r--jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java2
-rw-r--r--jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyNodeTemplate.java3
-rw-r--r--jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyTopologyTemplate.java2
-rw-r--r--jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyToscaTemplate.java1
-rw-r--r--jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/parameters/JyInput.java1
-rw-r--r--jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/nodetemplate.py13
-rw-r--r--jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/parameters.py5
-rw-r--r--jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/prereq/csar.py7
-rw-r--r--jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/topology_template.py12
-rw-r--r--jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/tosca_template.py5
-rw-r--r--pom.xml6
-rw-r--r--sdc-distribution-ci/src/main/java/org/openecomp/test/ClientTest.java29
-rw-r--r--sdc-tosca-parser/pom.xml2
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java7
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java5
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java92
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java69
-rw-r--r--sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserStubsTest.java96
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-allotted-resources-4.csarbin0 -> 39949 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-groups-status-supported-case-3.csarbin0 -> 39943 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-props-1.csarbin0 -> 39948 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-tt-metadata-2.csarbin0 -> 39938 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar.csarbin0 -> 39979 bytes
-rw-r--r--sdc-tosca-parser/src/test/resources/csars/service-vmme-csar.csarbin0 -> 74074 bytes
28 files changed, 358 insertions, 105 deletions
diff --git a/jython-tosca-parser/pom.xml b/jython-tosca-parser/pom.xml
index 2b8f024..7e29249 100644
--- a/jython-tosca-parser/pom.xml
+++ b/jython-tosca-parser/pom.xml
@@ -9,7 +9,7 @@
</parent>
<artifactId>jython-tosca-parser</artifactId>
- <version>0.3.1-SNAPSHOT</version>
+ <version>0.4.1-SNAPSHOT</version>
<dependencies>
<dependency>
diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java
index 047a421..d8cac9e 100644
--- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java
+++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java
@@ -1,10 +1,27 @@
package org.openecomp.sdc.toscaparser.api;
+import java.util.Map;
+
import org.openecomp.sdc.toscaparser.jython.JyNodeTemplate;
+import com.google.common.base.MoreObjects.ToStringHelper;
+
public class NodeTemplate extends EntityTemplate {
+ private final JyNodeTemplate jyNodeTemplate;
+
public NodeTemplate(JyNodeTemplate jyNodeTemplate) {
super(jyNodeTemplate);
+ this.jyNodeTemplate = jyNodeTemplate;
+ }
+
+ public Map<String, String> getMetadata() {
+ return jyNodeTemplate.getJyMetadata();
}
+
+ @Override
+ protected ToStringHelper toStringHelper() {
+ return super.toStringHelper()
+ .add("metadata", getMetadata());
+ }
}
diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java
index 1769455..5c9db48 100644
--- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java
+++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java
@@ -3,6 +3,7 @@ package org.openecomp.sdc.toscaparser.api;
import static com.google.common.collect.ImmutableList.toImmutableList;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import org.openecomp.sdc.toscaparser.api.parameters.Input;
@@ -48,6 +49,10 @@ public class TopologyTemplate {
JySubstitutionMappings jySubstitutionMappings = jyTopologyTemplate.getJySubstitutionMappings();
return jySubstitutionMappings != null ? new SubstitutionMappings(jySubstitutionMappings) : null;
}
+
+ public Map<String, String> getMetadata() {
+ return jyTopologyTemplate.getJyMetadata();
+ }
@Override
public String toString() {
@@ -57,6 +62,7 @@ public class TopologyTemplate {
.add("nodeTemplates", getNodeTemplates())
.add("groups", getGroups())
.add("substitutionMappings", getSubstitutionMappings())
+ .add("metadata", getMetadata())
.toString();
}
}
diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
index 97563fb..abf1b53 100644
--- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
+++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
@@ -1,5 +1,7 @@
package org.openecomp.sdc.toscaparser.api;
+import static com.google.common.collect.ImmutableList.toImmutableList;
+
import java.util.List;
import java.util.Objects;
@@ -10,40 +12,47 @@ import com.google.common.base.MoreObjects;
public class ToscaTemplate {
- private final JyToscaTemplate jyToscaTemplate;
- private final TopologyTemplate topologyTemplate;
-
- public ToscaTemplate(JyToscaTemplate jyToscaTemplate, TopologyTemplate topologyTemplate) {
- this.jyToscaTemplate = Objects.requireNonNull(jyToscaTemplate);
- this.topologyTemplate = Objects.requireNonNull(topologyTemplate);
- }
-
- public String getVersion() {
- return jyToscaTemplate.getJyVersion();
- }
-
- public String getDescription() {
- return jyToscaTemplate.getJyDescription();
- }
-
- public TopologyTemplate getTopologyTemplate() {
- return topologyTemplate;
- }
-
- public List<NodeTemplate> getNodeTemplates() {
- return topologyTemplate.getNodeTemplates();
- }
-
- public List<Input> getInputs() {
- return topologyTemplate.getInputs();
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("version", getVersion())
- .add("description", getDescription())
- .add("topologyTemplate", topologyTemplate)
- .toString();
- }
+ private final JyToscaTemplate jyToscaTemplate;
+ private final TopologyTemplate topologyTemplate;
+
+ public ToscaTemplate(JyToscaTemplate jyToscaTemplate, TopologyTemplate topologyTemplate) {
+ this.jyToscaTemplate = Objects.requireNonNull(jyToscaTemplate);
+ this.topologyTemplate = Objects.requireNonNull(topologyTemplate);
+ }
+
+ public String getVersion() {
+ return jyToscaTemplate.getJyVersion();
+ }
+
+ public String getDescription() {
+ return jyToscaTemplate.getJyDescription();
+ }
+
+ public TopologyTemplate getTopologyTemplate() {
+ return topologyTemplate;
+ }
+
+ public List<NodeTemplate> getNodeTemplates() {
+ return topologyTemplate.getNodeTemplates();
+ }
+
+ public List<TopologyTemplate> getNestedTopologyTemplates() {
+ return jyToscaTemplate.getNestedTopologyTemplates()
+ .stream()
+ .map(TopologyTemplate::new)
+ .collect(toImmutableList());
+ }
+
+ public List<Input> getInputs() {
+ return topologyTemplate.getInputs();
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("version", getVersion())
+ .add("description", getDescription())
+ .add("topologyTemplate", topologyTemplate)
+ .toString();
+ }
} \ No newline at end of file
diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java
index b700c47..0b9ad7d 100644
--- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java
+++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java
@@ -22,6 +22,8 @@ public class Input {
return jyInput.getJyType();
}
+
+
public boolean isRequired() {
return jyInput.isJyRequired();
}
diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyNodeTemplate.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyNodeTemplate.java
index b04a337..a837137 100644
--- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyNodeTemplate.java
+++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyNodeTemplate.java
@@ -1,5 +1,8 @@
package org.openecomp.sdc.toscaparser.jython;
+import java.util.Map;
+
public interface JyNodeTemplate extends JyEntityTemplate {
+ Map<String, String> getJyMetadata();
}
diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyTopologyTemplate.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyTopologyTemplate.java
index c6fe053..9cdc38b 100644
--- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyTopologyTemplate.java
+++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyTopologyTemplate.java
@@ -1,6 +1,7 @@
package org.openecomp.sdc.toscaparser.jython;
import java.util.List;
+import java.util.Map;
import org.openecomp.sdc.toscaparser.jython.parameters.JyInput;
@@ -11,4 +12,5 @@ public interface JyTopologyTemplate {
List<JyInput> getJyInputs();
List<JyGroup> getJyGroups();
JySubstitutionMappings getJySubstitutionMappings();
+ Map<String, String> getJyMetadata();
}
diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyToscaTemplate.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyToscaTemplate.java
index c58a042..7cba568 100644
--- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyToscaTemplate.java
+++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyToscaTemplate.java
@@ -7,5 +7,6 @@ public interface JyToscaTemplate {
String getJyVersion();
String getJyDescription();
List<JyNodeTemplate> getJyNodeTemplates();
+ List<JyTopologyTemplate> getNestedTopologyTemplates();
JyTopologyTemplate getJyTopologyTemplate();
}
diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/parameters/JyInput.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/parameters/JyInput.java
index 320e91b..253805b 100644
--- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/parameters/JyInput.java
+++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/parameters/JyInput.java
@@ -4,6 +4,7 @@ public interface JyInput {
String getJyName();
String getJyType();
+ String getJyDefault();
boolean isJyRequired();
String getJyDescription();
}
diff --git a/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/nodetemplate.py b/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/nodetemplate.py
index 6f37dfb..ee7622c 100644
--- a/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/nodetemplate.py
+++ b/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/nodetemplate.py
@@ -30,6 +30,7 @@ from toscaparser.elements.relationshiptype import RelationshipType
from toscaparser.entity_template import EntityTemplate
from toscaparser.relationship_template import RelationshipTemplate
from toscaparser.utils.gettextutils import _
+from toscaparser.utils import validateutils
from org.openecomp.sdc.toscaparser.jython import JyNodeTemplate
log = logging.getLogger('tosca')
@@ -39,11 +40,12 @@ class NodeTemplate(EntityTemplate, JyNodeTemplate):
'''Node template from a Tosca profile.'''
def __init__(self, name, node_templates, custom_def=None,
available_rel_tpls=None, available_rel_types=None):
- super(NodeTemplate, self).__init__(name, node_templates[name],
+ nodeTemplate = node_templates[name]
+ super(NodeTemplate, self).__init__(name, nodeTemplate,
'node_type',
custom_def)
self.templates = node_templates
- self._validate_fields(node_templates[name])
+ self._validate_fields(nodeTemplate)
self.custom_def = custom_def
self.related = {}
self.relationship_tpl = []
@@ -51,6 +53,13 @@ class NodeTemplate(EntityTemplate, JyNodeTemplate):
self.available_rel_types = available_rel_types
self._relationships = {}
self.sub_mapping_tosca_template = None
+ self.meta_data = None
+ if self.METADATA in nodeTemplate:
+ self.meta_data = nodeTemplate.get(self.METADATA)
+ validateutils.validate_map(self.meta_data)
+
+ def getJyMetadata(self):
+ return self.meta_data
@property
def relationships(self):
diff --git a/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/parameters.py b/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/parameters.py
index 7a4acd9..1bb58be 100644
--- a/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/parameters.py
+++ b/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/parameters.py
@@ -50,7 +50,10 @@ class Input(JyInput):
return self.required
def getJyDescription(self):
- return self.description
+ return self.description
+
+ def getJyDefault(self):
+ return self.default
@property
def type(self):
diff --git a/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/prereq/csar.py b/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/prereq/csar.py
index 36f39cc..de98328 100644
--- a/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/prereq/csar.py
+++ b/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/prereq/csar.py
@@ -251,7 +251,12 @@ class CSAR(object):
operation['implementation'])
finally:
if self.temp_dir:
- shutil.rmtree(self.temp_dir)
+ shutil.rmtree(self.temp_dir, False, self._printPath)
+
+
+ def _printPath(self, func, path, exc_info):
+ print('Could not delete: ' + path)
+
def _validate_external_reference(self, tpl_file, resource_file,
raise_exc=True):
diff --git a/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/topology_template.py b/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/topology_template.py
index 23f544a..c56e7b9 100644
--- a/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/topology_template.py
+++ b/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/topology_template.py
@@ -25,16 +25,17 @@ from toscaparser.relationship_template import RelationshipTemplate
from toscaparser.substitution_mappings import SubstitutionMappings
from toscaparser.tpl_relationship_graph import ToscaGraph
from toscaparser.utils.gettextutils import _
+from toscaparser.utils import validateutils
from org.openecomp.sdc.toscaparser.jython import JyTopologyTemplate
# Topology template key names
SECTIONS = (DESCRIPTION, INPUTS, NODE_TEMPLATES,
RELATIONSHIP_TEMPLATES, OUTPUTS, GROUPS,
- SUBSTITUION_MAPPINGS, POLICIES) = \
+ SUBSTITUION_MAPPINGS, POLICIES, METADATA) = \
('description', 'inputs', 'node_templates',
'relationship_templates', 'outputs', 'groups',
- 'substitution_mappings', 'policies')
+ 'substitution_mappings', 'policies', 'metadata')
log = logging.getLogger("tosca.model")
@@ -48,6 +49,10 @@ class TopologyTemplate(JyTopologyTemplate):
self.tpl = template
self.sub_mapped_node_template = sub_mapped_node_template
if self.tpl:
+ self.meta_data = None
+ if METADATA in self.tpl:
+ self.meta_data = self.tpl.get(METADATA)
+ validateutils.validate_map(self.meta_data)
self.custom_defs = custom_defs
self.rel_types = rel_types
self.parsed_params = parsed_params
@@ -78,6 +83,9 @@ class TopologyTemplate(JyTopologyTemplate):
def getJySubstitutionMappings(self):
return self.substitution_mappings
+
+ def getJyMetadata(self):
+ return self.meta_data
def _inputs(self):
inputs = []
diff --git a/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/tosca_template.py b/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/tosca_template.py
index 55485f0..6b3ea87 100644
--- a/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/tosca_template.py
+++ b/jython-tosca-parser/src/main/resources/Lib/site-packages/tosca_parser-0.7.0-py2.7.egg/toscaparser/tosca_template.py
@@ -119,8 +119,11 @@ class ToscaTemplate(JyToscaTemplate):
return self.description
def getJyTopologyTemplate(self):
- return self.topology_template
+ return self.topology_template
+ def getJyNestedTopologyTemplates(self):
+ return self.nested_tosca_templates_with_topology
+
def _topology_template(self):
return TopologyTemplate(self._tpl_topology_template(),
self._get_all_custom_defs(),
diff --git a/pom.xml b/pom.xml
index fe0f9e8..7c348e9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -45,6 +45,8 @@
<sonar.projectBaseDir>${project.basedir}</sonar.projectBaseDir>
<sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
<nexus.proxy>https://nexus.openecomp.org</nexus.proxy>
+ <snapshots.path>snapshots</snapshots.path>
+ <releases.path>releases</releases.path>
<staging.profile.id>176c31dfe190a</staging.profile.id>
</properties>
@@ -188,12 +190,12 @@
<repository>
<id>ecomp-releases</id>
<name>Release Repository</name>
- <url>${nexus.proxy}/content/repositories/releases/</url>
+ <url>${nexus.proxy}/content/repositories/${releases.path}/</url>
</repository>
<snapshotRepository>
<id>ecomp-snapshots</id>
<name>Snapshot Repository</name>
- <url>${nexus.proxy}/content/repositories/snapshots/</url>
+ <url>${nexus.proxy}/content/repositories/${snapshots.path}/</url>
</snapshotRepository>
</distributionManagement>
diff --git a/sdc-distribution-ci/src/main/java/org/openecomp/test/ClientTest.java b/sdc-distribution-ci/src/main/java/org/openecomp/test/ClientTest.java
index 519684b..d944bf0 100644
--- a/sdc-distribution-ci/src/main/java/org/openecomp/test/ClientTest.java
+++ b/sdc-distribution-ci/src/main/java/org/openecomp/test/ClientTest.java
@@ -20,16 +20,12 @@
package org.openecomp.test;
-import java.io.IOException;
-
import org.openecomp.sdc.api.IDistributionClient;
import org.openecomp.sdc.api.consumer.INotificationCallback;
import org.openecomp.sdc.api.results.IDistributionClientResult;
import org.openecomp.sdc.impl.DistributionClientFactory;
-import org.openecomp.sdc.tosca.parser.impl.SdcCsarHelperImpl;
-import org.openecomp.sdc.toscaparser.ToscaParser;
-import org.openecomp.sdc.toscaparser.ToscaParserFactory;
-import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
+import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Level;
@@ -37,24 +33,15 @@ import ch.qos.logback.classic.LoggerContext;
public class ClientTest {
public static void main(String[] args) throws Exception {
- /* ToscaParserFactory toscaParserFactory = null;
- try {
- toscaParserFactory = new ToscaParserFactory();
- ToscaParser parser = toscaParserFactory.create();
- ToscaTemplate toscaTemplate = parser.parse("test.csar");
- SdcCsarHelperImpl csarHelper = new SdcCsarHelperImpl(toscaTemplate);
+ try (SdcToscaParserFactory toscaParserFactory = SdcToscaParserFactory.getInstance()){
+ //ISdcCsarHelper csarHelper = toscaParserFactory.getSdcCsarHelper("C:\\Users\\pa0916\\Desktop\\Work\\ASDC\\CSARs\\service-ServiceFdnt-csar-nt-metadata.csar");
+ ISdcCsarHelper csarHelper = toscaParserFactory.getSdcCsarHelper("C:\\Users\\pa0916\\Desktop\\Work\\ASDC\\CSARs\\service-ServiceFdnt-csar-nt-props.csar");
+ //ISdcCsarHelper csarHelper = toscaParserFactory.getSdcCsarHelper("C:\\Users\\pa0916\\Desktop\\Work\\ASDC\\CSARs\\service-ServiceFdnt-csar.csar");
String serviceSubstitutionMappingsTypeName = csarHelper.getServiceSubstitutionMappingsTypeName();
System.out.println("serviceSubstitutionMappingsTypeName is "+serviceSubstitutionMappingsTypeName);
+ String nodeTemplatePropertyLeafValue = csarHelper.getNodeTemplatePropertyLeafValue(csarHelper.getServiceVfList().get(0), "nf_role#nf_naming#ecomp_generated_naming");
+ System.out.println("property is "+nodeTemplatePropertyLeafValue);
}
- catch (Exception e){
- System.out.println(e);
- }
- finally{
- if (toscaParserFactory != null){
- toscaParserFactory.close();
- }
- }*/
-
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
lc.getLogger("org.apache.http").setLevel(Level.INFO);
diff --git a/sdc-tosca-parser/pom.xml b/sdc-tosca-parser/pom.xml
index 2c8eff0..cd6e49e 100644
--- a/sdc-tosca-parser/pom.xml
+++ b/sdc-tosca-parser/pom.xml
@@ -71,7 +71,7 @@
<dependency>
<groupId>org.openecomp.sdc.sdc-distribution-client</groupId>
<artifactId>jython-tosca-parser</artifactId>
- <version>0.3.1-SNAPSHOT</version>
+ <version>0.4.1-SNAPSHOT</version>
</dependency>
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
index 916953c..26995c4 100644
--- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/api/ISdcCsarHelper.java
@@ -20,6 +20,7 @@ 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;
@@ -119,9 +120,9 @@ public interface ISdcCsarHelper {
* @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>
@@ -150,7 +151,7 @@ public interface ISdcCsarHelper {
* Get the CSAR service metadata
* @return - the service metadata object.
*/
- //public Metadata getServiceMetadata();
+ public Map<String, String> getServiceMetadata();
/**
* Get all VFC node templates from a specified VF.
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java
index 5d57fc9..f41141f 100644
--- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/exceptions/SdcToscaParserException.java
@@ -5,5 +5,8 @@ public class SdcToscaParserException extends Exception{
*
*/
private static final long serialVersionUID = 626014844866501196L;
-
+
+ public SdcToscaParserException(String string) {
+ super(string);
+ }
}
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
index 0d59a4d..d5caa5d 100644
--- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java
@@ -22,27 +22,48 @@ package org.openecomp.sdc.tosca.parser.impl;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collector;
+import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.Pair;
import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
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.TopologyTemplate;
import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
-import org.openecomp.sdc.tosca.parser.impl.Types;
+import org.yaml.snakeyaml.Yaml;
public class SdcCsarHelperImpl implements ISdcCsarHelper {
private ToscaTemplate toscaTemplate;
-
+ private static Yaml defaultYaml = new Yaml();
+
+
public SdcCsarHelperImpl(ToscaTemplate toscaTemplate) {
this.toscaTemplate = toscaTemplate;
}
@Override
+ //Sunny flow - covered with UT, flat and nested
public String getNodeTemplatePropertyLeafValue(NodeTemplate nodeTemplate, String leafValuePath) {
- //TODO
- return null;/*getLeafPropertyValue(nodeTemplate, leafValuePath);*/
+ String[] split = leafValuePath.split("#");
+ List<Property> properties = nodeTemplate.getProperties();
+ Optional<Property> findFirst = properties.stream().filter(x -> x.getName().equals(split[0])).findFirst();
+ if (findFirst.isPresent()){
+ Property property = findFirst.get();
+ Object current = property.getValue();
+ if (split.length > 1){
+ current = defaultYaml.load((String)current);
+ for (int i = 1; i < split.length; i++) {
+ current = ((Map<String, Object>)current).get(split[i]);
+ }
+ }
+ return String.valueOf(current);
+ }
+ return null;
}
@Override
@@ -52,16 +73,18 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
}
@Override
+ //Sunny flow - covered with UT
public List<NodeTemplate> getServiceVfList() {
return getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VF);
}
-
+
@Override
+ //Sunny flow - covered with UT
public List<NodeTemplate> getServiceNodeTemplatesByType(String nodeType) {
List<NodeTemplate> res = new ArrayList<>();
List<NodeTemplate> nodeTemplates = toscaTemplate.getNodeTemplates();
for (NodeTemplate nodeTemplate : nodeTemplates){
- if (nodeTemplate.getTypeDefinition().getType().equals(nodeType)){
+ if (nodeType.equals(nodeTemplate.getTypeDefinition().getType())){
res.add(nodeTemplate);
}
}
@@ -77,12 +100,11 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
//Assumed to be unique property for the list
private NodeTemplate getNodeTemplateByCustomizationUuid(List<NodeTemplate> nodeTemplates, String customizationId){
- //TODO Metadata is missing
- /*for (NodeTemplate nodeTemplate : nodeTemplates){
- if (nodeTemplate.getMetadata().getMetadataPropertyValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).equals(customizationId)){
+ for (NodeTemplate nodeTemplate : nodeTemplates){
+ if (customizationId.equals(nodeTemplate.getMetadata().get(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))){
return nodeTemplate;
}
- }*/
+ }
return null;
}
@@ -102,15 +124,9 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
return res;
}
- //Metadata question
- /*@Override
- public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName) {
- return metadata.getMetadataPropertyValue(metadataPropertyName);
- }*/
-
@Override
public String getServiceInputLeafValue(String inputLeafValuePath) {
- toscaTemplate.getTopologyTemplate().getNodeTemplates().get(0).getTypeDefinition().getType();
+ //toscaTemplate.getTopologyTemplate().getNodeTemplates().get(0).getProperties().get(0).
return null;//getLeafPropertyValue(toscaTemplate, inputLeafValuePath);
}
@@ -119,21 +135,22 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
return toscaTemplate.getTopologyTemplate().getSubstitutionMappings().getNodeDefinition().getType();
}
- //Metadata question
- /*@Override
- public Metadata getServiceMetadata() {
- return toscaTemplate.getMetadata();
- }*/
+ @Override
+ public Map<String, String> getServiceMetadata() {
+ TopologyTemplate topologyTemplate = toscaTemplate.getTopologyTemplate();
+ System.out.println(topologyTemplate.toString());
+ return topologyTemplate.getMetadata();
+ }
//Get property from group
@Override
public String getGroupPropertyLeafValue(Group group, String propertyName) {
return null;//getLeafPropertyValue(group, propertyName);
}
-
+
private List<NodeTemplate> getNodeTemplateBySdcType(NodeTemplate nodeTemplate, String sdcType){
//Need metadata to fetch by type
-
+
/*List<NodeTemplate> nodeTemplates = nodeTemplate.getNestedNodeTemplates();
List<NodeTemplate> res = new ArrayList<>();
for (NodeTemplate nodeTemplateEntry : nodeTemplates){
@@ -143,18 +160,20 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
}*/
return null;
}
-
+
private List<NodeTemplate> getNodeTemplateBySdcType(TopologyTemplate topologyTemplate, String sdcType){
//Need metadata to fetch by type
-
-/* List<NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates();
+
+ List<NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates();
List<NodeTemplate> res = new ArrayList<>();
for (NodeTemplate nodeTemplateEntry : nodeTemplates){
- if (nodeTemplateEntry.getMetadata().getMetadataPropertyValue(SdcPropertyNames.PROPERTY_NAME_TYPE).equals(sdcType)){
+ //TODO switch back to type condition
+ if (nodeTemplateEntry.getTypeDefinition().getType().contains("."+sdcType.toLowerCase()+".")){
+ //if (sdcType.equals(nodeTemplateEntry.getMetadata().get(SdcPropertyNames.PROPERTY_NAME_TYPE))){
res.add(nodeTemplateEntry);
}
}
-*/ return null;
+ return res;
}
@Override
@@ -178,16 +197,23 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
}
@Override
+ //TODO constant strings
public List<NodeTemplate> getAllottedResources() {
- //TODO - Need metadata
- return new ArrayList<>();
+ List<NodeTemplate> nodeTemplates = toscaTemplate.getTopologyTemplate().getNodeTemplates();
+ return nodeTemplates.stream().filter(x -> x.getMetadata() != null && x.getMetadata().get("category").equals("allotted_resources")).collect(Collectors.toList());
}
@Override
+ //Sunny flow - covered with UT
public String getTypeOfNodeTemplate(NodeTemplate nodeTemplate) {
//Can be done
return nodeTemplate.getTypeDefinition().getType();
}
-
-
+
+ /*//Not part of API, for inner/test use
+ public NodeTemplate getNodeTemplateByName(TopologyTemplate topologyTemplate, String topologyName){
+ List<NodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates();
+ Optional<NodeTemplate> findFirst = nodeTemplates.stream().filter(x -> x.getName().equals(topologyName)).findFirst();
+ return findFirst.isPresent() ? findFirst.get() : null;
+ }*/
}
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
new file mode 100644
index 0000000..6be293e
--- /dev/null
+++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java
@@ -0,0 +1,69 @@
+package org.openecomp.sdc.tosca.parser.impl;
+
+import java.io.IOException;
+
+import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.toscaparser.ToscaParserFactory;
+
+public class SdcToscaParserFactory implements AutoCloseable{
+
+ private static SdcToscaParserFactory instance;
+ private static ToscaParserFactory toscaParserFactory;
+
+ private SdcToscaParserFactory(){}
+
+ /**
+ * Get an SdcToscaParserFactory instance.
+ * After parsing work is done, it must be closed using the close() method.
+ */
+ public static SdcToscaParserFactory getInstance() {
+ if (instance == null) {
+ synchronized (SdcToscaParserFactory.class) {
+ if (instance == null) {
+ instance = new SdcToscaParserFactory();
+ toscaParserFactory = new ToscaParserFactory();
+ }
+ }
+ }
+ return instance;
+ }
+
+ /**
+ * Get an ISdcCsarHelper object for this CSAR file.
+ * @param csarPath - the path to CSAR file.
+ * @return ISdcCsarHelper object.
+ * @throws SdcToscaParserException - in case the path or CSAR are invalid.
+ */
+ public ISdcCsarHelper getSdcCsarHelper(String csarPath) throws SdcToscaParserException{
+ //TODO add logic to check if legal file and csar
+ synchronized (SdcToscaParserFactory.class) {
+ if (toscaParserFactory == null){
+ throw new SdcToscaParserException("The factory is closed. It was probably closed too soon.");
+ }
+ try {
+ return new SdcCsarHelperImpl(toscaParserFactory.create().parse(csarPath));
+ } catch (IOException e) {
+ throw new SdcToscaParserException("Exception when creating the parser: "+e.getMessage());
+ }
+ }
+ }
+
+ /**
+ * Close the SdcToscaParserFactory.
+ */
+ public void close() {
+ if (toscaParserFactory != null){
+ synchronized (SdcToscaParserFactory.class) {
+ if (toscaParserFactory != null) {
+ try {
+ toscaParserFactory.close();
+ toscaParserFactory = null;
+ } catch (IOException e) {
+ //TODO add logging
+ }
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserStubsTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserStubsTest.java
new file mode 100644
index 0000000..aac552c
--- /dev/null
+++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserStubsTest.java
@@ -0,0 +1,96 @@
+package org.openecomp.sdc.impl;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.AfterClass;
+import static org.junit.Assert.*;
+import org.junit.BeforeClass;
+import org.junit.Test;
+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.NodeTemplate;
+
+public class ToscaParserStubsTest {
+
+ private static ISdcCsarHelper csarHelper;
+ private static SdcToscaParserFactory factory;
+
+
+ @BeforeClass
+ public static void init() throws SdcToscaParserException{
+ factory = SdcToscaParserFactory.getInstance();
+ //csarHelper = factory.getSdcCsarHelper("C:\\Users\\pa0916\\Desktop\\Work\\ASDC\\CSARs\\service-ServiceFdnt-csar-allotted-resources-4.csar");
+ String fileStr = ToscaParserStubsTest.class.getClassLoader().getResource("csars/service-ServiceFdnt-csar-allotted-resources-4.csar").getFile();
+ File file = new File(fileStr);
+ csarHelper = factory.getSdcCsarHelper(file.getAbsolutePath());
+ }
+
+
+ @Test
+ //TODO add rainy flows
+ public void testNumberOfVfSunnyFlow() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList();
+ assertNotNull(serviceVfList);
+ assertEquals(1, serviceVfList.size());
+ }
+
+ @Test
+ //TODO add rainy flows
+ public void testNodeTemplateFlatProperty() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList();
+ String nodeTemplatePropertyLeafValue = csarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "availability_zone_max_count");
+ assertEquals("2", nodeTemplatePropertyLeafValue);
+ }
+
+ @Test
+ //TODO add rainy flows
+ public void testNodeTemplateNestedProperty() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList();
+ String nodeTemplatePropertyLeafValue = csarHelper.getNodeTemplatePropertyLeafValue(serviceVfList.get(0), "nf_role#nf_naming#instance_name");
+ assertEquals("FDNT_instance_VF", nodeTemplatePropertyLeafValue);
+ }
+
+ @Test
+ //TODO add rainy flows
+ public void testServiceNodeTemplatesByType() throws SdcToscaParserException {
+ List<NodeTemplate> serviceVfList = csarHelper.getServiceNodeTemplatesByType("org.openecomp.resource.vf.Fdnt");
+ assertNotNull(serviceVfList);
+ assertEquals(1, serviceVfList.size());
+ }
+
+ @Test
+ //TODO add rainy flows
+ public void testGetTypeOfNodeTemplate() {
+ List<NodeTemplate> serviceVfList = csarHelper.getServiceVfList();
+ String typeOfNodeTemplate = csarHelper.getTypeOfNodeTemplate(serviceVfList.get(0));
+ assertEquals("org.openecomp.resource.vf.Fdnt", typeOfNodeTemplate);
+ }
+
+
+ //@Test
+ //TODO add rainy flows
+ public void testGetServiceMetadata() {
+ //FAILS!! Metadata is null
+ Map<String, String> serviceMetadata = csarHelper.getServiceMetadata();
+ assertNotNull(serviceMetadata);
+ assertEquals("78c72999-1003-4a35-8534-bbd7d96fcae3", serviceMetadata.get("invariantUUID"));
+ assertEquals("Service FDNT", serviceMetadata.get("name"));
+ assertEquals("true", serviceMetadata.get("serviceEcompNaming"));
+ }
+
+ @Test
+ //TODO add rainy flows
+ public void testGetAllottedResources() {
+ List<NodeTemplate> allottedResources = csarHelper.getAllottedResources();
+ assertEquals(1, allottedResources.size());
+ }
+
+
+ @AfterClass
+ public static void close(){
+ factory.close();
+ }
+ }
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-allotted-resources-4.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-allotted-resources-4.csar
new file mode 100644
index 0000000..7b4cff2
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-allotted-resources-4.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-groups-status-supported-case-3.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-groups-status-supported-case-3.csar
new file mode 100644
index 0000000..7286663
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-groups-status-supported-case-3.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-props-1.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-props-1.csar
new file mode 100644
index 0000000..ceac90a
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-props-1.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-tt-metadata-2.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-tt-metadata-2.csar
new file mode 100644
index 0000000..3cda214
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar-nt-tt-metadata-2.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar.csar b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar.csar
new file mode 100644
index 0000000..6179316
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-ServiceFdnt-csar.csar
Binary files differ
diff --git a/sdc-tosca-parser/src/test/resources/csars/service-vmme-csar.csar b/sdc-tosca-parser/src/test/resources/csars/service-vmme-csar.csar
new file mode 100644
index 0000000..416707c
--- /dev/null
+++ b/sdc-tosca-parser/src/test/resources/csars/service-vmme-csar.csar
Binary files differ