Search in sources :

Example 86 with Model

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<>());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Script(org.btrplace.btrpsl.Script) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 87 with Model

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()));
}
Also used : ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Root(org.btrplace.model.constraint.Root) SchedulerException(org.btrplace.scheduler.SchedulerException) MigrateVM(org.btrplace.plan.event.MigrateVM) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) Fence(org.btrplace.model.constraint.Fence) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) SingleRunner(org.btrplace.scheduler.choco.runner.single.SingleRunner) BiConsumer(java.util.function.BiConsumer) ChocoMapper(org.btrplace.scheduler.choco.constraint.ChocoMapper) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) StagedSolvingStatistics(org.btrplace.scheduler.choco.runner.StagedSolvingStatistics) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) Collection(java.util.Collection) TransitionFactory(org.btrplace.scheduler.choco.transition.TransitionFactory) Collectors(java.util.stream.Collectors) MinMTTR(org.btrplace.model.constraint.MinMTTR) InconsistentSolutionException(org.btrplace.scheduler.InconsistentSolutionException) List(java.util.List) Instance(org.btrplace.model.Instance) InstanceSolver(org.btrplace.scheduler.choco.runner.InstanceSolver) Collections(java.util.Collections) Network(org.btrplace.model.view.network.Network) Settings(org.chocosolver.solver.Settings) InconsistentSolutionException(org.btrplace.scheduler.InconsistentSolutionException) Root(org.btrplace.model.constraint.Root) Instance(org.btrplace.model.Instance) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) StagedSolvingStatistics(org.btrplace.scheduler.choco.runner.StagedSolvingStatistics) Network(org.btrplace.model.view.network.Network) Model(org.btrplace.model.Model) Fence(org.btrplace.model.constraint.Fence)

Example 88 with Model

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));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) 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) Node(org.btrplace.model.Node) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) SubstitutedVMEvent(org.btrplace.plan.event.SubstitutedVMEvent) Test(org.testng.annotations.Test)

Example 89 with Model

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));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Mapping(org.btrplace.model.Mapping) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 90 with 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));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) BootNode(org.btrplace.plan.event.BootNode) Node(org.btrplace.model.Node) BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ShutdownNode(org.btrplace.plan.event.ShutdownNode) Mapping(org.btrplace.model.Mapping) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Model (org.btrplace.model.Model)171 DefaultModel (org.btrplace.model.DefaultModel)157 Test (org.testng.annotations.Test)145 Node (org.btrplace.model.Node)91 VM (org.btrplace.model.VM)89 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)46 Mapping (org.btrplace.model.Mapping)41 HashSet (java.util.HashSet)39 ArrayList (java.util.ArrayList)30 SatConstraint (org.btrplace.model.constraint.SatConstraint)29 ShareableResource (org.btrplace.model.view.ShareableResource)27 Instance (org.btrplace.model.Instance)19 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)19 MigrateVM (org.btrplace.plan.event.MigrateVM)18 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)18 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)17 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)17 MinMTTR (org.btrplace.model.constraint.MinMTTR)16 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)16 BootVM (org.btrplace.scheduler.choco.transition.BootVM)16