use of org.btrplace.model.Model in project scheduler by btrplace.
the class DefaultTemplateFactoryTest method testTypingIssue.
/*@Test(dependsOnMethods = {"testInstantiation", "testRegister"})
public void testAccessibleWithStrict() throws ElementBuilderException {
Model mo = new DefaultModel();
DefaultTemplateFactory tplf = new DefaultTemplateFactory(new InMemoryNamingService(mo));
tplf.register(new MockVMTemplate("mock1"));
Script scr = new Script();
tplf.check(scr, "mock1", null, new HashMap<String, String>());
Assert.assertEquals(mo.getAttributes().get(el.getElement(), "template"), "mock1");
} */
/*@Test(dependsOnMethods = {"testInstantiation", "testRegister"}, expectedExceptions = {ElementBuilderException.class})
public void testInaccessibleWithStrict() throws ElementBuilderException {
DefaultTemplateFactory tplf = new DefaultTemplateFactory(new InMemoryNamingService(), new DefaultModel());
Script scr = new Script();
tplf.check(scr, "bar", , "foo", new HashMap<String, String>());
} */
/*@Test(dependsOnMethods = {"testInstantiation", "testRegister"})
public void testAccessibleWithoutStrict() throws ElementBuilderException {
Model mo = new DefaultModel();
DefaultTemplateFactory tplf = new DefaultTemplateFactory(new InMemoryNamingService(), mo);
tplf.register(new MockVMTemplate("mock1"));
Script scr = new Script();
tplf.check(scr, "mock1", null, new HashMap<String, String>());
Assert.assertEquals(mo.getAttributes().get(el.getElement(), "template"), "mock1");
} */
/*@Test(dependsOnMethods = {"testInstantiation", "testRegister"})
public void testInaccessibleWithoutStrict() throws ElementBuilderException {
Model mo = new DefaultModel();
DefaultTemplateFactory tplf = new DefaultTemplateFactory(new InMemoryNamingService(), mo);
Map<String, String> m = new HashMap<>();
m.put("migratable", null);
m.put("foo", "7.5");
m.put("bar", "1243");
m.put("template", "bar");
Script scr = new Script();
tplf.check(scr, "bar", null, m);
Assert.assertEquals(mo.getAttributes().get(el.getElement(), "template"), "bar");
Assert.assertEquals(el.getName(), "foo");
Assert.assertTrue(mo.getAttributes().getBoolean(el.getElement(), "migratable"));
Assert.assertEquals(mo.getAttributes().getInteger(el.getElement(), "bar").longValue(), 1243);
Assert.assertEquals(mo.getAttributes().getDouble(el.getElement(), "foo"), 7.5);
Assert.assertEquals(mo.getAttributes().getKeys(el.getElement()), m.keySet());
} */
@Test(expectedExceptions = { ElementBuilderException.class })
public void testTypingIssue() throws ElementBuilderException {
Model mo = new DefaultModel();
DefaultTemplateFactory tplf = new DefaultTemplateFactory(NamingService.newNodeNS(), NamingService.newVMNS(), mo);
tplf.register(new MockVMTemplate("mock1"));
Script scr = new Script();
tplf.check(scr, "mock1", mo.newNode(), new HashMap<>());
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class DefaultChocoScheduler method solve.
@Override
public ReconfigurationPlan solve(Instance i) throws SchedulerException {
Model mo = i.getModel();
Collection<SatConstraint> cstrs = i.getSatConstraints();
// If a network view is attached, ensure that all the migrations' destination node are defined
Network net = Network.get(mo);
stages = null;
if (net != null) {
// The network view is useless to take placement decisions
mo.detach(net);
// Solve a first time using placement oriented MinMTTR optimisation constraint
ReconfigurationPlan p = runner.solve(params, i);
stages = new StagedSolvingStatistics(runner.getStatistics());
if (p == null) {
return null;
}
// Add Fence constraints for each destination node chosen
List<SatConstraint> newCstrs = p.getActions().stream().filter(a -> a instanceof MigrateVM).map(a -> new Fence(((MigrateVM) a).getVM(), Collections.singleton(((MigrateVM) a).getDestinationNode()))).collect(Collectors.toList());
Model result = p.getResult();
if (result == null) {
throw new InconsistentSolutionException(mo, p, "The plan cannot be applied");
}
// Add Root constraints to all staying VMs
newCstrs.addAll(mo.getMapping().getRunningVMs().stream().filter(v -> p.getOrigin().getMapping().getVMLocation(v).id() == result.getMapping().getVMLocation(v).id()).map(Root::new).collect(Collectors.toList()));
// Add the old constraints
newCstrs.addAll(cstrs);
// Re-attach the network view
mo.attach(net);
// New timeout value = elapsed time - initial timeout value
Parameters ps = new DefaultParameters(params);
if (ps.getTimeLimit() > 0) {
// in seconds
double timeout = params.getTimeLimit() - runner.getStatistics().getMetrics().timeCount() / 1000;
ps.setTimeLimit((int) timeout);
}
return runner.solve(ps, new Instance(mo, newCstrs, i.getOptConstraint()));
}
// Solve and return the computed plan
return runner.solve(params, new Instance(mo, cstrs, i.getOptConstraint()));
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class AllowAllConstraintCheckerTest method testMyVMsTracking.
@Test(dependsOnMethods = "testInstantiation")
public void testMyVMsTracking() {
SatConstraint cstr = mock(SatConstraint.class);
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);
AllowAllConstraintChecker<SatConstraint> c = new AllowAllConstraintChecker<>(cstr);
// VM1 (one of the involved vms) has to be removed to be substituted by vms.get(0)0
c.consume(new SubstitutedVMEvent(vms.get(0), vms.get(9)));
Assert.assertTrue(c.getVMs().contains(vms.get(9)));
Assert.assertFalse(c.getVMs().contains(vms.get(0)));
// VM5 is not involved, no removal
VM v = mo.newVM();
c.consume(new SubstitutedVMEvent(vms.get(0), v));
Assert.assertFalse(c.getVMs().contains(vms.get(0)));
Assert.assertFalse(c.getVMs().contains(v));
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class MaxOnlineTest method isSatisfiedModel.
@Test
public void isSatisfiedModel() {
Model model = new DefaultModel();
Mapping map = model.getMapping();
Node n1 = model.newNode();
Node n2 = model.newNode();
Node n3 = model.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addOfflineNode(n3);
Set<Node> s = new HashSet<>(Arrays.asList(n1, n2, n3));
MaxOnline mo = new MaxOnline(s, 2);
Assert.assertTrue(mo.isSatisfied(model));
model.getMapping().addOnlineNode(n3);
Assert.assertFalse(mo.isSatisfied(model));
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class MaxOnlineTest method isSatisfiedReconfigurationPlan.
@Test
public void isSatisfiedReconfigurationPlan() {
Model model = new DefaultModel();
Mapping map = model.getMapping();
Node n1 = model.newNode();
Node n2 = model.newNode();
Node n3 = model.newNode();
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addOfflineNode(n3);
Set<Node> s = new HashSet<>(Arrays.asList(n1, n2, n3));
MaxOnline mo = new MaxOnline(s, 2);
ReconfigurationPlan plan = new DefaultReconfigurationPlan(model);
Assert.assertTrue(mo.isSatisfied(plan));
plan.add(new BootNode(n3, 3, 9));
Assert.assertFalse(mo.isSatisfied(plan));
plan.add(new ShutdownNode(n2, 0, 5));
Assert.assertTrue(mo.isSatisfied(plan));
}
Aggregations