diff options
Diffstat (limited to 'jtosca')
51 files changed, 500 insertions, 394 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 |