use of org.btrplace.scheduler.choco.view.CShareableResource in project scheduler by btrplace.
the class COverbook method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
CShareableResource rcm = (CShareableResource) rp.getView(ShareableResource.VIEW_ID_BASE + cstr.getResource());
if (rcm == null) {
throw new SchedulerModelingException(rp.getSourceModel(), "Unable to get the resource mapping '" + cstr.getResource() + "'");
}
Node u = cstr.getInvolvedNodes().iterator().next();
rcm.capOverbookRatio(rp.getNode(u), cstr.getRatio());
return true;
}
use of org.btrplace.scheduler.choco.view.CShareableResource in project scheduler by btrplace.
the class CResourceCapacity method getMisPlacedVMs.
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
if (cstr.getInvolvedNodes().size() <= 1) {
// If there is only a single node, we delegate this work to CShareableResource.
return Collections.emptySet();
}
Mapping map = i.getModel().getMapping();
ShareableResource rc = ShareableResource.get(i.getModel(), cstr.getResource());
if (rc == null) {
return map.getRunningVMs(cstr.getInvolvedNodes());
}
Set<VM> bad = new HashSet<>();
int remainder = cstr.getAmount();
for (Node n : cstr.getInvolvedNodes()) {
for (VM v : map.getRunningVMs(n)) {
remainder -= rc.getConsumption(v);
if (remainder < 0) {
for (Node n2 : cstr.getInvolvedNodes()) {
bad.addAll(map.getRunningVMs(n2));
}
return bad;
}
}
}
return bad;
}
use of org.btrplace.scheduler.choco.view.CShareableResource in project scheduler by btrplace.
the class CMinMigrations method injectPlacementHeuristic.
private void injectPlacementHeuristic(ReconfigurationProblem p, Parameters ps, IntVar cost) {
List<CShareableResource> rcs = rp.getSourceModel().getViews().stream().filter(v -> v instanceof ShareableResource).map(v -> (CShareableResource) rp.getView(v.getIdentifier())).collect(Collectors.toList());
useResources = !rcs.isEmpty();
Model mo = p.getSourceModel();
Mapping map = mo.getMapping();
OnStableNodeFirst schedHeuristic = new OnStableNodeFirst(p);
// Get the VMs to place
Set<VM> onBadNodes = new HashSet<>(p.getManageableVMs());
// Get the VMs that runs and have a pretty low chances to move
Set<VM> onGoodNodes = map.getRunningVMs(map.getOnlineNodes());
onGoodNodes.removeAll(onBadNodes);
List<VMTransition> goodActions = p.getVMActions(onGoodNodes);
List<VMTransition> badActions = p.getVMActions(onBadNodes);
Solver s = p.getSolver();
// Get the VMs to move for exclusion issue
Set<VM> vmsToExclude = new HashSet<>(p.getManageableVMs());
for (Iterator<VM> ite = vmsToExclude.iterator(); ite.hasNext(); ) {
VM vm = ite.next();
if (!(map.isRunning(vm) && p.getFutureRunningVMs().contains(vm))) {
ite.remove();
}
}
List<AbstractStrategy<?>> strategies = new ArrayList<>();
Map<IntVar, VM> pla = VMPlacementUtils.makePlacementMap(p);
if (!vmsToExclude.isEmpty()) {
List<VMTransition> actions = new LinkedList<>();
// Get all the involved slices
for (VM vm : vmsToExclude) {
if (p.getFutureRunningVMs().contains(vm)) {
actions.add(p.getVMAction(vm));
}
}
placeVMs(ps, strategies, actions, schedHeuristic, pla);
}
TObjectIntMap<VM> costs = CShareableResource.getWeights(rp, rcs);
badActions.sort((v2, v1) -> costs.get(v1.getVM()) - costs.get(v2.getVM()));
goodActions.sort((v2, v1) -> costs.get(v1.getVM()) - costs.get(v2.getVM()));
placeVMs(ps, strategies, badActions, schedHeuristic, pla);
placeVMs(ps, strategies, goodActions, schedHeuristic, pla);
// Reinstantations. Try to reinstantiate first
List<IntVar> migs = new ArrayList<>();
for (VMTransition t : rp.getVMActions()) {
if (t instanceof RelocatableVM) {
migs.add(((RelocatableVM) t).getRelocationMethod());
}
}
strategies.add(Search.intVarSearch(new FirstFail(rp.getModel()), new IntDomainMax(), migs.toArray(new IntVar[migs.size()])));
if (!p.getNodeActions().isEmpty()) {
// Boot some nodes if needed
IntVar[] starts = p.getNodeActions().stream().map(Transition::getStart).toArray(IntVar[]::new);
strategies.add(new IntStrategy(starts, new FirstFail(rp.getModel()), new IntDomainMin()));
// Fix the duration. The side effect will be that states will be fixed as well
// with the objective to not do un-necessary actions
IntVar[] durations = p.getNodeActions().stream().map(Transition::getDuration).toArray(IntVar[]::new);
strategies.add(new IntStrategy(durations, new FirstFail(rp.getModel()), new IntDomainMin()));
}
postCostConstraints();
// /SCHEDULING PROBLEM
MovementGraph gr = new MovementGraph(rp);
IntVar[] starts = dSlices(rp.getVMActions()).map(Slice::getStart).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
strategies.add(new IntStrategy(starts, new StartOnLeafNodes(rp, gr), new IntDomainMin()));
strategies.add(new IntStrategy(schedHeuristic.getScope(), schedHeuristic, new IntDomainMin()));
IntVar[] ends = rp.getVMActions().stream().map(Transition::getEnd).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
strategies.add(Search.intVarSearch(new MyInputOrder<>(s), new IntDomainMin(), ends));
// At this stage only it matters to plug the cost constraints
strategies.add(new IntStrategy(new IntVar[] { p.getEnd(), cost }, new MyInputOrder<>(s, this), new IntDomainMin()));
s.setSearch(new StrategiesSequencer(s.getEnvironment(), strategies.toArray(new AbstractStrategy[strategies.size()])));
}
use of org.btrplace.scheduler.choco.view.CShareableResource in project scheduler by btrplace.
the class CMinMTTR method injectPlacementHeuristic.
private void injectPlacementHeuristic(ReconfigurationProblem p, Parameters ps, IntVar cost) {
List<CShareableResource> rcs = rp.getSourceModel().getViews().stream().filter(v -> v instanceof ShareableResource).map(v -> (CShareableResource) rp.getView(v.getIdentifier())).collect(Collectors.toList());
useResources = !rcs.isEmpty();
Model mo = p.getSourceModel();
Mapping map = mo.getMapping();
OnStableNodeFirst schedHeuristic = new OnStableNodeFirst(p);
// Get the VMs to place
Set<VM> onBadNodes = new HashSet<>(p.getManageableVMs());
// Get the VMs that runs and have a pretty low chances to move
Set<VM> onGoodNodes = map.getRunningVMs(map.getOnlineNodes());
onGoodNodes.removeAll(onBadNodes);
List<VMTransition> goodActions = p.getVMActions(onGoodNodes);
List<VMTransition> badActions = p.getVMActions(onBadNodes);
Solver s = p.getSolver();
// Get the VMs to move for exclusion issue
Set<VM> vmsToExclude = new HashSet<>(p.getManageableVMs());
for (Iterator<VM> ite = vmsToExclude.iterator(); ite.hasNext(); ) {
VM vm = ite.next();
if (!(map.isRunning(vm) && p.getFutureRunningVMs().contains(vm))) {
ite.remove();
}
}
List<AbstractStrategy<?>> strategies = new ArrayList<>();
Map<IntVar, VM> pla = VMPlacementUtils.makePlacementMap(p);
if (!vmsToExclude.isEmpty()) {
List<VMTransition> actions = new LinkedList<>();
// Get all the involved slices
for (VM vm : vmsToExclude) {
if (p.getFutureRunningVMs().contains(vm)) {
actions.add(p.getVMAction(vm));
}
}
placeVMs(ps, strategies, actions, schedHeuristic, pla);
}
TObjectIntMap<VM> costs = CShareableResource.getWeights(rp, rcs);
badActions.sort((v2, v1) -> costs.get(v1.getVM()) - costs.get(v2.getVM()));
goodActions.sort((v2, v1) -> costs.get(v1.getVM()) - costs.get(v2.getVM()));
placeVMs(ps, strategies, badActions, schedHeuristic, pla);
placeVMs(ps, strategies, goodActions, schedHeuristic, pla);
// Reinstantations. Try to reinstantiate first
List<IntVar> migs = new ArrayList<>();
for (VMTransition t : rp.getVMActions()) {
if (t instanceof RelocatableVM) {
migs.add(((RelocatableVM) t).getRelocationMethod());
}
}
strategies.add(Search.intVarSearch(new FirstFail(rp.getModel()), new IntDomainMax(), migs.toArray(new IntVar[migs.size()])));
if (!p.getNodeActions().isEmpty()) {
// Boot some nodes if needed
IntVar[] starts = p.getNodeActions().stream().map(Transition::getStart).toArray(IntVar[]::new);
strategies.add(new IntStrategy(starts, new FirstFail(rp.getModel()), new IntDomainMin()));
}
// /SCHEDULING PROBLEM
MovementGraph gr = new MovementGraph(rp);
IntVar[] starts = dSlices(rp.getVMActions()).map(Slice::getStart).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
strategies.add(new IntStrategy(starts, new StartOnLeafNodes(rp, gr), new IntDomainMin()));
strategies.add(new IntStrategy(schedHeuristic.getScope(), schedHeuristic, new IntDomainMin()));
IntVar[] ends = rp.getVMActions().stream().map(Transition::getEnd).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
strategies.add(Search.intVarSearch(new MyInputOrder<>(s), new IntDomainMin(), ends));
// At this stage only it matters to plug the cost constraints
strategies.add(new IntStrategy(new IntVar[] { p.getEnd(), cost }, new MyInputOrder<>(s, this), new IntDomainMin()));
s.setSearch(new StrategiesSequencer(s.getEnvironment(), strategies.toArray(new AbstractStrategy[strategies.size()])));
}
use of org.btrplace.scheduler.choco.view.CShareableResource in project scheduler by btrplace.
the class CPreserve method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
CShareableResource map = (CShareableResource) rp.getView(ShareableResource.VIEW_ID_BASE + cstr.getResource());
if (map == null) {
throw new SchedulerModelingException(rp.getSourceModel(), "Unable to get the resource mapper associated to '" + cstr.getResource() + "'");
}
VM vm = cstr.getInvolvedVMs().iterator().next();
if (rp.getFutureRunningVMs().contains(vm)) {
int idx = rp.getVM(vm);
map.minVMAllocation(idx, cstr.getAmount());
}
return true;
}
Aggregations