Search in sources :

Example 31 with Action

use of org.btrplace.plan.event.Action in project scheduler by btrplace.

the class ReconfigurationSimulator method start.

/**
 * Evaluate the proposition over a reconfiguration, at any timestamp.
 * @param prop the proposition to evaluate
 * @return the moment the proposition is not valid. {@code -1} if the proposition is correct
 */
public int start(Proposition prop) {
    // sort actions by timestamp
    Set<Integer> s = new TreeSet<>(Comparator.comparingInt(a -> a));
    for (Action a : p.getActions()) {
        s.add(a.getStart());
        s.add(a.getEnd());
        if (!starts.containsKey(a.getStart())) {
            starts.put(a.getStart(), new ArrayList<>());
        }
        if (!ends.containsKey(a.getEnd())) {
            ends.put(a.getEnd(), new ArrayList<>());
        }
        starts.get(a.getStart()).add(a);
        ends.get(a.getEnd()).add(a);
    }
    timeStamps = s.stream().collect(Collectors.toList());
    for (Integer i : timeStamps) {
        List<Action> st = starts.get(i);
        if (st == null) {
            st = new ArrayList<>();
        }
        List<Action> ed = ends.get(i);
        if (ed == null) {
            ed = new ArrayList<>();
        }
        at(st, ed);
        Boolean res = prop.eval(co);
        if (!Boolean.TRUE.equals(res)) {
            return i;
        }
    }
    return -1;
}
Also used : Node(org.btrplace.model.Node) MigrateVM(org.btrplace.plan.event.MigrateVM) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) BootVM(org.btrplace.plan.event.BootVM) ArrayList(java.util.ArrayList) SubstitutedVMEvent(org.btrplace.plan.event.SubstitutedVMEvent) ShutdownVM(org.btrplace.plan.event.ShutdownVM) NodeStateType(org.btrplace.safeplace.spec.type.NodeStateType) Map(java.util.Map) SuspendVM(org.btrplace.plan.event.SuspendVM) ActionVisitor(org.btrplace.plan.event.ActionVisitor) ResumeVM(org.btrplace.plan.event.ResumeVM) Set(java.util.Set) Collectors(java.util.stream.Collectors) BootNode(org.btrplace.plan.event.BootNode) AllocateEvent(org.btrplace.plan.event.AllocateEvent) List(java.util.List) Proposition(org.btrplace.safeplace.spec.prop.Proposition) ShutdownNode(org.btrplace.plan.event.ShutdownNode) Allocate(org.btrplace.plan.event.Allocate) VMStateType(org.btrplace.safeplace.spec.type.VMStateType) Action(org.btrplace.plan.event.Action) ForgeVM(org.btrplace.plan.event.ForgeVM) Comparator(java.util.Comparator) KillVM(org.btrplace.plan.event.KillVM) Action(org.btrplace.plan.event.Action) TreeSet(java.util.TreeSet)

Example 32 with Action

use of org.btrplace.plan.event.Action in project scheduler by btrplace.

the class ReconfigurationPlanConverter method toJSON.

@Override
public JSONObject toJSON(ReconfigurationPlan plan) throws JSONConverterException {
    JSONObject ob = new JSONObject();
    Model src = plan.getOrigin();
    ActionConverter ac = new ActionConverter(src);
    ob.put(ORIGIN_LABEL, mc.toJSON(src));
    JSONArray actions = new JSONArray();
    for (Action a : plan.getActions()) {
        actions.add(ac.toJSON(a));
    }
    ob.put(ACTIONS_LABEL, actions);
    return ob;
}
Also used : Action(org.btrplace.plan.event.Action) JSONObject(net.minidev.json.JSONObject) Model(org.btrplace.model.Model) JSONArray(net.minidev.json.JSONArray)

Example 33 with Action

use of org.btrplace.plan.event.Action in project scheduler by btrplace.

the class Actions method eval.

@Override
public Set<Action> eval(Context mo, Object... args) {
    VM v = (VM) args[0];
    if (v == null) {
        throw new UnsupportedOperationException();
    }
    Set<Action> s = new HashSet<>();
    for (Action a : mo.getPlan()) {
        if (a instanceof VMEvent) {
            if (((VMEvent) a).getVM().equals(v)) {
                s.add(a);
            }
        }
    }
    return s;
}
Also used : Action(org.btrplace.plan.event.Action) VMEvent(org.btrplace.plan.event.VMEvent) VM(org.btrplace.model.VM) HashSet(java.util.HashSet)

Example 34 with Action

use of org.btrplace.plan.event.Action in project scheduler by btrplace.

the class KillVMTest method testBasics.

/**
 * Test the action model with different action models.
 *
 * @throws ContradictionException
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testBasics() throws ContradictionException, SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    Node n1 = mo.newNode();
    map.addOnlineNode(n1);
    VM vm1 = mo.newVM();
    map.addRunningVM(vm1, n1);
    VM vm2 = mo.newVM();
    map.addReadyVM(vm2);
    VM vm3 = mo.newVM();
    map.addSleepingVM(vm3, n1);
    Set<VM> empty = new HashSet<>();
    DurationEvaluators dev = new DurationEvaluators();
    dev.register(org.btrplace.plan.event.KillVM.class, new ConstantActionDuration<>(1));
    Parameters ps = new DefaultParameters();
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(empty, empty, empty, map.getAllVMs()).setParams(ps).build();
    rp.getNodeAction(n1).getState().instantiateTo(rp.getVM(vm1), Cause.Null);
    // Common stuff
    for (VM vm : map.getAllVMs()) {
        KillVM m = (KillVM) rp.getVMAction(vm);
        Assert.assertEquals(vm, m.getVM());
        Assert.assertTrue(m.getState().isInstantiatedTo(0));
        Assert.assertNull(m.getDSlice());
        Assert.assertTrue(m.getDuration().isInstantiatedTo(1));
        Assert.assertTrue(m.getStart().isInstantiatedTo(0));
        Assert.assertTrue(m.getEnd().isInstantiatedTo(1));
    }
    // The waiting and the sleeping VM have no CSlice
    Assert.assertNull(rp.getVMAction(vm2).getCSlice());
    Assert.assertNull(rp.getVMAction(vm3).getCSlice());
    // The running VM has a CSlice
    Assert.assertNotNull(rp.getVMAction(vm1).getCSlice());
    Assert.assertTrue(rp.getVMAction(vm1).getCSlice().getHoster().isInstantiatedTo(rp.getNode(n1)));
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(0, false);
    Assert.assertNotNull(p);
    for (Action a : p) {
        if (a instanceof org.btrplace.plan.event.KillVM) {
            org.btrplace.plan.event.KillVM vma = (org.btrplace.plan.event.KillVM) a;
            Assert.assertEquals(1, a.getEnd());
            Assert.assertEquals(0, a.getStart());
            if (vma.getVM().equals(vm1) || vma.getVM().equals(vm3)) {
                Assert.assertEquals(vma.getNode(), n1);
            } else if (vma.getVM().equals(vm2)) {
                Assert.assertNull(vma.getNode());
            } else {
                Assert.fail();
            }
        }
    }
}
Also used : Action(org.btrplace.plan.event.Action) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 35 with Action

use of org.btrplace.plan.event.Action in project scheduler by btrplace.

the class RelocatableVMTest method testForcedReInstantiation.

@Test
public void testForcedReInstantiation() throws SchedulerException, ContradictionException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    final VM vm10 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    map.addOnlineNode(n1);
    map.addOnlineNode(n2);
    // Not using vm1 because intPool starts at 0 so their will be multiple (0,1) VMs.
    map.addRunningVM(vm10, n1);
    Parameters ps = new DefaultParameters();
    DurationEvaluators dev = ps.getDurationEvaluators();
    dev.register(MigrateVM.class, new ConstantActionDuration<>(20));
    dev.register(org.btrplace.plan.event.ForgeVM.class, new ConstantActionDuration<>(3));
    dev.register(org.btrplace.plan.event.BootVM.class, new ConstantActionDuration<>(2));
    dev.register(org.btrplace.plan.event.ShutdownVM.class, new ConstantActionDuration<>(1));
    mo.getAttributes().put(vm10, "template", "small");
    mo.getAttributes().put(vm10, "clone", true);
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setNextVMsStates(Collections.emptySet(), map.getAllVMs(), Collections.emptySet(), Collections.emptySet()).setParams(ps).setManageableVMs(map.getAllVMs()).build();
    RelocatableVM am = (RelocatableVM) rp.getVMAction(vm10);
    am.getRelocationMethod().instantiateTo(1, Cause.Null);
    am.getDSlice().getHoster().instantiateTo(rp.getNode(n2), Cause.Null);
    new CMinMTTR().inject(ps, rp);
    ReconfigurationPlan p = rp.solve(10, true);
    Assert.assertNotNull(p);
    Assert.assertTrue(am.getRelocationMethod().isInstantiatedTo(1));
    Assert.assertEquals(p.getSize(), 3);
    Model res = p.getResult();
    // Check the VM has been relocated
    Assert.assertEquals(res.getMapping().getRunningVMs(n1).size(), 0);
    Assert.assertEquals(res.getMapping().getRunningVMs(n2).size(), 1);
    Assert.assertNotNull(p);
    // Check for the actions duration
    for (Action a : p) {
        if (a instanceof org.btrplace.plan.event.ForgeVM) {
            Assert.assertEquals(a.getEnd() - a.getStart(), 3);
        } else if (a instanceof org.btrplace.plan.event.ShutdownVM) {
            Assert.assertEquals(a.getEnd() - a.getStart(), 1);
        } else if (a instanceof org.btrplace.plan.event.BootVM) {
            Assert.assertEquals(a.getEnd() - a.getStart(), 2);
        } else {
            Assert.fail();
        }
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Action(org.btrplace.plan.event.Action) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Parameters(org.btrplace.scheduler.choco.Parameters) Node(org.btrplace.model.Node) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Mapping(org.btrplace.model.Mapping) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) Test(org.testng.annotations.Test)

Aggregations

Action (org.btrplace.plan.event.Action)40 Test (org.testng.annotations.Test)25 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)18 MigrateVM (org.btrplace.plan.event.MigrateVM)10 DurationEvaluators (org.btrplace.scheduler.choco.duration.DurationEvaluators)10 HashSet (java.util.HashSet)9 Parameters (org.btrplace.scheduler.choco.Parameters)9 ReconfigurationProblem (org.btrplace.scheduler.choco.ReconfigurationProblem)9 VM (org.btrplace.model.VM)8 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)8 DefaultReconfigurationProblemBuilder (org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder)8 Model (org.btrplace.model.Model)7 CMinMTTR (org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR)7 ArrayList (java.util.ArrayList)6 SatConstraint (org.btrplace.model.constraint.SatConstraint)6 Node (org.btrplace.model.Node)5 ShareableResource (org.btrplace.model.view.ShareableResource)5 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)5 BootVM (org.btrplace.plan.event.BootVM)4 ShutdownNode (org.btrplace.plan.event.ShutdownNode)4