Search in sources :

Example 1 with VM

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

the class PreserveBuilder method buildConstraint.

@Override
public List<? extends SatConstraint> buildConstraint(BtrPlaceTree t, List<BtrpOperand> args) {
    if (!checkConformance(t, args)) {
        return Collections.emptyList();
    }
    @SuppressWarnings("unchecked") List<VM> s = (List<VM>) params[0].transform(this, t, args.get(0));
    String rcId = (String) params[1].transform(this, t, args.get(1));
    BtrpNumber n = (BtrpNumber) args.get(2);
    if (!n.isInteger()) {
        t.ignoreError("Parameter '" + params[2].getName() + "' expects an integer");
        return Collections.emptyList();
    }
    int v = n.getIntValue();
    if (v < 0) {
        t.ignoreError("Parameter '" + params[2].getName() + "' expects a positive integer (" + v + " given)");
        return Collections.emptyList();
    }
    return s != null && rcId != null ? Preserve.newPreserve(s, rcId, v) : Collections.emptyList();
}
Also used : BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber) VM(org.btrplace.model.VM) List(java.util.List) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Example 2 with VM

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

the class ScriptBuilderTest method testTemplateWithOptions.

@Test
public void testTemplateWithOptions() throws ScriptBuilderException {
    Model mo = new DefaultModel();
    ScriptBuilder b = new ScriptBuilder(mo);
    Script v = b.build("namespace test.template;\nVM[1..3] : tinyVMs<migratable,start=\"7.5\",stop=12>;");
    Assert.assertEquals(v.getVMs().size(), 3);
    for (VM el : v.getVMs()) {
        // 3 + 1 (the template)
        Assert.assertEquals(mo.getAttributes().getKeys(el).size(), 4);
        Assert.assertEquals(mo.getAttributes().get(el, "migratable", false), true);
        Assert.assertEquals(mo.getAttributes().get(el, "start", -1.5), 7.5);
        Assert.assertEquals(mo.getAttributes().get(el, "stop", -1), 12);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test) DefaultTemplateFactoryTest(org.btrplace.btrpsl.template.DefaultTemplateFactoryTest)

Example 3 with VM

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

the class ScriptBuilderTest method testTemplateReassignment.

@Test(expectedExceptions = { ScriptBuilderException.class })
public void testTemplateReassignment() throws ScriptBuilderException {
    Model mo = new DefaultModel();
    VM v = mo.newVM();
    VM v2 = mo.newVM();
    mo.getMapping().addReadyVM(v);
    mo.getMapping().addReadyVM(v2);
    mo.getAttributes().put(v, "template", "t1");
    mo.getAttributes().put(v2, "template", "tiny");
    NamingService<Node> nsNodes = NamingService.newNodeNS();
    NamingService<VM> nsVMs = NamingService.newVMNS();
    mo.attach(nsNodes);
    mo.attach(nsVMs);
    nsVMs.register(v, "foo.VM1");
    nsVMs.register(v2, "foo.VM2");
    ScriptBuilder b = new ScriptBuilder(100, mo);
    b.setTemplateFactory(new DefaultTemplateFactory(nsNodes, nsVMs, mo));
    b.getTemplateFactory().register(new DefaultTemplateFactoryTest.MockVMTemplate("tiny"));
    b.getTemplateFactory().register(new DefaultTemplateFactoryTest.MockVMTemplate("t1"));
    ErrorReporter r;
    try {
        Script scr = b.build("namespace foo; VM[1,2] : tiny;");
        System.out.println(scr.getVMs());
    } catch (ScriptBuilderException ex) {
        System.out.println(ex);
        r = ex.getErrorReporter();
        Assert.assertEquals(r.getErrors().size(), 1);
        throw ex;
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultTemplateFactoryTest(org.btrplace.btrpsl.template.DefaultTemplateFactoryTest) Node(org.btrplace.model.Node) DefaultTemplateFactory(org.btrplace.btrpsl.template.DefaultTemplateFactory) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test) DefaultTemplateFactoryTest(org.btrplace.btrpsl.template.DefaultTemplateFactoryTest)

Example 4 with VM

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

the class ScriptBuilderTest method testResolution.

@Test
public void testResolution() throws Exception {
    Model mo = new DefaultModel();
    ScriptBuilder b = new ScriptBuilder(mo);
    NamingService<Node> nsNodes = b.getNamingServiceNodes();
    NamingService<VM> nsVMs = b.getNamingServiceVMs();
    for (int i = 1; i < 10; i++) {
        if (i <= 5) {
            Node n = mo.newNode();
            mo.getMapping().addOnlineNode(n);
            nsNodes.register(n, "@N" + i);
        }
        VM v = mo.newVM();
        nsVMs.register(v, "ns.VM" + i);
        mo.getMapping().addReadyVM(v);
    }
    // TemplateFactory tpf = new DefaultTemplateFactory(b.getNamingService(), true);
    // b.setTemplateFactory(tpf);
    Script scr = b.build("namespace ns;\n" + "VM[1..10] : tiny;\n" + "@N[1..5]: default;\n" + "$vms = VM[1..10];\n" + "running($vms);\n" + ">>split($vms / 2);\n");
    Assert.assertEquals(mo.getMapping().getNbNodes(), 5);
    Assert.assertEquals(mo.getMapping().getNbVMs(), 10);
    ChocoScheduler ra = new DefaultChocoScheduler();
    ReconfigurationPlan p = ra.solve(mo, scr.getConstraints());
    Assert.assertNotNull(p);
    Assert.assertEquals(p.getSize(), 10);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) SatConstraint(org.btrplace.model.constraint.SatConstraint) Test(org.testng.annotations.Test) DefaultTemplateFactoryTest(org.btrplace.btrpsl.template.DefaultTemplateFactoryTest)

Example 5 with VM

use of org.btrplace.model.VM 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)

Aggregations

VM (org.btrplace.model.VM)192 Node (org.btrplace.model.Node)110 Model (org.btrplace.model.Model)92 DefaultModel (org.btrplace.model.DefaultModel)91 Test (org.testng.annotations.Test)91 Mapping (org.btrplace.model.Mapping)64 HashSet (java.util.HashSet)58 ArrayList (java.util.ArrayList)43 SatConstraint (org.btrplace.model.constraint.SatConstraint)40 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)39 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)35 IntVar (org.chocosolver.solver.variables.IntVar)35 ShareableResource (org.btrplace.model.view.ShareableResource)32 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)27 MigrateVM (org.btrplace.plan.event.MigrateVM)25 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)17 StayAwayVM (org.btrplace.scheduler.choco.transition.StayAwayVM)17 Slice (org.btrplace.scheduler.choco.Slice)16 BootVM (org.btrplace.scheduler.choco.transition.BootVM)16 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)16