Search in sources :

Example 16 with Model

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

the class AllowAllConstraintCheckerTest method testAnyTracking.

@Test(dependsOnMethods = "testInstantiation")
public void testAnyTracking() {
    SatConstraint cstr = mock(SatConstraint.class);
    AllowAllConstraintChecker<SatConstraint> c = new AllowAllConstraintChecker<>(cstr);
    Model mo = new DefaultModel();
    List<VM> vms = Util.newVMs(mo, 10);
    when(cstr.getInvolvedVMs()).thenReturn(vms);
    Set<VM> vs = new HashSet<>(Arrays.asList(vms.get(4), vms.get(6), vms.get(9)));
    c.track(vs);
    // VM1 (one of the involved vms) has to be removed to be substituted by vms.get(0)0
    c.consume(new SubstitutedVMEvent(vms.get(6), vms.get(9)));
    Assert.assertTrue(vs.contains(vms.get(9)));
    Assert.assertFalse(vs.contains(vms.get(6)));
    // VM5 is not involved, no removal
    c.consume(new SubstitutedVMEvent(vms.get(6), vms.get(0)));
    Assert.assertFalse(vs.contains(vms.get(6)));
    Assert.assertFalse(vs.contains(vms.get(0)));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) VM(org.btrplace.model.VM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) SuspendVM(org.btrplace.plan.event.SuspendVM) ResumeVM(org.btrplace.plan.event.ResumeVM) ForgeVM(org.btrplace.plan.event.ForgeVM) KillVM(org.btrplace.plan.event.KillVM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) SubstitutedVMEvent(org.btrplace.plan.event.SubstitutedVMEvent) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 17 with Model

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

the class AllowAllConstraintCheckerTest method testAcceptance.

@Test
public void testAcceptance() {
    SatConstraint cstr = mock(SatConstraint.class);
    AllowAllConstraintChecker<?> c = mock(AllowAllConstraintChecker.class, CALLS_REAL_METHODS);
    Model mo = new DefaultModel();
    List<VM> vms = Util.newVMs(mo, 10);
    List<Node> ns = Util.newNodes(mo, 10);
    when(cstr.getInvolvedNodes()).thenReturn(ns);
    when(cstr.getInvolvedVMs()).thenReturn(vms);
    MigrateVM m = new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
    Assert.assertTrue(c.start(m));
    verify(c).startRunningVMPlacement(m);
    c.end(m);
    verify(c).endRunningVMPlacement(m);
    BootVM b = new BootVM(vms.get(0), ns.get(0), 0, 3);
    Assert.assertTrue(c.start(b));
    verify(c).startRunningVMPlacement(b);
    c.end(b);
    verify(c).endRunningVMPlacement(b);
    ResumeVM r = new ResumeVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
    Assert.assertTrue(c.start(r));
    verify(c).startRunningVMPlacement(r);
    c.end(r);
    verify(c).endRunningVMPlacement(r);
    // do not use the mock as the constructor is important
    // while earlier, the mock was needed for the verify()
    c = new AllowAllConstraintChecker<>(cstr);
    Set<VM> allVMs = new HashSet<>();
    for (Node n : mo.getMapping().getOnlineNodes()) {
        allVMs.addAll(mo.getMapping().getRunningVMs(n));
        allVMs.addAll(mo.getMapping().getSleepingVMs(n));
    }
    allVMs.addAll(mo.getMapping().getReadyVMs());
    c.track(allVMs);
    SuspendVM s = new SuspendVM(vms.get(0), ns.get(0), ns.get(1), 0, 3);
    Assert.assertTrue(c.start(s));
    ShutdownVM s2 = new ShutdownVM(vms.get(0), ns.get(0), 0, 3);
    Assert.assertTrue(c.start(s2));
    KillVM k = new KillVM(vms.get(0), ns.get(0), 0, 3);
    Assert.assertTrue(c.start(k));
    ForgeVM f = new ForgeVM(vms.get(0), 0, 3);
    Assert.assertTrue(c.start(f));
    BootNode bn = new BootNode(ns.get(0), 0, 3);
    Assert.assertTrue(c.start(bn));
    ShutdownNode sn = new ShutdownNode(ns.get(0), 0, 3);
    Assert.assertTrue(c.start(sn));
    SubstitutedVMEvent ss = new SubstitutedVMEvent(vms.get(9), vms.get(2));
    Assert.assertTrue(c.consume(ss));
    Allocate a = new Allocate(vms.get(0), ns.get(0), "cpu", 3, 4, 5);
    Assert.assertTrue(c.start(a));
    AllocateEvent ae = new AllocateEvent(vms.get(0), "cpu", 3);
    Assert.assertTrue(c.consume(ae));
}
Also used : KillVM(org.btrplace.plan.event.KillVM) DefaultModel(org.btrplace.model.DefaultModel) BootNode(org.btrplace.plan.event.BootNode) Node(org.btrplace.model.Node) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) MigrateVM(org.btrplace.plan.event.MigrateVM) ForgeVM(org.btrplace.plan.event.ForgeVM) SubstitutedVMEvent(org.btrplace.plan.event.SubstitutedVMEvent) ResumeVM(org.btrplace.plan.event.ResumeVM) SuspendVM(org.btrplace.plan.event.SuspendVM) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) VM(org.btrplace.model.VM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) SuspendVM(org.btrplace.plan.event.SuspendVM) ResumeVM(org.btrplace.plan.event.ResumeVM) ForgeVM(org.btrplace.plan.event.ForgeVM) KillVM(org.btrplace.plan.event.KillVM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) BootVM(org.btrplace.plan.event.BootVM) ShutdownNode(org.btrplace.plan.event.ShutdownNode) 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)

Example 18 with Model

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

the class BanTest method testEquals.

@Test
public void testEquals() {
    Model m = new DefaultModel();
    VM v = m.newVM();
    List<Node> ns = Util.newNodes(m, 10);
    Set<Node> nodes = new HashSet<>(Arrays.asList(ns.get(0), ns.get(1)));
    Ban b = new Ban(v, nodes);
    Assert.assertTrue(b.equals(b));
    Assert.assertTrue(new Ban(v, nodes).equals(b));
    Assert.assertEquals(new Ban(v, nodes).hashCode(), b.hashCode());
    Assert.assertNotEquals(new Ban(m.newVM(), nodes), b);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) 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 19 with Model

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

the class BanTest method testIsSatisfied.

@Test
public void testIsSatisfied() {
    Model m = new DefaultModel();
    List<VM> vms = Util.newVMs(m, 10);
    List<Node> ns = Util.newNodes(m, 10);
    Mapping map = m.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(1));
    map.addRunningVM(vms.get(2), ns.get(2));
    Set<Node> nodes = new HashSet<>(Collections.singletonList(ns.get(0)));
    Ban b = new Ban(vms.get(2), nodes);
    Assert.assertEquals(b.isSatisfied(m), true);
    map.addRunningVM(vms.get(2), ns.get(0));
    Assert.assertEquals(new Ban(vms.get(2), nodes).isSatisfied(m), false);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(m);
    plan.add(new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 3));
    plan.add(new MigrateVM(vms.get(0), ns.get(1), ns.get(0), 3, 6));
    plan.add(new MigrateVM(vms.get(1), ns.get(1), ns.get(2), 3, 6));
    Assert.assertEquals(b.isSatisfied(plan), false);
}
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) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 20 with Model

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

the class FenceTest method testIsSatisfied.

@Test
public void testIsSatisfied() {
    Model m = new DefaultModel();
    List<Node> ns = Util.newNodes(m, 10);
    List<VM> vms = Util.newVMs(m, 10);
    Mapping map = m.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(1));
    map.addRunningVM(vms.get(2), ns.get(1));
    Set<Node> nodes = new HashSet<>(Arrays.asList(ns.get(0), ns.get(1)));
    Fence f = new Fence(vms.get(2), nodes);
    Assert.assertEquals(true, f.isSatisfied(m));
    map.addRunningVM(vms.get(0), ns.get(2));
    Assert.assertEquals(false, new Fence(vms.get(0), nodes).isSatisfied(m));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Mapping(org.btrplace.model.Mapping) HashSet(java.util.HashSet) 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