1- /*
2- * To change this template, choose Tools | Templates
3- * and open the template in the editor.
4- */
51package org .jenkinsci .plugins ;
6-
2+
73import hudson .AbortException ;
84import hudson .Extension ;
95import hudson .Functions ;
2622
2723import com .vmware .vim25 .mo .VirtualMachine ;
2824import com .vmware .vim25 .mo .VirtualMachineSnapshot ;
25+
2926import hudson .model .Executor ;
3027import hudson .model .Queue ;
28+
3129import java .util .ArrayList ;
3230import java .util .Date ;
3331import java .util .Iterator ;
3432import java .util .List ;
3533import java .util .Map .Entry ;
3634import java .util .concurrent .ConcurrentHashMap ;
35+
3736import jenkins .model .Jenkins ;
3837
3938/**
@@ -48,7 +47,9 @@ public class vSphereCloudSlave extends AbstractCloudSlave {
4847 private final Boolean waitForVMTools ;
4948 private final String launchDelay ;
5049 private final String idleOption ;
51- private Integer LimitedTestRunCount = 0 ; // If limited test runs enabled, the number of tests to limit the slave too.
50+ /** If more than zero then this is the number of build-jobs we limit the slave to. */
51+ private Integer LimitedTestRunCount = 0 ;
52+ /** A count of the number of build-jobs this slave has done. */
5253 private transient Integer NumberOfLimitedTestRuns = 0 ;
5354 public transient Boolean doingLastInLimitedTestRun = Boolean .FALSE ;
5455
@@ -85,7 +86,7 @@ public vSphereCloudSlave(String name, String nodeDescription,
8586 this .NumberOfLimitedTestRuns = 0 ;
8687 readResolve ();
8788 }
88-
89+
8990 @ Override
9091 protected Object readResolve () {
9192 super .readResolve ();
@@ -97,7 +98,7 @@ protected Object readResolve() {
9798 }
9899 return this ;
99100 }
100-
101+
101102 public String getVmName () {
102103 return vmName ;
103104 }
@@ -141,10 +142,10 @@ public String toString() {
141142 return "Shutting down VSphere Cloud Slave" ;
142143 }
143144 });
144- vSphereCloud .Log ("Disconnected computer" );
145+ vSphereCloud .Log (this , listener , "Disconnected computer" );
145146 }
146147 } catch (Exception e ) {
147- vSphereCloud .Log ("Can't disconnect: \n " + e . getMessage () );
148+ vSphereCloud .Log (this , listener , e , "Can't disconnect" );
148149 }
149150 }
150151
@@ -224,7 +225,7 @@ public static vSphereCloudSlave ProbablyLaunchCanHandle(BuildableItem item) {
224225 public AbstractCloudComputer createComputer () {
225226 return new vSphereCloudSlaveComputer (this );
226227 }
227-
228+
228229 @ Override
229230 public CauseOfBlockage canTake (BuildableItem buildItem ) {
230231 // https://issues.jenkins-ci.org/browse/JENKINS-30203
@@ -236,15 +237,15 @@ public String getShortDescription() {
236237 }
237238 };
238239 }
239-
240+
240241 if (slaveIsStarting == Boolean .TRUE ) {
241242 return new CauseOfBlockage .BecauseNodeIsBusy (this );
242243 }
243-
244+
244245 if (slaveIsDisconnecting == Boolean .TRUE ) {
245246 return new CauseOfBlockage .BecauseNodeIsOffline (this );
246247 }
247-
248+
248249 return super .canTake (buildItem );
249250 }
250251
@@ -267,11 +268,11 @@ public boolean StartLimitedTestRun(Run r, TaskListener listener) {
267268 if (executor != null && DoUpdates ) {
268269 if (ret ) {
269270 NumberOfLimitedTestRuns ++;
270- vSphereCloud .Log (listener , "Starting limited count build: %d" , NumberOfLimitedTestRuns );
271+ vSphereCloud .Log (this , listener , "Starting limited count build: %d of %d " , NumberOfLimitedTestRuns , LimitedTestRunCount );
271272 Computer slave = executor .getOwner ();
272273 RunToSlaveMapper .put (r , slave );
273274 } else {
274- vSphereCloud .Log (listener , "Terminating build due to limited build count: %d" , LimitedTestRunCount );
275+ vSphereCloud .Log (this , listener , "Terminating build due to limited build count: %d of %d" , NumberOfLimitedTestRuns , LimitedTestRunCount );
275276 executor .interrupt (Result .ABORTED );
276277 }
277278 }
@@ -281,7 +282,7 @@ public boolean StartLimitedTestRun(Run r, TaskListener listener) {
281282
282283 public boolean EndLimitedTestRun (Run r ) {
283284 boolean ret = true ;
284-
285+
285286 // See if the run maps to an existing computer; remove if found.
286287 Computer slave = RunToSlaveMapper .get (r );
287288 if (slave != null ) {
@@ -294,20 +295,20 @@ public boolean EndLimitedTestRun(Run r) {
294295 NumberOfLimitedTestRuns = 0 ;
295296 try {
296297 if (slave != null ) {
297- vSphereCloud .Log ("Disconnecting the slave agent on %s due to limited build threshold" , slave .getName ());
298-
298+ vSphereCloud .Log (this , "Disconnecting the slave agent on %s due to limited build threshold" , slave .getName ());
299+
299300 slave .setTemporarilyOffline (true , new OfflineCause .ByCLI ("vSphere Plugin marking the slave as offline due to reaching limited build threshold" ));
300301 slave .waitUntilOffline ();
301302 slave .disconnect (new OfflineCause .ByCLI ("vSphere Plugin disconnecting the slave as offline due to reaching limited build threshold" ));
302303 slave .setTemporarilyOffline (false , new OfflineCause .ByCLI ("vSphere Plugin marking the slave as online after completing post-disconnect actions." ));
303304 }
304305 else {
305- vSphereCloud .Log ("Attempting to shutdown slave due to limited build threshold, but cannot determine slave" );
306+ vSphereCloud .Log (this , "Attempting to shutdown slave due to limited build threshold, but cannot determine slave" );
306307 }
307308 } catch (NullPointerException ex ) {
308- vSphereCloud .Log ("NullPointerException thrown while retrieving the slave agent: %s" , ex . getMessage () );
309+ vSphereCloud .Log (this , ex , "NullPointerException thrown while retrieving the slave agent" );
309310 } catch (InterruptedException ex ) {
310- vSphereCloud .Log ("InterruptedException thrown while marking the slave as online or offline: %s" , ex . getMessage () );
311+ vSphereCloud .Log (this , ex , "InterruptedException thrown while marking the slave as online or offline" );
311312 }
312313 }
313314 } else {
@@ -316,8 +317,6 @@ public boolean EndLimitedTestRun(Run r) {
316317 return ret ;
317318 }
318319
319-
320-
321320 /**
322321 * For UI.
323322 *
0 commit comments