@Test public void testContinuousIsSatisfied() { Model mo = new DefaultModel(); List<VM> vms = Util.newVMs(mo, 5); List<Node> ns = Util.newNodes(mo, 5); 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.addReadyVM(vms.get(2)); map.addRunningVM(vms.get(3), ns.get(2)); Quarantine q = new Quarantine(ns.get(0)); ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo); Assert.assertEquals(q.isSatisfied(plan), true); plan.add(new ShutdownVM(vms.get(1), ns.get(1), 1, 2)); Assert.assertEquals(q.isSatisfied(plan), true); plan.add(new BootVM(vms.get(2), ns.get(0), 0, 1)); Assert.assertEquals(q.isSatisfied(plan), false); plan = new DefaultReconfigurationPlan(mo); plan.add(new BootVM(vms.get(2), ns.get(2), 0, 1)); Assert.assertEquals(new Quarantine(ns.get(1)).isSatisfied(plan), true); plan.add(new MigrateVM(vms.get(3), ns.get(2), ns.get(1), 0, 1)); Assert.assertEquals(new Quarantine(ns.get(1)).isSatisfied(plan), false); plan = new DefaultReconfigurationPlan(mo); plan.add(new MigrateVM(vms.get(1), ns.get(1), ns.get(0), 0, 1)); Assert.assertEquals(q.isSatisfied(plan), false); }
@Override public boolean insertActions(Solution s, ReconfigurationPlan plan) { DurationEvaluators dev = rp.getDurationEvaluators(); // Only if the VM doesn't stay if (s.getIntVal(cSlice.getHoster()) != (s.getIntVal(dSlice.getHoster()))) { Action a; Node dst = rp.getNode(s.getIntVal(dSlice.getHoster())); // Migration if (s.getIntVal(doReinstantiation) == 0) { int st = s.getIntVal(getStart()); int ed = s.getIntVal(getEnd()); if (getBandwidth() != null) { a = new MigrateVM(vm, src, dst, st, ed, s.getIntVal(getBandwidth())); } else { a = new MigrateVM(vm, src, dst, st, ed); } plan.add(a); // Re-instantiation } else { VM newVM = rp.cloneVM(vm); if (newVM == null) { rp.getLogger().error("Unable to get a new int to plan the re-instantiate of VM {}", vm); return false; } org.btrplace.plan.event.ForgeVM fvm = new org.btrplace.plan.event.ForgeVM( newVM, s.getIntVal(dSlice.getStart()) - dev.evaluate(rp.getSourceModel(), org.btrplace.plan.event.ForgeVM.class, vm), s.getIntVal(dSlice.getStart())); // forge the new VM from a template plan.add(fvm); // Boot the new VM int endForging = fvm.getEnd(); org.btrplace.plan.event.BootVM boot = new org.btrplace.plan.event.BootVM( newVM, dst, endForging, endForging + dev.evaluate( rp.getSourceModel(), org.btrplace.plan.event.BootVM.class, newVM)); boot.addEvent(Action.Hook.PRE, new SubstitutedVMEvent(vm, newVM)); return plan.add(boot) && plan.add( new org.btrplace.plan.event.ShutdownVM( vm, src, boot.getEnd(), s.getIntVal(cSlice.getEnd()))); } } return true; }