diff options
Diffstat (limited to 'jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/functions')
6 files changed, 48 insertions, 53 deletions
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"); } |