|
22 | 22 | import java.net.URISyntaxException; |
23 | 23 | import java.net.URL; |
24 | 24 | import java.rmi.RemoteException; |
| 25 | +import java.time.Duration; |
| 26 | +import java.time.Instant; |
25 | 27 | import java.util.ArrayList; |
26 | 28 | import java.util.HashMap; |
27 | 29 | import java.util.List; |
|
129 | 131 | public class VmwareManagerImpl extends ManagerBase implements VmwareManager, VmwareStorageMount, Listener, VmwareDatacenterService, Configurable { |
130 | 132 | private static final Logger s_logger = Logger.getLogger(VmwareManagerImpl.class); |
131 | 133 |
|
132 | | - private static final long MILISECONDS_PER_MINUTE = 60000; |
| 134 | + private static final long SECONDS_PER_MINUTE = 60; |
133 | 135 | private static final int STARTUP_DELAY = 60000; // 60 seconds |
134 | 136 | private static final long DEFAULT_HOST_SCAN_INTERVAL = 600000; // every 10 minutes |
135 | 137 | private long _hostScanInterval = DEFAULT_HOST_SCAN_INTERVAL; |
@@ -555,17 +557,18 @@ public boolean needRecycle(String workerTag) { |
555 | 557 | // this time-out check was disabled |
556 | 558 | // "until we have found out a VMware API that can check if there are pending tasks on the subject VM" |
557 | 559 | // 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 | | - Long letsSayNow = System.currentTimeMillis(); |
560 | | - if(s_vmwareCleanOldWorderVMs.value() && letsSayNow - startTick > hungWorkerTimeout) { |
| 560 | + Instant start = Instant.ofEpochMilli(startTick); |
| 561 | + Instant end = start.plusSeconds(2 * (AsyncJobManagerImpl.JobExpireMinutes.value() + AsyncJobManagerImpl.JobCancelThresholdMinutes.value()) * SECONDS_PER_MINUTE); |
| 562 | + Instant now = Instant.now(); |
| 563 | + if(s_vmwareCleanOldWorderVMs.value() && now.isAfter(end)) { |
561 | 564 | if(s_logger.isInfoEnabled()) { |
562 | | - s_logger.info("Worker VM expired, seconds elapsed: " + (System.currentTimeMillis() - startTick) / 1000); |
| 565 | + s_logger.info("Worker VM expired, seconds elapsed: " + Duration.between(start,now).getSeconds()); |
563 | 566 | } |
564 | 567 | return true; |
565 | 568 | } |
566 | 569 | if (s_logger.isTraceEnabled()) { |
567 | 570 | s_logger.trace("Worker VM with tag '" + workerTag + "' does not need recycling, yet." + |
568 | | - "But in " + (startTick + hungWorkerTimeout - letsSayNow) + " milisecs, though"); |
| 571 | + "But in " + Duration.between(now,end).getSeconds() + " seconds, though"); |
569 | 572 | } |
570 | 573 | return false; |
571 | 574 | } |
|
0 commit comments