diff options
author | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-02-11 17:44:17 +0000 |
---|---|---|
committer | mark.j.leonard <mark.j.leonard@gmail.com> | 2019-02-11 18:16:08 +0000 |
commit | fc779f51a624bfddc68328bf3fd3c74594ef31f6 (patch) | |
tree | 397e3aa3e0f225b01a9845537e8ea2f8cfacf4ec /src/main/java | |
parent | a583d474260f071cb2ee465ec76a277240575a21 (diff) |
Rename the groupfilter.config System Property
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>
Diffstat (limited to 'src/main/java')
5 files changed, 73 insertions, 39 deletions
diff --git a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java index 7dfc807..50c6edf 100644 --- a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java +++ b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java @@ -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, diff --git a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java index fc5acda..19b3d80 100644 --- a/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java +++ b/src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java @@ -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); + } } } diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java index 9af6e8d..5298f08 100644 --- a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java +++ b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java @@ -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); diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java index 2157728..dd46626 100644 --- a/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java +++ b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java @@ -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 + "]"; + } } diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java index dffff62..d6a9405 100644 --- a/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java +++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java @@ -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); |