
org.btrplace.scheduler.choco.constraint.CRunning Maven / Gradle / Ivy
/*
* Copyright (c) 2016 University Nice Sophia Antipolis
*
* This file is part of btrplace.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
package org.btrplace.scheduler.choco.constraint;
import org.btrplace.model.Instance;
import org.btrplace.model.Mapping;
import org.btrplace.model.VM;
import org.btrplace.model.constraint.Running;
import org.btrplace.scheduler.SchedulerException;
import org.btrplace.scheduler.choco.Parameters;
import org.btrplace.scheduler.choco.ReconfigurationProblem;
import java.util.Collections;
import java.util.Set;
/**
* Naive implementation of {@link Running}.
* This constraint is just a stub to be consistent with the model. It does not state any constraint
* as the state has already been expressed inside {@link ReconfigurationProblem}.
*
* @author Fabien Hermenier
*/
public class CRunning implements ChocoConstraint {
private Running cstr;
/**
* Make a new constraint.
*
* @param c the constraint to rely on
*/
public CRunning(Running c) {
cstr = c;
}
@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) throws SchedulerException {
if (cstr.isContinuous() && !cstr.getChecker().startsWith(rp.getSourceModel())) {
rp.getLogger().error("Constraint {} is not satisfied initially", cstr);
return false;
}
return true;
}
@Override
public Set getMisPlacedVMs(Instance i) {
VM vm = cstr.getInvolvedVMs().iterator().next();
Mapping map = i.getModel().getMapping();
if (!map.isRunning(vm)) {
return Collections.singleton(vm);
}
return Collections.emptySet();
}
@Override
public String toString() {
return cstr.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy