summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatalia Sheshukov <ns019t@intl.att.com>2018-02-22 16:40:51 +0200
committerNatalia Sheshukov <ns019t@intl.att.com>2018-02-22 16:40:51 +0200
commit5e7130be2350a29d8dbc65f52cdca596a188114f (patch)
tree07dd49fc51d00d6259552b7e489c061bdbfad8c3
parent224c7e15ed15cb7fd7250c8428e66b3c9b5cb0b1 (diff)
[367741] vLAN Tagging - Support Tosca Policies
Change-Id: Icb0739eaf5abd071c45b4d7c49d7b412e10c8c4d Issue-ID: SDC-1056 Signed-off-by: Natalia Sheshukov <ns019t@intl.att.com>
-rw-r--r--LICENSE.TXT6
-rw-r--r--pom.xml2
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/ImportsLoader.java73
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/Policy.java6
-rw-r--r--src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java216
-rw-r--r--src/test/java/org/openecomp/sdc/toscaparser/api/JToscaImportTest.java64
-rw-r--r--src/test/resources/csars/resource-Spgw-csar-ZTE.csarbin31639 -> 0 bytes
-rw-r--r--src/test/resources/csars/sdc-onboarding_csar.csarbin80596 -> 0 bytes
-rw-r--r--version.properties2
9 files changed, 58 insertions, 311 deletions
diff --git a/LICENSE.TXT b/LICENSE.TXT
index 2b91311..724329f 100644
--- a/LICENSE.TXT
+++ b/LICENSE.TXT
@@ -1,8 +1,8 @@
-/*
+/*
* ============LICENSE_START==========================================
* ===================================================================
-* Copyright © 2018 AT&T Intellectual Property.
-* Copyright © 2018 Amdocs
+* Copyright © 2017 AT&T Intellectual Property.
+* Copyright © 2017 Amdocs
* All rights reserved.
* ===================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/pom.xml b/pom.xml
index a6afeee..63da98a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
<groupId>org.openecomp.sdc.jtosca</groupId>
<artifactId>jtosca</artifactId>
- <version>1.2.1-SNAPSHOT</version>
+ <version>1.2.2-SNAPSHOT</version>
<name>sdc-jtosca</name>
<properties>
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/ImportsLoader.java b/src/main/java/org/openecomp/sdc/toscaparser/api/ImportsLoader.java
index b2a0da7..5e94378 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/ImportsLoader.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/ImportsLoader.java
@@ -28,7 +28,6 @@ public class ImportsLoader {
private ArrayList<String> typeDefinitionList;
private LinkedHashMap<String,Object> customDefs;
- private LinkedHashMap<String,Object> allCustomDefs;
private ArrayList<LinkedHashMap<String,Object>> nestedToscaTpls;
private LinkedHashMap<String,Object> repositories;
@@ -40,7 +39,6 @@ public class ImportsLoader {
this.importslist = _importslist;
customDefs = new LinkedHashMap<String,Object>();
- allCustomDefs = new LinkedHashMap<String,Object>();
nestedToscaTpls = new ArrayList<LinkedHashMap<String,Object>>();
if((_path == null || _path.isEmpty()) && tpl == null) {
//msg = _('Input tosca template is not provided.')
@@ -67,7 +65,7 @@ public class ImportsLoader {
}
public LinkedHashMap<String,Object> getCustomDefs() {
- return allCustomDefs;
+ return customDefs;
}
public ArrayList<LinkedHashMap<String,Object>> getNestedToscaTpls() {
@@ -133,50 +131,33 @@ public class ImportsLoader {
}
}
- /**
- * This method is used to get consolidated custom definitions by passing custom Types from
- * each import. The resultant collection is then passed back which contains all import
- * definitions
- *
- * @param customType the custom type
- * @param namespacePrefix the namespace prefix
- */
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("unchecked")
private void _updateCustomDefs(LinkedHashMap<String,Object> customType, String namespacePrefix) {
- LinkedHashMap<String,Object> outerCustomTypes;
- for(String typeDef: typeDefinitionList) {
- if(typeDef.equals("imports")) {
- customDefs.put("imports", customType.get(typeDef));
- if (allCustomDefs.isEmpty() || allCustomDefs.get("imports") == null){
- allCustomDefs.put("imports",customType.get(typeDef));
- }
- else if (customType.get(typeDef) != null){
- Set<Object> allCustomImports = new HashSet<>((ArrayList<Object>)allCustomDefs.get("imports"));
- allCustomImports.addAll((ArrayList<Object>) customType.get(typeDef));
- allCustomDefs.put("imports", new ArrayList<>(allCustomImports));
- }
- }
- else {
- outerCustomTypes = (LinkedHashMap<String,Object>)customType.get(typeDef);
- if(outerCustomTypes != null) {
- if(namespacePrefix != null && !namespacePrefix.isEmpty()) {
- LinkedHashMap<String,Object> prefixCustomTypes = new LinkedHashMap<String,Object>();
- for(Map.Entry<String,Object> me: outerCustomTypes.entrySet()) {
- String typeDefKey = me.getKey();
- String nameSpacePrefixToKey = namespacePrefix + "." + typeDefKey;
- prefixCustomTypes.put(nameSpacePrefixToKey, outerCustomTypes.get(typeDefKey));
- }
- customDefs.putAll(prefixCustomTypes);
- allCustomDefs.putAll(prefixCustomTypes);
- }
- else {
- customDefs.putAll(outerCustomTypes);
- allCustomDefs.putAll(outerCustomTypes);
- }
- }
- }
- }
- }
+ LinkedHashMap<String,Object> outerCustomTypes;// = new LinkedHashMap<String,Object>();
+ for(String typeDef: typeDefinitionList) {
+ if(typeDef.equals("imports")) {
+ // imports are ArrayList...
+ customDefs.put("imports",(ArrayList<Object>)customType.get(typeDef));
+ }
+ else {
+ outerCustomTypes = (LinkedHashMap<String,Object>)customType.get(typeDef);
+ if(outerCustomTypes != null) {
+ if(namespacePrefix != null && !namespacePrefix.isEmpty()) {
+ LinkedHashMap<String,Object> prefixCustomTypes = new LinkedHashMap<String,Object>();
+ for(Map.Entry<String,Object> me: outerCustomTypes.entrySet()) {
+ String typeDefKey = me.getKey();
+ String nameSpacePrefixToKey = namespacePrefix + "." + typeDefKey;
+ prefixCustomTypes.put(nameSpacePrefixToKey, outerCustomTypes.get(typeDefKey));
+ }
+ customDefs.putAll(prefixCustomTypes);
+ }
+ else {
+ customDefs.putAll(outerCustomTypes);
+ }
+ }
+ }
+ }
+ }
private void _updateNestedToscaTpls(String fullFileName,LinkedHashMap<String,Object> customTpl) {
if(fullFileName != null && customTpl != null) {
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/Policy.java b/src/main/java/org/openecomp/sdc/toscaparser/api/Policy.java
index 26805bd..1f536f8 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/Policy.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/Policy.java
@@ -119,6 +119,12 @@ public class Policy extends EntityTemplate {
", properties=" + properties +
'}';
}
+
+ public int compareTo(Policy other){
+ if(this.equals(other))
+ return 0;
+ return this.getName().compareTo(other.getName()) == 0 ? this.getType().compareTo(other.getType()) : this.getName().compareTo(other.getName());
+ }
}
/*python
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java b/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
index e96ca56..7553414 100644
--- a/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
+++ b/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java
@@ -9,9 +9,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
-import java.nio.file.Files;
-import java.util.function.Predicate;
-import java.nio.file.Paths;
import org.openecomp.sdc.toscaparser.api.common.ValidationIssueCollector;
import org.openecomp.sdc.toscaparser.api.common.JToscaException;
@@ -73,7 +70,6 @@ public class ToscaTemplate extends Object {
private boolean isFile;
private String path;
private String inputPath;
- private String rootPath;
private LinkedHashMap<String,Object> parsedParams;
private boolean resolveGetInput;
private LinkedHashMap<String,Object> tpl;
@@ -95,7 +91,6 @@ public class ToscaTemplate extends Object {
private String csarTempDir;
private int nestingLoopCounter;
private LinkedHashMap<String, LinkedHashMap<String, Object>> metaProperties;
- private Set<String> processedImports;
public ToscaTemplate(String _path,
LinkedHashMap<String,Object> _parsedParams,
@@ -198,9 +193,6 @@ public class ToscaTemplate extends Object {
if(tpl != null) {
parsedParams = _parsedParams;
_validateField();
- this.rootPath = path;
- this.processedImports = new HashSet<String>();
- this.imports = _tplImports();
this.version = _tplVersion();
this.metaData = _tplMetaData();
this.relationshipTypes = _tplRelationshipTypes();
@@ -313,200 +305,30 @@ public class ToscaTemplate extends Object {
private ArrayList<Policy> _policies() {
return topologyTemplate.getPolicies();
}
-
- /**
- * This method is used to get consolidated custom definitions from all imports
- * It is logically divided in two parts to handle imports; map and list formats.
- * Before processing the imports; it sorts them to make sure the current directory imports are
- * being processed first and then others. Once sorted; it processes each import one by one in
- * recursive manner.
- * To avoid cyclic dependency among imports; this method uses a set to keep track of all
- * imports which are already processed and filters the imports which occurs more than once.
- *
- * @param alImports all imports which needs to be processed
- * @return the linked hash map containing all import definitions
- */
- private LinkedHashMap<String,Object> _getAllCustomDefs(Object alImports) {
-
+
+ private LinkedHashMap<String,Object> _getAllCustomDefs(ArrayList<Object> alImports) {
+
String types[] = {
- IMPORTS, NODE_TYPES, CAPABILITY_TYPES, RELATIONSHIP_TYPES,
- DATA_TYPES, INTERFACE_TYPES, POLICY_TYPES, GROUP_TYPES
+ IMPORTS, NODE_TYPES, CAPABILITY_TYPES, RELATIONSHIP_TYPES,
+ DATA_TYPES, INTERFACE_TYPES, POLICY_TYPES, GROUP_TYPES
};
- LinkedHashMap<String,Object> customDefsFinal = new LinkedHashMap<>();
-
- List<Map<String, Object>> imports = (List<Map<String, Object>>) alImports;
- if (imports != null && !imports.isEmpty()) {
- if (imports.get(0) instanceof LinkedHashMap) {
- imports = sortImports(imports);
-
- for (Map<String, Object> map : imports) {
- List<Map<String, Object>> singleImportList = new ArrayList();
- singleImportList.add(map);
-
- Map<String, String> importNameDetails = getValidFileNameForImportReference(singleImportList);
- singleImportList = filterImportsForRecursion(singleImportList, importNameDetails);
-
- if(!singleImportList.get(0).isEmpty()){
- LinkedHashMap<String, Object> customDefs = _getCustomTypes(types, new ArrayList<>(singleImportList));
- processedImports.add(importNameDetails.get("importFileName"));
-
- if (customDefs != null) {
- customDefsFinal.putAll(customDefs);
-
- if (customDefs.get(IMPORTS) != null) {
- resetPathForRecursiveImports(importNameDetails.get("importRelativeName"));
- LinkedHashMap<String, Object> importDefs = _getAllCustomDefs(customDefs.get(IMPORTS));
- customDefsFinal.putAll(importDefs);
- }
- }
- }
- }
- } else {
- LinkedHashMap<String, Object> customDefs = _getCustomTypes(types, new ArrayList<>(imports));
- if (customDefs != null) {
- customDefsFinal.putAll(customDefs);
-
- if (customDefs.get(IMPORTS) != null) {
- LinkedHashMap<String, Object> importDefs = _getAllCustomDefs(customDefs.get(IMPORTS));
- customDefsFinal.putAll(importDefs);
- }
- }
+ LinkedHashMap<String,Object> customDefsFinal = new LinkedHashMap<String,Object>();
+ LinkedHashMap<String,Object> customDefs = _getCustomTypes(types,alImports);
+ if(customDefs != null) {
+ customDefsFinal.putAll(customDefs);
+ if(customDefs.get(IMPORTS) != null) {
+ @SuppressWarnings("unchecked")
+ LinkedHashMap<String,Object> importDefs = _getAllCustomDefs((ArrayList<Object>)customDefs.get(IMPORTS));
+ customDefsFinal.putAll(importDefs);
}
}
-
- // As imports are not custom_types, remove from the dict
- customDefsFinal.remove(IMPORTS);
+
+ // As imports are not custom_types, remove from the dict
+ customDefsFinal.remove(IMPORTS);
return customDefsFinal;
}
- /**
- * This method is used to sort the imports in order so that same directory
- * imports will be processed first
- *
- * @param customImports the custom imports
- * @return the sorted list of imports
- */
- private List<Map<String, Object>> sortImports(List<Map<String, Object>> customImports){
- List<Map<String, Object>> finalList1 = new ArrayList<>();
- List<Map<String, Object>> finalList2 = new ArrayList<>();
- Iterator<Map<String, Object>> itr = customImports.iterator();
- while(itr.hasNext()) {
- Map innerMap = itr.next();
- if (innerMap.toString().contains("../")) {
- finalList2.add(innerMap);
- itr.remove();
- }
- else if (innerMap.toString().contains("/")) {
- finalList1.add(innerMap);
- itr.remove();
- }
- }
-
- customImports.addAll(finalList1);
- customImports.addAll(finalList2);
- return customImports;
- }
-
- /**
- * This method is used to reset PATH variable after processing of current import file is done
- * This is required because of relative path nature of imports present in files.
- *
- * @param currImportRelativeName the current import relative name
- */
- private void resetPathForRecursiveImports(String currImportRelativeName){
- path = getPath(path, currImportRelativeName);
- }
-
- /**
- * This is a recursive method which starts from current import and then recursively finds a
- * valid path relative to current import file name.
- * By doing this it handles all nested hierarchy of imports defined in CSARs
- *
- * @param path the path
- * @param importFileName the import file name
- * @return the string containing updated path value
- */
- private String getPath(String path, String importFileName){
- String tempFullPath = (Paths.get(path).toAbsolutePath().getParent()
- .toString() + File.separator + importFileName.replace("../", "")).replace('\\', '/');
- String tempPartialPath = (Paths.get(path).toAbsolutePath().getParent().toString()).replace('\\', '/');
- if(Files.exists(Paths.get(tempFullPath)))
- return tempFullPath;
- else
- return getPath(tempPartialPath, importFileName);
- }
-
- /**
- * This method is used to get full path name for the file which needs to be processed. It helps
- * in situation where files are present in different directory and are references as relative
- * paths.
- *
- * @param customImports the custom imports
- * @return the map containing import file full and relative paths
- */
- private Map<String, String> getValidFileNameForImportReference(List<Map<String, Object>>
- customImports){
- String importFileName;
- Map<String, String> retMap = new HashMap<>();
- for (Map<String, Object> map1 : customImports) {
- for (Map.Entry<String, Object> entry : map1.entrySet()) {
- Map innerMostMap = (Map) entry.getValue();
- Iterator<Map.Entry<String, String>> it = innerMostMap.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry<String, String> val = it.next();
- if(val.getValue().contains("/")){
- importFileName = (Paths.get(rootPath).toAbsolutePath().getParent().toString() + File
- .separator + val.getValue().replace("../", "")).replace('\\', '/');
- }
- else {
- importFileName = (Paths.get(path).toAbsolutePath().getParent().toString() + File
- .separator + val.getValue().replace("../", "")).replace('\\', '/');
- }
- retMap.put("importFileName", importFileName);
- retMap.put("importRelativeName", val.getValue());
- }
- }
- }
- return retMap;
- }
-
- /**
- * This method is used to filter the imports which already gets processed in previous step.
- * It handles the use case of cyclic dependency in imports which may cause Stack Overflow
- * exception
- *
- * @param customImports the custom imports
- * @param importNameDetails the import name details
- * @return the list containing filtered imports
- */
- private List<Map<String, Object>> filterImportsForRecursion(List<Map<String, Object>>
- customImports, Map<String,
- String> importNameDetails){
- for (Map<String, Object> map1 : customImports) {
- for (Map.Entry<String, Object> entry : map1.entrySet()) {
- Map innerMostMap = (Map) entry.getValue();
- Iterator<Map.Entry<String, String>> it = innerMostMap.entrySet().iterator();
- while (it.hasNext()) {
- it.next();
- if (processedImports.contains(importNameDetails.get("importFileName"))) {
- it.remove();
- }
- }
- }
- }
-
- // Remove Empty elements
- Iterator<Map<String, Object>> itr = customImports.iterator();
- while(itr.hasNext()) {
- Map innerMap = itr.next();
- Predicate<Map> predicate = p-> p.values().isEmpty();
- innerMap.values().removeIf(predicate);
- }
-
- return customImports;
- }
-
@SuppressWarnings("unchecked")
private LinkedHashMap<String,Object> _getCustomTypes(Object typeDefinitions,ArrayList<Object> alImports) {
@@ -574,8 +396,6 @@ public class ToscaTemplate extends Object {
log.error("ToscaTemplate - _handleNestedToscaTemplatesWithTopology - Nested Topologies Loop: too many levels, aborting");
return;
}
- // Reset Processed Imports for nested templates
- this.processedImports = new HashSet<>();
for(Map.Entry<String,Object> me: nestedToscaTplsWithTopology.entrySet()) {
String fname = me.getKey();
LinkedHashMap<String,Object> toscaTpl =
@@ -836,6 +656,10 @@ public class ToscaTemplate extends Object {
return nestedToscaTemplatesWithTopology;
}
+ public ConcurrentHashMap<String, Object> getNestedTopologyTemplates() {
+ return nestedToscaTplsWithTopology;
+ }
+
@Override
public String toString() {
return "ToscaTemplate{" +
diff --git a/src/test/java/org/openecomp/sdc/toscaparser/api/JToscaImportTest.java b/src/test/java/org/openecomp/sdc/toscaparser/api/JToscaImportTest.java
deleted file mode 100644
index c8a30fa..0000000
--- a/src/test/java/org/openecomp/sdc/toscaparser/api/JToscaImportTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package org.openecomp.sdc.toscaparser.api;
-
-import org.junit.Test;
-import org.openecomp.sdc.toscaparser.api.common.JToscaException;
-import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import static org.junit.Assert.assertEquals;
-
-public class JToscaImportTest {
-
- @Test
- public void testNoMissingTypeValidationError() throws JToscaException {
- String fileStr = JToscaImportTest.class.getClassLoader().getResource
- ("csars/sdc-onboarding_csar.csar").getFile();
- File file = new File(fileStr);
- new ToscaTemplate(file.getAbsolutePath(), null, true, null);
- List<String> missingTypeErrors = ThreadLocalsHolder.getCollector()
- .getValidationIssueReport()
- .stream()
- .filter(s -> s.contains("JE136"))
- .collect(Collectors.toList());
- assertEquals(0, missingTypeErrors.size());
- }
-
- @Test
- public void testNoStackOverFlowError() {
- Exception jte = null;
- try {
- String fileStr = JToscaImportTest.class.getClassLoader().getResource
- ("csars/sdc-onboarding_csar.csar").getFile();
- File file = new File(fileStr);
- new ToscaTemplate(file.getAbsolutePath(), null, true, null);
- } catch (Exception e){
- jte = e;
- }
- assertEquals(null, jte);
- }
-
- @Test
- public void testNoInvalidImports() throws JToscaException {
- List<String> fileNames = new ArrayList<>();
- fileNames.add("csars/tmpCSAR_Huawei_vSPGW_fixed.csar");
- fileNames.add("csars/sdc-onboarding_csar.csar");
- fileNames.add("csars/resource-Spgw-csar-ZTE.csar");
-
- for (String fileName : fileNames) {
- String fileStr = JToscaImportTest.class.getClassLoader().getResource(fileName).getFile();
- File file = new File(fileStr);
- new ToscaTemplate(file.getAbsolutePath(), null, true, null);
- List<String> invalidImportErrors = ThreadLocalsHolder.getCollector()
- .getValidationIssueReport()
- .stream()
- .filter(s -> s.contains("JE195"))
- .collect(Collectors.toList());
- assertEquals(0, invalidImportErrors.size());
- }
- }
-
-}
diff --git a/src/test/resources/csars/resource-Spgw-csar-ZTE.csar b/src/test/resources/csars/resource-Spgw-csar-ZTE.csar
deleted file mode 100644
index 58c3ddd..0000000
--- a/src/test/resources/csars/resource-Spgw-csar-ZTE.csar
+++ /dev/null
Binary files differ
diff --git a/src/test/resources/csars/sdc-onboarding_csar.csar b/src/test/resources/csars/sdc-onboarding_csar.csar
deleted file mode 100644
index e1c3267..0000000
--- a/src/test/resources/csars/sdc-onboarding_csar.csar
+++ /dev/null
Binary files differ
diff --git a/version.properties b/version.properties
index 10a6323..a6be0db 100644
--- a/version.properties
+++ b/version.properties
@@ -5,7 +5,7 @@
major=1
minor=2
-patch=1
+patch=2
base_version=${major}.${minor}.${patch}