From 22195894ccc1506479e8674c9d7657e084c4be4c Mon Sep 17 00:00:00 2001 From: Mattias Holmqvist Date: Thu, 15 Dec 2011 01:55:02 +0100 Subject: [PATCH] Moved the VmSpecification from the constructor in IsoToIMachine to apply(). --- .../virtualbox/functions/IsoToIMachine.java | 19 +++++++------------ ...hineFromIsoIfNotAlreadyExistsLiveTest.java | 5 ++--- .../functions/IsoToIMachineLiveTest.java | 4 ++-- .../predicates/SshAvailableLiveTest.java | 10 +++++----- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IsoToIMachine.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IsoToIMachine.java index 2ebd485ed0..63b21a6d82 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IsoToIMachine.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IsoToIMachine.java @@ -48,7 +48,7 @@ import static org.jclouds.virtualbox.util.MachineUtils.*; import static org.virtualbox_4_1.LockType.Shared; import static org.virtualbox_4_1.LockType.Write; -public class IsoToIMachine implements Function { +public class IsoToIMachine implements Function { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) @@ -56,7 +56,6 @@ public class IsoToIMachine implements Function { private final VirtualBoxManager manager; private String guestId; - private final VmSpecification vmSpecification; private final ComputeServiceContext context; private final String hostId; private final Predicate socketTester; @@ -65,13 +64,11 @@ public class IsoToIMachine implements Function { private final ExecutionType executionType; @Inject - public IsoToIMachine(VirtualBoxManager manager, String guestId, - VmSpecification vmSpecification, ComputeServiceContext context, + public IsoToIMachine(VirtualBoxManager manager, String guestId, ComputeServiceContext context, String hostId, Predicate socketTester, String webServerHost, int webServerPort, ExecutionType executionType) { this.manager = manager; this.guestId = guestId; - this.vmSpecification = vmSpecification; this.context = context; this.hostId = hostId; this.socketTester = socketTester; @@ -81,7 +78,7 @@ public class IsoToIMachine implements Function { } @Override - public IMachine apply(@Nullable String isoName) { + public IMachine apply(VmSpecification vmSpecification) { ensureWebServerIsRunning(); @@ -94,14 +91,12 @@ public class IsoToIMachine implements Function { Set controllers = vmSpecification.getControllers(); if (controllers.isEmpty()) { - throw new IllegalStateException(missingIDEControllersMessage()); + throw new IllegalStateException(missingIDEControllersMessage(vmSpecification)); } StorageController controller = controllers.iterator().next(); ensureMachineHasIDEControllerNamed(vmName, controller); setupHardDisksForController(vmName, controller); - setupDvdsForController(vmName, controller); - missingIDEControllersMessage(); - + setupDvdsForController(vmSpecification, vmName, controller); // NAT Map natNetworkAdapters = vmSpecification.getNatNetworkAdapters(); @@ -143,7 +138,7 @@ public class IsoToIMachine implements Function { return vm; } - private void setupDvdsForController(String vmName, StorageController controller) { + private void setupDvdsForController(VmSpecification vmSpecification, String vmName, StorageController controller) { Set dvds = controller.getIsoImages(); for (IsoImage dvd : dvds) { String dvdSource = dvd.getSourcePath(); @@ -168,7 +163,7 @@ public class IsoToIMachine implements Function { } } - private String missingIDEControllersMessage() { + private String missingIDEControllersMessage(VmSpecification vmSpecification) { return String.format("First controller is not an IDE controller. Please verify that the VM spec is a correct master node: %s", vmSpecification); } diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java index 3c42b6e28c..ccddb10aee 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java @@ -92,9 +92,8 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends Ba VmSpecification vmSpecification = VmSpecification.builder().id(vmId).name(vmName).osTypeId(osTypeId) .controller(ideController) .forceOverwrite(true).build(); - return new IsoToIMachine(manager, guestId, - vmSpecification, localHostContext, hostId, socketTester, - "127.0.0.1", 8080, HEADLESS).apply(isoName); + return new IsoToIMachine(manager, guestId, localHostContext, hostId, socketTester, + "127.0.0.1", 8080, HEADLESS).apply(vmSpecification); } catch (IllegalStateException e) { // already created return manager.getVBox().findMachine(vmName); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IsoToIMachineLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IsoToIMachineLiveTest.java index ad91b2fbe6..19f5a47e9a 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IsoToIMachineLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IsoToIMachineLiveTest.java @@ -95,9 +95,9 @@ public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest { .controller(ideController) .forceOverwrite(true) .natNetworkAdapter(0, NatAdapter.builder().tcpRedirectRule("127.0.0.1", 2222, "", 22).build()).build(); - IMachine imageMachine = new IsoToIMachine(manager, guestId, vmSpecification, localHostContext, hostId, + IMachine imageMachine = new IsoToIMachine(manager, guestId, localHostContext, hostId, socketTester, "127.0.0.1", 8080, HEADLESS) - .apply("ubuntu-11.04-server-i386.iso"); + .apply(vmSpecification); IMachineToImage iMachineToImage = new IMachineToImage(manager, map); Image newImage = iMachineToImage.apply(imageMachine); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/SshAvailableLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/SshAvailableLiveTest.java index ecaf439550..b1b4c7971b 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/SshAvailableLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/predicates/SshAvailableLiveTest.java @@ -38,7 +38,7 @@ public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest { public void testSshDaemonIsRunning() { VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi(); ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest( - hostId, "localhost", guestId, "localhost", new Credentials("toor","password")); + hostId, "localhost", guestId, "localhost", new Credentials("toor", "password")); getNodeWithSshDaemonRunning(manager, localHostContext); ensureMachineIsLaunched(vmName); @@ -68,14 +68,14 @@ public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest { String workingDir = PropertyUtils.getWorkingDirFromProperty(); StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE) - .attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso") - .attachHardDisk(0, 1, workingDir + "/testadmin.vdi").build(); + .attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso") + .attachHardDisk(0, 1, workingDir + "/testadmin.vdi").build(); VmSpecification vmSpecification = VmSpecification.builder().id(vmId).name(vmName).osTypeId("") .controller(ideController) .forceOverwrite(true).build(); - return new IsoToIMachine(manager, guestId, vmSpecification, localHostContext, - hostId, socketTester, "127.0.0.1", 8080, HEADLESS).apply(isoName); + return new IsoToIMachine(manager, guestId, localHostContext, + hostId, socketTester, "127.0.0.1", 8080, HEADLESS).apply(vmSpecification); } catch (IllegalStateException e) { // already created return manager.getVBox().findMachine(vmName);