From c72d565bb58226b20625b2bce5f0019046bee649 Mon Sep 17 00:00:00 2001 From: "Sonsino, Ofir (os0695)" Date: Tue, 10 Jul 2018 14:20:54 +0300 Subject: Merge 1806 code of vid-common Change-Id: I75d52abed4a24dfe3827d79edc4a2938726aa87a Issue-ID: VID-208 Signed-off-by: Sonsino, Ofir (os0695) --- .../java/org/onap/vid/asdc/parser/ToscaParser.java | 9 +- .../org/onap/vid/asdc/parser/ToscaParserImpl.java | 137 ++++----- .../org/onap/vid/asdc/parser/ToscaParserImpl2.java | 342 +++++++++++++++------ 3 files changed, 310 insertions(+), 178 deletions(-) (limited to 'vid-app-common/src/main/java/org/onap/vid/asdc/parser') 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> imports : parentModel.getImports()) { - LOG.debug("imports = " + imports.toString()); - for (Entry> 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> imports : parentModel.getImports()) { + LOG.debug("imports = " + imports.toString()); + for (Entry> 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 vnfs = new HashMap(); - final Map networks = new HashMap(); + final Map vnfs = new HashMap<>(); + final Map 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 vnfs, - final Map networks, final ToscaModel asdcServiceToscaModel, ServiceModel serviceModel) - throws AsdcCatalogException, SdcToscaParserException { + final Map networks, final ToscaModel asdcServiceToscaModel, ServiceModel serviceModel) { for (Entry 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 extractVnfsFromCsar(ServiceModel serviceModel,ISdcCsarHelper csarHelper) { + private Map extractCRFromCsar(ISdcCsarHelper sdcCsarHelper) { + List nodeTemplates = sdcCsarHelper.getServiceNodeTemplates(); + Map 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 getNetworksCollectionMapFromGroupsList(ISdcCsarHelper sdcCsarHelper, NodeTemplate nodeTemplate) { + List groups = sdcCsarHelper.getGroupsOfOriginOfNodeTemplateByToscaGroupType(nodeTemplate, Constants.ORG_OPENECOMP_GROUPS_NETWORK_COLLECTION); + Map networksCollectionMap = new HashMap(); + 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 properties = group.getProperties(); + Map 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 extractVnfsFromCsar(ISdcCsarHelper csarHelper) { List nodeTemplates = csarHelper.getServiceVfList(); Map vnfsMaps = new HashMap(); for (NodeTemplate nodeTemplate : nodeTemplates) { VNF vnf = new VNF(); populateNodeFromNodeTemplate(nodeTemplate, csarHelper, vnf); - vnf.setModelCustomizationName(nodeTemplate.getName()); - Map vfModuleHashMap = getVfModulesFromVF(csarHelper, vnf.getCustomizationUuid()); - vnf.setVfModules(vfModuleHashMap); - - Map 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 getVfcInstanceGroup(ISdcCsarHelper csarHelper, NodeTemplate nodeTemplate) { + List 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 extractPortMirroringConfigFromCsar(ISdcCsarHelper csarHelper) { List nodeTemplates = csarHelper.getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION); Map configMaps = new HashMap<>(); @@ -175,18 +286,18 @@ public class ToscaParserImpl2 { Map getVfModulesFromVF(ISdcCsarHelper csarHelper, String vfUuid) { List vfModulesByVf = csarHelper.getVfModulesByVf(vfUuid); return vfModulesByVf.stream() - .collect(toMap(Group::getName, this::populateVfModuleFromGroup)); + .collect(toMap(Group::getName, group -> populateVfModuleFromGroup(group, csarHelper))); } Map getVolumeGroupsFromVF(ISdcCsarHelper csarHelper, String vfCustomizationUuid) { List 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 extractNetworksFromCsar(ISdcCsarHelper csarHelper) { @@ -220,7 +331,7 @@ public class ToscaParserImpl2 { for (NodeTemplate nodeTemplate : serviceVfList) { Map 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 inputsListToInputsMap(List inputList) { Map 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 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 extractVfInputsFromCsarByAnnotation(ISdcCsarHelper csarHelper, org.onap.vid.model.Group group) { + Map inputMap = new HashMap<>(); + if(group.getProperties().getVfModuleLabel() != null){ + List inputsList = csarHelper.getInputsWithAnnotations(); + for(Input input: inputsList){ + if(input.getAnnotations() != null){ + List 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 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 extractInputsAndCommandsForNodeTemplate(NodeTemplate nodeTemplate, ISdcCsarHelper csarHelper, Node newNode){ Map inputMap = new HashMap<>(); Map commandPropertyMap = new HashMap<>(); List inputs = csarHelper.getServiceInputs(); - Map properties = csarHelper.filterNodeTemplatePropertiesByValue(nodeTemplate, FilterType.CONTAINS, Constants.getInput); + Map properties = csarHelper.filterNodeTemplatePropertiesByValue(nodeTemplate, FilterType.CONTAINS, Constants.GET_INPUT); for (Map.Entry 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 setPropertiesOfVnf(List properties) { Map propertiesMap = new HashMap(); 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; } -- cgit 1.2.3-korg