use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class CMinMTTR method placeVMs.
/*
* Try to place the VMs associated on the actions in a random node while trying first to stay on the current node
*/
private void placeVMs(Parameters ps, List<AbstractStrategy<?>> strategies, List<VMTransition> actions, OnStableNodeFirst schedHeuristic, Map<IntVar, VM> map) {
IntValueSelector rnd = new WorstFit(map, rp, new BiggestDimension());
if (!useResources) {
rnd = new RandomVMPlacement(rp, map, true, ps.getRandomSeed());
}
IntVar[] hosts = dSlices(actions).map(Slice::getHoster).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
if (hosts.length > 0) {
strategies.add(new IntStrategy(hosts, new HostingVariableSelector(rp.getModel(), schedHeuristic), rnd));
}
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class MovementGraph method make.
public void make() {
incoming.clear();
outgoings.clear();
for (VMTransition a : rp.getVMActions()) {
Slice cSlice = a.getCSlice();
Slice dSlice = a.getDSlice();
if (cSlice != null) {
addOutgoing(cSlice);
}
if (dSlice != null) {
addIncoming(dSlice);
}
}
}
use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.
the class AbstractCumulatives method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
cUsages = new ArrayList<>();
dUsages = new ArrayList<>();
List<Slice> dS = new ArrayList<>();
List<Slice> cS = new ArrayList<>();
non = new HashMap<>();
int dIdx = 0;
int cIdx = 0;
for (VMTransition a : rp.getVMActions()) {
Slice c = a.getCSlice();
Slice d = a.getDSlice();
if (d != null && c != null) {
non.put(a.getVM(), new int[] { dIdx, cIdx });
}
if (d != null) {
dS.add(dIdx, d);
dIdx++;
}
if (c != null) {
cS.add(cIdx, c);
cIdx++;
}
}
int i = 0;
cHosts = new IntVar[cS.size()];
cEnds = new IntVar[cS.size()];
for (Slice s : cS) {
cHosts[i] = s.getHoster();
cEnds[i] = s.getEnd();
i++;
}
i = 0;
dStarts = new IntVar[dS.size()];
dHosts = new IntVar[dS.size()];
for (Slice s : dS) {
dHosts[i] = s.getHoster();
dStarts[i] = s.getStart();
i++;
}
associations = makeAssociations();
return true;
}
use of org.btrplace.scheduler.choco.transition.VMTransition 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.scheduler.choco.transition.VMTransition 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