use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class ReconfigurationPlanFuzzer method setDestinationState.
private void setDestinationState(ReconfigurationPlan p, VM v) {
Mapping map = p.getOrigin().getMapping();
Node host = map.getVMLocation(v);
int n = rnd.nextInt(dstReadyVMs + dstRunningVMs + dstSleepingVMs);
int[] bounds = schedule();
int duration = bounds[1] - bounds[0];
if (n < dstReadyVMs) {
if (host != null) {
p.add(new ShutdownVM(v, host, bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "shutdown", duration);
}
} else if (n < dstReadyVMs + dstRunningVMs) {
if (host == null) {
p.add(new BootVM(v, pick(map.getAllNodes()), bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "boot", duration);
} else {
// was running -> migrate
if (map.isRunning(v)) {
Node dst = pick(map.getAllNodes());
if (!host.equals(dst)) {
p.add(new MigrateVM(v, host, dst, bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "migrate", duration);
}
} else {
// was sleeping -> resume
p.add(new ResumeVM(v, host, pick(map.getAllNodes()), bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "resume", duration);
}
}
} else {
// moving to sleeping state
if (map.isRunning(v)) {
p.add(new SuspendVM(v, host, host, bounds[0], bounds[1]));
p.getOrigin().getAttributes().put(v, "sleeping", duration);
}
}
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class NetworkFuzzer method decorate.
@Override
public void decorate(ReconfigurationPlan p) {
Network net = new Network();
Mapping m = p.getOrigin().getMapping();
Switch s = net.newSwitch(1000 * (1 + rnd.nextInt(40)));
for (Node n : m.getAllNodes()) {
int bw = 1000 * (1 + rnd.nextInt(40));
net.connect(bw, s, n);
}
}
use of org.btrplace.model.Mapping 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.Mapping in project scheduler by btrplace.
the class RelocatableVMTest method testForcedToMove.
@Test
public void testForcedToMove() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm1 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addRunningVM(vm1, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(MigrateVM.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).build();
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
RelocatableVM am = (RelocatableVM) rp.getVMAction(vm1);
Assert.assertTrue(am.getRelocationMethod().isInstantiatedTo(0));
Assert.assertEquals(vm1, am.getVM());
Assert.assertEquals(2, am.getDuration().getDomainSize());
Assert.assertEquals(0, am.getDuration().getLB());
Assert.assertEquals(5, am.getDuration().getUB());
Assert.assertFalse(am.getStart().isInstantiated());
Assert.assertFalse(am.getEnd().isInstantiated());
Assert.assertNotNull(am.getCSlice());
Assert.assertTrue(am.getCSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
Assert.assertTrue(am.getState().isInstantiatedTo(1));
Assert.assertNotNull(am.getDSlice());
Assert.assertFalse(am.getDSlice().getHoster().isInstantiated());
// No VMs on n1, discrete mode
rp.getModel().post(rp.getModel().arithm(rp.getNbRunningVMs().get(rp.getNode(n1)), "=", 0));
new CMinMTTR().inject(new DefaultParameters(), rp);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Model m = p.getResult();
Assert.assertEquals(n2, m.getMapping().getVMLocation(vm1));
MigrateVM a = (MigrateVM) p.getActions().iterator().next();
Assert.assertEquals(0, a.getStart());
Assert.assertEquals(5, a.getEnd());
Assert.assertEquals(n1, a.getSourceNode());
Assert.assertEquals(n2, a.getDestinationNode());
Assert.assertEquals(vm1, a.getVM());
}
use of org.btrplace.model.Mapping in project scheduler by btrplace.
the class RelocatableVMTest method testForcedToStay.
@Test
public void testForcedToStay() throws SchedulerException, ContradictionException {
Model mo = new DefaultModel();
Mapping map = mo.getMapping();
final VM vm1 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addRunningVM(vm1, n1);
Parameters ps = new DefaultParameters();
DurationEvaluators dev = ps.getDurationEvaluators();
dev.register(MigrateVM.class, new ConstantActionDuration<>(5));
ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).build();
rp.getNodeActions().get(0).getState().instantiateTo(1, Cause.Null);
rp.getNodeActions().get(1).getState().instantiateTo(1, Cause.Null);
RelocatableVM am = (RelocatableVM) rp.getVMAction(vm1);
// No VMs on n2
rp.getNbRunningVMs().get(rp.getNode(n2)).instantiateTo(0, Cause.Null);
new CMinMTTR().inject(new DefaultParameters(), rp);
ReconfigurationPlan p = rp.solve(0, false);
Assert.assertNotNull(p);
Assert.assertEquals(0, p.getSize());
Assert.assertTrue(am.getDuration().isInstantiatedTo(0));
Assert.assertTrue(am.getDSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
Assert.assertTrue(am.getStart().isInstantiatedTo(0));
Assert.assertTrue(am.getEnd().isInstantiatedTo(0));
Model m = p.getResult();
Assert.assertEquals(n1, m.getMapping().getVMLocation(vm1));
}
Aggregations