Search in sources :

Example 1 with Running

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);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) Mapping(org.btrplace.model.Mapping) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Running(org.btrplace.model.constraint.Running) Test(org.testng.annotations.Test)

Example 2 with Running

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));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Running(org.btrplace.model.constraint.Running) Test(org.testng.annotations.Test)

Example 3 with Running

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;
}
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 4 with Running

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;
}
Also used : Ready(org.btrplace.model.constraint.Ready) Spread(org.btrplace.model.constraint.Spread) SatConstraint(org.btrplace.model.constraint.SatConstraint) ArrayList(java.util.ArrayList) Running(org.btrplace.model.constraint.Running) Offline(org.btrplace.model.constraint.Offline) Preserve(org.btrplace.model.constraint.Preserve) HashSet(java.util.HashSet)

Example 5 with Running

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);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Parameters(org.btrplace.scheduler.choco.Parameters) Instance(org.btrplace.model.Instance) DefaultElementBuilder(org.btrplace.model.DefaultElementBuilder) Node(org.btrplace.model.Node) MinMTTR(org.btrplace.model.constraint.MinMTTR) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) SubModel(org.btrplace.scheduler.runner.disjoint.model.SubModel) DefaultModel(org.btrplace.model.DefaultModel) Running(org.btrplace.model.constraint.Running) SynchronizedElementBuilder(org.btrplace.model.SynchronizedElementBuilder) Test(org.testng.annotations.Test)

Aggregations

Running (org.btrplace.model.constraint.Running)24 VM (org.btrplace.model.VM)20 Test (org.testng.annotations.Test)20 DefaultModel (org.btrplace.model.DefaultModel)17 Model (org.btrplace.model.Model)17 Node (org.btrplace.model.Node)17 SatConstraint (org.btrplace.model.constraint.SatConstraint)13 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)13 ArrayList (java.util.ArrayList)12 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)10 Instance (org.btrplace.model.Instance)8 MinMTTR (org.btrplace.model.constraint.MinMTTR)8 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)8 Mapping (org.btrplace.model.Mapping)7 ShareableResource (org.btrplace.model.view.ShareableResource)7 HashSet (java.util.HashSet)5 Ready (org.btrplace.model.constraint.Ready)5 Preserve (org.btrplace.model.constraint.Preserve)4 BootVM (org.btrplace.plan.event.BootVM)4 Fence (org.btrplace.model.constraint.Fence)3