use of org.btrplace.model.VM in project scheduler by btrplace.
the class CRunningCapacity method getMisPlacedVMs.
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
Mapping map = i.getModel().getMapping();
Set<VM> bad = new HashSet<>();
int remainder = cstr.getAmount();
for (Node n : cstr.getInvolvedNodes()) {
remainder -= map.getRunningVMs(n).size();
if (remainder < 0) {
for (Node n2 : cstr.getInvolvedNodes()) {
bad.addAll(map.getRunningVMs(n2));
}
return bad;
}
}
return bad;
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class CSequentialVMTransitions method inject.
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
List<VM> seq = cstr.getInvolvedVMs();
List<VMTransition> ams = new ArrayList<>();
for (VM vmId : seq) {
VMTransition am = rp.getVMAction(vmId);
// Avoid VMs with no action model or Transition that do not denotes a state transition
if (am == null || am instanceof StayAwayVM || am instanceof RelocatableVM) {
continue;
}
ams.add(am);
}
if (ams.size() > 1) {
Iterator<VMTransition> ite = ams.iterator();
VMTransition prev = ite.next();
Model csp = rp.getModel();
while (ite.hasNext()) {
VMTransition cur = ite.next();
csp.post(csp.arithm(prev.getEnd(), "<=", cur.getStart()));
prev = cur;
}
}
return true;
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class CSplit method getMisPlacedVMs.
@Override
public Set<VM> getMisPlacedVMs(Instance i) {
Mapping map = i.getModel().getMapping();
List<Collection<VM>> groups = new ArrayList<>(cstr.getSets());
// Bad contains the VMs on nodes that host VMs from different groups.
Set<VM> bad = new HashSet<>();
for (Collection<VM> grp : groups) {
for (VM vm : grp) {
if (map.isRunning(vm)) {
Node n = map.getVMLocation(vm);
Set<VM> allOnN = map.getRunningVMs(n);
for (VM vmOnN : allOnN) {
if (inOtherGroup(groups, grp, vmOnN)) {
// The VM belong to another group
bad.add(vm);
bad.add(vmOnN);
}
}
}
}
}
return bad;
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class AllowAllConstraintCheckerTest method testMyVMsTracking.
@Test(dependsOnMethods = "testInstantiation")
public void testMyVMsTracking() {
SatConstraint cstr = mock(SatConstraint.class);
Model mo = new DefaultModel();
List<VM> vms = Util.newVMs(mo, 10);
List<Node> ns = Util.newNodes(mo, 10);
when(cstr.getInvolvedNodes()).thenReturn(ns);
when(cstr.getInvolvedVMs()).thenReturn(vms);
AllowAllConstraintChecker<SatConstraint> c = new AllowAllConstraintChecker<>(cstr);
// VM1 (one of the involved vms) has to be removed to be substituted by vms.get(0)0
c.consume(new SubstitutedVMEvent(vms.get(0), vms.get(9)));
Assert.assertTrue(c.getVMs().contains(vms.get(9)));
Assert.assertFalse(c.getVMs().contains(vms.get(0)));
// VM5 is not involved, no removal
VM v = mo.newVM();
c.consume(new SubstitutedVMEvent(vms.get(0), v));
Assert.assertFalse(c.getVMs().contains(vms.get(0)));
Assert.assertFalse(c.getVMs().contains(v));
}
use of org.btrplace.model.VM in project scheduler by btrplace.
the class NamingServiceTest method testEqualsAndHashCode.
@Test(dependsOnMethods = { "testRegisterAndGets" })
public void testEqualsAndHashCode() {
NamingService<VM> ns = NamingService.newVMNS();
Assert.assertEquals(ns, ns);
Model mo = new DefaultModel();
VM v = mo.newVM();
NamingService<VM> ns2 = NamingService.newVMNS();
Assert.assertEquals(ns, ns2);
Assert.assertEquals(ns.hashCode(), ns2.hashCode());
ns2.register(v, "vm0");
Assert.assertNotEquals(ns, ns2);
}
Aggregations