Skip to content

Instantly share code, notes, and snippets.

@tudang
Last active December 19, 2015 01:19
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/5874954 to your computer and use it in GitHub Desktop.
Save tudang/5874954 to your computer and use it in GitHub Desktop.
@Test
public void testOverbook() throws SolverException {
Model model = new DefaultModel();
ShareableResource cpu = new ShareableResource("cpu", 8, 1);
model.attach(cpu);
int NODE = 256;
for (int i = 0; i < NODE; i++) {
model.getMapping().addOnlineNode(model.newNode());
}
Collection<VM> vms = new ArrayList<>();
for (int i = 0; i < 32*NODE; i++) {
VM e = model.newVM();
vms.add(e);
model.getMapping().addReadyVM(e);
}
Running run = new Running(vms);
Overbook overbook = new Overbook(model.getNodes(), "cpu", 4);
Collection<SatConstraint> VMconstraints = new ArrayList<>();
VMconstraints.add(overbook);
VMconstraints.add(run);
ChocoReconfigurationAlgorithm cra = new DefaultChocoReconfigurationAlgorithm();
ReconfigurationPlan plan = cra.solve(model, VMconstraints);
Assert.assertNotNull(plan);
Mapping mapping = plan.getResult().getMapping();
Set<Node> onlineNodes = mapping.getOnlineNodes();
Set<VM> runningVMs = mapping.getRunningVMs();
ShareableResource sr = (ShareableResource) model.getView("ShareableResource.cpu");
double capacity = sr.sumCapacities(onlineNodes, true) * overbook.getRatio();
double used = sr.sumConsumptions(runningVMs, true);
System.out.printf("%f %f %f", capacity, used, used / capacity * 100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment