Search in sources :

Example 1 with RunningCapacity

use of org.btrplace.model.constraint.RunningCapacity in project scheduler by btrplace.

the class RunningCapacityConverterTest method testViables.

@Test
public void testViables() throws JSONConverterException {
    ConstraintsConverter conv = new ConstraintsConverter();
    conv.register(new RunningCapacityConverter());
    Model mo = new DefaultModel();
    RunningCapacity d = new RunningCapacity(new HashSet<>(Arrays.asList(mo.newNode(), mo.newNode(), mo.newNode())), 5);
    Assert.assertEquals(conv.fromJSON(mo, conv.toJSON(d)), d);
    System.out.println(conv.toJSON(d));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) RunningCapacity(org.btrplace.model.constraint.RunningCapacity) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 2 with RunningCapacity

use of org.btrplace.model.constraint.RunningCapacity 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;
}
Also used : RunningCapacity(org.btrplace.model.constraint.RunningCapacity) SatConstraint(org.btrplace.model.constraint.SatConstraint) Node(org.btrplace.model.Node) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) VM(org.btrplace.model.VM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) ArrayList(java.util.ArrayList) Running(org.btrplace.model.constraint.Running) Split(org.btrplace.model.constraint.Split) Gather(org.btrplace.model.constraint.Gather)

Example 3 with RunningCapacity

use of org.btrplace.model.constraint.RunningCapacity in project scheduler by btrplace.

the class ScriptTest method testConstraints.

public void testConstraints() {
    Script v = new Script();
    Model mo = new DefaultModel();
    VM vm2 = mo.newVM();
    v.addConstraint(new Gather(Collections.singleton(vm2)));
    v.addConstraint(new RunningCapacity(Collections.singleton(mo.newNode()), 5));
    Assert.assertEquals(v.getConstraints().size(), 2);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) RunningCapacity(org.btrplace.model.constraint.RunningCapacity) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Gather(org.btrplace.model.constraint.Gather)

Example 4 with RunningCapacity

use of org.btrplace.model.constraint.RunningCapacity in project scheduler by btrplace.

the class IssuesTest method testIssue86.

@Test
public void testIssue86() throws Exception {
    Model mo = new DefaultModel();
    mo.getMapping().addReadyVM(mo.newVM());
    mo.getMapping().addReadyVM(mo.newVM());
    mo.getMapping().addReadyVM(mo.newVM());
    mo.getMapping().addOnlineNode(mo.newNode());
    mo.getMapping().addOnlineNode(mo.newNode());
    mo.getMapping().addOnlineNode(mo.newNode());
    List<SatConstraint> cstrs = mo.getMapping().getAllVMs().stream().map(Running::new).collect(Collectors.toList());
    cstrs.add(new Spread(mo.getMapping().getAllVMs(), false));
    cstrs.addAll(mo.getMapping().getOnlineNodes().stream().map(n -> new RunningCapacity(n, 1)).collect(Collectors.toList()));
    Instance i = new Instance(mo, cstrs, new MinMTTR());
    ChocoScheduler s = new DefaultChocoScheduler();
    s.doOptimize(false);
    s.doRepair(false);
    ReconfigurationPlan p = s.solve(i.getModel(), i.getSatConstraints(), i.getOptConstraint());
    Assert.assertNotNull(p);
    Assert.assertEquals(3, p.getActions().size());
    s.doRepair(true);
    p = s.solve(i.getModel(), i.getSatConstraints(), i.getOptConstraint());
    Assert.assertNotNull(p);
    Assert.assertEquals(3, p.getActions().size());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Spread(org.btrplace.model.constraint.Spread) RunningCapacity(org.btrplace.model.constraint.RunningCapacity) Instance(org.btrplace.model.Instance) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMTTR(org.btrplace.model.constraint.MinMTTR) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) Test(org.testng.annotations.Test)

Example 5 with RunningCapacity

use of org.btrplace.model.constraint.RunningCapacity in project scheduler by btrplace.

the class RunningCapacityBuilderTest method testGoodSignatures.

@Test(dataProvider = "goodCapacities")
public void testGoodSignatures(String str, int nbNodes, int capa, boolean c) throws Exception {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n@N[1..20] : defaultNode;\n" + str).getConstraints();
    Assert.assertEquals(cstrs.size(), 1);
    RunningCapacity x = (RunningCapacity) cstrs.iterator().next();
    Assert.assertEquals(x.getInvolvedNodes().size(), nbNodes);
    Assert.assertEquals(x.getAmount(), capa);
    Assert.assertEquals(x.isContinuous(), c);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) RunningCapacity(org.btrplace.model.constraint.RunningCapacity) SatConstraint(org.btrplace.model.constraint.SatConstraint) ScriptBuilder(org.btrplace.btrpsl.ScriptBuilder) Test(org.testng.annotations.Test)

Aggregations

RunningCapacity (org.btrplace.model.constraint.RunningCapacity)6 DefaultModel (org.btrplace.model.DefaultModel)4 SatConstraint (org.btrplace.model.constraint.SatConstraint)4 Model (org.btrplace.model.Model)3 Test (org.testng.annotations.Test)3 Node (org.btrplace.model.Node)2 VM (org.btrplace.model.VM)2 Gather (org.btrplace.model.constraint.Gather)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)1 BtrpNumber (org.btrplace.btrpsl.element.BtrpNumber)1 Instance (org.btrplace.model.Instance)1 MinMTTR (org.btrplace.model.constraint.MinMTTR)1 Running (org.btrplace.model.constraint.Running)1 Split (org.btrplace.model.constraint.Split)1 Spread (org.btrplace.model.constraint.Spread)1 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)1 BootVM (org.btrplace.plan.event.BootVM)1 MigrateVM (org.btrplace.plan.event.MigrateVM)1