mirror of https://github.com/apache/cloudstack.git
Merge pull request #909 from DaanHoogland/RESMO-CLOUDSTACK-8848
CLOUDSTACK-8848 ensure power state is up to date for missing PowerState handlingadded a null guard to @resmo's #885 A unit test or two would be nice as well but as this is a blocker I want to get it to review asap. @koushik-das @wilderrodrigues @anshul1886 @karuturi @remibergsma you all commented on the original, please have a look. @bhaisaab welcome to comment as well. * pr/909: CLOUDSTACK-8848: added null pointer guard to new public method CLOUDSTACK-8848: ensure power state is up to date when handling missing VMs in powerReport Signed-off-by: Rajani Karuturi <rajani.karuturi@citrix.com>
This commit is contained in:
commit
99059e2212
|
|
@ -24,13 +24,13 @@ import java.util.Map;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||
import org.apache.cloudstack.framework.messagebus.MessageBus;
|
||||
import org.apache.cloudstack.framework.messagebus.PublishScope;
|
||||
|
||||
import com.cloud.agent.api.HostVmStateReportEntry;
|
||||
import com.cloud.utils.DateUtil;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStateSync {
|
||||
|
|
@ -111,7 +111,19 @@ public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStat
|
|||
|
||||
for (VMInstanceVO instance : vmsThatAreMissingReport) {
|
||||
|
||||
Date vmStateUpdateTime = instance.getUpdateTime();
|
||||
// Make sure powerState is up to date for missing VMs
|
||||
try {
|
||||
if (!_instanceDao.isPowerStateUpToDate(instance.getId())) {
|
||||
s_logger.warn("Detected missing VM but power state is outdated, wait for another process report run for VM id: " + instance.getId());
|
||||
_instanceDao.resetVmPowerStateTracking(instance.getId());
|
||||
continue;
|
||||
}
|
||||
} catch (CloudRuntimeException e) {
|
||||
s_logger.warn("Checked for missing powerstate of a none existing vm", e);
|
||||
continue;
|
||||
}
|
||||
|
||||
Date vmStateUpdateTime = instance.getPowerStateUpdateTime();
|
||||
if (vmStateUpdateTime == null) {
|
||||
s_logger.warn("VM state was updated but update time is null?! vm id: " + instance.getId());
|
||||
vmStateUpdateTime = currentTime;
|
||||
|
|
|
|||
|
|
@ -138,4 +138,6 @@ public interface VMInstanceDao extends GenericDao<VMInstanceVO, Long>, StateDao<
|
|||
HashMap<String, Long> countVgpuVMs(Long dcId, Long podId, Long clusterId);
|
||||
|
||||
VMInstanceVO findVMByHostNameInZone(String hostName, long zoneId);
|
||||
|
||||
boolean isPowerStateUpToDate(long instanceId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -804,6 +804,15 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowerStateUpToDate(final long instanceId) {
|
||||
VMInstanceVO instance = findById(instanceId);
|
||||
if(instance == null) {
|
||||
throw new CloudRuntimeException("checking power state update count on non existing instance " + instanceId);
|
||||
}
|
||||
return instance.getPowerStateUpdateCount() < MAX_CONSECUTIVE_SAME_STATE_UPDATE_COUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetVmPowerStateTracking(final long instanceId) {
|
||||
Transaction.execute(new TransactionCallbackNoReturn() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue