GIPS algos: adds a check to ensure given vnets are exclusively available in the model

This commit is contained in:
Maximilian Kratz 2024-06-06 10:27:01 +02:00
parent 9e89228398
commit 02a431331c
4 changed files with 51 additions and 0 deletions

View file

@ -69,6 +69,8 @@ public class VneGipsAlgorithm extends AbstractAlgorithm {
throw new IllegalArgumentException("Provided set of virtual networks was empty.");
}
VneGipsAlgorithmUtils.checkGivenVnets(vNets);
if (instance == null) {
instance = new VneGipsAlgorithm(sNet, vNets);
}

View file

@ -0,0 +1,45 @@
package algorithms.gips;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import facade.ModelFacade;
import model.Network;
import model.VirtualNetwork;
public class VneGipsAlgorithmUtils {
/**
* Checks if the given set of virtual networks exactly match the non-embedded
* virtual networks within the model.
*
* @param vNets Set of virtual networks to check for.
*/
protected static void checkGivenVnets(final Set<VirtualNetwork> vNets) {
if (vNets == null) {
throw new IllegalArgumentException("Virtual network set was null.");
}
final Collection<Network> modelNets = ModelFacade.getInstance().getAllNetworks();
final Set<VirtualNetwork> modelVnets = new HashSet<VirtualNetwork>();
for (final Network n : modelNets) {
if (n instanceof VirtualNetwork vnet) {
if (vnet.getHost() == null && vnet.getHostServer() == null) {
modelVnets.add(vnet);
}
}
}
if (vNets.size() != modelVnets.size()) {
throw new IllegalStateException("Number of given virtual networks does not match the number of "
+ "non-embedded virtual networks existing in the model.");
}
if (!vNets.containsAll(modelVnets) || !modelVnets.containsAll(vNets)) {
throw new IllegalStateException("Given set of virtual network does not match the set of non-embedded"
+ " virtual networks existing in the model.");
}
}
}

View file

@ -84,6 +84,8 @@ public class VneGipsMigrationAlgorithm extends AbstractAlgorithm {
throw new IllegalArgumentException("Provided set of virtual networks was empty.");
}
VneGipsAlgorithmUtils.checkGivenVnets(vNets);
if (instance == null) {
instance = new VneGipsMigrationAlgorithm(sNet, vNets);
}

View file

@ -69,6 +69,8 @@ public class VneGipsSeqAlgorithm extends AbstractAlgorithm {
throw new IllegalArgumentException("Provided set of virtual networks was empty.");
}
VneGipsAlgorithmUtils.checkGivenVnets(vNets);
if (instance == null) {
instance = new VneGipsSeqAlgorithm(sNet, vNets);
}