X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fcsar%2Fvnfcatalog%2FVnfVendorImageExtractor.java;h=5f3d15bc5a1805cff8cd96e05f8464aef7e252d8;hb=c1824169b0cfa25101c1efa8118d6b0b085edd15;hp=c272b355b8d9da83085fe3f6445f8f404c0d4fe2;hpb=7f5e9cf4d3cb5dc63fca4e27935b4a3164749406;p=aai%2Fbabel.git
diff --git a/src/main/java/org/onap/aai/babel/csar/vnfcatalog/VnfVendorImageExtractor.java b/src/main/java/org/onap/aai/babel/csar/vnfcatalog/VnfVendorImageExtractor.java
index c272b35..5f3d15b 100644
--- a/src/main/java/org/onap/aai/babel/csar/vnfcatalog/VnfVendorImageExtractor.java
+++ b/src/main/java/org/onap/aai/babel/csar/vnfcatalog/VnfVendorImageExtractor.java
@@ -24,26 +24,25 @@ package org.onap.aai.babel.csar.vnfcatalog;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
-import java.util.function.Consumer;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.time.StopWatch;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.apache.commons.lang3.tuple.Pair;
import org.onap.aai.babel.logging.ApplicationMsgs;
import org.onap.aai.babel.logging.LogHelper;
+import org.onap.aai.babel.parser.ToscaParser;
import org.onap.aai.babel.service.data.BabelArtifact;
import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
import org.onap.sdc.tosca.parser.enums.SdcTypes;
import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
import org.onap.sdc.toscaparser.api.NodeTemplate;
-import org.onap.sdc.toscaparser.api.SubstitutionMappings;
/**
* This class is responsible for extracting Virtual Network Function (VNF) information from a TOSCA 1.1 CSAR package.
@@ -97,6 +96,9 @@ public class VnfVendorImageExtractor {
// The name of the property (for a VNF Configuration type) storing the Vendor Information
private static final String VNF_CONF_TYPE_PROPERTY_VENDOR_INFO_CONTAINER = "allowed_flavors";
+ // Name of property key that contains the Vendor Information
+ private static final String VENDOR_INFO = "vendor_info";
+
// Name of property key that contains the value of model of the Vendor application
private static final String VENDOR_MODEL = "vendor_model";
@@ -126,10 +128,12 @@ public class VnfVendorImageExtractor {
* "Deployment Flavors" x "ImageInfo"
*
*
- * @param csar compressed format that stores multiple TOSCA files and in particular a vnfConfiguration
+ * @param csar
+ * compressed format that stores multiple TOSCA files and in particular a vnfConfiguration
* @return BabelArtifact VendorImageConfiguration objects created during processing represented as the Babel service
* public data structure
- * @throws ToscaToCatalogException if the CSAR content is not valid
+ * @throws ToscaToCatalogException
+ * if the CSAR content is not valid
*/
public BabelArtifact extract(byte[] csar) throws ToscaToCatalogException {
StopWatch stopwatch = new StopWatch();
@@ -162,9 +166,11 @@ public class VnfVendorImageExtractor {
/**
* Creates a temporary file to store the CSAR content.
*
- * @param bytes the CSAR content
+ * @param bytes
+ * the CSAR content
* @return Path to a temporary file containing the CSAR bytes
- * @throws IOException if an I/O error occurs or the temporary-file directory does not exist
+ * @throws IOException
+ * if an I/O error occurs or the temporary-file directory does not exist
*/
private Path createTempFile(byte[] bytes) throws IOException {
Path path = Files.createTempFile("temp", ".csar");
@@ -177,163 +183,134 @@ public class VnfVendorImageExtractor {
* Build VNF Vendor Image Configurations for the VNF Configuration node (if present) in the CSAR file referenced by
* the supplied Path.
*
- * @param csarFilepath the path to the CSAR file
+ * @param csarFilepath
+ * the path to the CSAR file
* @return a List of Vendor Image Configurations
* @throws SdcToscaParserException
* @throws ToscaToCatalogException
* @throws InvalidNumberOfNodesException
*/
private List createVendorImageConfigurations(String csarFilepath)
- throws SdcToscaParserException, ToscaToCatalogException, InvalidNumberOfNodesException {
- List vendorImageConfigurations = new ArrayList<>();
-
+ throws SdcToscaParserException, InvalidNumberOfNodesException {
ISdcCsarHelper csarHelper = SdcToscaParserFactory.getInstance().getSdcCsarHelper(csarFilepath);
- NodeTemplate vnfConfigurationNode = findVnfConfigurationNode(csarHelper);
- applicationLogger.info(ApplicationMsgs.DISTRIBUTION_EVENT,
- String.format("Found VNF Configuration node \"%s\"", vnfConfigurationNode));
-
- if (vnfConfigurationNode != null) {
- for (NodeTemplate node : csarHelper.getServiceVfList()) {
- vendorImageConfigurations.addAll(buildVendorImageConfigurations(vnfConfigurationNode, node));
- }
- }
-
- return vendorImageConfigurations;
- }
+ List serviceVfList = ToscaParser.getServiceNodeTemplates(csarHelper)
+ .filter(ToscaParser.filterOnType(SdcTypes.VF)).collect(Collectors.toList());
- /**
- * Find VNF configuration node.
- *
- * @param csarHelper the csar helper
- * @return the node template
- * @throws InvalidNumberOfNodesException
- */
- private NodeTemplate findVnfConfigurationNode(ISdcCsarHelper csarHelper) throws InvalidNumberOfNodesException {
- List nodeTemplates = csarHelper.getServiceNodeTemplateBySdcType(SdcTypes.VF);
- applicationLogger.debug(nodeTemplates.toString());
-
- List configNodes = nodeTemplates.stream() //
- .map(serviceNodeTemplate -> {
- String uuid = csarHelper.getNodeTemplateCustomizationUuid(serviceNodeTemplate);
- applicationLogger.debug(serviceNodeTemplate + " Customization UUID is " + uuid);
- return csarHelper.getVnfConfig(uuid);
- }) //
+ List vnfConfigs = serviceVfList.stream()
+ .flatMap(vf -> vf.getSubMappingToscaTemplate().getNodeTemplates().stream()
+ .filter(ToscaParser.filterOnType(SdcTypes.VFC)) //
+ .filter(vfc -> vfc.getType().endsWith("VnfConfiguration")))
.filter(Objects::nonNull) //
.collect(Collectors.toList());
- if (configNodes.size() > 1) {
- throw new InvalidNumberOfNodesException("Only one vnf configuration node is allowed however "
- + configNodes.size() + " nodes were found in the csar.");
+ if (!vnfConfigs.isEmpty()) {
+ NodeTemplate vnfConfigurationNode = vnfConfigs.get(0);
+
+ applicationLogger.info(ApplicationMsgs.DISTRIBUTION_EVENT,
+ String.format("Found VNF Configuration node \"%s\"", vnfConfigurationNode));
+
+ if (vnfConfigs.size() > 1) {
+ throw new InvalidNumberOfNodesException("Only one VNF configuration node is allowed however "
+ + vnfConfigs.size() + " nodes were found in the CSAR.");
+ }
+
+ return createVendorImageConfigurations(serviceVfList, vnfConfigurationNode);
}
- return configNodes.size() == 1 ? configNodes.get(0) : null;
+ return Collections.emptyList();
}
/**
- * Builds the Vendor image configurations.
+ * Build VNF Vendor Image Configurations for each Service VF, using the flavors of the specified VNF Configuration
+ * node.
*
- * @param vendorInfoNode the vendor info node
- * @param node the node
- * @return the list
- * @throws ToscaToCatalogException if there are no software versions
+ * @param serviceVfList
+ * the Service level VF node templates
+ * @param vnfConfigurationNode
+ * the VNF node template
+ * @return a new List of Vendor Image Configurations
*/
- private List buildVendorImageConfigurations(NodeTemplate vendorInfoNode,
- NodeTemplate node) throws ToscaToCatalogException {
- List vendorImageConfigurations = new ArrayList<>();
-
- List softwareVersions = extractSoftwareVersions(node.getSubMappingToscaTemplate());
+ private List createVendorImageConfigurations(List serviceVfList,
+ NodeTemplate vnfConfigurationNode) {
+ List vendorImageConfigurations = Collections.emptyList();
- Consumer super Pair> buildConfigurations =
- vi -> vendorImageConfigurations.addAll(softwareVersions.stream() //
- .map(sv -> (new VendorImageConfiguration(vi.getRight(), vi.getLeft(), sv)))
- .collect(Collectors.toList()));
+ Object allowedFlavorProperties =
+ vnfConfigurationNode.getPropertyValue(VNF_CONF_TYPE_PROPERTY_VENDOR_INFO_CONTAINER);
- String resourceVendor = node.getMetaData().getValue("resourceVendor");
+ if (allowedFlavorProperties instanceof Map) {
+ @SuppressWarnings("unchecked")
+ Collection