@@ -224,6 +224,18 @@ public void setHaPlanners(List<HAPlanner> haPlanners) {
224224 long _timeBetweenCleanups ;
225225 String _haTag = null ;
226226
227+ private boolean vmHasPendingHAJob (final List <HaWorkVO > pendingHaWorks , final VMInstanceVO vm ) {
228+ Optional <HaWorkVO > item = pendingHaWorks .stream ()
229+ .filter (h -> h .getInstanceId () == vm .getId ())
230+ .reduce ((first , second ) -> second );
231+ if (item .isPresent () && (item .get ().getTimesTried () < _maxRetries ||
232+ !item .get ().canScheduleNew (_timeBetweenFailures ))) {
233+ s_logger .debug (String .format ("Skipping HA on %s as there is already a running HA job for it" , vm ));
234+ return true ;
235+ }
236+ return false ;
237+ }
238+
227239 protected HighAvailabilityManagerImpl () {
228240 }
229241
@@ -278,12 +290,7 @@ public void scheduleRestartForVmsOnHost(final HostVO host, boolean investigate)
278290 sb .append (" Starting HA on the following VMs:" );
279291 // collect list of vm names for the alert email
280292 for (VMInstanceVO vm : vms ) {
281- Optional <HaWorkVO > item = pendingHaWorks .stream ()
282- .filter (h -> h .getInstanceId () == vm .getId ())
283- .reduce ((first , second ) -> second );
284- if (item .isPresent () && (item .get ().getTimesTried () < _maxRetries ||
285- !item .get ().canScheduleNew (_timeBetweenFailures ))) {
286- s_logger .debug (String .format ("Skipping HA on %s as there is already a running HA job for it" , vm ));
293+ if (vmHasPendingHAJob (pendingHaWorks , vm )) {
287294 skippedHAVms ++;
288295 continue ;
289296 }
0 commit comments