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();
}
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);
}
}
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;
}
}
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);
}
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));
}
Aggregations