Search in sources :

Example 6 with DefaultModel

use of org.btrplace.model.DefaultModel 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 7 with DefaultModel

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

the class ScriptBuilderTest method testNumberComputation.

public void testNumberComputation() {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    try {
        Script v = b.build(new File(RC_ROOT + "number.btrp"));
        BtrpNumber x = (BtrpNumber) v.getImportable("$x");
        BtrpNumber y = (BtrpNumber) v.getImportable("$y");
        BtrpNumber z = (BtrpNumber) v.getImportable("$z");
        BtrpNumber a = (BtrpNumber) v.getImportable("$a");
        BtrpNumber c2 = (BtrpNumber) v.getImportable("$c");
        BtrpNumber toto = (BtrpNumber) v.getImportable("$toto");
        BtrpNumber titi = (BtrpNumber) v.getImportable("$titi");
        BtrpNumber foo = (BtrpNumber) v.getImportable("$foo");
        BtrpNumber bar = (BtrpNumber) v.getImportable("$bar");
        BtrpNumber bi = (BtrpNumber) v.getImportable("$bi");
        BtrpNumber f1 = (BtrpNumber) v.getImportable("$f1");
        BtrpNumber f2 = (BtrpNumber) v.getImportable("$f2");
        BtrpNumber f3 = (BtrpNumber) v.getImportable("$f3");
        // System.err.println(v);
        Assert.assertTrue(x.isInteger());
        Assert.assertEquals(x.getIntValue(), 2);
        Assert.assertTrue(y.isInteger());
        Assert.assertEquals(y.getIntValue(), 8);
        Assert.assertTrue(z.isInteger());
        Assert.assertEquals(z.getIntValue(), 26);
        Assert.assertTrue(a.isInteger());
        Assert.assertEquals(a.getIntValue(), 2);
        Assert.assertTrue(c2.isInteger());
        Assert.assertEquals(c2.getIntValue(), 1);
        Assert.assertFalse(f1.isInteger());
        Assert.assertEquals(f1.getDoubleValue(), 0.7);
        Assert.assertFalse(f2.isInteger());
        Assert.assertEquals(f2.getDoubleValue(), 3.0);
        Assert.assertFalse(f3.isInteger());
        Assert.assertEquals(f3.getDoubleValue(), 892, 5);
        BtrpNumber baz = (BtrpNumber) v.getImportable("$baz");
        Assert.assertEquals(baz, BtrpNumber.TRUE);
        BtrpNumber biz = (BtrpNumber) v.getImportable("$biz");
        Assert.assertEquals(biz, BtrpNumber.TRUE);
        Assert.assertEquals(toto, BtrpNumber.FALSE);
        Assert.assertEquals(titi, BtrpNumber.TRUE);
        Assert.assertEquals(foo, BtrpNumber.TRUE);
        Assert.assertEquals(bar, BtrpNumber.TRUE);
        Assert.assertEquals(bi, BtrpNumber.FALSE);
    } catch (ScriptBuilderException x) {
        Assert.fail(x.getMessage(), x);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber) File(java.io.File)

Example 8 with DefaultModel

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

the class ScriptBuilderTest method testVariablesInElementRange.

public void testVariablesInElementRange() throws ScriptBuilderException {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    Script v = b.build(new File(RC_ROOT + "range.btrp"));
    BtrpSet s = (BtrpSet) v.getImportable("$foo");
    System.out.println(s);
    Assert.assertEquals(s.size(), 9);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) BtrpSet(org.btrplace.btrpsl.element.BtrpSet) File(java.io.File)

Example 9 with DefaultModel

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

the class ScriptBuilderTest method testSetManipulationWithErrors.

@Test(expectedExceptions = { ScriptBuilderException.class })
public void testSetManipulationWithErrors() throws ScriptBuilderException {
    try {
        ScriptBuilder b = new ScriptBuilder(new DefaultModel());
        b.build("namespace test.template;\n" + "VM[1..20] : tinyVMs<migratable,volatile>;\n" + "$x = VM[1..10] + VM15;\n" + "$y = VM[1..10] + @N[1..20,57];\n" + "$z = VM[1..10] + 7;\n" + "$a = VM[1..10] - {VM[1..10]};\n" + "$b = VM[1..10] / @N1;\n" + "$c = VM[1..10] / @N[1,3];\n" + "$d = VM[1..10] * VM[21,22];\n" + "$e = VM[22,23] / 2;\n");
    } catch (ScriptBuilderException x) {
        System.out.println(x);
        Assert.assertEquals(x.getErrorReporter().getErrors().size(), 8);
        throw x;
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test) DefaultTemplateFactoryTest(org.btrplace.btrpsl.template.DefaultTemplateFactoryTest)

Example 10 with DefaultModel

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

Aggregations

DefaultModel (org.btrplace.model.DefaultModel)201 Test (org.testng.annotations.Test)177 Model (org.btrplace.model.Model)157 Node (org.btrplace.model.Node)91 VM (org.btrplace.model.VM)91 HashSet (java.util.HashSet)48 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)43 SatConstraint (org.btrplace.model.constraint.SatConstraint)40 Mapping (org.btrplace.model.Mapping)39 ArrayList (java.util.ArrayList)26 ShareableResource (org.btrplace.model.view.ShareableResource)24 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)22 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)18 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)17 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)17 MigrateVM (org.btrplace.plan.event.MigrateVM)16 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)16 BootVM (org.btrplace.scheduler.choco.transition.BootVM)16 ForgeVM (org.btrplace.scheduler.choco.transition.ForgeVM)16 KillVM (org.btrplace.scheduler.choco.transition.KillVM)16