use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class ReconfigurationPlanConverter method fromJSON.
@Override
public ReconfigurationPlan fromJSON(JSONObject ob) throws JSONConverterException {
checkKeys(ob, ORIGIN_LABEL, ACTIONS_LABEL);
Model m = mc.fromJSON((JSONObject) ob.get(ORIGIN_LABEL));
ActionConverter ac = new ActionConverter(m);
ReconfigurationPlan plan = new DefaultReconfigurationPlan(m);
for (Action a : ac.listFromJSON((JSONArray) ob.get(ACTIONS_LABEL))) {
plan.add(a);
}
return plan;
}
use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class ReconfigurationPlanConverterTest method testConversion.
@Test
public void testConversion() throws JSONConverterException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Mapping map = mo.getMapping();
map.addOnlineNode(n1);
map.addOfflineNode(n2);
map.addOnlineNode(n3);
map.addReadyVM(vm1);
map.addRunningVM(vm2, n1);
map.addRunningVM(vm3, n1);
map.addSleepingVM(vm4, n3);
map.addRunningVM(vm5, n3);
ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
plan.add(new MigrateVM(vm2, n1, n3, 0, 1));
plan.add(new BootVM(vm1, n3, 1, 2));
plan.add(new BootNode(n2, 2, 5));
plan.add(new Allocate(vm1, n3, "foo", 5, 3, 5));
ReconfigurationPlanConverter rcp = new ReconfigurationPlanConverter();
String j = rcp.toJSONString(plan);
ReconfigurationPlan p2 = rcp.fromJSON(j);
Assert.assertEquals(p2, plan);
}
use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class CAmongTest method testContinuousWithNotAlreadySatisfied.
@Test
public void testContinuousWithNotAlreadySatisfied() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2, n3, n4).run(n1, vm1).run(n2, vm2).run(n3, vm3).ready(vm4, vm5);
Set<VM> vms = new HashSet<>(Arrays.asList(vm1, vm2, vm5));
Collection<Node> s1 = new HashSet<>(Arrays.asList(n1, n2));
Collection<Node> s2 = new HashSet<>(Arrays.asList(n3, n4));
Collection<Collection<Node>> pGrps = new HashSet<>(Arrays.asList(s1, s2));
Among a = new Among(vms, pGrps);
a.setContinuous(true);
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Running.newRunning(map.getAllVMs()));
cstrs.add(new Fence(vm2, Collections.singleton(n3)));
cstrs.add(a);
ChocoScheduler cra = new DefaultChocoScheduler();
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNull(p);
}
use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class CAmongTest method testWithNoSolution.
/**
* No solution because constraints force to spread the VMs among 2 groups.
*
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void testWithNoSolution() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2, n3, n4).run(n1, vm1).run(n2, vm2, vm3).ready(vm4, vm5);
Set<VM> vms = new HashSet<>(Arrays.asList(vm1, vm2, vm5));
Collection<Node> s = new HashSet<>(Arrays.asList(n1, n2));
Collection<Node> s2 = new HashSet<>(Arrays.asList(n3, n4));
Collection<Collection<Node>> pGrps = new HashSet<>(Arrays.asList(s, s2));
Among a = new Among(vms, pGrps);
a.setContinuous(false);
ChocoScheduler cra = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Running.newRunning(map.getAllVMs()));
cstrs.add(new Fence(vm2, Collections.singleton(n3)));
cstrs.add(new Fence(vm1, Collections.singleton(n1)));
cstrs.add(a);
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNull(p);
}
use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class CAmongTest method testWithGroupChange.
@Test
public void testWithGroupChange() throws SchedulerException {
Model mo = new DefaultModel();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
VM vm3 = mo.newVM();
VM vm4 = mo.newVM();
VM vm5 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
Node n3 = mo.newNode();
Node n4 = mo.newNode();
Mapping map = mo.getMapping().on(n1, n2, n3, n4).run(n1, vm1).run(n2, vm2, vm3).ready(vm4, vm5);
Set<VM> vms = new HashSet<>(Arrays.asList(vm1, vm2, vm5));
Collection<Node> s1 = new HashSet<>(Arrays.asList(n1, n2));
Collection<Node> s2 = new HashSet<>(Arrays.asList(n3, n4));
Collection<Collection<Node>> pGrps = Arrays.asList(s1, s2);
Among a = new Among(vms, pGrps);
a.setContinuous(false);
ChocoScheduler cra = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.addAll(Running.newRunning(map.getAllVMs()));
cstrs.add(new Fence(vm2, s2));
cstrs.add(a);
ReconfigurationPlan p = cra.solve(mo, cstrs);
Assert.assertNotNull(p);
// System.out.println(p);
// Assert.assertEquals(a.isSatisfied(p.getResult()), SatConstraint.Sat.SATISFIED);
}
Aggregations