From 1954294aed95c2db4eb2659dcef91248535de079 Mon Sep 17 00:00:00 2001 From: "mark.j.leonard" Date: Tue, 5 Feb 2019 14:24:33 +0000 Subject: Replace Resource sub-classes with configuration Delete the sub-classes of the Resource (internal Model class) and replace the annotated properties of these classes with TOSCA-to-Model mappping data loaded from the JSON configuration. Change-Id: I56d5d9d4893be45eb42ae65099ea9abe5f4409b9 Issue-ID: AAI-2121 Signed-off-by: mark.j.leonard --- .../babel/parser/ArtifactGeneratorToscaParser.java | 144 ++++++++++----------- .../xml/generator/api/AaiArtifactGenerator.java | 43 ++++-- .../xml/generator/data/GroupConfiguration.java | 12 +- .../generator/data/WidgetConfigurationUtil.java | 40 ++---- .../babel/xml/generator/data/WidgetMapping.java | 33 +++++ .../xml/generator/logging/CategoryLogLevel.java | 29 ----- .../babel/xml/generator/model/AllotedResource.java | 28 ---- .../org/onap/aai/babel/xml/generator/model/CR.java | 28 ---- .../babel/xml/generator/model/Configuration.java | 28 ---- .../babel/xml/generator/model/InstanceGroup.java | 28 ---- .../aai/babel/xml/generator/model/L3Network.java | 28 ---- .../onap/aai/babel/xml/generator/model/Model.java | 63 +++------ .../xml/generator/model/ProvidingService.java | 28 ---- .../aai/babel/xml/generator/model/Resource.java | 125 ++++++++++++++++-- .../aai/babel/xml/generator/model/Service.java | 12 ++ .../aai/babel/xml/generator/model/VfModule.java | 109 ---------------- .../babel/xml/generator/model/VirtualFunction.java | 28 ---- .../onap/aai/babel/xml/generator/model/Widget.java | 42 +++--- .../parser/TestArtifactGeneratorToscaParser.java | 16 ++- .../aai/babel/xml/generator/model/TestModel.java | 83 +++++++----- .../babel/xml/generator/model/TestVfModule.java | 44 +++---- src/test/resources/tosca-mappings.json | 70 +++++++--- 22 files changed, 462 insertions(+), 599 deletions(-) create mode 100644 src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java delete mode 100644 src/main/java/org/onap/aai/babel/xml/generator/logging/CategoryLogLevel.java delete mode 100644 src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResource.java delete mode 100644 src/main/java/org/onap/aai/babel/xml/generator/model/CR.java delete mode 100644 src/main/java/org/onap/aai/babel/xml/generator/model/Configuration.java delete mode 100644 src/main/java/org/onap/aai/babel/xml/generator/model/InstanceGroup.java delete mode 100644 src/main/java/org/onap/aai/babel/xml/generator/model/L3Network.java delete mode 100644 src/main/java/org/onap/aai/babel/xml/generator/model/ProvidingService.java delete mode 100644 src/main/java/org/onap/aai/babel/xml/generator/model/VfModule.java delete mode 100644 src/main/java/org/onap/aai/babel/xml/generator/model/VirtualFunction.java 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 505afbf..7dfc807 100644 --- a/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java +++ b/src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.babel.parser; import com.google.gson.Gson; @@ -38,14 +39,10 @@ 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; -import org.onap.aai.babel.xml.generator.model.L3NetworkWidget; import org.onap.aai.babel.xml.generator.model.Model; -import org.onap.aai.babel.xml.generator.model.ProvidingService; import org.onap.aai.babel.xml.generator.model.Resource; -import org.onap.aai.babel.xml.generator.model.VfModule; import org.onap.aai.babel.xml.generator.model.Widget; +import org.onap.aai.babel.xml.generator.model.Widget.Type; import org.onap.aai.cl.api.Logger; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.Group; @@ -87,7 +84,7 @@ public class ArtifactGeneratorToscaParser { * Constructs using csarHelper * * @param csarHelper - * The csar helper + * The csar helper */ public ArtifactGeneratorToscaParser(ISdcCsarHelper csarHelper) { this.csarHelper = csarHelper; @@ -97,7 +94,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) { @@ -152,11 +149,11 @@ public class ArtifactGeneratorToscaParser { 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()); + WidgetConfigurationUtil.setWidgetMappings(config.getWidgetMappings()); } /** @@ -185,9 +182,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 mergeProperties(Map stringProps, Map toscaProps) { @@ -198,7 +195,7 @@ public class ArtifactGeneratorToscaParser { } public Resource createInstanceGroupModel(Map properties) { - Resource groupModel = new InstanceGroup(); + Resource groupModel = new Resource(Type.INSTANCE_GROUP, true); groupModel.populateModelIdentificationInformation(properties); return groupModel; } @@ -207,28 +204,14 @@ public class ArtifactGeneratorToscaParser { * @param model * @param relation */ - public void addRelatedModel(final Model model, final Model relation) { - if (relation instanceof Resource) { - model.addResource((Resource) relation); + public void addRelatedModel(final Model model, final Resource relation) { + if (relation.isResource()) { + model.addResource(relation); } else { - model.addWidget((Widget) relation); + model.addWidget(Widget.getWidget(relation.getWidgetType())); } } - public String normaliseNodeTypeName(NodeTemplate nodeType) { - String nodeTypeName = nodeType.getType(); - Metadata metadata = nodeType.getMetaData(); - if (metadata != null && hasAllottedResource(metadata.getAllProperties())) { - if (nodeType.getType().contains("org.openecomp.resource.vf.")) { - nodeTypeName = "org.openecomp.resource.vf.allottedResource"; - } - if (nodeType.getType().contains("org.openecomp.resource.vfc.")) { - nodeTypeName = "org.openecomp.resource.vfc.AllottedResource"; - } - } - return nodeTypeName; - } - public boolean hasAllottedResource(Map metadata) { return ALLOTTED_RESOURCE.equals(metadata.get(CATEGORY)); } @@ -252,8 +235,8 @@ public class ArtifactGeneratorToscaParser { // Process each VF Group for (Group serviceGroup : serviceGroups) { Model groupModel = Model.getModelFor(serviceGroup.getType()); - if (groupModel instanceof VfModule) { - processVfModule(resources, resourceModel, serviceGroup, serviceNode, (VfModule) groupModel); + if (groupModel.getWidgetType() == Type.VFMODULE) { + processVfModule(resources, resourceModel, serviceGroup, serviceNode, (Resource) groupModel); } } } @@ -266,15 +249,24 @@ public class ArtifactGeneratorToscaParser { boolean foundProvidingService = false; for (NodeTemplate resourceNodeTemplate : resourceNodeTemplates) { - String nodeTypeName = normaliseNodeTypeName(resourceNodeTemplate); - Metadata metaData = resourceNodeTemplate.getMetaData(); - String metaDataType = Optional.ofNullable(metaData).map(m -> m.getValue("type")).orElse(nodeTypeName); - Model resourceNode = Model.getModelFor(nodeTypeName, metaDataType); - foundProvidingService |= - processModel(resourceModel, metaData, resourceNode, resourceNodeTemplate.getProperties()); + String nodeTypeName = resourceNodeTemplate.getType(); + Metadata metadata = resourceNodeTemplate.getMetaData(); + String metaDataType = Optional.ofNullable(metadata).map(m -> m.getValue("type")).orElse(nodeTypeName); + Resource model = Model.getModelFor(nodeTypeName, metaDataType); + + if (metadata != null && hasAllottedResource(metadata.getAllProperties())) { + if (model.getWidgetType() == Type.VSERVER) { + model = new Resource(Type.ALLOTTED_RESOURCE, false); + Map props = new HashMap<>(); + props.put("providingService", true); + model.setProperties(props); + } + } + + foundProvidingService |= processModel(resourceModel, metadata, model, resourceNodeTemplate.getProperties()); } - if (resourceModel instanceof AllotedResource && !foundProvidingService) { + if (resourceModel.getWidgetType() == Type.ALLOTTED_RESOURCE && !foundProvidingService) { final String modelInvariantId = resourceModel.getModelId(); throw new IllegalArgumentException(String.format(GENERATOR_AAI_PROVIDING_SERVICE_MISSING, modelInvariantId == null ? "" : modelInvariantId)); @@ -285,13 +277,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 processInstanceGroup(Model resourceModel, ArrayList memberNodes, @@ -320,11 +312,11 @@ public class ArtifactGeneratorToscaParser { List resources = new ArrayList<>(); for (NodeTemplate nodeTemplate : memberNodes) { - String nodeTypeName = normaliseNodeTypeName(nodeTemplate); + String nodeTypeName = nodeTemplate.getType(); final String metadataType = nodeTemplate.getMetaData().getValue("type"); log.debug(String.format("Get model for %s (metadata type %s)", nodeTypeName, metadataType)); - Model memberModel = Model.getModelFor(nodeTypeName, metadataType); + Resource memberModel = Model.getModelFor(nodeTypeName, metadataType); if (memberModel != null) { memberModel.populateModelIdentificationInformation(nodeTemplate.getMetaData().getAllProperties()); @@ -333,8 +325,8 @@ public class ArtifactGeneratorToscaParser { memberModel.getClass().getSuperclass().getSimpleName(), memberModel.getClass(), nodeTypeName)); addRelatedModel(groupModel, memberModel); - if (memberModel instanceof Resource) { - resources.add((Resource) memberModel); + if (memberModel.isResource()) { + resources.add(memberModel); } } } @@ -342,7 +334,7 @@ public class ArtifactGeneratorToscaParser { } private void processVfModule(List resources, Model vfModel, Group groupDefinition, - NodeTemplate serviceNode, VfModule groupModel) { + NodeTemplate serviceNode, Resource groupModel) { groupModel.populateModelIdentificationInformation( mergeProperties(groupDefinition.getMetadata().getAllProperties(), groupDefinition.getProperties())); @@ -355,7 +347,7 @@ public class ArtifactGeneratorToscaParser { } } - private void processVfModuleGroup(VfModule groupModel, List members) { + private void processVfModuleGroup(Resource groupModel, List members) { if (members != null && !members.isEmpty()) { // Get names of the members of the service group List memberNames = members.stream().map(NodeTemplate::getName).collect(Collectors.toList()); @@ -366,16 +358,22 @@ public class ArtifactGeneratorToscaParser { } } - private void processGroupMembers(Model group, NodeTemplate member) { - Model resourceNode; - // L3-network inside vf-module to be generated as Widget a special handling. - if (member.getType().contains("org.openecomp.resource.vl")) { - resourceNode = new L3NetworkWidget(); - } else { - resourceNode = Model.getModelFor(member.getType()); + /** + * Process the Widget members of a VF Module Group + * + * @param group + * @param member + */ + private void processGroupMembers(Resource group, NodeTemplate member) { + Resource resource = Model.getModelFor(member.getType()); + + if (resource.getWidgetType() == Type.L3_NET) { + // An l3-network inside a vf-module is treated as a Widget + resource.setIsResource(false); } - if (resourceNode != null && !(resourceNode instanceof Resource)) { - Widget widget = (Widget) resourceNode; + + if (!resource.isResource()) { + Widget widget = Widget.getWidget(resource.getWidgetType()); widget.addKey(member.getName()); // Add the widget element encountered to the Group model group.addWidget(widget); @@ -386,7 +384,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 populateStringProperties(Map inputMap) { @@ -396,25 +394,27 @@ public class ArtifactGeneratorToscaParser { /** * If the specified resourceNode is a type of Resource, add it to the specified resourceModel. If the Resource type - * is ProvidingService return true, otherwise return false. + * 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 - * @return whether or not a ProvidingService was prcoessed + * the node properties + * @return whether or not a ProvidingService was processed */ - private boolean processModel(Model resourceModel, Metadata metaData, Model resourceNode, + private boolean processModel(Model resourceModel, Metadata metaData, Resource resourceNode, Map nodeProperties) { - boolean foundProvidingService = false; - if (resourceNode instanceof ProvidingService) { - foundProvidingService = true; + boolean foundProvidingService = resourceNode != null + && (boolean) Optional.ofNullable(resourceNode.getProperties().get("providingService")).orElse(false); + + if (foundProvidingService) { processProvidingService(resourceModel, resourceNode, nodeProperties); - } else if (resourceNode instanceof Resource && !(resourceNode.getWidgetType().equals(Widget.Type.L3_NET))) { + } else if (resourceNode != null && resourceNode.isResource() + && resourceNode.getWidgetType() != Widget.Type.L3_NET) { if (metaData != null) { resourceNode.populateModelIdentificationInformation(metaData.getAllProperties()); } @@ -423,7 +423,7 @@ public class ArtifactGeneratorToscaParser { return foundProvidingService; } - private void processProvidingService(Model resourceModel, Model resourceNode, + private void processProvidingService(Model resourceModel, Resource resourceNode, Map nodeProperties) { if (nodeProperties == null || nodeProperties.get("providing_service_uuid") == null || nodeProperties.get("providing_service_invariant_uuid") == null) { @@ -433,6 +433,6 @@ public class ArtifactGeneratorToscaParser { Map properties = populateStringProperties(nodeProperties); properties.put(VERSION, "1.0"); resourceNode.populateModelIdentificationInformation(properties); - resourceModel.addResource((Resource) resourceNode); + resourceModel.addResource(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 d6d0a1e..fc5acda 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 @@ -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. @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.babel.xml.generator.api; import java.io.IOException; @@ -26,6 +27,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.onap.aai.babel.logging.ApplicationMsgs; @@ -39,15 +41,16 @@ import org.onap.aai.babel.xml.generator.data.GeneratorUtil; import org.onap.aai.babel.xml.generator.data.GroupType; import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil; import org.onap.aai.babel.xml.generator.model.Model; -import org.onap.aai.babel.xml.generator.model.ProvidingService; import org.onap.aai.babel.xml.generator.model.Resource; import org.onap.aai.babel.xml.generator.model.Service; import org.onap.aai.babel.xml.generator.model.TunnelXconnectWidget; +import org.onap.aai.babel.xml.generator.model.Widget.Type; import org.onap.aai.cl.api.Logger; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; import org.slf4j.MDC; public class AaiArtifactGenerator implements ArtifactGenerator { @@ -128,7 +131,10 @@ public class AaiArtifactGenerator implements ArtifactGenerator { for (Resource resource : resources) { generateResourceArtifact(generationData, resource); for (Resource childResource : resource.getResources()) { - if (!(childResource instanceof ProvidingService)) { + boolean isProvidingService = + (boolean) Optional.ofNullable(childResource.getProperties().get("providingService")) // + .orElse(false); + if (!isProvidingService) { generateResourceArtifact(generationData, childResource); } } @@ -179,16 +185,16 @@ public class AaiArtifactGenerator implements ArtifactGenerator { private void generateModelFromNodeTemplate(ISdcCsarHelper csarHelper, Service serviceModel, List resources, final List serviceGroups, ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) { - String nodeTypeName = parser.normaliseNodeTypeName(nodeTemplate); - Model model = Model.getModelFor(nodeTypeName, nodeTemplate.getMetaData().getValue("type")); + Resource model = getModelFor(parser, nodeTemplate); + if (model != null) { if (nodeTemplate.getMetaData() != null) { model.populateModelIdentificationInformation(nodeTemplate.getMetaData().getAllProperties()); } parser.addRelatedModel(serviceModel, model); - if (model instanceof Resource) { - generateResourceModel(csarHelper, resources, parser, nodeTemplate, nodeTypeName); + if (model.isResource()) { + generateResourceModel(csarHelper, resources, parser, nodeTemplate); } } else { for (Group group : serviceGroups) { @@ -206,11 +212,26 @@ public class AaiArtifactGenerator implements ArtifactGenerator { } } - private void generateResourceModel(ISdcCsarHelper csarHelper, List resources, - ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate, String nodeTypeName) { + private Resource getModelFor(ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) { + String nodeTypeName = nodeTemplate.getType(); + log.debug("Processing resource " + nodeTypeName + ": " + nodeTemplate.getMetaData().getValue("UUID")); - Model resourceModel = Model.getModelFor(nodeTypeName, nodeTemplate.getMetaData().getValue("type")); + 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); + } + } + + return model; + } + + private void generateResourceModel(ISdcCsarHelper csarHelper, List resources, + ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) { + Resource resourceModel = getModelFor(parser, nodeTemplate); Map serviceMetadata = nodeTemplate.getMetaData().getAllProperties(); resourceModel.populateModelIdentificationInformation(serviceMetadata); 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 index 9223f27..bbc7164 100644 --- 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 @@ -18,10 +18,10 @@ * 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 { @@ -29,17 +29,17 @@ public class GroupConfiguration { * Names of Instance Groups that will be processed (not filtered out). */ private List instanceGroupTypes; - + /** - * Mapping from TOSCA type to Widget Model. + * Mapping from TOSCA type to Widget directly. */ - private Map toscaToWidgetMappings; + private List widgetMappings; public List getInstanceGroupTypes() { return instanceGroupTypes; } - public Map getToscaToWidgetMappings() { - return toscaToWidgetMappings; + public List getWidgetMappings() { + return widgetMappings; } } 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 30b6c8e..9af6e8d 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 @@ -24,15 +24,16 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; +import java.util.Optional; import java.util.Properties; -import org.onap.aai.babel.xml.generator.model.Model; +import org.onap.aai.babel.xml.generator.model.Resource; +import org.onap.aai.babel.xml.generator.model.Widget; public class WidgetConfigurationUtil { private static Properties config; private static List instanceGroups = Collections.emptyList(); - private static Map> typeToModel = new HashMap<>(); + private static Map typeToWidget = new HashMap<>(); /* * Private constructor to prevent instantiation @@ -51,36 +52,21 @@ public class WidgetConfigurationUtil { public static void setSupportedInstanceGroups(List 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 map) { - for (Entry 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) 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 Optional createModelFromType(String typePrefix) { + return Optional.ofNullable(typeToWidget.get(typePrefix)); } - public static Class getModelFromType(String typePrefix) { - return typeToModel.get(typePrefix); + public static void setWidgetMappings(List mappings) { + for (WidgetMapping mapping : mappings) { + 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 new file mode 100644 index 0000000..2157728 --- /dev/null +++ b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java @@ -0,0 +1,33 @@ +/** + * ============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.Map; + +public class WidgetMapping { + + String prefix; + String type = "resource"; // Default type is Resource (not Widget) + String widget; + boolean deleteFlag; + Map properties; +} diff --git a/src/main/java/org/onap/aai/babel/xml/generator/logging/CategoryLogLevel.java b/src/main/java/org/onap/aai/babel/xml/generator/logging/CategoryLogLevel.java deleted file mode 100644 index b6ca2d3..0000000 --- a/src/main/java/org/onap/aai/babel/xml/generator/logging/CategoryLogLevel.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 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.logging; - -public enum CategoryLogLevel { - INFO, - WARN, - DEBUG, - ERROR, - FATAL -} diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResource.java b/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResource.java deleted file mode 100644 index cecf7bd..0000000 --- a/src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResource.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 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.model; - -import org.onap.aai.babel.xml.generator.types.Cardinality; -import org.onap.aai.babel.xml.generator.types.Model; - -@Model(widget = Widget.Type.ALLOTTED_RESOURCE, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true) -public class AllotedResource extends Resource { -} diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/CR.java b/src/main/java/org/onap/aai/babel/xml/generator/model/CR.java deleted file mode 100644 index 2c50a0f..0000000 --- a/src/main/java/org/onap/aai/babel/xml/generator/model/CR.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 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.model; - -import org.onap.aai.babel.xml.generator.types.Cardinality; -import org.onap.aai.babel.xml.generator.types.Model; - -@Model(widget = Widget.Type.CR, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true) -public class CR extends Resource { -} \ No newline at end of file diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Configuration.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Configuration.java deleted file mode 100644 index 20dbea9..0000000 --- a/src/main/java/org/onap/aai/babel/xml/generator/model/Configuration.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 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.model; - -import org.onap.aai.babel.xml.generator.types.Cardinality; -import org.onap.aai.babel.xml.generator.types.Model; - -@Model(widget = Widget.Type.CONFIGURATION, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true) -public class Configuration extends Resource { -} diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/InstanceGroup.java b/src/main/java/org/onap/aai/babel/xml/generator/model/InstanceGroup.java deleted file mode 100644 index f312064..0000000 --- a/src/main/java/org/onap/aai/babel/xml/generator/model/InstanceGroup.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 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.model; - -import org.onap.aai.babel.xml.generator.types.Cardinality; -import org.onap.aai.babel.xml.generator.types.Model; - -@Model(widget = Widget.Type.INSTANCE_GROUP, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true) -public class InstanceGroup extends Resource { -} diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/L3Network.java b/src/main/java/org/onap/aai/babel/xml/generator/model/L3Network.java deleted file mode 100644 index 105c3a1..0000000 --- a/src/main/java/org/onap/aai/babel/xml/generator/model/L3Network.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 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.model; - -import org.onap.aai.babel.xml.generator.types.Cardinality; - -@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.L3_NET, cardinality = Cardinality.UNBOUNDED, - dataDeleteFlag = false) -public class L3Network extends Resource { -} 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 0e2b8d5..d4da6df 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 @@ -27,20 +27,15 @@ import java.util.Iterator; import java.util.Map; 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.model.Widget.Type; import org.onap.aai.babel.xml.generator.types.ModelType; -import org.onap.aai.cl.api.Logger; public abstract class Model { public static final String GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION = "Operation Not Supported for Widgets"; - private static Logger log = LogHelper.INSTANCE; - private enum ModelIdentification { ID("vfModuleModelInvariantUUID", "serviceInvariantUUID", "resourceInvariantUUID", "invariantUUID", "providing_service_invariant_uuid") { @@ -117,37 +112,28 @@ public abstract class Model { * Gets the object (model) corresponding to the supplied TOSCA type. * * @param toscaType - * the tosca type + * the tosca type * @return the model for the type, or null */ - public static Model getModelFor(String toscaType) { - Model model = null; + public static Resource getModelFor(String toscaType) { + Resource resource = null; if (toscaType != null && !toscaType.isEmpty()) { - model = getModelFromType(toscaType).orElseGet(() -> Model.getModelFromPrefix(toscaType)); + resource = getModelFromType(toscaType).orElseGet(() -> Model.getModelFromPrefix(toscaType)); } - return model; + return resource; } - private static Model getModelFromPrefix(String toscaType) { - Model model = null; + private static Resource getModelFromPrefix(String toscaType) { + Resource resource = null; int lastSeparator = toscaType.lastIndexOf('.'); if (lastSeparator != -1) { - model = getModelFor(toscaType.substring(0, lastSeparator)); + resource = getModelFor(toscaType.substring(0, lastSeparator)); } - return model; + return resource; } - private static Optional getModelFromType(String typePrefix) { - Optional modelToBeReturned = Optional.empty(); - Class clazz = WidgetConfigurationUtil.getModelFromType(typePrefix); - if (clazz != null) { - try { - modelToBeReturned = Optional.ofNullable(clazz.getConstructor().newInstance()); - } catch (Exception e) { - log.error(ApplicationMsgs.INVALID_CSAR_FILE, e); - } - } - return modelToBeReturned; + private static Optional getModelFromType(String typePrefix) { + return WidgetConfigurationUtil.createModelFromType(typePrefix); } /** @@ -155,16 +141,16 @@ public abstract class Model { * information. * * @param toscaType - * the TOSCA type + * the TOSCA type * @param metaDataType - * the type from the TOSCA metadata + * the type from the TOSCA metadata * @return the model for the type, or null */ - public static Model getModelFor(String toscaType, String metaDataType) { + public static Resource getModelFor(String toscaType, String metaDataType) { if ("Configuration".equals(metaDataType)) { - return new Configuration(); + return new Resource(Type.CONFIGURATION, true); } else if ("CR".equals(metaDataType)) { - return new CR(); + return new Resource(Type.CR, true); } else { return getModelFor(toscaType); } @@ -176,16 +162,9 @@ public abstract class Model { public abstract Widget.Type getWidgetType(); - /** - * Gets cardinality. - * - * @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); - return model.cardinality(); - } + public abstract Map getProperties(); + + public abstract boolean isResource(); /** * Gets delete flag. @@ -263,7 +242,7 @@ public abstract class Model { * Populate model identification information. * * @param modelIdentInfo - * the model ident info + * the model ident info */ public void populateModelIdentificationInformation(Map modelIdentInfo) { Iterator iter = modelIdentInfo.keySet().iterator(); diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/ProvidingService.java b/src/main/java/org/onap/aai/babel/xml/generator/model/ProvidingService.java deleted file mode 100644 index e25274e..0000000 --- a/src/main/java/org/onap/aai/babel/xml/generator/model/ProvidingService.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 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.model; - -import org.onap.aai.babel.xml.generator.types.Cardinality; - -@org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.ALLOTTED_RESOURCE, - cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = false) -public class ProvidingService extends Resource { -} 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 1b64907..121bc19 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 @@ -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,28 @@ */ package org.onap.aai.babel.xml.generator.model; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import org.onap.aai.babel.xml.generator.model.Widget.Type; + public class Resource extends Model { + private Type type; + private boolean deleteFlag; + private boolean isResource = true; + private Map properties = Collections.emptyMap(); + + Widget vserver = null; + boolean addlintf = false; + boolean addvolume = false; + List members; + + public Resource(Type type, boolean deleteFlag) { + this.type = type; + this.deleteFlag = deleteFlag; + } + @Override public int hashCode() { final String uuid = getModelNameVersionId(); @@ -36,20 +56,109 @@ public class Resource extends Model { return false; } + public boolean getDeleteFlag() { + return deleteFlag; + } + + public String getWidgetInvariantId() { + return Widget.getWidget(getWidgetType()).getWidgetId(); + } + + public String getWidgetId() { + return Widget.getWidget(getWidgetType()).getId(); + } + + public void setProperties(Map properties) { + this.properties = properties; + } + + @Override + public Map getProperties() { + return properties; + } + + public void setIsResource(boolean isResource) { + this.isResource = isResource; + } + + @Override + public boolean isResource() { + return isResource; + } + + public void setMembers(List members) { + this.members = members; + } + @Override public boolean addResource(Resource resource) { return resources.add(resource); } + /** + * Adds a Widget. + * + * @param widget + * the widget + * @return the boolean + */ @Override public boolean addWidget(Widget widget) { - return widgets.add(widget); + if (type == Type.VFMODULE) { + if (widget.memberOf(members)) { + if (vserver == null && widget.getId().equals(new VServerWidget().getId())) { + addVserverWidget(widget); + } else if (widget.getId().equals(new LIntfWidget().getId())) { + return addLIntfWidget(widget); + } else if (widget.getId().equals(new VolumeWidget().getId())) { + addVolumeWidget(widget); + return true; + } + if (widget.getId().equals(new OamNetwork().getId())) { + return false; + } + return widgets.add(widget); + } + return false; + } else { + return widgets.add(widget); + } } - @Override - public Widget.Type getWidgetType() { - org.onap.aai.babel.xml.generator.types.Model model = - this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class); - return model.widget(); + public Type getWidgetType() { + return type; + } + + private void addVolumeWidget(Widget widget) { + if (vserver != null) { + vserver.addWidget(widget); + } else { + addvolume = true; + } } + + /** + * @param widget + * @return + */ + private boolean addLIntfWidget(Widget widget) { + if (vserver != null) { + vserver.addWidget(widget); + return true; + } else { + addlintf = true; + return false; + } + } + + private void addVserverWidget(Widget widget) { + vserver = widget; + if (addlintf) { + vserver.addWidget(new LIntfWidget()); + } + if (addvolume) { + vserver.addWidget(new VolumeWidget()); + } + } + } diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java index 9d22e41..0815a61 100644 --- a/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java +++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Service.java @@ -20,6 +20,8 @@ */ package org.onap.aai.babel.xml.generator.model; +import java.util.Collections; +import java.util.Map; import org.onap.aai.babel.xml.generator.types.Cardinality; @org.onap.aai.babel.xml.generator.types.Model(widget = Widget.Type.SERVICE, cardinality = Cardinality.UNBOUNDED, @@ -40,4 +42,14 @@ public class Service extends Model { public Widget.Type getWidgetType() { return null; } + + @Override + public Map getProperties() { + return Collections.emptyMap(); + } + + @Override + public boolean isResource() { + return false; + } } diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VfModule.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VfModule.java deleted file mode 100644 index d6d3a2d..0000000 --- a/src/main/java/org/onap/aai/babel/xml/generator/model/VfModule.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 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.model; - -import java.util.List; -import org.onap.aai.babel.xml.generator.types.Cardinality; -import org.onap.aai.babel.xml.generator.types.Model; - -@Model(widget = Widget.Type.VFMODULE, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true) -public class VfModule extends Resource { - - Widget vserver = null; - boolean addlintf = false; - boolean addvolume = false; - - List members; - - public void setMembers(List members) { - this.members = members; - } - - /** - * Adds a Widget. - * - * @param widget the widget - * @return the boolean - */ - @Override - public boolean addWidget(Widget widget) { - if (widget.memberOf(members)) { - if (vserver == null && widget.getId().equals(new VServerWidget().getId())) { - addVserverWidget(widget); - } else if (widget.getId().equals(new LIntfWidget().getId())) { - return addLIntfWidget(widget); - } else if (widget.getId().equals(new VolumeWidget().getId())) { - addVolumeWidget(widget); - return true; - } - if (widget.getId().equals(new OamNetwork().getId())) { - return false; - } - return widgets.add(widget); - } - return false; - } - - private void addVolumeWidget(Widget widget) { - if (vserver != null) { - vserver.addWidget(widget); - } else { - addvolume = true; - } - } - - /** - * @param widget - * @return - */ - private boolean addLIntfWidget(Widget widget) { - if (vserver != null) { - vserver.addWidget(widget); - return true; - } else { - addlintf = true; - return false; - } - } - - private void addVserverWidget(Widget widget) { - vserver = widget; - if (addlintf) { - vserver.addWidget(new LIntfWidget()); - } - if (addvolume) { - vserver.addWidget(new VolumeWidget()); - } - } - - @Override - public int hashCode() { - return getModelNameVersionId().hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof Resource) { - return getModelNameVersionId().equals(((Resource) obj).getModelNameVersionId()); - } - return false; - } -} diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/VirtualFunction.java b/src/main/java/org/onap/aai/babel/xml/generator/model/VirtualFunction.java deleted file mode 100644 index be75d65..0000000 --- a/src/main/java/org/onap/aai/babel/xml/generator/model/VirtualFunction.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 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.model; - -import org.onap.aai.babel.xml.generator.types.Cardinality; -import org.onap.aai.babel.xml.generator.types.Model; - -@Model(widget = Widget.Type.VF, cardinality = Cardinality.UNBOUNDED, dataDeleteFlag = true) -public class VirtualFunction extends Resource { -} 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 963d9e2..11a9612 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 @@ -25,6 +25,7 @@ import java.util.Collection; import java.util.Collections; import java.util.EnumMap; import java.util.HashSet; +import java.util.Map; import java.util.Properties; import java.util.Set; import org.onap.aai.babel.logging.ApplicationMsgs; @@ -42,24 +43,7 @@ public abstract class Widget extends Model { "Cannot generate artifacts. Widget configuration not found for %s"; public enum Type { - SERVICE, - VF, - VFC, - VSERVER, - VOLUME, - FLAVOR, - TENANT, - VOLUME_GROUP, - LINT, - L3_NET, - VFMODULE, - IMAGE, - OAM_NETWORK, - ALLOTTED_RESOURCE, - TUNNEL_XCONNECT, - CONFIGURATION, - CR, - INSTANCE_GROUP; + SERVICE, VF, VFC, VSERVER, VOLUME, FLAVOR, TENANT, VOLUME_GROUP, LINT, L3_NET, VFMODULE, IMAGE, OAM_NETWORK, ALLOTTED_RESOURCE, TUNNEL_XCONNECT, CONFIGURATION, CR, INSTANCE_GROUP; } private static Logger log = LogHelper.INSTANCE; @@ -91,7 +75,8 @@ public abstract class Widget extends Model { /** * Gets widget. * - * @param type the type + * @param type + * the type * @return the widget */ public static Widget getWidget(Type type) { @@ -108,8 +93,14 @@ public abstract class Widget extends Model { return widget; } + @Override + public boolean isResource() { + return false; + } + public String getId() { - String id = WidgetConfigurationUtil.getConfig().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())); @@ -156,7 +147,8 @@ public abstract class Widget extends Model { /** * Equals method that compares Widget IDs. * - * @param obj the Widget object to compare + * @param obj + * the Widget object to compare * @return whether or not obj is equal to this Widget */ @Override @@ -179,7 +171,8 @@ public abstract class Widget extends Model { /** * Determine whether one or more keys belonging to this Widget appear in the specified Collection. * - * @param keys the keys + * @param keys + * the keys * @return the boolean */ public boolean memberOf(Collection keys) { @@ -198,4 +191,9 @@ public abstract class Widget extends Model { public boolean addWidget(Widget widget) { return true; } + + @Override + public Map getProperties() { + return Collections.emptyMap(); + } } diff --git a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java index 52dd462..d7519c0 100644 --- a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java +++ b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java @@ -32,9 +32,8 @@ 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.model.AllotedResource; -import org.onap.aai.babel.xml.generator.model.InstanceGroup; 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; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; @@ -55,7 +54,8 @@ public class TestArtifactGeneratorToscaParser { @Test(expected = IllegalArgumentException.class) public void testMissingProvidingService() { List nodeTemplateList = Collections.singletonList(buildNodeTemplate("name", "BlockStorage")); - new ArtifactGeneratorToscaParser(null).processResourceModels(new AllotedResource(), nodeTemplateList); + new ArtifactGeneratorToscaParser(null).processResourceModels(new Resource(Type.ALLOTTED_RESOURCE, true), + nodeTemplateList); } /** @@ -65,7 +65,8 @@ public class TestArtifactGeneratorToscaParser { @Test(expected = IllegalArgumentException.class) public void testAddResourceNotProvidingService() { List nodeTemplateList = Collections.singletonList(buildNodeTemplate("testCR", "CR")); - final Resource dummyResource = new AllotedResource(); // Any Resource to which the CR can be added + // Create any Resource to which the CR can be added + final Resource dummyResource = new Resource(Type.ALLOTTED_RESOURCE, true); new ArtifactGeneratorToscaParser(null).processResourceModels(dummyResource, nodeTemplateList); } @@ -90,7 +91,8 @@ public class TestArtifactGeneratorToscaParser { Mockito.when(helper.getGroupsOfOriginOfNodeTemplate(serviceNodeTemplate)).thenReturn(groups); ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(helper); - List resources = parser.processInstanceGroups(new InstanceGroup(), serviceNodeTemplate); + List resources = + parser.processInstanceGroups(new Resource(Type.INSTANCE_GROUP, true), serviceNodeTemplate); assertThat(resources.size(), is(1)); Resource resource = resources.get(0); @@ -102,9 +104,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) { diff --git a/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java b/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java index 912a505..3d5e841 100644 --- a/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java +++ b/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java @@ -21,14 +21,15 @@ package org.onap.aai.babel.xml.generator.model; -import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; import java.io.IOException; import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.Map; import org.junit.Before; import org.junit.Test; import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser; @@ -43,7 +44,8 @@ import org.onap.aai.babel.xml.generator.types.ModelType; public class TestModel { private Service serviceModel = new Service(); - private List resourceModels = Arrays.asList(new VirtualFunction(), new InstanceGroup()); + private List resourceModels = + Arrays.asList(new Resource(Type.CR, true), new Resource(Type.INSTANCE_GROUP, true)); private Widget widgetModel = new OamNetwork(); private Model anonymousModel; @@ -56,7 +58,7 @@ public class TestModel { * from the Artifact Generator properties. * * @throws IOException - * if the Artifact Generator properties file is not loaded + * if the Artifact Generator properties file is not loaded */ @Before public void setup() throws IOException { @@ -81,6 +83,16 @@ public class TestModel { public Type getWidgetType() { return null; } + + @Override + public Map getProperties() { + return Collections.emptyMap(); + } + + @Override + public boolean isResource() { + return false; + } }; } @@ -90,34 +102,47 @@ public class TestModel { assertThat(Model.getModelFor(""), is(nullValue())); assertThat(Model.getModelFor("any.unknown.type"), is(nullValue())); - assertThat(Model.getModelFor("org.openecomp.resource.vf.allottedResource"), instanceOf(AllotedResource.class)); - assertThat(Model.getModelFor("org.openecomp.resource.vf.allottedResource.with.sub.type"), - instanceOf(AllotedResource.class)); - assertThat(Model.getModelFor("org.openecomp.resource.vfc.AllottedResource"), - instanceOf(ProvidingService.class)); - assertThat(Model.getModelFor("org.openecomp.resource.vfc"), instanceOf(VServerWidget.class)); - assertThat(Model.getModelFor("org.openecomp.resource.cp"), instanceOf(LIntfWidget.class)); - assertThat(Model.getModelFor("org.openecomp.cp"), instanceOf(LIntfWidget.class)); - assertThat(Model.getModelFor("org.openecomp.cp.some.suffix"), instanceOf(LIntfWidget.class)); - assertThat(Model.getModelFor("org.openecomp.resource.vl"), instanceOf(L3Network.class)); - assertThat(Model.getModelFor("org.openecomp.resource.vf"), instanceOf(VirtualFunction.class)); - assertThat(Model.getModelFor("org.openecomp.groups.vfmodule"), instanceOf(VfModule.class)); - assertThat(Model.getModelFor("org.openecomp.groups.VfModule"), instanceOf(VfModule.class)); - assertThat(Model.getModelFor("org.openecomp.resource.vfc.nodes.heat.cinder"), instanceOf(VolumeWidget.class)); - assertThat(Model.getModelFor("org.openecomp.nodes.PortMirroringConfiguration"), - instanceOf(Configuration.class)); - assertThat(Model.getModelFor("org.openecomp.nodes.PortMirroringConfiguration", "Configuration"), - instanceOf(Configuration.class)); - assertThat(Model.getModelFor("any.string", "Configuration"), instanceOf(Configuration.class)); - assertThat(Model.getModelFor("org.openecomp.resource.cr.Kk1806Cr1", "CR"), instanceOf(CR.class)); - assertThat(Model.getModelFor("any.string", "CR"), instanceOf(CR.class)); - - assertThat(Model.getModelFor("org.openecomp.resource.vfc", "an.unknown.type"), instanceOf(VServerWidget.class)); + assertMapping("org.openecomp.resource.vfc", Type.VSERVER); + assertMapping("org.openecomp.resource.cp", Type.LINT); + assertMapping("org.openecomp.cp", Type.LINT); + assertMapping("org.openecomp.cp.some.suffix", Type.LINT); + assertMapping("org.openecomp.resource.vl", Type.L3_NET); + assertMapping("org.openecomp.resource.vf", Type.VF); + assertMapping("org.openecomp.groups.vfmodule", Type.VFMODULE); + assertMapping("org.openecomp.groups.VfModule", Type.VFMODULE); + assertMapping("org.openecomp.resource.vfc.nodes.heat.cinder", Type.VOLUME); + assertMapping("org.openecomp.nodes.PortMirroringConfiguration", "Configuration", Type.CONFIGURATION); + assertMapping("any.string", "Configuration", Type.CONFIGURATION); + assertMapping("org.openecomp.resource.cr.Kk1806Cr1", "CR", Type.CR); + assertMapping("any.string", "CR", Type.CR); + + assertMapping("org.openecomp.resource.vfc", "an.unknown.type", Type.VSERVER); } - @Test - public void testGetCardinality() { - resourceModels.get(0).getCardinality(); + /** + * Assert that the TOSCA type String is mapped to the expected Widget Type. + * + * @param toscaType + * the TOSCA type or prefix + * @param widgetType + * the type of Widget expected from the mappings + */ + private void assertMapping(String toscaType, Type widgetType) { + assertThat(Model.getModelFor(toscaType).getWidgetType(), is(widgetType)); + } + + /** + * Assert that the TOSCA metadata type is mapped to the expected Widget Type. + * + * @param toscaType + * the name (or name prefix) of the TOSCA type + * @param metadataType + * the type specified in the TOSCA metadata + * @param widgetType + * the type of Widget expected from the mappings + */ + private void assertMapping(String toscaType, String metadataType, Type widgetType) { + assertThat(Model.getModelFor(toscaType, metadataType).getWidgetType(), is(widgetType)); } @Test diff --git a/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java b/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java index 1a5986b..451d2bb 100644 --- a/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java +++ b/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java @@ -54,25 +54,25 @@ public class TestVfModule { */ @Test public void testHashCode() { - VfModule vfModule = createNewVfModule(); + Resource vfModule = createNewVfModule(); populateIdentInfo(vfModule); assertThat(vfModule.hashCode(), is(notNullValue())); } - + /** * Call equals() method for code coverage. */ @Test public void testEquals() { - VfModule vfModuleA = createNewVfModule(); - populateIdentInfo(vfModuleA); + Resource vfModuleA = createNewVfModule(); + populateIdentInfo(vfModuleA); - // equals() is reflexive + // equals() is reflexive assertThat(vfModuleA.equals(vfModuleA), is(true)); - + // equals() is symmetric - VfModule vfModuleB = createNewVfModule(); - populateIdentInfo(vfModuleB); + Resource vfModuleB = createNewVfModule(); + populateIdentInfo(vfModuleB); assertThat(vfModuleA.equals(vfModuleB), is(true)); assertThat(vfModuleB.equals(vfModuleA), is(true)); @@ -95,7 +95,7 @@ public class TestVfModule { */ @Test public void testNonMemberWidgetToVf() { - VfModule vfModule = createNewVfModule(); + Resource vfModule = createNewVfModule(); assertThat(vfModule.addWidget(createNewWidget(Type.SERVICE)), is(false)); assertNumberOfWidgets(vfModule, 0); } @@ -105,7 +105,7 @@ public class TestVfModule { */ @Test public void testAddOamNetworkWidgetToVf() { - VfModule vfModule = createNewVfModule(); + Resource vfModule = createNewVfModule(); assertThat(createNewWidgetForModule(vfModule, Type.OAM_NETWORK), is(false)); assertNumberOfWidgets(vfModule, 0); } @@ -120,7 +120,7 @@ public class TestVfModule { */ @Test public void testAddVolumeWidgetToVf() { - VfModule vfModule = createNewVfModule(); + Resource vfModule = createNewVfModule(); // Adding a Volume widget has no effect until a vserver widget is added. assertAddWidget(vfModule, Type.VOLUME); @@ -152,7 +152,7 @@ public class TestVfModule { */ @Test public void testAddLinterfaceWidgetToVf() { - VfModule vfModule = createNewVfModule(); + Resource vfModule = createNewVfModule(); // Adding an L-Interface widget has no effect until a vserver widget is added. assertFailToAddWidget(vfModule, Type.LINT); @@ -185,7 +185,7 @@ public class TestVfModule { */ @Test public void testAddVolumeAndLinterfaceWidgetToVf() { - VfModule vfModule = createNewVfModule(); + Resource vfModule = createNewVfModule(); // Adding a Volume widget has no effect until a vserver widget is added. assertAddWidget(vfModule, Type.VOLUME); @@ -232,8 +232,8 @@ public class TestVfModule { * * @return new VF Module resource */ - private VfModule createNewVfModule() { - VfModule vfModule = new VfModule(); + private Resource createNewVfModule() { + Resource vfModule = new Resource(Type.VFMODULE, true); assertNumberOfWidgets(vfModule, 0); return vfModule; } @@ -244,7 +244,7 @@ public class TestVfModule { * @param vfModule * to be populated */ - private void populateIdentInfo(VfModule vfModule) { + private void populateIdentInfo(Resource vfModule) { Map modelIdentInfo = new HashMap<>(); modelIdentInfo.put("UUID", "dummy_uuid"); vfModule.populateModelIdentificationInformation(modelIdentInfo); @@ -258,7 +258,7 @@ public class TestVfModule { * @param widgetType * the type of Widget to create and add */ - private void assertAddWidget(VfModule vfModule, Type widgetType) { + private void assertAddWidget(Resource vfModule, Type widgetType) { assertThat(createNewWidgetForModule(vfModule, widgetType), is(true)); } @@ -270,7 +270,7 @@ public class TestVfModule { * @param widgetType * the type of Widget to create and attempt to add */ - private void assertFailToAddWidget(VfModule vfModule, Type widgetType) { + private void assertFailToAddWidget(Resource vfModule, Type widgetType) { assertThat(createNewWidgetForModule(vfModule, widgetType), is(false)); } @@ -283,7 +283,7 @@ public class TestVfModule { * the type of Widget to create and attempt to add * @return whether or not the Widget was added to the module */ - private boolean createNewWidgetForModule(VfModule vfModule, Type widgetType) { + private boolean createNewWidgetForModule(Resource vfModule, Type widgetType) { Widget widget = createNewWidget(widgetType); setWidgetAsMember(vfModule, widget); return vfModule.addWidget(widget); @@ -299,7 +299,7 @@ public class TestVfModule { * @param widget * the widget to be set as the member */ - private void setWidgetAsMember(VfModule vfModule, Widget widget) { + private void setWidgetAsMember(Resource vfModule, Widget widget) { String id = widget.getId(); widget.addKey(id); vfModule.setMembers(Collections.singletonList(id)); @@ -312,7 +312,7 @@ public class TestVfModule { * the VF Module to update * @return the number of Widgets present in the vserver on creation */ - private int createVserverForVf(VfModule vfModule) { + private int createVserverForVf(Resource vfModule) { VServerWidget vserverWidget = (VServerWidget) createNewWidget(Type.VSERVER); assertNumberOfWidgets(vfModule, 0); final int initialWidgetCount = addVserverToVf(vfModule, vserverWidget); @@ -329,7 +329,7 @@ public class TestVfModule { * the Widget to add * @return initial widget count for the vserver Widget */ - private int addVserverToVf(VfModule vfModule, VServerWidget vserverWidget) { + private int addVserverToVf(Resource vfModule, VServerWidget vserverWidget) { // A vserver (initially) has Flavor, Image, Tenant and Vfc. final int initialWidgetCount = 4; assertNumberOfWidgets(vserverWidget, initialWidgetCount); diff --git a/src/test/resources/tosca-mappings.json b/src/test/resources/tosca-mappings.json index 9c3d0b4..0d306ea 100644 --- a/src/test/resources/tosca-mappings.json +++ b/src/test/resources/tosca-mappings.json @@ -1,21 +1,53 @@ { - "instanceGroupTypes": [ - "org.openecomp.groups.NetworkCollection", - "org.openecomp.groups.VfcInstanceGroup", - "org.openecomp.groups.ResourceInstanceGroup" - ], - "toscaToWidgetMappings": { - "org.openecomp.resource.vf.allottedResource": "AllotedResource", - "org.openecomp.resource.vfc.AllottedResource": "ProvidingService", - "org.openecomp.resource.vfc": "VServerWidget", - "org.openecomp.resource.cp": "LIntfWidget", - "org.openecomp.cp": "LIntfWidget", - "org.openecomp.resource.vl": "L3Network", - "org.openecomp.resource.vf": "VirtualFunction", - "org.openecomp.groups.vfmodule": "VfModule", - "org.openecomp.groups.VfModule": "VfModule", - "org.openecomp.resource.vfc.nodes.heat.cinder": "VolumeWidget", - "org.openecomp.nodes.PortMirroringConfiguration": "Configuration", - "org.openecomp.resource.cr.Kk1806Cr1": "CR" - } + "instanceGroupTypes": [ + "org.openecomp.groups.NetworkCollection", + "org.openecomp.groups.VfcInstanceGroup", + "org.openecomp.groups.ResourceInstanceGroup" + ], + "widgetMappings": [ + { + "prefix": "org.openecomp.resource.vfc", + "type": "widget", + "widget": "VSERVER", + "deleteFlag": true + }, + { + "prefix": "org.openecomp.resource.cp", + "type": "widget", + "widget": "LINT", + "deleteFlag": true + }, + { + "prefix": "org.openecomp.cp", + "type": "widget", + "widget": "LINT", + "deleteFlag": true + }, + { + "prefix": "org.openecomp.resource.vl", + "widget": "L3_NET", + "deleteFlag": false + }, + { + "prefix": "org.openecomp.resource.vf", + "widget": "VF", + "deleteFlag": true + }, + { + "prefix": "org.openecomp.groups.vfmodule", + "widget": "VFMODULE", + "deleteFlag": true + }, + { + "prefix": "org.openecomp.groups.VfModule", + "widget": "VFMODULE", + "deleteFlag": true + }, + { + "prefix": "org.openecomp.resource.vfc.nodes.heat.cinder", + "type": "widget", + "widget": "VOLUME", + "deleteFlag": true + } + ] } -- cgit 1.2.3-korg