use of org.btrplace.model.constraint.Running in project scheduler by btrplace.
the class InstanceConverterTest method testConversion.
@Test
public void testConversion() throws JSONConverterException {
Model mo = new DefaultModel();
Mapping ma = mo.getMapping();
Node n1 = mo.newNode();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
ma.addOnlineNode(n1);
ma.addOfflineNode(n1);
ma.addReadyVM(vm1);
ma.addReadyVM(vm2);
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Online.newOnline(ma.getAllNodes()));
cstrs.add(new Running(vm2));
Instance i = new Instance(mo, cstrs, new MinMTTR());
InstanceConverter conv = new InstanceConverter();
String o = conv.toJSONString(i);
System.out.println(o);
Instance res = conv.fromJSON(o);
Assert.assertEquals(i, res);
}
use of org.btrplace.model.constraint.Running in project scheduler by btrplace.
the class RunningConverterTest method testViables.
@Test
public void testViables() throws JSONConverterException {
Model mo = new DefaultModel();
ConstraintsConverter conv = new ConstraintsConverter();
conv.register(new RunningConverter());
Running d = new Running(mo.newVM());
Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
System.out.println(conv.toJSON(d));
}
use of org.btrplace.model.constraint.Running in project scheduler by btrplace.
the class ModelCustomization method makeConstraints.
private List<SatConstraint> makeConstraints(Model model) {
List<SatConstraint> cstrs = new ArrayList<>();
// No more than 5 VMs per node
for (Node n : model.getMapping().getAllNodes()) {
cstrs.add(new RunningCapacity(n, 5));
}
// vm1 and vm10 on the same node
cstrs.add(new Gather(Arrays.asList(vms.get(0), vms.get(9))));
// (vm1, vm2, vm4) and (vm5, vm6, vm8) must not share node
Collection<VM> g1 = Arrays.asList(vms.get(0), vms.get(1), vms.get(3));
Collection<VM> g2 = Arrays.asList(vms.get(4), vms.get(5), vms.get(7));
cstrs.add(new Split(Arrays.asList(g1, g2)));
// vm10 must be running
cstrs.add(new Running(vms.get(9)));
return cstrs;
}
use of org.btrplace.model.constraint.Running in project scheduler by btrplace.
the class GettingStarted method makeConstraints.
/**
* Declare some constraints.
*/
public List<SatConstraint> makeConstraints() {
List<SatConstraint> cstrs = new ArrayList<>();
// VM1 and VM2 must be running on distinct nodes
cstrs.add(new Spread(new HashSet<>(Arrays.asList(vms.get(1), vms.get(2)))));
// VM0 must have at least 3 virtual CPU dedicated to it
cstrs.add(new Preserve(vms.get(0), "cpu", 3));
// N3 must be set offline
cstrs.add(new Offline(nodes.get(3)));
// VM4 must be running, It asks for 3 cpu and 2 mem resources
cstrs.add(new Running(vms.get(4)));
cstrs.add(new Preserve(vms.get(4), "cpu", 3));
cstrs.add(new Preserve(vms.get(4), "mem", 2));
// VM3 must be turned off, i.e. set back to the ready state
cstrs.add(new Ready(vms.get(3)));
return cstrs;
}
use of org.btrplace.model.constraint.Running 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);
}
Aggregations