protected Map<String, HostVmStateReportEntry> getHostVmStateReport() { Map<String, HostVmStateReportEntry> states = new HashMap<String, HostVmStateReportEntry>(); if (hostId != null) { final List<? extends VMInstanceVO> vms = vmDao.listByHostId(hostId); for (VMInstanceVO vm : vms) { states.put( vm.getInstanceName(), new HostVmStateReportEntry( vm.getPowerState(), "host-" + hostId ) ); } } return states; }
@Override public Boolean doInTransaction(TransactionStatus status) { boolean needToUpdate = false; VMInstanceVO instance = findById(instanceId); if (instance != null) { Long savedPowerHostId = instance.getPowerHostId(); if (instance.getPowerState() != powerState || savedPowerHostId == null || savedPowerHostId.longValue() != powerHostId) { instance.setPowerState(powerState); instance.setPowerHostId(powerHostId); instance.setPowerStateUpdateCount(1); instance.setPowerStateUpdateTime(DateUtil.currentGMTTime()); needToUpdate = true; update(instanceId, instance); } else { // to reduce DB updates, consecutive same state update for more than 3 times if (instance.getPowerStateUpdateCount() < MAX_CONSECUTIVE_SAME_STATE_UPDATE_COUNT) { instance.setPowerStateUpdateCount(instance.getPowerStateUpdateCount() + 1); instance.setPowerStateUpdateTime(DateUtil.currentGMTTime()); needToUpdate = true; update(instanceId, instance); } } } return needToUpdate; } });
switch (vm.getPowerState()) { case PowerOn: handlePowerOnReportWithNoPendingJobsOnVM(vm);
final VMInstanceVO vm = _vmDao.findById(vmId); assert vm != null; if (vm.getPowerState() == PowerState.PowerOn) { handlePowerOnReportWithNoPendingJobsOnVM(vm); } else {