use of org.btrplace.scheduler.runner.disjoint.model.SubModel in project scheduler by btrplace.
the class StaticPartitioningTest method testSolvingIncorrectPartitioning.
@Test(expectedExceptions = { SchedulerException.class })
public void testSolvingIncorrectPartitioning() throws SchedulerException {
SynchronizedElementBuilder eb = new SynchronizedElementBuilder(new DefaultElementBuilder());
Model origin = new DefaultModel(eb);
Node n1 = origin.newNode();
Node n2 = origin.newNode();
VM vm1 = origin.newVM();
VM vm2 = origin.newVM();
/*
* 2 nodes among 2 instances, 2 VMs to boot on the nodes
*/
origin.getMapping().addOnlineNode(n1);
origin.getMapping().addOfflineNode(n2);
origin.getMapping().addReadyVM(vm1);
origin.getMapping().addReadyVM(vm2);
Model s1 = new SubModel(origin, eb, Collections.singletonList(n1), Collections.singleton(vm1));
Model s2 = new SubModel(origin, eb, Collections.singletonList(n2), Collections.singleton(vm2));
Instance i0 = new Instance(origin, new MinMTTR());
final Instance i1 = new Instance(s1, Running.newRunning(Collections.singletonList(vm1)), new MinMTTR());
final Instance i2 = new Instance(s2, new MinMTTR());
// Error, vm1 is in s1, not s2
i2.getSatConstraints().add(new Running(vm1));
StaticPartitioning st = new StaticPartitioning() {
@Override
public List<Instance> split(Parameters ps, Instance i) throws SchedulerException {
return Arrays.asList(i1, i2);
}
};
Parameters p = new DefaultChocoScheduler();
st.solve(p, i0);
}
use of org.btrplace.scheduler.runner.disjoint.model.SubModel in project scheduler by btrplace.
the class FixedNodeSetsPartitioning method split.
@Override
public List<Instance> split(Parameters ps, Instance i) throws SchedulerException {
Model mo = i.getModel();
SynchronizedElementBuilder eb = new SynchronizedElementBuilder(mo);
List<Instance> parts = new ArrayList<>(partitions.size());
// nb of VMs
int nbVMs = i.getModel().getMapping().getNbVMs();
int nbNodes = i.getModel().getMapping().getNbNodes();
TIntIntHashMap vmPosition = new TIntIntHashMap(nbVMs);
TIntIntHashMap nodePosition = new TIntIntHashMap(nbNodes);
int partNumber = 0;
Set<VM> toLaunch = getVMsToLaunch(i);
for (Collection<Node> s : partitions) {
SubModel partModel = new SubModel(mo, eb, s, new HashSet<>(toLaunch.size() / partitions.size()));
parts.add(new Instance(partModel, new THashSet<>(), i.getOptConstraint()));
// VM Index
partModel.getMapping().fillVMIndex(vmPosition, partNumber);
// Node index
for (Node n : s) {
nodePosition.put(n.id(), partNumber);
}
partNumber++;
}
// Round-robin placement for the VMs to launch
int p = 0;
for (VM v : toLaunch) {
if (!parts.get(p).getModel().getMapping().addReadyVM(v)) {
throw new SplitException(parts.get(p).getModel(), "Unable to dispatch the VM to launch '" + v + "'");
}
vmPosition.put(v.id(), p);
p = (p + 1) % parts.size();
}
// Split the constraints
for (SatConstraint cstr : i.getSatConstraints()) {
if (!cstrMapper.split(cstr, i, parts, vmPosition, nodePosition)) {
throw new SplitException(i.getModel(), "Unable to split " + cstr);
}
}
return parts;
}
use of org.btrplace.scheduler.runner.disjoint.model.SubModel in project scheduler by btrplace.
the class StaticPartitioningTest method testParallelSolve.
@Test
public void testParallelSolve() throws SchedulerException {
SynchronizedElementBuilder eb = new SynchronizedElementBuilder(new DefaultElementBuilder());
Model origin = new DefaultModel(eb);
Node n1 = origin.newNode();
Node n2 = origin.newNode();
VM vm1 = origin.newVM();
VM vm2 = origin.newVM();
/*
* 2 nodes among 2 instances, 2 VMs to boot on the nodes
*/
origin.getMapping().addOnlineNode(n1);
origin.getMapping().addOfflineNode(n2);
origin.getMapping().addReadyVM(vm1);
origin.getMapping().addReadyVM(vm2);
Model s1 = new SubModel(origin, eb, Collections.singletonList(n1), Collections.singleton(vm1));
Model s2 = new SubModel(origin, eb, Collections.singletonList(n2), Collections.singleton(vm2));
Instance i0 = new Instance(origin, new MinMTTR());
final Instance i1 = new Instance(s1, Running.newRunning(Collections.singletonList(vm1)), new MinMTTR());
final Instance i2 = new Instance(s2, new MinMTTR());
i2.getSatConstraints().add(new Running(vm2));
StaticPartitioning st = new StaticPartitioning() {
@Override
public List<Instance> split(Parameters ps, Instance i) throws SchedulerException {
return Arrays.asList(i1, i2);
}
};
Parameters p = new DefaultChocoScheduler();
ReconfigurationPlan plan = st.solve(p, i0);
Assert.assertNotNull(plan);
Model dst = plan.getResult();
Assert.assertEquals(dst.getMapping().getOnlineNodes().size(), 2);
Assert.assertEquals(dst.getMapping().getRunningVMs().size(), 2);
// Now, there is no solution for i2. the resulting plan should be null
i2.getSatConstraints().addAll(Offline.newOffline(Collections.singletonList(n2)));
plan = st.solve(p, i0);
Assert.assertNull(plan);
Assert.assertEquals(st.getStatistics().getSolutions().size(), 0);
}
Aggregations