use of org.btrplace.plan.event.SuspendVM in project scheduler by btrplace.
the class DefaultPlanApplierTest method testFireSimpleAction.
@Test(dependsOnMethods = { "testEventCommittedListeners" })
public void testFireSimpleAction() {
DefaultPlanApplier app = new MockApplier();
EventCommittedListener ev = mock(EventCommittedListener.class);
app.addEventCommittedListener(ev);
BootVM b = new BootVM(vms.get(0), ns.get(0), 0, 5);
app.fireAction(b);
verify(ev, times(1)).committed(b);
ShutdownVM svm = new ShutdownVM(vms.get(0), ns.get(0), 0, 5);
app.fireAction(svm);
verify(ev, times(1)).committed(svm);
BootNode bn = new BootNode(ns.get(0), 0, 5);
app.fireAction(bn);
verify(ev, times(1)).committed(bn);
ShutdownNode sn = new ShutdownNode(ns.get(0), 0, 5);
app.fireAction(sn);
verify(ev, times(1)).committed(sn);
SuspendVM susVM = new SuspendVM(vms.get(0), ns.get(0), ns.get(1), 0, 5);
app.fireAction(susVM);
verify(ev, times(1)).committed(susVM);
ResumeVM resVM = new ResumeVM(vms.get(0), ns.get(0), ns.get(1), 0, 5);
app.fireAction(resVM);
verify(ev, times(1)).committed(resVM);
MigrateVM miVM = new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 5);
app.fireAction(miVM);
verify(ev, times(1)).committed(miVM);
KillVM kvm = new KillVM(vms.get(0), ns.get(0), 0, 5);
app.fireAction(kvm);
verify(ev, times(1)).committed(kvm);
ForgeVM fvm = new ForgeVM(vms.get(0), 0, 5);
app.fireAction(fvm);
verify(ev, times(1)).committed(fvm);
}
use of org.btrplace.plan.event.SuspendVM in project scheduler by btrplace.
the class DefaultReconfigurationPlanTest method testDumb.
@Test
public void testDumb() {
Model mo = new DefaultModel();
VM v = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
mo.getMapping().addOnlineNode(n1);
mo.getMapping().addOnlineNode(n2);
mo.getMapping().addRunningVM(v, n1);
ReconfigurationPlan p1 = new DefaultReconfigurationPlan(mo);
Action a1 = new SuspendVM(v, n1, n1, 0, 1);
Action a2 = new ShutdownNode(n1, 1, 2);
Action a3 = new ShutdownNode(n2, 1, 2);
Assert.assertTrue(p1.add(a1));
Assert.assertTrue(p1.add(a2));
Assert.assertTrue(p1.add(a3));
Assert.assertTrue(p1.getActions().contains(a1));
Assert.assertTrue(p1.getActions().contains(a2));
Assert.assertTrue(p1.getActions().contains(a3));
}
use of org.btrplace.plan.event.SuspendVM in project scheduler by btrplace.
the class SplitTest method testContinuousIsSatisfied.
@Test
public void testContinuousIsSatisfied() {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
List<Node> ns = Util.newNodes(mo, 3);
List<VM> vms = Util.newVMs(mo, 5);
map.addOnlineNode(ns.get(0));
map.addOnlineNode(ns.get(1));
map.addOnlineNode(ns.get(2));
Collection<VM> s1 = Arrays.asList(vms.get(0), vms.get(1));
Collection<VM> s2 = Arrays.asList(vms.get(2), vms.get(3));
Collection<VM> s3 = Collections.singleton(vms.get(4));
Collection<Collection<VM>> args = Arrays.asList(s1, s2, s3);
map.addRunningVM(vms.get(0), ns.get(0));
map.addRunningVM(vms.get(1), ns.get(0));
map.addRunningVM(vms.get(2), ns.get(1));
map.addRunningVM(vms.get(3), ns.get(1));
Split sp = new Split(args, true);
ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
Assert.assertEquals(sp.isSatisfied(plan), true);
// Violation
map.addRunningVM(vms.get(2), ns.get(0));
Assert.assertEquals(sp.isSatisfied(plan), false);
plan.add(new MigrateVM(vms.get(2), ns.get(0), ns.get(1), 0, 1));
// False cause there is the initial violation
Assert.assertEquals(sp.isSatisfied(plan), false);
sp.setContinuous(false);
Assert.assertEquals(sp.isSatisfied(plan), true);
sp.setContinuous(true);
// Temporary overlap
plan.add(new MigrateVM(vms.get(2), ns.get(1), ns.get(0), 5, 6));
plan.add(new MigrateVM(vms.get(2), ns.get(0), ns.get(1), 6, 7));
Assert.assertEquals(sp.isSatisfied(plan), false);
// Liberate ns.get(0) from vms.get(0) and vms.get(1) before
plan.add(new SuspendVM(vms.get(0), ns.get(0), ns.get(0), 2, 3));
plan.add(new ShutdownVM(vms.get(1), ns.get(0), 2, 3));
sp.setContinuous(false);
Assert.assertEquals(sp.isSatisfied(plan), true);
}
use of org.btrplace.plan.event.SuspendVM in project scheduler by btrplace.
the class InstanceConverter method toInstance.
public static Instance toInstance(ReconfigurationPlan p) {
Model mo = p.getOrigin().copy();
List<SatConstraint> cstrs = new ArrayList<>();
Set<VM> knownVMs = new HashSet<>();
Set<Node> knownNodes = new HashSet<>();
for (Action a : p.getActions()) {
if (a instanceof NodeEvent) {
Node n = ((NodeEvent) a).getNode();
knownNodes.add(n);
cstrs.add(new Schedule(n, a.getStart(), a.getEnd()));
if (a instanceof BootNode) {
cstrs.add(new Online(n));
} else if (a instanceof ShutdownNode) {
cstrs.add(new Offline(n));
}
} else if (a instanceof VMEvent) {
VM v = ((VMEvent) a).getVM();
knownVMs.add(v);
cstrs.add(new Schedule(v, a.getStart(), a.getEnd()));
if (a instanceof BootVM) {
cstrs.add(new Running(v));
cstrs.add(new Fence(v, ((BootVM) a).getDestinationNode()));
} else if (a instanceof MigrateVM) {
cstrs.add(new Fence(v, ((MigrateVM) a).getDestinationNode()));
cstrs.add(new Running(v));
} else if (a instanceof ShutdownVM) {
cstrs.add(new Ready(v));
} else if (a instanceof SuspendVM) {
cstrs.add(new Sleeping(v));
} else if (a instanceof ResumeVM) {
cstrs.add(new Running(v));
cstrs.add(new Fence(v, ((ResumeVM) a).getDestinationNode()));
} else if (a instanceof Allocate) {
cstrs.add(new Preserve(v, ((Allocate) a).getResourceId(), ((Allocate) a).getAmount()));
cstrs.add(new Fence(v, ((Allocate) a).getHost()));
}
}
// Catch the allocate events
for (Event e : a.getEvents(Action.Hook.PRE)) {
if (e instanceof AllocateEvent) {
cstrs.add(new Preserve(((AllocateEvent) e).getVM(), ((AllocateEvent) e).getResourceId(), ((AllocateEvent) e).getAmount()));
}
}
for (Event e : a.getEvents(Action.Hook.POST)) {
if (e instanceof AllocateEvent) {
cstrs.add(new Preserve(((AllocateEvent) e).getVM(), ((AllocateEvent) e).getResourceId(), ((AllocateEvent) e).getAmount()));
}
}
}
// State maintenance
for (Node n : mo.getMapping().getAllNodes()) {
if (knownNodes.contains(n)) {
continue;
}
if (mo.getMapping().isOnline(n)) {
cstrs.add(new Online(n));
} else if (mo.getMapping().isOffline(n)) {
cstrs.add(new Offline(n));
}
}
mo.getMapping().getAllVMs().stream().filter(v -> !knownVMs.contains(v)).forEach(v -> {
if (mo.getMapping().isReady(v)) {
cstrs.add(new Ready(v));
} else if (mo.getMapping().isRunning(v)) {
cstrs.add(new Running(v));
cstrs.add(new Fence(v, mo.getMapping().getVMLocation(v)));
} else if (mo.getMapping().isSleeping(v)) {
cstrs.add(new Sleeping(v));
cstrs.add(new Fence(v, mo.getMapping().getVMLocation(v)));
}
});
return new Instance(mo, cstrs, new MinMTTR());
}
use of org.btrplace.plan.event.SuspendVM in project scheduler by btrplace.
the class ReconfigurationPlanFuzzer method setDestinationState.
private void setDestinationState(ReconfigurationPlan p, VM v) {
Mapping map = p.getOrigin().getMapping();
Node host = map.getVMLocation(v);
int n = rnd.nextInt(dstReadyVMs + dstRunningVMs + dstSleepingVMs);
int[] bounds = schedule();
int duration = bounds[1] - bounds[0];
if (n < dstReadyVMs) {
if (host != null) {
p.add(new ShutdownVM(v, host, bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "shutdown", duration);
}
} else if (n < dstReadyVMs + dstRunningVMs) {
if (host == null) {
p.add(new BootVM(v, pick(map.getAllNodes()), bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "boot", duration);
} else {
// was running -> migrate
if (map.isRunning(v)) {
Node dst = pick(map.getAllNodes());
if (!host.equals(dst)) {
p.add(new MigrateVM(v, host, dst, bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "migrate", duration);
}
} else {
// was sleeping -> resume
p.add(new ResumeVM(v, host, pick(map.getAllNodes()), bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "resume", duration);
}
}
} else {
// moving to sleeping state
if (map.isRunning(v)) {
p.add(new SuspendVM(v, host, host, bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "sleeping", duration);
}
}
}
Aggregations