Search in sources :

Example 26 with Model

use of org.btrplace.model.Model in project scheduler by btrplace.

the class OverbookTest method testContinuousIsSatisfied.

@Test
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<VM> vms = Util.newVMs(mo, 10);
    Node n0 = mo.newNode();
    Node n1 = mo.newNode();
    Model i = new DefaultModel();
    Mapping cfg = i.getMapping();
    cfg.addOnlineNode(n0);
    cfg.addOnlineNode(n1);
    ShareableResource rc = new ShareableResource("cpu");
    rc.setCapacity(n0, 1);
    rc.setCapacity(n1, 4);
    rc.setConsumption(vms.get(0), 2);
    rc.setConsumption(vms.get(1), 2);
    rc.setConsumption(vms.get(2), 4);
    cfg.addRunningVM(vms.get(0), n0);
    cfg.addRunningVM(vms.get(1), n1);
    cfg.addRunningVM(vms.get(2), n1);
    cfg.addRunningVM(vms.get(3), n1);
    i.attach(rc);
    Overbook o = new Overbook(n1, "cpu", 2);
    o.setContinuous(true);
    ReconfigurationPlan p = new DefaultReconfigurationPlan(i);
    Assert.assertEquals(o.isSatisfied(p), true);
    p.add(new Allocate(vms.get(0), n0, "cpu", 1, 2, 5));
    Assert.assertEquals(o.isSatisfied(p), true);
    p.add(new Allocate(vms.get(1), n1, "cpu", 5, 2, 5));
    Assert.assertEquals(o.isSatisfied(p), false);
    p.add(new Allocate(vms.get(2), n1, "cpu", 2, 0, 1));
    Assert.assertEquals(o.isSatisfied(p), true);
    p.add(new Allocate(vms.get(3), n1, "cpu", 3, 4, 6));
    Assert.assertEquals(o.isSatisfied(p), false);
    p.add(new ShutdownVM(vms.get(2), n1, 2, 3));
    Assert.assertEquals(o.isSatisfied(p), true);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) VM(org.btrplace.model.VM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Node(org.btrplace.model.Node) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Allocate(org.btrplace.plan.event.Allocate) Test(org.testng.annotations.Test)

Example 27 with Model

use of org.btrplace.model.Model in project scheduler by btrplace.

the class QuarantineTest method testQuarantines.

@Test
public void testQuarantines() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 5);
    List<Quarantine> qs = Quarantine.newQuarantine(ns);
    Assert.assertEquals(qs.size(), ns.size());
    qs.stream().forEach((q) -> {
        Assert.assertTrue(ns.containsAll(q.getInvolvedNodes()));
        Assert.assertTrue(q.isContinuous());
    });
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 28 with Model

use of org.btrplace.model.Model in project scheduler by btrplace.

the class QuarantineTest method testEqualsHashCode.

@Test
public void testEqualsHashCode() {
    Model mo = new DefaultModel();
    Node n = mo.newNode();
    Quarantine q = new Quarantine(n);
    Assert.assertTrue(q.equals(q));
    Assert.assertTrue(q.equals(new Quarantine(n)));
    Assert.assertEquals(q.hashCode(), new Quarantine(n).hashCode());
    Assert.assertFalse(q.equals(new Quarantine(mo.newNode())));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 29 with Model

use of org.btrplace.model.Model in project scheduler by btrplace.

the class ResourceCapacityTest method testEqualsAndHashCode.

@Test(dependsOnMethods = { "testInstantiation" })
public void testEqualsAndHashCode() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 10);
    Set<Node> s = new HashSet<>(Arrays.asList(ns.get(0), ns.get(1)));
    ResourceCapacity c = new ResourceCapacity(s, "foo", 3);
    ResourceCapacity c2 = new ResourceCapacity(s, "foo", 3);
    Assert.assertTrue(c.equals(c));
    Assert.assertTrue(c.equals(c2));
    Assert.assertEquals(c.hashCode(), c2.hashCode());
    Assert.assertFalse(c.equals(new ResourceCapacity(s, "bar", 3)));
    Assert.assertFalse(c.equals(new ResourceCapacity(s, "foo", 2)));
    Assert.assertFalse(c.equals(new ResourceCapacity(new HashSet<>(), "foo", 3)));
    Assert.assertNotEquals(new ResourceCapacity(s, "f", 3, true), new ResourceCapacity(s, "f", 3, false));
    Assert.assertNotEquals(new ResourceCapacity(s, "f", 3, true).hashCode(), new ResourceCapacity(s, "f", 3, false).hashCode());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 30 with Model

use of org.btrplace.model.Model in project scheduler by btrplace.

the class ResourceCapacityTest method testContinuousIsSatisfied.

@Test
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 10);
    List<VM> vms = Util.newVMs(mo, 10);
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addOnlineNode(ns.get(2));
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addRunningVM(vms.get(1), ns.get(0));
    map.addRunningVM(vms.get(2), ns.get(1));
    map.addRunningVM(vms.get(3), ns.get(2));
    map.addReadyVM(vms.get(4));
    ShareableResource rc = new ShareableResource("foo", 1, 1);
    mo.attach(rc);
    Set<Node> nodes = new HashSet<>(Arrays.asList(ns.get(0), ns.get(1)));
    ResourceCapacity cc = new ResourceCapacity(nodes, "foo", 4, true);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    Assert.assertEquals(cc.isSatisfied(plan), true);
    // 3/4
    MigrateVM m = new MigrateVM(vms.get(3), ns.get(2), ns.get(1), 0, 1);
    m.addEvent(Action.Hook.POST, new AllocateEvent(vms.get(3), "foo", 2));
    plan.add(m);
    // 5/4
    plan.add(new ShutdownVM(vms.get(2), ns.get(1), 1, 2));
    // 4/4
    plan.add(new BootVM(vms.get(4), ns.get(2), 2, 3));
    // 4/4
    plan.add(new Allocate(vms.get(1), ns.get(0), "foo", 2, 2, 3));
    // 5/4
    plan.add(new MigrateVM(vms.get(0), ns.get(0), ns.get(2), 3, 4));
    System.out.println(plan);
    Assert.assertEquals(cc.isSatisfied(plan), true);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) MigrateVM(org.btrplace.plan.event.MigrateVM) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) VM(org.btrplace.model.VM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) BootVM(org.btrplace.plan.event.BootVM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Allocate(org.btrplace.plan.event.Allocate) HashSet(java.util.HashSet) AllocateEvent(org.btrplace.plan.event.AllocateEvent) Test(org.testng.annotations.Test)

Aggregations

Model (org.btrplace.model.Model)419 DefaultModel (org.btrplace.model.DefaultModel)406 Test (org.testng.annotations.Test)373 Node (org.btrplace.model.Node)276 VM (org.btrplace.model.VM)271 Mapping (org.btrplace.model.Mapping)181 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)147 HashSet (java.util.HashSet)97 MigrateVM (org.btrplace.plan.event.MigrateVM)90 SatConstraint (org.btrplace.model.constraint.SatConstraint)87 ArrayList (java.util.ArrayList)86 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)84 ShareableResource (org.btrplace.model.view.ShareableResource)75 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)66 Instance (org.btrplace.model.Instance)50 ShutdownNode (org.btrplace.plan.event.ShutdownNode)47 MinMTTR (org.btrplace.model.constraint.MinMTTR)43 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)43 Parameters (org.btrplace.scheduler.choco.Parameters)39 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)39