aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authormark.j.leonard <mark.j.leonard@gmail.com>2019-01-28 11:42:54 +0000
committermark.j.leonard <mark.j.leonard@gmail.com>2019-01-30 14:05:06 +0000
commit7fcc74469c941c1834cd02b54ff5ca88a53bf83b (patch)
tree3d9c130fb098cb996d2c8db4a8b9f57501c393b6 /src/main/java/org
parent6833fb0a9a3f8c26688ad5c323eb266827b707c2 (diff)
Load type mappings from a group configuration file
Change the filter-types.properties file: re-implement to use JSON content. Remove the System Property that defines the location of the file and add this to the Spring application properties. Initialise the type-to-model mappings using the key=value pairs from this JSON content. Refactor existing Junit tests to remove duplicated resource loading code. Change-Id: Idb2e962fe5cae39b70cc8cf16053d0a253f4fac0 Issue-ID: AAI-2121 Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java65
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java12
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.java45
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java46
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Model.java39
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java7
6 files changed, 139 insertions, 75 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 615ad1e..505afbf 100644
--- a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
+++ b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java
@@ -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.
@@ -20,8 +20,12 @@
*/
package org.onap.aai.babel.parser;
+import com.google.gson.Gson;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -32,6 +36,7 @@ import java.util.Properties;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.xml.generator.data.GroupConfiguration;
import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
import org.onap.aai.babel.xml.generator.model.AllotedResource;
import org.onap.aai.babel.xml.generator.model.InstanceGroup;
@@ -82,7 +87,7 @@ public class ArtifactGeneratorToscaParser {
* Constructs using csarHelper
*
* @param csarHelper
- * The csar helper
+ * The csar helper
*/
public ArtifactGeneratorToscaParser(ISdcCsarHelper csarHelper) {
this.csarHelper = csarHelper;
@@ -92,7 +97,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) {
@@ -130,26 +135,28 @@ public class ArtifactGeneratorToscaParser {
}
/**
- * Initialises the group filter configuration.
+ * Initialises the group filtering and mapping configuration.
+ *
+ * @throws FileNotFoundException
*
- * @throws IOException
*/
- public static void initGroupFilterConfiguration() throws IOException {
- log.debug("Getting Filter Tyoes Configuration");
+ public static void initGroupFilterConfiguration() throws FileNotFoundException {
+ log.debug("Getting Filter Types Configuration");
String configLocation = System.getProperty(PROPERTY_GROUP_FILTERS_CONFIG_FILE);
- if (configLocation != null) {
- File file = new File(configLocation);
- if (file.exists()) {
- Properties properties = new Properties();
- properties.load(new FileInputStream(file));
- WidgetConfigurationUtil.setFilterConfig(properties);
- } else {
- throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGFILE_NOT_FOUND, configLocation));
- }
- } else {
+ if (configLocation == null) {
throw new IllegalArgumentException(
String.format(GENERATOR_AAI_CONFIGLOCATION_NOT_FOUND, PROPERTY_GROUP_FILTERS_CONFIG_FILE));
}
+
+ File file = new File(configLocation);
+ if (!file.exists()) {
+ throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGFILE_NOT_FOUND, configLocation));
+ }
+
+ BufferedReader bufferedReader = new BufferedReader(new FileReader(configLocation));
+ GroupConfiguration config = new Gson().fromJson(bufferedReader, GroupConfiguration.class);
+ WidgetConfigurationUtil.setSupportedInstanceGroups(config.getInstanceGroupTypes());
+ WidgetConfigurationUtil.setTypeMappings(config.getToscaToWidgetMappings());
}
/**
@@ -178,9 +185,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) {
@@ -278,13 +285,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,
@@ -379,7 +386,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) {
@@ -392,13 +399,13 @@ public class ArtifactGeneratorToscaParser {
* is ProvidingService 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 prcoessed
*/
private boolean processModel(Model resourceModel, Metadata metaData, Model 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 531a044..d6d0a1e 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
@@ -102,7 +102,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
*
* @param serviceVersion
* @param csarHelper
- * interface to the TOSCA parser
+ * interface to the TOSCA parser
* @return the generated Artifacts (containing XML models)
*/
private GenerationData generateAllArtifacts(final String serviceVersion, ISdcCsarHelper csarHelper) {
@@ -265,7 +265,7 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
* Method to generate the artifact name for an AAI model.
*
* @param model
- * AAI artifact model
+ * AAI artifact model
* @return Model artifact name
*/
private String getArtifactName(Model model) {
@@ -289,9 +289,9 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
* Create Resource artifact model from the AAI xml model string.
*
* @param resourceModel
- * Model of the resource artifact
+ * Model of the resource artifact
* @param aaiResourceModel
- * AAI model as string
+ * AAI model as string
* @return Generated {@link Artifact} model for the resource
*/
private Artifact getResourceArtifact(Model resourceModel, String aaiResourceModel) {
@@ -321,9 +321,9 @@ public class AaiArtifactGenerator implements ArtifactGenerator {
* Create Service artifact model from the AAI XML model.
*
* @param serviceModel
- * Model of the service artifact
+ * Model of the service artifact
* @param aaiServiceModel
- * AAI model as string
+ * AAI model as string
* @return Generated {@link Artifact} model for the service
*/
private Artifact getServiceArtifact(Service serviceModel, String aaiServiceModel) {
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.java b/src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.java
new file mode 100644
index 0000000..9223f27
--- /dev/null
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.java
@@ -0,0 +1,45 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.aai.babel.xml.generator.data;
+
+import java.util.List;
+import java.util.Map;
+
+public class GroupConfiguration {
+
+ /**
+ * Names of Instance Groups that will be processed (not filtered out).
+ */
+ private List<String> instanceGroupTypes;
+
+ /**
+ * Mapping from TOSCA type to Widget Model.
+ */
+ private Map<String, String> toscaToWidgetMappings;
+
+ public List<String> getInstanceGroupTypes() {
+ return instanceGroupTypes;
+ }
+
+ public Map<String, String> getToscaToWidgetMappings() {
+ return toscaToWidgetMappings;
+ }
+}
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 9f8cbf8..30b6c8e 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
@@ -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.
@@ -20,15 +20,19 @@
*/
package org.onap.aai.babel.xml.generator.data;
-import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
+import org.onap.aai.babel.xml.generator.model.Model;
public class WidgetConfigurationUtil {
private static Properties config;
private static List<String> instanceGroups = Collections.emptyList();
+ private static Map<String, Class<? extends Model>> typeToModel = new HashMap<>();
/*
* Private constructor to prevent instantiation
@@ -45,14 +49,38 @@ public class WidgetConfigurationUtil {
WidgetConfigurationUtil.config = config;
}
- public static void setFilterConfig(Properties properties) {
- String instanceGroupsList = (String) properties.get("AAI.instance-group-types");
- if (instanceGroupsList != null) {
- instanceGroups = Arrays.asList(instanceGroupsList.split(","));
- }
- }
+ public static void setSupportedInstanceGroups(List<String> supportedInstanceGroups) {
+ instanceGroups = supportedInstanceGroups;
+ }
public static boolean isSupportedInstanceGroup(String groupType) {
return instanceGroups.contains(groupType);
}
+
+ /**
+ * Create the mappings from TOSCA type to Widget type. The Properties store a set of TOSCA type prefix Strings.
+ * These keys take a single class name (String), which is used to map to a Widget Class in the Model.
+ *
+ * @param map
+ * the key/value pairs of TOSCA type and Class name
+ */
+ @SuppressWarnings("unchecked")
+ public static void setTypeMappings(Map<String, String> map) {
+ for (Entry<String, String> entry : map.entrySet()) {
+ final String toscaType = entry.getKey();
+ final String javaBean = entry.getValue();
+ final String modelClassName = Model.class.getPackage().getName() + "." + javaBean;
+ try {
+ typeToModel.put(toscaType, (Class<? extends Model>) Class.forName(modelClassName));
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException(
+ String.format("Unsupported type \"%s\" for TOSCA mapping %s: no class found for %s", //
+ javaBean, toscaType, modelClassName));
+ }
+ }
+ }
+
+ public static Class<? extends Model> getModelFromType(String typePrefix) {
+ return typeToModel.get(typePrefix);
+ }
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
index 7b2fc42..0e2b8d5 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java
@@ -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.
@@ -29,6 +29,7 @@ import java.util.Optional;
import java.util.Set;
import org.onap.aai.babel.logging.ApplicationMsgs;
import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
import org.onap.aai.babel.xml.generator.error.IllegalAccessException;
import org.onap.aai.babel.xml.generator.types.Cardinality;
import org.onap.aai.babel.xml.generator.types.ModelType;
@@ -40,22 +41,6 @@ public abstract class Model {
private static Logger log = LogHelper.INSTANCE;
- private static Map<String, Class<? extends Model>> typeToModel = new HashMap<>();
- static {
- typeToModel.put("org.openecomp.resource.vf.allottedResource", AllotedResource.class);
- typeToModel.put("org.openecomp.resource.vfc.AllottedResource", ProvidingService.class);
- typeToModel.put("org.openecomp.resource.vfc", VServerWidget.class);
- typeToModel.put("org.openecomp.resource.cp", LIntfWidget.class);
- typeToModel.put("org.openecomp.cp", LIntfWidget.class);
- typeToModel.put("org.openecomp.resource.vl", L3Network.class);
- typeToModel.put("org.openecomp.resource.vf", VirtualFunction.class);
- typeToModel.put("org.openecomp.groups.vfmodule", VfModule.class);
- typeToModel.put("org.openecomp.groups.VfModule", VfModule.class);
- typeToModel.put("org.openecomp.resource.vfc.nodes.heat.cinder", VolumeWidget.class);
- typeToModel.put("org.openecomp.nodes.PortMirroringConfiguration", Configuration.class);
- typeToModel.put("org.openecomp.resource.cr.Kk1806Cr1", CR.class);
- }
-
private enum ModelIdentification {
ID("vfModuleModelInvariantUUID", "serviceInvariantUUID", "resourceInvariantUUID", "invariantUUID",
"providing_service_invariant_uuid") {
@@ -154,7 +139,7 @@ public abstract class Model {
private static Optional<Model> getModelFromType(String typePrefix) {
Optional<Model> modelToBeReturned = Optional.empty();
- Class<? extends Model> clazz = typeToModel.get(typePrefix);
+ Class<? extends Model> clazz = WidgetConfigurationUtil.getModelFromType(typePrefix);
if (clazz != null) {
try {
modelToBeReturned = Optional.ofNullable(clazz.getConstructor().newInstance());
@@ -197,8 +182,8 @@ public abstract class Model {
* @return the cardinality
*/
public Cardinality getCardinality() {
- org.onap.aai.babel.xml.generator.types.Model model = this.getClass()
- .getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
+ org.onap.aai.babel.xml.generator.types.Model model =
+ this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
return model.cardinality();
}
@@ -208,8 +193,8 @@ public abstract class Model {
* @return the delete flag
*/
public boolean getDeleteFlag() {
- org.onap.aai.babel.xml.generator.types.Model model = this.getClass()
- .getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
+ org.onap.aai.babel.xml.generator.types.Model model =
+ this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
return model.dataDeleteFlag();
}
@@ -258,8 +243,8 @@ public abstract class Model {
* @return the widget version id
*/
public String getWidgetId() {
- org.onap.aai.babel.xml.generator.types.Model model = this.getClass()
- .getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
+ org.onap.aai.babel.xml.generator.types.Model model =
+ this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
return Widget.getWidget(model.widget()).getId();
}
@@ -269,8 +254,8 @@ public abstract class Model {
* @return the invariant id
*/
public String getWidgetInvariantId() {
- org.onap.aai.babel.xml.generator.types.Model model = this.getClass()
- .getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
+ org.onap.aai.babel.xml.generator.types.Model model =
+ this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
return Widget.getWidget(model.widget()).getWidgetId();
}
diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java
index d78e2e6..963d9e2 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java
@@ -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.
@@ -109,8 +109,7 @@ public abstract class Widget extends Model {
}
public String getId() {
- Properties properties = WidgetConfigurationUtil.getConfig();
- String id = properties.getProperty(ArtifactType.AAI.name() + ".model-version-id." + getName());
+ String id = WidgetConfigurationUtil.getConfig().getProperty(ArtifactType.AAI.name() + ".model-version-id." + getName());
if (id == null) {
throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
ArtifactType.AAI.name() + ".model-version-id." + getName()));