Skip to content

Commit

Permalink
Add image names to VDUs without images
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBri committed Feb 15, 2019
1 parent 6e46b07 commit 06c5e7c
Showing 1 changed file with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<String> 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");
Expand Down Expand Up @@ -270,7 +291,7 @@ public synchronized VirtualNetworkFunctionDescriptor add(
}

vnfPackage = vnfPackageRepository.save(vnfPackage);
// TODO understand this

vnfPackageMetadataRepository.setVNFPackageId(vnfPackage.getId());

virtualNetworkFunctionDescriptor.setVnfPackageLocation(vnfPackage.getId());
Expand All @@ -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<String> extractImageNamesFromMetadata(Map<String, Object> metadata)
throws BadFormatException {
Set<String> imageNames = new HashSet<>();
// extract images from metadata
if (metadata.containsKey("images")) {
try {
Map<String, Map<String, Object>> images =
(Map<String, Map<String, Object>>) 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
Expand Down

0 comments on commit 06c5e7c

Please sign in to comment.