use of org.btrplace.model.Instance in project scheduler by btrplace.
the class FixedNodeSetsPartitioning method split.
@Override
public List<Instance> split(Parameters ps, Instance i) throws SchedulerException {
Model mo = i.getModel();
SynchronizedElementBuilder eb = new SynchronizedElementBuilder(mo);
List<Instance> parts = new ArrayList<>(partitions.size());
// nb of VMs
int nbVMs = i.getModel().getMapping().getNbVMs();
int nbNodes = i.getModel().getMapping().getNbNodes();
TIntIntHashMap vmPosition = new TIntIntHashMap(nbVMs);
TIntIntHashMap nodePosition = new TIntIntHashMap(nbNodes);
int partNumber = 0;
Set<VM> toLaunch = getVMsToLaunch(i);
for (Collection<Node> s : partitions) {
SubModel partModel = new SubModel(mo, eb, s, new HashSet<>(toLaunch.size() / partitions.size()));
parts.add(new Instance(partModel, new THashSet<>(), i.getOptConstraint()));
// VM Index
partModel.getMapping().fillVMIndex(vmPosition, partNumber);
// Node index
for (Node n : s) {
nodePosition.put(n.id(), partNumber);
}
partNumber++;
}
// Round-robin placement for the VMs to launch
int p = 0;
for (VM v : toLaunch) {
if (!parts.get(p).getModel().getMapping().addReadyVM(v)) {
throw new SplitException(parts.get(p).getModel(), "Unable to dispatch the VM to launch '" + v + "'");
}
vmPosition.put(v.id(), p);
p = (p + 1) % parts.size();
}
// Split the constraints
for (SatConstraint cstr : i.getSatConstraints()) {
if (!cstrMapper.split(cstr, i, parts, vmPosition, nodePosition)) {
throw new SplitException(i.getModel(), "Unable to split " + cstr);
}
}
return parts;
}
use of org.btrplace.model.Instance in project scheduler by btrplace.
the class SingleRunnerStatisticsTest method testInstantiate.
@Test
public void testInstantiate() {
Parameters ps = new DefaultParameters();
Model mo = new DefaultModel();
long st = System.currentTimeMillis();
List<SatConstraint> cstrs = new ArrayList<>();
Instance i = new Instance(mo, cstrs, new MinMTTR());
SingleRunnerStatistics stats = new SingleRunnerStatistics(ps, i, st);
Assert.assertEquals(stats.getStart(), st);
Assert.assertEquals(stats.getCoreBuildDuration(), -1);
Assert.assertEquals(stats.getSpecializationDuration(), -1);
Assert.assertEquals(stats.getInstance(), i);
Assert.assertEquals(stats.getNbManagedVMs(), -1);
Assert.assertEquals(stats.getParameters(), ps);
Assert.assertEquals(stats.getSolutions().size(), 0);
Assert.assertEquals(stats.completed(), false);
Assert.assertEquals(stats.getMetrics(), null);
stats.setCoreBuildDuration(12);
stats.setSpecialisationDuration(17);
stats.setNbManagedVMs(18);
stats.setCompleted(true);
Assert.assertEquals(stats.getCoreBuildDuration(), 12);
Assert.assertEquals(stats.getSpecializationDuration(), 17);
Assert.assertEquals(stats.getNbManagedVMs(), 18);
Assert.assertEquals(stats.completed(), true);
ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
SolutionStatistics sol = new SolutionStatistics(new Metrics(), plan);
stats.addSolution(sol);
Assert.assertEquals(stats.getSolutions().size(), 1);
Assert.assertEquals(stats.getSolutions().get(0), sol);
}
use of org.btrplace.model.Instance in project scheduler by btrplace.
the class CShareableResourceTest method testIssue170.
@Test
public void testIssue170() {
String buf = "{\"model\": {\"mapping\": {\"readyVMs\": [],\"onlineNodes\": {\"0\": {\"sleepingVMs\": [],\"runningVMs\": []},\"1\": {\"sleepingVMs\": [],\"runningVMs\": []},\"2\": {\"sleepingVMs\": [],\"runningVMs\": [15, 14, 13, 12,11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]},\"3\": {\"sleepingVMs\": [],\"runningVMs\": []}},\"offlineNodes\": []},\"attributes\": {\"nodes\": {},\"vms\": {\"11\": {\"migrate\": 1},\"12\": {\"migrate\": 1},\"13\": {\"migrate\": 1},\"14\": {\"migrate\": 1},\"15\": {\"migrate\": 1},\"0\": {\"migrate\": 1},\"1\": {\"migrate\": 1},\"2\": {\"migrate\": 1},\"3\": {\"migrate\": 1},\"4\": {\"migrate\": 1},\"5\": {\"migrate\": 1},\"6\": {\"migrate\": 2},\"7\": {\"migrate\": 1},\"8\": {\"migrate\": 1},\"9\": {\"migrate\": 1},\"10\": {\"migrate\": 1}}},\"views\": [{\"defConsumption\": 0,\"nodes\": {\"0\": 239094,\"1\": 111355,\"2\": 239725,\"3\": 110774},\"rcId\": \"memory\",\"id\": \"shareableResource\",\"defCapacity\": 0,\"vms\": {\"11\": 1082,\"12\": 1082,\"13\": 1082,\"14\": 1082,\"15\": 1082,\"0\": 1082,\"1\": 1082,\"2\": 1082,\"3\": 1082,\"4\": 1082,\"5\": 1082,\"6\": 1082,\"7\": 1082,\"8\": 1082,\"9\": 1082,\"10\": 1082}}, {\"defConsumption\": 0,\"nodes\": {\"0\": 63913,\"1\": 61663,\"2\": 67200,\"3\": 61620},\"rcId\": \"cpu\",\"id\": \"shareableResource\",\"defCapacity\": 0,\"vms\": {\"11\": 1271,\"12\": 1263,\"13\": 1257,\"14\": 1243,\"15\": 1253,\"0\": 1252,\"1\": 1238,\"2\": 1236,\"3\": 1253,\"4\": 1257,\"5\": 1244,\"6\": 1255,\"7\": 1251,\"8\": 1244,\"9\": 1240,\"10\": 1246}}, {\"defConsumption\": 0,\"nodes\": {\"0\": 7498,\"1\": 6854,\"2\": 7560,\"3\": 7560},\"rcId\": \"controller_cpu\",\"id\": \"shareableResource\",\"defCapacity\": 0,\"vms\": {\"11\": 431,\"12\": 435,\"13\": 432,\"14\": 423,\"15\": 430,\"0\": 430,\"1\": 420,\"2\": 425,\"3\": 430,\"4\": 429,\"5\": 425,\"6\": 431,\"7\": 429,\"8\": 424,\"9\": 426,\"10\": 428}}]},\"constraints\": [{\"rc\": \"cpu\",\"amount\": 26912,\"nodes\": [0],\"continuous\": false,\"id\": \"resourceCapacity\"}, {\"rc\": \"controller_cpu\",\"amount\": 5608,\"nodes\": [0],\"continuous\": false,\"id\": \"resourceCapacity\"}, {\"rc\": \"cpu\",\"amount\": 25093,\"nodes\": [1],\"continuous\": false,\"id\": \"resourceCapacity\"}, {\"rc\": \"controller_cpu\",\"amount\": 4964,\"nodes\": [1],\"continuous\": false,\"id\": \"resourceCapacity\"}, {\"rc\": \"cpu\",\"amount\": 29568,\"nodes\": [2],\"continuous\": false,\"id\": \"resourceCapacity\"}, {\"rc\": \"controller_cpu\",\"amount\": 5670,\"nodes\": [2],\"continuous\": false,\"id\": \"resourceCapacity\"}, {\"rc\": \"controller_cpu\",\"amount\": 516,\"vm\": 0,\"id\": \"preserve\"}, {\"rc\": \"controller_cpu\",\"amount\": 505,\"vm\": 1,\"id\": \"preserve\"}, {\"rc\": \"controller_cpu\",\"amount\": 510,\"vm\": 2,\"id\": \"preserve\"},{\"rc\": \"controller_cpu\",\"amount\": 516,\"vm\": 3,\"id\": \"preserve\"}, {\"rc\": \"controller_cpu\",\"amount\": 515,\"vm\": 4,\"id\": \"preserve\"}, {\"rc\": \"controller_cpu\",\"amount\": 510,\"vm\": 5,\"id\": \"preserve\"}, {\"rc\": \"controller_cpu\",\"amount\": 517,\"vm\": 6,\"id\": \"preserve\"}, {\"rc\": \"controller_cpu\",\"amount\": 515,\"vm\": 7,\"id\": \"preserve\"}, {\"rc\": \"controller_cpu\",\"amount\": 509,\"vm\": 8,\"id\": \"preserve\"}, {\"rc\": \"controller_cpu\",\"amount\": 511,\"vm\": 9,\"id\": \"preserve\"}, {\"rc\": \"controller_cpu\",\"amount\": 514,\"vm\": 10,\"id\": \"preserve\"}, {\"rc\": \"controller_cpu\",\"amount\": 517,\"vm\": 11,\"id\": \"preserve\"},{\"rc\": \"controller_cpu\",\"amount\": 522,\"vm\": 12,\"id\": \"preserve\"}, {\"rc\": \"controller_cpu\",\"amount\": 519,\"vm\": 13,\"id\": \"preserve\"}, {\"rc\": \"controller_cpu\",\"amount\": 508,\"vm\": 14,\"id\": \"preserve\"}, {\"rc\": \"controller_cpu\",\"amount\": 516,\"vm\": 15,\"id\": \"preserve\"}, {\"rc\": \"cpu\",\"amount\": 25059,\"nodes\": [3],\"continuous\": false,\"id\": \"resourceCapacity\"}, {\"rc\": \"controller_cpu\",\"amount\": 5670,\"nodes\": [3],\"continuous\": false,\"id\": \"resourceCapacity\"}],\"objective\": {\"id\": \"minimizeMigrations\"}}";
Instance i = JSON.readInstance(new StringReader(buf));
ChocoScheduler s = new DefaultChocoScheduler();
ReconfigurationPlan plan = s.solve(i);
Assert.assertNotNull(plan);
}
use of org.btrplace.model.Instance in project scheduler by btrplace.
the class CMinMigrationsTest method testNtnx.
@Test
public void testNtnx() {
String root = "src/test/resources/min-migrations.json";
Instance i = JSON.readInstance(new File(root));
i = new Instance(i.getModel(), i.getSatConstraints(), new MinMigrations());
ChocoScheduler s = new DefaultChocoScheduler();
s.doOptimize(true);
ReconfigurationPlan p = s.solve(i);
Assert.assertNotNull(p);
System.out.println(s.getStatistics());
System.out.println(p);
Assert.assertEquals(p.getActions().stream().filter(x -> x instanceof MigrateVM).count(), 1);
Assert.assertEquals(3, p.getDuration());
}
use of org.btrplace.model.Instance in project scheduler by btrplace.
the class LonelySplitterTest method simpleTest.
@Test
public void simpleTest() {
LonelySplitter splitter = new LonelySplitter();
List<Instance> instances = new ArrayList<>();
Model m0 = new DefaultModel();
m0.getMapping().addReadyVM(m0.newVM(1));
m0.getMapping().addRunningVM(m0.newVM(2), m0.newNode(1));
Model m1 = new DefaultModel();
m1.getMapping().addReadyVM(m1.newVM(3));
m1.getMapping().addSleepingVM(m1.newVM(4), m1.newNode(2));
m1.getMapping().addRunningVM(m1.newVM(5), m1.newNode(3));
instances.add(new Instance(m0, new ArrayList<>(), new MinMTTR()));
instances.add(new Instance(m1, new ArrayList<>(), new MinMTTR()));
TIntIntHashMap index = Instances.makeVMIndex(instances);
Set<VM> all = new HashSet<>(m0.getMapping().getAllVMs());
all.addAll(m1.getMapping().getAllVMs());
// Only VMs in m0
Lonely single = new Lonely(m0.getMapping().getAllVMs());
Assert.assertTrue(splitter.split(single, null, instances, index, new TIntIntHashMap()));
Assert.assertTrue(instances.get(0).getSatConstraints().contains(single));
Assert.assertFalse(instances.get(1).getSatConstraints().contains(single));
// All the VMs, test the split
Lonely among = new Lonely(all, false);
Assert.assertTrue(splitter.split(among, null, instances, index, new TIntIntHashMap()));
Assert.assertTrue(instances.get(0).getSatConstraints().contains(new Lonely(m0.getMapping().getAllVMs(), false)));
Assert.assertTrue(instances.get(1).getSatConstraints().contains(new Lonely(m1.getMapping().getAllVMs(), false)));
}
Aggregations