You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2019/07/01 10:34:21 UTC

[GitHub] [cloudstack] anuragaw commented on a change in pull request #3425: [WIP DO NOT MERGE] Better tracking host maintanence success and failure

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_r298980818
 
 

 ##########
 File path: server/src/main/java/com/cloud/resource/ResourceManagerImpl.java
 ##########
 @@ -1353,46 +1353,57 @@ protected boolean setHostIntoMaintenance(HostVO host) throws NoTransitionExcepti
         return true;
     }
 
-    protected boolean setHostIntoPrepareForMaintenanceWithErrors(HostVO host) throws NoTransitionException {
-        s_logger.debug("Host " + host.getUuid() + " entering in PrepareForMaintainenceWithErrors state");
+    protected boolean setHostIntoPrepareForMaintenanceWithErrors(HostVO host, List<VMInstanceVO> errorVms) throws NoTransitionException {
+        s_logger.debug("Host " + host.getUuid() + " entering in PrepareForMaintenanceWithErrors state");
+        configureVncAccessForKVMHostFailedMigrations(host, errorVms);
         resourceStateTransitTo(host, ResourceState.Event.UnableToMigrate, _nodeId);
         return true;
     }
 
+    protected boolean setHostIntoPrepareForMaintenanceAfterErrorsFixed(HostVO host) throws NoTransitionException {
+        s_logger.debug("Host " + host.getUuid() + " entering in PrepareForMaintenance state as any previous corrections have been fixed");
+        resourceStateTransitTo(host, ResourceState.Event.ErrorsCorrected, _nodeId);
+        return true;
+    }
+
     /**
      * Return true if host goes into Maintenance mode, only when:
      * - No Running, Migrating or Failed migrations (host_id = last_host_id) for the host
      */
-    protected boolean attemptMaintain(HostVO host) throws NoTransitionException {
+    private boolean attemptMaintain(HostVO host) throws NoTransitionException {
         final long hostId = host.getId();
 
         if (CollectionUtils.isEmpty(_vmDao.findByHostInStates(hostId, State.Migrating, State.Running, State.Starting, State.Stopping, State.Error, State.Unknown))) {
             return setHostIntoMaintenance(host);
         }
 
         final List<VMInstanceVO> allVmsOnHost = _vmDao.listByHostId(hostId);
-        final List<VMInstanceVO> migratingVms = _vmDao.listVmsMigratingFromHost(hostId);
-        final List<VMInstanceVO> failedMigrations = _vmDao.listNonMigratingVmsByHostEqualsLastHost(hostId);
-        boolean hasPendingWorkForVMs = false;
+        boolean hasPendingMigrationWorks = false;
         for (VMInstanceVO vmInstanceVO : allVmsOnHost) {
-            if (_haMgr.hasPendingHaWork(vmInstanceVO.getId())) {
-                hasPendingWorkForVMs = true;
+            if (_haMgr.hasPendingMigrationsWork(vmInstanceVO.getId())) {
+                hasPendingMigrationWorks = true;
                 break;
             }
         }
 
-        if (!hasPendingWorkForVMs) {
-            if ((CollectionUtils.isNotEmpty(_vmDao.findByHostInStates(hostId, State.Running)) && CollectionUtils.isEmpty(migratingVms)) ||
-                    (CollectionUtils.isEmpty(_vmDao.findByHostInStates(hostId, State.Running)) &&
-                        CollectionUtils.isNotEmpty(_vmDao.findByHostInStates(hostId, State.Unknown, State.Error, State.Shutdowned)))) {
-                return setHostIntoErrorInMaintenance(host, failedMigrations);
-            }
+        final List<VMInstanceVO> failedMigrations = new ArrayList<>(_vmDao.listNonMigratingVmsByHostEqualsLastHost(hostId));
+        final List<VMInstanceVO> errorVms = new ArrayList<>(_vmDao.findByHostInStates(hostId, State.Unknown, State.Error, State.Shutdowned));
+        final boolean hasMigratingVms = CollectionUtils.isNotEmpty(_vmDao.listVmsMigratingFromHost(hostId));
+        final boolean hasRunningVms = CollectionUtils.isNotEmpty(_vmDao.findByHostInStates(hostId, State.Running));
+        final boolean hasFailedMigrations = CollectionUtils.isNotEmpty(failedMigrations);
+        final boolean hasVmsInFailureStates = CollectionUtils.isNotEmpty(errorVms);
+        errorVms.addAll(failedMigrations);
+
+        if (!hasPendingMigrationWorks && (hasRunningVms || (!hasRunningVms && !hasMigratingVms && hasVmsInFailureStates))) {
+            return setHostIntoErrorInMaintenance(host, errorVms);
+        }
+
+        if ((hasVmsInFailureStates || hasFailedMigrations) && (hasPendingMigrationWorks || hasMigratingVms || CollectionUtils.isNotEmpty(_vmDao.findByHostInStates(hostId, State.Stopping)))) {
 
 Review comment:
   Good point. Doing it.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services