summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jython-tosca-parser/pom.xml2
-rw-r--r--pom.xml1
-rw-r--r--sdc-distribution-ci/src/main/java/org/openecomp/test/ClientTest.java28
-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.java49
-rw-r--r--sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcToscaParserFactory.java69
8 files changed, 116 insertions, 47 deletions
diff --git a/jython-tosca-parser/pom.xml b/jython-tosca-parser/pom.xml
index 2058d3a..29a8cd2 100644
--- a/jython-tosca-parser/pom.xml
+++ b/jython-tosca-parser/pom.xml
@@ -9,7 +9,7 @@
</parent>
<artifactId>jython-tosca-parser</artifactId>
- <version>${jython.tosca.parser.version}</version>
+ <version>0.4.0-SNAPSHOT</version>
<dependencies>
<dependency>
diff --git a/pom.xml b/pom.xml
index 27ee15c..fe0f9e8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -35,7 +35,6 @@
<logback.version>1.1.2</logback.version>
<junit.version>4.12</junit.version>
<snakeyaml.version>1.14</snakeyaml.version>
- <jython.tosca.parser.version>0.4.0-SNAPSHOT</jython.tosca.parser.version>
<!-- Repositories -->
<!-- <nexusServerName>mavencentral.it.att.com</nexusServerName> -->
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..5e8dafd 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,14 @@ 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.csar");
String serviceSubstitutionMappingsTypeName = csarHelper.getServiceSubstitutionMappingsTypeName();
System.out.println("serviceSubstitutionMappingsTypeName is "+serviceSubstitutionMappingsTypeName);
+ String nodeTemplatePropertyLeafValue = csarHelper.getNodeTemplatePropertyLeafValue(csarHelper.getServiceVfList().get(0), "nf_role");
+ 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 59ae0e4..d4ffda8 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>${jython.tosca.parser.version}</version>
+ <version>0.4.0-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..51afe7e 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,14 +22,16 @@ package org.openecomp.sdc.tosca.parser.impl;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.Optional;
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;
public class SdcCsarHelperImpl implements ISdcCsarHelper {
@@ -41,8 +43,18 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
@Override
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()){
+ Object current = findFirst.get().getValue();
+ /*for (int i = 1; i < split.length; i++) {
+ //if (i )
+ }*/
+ //TODO add nested props
+ return (String)current;
+ }
+ return null;
}
@Override
@@ -61,7 +73,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
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 +89,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 +113,14 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
return res;
}
- //Metadata question
/*@Override
public String getMetadataPropertyValue(Metadata metadata, String metadataPropertyName) {
- return metadata.getMetadataPropertyValue(metadataPropertyName);
+ return (String)metadata.get(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,11 +129,10 @@ 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() {
+ return toscaTemplate.getTopologyTemplate().getMetadata();
+ }
//Get property from group
@Override
@@ -147,14 +156,16 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
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
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