aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authormark.j.leonard <mark.j.leonard@gmail.com>2019-02-05 14:24:33 +0000
committermark.j.leonard <mark.j.leonard@gmail.com>2019-02-05 14:24:33 +0000
commit1954294aed95c2db4eb2659dcef91248535de079 (patch)
tree05011d5cb74775e02e6b28f02150c9e2b0539708 /src/main
parent7fcc74469c941c1834cd02b54ff5ca88a53bf83b (diff)
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 <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/aai/babel/parser/ArtifactGeneratorToscaParser.java144
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/api/AaiArtifactGenerator.java43
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/GroupConfiguration.java12
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/WidgetConfigurationUtil.java40
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java (renamed from src/main/java/org/onap/aai/babel/xml/generator/logging/CategoryLogLevel.java)22
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/AllotedResource.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/CR.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Configuration.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/InstanceGroup.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/L3Network.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Model.java63
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/ProvidingService.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Resource.java125
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Service.java12
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VfModule.java109
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/VirtualFunction.java28
-rw-r--r--src/main/java/org/onap/aai/babel/xml/generator/model/Widget.java42
17 files changed, 306 insertions, 502 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 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<String, String> mergeProperties(Map<String, String> stringProps, Map<String, Property> toscaProps) {
@@ -198,7 +195,7 @@ public class ArtifactGeneratorToscaParser {
}
public Resource createInstanceGroupModel(Map<String, String> 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<String, String> 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<String, Object> 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 ? "<null ID>" : 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<Resource> processInstanceGroup(Model resourceModel, ArrayList<NodeTemplate> memberNodes,
@@ -320,11 +312,11 @@ public class ArtifactGeneratorToscaParser {
List<Resource> 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<Resource> 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<NodeTemplate> members) {
+ private void processVfModuleGroup(Resource groupModel, List<NodeTemplate> members) {
if (members != null && !members.isEmpty()) {
// Get names of the members of the service group
List<String> 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<String, String> populateStringProperties(Map<String, Property> 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<String, Property> 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<String, Property> 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<String, String> 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<Resource> resources, final List<Group> 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<Resource> 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<Resource> resources,
+ ArtifactGeneratorToscaParser parser, NodeTemplate nodeTemplate) {
+ Resource resourceModel = getModelFor(parser, nodeTemplate);
Map<String, String> 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<String> instanceGroupTypes;
-
+
/**
- * Mapping from TOSCA type to Widget Model.
+ * Mapping from TOSCA type to Widget directly.
*/
- private Map<String, String> toscaToWidgetMappings;
+ private List<WidgetMapping> widgetMappings;
public List<String> getInstanceGroupTypes() {
return instanceGroupTypes;
}
- public Map<String, String> getToscaToWidgetMappings() {
- return toscaToWidgetMappings;
+ public List<WidgetMapping> 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<String> instanceGroups = Collections.emptyList();
- private static Map<String, Class<? extends Model>> typeToModel = new HashMap<>();
+ private static Map<String, Resource> typeToWidget = new HashMap<>();
/*
* Private constructor to prevent instantiation
@@ -51,36 +52,21 @@ public class WidgetConfigurationUtil {
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 Optional<Resource> createModelFromType(String typePrefix) {
+ return Optional.ofNullable(typeToWidget.get(typePrefix));
}
- public static Class<? extends Model> getModelFromType(String typePrefix) {
- return typeToModel.get(typePrefix);
+ public static void setWidgetMappings(List<WidgetMapping> 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/logging/CategoryLogLevel.java b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.java
index b6ca2d3..2157728 100644
--- a/src/main/java/org/onap/aai/babel/xml/generator/logging/CategoryLogLevel.java
+++ b/src/main/java/org/onap/aai/babel/xml/generator/data/WidgetMapping.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,12 +18,16 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.aai.babel.xml.generator.logging;
-public enum CategoryLogLevel {
- INFO,
- WARN,
- DEBUG,
- ERROR,
- FATAL
+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<String, Object> properties;
}
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<Model> getModelFromType(String typePrefix) {
- Optional<Model> modelToBeReturned = Optional.empty();
- Class<? extends Model> 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<Resource> 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<String, Object> 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<String, String> modelIdentInfo) {
Iterator<String> 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<String, Object> properties = Collections.emptyMap();
+
+ Widget vserver = null;
+ boolean addlintf = false;
+ boolean addvolume = false;
+ List<String> 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<String, Object> properties) {
+ this.properties = properties;
+ }
+
+ @Override
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ public void setIsResource(boolean isResource) {
+ this.isResource = isResource;
+ }
+
+ @Override
+ public boolean isResource() {
+ return isResource;
+ }
+
+ public void setMembers(List<String> 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<String, Object> 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<String> members;
-
- public void setMembers(List<String> 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<String> keys) {
@@ -198,4 +191,9 @@ public abstract class Widget extends Model {
public boolean addWidget(Widget widget) {
return true;
}
+
+ @Override
+ public Map<String, Object> getProperties() {
+ return Collections.emptyMap();
+ }
}