[SDC-20] fix toString loop and validation 75/4275/1
authorPavel Aharoni <pa0916@att.com>
Wed, 17 May 2017 12:10:58 +0000 (15:10 +0300)
committerPavel Aharoni <pa0916@att.com>
Wed, 17 May 2017 12:12:27 +0000 (15:12 +0300)
Change-Id: I24f5cdc52bf1c054fed1557ecf877d87c1fa6a34
Signed-off-by: Pavel Aharoni <pa0916@att.com>
jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/DataEntity.java
jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java
jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java
jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java
jtosca/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java
sdc-distribution-ci/src/main/java/org/openecomp/test/CsarToscaTester.java
sdc-tosca-parser/src/main/java/org/openecomp/sdc/tosca/parser/impl/SdcCsarHelperImpl.java

index a96b36a..a081f89 100644 (file)
@@ -52,12 +52,14 @@ public class DataEntity {
                 ExceptionCollector.appendWarning(String.format(
                     "TypeMismatchError: \"%s\" is not a map. The type is \"%s\"",
                     value.toString(),dataType.getType()));
-
-                               if (value instanceof List)
+                
+                               if (value instanceof List && ((List) value).size() > 0)  {
                                        value = ((List) value).get(0);
+                               }
 
-                               if (!(value instanceof LinkedHashMap))
+                               if (!(value instanceof LinkedHashMap))  {
                                        return value;
+                               }
                        }
 
 
index 2c9d981..4d0baaf 100644 (file)
@@ -467,19 +467,9 @@ public class NodeTemplate extends EntityTemplate {
 
        @Override
        public String toString() {
-               return "NodeTemplate{" +
-                               //"templates=" + templates +
-                               //", customDef=" + customDef +
-                               //", availableRelTpls=" + availableRelTpls +
-                               //", availableRelTypes=" + availableRelTypes +
-                               //", related=" + related +
-                               //", relationshipTpl=" + relationshipTpl +
-                               //", _relationships=" + _relationships +
-                               ", subMappingToscaTemplate=" + (subMappingToscaTemplate==null?"":subMappingToscaTemplate.toLimitedString()) +
-                               //", subMappingToscaTemplate2=" +( subMappingToscaTemplate2 ==null?"":subMappingToscaTemplate2.toLimitedString()) +
-                               ", metadata=" + metadata +
-                               '}';
+               return getName();
        }
+
 }
 
 /*python
index f02ec2a..153bd89 100644 (file)
@@ -286,18 +286,19 @@ public class SubstitutionMappings {
        @Override
        public String toString() {
                return "SubstitutionMappings{" +
-                               "subMappingDef=" + subMappingDef +
-                               ", nodetemplates=" + nodetemplates +
-                               ", inputs=" + inputs +
-                               ", outputs=" + outputs +
-                               ", groups=" + groups +
-                               ", subMappedNodeTemplate=" + subMappedNodeTemplate +
-                               ", customDefs=" + customDefs +
-                               ", _capabilities=" + _capabilities +
-                               ", _requirements=" + _requirements +
+//                             "subMappingDef=" + subMappingDef +
+//                             ", nodetemplates=" + nodetemplates +
+//                             ", inputs=" + inputs +
+//                             ", outputs=" + outputs +
+//                             ", groups=" + groups +
+                               ", subMappedNodeTemplate=" + (subMappedNodeTemplate==null?"":subMappedNodeTemplate.getName()) +
+//                             ", customDefs=" + customDefs +
+//                             ", _capabilities=" + _capabilities +
+//                             ", _requirements=" + _requirements +
                                '}';
        }
 
+       @Deprecated
        public String toLimitedString() {
                return "SubstitutionMappings{" +
                                "subMappingDef=" + subMappingDef +
@@ -305,7 +306,7 @@ public class SubstitutionMappings {
                                ", inputs=" + inputs +
                                ", outputs=" + outputs +
                                ", groups=" + groups +
-                               ", subMappedNodeTemplate=" + subMappedNodeTemplate.getName() +
+                               ", subMappedNodeTemplate=" + (subMappedNodeTemplate==null?"":subMappedNodeTemplate.getName()) +
                                ", customDefs=" + customDefs +
                                ", _capabilities=" + _capabilities +
                                ", _requirements=" + _requirements +
index 39536ca..4050643 100644 (file)
@@ -84,7 +84,7 @@ public class TopologyTemplate {
                ArrayList<Input> alInputs = new ArrayList<>();
                for(String name: _tplInputs().keySet()) {
                        Object attrs = _tplInputs().get(name);
-                       Input input = new Input(name,(LinkedHashMap<String,Object>)attrs,customDefs);//ATT-CDT
+                       Input input = new Input(name,(LinkedHashMap<String,Object>)attrs,customDefs);
             if(parsedParams != null && parsedParams.get(name) != null) {
                input.validate(parsedParams.get(name));
             }
@@ -173,7 +173,7 @@ public class TopologyTemplate {
                                                            nodeTemplates,
                                                            inputs,
                                                            outputs,
-                                                           groups, //ATT addition
+                                                           groups,
                                                            subMappedNodeTemplate,
                                                            customDefs);
                }
@@ -232,7 +232,7 @@ public class TopologyTemplate {
                 DataEntity.validateDatatype("list", memberNames,null,null,null);
                                if(memberNames.size() < 1 || 
                                       (new HashSet<String>(memberNames)).size() != memberNames.size()) {
-                    ExceptionCollector.appendException(String.format(
+                    ExceptionCollector.appendWarning(String.format(
                             "InvalidGroupTargetException: Member nodes \"%s\" should be >= 1 and not repeated",
                             memberNames.toString()));
                                }
index 2eb64e8..96958ce 100644 (file)
@@ -1,6 +1,7 @@
 package org.openecomp.sdc.toscaparser.api.parameters;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.LinkedHashMap;
 
 import org.openecomp.sdc.toscaparser.api.DataEntity;
@@ -18,19 +19,31 @@ public class Input {
        private static final String REQUIRED = "required";
        private static final String STATUS = "status";
        private static final String ENTRY_SCHEMA = "entry_schema";
+       
+       public static final String INTEGER = "integer";
+       public static final String STRING = "string";
+       public static final String BOOLEAN = "boolean";
+       public static final String FLOAT = "float";
+       public static final String LIST = "list";
+       public static final String MAP = "map";
+       public static final String JSON = "json";
     
        private static String INPUTFIELD[] = {
                TYPE, DESCRIPTION, DEFAULT, CONSTRAINTS, REQUIRED,STATUS, ENTRY_SCHEMA
     };
+       
+       private static String PRIMITIVE_TYPES[] = {
+                       INTEGER, STRING, BOOLEAN, FLOAT, LIST, MAP, JSON
+    };
     
     private String name;
     private Schema schema;
-       private LinkedHashMap<String,Object> customDefs;//ATT-CDT
+       private LinkedHashMap<String,Object> customDefs;
        
-       public Input(String _name,LinkedHashMap<String,Object> _schemaDict,LinkedHashMap<String,Object> _customDefs) {//ATT-CDT
+       public Input(String _name,LinkedHashMap<String,Object> _schemaDict,LinkedHashMap<String,Object> _customDefs) {
                name = _name;
                schema = new Schema(_name,_schemaDict);
-               customDefs = _customDefs;//ATT-CDT
+               customDefs = _customDefs;
        }
        
        public String getName() {
@@ -90,13 +103,13 @@ public class Input {
                                break;
                        }
                }
-               //ATT-CDT
+               
                if(!bFound) {
                        if(customDefs.get(inputType) != null) {
                                bFound = true;
                        }
                }
-               //ATT-CDT
+               
                if(!bFound) {
             ExceptionCollector.appendException(String.format(
                     "ValueError: Invalid type \"%s\"",inputType));
@@ -111,14 +124,20 @@ public class Input {
        else if(EntityType.TOSCA_DEF.get(EntityType.DATATYPE_NETWORK_PREFIX + getType()) != null) {
                datatype = EntityType.TOSCA_DEF.get(EntityType.DATATYPE_NETWORK_PREFIX + getType());
        }
-       //ATT-CDT
+       
+       String type = getType();
+       // if it's one of the basic types DON'T look in customDefs
+       if(Arrays.asList(PRIMITIVE_TYPES).contains(type)) {
+               DataEntity.validateDatatype(getType(), value, null, (LinkedHashMap<String,Object>)datatype, null);
+               return; 
+       }
        else if(customDefs.get(getType()) != null) {
                datatype = customDefs.get(getType());
-               DataEntity.validateDatatype(getType(),value,(LinkedHashMap<String,Object>)datatype,customDefs,null);
+               DataEntity.validateDatatype(getType(), value, (LinkedHashMap<String,Object>)datatype, customDefs, null);
                return;
        }
-       //ATT-CDT 
-       DataEntity.validateDatatype(getType(),value,null,(LinkedHashMap<String,Object>)datatype,null);
+       
+       DataEntity.validateDatatype(getType(), value, null, (LinkedHashMap<String,Object>)datatype, null);
     }
 }
 
index 068ef24..b07de08 100644 (file)
@@ -27,7 +27,8 @@ public class CsarToscaTester {
                Date now = new Date();\r
                SimpleDateFormat dateFormat = new SimpleDateFormat("d-MM-y-HH_mm_ss");\r
                String time = dateFormat.format(now);\r
-               File dir = new File(args[1].toString() + "/csar-reports-" + time);\r
+               String csarsDir = args[1].toString() + "/csar-reports-" + time;\r
+               File dir = new File(csarsDir);\r
                dir.mkdir();\r
                \r
                \r
@@ -35,7 +36,10 @@ public class CsarToscaTester {
                        if (file.isFile()) {  \r
                        System.out.println("File " + file.getAbsolutePath());\r
                        ExceptionCollector.clear();\r
-\r
+                       String name = file.getName();\r
+                       String currentCsarDir = csarsDir+"/"+name+"-"+time;\r
+                               dir = new File(currentCsarDir);\r
+                               dir.mkdir();\r
                        ISdcCsarHelper csarHelper = factory.getSdcCsarHelper(file.getAbsolutePath());\r
                        List<NodeTemplate> vflist = csarHelper.getServiceVfList();\r
                        List<Input> inputs = csarHelper.getServiceInputs();\r
@@ -44,18 +48,19 @@ public class CsarToscaTester {
                        List<String> warningsReport = ExceptionCollector.getWarningsReport();\r
                        //System.out.println("WARNINGS during CSAR parsing are: " + (warningsReport != null ? warningsReport.toString() : "none"));\r
                        \r
+                       \r
                                \r
                        if (!exceptionReport.isEmpty())  {\r
                                \r
                                        try {\r
-                                               fw = new FileWriter(new File(dir + "/" + exceptionReport.size() / 2 + "-critical-" + file.getName() + ".txt"));\r
+                                               fw = new FileWriter(new File(currentCsarDir + "/" + exceptionReport.size() / 2 + "-critical-" + name +"-"+time + ".txt"));\r
                                                for (String exception : exceptionReport) {\r
                                                        fw.write(exception);\r
                                                        fw.write("\r\n");\r
                                                }\r
                                                fw.close();\r
                                                \r
-                                               fw = new FileWriter(new File(dir + "/" + warningsReport.size() / 2 +  "-warning-" + file.getName() + ".txt"));\r
+                                               fw = new FileWriter(new File(currentCsarDir + "/" + warningsReport.size() / 2 +  "-warning-" + name +"-"+time + ".txt"));\r
                                                for (String warning : warningsReport) {\r
                                                        fw.write(warning);\r
                                                        fw.write("\r\n");\r
@@ -63,6 +68,14 @@ public class CsarToscaTester {
                                                fw.close();\r
                                                \r
                                                \r
+                                               //TODO\r
+                                               fw = new FileWriter(new File(currentCsarDir + "/" + exceptionReport.size() / 2 + "-critical-" + name +"-"+time + ".txt"));\r
+                                               for (String critical : exceptionReport) {\r
+                                                       fw.write(critical);\r
+                                                       fw.write("\r\n");\r
+                                               }\r
+                                               fw.close();\r
+                                               \r
                                        } catch (IOException ex) {\r
                                                ex.printStackTrace();\r
                                        }\r
index b9ce069..df1d470 100644 (file)
@@ -68,10 +68,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
             log.error("getNodeTemplatePropertyLeafValue - leafValuePath is null or empty");
             return null;
         }
-        log.debug("getNodeTemplatePropertyLeafValue - nodeTemplate is : {}, leafValuePath is {} ", nodeTemplate, leafValuePath);
         String[] split = getSplittedPath(leafValuePath);
         LinkedHashMap<String, Property> properties = nodeTemplate.getProperties();
-        log.debug("getNodeTemplatePropertyLeafValue - properties of nodeTemplate are : {}", properties);
         Object property = processProperties(split, properties);
         return property == null ? null : String.valueOf(property);
     }
@@ -86,10 +84,8 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
             log.error("getNodeTemplatePropertyAsObject - leafValuePath is null or empty");
             return null;
         }
-        log.debug("getNodeTemplatePropertyAsObject - nodeTemplate is : {}, leafValuePath is {} ", nodeTemplate, leafValuePath);
         String[] split = getSplittedPath(leafValuePath);
         LinkedHashMap<String, Property> properties = nodeTemplate.getProperties();
-        log.debug("getNodeTemplatePropertyAsObject - properties of nodeTemplate are : {}", properties);
         return processProperties(split, properties);
     }
 
@@ -134,7 +130,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
     //Sunny flow - covered with UT
     public List<NodeTemplate> getServiceVlList() {
         List<NodeTemplate> serviceVlList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VL);
-        log.debug("getServiceVlList - the VL list is {}", serviceVlList);
         return serviceVlList;
     }
 
@@ -142,7 +137,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
     //Sunny flow - covered with UT
     public List<NodeTemplate> getServiceVfList() {
         List<NodeTemplate> serviceVfList = getNodeTemplateBySdcType(toscaTemplate.getTopologyTemplate(), Types.TYPE_VF);
-        log.debug("getServiceVfList - the VF list is {}", serviceVfList);
         return serviceVfList;
     }
 
@@ -158,7 +152,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
             return null;
         }
         String metadataPropertyValue = metadata.getValue(metadataPropertyName);
-        log.debug("getMetadataPropertyValue - metadata is {} metadataPropertyName is {} the value is : {}", metadata, metadataPropertyName, metadataPropertyValue);
         return metadataPropertyValue;
     }
 
@@ -179,7 +172,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
             }
         }
 
-        log.debug("getServiceNodeTemplatesByType - For Node Type : {} -  NodeTemplate list value is: {}", nodeType, res);
         return res;
     }
 
@@ -193,7 +185,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
 
         List<NodeTemplate> serviceVfList = getServiceVfList();
         NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId);
-        log.debug("getVfcListByVf - serviceVfList value: {}, vfInstance value: {}", serviceVfList, vfInstance);
         return getNodeTemplateBySdcType(vfInstance, Types.TYPE_VFC);
     }
 
@@ -201,9 +192,7 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
     //Sunny flow - covered with UT
     public List<Group> getVfModulesByVf(String vfCustomizationUuid) {
         List<NodeTemplate> serviceVfList = getServiceVfList();
-        log.debug("getVfModulesByVf - VF list is {}", serviceVfList);
         NodeTemplate nodeTemplateByCustomizationUuid = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationUuid);
-        log.debug("getVfModulesByVf - getNodeTemplateByCustomizationUuid is {}, customizationUuid {}", nodeTemplateByCustomizationUuid, vfCustomizationUuid);
         if (nodeTemplateByCustomizationUuid != null) {
             /*SubstitutionMappings substitutionMappings = nodeTemplateByCustomizationUuid.getSubstitutionMappings();
                        if (substitutionMappings != null){
@@ -223,7 +212,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
                         .stream()
                         .filter(x -> "org.openecomp.groups.VfModule".equals(x.getTypeDefinition().getType()) && x.getName().startsWith(normaliseComponentInstanceName))
                         .collect(Collectors.toList());
-                log.debug("getVfModulesByVf - VfModules are {}", collect);
                 return collect;
             }
         }
@@ -245,11 +233,9 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
         }
 
         List<Input> inputs = toscaTemplate.getInputs();
-        log.debug("getServiceInputLeafValue - the leafValuePath is  {} , the inputs are {}", inputLeafValuePath, inputs);
         if (inputs != null) {
             Optional<Input> findFirst = inputs.stream().filter(x -> x.getName().equals(split[0])).findFirst();
             if (findFirst.isPresent()) {
-                log.debug("getServiceInputLeafValue - find first item is {}", findFirst.get());
                 Input input = findFirst.get();
                 Object current = input.getDefault();
                 Object property = iterateProcessPath(2, current, split);
@@ -274,11 +260,9 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
         }
 
         List<Input> inputs = toscaTemplate.getInputs();
-        log.debug("getServiceInputLeafValueOfDefaultAsObject - the leafValuePath is  {} , the inputs are {}", inputLeafValuePath, inputs);
         if (inputs != null) {
             Optional<Input> findFirst = inputs.stream().filter(x -> x.getName().equals(split[0])).findFirst();
             if (findFirst.isPresent()) {
-                log.debug("getServiceInputLeafValueOfDefaultAsObject - find first item is {}", findFirst.get());
                 Input input = findFirst.get();
                 Object current = input.getDefault();
                 return iterateProcessPath(2, current, split);
@@ -308,7 +292,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
             }
         }
         if (current != null) {
-            log.debug("iterateProcessPath - the input default leaf value is {}", String.valueOf(current));
             return current;
         }
         log.error("iterateProcessPath - Path not Found");
@@ -328,14 +311,12 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
             log.debug("getServiceSubstitutionMappingsTypeName - No Substitution Mappings defined");
             return null;
         }
-        log.debug("getServiceSubstitutionMappingsTypeName - SubstitutionMappings value: {}", substitutionMappings);
 
         NodeType nodeType = substitutionMappings.getNodeDefinition();
         if (nodeType == null) {
             log.debug("getServiceSubstitutionMappingsTypeName - No Substitution Mappings node defined");
             return null;
         }
-        log.debug("getServiceSubstitutionMappingsTypeName - nodeType value: {}", nodeType);
 
         return nodeType.getType();
     }
@@ -403,7 +384,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
             return cpList;
         }
         NodeTemplate vfInstance = getNodeTemplateByCustomizationUuid(serviceVfList, vfCustomizationId);
-        log.debug("getCpListByVf vf list is {}", vfInstance);
         if (vfInstance == null) {
             log.debug("getCpListByVf vf list is null");
             return cpList;
@@ -436,12 +416,9 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
                         .stream()
                         .filter(x -> (x.getMetadata() != null && serviceLevelVfModule.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID).equals(x.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID)))).findFirst();
                 if (findFirst.isPresent()) {
-                    log.debug("getMembersOfVfModule - Found VF level group with vfModuleModelInvariantUUID {}", serviceLevelVfModule.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID));
                     List<String> members = findFirst.get().getMembers();
-                    log.debug("getMembersOfVfModule - members section is {}", members);
                     if (members != null) {
                         List<NodeTemplate> collect = substitutionMappings.getNodeTemplates().stream().filter(x -> members.contains(x.getName())).collect(Collectors.toList());
-                        log.debug("getMembersOfVfModule - Node templates are {}", collect);
                         return collect;
                     }
                 }
@@ -498,7 +475,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
         if (nodeTemplates.isEmpty()) {
             log.debug("getAllottedResources -  allotted resources not exist");
         } else {
-            log.debug("getAllottedResources - the allotted resources list is {}", nodeTemplates);
         }
 
         return nodeTemplates;
@@ -512,7 +488,6 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
             log.error("getTypeOfNodeTemplate nodeTemplate is null");
             return null;
         }
-        log.debug("getTypeOfNodeTemplate node template type is {}", nodeTemplate.getTypeDefinition().getType());
         return nodeTemplate.getTypeDefinition().getType();
     }
 
@@ -583,16 +558,13 @@ public class SdcCsarHelperImpl implements ISdcCsarHelper {
 
     //Assumed to be unique property for the list
     private NodeTemplate getNodeTemplateByCustomizationUuid(List<NodeTemplate> nodeTemplates, String customizationId) {
-        log.debug("getNodeTemplateByCustomizationUuid - nodeTemplates {}, customizationId {}", nodeTemplates, customizationId);
         Optional<NodeTemplate> findFirst = nodeTemplates.stream().filter(x -> (x.getMetaData() != null && customizationId.equals(x.getMetaData().getValue(PROPERTY_NAME_CUSTOMIZATIONUUID)))).findFirst();
         return findFirst.isPresent() ? findFirst.get() : null;
     }
 
     private Object processProperties(String[] split, LinkedHashMap<String, Property> properties) {
-        log.debug("processProperties - the leafValuePath is  {} , the properties are {}", Arrays.toString(split), properties.toString());
         Optional<Entry<String, Property>> findFirst = properties.entrySet().stream().filter(x -> x.getKey().equals(split[0])).findFirst();
         if (findFirst.isPresent()) {
-            log.debug("processProperties - find first item is {}", findFirst.get());
             Property property = findFirst.get().getValue();
             Object current = property.getValue();
             return iterateProcessPath(1, current, split);