Search in sources :

Example 11 with Instance

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)));
}
Also used : Instance(org.btrplace.model.Instance) Model(org.btrplace.model.Model) JSONArray(net.minidev.json.JSONArray)

Example 12 with Instance

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;
}
Also used : Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) Mapping(org.btrplace.model.Mapping) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap)

Example 13 with Instance

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;
}
Also used : Instance(org.btrplace.model.Instance) Node(org.btrplace.model.Node) Mapping(org.btrplace.model.Mapping) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap)

Example 14 with Instance

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);
}
Also used : InstanceSolverRunner(org.btrplace.scheduler.choco.runner.single.InstanceSolverRunner) Instance(org.btrplace.model.Instance) ArrayList(java.util.ArrayList) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) ExecutorService(java.util.concurrent.ExecutorService) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) ExecutionException(java.util.concurrent.ExecutionException)

Example 15 with Instance

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);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Spread(org.btrplace.model.constraint.Spread) Instance(org.btrplace.model.Instance) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Node(org.btrplace.model.Node) MigrateVM(org.btrplace.plan.event.MigrateVM) VM(org.btrplace.model.VM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) MinMigrations(org.btrplace.model.constraint.MinMigrations) Test(org.testng.annotations.Test)

Aggregations

Instance (org.btrplace.model.Instance)34 Test (org.testng.annotations.Test)24 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)20 Model (org.btrplace.model.Model)19 ArrayList (java.util.ArrayList)17 DefaultModel (org.btrplace.model.DefaultModel)14 MinMTTR (org.btrplace.model.constraint.MinMTTR)13 TIntIntHashMap (gnu.trove.map.hash.TIntIntHashMap)12 Node (org.btrplace.model.Node)12 VM (org.btrplace.model.VM)12 StringReader (java.io.StringReader)10 HashSet (java.util.HashSet)10 SatConstraint (org.btrplace.model.constraint.SatConstraint)8 List (java.util.List)5 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)5 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)4 File (java.io.File)3 MinMigrations (org.btrplace.model.constraint.MinMigrations)3 Spread (org.btrplace.model.constraint.Spread)3 MigrateVM (org.btrplace.plan.event.MigrateVM)3