use of org.btrplace.model.constraint.MinMTTR in project scheduler by btrplace.
the class DefaultChocoScheduler method solve.
@Override
public ReconfigurationPlan solve(Instance i) throws SchedulerException {
Model mo = i.getModel();
Collection<SatConstraint> cstrs = i.getSatConstraints();
// If a network view is attached, ensure that all the migrations' destination node are defined
Network net = Network.get(mo);
stages = null;
if (net != null) {
// The network view is useless to take placement decisions
mo.detach(net);
// Solve a first time using placement oriented MinMTTR optimisation constraint
ReconfigurationPlan p = runner.solve(params, i);
stages = new StagedSolvingStatistics(runner.getStatistics());
if (p == null) {
return null;
}
// Add Fence constraints for each destination node chosen
List<SatConstraint> newCstrs = p.getActions().stream().filter(a -> a instanceof MigrateVM).map(a -> new Fence(((MigrateVM) a).getVM(), Collections.singleton(((MigrateVM) a).getDestinationNode()))).collect(Collectors.toList());
Model result = p.getResult();
if (result == null) {
throw new InconsistentSolutionException(p, "The plan cannot be applied");
}
// Add Root constraints to all staying VMs
newCstrs.addAll(mo.getMapping().getRunningVMs().stream().filter(v -> p.getOrigin().getMapping().getVMLocation(v).id() == result.getMapping().getVMLocation(v).id()).map(Root::new).collect(Collectors.toList()));
// Add the old constraints
newCstrs.addAll(cstrs);
// Re-attach the network view
mo.attach(net);
// New timeout value = elapsed time - initial timeout value
Parameters ps = new DefaultParameters(params);
if (ps.getTimeLimit() > 0) {
// in seconds
double timeout = params.getTimeLimit() - runner.getStatistics().getMetrics().timeCount() / 1000;
ps.setTimeLimit((int) timeout);
}
return runner.solve(ps, new Instance(mo, newCstrs, i.getOptConstraint()));
}
// Solve and return the computed plan
return runner.solve(params, new Instance(mo, cstrs, i.getOptConstraint()));
}
use of org.btrplace.model.constraint.MinMTTR in project scheduler by btrplace.
the class Bench method benchHA.
public static void benchHA(int nbSamples, Integer partSize, Integer ratio, Integer nbParts) {
Model mo = new DefaultModel();
Instance inst = new Instance(mo, new MinMTTR());
int nbNodes = partSize * nbParts;
int nbVMs = ratio * nbNodes;
// Make the infrastructure
List<Node> l = makeNodeList(mo, nbNodes);
ShareableResource rcCpu = new ShareableResource("cpu", 20, 0);
ShareableResource rcMem = new ShareableResource("mem", 16, /*GB*/
0);
List<Collection<Node>> edges = makeEdges(l, 250);
mo.attach(rcCpu);
mo.attach(rcMem);
while (nbVMs != 0) {
nbVMs -= makeApp(inst, nbVMs, edges);
}
FixedSizePartitioning partitioner = new FixedSizePartitioning(partSize);
try {
for (int x = 0; x < nbSamples; x++) {
long start = System.currentTimeMillis();
List<Instance> instances = partitioner.split(new DefaultParameters(), inst);
long end = System.currentTimeMillis();
System.err.println(instances.size() + " " + nbNodes + " " + nbNodes * ratio + " " + inst.getSatConstraints().size() + " " + (end - start));
}
} catch (SchedulerException ex) {
Assert.fail(ex.getMessage(), ex);
}
}
use of org.btrplace.model.constraint.MinMTTR 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.model.constraint.MinMTTR in project scheduler by btrplace.
the class AmongSplitterTest method testSplittable.
@Test
public void testSplittable() throws SchedulerException {
List<VM> vms = Arrays.asList(vm1, vm2, vm3);
Collection<Collection<Node>> parts = new ArrayList<>();
parts.add(Arrays.asList(n1, n2));
parts.add(Collections.singletonList(n3));
parts.add(Collections.singletonList(n4));
Among single = new Among(vms, parts);
/*
N1 v1 v2
N2 v3
---
N3 v4
--
N4 v5
*/
FixedNodeSetsPartitioning partitionner = new FixedNodeSetsPartitioning(parts);
partitionner.setPartitions(parts);
List<Instance> instances = partitionner.split(new DefaultParameters(), new Instance(mo, Collections.emptyList(), new MinMTTR()));
TIntIntHashMap vmIndex = Instances.makeVMIndex(instances);
TIntIntHashMap nodeIndex = Instances.makeNodeIndex(instances);
splitter.split(single, new Instance(mo, new MinMTTR()), instances, vmIndex, nodeIndex);
Among a = (Among) instances.get(0).getSatConstraints().iterator().next();
Assert.assertEquals(a.getGroupsOfNodes().size(), 1);
Assert.assertEquals(a.getInvolvedNodes(), Arrays.asList(n1, n2));
for (Instance i : instances) {
System.out.println(i.getSatConstraints());
}
}
use of org.btrplace.model.constraint.MinMTTR in project scheduler by btrplace.
the class GatherSplitterTest method simpleTest.
@Test
public void simpleTest() {
GatherSplitter splitter = new GatherSplitter();
List<Instance> instances = new ArrayList<>();
Model m0 = new DefaultModel();
m0.getMapping().addReadyVM(m0.newVM(1));
Node n1 = m0.newNode();
m0.getMapping().addOnlineNode(n1);
m0.getMapping().addRunningVM(m0.newVM(2), n1);
Model m1 = new DefaultModel();
Node n2 = m1.newNode();
Node n3 = m1.newNode();
m1.getMapping().addOnlineNode(n2);
m1.getMapping().addOnlineNode(n3);
m1.getMapping().addReadyVM(m1.newVM(3));
m1.getMapping().addSleepingVM(m1.newVM(4), n2);
m1.getMapping().addRunningVM(m1.newVM(5), n3);
instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
all.addAll(m1.getMapping().getAllVMs());
TIntIntHashMap vmIndex = Instances.makeVMIndex(instances);
// Only VMs in m0
Gather single = new Gather(m0.getMapping().getAllVMs());
Assert.assertTrue(splitter.split(single, null, instances, vmIndex, new TIntIntHashMap()));
Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
// All the VMs, test the unfeasibility
Gather among = new Gather(all, false);
Assert.assertFalse(splitter.split(among, null, instances, vmIndex, new TIntIntHashMap()));
}
Aggregations