server: fix host anti-affinity when start batch vms (#6002)

This commit is contained in:
Wei Zhou 2022-02-21 09:54:03 +01:00 committed by GitHub
parent b8ce07475d
commit 5d1e54a4ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,6 +16,7 @@
// under the License.
package org.apache.cloudstack.affinity;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -85,7 +86,7 @@ public class HostAntiAffinityProcessor extends AffinityProcessorBase implements
if (s_logger.isDebugEnabled()) {
s_logger.debug("Added host " + groupVM.getHostId() + " to avoid set, since VM " + groupVM.getId() + " is present on the host");
}
} else if (VirtualMachine.State.Stopped.equals(groupVM.getState()) && groupVM.getLastHostId() != null) {
} else if (Arrays.asList(VirtualMachine.State.Starting, VirtualMachine.State.Stopped).contains(groupVM.getState()) && groupVM.getLastHostId() != null) {
long secondsSinceLastUpdate = (DateUtil.currentGMTTime().getTime() - groupVM.getUpdateTime().getTime()) / 1000;
if (secondsSinceLastUpdate < _vmCapacityReleaseInterval) {
avoid.addHost(groupVM.getLastHostId());