use of org.btrplace.model.constraint.Running in project scheduler by btrplace.
the class InstanceTest method testEqualsAndHashcode.
@Test
public void testEqualsAndHashcode() {
Model mo = new DefaultModel();
List<Node> ns = Util.newNodes(mo, 10);
List<VM> vms = Util.newVMs(mo, 10);
Mapping ma = mo.getMapping();
ma.addOnlineNode(ns.get(0));
ma.addOfflineNode(ns.get(0));
ma.addReadyVM(vms.get(0));
List<SatConstraint> cstrs = new ArrayList<>(Online.newOnline(ma.getAllNodes()));
cstrs.add(new Running(vms.get(0)));
Instance i = new Instance(mo, cstrs, new MinMTTR());
Instance i2 = new Instance(mo.copy(), new ArrayList<>(cstrs), new MinMTTR());
Assert.assertEquals(i, i2);
Assert.assertEquals(i, i);
Assert.assertNotEquals(i, null);
Assert.assertNotEquals(ma, i);
Assert.assertEquals(i.hashCode(), i2.hashCode());
i2.getModel().getMapping().addReadyVM(vms.get(2));
Assert.assertNotEquals(i, i2);
}
use of org.btrplace.model.constraint.Running 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.model.constraint.Running in project scheduler by btrplace.
the class FixedNodeSetsPartitioning method getVMsToLaunch.
private Set<VM> getVMsToLaunch(Instance i) {
Mapping m = i.getModel().getMapping();
Set<VM> toLaunch = new THashSet<>();
for (SatConstraint cstr : i.getSatConstraints()) {
// Extract the VMs to launch
if (cstr instanceof Running) {
for (VM v : cstr.getInvolvedVMs()) {
if (m.isReady(v)) {
m.remove(v);
toLaunch.add(v);
}
}
}
}
return toLaunch;
}
use of org.btrplace.model.constraint.Running in project scheduler by btrplace.
the class CResourceCapacityTest method testSingleContinuousSolvable.
@Test
public void testSingleContinuousSolvable() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2).run(n1, vm1, vm2).ready(vm4);
ShareableResource rc = new ShareableResource("cpu", 5, 5);
rc.setConsumption(vm1, 3);
rc.setConsumption(vm2, 1);
rc.setConsumption(vm3, 1);
rc.setConsumption(vm4, 3);
mo.attach(rc);
List<SatConstraint> cstrs = new ArrayList<>();
ResourceCapacity s = new ResourceCapacity(n1, "cpu", 4);
s.setContinuous(true);
cstrs.add(s);
cstrs.add(new Fence(vm4, Collections.singleton(n1)));
cstrs.add(new Running(vm4));
cstrs.addAll(Overbook.newOverbooks(map.getAllNodes(), "cpu", 1));
ChocoScheduler cra = new DefaultChocoScheduler();
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
Assert.assertEquals(p.getSize(), 2);
}
use of org.btrplace.model.constraint.Running in project scheduler by btrplace.
the class CResourceCapacityTest method testFeasibleContinuousResolution.
@Test
public void testFeasibleContinuousResolution() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
mo.getMapping().on(n1, n2, n3).run(n1, vm1, vm2).run(n2, vm3, vm4).ready(vm5);
Set<Node> on = new HashSet<>(Arrays.asList(n1, n2));
ShareableResource rc = new ShareableResource("cpu", 5, 5);
rc.setConsumption(vm1, 2);
rc.setConsumption(vm2, 3);
rc.setConsumption(vm3, 3);
rc.setConsumption(vm4, 1);
rc.setConsumption(vm5, 5);
mo.attach(rc);
List<SatConstraint> l = new ArrayList<>();
l.add(new Running(vm5));
l.add(new Fence(vm5, Collections.singleton(n1)));
ResourceCapacity x = new ResourceCapacity(on, "cpu", 10);
x.setContinuous(true);
l.add(x);
ChocoScheduler cra = new DefaultChocoScheduler();
ReconfigurationPlan plan = cra.solve(mo, l);
Assert.assertNotNull(plan);
// System.out.println(plan);
Assert.assertTrue(plan.getSize() > 0);
}
Aggregations