Search in sources :

Example 91 with Model

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

the class MaxOnlineTest method testEquals.

public void testEquals() {
    Model m = new DefaultModel();
    Set<Node> s = new HashSet<>(Arrays.asList(m.newNode(), m.newNode()));
    MaxOnline mo = new MaxOnline(s, 3);
    Assert.assertEquals(mo, new MaxOnline(s, 3));
    Assert.assertNotEquals(mo, new MaxOnline(s, 1));
    Assert.assertNotEquals(mo, new MaxOnline(new HashSet<>(), 3));
    Assert.assertNotEquals(new MaxOnline(s, 3, true), new MaxOnline(s, 3, false));
    Assert.assertEquals(mo, new MaxOnline(s, 3));
    Assert.assertNotEquals(new MaxOnline(s, 3, true).hashCode(), new MaxOnline(s, 3, false).hashCode());
    Assert.assertEquals(new MaxOnline(s, 3, true), new MaxOnline(s, 3, false));
}
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) HashSet(java.util.HashSet)

Example 92 with Model

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

the class NamingServiceTest method testEqualsAndHashCode.

@Test(dependsOnMethods = { "testRegisterAndGets" })
public void testEqualsAndHashCode() {
    NamingService<VM> ns = NamingService.newVMNS();
    Assert.assertEquals(ns, ns);
    Model mo = new DefaultModel();
    VM v = mo.newVM();
    NamingService<VM> ns2 = NamingService.newVMNS();
    Assert.assertEquals(ns, ns2);
    Assert.assertEquals(ns.hashCode(), ns2.hashCode());
    ns2.register(v, "vm0");
    Assert.assertNotEquals(ns, ns2);
}
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)

Example 93 with Model

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

the class NetworkTest method defaultTest.

/**
 * Test the instantiation and the creation of the objects using the default routing implementation.
 */
@Test
public void defaultTest() {
    Model mo = new DefaultModel();
    Network net = new Network();
    Switch s = net.newSwitch(1000);
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    net.connect(2000, s, n1, n2);
    Assert.assertNull(Network.get(mo));
    mo.attach(net);
    Assert.assertEquals(Network.get(mo), net);
    Assert.assertTrue(net.getSwitches().size() == 1);
    Assert.assertEquals(net.getSwitches().get(0), s);
    Assert.assertTrue(s.getCapacity() == 1000);
    Assert.assertTrue(net.getLinks().size() == 2);
    Assert.assertTrue(net.getLinks().size() == 2);
    for (Link l : net.getLinks()) {
        Assert.assertTrue(l.getCapacity() == 2000);
        Assert.assertTrue(l.getSwitch().equals(s) || l.getElement() instanceof Switch);
    }
    Assert.assertTrue(net.getRouting().getPath(n1, n2).size() == 2);
    Assert.assertTrue(net.getRouting().getPath(n1, n2).containsAll(net.getLinks()));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Switch(org.btrplace.model.view.network.Switch) Network(org.btrplace.model.view.network.Network) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Link(org.btrplace.model.view.network.Link) Test(org.testng.annotations.Test)

Example 94 with Model

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

the class NetworkTest method staticRoutingTest.

/**
 * Test the static routing implementation.
 */
@Test
public void staticRoutingTest() {
    Model mo = new DefaultModel();
    Network net = new Network(new StaticRouting());
    Switch s = net.newSwitch(1000);
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    net.connect(2000, s, n1, n2);
    Map<Link, Boolean> route = new LinkedHashMap<>();
    route.put(net.getConnectedLinks(n1).get(0), true);
    route.put(net.getConnectedLinks(n2).get(0), false);
    ((StaticRouting) net.getRouting()).setStaticRoute(new StaticRouting.NodesMap(n1, n2), route);
    mo.attach(net);
    Assert.assertTrue(net.getRouting().getPath(n1, n2).size() == 2);
    Assert.assertTrue(net.getRouting().getPath(n1, n2).containsAll(net.getLinks()));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Switch(org.btrplace.model.view.network.Switch) StaticRouting(org.btrplace.model.view.network.StaticRouting) Network(org.btrplace.model.view.network.Network) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Link(org.btrplace.model.view.network.Link) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 95 with Model

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

the class ReconfigurationPlanChecker method check.

/**
 * Check if a plan satisfies all the {@link SatConstraintChecker}.
 *
 * @param p the plan to check
 * @throws SatConstraintViolationException if a violation is detected
 */
public void check(ReconfigurationPlan p) throws SatConstraintViolationException {
    if (checkers.isEmpty()) {
        return;
    }
    checkModel(p.getOrigin(), true);
    if (!p.getActions().isEmpty()) {
        PriorityQueue<Action> starts = new PriorityQueue<>(p.getActions().size(), STARTS_CMP);
        PriorityQueue<Action> ends = new PriorityQueue<>(p.getActions().size(), ENDS_CMP);
        starts.addAll(p.getActions());
        ends.addAll(p.getActions());
        // Starts the actions
        int curMoment = starts.peek().getStart();
        while (!starts.isEmpty() || !ends.isEmpty()) {
            Action a = ends.peek();
            while (a != null && a.getEnd() == curMoment) {
                ends.remove();
                startingEvent = false;
                visitAndThrowOnViolation(a);
                visitEvents(a, Action.Hook.POST);
                a = ends.peek();
            }
            a = starts.peek();
            while (a != null && a.getStart() == curMoment) {
                starts.remove();
                startingEvent = true;
                visitEvents(a, Action.Hook.PRE);
                visitAndThrowOnViolation(a);
                a = starts.peek();
            }
            int nextEnd = Integer.MAX_VALUE;
            if (!ends.isEmpty()) {
                nextEnd = ends.peek().getEnd();
            }
            int nextStart = Integer.MAX_VALUE;
            if (!starts.isEmpty()) {
                nextStart = starts.peek().getStart();
            }
            curMoment = Math.min(nextEnd, nextStart);
        }
    }
    Model mo = p.getResult();
    if (mo == null) {
        throw new InconsistentSolutionException(p.getOrigin(), p, "The resulting reconfiguration plan is not applyable");
    }
    checkModel(mo, false);
}
Also used : Action(org.btrplace.plan.event.Action) InconsistentSolutionException(org.btrplace.scheduler.InconsistentSolutionException) Model(org.btrplace.model.Model) PriorityQueue(java.util.PriorityQueue) SatConstraint(org.btrplace.model.constraint.SatConstraint)

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