Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class VirtualBoxComputerLauncher extends ComputerLauncher {

private static final int SECOND = 1000;

private transient VirtualBoxMachine virtualMachine;

private ComputerLauncher delegate;

private String hostName;
Expand All @@ -43,20 +45,28 @@ public VirtualBoxComputerLauncher(ComputerLauncher delegate, String hostName, St
this.virtualMachineName = virtualMachineName;
this.virtualMachineType = virtualMachineType;
this.virtualMachineStopMode = virtualMachineStopMode;
lookupVirtualMachineHandle();
}

private void lookupVirtualMachineHandle() {
virtualMachine = VirtualBoxPlugin.getVirtualBoxMachine(hostName, virtualMachineName);
}

@Override
public void launch(SlaveComputer computer, TaskListener listener) throws IOException, InterruptedException {
log(listener, "Launching node " + virtualMachineName);
try {
// Connect to VirtualBox host
VirtualBoxMachine machine = VirtualBoxPlugin.getVirtualBoxMachine(hostName, virtualMachineName);
if (machine == null) {
listener.fatalError("Unable to find specified machine");
return;
if (virtualMachine == null) {
listener.getLogger().println("Virtual machine " + virtualMachineName + " not found, retrying ...");
lookupVirtualMachineHandle();
if (virtualMachine == null) {
listener.fatalError("Unable to find specified machine (" + virtualMachineName + ") on host " + hostName);
throw new Exception("Unable to find specified machine (" + virtualMachineName + ") on host " + hostName);
}
}
log(listener, Messages.VirtualBoxLauncher_startVM(machine));
long result = VirtualBoxUtils.startVm(machine, virtualMachineType, new VirtualBoxTaskListenerLog(listener, "[VirtualBox] "));
log(listener, Messages.VirtualBoxLauncher_startVM(virtualMachine));
long result = VirtualBoxUtils.startVm(virtualMachine, virtualMachineType, new VirtualBoxTaskListenerLog(listener, "[VirtualBox] "));
if (result != 0) {
listener.fatalError("Unable to launch");
return;
Expand Down Expand Up @@ -121,13 +131,8 @@ public void afterDisconnect(SlaveComputer computer, TaskListener listener) {
log(listener, "Stage 2 afterDisconnect completed");

try {
// Connect to VirtualBox host
VirtualBoxMachine machine = VirtualBoxPlugin.getVirtualBoxMachine(hostName, virtualMachineName);
if (machine == null) {
listener.fatalError("Unable to find specified machine");
}
log(listener, Messages.VirtualBoxLauncher_stopVM(machine));
long result = VirtualBoxUtils.stopVm(machine, virtualMachineStopMode, new VirtualBoxTaskListenerLog(listener, "[VirtualBox] "));
log(listener, Messages.VirtualBoxLauncher_stopVM(virtualMachine));
long result = VirtualBoxUtils.stopVm(virtualMachine, virtualMachineStopMode, new VirtualBoxTaskListenerLog(listener, "[VirtualBox] "));
if (result != 0) {
listener.fatalError("Unable to stop");
}
Expand Down