use of org.btrplace.model.Node in project scheduler by btrplace.
the class Network method createDefaultNetwork.
/**
* Create and attach a default network view to the given model.
* Basically, the Network consists of a main non-blocking switch connected
* to all the existing nodes in the model using links with the given
* bandwidth in Mbit/sec.
*
* Note: replace the previous Network view attached to the model (if exists).
*
* @param mo the model to add/replace the Network view
* @param bw the links bandwidth
* @return the new 'default' network view, already attached to the given model
*/
public static Network createDefaultNetwork(Model mo, int bw) {
Network net = new Network();
// Main non-blocking switch
Switch mainSwitch = net.newSwitch();
for (Node n : mo.getMapping().getAllNodes()) {
// Connect all nodes with 1Gbit/s links
net.connect(bw, mainSwitch, n);
}
// Remove the current Network view if exists
if (get(mo) != null) {
mo.detach(get(mo));
}
mo.attach(net);
return net;
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class MaxOnlineChecker method startsWith.
@Override
public boolean startsWith(Model mo) {
if (getConstraint().isContinuous()) {
Mapping map = mo.getMapping();
currentOnline = 0;
for (Node n : getConstraint().getInvolvedNodes()) {
if (map.isOnline(n)) {
currentOnline++;
}
}
return currentOnline <= getConstraint().getAmount();
}
return true;
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class AmongTest method testEqualsHashCode.
@Test(dependsOnMethods = { "testInstantiation" })
public void testEqualsHashCode() {
Model mo = new DefaultModel();
List<Node> ns = Util.newNodes(mo, 10);
List<VM> vms = Util.newVMs(mo, 10);
Collection<Node> s1 = Arrays.asList(ns.get(0), ns.get(1));
Collection<Node> s2 = Collections.singletonList(ns.get(2));
Collection<Collection<Node>> pGrps = Arrays.asList(s1, s2);
Set<VM> vg = new HashSet<>(Arrays.asList(vms.get(0), vms.get(1), vms.get(2)));
Among a = new Among(vg, pGrps);
Assert.assertTrue(a.equals(a));
Assert.assertTrue(a.equals(new Among(new HashSet<>(vg), pGrps)));
Assert.assertEquals(a.hashCode(), new Among(new HashSet<>(vg), pGrps).hashCode());
Assert.assertFalse(a.equals(new Among(new HashSet<>(), pGrps)));
Assert.assertFalse(a.equals(new Among(new HashSet<>(vg), Collections.emptyList())));
Among a2 = new Among(new HashSet<>(vg), Collections.emptyList());
a2.setContinuous(true);
Assert.assertFalse(a.equals(a2));
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class AmongTest method testContinuousIsSatisfied.
@Test(dependsOnMethods = { "testInstantiation" })
public void testContinuousIsSatisfied() {
Model mo = new DefaultModel();
List<Node> ns = Util.newNodes(mo, 10);
List<VM> vms = Util.newVMs(mo, 10);
Collection<Node> s1 = new HashSet<>(Arrays.asList(ns.get(0), ns.get(1)));
Collection<Node> s2 = new HashSet<>(Collections.singletonList(ns.get(2)));
Collection<Collection<Node>> pGrps = Arrays.asList(s1, s2);
Set<VM> vs = new HashSet<>(Arrays.asList(vms.get(0), vms.get(1), vms.get(2)));
Among a = new Among(vs, pGrps, true);
Mapping map = mo.getMapping();
map.addOnlineNode(ns.get(0));
map.addOnlineNode(ns.get(1));
map.addOnlineNode(ns.get(2));
map.addRunningVM(vms.get(0), ns.get(0));
map.addRunningVM(vms.get(1), ns.get(1));
map.addRunningVM(vms.get(2), ns.get(1));
ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
Assert.assertEquals(a.isSatisfied(plan), true);
plan.add(new MigrateVM(vms.get(2), ns.get(1), ns.get(2), 0, 1));
plan.add(new MigrateVM(vms.get(2), ns.get(2), ns.get(1), 1, 2));
// At moment 1, the constraint will be violated
Assert.assertEquals(a.isSatisfied(plan), false);
}
use of org.btrplace.model.Node in project scheduler by btrplace.
the class AmongTest method testInstantiation.
@Test
public void testInstantiation() {
Model mo = new DefaultModel();
List<Node> ns = Util.newNodes(mo, 10);
List<VM> vms = Util.newVMs(mo, 10);
Collection<Node> s1 = Arrays.asList(ns.get(0), ns.get(1));
Collection<Node> s2 = Collections.singletonList(ns.get(2));
Collection<Collection<Node>> pGrps = Arrays.asList(s1, s2);
Set<VM> vg = new HashSet<>(Arrays.asList(vms.get(0), vms.get(1), vms.get(2)));
Among a = new Among(vg, pGrps);
Assert.assertNotNull(a.getChecker());
Assert.assertEquals(a.getInvolvedVMs(), vg);
Assert.assertEquals(a.getGroupsOfNodes(), pGrps);
Assert.assertEquals(a.getInvolvedNodes().size(), s1.size() + s2.size());
Assert.assertTrue(a.getInvolvedNodes().containsAll(s1));
Assert.assertTrue(a.getInvolvedNodes().containsAll(s2));
Assert.assertFalse(a.toString().contains("null"));
Assert.assertFalse(a.isContinuous());
Assert.assertTrue(a.setContinuous(true));
Assert.assertTrue(a.setContinuous(false));
a = new Among(vg, pGrps, true);
Assert.assertTrue(a.isContinuous());
}
Aggregations