use of org.btrplace.model.VM in project scheduler by btrplace.
the class CShareableResource method getMisPlacedVMs.
/**
* {@inheritDoc}
*
* @param i the model to use to inspect the VMs.
* @return the set of VMs that cannot have their associated {@link Preserve} constraint satisfy with regards
* to a possible {@link Overbook} and single-node {@link ResourceCapacity} constraint.
*/
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
for (SatConstraint c : i.getSatConstraints()) {
if (!(c instanceof ResourceRelated && ((ResourceRelated) c).getResource().equals(rc.getResourceIdentifier()))) {
continue;
}
if (c instanceof Preserve) {
VM v = c.getInvolvedVMs().iterator().next();
wantedAmount.put(v, consumption(v, ((Preserve) c).getAmount()));
} else if (c instanceof Overbook) {
Node n = c.getInvolvedNodes().iterator().next();
wantedRatios.put(n, ratio(n, ((Overbook) c).getRatio()));
} else if (c instanceof ResourceCapacity && c.getInvolvedNodes().size() == 1) {
Node n = c.getInvolvedNodes().iterator().next();
wantedCapacity.put(n, capacity(n, ((ResourceCapacity) c).getAmount()));
}
}
Mapping m = i.getModel().getMapping();
Set<VM> candidates = new HashSet<>();
for (Node n : m.getOnlineNodes()) {
if (overloaded(m, n)) {
candidates.addAll(m.getRunningVMs(n));
}
}
return candidates;
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class DefaultChocoSchedulerTest method testWithUnknownVMs.
/*@Test
public void testGetStatistics() throws SchedulerException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
for (int i = 0; i < 10; i++) {
Node n = mo.newNode();
map.addOnlineNode(n);
map.addRunningVM(mo.newVM(), n);
}
ChocoScheduler cra = new DefaultChocoScheduler();
cra.doOptimize(true);
cra.setTimeLimit(0);
Assert.assertNull(cra.getStatistics());
OptConstraint o = new OptConstraint() {
@Override
public String id() {
return "foo";
}
};
ChocoConstraint co = new ChocoMapperTest.MockCConstraint() {
public ChocoMapperTest.MockCConstraint(OptConstraint f) {}
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
return false;
}
@Override
public Set<VM> getMisPlacedVMs(Model m) {
return Collections.emptySet();
}
};
cra.getMapper().register(o.getClass(), co.getClass());
ReconfigurationPlan p = cra.solve(mo, Collections.<SatConstraint>emptyList(), o);
Mapping res = p.getResult().getMapping();
int nbRunning = 0;
for (Node n : res.getOnlineNodes()) {
if (!res.getRunningVMs(n).isEmpty()) {
nbRunning++;
}
}
Assert.assertEquals(nbRunning, 1);
SolvingStatistics st = cra.getStatistics();
Assert.assertEquals(st.getSolutions().get(0).getOptValue(), 1);
Assert.assertEquals(st.getSolutions().size(), 1);
}
*/
/* @Test
public void testSolvableRepair() throws SchedulerException {
Model mo = new DefaultModel();
final VM vm1 = mo.newVM();
final VM vm2 = mo.newVM();
final VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
mo.on(n1, n2, n3).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3, vm5).get();
//A satisfied constraint
Fence c1 = new Fence(vm1, new HashSet<>(Arrays.asList(n1, n2)));
//A constraint that is not satisfied. vm2 is misplaced
Fence c2 = new Fence(vm2, new HashSet<>(Arrays.asList(n1, n3)));
Set<SatConstraint> cstrs = new HashSet<SatConstraint>(Arrays.asList(c1, c2));
mo = new DefaultModel();
mo.on(n1, n2, n3).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3, vm5).get();
ChocoScheduler cra = new DefaultChocoScheduler();
OptConstraint o = new OptConstraint() {
@Override
public String id() {
return "foo";
}
};
ChocoConstraint co = new ChocoConstraint() {
@Override
public Set<VM> getMisPlacedVMs(Model m) {
return new HashSet<>(Arrays.asList(vm2, vm3));
}
};
cra.getMapper().register(o.getClass(), co.getClass());
cra.doRepair(true);
cra.doOptimize(false);
//Solve a problem with the repair mode
Assert.assertNotNull(cra.solve(mo, cstrs, o));
SolvingStatistics st = cra.getStatistics();
System.out.println(st);
Assert.assertEquals(st.getNbManagedVMs(), 2); //vm2, vm3.
}
*/
@Test(expectedExceptions = { SchedulerException.class })
public void testWithUnknownVMs() throws SchedulerException {
Model mo = new DefaultModel();
final VM vm1 = mo.newVM();
final VM vm2 = mo.newVM();
final VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
VM vm6 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
mo.getMapping().on(n1, n2, n3).run(n1, vm1, vm4).run(n2, vm2).run(n3, vm3, vm5);
SatConstraint cstr = mock(SatConstraint.class);
when(cstr.getInvolvedVMs()).thenReturn(Arrays.asList(vm1, vm2, vm6));
when(cstr.getInvolvedNodes()).thenReturn(Arrays.asList(n1, n4));
ChocoScheduler cra = new DefaultChocoScheduler();
cra.solve(mo, Collections.singleton(cstr));
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMCounting.
/**
* Check the consistency between the variables counting the number of VMs on
* each node, and the placement variable.
*
* @throws org.btrplace.scheduler.SchedulerException
* @throws ContradictionException
*/
@Test
public void testVMCounting() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Node n3 = mo.newNode();
Node n2 = mo.newNode();
Mapping map = mo.getMapping();
for (int i = 0; i < 7; i++) {
VM v = mo.newVM();
map.addReadyVM(v);
}
map.addOnlineNode(n3);
map.addOnlineNode(n2);
Parameters ps = new DefaultParameters();
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).setNextVMsStates(new HashSet<>(), map.getAllVMs(), new HashSet<>(), new HashSet<>()).build();
// Restrict the capacity to 5 at most
for (IntVar capa : rp.getNbRunningVMs()) {
capa.updateUpperBound(5, Cause.Null);
}
new CMinMTTR().inject(ps, rp);
ReconfigurationPlan p = rp.solve(-1, false);
Assert.assertNotNull(p);
// Check consistency between the counting and the hoster variables
int[] counts = new int[map.getAllNodes().size()];
for (Node n : map.getOnlineNodes()) {
int nIdx = rp.getNode(n);
counts[nIdx] = rp.getNbRunningVMs().get(nIdx).getValue();
}
for (VM vm : rp.getFutureRunningVMs()) {
VMTransition vmo = rp.getVMActions().get(rp.getVM(vm));
int on = vmo.getDSlice().getHoster().getValue();
counts[on]--;
}
for (int count : counts) {
Assert.assertEquals(count, 0);
}
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testManageableVMs.
@Test
public void testManageableVMs() 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();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addOfflineNode(n3);
map.addRunningVM(vm1, n1);
map.addRunningVM(vm2, n1);
map.addRunningVM(vm3, n2);
map.addSleepingVM(vm4, n2);
map.addReadyVM(vm5);
map.addReadyVM(vm6);
Set<VM> runnings = new HashSet<>(map.getRunningVMs());
runnings.add(vm6);
runnings.add(vm5);
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), runnings, map.getSleepingVMs(), Collections.emptySet()).setManageableVMs(map.getRunningVMs(n1)).build();
/*
vm1: running -> running
vm2: running-> running
vm3: running -> running
vm4: sleeping -> sleeping
vm5: ready -> running
vm6: ready -> running
* manageable_runnings: vm1, vm2
* manageable: vm1, vm2, vm5, vm6 (with ids: vm#0, vm#1, vm#4, vm#5)
*/
Set<VM> manageable = rp.getManageableVMs();
Assert.assertEquals(manageable.size(), 4, manageable.toString());
Assert.assertTrue(manageable.containsAll(Arrays.asList(vm6, vm5, vm1, vm2)));
// Check the action model that has been used for each of the VM.
for (VM vm : map.getAllVMs()) {
Assert.assertEquals(manageable.contains(vm), rp.getVMAction(vm).isManaged());
}
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class DefaultReconfigurationProblemTest method testVMToShutdown.
@Test
public void testVMToShutdown() 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();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addOfflineNode(n3);
map.addRunningVM(vm1, n1);
map.addRunningVM(vm2, n1);
map.addRunningVM(vm3, n2);
map.addSleepingVM(vm4, n2);
map.addReadyVM(vm5);
map.addReadyVM(vm6);
Mapping m = mo.getMapping();
m.addOnlineNode(n1);
m.addRunningVM(vm1, n1);
DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.singleton(vm1), new HashSet<>(), new HashSet<>(), new HashSet<>()).build();
VMTransition a = rp.getVMActions().get(0);
Assert.assertEquals(a, rp.getVMAction(vm1));
Assert.assertEquals(ShutdownVM.class, a.getClass());
}
Aggregations