diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/VmSpecification.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/VmSpec.java similarity index 92% rename from sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/VmSpecification.java rename to sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/VmSpec.java index 560231cabc..25414bbcfc 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/VmSpecification.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/VmSpec.java @@ -26,7 +26,7 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * A description of a Virtual Machine in VirtualBox. */ -public class VmSpecification { +public class VmSpec { private final String vmName; private final String osTypeId; @@ -35,7 +35,7 @@ public class VmSpecification { private final Map natNetworkAdapters; private final Set controllers; - public VmSpecification(String vmId, String vmName, String osTypeId, boolean forceOverwrite, Set controllers, Map natNetworkAdapters) { + public VmSpec(String vmId, String vmName, String osTypeId, boolean forceOverwrite, Set controllers, Map natNetworkAdapters) { this.vmId = vmId; this.vmName = vmName; this.osTypeId = osTypeId; @@ -88,10 +88,10 @@ public class VmSpecification { } - public VmSpecification build() { + public VmSpec build() { checkNotNull(name, "name"); checkNotNull(id, "id"); - return new VmSpecification(id, name, osTypeId, forceOverwrite, controllers, natNetworkAdapters); + return new VmSpec(id, name, osTypeId, forceOverwrite, controllers, natNetworkAdapters); } } @@ -124,7 +124,7 @@ public class VmSpecification { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - VmSpecification that = (VmSpecification) o; + VmSpec that = (VmSpec) o; if (forceOverwrite != that.forceOverwrite) return false; if (controllers != null ? !controllers.equals(that.controllers) : that.controllers != null) return false; diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExists.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExists.java index ae54d1d03c..c30d392ada 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExists.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExists.java @@ -20,7 +20,7 @@ package org.jclouds.virtualbox.functions; import com.google.common.base.Function; -import org.jclouds.virtualbox.domain.VmSpecification; +import org.jclouds.virtualbox.domain.VmSpec; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IVirtualBox; import org.virtualbox_4_1.VBoxException; @@ -31,7 +31,7 @@ import javax.annotation.Nullable; /** * @author Mattias Holmqvist */ -public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Function { +public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Function { private VirtualBoxManager manager; @@ -40,7 +40,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi } @Override - public IMachine apply(@Nullable VmSpecification launchSpecification) { + public IMachine apply(@Nullable VmSpec launchSpecification) { final IVirtualBox vBox = manager.getVBox(); String vmName = launchSpecification.getVmName(); try { @@ -58,7 +58,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi return e.getMessage().contains("VirtualBox error: Could not find a registered machine named "); } - private IMachine createMachine(IVirtualBox vBox, VmSpecification launchSpecification) { + private IMachine createMachine(IVirtualBox vBox, VmSpec launchSpecification) { // TODO: add support for settingsfile String settingsFile1 = null; IMachine newMachine = vBox.createMachine(settingsFile1, launchSpecification.getVmName(), 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 63b21a6d82..7a44dbb49a 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 @@ -26,7 +26,6 @@ import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.javax.annotation.Nullable; import org.jclouds.logging.Logger; import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshException; @@ -48,7 +47,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) @@ -78,7 +77,7 @@ public class IsoToIMachine implements Function { } @Override - public IMachine apply(VmSpecification vmSpecification) { + public IMachine apply(VmSpec vmSpecification) { ensureWebServerIsRunning(); @@ -138,7 +137,7 @@ public class IsoToIMachine implements Function { return vm; } - private void setupDvdsForController(VmSpecification vmSpecification, String vmName, StorageController controller) { + private void setupDvdsForController(VmSpec vmSpecification, String vmName, StorageController controller) { Set dvds = controller.getIsoImages(); for (IsoImage dvd : dvds) { String dvdSource = dvd.getSourcePath(); @@ -163,7 +162,7 @@ public class IsoToIMachine implements Function { } } - private String missingIDEControllersMessage(VmSpecification vmSpecification) { + private String missingIDEControllersMessage(VmSpec 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/domain/VmSpecTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/domain/VmSpecTest.java new file mode 100644 index 0000000000..d129802f63 --- /dev/null +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/domain/VmSpecTest.java @@ -0,0 +1,79 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.virtualbox.domain; + +import org.testng.annotations.Test; +import org.virtualbox_4_1.StorageBus; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; + +public class VmSpecTest { + + @Test + public void testEqualsSuccessful() throws Exception { + VmSpec vmSpec = defaultVm().build(); + VmSpec sameVmSpec = defaultVm().build(); + assertEquals(vmSpec, sameVmSpec); + } + + @Test + public void testEqualsWrongId() throws Exception { + VmSpec vmSpec = defaultVm().build(); + VmSpec other = defaultVm().id("OtherVMId").build(); + assertFalse(vmSpec.equals(other)); + } + + @Test + public void testEqualsWrongName() throws Exception { + VmSpec vmSpec = defaultVm().build(); + VmSpec other = defaultVm().name("OtherName").build(); + assertFalse(vmSpec.equals(other)); + } + + @Test + public void testEqualsWrongOsType() throws Exception { + VmSpec vmSpec = defaultVm().build(); + VmSpec other = defaultVm().osTypeId("OtherOS").build(); + assertFalse(vmSpec.equals(other)); + } + + @Test + public void testEqualsWrongForceOverwriteRule() throws Exception { + VmSpec vmSpec = defaultVm().build(); + VmSpec other = defaultVm().forceOverwrite(false).build(); + assertFalse(vmSpec.equals(other)); + } + + private VmSpec.Builder defaultVm() { + return VmSpec.builder() + .id("MyVmId") + .name("My VM") + .osTypeId("Ubuntu") + .natNetworkAdapter( + 0, + NatAdapter.builder().tcpRedirectRule("localhost", 2222, "", 22).build()) + .forceOverwrite(true) + .controller( + StorageController.builder().name("Controller") + .bus(StorageBus.IDE) + .attachHardDisk(0, 0, "/tmp/tempdisk.vdi").build()); + } +} 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 ccddb10aee..7a9ac2d8be 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 @@ -26,9 +26,8 @@ import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; -import org.jclouds.virtualbox.domain.HardDisk; import org.jclouds.virtualbox.domain.StorageController; -import org.jclouds.virtualbox.domain.VmSpecification; +import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.util.PropertyUtils; import org.testng.annotations.Test; import org.virtualbox_4_1.*; @@ -89,7 +88,7 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends Ba .attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso") .attachHardDisk(0, 1, workingDir + "/testadmin.vdi") .attachISO(1, 1, workingDir + "/VBoxGuestAdditions_4.1.2.iso").build(); - VmSpecification vmSpecification = VmSpecification.builder().id(vmId).name(vmName).osTypeId(osTypeId) + VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).osTypeId(osTypeId) .controller(ideController) .forceOverwrite(true).build(); return new IsoToIMachine(manager, guestId, localHostContext, hostId, socketTester, diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java index 6192d2a533..6b04272833 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest.java @@ -21,7 +21,7 @@ package org.jclouds.virtualbox.functions; import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; import org.jclouds.virtualbox.domain.ErrorCode; -import org.jclouds.virtualbox.domain.VmSpecification; +import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.functions.admin.UnregisterMachineIfExists; import org.testng.annotations.Test; import org.virtualbox_4_1.CleanupMode; @@ -40,7 +40,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B public void testCreateNewMachine() throws Exception { String vmName = "jclouds-test-create-1-node"; new UnregisterMachineIfExists(manager, CleanupMode.Full).apply(vmName); - VmSpecification launchSpecification = VmSpecification.builder().id(vmName).name(vmName) + VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName) .osTypeId("Debian").forceOverwrite(true).build(); IMachine debianNode = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification); IMachine machine = manager.getVBox().findMachine(vmName); @@ -52,7 +52,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B public void testCreateNewMachineWithBadOsType() throws Exception { String vmName = "jclouds-test-create-2-node"; new UnregisterMachineIfExists(manager, CleanupMode.Full).apply(vmName); - VmSpecification launchSpecification = VmSpecification.builder().id(vmName).name(vmName) + VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName) .osTypeId("SomeWeirdUnknownOs").forceOverwrite(true).build(); try { new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest.java index 8d4b68b2e9..0cf406cb9a 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest.java @@ -29,7 +29,7 @@ import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.verify; import org.easymock.EasyMock; -import org.jclouds.virtualbox.domain.VmSpecification; +import org.jclouds.virtualbox.domain.VmSpec; import org.testng.annotations.Test; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IVirtualBox; @@ -49,7 +49,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest { IVirtualBox vBox = createMock(IVirtualBox.class); String vmName = "jclouds-image-my-ubuntu-image"; - VmSpecification launchSpecification = VmSpecification.builder().id(vmName).name(vmName).osTypeId("").build(); + VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").build(); IMachine createdMachine = createMock(IMachine.class); @@ -90,7 +90,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest { replay(manager, vBox); - VmSpecification launchSpecification = VmSpecification.builder().id("").name(vmName).osTypeId("").build(); + VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").build(); new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification); } @@ -111,7 +111,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest { replay(manager, vBox); - VmSpecification launchSpecification = VmSpecification.builder().id("").name(vmName).osTypeId("").build(); + VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").build(); new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification); } 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 19f5a47e9a..eb2be74e52 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 @@ -49,7 +49,6 @@ import java.util.concurrent.TimeUnit; import static com.google.common.base.Predicates.equalTo; import static com.google.common.collect.Iterables.any; import static com.google.common.collect.Iterables.transform; -import static org.jclouds.virtualbox.domain.ExecutionType.GUI; import static org.jclouds.virtualbox.domain.ExecutionType.HEADLESS; import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest; import static org.testng.Assert.assertTrue; @@ -91,7 +90,7 @@ public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest { .attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso") .attachHardDisk(0, 1, workingDir + "/testadmin.vdi") .attachISO(1, 1, workingDir + "/VBoxGuestAdditions_4.1.2.iso").build(); - VmSpecification vmSpecification = VmSpecification.builder().id(vmId).name(vmName).osTypeId(osTypeId) + VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).osTypeId(osTypeId) .controller(ideController) .forceOverwrite(true) .natNetworkAdapter(0, NatAdapter.builder().tcpRedirectRule("127.0.0.1", 2222, "", 22).build()).build(); 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 b1b4c7971b..fe71e4de75 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 @@ -10,7 +10,7 @@ import org.jclouds.predicates.RetryablePredicate; import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; import org.jclouds.virtualbox.domain.ExecutionType; import org.jclouds.virtualbox.domain.StorageController; -import org.jclouds.virtualbox.domain.VmSpecification; +import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.functions.IsoToIMachine; import org.jclouds.virtualbox.functions.LaunchMachineIfNotAlreadyRunning; import org.jclouds.virtualbox.util.PropertyUtils; @@ -70,7 +70,7 @@ public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest { 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(); - VmSpecification vmSpecification = VmSpecification.builder().id(vmId).name(vmName).osTypeId("") + VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).osTypeId("") .controller(ideController) .forceOverwrite(true).build();