diff --git a/core/core-impl/src/main/java/org/openbaton/nfvo/core/api/VNFPackageManagement.java b/core/core-impl/src/main/java/org/openbaton/nfvo/core/api/VNFPackageManagement.java index d373566f6..deed14152 100644 --- a/core/core-impl/src/main/java/org/openbaton/nfvo/core/api/VNFPackageManagement.java +++ b/core/core-impl/src/main/java/org/openbaton/nfvo/core/api/VNFPackageManagement.java @@ -27,6 +27,7 @@ import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.locks.ReentrantLock; +import java.util.stream.Collectors; import org.apache.commons.compress.archivers.ArchiveException; import org.apache.commons.compress.archivers.ArchiveInputStream; import org.apache.commons.compress.archivers.ArchiveStreamFactory; @@ -128,6 +129,16 @@ private VirtualNetworkFunctionDescriptor handleVirtualNetworkFunctionDescriptor( vdu.setName(virtualNetworkFunctionDescriptor.getName() + "-" + i); i++; } + if (vdu.getVm_image() != null && !vdu.getVm_image().isEmpty()) { + // filter blank image names + vdu.setVm_image( + vdu.getVm_image() + .stream() + .filter(image -> !image.trim().equals("")) + .collect(Collectors.toSet())); + } else { + vdu.setVm_image(new HashSet<>()); + } } for (VirtualDeploymentUnit vdu : virtualNetworkFunctionDescriptor.getVdu()) { log.debug("vdu name: " + vdu.getName()); @@ -230,6 +241,16 @@ public synchronized VirtualNetworkFunctionDescriptor add( } } + if (metadata.containsKey("images")) { + // add images from Metadata.yaml to VDUs IF THEY DO NOT specify any image + Set imageNames = extractImageNamesFromMetadata(metadata); + for (VirtualDeploymentUnit vdu : virtualNetworkFunctionDescriptor.getVdu()) { + if (vdu.getVm_image() == null || vdu.getVm_image().isEmpty()) { + vdu.setVm_image(imageNames); + } + } + } + VNFPackageMetadata vnfPackageMetadata = handleVnfPackageMetadata( metadata, vnfPackage, virtualNetworkFunctionDescriptor.getEndpoint(), projectId, "tar"); @@ -270,7 +291,7 @@ public synchronized VirtualNetworkFunctionDescriptor add( } vnfPackage = vnfPackageRepository.save(vnfPackage); - // TODO understand this + vnfPackageMetadataRepository.setVNFPackageId(vnfPackage.getId()); virtualNetworkFunctionDescriptor.setVnfPackageLocation(vnfPackage.getId()); @@ -286,6 +307,33 @@ public synchronized VirtualNetworkFunctionDescriptor add( return virtualNetworkFunctionDescriptor; } + /** + * Returns a Set of image names that are listed in the metadata under images. + * + * @param metadata the Metadata.yaml file as a Map + * @return the image names + * @throws BadFormatException if the metadata cannot be parsed + */ + private Set extractImageNamesFromMetadata(Map metadata) + throws BadFormatException { + Set imageNames = new HashSet<>(); + // extract images from metadata + if (metadata.containsKey("images")) { + try { + Map> images = + (Map>) metadata.get("images"); + + for (String imageName : images.keySet()) { + imageNames.add(imageName); + } + } catch (Exception e) { + throw new BadFormatException( + "Unable to parse 'images' section of VNF package metadata: " + e.getMessage()); + } + } + return imageNames; + } + private VirtualNetworkFunctionDescriptor setIPConfigurations( VirtualNetworkFunctionDescriptor virtualNetworkFunctionDescriptor) { // If the VNF manager is not the fixed-host then skip this part