use of org.btrplace.model.VM in project scheduler by btrplace.
the class CSerialize method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
// Get the solver
Model csp = rp.getModel();
// Not enough VMs
if (ser.getInvolvedVMs().size() < 2) {
return true;
}
// Get all migrations involved
for (VM vm : ser.getInvolvedVMs()) {
VMTransition vt = rp.getVMAction(vm);
if (vt instanceof RelocatableVM) {
migrationList.add((RelocatableVM) vt);
}
}
// Not enough migrations
if (migrationList.size() < 2) {
return true;
}
// Using a cumulative
List<Task> tasks = new ArrayList<>();
for (RelocatableVM mig : migrationList) {
tasks.add(new Task(mig.getStart(), mig.getDuration(), mig.getEnd()));
}
IntVar[] heights = new IntVar[tasks.size()];
Arrays.fill(heights, csp.intVar(1));
csp.post(csp.cumulative(tasks.toArray(new Task[tasks.size()]), heights, csp.intVar(1), true));
return true;
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class CMinMTTR method placeVMs.
/*
* Try to place the VMs associated on the actions in a random node while trying first to stay on the current node
*/
private void placeVMs(Parameters ps, List<AbstractStrategy<?>> strategies, List<VMTransition> actions, OnStableNodeFirst schedHeuristic, Map<IntVar, VM> map) {
IntValueSelector rnd = new WorstFit(map, rp, new BiggestDimension());
if (!useResources) {
rnd = new RandomVMPlacement(rp, map, true, ps.getRandomSeed());
}
IntVar[] hosts = dSlices(actions).map(Slice::getHoster).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
if (hosts.length > 0) {
strategies.add(new IntStrategy(hosts, new HostingVariableSelector(rp.getModel(), schedHeuristic), rnd));
}
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class LinearToAResourceActionDuration method evaluate.
@Override
public int evaluate(Model mo, E e) {
ShareableResource r = ShareableResource.get(mo, rc);
if (r == null) {
return -1;
}
int x;
if (e instanceof VM) {
x = r.getConsumption((VM) e);
} else if (e instanceof Node) {
x = r.getCapacity((Node) e);
} else {
return -1;
}
return (int) Math.round(coefficient * x + offset);
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class RelocatableVM method insertActions.
@Override
public boolean insertActions(Solution s, ReconfigurationPlan plan) {
DurationEvaluators dev = rp.getDurationEvaluators();
// Only if the VM doesn't stay
if (s.getIntVal(cSlice.getHoster()) != (s.getIntVal(dSlice.getHoster()))) {
Action a;
Node dst = rp.getNode(s.getIntVal(dSlice.getHoster()));
// Migration
if (s.getIntVal(doReinstantiation) == 0) {
int st = s.getIntVal(getStart());
int ed = s.getIntVal(getEnd());
if (getBandwidth() != null) {
a = new MigrateVM(vm, src, dst, st, ed, s.getIntVal(getBandwidth()));
} else {
a = new MigrateVM(vm, src, dst, st, ed);
}
plan.add(a);
// Re-instantiation
} else {
VM newVM = rp.cloneVM(vm);
if (newVM == null) {
rp.getLogger().error("Unable to get a new int to plan the re-instantiate of VM {}", vm);
return false;
}
org.btrplace.plan.event.ForgeVM fvm = new org.btrplace.plan.event.ForgeVM(newVM, s.getIntVal(dSlice.getStart()) - dev.evaluate(rp.getSourceModel(), org.btrplace.plan.event.ForgeVM.class, vm), s.getIntVal(dSlice.getStart()));
// forge the new VM from a template
plan.add(fvm);
// Boot the new VM
int endForging = fvm.getEnd();
org.btrplace.plan.event.BootVM boot = new org.btrplace.plan.event.BootVM(newVM, dst, endForging, endForging + dev.evaluate(rp.getSourceModel(), org.btrplace.plan.event.BootVM.class, newVM));
boot.addEvent(Action.Hook.PRE, new SubstitutedVMEvent(vm, newVM));
return plan.add(boot) && plan.add(new org.btrplace.plan.event.ShutdownVM(vm, src, boot.getEnd(), s.getIntVal(cSlice.getEnd())));
}
}
return true;
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class CShareableResource method beforeSolve.
/**
* Set the resource usage for each of the VM.
* If the LB is < 0 , the previous consumption is used to maintain the resource usage.
* Otherwise, the usage is set to the variable lower bound.
*
* @return false if an operation leads to a problem without solution
*/
@Override
public boolean beforeSolve(ReconfigurationProblem p) throws SchedulerException {
for (VM vm : source.getMapping().getAllVMs()) {
int vmId = p.getVM(vm);
int v = getVMAllocation(vmId);
if (v < 0) {
int prevUsage = rc.getConsumption(vm);
minVMAllocation(vmId, prevUsage);
}
}
ChocoView v = rp.getView(Packing.VIEW_ID);
if (v == null) {
throw SchedulerModelingException.missingView(rp.getSourceModel(), Packing.VIEW_ID);
}
IntVar[] host = new IntVar[p.getFutureRunningVMs().size()];
int[] demand = new int[host.length];
int i = 0;
for (VM vm : p.getFutureRunningVMs()) {
host[i] = rp.getVMAction(vm).getDSlice().getHoster();
demand[i] = getVMAllocation(p.getVM(vm));
i++;
}
((Packing) v).addDim(rc.getResourceIdentifier(), virtRcUsage, demand, host);
return linkVirtualToPhysicalUsage();
}
Aggregations