Search in sources :

Example 61 with Mapping

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

the class DefaultReconfigurationProblemTest method testNodeOff.

@Test
public void testNodeOff() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    VM vm6 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    Mapping map = mo.getMapping();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    map.addOfflineNode(n3);
    map.addRunningVM(vm1, n1);
    map.addRunningVM(vm2, n1);
    map.addRunningVM(vm3, n2);
    map.addSleepingVM(vm4, n2);
    map.addReadyVM(vm5);
    map.addReadyVM(vm6);
    Mapping m = mo.getMapping();
    m.addOfflineNode(n1);
    DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), new HashSet<>(), new HashSet<>(), new HashSet<>()).build();
    NodeTransition a = rp.getNodeActions().get(rp.getNode(n3));
    Assert.assertEquals(a, rp.getNodeAction(n3));
    Assert.assertEquals(BootableNode.class, a.getClass());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SuspendVM(org.btrplace.scheduler.choco.transition.SuspendVM) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) ResumeVM(org.btrplace.scheduler.choco.transition.ResumeVM) KillVM(org.btrplace.scheduler.choco.transition.KillVM) BootVM(org.btrplace.scheduler.choco.transition.BootVM) ForgeVM(org.btrplace.scheduler.choco.transition.ForgeVM) ShutdownVM(org.btrplace.scheduler.choco.transition.ShutdownVM) ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) Node(org.btrplace.model.Node) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) NodeTransition(org.btrplace.scheduler.choco.transition.NodeTransition) Mapping(org.btrplace.model.Mapping) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 62 with Mapping

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

the class DefaultReconfigurationProblemTest method testVMRunningToSleeping.

@Test
public void testVMRunningToSleeping() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    VM vm6 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    Mapping map = mo.getMapping();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    map.addOfflineNode(n3);
    map.addRunningVM(vm1, n1);
    map.addRunningVM(vm2, n1);
    map.addRunningVM(vm3, n2);
    map.addSleepingVM(vm4, n2);
    map.addReadyVM(vm5);
    map.addReadyVM(vm6);
    Mapping m = mo.getMapping();
    m.addOnlineNode(n1);
    m.addRunningVM(vm1, n1);
    DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), new HashSet<>(), Collections.singleton(vm1), new HashSet<>()).build();
    VMTransition a = rp.getVMActions().get(0);
    Assert.assertEquals(a, rp.getVMAction(vm1));
    Assert.assertEquals(SuspendVM.class, a.getClass());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SuspendVM(org.btrplace.scheduler.choco.transition.SuspendVM) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) ResumeVM(org.btrplace.scheduler.choco.transition.ResumeVM) KillVM(org.btrplace.scheduler.choco.transition.KillVM) BootVM(org.btrplace.scheduler.choco.transition.BootVM) ForgeVM(org.btrplace.scheduler.choco.transition.ForgeVM) ShutdownVM(org.btrplace.scheduler.choco.transition.ShutdownVM) ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) Node(org.btrplace.model.Node) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 63 with Mapping

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

the class DefaultReconfigurationProblemTest method testVMSleepToRun.

@Test
public void testVMSleepToRun() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    VM vm3 = mo.newVM();
    VM vm4 = mo.newVM();
    VM vm5 = mo.newVM();
    VM vm6 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Node n3 = mo.newNode();
    Mapping map = mo.getMapping();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    map.addOfflineNode(n3);
    map.addRunningVM(vm1, n1);
    map.addRunningVM(vm2, n1);
    map.addRunningVM(vm3, n2);
    map.addSleepingVM(vm4, n2);
    map.addReadyVM(vm5);
    map.addReadyVM(vm6);
    Mapping m = mo.getMapping();
    m.addOnlineNode(n1);
    m.addSleepingVM(vm1, n1);
    DefaultReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(new HashSet<>(), Collections.singleton(vm1), new HashSet<>(), new HashSet<>()).build();
    VMTransition a = rp.getVMActions().get(0);
    Assert.assertEquals(a, rp.getVMAction(vm1));
    Assert.assertEquals(ResumeVM.class, a.getClass());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) SuspendVM(org.btrplace.scheduler.choco.transition.SuspendVM) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) ResumeVM(org.btrplace.scheduler.choco.transition.ResumeVM) KillVM(org.btrplace.scheduler.choco.transition.KillVM) BootVM(org.btrplace.scheduler.choco.transition.BootVM) ForgeVM(org.btrplace.scheduler.choco.transition.ForgeVM) ShutdownVM(org.btrplace.scheduler.choco.transition.ShutdownVM) ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) Node(org.btrplace.model.Node) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 64 with Mapping

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

the class IssuesTest method testIssue5b.

/**
 * Test a suspicious bug in issue #5
 */
@Test
public void testIssue5b() throws SchedulerException {
    Model model = new DefaultModel();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    Node n3 = model.newNode();
    VM vm1 = model.newVM();
    VM vm2 = model.newVM();
    VM vm3 = model.newVM();
    VM vm4 = model.newVM();
    Mapping map = model.getMapping().on(n1, n2, n3).run(n2, vm1, vm2, vm3, vm4);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(model).build();
    List<IntVar> nodes_state = rp.getNbRunningVMs();
    IntVar[] nodeVM = new IntVar[map.getAllNodes().size()];
    int i = 0;
    for (Node n : map.getAllNodes()) {
        nodeVM[i++] = nodes_state.get(rp.getNode(n));
    }
    IntVar idle = rp.getModel().intVar("Nidles", 0, map.getAllNodes().size(), true);
    rp.getModel().post(rp.getModel().count(0, nodeVM, idle));
    // Amount of maxSpareNode =  1
    rp.getModel().post(rp.getModel().arithm(idle, "<=", 1));
    ReconfigurationPlan plan = rp.solve(0, false);
    Assert.assertNotNull(plan);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) OptConstraint(org.btrplace.model.constraint.OptConstraint) Constraint(org.chocosolver.solver.constraints.Constraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) Test(org.testng.annotations.Test)

Example 65 with Mapping

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

the class IssuesTest method testIssue5a.

/**
 * Another test related to issue #5.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testIssue5a() throws SchedulerException, ContradictionException {
    Model model = new DefaultModel();
    Node n1 = model.newNode();
    Node n2 = model.newNode();
    Node n3 = model.newNode();
    VM vm1 = model.newVM();
    VM vm2 = model.newVM();
    ShareableResource resources = new ShareableResource("vcpu", 1, 1);
    resources.setCapacity(n1, 2);
    resources.setCapacity(n2, 2);
    Mapping map = model.getMapping().on(n1, n2).off(n3).run(n1, vm1, vm2);
    model.attach(resources);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(model).build();
    List<IntVar> VMsOnAllNodes = rp.getNbRunningVMs();
    int NUMBER_OF_NODE = map.getAllNodes().size();
    // Each element is the number of VMs on each node
    IntVar[] vmsOnInvolvedNodes = new IntVar[NUMBER_OF_NODE];
    BoolVar[] busy = new BoolVar[NUMBER_OF_NODE];
    rp.getEnd().updateUpperBound(10, Cause.Null);
    int i = 0;
    int maxVMs = rp.getSourceModel().getMapping().getAllVMs().size();
    for (Node n : map.getAllNodes()) {
        vmsOnInvolvedNodes[i] = rp.getModel().intVar("nVMs", -1, maxVMs, true);
        IntVar state = rp.getNodeAction(n).getState();
        // If the node is offline -> the temporary variable is -1, otherwise, it equals the number of VMs on that node
        Constraint elem = rp.getModel().element(vmsOnInvolvedNodes[i], new IntVar[] { rp.getModel().intVar(-1), VMsOnAllNodes.get(rp.getNode(n)) }, state, 0);
        rp.getModel().post(elem);
        // IF the node is online and hosting VMs -> busy = 1.
        busy[i] = rp.getModel().boolVar("busy" + n);
        ChocoUtils.postIfOnlyIf(rp, busy[i], rp.getModel().arithm(vmsOnInvolvedNodes[i], ">=", 1));
        i++;
    }
    // idle is equals the number of vmsOnInvolvedNodes with value 0. (The node without VM)
    IntVar idle = rp.getModel().intVar("Nidles", 0, NUMBER_OF_NODE, true);
    rp.getModel().post(rp.getModel().count(0, vmsOnInvolvedNodes, idle));
    // idle should be less than Amount for MaxSN (0, in this case)
    rp.getModel().post(rp.getModel().arithm(idle, "<=", 0));
    // Extract all the state of the involved nodes (all nodes in this case)
    IntVar[] states = new IntVar[NUMBER_OF_NODE];
    int j = 0;
    for (Node n : map.getAllNodes()) {
        states[j++] = rp.getNodeAction(n).getState();
    }
    // In case the number of VMs is inferior to the number of online nodes, some nodes have to shutdown
    // to satisfy the constraint. This could be express as:
    // The addition of the idle nodes and busy nodes should be equals the number of online nodes.
    IntVar sumStates = rp.getModel().intVar("sumStates", 0, 1000, true);
    rp.getModel().post(rp.getModel().sum(states, "=", sumStates));
    IntVar sumBusy = rp.getModel().intVar("sumBusy", 0, 1000, true);
    rp.getModel().post(rp.getModel().sum(states, "=", sumBusy));
    IntVar sumIB = rp.getModel().intVar("ib", 0, 1000, true);
    @SuppressWarnings("unused") Task task = new Task(sumBusy, idle, sumIB);
    // solver.eq(sumStates, sumIB));
    rp.getModel().post(rp.getModel().arithm(sumStates, "=", sumIB));
    ReconfigurationPlan plan = rp.solve(0, false);
    Assert.assertNotNull(plan);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Task(org.chocosolver.solver.variables.Task) OptConstraint(org.btrplace.model.constraint.OptConstraint) Constraint(org.chocosolver.solver.constraints.Constraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource) IntVar(org.chocosolver.solver.variables.IntVar) OptConstraint(org.btrplace.model.constraint.OptConstraint) Constraint(org.chocosolver.solver.constraints.Constraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) BoolVar(org.chocosolver.solver.variables.BoolVar) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Aggregations

Mapping (org.btrplace.model.Mapping)83 Node (org.btrplace.model.Node)68 VM (org.btrplace.model.VM)62 Model (org.btrplace.model.Model)42 DefaultModel (org.btrplace.model.DefaultModel)39 Test (org.testng.annotations.Test)39 HashSet (java.util.HashSet)29 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)23 ShareableResource (org.btrplace.model.view.ShareableResource)16 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)16 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)15 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)15 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)15 IntVar (org.chocosolver.solver.variables.IntVar)15 SatConstraint (org.btrplace.model.constraint.SatConstraint)14 BootVM (org.btrplace.scheduler.choco.transition.BootVM)14 ForgeVM (org.btrplace.scheduler.choco.transition.ForgeVM)14 KillVM (org.btrplace.scheduler.choco.transition.KillVM)14 ResumeVM (org.btrplace.scheduler.choco.transition.ResumeVM)14 ShutdownVM (org.btrplace.scheduler.choco.transition.ShutdownVM)14