Rename the groupfilter.config System Property 41/78241/1
authormark.j.leonard <mark.j.leonard@gmail.com>
Mon, 11 Feb 2019 17:44:17 +0000 (17:44 +0000)
committermark.j.leonard <mark.j.leonard@gmail.com>
Mon, 11 Feb 2019 18:16:08 +0000 (18:16 +0000)
Rename the System Property to be tosca.mappings.config and default the
value to ${CONFIG_HOME}/tosca-mappings.json

Update Java code and comments to remove the word "filter" where this is
now outdated.

Add new JUnit tests for better code coverage.

Change-Id: Iaa9685638e099c898894171a958b0d5d51542fde
Issue-ID: AAI-2121
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
12 files changed:
src/main/bin/start.sh
src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java
src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java
src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java
src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java
src/main/resources/application.properties
src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java
src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java
src/test/java/org/onap/aai/babel/util/ArtifactTestUtils.java
src/test/java/org/onap/aai/babel/util/Resources.java
src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java

index 1ee1db6..f30a599 100644 (file)
@@ -34,6 +34,7 @@ fi
 PROPS="-DAPP_HOME=${APP_HOME}"
 PROPS="${PROPS} -DCONFIG_HOME=${CONFIG_HOME}"
 PROPS="${PROPS} -Dartifactgenerator.config=${CONFIG_HOME}/artifact-generator.properties"
+PROPS="${PROPS} -Dtosca.mappings.config=${CONFIG_HOME}/tosca-mappings.json"
 PROPS="${PROPS} -DKEY_STORE_PASSWORD=${KEY_STORE_PASSWORD}"
 JVM_MAX_HEAP=${MAX_HEAP:-1024}
 
index 7dfc807..50c6edf 100644 (file)
@@ -51,7 +51,7 @@ import org.onap.sdc.toscaparser.api.Property;
 import org.onap.sdc.toscaparser.api.elements.Metadata;
 
 /**
- * Wrapper for the sdc-tosca parser
+ * Wrapper for the sdc-tosca parser.
  *
  */
 public class ArtifactGeneratorToscaParser {
@@ -59,12 +59,13 @@ public class ArtifactGeneratorToscaParser {
     private static Logger log = LogHelper.INSTANCE;
 
     public static final String PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE = "artifactgenerator.config";
-    public static final String PROPERTY_GROUP_FILTERS_CONFIG_FILE = "groupfilter.config";
+    public static final String PROPERTY_TOSCA_MAPPING_FILE = "tosca.mappings.config";
+
+    public static final String GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND =
+            "Cannot generate artifacts. System property %s not configured";
 
     private static final String GENERATOR_AAI_CONFIGFILE_NOT_FOUND =
             "Cannot generate artifacts. Artifact Generator Configuration file not found at %s";
-    private static final String GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND =
-            "Cannot generate artifacts. System property %s not configured";
     private static final String GENERATOR_AAI_PROVIDING_SERVICE_METADATA_MISSING =
             "Cannot generate artifacts. Providing Service Metadata is missing for allotted resource %s";
     private static final String GENERATOR_AAI_PROVIDING_SERVICE_MISSING =
@@ -84,7 +85,7 @@ public class ArtifactGeneratorToscaParser {
      * Constructs using csarHelper
      *
      * @param csarHelper
-     *     The csar helper
+     *            The csar helper
      */
     public ArtifactGeneratorToscaParser(ISdcCsarHelper csarHelper) {
         this.csarHelper = csarHelper;
@@ -94,7 +95,7 @@ public class ArtifactGeneratorToscaParser {
      * Get or create the artifact description.
      *
      * @param model
-     *     the artifact model
+     *            the artifact model
      * @return the artifact model's description
      */
     public static String getArtifactDescription(Model model) {
@@ -132,19 +133,15 @@ public class ArtifactGeneratorToscaParser {
     }
 
     /**
-     * Initialises the group filtering and mapping configuration.
+     * Initialises the group filtering and TOSCA mapping configuration.
      * 
+     * @param configLocation
+     *            the pathname to the JSON config file
      * @throws FileNotFoundException
-     *
+     *             if the file cannot be opened for reading
      */
-    public static void initGroupFilterConfiguration() throws FileNotFoundException {
-        log.debug("Getting Filter Types Configuration");
-        String configLocation = System.getProperty(PROPERTY_GROUP_FILTERS_CONFIG_FILE);
-        if (configLocation == null) {
-            throw new IllegalArgumentException(
-                    String.format(GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND, PROPERTY_GROUP_FILTERS_CONFIG_FILE));
-        }
-
+    public static void initToscaMappingsConfiguration(String configLocation) throws FileNotFoundException {
+        log.debug("Getting TOSCA Mappings Configuration");
         File file = new File(configLocation);
         if (!file.exists()) {
             throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGFILE_NOT_FOUND, configLocation));
@@ -152,8 +149,10 @@ public class ArtifactGeneratorToscaParser {
 
         BufferedReader bufferedReader = new BufferedReader(new FileReader(configLocation));
         GroupConfiguration config = new Gson().fromJson(bufferedReader, GroupConfiguration.class);
-        WidgetConfigurationUtil.setSupportedInstanceGroups(config.getInstanceGroupTypes());
-        WidgetConfigurationUtil.setWidgetMappings(config.getWidgetMappings());
+        if (config != null) {
+            WidgetConfigurationUtil.setSupportedInstanceGroups(config.getInstanceGroupTypes());
+            WidgetConfigurationUtil.setWidgetMappings(config.getWidgetMappings());
+        }
     }
 
     /**
@@ -182,9 +181,9 @@ public class ArtifactGeneratorToscaParser {
      * duplicate keys then the TOSCA Property value takes precedence.
      *
      * @param stringProps
-     *     initial Map of String property values (e.g. from the TOSCA YAML metadata section)
+     *            initial Map of String property values (e.g. from the TOSCA YAML metadata section)
      * @param toscaProps
-     *     Map of TOSCA Property Type Object values to merge in (or overwrite)
+     *            Map of TOSCA Property Type Object values to merge in (or overwrite)
      * @return a Map of the property values converted to String
      */
     public Map<String, String> mergeProperties(Map<String, String> stringProps, Map<String, Property> toscaProps) {
@@ -277,13 +276,13 @@ public class ArtifactGeneratorToscaParser {
      * Create an Instance Group Model and populate it with the supplied data.
      *
      * @param resourceModel
-     *     the Resource node template Model
+     *            the Resource node template Model
      * @param memberNodes
-     *     the Resources and Widgets belonging to the Group
+     *            the Resources and Widgets belonging to the Group
      * @param metaProperties
-     *     the metadata of the Group
+     *            the metadata of the Group
      * @param properties
-     *     the properties of the Group
+     *            the properties of the Group
      * @return the Instance Group and Member resource models
      */
     private List<Resource> processInstanceGroup(Model resourceModel, ArrayList<NodeTemplate> memberNodes,
@@ -367,6 +366,8 @@ public class ArtifactGeneratorToscaParser {
     private void processGroupMembers(Resource group, NodeTemplate member) {
         Resource resource = Model.getModelFor(member.getType());
 
+        log.debug(member.getType() + " mapped to " + resource);
+
         if (resource.getWidgetType() == Type.L3_NET) {
             // An l3-network inside a vf-module is treated as a Widget
             resource.setIsResource(false);
@@ -384,7 +385,7 @@ public class ArtifactGeneratorToscaParser {
      * Create a Map of property name against String property value from the input Map
      *
      * @param inputMap
-     *     The input Map
+     *            The input Map
      * @return Map of property name against String property value
      */
     private Map<String, String> populateStringProperties(Map<String, Property> inputMap) {
@@ -397,13 +398,13 @@ public class ArtifactGeneratorToscaParser {
      * is ProvidingService then return true, otherwise return false.
      *
      * @param resourceModel
-     *     parent Resource
+     *            parent Resource
      * @param metaData
-     *     for populating the Resource IDs
+     *            for populating the Resource IDs
      * @param resourceNode
-     *     any Model (will be ignored if not a Resource)
+     *            any Model (will be ignored if not a Resource)
      * @param nodeProperties
-     *     the node properties
+     *            the node properties
      * @return whether or not a ProvidingService was processed
      */
     private boolean processModel(Model resourceModel, Metadata metaData, Resource resourceNode,
index fc5acda..19b3d80 100644 (file)
@@ -80,9 +80,16 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
             return createErrorData(e);
         }
 
+        String configLocation = System.getProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE);
+        if (configLocation == null) {
+            throw new IllegalArgumentException(
+                    String.format(ArtifactGeneratorToscaParser.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND,
+                            ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE));
+        }
+
         try {
             ArtifactGeneratorToscaParser.initWidgetConfiguration();
-            ArtifactGeneratorToscaParser.initGroupFilterConfiguration();
+            ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(configLocation);
             ISdcCsarHelper csarHelper =
                     SdcToscaParserFactory.getInstance().getSdcCsarHelper(csarPath.toAbsolutePath().toString());
             return generateAllArtifacts(validateServiceVersion(additionalParams), csarHelper);
@@ -198,10 +205,11 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
             }
         } else {
             for (Group group : serviceGroups) {
-                if (group.getMembers().contains(nodeTemplate.getName())
+                ArrayList<String> members = group.getMembers();
+                if (members != null && members.contains(nodeTemplate.getName())
                         && WidgetConfigurationUtil.isSupportedInstanceGroup(group.getType())) {
                     log.debug(String.format("Adding group %s (type %s) with members %s", group.getName(),
-                            group.getType(), group.getMembers()));
+                            group.getType(), members));
 
                     Resource groupModel = parser.createInstanceGroupModel(
                             parser.mergeProperties(group.getMetadata().getAllProperties(), group.getProperties()));
@@ -219,10 +227,12 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
 
         Resource model = Model.getModelFor(nodeTypeName, nodeTemplate.getMetaData().getValue("type"));
 
-        Metadata metadata = nodeTemplate.getMetaData();
-        if (metadata != null && parser.hasAllottedResource(metadata.getAllProperties())) {
-            if (model.getWidgetType() == Type.VF) {
-                model = new Resource(Type.ALLOTTED_RESOURCE, true);
+        if (model != null) {
+            Metadata metadata = nodeTemplate.getMetaData();
+            if (metadata != null && parser.hasAllottedResource(metadata.getAllProperties())) {
+                if (model.getWidgetType() == Type.VF) {
+                    model = new Resource(Type.ALLOTTED_RESOURCE, true);
+                }
             }
         }
 
index 9af6e8d..5298f08 100644 (file)
@@ -18,6 +18,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.babel.xml.generator.data;
 
 import java.util.Collections;
@@ -64,6 +65,9 @@ public class WidgetConfigurationUtil {
 
     public static void setWidgetMappings(List<WidgetMapping> mappings) {
         for (WidgetMapping mapping : mappings) {
+            if (mapping.prefix == null || mapping.widget == null) {
+                throw new IllegalArgumentException("Incomplete widget mapping specified: " + mapping);
+            }
             Resource resource = new Resource(Widget.Type.valueOf(mapping.widget), mapping.deleteFlag);
             resource.setIsResource(mapping.type.equalsIgnoreCase("resource"));
             typeToWidget.put(mapping.prefix, resource);
index 2157728..dd46626 100644 (file)
@@ -25,9 +25,23 @@ import java.util.Map;
 
 public class WidgetMapping {
 
-    String prefix;
+    String prefix = null;
     String type = "resource"; // Default type is Resource (not Widget)
-    String widget;
-    boolean deleteFlag;
+    String widget = null;
+    boolean deleteFlag = true;
     Map<String, Object> properties;
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public void setWidget(String widgetName) {
+        this.widget = widgetName;
+    }
+
+    @Override
+    public String toString() {
+        return "WidgetMapping [prefix=" + prefix + ", type=" + type + ", widget=" + widget + ", deleteFlag="
+                + deleteFlag + ", properties=" + properties + "]";
+    }
 }
index dffff62..d6a9405 100644 (file)
@@ -129,6 +129,11 @@ public class Resource extends Model {
         return type;
     }
 
+    @Override
+    public String toString() {
+        return "Widget type " + getWidgetType() + ", isResource=" + isResource() + ", deleteFlag=" + deleteFlag;
+    }
+
     private void addVolumeWidget(Widget widget) {
         if (vserver != null) {
             vserver.addWidget(widget);
index 1f5d420..b845b8f 100644 (file)
@@ -5,4 +5,4 @@ server.contextPath=/services/babel-service
 
 logging.config=${CONFIG_HOME}/logback.xml
 
-groupfilter.config=${CONFIG_HOME}/tosca-mappings.json
+tosca.mappings.config=${CONFIG_HOME}/tosca-mappings.json
index d7519c0..a538373 100644 (file)
@@ -2,8 +2,8 @@
  * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 European Software Marketing Ltd.
+ * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2019 European Software Marketing Ltd.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ import java.util.List;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
+import org.onap.aai.babel.xml.generator.data.WidgetMapping;
 import org.onap.aai.babel.xml.generator.model.Resource;
 import org.onap.aai.babel.xml.generator.model.Widget.Type;
 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
@@ -59,7 +60,6 @@ public class TestArtifactGeneratorToscaParser {
     }
 
     /**
-     *
      * Add a CR (a type of Resource which is not a Providing Service) to a Resource Model.
      */
     @Test(expected = IllegalArgumentException.class)
@@ -70,6 +70,26 @@ public class TestArtifactGeneratorToscaParser {
         new ArtifactGeneratorToscaParser(null).processResourceModels(dummyResource, nodeTemplateList);
     }
 
+    /**
+     * Initialise the Artifact Generator Widget Mapping config with incomplete data.
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testToscaMappingWithoutType() {
+        WidgetMapping invalidMapping = new WidgetMapping();
+        invalidMapping.setType(null);
+        WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
+    }
+
+    /**
+     * Initialise the Artifact Generator Widget Mapping config with incomplete data.
+     */
+    @Test(expected = IllegalArgumentException.class)
+    public void testToscaMappingWithoutWidget() {
+        WidgetMapping invalidMapping = new WidgetMapping();
+        invalidMapping.setWidget(null);
+        WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
+    }
+
     /**
      * Process a dummy Group object for a Service Resource.
      */
@@ -104,9 +124,9 @@ public class TestArtifactGeneratorToscaParser {
      * sdc-tosca parser.
      *
      * @param name
-     *     name of the NodeTemplate
+     *            name of the NodeTemplate
      * @param type
-     *     type of the NodeTemplate
+     *            type of the NodeTemplate
      * @return a new NodeTemplate object
      */
     private NodeTemplate buildNodeTemplate(String name, String type) {
index bcd1e8a..4921490 100644 (file)
@@ -126,7 +126,7 @@ public class CsarToXmlConverterTest {
     }
 
     /**
-     * Test that an Exception is thrown when the Artifact Generator's Group Filter properties are not present.
+     * Test that an Exception is thrown when the Artifact Generator's TOSCA Mappings configuration file is not present.
      *
      * @throws CsarConverterException
      *             if there is an error either extracting the YAML files or generating XML artifacts
@@ -134,13 +134,13 @@ public class CsarToXmlConverterTest {
      *             if an I/O exception occurs
      */
     @Test
-    public void generateXmlFromCsarFilterTypesSystemPropertyNotSet() throws CsarConverterException, IOException {
-        exception.expect(CsarConverterException.class);
+    public void generateXmlFromCsarMappingSystemPropertyNotSet() throws CsarConverterException, IOException {
+        exception.expect(IllegalArgumentException.class);
         exception.expectMessage("Cannot generate artifacts. System property "
-                + ArtifactGeneratorToscaParser.PROPERTY_GROUP_FILTERS_CONFIG_FILE + " not configured");
+                + ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE + " not configured");
 
         // Unset the required system property
-        System.clearProperty(ArtifactGeneratorToscaParser.PROPERTY_GROUP_FILTERS_CONFIG_FILE);
+        System.clearProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE);
         converter.generateXmlFromCsar(CsarTest.SD_WAN_CSAR_FILE.getContent(), CsarTest.SD_WAN_CSAR_FILE.getName(),
                 SERVICE_VERSION);
     }
index 445dd84..01f62cf 100644 (file)
@@ -63,8 +63,8 @@ public class ArtifactTestUtils {
         System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE,
                 getResourcePath(Resources.ARTIFACT_GENERATOR_CONFIG));
 
-        System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_GROUP_FILTERS_CONFIG_FILE,
-                getResourcePath(Resources.FILTER_TYPES_CONFIG));
+        System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE,
+                getResourcePath(Resources.TOSCA_MAPPING_CONFIG));
     }
 
     /**
index 199b3cd..bbd663d 100644 (file)
@@ -26,6 +26,6 @@ package org.onap.aai.babel.util;
 public class Resources {
 
     public static final String ARTIFACT_GENERATOR_CONFIG = "artifact-generator.properties";
-    public static final String FILTER_TYPES_CONFIG = "tosca-mappings.json";
+    public static final String TOSCA_MAPPING_CONFIG = "tosca-mappings.json";
 
 }
index 3d5e841..8d1a045 100644 (file)
@@ -65,7 +65,13 @@ public class TestModel {
         ArtifactTestUtils utils = new ArtifactTestUtils();
         utils.setGeneratorSystemProperties();
 
-        ArtifactGeneratorToscaParser.initGroupFilterConfiguration();
+        String configLocation = System.getProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE);
+        if (configLocation == null) {
+            throw new IllegalArgumentException(
+                    String.format(ArtifactGeneratorToscaParser.GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND, ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE));
+        }
+        
+        ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(configLocation);
         utils.loadWidgetToUuidMappings();
 
         anonymousModel = new Model() {