use of org.btrplace.model.constraint.Fence in project scheduler by btrplace.
the class CShareableResourceTest method testRealNodeUsage.
/**
* Place some VMs and check realNodeUsage is updated accordingly
*/
@Test
public void testRealNodeUsage() throws SchedulerException {
Model mo = new DefaultModel();
Mapping ma = mo.getMapping();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
ma.addOnlineNode(n1);
ma.addOnlineNode(n2);
ma.addRunningVM(vm1, n1);
ma.addRunningVM(vm2, n1);
ShareableResource rc = new ShareableResource("foo", 0, 0);
rc.setConsumption(vm1, 2);
rc.setConsumption(vm2, 3);
rc.setCapacity(n1, 5);
rc.setCapacity(n2, 3);
mo.attach(rc);
ChocoScheduler s = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.add(new Fence(vm1, n1));
cstrs.add(new Fence(vm2, n2));
ReconfigurationPlan p = s.solve(mo, cstrs);
Assert.assertNotNull(p);
Model res = p.getResult();
rc = (ShareableResource.get(res, "foo"));
Assert.assertEquals(2, rc.getConsumption(vm1));
Assert.assertEquals(3, rc.getConsumption(vm2));
}
use of org.btrplace.model.constraint.Fence 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.Fence in project scheduler by btrplace.
the class FenceSplitter method split.
@Override
public boolean split(Fence cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
final SplittableElementSet<Node> nodeIndex = SplittableElementSet.newNodeIndex(cstr.getInvolvedNodes(), nodePosition);
VM v = cstr.getInvolvedVMs().iterator().next();
int p = vmsPosition.get(v.id());
Set<Node> ns = nodeIndex.getSubSet(p);
if (!ns.isEmpty()) {
return partitions.get(p).getSatConstraints().add(new Fence(v, ns));
}
return true;
}
use of org.btrplace.model.constraint.Fence in project scheduler by btrplace.
the class CGatherTest method testContinuousWithRelocationOfVMs.
/**
* We try to relocate co-located VMs in continuous mode. Not allowed
*
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void testContinuousWithRelocationOfVMs() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2).run(n2, vm1, vm2);
Gather g = new Gather(map.getAllVMs());
g.setContinuous(true);
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Running.newRunning(map.getAllVMs()));
cstrs.add(g);
cstrs.add(new Fence(vm1, Collections.singleton(n1)));
cstrs.add(new Fence(vm2, Collections.singleton(n1)));
ChocoScheduler cra = new DefaultChocoScheduler();
ReconfigurationPlan plan = cra.solve(mo, cstrs);
Assert.assertNull(plan);
}
use of org.btrplace.model.constraint.Fence in project scheduler by btrplace.
the class CSplitTest method testContinuous.
// @Test
@Test(enabled = false)
public void testContinuous() 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();
VM vm6 = mo.newVM();
VM vm7 = mo.newVM();
VM vm8 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
Node n5 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2, n3, n4, n5).run(n1, vm1, vm2).run(n3, vm3, vm4, vm5).run(n5, vm6, vm7, vm8);
Collection<VM> g1 = Arrays.asList(vm1, vm2);
Collection<VM> g2 = Arrays.asList(vm3, vm4, vm5);
Collection<VM> g3 = Arrays.asList(vm6, vm7);
Collection<Collection<VM>> grps = Arrays.asList(g1, g2, g3);
Split s = new Split(grps);
s.setContinuous(true);
ChocoScheduler cra = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.add(s);
// go away before the other arrive.
for (VM v : map.getRunningVMs(n1)) {
cstrs.add(new Fence(v, Collections.singleton(n3)));
}
// cra.setTimeLimit(2);
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
Assert.assertTrue(p.getSize() > 0);
}
Aggregations