use of org.btrplace.model.constraint.MinMTTR in project scheduler by btrplace.
the class InstanceTest method testInstantiation.
@Test
public void testInstantiation() {
Model mo = Mockito.mock(Model.class);
List<SatConstraint> l = new ArrayList<>();
l.add(Mockito.mock(SatConstraint.class));
MinMTTR o = new MinMTTR();
Instance i = new Instance(mo, l, o);
Assert.assertEquals(i.getModel(), mo);
Assert.assertEquals(i.getSatConstraints(), l);
Assert.assertEquals(i.getOptConstraint(), o);
i = new Instance(mo, o);
Assert.assertEquals(i.getSatConstraints().size(), 0);
}
use of org.btrplace.model.constraint.MinMTTR 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.MinMTTR in project scheduler by btrplace.
the class CSpreadTest method testGetMisplaced.
@Test
public void testGetMisplaced() {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2).run(n1, vm1, vm3).run(n2, vm2);
Set<VM> vms = new HashSet<>(Arrays.asList(vm1, vm2));
Spread s = new Spread(vms);
CSpread cs = new CSpread(s);
Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
Assert.assertTrue(cs.getMisPlacedVMs(i).isEmpty());
vms.add(vm3);
Assert.assertEquals(map.getRunningVMs(n1), cs.getMisPlacedVMs(i));
}
use of org.btrplace.model.constraint.MinMTTR in project scheduler by btrplace.
the class CReadyTest method testGetMisplaced.
@Test
public void testGetMisplaced() {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
Node n1 = mo.newNode();
mo.getMapping().ready(vm1).on(n1).run(n1, vm2, vm3);
Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
CReady k = new CReady(new Ready(vm1));
Assert.assertEquals(0, k.getMisPlacedVMs(i).size());
k = new CReady(new Ready(vm2));
Assert.assertEquals(1, k.getMisPlacedVMs(i).size());
Assert.assertTrue(k.getMisPlacedVMs(i).contains(vm2));
}
use of org.btrplace.model.constraint.MinMTTR in project scheduler by btrplace.
the class CRunningTest method testGetMisplaced.
@Test
public void testGetMisplaced() {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
mo.getMapping().on(n1).ready(vm1).run(n1, vm2);
Instance i = new Instance(mo, Collections.emptyList(), new MinMTTR());
CRunning k = new CRunning(new Running(vm1));
Assert.assertEquals(1, k.getMisPlacedVMs(i).size());
Assert.assertTrue(k.getMisPlacedVMs(i).contains(vm1));
k = new CRunning(new Running(vm2));
Assert.assertEquals(0, k.getMisPlacedVMs(i).size());
}
Aggregations