3535import javax .inject .Inject ;
3636import javax .naming .ConfigurationException ;
3737
38+ import org .apache .cloudstack .framework .jobs .impl .AsyncJobManagerImpl ;
3839import org .apache .log4j .Logger ;
3940
4041import com .vmware .vim25 .AboutInfo ;
128129public class VmwareManagerImpl extends ManagerBase implements VmwareManager , VmwareStorageMount , Listener , VmwareDatacenterService , Configurable {
129130 private static final Logger s_logger = Logger .getLogger (VmwareManagerImpl .class );
130131
132+ private static final long MILISECONDS_PER_MINUTE = 60000 ;
131133 private static final int STARTUP_DELAY = 60000 ; // 60 seconds
132134 private static final long DEFAULT_HOST_SCAN_INTERVAL = 600000 ; // every 10 minutes
133135 private long _hostScanInterval = DEFAULT_HOST_SCAN_INTERVAL ;
@@ -212,7 +214,7 @@ public String getConfigComponentName() {
212214
213215 @ Override
214216 public ConfigKey <?>[] getConfigKeys () {
215- return new ConfigKey <?>[] {s_vmwareNicHotplugWaitTimeout };
217+ return new ConfigKey <?>[] {s_vmwareNicHotplugWaitTimeout , s_vmwareCleanOldWorderVMs };
216218 }
217219
218220 @ Override
@@ -534,7 +536,7 @@ public boolean needRecycle(String workerTag) {
534536 return false ;
535537 }
536538
537- Long .parseLong (tokens [0 ]);
539+ long startTick = Long .parseLong (tokens [0 ]);
538540 long msid = Long .parseLong (tokens [1 ]);
539541 long runid = Long .parseLong (tokens [2 ]);
540542
@@ -550,15 +552,16 @@ public boolean needRecycle(String workerTag) {
550552 return true ;
551553 }
552554
553- // disable time-out check until we have found out a VMware API that can check if
554- // there are pending tasks on the subject VM
555- /*
556- if(System.currentTimeMillis() - startTick > _hungWorkerTimeout) {
557- if(s_logger.isInfoEnabled())
558- s_logger.info("Worker VM expired, seconds elapsed: " + (System.currentTimeMillis() - startTick) / 1000);
559- return true;
560- }
561- */
555+ // this time-out check was disabled
556+ // "until we have found out a VMware API that can check if there are pending tasks on the subject VM"
557+ // but as we expire jobs and those stale worker VMs stay around untill an MS reboot we opt in to have them removed anyway
558+ Long hungWorkerTimeout = 2 * (AsyncJobManagerImpl .JobExpireMinutes .value () + AsyncJobManagerImpl .JobCancelThresholdMinutes .value ()) * MILISECONDS_PER_MINUTE ;
559+ if (s_vmwareCleanOldWorderVMs .value () && System .currentTimeMillis () - startTick > hungWorkerTimeout ) {
560+ if (s_logger .isInfoEnabled ()) {
561+ s_logger .info ("Worker VM expired, seconds elapsed: " + (System .currentTimeMillis () - startTick ) / 1000 );
562+ }
563+ return true ;
564+ }
562565 return false ;
563566 }
564567
0 commit comments