public void deleteComputer(final CloudComputer computer) {
logger.info("Scheduling delete of computer ({}).", computer);
solutionBusiness.doProblemFactChange(new ProblemFactChange() {
public void doChange(ScoreDirector scoreDirector) {
CloudBalance cloudBalance = (CloudBalance) scoreDirector.getWorkingSolution();
// First remove the planning fact from all planning entities that use it
for (CloudProcess process : cloudBalance.getProcessList()) {
if (ObjectUtils.equals(process.getComputer(), computer)) {
// TODO HACK we are removing it because it becomes uninitialized,
// which means it has to be retracted
// This is nonsense from a ProblemFactChange point of view, FIXME!
scoreDirector.beforeEntityRemoved(process);
process.setComputer(null);
scoreDirector.afterEntityRemoved(process);
}
}
// Next remove it the planning fact itself
for (Iterator<CloudComputer> it = cloudBalance.getComputerList().iterator(); it.hasNext(); ) {
CloudComputer workingComputer = it.next();
if (ObjectUtils.equals(workingComputer, computer)) {
scoreDirector.beforeProblemFactRemoved(workingComputer);
it.remove(); // remove from list
scoreDirector.beforeProblemFactRemoved(workingComputer);