Search in sources :

Example 11 with Node

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

the class Network method createDefaultNetwork.

/**
 * Create and attach a default network view to the given model.
 * Basically, the Network consists of a main non-blocking switch connected
 * to all the existing nodes in the model using links with the given
 * bandwidth in Mbit/sec.
 *
 * Note: replace the previous Network view attached to the model (if exists).
 *
 * @param mo    the model to add/replace the Network view
 * @param bw    the links bandwidth
 * @return the new 'default' network view, already attached to the given model
 */
public static Network createDefaultNetwork(Model mo, int bw) {
    Network net = new Network();
    // Main non-blocking switch
    Switch mainSwitch = net.newSwitch();
    for (Node n : mo.getMapping().getAllNodes()) {
        // Connect all nodes with 1Gbit/s links
        net.connect(bw, mainSwitch, n);
    }
    // Remove the current Network view if exists
    if (get(mo) != null) {
        mo.detach(get(mo));
    }
    mo.attach(net);
    return net;
}
Also used : Node(org.btrplace.model.Node)

Example 12 with Node

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

the class MaxOnlineChecker method startsWith.

@Override
public boolean startsWith(Model mo) {
    if (getConstraint().isContinuous()) {
        Mapping map = mo.getMapping();
        currentOnline = 0;
        for (Node n : getConstraint().getInvolvedNodes()) {
            if (map.isOnline(n)) {
                currentOnline++;
            }
        }
        return currentOnline <= getConstraint().getAmount();
    }
    return true;
}
Also used : Node(org.btrplace.model.Node) ShutdownNode(org.btrplace.plan.event.ShutdownNode) BootNode(org.btrplace.plan.event.BootNode) Mapping(org.btrplace.model.Mapping)

Example 13 with Node

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

the class AmongTest method testEqualsHashCode.

@Test(dependsOnMethods = { "testInstantiation" })
public void testEqualsHashCode() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 10);
    List<VM> vms = Util.newVMs(mo, 10);
    Collection<Node> s1 = Arrays.asList(ns.get(0), ns.get(1));
    Collection<Node> s2 = Collections.singletonList(ns.get(2));
    Collection<Collection<Node>> pGrps = Arrays.asList(s1, s2);
    Set<VM> vg = new HashSet<>(Arrays.asList(vms.get(0), vms.get(1), vms.get(2)));
    Among a = new Among(vg, pGrps);
    Assert.assertTrue(a.equals(a));
    Assert.assertTrue(a.equals(new Among(new HashSet<>(vg), pGrps)));
    Assert.assertEquals(a.hashCode(), new Among(new HashSet<>(vg), pGrps).hashCode());
    Assert.assertFalse(a.equals(new Among(new HashSet<>(), pGrps)));
    Assert.assertFalse(a.equals(new Among(new HashSet<>(vg), Collections.emptyList())));
    Among a2 = new Among(new HashSet<>(vg), Collections.emptyList());
    a2.setContinuous(true);
    Assert.assertFalse(a.equals(a2));
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Collection(java.util.Collection) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 14 with Node

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

the class AmongTest method testContinuousIsSatisfied.

@Test(dependsOnMethods = { "testInstantiation" })
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 10);
    List<VM> vms = Util.newVMs(mo, 10);
    Collection<Node> s1 = new HashSet<>(Arrays.asList(ns.get(0), ns.get(1)));
    Collection<Node> s2 = new HashSet<>(Collections.singletonList(ns.get(2)));
    Collection<Collection<Node>> pGrps = Arrays.asList(s1, s2);
    Set<VM> vs = new HashSet<>(Arrays.asList(vms.get(0), vms.get(1), vms.get(2)));
    Among a = new Among(vs, pGrps, true);
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addOnlineNode(ns.get(2));
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addRunningVM(vms.get(1), ns.get(1));
    map.addRunningVM(vms.get(2), ns.get(1));
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    Assert.assertEquals(a.isSatisfied(plan), true);
    plan.add(new MigrateVM(vms.get(2), ns.get(1), ns.get(2), 0, 1));
    plan.add(new MigrateVM(vms.get(2), ns.get(2), ns.get(1), 1, 2));
    // At moment 1, the constraint will be violated
    Assert.assertEquals(a.isSatisfied(plan), false);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) MigrateVM(org.btrplace.plan.event.MigrateVM) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Collection(java.util.Collection) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 15 with Node

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

the class AmongTest method testInstantiation.

@Test
public void testInstantiation() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 10);
    List<VM> vms = Util.newVMs(mo, 10);
    Collection<Node> s1 = Arrays.asList(ns.get(0), ns.get(1));
    Collection<Node> s2 = Collections.singletonList(ns.get(2));
    Collection<Collection<Node>> pGrps = Arrays.asList(s1, s2);
    Set<VM> vg = new HashSet<>(Arrays.asList(vms.get(0), vms.get(1), vms.get(2)));
    Among a = new Among(vg, pGrps);
    Assert.assertNotNull(a.getChecker());
    Assert.assertEquals(a.getInvolvedVMs(), vg);
    Assert.assertEquals(a.getGroupsOfNodes(), pGrps);
    Assert.assertEquals(a.getInvolvedNodes().size(), s1.size() + s2.size());
    Assert.assertTrue(a.getInvolvedNodes().containsAll(s1));
    Assert.assertTrue(a.getInvolvedNodes().containsAll(s2));
    Assert.assertFalse(a.toString().contains("null"));
    Assert.assertFalse(a.isContinuous());
    Assert.assertTrue(a.setContinuous(true));
    Assert.assertTrue(a.setContinuous(false));
    a = new Among(vg, pGrps, true);
    Assert.assertTrue(a.isContinuous());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Collection(java.util.Collection) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Node (org.btrplace.model.Node)382 DefaultModel (org.btrplace.model.DefaultModel)278 Model (org.btrplace.model.Model)276 VM (org.btrplace.model.VM)262 Test (org.testng.annotations.Test)259 Mapping (org.btrplace.model.Mapping)187 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)142 HashSet (java.util.HashSet)95 SatConstraint (org.btrplace.model.constraint.SatConstraint)87 ArrayList (java.util.ArrayList)86 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)82 MigrateVM (org.btrplace.plan.event.MigrateVM)72 ShareableResource (org.btrplace.model.view.ShareableResource)71 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)64 ShutdownNode (org.btrplace.plan.event.ShutdownNode)52 Instance (org.btrplace.model.Instance)43 BootNode (org.btrplace.plan.event.BootNode)41 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)40 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)36 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)36