Search in sources :

Example 6 with Model

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

the class AmongTest method testContinuousIsSatisfied.

@Test(dependsOnMethods = { "testInstantiation" })
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 10);
    List<VM> vms = Util.newVMs(mo, 10);
    Collection<Node> s1 = new HashSet<>(Arrays.asList(ns.get(0), ns.get(1)));
    Collection<Node> s2 = new HashSet<>(Collections.singletonList(ns.get(2)));
    Collection<Collection<Node>> pGrps = Arrays.asList(s1, s2);
    Set<VM> vs = new HashSet<>(Arrays.asList(vms.get(0), vms.get(1), vms.get(2)));
    Among a = new Among(vs, pGrps, true);
    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(1));
    map.addRunningVM(vms.get(2), ns.get(1));
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    Assert.assertEquals(a.isSatisfied(plan), true);
    plan.add(new MigrateVM(vms.get(2), ns.get(1), ns.get(2), 0, 1));
    plan.add(new MigrateVM(vms.get(2), ns.get(2), ns.get(1), 1, 2));
    // At moment 1, the constraint will be violated
    Assert.assertEquals(a.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) Collection(java.util.Collection) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 7 with Model

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

the class AmongTest method testInstantiation.

@Test
public void testInstantiation() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 10);
    List<VM> vms = Util.newVMs(mo, 10);
    Collection<Node> s1 = Arrays.asList(ns.get(0), ns.get(1));
    Collection<Node> s2 = Collections.singletonList(ns.get(2));
    Collection<Collection<Node>> pGrps = Arrays.asList(s1, s2);
    Set<VM> vg = new HashSet<>(Arrays.asList(vms.get(0), vms.get(1), vms.get(2)));
    Among a = new Among(vg, pGrps);
    Assert.assertNotNull(a.getChecker());
    Assert.assertEquals(a.getInvolvedVMs(), vg);
    Assert.assertEquals(a.getGroupsOfNodes(), pGrps);
    Assert.assertEquals(a.getInvolvedNodes().size(), s1.size() + s2.size());
    Assert.assertTrue(a.getInvolvedNodes().containsAll(s1));
    Assert.assertTrue(a.getInvolvedNodes().containsAll(s2));
    Assert.assertFalse(a.toString().contains("null"));
    Assert.assertFalse(a.isContinuous());
    Assert.assertTrue(a.setContinuous(true));
    Assert.assertTrue(a.setContinuous(false));
    a = new Among(vg, pGrps, true);
    Assert.assertTrue(a.isContinuous());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Collection(java.util.Collection) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 8 with Model

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

the class DenyMyVMsActionsTest method testDeny.

@Test
public void testDeny() {
    Model mo = new DefaultModel();
    List<VM> vms = Util.newVMs(mo, 10);
    List<Node> ns = Util.newNodes(mo, 10);
    when(cstr.getInvolvedNodes()).thenReturn(Arrays.asList(ns.get(0), ns.get(1), ns.get(2)));
    when(cstr.getInvolvedVMs()).thenReturn(Arrays.asList(vms.get(0), vms.get(1), vms.get(2)));
    DenyMyVMsActions<SatConstraint> c = new DenyMyVMsActions<SatConstraint>(cstr) {
    };
    Assert.assertFalse(c.start(new BootVM(vms.get(0), ns.get(0), 0, 3)));
    Assert.assertTrue(c.start(new BootVM(vms.get(8), ns.get(0), 0, 3)));
    Assert.assertFalse(c.start(new ResumeVM(vms.get(0), ns.get(0), ns.get(1), 0, 3)));
    Assert.assertTrue(c.start(new ResumeVM(vms.get(6), ns.get(0), ns.get(1), 0, 3)));
    Assert.assertFalse(c.start(new MigrateVM(vms.get(0), ns.get(0), ns.get(1), 0, 3)));
    Assert.assertTrue(c.start(new MigrateVM(vms.get(4), ns.get(0), ns.get(1), 0, 3)));
    Assert.assertFalse(c.start(new SuspendVM(vms.get(0), ns.get(0), ns.get(1), 0, 3)));
    Assert.assertTrue(c.start(new SuspendVM(vms.get(9), ns.get(0), ns.get(1), 0, 3)));
    Assert.assertFalse(c.start(new ShutdownVM(vms.get(0), ns.get(0), 0, 3)));
    Assert.assertTrue(c.start(new ShutdownVM(vms.get(5), ns.get(0), 0, 3)));
    Assert.assertFalse(c.start(new KillVM(vms.get(0), ns.get(0), 0, 3)));
    Assert.assertTrue(c.start(new KillVM(vms.get(6), ns.get(0), 0, 3)));
    Assert.assertFalse(c.start(new ForgeVM(vms.get(0), 0, 3)));
    Assert.assertTrue(c.start(new ForgeVM(vms.get(6), 0, 3)));
    Assert.assertFalse(c.start(new Allocate(vms.get(0), ns.get(0), "cpu", 3, 4, 5)));
    Assert.assertTrue(c.start(new Allocate(vms.get(5), ns.get(0), "cpu", 3, 4, 5)));
    Assert.assertFalse(c.consume(new SubstitutedVMEvent(vms.get(0), vms.get(2))));
    Assert.assertTrue(c.consume(new SubstitutedVMEvent(vms.get(9), vms.get(2))));
    Assert.assertFalse(c.consume(new AllocateEvent(vms.get(2), "cpu", 3)));
    Assert.assertTrue(c.consume(new AllocateEvent(vms.get(9), "cpu", 3)));
}
Also used : KillVM(org.btrplace.plan.event.KillVM) DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) 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) ResumeVM(org.btrplace.plan.event.ResumeVM) 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) 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) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Allocate(org.btrplace.plan.event.Allocate) AllocateEvent(org.btrplace.plan.event.AllocateEvent) Test(org.testng.annotations.Test)

Example 9 with Model

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

the class GatherTest method testInstantiate.

@Test
public void testInstantiate() {
    Model mo = new DefaultModel();
    Set<VM> s = new HashSet<>(Arrays.asList(mo.newVM(), mo.newVM()));
    Gather g = new Gather(s);
    Assert.assertNotNull(g.getChecker());
    Assert.assertTrue(g.getInvolvedNodes().isEmpty());
    Assert.assertEquals(g.getInvolvedVMs(), s);
    Assert.assertFalse(g.toString().contains("null"));
    Assert.assertFalse(g.isContinuous());
    Assert.assertTrue(g.setContinuous(true));
    Assert.assertTrue(g.isContinuous());
    System.out.println(g);
    g = new Gather(s, true);
    Assert.assertTrue(g.isContinuous());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) 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 10 with Model

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

the class GatherTest method testEqualsHashCode.

@Test(dependsOnMethods = { "testInstantiate" })
public void testEqualsHashCode() {
    Model mo = new DefaultModel();
    VM vm = mo.newVM();
    Set<VM> s = new HashSet<>(Arrays.asList(vm, mo.newVM()));
    Gather g = new Gather(s);
    Assert.assertTrue(g.equals(g));
    Assert.assertFalse(g.equals(new Object()));
    Gather g2 = new Gather(new HashSet<>(s));
    Assert.assertTrue(g2.equals(g));
    Assert.assertEquals(g2.hashCode(), g.hashCode());
    s.remove(vm);
    Assert.assertFalse(g2.equals(g));
    Assert.assertFalse(new Gather(s, false).equals(new Gather(s, true)));
    Assert.assertNotEquals(new Gather(s, false).hashCode(), new Gather(s, true).hashCode());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) 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