aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/asdc/parser
diff options
context:
space:
mode:
authorSonsino, Ofir (os0695) <os0695@intl.att.com>2018-07-10 14:20:54 +0300
committerSonsino, Ofir (os0695) <os0695@intl.att.com>2018-07-10 14:20:54 +0300
commitc72d565bb58226b20625b2bce5f0019046bee649 (patch)
tree8658e49595705b02e47ddc14afa20d6bb7123547 /vid-app-common/src/main/java/org/onap/vid/asdc/parser
parentef8a6b47847012fd59ea20da21d8d3d7c4a301ed (diff)
Merge 1806 code of vid-common
Change-Id: I75d52abed4a24dfe3827d79edc4a2938726aa87a Issue-ID: VID-208 Signed-off-by: Sonsino, Ofir (os0695) <os0695@intl.att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/asdc/parser')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParser.java9
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl.java137
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java342
3 files changed, 310 insertions, 178 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParser.java b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParser.java
index 6da1738a9..8af1f7b02 100644
--- a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParser.java
+++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParser.java
@@ -1,15 +1,14 @@
package org.onap.vid.asdc.parser;
-import java.nio.file.Path;
-
-import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.onap.vid.asdc.AsdcCatalogException;
-import org.onap.vid.asdc.beans.tosca.ToscaCsar;
import org.onap.vid.asdc.beans.Service;
+import org.onap.vid.asdc.beans.tosca.ToscaCsar;
import org.onap.vid.model.ServiceModel;
+import java.nio.file.Path;
+
public interface ToscaParser{
ToscaCsar parse(Path path) throws AsdcCatalogException;
- ServiceModel makeServiceModel(String uuid,Path path,Service asdcServiceMetadata) throws Exception;
+ ServiceModel makeServiceModel(String uuid,Path path,Service asdcServiceMetadata) throws AsdcCatalogException;
} \ No newline at end of file
diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl.java b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl.java
index 37f4b0ab0..27445c0f3 100644
--- a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl.java
@@ -1,49 +1,34 @@
package org.onap.vid.asdc.parser;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Path;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.Map.Entry;
-import java.util.zip.ZipFile;
-
import org.apache.commons.lang3.mutable.MutableBoolean;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.onap.vid.asdc.AsdcCatalogException;
import org.onap.vid.asdc.beans.Service;
import org.onap.vid.asdc.beans.tosca.NodeTemplate;
import org.onap.vid.asdc.beans.tosca.ToscaCsar;
import org.onap.vid.asdc.beans.tosca.ToscaMeta;
import org.onap.vid.asdc.beans.tosca.ToscaModel;
-import org.onap.vid.model.ModelConstants;
-import org.onap.vid.model.Network;
-import org.onap.vid.model.Node;
-import org.onap.vid.model.ServiceModel;
-import org.onap.vid.model.VNF;
+import org.onap.vid.model.*;
import org.onap.vid.properties.VidProperties;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.error.YAMLException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.zip.ZipFile;
+
public class ToscaParserImpl implements ToscaParser {
/** The Constant LOG. */
static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ToscaParserImpl.class);
- @Autowired
- private final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
-
-
- private static final String asdcModelNamespace = VidProperties.getAsdcModelNamespace();
- private static final String vnfTag = asdcModelNamespace + ModelConstants.VNF;
- private static final String networkTag = asdcModelNamespace + ModelConstants.NETWORK;
- private static final String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE;
+ private static final String ASDC_MODEL_NAMESPACE = VidProperties.getAsdcModelNamespace();
+ private static final String VNF_TAG = ASDC_MODEL_NAMESPACE + ModelConstants.VNF;
+ private static final String NETWORK_TAG = ASDC_MODEL_NAMESPACE + ModelConstants.NETWORK;
@Override
@@ -60,29 +45,7 @@ public class ToscaParserImpl implements ToscaParser {
final InputStream toscaParentEntryYamlStream = csar.getInputStream(csar.getEntry(entryDefinitions));
try {
- final Yaml yaml = new Yaml();
- final ToscaModel parentModel = yaml.loadAs(toscaParentEntryYamlStream, ToscaModel.class);
-
- final ToscaCsar.Builder csarBuilder = new ToscaCsar.Builder(parentModel);
-
- for (Map<String, Map<String, String>> imports : parentModel.getImports()) {
- LOG.debug("imports = " + imports.toString());
- for (Entry<String, Map<String, String>> entry : imports.entrySet()) {
- if (entry.getValue() != null) {
- String fname = entry.getValue().get("file");
- if ((fname != null) && (fname.startsWith("service") || fname.startsWith("resource"))) {
- LOG.debug("fname = " + fname);
- final InputStream toscaChildEntryYamlStream = csar
- .getInputStream(csar.getEntry("Definitions/" + fname));
-
- final ToscaModel childModel = yaml.loadAs(toscaChildEntryYamlStream, ToscaModel.class);
- csarBuilder.addVnf(childModel);
- }
- }
- }
- }
-
- return csarBuilder.build();
+ return createToscaCsar(csar, toscaParentEntryYamlStream);
} catch (YAMLException e) {
throw new AsdcCatalogException("Caught exception while processing TOSCA YAML", e);
}
@@ -91,22 +54,49 @@ public class ToscaParserImpl implements ToscaParser {
}
}
- public ServiceModel makeServiceModel(String uuid, final Path serviceCsar,Service service ) throws AsdcCatalogException, SdcToscaParserException {
+ private ToscaCsar createToscaCsar(ZipFile csar, InputStream toscaParentEntryYamlStream) throws IOException {
+ final Yaml yaml = new Yaml();
+ final ToscaModel parentModel = yaml.loadAs(toscaParentEntryYamlStream, ToscaModel.class);
+
+ final ToscaCsar.Builder csarBuilder = new ToscaCsar.Builder(parentModel);
+
+ for (Map<String, Map<String, String>> imports : parentModel.getImports()) {
+ LOG.debug("imports = " + imports.toString());
+ for (Entry<String, Map<String, String>> entry : imports.entrySet()) {
+ if (entry.getValue() != null) {
+ String fname = entry.getValue().get("file");
+ if ((fname != null) && (fname.startsWith("service") || fname.startsWith("resource"))) {
+ LOG.debug("fname = " + fname);
+ final InputStream toscaChildEntryYamlStream = csar
+ .getInputStream(csar.getEntry("Definitions/" + fname));
+
+ final ToscaModel childModel = yaml.loadAs(toscaChildEntryYamlStream, ToscaModel.class);
+ csarBuilder.addVnf(childModel);
+ }
+ }
+ }
+ }
+
+ return csarBuilder.build();
+ }
+
+ public ServiceModel makeServiceModel(String uuid, final Path serviceCsar,Service service ) throws AsdcCatalogException {
final ServiceModel serviceModel = new ServiceModel();
ToscaCsar toscaCsar = getToscaCsar(serviceCsar);
String methodName = "getServices";
- LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start");
MutableBoolean isNewFlow = new MutableBoolean(false);
- final Map<String, VNF> vnfs = new HashMap<String, VNF>();
- final Map<String, Network> networks = new HashMap<String, Network>();
+ final Map<String, VNF> vnfs = new HashMap<>();
+ final Map<String, Network> networks = new HashMap<>();
final ToscaModel asdcServiceToscaModel = toscaCsar.getParent();
serviceModel.setService(ServiceModel.extractService(asdcServiceToscaModel, service));
+
populateVnfsAndNetwork(methodName, isNewFlow, vnfs, networks, asdcServiceToscaModel, serviceModel);
+
// If we see customization uuid under vnf or network, follow 1702 flow
if (isNewFlow.getValue()) {
return (getCustomizedServices(asdcServiceToscaModel, serviceModel));
@@ -147,33 +137,30 @@ public class ToscaParserImpl implements ToscaParser {
}
private static void populateVnfsAndNetwork(String methodName, MutableBoolean isNewFlow, final Map<String, VNF> vnfs,
- final Map<String, Network> networks, final ToscaModel asdcServiceToscaModel, ServiceModel serviceModel)
- throws AsdcCatalogException, SdcToscaParserException {
+ final Map<String, Network> networks, final ToscaModel asdcServiceToscaModel, ServiceModel serviceModel) {
for (Entry<String, NodeTemplate> component : extractNodeTemplates(asdcServiceToscaModel)) {
final String modelCustomizationName = component.getKey();
- LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName
+ LOG.debug(EELFLoggerDelegate.debugLogger, methodName
+ " model customization name: " + modelCustomizationName);
final NodeTemplate nodeTemplate = component.getValue();
final String type = nodeTemplate.getType();
- if (type.startsWith(vnfTag)) {
+ if (type.startsWith(VNF_TAG)) {
LOG.debug(EELFLoggerDelegate.debugLogger,
- dateFormat.format(new Date()) + methodName + " found node template type: " + type);
+ methodName + " found node template type: " + type);
final VNF vnf = new VNF();
vnf.extractVnf(modelCustomizationName, nodeTemplate);
-// populateNodeVersionIfMissing(nodeTemplate, vnf,service);
LOG.debug(EELFLoggerDelegate.debugLogger,
- dateFormat.format(new Date()) + methodName + " VNF commands: " + vnf.getCommands());
+ methodName + " VNF commands: " + vnf.getCommands());
vnfs.put(modelCustomizationName, vnf);
isNewFlow.setValue(isNewFlow(vnf));
}
// Networks
- if (type.startsWith(networkTag)) {
+ if (type.startsWith(NETWORK_TAG)) {
LOG.debug(EELFLoggerDelegate.debugLogger,
- dateFormat.format(new Date()) + methodName + " found node template type: " + type);
+ methodName + " found node template type: " + type);
final Network network = new Network();
network.extractNetwork(modelCustomizationName, nodeTemplate);
-// populateNodeVersionIfMissing(nodeTemplate, network, service);
isNewFlow.setValue(isNewFlow(network));
networks.put(modelCustomizationName, network);
@@ -192,20 +179,8 @@ public class ToscaParserImpl implements ToscaParser {
return (node.getCustomizationUuid() != null) && (node.getCustomizationUuid().length() > 0);
}
- private static boolean isNodeVersionMissing(Node Node) {
- return Node.getVersion() == null;
- }
-
- private static void populateNodeVersionIfMissing(final NodeTemplate nodeTemplate, final Node node, Service service)
- throws AsdcCatalogException {
- if (isNodeVersionMissing(node)) {
- node.setVersion(service.getVersion());
- }
- }
-
private ServiceModel getCustomizedServices(ToscaModel asdcServiceToscaModel, ServiceModel serviceModel) {
String methodName = "asdcServiceToscaModel";
- LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start");
// asdcServiceToscaModel should have vf modules and vol groups populated
// at this point but
@@ -217,10 +192,4 @@ public class ToscaParserImpl implements ToscaParser {
return (serviceModel);
}
-
- private UUID extractUUIDFromNodeTemplate(final NodeTemplate nodeTemplate) {
- return UUID.fromString(nodeTemplate.getMetadata().getUUID());
- }
-
-
} \ No newline at end of file
diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java
index e75bb3063..17fb29b59 100644
--- a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java
+++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ToscaParserImpl2.java
@@ -7,6 +7,7 @@ import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.onap.sdc.tosca.parser.impl.FilterType;
import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
import org.onap.sdc.tosca.parser.impl.SdcTypes;
+import org.onap.sdc.toscaparser.api.Group;
import org.onap.sdc.toscaparser.api.*;
import org.onap.sdc.toscaparser.api.elements.Metadata;
import org.onap.sdc.toscaparser.api.parameters.Input;
@@ -16,98 +17,208 @@ import java.util.*;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toMap;
+import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.VF_MODULE_LABEL;
public class ToscaParserImpl2 {
public class Constants {
- public final static String uuid = "UUID";
- public final static String description = "description";
- public final static String serviceType = "serviceType";
- public final static String serviceRole = "serviceRole";
- public final static String ecompGeneratedNaming = "ecompGeneratedNaming";
-
- public final static String customizationUUID = "customizationUUID";
- public final static String vfModuleModelVersion = "vfModuleModelVersion";
- public final static String vfModuleModelCustomizationUUID = "vfModuleModelCustomizationUUID";
- public final static String volume_group = "volume_group";
- public final static String vfModuleModelInvariantUUID = "vfModuleModelInvariantUUID";
- public final static String vfModuleModelUUID = "vfModuleModelUUID";
- public final static String invariantUUID = "invariantUUID";
- public final static String version = "version";
- public final static String name = "name";
- public final static String category = "category";
- public final static String vfModuleModelName = "vfModuleModelName";
- public final static String getInput = "get_input";
-
- public final static String instantiationType = "instantiationType";
- //Instantiation Types
- public final static String both = "Both";
- public final static String macro = "Macro";
- public final static String aLaCarte = "A-La-Carte";
- public final static String clientConfig = "ClientConfig";
-
-
- }
-
- public ToscaParserImpl2() {
-
+ public final static String UUID = "UUID";
+ public final static String DESCRIPTION = "description";
+ public final static String SERVICE_TYPE = "serviceType";
+ public final static String SERVICE_ROLE = "serviceRole";
+ public final static String ECOMP_GENERATED_NAMING = "ecompGeneratedNaming";
+
+ public final static String CUSTOMIZATION_UUID = "customizationUUID";
+ public final static String VF_MODULE_MODEL_VERSION = "vfModuleModelVersion";
+ public final static String VF_MODULE_MODEL_CUSTOMIZATION_UUID = "vfModuleModelCustomizationUUID";
+ public final static String VOLUME_GROUP = "volume_group";
+ public final static String VF_MODULE_MODEL_INVARIANT_UUID = "vfModuleModelInvariantUUID";
+ public final static String VF_MODULE_MODEL_UUID = "vfModuleModelUUID";
+ public final static String INVARIANT_UUID = "invariantUUID";
+ public final static String VERSION = "version";
+ public final static String NAME = "name";
+ public final static String CATEGORY = "category";
+ public final static String VF_MODULE_MODEL_NAME = "vfModuleModelName";
+ public final static String GET_INPUT = "get_input";
+ public final static String TYPE = "type";
+
+ public final static String INSTANTIATION_TYPE = "instantiationType";
+ //instantiation type
+ public final static String BOTH = "Both";
+ public final static String MACRO = "Macro";
+ public final static String A_LA_CARTE = "A-La-Carte";
+ public final static String CLIENT_CONFIG = "ClientConfig";
+
+ //group properties
+ public final static String MIN_VF_MODULE_INSTANCES = "min_vf_module_instances";
+ public final static String MAX_VF_MODULE_INSTANCES = "max_vf_module_instances";
+ public final static String INITIAL_COUNT = "initial_count";
+ public final static String VF_MODULE_LABEL = "vf_module_label";
+
+ //collection resource properties
+ public final static String SUBCATEGORY = "subcategory";
+ public final static String RESOURCE_VENDOR = "resourceVendor";
+ public final static String RESOURCE_VENDOR_RELEASE = "resourceVendorRelease";
+ public final static String RESOURCE_VENDOR_MODEL_NUMBER = "resourceVendorModelNumber";
+ public final static String ORG_OPENECOMP_GROUPS_NETWORK_COLLECTION = "org.openecomp.groups.NetworkCollection";
+ public final static String NETWORK_COLLECTION_FUNCTION = "network_collection_function";
+ public final static String NETWORK_COLLECTION_DESCRIPTION = "network_collection_description";
+
+ //vfc instance group properties
+ public final static String VFC_INSTANCE_GROUP_TYPE = "org.openecomp.groups.VfcInstanceGroup";
+ public final static String VFC_PARENT_PORT_ROLE = "vfc_parent_port_role";
+ public final static String SUBINTERFACE_ROLE = "subinterface_role";
+ public final static String VFC_INSTANCE_GROUP_FUNCTION = "vfc_instance_group_function";
}
+
+ public ToscaParserImpl2() {}
- public ServiceModel makeServiceModel(Path path, Service asdcServiceMetadata) throws Exception {
+ public ServiceModel makeServiceModel(Path path, Service asdcServiceMetadata) throws SdcToscaParserException {
ServiceModel serviceModel = new ServiceModel();
SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(path.toFile().getAbsolutePath(),false);
- serviceModel.setService(extractServiceFromCsar(asdcServiceMetadata, sdcCsarHelper));
+ serviceModel.setService(extractServiceFromCsar(asdcServiceMetadata, sdcCsarHelper));
serviceModel.setVolumeGroups(extractVolumeGroups(sdcCsarHelper));
serviceModel.setVfModules(extractVfModuleFromCsar(sdcCsarHelper));
- serviceModel.setVnfs(extractVnfsFromCsar(serviceModel,sdcCsarHelper));
+ serviceModel.setVnfs(extractVnfsFromCsar(sdcCsarHelper));
serviceModel.setConfigurations(extractPortMirroringConfigFromCsar(sdcCsarHelper));
serviceModel.setServiceProxies(extractServiceProxyFromCsar(sdcCsarHelper));
serviceModel.setNetworks(extractNetworksFromCsar(sdcCsarHelper));
serviceModel.setPnfs(extractPnfsFromCsar(sdcCsarHelper));
+ serviceModel.setCollectionResource(extractCRFromCsar(sdcCsarHelper));
return serviceModel;
}
+
+
private org.onap.vid.model.Service extractServiceFromCsar(Service asdcServiceMetadata, ISdcCsarHelper csarHelper) throws SdcToscaParserException {
org.onap.vid.model.Service service = new org.onap.vid.model.Service();
- service.setName(csarHelper.getServiceMetadata().getValue(Constants.name));
- service.setCategory(csarHelper.getServiceMetadata().getValue(Constants.category));
- service.setInvariantUuid(csarHelper.getServiceMetadata().getValue(Constants.invariantUUID));
- service.setUuid(csarHelper.getServiceMetadata().getValue(Constants.uuid));
+ service.setName(csarHelper.getServiceMetadata().getValue(Constants.NAME));
+ service.setCategory(csarHelper.getServiceMetadata().getValue(Constants.CATEGORY));
+ service.setInvariantUuid(csarHelper.getServiceMetadata().getValue(Constants.INVARIANT_UUID));
+ service.setUuid(csarHelper.getServiceMetadata().getValue(Constants.UUID));
service.setVersion(asdcServiceMetadata.getVersion());
- service.setDescription(csarHelper.getServiceMetadata().getValue(Constants.description));
- service.setInputs(inputsListToInputsMap(csarHelper.getServiceInputs()));
- service.setServiceEcompNaming(csarHelper.getServiceMetadata().getValue(Constants.ecompGeneratedNaming));
- service.setServiceType(csarHelper.getServiceMetadata().getValue(Constants.serviceType));
- service.setServiceRole(csarHelper.getServiceMetadata().getValue(Constants.serviceRole));
+ service.setDescription(csarHelper.getServiceMetadata().getValue(Constants.DESCRIPTION));
+ service.setInputs(inputsListToInputsMap(csarHelper.getInputsWithAnnotations()));
+ service.setServiceEcompNaming(csarHelper.getServiceMetadata().getValue(Constants.ECOMP_GENERATED_NAMING));
+ service.setServiceType(csarHelper.getServiceMetadata().getValue(Constants.SERVICE_TYPE));
+ service.setServiceRole(csarHelper.getServiceMetadata().getValue(Constants.SERVICE_ROLE));
service.setInstantiationType(validateInstantiationType(csarHelper));
return service;
}
-
- private Map<String, VNF> extractVnfsFromCsar(ServiceModel serviceModel,ISdcCsarHelper csarHelper) {
+ private Map<String,CR> extractCRFromCsar(ISdcCsarHelper sdcCsarHelper) {
+ List<NodeTemplate> nodeTemplates = sdcCsarHelper.getServiceNodeTemplates();
+ Map<String, CR> collectionResourceMap = new HashMap<>();
+
+ for(NodeTemplate nodeTemplate: nodeTemplates){
+ if(nodeTemplate.getMetaData().getValue(Constants.TYPE).equals(SdcTypes.CR.getValue())) {
+ CR cr = new CR();
+ populateCrFromNodeTemplate(nodeTemplate, sdcCsarHelper, cr);
+ collectionResourceMap.put(nodeTemplate.getName(), cr);
+ }
+ }
+
+ return collectionResourceMap;
+ }
+
+ private void populateCrFromNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper sdcCsarHelper, CR cr) {
+ populateNodeFromNodeTemplate(nodeTemplate, sdcCsarHelper, cr);
+ cr.setCustomizationUUID(nodeTemplate.getMetaData().getValue(Constants.CUSTOMIZATION_UUID));
+ cr.setCategory(nodeTemplate.getMetaData().getValue(Constants.CATEGORY));
+ cr.setSubcategory(nodeTemplate.getMetaData().getValue(Constants.SUBCATEGORY));
+ cr.setResourceVendor(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR));
+ cr.setResourceVendorRelease(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR_RELEASE));
+ cr.setResourceVendorModelNumber(nodeTemplate.getMetaData().getValue(Constants.RESOURCE_VENDOR_MODEL_NUMBER));
+ cr.setNetworksCollection(getNetworksCollectionMapFromGroupsList(sdcCsarHelper, nodeTemplate));
+ }
+
+ private Map<String, NetworkCollection> getNetworksCollectionMapFromGroupsList(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) {
+ List<Group> groups = sdcCsarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, Constants.ORG_OPENECOMP_GROUPS_NETWORK_COLLECTION);
+ Map<String, NetworkCollection> networksCollectionMap = new HashMap<String, NetworkCollection>();
+ for(Group group: groups){
+ networksCollectionMap.put(group.getName(), populateCollectionNetworkFromGroup(group, nodeTemplate));
+ }
+ return networksCollectionMap;
+ }
+
+ private NetworkCollection populateCollectionNetworkFromGroup(Group group, NodeTemplate nodeTemplate) {
+ NetworkCollection networkCollection = new NetworkCollection();
+ networkCollection.setUuid(group.getMetadata().getValue(Constants.UUID));
+ networkCollection.setInvariantUuid(group.getMetadata().getValue(Constants.INVARIANT_UUID));
+ networkCollection.setVersion(group.getMetadata().getValue(Constants.VERSION));
+ networkCollection.setName(group.getMetadata().getValue(Constants.NAME));
+ extractPropertiesOfCollectionNetworkFromCsar(group, nodeTemplate, networkCollection);
+
+ return networkCollection;
+ }
+
+ private void extractPropertiesOfCollectionNetworkFromCsar(Group group, NodeTemplate nodeTemplate, NetworkCollection networkCollection) {
+ LinkedHashMap<String, Property> properties = group.getProperties();
+ Map<String, Property> nodeTemplateProperties = nodeTemplate.getProperties();
+
+ String networkCollectionFunction = (String)((Map)(properties.get(Constants.NETWORK_COLLECTION_FUNCTION).getValue())).get(Constants.GET_INPUT);
+ String networkCollectionDescription = (String)((Map)(properties.get(Constants.NETWORK_COLLECTION_DESCRIPTION).getValue())).get(Constants.GET_INPUT);
+
+ networkCollection.getNetworkCollectionProperties().setNetworkCollectionDescription((String)nodeTemplateProperties.get(networkCollectionDescription).getValue());
+ networkCollection.getNetworkCollectionProperties().setNetworkCollectionFunction((String)nodeTemplateProperties.get(networkCollectionFunction).getValue());
+ }
+
+
+ private Map<String, VNF> extractVnfsFromCsar(ISdcCsarHelper csarHelper) {
List<NodeTemplate> nodeTemplates = csarHelper.getServiceVfList();
Map<String, VNF> vnfsMaps = new HashMap<String, VNF>();
for (NodeTemplate nodeTemplate : nodeTemplates) {
VNF vnf = new VNF();
populateNodeFromNodeTemplate(nodeTemplate, csarHelper, vnf);
-
vnf.setModelCustomizationName(nodeTemplate.getName());
- Map<String, VfModule> vfModuleHashMap = getVfModulesFromVF(csarHelper, vnf.getCustomizationUuid());
- vnf.setVfModules(vfModuleHashMap);
-
- Map<String, VolumeGroup> volumeGroupMap = getVolumeGroupsFromVF(csarHelper, vnf.getCustomizationUuid());
- vnf.setVolumeGroups(volumeGroupMap);
+ vnf.setVfModules(getVfModulesFromVF(csarHelper, vnf.getCustomizationUuid()));
+ vnf.setVolumeGroups(getVolumeGroupsFromVF(csarHelper, vnf.getCustomizationUuid()));
+ vnf.setVfcInstanceGroups(getVfcInstanceGroup(csarHelper, nodeTemplate));
vnfsMaps.put(nodeTemplate.getName(), vnf);
}
return vnfsMaps;
}
+ private Map<String,VfcInstanceGroup> getVfcInstanceGroup(ISdcCsarHelper csarHelper, NodeTemplate nodeTemplate) {
+ List<Group> vfcList = csarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, Constants.VFC_INSTANCE_GROUP_TYPE);
+ return vfcList.stream()
+ .collect(toMap(Group::getName, group -> populateVfcInstanceGroupFromGroup(group, csarHelper, nodeTemplate)));
+ }
+
+ private VfcInstanceGroup populateVfcInstanceGroupFromGroup(Group group, ISdcCsarHelper csarHelper, NodeTemplate nodeTemplate) {
+ VfcInstanceGroup vfcInstanceGroup = new VfcInstanceGroup();
+ vfcInstanceGroup.setUuid(group.getMetadata().getValue(Constants.UUID));
+ vfcInstanceGroup.setInvariantUuid(group.getMetadata().getValue(Constants.INVARIANT_UUID));
+ vfcInstanceGroup.setVersion(group.getMetadata().getValue(Constants.VERSION));
+ vfcInstanceGroup.setName(group.getMetadata().getValue(Constants.NAME));
+ vfcInstanceGroup.setVfcInstanceGroupProperties(getVfcPropertiesFromGroup(nodeTemplate, group));
+
+ return vfcInstanceGroup;
+
+ }
+
+ private VfcInstanceGroupProperties getVfcPropertiesFromGroup(NodeTemplate nodeTemplate, Group group) {
+ VfcInstanceGroupProperties vfcInstanceGroupProperties = new VfcInstanceGroupProperties();
+ vfcInstanceGroupProperties.setVfcParentPortRole((String) group.getProperties().get(Constants.VFC_PARENT_PORT_ROLE).getValue());
+ vfcInstanceGroupProperties.setSubinterfaceRole((String) group.getProperties().get(Constants.SUBINTERFACE_ROLE).getValue());
+
+ String networkCollectionFunction = (String)((Map)(group.getProperties().get(Constants.NETWORK_COLLECTION_FUNCTION).getValue())).get(Constants.GET_INPUT);
+ String vfcInstanceGroupFunction = (String)((Map)(group.getProperties().get(Constants.VFC_INSTANCE_GROUP_FUNCTION).getValue())).get(Constants.GET_INPUT);
+
+ if(nodeTemplate.getProperties().get(networkCollectionFunction) != null)
+ vfcInstanceGroupProperties.setNetworkCollectionFunction((String) nodeTemplate.getProperties().get(networkCollectionFunction).getValue());
+ if(nodeTemplate.getProperties().get(vfcInstanceGroupFunction) != null)
+ vfcInstanceGroupProperties.setVfcInstanceGroupFunction((String) nodeTemplate.getProperties().get(vfcInstanceGroupFunction).getValue());
+
+ return vfcInstanceGroupProperties;
+ }
+
private Map<String, PortMirroringConfig> extractPortMirroringConfigFromCsar(ISdcCsarHelper csarHelper) {
List<NodeTemplate> nodeTemplates = csarHelper.getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION);
Map<String, PortMirroringConfig> configMaps = new HashMap<>();
@@ -175,18 +286,18 @@ public class ToscaParserImpl2 {
Map<String, VfModule> getVfModulesFromVF(ISdcCsarHelper csarHelper, String vfUuid) {
List<Group> vfModulesByVf = csarHelper.getVfModulesByVf(vfUuid);
return vfModulesByVf.stream()
- .collect(toMap(Group::getName, this::populateVfModuleFromGroup));
+ .collect(toMap(Group::getName, group -> populateVfModuleFromGroup(group, csarHelper)));
}
Map<String, VolumeGroup> getVolumeGroupsFromVF(ISdcCsarHelper csarHelper, String vfCustomizationUuid) {
List<Group> vfModulesByVf = csarHelper.getVfModulesByVf(vfCustomizationUuid);
return vfModulesByVf.stream()
.filter((group -> isVolumeGroup(group)))
- .collect(toMap(Group::getName, this::populateVolumeGroupFromGroup));
+ .collect(toMap(Group::getName, group -> populateVolumeGroupFromGroup(group, csarHelper)));
}
private static Boolean isVolumeGroup(Group group) {
- return Boolean.valueOf(group.getPropertyValue(Constants.volume_group).toString());
+ return Boolean.valueOf(group.getPropertyValue(Constants.VOLUME_GROUP).toString());
}
private Map<String, Network> extractNetworksFromCsar(ISdcCsarHelper csarHelper) {
@@ -220,7 +331,7 @@ public class ToscaParserImpl2 {
for (NodeTemplate nodeTemplate : serviceVfList) {
Map<String, VfModule> nodeTemplateVfModule =
- getVfModulesFromVF(csarHelper, nodeTemplate.getMetaData().getValue(Constants.customizationUUID));
+ getVfModulesFromVF(csarHelper, nodeTemplate.getMetaData().getValue(Constants.CUSTOMIZATION_UUID));
vfModuleHashMap.putAll(nodeTemplateVfModule);
}
return vfModuleHashMap;
@@ -239,60 +350,109 @@ public class ToscaParserImpl2 {
private Map<String, org.onap.vid.asdc.beans.tosca.Input> inputsListToInputsMap(List<org.onap.sdc.toscaparser.api.parameters.Input> inputList) {
Map<String, org.onap.vid.asdc.beans.tosca.Input> inputs = new HashMap<>();
for (org.onap.sdc.toscaparser.api.parameters.Input input : inputList) {
- inputs.put(input.getName(), convertInput(input, new org.onap.vid.asdc.beans.tosca.Input(), null));
+ //Set only inputs without annotation to the service level
+ if(input.getAnnotations() == null)
+ inputs.put(input.getName(), convertInput(input, new org.onap.vid.asdc.beans.tosca.Input(), null));
}
return inputs;
}
private Node populateNodeFromNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode) {
newNode.setCustomizationUuid(csarHelper.getNodeTemplateCustomizationUuid(nodeTemplate));
- newNode.setDescription(nodeTemplate.getMetaData().getValue(Constants.description));
- newNode.setInvariantUuid(nodeTemplate.getMetaData().getValue(Constants.invariantUUID));
- newNode.setUuid(nodeTemplate.getMetaData().getValue(Constants.uuid));
- newNode.setName(nodeTemplate.getMetaData().getValue(Constants.name));
- newNode.setVersion(nodeTemplate.getMetaData().getValue(Constants.version));
+ newNode.setDescription(nodeTemplate.getMetaData().getValue(Constants.DESCRIPTION));
+ newNode.setInvariantUuid(nodeTemplate.getMetaData().getValue(Constants.INVARIANT_UUID));
+ newNode.setUuid(nodeTemplate.getMetaData().getValue(Constants.UUID));
+ newNode.setName(nodeTemplate.getMetaData().getValue(Constants.NAME));
+ newNode.setVersion(nodeTemplate.getMetaData().getValue(Constants.VERSION));
newNode.setInputs(extractInputsAndCommandsForNodeTemplate(nodeTemplate, csarHelper, newNode));
- newNode.setType(nodeTemplate.getMetaData().getValue("type"));
+ newNode.setType(nodeTemplate.getMetaData().getValue(Constants.TYPE));
Map<String, String> propertiesMap = setPropertiesOfVnf(nodeTemplate.getPropertiesObjects());
newNode.setProperties(propertiesMap);
return newNode;
}
- private VfModule populateVfModuleFromGroup(Group group){
+ private VfModule populateVfModuleFromGroup(Group group, ISdcCsarHelper csarHelper){
VfModule vfModule = new VfModule();
-
- vfModule.setVersion(group.getMetadata().getValue(Constants.vfModuleModelVersion));
- vfModule.setCustomizationUuid(group.getMetadata().getValue(Constants.vfModuleModelCustomizationUUID));
- vfModule.setModelCustomizationName(group.getMetadata().getValue(Constants.vfModuleModelName));
- vfModule.setName(group.getMetadata().getValue(Constants.vfModuleModelName));
+ extractBasicPropertiesForGroup(vfModule, group, csarHelper);
vfModule.setVolumeGroupAllowed(isVolumeGroup(group));
- vfModule.setDescription(group.getDescription());
- vfModule.setInvariantUuid(group.getMetadata().getValue(Constants.vfModuleModelInvariantUUID));
- vfModule.setUuid(group.getMetadata().getValue(Constants.vfModuleModelUUID));
- vfModule.setProperties(group.getProperties());
return vfModule;
}
- private VolumeGroup populateVolumeGroupFromGroup(Group group){
+ private VolumeGroup populateVolumeGroupFromGroup(Group group, ISdcCsarHelper csarHelper){
VolumeGroup volumeGroup = new VolumeGroup();
- volumeGroup.setDescription(group.getDescription());
- volumeGroup.setInvariantUuid(group.getMetadata().getValue(Constants.vfModuleModelInvariantUUID));
- volumeGroup.setName(group.getMetadata().getValue(Constants.vfModuleModelName));
- volumeGroup.setModelCustomizationName(group.getMetadata().getValue(Constants.vfModuleModelName));
- volumeGroup.setVersion(group.getMetadata().getValue(Constants.vfModuleModelVersion));
- volumeGroup.setUuid(group.getMetadata().getValue(Constants.vfModuleModelUUID));
- volumeGroup.setCustomizationUuid(group.getMetadata().getValue(Constants.vfModuleModelCustomizationUUID));
-
+ extractBasicPropertiesForGroup(volumeGroup, group, csarHelper);
return volumeGroup;
}
+ private void extractBasicPropertiesForGroup(org.onap.vid.model.Group newGroup, Group group, ISdcCsarHelper csarHelper) {
+ newGroup.setDescription(group.getDescription());
+ newGroup.setVersion(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_VERSION));
+ newGroup.setCustomizationUuid(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_CUSTOMIZATION_UUID));
+ newGroup.setModelCustomizationName(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_NAME));
+ newGroup.setName(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_NAME));
+ newGroup.setUuid(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_UUID));
+ newGroup.setInvariantUuid(group.getMetadata().getValue(Constants.VF_MODULE_MODEL_INVARIANT_UUID));
+ newGroup.setProperties(extractVfModuleProperties(group, csarHelper));
+ newGroup.setInputs(extractVfInputsFromCsarByAnnotation(csarHelper, newGroup));
+ }
+
+
+ private Map<String,org.onap.vid.asdc.beans.tosca.Input> extractVfInputsFromCsarByAnnotation(ISdcCsarHelper csarHelper, org.onap.vid.model.Group group) {
+ Map<String, org.onap.vid.asdc.beans.tosca.Input> inputMap = new HashMap<>();
+ if(group.getProperties().getVfModuleLabel() != null){
+ List<Input> inputsList = csarHelper.getInputsWithAnnotations();
+ for(Input input: inputsList){
+ if(input.getAnnotations() != null){
+ List<Property> annotationProperties = input.getAnnotations().get("source").getProperties();
+ if(isInputMatchesToGroup(annotationProperties, group)){
+ inputMap.put(input.getName(), new org.onap.vid.asdc.beans.tosca.Input(input ,annotationProperties));
+ }
+ }
+ }
+ }
+ return inputMap;
+ }
+
+
+ private boolean isInputMatchesToGroup(List<Property> annotationProperties, org.onap.vid.model.Group group){
+ for(Property property: annotationProperties){
+ if(property.getName().equals(VF_MODULE_LABEL)){
+ return getPropertyValueAsString(property).equals(group.getProperties().getVfModuleLabel());
+ }
+ }
+ return false;
+ }
+
+ public String getPropertyValueAsString(Property property) {
+ return removeSquareBrackets(property.getValue().toString());
+ }
+
+ private String removeSquareBrackets(String stringWithSquareBrackets){
+ return stringWithSquareBrackets.substring(1, stringWithSquareBrackets.length()-1);
+ }
+
+ private GroupProperties extractVfModuleProperties(Group group, ISdcCsarHelper csarHelper){
+ GroupProperties vfModuleProperties = new GroupProperties();
+ if(csarHelper.getGroupPropertyAsObject(group, Constants.MIN_VF_MODULE_INSTANCES) != null)
+ vfModuleProperties.setMinCountInstances((Integer)csarHelper.getGroupPropertyAsObject(group, Constants.MIN_VF_MODULE_INSTANCES));
+ if(csarHelper.getGroupPropertyAsObject(group, Constants.MAX_VF_MODULE_INSTANCES) != null)
+ vfModuleProperties.setMaxCountInstances((Integer)csarHelper.getGroupPropertyAsObject(group, Constants.MAX_VF_MODULE_INSTANCES));
+ if(csarHelper.getGroupPropertyAsObject(group, Constants.INITIAL_COUNT) != null)
+ vfModuleProperties.setInitialCount((Integer)csarHelper.getGroupPropertyAsObject(group, Constants.INITIAL_COUNT));
+ if(csarHelper.getGroupPropertyAsObject(group, VF_MODULE_LABEL) != null)
+ vfModuleProperties.setVfModuleLabel((String) csarHelper.getGroupPropertyAsObject(group, VF_MODULE_LABEL));
+ return vfModuleProperties;
+ }
+
+
+
private Map<String, org.onap.vid.asdc.beans.tosca.Input> extractInputsAndCommandsForNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode){
Map<String, org.onap.vid.asdc.beans.tosca.Input> inputMap = new HashMap<>();
Map<String, CommandProperty> commandPropertyMap = new HashMap<>();
List<Input> inputs = csarHelper.getServiceInputs();
- Map<String, String> properties = csarHelper.filterNodeTemplatePropertiesByValue(nodeTemplate, FilterType.CONTAINS, Constants.getInput);
+ Map<String, String> properties = csarHelper.filterNodeTemplatePropertiesByValue(nodeTemplate, FilterType.CONTAINS, Constants.GET_INPUT);
for (Map.Entry<String, String> property : properties.entrySet()) {
String inputKey = property.getValue();
String key = extractInputValue(inputKey);
@@ -337,7 +497,7 @@ public class ToscaParserImpl2 {
private CommandProperty extractCommands(String displayName, String inputName){
CommandProperty commandProperty = new CommandProperty();
commandProperty.setDisplayName(displayName);
- commandProperty.setCommand(Constants.getInput);
+ commandProperty.setCommand(Constants.GET_INPUT);
commandProperty.setInputName(inputName);
return commandProperty;
}
@@ -345,19 +505,23 @@ public class ToscaParserImpl2 {
private Map<String, String> setPropertiesOfVnf(List<Property> properties) {
Map<String, String> propertiesMap = new HashMap<String, String>();
for (Property property : properties) {
+ //special handling to necessary sub-property "ecomp_generated_naming"
+ if(property.getName().equals("nf_naming")){
+ propertiesMap.put(removeSquareBrackets(((LinkedHashMap)(property.getValue())).keySet().toString()) ,((LinkedHashMap)(property.getValue())).get("ecomp_generated_naming").toString());
+ }
propertiesMap.put(property.getName(), property.getValue().toString());
}
return propertiesMap;
}
private String validateInstantiationType(ISdcCsarHelper csarHelper){
- String instantiationType = csarHelper.getServiceMetadata().getValue(Constants.instantiationType);
- String validatedInstantiationType = Constants.clientConfig;
+ String instantiationType = csarHelper.getServiceMetadata().getValue(Constants.INSTANTIATION_TYPE);
+ String validatedInstantiationType = Constants.CLIENT_CONFIG;
if(instantiationType != null && !instantiationType.isEmpty()){
- if(instantiationType.equalsIgnoreCase(Constants.macro) || instantiationType.equalsIgnoreCase(Constants.both))
- validatedInstantiationType = Constants.macro;
- else if(instantiationType.equalsIgnoreCase(Constants.aLaCarte))
- validatedInstantiationType = Constants.aLaCarte;
+ if(instantiationType.equalsIgnoreCase(Constants.MACRO) || instantiationType.equalsIgnoreCase(Constants.BOTH))
+ validatedInstantiationType = Constants.MACRO;
+ else if(instantiationType.equalsIgnoreCase(Constants.A_LA_CARTE))
+ validatedInstantiationType = Constants.A_LA_CARTE;
}
return validatedInstantiationType;
}