org.btrplace.scheduler.runner.disjoint.splitter.AmongSplitter Maven / Gradle / Ivy
Show all versions of split Show documentation
/*
* Copyright (c) 2016 University Nice Sophia Antipolis
*
* This file is part of btrplace.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
package org.btrplace.scheduler.runner.disjoint.splitter;
import gnu.trove.map.hash.TIntIntHashMap;
import org.btrplace.model.Instance;
import org.btrplace.model.Node;
import org.btrplace.model.VM;
import org.btrplace.model.constraint.Among;
import org.btrplace.scheduler.runner.disjoint.model.ElementSubSet;
import org.btrplace.scheduler.runner.disjoint.model.SplittableElementSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
* Splitter for {@link org.btrplace.model.constraint.Among} constraints.
*
* When the constraint focuses VMs among different partitions,
* the constraint is split accordingly.
* If the nodes groups are also split among different partitions,
* this leads to a un-solvable problem as it is not possible to
* synchronize the sub-among constraints to make them choose the same nodes group.
*
* @author Fabien Hermenier
*/
public class AmongSplitter implements ConstraintSplitter {
@Override
public Class getKey() {
return Among.class;
}
@Override
public boolean split(final Among cstr, Instance origin, final List partitions, TIntIntHashMap vmsPosition, final TIntIntHashMap nodePosition) {
final boolean c = cstr.isContinuous();
return SplittableElementSet.newVMIndex(cstr.getInvolvedVMs(), vmsPosition).
forEachPartition((index, idx, from, to) -> {
if (to - from >= 2) {
ElementSubSet vms = new ElementSubSet<>(index, idx, from, to);
//Get the servers on the partition
//Filter out the other nodes in the original constraint
final Collection> subParams = new ArrayList<>();
for (Collection ns : cstr.getGroupsOfNodes()) {
SplittableElementSet nodeIndex = SplittableElementSet.newNodeIndex(ns, nodePosition);
Set s = nodeIndex.getSubSet(idx);
if (s != null && !s.isEmpty()) {
subParams.add(s);
}
}
partitions.get(idx).getSatConstraints().add(new Among(vms, subParams, c));
}
return true;
});
}
}