Skip to content

Commit 0361263

Browse files
committed
vSphereCloudLauncher enhancement
vSphereCloudLauncher no longer connects to vSphere when its "idleAction" is "nothing". It still connects as normal if it needs to, it just doesn't bother connecting when it's not going to use the connection. It also now calls VSphere's disconnect method from a finally {...} block to ensure that it will always disconnect from vSphere if it had previously connected; before, it could remain connected if exceptions happened.
1 parent 5b0ea26 commit 0361263

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/main/java/org/jenkinsci/plugins/vSphereCloudLauncher.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,21 @@ public synchronized void afterDisconnect(SlaveComputer slaveComputer, TaskListen
293293
try {
294294
vSphereCloud.Log(slaveComputer, taskListener, "Running disconnect procedure...");
295295
super.afterDisconnect(slaveComputer, taskListener);
296-
vSphereCloud.Log(slaveComputer, taskListener, "Shutting down Virtual Machine...");
297296
MACHINE_ACTION localIdle = idleAction;
298297
if (localIdle == null) {
299298
localIdle = MACHINE_ACTION.SHUTDOWN;
300299
}
301-
vSphereCloud vsC = findOurVsInstance();
300+
vSphereCloud.Log(slaveComputer, taskListener, "Disconnect done. Performing idle action %s...", localIdle);
301+
final vSphereCloud vsC = findOurVsInstance();
302302
vsC.markVMOffline(slaveComputer.getDisplayName(), vmName);
303-
v = vsC.vSphereInstance();
304-
VirtualMachine vm = v.getVmByName(vmName);
305-
if (vm != null && !MACHINE_ACTION.NOTHING.equals(localIdle)) {
303+
final VirtualMachine vm;
304+
if( !MACHINE_ACTION.NOTHING.equals(localIdle) ) {
305+
v = vsC.vSphereInstance();
306+
vm = v.getVmByName(vmName);
307+
} else {
308+
vm = null;
309+
}
310+
if (vm != null ) {
306311
//VirtualMachinePowerState power = vm.getRuntime().getPowerState();
307312
VirtualMachinePowerState power = vm.getSummary().getRuntime().powerState;
308313
if (power == VirtualMachinePowerState.poweredOn) {
@@ -340,13 +345,15 @@ public synchronized void afterDisconnect(SlaveComputer slaveComputer, TaskListen
340345
// VM is already powered down.
341346
}
342347
}
343-
if (v != null) {
344-
v.disconnect();
345-
}
348+
vSphereCloud.Log(slaveComputer, taskListener, "Idle action %s complete.", localIdle);
346349
} catch (Throwable t) {
347350
vSphereCloud.Log(slaveComputer, taskListener, t, "Got an exception");
348351
taskListener.fatalError(t.getMessage(), t);
349352
} finally {
353+
if (v != null) {
354+
v.disconnect();
355+
v = null;
356+
}
350357
vsSlave.slaveIsDisconnecting = Boolean.FALSE;
351358
vsSlave.slaveIsStarting = Boolean.FALSE;
352359
}

0 commit comments

Comments
 (0)