use of org.btrplace.plan.event.VMEvent in project scheduler by btrplace.
the class ShareableResourceFuzzer method setDemand.
private void setDemand(ReconfigurationPlan p, ShareableResource rc, VM v, int c) {
if (c == rc.getConsumption(v)) {
return;
}
boolean found = false;
for (Action a : p.getActions()) {
if (a instanceof VMEvent && ((VMEvent) a).getVM().equals(v) && a instanceof RunningVMPlacement) {
AllocateEvent ev = new AllocateEvent(v, id, c);
Action.Hook h = Action.Hook.PRE;
if (a instanceof MigrateVM) {
h = Action.Hook.POST;
}
// For a migrated VM, we allocate once the migration over
a.addEvent(h, ev);
found = true;
break;
}
}
if (!found && p.getOrigin().getMapping().isRunning(v)) {
int d = 1;
if (p.getDuration() > 0) {
d = rnd.nextInt(p.getDuration());
}
p.add(new Allocate(v, p.getOrigin().getMapping().getVMLocation(v), id, c, d, d + 1));
p.getOrigin().getAttributes().put(v, "allocate", 1);
}
}
use of org.btrplace.plan.event.VMEvent in project scheduler by btrplace.
the class InstanceConverter method toInstance.
public static Instance toInstance(ReconfigurationPlan p) {
Model mo = p.getOrigin().copy();
List<SatConstraint> cstrs = new ArrayList<>();
Set<VM> knownVMs = new HashSet<>();
Set<Node> knownNodes = new HashSet<>();
for (Action a : p.getActions()) {
if (a instanceof NodeEvent) {
Node n = ((NodeEvent) a).getNode();
knownNodes.add(n);
cstrs.add(new Schedule(n, a.getStart(), a.getEnd()));
if (a instanceof BootNode) {
cstrs.add(new Online(n));
} else if (a instanceof ShutdownNode) {
cstrs.add(new Offline(n));
}
} else if (a instanceof VMEvent) {
VM v = ((VMEvent) a).getVM();
knownVMs.add(v);
cstrs.add(new Schedule(v, a.getStart(), a.getEnd()));
if (a instanceof BootVM) {
cstrs.add(new Running(v));
cstrs.add(new Fence(v, ((BootVM) a).getDestinationNode()));
} else if (a instanceof MigrateVM) {
cstrs.add(new Fence(v, ((MigrateVM) a).getDestinationNode()));
cstrs.add(new Running(v));
} else if (a instanceof ShutdownVM) {
cstrs.add(new Ready(v));
} else if (a instanceof SuspendVM) {
cstrs.add(new Sleeping(v));
} else if (a instanceof ResumeVM) {
cstrs.add(new Running(v));
cstrs.add(new Fence(v, ((ResumeVM) a).getDestinationNode()));
} else if (a instanceof Allocate) {
cstrs.add(new Preserve(v, ((Allocate) a).getResourceId(), ((Allocate) a).getAmount()));
cstrs.add(new Fence(v, ((Allocate) a).getHost()));
}
}
// Catch the allocate events
for (Event e : a.getEvents(Action.Hook.PRE)) {
if (e instanceof AllocateEvent) {
cstrs.add(new Preserve(((AllocateEvent) e).getVM(), ((AllocateEvent) e).getResourceId(), ((AllocateEvent) e).getAmount()));
}
}
for (Event e : a.getEvents(Action.Hook.POST)) {
if (e instanceof AllocateEvent) {
cstrs.add(new Preserve(((AllocateEvent) e).getVM(), ((AllocateEvent) e).getResourceId(), ((AllocateEvent) e).getAmount()));
}
}
}
// State maintenance
for (Node n : mo.getMapping().getAllNodes()) {
if (knownNodes.contains(n)) {
continue;
}
if (mo.getMapping().isOnline(n)) {
cstrs.add(new Online(n));
} else if (mo.getMapping().isOffline(n)) {
cstrs.add(new Offline(n));
}
}
mo.getMapping().getAllVMs().stream().filter(v -> !knownVMs.contains(v)).forEach(v -> {
if (mo.getMapping().isReady(v)) {
cstrs.add(new Ready(v));
} else if (mo.getMapping().isRunning(v)) {
cstrs.add(new Running(v));
cstrs.add(new Fence(v, mo.getMapping().getVMLocation(v)));
} else if (mo.getMapping().isSleeping(v)) {
cstrs.add(new Sleeping(v));
cstrs.add(new Fence(v, mo.getMapping().getVMLocation(v)));
}
});
return new Instance(mo, cstrs, new MinMTTR());
}
use of org.btrplace.plan.event.VMEvent in project scheduler by btrplace.
the class Actions method eval.
@Override
public Set<Action> eval(Context mo, Object... args) {
VM v = (VM) args[0];
if (v == null) {
throw new UnsupportedOperationException();
}
Set<Action> s = new HashSet<>();
for (Action a : mo.getPlan()) {
if (a instanceof VMEvent) {
if (((VMEvent) a).getVM().equals(v)) {
s.add(a);
}
}
}
return s;
}
Aggregations