use of org.btrplace.model.Instance in project scheduler by btrplace.
the class InstanceConverter method fromJSON.
@Override
public Instance fromJSON(JSONObject in) throws JSONConverterException {
checkKeys(in, MODEL_LABEL, CONSTRAINTS_LABEL, OBJ_LABEL);
Model mo = moc.fromJSON((JSONObject) in.get(MODEL_LABEL));
return new Instance(mo, cc.listFromJSON(mo, (JSONArray) in.get(CONSTRAINTS_LABEL)), (OptConstraint) cc.fromJSON(mo, (JSONObject) in.get(OBJ_LABEL)));
}
use of org.btrplace.model.Instance in project scheduler by btrplace.
the class Instances method makeVMIndex.
/**
* Make an index revealing the position of each VM in a collection
* of disjoint instances
*
* @param instances the collection to browse. Instances are supposed to be disjoint
* @return the index of every VM. Format {@code VM#id() -> position}
*/
public static TIntIntHashMap makeVMIndex(Collection<Instance> instances) {
TIntIntHashMap index = new TIntIntHashMap();
int p = 0;
for (Instance i : instances) {
Mapping m = i.getModel().getMapping();
for (Node n : m.getOnlineNodes()) {
for (VM v : m.getRunningVMs(n)) {
index.put(v.id(), p);
}
for (VM v : m.getSleepingVMs(n)) {
index.put(v.id(), p);
}
}
for (VM v : m.getReadyVMs()) {
index.put(v.id(), p);
}
p++;
}
return index;
}
use of org.btrplace.model.Instance in project scheduler by btrplace.
the class Instances method makeNodeIndex.
/**
* Make an index revealing the position of each node in a collection
* of disjoint instances
*
* @param instances the collection to browse. Instances are supposed to be disjoint
* @return the index of every node. Format {@code Node#id() -> position}
*/
public static TIntIntHashMap makeNodeIndex(Collection<Instance> instances) {
TIntIntHashMap index = new TIntIntHashMap();
int p = 0;
for (Instance i : instances) {
Mapping m = i.getModel().getMapping();
for (Node n : m.getOfflineNodes()) {
index.put(n.id(), p);
}
for (Node n : m.getOnlineNodes()) {
index.put(n.id(), p);
}
p++;
}
return index;
}
use of org.btrplace.model.Instance in project scheduler by btrplace.
the class StaticPartitioning method solve.
@Override
public ReconfigurationPlan solve(Parameters cra, Instance orig) throws SchedulerException {
stats = new StaticPartitioningStatistics(cra, orig, System.currentTimeMillis(), workersCount);
long d = -System.currentTimeMillis();
List<Instance> partitions = split(cra, orig);
d += System.currentTimeMillis();
stats.setSplittingStatistics(partitions.size(), d);
ExecutorService exe = Executors.newFixedThreadPool(this.workersCount);
CompletionService<SolvingStatistics> completionService = new ExecutorCompletionService<>(exe);
List<SolvingStatistics> results = new ArrayList<>(partitions.size());
long duration = -System.currentTimeMillis();
for (Instance partition : partitions) {
completionService.submit(new InstanceSolverRunner(cra, partition));
}
for (int i = 0; i < partitions.size(); i++) {
try {
results.add(completionService.take().get());
} catch (ExecutionException ignore) {
Throwable cause = ignore.getCause();
if (cause != null) {
throw new SplitException(null, cause.getMessage(), ignore);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new SplitException(orig.getModel(), e.getMessage(), e);
}
}
duration += System.currentTimeMillis();
stats.setSolvingDuration(duration);
exe.shutdown();
return merge(orig, results);
}
use of org.btrplace.model.Instance in project scheduler by btrplace.
the class CMinMigrationsTest method testWithFreeNodes.
/**
* Issue #137.
* ShutdownableNode.isOnline() is not instantiated at the end of the problem
*/
@Test
public void testWithFreeNodes() {
Model mo = new DefaultModel();
Node n0 = mo.newNode();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
VM v1 = mo.newVM();
VM v2 = mo.newVM();
DefaultChocoScheduler s = new DefaultChocoScheduler();
mo.getMapping().on(n0, n1, n2).run(n0, v1, v2);
Instance i = new Instance(mo, Arrays.asList(new Spread(mo.getMapping().getAllVMs(), false)), new MinMigrations());
ReconfigurationPlan p = s.solve(i);
Assert.assertNotNull(p);
}
Aggregations