diff options
82 files changed, 1032 insertions, 527 deletions
diff --git a/jtosca/pom.xml b/jtosca/pom.xml index 3ef6a3c..8886012 100644 --- a/jtosca/pom.xml +++ b/jtosca/pom.xml @@ -5,11 +5,11 @@ <parent> <groupId>org.openecomp.sdc.sdc-distribution-client</groupId> <artifactId>sdc-main-distribution-client</artifactId> - <version>1.1.13-SNAPSHOT</version> + <version>1.1.14-SNAPSHOT</version> </parent> <artifactId>jtosca</artifactId> - <version>0.1.6-SNAPSHOT</version> + <version>0.1.7-SNAPSHOT</version> <dependencies> diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java index a081f89..350068b 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java @@ -11,6 +11,7 @@ import org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint; import org.openecomp.sdc.toscaparser.api.elements.constraints.Schema; import org.openecomp.sdc.toscaparser.api.functions.Function; import org.openecomp.sdc.toscaparser.api.utils.TOSCAVersionProperty; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; import org.openecomp.sdc.toscaparser.api.utils.ValidateUtils; public class DataEntity { @@ -49,7 +50,7 @@ public class DataEntity { else { if(!(value instanceof LinkedHashMap)) { //ERROR under investigation - ExceptionCollector.appendWarning(String.format( + ThreadLocalsHolder.getCollector().appendWarning(String.format( "TypeMismatchError: \"%s\" is not a map. The type is \"%s\"", value.toString(),dataType.getType())); @@ -85,7 +86,7 @@ public class DataEntity { for(String valueKey: valueDict.keySet()) { //1710 devlop JSON validation if(!("json").equals(dataType.getType()) && !allowedProps.contains(valueKey)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Data value of type \"%s\" contains unknown field \"%s\"", dataType.getType(),valueKey)); } @@ -108,7 +109,7 @@ public class DataEntity { } } if(missingProp.size() > 0) { - ExceptionCollector.appendWarning(String.format( + ThreadLocalsHolder.getCollector().appendWarning(String.format( "MissingRequiredFieldError: Data value of type \"%s\" is missing required field(s) \"%s\"", dataType.getType(),missingProp.toString())); } @@ -168,7 +169,7 @@ public class DataEntity { } else if (type == null) { //NOT ANALYZED - ExceptionCollector.appendWarning(String.format( + ThreadLocalsHolder.getCollector().appendWarning(String.format( "MissingType: Type is missing for value \"%s\"", value.toString())); return value; diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java index 224d5df..e896905 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java @@ -6,6 +6,7 @@ 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; public abstract class EntityTemplate { // Base class for TOSCA templates @@ -92,7 +93,7 @@ public abstract class EntityTemplate { if(type == null) { //msg = (_('Policy definition of "%(pname)s" must have' // ' a "type" ''attribute.') % dict(pname=name)) - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValidationError: Policy definition of \"%s\" must have a \"type\" attribute",name)); } typeDefinition = new PolicyType(type, customDef); @@ -312,7 +313,7 @@ public abstract class EntityTemplate { // '"default_instances" value is not between ' // '"min_instances" and "max_instances".' % // self.name) - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValidationError: \"properties\" of template \"%s\": \"default_instances\" value is not between \"min_instances\" and \"max_instances\"", name)); } @@ -343,7 +344,7 @@ public abstract class EntityTemplate { } // Required properties found without value or a default value if(!reqPropsNoValueOrDefault.isEmpty()) { - ExceptionCollector.appendWarning(String.format( + ThreadLocalsHolder.getCollector().appendWarning(String.format( "MissingRequiredFieldError: properties of template \"%s\" are missing field(s): %s", name,reqPropsNoValueOrDefault.toString())); } @@ -351,7 +352,7 @@ public abstract class EntityTemplate { else { // Required properties in schema, but not in template if(!requiredProps.isEmpty()) { - ExceptionCollector.appendWarning(String.format( + ThreadLocalsHolder.getCollector().appendWarning(String.format( "MissingRequiredFieldError2: properties of template \"%s\" are missing field(s): %s", name,requiredProps.toString())); } @@ -361,7 +362,7 @@ public abstract class EntityTemplate { @SuppressWarnings("unchecked") private void _validateField(LinkedHashMap<String,Object> template) { if(!(template instanceof LinkedHashMap)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "MissingRequiredFieldError: Template \"%s\" is missing required field \"%s\"",name,TYPE)); return;//??? } @@ -379,7 +380,7 @@ public abstract class EntityTemplate { bBad = (template.get(TYPE) == null); } if(bBad) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "MissingRequiredFieldError: Template \"%s\" is missing required field \"%s\"",name,TYPE)); } } @@ -394,7 +395,7 @@ public abstract class EntityTemplate { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Section \"%s\" of template \"%s\" contains unknown field \"%s\"",section,name,sname)); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Group.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Group.java index 58a3f87..8ed623f 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Group.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Group.java @@ -6,6 +6,7 @@ import java.util.Map; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.elements.Metadata; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; import org.openecomp.sdc.toscaparser.api.utils.ValidateUtils; public class Group extends EntityTemplate { @@ -69,7 +70,7 @@ public class Group extends EntityTemplate { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Groups \"%s\" contains unknown field \"%s\"", name,key)); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ImportsLoader.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ImportsLoader.java index 1ac334a..a97a360 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ImportsLoader.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ImportsLoader.java @@ -2,6 +2,7 @@ package org.openecomp.sdc.toscaparser.api; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.elements.TypeValidation; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; import org.openecomp.sdc.toscaparser.api.utils.UrlUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,7 +42,7 @@ public class ImportsLoader { if((_path == null || _path.isEmpty()) && tpl == null) { //msg = _('Input tosca template is not provided.') //log.warning(msg) - ExceptionCollector.appendException("ValidationError: Input tosca template is not provided"); + ThreadLocalsHolder.getCollector().appendException("ValidationError: Input tosca template is not provided"); } this.path = _path; @@ -77,7 +78,7 @@ public class ImportsLoader { if(importslist == null) { //msg = _('"imports" keyname is defined without including templates.') //log.error(msg) - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "ValidationError: \"imports\" keyname is defined without including templates"); return; } @@ -92,7 +93,7 @@ public class ImportsLoader { if(importNames.contains(importName)) { //msg = (_('Duplicate import name "%s" was found.') % import_name) //log.error(msg) - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValidationError: Duplicate import name \"%s\" was found",importName)); } importNames.add(importName); //??? @@ -168,7 +169,7 @@ public class ImportsLoader { private void _validateImportKeys(String importName, LinkedHashMap<String,Object> importUri) { if(importUri.get(FILE) == null) { //log.warning(_('Missing keyname "file" in import "%(name)s".') % {'name': import_name}) - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "MissingRequiredFieldError: Import of template \"%s\" is missing field %s",importName,FILE)); } for(String key: importUri.keySet()) { @@ -183,7 +184,7 @@ public class ImportsLoader { //log.warning(_('Unknown keyname "%(key)s" error in ' // 'imported definition "%(def)s".') // % {'key': key, 'def': import_name}) - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Import of template \"%s\" has unknown fiels %s",importName,key)); } } @@ -220,7 +221,7 @@ public class ImportsLoader { repository = (String)((LinkedHashMap<String,Object>)importUriDef).get(REPOSITORY); if(repository != null) { if(!repositories.keySet().contains(repository)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidPropertyValueError: Repository \"%s\" not found in \"%s\"", repository,repositories.keySet().toString())); } @@ -237,7 +238,7 @@ public class ImportsLoader { // 'definition "%(import_name)s".') // % {'import_name': import_name}) //log.error(msg) - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValidationError: A template file name is not provided with import definition \"%s\"",importName)); al[0] = al[1] = null; return al; @@ -252,7 +253,7 @@ public class ImportsLoader { return al; } catch(IOException e) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ImportError: \"%s\" loading YAML import from \"%s\"",e.getClass().getSimpleName(),fileName)); al[0] = al[1] = null; return al; @@ -268,7 +269,7 @@ public class ImportsLoader { String msg = String.format( "ImportError: Absolute file name \"%s\" cannot be used in the URL-based input template \"%s\"", fileName,path); - ExceptionCollector.appendException(msg); + ThreadLocalsHolder.getCollector().appendException(msg); al[0] = al[1] = null; return al; } @@ -311,7 +312,7 @@ public class ImportsLoader { //log.error(msg) String msg = String.format( "ValueError: \"%s\" is not a valid file",importTemplate); - ExceptionCollector.appendException(msg); + ThreadLocalsHolder.getCollector().appendException(msg); log.debug("ImportsLoader - _loadImportTemplate - {}", msg); } } @@ -329,7 +330,7 @@ public class ImportsLoader { else { String msg = String.format( "Relative file name \"%s\" cannot be used in a pre-parsed input template",fileName); - ExceptionCollector.appendException("ImportError: " + msg); + ThreadLocalsHolder.getCollector().appendException("ImportError: " + msg); al[0] = al[1] = null; return al; } @@ -338,7 +339,7 @@ public class ImportsLoader { if(importTemplate == null || importTemplate.isEmpty()) { //log.error(_('Import "%(name)s" is not valid.') % // {'name': import_uri_def}) - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ImportError: Import \"%s\" is not valid",importUriDef)); al[0] = al[1] = null; return al; @@ -347,7 +348,7 @@ public class ImportsLoader { // for now, this must be a file if(!aFile) { log.error("ImportsLoader - _loadImportTemplate - Error!! Expected a file. importUriDef = {}, importTemplate = {}", importUriDef, importTemplate); - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ImportError: Import \"%s\" is not a file",importName)); al[0] = al[1] = null; return al; @@ -360,13 +361,13 @@ public class ImportsLoader { return al; } catch(FileNotFoundException e) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ImportError: Failed to load YAML from \"%s\"",importName)); al[0] = al[1] = null; return al; } catch(Exception e) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ImportError: Exception from SnakeYAML file = \"%s\"",importName)); al[0] = al[1] = null; return al; @@ -375,7 +376,7 @@ public class ImportsLoader { if(shortImportNotation) { //log.error(_('Import "%(name)s" is not valid.') % import_uri_def) - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ImportError: Import \"%s\" is not valid",importName)); al[0] = al[1] = null; return al; @@ -409,7 +410,7 @@ public class ImportsLoader { String msg = String.format( "referenced repository \"%s\" in import definition \"%s\" not found", repository,importName); - ExceptionCollector.appendException("ImportError: " + msg); + ThreadLocalsHolder.getCollector().appendException("ImportError: " + msg); al[0] = al[1] = null; return al; } @@ -423,7 +424,7 @@ public class ImportsLoader { return al; } catch(IOException e) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ImportError: Exception loading YAML import from \"%s\"",fullUrl)); al[0] = al[1] = null; return al; @@ -433,12 +434,12 @@ public class ImportsLoader { String msg = String.format( "repository URL \"%s\" in import definition \"%s\" is not valid", repoUrl,importName); - ExceptionCollector.appendException("ImportError: " + msg); + ThreadLocalsHolder.getCollector().appendException("ImportError: " + msg); } // if we got here something is wrong with the flow... log.error("ImportsLoader - _loadImportTemplate - got to dead end (importName {})", importName); - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ImportError: _loadImportTemplate got to dead end (importName %s)\n",importName)); al[0] = al[1] = null; return al; diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java index 4d0baaf..c8af559 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java @@ -7,6 +7,7 @@ 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.CopyUtils; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class NodeTemplate extends EntityTemplate { @@ -96,13 +97,13 @@ public class NodeTemplate extends EntityTemplate { } } if(bFound || customDef.get(node) != null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "NotImplementedError: Lookup by TOSCA types is not supported. Requirement for \"%s\" can not be full-filled", getName())); return null; } if(templates.get(node) == null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Node template \"%s\" was not found",node)); return null; } @@ -117,7 +118,7 @@ public class NodeTemplate extends EntityTemplate { if(relationship == null) { ArrayList<Object> parentReqs = ((NodeType)typeDefinition).getAllRequirements(); if(parentReqs == null) { - ExceptionCollector.appendException("ValidationError: parent_req is null"); + ThreadLocalsHolder.getCollector().appendException("ValidationError: parent_req is null"); } else { for(String key: req.keySet()) { @@ -177,7 +178,7 @@ public class NodeTemplate extends EntityTemplate { } } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "MissingRequiredFieldError: \"relationship\" used in template \"%s\" is missing required field \"type\"", relatedTpl.getName())); } @@ -286,7 +287,7 @@ public class NodeTemplate extends EntityTemplate { ArrayList<Object> requires = (ArrayList<Object>)((NodeType)typeDefinition).getValue(REQUIREMENTS, entityTpl, false); if(requires != null) { if(!(requires instanceof ArrayList)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "TypeMismatchError: \"requirements\" of template \"%s\" are not of type \"list\"",name)); } else { @@ -331,7 +332,7 @@ public class NodeTemplate extends EntityTemplate { if(occurrences.size() != 2 || !(0 <= (int)occurrences.get(0) && (int)occurrences.get(0) <= (int)occurrences.get(1)) || (int)occurrences.get(1) == 0) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidPropertyValueError: property has invalid value %s",occurrences.toString())); } } @@ -346,7 +347,7 @@ public class NodeTemplate extends EntityTemplate { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: \"requirements\" of template \"%s\" contains unknown field \"%s\"",name,key)); } } @@ -380,7 +381,7 @@ public class NodeTemplate extends EntityTemplate { _commonValidateField(value,_collectCustomIfaceOperations(iname),"interfaces"); } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: \"interfaces\" of template \"%s\" contains unknown field %s",name,iname)); } } @@ -432,7 +433,7 @@ public class NodeTemplate extends EntityTemplate { } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Node template \"%s\" has unknown field \"%s\"",name,ntname)); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Policy.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Policy.java index 1474d0b..a59d9d5 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Policy.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Policy.java @@ -5,6 +5,7 @@ import java.util.LinkedHashMap; import java.util.Map; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; import org.openecomp.sdc.toscaparser.api.utils.ValidateUtils; public class Policy extends EntityTemplate { @@ -100,7 +101,7 @@ public class Policy extends EntityTemplate { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Policy \"%s\" contains unknown field \"%s\"", name,key)); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Repository.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Repository.java index 39699f3..92a90af 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Repository.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Repository.java @@ -3,6 +3,7 @@ package org.openecomp.sdc.toscaparser.api; import java.util.LinkedHashMap; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; import org.openecomp.sdc.toscaparser.api.utils.UrlUtils; public class Repository { @@ -23,7 +24,7 @@ public class Repository { if(reposit instanceof LinkedHashMap) { url = (String)((LinkedHashMap<String,Object>)reposit).get("url"); if(url == null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "MissingRequiredFieldError: Repository \"%s\" is missing required field \"url\"", name)); } @@ -44,7 +45,7 @@ public class Repository { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: repositories \"%s\" contains unknown field \"%s\"", keyname,key)); } @@ -54,7 +55,7 @@ public class Repository { if(repositUrl != null) { boolean urlVal = UrlUtils.validateUrl(repositUrl); if(!urlVal) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "URLException: repsositories \"%s\" Invalid Url",keyname)); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java index 153bd89..b9c2238 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java @@ -9,6 +9,7 @@ import org.openecomp.sdc.toscaparser.api.elements.NodeType; import org.openecomp.sdc.toscaparser.api.elements.PropertyDef; import org.openecomp.sdc.toscaparser.api.parameters.Input; import org.openecomp.sdc.toscaparser.api.parameters.Output; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class SubstitutionMappings { @@ -128,7 +129,7 @@ public class SubstitutionMappings { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: SubstitutionMappings contain unknown field \"%s\"", key)); } @@ -139,13 +140,13 @@ public class SubstitutionMappings { // validate the node_type of substitution mappings String nodeType = (String)subMappingDef.get(NODE_TYPE); if(nodeType == null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "MissingRequiredFieldError: SubstitutionMappings used in topology_template is missing required field \"%s\"", NODE_TYPE)); } Object nodeTypeDef = customDefs.get(nodeType); if(nodeTypeDef == null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidNodeTypeError: \"%s\" is invalid",nodeType)); } } @@ -172,7 +173,7 @@ public class SubstitutionMappings { for(String property: requiredProperties) { // Check property which is 'required' and has no 'default' value if(!allInputs.contains(property)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "MissingRequiredInputError: SubstitutionMappings with node_type \"%s\" is missing required input \"%s\"", getNodeType(),property)); } @@ -190,7 +191,7 @@ public class SubstitutionMappings { diffset.removeAll(allInputs); for(String parameter: diffset) { if(allProperties.contains(parameter)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "MissingRequiredInputError: SubstitutionMappings with node_type \"%s\" is missing required input \"%s\"", getNodeType(),parameter)); } @@ -203,7 +204,7 @@ public class SubstitutionMappings { diffset = allInputs; diffset.removeAll(allProperties); if(diffset.contains(inp.getName()) && inp.getDefault() == null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "MissingRequiredInputError: SubstitutionMappings with node_type \"%s\" is missing rquired input \"%s\"", getNodeType(),inp.getName())); } @@ -276,7 +277,7 @@ public class SubstitutionMappings { for(Output output: outputs) { Object ado = getNodeDefinition().getAttributesDef(); if(ado != null && ((LinkedHashMap<String,Object>)ado).get(output.getName()) == null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownOutputError: Unknown output \"%s\" in SubstitutionMappings with node_type \"%s\"", output.getName(),getNodeType())); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java index 4050643..25f118b 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java @@ -14,6 +14,7 @@ import org.openecomp.sdc.toscaparser.api.functions.GetAttribute; import org.openecomp.sdc.toscaparser.api.functions.GetInput; import org.openecomp.sdc.toscaparser.api.parameters.Input; import org.openecomp.sdc.toscaparser.api.parameters.Output; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class TopologyTemplate { @@ -232,7 +233,7 @@ public class TopologyTemplate { DataEntity.validateDatatype("list", memberNames,null,null,null); if(memberNames.size() < 1 || (new HashSet<String>(memberNames)).size() != memberNames.size()) { - ExceptionCollector.appendWarning(String.format( + ThreadLocalsHolder.getCollector().appendWarning(String.format( "InvalidGroupTargetException: Member nodes \"%s\" should be >= 1 and not repeated", memberNames.toString())); } @@ -281,7 +282,7 @@ public class TopologyTemplate { } for(String member: members) { if(!nodeNames.contains(member)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidGroupTargetException: Target member \"%s\" is not found in \"nodeTemplates\"",member)); } } @@ -383,7 +384,7 @@ public class TopologyTemplate { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: TopologyTemplate contains unknown field \"%s\"",name)); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java index 9f2fd7a..b13a2a5 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java @@ -5,10 +5,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.common.JToscaException; @@ -18,6 +15,8 @@ import org.openecomp.sdc.toscaparser.api.extensions.ExtTools; import org.openecomp.sdc.toscaparser.api.parameters.Input; import org.openecomp.sdc.toscaparser.api.parameters.Output; import org.openecomp.sdc.toscaparser.api.prereq.CSAR; +import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.yaml.snakeyaml.Yaml; @@ -65,7 +64,6 @@ public class ToscaTemplate extends Object { private ArrayList<String> VALID_TEMPLATE_VERSIONS; private LinkedHashMap<String,ArrayList<String>> ADDITIONAL_SECTIONS; - private boolean bAbortOnParsingErrors = false; private boolean isFile; private String path; private String inputPath; @@ -96,6 +94,8 @@ public class ToscaTemplate extends Object { boolean aFile, LinkedHashMap<String,Object> yamlDictTpl) throws JToscaException { + ThreadLocalsHolder.setCollector(new ExceptionCollector(_path)); + VALID_TEMPLATE_VERSIONS = new ArrayList<>(); VALID_TEMPLATE_VERSIONS.add("tosca_simple_yaml_1_0"); VALID_TEMPLATE_VERSIONS.addAll(exttools.getVersions()); @@ -107,7 +107,6 @@ public class ToscaTemplate extends Object { //long startTime = System.nanoTime(); - //ExceptionCollector.start(); isFile = aFile; inputPath = null; @@ -158,7 +157,7 @@ public class ToscaTemplate extends Object { tpl = yamlDictTpl; } else { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "ValueError: No path or yaml_dict_tpl was provided. There is nothing to parse"); log.debug("ToscaTemplate ValueError: No path or yaml_dict_tpl was provided. There is nothing to parse"); @@ -190,14 +189,14 @@ public class ToscaTemplate extends Object { csarTempDir = null; } - //ExceptionCollector.stop(); verifyTemplate(); - } + } + private void _abort() throws JToscaException { // print out all exceptions caught verifyTemplate(); - throw new JToscaException("jtosca aborting"); + throw new JToscaException("jtosca aborting", JToscaErrorCodes.PATH_NOT_VALID.getValue()); } private TopologyTemplate _topologyTemplate() { return new TopologyTemplate( @@ -429,7 +428,7 @@ public class ToscaTemplate extends Object { private void _validateField() { String sVersion = _tplVersion(); if(sVersion == null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "MissingRequiredField: Template is missing required field \"%s\"",DEFINITION_VERSION)); } else { @@ -453,7 +452,7 @@ public class ToscaTemplate extends Object { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Template contains unknown field \"%s\"", sKey)); } @@ -469,7 +468,7 @@ public class ToscaTemplate extends Object { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidTemplateVersion: \"%s\" is invalid. Valid versions are %s", sVersion,VALID_TEMPLATE_VERSIONS.toString())); } @@ -478,7 +477,7 @@ public class ToscaTemplate extends Object { } } - private String _getPath(String _path) { + private String _getPath(String _path) throws JToscaException { if (_path.toLowerCase().endsWith(".yaml") || _path.toLowerCase().endsWith(".yml")) { return _path; } @@ -501,49 +500,39 @@ public class ToscaTemplate extends Object { } } else { - ExceptionCollector.appendException("ValueError: " + _path + " is not a valid file"); + ThreadLocalsHolder.getCollector().appendException("ValueError: " + _path + " is not a valid file"); return null; } return null; } private void verifyTemplate() throws JToscaException { + ThreadLocalsHolder.getCollector().setWantTrace(false); + //Warnings - List<String> warningsStrings = ExceptionCollector.getWarningsReport(); - if (warningsStrings != null && warningsStrings.size() > 0) { - int nexcw = ExceptionCollector.warningsCaught(); + int warningsCount = ThreadLocalsHolder.getCollector().warningsCaught(); + if (warningsCount > 0) { + List<String> warningsStrings = ThreadLocalsHolder.getCollector().getWarningsReport(); log.warn("####################################################################################################"); - log.warn("ToscaTemplate - verifyTemplate - {} Parsing Warning{} occurred...", nexcw, (nexcw > 1 ? "s" : "")); + log.warn("CSAR Warnings found! CSAR name - {}", inputPath); + log.warn("ToscaTemplate - verifyTemplate - {} Parsing Warning{} occurred...", warningsCount, (warningsCount > 1 ? "s" : "")); for (String s : warningsStrings) { - if (s != null) { - log.debug("ToscaTemplate - verifyTemplate - {}", s); - } + log.warn("{}. CSAR name - {}", s, inputPath); } log.warn("####################################################################################################"); + } - - List<String> exceptionStrings = ExceptionCollector.getCriticalsReport(); - if (exceptionStrings != null && exceptionStrings.size() > 0) { - int nexc = ExceptionCollector.errorsCaught(); - log.error("####################################################################################################"); - log.error("ToscaTemplate - verifyTemplate - {} Parsing Critical{} occurred...", nexc, (nexc > 1 ? "s" : "")); - for (String s : exceptionStrings) { - if (s != null) { - log.debug("ToscaTemplate - verifyTemplate - {}", s); - } - } - log.error("####################################################################################################"); - if(bAbortOnParsingErrors) { - throw new JToscaException("Aborting because of parsing errors"); - } - } - else { - if (inputPath != null) { - log.debug("ToscaTemplate - verifyTemplate - The input {} passed validation", inputPath); - } + //Criticals + int criticalsCount = ThreadLocalsHolder.getCollector().criticalsCaught(); + if (criticalsCount > 0) { + List<String> criticalStrings = ThreadLocalsHolder.getCollector().getCriticalsReport(); + log.error("####################################################################################################"); + log.error("ToscaTemplate - verifyTemplate - {} Parsing Critical{} occurred...", criticalsCount, (criticalsCount > 1 ? "s" : "")); + for (String s : criticalStrings) { + log.error("{}. CSAR name - {}", s, inputPath); } - - } + throw new JToscaException(String.format("CSAR Validation Failed. CSAR name - {}. Please check logs for details.", inputPath), JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR.getValue()); + } } public String getPath() { @@ -648,10 +637,6 @@ public class ToscaTemplate extends Object { public ArrayList<TopologyTemplate> getNestedTemplates() { return nestedToscaTemplatesWithTopology; } - - public void setAbortOnParsingErrors(boolean b) { - bAbortOnParsingErrors = b; - } @Override public String toString() { @@ -659,7 +644,6 @@ public class ToscaTemplate extends Object { "exttools=" + exttools + ", VALID_TEMPLATE_VERSIONS=" + VALID_TEMPLATE_VERSIONS + ", ADDITIONAL_SECTIONS=" + ADDITIONAL_SECTIONS + - ", bAbortOnParsingErrors=" + bAbortOnParsingErrors + ", isFile=" + isFile + ", path='" + path + '\'' + ", inputPath='" + inputPath + '\'' + @@ -692,7 +676,7 @@ import logging import os from copy import deepcopy -from toscaparser.common.exception import ExceptionCollector +from toscaparser.common.exception import ExceptionCollector.collector from toscaparser.common.exception import InvalidTemplateVersion from toscaparser.common.exception import MissingRequiredFieldError from toscaparser.common.exception import UnknownFieldError @@ -744,7 +728,7 @@ class ToscaTemplate(object): def __init__(self, path=None, parsed_params=None, a_file=True, yaml_dict_tpl=None): - ExceptionCollector.start() + ExceptionCollector.collector.start() self.a_file = a_file self.input_path = None self.path = None @@ -765,7 +749,7 @@ class ToscaTemplate(object): if yaml_dict_tpl: self.tpl = yaml_dict_tpl else: - ExceptionCollector.appendException( + ExceptionCollector.collector.appendException( ValueError(_('No path or yaml_dict_tpl was provided. ' 'There is nothing to parse.'))) @@ -785,7 +769,7 @@ class ToscaTemplate(object): self._handle_nested_tosca_templates_with_topology() self.graph = ToscaGraph(self.nodetemplates) - ExceptionCollector.stop() + ExceptionCollector.collector.stop() self.verify_template() def _topology_template(self): @@ -921,7 +905,7 @@ class ToscaTemplate(object): def _validate_field(self): version = self._tpl_version() if not version: - ExceptionCollector.appendException( + ExceptionCollector.collector.appendException( MissingRequiredFieldError(what='Template', required=DEFINITION_VERSION)) else: @@ -931,12 +915,12 @@ class ToscaTemplate(object): for name in self.tpl: if (name not in SECTIONS and name not in self.ADDITIONAL_SECTIONS.get(version, ())): - ExceptionCollector.appendException( + ExceptionCollector.collector.appendException( UnknownFieldError(what='Template', field=name)) def _validate_version(self, version): if version not in self.VALID_TEMPLATE_VERSIONS: - ExceptionCollector.appendException( + ExceptionCollector.collector.appendException( InvalidTemplateVersion( what=version, valid_versions=', '. join(self.VALID_TEMPLATE_VERSIONS))) @@ -955,23 +939,23 @@ class ToscaTemplate(object): self.a_file = True # the file has been decompressed locally return os.path.join(csar.temp_dir, csar.get_main_template()) else: - ExceptionCollector.appendException( + ExceptionCollector.collector.appendException( ValueError(_('"%(path)s" is not a valid file.') % {'path': path})) def verify_template(self): - if ExceptionCollector.exceptionsCaught(): + if ExceptionCollector.collector.exceptionsCaught(): if self.input_path: raise ValidationError( message=(_('\nThe input "%(path)s" failed validation with ' 'the following error(s): \n\n\t') % {'path': self.input_path}) + - '\n\t'.join(ExceptionCollector.getExceptionsReport())) + '\n\t'.join(ExceptionCollector.collector.getExceptionsReport())) else: raise ValidationError( message=_('\nThe pre-parsed input failed validation with ' 'the following error(s): \n\n\t') + - '\n\t'.join(ExceptionCollector.getExceptionsReport())) + '\n\t'.join(ExceptionCollector.collector.getExceptionsReport())) else: if self.input_path: msg = (_('The input "%(path)s" successfully passed ' diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Triggers.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Triggers.java index d753f4b..0ec0b5a 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Triggers.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/Triggers.java @@ -3,6 +3,7 @@ package org.openecomp.sdc.toscaparser.api; import java.util.LinkedHashMap; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; import org.openecomp.sdc.toscaparser.api.utils.ValidateUtils; public class Triggers extends EntityTemplate { @@ -76,7 +77,7 @@ public class Triggers extends EntityTemplate { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Triggers \"%s\" contains unknown field \"%s\"", name,key)); } @@ -93,7 +94,7 @@ public class Triggers extends EntityTemplate { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Triggers \"%s\" contains unknown field \"%s\"", name,key)); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/UnsupportedType.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/UnsupportedType.java index 318b3d3..2bd0197 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/UnsupportedType.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/UnsupportedType.java @@ -1,6 +1,7 @@ package org.openecomp.sdc.toscaparser.api; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class UnsupportedType { @@ -26,7 +27,7 @@ public class UnsupportedType { public static boolean validateType(String entityType) { for(String ust: unsupportedTypes) { if(ust.equals(entityType)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnsupportedTypeError: Entity type \"%s\" is not supported",entityType)); return true; } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java index b810e87..fa65ae4 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/ExceptionCollector.java @@ -1,7 +1,9 @@ package org.openecomp.sdc.toscaparser.api.common; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -10,114 +12,111 @@ import org.slf4j.LoggerFactory; public class ExceptionCollector { - private static Logger log = LoggerFactory.getLogger(ExceptionCollector.class.getName()); - - //private static boolean isCollecting = false; - private static ArrayList<String> exceptionStrings = new ArrayList<>(); - private static ArrayList<String> exceptionTraceStrings = new ArrayList<>(); - private static ArrayList<String> warningStrings = new ArrayList<>(); - private static ArrayList<String> warningTraceStrings = new ArrayList<>(); - private static boolean bWantTrace = true; - - /*public static void start() { - if(exceptionStrings == null) { - exceptionStrings = new ArrayList<String>(); - exceptionTraceStrings = new ArrayList<String>(); - } - isCollecting = true; - }*/ - - /*public static void stop() { - isCollecting = false; - }*/ - - public static void clear() { - exceptionStrings = new ArrayList<>(); - exceptionTraceStrings = new ArrayList<>(); - warningStrings = new ArrayList<>(); - warningTraceStrings = new ArrayList<>(); - } - - public static void appendException(String strExc) { // throws Exception { - - /*if(!isCollecting) { - // throw new Exception("Can't append exception " + strExc); - log.error("ExceptionCollector - appendException - Can't append exception {}", strExc); - }*/ - - if(!exceptionStrings.contains(strExc)) { - exceptionStrings.add(strExc); - // get stack trace - StackTraceElement[] ste = Thread.currentThread().getStackTrace(); - StringBuilder sb = new StringBuilder(); - // skip the last 2 (getStackTrace and this) - for(int i=2; i<ste.length; i++) { - sb.append(String.format(" %s(%s:%d)%s",ste[i].getClassName(),ste[i].getFileName(), - ste[i].getLineNumber(),i==ste.length-1?" ":"\n")); - } - exceptionTraceStrings.add(sb.toString()); - } - } - - public static void appendWarning(String strExc) { // throws Exception { - - /*if(!isCollecting) { - // throw new Exception("Can't append exception " + strExc); - log.error("ExceptionCollector - appendException - Can't append exception {}", strExc); - }*/ - - if(!warningStrings.contains(strExc)) { - warningStrings.add(strExc); - // get stack trace - StackTraceElement[] ste = Thread.currentThread().getStackTrace(); - StringBuilder sb = new StringBuilder(); - // skip the last 2 (getStackTrace and this) - for(int i=2; i<ste.length; i++) { - sb.append(String.format(" %s(%s:%d)%s",ste[i].getClassName(),ste[i].getFileName(), - ste[i].getLineNumber(),i==ste.length-1?" ":"\n")); - } - warningTraceStrings.add(sb.toString()); - } - } - - public static List<String> getCriticalsReport() { - - List<String> res = new ArrayList<>(); - if(exceptionStrings.size() > 0) { - for(int i=0; i<exceptionStrings.size(); i++) { - res.add(exceptionStrings.get(i)); - if(bWantTrace) { - res.add(exceptionTraceStrings.get(i)); - } - } - } - return res; - } - - public static List<String> getWarningsReport() { - - List<String> res = new ArrayList<>(); - if(warningStrings.size() > 0) { - for(int i=0; i<warningStrings.size(); i++) { - res.add(warningStrings.get(i)); - if(bWantTrace) { - res.add(warningTraceStrings.get(i)); - } - } - } - return res; - } - - public static int errorsCaught() { - return exceptionStrings.size(); - } - - public static int warningsCaught() { - return warningStrings.size(); - } - - public static void setWantTrace(boolean b) { - bWantTrace = b; - } + private static Logger log = LoggerFactory.getLogger(ExceptionCollector.class.getName()); + + private Map<String, String> notAnalyzedExceptions = new HashMap<>(); + private Map<String, String> criticalExceptions = new HashMap<>(); + private Map<String, String> warningExceptions = new HashMap<>(); + + private boolean bWantTrace = true; + private String filePath; + + public enum ReportType {WARNING, CRITICAL, NOT_ANALYZED} + + public ExceptionCollector(String filePath) { + this.filePath = filePath; + } + + public void appendException(String exception) { + + addException(exception, ReportType.NOT_ANALYZED); + } + + public void appendCriticalException(String exception) { + + addException(exception, ReportType.CRITICAL); + } + + public void appendWarning(String exception) { + + addException(exception, ReportType.WARNING); + } + + private void addException(String exception, ReportType type) { + + Map<String, String> exceptions = getExceptionCollection(type); + + if (!exceptions.containsKey(exception)) { + // get stack trace + StackTraceElement[] ste = Thread.currentThread().getStackTrace(); + StringBuilder sb = new StringBuilder(); + // skip the last 2 (getStackTrace and this) + for (int i = 2; i < ste.length; i++) { + sb.append(String.format(" %s(%s:%d)%s", ste[i].getClassName(), ste[i].getFileName(), + ste[i].getLineNumber(), i == ste.length - 1 ? " " : "\n")); + } + exceptions.put(exception, sb.toString()); + } + } + + public List<String> getCriticalsReport() { + + return getReport(ReportType.CRITICAL); + } + + public List<String> getNotAnalyzedExceptionsReport() { + + return getReport(ReportType.NOT_ANALYZED); + } + + public List<String> getWarningsReport() { + + return getReport(ReportType.WARNING); + } + + private List<String> getReport(ReportType type) { + Map<String, String> collectedExceptions = getExceptionCollection(type); + + List<String> report = new ArrayList<>(); + if (collectedExceptions.size() > 0) { + for (Map.Entry<String, String> exception : collectedExceptions.entrySet()) { + report.add(exception.getKey()); + if (bWantTrace) { + report.add(exception.getValue()); + } + } + } + + return report; + } + + private Map<String, String> getExceptionCollection(ReportType type) { + switch (type) { + case WARNING: + return warningExceptions; + case CRITICAL: + return criticalExceptions; + case NOT_ANALYZED: + return notAnalyzedExceptions; + default: + return notAnalyzedExceptions; + } + } + + public int errorsNotAnalyzedCaught() { + return notAnalyzedExceptions.size(); + } + + public int criticalsCaught() { + return criticalExceptions.size(); + } + + public int warningsCaught() { + return warningExceptions.size(); + } + + public void setWantTrace(boolean b) { + bWantTrace = b; + } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/JToscaException.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/JToscaException.java index 0046aa1..6cd5872 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/JToscaException.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/common/JToscaException.java @@ -3,9 +3,25 @@ package org.openecomp.sdc.toscaparser.api.common; public class JToscaException extends Exception { private static final long serialVersionUID = 1L; - - public JToscaException(String message) { + private String code; + + public JToscaException(String message, String code) { super(message); + this.code = code; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; } + //JT1001 - Meta file missing + //JT1002 - Invalid yaml content + //JT1003 - Entry-Definition not defined in meta file + //JT1004 - Entry-Definition file missing + //JT1005 - General Error + //JT1006 - General Error/Path not valid } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/GroupType.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/GroupType.java index 9a343b7..d226b78 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/GroupType.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/GroupType.java @@ -3,6 +3,7 @@ package org.openecomp.sdc.toscaparser.api.elements; import java.util.LinkedHashMap; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class GroupType extends StatefulEntityType { @@ -91,7 +92,7 @@ public class GroupType extends StatefulEntityType { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Group Type \"%s\" contains unknown field \"%s\"", groupType,name)); } @@ -103,7 +104,7 @@ public class GroupType extends StatefulEntityType { private void _validateMetadata(LinkedHashMap<String,Object> metadata) { String mtt = (String) metadata.get("type"); if(mtt != null && !mtt.equals("map") && !mtt.equals("tosca:map")) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidTypeError: \"%s\" defined in group for metadata is invalid", mtt)); } @@ -112,7 +113,7 @@ public class GroupType extends StatefulEntityType { if(estob instanceof LinkedHashMap) { String est = (String)((LinkedHashMap<String,Object>)estob).get("type"); if(!est.equals("string")) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidTypeError: \"%s\" defined in group for metadata \"%s\" is invalid", est,entrySchema)); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/InterfacesDef.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/InterfacesDef.java index c8c1518..8a2b4dd 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/InterfacesDef.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/InterfacesDef.java @@ -6,6 +6,7 @@ import java.util.Map; import org.openecomp.sdc.toscaparser.api.EntityTemplate; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class InterfacesDef extends StatefulEntityType { @@ -90,7 +91,7 @@ public class InterfacesDef extends StatefulEntityType { inputs = (LinkedHashMap<String,Object>)me.getValue(); } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: \"interfaces\" of template \"%s\" contain unknown field \"%s\"", nodeTemplate.getName(),me.getKey())); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/NodeType.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/NodeType.java index e7dc464..d5f1a18 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/NodeType.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/NodeType.java @@ -6,6 +6,7 @@ import java.util.Map; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.elements.InterfacesDef; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class NodeType extends StatefulEntityType { // TOSCA built-in node type @@ -314,7 +315,7 @@ public class NodeType extends StatefulEntityType { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Nodetype \"%s\" has unknown field \"%s\"",ntype,key)); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PolicyType.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PolicyType.java index d894b04..c60bed1 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PolicyType.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PolicyType.java @@ -5,6 +5,7 @@ import java.util.LinkedHashMap; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.utils.TOSCAVersionProperty; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class PolicyType extends StatefulEntityType { @@ -134,7 +135,7 @@ public class PolicyType extends StatefulEntityType { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Policy \"%s\" contains unknown field \"%s\"", type,key)); } @@ -145,7 +146,7 @@ public class PolicyType extends StatefulEntityType { LinkedHashMap<String,Object> _customDef) { for(String nodetype: _targetsList) { if(_customDef.get(nodetype) == null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidTypeError: \"%s\" defined in targets for policy \"%s\"", nodetype,type)); @@ -156,7 +157,7 @@ public class PolicyType extends StatefulEntityType { private void _validateMetadata(LinkedHashMap<String,Object> _metaData) { String mtype = (String)_metaData.get("type"); if(mtype != null && !mtype.equals("map") && !mtype.equals("tosca:map")) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidTypeError: \"%s\" defined in policy for metadata", mtype)); } @@ -166,7 +167,7 @@ public class PolicyType extends StatefulEntityType { String est = (String) ((LinkedHashMap<String,Object>)estob).get("type"); if(!est.equals("string")) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidTypeError: \"%s\" defined in policy for metadata \"%s\"", est,entrySchema)); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PortSpec.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PortSpec.java index dcb14f9..8d490ee 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PortSpec.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PortSpec.java @@ -4,6 +4,7 @@ import java.util.LinkedHashMap; import org.openecomp.sdc.toscaparser.api.DataEntity; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; import org.openecomp.sdc.toscaparser.api.utils.ValidateUtils; public class PortSpec { @@ -52,7 +53,7 @@ public class PortSpec { // verify one of the specified values is set if(source == null && sourceRange == null && target == null && targetRange == null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidTypeAdditionalRequirementsError: Additional requirements for type \"%s\" not met", TYPE_URI)); } @@ -74,7 +75,7 @@ public class PortSpec { } } catch(Exception e) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: \"%s\" do not meet requirements for type \"%s\"", _properties.toString(),SHORTNAME)); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PropertyDef.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PropertyDef.java index 5e6b47d..c139eb6 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PropertyDef.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/PropertyDef.java @@ -4,6 +4,7 @@ import java.util.LinkedHashMap; import java.util.Map; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class PropertyDef { @@ -45,7 +46,7 @@ public class PropertyDef { if(schema.get("type") == null) { //msg = (_('Schema definition of "%(pname)s" must have a "type" ' // 'attribute.') % dict(pname=self.name)) - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidSchemaError: Schema definition of \"%s\" must have a \"type\" attribute",name)); } _loadRequiredAttrFromSchema(); @@ -83,7 +84,7 @@ public class PropertyDef { // attr, // value, // valid_values) - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "Schema definition of \"%s\" has \"required\" attribute with an invalid value", name)); } @@ -116,7 +117,7 @@ public class PropertyDef { // attr, // value, // valid_values) - ExceptionCollector.appendWarning(String.format( + ThreadLocalsHolder.getCollector().appendWarning(String.format( "Schema definition of \"%s\" has \"status\" attribute with an invalid value", name)); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/RelationshipType.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/RelationshipType.java index 15930ed..3903941 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/RelationshipType.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/RelationshipType.java @@ -5,6 +5,7 @@ import java.util.LinkedHashMap; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.elements.EntityType; import org.openecomp.sdc.toscaparser.api.elements.StatefulEntityType; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class RelationshipType extends StatefulEntityType { @@ -53,7 +54,7 @@ public class RelationshipType extends StatefulEntityType { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Relationshiptype \"%s\" has unknown field \"%s\"",type,key)); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/ScalarUnit.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/ScalarUnit.java index 42e94eb..de18cd6 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/ScalarUnit.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/ScalarUnit.java @@ -5,6 +5,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; import org.openecomp.sdc.toscaparser.api.utils.ValidateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,7 +52,7 @@ public abstract class ScalarUnit { return key; } } - ExceptionCollector.appendWarning(String.format( + ThreadLocalsHolder.getCollector().appendWarning(String.format( "'The unit \"%s\" is not valid. Valid units are \n%s", inputUnit,SCALAR_UNIT_DICT.keySet().toString())); return inputUnit; @@ -67,7 +68,7 @@ public abstract class ScalarUnit { value = matcher.group(1) + " " + scalarUnit; } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: \"%s\" is not a valid scalar-unit",value.toString())); } return value; @@ -135,7 +136,7 @@ public abstract class ScalarUnit { if(type.equals(SCALAR_UNIT_FREQUENCY)) { return (new ScalarUnitFrequency(value)).getNumFromScalarUnit(unit); } - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "TypeError: \"%s\" is not a valid scalar-unit type",type)); return 0.0; } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/StatefulEntityType.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/StatefulEntityType.java index 04836ff..5ab816f 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/StatefulEntityType.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/StatefulEntityType.java @@ -9,6 +9,7 @@ import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.elements.AttributeDef; import org.openecomp.sdc.toscaparser.api.elements.EntityType; import org.openecomp.sdc.toscaparser.api.elements.PropertyDef; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class StatefulEntityType extends EntityType { @@ -48,7 +49,7 @@ public class StatefulEntityType extends EntityType { } else{ defs = null; - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidTypeError: \"%s\" is not a valid type",entityType)); } } @@ -66,7 +67,7 @@ public class StatefulEntityType extends EntityType { Object to = me.getValue(); if(to == null || !(to instanceof LinkedHashMap)) { String s = to == null ? "null" : to.getClass().getSimpleName(); - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "Unexpected type error: property \"%s\" has type \"%s\" (expected dict)",pdname,s)); continue; } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/TypeValidation.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/TypeValidation.java index c951540..2caf5c4 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/TypeValidation.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/TypeValidation.java @@ -5,6 +5,7 @@ import java.util.LinkedHashMap; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.extensions.ExtTools; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class TypeValidation { @@ -70,7 +71,7 @@ public class TypeValidation { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Template \"%s\" contains unknown field \"%s\"", importDef.toString(),name)); } @@ -88,7 +89,7 @@ public class TypeValidation { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidTemplateVersion: version \"%s\" in \"%s\" is not supported\n" + "Allowed versions: [%s]", sVersion,importDef.toString(),allowed)); diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Constraint.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Constraint.java index 60b756f..3c60a66 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Constraint.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Constraint.java @@ -5,6 +5,7 @@ import java.util.LinkedHashMap; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.elements.ScalarUnit; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public abstract class Constraint { @@ -34,7 +35,7 @@ public abstract class Constraint { if(!(constraint instanceof LinkedHashMap) || ((LinkedHashMap<String,Object>)constraint).size() != 1) { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "InvalidSchemaError: Invalid constraint schema " + constraint.toString()); } @@ -72,7 +73,7 @@ public abstract class Constraint { return new Pattern(propname,proptype,constraint); } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidSchemaError: Invalid property \"%s\"",constraintClass)); return null; } @@ -116,7 +117,7 @@ public abstract class Constraint { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidSchemaError: Property \"%s\" is not valid for data type \"%s\"", constraintKey,propertyType)); } @@ -152,7 +153,7 @@ public abstract class Constraint { value = ScalarUnit.getScalarunitValue(propertyType,value,null); } if(!_isValid(value)) { - ExceptionCollector.appendWarning("ValidationError: " + _errMsg(value)); + ThreadLocalsHolder.getCollector().appendWarning("ValidationError: " + _errMsg(value)); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterOrEqual.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterOrEqual.java index 168fd92..021bed3 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterOrEqual.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterOrEqual.java @@ -4,6 +4,7 @@ import java.util.Date; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.functions.Function; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class GreaterOrEqual extends Constraint { // Constraint class for "greater_or_equal" @@ -37,7 +38,7 @@ public class GreaterOrEqual extends Constraint { super(name,type,c); if(!validTypes.contains(constraintValue.getClass().getSimpleName())) { - ExceptionCollector.appendException("InvalidSchemaError: The property \"greater_or_equal\" expects comparable values"); + ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"greater_or_equal\" expects comparable values"); } } @@ -90,7 +91,7 @@ def __init__(self, property_name, property_type, constraint): super(GreaterOrEqual, self).__init__(property_name, property_type, constraint) if not isinstance(self.constraint_value, self.valid_types): - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( InvalidSchemaError(message=_('The property ' '"greater_or_equal" expects ' 'comparable values.'))) diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterThan.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterThan.java index 2803bb4..d23d7ce 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterThan.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/GreaterThan.java @@ -3,6 +3,7 @@ package org.openecomp.sdc.toscaparser.api.elements.constraints; import java.util.Date; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class GreaterThan extends Constraint { @@ -34,7 +35,7 @@ public class GreaterThan extends Constraint { super(name,type,c); if(!validTypes.contains(constraintValue.getClass().getSimpleName())) { - ExceptionCollector.appendException("InvalidSchemaError: The property \"greater_than\" expects comparable values"); + ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"greater_than\" expects comparable values"); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/InRange.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/InRange.java index 6a5432c..282267d 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/InRange.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/InRange.java @@ -3,6 +3,7 @@ package org.openecomp.sdc.toscaparser.api.elements.constraints; import java.util.Date; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; import java.util.ArrayList; @@ -45,7 +46,7 @@ public class InRange extends Constraint { super(name,type,c); if(!(constraintValue instanceof ArrayList) || ((ArrayList<Object>)constraintValue).size() != 2) { - ExceptionCollector.appendException("InvalidSchemaError: The property \"in_range\" expects a list"); + ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"in_range\" expects a list"); } @@ -53,11 +54,11 @@ public class InRange extends Constraint { String msg = "The property \"in_range\" expects comparable values"; for(Object vo: alcv) { if(!validTypes.contains(vo.getClass().getSimpleName())) { - ExceptionCollector.appendException("InvalidSchemaError: " + msg); + ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: " + msg); } // The only string we allow for range is the special value 'UNBOUNDED' if((vo instanceof String) && !((String)vo).equals(UNBOUNDED)) { - ExceptionCollector.appendException("InvalidSchemaError: " + msg); + ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: " + msg); } } min = alcv.get(0); diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Length.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Length.java index 939cb2a..4cfd1c0 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Length.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Length.java @@ -1,6 +1,7 @@ package org.openecomp.sdc.toscaparser.api.elements.constraints; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class Length extends Constraint { // Constraint class for "length" @@ -22,7 +23,7 @@ public class Length extends Constraint { super(name,type,c); if(!validTypes.contains(constraintValue.getClass().getSimpleName())) { - ExceptionCollector.appendException("InvalidSchemaError: The property \"length\" expects an integer"); + ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"length\" expects an integer"); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessOrEqual.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessOrEqual.java index f7778b6..00cba36 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessOrEqual.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessOrEqual.java @@ -3,6 +3,7 @@ package org.openecomp.sdc.toscaparser.api.elements.constraints; import java.util.Date; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class LessOrEqual extends Constraint { // Constraint class for "less_or_equal" @@ -36,7 +37,7 @@ public class LessOrEqual extends Constraint { super(name,type,c); if(!validTypes.contains(constraintValue.getClass().getSimpleName())) { - ExceptionCollector.appendException("InvalidSchemaError: The property \"less_or_equal\" expects comparable values"); + ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"less_or_equal\" expects comparable values"); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessThan.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessThan.java index 2432e82..eb5a41d 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessThan.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/LessThan.java @@ -3,6 +3,7 @@ package org.openecomp.sdc.toscaparser.api.elements.constraints; import java.util.Date; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class LessThan extends Constraint { @@ -34,7 +35,7 @@ public class LessThan extends Constraint { super(name,type,c); if(!validTypes.contains(constraintValue.getClass().getSimpleName())) { - ExceptionCollector.appendException("InvalidSchemaError: The property \"less_than\" expects comparable values"); + ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"less_than\" expects comparable values"); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MaxLength.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MaxLength.java index d50fd1a..278ae85 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MaxLength.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MaxLength.java @@ -3,6 +3,7 @@ package org.openecomp.sdc.toscaparser.api.elements.constraints; import java.util.LinkedHashMap; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class MaxLength extends Constraint { // Constraint class for "min_length" @@ -25,7 +26,7 @@ public class MaxLength extends Constraint { super(name,type,c); if(!validTypes.contains(constraintValue.getClass().getSimpleName())) { - ExceptionCollector.appendException("InvalidSchemaError: The property \"max_length\" expects an integer"); + ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"max_length\" expects an integer"); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MinLength.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MinLength.java index 50fe7a1..480c878 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MinLength.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/MinLength.java @@ -3,6 +3,7 @@ package org.openecomp.sdc.toscaparser.api.elements.constraints; import java.util.LinkedHashMap; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class MinLength extends Constraint { // Constraint class for "min_length" @@ -25,7 +26,7 @@ public class MinLength extends Constraint { super(name,type,c); if(!validTypes.contains(constraintValue.getClass().getSimpleName())) { - ExceptionCollector.appendException("InvalidSchemaError: The property \"min_length\" expects an integer"); + ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"min_length\" expects an integer"); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Pattern.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Pattern.java index 2fa5a2f..444a73c 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Pattern.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Pattern.java @@ -4,6 +4,7 @@ import java.util.regex.Matcher; import java.util.regex.PatternSyntaxException; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class Pattern extends Constraint { @@ -23,7 +24,7 @@ public class Pattern extends Constraint { super(name,type,c); if(!validTypes.contains(constraintValue.getClass().getSimpleName())) { - ExceptionCollector.appendException("InvalidSchemaError: The property \"pattern\" expects a string"); + ThreadLocalsHolder.getCollector().appendException("InvalidSchemaError: The property \"pattern\" expects a string"); } } @@ -31,7 +32,7 @@ public class Pattern extends Constraint { protected boolean _isValid(Object value) { try { if(!(value instanceof String)) { - ExceptionCollector.appendException(String.format("ValueError: Input value \"%s\" to \"pattern\" property \"%s\" must be a string", + ThreadLocalsHolder.getCollector().appendException(String.format("ValueError: Input value \"%s\" to \"pattern\" property \"%s\" must be a string", value.toString(),propertyName)); return false; } @@ -45,7 +46,7 @@ public class Pattern extends Constraint { return false; } catch(PatternSyntaxException pse) { - ExceptionCollector.appendException(String.format("ValueError: Invalid regex \"%s\" in \"pattern\" property \"%s\"", + ThreadLocalsHolder.getCollector().appendException(String.format("ValueError: Invalid regex \"%s\" in \"pattern\" property \"%s\"", constraintValue.toString(),propertyName)); return false; } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java index eb4b6ce..ca721e6 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/elements/constraints/Schema.java @@ -6,6 +6,7 @@ import java.util.LinkedHashMap; import java.util.Map; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class Schema { @@ -70,14 +71,14 @@ public class Schema { if(!(_schemaDict instanceof LinkedHashMap)) { //msg = (_('Schema definition of "%(pname)s" must be a dict.') // % dict(pname=name)) - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidSchemaError: Schema definition of \"%s\" must be a dict",name)); } if(_schemaDict.get("type") == null) { //msg = (_('Schema definition of "%(pname)s" must have a "type" ' // 'attribute.') % dict(pname=name)) - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidSchemaError: Schema definition of \"%s\" must have a \"type\" attribute",name)); } @@ -121,7 +122,7 @@ public class Schema { } else { // error - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Constraint type \"%s\" for property \"%s\" is not supported", cClass,name)); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Concat.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Concat.java index 9f29dd2..6dc7deb 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Concat.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Concat.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import org.openecomp.sdc.toscaparser.api.TopologyTemplate; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class Concat extends Function { // Validate the function and provide an instance of the function @@ -36,7 +37,7 @@ public class Concat extends Function { @Override void validate() { if(args.size() < 1) { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "ValueError: Invalid arguments for function \"concat\". " + "Expected at least one argument"); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetAttribute.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetAttribute.java index 5536dc5..549073b 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetAttribute.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetAttribute.java @@ -3,11 +3,7 @@ package org.openecomp.sdc.toscaparser.api.functions; import java.util.ArrayList; import java.util.LinkedHashMap; -import org.openecomp.sdc.toscaparser.api.Capability; -import org.openecomp.sdc.toscaparser.api.EntityTemplate; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.openecomp.sdc.toscaparser.api.RelationshipTemplate; -import org.openecomp.sdc.toscaparser.api.TopologyTemplate; +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; @@ -18,6 +14,7 @@ import org.openecomp.sdc.toscaparser.api.elements.PropertyDef; import org.openecomp.sdc.toscaparser.api.elements.RelationshipType; import org.openecomp.sdc.toscaparser.api.elements.StatefulEntityType; import org.openecomp.sdc.toscaparser.api.elements.constraints.Schema; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class GetAttribute extends Function { // Get an attribute value of an entity defined in the service template @@ -49,7 +46,7 @@ public class GetAttribute extends Function { @Override void validate() { if(args.size() < 2) { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "ValueError: Illegal arguments for function \"get_attribute\". Expected arguments: \"node-template-name\", \"req-or-cap\" (optional), \"property name.\""); return; } @@ -80,7 +77,7 @@ public class GetAttribute extends Function { for(Object elem: args.subList(index,args.size())) { if(valueType.equals("list")) { if(!(elem instanceof Integer)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: Illegal arguments for function \"get_attribute\" \"%s\". Expected positive integer argument", elem.toString())); } @@ -102,7 +99,7 @@ public class GetAttribute extends Function { } } if(bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: 'Illegal arguments for function \"get_attribute\". Unexpected attribute/index value \"%d\"", elem)); return; @@ -116,7 +113,7 @@ public class GetAttribute extends Function { valueType = (String)prop.getSchema().get("type"); } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Illegal arguments for function \"get_attribute\". Attribute name \"%s\" not found in \"%\"", elem,valueType)); } @@ -150,7 +147,7 @@ public class GetAttribute extends Function { if(nodeTpl != null && !_attributeExistsInType(nodeTpl.getTypeDefinition()) && !nodeTpl.getProperties().keySet().contains(getAttributeName())) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Attribute \"%s\" was not found in node template \"%s\"", getAttributeName(),nodeTpl.getName())); } @@ -196,13 +193,13 @@ public class GetAttribute extends Function { // Currently this is the only way to tell whether the function // is used within the outputs section of the TOSCA template. if(context instanceof ArrayList) { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "ValueError: \"get_attribute: [ HOST, ... ]\" is not allowed in \"outputs\" section of the TOSCA template"); return null; } NodeTemplate nodeTpl = _findHostContainingAttribute(SELF); if(nodeTpl == null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: \"get_attribute: [ HOST, ... ]\" was used in " + "node template \"%s\" but \"%s\" was not found in " + "the relationship chain",((NodeTemplate)context).getName(),HOSTED_ON)); @@ -212,7 +209,7 @@ public class GetAttribute extends Function { } if(nodeTemplateName.equals(TARGET)) { if(!(((EntityTemplate)context).getTypeDefinition() instanceof RelationshipType)) { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "KeyError: \"TARGET\" keyword can only be used in context " + " to \"Relationships\" target node"); return null; @@ -221,7 +218,7 @@ public class GetAttribute extends Function { } if(nodeTemplateName.equals(SOURCE)) { if(!(((EntityTemplate)context).getTypeDefinition() instanceof RelationshipType)) { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "KeyError: \"SOURCE\" keyword can only be used in context " + " to \"Relationships\" source node"); return null; @@ -240,7 +237,7 @@ public class GetAttribute extends Function { return nt; } } - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Node template \"%s\" was not found",nodeTemplateName)); return null; } @@ -279,7 +276,7 @@ public class GetAttribute extends Function { attribute = attrs.get(attrName); } if(attribute == null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Attribute \"%s\" was not found in capability \"%s\" of node template \"%s\" referenced from node template \"%s\"", attrName,capabilityName,nodeTemplate.getName(),((NodeTemplate)context).getName())); } @@ -288,7 +285,7 @@ public class GetAttribute extends Function { String msg = String.format( "Requirement/Capability \"%s\" referenced from node template \"%s\" was not found in node template \"%s\"", capabilityName,((NodeTemplate)context).getName(),nodeTemplate.getName()); - ExceptionCollector.appendException("KeyError: " + msg); + ThreadLocalsHolder.getCollector().appendException("KeyError: " + msg); return null; } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetInput.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetInput.java index df32699..4332f70 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetInput.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetInput.java @@ -7,6 +7,7 @@ import org.openecomp.sdc.toscaparser.api.DataEntity; import org.openecomp.sdc.toscaparser.api.TopologyTemplate; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.parameters.Input; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class GetInput extends Function { @@ -18,8 +19,8 @@ public class GetInput extends Function { @Override void validate() { if(args.size() != 1) { - //ERROR under investigation - ExceptionCollector.appendWarning(String.format( + //PA - changed to WARNING from CRITICAL after talking to Renana, 22/05/2017 + ThreadLocalsHolder.getCollector().appendWarning(String.format( "ValueError: Expected one argument for function \"get_input\" but received \"%s\"", args.toString())); } @@ -31,7 +32,7 @@ public class GetInput extends Function { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownInputError: Unknown input \"%s\"",args.get(0))); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetOperationOutput.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetOperationOutput.java index f2231a1..22f2cd7 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetOperationOutput.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetOperationOutput.java @@ -2,14 +2,12 @@ package org.openecomp.sdc.toscaparser.api.functions; import java.util.ArrayList; -import org.openecomp.sdc.toscaparser.api.EntityTemplate; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.openecomp.sdc.toscaparser.api.RelationshipTemplate; -import org.openecomp.sdc.toscaparser.api.TopologyTemplate; +import org.openecomp.sdc.toscaparser.api.*; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.elements.InterfacesDef; import org.openecomp.sdc.toscaparser.api.elements.RelationshipType; import org.openecomp.sdc.toscaparser.api.elements.StatefulEntityType; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class GetOperationOutput extends Function { @@ -25,7 +23,7 @@ public class GetOperationOutput extends Function { _findOperationName(interfaceName,(String)args.get(2)); } else { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "ValueError: Illegal arguments for function \"get_operation_output\". " + "Expected arguments: \"template_name\",\"interface_name\"," + "\"operation_name\",\"output_variable_name\""); @@ -44,7 +42,7 @@ public class GetOperationOutput extends Function { return _interfaceName; } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: invalid interface name \"%s\" in \"get_operation_output\"", _interfaceName)); return null; @@ -66,7 +64,7 @@ public class GetOperationOutput extends Function { return operationName; } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: Invalid operation of Configure interface \"%s\" in \"get_operation_output\"", operationName)); return null; @@ -85,14 +83,14 @@ public class GetOperationOutput extends Function { return operationName; } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: Invalid operation of Configure interface \"%s\" in \"get_operation_output\"", operationName)); return null; } } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: Invalid interface name \"%s\" in \"get_operation_output\"", interfaceName)); return null; @@ -102,7 +100,7 @@ public class GetOperationOutput extends Function { private NodeTemplate _findNodeTemplate(String nodeTemplateName) { if(nodeTemplateName.equals(TARGET)) { if(!(((EntityTemplate)context).getTypeDefinition() instanceof RelationshipType)) { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "KeyError: \"TARGET\" keyword can only be used in context " + " to \"Relationships\" target node"); return null; @@ -111,7 +109,7 @@ public class GetOperationOutput extends Function { } if(nodeTemplateName.equals(SOURCE)) { if(!(((EntityTemplate)context).getTypeDefinition() instanceof RelationshipType)) { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "KeyError: \"SOURCE\" keyword can only be used in context " + " to \"Relationships\" source node"); return null; @@ -130,7 +128,7 @@ public class GetOperationOutput extends Function { return nt; } } - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Node template \"%s\" was not found",nodeTemplateName)); return null; } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java index e55250c..3550542 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java @@ -3,11 +3,7 @@ package org.openecomp.sdc.toscaparser.api.functions; import java.util.ArrayList; import java.util.LinkedHashMap; -import org.openecomp.sdc.toscaparser.api.Capability; -import org.openecomp.sdc.toscaparser.api.NodeTemplate; -import org.openecomp.sdc.toscaparser.api.Property; -import org.openecomp.sdc.toscaparser.api.RelationshipTemplate; -import org.openecomp.sdc.toscaparser.api.TopologyTemplate; +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; @@ -15,6 +11,7 @@ import org.openecomp.sdc.toscaparser.api.elements.NodeType; import org.openecomp.sdc.toscaparser.api.elements.PropertyDef; import org.openecomp.sdc.toscaparser.api.elements.RelationshipType; import org.openecomp.sdc.toscaparser.api.elements.StatefulEntityType; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class GetProperty extends Function { // Get a property value of an entity defined in the same service template @@ -50,7 +47,7 @@ public class GetProperty extends Function { @Override void validate() { if(args.size() < 2) { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "ValueError: Illegal arguments for function \"get_property\". Expected arguments: \"node-template-name\", \"req-or-cap\" (optional), \"property name.\""); return; } @@ -139,14 +136,14 @@ public class GetProperty extends Function { property = ((Property)props.get(propertyName)).getValue(); } if(property == null && throwErrors) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Property \"%s\" was not found in capability \"%s\" of node template \"%s\" referenced from node template \"%s\"", propertyName,capabilityName,nodeTemplate.getName(),((NodeTemplate)context).getName())); } return property; } if(throwErrors) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Requirement/Capability \"%s\" referenced from node template \"%s\" was not found in node template \"%s\"", capabilityName,((NodeTemplate)context).getName(),nodeTemplate.getName())); } @@ -162,7 +159,7 @@ public class GetProperty extends Function { LinkedHashMap<String,Property> props = nodeTpl.getProperties(); Property found = props.get(propertyName); if(found == null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Property \"%s\" was not found in node template \"%s\"", propertyName,nodeTpl.getName())); } @@ -177,7 +174,7 @@ public class GetProperty extends Function { if(nodeTemplateName.equals(HOST)) { NodeTemplate node = _findHostContainingProperty(null); if(node == null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Property \"%s\" was not found in capability \"%s\" of node template \"%s\" referenced from node template \"%s\"", (String)args.get(2),(String)args.get(1),((NodeTemplate)context).getName())); return null; @@ -186,7 +183,7 @@ public class GetProperty extends Function { } if(nodeTemplateName.equals(TARGET)) { if(!(((RelationshipTemplate)context).getTypeDefinition() instanceof RelationshipType)) { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "KeyError: \"TARGET\" keyword can only be used in context to \"Relationships\" target node"); return null; } @@ -194,7 +191,7 @@ public class GetProperty extends Function { } if(nodeTemplateName.equals(SOURCE)) { if(!(((RelationshipTemplate)context).getTypeDefinition() instanceof RelationshipType)) { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "KeyError: \"SOURCE\" keyword can only be used in context to \"Relationships\" target node"); return null; } @@ -208,7 +205,7 @@ public class GetProperty extends Function { return nodeTemplate; } } - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Node template \"%s\" was not found. Referenced from Node Template \"%s\"", nodeTemplateName,((NodeTemplate)context).getName())); @@ -222,14 +219,14 @@ public class GetProperty extends Function { return ((ArrayList)value).get(index); } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Property \"%s\" found in capability \"%s\" referenced from node template \"%s\" must have an element with index %d", args.get(2),args.get(1),((NodeTemplate)context).getName(),index)); } } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Property \"%s\" found in capability \"%s\" referenced from node template \"%s\" must be a list", args.get(2),args.get(1),((NodeTemplate)context).getName())); } @@ -244,13 +241,13 @@ public class GetProperty extends Function { return ov; } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Property \"%s\" found in capability \"%s\" referenced from node template \"%s\" must have an attribute named \"%s\"", args.get(2),args.get(1),((NodeTemplate)context).getName(),attribute)); } } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "KeyError: Property \"%s\" found in capability \"%s\" referenced from node template \"%s\" must be a dict", args.get(2),args.get(1),((NodeTemplate)context).getName())); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Token.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Token.java index e282d8a..4438908 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Token.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions/Token.java @@ -6,6 +6,7 @@ import java.util.LinkedHashMap; import org.openecomp.sdc.toscaparser.api.NodeTemplate; import org.openecomp.sdc.toscaparser.api.TopologyTemplate; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class Token extends Function { // Validate the function and provide an instance of the function @@ -41,19 +42,19 @@ public class Token extends Function { @Override void validate() { if(args.size() < 3) { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "ValueError: Invalid arguments for function \"token\". " + "Expected at least three arguments"); } else { if(!(args.get(1) instanceof String) || ((String)args.get(1)).length() != 1) { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "ValueError: Invalid arguments for function \"token\". " + "Expected single char value as second argument"); } if(!(args.get(2) instanceof Integer)) { - ExceptionCollector.appendException( + ThreadLocalsHolder.getCollector().appendException( "ValueError: Invalid arguments for function \"token\"" + "Expected integer value as third argument"); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java index 96958ce..7b3e64f 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java @@ -9,6 +9,7 @@ import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.elements.EntityType; import org.openecomp.sdc.toscaparser.api.elements.constraints.Constraint; import org.openecomp.sdc.toscaparser.api.elements.constraints.Schema; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class Input { @@ -88,7 +89,7 @@ public class Input { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Input \"%s\" contains unknown field \"%s\"", name,key)); } @@ -111,7 +112,7 @@ public class Input { } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: Invalid type \"%s\"",inputType)); } } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Output.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Output.java index e987996..34ecf12 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Output.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Output.java @@ -3,6 +3,7 @@ package org.openecomp.sdc.toscaparser.api.parameters; import java.util.LinkedHashMap; import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; public class Output { @@ -33,13 +34,13 @@ public class Output { private void _validateField() { if(!(attrs instanceof LinkedHashMap)) { //TODO wrong error message... - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValidationError: Output \"%s\" has wrong type. Expecting a dict", name)); } if(getValue() == null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "MissingRequiredFieldError: Output \"%s\" is missing required \"%s\"", name,VALUE)); } @@ -52,7 +53,7 @@ public class Output { } } if(!bFound) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "UnknownFieldError: Output \"%s\" contains unknown field \"%s\"", name,key)); } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java index 2ab5d26..85b54ee 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/prereq/CSAR.java @@ -18,8 +18,9 @@ import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; import org.openecomp.sdc.toscaparser.api.ImportsLoader; -import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; -import org.openecomp.sdc.toscaparser.api.elements.Metadata; +import org.openecomp.sdc.toscaparser.api.common.JToscaException; +import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; import org.openecomp.sdc.toscaparser.api.utils.UrlUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,7 +53,7 @@ public class CSAR { } @SuppressWarnings("unchecked") - public boolean validate() { + public boolean validate() throws JToscaException { isValidated = true; //validate that the file or URL exists @@ -60,7 +61,7 @@ public class CSAR { if(isFile) { File f = new File(path); if (!f.isFile()) { - ExceptionCollector.appendException(String.format("\"%s\" is not a file", path)); + ThreadLocalsHolder.getCollector().appendException(String.format("\"%s\" is not a file", path)); return false; } else { @@ -69,7 +70,7 @@ public class CSAR { } else { if(!UrlUtils.validateUrl(path)) { - ExceptionCollector.appendException(String.format("ImportError: \"%s\" does not exist",path)); + ThreadLocalsHolder.getCollector().appendException(String.format("ImportError: \"%s\" does not exist",path)); return false; } // get it to a local file @@ -81,7 +82,7 @@ public class CSAR { Files.copy(in,ptf,StandardCopyOption.REPLACE_EXISTING); } catch(Exception e) { - ExceptionCollector.appendException("ImportError: failed to load CSAR from " + path); + ThreadLocalsHolder.getCollector().appendException("ImportError: failed to load CSAR from " + path); return false; } @@ -102,7 +103,7 @@ public class CSAR { } - private void _parseAndValidateMetaProperties() { + private void _parseAndValidateMetaProperties() throws JToscaException { ZipFile zf = null; @@ -114,16 +115,21 @@ public class CSAR { raf.close(); // check if Zip's magic number if (n != 0x504B0304) { - throw new IOException(String.format("\"%s\" is not a valid zip file", csar)); + String errorString = String.format("\"%s\" is not a valid zip file", csar); + log.error(errorString); + throw new JToscaException(errorString , JToscaErrorCodes.INVALID_CSAR_FORMAT.getValue()); } // validate that it contains the metadata file in the correct location zf = new ZipFile(csar); ZipEntry ze = zf.getEntry("TOSCA-Metadata/TOSCA.meta"); if (ze == null) { - throw new IOException(String.format( + + String errorString = String.format( "\"%s\" is not a valid CSAR as it does not contain the " + - "required file \"TOSCA.meta\" in the folder \"TOSCA-Metadata\"", csar)); + "required file \"TOSCA.meta\" in the folder \"TOSCA-Metadata\"", csar); + log.error(errorString); + throw new JToscaException(errorString, JToscaErrorCodes.MISSING_META_FILE.getValue()); } //Going over expected metadata files and parsing them @@ -134,22 +140,31 @@ public class CSAR { if (ze != null) { InputStream inputStream = zf.getInputStream(ze); n = inputStream.read(ba, 0, 4096); - String md = new String(ba); md = md.substring(0, (int) n); - Yaml yaml = new Yaml(); - Object mdo = yaml.load(md); - if (!(mdo instanceof LinkedHashMap)) { - throw new IOException(String.format( - "The file \"%s\" in the" + - " CSAR \"%s\" does not contain valid YAML content", ze.getName(), csar)); + + String errorString = String.format( + "The file \"%s\" in the" + + " CSAR \"%s\" does not contain valid YAML content", ze.getName(), csar); + + try { + Yaml yaml = new Yaml(); + Object mdo = yaml.load(md); + if (!(mdo instanceof LinkedHashMap)) { + log.error(errorString); + throw new JToscaException(errorString, JToscaErrorCodes.INVALID_META_YAML_CONTENT.getValue()); + } + + String[] split = ze.getName().split("/"); + String fileName = split[split.length - 1]; + + if (!metaProperties.containsKey(fileName)) { + metaProperties.put(fileName, (LinkedHashMap<String, Object>) mdo); + } } - - String[] split = ze.getName().split("/"); - String fileName = split[split.length - 1]; - - if (!metaProperties.containsKey(fileName)) { - metaProperties.put(fileName, (LinkedHashMap<String, Object>) mdo); + catch(Exception e) { + log.error(errorString); + throw new JToscaException(errorString, JToscaErrorCodes.INVALID_META_YAML_CONTENT.getValue()); } } } @@ -157,9 +172,11 @@ public class CSAR { // verify it has "Entry-Definition" String edf = _getMetadata("Entry-Definitions"); if (edf == null) { - throw new IOException(String.format( + String errorString = String.format( "The CSAR \"%s\" is missing the required metadata " + - "\"Entry-Definitions\" in \"TOSCA-Metadata/TOSCA.meta\"", csar)); + "\"Entry-Definitions\" in \"TOSCA-Metadata/TOSCA.meta\"", csar); + log.error(errorString); + throw new JToscaException(errorString, JToscaErrorCodes.ENTRY_DEFINITION_NOT_DEFINED.getValue()); } //validate that "Entry-Definitions' metadata value points to an existing file in the CSAR @@ -173,11 +190,16 @@ public class CSAR { } } if (!foundEDF) { - throw new IOException(String.format( - "The \"Entry-Definitions\" file defined in the CSAR \"%s\" does not exist", csar)); + String errorString = String.format( + "The \"Entry-Definitions\" file defined in the CSAR \"%s\" does not exist", csar); + log.error(errorString); + throw new JToscaException(errorString, JToscaErrorCodes.MISSING_ENTRY_DEFINITION_FILE.getValue()); } + } catch (JToscaException e) { + //ThreadLocalsHolder.getCollector().appendCriticalException(e.getMessage()); + throw e; } catch (Exception e) { - ExceptionCollector.appendException("ValidationError: " + e.getMessage()); + ThreadLocalsHolder.getCollector().appendException("ValidationError: " + e.getMessage()); errorCaught = true; } @@ -199,7 +221,7 @@ public class CSAR { } } - private String _getMetadata(String key) { + private String _getMetadata(String key) throws JToscaException { if(!isValidated) { validate(); } @@ -207,11 +229,11 @@ public class CSAR { return value != null ? value.toString() : null; } - public String getAuthor() { + public String getAuthor() throws JToscaException { return _getMetadata("Created-By"); } - public String getVersion() { + public String getVersion() throws JToscaException { return _getMetadata("CSAR-Version"); } @@ -223,7 +245,7 @@ public class CSAR { return metaProperties.get(propertiesFile); } - public String getMainTemplate() { + public String getMainTemplate() throws JToscaException { String entryDef = _getMetadata("Entry-Definitions"); ZipFile zf; boolean ok = false; @@ -246,7 +268,7 @@ public class CSAR { } @SuppressWarnings("unchecked") - public LinkedHashMap<String,Object> getMainTemplateYaml() { + public LinkedHashMap<String,Object> getMainTemplateYaml() throws JToscaException { String mainTemplate = tempDir + File.separator + getMainTemplate(); if(mainTemplate != null) { try { @@ -259,7 +281,7 @@ public class CSAR { return (LinkedHashMap<String,Object>)data; } catch(Exception e) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "The file \"%s\" in the CSAR \"%s\" does not " + "contain valid TOSCA YAML content", mainTemplate,csar)); @@ -268,7 +290,7 @@ public class CSAR { return null; } - public String getDescription() { + public String getDescription() throws JToscaException { String desc = _getMetadata("Description"); if(desc != null) { return desc; @@ -283,7 +305,7 @@ public class CSAR { return tempDir; } - public void decompress() throws IOException { + public void decompress() throws IOException, JToscaException { if(!isValidated) { validate(); } @@ -292,7 +314,7 @@ public class CSAR { } - private void _validateExternalReferences() { + private void _validateExternalReferences() throws JToscaException { // Extracts files referenced in the main template // These references are currently supported: // * imports @@ -339,7 +361,7 @@ public class CSAR { } } else { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: Unexpected artifact definition for \"%s\"", artifactKey)); errorCaught = true; @@ -407,12 +429,12 @@ public class CSAR { return; } else { - ExceptionCollector.appendException(msg); + ThreadLocalsHolder.getCollector().appendException(msg); errorCaught = true; } } catch (Exception e) { - ExceptionCollector.appendException(msg); + ThreadLocalsHolder.getCollector().appendException(msg); } } @@ -424,7 +446,7 @@ public class CSAR { } if(raiseExc) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: The resource \"%s\" does not exist",resourceFile)); } errorCaught = true; diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/JToscaErrorCodes.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/JToscaErrorCodes.java new file mode 100644 index 0000000..354fef0 --- /dev/null +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/JToscaErrorCodes.java @@ -0,0 +1,32 @@ +package org.openecomp.sdc.toscaparser.api.utils; + + +public enum JToscaErrorCodes { + MISSING_META_FILE("JT1001"), + INVALID_META_YAML_CONTENT("JT1002"), + ENTRY_DEFINITION_NOT_DEFINED("JT1003"), + MISSING_ENTRY_DEFINITION_FILE ("JT1004"), + GENERAL_ERROR("JT1005"), + PATH_NOT_VALID("JT1006"), + CSAR_TOSCA_VALIDATION_ERROR("JT1007"), + INVALID_CSAR_FORMAT("JT1008"); + + private String value; + + private JToscaErrorCodes(String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static JToscaErrorCodes getByCode(String code) { + for(JToscaErrorCodes v : values()){ + if( v.getValue().equals(code)){ + return v; + } + } + return null; + } +}
\ No newline at end of file diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/TOSCAVersionProperty.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/TOSCAVersionProperty.java index 7c6b62f..6b3c1ce 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/TOSCAVersionProperty.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/TOSCAVersionProperty.java @@ -35,7 +35,7 @@ public class TOSCAVersionProperty {// test with functions/test_concat.yaml Pattern pattern = Pattern.compile(versionRe); Matcher matcher = pattern.matcher(version); if(!matcher.find()) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidTOSCAVersionPropertyException: " + "Value of TOSCA version property \"%s\" is invalid", version)); @@ -77,7 +77,7 @@ public class TOSCAVersionProperty {// test with functions/test_concat.yaml if((fixVersion == null && value != null) || (minorVersion.equals("0") && majorVersion.equals("0") && fixVersion.equals("0") && value != null)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidTOSCAVersionPropertyException: " + "Value of TOSCA version property \"%s\" is invalid", version)); @@ -92,7 +92,7 @@ public class TOSCAVersionProperty {// test with functions/test_concat.yaml // Eg: version = 18.0.0-1 is invalid. if(qualifier == null && value != null) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "InvalidTOSCAVersionPropertyException: " + "Value of TOSCA version property \"%s\" is invalid", version)); diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ThreadLocalsHolder.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ThreadLocalsHolder.java new file mode 100644 index 0000000..47ba972 --- /dev/null +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ThreadLocalsHolder.java @@ -0,0 +1,24 @@ +package org.openecomp.sdc.toscaparser.api.utils; + +import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; + +public class ThreadLocalsHolder { + + private static final ThreadLocal<ExceptionCollector> exceptionCollectorThreadLocal = new ThreadLocal<>(); + + private ThreadLocalsHolder(){} + + public static ExceptionCollector getCollector() { + return exceptionCollectorThreadLocal.get(); + } + + public static void setCollector(ExceptionCollector exceptionCollector) { + cleanup(); + exceptionCollectorThreadLocal.set(exceptionCollector); + } + + public static void cleanup(){ + exceptionCollectorThreadLocal.remove(); + } + +} diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/UrlUtils.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/UrlUtils.java index 0aadcfe..092f827 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/UrlUtils.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/UrlUtils.java @@ -34,7 +34,7 @@ public class UrlUtils { // relative_path: heat-translator // - joined: http://www.githib.com/openstack/heat-translator if(!validateUrl(sUrl)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: The URL \"%s\" is malformed",sUrl)); } try { @@ -42,7 +42,7 @@ public class UrlUtils { return (new URL(base,relativePath)).toString(); } catch(MalformedURLException e) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: Joining URL \"%s\" and relative path \"%s\" caused an exception",sUrl,relativePath)); return sUrl; } diff --git a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ValidateUtils.java b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ValidateUtils.java index 675ab16..291316f 100644 --- a/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ValidateUtils.java +++ b/jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/utils/ValidateUtils.java @@ -34,7 +34,7 @@ public class ValidateUtils { public static Object validateNumeric(Object value) { if(!(value instanceof Number)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: \"%s\" is not a numeric",value.toString())); } return value; @@ -46,7 +46,7 @@ public class ValidateUtils { if(value instanceof Boolean) { return (Boolean)value ? 1 : 0; } - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: \"%s\" is not an integer",value.toString())); } return value; @@ -54,7 +54,7 @@ public class ValidateUtils { public static Object validateFloat(Object value) { if(!(value instanceof Float || value instanceof Double)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: \"%s\" is not a float",value.toString())); } return value; @@ -62,7 +62,7 @@ public class ValidateUtils { public static Object validateString(Object value) { if(!(value instanceof String)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: \'%s\' is not a string",value.toString())); } return value; @@ -70,7 +70,7 @@ public class ValidateUtils { public static Object validateList(Object value) { if(!(value instanceof ArrayList)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: \"%s\" is not a list",value.toString())); } return value; @@ -83,7 +83,7 @@ public class ValidateUtils { validateList(range); // validate range list has a min and max if(range instanceof ArrayList && ((ArrayList<Object>)range).size() != 2) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: \"%s\" is not a valid range",range.toString())); // too dangerous to continue... return range; @@ -96,7 +96,7 @@ public class ValidateUtils { if(!(r0 instanceof Integer) && !(r0 instanceof Float) || !(r1 instanceof Integer) && !(r1 instanceof Float)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: \"%s\" is not a valid range",range.toString())); // too dangerous to continue... return range; @@ -121,7 +121,7 @@ public class ValidateUtils { if(!minTest && !maxTest) { // Note: min == max is allowed if(min > max) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError:\"%s\" is not a valid range",range.toString())); } } @@ -132,7 +132,7 @@ public class ValidateUtils { public static Object validateValueInRange(Object value,Object range,String propName) { // verify all 3 are numeric and convert to Floats if(!(value instanceof Integer || value instanceof Float)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: validateInRange: \"%s\" is not a number",range.toString())); return value; } @@ -144,7 +144,7 @@ public class ValidateUtils { // better safe than sorry... // validate that range list has a min and max if(range instanceof ArrayList && ((ArrayList<Object>)range).size() != 2) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: \"%s\" is not a valid range",range.toString())); // too dangerous to continue... return value; @@ -157,7 +157,7 @@ public class ValidateUtils { if(!(r0 instanceof Integer) && !(r0 instanceof Float) || !(r1 instanceof Integer) && !(r1 instanceof Float)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: \"%s\" is not a valid range",range.toString())); // too dangerous to continue... return value; @@ -182,7 +182,7 @@ public class ValidateUtils { if(!minTest && !maxTest) { // Note: min == max is allowed if(min > max) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError:\"%s\" is not a valid range",range.toString())); } } @@ -201,7 +201,7 @@ public class ValidateUtils { } } if(bError) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "RangeValueError: Property \"%s\", \"%s\" not in range [\"%s\" - \"%s\"", propName,value.toString(),r0.toString(),r1.toString())); } @@ -210,7 +210,7 @@ public class ValidateUtils { public static Object validateMap(Object ob) { if(!(ob instanceof LinkedHashMap)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError\"%s\" is not a map.",ob.toString())); } return ob; @@ -226,7 +226,7 @@ public class ValidateUtils { return normalized.equals("true"); } } - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: \"%s\" is not a boolean",value.toString())); return value; } @@ -249,7 +249,7 @@ public class ValidateUtils { // timestamps are loaded as Date objects by the YAML parser if(!(value instanceof Date)) { - ExceptionCollector.appendException(String.format( + ThreadLocalsHolder.getCollector().appendException(String.format( "ValueError: \"%s\" is not a valid timestamp", value.toString())); diff --git a/jtosca/src/test/resources/csars/service-ServiceFdnt-csar.csar b/jtosca/src/test/resources/csars/service-ServiceFdnt-csar.csar Binary files differnew file mode 100644 index 0000000..983dc9b --- /dev/null +++ b/jtosca/src/test/resources/csars/service-ServiceFdnt-csar.csar @@ -4,7 +4,7 @@ <groupId>org.openecomp.sdc.sdc-distribution-client</groupId> <artifactId>sdc-main-distribution-client</artifactId> - <version>1.1.13-SNAPSHOT</version> + <version>1.1.14-SNAPSHOT</version> <packaging>pom</packaging> <modules> diff --git a/sdc-distribution-ci/pom.xml b/sdc-distribution-ci/pom.xml index 68cbd9c..6a6b80f 100644 --- a/sdc-distribution-ci/pom.xml +++ b/sdc-distribution-ci/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.openecomp.sdc.sdc-distribution-client</groupId> <artifactId>sdc-main-distribution-client</artifactId> - <version>1.1.13-SNAPSHOT</version> + <version>1.1.14-SNAPSHOT</version> </parent> <artifactId>sdc-distribution-ci</artifactId> diff --git a/sdc-distribution-ci/src/main/java/org/openecomp/test/CsarToscaTester.java b/sdc-distribution-ci/src/main/java/org/openecomp/test/CsarToscaTester.java index b07de08..08688fa 100644 --- a/sdc-distribution-ci/src/main/java/org/openecomp/test/CsarToscaTester.java +++ b/sdc-distribution-ci/src/main/java/org/openecomp/test/CsarToscaTester.java @@ -8,80 +8,66 @@ import java.util.Arrays; import java.util.Date;
import java.util.List;
-import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames;
import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory;
-import org.openecomp.sdc.toscaparser.api.NodeTemplate;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
-import org.openecomp.sdc.toscaparser.api.parameters.Input;
+import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
public class CsarToscaTester {
public static void main(String[] args) throws Exception {
- ClassLoader loader = CsarToscaTester.class.getClassLoader();
System.out.println("CsarToscaParser - path to CSAR's Directory is " + Arrays.toString(args));
SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
-
- File folder = new File(args[0].toString());
+
+ File folder = new File(args[0]);
File[] listOfFiles = folder.listFiles();
- FileWriter fw;
-
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("d-MM-y-HH_mm_ss");
String time = dateFormat.format(now);
- String csarsDir = args[1].toString() + "/csar-reports-" + time;
+ String csarsDir = args[1] + "/csar-reports-" + time;
File dir = new File(csarsDir);
dir.mkdir();
-
-
+
+
for (File file : listOfFiles) {
if (file.isFile()) {
- System.out.println("File " + file.getAbsolutePath());
- ExceptionCollector.clear();
- String name = file.getName();
- String currentCsarDir = csarsDir+"/"+name+"-"+time;
+ System.out.println("File " + file.getAbsolutePath());
+ String name = file.getName();
+ String currentCsarDir = csarsDir+"/"+name+"-"+time;
dir = new File(currentCsarDir);
dir.mkdir();
- ISdcCsarHelper csarHelper = factory.getSdcCsarHelper(file.getAbsolutePath());
- List<NodeTemplate> vflist = csarHelper.getServiceVfList();
- List<Input> inputs = csarHelper.getServiceInputs();
- List<String> exceptionReport = ExceptionCollector.getCriticalsReport();
- //System.out.println("CRITICALS during CSAR parsing are: " + (exceptionReport != null ? exceptionReport.toString() : "none"));
- List<String> warningsReport = ExceptionCollector.getWarningsReport();
- //System.out.println("WARNINGS during CSAR parsing are: " + (warningsReport != null ? warningsReport.toString() : "none"));
-
-
-
- if (!exceptionReport.isEmpty()) {
-
- try {
- fw = new FileWriter(new File(currentCsarDir + "/" + exceptionReport.size() / 2 + "-critical-" + name +"-"+time + ".txt"));
- for (String exception : exceptionReport) {
- fw.write(exception);
- fw.write("\r\n");
- }
- fw.close();
-
- fw = new FileWriter(new File(currentCsarDir + "/" + warningsReport.size() / 2 + "-warning-" + name +"-"+time + ".txt"));
- for (String warning : warningsReport) {
- fw.write(warning);
- fw.write("\r\n");
- }
- fw.close();
-
-
- //TODO
- fw = new FileWriter(new File(currentCsarDir + "/" + exceptionReport.size() / 2 + "-critical-" + name +"-"+time + ".txt"));
- for (String critical : exceptionReport) {
- fw.write(critical);
- fw.write("\r\n");
- }
- fw.close();
-
- } catch (IOException ex) {
- ex.printStackTrace();
- }
+ try {
+ factory.getSdcCsarHelper(file.getAbsolutePath());
+ } catch (SdcToscaParserException e){
+ System.out.println("SdcToscaParserException caught. Code: "+e.getCode()+", message: "+ e.getMessage());
}
- }
-
+ List<String> notAnalyzedReport = ThreadLocalsHolder.getCollector().getNotAnalyzedExceptionsReport();
+ System.out.println("NOT ANALYZED during CSAR parsing are: " + (notAnalyzedReport != null ? notAnalyzedReport.toString() : "none"));
+ List<String> warningsReport = ThreadLocalsHolder.getCollector().getWarningsReport();
+ //System.out.println("WARNINGS during CSAR parsing are: " + (warningsReport != null ? warningsReport.toString() : "none"));
+ List<String> criticalsReport = ThreadLocalsHolder.getCollector().getCriticalsReport();
+ System.out.println("CRITICALS during CSAR parsing are: " + (criticalsReport != null ? criticalsReport.toString() : "none"));
+
+ try {
+ generateReport(time, name, currentCsarDir, criticalsReport, "critical");
+ generateReport(time, name, currentCsarDir, warningsReport, "warning");
+ generateReport(time, name, currentCsarDir, notAnalyzedReport, "notAnalyzed");
+
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+
}
}
+
+ private static void generateReport(String time, String name, String currentCsarDir, List<String> criticalsReport, String type)
+ throws IOException {
+ FileWriter fw;
+ fw = new FileWriter(new File(currentCsarDir + "/" + criticalsReport.size() + "-"+type+"-" + name +"-"+time + ".txt"));
+ for (String exception : criticalsReport) {
+ fw.write(exception);
+ fw.write("\r\n");
+ }
+ fw.close();
+ }
}
diff --git a/sdc-distribution-client/pom.xml b/sdc-distribution-client/pom.xml index 2047ff3..9681dd6 100644 --- a/sdc-distribution-client/pom.xml +++ b/sdc-distribution-client/pom.xml @@ -6,7 +6,7 @@ <parent> <groupId>org.openecomp.sdc.sdc-distribution-client</groupId> <artifactId>sdc-main-distribution-client</artifactId> - <version>1.1.13-SNAPSHOT</version> + <version>1.1.14-SNAPSHOT</version> </parent> <artifactId>sdc-distribution-client</artifactId> diff --git a/sdc-distribution-client/src/main/java/org/openecomp/sdc/http/HttpAsdcClient.java b/sdc-distribution-client/src/main/java/org/openecomp/sdc/http/HttpAsdcClient.java index 6eb2ebd..7ace38f 100644 --- a/sdc-distribution-client/src/main/java/org/openecomp/sdc/http/HttpAsdcClient.java +++ b/sdc-distribution-client/src/main/java/org/openecomp/sdc/http/HttpAsdcClient.java @@ -70,7 +70,7 @@ public class HttpAsdcClient implements IHttpAsdcClient { private static final String TLS = "TLSv1.2"; private static final String AUTHORIZATION_HEADER = "Authorization"; private static final String HTTPS = "https://"; - private static Logger log = LoggerFactory.getLogger(DistributionClientImpl.class.getName()); + private static Logger log = LoggerFactory.getLogger(HttpAsdcClient.class.getName()); private CloseableHttpClient httpClient = null; private String serverFqdn = null; private String authHeaderValue = ""; diff --git a/sdc-tosca-parser/pom.xml b/sdc-tosca-parser/pom.xml index d6b0bb8..c56b471 100644 --- a/sdc-tosca-parser/pom.xml +++ b/sdc-tosca-parser/pom.xml @@ -6,7 +6,7 @@ <parent>
<groupId>org.openecomp.sdc.sdc-distribution-client</groupId>
<artifactId>sdc-main-distribution-client</artifactId>
- <version>1.1.13-SNAPSHOT</version>
+ <version>1.1.14-SNAPSHOT</version>
</parent>
<artifactId>sdc-tosca-parser</artifactId>
@@ -78,7 +78,7 @@ <dependency>
<groupId>org.openecomp.sdc.sdc-distribution-client</groupId>
<artifactId>jtosca</artifactId>
- <version>0.1.6-SNAPSHOT</version>
+ <version>0.1.7-SNAPSHOT</version>
</dependency>
diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java index 7cd9ed2..e83e6aa 100644 --- a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java +++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ConfigurationManager.java @@ -8,18 +8,44 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.net.URL; +import java.util.HashMap; +import java.util.Map; + public class ConfigurationManager { private static Logger log = LoggerFactory.getLogger(ConfigurationManager.class.getName()); - private static final String CONFIGURATION_FILE = "config/configuration.yaml"; + private static final String CONFIGURATION_DIR = "config/"; private static volatile ConfigurationManager instance; - private Configuration configuration; +// private Configuration configuration; +// private ErrorConfiguration errorConfiguration; + + Map<String, Object> configurations = new HashMap<String, Object>(); + + + private ConfigurationManager() { + initialConfigObjectsFromFiles(); + } + + private void initialConfigObjectsFromFiles() { + loadConfigurationClass(ErrorConfiguration.class); + loadConfigurationClass(Configuration.class); + } - private ConfigurationManager() { - URL url = Resources.getResource(CONFIGURATION_FILE); + private <T> void loadConfigurationClass(Class<T> clazz) { + T object = getObjectFromYaml(clazz); + configurations.put(clazz.getSimpleName(), object); + } + + + public <T> T getObjectFromYaml(Class<T> className) { + + + String configFileName = calculateFileName(className); + + URL url = Resources.getResource(CONFIGURATION_DIR + configFileName); String configFileContents = null; try { configFileContents = Resources.toString(url, Charsets.UTF_8); @@ -27,17 +53,16 @@ public class ConfigurationManager { log.error("ConfigurationManager - Failed to load configuration file"); } YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter(); - this.configuration = yamlToObjectConverter.convertFromString(configFileContents, Configuration.class); - } + T object = yamlToObjectConverter.convertFromString(configFileContents, className); - public Configuration getConfiguration() { - return configuration; + return object; } + public static ConfigurationManager getInstance() { if (instance == null) { - synchronized (ConfigurationManager.class){ - if (instance == null){ + synchronized (ConfigurationManager.class) { + if (instance == null) { instance = new ConfigurationManager(); } } @@ -45,7 +70,41 @@ public class ConfigurationManager { return instance; } - public void setConfiguration(Configuration configuration) { - this.configuration = configuration; + private static <T> String calculateFileName(Class<T> className) { + + String[] words = className.getSimpleName().split("(?=\\p{Upper})"); + + StringBuilder builder = new StringBuilder(); + + // There cannot be a null value returned from "split" - words != null is + // redundant + // if (words != null) { + boolean isFirst = true; + for (int i = 0; i < words.length; i++) { + + String word = words[i]; + if (word != null && !word.isEmpty()) { + if (!isFirst) { + builder.append("-"); + } else { + isFirst = false; + } + builder.append(words[i].toLowerCase()); + } + } + return builder.toString() + ".yaml"; + + /* + * } else { return className.getSimpleName().toLowerCase() + Constants.YAML_SUFFIX; } + */ + + } + + public ErrorConfiguration getErrorConfiguration() { + return (ErrorConfiguration) configurations.get((ErrorConfiguration.class.getSimpleName())); + } + + public Configuration getConfiguration() { + return (Configuration) configurations.get((Configuration.class.getSimpleName())); } } diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java new file mode 100644 index 0000000..59e8c6d --- /dev/null +++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorConfiguration.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.tosca.parser.config; + +import java.util.Map; + +public class ErrorConfiguration { + + private Map<String, ErrorInfo> errors; + + public Map<String, ErrorInfo> getErrors() { + return errors; + } + + public void setErrors(Map<String, ErrorInfo> errors) { + this.errors = errors; + } + + public ErrorInfo getErrorInfo(String key) { + ErrorInfo clone = null; + ErrorInfo other = errors.get(key); + if (other != null) { + clone = new ErrorInfo(); + clone.cloneData(other); + } + return clone; + } +} diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java new file mode 100644 index 0000000..01df115 --- /dev/null +++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/ErrorInfo.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.tosca.parser.config; + +public class ErrorInfo { + + private String code; + private String message; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public void cloneData(ErrorInfo other) { + this.code = other.getCode(); + this.message = other.getMessage(); + } + +} diff --git a/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java new file mode 100644 index 0000000..ce84a9c --- /dev/null +++ b/sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/config/SdcToscaParserErrors.java @@ -0,0 +1,31 @@ +package org.openecomp.sdc.tosca.parser.config; + +import java.util.EnumMap; +import java.util.Map; + +import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes; + +public enum SdcToscaParserErrors { + + BAD_FORMAT, CONFORMANCE_LEVEL_ERROR, FILE_NOT_FOUND, GENERAL_ERROR; + + private static final Map<JToscaErrorCodes, SdcToscaParserErrors> JTOSCA_ERRORS = + new EnumMap<JToscaErrorCodes, SdcToscaParserErrors>(JToscaErrorCodes.class) {{ + + put(JToscaErrorCodes.GENERAL_ERROR, GENERAL_ERROR); + + put(JToscaErrorCodes.PATH_NOT_VALID, FILE_NOT_FOUND); + //CSAR contents problems + put(JToscaErrorCodes.MISSING_META_FILE, BAD_FORMAT); + put(JToscaErrorCodes.INVALID_META_YAML_CONTENT, BAD_FORMAT); + put(JToscaErrorCodes.ENTRY_DEFINITION_NOT_DEFINED, BAD_FORMAT); + put(JToscaErrorCodes.MISSING_ENTRY_DEFINITION_FILE, BAD_FORMAT); + put(JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR, BAD_FORMAT); + put(JToscaErrorCodes.INVALID_CSAR_FORMAT, BAD_FORMAT); + }}; + + public static SdcToscaParserErrors getSdcErrorByJToscaError(JToscaErrorCodes jToscaErrorCode) { + return JTOSCA_ERRORS.get(jToscaErrorCode); + } + +} diff --git a/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 f41141f..a7fd99d 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 @@ -1,12 +1,20 @@ package org.openecomp.sdc.tosca.parser.exceptions;
-public class SdcToscaParserException extends Exception{
- /**
- *
- */
- private static final long serialVersionUID = 626014844866501196L;
-
- public SdcToscaParserException(String string) {
- super(string);
- }
+public class SdcToscaParserException extends Exception {
+
+ private static final long serialVersionUID = 626014844866501196L;
+ private String code;
+
+ public SdcToscaParserException(String string, String code) {
+ super(string);
+ this.code = code;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
}
diff --git a/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 df1d470..c53dcec 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,6 +22,8 @@ package org.openecomp.sdc.tosca.parser.impl; import java.util.*; import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; @@ -49,7 +51,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { private static final String PATH_DELIMITER = "#"; private static final String PREFIX = "port_"; - private static final String[] SUFFIX = new String[]{"_network_role_tag", "_ip_requirements", "_subnetpoolid"}; + Pattern SUFFIX = Pattern.compile("(_network_role_tag|_ip_requirements|_subnetpoolid)$"); +// private static final String[] SUFFIX = new String[]{"_network_role_tag", "_ip_requirements", "_subnetpoolid"}; private ToscaTemplate toscaTemplate; private static Logger log = LoggerFactory.getLogger(SdcCsarHelperImpl.class.getName()); @@ -91,6 +94,11 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { public Map<String, Map<String, Object>> getCpPropertiesFromVfc(NodeTemplate vfc) { + if (vfc == null) { + log.error("getCpPropertiesFromVfc - vfc is null"); + return new HashMap<>(); + } + List<String> paths = new ArrayList<>(); paths.add("network_role_tag"); paths.add("ip_requirements#ip_count_required#count"); @@ -102,22 +110,25 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { Map<String, Map<String, Object>> cps = new HashMap<>(); - for (Map.Entry<String, Property> entry : props.entrySet()) { - String fullCpName = entry.getKey(); - - if (fullCpName.startsWith(PREFIX) && - Arrays.stream(SUFFIX).parallel().anyMatch(fullCpName::endsWith)) - { - //this is CP - get all it's properties according to paths list - String cpName = fullCpName.replaceAll("^("+PREFIX+")", "").replaceAll("("+String.join("|", SUFFIX)+")$", ""); - cps.put(cpName, new HashMap<>()); - for (String path: paths) { - String fullPathToSearch = PREFIX + cpName + "_" + path; - String value = getNodeTemplatePropertyLeafValue(vfc, fullPathToSearch); - if (value != null) { - value = StringUtils.stripStart(value, "["); - value = StringUtils.stripEnd(value, "]"); - cps.get(cpName).put(path, value); + if (props != null) { + for (Map.Entry<String, Property> entry : props.entrySet()) { + String fullCpName = entry.getKey(); + Matcher matcher = SUFFIX.matcher(fullCpName); + + if (fullCpName.startsWith(PREFIX) && matcher.find()) { + //this is CP - get all it's properties according to paths list + String cpName = fullCpName.replaceAll("^(" + PREFIX + ")", "").replaceAll(matcher.group(1), ""); + + List<String> propertiesToSearch = paths.stream().filter(i -> i.contains(StringUtils.stripStart(matcher.group(1), "_"))).collect(Collectors.toList()); + for (String item : propertiesToSearch) { + String fullPathToSearch = PREFIX + cpName + "_" + item; + Object value = getNodeTemplatePropertyAsObject(vfc, fullPathToSearch); + if (value != null) { + if (!cps.containsKey(cpName)) + cps.put(cpName, new HashMap<>()); + } + + cps.get(cpName).put(item, value); } } } @@ -569,7 +580,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper { Object current = property.getValue(); return iterateProcessPath(1, current, split); } - log.error("processProperties - property not found"); + String propName = (split != null && split.length > 0 ? split[0] : null); + log.error("processProperties - property {} not found", propName); return 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 index 14c332c..2ddde1f 100644 --- 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 @@ -2,17 +2,18 @@ package org.openecomp.sdc.tosca.parser.impl; import org.openecomp.sdc.tosca.parser.api.ConformanceLevel;
import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
-import org.openecomp.sdc.tosca.parser.config.Configuration;
-import org.openecomp.sdc.tosca.parser.config.ConfigurationManager;
+import org.openecomp.sdc.tosca.parser.config.*;
import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.openecomp.sdc.tosca.parser.utils.GeneralUtility;
import org.openecomp.sdc.toscaparser.api.ToscaTemplate;
import org.openecomp.sdc.toscaparser.api.common.JToscaException;
+import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes;
public class SdcToscaParserFactory {
private static volatile SdcToscaParserFactory instance;
private static Configuration configuration;
+ private static ErrorConfiguration errorConfiguration;
private SdcToscaParserFactory() {
@@ -28,6 +29,7 @@ public class SdcToscaParserFactory { if (instance == null) {
instance = new SdcToscaParserFactory();
configuration = ConfigurationManager.getInstance().getConfiguration();
+ errorConfiguration = ConfigurationManager.getInstance().getErrorConfiguration();
}
}
}
@@ -40,11 +42,15 @@ public class SdcToscaParserFactory { * @param csarPath - the absolute path to CSAR file.
* @return ISdcCsarHelper object.
* @throws SdcToscaParserException - in case the path or CSAR are invalid.
- * @throws JToscaException - in case the path or CSAR are invalid.
*/
- public ISdcCsarHelper getSdcCsarHelper(String csarPath) throws JToscaException, SdcToscaParserException {
+ public ISdcCsarHelper getSdcCsarHelper(String csarPath) throws SdcToscaParserException {
synchronized (SdcToscaParserFactory.class) {
- ToscaTemplate tosca = new ToscaTemplate(csarPath, null, true, null);
+ ToscaTemplate tosca = null;
+ try {
+ tosca = new ToscaTemplate(csarPath, null, true, null);
+ } catch (JToscaException e) {
+ throwSdcToscaParserException(e);
+ }
SdcCsarHelperImpl sdcCsarHelperImpl = new SdcCsarHelperImpl(tosca);
validateCsarVersion(sdcCsarHelperImpl.getConformanceLevel());
return sdcCsarHelperImpl;
@@ -57,11 +63,20 @@ public class SdcToscaParserFactory { String maxVersion = level.getMaxVersion();
if (cSarVersion != null) {
if ((GeneralUtility.conformanceLevelCompare(cSarVersion, minVersion) < 0) || (GeneralUtility.conformanceLevelCompare(cSarVersion, maxVersion) > 0)) {
- throw new SdcToscaParserException("Model is not supported. Parser supports versions " + minVersion + " to " + maxVersion);
+ throwConformanceLevelException(minVersion, maxVersion);
}
} else {
- throw new SdcToscaParserException("Model is not supported. Parser supports versions " + minVersion + " to " + maxVersion);
+ throwConformanceLevelException(minVersion, maxVersion);
}
}
+ private void throwConformanceLevelException(String minVersion, String maxVersion) throws SdcToscaParserException {
+ ErrorInfo errorInfo = errorConfiguration.getErrorInfo(SdcToscaParserErrors.CONFORMANCE_LEVEL_ERROR.toString());
+ throw new SdcToscaParserException(String.format(errorInfo.getMessage(), minVersion, maxVersion), errorInfo.getCode());
+ }
+
+ private void throwSdcToscaParserException(JToscaException e) throws SdcToscaParserException {
+ ErrorInfo errorInfo = errorConfiguration.getErrorInfo(SdcToscaParserErrors.getSdcErrorByJToscaError(JToscaErrorCodes.getByCode(e.getCode())).toString());
+ throw new SdcToscaParserException(errorInfo.getMessage(), errorInfo.getCode());
+ }
}
\ No newline at end of file diff --git a/sdc-tosca-parser/src/main/resources/config/error-configuration.yaml b/sdc-tosca-parser/src/main/resources/config/error-configuration.yaml new file mode 100644 index 0000000..3febd33 --- /dev/null +++ b/sdc-tosca-parser/src/main/resources/config/error-configuration.yaml @@ -0,0 +1,18 @@ +# Errors +errors: + FILE_NOT_FOUND: { + code: TP0001, + message: "Error: CSAR file not found." + } + BAD_FORMAT: { + code: TP0002, + message: "Error: CSAR file bad format. Check the log for details." + } + CONFORMANCE_LEVEL_ERROR: { + code: TP0003, + message: "Error: CSAR version is unsupported. Parser supports versions %s to %s." + } + GENERAL_ERROR: { + code: TP0004, + message: "Error: an unexpected internal error occured." + }
\ No newline at end of file diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/BasicTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java index 0eb58f8..6746df7 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/BasicTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/SdcToscaParserBasicTest.java @@ -11,13 +11,13 @@ import java.util.Map; import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper; import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory; -import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector; import org.openecomp.sdc.toscaparser.api.common.JToscaException; +import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; -public abstract class BasicTest { +public abstract class SdcToscaParserBasicTest { public static final String VF_CUSTOMIZATION_UUID = "56179cd8-de4a-4c38-919b-bbc4452d2d73"; static SdcToscaParserFactory factory; @@ -97,18 +97,11 @@ public abstract class BasicTest { }; }; - private static ISdcCsarHelper getCsarHelper(String path) throws JToscaException, IOException, SdcToscaParserException { + protected static ISdcCsarHelper getCsarHelper(String path) throws SdcToscaParserException { System.out.println("Parsing CSAR "+path+"..."); - String fileStr1 = BasicTest.class.getClassLoader().getResource(path).getFile(); + String fileStr1 = SdcToscaParserBasicTest.class.getClassLoader().getResource(path).getFile(); File file1 = new File(fileStr1); ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(file1.getAbsolutePath()); - List<String> exceptionReport = ExceptionCollector.getCriticalsReport(); - if (!exceptionReport.isEmpty()){ - System.out.println("TOSCA Errors found in CSAR - failing the tests..."); - System.out.println(exceptionReport.toString()); - ExceptionCollector.clear(); - //throw new SdcToscaParserException("CSAR didn't pass validation"); - } return sdcCsarHelper; } diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java index 0e6387d..8c96303 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserConfigurationTest.java @@ -1,5 +1,6 @@ package org.openecomp.sdc.impl; +import org.openecomp.sdc.tosca.parser.config.ErrorConfiguration; import org.testng.annotations.Test; import org.openecomp.sdc.tosca.parser.config.Configuration; import org.openecomp.sdc.tosca.parser.config.ConfigurationManager; @@ -8,7 +9,7 @@ import java.io.IOException; import static org.testng.Assert.assertNotNull; -public class ToscaParserConfigurationTest extends BasicTest { +public class ToscaParserConfigurationTest extends SdcToscaParserBasicTest { @Test public void testConfigurationConformanceLevel() throws IOException { @@ -18,4 +19,13 @@ public class ToscaParserConfigurationTest extends BasicTest { assertNotNull(config.getConformanceLevel().getMaxVersion()); assertNotNull(config.getConformanceLevel().getMinVersion()); } + + + @Test + public void testErrorConfigurations() throws IOException { + ErrorConfiguration errorConfig = ConfigurationManager.getInstance().getErrorConfiguration(); + assertNotNull(errorConfig); + assertNotNull(errorConfig.getErrors()); + } + } diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java new file mode 100644 index 0000000..8451a58 --- /dev/null +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserErrorHandlingTest.java @@ -0,0 +1,143 @@ +package org.openecomp.sdc.impl; + +import org.testng.annotations.Test; +import static org.testng.Assert.*; + +import java.io.File; + +import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.openecomp.sdc.toscaparser.api.utils.JToscaErrorCodes; + + +/*put(JToscaErrorCodes.GENERAL_ERROR, GENERAL_ERROR); + +put(JToscaErrorCodes.PATH_NOT_VALID, FILE_NOT_FOUND); +//CSAR contents problems +put(JToscaErrorCodes.MISSING_META_FILE, BAD_FORMAT); +put(JToscaErrorCodes.INVALID_META_YAML_CONTENT, BAD_FORMAT); +put(JToscaErrorCodes.ENTRY_DEFINITION_NOT_DEFINED, BAD_FORMAT); +put(JToscaErrorCodes.MISSING_ENTRY_DEFINITION_FILE, BAD_FORMAT); +put(JToscaErrorCodes.CSAR_TOSCA_VALIDATION_ERROR, BAD_FORMAT); + + MISSING_META_FILE("JT1001"), +/* INVALID_META_YAML_CONTENT("JT1002"), +/* ENTRY_DEFINITION_NOT_DEFINED("JT1003"), +/* MISSING_ENTRY_DEFINITION_FILE("JT1004"), +/* GENERAL_ERROR("JT1005"), +/* PATH_NOT_VALID("JT1006"), +/* CSAR_TOSCA_VALIDATION_ERROR("JT1007"); + +*/ + +/* + * + * # Errors +errors: + FILE_NOT_FOUND: { + code: TP0001, + message: "Error: CSAR file not found." + } + BAD_FORMAT: { + code: TP0002, + message: "Error: CSAR file bad format. Check the log for details." + } + CONFORMANCE_LEVEL_ERROR: { + code: TP0003, + message: "Error: CSAR version is unsupported. Parser supports versions %s to %s." + } + GENERAL_ERROR: { + code: TP0004, + message: "Error: an unexpected internal error occured." + } + * + */ + +public class ToscaParserErrorHandlingTest extends SdcToscaParserBasicTest { + + + @Test + public void testMissingMetadata(){ + String csarPath = "csars/service-missing-meta-file.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + + @Test + public void testInvalidYamlContentMeta(){ + String csarPath = "csars/service-invalid-yaml-content-meta.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + @Test + public void testEntryDefinitionNotDefined(){ + String csarPath = "csars/service-entry-definition-not-defined.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + @Test + public void testMissingEntryDefinitionFile(){ + String csarPath = "csars/service-missing-entry-definition.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + //@Test - PA - there are currently no critical erros in JTosca + public void tesValidationError(){ + String csarPath = "csars/service-invalid-input-args.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + @Test + public void testInValidConformanceLevelError(){ + String csarPath = "csars/service-invalid-conformence-level.csar"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0003"); + } + + @Test + public void testFileNotFound(){ + Throwable captureThrowable = captureThrowable("csars/XXX.csar"); + testThrowable(captureThrowable, "TP0001"); + } + + @Test + public void testInvalidCsarFormat(){ + String csarPath = "csars/csar-invalid-zip.zip"; + String fileLocationString = ToscaParserErrorHandlingTest.class.getClassLoader().getResource(csarPath).getFile(); + File file = new File(fileLocationString); + Throwable captureThrowable = captureThrowable(file.getAbsolutePath()); + testThrowable(captureThrowable, "TP0002"); + } + + private static void testThrowable(Throwable captureThrowable, String expectedCode) { + assertNotNull(captureThrowable); + assertTrue(captureThrowable instanceof SdcToscaParserException, "Error thrown is of type "+captureThrowable.getClass().getSimpleName()); + assertEquals(((SdcToscaParserException)captureThrowable).getCode(), expectedCode); + } + + public static Throwable captureThrowable(String csarPath) { + Throwable result = null; + try { + factory.getSdcCsarHelper(csarPath); + } catch( Throwable throwable ) { + result = throwable; + } + return result; + } +} diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java index b903867..9f349ae 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGeneralUtilTest.java @@ -5,7 +5,7 @@ import org.openecomp.sdc.tosca.parser.utils.GeneralUtility; import static org.testng.Assert.assertTrue; -public class ToscaParserGeneralUtilTest extends BasicTest { +public class ToscaParserGeneralUtilTest extends SdcToscaParserBasicTest { @Test public void testVersionCompare() { diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java index 58e967a..01c888f 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserGroupTest.java @@ -10,7 +10,7 @@ import java.util.List; import static org.testng.Assert.*; -public class ToscaParserGroupTest extends BasicTest{ +public class ToscaParserGroupTest extends SdcToscaParserBasicTest{ //region getVfModulesByVf @Test diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java index 802d5b8..4fbc9c3 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserMetadataTest.java @@ -7,7 +7,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; -public class ToscaParserMetadataTest extends BasicTest { +public class ToscaParserMetadataTest extends SdcToscaParserBasicTest { //region getServiceMetadata @Test diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java index c9215a2..dd895c3 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserNodeTemplateTest.java @@ -14,7 +14,7 @@ import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.openecomp.sdc.toscaparser.api.Group; import org.openecomp.sdc.toscaparser.api.NodeTemplate; -public class ToscaParserNodeTemplateTest extends BasicTest { +public class ToscaParserNodeTemplateTest extends SdcToscaParserBasicTest { //region getServiceVfList @Test @@ -311,13 +311,22 @@ public class ToscaParserNodeTemplateTest extends BasicTest { List<NodeTemplate> vfcs = complexCps.getVfcListByVf(VF_CUSTOMIZATION_UUID); Map<String, Map<String, Object>> cps = complexCps.getCpPropertiesFromVfc(vfcs.get(0)); - assertEquals("1", cps.get("port_fe1_sigtran").get("ip_requirements#ip_count_required#count")); - assertEquals("true", cps.get("port_fe1_sigtran").get("ip_requirements#dhcp_enabled")); - assertEquals("4", cps.get("port_fe1_sigtran").get("ip_requirements#ip_version")); + assertEquals(5, cps.size()); - assertEquals("2", cps.get("port_fe_cluster").get("ip_requirements#ip_count_required#count")); - assertEquals("true", cps.get("port_fe_cluster").get("ip_requirements#dhcp_enabled")); - assertEquals("4", cps.get("port_fe_cluster").get("ip_requirements#ip_version")); + assertEquals(1, cps.get("port_fe1_sigtran").get("ip_requirements#ip_count_required#count")); + assertEquals(true, cps.get("port_fe1_sigtran").get("ip_requirements#dhcp_enabled")); + assertEquals(4, cps.get("port_fe1_sigtran").get("ip_requirements#ip_version")); + + assertEquals(2, cps.get("port_fe_cluster").get("ip_requirements#ip_count_required#count")); + assertEquals(true, cps.get("port_fe_cluster").get("ip_requirements#dhcp_enabled")); + assertEquals(4, cps.get("port_fe_cluster").get("ip_requirements#ip_version")); + } + + @Test + public void testGetCpPropertiesFromVfcForNullVFC() { + Map<String, Map<String, Object>> cps = complexCps.getCpPropertiesFromVfc(null); + assertNotNull(cps); + assertEquals(0, cps.size()); } //endregion diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java index 0599dcc..0b172f5 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserServiceInputTest.java @@ -9,7 +9,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; -public class ToscaParserServiceInputTest extends BasicTest { +public class ToscaParserServiceInputTest extends SdcToscaParserBasicTest { //region getServiceInputs @Test diff --git a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java index c61f465..6461a92 100644 --- a/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java +++ b/sdc-tosca-parser/src/test/java/org/openecomp/sdc/impl/ToscaParserSubsMappingsTest.java @@ -20,7 +20,7 @@ import org.openecomp.sdc.toscaparser.api.Property; //import static org.junit.Assert.assertEquals; //import static org.junit.Assert.assertNull; -public class ToscaParserSubsMappingsTest extends BasicTest { +public class ToscaParserSubsMappingsTest extends SdcToscaParserBasicTest { //region getServiceSubstitutionMappingsTypeName @Test diff --git a/sdc-tosca-parser/src/test/resources/config/error-configuration.yaml b/sdc-tosca-parser/src/test/resources/config/error-configuration.yaml new file mode 100644 index 0000000..3febd33 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/config/error-configuration.yaml @@ -0,0 +1,18 @@ +# Errors +errors: + FILE_NOT_FOUND: { + code: TP0001, + message: "Error: CSAR file not found." + } + BAD_FORMAT: { + code: TP0002, + message: "Error: CSAR file bad format. Check the log for details." + } + CONFORMANCE_LEVEL_ERROR: { + code: TP0003, + message: "Error: CSAR version is unsupported. Parser supports versions %s to %s." + } + GENERAL_ERROR: { + code: TP0004, + message: "Error: an unexpected internal error occured." + }
\ No newline at end of file diff --git a/sdc-tosca-parser/src/test/resources/csars/csar-invalid-zip.zip b/sdc-tosca-parser/src/test/resources/csars/csar-invalid-zip.zip new file mode 100644 index 0000000..04de055 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/csar-invalid-zip.zip @@ -0,0 +1,2 @@ +SDC-TOSCA-Meta-File-Version: 1.0 +SDC-TOSCA-Definitions-Version: 2.0 diff --git a/sdc-tosca-parser/src/test/resources/csars/service-entry-definition-not-defined.csar b/sdc-tosca-parser/src/test/resources/csars/service-entry-definition-not-defined.csar Binary files differnew file mode 100644 index 0000000..47e65b6 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-entry-definition-not-defined.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-invalid-conformence-level.csar b/sdc-tosca-parser/src/test/resources/csars/service-invalid-conformence-level.csar Binary files differnew file mode 100644 index 0000000..12621f0 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-invalid-conformence-level.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-invalid-input-args.csar b/sdc-tosca-parser/src/test/resources/csars/service-invalid-input-args.csar Binary files differnew file mode 100644 index 0000000..22f9970 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-invalid-input-args.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-invalid-yaml-content-meta.csar b/sdc-tosca-parser/src/test/resources/csars/service-invalid-yaml-content-meta.csar Binary files differnew file mode 100644 index 0000000..f77af6f --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-invalid-yaml-content-meta.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-missing-entry-definition.csar b/sdc-tosca-parser/src/test/resources/csars/service-missing-entry-definition.csar Binary files differnew file mode 100644 index 0000000..8fd1962 --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-missing-entry-definition.csar diff --git a/sdc-tosca-parser/src/test/resources/csars/service-missing-meta-file.csar b/sdc-tosca-parser/src/test/resources/csars/service-missing-meta-file.csar Binary files differnew file mode 100644 index 0000000..79348db --- /dev/null +++ b/sdc-tosca-parser/src/test/resources/csars/service-missing-meta-file.csar |