use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.
the class CMinMigrationsTest method main.
public static void main(String[] args) {
String root = "/Users/fabien.hermenier/Documents/BtrPlace/nutanix/instances";
List<OptConstraint> objs = Arrays.asList(/*new MinMTTR(),*/
new MinMigrations());
boolean verbose = true;
for (OptConstraint o : objs) {
System.out.print(" " + o);
}
System.out.println();
for (int idx = 1; idx <= 256; idx += 5) {
String path = root + "/lazan/lazan-" + idx + ".json.gz";
if (verbose) {
System.out.println("--- " + idx + " --- ");
} else {
System.out.print(idx);
}
List<Long> res = new ArrayList<>();
for (OptConstraint o : objs) {
if (verbose) {
System.out.println("\t" + o);
}
Instance i = JSON.readInstance(new File(path));
if (Network.get(i.getModel()) != null) {
i.getModel().detach(Network.get(i.getModel()));
}
i = new Instance(i.getModel(), i.getSatConstraints(), o);
ChocoScheduler s = new DefaultChocoScheduler();
s.doOptimize(false);
s.setTimeLimit(30);
s.doRepair(false);
ReconfigurationPlan p = s.solve(i);
Assert.assertNotNull(p);
res.add(p.getActions().stream().filter(x -> x instanceof MigrateVM).mapToLong(x -> x.getEnd() - x.getStart()).sum());
// res.add((long)s.getStatistics().lastSolution().getDuration());
if (verbose) {
System.out.println(s.getStatistics());
// System.out.println(p);
}
}
if (!verbose) {
for (Long l : res) {
System.out.print("\t" + l);
}
System.out.println();
}
}
}
use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.
the class DefaultChocoScheduler method solve.
@Override
public ReconfigurationPlan solve(Instance i) throws SchedulerException {
Model mo = i.getModel();
Collection<SatConstraint> cstrs = i.getSatConstraints();
// If a network view is attached, ensure that all the migrations' destination node are defined
Network net = Network.get(mo);
stages = null;
if (net != null) {
// The network view is useless to take placement decisions
mo.detach(net);
// Solve a first time using placement oriented MinMTTR optimisation constraint
ReconfigurationPlan p = runner.solve(params, i);
stages = new StagedSolvingStatistics(runner.getStatistics());
if (p == null) {
return null;
}
// Add Fence constraints for each destination node chosen
List<SatConstraint> newCstrs = p.getActions().stream().filter(a -> a instanceof MigrateVM).map(a -> new Fence(((MigrateVM) a).getVM(), Collections.singleton(((MigrateVM) a).getDestinationNode()))).collect(Collectors.toList());
Model result = p.getResult();
if (result == null) {
throw new InconsistentSolutionException(mo, p, "The plan cannot be applied");
}
// Add Root constraints to all staying VMs
newCstrs.addAll(mo.getMapping().getRunningVMs().stream().filter(v -> p.getOrigin().getMapping().getVMLocation(v).id() == result.getMapping().getVMLocation(v).id()).map(Root::new).collect(Collectors.toList()));
// Add the old constraints
newCstrs.addAll(cstrs);
// Re-attach the network view
mo.attach(net);
// New timeout value = elapsed time - initial timeout value
Parameters ps = new DefaultParameters(params);
if (ps.getTimeLimit() > 0) {
// in seconds
double timeout = params.getTimeLimit() - runner.getStatistics().getMetrics().timeCount() / 1000;
ps.setTimeLimit((int) timeout);
}
return runner.solve(ps, new Instance(mo, newCstrs, i.getOptConstraint()));
}
// Solve and return the computed plan
return runner.solve(params, new Instance(mo, cstrs, i.getOptConstraint()));
}
use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.
the class GatherTest method testContinuousIsSatisfied.
@Test(dependsOnMethods = { "testDiscreteIsSatisfied" })
public void testContinuousIsSatisfied() {
Model mo = new DefaultModel();
List<Node> ns = Util.newNodes(mo, 10);
List<VM> vms = Util.newVMs(mo, 10);
Set<VM> s = new HashSet<>(Arrays.asList(vms.get(0), vms.get(1)));
Gather g = new Gather(s);
g.setContinuous(true);
Mapping map = mo.getMapping();
map.addOnlineNode(ns.get(0));
map.addOnlineNode(ns.get(1));
map.addRunningVM(vms.get(0), ns.get(0));
map.addReadyVM(vms.get(1));
map.addRunningVM(vms.get(1), ns.get(1));
ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
Assert.assertEquals(g.isSatisfied(plan), false);
map.addReadyVM(vms.get(1));
Assert.assertEquals(g.isSatisfied(plan), true);
plan.add(new BootVM(vms.get(1), ns.get(0), 0, 1));
Assert.assertEquals(g.isSatisfied(plan), true);
map.addRunningVM(vms.get(1), ns.get(0));
plan = new DefaultReconfigurationPlan(mo);
plan.add(new MigrateVM(vms.get(1), ns.get(0), ns.get(1), 0, 1));
plan.add(new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 1));
Assert.assertEquals(g.isSatisfied(plan), false);
}
use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.
the class NoDelayTest method testIsSatisfied.
@Test
public void testIsSatisfied() {
// Create a new default model
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
// Create 4 nodes
List<Node> ns = Util.newNodes(mo, 4);
// Create 2 vms
List<VM> vms = Util.newVMs(mo, 2);
// Set the nodes online
map.addOnlineNode(ns.get(0));
map.addOnlineNode(ns.get(1));
map.addOnlineNode(ns.get(2));
map.addOnlineNode(ns.get(3));
// Run the 2 vms on the two first nodes
map.addRunningVM(vms.get(0), ns.get(0));
map.addRunningVM(vms.get(1), ns.get(1));
// Set as initial plan
ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
// Create a NoDelay constraint by constraining the first VM
NoDelay nd = new NoDelay(vms.get(0));
// The constraint should be satisfied by default
Assert.assertEquals(nd.isSatisfied(plan), true);
// Migrate the first VM (constrained) at t=0 to the third node
plan.add(new MigrateVM(vms.get(0), ns.get(0), ns.get(2), 0, 1));
Assert.assertEquals(nd.isSatisfied(plan), true);
// Migrate the second VM at t=0 to the last node
plan.add(new MigrateVM(vms.get(1), ns.get(1), ns.get(3), 0, 1));
Assert.assertEquals(nd.isSatisfied(plan), true);
// Re-Migrate the second VM at t=1 to the second node
plan.add(new MigrateVM(vms.get(1), ns.get(3), ns.get(1), 1, 2));
Assert.assertEquals(nd.isSatisfied(plan), true);
// Re-Migrate the first VM (constrained) at t=1 to the first node
plan.add(new MigrateVM(vms.get(0), ns.get(2), ns.get(0), 1, 2));
Assert.assertEquals(nd.isSatisfied(plan), false);
// Shutdown node
// plan.add(new ShutdownNode(ns.get(2), 0, 1));
// Assert.assertEquals(nd.isSatisfied(plan), true);
// Boot node
// plan.add(new BootNode(ns.get(2), 1, 3));
// Assert.assertEquals(nd.isSatisfied(plan), false);
}
use of org.btrplace.plan.event.MigrateVM in project scheduler by btrplace.
the class PreserveTest method testIsSatisfied.
@Test(dependsOnMethods = { "testInstantiation" })
public void testIsSatisfied() {
Model m = new DefaultModel();
List<VM> vms = Util.newVMs(m, 5);
List<Node> ns = Util.newNodes(m, 5);
ShareableResource rc = new ShareableResource("cpu", 3, 3);
Mapping map = m.getMapping();
map.addOnlineNode(ns.get(0));
map.addOnlineNode(ns.get(1));
map.addRunningVM(vms.get(0), ns.get(0));
map.addSleepingVM(vms.get(1), ns.get(0));
map.addRunningVM(vms.get(2), ns.get(0));
m.attach(rc);
Preserve p = new Preserve(vms.get(0), "cpu", 3);
rc.setConsumption(vms.get(0), 3);
// Not running so we don't care
rc.setConsumption(vms.get(1), 1);
rc.setConsumption(vms.get(2), 3);
Assert.assertEquals(true, p.isSatisfied(m));
// Set to 3 by default
rc.unset(vms.get(2));
Assert.assertEquals(true, p.isSatisfied(m));
Assert.assertEquals(false, new Preserve(vms.get(2), "mem", 3).isSatisfied(m));
ReconfigurationPlan plan = new DefaultReconfigurationPlan(m);
rc.setConsumption(vms.get(1), 1);
Assert.assertFalse(new Preserve(vms.get(2), "cpu", 4).isSatisfied(plan));
plan.add(new Allocate(vms.get(2), ns.get(0), "cpu", 7, 5, 7));
Assert.assertTrue(p.isSatisfied(plan));
rc.setConsumption(vms.get(0), 1);
AllocateEvent e = new AllocateEvent(vms.get(0), "cpu", 4);
Assert.assertFalse(p.isSatisfied(plan));
MigrateVM mig = new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
mig.addEvent(Action.Hook.POST, e);
plan.add(mig);
Assert.assertTrue(p.isSatisfied(plan));
}
Aggregations