Skip to content

Instantly share code, notes, and snippets.

@tudang
Created May 17, 2013 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tudang/5599099 to your computer and use it in GitHub Desktop.
Save tudang/5599099 to your computer and use it in GitHub Desktop.
Solution should be: 0:1 Migrate(vm2, n1, n4); 0:1 Migrate(vm3, n2, n4); 1:2 Migrate(vm4, n2, n1); 2:3 Shutdown(n2);
@Test
public void spreadBasicEvaluation() {
Mapping map = new MappingBuilder().on(n1, n2, n3, n4)
.run(n1, vm1, vm2)
.run(n2, vm3, vm4)
.run(n3, vm5, vm6).build();
ShareableResource cpu = new ShareableResource("cpu", 1);
cpu.set(n1, 4);
cpu.set(n2, 4);
cpu.set(n3, 2);
cpu.set(n4, 4);
cpu.set(vm2, 2);
ShareableResource mem = new ShareableResource("mem", 1);
mem.set(n1, 4);
mem.set(n2, 4);
mem.set(n3, 4);
mem.set(n4, 2);
mem.set(vm4, 2);
mem.set(vm6, 2);
Model model = new DefaultModel(map);
model.attach(cpu);
model.attach(mem);
log.info(model.toString());
Set<SatConstraint> ctrs = new HashSet<SatConstraint>();
Set<SatConstraint> ctrsC = new HashSet<SatConstraint>();
Set<UUID> vms1 = new HashSet<UUID>(Arrays.asList(vm1, vm3, vm5));
Set<UUID> vms2 = new HashSet<UUID>(Arrays.asList(vm2, vm4, vm6));
ctrs.add(new Spread(vms1, false));
ctrs.add(new Spread(vms2, false));
ctrsC.add(new Spread(vms1));
ctrsC.add(new Spread(vms2));
Offline off = new Offline(new HashSet<UUID>() {{
add(n2);
}});
ctrs.add(off);
ctrsC.add(off);
ChocoReconfigurationAlgorithm cra = new DefaultChocoReconfigurationAlgorithm();
try {
ReconfigurationPlan dp = cra.solve(model, ctrs);
if (!satisfy(dp, ctrsC)) {
ReconfigurationPlan cp = cra.solve(model, ctrsC);
if (!satisfy(cp, ctrsC)) {
log.info("Not found continuous plan");
} else log.info(cp.toString());
}
} catch (SolverException e) {
e.printStackTrace();
}
}
private boolean satisfy(ReconfigurationPlan dp, Set<SatConstraint> constraints) {
for (SatConstraint sc : constraints) {
if (sc.isSatisfied(dp)) {
log.info("Satisfy: " + sc);
} else {
log.info("Not Satisfy: " + sc);
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment