anuragaw commented on a change in pull request #3425: [WIP DO NOT MERGE] Better tracking host maintanence success and failure URL: https://github.com/apache/cloudstack/pull/3425#discussion_r350034746
########## File path: server/src/main/java/com/cloud/resource/ResourceManagerImpl.java ########## @@ -1286,12 +1288,31 @@ public Host maintain(final PrepareForMaintenanceCmd cmd) { throw new InvalidParameterValueException("Unable to find host with ID: " + hostId + ". Please specify a valid host ID."); } - if (_hostDao.countBy(host.getClusterId(), ResourceState.PrepareForMaintenance, ResourceState.ErrorInMaintenance) > 0) { - throw new InvalidParameterValueException("There are other servers in PrepareForMaintenance OR ErrorInMaintenance STATUS in cluster " + host.getClusterId()); + final ResourceState hostState = host.getResourceState(); + if (hostState == ResourceState.Maintenance || hostState == ResourceState.PrepareForMaintenance || + hostState == ResourceState.ErrorInPrepareForMaintenance) { + throw new CloudRuntimeException("Host is already in state " + hostState + ". Cannot recall for maintenance until resolved."); + } + + if (_hostDao.countBy(host.getClusterId(), ResourceState.PrepareForMaintenance, ResourceState.ErrorInPrepareForMaintenance) > 0) { + throw new CloudRuntimeException("There are other servers attempting migrations for maintenance. " + + "Found hosts in PrepareForMaintenance OR ErrorInPrepareForMaintenance STATUS in cluster " + host.getClusterId()); } if (_storageMgr.isLocalStorageActiveOnHost(host.getId())) { - throw new InvalidParameterValueException("There are active VMs using the host's local storage pool. Please stop all VMs on this host that use local storage."); + throw new CloudRuntimeException("There are active VMs using the host's local storage pool. Please stop all VMs on this host that use local storage."); + } + List<VMInstanceVO> migratingInVMs = _vmDao.findByHostInStates(hostId, State.Migrating); + if (migratingInVMs.size() > 0) { + throw new CloudRuntimeException("Host contains incoming VMs migrating. Please wait for them to complete before putting to maintenance."); + } + + if (_vmDao.findByHostInStates(hostId, State.Starting, State.Stopping).size() > 0) { + throw new CloudRuntimeException("Host contains VMs in starting/stopping state. Please wait for them to complete before putting to maintenance."); + } + + if (_vmDao.findByHostInStates(hostId, State.Error, State.Unknown).size() > 0) { Review comment: Covers all VMs. Just searches by host and state not VM type. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services