Search in sources :

Example 11 with Fence

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

the class FenceSplitter method split.

@Override
public boolean split(Fence cstr, Instance origin, final List<Instance> partitions, TIntIntHashMap vmsPosition, TIntIntHashMap nodePosition) {
    final SplittableElementSet<Node> nodeIndex = SplittableElementSet.newNodeIndex(cstr.getInvolvedNodes(), nodePosition);
    VM v = cstr.getInvolvedVMs().iterator().next();
    int p = vmsPosition.get(v.id());
    Set<Node> ns = nodeIndex.getSubSet(p);
    if (!ns.isEmpty()) {
        return partitions.get(p).getSatConstraints().add(new Fence(v, ns));
    }
    return true;
}
Also used : Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) Fence(org.btrplace.model.constraint.Fence)

Example 12 with Fence

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

the class CNetworkTest method defaultTest.

/**
 * Test the instantiation and the creation of the variables.
 *
 * @throws org.btrplace.scheduler.SchedulerException if an error occurs during the solving process (it should not)
 */
@Test
public void defaultTest() throws SchedulerException {
    // New default model
    Model mo = new DefaultModel();
    Mapping ma = mo.getMapping();
    // Create and boot 1 source and 1 destination node
    Node srcNode = mo.newNode(), dstNode = mo.newNode();
    ma.addOnlineNode(srcNode);
    ma.addOnlineNode(dstNode);
    // Attach a network view
    Network net = new Network();
    mo.attach(net);
    // Connect the nodes through a main non-blocking switch using 1 Gbit/s links
    Switch swMain = net.newSwitch();
    int bw = 1000;
    net.connect(bw, swMain, srcNode, dstNode);
    // Create and host 1 running VM on the source node
    VM vm = mo.newVM();
    ma.addRunningVM(vm, srcNode);
    // The VM consumes 6 GiB memory and has a memory intensive workload equivalent to "stress --vm 1000 --bytes 50K"
    int memUsed = 6000, hotDirtySize = 46, hotDirtyDuration = 2;
    double coldDirtyRate = 23.6;
    // 6 GiB
    mo.getAttributes().put(vm, "memUsed", memUsed);
    // 46 MiB
    mo.getAttributes().put(vm, "hotDirtySize", hotDirtySize);
    // 2 sec.
    mo.getAttributes().put(vm, "hotDirtyDuration", hotDirtyDuration);
    // 23.6 MiB/sec.
    mo.getAttributes().put(vm, "coldDirtyRate", coldDirtyRate);
    // Add constraints
    List<SatConstraint> cstrs = new ArrayList<>();
    // We force the migration to go on the destination node
    cstrs.add(new Fence(vm, Collections.singleton(dstNode)));
    // Try to solve using the custom Min MTTR objective for migration scheduling
    ReconfigurationPlan p = new DefaultChocoScheduler().solve(mo, cstrs, new MinMTTRMig());
    Assert.assertNotNull(p);
    // The switch is non-blocking
    Assert.assertEquals(swMain.getCapacity(), Integer.MAX_VALUE);
    // Check the migration path and bandwidth
    MigrateVM mig = (MigrateVM) p.getActions().stream().filter(s -> s instanceof MigrateVM).findFirst().get();
    Assert.assertTrue(net.getRouting().getPath(mig.getSourceNode(), mig.getDestinationNode()).containsAll(net.getLinks()));
    Assert.assertEquals(net.getRouting().getMaxBW(mig.getSourceNode(), mig.getDestinationNode()), bw);
    Assert.assertEquals(mig.getBandwidth(), bw);
    // Check the migration duration computation
    double bandwidth_octet = mig.getBandwidth() / 9, durationMin, durationColdPages, durationHotPages, durationTotal;
    durationMin = memUsed / bandwidth_octet;
    durationColdPages = ((hotDirtySize + ((durationMin - hotDirtyDuration) * coldDirtyRate)) / (bandwidth_octet - coldDirtyRate));
    durationHotPages = ((hotDirtySize / bandwidth_octet) * ((hotDirtySize / hotDirtyDuration) / (bandwidth_octet - (hotDirtySize / hotDirtyDuration))));
    durationTotal = durationMin + durationColdPages + durationHotPages;
    Assert.assertEquals((mig.getEnd() - mig.getStart()), (int) Math.round(durationTotal));
}
Also used : SchedulerException(org.btrplace.scheduler.SchedulerException) MigrateVM(org.btrplace.plan.event.MigrateVM) Test(org.testng.annotations.Test) MinMTTRMig(org.btrplace.model.constraint.migration.MinMTTRMig) Fence(org.btrplace.model.constraint.Fence) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) List(java.util.List) Assert(org.testng.Assert) org.btrplace.model(org.btrplace.model) ShareableResource(org.btrplace.model.view.ShareableResource) Switch(org.btrplace.model.view.network.Switch) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Collections(java.util.Collections) Network(org.btrplace.model.view.network.Network) SatConstraint(org.btrplace.model.constraint.SatConstraint) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) MigrateVM(org.btrplace.plan.event.MigrateVM) SatConstraint(org.btrplace.model.constraint.SatConstraint) MinMTTRMig(org.btrplace.model.constraint.migration.MinMTTRMig) Switch(org.btrplace.model.view.network.Switch) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Network(org.btrplace.model.view.network.Network) MigrateVM(org.btrplace.plan.event.MigrateVM) Fence(org.btrplace.model.constraint.Fence) Test(org.testng.annotations.Test)

Example 13 with Fence

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

the class CNetworkTest method testWithSwitchCapacity.

@Test
public void testWithSwitchCapacity() {
    Model mo = new DefaultModel();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    VM v = mo.newVM();
    mo.getMapping().on(n1, n2).run(n1, v);
    ShareableResource mem = new ShareableResource("mem", 10000, 5000);
    Network net = new Network();
    mo.attach(net);
    mo.attach(mem);
    mo.getAttributes().put(v, "memUsed", 10000);
    Switch sw = net.newSwitch(1000);
    net.connect(2000, sw, n1, n2);
    ChocoScheduler s = new DefaultChocoScheduler();
    ReconfigurationPlan p = s.solve(mo, Collections.singletonList(new Fence(v, n2)));
    Assert.assertNotNull(p);
}
Also used : DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) Switch(org.btrplace.model.view.network.Switch) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) MigrateVM(org.btrplace.plan.event.MigrateVM) Network(org.btrplace.model.view.network.Network) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Fence(org.btrplace.model.constraint.Fence) ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 14 with Fence

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

the class CShareableResourceTest method testRealNodeUsage.

/**
 * Place some VMs and check realNodeUsage is updated accordingly
 */
@Test
public void testRealNodeUsage() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping ma = mo.getMapping();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    ma.addOnlineNode(n1);
    ma.addOnlineNode(n2);
    ma.addRunningVM(vm1, n1);
    ma.addRunningVM(vm2, n1);
    ShareableResource rc = new ShareableResource("foo", 0, 0);
    rc.setConsumption(vm1, 2);
    rc.setConsumption(vm2, 3);
    rc.setCapacity(n1, 5);
    rc.setCapacity(n2, 3);
    mo.attach(rc);
    ChocoScheduler s = new DefaultChocoScheduler();
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.add(new Fence(vm1, n1));
    cstrs.add(new Fence(vm2, n2));
    ReconfigurationPlan p = s.solve(mo, cstrs);
    Assert.assertNotNull(p);
    Model res = p.getResult();
    rc = (ShareableResource.get(res, "foo"));
    // rcm.getVirtualUsage(0).isInstantiatedTo(2));
    Assert.assertEquals(2, rc.getConsumption(vm1));
    // rcm.getVirtualUsage(1).isInstantiatedTo(3));
    Assert.assertEquals(3, rc.getConsumption(vm2));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Fence(org.btrplace.model.constraint.Fence) Test(org.testng.annotations.Test)

Example 15 with Fence

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

the class CSplitAmongTest method testDiscreteWithGroupChange.

@Test
public void testDiscreteWithGroupChange() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    VM vm6 = mo.newVM();
    VM vm7 = mo.newVM();
    VM vm8 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    Node n4 = mo.newNode();
    Node n5 = mo.newNode();
    Mapping map = mo.getMapping().on(n1, n2, n3, n4, n5).run(n1, vm1, vm3).run(n2, vm2).run(n3, vm4, vm6).run(n4, vm5).run(n5, vm7);
    // Isolated VM not considered by the constraint
    map.addRunningVM(vm8, n1);
    Collection<VM> vg1 = new HashSet<>(Arrays.asList(vm1, vm2, vm3));
    Collection<VM> vg2 = new HashSet<>(Arrays.asList(vm4, vm5, vm6));
    Collection<Node> pg1 = new HashSet<>(Arrays.asList(n1, n2));
    Collection<Node> pg2 = new HashSet<>(Arrays.asList(n3, n4));
    Collection<Node> pg3 = new HashSet<>(Collections.singletonList(n5));
    Collection<Collection<VM>> vgs = new HashSet<>(Arrays.asList(vg1, vg2));
    Collection<Collection<Node>> pgs = new HashSet<>(Arrays.asList(pg1, pg2, pg3));
    List<SatConstraint> cstrs = new ArrayList<>();
    SplitAmong s = new SplitAmong(vgs, pgs);
    s.setContinuous(false);
    // Move group of VMs 1 to the group of nodes 2. This is allowed
    // group of VMs 2 will move to another group of node so at the end, the constraint should be satisfied
    cstrs.add(s);
    for (VM v : vg1) {
        cstrs.add(new Fence(v, pg2));
    }
    ChocoScheduler cra = new DefaultChocoScheduler();
    ReconfigurationPlan plan = cra.solve(mo, cstrs);
    Assert.assertNotNull(plan);
}
Also used : SplitAmong(org.btrplace.model.constraint.SplitAmong) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Fence(org.btrplace.model.constraint.Fence) Test(org.testng.annotations.Test)

Aggregations

Fence (org.btrplace.model.constraint.Fence)19 SatConstraint (org.btrplace.model.constraint.SatConstraint)16 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)15 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)14 Test (org.testng.annotations.Test)13 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)10 ArrayList (java.util.ArrayList)9 ShareableResource (org.btrplace.model.view.ShareableResource)8 DefaultModel (org.btrplace.model.DefaultModel)7 Model (org.btrplace.model.Model)7 VM (org.btrplace.model.VM)7 Network (org.btrplace.model.view.network.Network)7 Node (org.btrplace.model.Node)6 Switch (org.btrplace.model.view.network.Switch)6 SchedulerException (org.btrplace.scheduler.SchedulerException)6 Offline (org.btrplace.model.constraint.Offline)5 MinMTTRMig (org.btrplace.model.constraint.migration.MinMTTRMig)5 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)4 HashSet (java.util.HashSet)3 MigrateVM (org.btrplace.plan.event.MigrateVM)3