mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-2102: Anti-Affinity - Even after reserved capacity has been released for a Vm in "Stopped" state , we are not allowed to deploy new Vms as part of same anti-affinity group in the last_host_id where the stopped Vm was running.
Changes: Do not add the last_host_id of a Stopped VM to avoid set, if the VM has been stopped for more that capacity.skip.counting.hours time limit
This commit is contained in:
parent
5646f5e977
commit
55c1e282e3
|
|
@ -17,17 +17,24 @@
|
|||
package org.apache.cloudstack.affinity;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
|
||||
import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.exception.AffinityConflictException;
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
|
@ -46,7 +53,10 @@ public class HostAntiAffinityProcessor extends AffinityProcessorBase implements
|
|||
protected AffinityGroupDao _affinityGroupDao;
|
||||
@Inject
|
||||
protected AffinityGroupVMMapDao _affinityGroupVMMapDao;
|
||||
|
||||
private int _vmCapacityReleaseInterval;
|
||||
@Inject
|
||||
protected ConfigurationDao _configDao;
|
||||
|
||||
@Override
|
||||
public void process(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan,
|
||||
ExcludeList avoid)
|
||||
|
|
@ -76,12 +86,14 @@ public class HostAntiAffinityProcessor extends AffinityProcessorBase implements
|
|||
}
|
||||
} else if (VirtualMachine.State.Stopped.equals(groupVM.getState())
|
||||
&& groupVM.getLastHostId() != null) {
|
||||
avoid.addHost(groupVM.getLastHostId());
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Added host " + groupVM.getLastHostId() + " to avoid set, since VM "
|
||||
+ groupVM.getId() + " is present on the host, in Stopped state");
|
||||
long secondsSinceLastUpdate = (DateUtil.currentGMTTime().getTime() - groupVM.getUpdateTime().getTime()) / 1000;
|
||||
if (secondsSinceLastUpdate < _vmCapacityReleaseInterval) {
|
||||
avoid.addHost(groupVM.getLastHostId());
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Added host " + groupVM.getLastHostId() + " to avoid set, since VM "
|
||||
+ groupVM.getId() + " is present on the host, in Stopped state but has reserved capacity");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -89,5 +101,12 @@ public class HostAntiAffinityProcessor extends AffinityProcessorBase implements
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
_vmCapacityReleaseInterval = NumbersUtil.parseInt(_configDao.getValue(Config.CapacitySkipcountingHours.key()),3600);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue