Search in sources :

Example 11 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class DefaultReconfigurationProblemTest method testVMStaySleeping.

@Test
public void testVMStaySleeping() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    Node n1 = mo.newNode();
    mo.getMapping().addOnlineNode(n1);
    mo.getMapping().addSleepingVM(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(StayAwayVM.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) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 12 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class DefaultReconfigurationProblem method makeVMTransitions.

private void makeVMTransitions() {
    Mapping map = model.getMapping();
    vmActions = new ArrayList<>(vms.size());
    for (VM vmId : vms) {
        VMState curState = map.getState(vmId);
        if (curState == null) {
            curState = VMState.INIT;
        }
        VMState nextState;
        if (running.contains(vmId)) {
            nextState = VMState.RUNNING;
        } else if (sleeping.contains(vmId)) {
            nextState = VMState.SLEEPING;
        } else if (ready.contains(vmId)) {
            nextState = VMState.READY;
        } else if (killed.contains(vmId)) {
            nextState = VMState.KILLED;
        } else {
            // by default, maintain state
            nextState = curState;
            switch(nextState) {
                case READY:
                    ready.add(vmId);
                    break;
                case RUNNING:
                    running.add(vmId);
                    break;
                case SLEEPING:
                    sleeping.add(vmId);
                    break;
                default:
                    throw new LifeCycleViolationException(model, vmId, curState, nextState);
            }
        }
        VMTransitionBuilder am = amFactory.getBuilder(curState, nextState);
        if (am == null) {
            throw new LifeCycleViolationException(model, vmId, curState, nextState);
        }
        VMTransition t = am.build(this, vmId);
        vmActions.add(t);
        if (t.isManaged()) {
            manageable.add(vmId);
        }
    }
}
Also used : VM(org.btrplace.model.VM) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) VMTransitionBuilder(org.btrplace.scheduler.choco.transition.VMTransitionBuilder) VMState(org.btrplace.model.VMState)

Example 13 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class DefaultReconfigurationProblem method addContinuousResourceCapacities.

private void addContinuousResourceCapacities() {
    TIntArrayList cUse = new TIntArrayList();
    List<IntVar> iUse = new ArrayList<>();
    for (int j = 0; j < getVMs().size(); j++) {
        VMTransition a = vmActions.get(j);
        if (a.getDSlice() != null) {
            iUse.add(csp.intVar(1));
        }
        if (a.getCSlice() != null) {
            cUse.add(1);
        }
    }
    ChocoView v = getView(Cumulatives.VIEW_ID);
    if (v == null) {
        throw SchedulerModelingException.missingView(model, Cumulatives.VIEW_ID);
    }
    ((Cumulatives) v).addDim(getNbRunningVMs(), cUse.toArray(), iUse.toArray(new IntVar[iUse.size()]));
}
Also used : ChocoView(org.btrplace.scheduler.choco.view.ChocoView) AliasedCumulatives(org.btrplace.scheduler.choco.view.AliasedCumulatives) Cumulatives(org.btrplace.scheduler.choco.view.Cumulatives) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 14 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class CGather method getDSlices.

private List<Slice> getDSlices(ReconfigurationProblem rp) {
    List<Slice> dSlices = new ArrayList<>();
    for (VM vm : cstr.getInvolvedVMs()) {
        VMTransition a = rp.getVMAction(vm);
        Slice dSlice = a.getDSlice();
        if (dSlice != null) {
            dSlices.add(dSlice);
        }
    }
    return dSlices;
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) VM(org.btrplace.model.VM) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition)

Example 15 with VMTransition

use of org.btrplace.scheduler.choco.transition.VMTransition in project scheduler by btrplace.

the class CLonely method continuousRestriction.

private static void continuousRestriction(ReconfigurationProblem rp, Collection<VM> vms, Set<VM> otherVMs) {
    // Get the position of all the others c-slices and their associated end moment
    TIntArrayList otherPos = new TIntArrayList();
    TIntArrayList minePos = new TIntArrayList();
    List<IntVar> otherEnds = new ArrayList<>();
    List<IntVar> mineEnds = new ArrayList<>();
    Mapping map = rp.getSourceModel().getMapping();
    for (Node n : map.getOnlineNodes()) {
        for (VM vm : map.getRunningVMs(n)) {
            if (!vms.contains(vm)) {
                otherPos.add(rp.getNode(map.getVMLocation(vm)));
                VMTransition a = rp.getVMAction(vm);
                otherEnds.add(a.getCSlice().getEnd());
            } else {
                minePos.add(rp.getNode(map.getVMLocation(vm)));
                VMTransition a = rp.getVMAction(vm);
                mineEnds.add(a.getCSlice().getEnd());
            }
        }
    }
    for (VM vm : vms) {
        VMTransition a = rp.getVMAction(vm);
        Precedences p = new Precedences(a.getDSlice().getHoster(), a.getDSlice().getStart(), otherPos.toArray(), otherEnds.toArray(new IntVar[otherEnds.size()]));
        rp.getModel().post(p);
    }
    // TODO: The following reveals a model problem. Too many constraints!!
    for (VM vm : otherVMs) {
        VMTransition a = rp.getVMAction(vm);
        Precedences p = new Precedences(a.getDSlice().getHoster(), a.getDSlice().getStart(), minePos.toArray(), mineEnds.toArray(new IntVar[mineEnds.size()]));
        rp.getModel().post(p);
    }
}
Also used : Precedences(org.btrplace.scheduler.choco.extensions.Precedences) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Aggregations

VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)41 VM (org.btrplace.model.VM)34 RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)23 Node (org.btrplace.model.Node)22 IntVar (org.chocosolver.solver.variables.IntVar)22 ArrayList (java.util.ArrayList)18 Model (org.btrplace.model.Model)17 HashSet (java.util.HashSet)16 Mapping (org.btrplace.model.Mapping)16 Slice (org.btrplace.scheduler.choco.Slice)16 DefaultModel (org.btrplace.model.DefaultModel)12 BootableNode (org.btrplace.scheduler.choco.transition.BootableNode)12 ShutdownableNode (org.btrplace.scheduler.choco.transition.ShutdownableNode)12 StayAwayVM (org.btrplace.scheduler.choco.transition.StayAwayVM)12 Test (org.testng.annotations.Test)12 BootVM (org.btrplace.scheduler.choco.transition.BootVM)11 ForgeVM (org.btrplace.scheduler.choco.transition.ForgeVM)11 KillVM (org.btrplace.scheduler.choco.transition.KillVM)11 ResumeVM (org.btrplace.scheduler.choco.transition.ResumeVM)11 ShutdownVM (org.btrplace.scheduler.choco.transition.ShutdownVM)11