From d300681bcc42fe86e0827260ef1e49507d5abdd5 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 29 Oct 2011 11:00:02 +0200 Subject: [PATCH] formatting in virtualbox --- .../virtualbox/VirtualBoxContextBuilder.java | 6 +- .../VirtualBoxPropertiesBuilder.java | 40 +-- .../compute/LoadMachineFromVirtualBox.java | 60 ++-- .../VirtualBoxComputeServiceAdapter.java | 41 +-- ...VirtualBoxComputeServiceContextModule.java | 58 ++-- .../config/VirtualBoxConstants.java | 8 +- .../jclouds/virtualbox/domain/ErrorCode.java | 43 +-- .../virtualbox/domain/ExecutionType.java | 7 +- .../jclouds/virtualbox/domain/YamlImage.java | 145 +++++----- .../AddIDEControllerIfNotExists.java | 1 + .../functions/ApplyMemoryToMachine.java | 7 +- .../AttachDistroMediumToMachine.java | 5 +- ...chMediumToMachineIfNotAlreadyAttached.java | 13 +- .../AttachNATRedirectRuleToMachine.java | 13 +- ...isterMachineFromIsoIfNotAlreadyExists.java | 6 +- .../CreateMediumIfNotAlreadyExists.java | 25 +- .../functions/IMachineToHardware.java | 1 - .../virtualbox/functions/IMachineToImage.java | 3 +- .../functions/IMachineToIpAddress.java | 28 +- .../functions/IMachineToNodeMetadata.java | 31 ++- .../virtualbox/functions/IsoToIMachine.java | 89 +++--- .../LaunchMachineIfNotAlreadyRunning.java | 55 ++-- .../functions/admin/FileDownloadFromURI.java | 4 +- .../functions/admin/ImageFromYamlStream.java | 81 +++--- .../admin/StartJettyIfNotAlreadyRunning.java | 100 +++---- .../admin/StartVBoxIfNotAlreadyRunning.java | 19 +- .../settings/KeyboardScancodes.java | 256 +++++++++--------- ...rtualBoxComputeServiceAdapterLiveTest.java | 40 +-- .../VirtualBoxComputeServiceAdapterTest.java | 34 +-- .../compute/VirtualBoxExperimentLiveTest.java | 2 +- .../VirtualBoxTemplateBuilderLiveTest.java | 61 ++--- .../SetupVirtualBoxForLiveTest.java | 38 ++- .../virtualbox/experiment/TestUtils.java | 103 +++---- .../functions/ApplyMemoryToMachineTest.java | 14 +- .../AttachDistroMediumToMachineTest.java | 16 +- ...diumToMachineIfNotAlreadyAttachedTest.java | 34 ++- .../AttachNATRedirectRuleToMachineTest.java | 22 +- ...rMachineFromIsoIfNotAlreadyExistsTest.java | 23 +- .../CreateMediumIfNotAlreadyExistsTest.java | 18 +- .../functions/IMachineToNodeMetadataTest.java | 1 - .../functions/IsoToIMachineLiveTest.java | 35 +-- .../LaunchMachineIfNotAlreadyRunningTest.java | 17 +- .../admin/ImageFromYamlStreamTest.java | 36 +-- ...StartJettyIfNotAlreadyRunningLiveTest.java | 10 +- .../StartVBoxIfNotAlreadyRunningLiveTest.java | 24 +- 45 files changed, 853 insertions(+), 820 deletions(-) diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxContextBuilder.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxContextBuilder.java index f9d48ddfbf..5a1ce5638d 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxContextBuilder.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxContextBuilder.java @@ -30,11 +30,11 @@ import com.google.inject.Module; /** * Creates compute service context for VirtualBox - * + * * @author Mattias Holmqvist, Andrea Turli */ public class VirtualBoxContextBuilder extends StandaloneComputeServiceContextBuilder { - + public VirtualBoxContextBuilder(Properties properties) { super(VirtualBoxManager.class, properties); } @@ -43,5 +43,5 @@ public class VirtualBoxContextBuilder extends StandaloneComputeServiceContextBui protected void addContextModule(List modules) { modules.add(new VirtualBoxComputeServiceContextModule()); } - + } diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxPropertiesBuilder.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxPropertiesBuilder.java index 0f8f03111f..91877c3d5c 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxPropertiesBuilder.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/VirtualBoxPropertiesBuilder.java @@ -19,17 +19,19 @@ package org.jclouds.virtualbox; -import org.jclouds.PropertiesBuilder; -import org.jclouds.virtualbox.config.VirtualBoxConstants; +import static org.jclouds.Constants.PROPERTY_CREDENTIAL; +import static org.jclouds.Constants.PROPERTY_ENDPOINT; +import static org.jclouds.Constants.PROPERTY_IDENTITY; import java.io.File; import java.util.Properties; -import static org.jclouds.Constants.*; +import org.jclouds.PropertiesBuilder; +import org.jclouds.virtualbox.config.VirtualBoxConstants; /** * Builds properties for VirtualBox integration. - * + * * @author Mattias Holmqvist */ public class VirtualBoxPropertiesBuilder extends PropertiesBuilder { @@ -51,24 +53,24 @@ public class VirtualBoxPropertiesBuilder extends PropertiesBuilder { properties.put(VirtualBoxConstants.VIRTUALBOX_PRESEED_URL, "http://dl.dropbox.com/u/693111/preseed.cfg"); properties.put(VirtualBoxConstants.VIRTUALBOX_SNAPSHOT_DESCRIPTION, "jclouds-virtualbox-snaphot"); properties.put(VirtualBoxConstants.VIRTUALBOX_HOSTNAME, "jclouds-virtualbox-kickstart-admin"); - properties.put(VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, " " - + "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg " - + "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " - + "hostname=" - + properties.get(VirtualBoxConstants.VIRTUALBOX_HOSTNAME) - + " " - + "fb=false debconf/frontend=noninteractive " - + "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false " - + "initrd=/install/initrd.gz -- "); + properties + .put(VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE, + " " + + "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg " + + "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + + "hostname=" + + properties.get(VirtualBoxConstants.VIRTUALBOX_HOSTNAME) + + " " + + "fb=false debconf/frontend=noninteractive " + + "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false " + + "initrd=/install/initrd.gz -- "); + + properties.put(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR, System.getProperty("user.home") + File.separator + + System.getProperty("test.virtualbox.workingDir", "jclouds-virtualbox-test")); - properties.put(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR, System.getProperty("user.home") - + File.separator - + System.getProperty("test.virtualbox.workingDir", - "jclouds-virtualbox-test")); - // TODO: Add more properties and use the wired properties from test code. properties.put(VirtualBoxConstants.VIRTUALBOX_DISTRO_ISO_NAME, "ubuntu-11.04-server-i386.iso"); - + properties.put(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080"); return properties; diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/compute/LoadMachineFromVirtualBox.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/compute/LoadMachineFromVirtualBox.java index 2300050b95..b84b3550ea 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/compute/LoadMachineFromVirtualBox.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/compute/LoadMachineFromVirtualBox.java @@ -19,23 +19,28 @@ package org.jclouds.virtualbox.compute; -import com.google.common.base.Function; -import com.google.common.cache.CacheLoader; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_MACHINE_CREDENTIAL; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_MACHINE_GROUP; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_MACHINE_LOCATION; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_MACHINE_USERNAME; + +import java.net.URI; +import java.net.URISyntaxException; + +import javax.inject.Inject; + import org.jclouds.byon.Node; import org.jclouds.compute.domain.OsFamily; import org.virtualbox_4_1.IGuestOSType; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.VirtualBoxManager; -import javax.inject.Inject; -import java.net.URI; -import java.net.URISyntaxException; - -import static org.jclouds.virtualbox.config.VirtualBoxConstants.*; +import com.google.common.base.Function; +import com.google.common.cache.CacheLoader; /** * Loads a node from a VirtualBox IMachine - * + * * @author Mattias Holmqvist */ public class LoadMachineFromVirtualBox extends CacheLoader { @@ -53,16 +58,10 @@ public class LoadMachineFromVirtualBox extends CacheLoader { public Node load(final String id) throws Exception { if (id.equals("host")) { - final Node hostNode = Node.builder().id("host") - .name("host installing virtualbox") - .hostname("localhost") - .osFamily(OsFamily.LINUX.toString()) - .osDescription(System.getProperty("os.name")) - .osVersion(System.getProperty("os.version")) - .group("ssh") - .username(System.getProperty("user.name")) - .credentialUrl(privateKeyFile()) - .build(); + final Node hostNode = Node.builder().id("host").name("host installing virtualbox").hostname("localhost") + .osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name")) + .osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name")) + .credentialUrl(privateKeyFile()).build(); return hostNode; } @@ -71,23 +70,14 @@ public class LoadMachineFromVirtualBox extends CacheLoader { final String osTypeId = machine.getOSTypeId(); final IGuestOSType guestOSType = manager.getVBox().getGuestOSType(osTypeId); - final Node node = Node.builder() - .id(machine.getId()) - .name(machine.getName()) - .description(machine.getDescription()) - .loginPort(22) - .group(System.getProperty(VIRTUALBOX_MACHINE_GROUP)) - .username(System.getProperty(VIRTUALBOX_MACHINE_USERNAME)) - .credential(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL)) - .sudoPassword(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL)) - .locationId(System.getProperty(VIRTUALBOX_MACHINE_LOCATION)) - .os64Bit(guestOSType.getIs64Bit()) - .osArch(guestOSType.getDescription()) - .osFamily(guestOSType.getFamilyDescription()) - .osVersion(guestOSType.getId()) - .osDescription(guestOSType.getDescription()) - .hostname(ipAddress) - .build(); + final Node node = Node.builder().id(machine.getId()).name(machine.getName()) + .description(machine.getDescription()).loginPort(22).group(System.getProperty(VIRTUALBOX_MACHINE_GROUP)) + .username(System.getProperty(VIRTUALBOX_MACHINE_USERNAME)) + .credential(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL)) + .sudoPassword(System.getProperty(VIRTUALBOX_MACHINE_CREDENTIAL)) + .locationId(System.getProperty(VIRTUALBOX_MACHINE_LOCATION)).os64Bit(guestOSType.getIs64Bit()) + .osArch(guestOSType.getDescription()).osFamily(guestOSType.getFamilyDescription()) + .osVersion(guestOSType.getId()).osDescription(guestOSType.getDescription()).hostname(ipAddress).build(); return node; diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java index e43d65ada7..7ba6c7ae95 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapter.java @@ -19,10 +19,16 @@ package org.jclouds.virtualbox.compute; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.base.Throwables; -import com.google.inject.Singleton; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.filter; +import static com.google.common.collect.Iterables.transform; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; + +import java.util.Collections; +import java.util.Map; + +import javax.inject.Inject; + import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Template; @@ -30,15 +36,17 @@ import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.javax.annotation.Nullable; import org.jclouds.location.suppliers.JustProvider; -import org.virtualbox_4_1.*; +import org.virtualbox_4_1.CleanupMode; +import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_1.IProgress; +import org.virtualbox_4_1.ISession; +import org.virtualbox_4_1.SessionState; +import org.virtualbox_4_1.VirtualBoxManager; -import javax.inject.Inject; -import java.util.*; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.transform; -import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.base.Throwables; +import com.google.inject.Singleton; /** * Defines the connection between the @@ -55,7 +63,8 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter iMachineToImage; @Inject - public VirtualBoxComputeServiceAdapter(VirtualBoxManager manager, JustProvider justProvider, Function iMachineToImage) { + public VirtualBoxComputeServiceAdapter(VirtualBoxManager manager, JustProvider justProvider, + Function iMachineToImage) { this.iMachineToImage = iMachineToImage; this.manager = checkNotNull(manager, "manager"); this.justProvider = checkNotNull(justProvider, "justProvider"); @@ -77,8 +86,8 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter listImages() { + @Override + public Iterable listImages() { final Predicate imagePredicate = new Predicate() { @Override public boolean apply(@Nullable IMachine iMachine) { @@ -87,7 +96,7 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter imageMachines = filter(manager.getVBox().getMachines(), imagePredicate); return transform(imageMachines, iMachineToImage); - } + } @SuppressWarnings("unchecked") @Override diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java index 8cdc72a22a..6f3274f22e 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxComputeServiceContextModule.java @@ -57,20 +57,21 @@ import com.google.inject.TypeLiteral; /** * @author Mattias Holmqvist, Andrea Turli */ -public class VirtualBoxComputeServiceContextModule extends ComputeServiceAdapterContextModule { +public class VirtualBoxComputeServiceContextModule extends + ComputeServiceAdapterContextModule { public VirtualBoxComputeServiceContextModule() { super(VirtualBoxManager.class, VirtualBoxManager.class); } - + @Provides @Singleton - protected VirtualBoxManager createInstance(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity, - @Named(Constants.PROPERTY_CREDENTIAL) String credential) { - - VirtualBoxManager manager = VirtualBoxManager.createInstance(""); - manager.connect(endpoint.toASCIIString(), identity, credential); - return manager; + protected VirtualBoxManager createInstance(@Provider URI endpoint, + @Named(Constants.PROPERTY_IDENTITY) String identity, @Named(Constants.PROPERTY_CREDENTIAL) String credential) { + + VirtualBoxManager manager = VirtualBoxManager.createInstance(""); + manager.connect(endpoint.toASCIIString(), identity, credential); + return manager; } @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -100,31 +101,24 @@ public class VirtualBoxComputeServiceContextModule extends ComputeServiceAdapter @VisibleForTesting public static final Map machineToNodeState = ImmutableMap - .builder() - .put(MachineState.Running, NodeState.RUNNING) - .put(MachineState.PoweredOff, NodeState.SUSPENDED) - .put(MachineState.DeletingSnapshot, NodeState.PENDING) - .put(MachineState.DeletingSnapshotOnline, NodeState.PENDING) - .put(MachineState.DeletingSnapshotPaused, NodeState.PENDING) - .put(MachineState.FaultTolerantSyncing, NodeState.PENDING) - .put(MachineState.LiveSnapshotting, NodeState.PENDING) - .put(MachineState.SettingUp, NodeState.PENDING) - .put(MachineState.Starting, NodeState.PENDING) - .put(MachineState.Stopping, NodeState.PENDING) - .put(MachineState.Restoring, NodeState.PENDING) - // TODO What to map these states to? - .put(MachineState.FirstOnline, NodeState.PENDING) - .put(MachineState.FirstTransient, NodeState.PENDING) - .put(MachineState.LastOnline, NodeState.PENDING) - .put(MachineState.LastTransient, NodeState.PENDING) - .put(MachineState.Teleported, NodeState.PENDING) - .put(MachineState.TeleportingIn, NodeState.PENDING) - .put(MachineState.TeleportingPausedVM, NodeState.PENDING) + . builder().put(MachineState.Running, NodeState.RUNNING) + .put(MachineState.PoweredOff, NodeState.SUSPENDED).put(MachineState.DeletingSnapshot, NodeState.PENDING) + .put(MachineState.DeletingSnapshotOnline, NodeState.PENDING) + .put(MachineState.DeletingSnapshotPaused, NodeState.PENDING) + .put(MachineState.FaultTolerantSyncing, NodeState.PENDING) + .put(MachineState.LiveSnapshotting, NodeState.PENDING) + .put(MachineState.SettingUp, NodeState.PENDING) + .put(MachineState.Starting, NodeState.PENDING) + .put(MachineState.Stopping, NodeState.PENDING) + .put(MachineState.Restoring, NodeState.PENDING) + // TODO What to map these states to? + .put(MachineState.FirstOnline, NodeState.PENDING).put(MachineState.FirstTransient, NodeState.PENDING) + .put(MachineState.LastOnline, NodeState.PENDING).put(MachineState.LastTransient, NodeState.PENDING) + .put(MachineState.Teleported, NodeState.PENDING).put(MachineState.TeleportingIn, NodeState.PENDING) + .put(MachineState.TeleportingPausedVM, NodeState.PENDING) + .put(MachineState.Aborted, NodeState.ERROR).put(MachineState.Stuck, NodeState.ERROR) - .put(MachineState.Aborted, NodeState.ERROR) - .put(MachineState.Stuck, NodeState.ERROR) - - .put(MachineState.Null, NodeState.UNRECOGNIZED).build(); + .put(MachineState.Null, NodeState.UNRECOGNIZED).build(); } diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxConstants.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxConstants.java index f83bf795fb..804718e6ab 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxConstants.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/config/VirtualBoxConstants.java @@ -21,7 +21,7 @@ package org.jclouds.virtualbox.config; /** * Configuration properties used for interacting with VirtualBox instances. - * + * * @author Mattias Holmqvist, Andrea Turli * */ @@ -34,11 +34,11 @@ public interface VirtualBoxConstants { public static final String VIRTUALBOX_SNAPSHOT_DESCRIPTION = "jclouds.virtualbox.snapshotDescription"; public static final String VIRTUALBOX_INSTALLATION_KEY_SEQUENCE = "jclouds.virtualbox.installationkeysequence"; - + public static final String VIRTUALBOX_HOSTNAME = "jclouds.virtualbox.hostname"; - + public static final String VIRTUALBOX_WORKINGDIR = "jclouds.virtualbox.workingdir"; - + public static final String VIRTUALBOX_ISOFILE = "jclouds.virtualbox.isofile"; public static final String VIRTUALBOX_MACHINE_GROUP = "jclouds.virtualbox.machinegroup"; diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/ErrorCode.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/ErrorCode.java index 74801270d5..96255ac145 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/ErrorCode.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/ErrorCode.java @@ -1,4 +1,4 @@ -/* +/** * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -19,17 +19,18 @@ package org.jclouds.virtualbox.domain; -import org.virtualbox_4_1.VBoxException; -import org.virtualbox_4_1.jaxws.RuntimeFaultMsg; - import java.util.HashMap; import java.util.Map; +import org.virtualbox_4_1.VBoxException; +import org.virtualbox_4_1.jaxws.RuntimeFaultMsg; + /** * Maps the error codes in the Virtual Box Java API into enum values. *

*

* To get the error code from a VBoxException, use: + * *

  * try {
  *    ...
@@ -41,32 +42,17 @@ import java.util.Map;
  *    ErrorCode errorCode = ErrorCode.valueOf(faultCode);
  * }
  * 
- * + * * @author Mattias Holmqvist */ public enum ErrorCode { - VBOX_E_OBJECT_NOT_FOUND(2159738881L), - VBOX_E_INVALID_VM_STATE(2159738882L), - VBOX_E_VM_ERROR(2159738883L), - VBOX_E_FILE_ERROR(2159738884L), - VBOX_E_IPRT_ERROR(2159738885L), - VBOX_E_PDM_ERROR(2159738886L), - VBOX_E_INVALID_OBJECT_STATE(2159738887L), - VBOX_E_HOST_ERROR(2159738888L), - VBOX_E_NOT_SUPPORTED(2159738889L), - VBOX_E_XML_ERROR(2159738890L), - VBOX_E_INVALID_SESSION_STATE(2159738891L), - VBOX_E_OBJECT_IN_USE(2159738892L), - VBOX_E_ACCESSDENIED(2147942405L), - VBOX_E_POINTER(2147500035L), - VBOX_E_FAIL(2147500037L), - VBOX_E_NOTIMPL(2147500033L), - VBOX_E_OUTOFMEMORY(2147942414L), - VBOX_E_INVALIDARG(2147942487L), - VBOX_E_UNEXPECTED(2147549183L), - VBOX_E_UNKNOWN_ERROR_CODE(-1L), - VBOX_E_ERROR_CODE_UNAVAILABLE(-2L); + VBOX_E_OBJECT_NOT_FOUND(2159738881L), VBOX_E_INVALID_VM_STATE(2159738882L), VBOX_E_VM_ERROR(2159738883L), VBOX_E_FILE_ERROR( + 2159738884L), VBOX_E_IPRT_ERROR(2159738885L), VBOX_E_PDM_ERROR(2159738886L), VBOX_E_INVALID_OBJECT_STATE( + 2159738887L), VBOX_E_HOST_ERROR(2159738888L), VBOX_E_NOT_SUPPORTED(2159738889L), VBOX_E_XML_ERROR(2159738890L), VBOX_E_INVALID_SESSION_STATE( + 2159738891L), VBOX_E_OBJECT_IN_USE(2159738892L), VBOX_E_ACCESSDENIED(2147942405L), VBOX_E_POINTER(2147500035L), VBOX_E_FAIL( + 2147500037L), VBOX_E_NOTIMPL(2147500033L), VBOX_E_OUTOFMEMORY(2147942414L), VBOX_E_INVALIDARG(2147942487L), VBOX_E_UNEXPECTED( + 2147549183L), VBOX_E_UNKNOWN_ERROR_CODE(-1L), VBOX_E_ERROR_CODE_UNAVAILABLE(-2L); private long code; @@ -84,8 +70,9 @@ public enum ErrorCode { /** * Returns an ErrorCode from the fault code given by the VirtualBox API. - * - * @param vboxException the exception to get the error code from. + * + * @param vboxException + * the exception to get the error code from. * @return an ErrorCode representing the given fault code. */ public static ErrorCode valueOf(VBoxException vboxException) { diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/ExecutionType.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/ExecutionType.java index fa986351ab..9d97f15fa1 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/ExecutionType.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/ExecutionType.java @@ -1,4 +1,4 @@ -/* +/** * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -21,10 +21,7 @@ package org.jclouds.virtualbox.domain; public enum ExecutionType { - GUI("gui"), - HEADLESS("headless"), - SDL("sdl"), - EMERGENCYSTOP("emergencystop"); + GUI("gui"), HEADLESS("headless"), SDL("sdl"), EMERGENCYSTOP("emergencystop"); private final String type; diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/YamlImage.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/YamlImage.java index fb4c472c76..61a40d828c 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/YamlImage.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/domain/YamlImage.java @@ -41,73 +41,73 @@ import com.google.common.collect.Maps; * Serializes to the following * *
-id: myTestId
-      name: ubuntu-11.04-server-i386
-      description: ubuntu 11.04 server (i386)
-      os_arch: x86
-      os_family: linux
-      os_description: ubuntu
-      os_version: 11.04
-      iso: http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso
-      keystroke_sequence: |
-                 
-                /install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg 
-                debian-installer=en_US auto locale=en_US kbd-chooser/method=us 
-                hostname=vmName 
-                fb=false debconf/frontend=noninteractive 
-                keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false 
-                initrd=/install/initrd.gz -- 
-      preseed_cfg: |                
-                      ## Options to set on the command line
-                      d-i debian-installer/locale string en_US.utf8
-                      d-i console-setup/ask_detect boolean false
-                      d-i console-setup/layout string USA
-                      d-i netcfg/get_hostname string unassigned-hostname
-                      d-i netcfg/get_domain string unassigned-domain
-                      # Continue without a default route
-                      # Not working , specify a dummy in the DHCP
-                      d-i time/zone string UTC
-                      d-i clock-setup/utc-auto boolean true
-                      d-i clock-setup/utc boolean true
-                      d-i kbd-chooser/method	select	American English
-                      d-i netcfg/wireless_wep string
-                      d-i base-installer/kernel/override-image string linux-server
-                      # Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive
-                      d-i debconf debconf/frontend select Noninteractive
-                      d-i pkgsel/install-language-support boolean false
-                      tasksel tasksel/first multiselect standard, ubuntu-server
-                      d-i partman-auto/method string lvm
-                      d-i partman-lvm/confirm boolean true
-                      d-i partman-lvm/device_remove_lvm boolean true
-                      d-i partman-auto/choose_recipe select atomic
-                      d-i partman/confirm_write_new_label boolean true
-                      d-i partman/confirm_nooverwrite boolean true
-                      d-i partman/choose_partition select finish
-                      d-i partman/confirm boolean true
-                      # Write the changes to disks and configure LVM?
-                      d-i partman-lvm/confirm boolean true
-                      d-i partman-lvm/confirm_nooverwrite boolean true
-                      d-i partman-auto-lvm/guided_size string max
-                      ## Default user, we can get away with a recipe to change this
-                      d-i passwd/user-fullname string toor
-                      d-i passwd/username string toor
-                      d-i passwd/user-password password password
-                      d-i passwd/user-password-again password password
-                      d-i user-setup/encrypt-home boolean false
-                      d-i user-setup/allow-password-weak boolean true
-                      # Individual additional packages to install
-                      d-i pkgsel/include string openssh-server ntp
-                      # Whether to upgrade packages after debootstrap.
-                      # Allowed values: none, safe-upgrade, full-upgrade
-                      d-i pkgsel/upgrade select full-upgrade
-                      d-i grub-installer/only_debian boolean true
-                      d-i grub-installer/with_other_os boolean true
-                      d-i finish-install/reboot_in_progress note
-                      #For the update
-                      d-i pkgsel/update-policy select none
-                      # debconf-get-selections --install
-                      #Use mirror
-                      choose-mirror-bin mirror/http/proxy string
+ * id: myTestId
+ *       name: ubuntu-11.04-server-i386
+ *       description: ubuntu 11.04 server (i386)
+ *       os_arch: x86
+ *       os_family: linux
+ *       os_description: ubuntu
+ *       os_version: 11.04
+ *       iso: http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso
+ *       keystroke_sequence: |
+ *                  
+ *                 /install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg 
+ *                 debian-installer=en_US auto locale=en_US kbd-chooser/method=us 
+ *                 hostname=vmName 
+ *                 fb=false debconf/frontend=noninteractive 
+ *                 keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false 
+ *                 initrd=/install/initrd.gz -- 
+ *       preseed_cfg: |                
+ *                       ## Options to set on the command line
+ *                       d-i debian-installer/locale string en_US.utf8
+ *                       d-i console-setup/ask_detect boolean false
+ *                       d-i console-setup/layout string USA
+ *                       d-i netcfg/get_hostname string unassigned-hostname
+ *                       d-i netcfg/get_domain string unassigned-domain
+ *                       # Continue without a default route
+ *                       # Not working , specify a dummy in the DHCP
+ *                       d-i time/zone string UTC
+ *                       d-i clock-setup/utc-auto boolean true
+ *                       d-i clock-setup/utc boolean true
+ *                       d-i kbd-chooser/method	select	American English
+ *                       d-i netcfg/wireless_wep string
+ *                       d-i base-installer/kernel/override-image string linux-server
+ *                       # Choices: Dialog, Readline, Gnome, Kde, Editor, Noninteractive
+ *                       d-i debconf debconf/frontend select Noninteractive
+ *                       d-i pkgsel/install-language-support boolean false
+ *                       tasksel tasksel/first multiselect standard, ubuntu-server
+ *                       d-i partman-auto/method string lvm
+ *                       d-i partman-lvm/confirm boolean true
+ *                       d-i partman-lvm/device_remove_lvm boolean true
+ *                       d-i partman-auto/choose_recipe select atomic
+ *                       d-i partman/confirm_write_new_label boolean true
+ *                       d-i partman/confirm_nooverwrite boolean true
+ *                       d-i partman/choose_partition select finish
+ *                       d-i partman/confirm boolean true
+ *                       # Write the changes to disks and configure LVM?
+ *                       d-i partman-lvm/confirm boolean true
+ *                       d-i partman-lvm/confirm_nooverwrite boolean true
+ *                       d-i partman-auto-lvm/guided_size string max
+ *                       ## Default user, we can get away with a recipe to change this
+ *                       d-i passwd/user-fullname string toor
+ *                       d-i passwd/username string toor
+ *                       d-i passwd/user-password password password
+ *                       d-i passwd/user-password-again password password
+ *                       d-i user-setup/encrypt-home boolean false
+ *                       d-i user-setup/allow-password-weak boolean true
+ *                       # Individual additional packages to install
+ *                       d-i pkgsel/include string openssh-server ntp
+ *                       # Whether to upgrade packages after debootstrap.
+ *                       # Allowed values: none, safe-upgrade, full-upgrade
+ *                       d-i pkgsel/upgrade select full-upgrade
+ *                       d-i grub-installer/only_debian boolean true
+ *                       d-i grub-installer/with_other_os boolean true
+ *                       d-i finish-install/reboot_in_progress note
+ *                       #For the update
+ *                       d-i pkgsel/update-policy select none
+ *                       # debconf-get-selections --install
+ *                       #Use mirror
+ *                       choose-mirror-bin mirror/http/proxy string
  * 
* * @author Kelvin Kakugawa @@ -143,14 +143,11 @@ public class YamlImage { return null; OsFamily family = parseOsFamilyOrUnrecognized(arg0.os_family); - OperatingSystem operatingSystem = OperatingSystem.builder() - .description(arg0.os_description) - .family(family) - .version(arg0.os_version) - .is64Bit(arg0.os_64bit) - .build(); + OperatingSystem operatingSystem = OperatingSystem.builder().description(arg0.os_description).family(family) + .version(arg0.os_version).is64Bit(arg0.os_64bit).build(); - return new ImageBuilder().id(arg0.id).name(arg0.name).description(arg0.description).operatingSystem(operatingSystem).build(); + return new ImageBuilder().id(arg0.id).name(arg0.name).description(arg0.description) + .operatingSystem(operatingSystem).build(); } }; diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExists.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExists.java index 69628e8d05..b3c52b1cc4 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExists.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AddIDEControllerIfNotExists.java @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ + package org.jclouds.virtualbox.functions; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachine.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachine.java index dc60249a94..c40fedc811 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachine.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachine.java @@ -1,4 +1,4 @@ -/* +/** * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -19,10 +19,11 @@ package org.jclouds.virtualbox.functions; -import com.google.common.base.Function; +import javax.annotation.Nullable; + import org.virtualbox_4_1.IMachine; -import javax.annotation.Nullable; +import com.google.common.base.Function; /** * @author Mattias Holmqvist diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachDistroMediumToMachine.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachDistroMediumToMachine.java index 253b2c5fbf..e4325e70c2 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachDistroMediumToMachine.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachDistroMediumToMachine.java @@ -19,13 +19,14 @@ package org.jclouds.virtualbox.functions; -import com.google.common.base.Function; +import javax.annotation.Nullable; + import org.virtualbox_4_1.DeviceType; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IMedium; import org.virtualbox_4_1.VBoxException; -import javax.annotation.Nullable; +import com.google.common.base.Function; /** * @author Mattias Holmqvist diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttached.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttached.java index 4d88b5e2e0..81bff200c8 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttached.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttached.java @@ -19,12 +19,14 @@ package org.jclouds.virtualbox.functions; -import com.google.common.base.Function; -import org.virtualbox_4_1.*; - import javax.annotation.Nullable; -import static org.virtualbox_4_1.DeviceType.HardDisk; +import org.virtualbox_4_1.DeviceType; +import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_1.IMedium; +import org.virtualbox_4_1.VBoxException; + +import com.google.common.base.Function; /** * @author Mattias Holmqvist @@ -37,7 +39,8 @@ public class AttachMediumToMachineIfNotAlreadyAttached implements Function private void createBaseStorage(IMedium hardDisk) { try { long size = 4L * 1024L * 1024L * 1024L - 4L; - IProgress storageCreation = hardDisk.createBaseStorage(size, (long) org.virtualbox_4_1.jaxws.MediumVariant.STANDARD.ordinal()); + IProgress storageCreation = hardDisk.createBaseStorage(size, + (long) org.virtualbox_4_1.jaxws.MediumVariant.STANDARD.ordinal()); storageCreation.waitForCompletion(-1); } catch (VBoxException e) { if (fileNotFoundException(e)) { - // File for medium could not be found. Something wrong with creation. + // File for medium could not be found. Something wrong with + // creation. hardDisk.deleteStorage(); } if (!storageAlreadyExists(e)) { - // Hard disk file was created but the storage had been created before that. + // Hard disk file was created but the storage had been created + // before that. throw e; } } @@ -90,8 +99,8 @@ public class CreateMediumIfNotAlreadyExists implements Function } private boolean storageAlreadyExists(VBoxException e) { - return e.getMessage().indexOf("VirtualBox error: Storage for the medium ") != -1 && - e.getMessage().indexOf("is already created") != -1; + return e.getMessage().indexOf("VirtualBox error: Storage for the medium ") != -1 + && e.getMessage().indexOf("is already created") != -1; } } diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToHardware.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToHardware.java index 1c30996721..3bebaa7c40 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToHardware.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToHardware.java @@ -44,7 +44,6 @@ public class IMachineToHardware implements Function { public Hardware apply(@Nullable IMachine vm) { String osTypeId = vm.getOSTypeId(); - IGuestOSType guestOSType = virtualBoxManager.getVBox().getGuestOSType(osTypeId); Boolean is64Bit = guestOSType.getIs64Bit(); HardwareBuilder hardwareBuilder = new HardwareBuilder(); diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToImage.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToImage.java index 8e5454c8d0..b3b4f26a05 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToImage.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToImage.java @@ -58,8 +58,7 @@ public class IMachineToImage implements Function { IGuestOSType guestOSType = virtualboxManager.getVBox().getGuestOSType(from.getOSTypeId()); OsFamily family = parseOsFamilyOrUnrecognized(guestOSType.getDescription()); - String version = parseVersionOrReturnEmptyString(family, guestOSType.getDescription(), - osVersionMap); + String version = parseVersionOrReturnEmptyString(family, guestOSType.getDescription(), osVersionMap); OperatingSystem os = OperatingSystem.builder().description(guestOSType.getDescription()).family(family) .version(version).is64Bit(guestOSType.getIs64Bit()).build(); diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToIpAddress.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToIpAddress.java index 0fef44fd8f..f7727e90ca 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToIpAddress.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToIpAddress.java @@ -19,7 +19,10 @@ package org.jclouds.virtualbox.functions; -import com.google.common.base.Function; +import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; + +import javax.annotation.Nullable; + import org.jclouds.compute.ComputeService; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.options.RunScriptOptions; @@ -28,13 +31,11 @@ import org.virtualbox_4_1.IGuestOSType; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.VirtualBoxManager; -import javax.annotation.Nullable; - -import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; +import com.google.common.base.Function; /** * Get an IP address from an IMachine using arp of the host machine. - * + * * @author Mattias Holmqvist, Andrea Turli */ public class IMachineToIpAddress implements Function { @@ -63,18 +64,25 @@ public class IMachineToIpAddress implements Function { IMachine hostMachine = manager.getVBox().findMachine(hostId); if (isOSX(hostMachine)) { if (simplifiedMacAddressOfClonedVM.contains("00")) - simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(simplifiedMacAddressOfClonedVM.indexOf("00"), simplifiedMacAddressOfClonedVM.indexOf("00") + 1).toString(); + simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete( + simplifiedMacAddressOfClonedVM.indexOf("00"), simplifiedMacAddressOfClonedVM.indexOf("00") + 1) + .toString(); if (simplifiedMacAddressOfClonedVM.contains("0")) - if (simplifiedMacAddressOfClonedVM.indexOf("0") + 1 != ':' && simplifiedMacAddressOfClonedVM.indexOf("0") - 1 != ':') - simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete(simplifiedMacAddressOfClonedVM.indexOf("0"), simplifiedMacAddressOfClonedVM.indexOf("0") + 1).toString(); + if (simplifiedMacAddressOfClonedVM.indexOf("0") + 1 != ':' + && simplifiedMacAddressOfClonedVM.indexOf("0") - 1 != ':') + simplifiedMacAddressOfClonedVM = new StringBuffer(simplifiedMacAddressOfClonedVM).delete( + simplifiedMacAddressOfClonedVM.indexOf("0"), simplifiedMacAddressOfClonedVM.indexOf("0") + 1) + .toString(); } // TODO: This is both shell-dependent and hard-coded. Needs to be fixed. - ExecResponse execResponse = runScriptOnNode(hostId, "for i in {1..254} ; do ping -c 1 -t 1 192.168.2.$i & done", runAsRoot(false).wrapInInitScript(false)); + ExecResponse execResponse = runScriptOnNode(hostId, "for i in {1..254} ; do ping -c 1 -t 1 192.168.2.$i & done", + runAsRoot(false).wrapInInitScript(false)); System.out.println(execResponse); - String arpLine = runScriptOnNode(hostId, "arp -an | grep " + simplifiedMacAddressOfClonedVM, runAsRoot(false).wrapInInitScript(false)).getOutput(); + String arpLine = runScriptOnNode(hostId, "arp -an | grep " + simplifiedMacAddressOfClonedVM, + runAsRoot(false).wrapInInitScript(false)).getOutput(); String ipAddress = arpLine.substring(arpLine.indexOf("(") + 1, arpLine.indexOf(")")); System.out.println("IP address " + ipAddress); return ipAddress; diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java index 7dc2a07c62..808b30efa5 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadata.java @@ -19,8 +19,19 @@ package org.jclouds.virtualbox.functions; -import com.google.common.base.Function; -import org.jclouds.compute.domain.*; +import static org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule.machineToNodeState; + +import java.util.HashSet; +import java.util.Set; + +import javax.annotation.Resource; +import javax.inject.Named; + +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeMetadataBuilder; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.compute.domain.Processor; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Credentials; import org.jclouds.domain.LocationBuilder; @@ -31,12 +42,7 @@ import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.INetworkAdapter; import org.virtualbox_4_1.MachineState; -import javax.annotation.Resource; -import javax.inject.Named; -import java.util.HashSet; -import java.util.Set; - -import static org.jclouds.virtualbox.config.VirtualBoxComputeServiceContextModule.machineToNodeState; +import com.google.common.base.Function; public class IMachineToNodeMetadata implements Function { @@ -57,7 +63,7 @@ public class IMachineToNodeMetadata implements Function locationBuilder.id(""); locationBuilder.scope(LocationScope.HOST); nodeMetadataBuilder.location(locationBuilder.build()); - + HardwareBuilder hardwareBuilder = new HardwareBuilder(); hardwareBuilder.ram(vm.getMemorySize().intValue()); @@ -75,7 +81,6 @@ public class IMachineToNodeMetadata implements Function nodeMetadataBuilder.hostname(vm.getName()); nodeMetadataBuilder.loginPort(18083); - MachineState vmState = vm.getState(); NodeState nodeState = machineToNodeState.get(vmState); if (nodeState == null) @@ -90,8 +95,8 @@ public class IMachineToNodeMetadata implements Function System.out.println("Interface: " + bridgedInterface); } -// nodeMetadataBuilder.imageId(""); -// nodeMetadataBuilder.group(""); + // nodeMetadataBuilder.imageId(""); + // nodeMetadataBuilder.group(""); String provider = "virtualbox"; String identity = System.getProperty("test." + provider + ".identity", "administrator"); @@ -101,5 +106,5 @@ public class IMachineToNodeMetadata implements Function nodeMetadataBuilder.id(vm.getId()); return nodeMetadataBuilder.build(); } - + } 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 9761738a15..932a9a22b6 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 @@ -19,8 +19,22 @@ package org.jclouds.virtualbox.functions; -import com.google.common.base.Function; -import com.google.inject.Inject; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; +import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_WORKINGDIR; +import static org.virtualbox_4_1.AccessMode.ReadOnly; +import static org.virtualbox_4_1.DeviceType.DVD; +import static org.virtualbox_4_1.DeviceType.HardDisk; +import static org.virtualbox_4_1.LockType.Shared; +import static org.virtualbox_4_1.LockType.Write; + +import java.io.File; + +import javax.annotation.Resource; +import javax.inject.Named; + import org.eclipse.jetty.server.Server; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.ExecResponse; @@ -34,22 +48,18 @@ import org.jclouds.virtualbox.config.VirtualBoxConstants; import org.jclouds.virtualbox.domain.ExecutionType; import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning; import org.jclouds.virtualbox.settings.KeyboardScancodes; -import org.virtualbox_4_1.*; +import org.virtualbox_4_1.AccessMode; +import org.virtualbox_4_1.DeviceType; +import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_1.IMedium; +import org.virtualbox_4_1.IProgress; +import org.virtualbox_4_1.ISession; +import org.virtualbox_4_1.LockType; +import org.virtualbox_4_1.VBoxException; +import org.virtualbox_4_1.VirtualBoxManager; -import javax.annotation.Resource; -import javax.inject.Named; -import java.io.File; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; -import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript; -import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_INSTALLATION_KEY_SEQUENCE; -import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_WORKINGDIR; -import static org.virtualbox_4_1.AccessMode.ReadOnly; -import static org.virtualbox_4_1.DeviceType.DVD; -import static org.virtualbox_4_1.DeviceType.HardDisk; -import static org.virtualbox_4_1.LockType.Shared; -import static org.virtualbox_4_1.LockType.Write; +import com.google.common.base.Function; +import com.google.inject.Inject; public class IsoToIMachine implements Function { @@ -73,8 +83,8 @@ public class IsoToIMachine implements Function { @Inject public IsoToIMachine(VirtualBoxManager manager, String adminDisk, String diskFormat, String settingsFile, - String vmName, String osTypeId, String vmId, boolean forceOverwrite, String controllerIDE, - ComputeServiceContext context, String hostId, String guestId, Credentials credentials) { + String vmName, String osTypeId, String vmId, boolean forceOverwrite, String controllerIDE, + ComputeServiceContext context, String hostId, String guestId, Credentials credentials) { super(); this.manager = manager; this.adminDisk = adminDisk; @@ -98,7 +108,8 @@ public class IsoToIMachine implements Function { String baseResource = "."; Server server = new StartJettyIfNotAlreadyRunning(port).apply(baseResource); - IMachine vm = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(settingsFile, osTypeId, vmId, forceOverwrite, manager).apply(vmName); + IMachine vm = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(settingsFile, osTypeId, vmId, forceOverwrite, + manager).apply(vmName); String defaultWorkingDir = System.getProperty("user.home") + "/jclouds-virtualbox-test"; String workingDir = System.getProperty(VIRTUALBOX_WORKINGDIR, defaultWorkingDir); @@ -129,7 +140,7 @@ public class IsoToIMachine implements Function { String guestAdditionsDvd = workingDir + "/VBoxGuestAdditions_4.1.2.iso"; final IMedium guestAdditionsDvdMedium = manager.getVBox().openMedium(guestAdditionsDvd, DeviceType.DVD, - AccessMode.ReadOnly, forceOverwrite); + AccessMode.ReadOnly, forceOverwrite); // Guest additions ensureGuestAdditionsMediumIsAttached(vmName, guestAdditionsDvdMedium); @@ -178,13 +189,13 @@ public class IsoToIMachine implements Function { } private void ensureGuestAdditionsMediumIsAttached(String vmName, final IMedium guestAdditionsDvdMedium) { - lockMachineAndApply(manager, Write, vmName, - new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, guestAdditionsDvdMedium, 1, 1, DeviceType.DVD)); + lockMachineAndApply(manager, Write, vmName, new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, + guestAdditionsDvdMedium, 1, 1, DeviceType.DVD)); } private void ensureMachineHasHardDiskAttached(String vmName, IMedium hardDisk) { - lockMachineAndApply(manager, Write, vmName, - new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, 0, 1, HardDisk)); + lockMachineAndApply(manager, Write, vmName, new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, + hardDisk, 0, 1, HardDisk)); } private void ensureMachineHasMemory(String vmName, final long memorySize) { @@ -198,10 +209,12 @@ public class IsoToIMachine implements Function { private void ensureMachineHasAttachedDistroMedium(String isoName, String workingDir, String controllerIDE) { final String pathToIsoFile = checkFileExists(workingDir + "/" + isoName); final IMedium distroMedium = manager.getVBox().openMedium(pathToIsoFile, DVD, ReadOnly, forceOverwrite); - lockMachineAndApply(manager, Write, vmName, - new AttachDistroMediumToMachine( - checkNotNull(controllerIDE, "controllerIDE"), - checkNotNull(distroMedium, "distroMedium"))); + lockMachineAndApply( + manager, + Write, + vmName, + new AttachDistroMediumToMachine(checkNotNull(controllerIDE, "controllerIDE"), checkNotNull(distroMedium, + "distroMedium"))); } public static String checkFileExists(String filePath) { @@ -213,7 +226,7 @@ public class IsoToIMachine implements Function { public void ensureMachineHasIDEControllerNamed(String vmName, String controllerIDE) { lockMachineAndApply(manager, Write, checkNotNull(vmName, "vmName"), - new AddIDEControllerIfNotExists(checkNotNull(controllerIDE, "controllerIDE"))); + new AddIDEControllerIfNotExists(checkNotNull(controllerIDE, "controllerIDE"))); } private T applyForMachine(VirtualBoxManager manager, final String machineId, final Function function) { @@ -232,7 +245,7 @@ public class IsoToIMachine implements Function { } public static T lockMachineAndApply(VirtualBoxManager manager, final LockType type, final String machineId, - final Function function) { + final Function function) { return lockSessionOnMachineAndApply(manager, type, machineId, new Function() { @Override @@ -250,7 +263,7 @@ public class IsoToIMachine implements Function { } public static T lockSessionOnMachineAndApply(VirtualBoxManager manager, LockType type, String machineId, - Function function) { + Function function) { try { ISession session = manager.getSessionObject(); IMachine immutableMachine = manager.getVBox().findMachine(machineId); @@ -262,17 +275,17 @@ public class IsoToIMachine implements Function { } } catch (VBoxException e) { throw new RuntimeException(String.format("error applying %s to %s with %s lock: %s", function, machineId, - type, e.getMessage()), e); + type, e.getMessage()), e); } } private String defaultInstallSequence() { return " " - + "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg " - + "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + "hostname=" + vmName + " " - + "fb=false debconf/frontend=noninteractive " - + "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false " - + "initrd=/install/initrd.gz -- "; + + "/install/vmlinuz noapic preseed/url=http://10.0.2.2:8080/src/test/resources/preseed.cfg " + + "debian-installer=en_US auto locale=en_US kbd-chooser/method=us " + "hostname=" + vmName + " " + + "fb=false debconf/frontend=noninteractive " + + "keyboard-configuration/layout=USA keyboard-configuration/variant=USA console-setup/ask_detect=false " + + "initrd=/install/initrd.gz -- "; } private void sendKeyboardSequence(String keyboardSequence) { diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunning.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunning.java index a118c77658..8c7059f9c4 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunning.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunning.java @@ -19,34 +19,36 @@ package org.jclouds.virtualbox.functions; -import com.google.common.base.Function; -import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.logging.Logger; -import org.jclouds.virtualbox.domain.ErrorCode; -import org.jclouds.virtualbox.domain.ExecutionType; -import org.virtualbox_4_1.*; -import org.virtualbox_4_1.jaxws.RuntimeFaultMsg; +import static com.google.common.base.Throwables.propagate; import javax.annotation.Nullable; import javax.annotation.Resource; import javax.inject.Named; -import javax.lang.model.type.ExecutableType; -import static com.google.common.base.Throwables.propagate; -import static javax.xml.bind.DatatypeConverter.parseUnsignedInt; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.virtualbox.domain.ErrorCode; +import org.jclouds.virtualbox.domain.ExecutionType; +import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_1.IProgress; +import org.virtualbox_4_1.VBoxException; +import org.virtualbox_4_1.VirtualBoxManager; + +import com.google.common.base.Function; /** - * Starts a machine using launchMachine() with the provided type and environment. + * Starts a machine using launchMachine() with the provided type and + * environment. *

- * Note that launchMachine() may throw VBoxException with the following error codes: + * Note that launchMachine() may throw VBoxException with the following error + * codes: *

- * VBOX_E_UNEXPECTED: Virtual machine not registered. - * VBOX_E_INVALIDARG: Invalid session type type. - * VBOX_E_OBJECT_NOT_FOUND: No machine matching machineId found. - * VBOX_E_INVALID_OBJECT_STATE: Session already open or being opened. - * VBOX_E_IPRT_ERROR: Launching process for machine failed. - * VBOX_E_VM_ERROR: Failed to assign machine to session. - * + * VBOX_E_UNEXPECTED: Virtual machine not registered. VBOX_E_INVALIDARG: Invalid + * session type type. VBOX_E_OBJECT_NOT_FOUND: No machine matching machineId + * found. VBOX_E_INVALID_OBJECT_STATE: Session already open or being opened. + * VBOX_E_IPRT_ERROR: Launching process for machine failed. VBOX_E_VM_ERROR: + * Failed to assign machine to session. + * * @author Mattias Holmqvist * * @see ErrorCode @@ -70,7 +72,8 @@ public class LaunchMachineIfNotAlreadyRunning implements Function { @Inject public FileDownloadFromURI(final ComputeServiceContext context, - @Named(VIRTUALBOX_WORKINGDIR) final String workingDir, - @Named(VirtualBoxConstants.VIRTUALBOX_ISOFILE) final String isoFile) { + @Named(VIRTUALBOX_WORKINGDIR) final String workingDir, + @Named(VirtualBoxConstants.VIRTUALBOX_ISOFILE) final String isoFile) { this.context = context; this.workingDir = workingDir; this.isoFile = isoFile; diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStream.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStream.java index fc68e70fd5..c6ec3a02da 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStream.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStream.java @@ -1,28 +1,4 @@ -package org.jclouds.virtualbox.functions.admin; - -import com.google.common.base.Function; -import com.google.common.base.Functions; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.CacheLoader; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; -import org.jclouds.compute.domain.Image; -import org.jclouds.virtualbox.domain.YamlImage; -import org.yaml.snakeyaml.Loader; -import org.yaml.snakeyaml.TypeDescription; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.Constructor; - -import javax.inject.Singleton; -import java.io.InputStream; -import java.util.List; -import java.util.Map; - -import static com.google.common.base.Preconditions.checkState; - /** - * * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -39,7 +15,34 @@ import static com.google.common.base.Preconditions.checkState; * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - * + */ + +package org.jclouds.virtualbox.functions.admin; + +import static com.google.common.base.Preconditions.checkState; + +import java.io.InputStream; +import java.util.List; +import java.util.Map; + +import javax.inject.Singleton; + +import org.jclouds.compute.domain.Image; +import org.jclouds.virtualbox.domain.YamlImage; +import org.yaml.snakeyaml.Loader; +import org.yaml.snakeyaml.TypeDescription; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.Constructor; + +import com.google.common.base.Function; +import com.google.common.base.Functions; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; + +/** * * @author Andrea Turli */ @@ -53,12 +56,12 @@ public class ImageFromYamlStream implements Function images; } - + private Object construct(String data) { - Yaml yaml = new Yaml(); - return yaml.load(data); + Yaml yaml = new Yaml(); + return yaml.load(data); } - + @Override public Cache apply(InputStream source) { @@ -74,15 +77,15 @@ public class ImageFromYamlStream implements Function backingMap = Maps.uniqueIndex(Iterables.transform(config.images, YamlImage.toImage), - new Function() { - public String apply(Image image) { - return image.getId(); - } - }); - Cache cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap))); - for (String node : backingMap.keySet()) - cache.getUnchecked(node); - return cache; + new Function() { + public String apply(Image image) { + return image.getId(); + } + }); + Cache cache = CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(backingMap))); + for (String node : backingMap.keySet()) + cache.getUnchecked(node); + return cache; } - + } \ No newline at end of file diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartJettyIfNotAlreadyRunning.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartJettyIfNotAlreadyRunning.java index 9d9538a55d..96d5e4c21f 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartJettyIfNotAlreadyRunning.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartJettyIfNotAlreadyRunning.java @@ -43,65 +43,65 @@ import com.google.inject.Singleton; */ public class StartJettyIfNotAlreadyRunning implements Function { - @Resource - @Named(ComputeServiceConstants.COMPUTE_LOGGER) - protected Logger logger = Logger.NULL; + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; - private final int port; + private final int port; - @Inject - public StartJettyIfNotAlreadyRunning( - @Named(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT) final String port) { - this.port = Integer.parseInt(port); - } + @Inject + public StartJettyIfNotAlreadyRunning(@Named(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT) final String port) { + this.port = Integer.parseInt(port); + } - @Override - public Server apply(@Nullable String baseResource) { - final Server server = ServerJetty.getInstance().getServer(); + @Override + public Server apply(@Nullable String baseResource) { + final Server server = ServerJetty.getInstance().getServer(); - if (!server.getState().equals(Server.STARTED) && !new InetSocketAddressConnect().apply(new IPSocket("localhost", port))) { - ResourceHandler resource_handler = new ResourceHandler(); - resource_handler.setDirectoriesListed(true); - resource_handler.setWelcomeFiles(new String[] { "index.html" }); + if (!server.getState().equals(Server.STARTED) + && !new InetSocketAddressConnect().apply(new IPSocket("localhost", port))) { + ResourceHandler resource_handler = new ResourceHandler(); + resource_handler.setDirectoriesListed(true); + resource_handler.setWelcomeFiles(new String[] { "index.html" }); - resource_handler.setResourceBase(baseResource); - logger.info("serving " + resource_handler.getBaseResource()); + resource_handler.setResourceBase(baseResource); + logger.info("serving " + resource_handler.getBaseResource()); - HandlerList handlers = new HandlerList(); - handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() }); - server.setHandler(handlers); + HandlerList handlers = new HandlerList(); + handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() }); + server.setHandler(handlers); - try { - server.start(); - } catch (Exception e) { - logger.error(e, "Server jetty could not be started at this %s", baseResource); - } - return server; - } else { - logger.debug("Server jetty serving %s already running. Skipping start", baseResource); - return server; - } + try { + server.start(); + } catch (Exception e) { + logger.error(e, "Server jetty could not be started at this %s", baseResource); + } + return server; + } else { + logger.debug("Server jetty serving %s already running. Skipping start", baseResource); + return server; + } - } - - @Singleton - private static class ServerJetty { - private static ServerJetty instance; - private Server server; - private String port = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080"); + } - private ServerJetty() { - this.server = new Server(Integer.parseInt(port)); - } + @Singleton + private static class ServerJetty { + private static ServerJetty instance; + private Server server; + private String port = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080"); - public static ServerJetty getInstance() { - if (instance == null) - instance = new ServerJetty(); - return instance; - } + private ServerJetty() { + this.server = new Server(Integer.parseInt(port)); + } - public Server getServer() { - return server; - } - } + public static ServerJetty getInstance() { + if (instance == null) + instance = new ServerJetty(); + return instance; + } + + public Server getServer() { + return server; + } + } } diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java index 4add602999..9da826f9f1 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java @@ -20,8 +20,14 @@ package org.jclouds.virtualbox.functions.admin; -import com.google.common.base.Function; -import com.google.common.cache.Cache; +import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; + +import java.net.URI; + +import javax.annotation.Nullable; +import javax.annotation.Resource; +import javax.inject.Named; + import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Credentials; @@ -30,14 +36,7 @@ import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.virtualbox_4_1.VirtualBoxManager; -import javax.annotation.Nullable; -import javax.annotation.Resource; -import javax.inject.Named; - -import java.net.URI; -import java.util.concurrent.ExecutionException; - -import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; +import com.google.common.base.Function; public class StartVBoxIfNotAlreadyRunning implements Function { diff --git a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/settings/KeyboardScancodes.java b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/settings/KeyboardScancodes.java index bbd00825d9..5491364a11 100644 --- a/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/settings/KeyboardScancodes.java +++ b/sandbox-apis/virtualbox/src/main/java/org/jclouds/virtualbox/settings/KeyboardScancodes.java @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ + package org.jclouds.virtualbox.settings; import java.util.Collections; @@ -24,138 +25,139 @@ import java.util.Map; public class KeyboardScancodes { - // http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html - - public static final Map NORMAL_KEYBOARD_BUTTON_MAP = createMap(); - public static final Map SPECIAL_KEYBOARD_BUTTON_MAP = createSpecialMap(); + // http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html - private static Map createMap() { - Map alphaToHex = new HashMap(); - alphaToHex.put("1", "02 82"); - alphaToHex.put("2", "03 83"); - alphaToHex.put("3", "04 84"); - alphaToHex.put("4", "05 85"); - alphaToHex.put("5", "06 86"); - alphaToHex.put("6", "07 87"); - alphaToHex.put("7", "08 88"); - alphaToHex.put("8", "09 89"); - alphaToHex.put("9", "0a 8a"); - alphaToHex.put("0", "0b 8b"); - alphaToHex.put("-", "0c 8c"); - alphaToHex.put("=", "0d 8d"); - alphaToHex.put("Tab", "0f 8f"); - alphaToHex.put("q", "10 90"); - alphaToHex.put("w", "11 91"); - alphaToHex.put("e", "12 92"); - alphaToHex.put("r", "13 93"); - alphaToHex.put("t", "14 94"); - alphaToHex.put("y", "15 95"); - alphaToHex.put("u", "16 96"); - alphaToHex.put("i", "17 97"); - alphaToHex.put("o", "18 98"); - alphaToHex.put("p", "19 99"); + public static final Map NORMAL_KEYBOARD_BUTTON_MAP = createMap(); + public static final Map SPECIAL_KEYBOARD_BUTTON_MAP = createSpecialMap(); - alphaToHex.put("Q", "2a 10 aa"); - alphaToHex.put("W", "2a 11 aa"); - alphaToHex.put("E", "2a 12 aa"); - alphaToHex.put("R", "2a 13 aa"); - alphaToHex.put("T", "2a 14 aa"); - alphaToHex.put("Y", "2a 15 aa"); - alphaToHex.put("U", "2a 16 aa"); - alphaToHex.put("I", "2a 17 aa"); - alphaToHex.put("O", "2a 18 aa"); - alphaToHex.put("P", "2a 19 aa"); + private static Map createMap() { + Map alphaToHex = new HashMap(); + alphaToHex.put("1", "02 82"); + alphaToHex.put("2", "03 83"); + alphaToHex.put("3", "04 84"); + alphaToHex.put("4", "05 85"); + alphaToHex.put("5", "06 86"); + alphaToHex.put("6", "07 87"); + alphaToHex.put("7", "08 88"); + alphaToHex.put("8", "09 89"); + alphaToHex.put("9", "0a 8a"); + alphaToHex.put("0", "0b 8b"); + alphaToHex.put("-", "0c 8c"); + alphaToHex.put("=", "0d 8d"); + alphaToHex.put("Tab", "0f 8f"); + alphaToHex.put("q", "10 90"); + alphaToHex.put("w", "11 91"); + alphaToHex.put("e", "12 92"); + alphaToHex.put("r", "13 93"); + alphaToHex.put("t", "14 94"); + alphaToHex.put("y", "15 95"); + alphaToHex.put("u", "16 96"); + alphaToHex.put("i", "17 97"); + alphaToHex.put("o", "18 98"); + alphaToHex.put("p", "19 99"); - alphaToHex.put("a", "1e 9e"); - alphaToHex.put("s", "1f 9f"); - alphaToHex.put("d", "20 a0"); - alphaToHex.put("f", "21 a1"); - alphaToHex.put("g", "22 a2"); - alphaToHex.put("h", "23 a3"); - alphaToHex.put("j", "24 a4"); - alphaToHex.put("k", "25 a5"); - alphaToHex.put("l", "26 a6"); + alphaToHex.put("Q", "2a 10 aa"); + alphaToHex.put("W", "2a 11 aa"); + alphaToHex.put("E", "2a 12 aa"); + alphaToHex.put("R", "2a 13 aa"); + alphaToHex.put("T", "2a 14 aa"); + alphaToHex.put("Y", "2a 15 aa"); + alphaToHex.put("U", "2a 16 aa"); + alphaToHex.put("I", "2a 17 aa"); + alphaToHex.put("O", "2a 18 aa"); + alphaToHex.put("P", "2a 19 aa"); - alphaToHex.put("A", "2a 1e aa 9e"); - alphaToHex.put("S", "2a 1f aa 9f"); - alphaToHex.put("D", "2a 20 aa a0"); - alphaToHex.put("F", "2a 21 aa a1"); - alphaToHex.put("G", "2a 22 aa a2"); - alphaToHex.put("H", "2a 23 aa a3"); - alphaToHex.put("J", "2a 24 aa a4"); - alphaToHex.put("K", "2a 25 aa a5"); - alphaToHex.put("L", "2a 26 aa a6"); + alphaToHex.put("a", "1e 9e"); + alphaToHex.put("s", "1f 9f"); + alphaToHex.put("d", "20 a0"); + alphaToHex.put("f", "21 a1"); + alphaToHex.put("g", "22 a2"); + alphaToHex.put("h", "23 a3"); + alphaToHex.put("j", "24 a4"); + alphaToHex.put("k", "25 a5"); + alphaToHex.put("l", "26 a6"); - alphaToHex.put(");", "27 a7"); - alphaToHex.put("\"", "2a 28 aa a8"); - alphaToHex.put("\"", "28 a8"); - alphaToHex.put("\\", "2b ab"); - alphaToHex.put("|", "2a 2b aa 8b"); - alphaToHex.put("[", "1a 9a"); - alphaToHex.put("", "1b 9b"); - alphaToHex.put("<", "2a 33 aa b3"); - alphaToHex.put(">", "2a 34 aa b4"); - alphaToHex.put("$", "2a 05 aa 85"); - alphaToHex.put("+", "2a 0d aa 8d"); + alphaToHex.put("A", "2a 1e aa 9e"); + alphaToHex.put("S", "2a 1f aa 9f"); + alphaToHex.put("D", "2a 20 aa a0"); + alphaToHex.put("F", "2a 21 aa a1"); + alphaToHex.put("G", "2a 22 aa a2"); + alphaToHex.put("H", "2a 23 aa a3"); + alphaToHex.put("J", "2a 24 aa a4"); + alphaToHex.put("K", "2a 25 aa a5"); + alphaToHex.put("L", "2a 26 aa a6"); - alphaToHex.put("z", "2c ac"); - alphaToHex.put("x", "2d ad"); - alphaToHex.put("c", "2e ae"); - alphaToHex.put("v", "2f af"); - alphaToHex.put("b", "30 b0"); - alphaToHex.put("n", "31 b1"); - alphaToHex.put("m", "32 b2"); - alphaToHex.put("Z", "2a 2c aa ac"); - alphaToHex.put("X", "2a 2d aa ad"); - alphaToHex.put("C", "2a 2e aa ae"); - alphaToHex.put("V", "2a 2f aa af"); - alphaToHex.put("B", "2a 30 aa b0"); - alphaToHex.put("N", "2a 31 aa b1"); - alphaToHex.put("M", "2a 32 aa b2"); + alphaToHex.put(");", "27 a7"); + alphaToHex.put("\"", "2a 28 aa a8"); + alphaToHex.put("\"", "28 a8"); + alphaToHex.put("\\", "2b ab"); + alphaToHex.put("|", "2a 2b aa 8b"); + alphaToHex.put("[", "1a 9a"); + alphaToHex.put("", "1b 9b"); + alphaToHex.put("<", "2a 33 aa b3"); + alphaToHex.put(">", "2a 34 aa b4"); + alphaToHex.put("$", "2a 05 aa 85"); + alphaToHex.put("+", "2a 0d aa 8d"); - alphaToHex.put(",", "33 b3"); - alphaToHex.put(".", "34 b4"); - alphaToHex.put("/", "35 b5"); - alphaToHex.put(":", "2a 27 aa a7"); - alphaToHex.put("%", "2a 06 aa 86"); - alphaToHex.put("_", "2a 0c aa 8c"); - alphaToHex.put("&", "2a 08 aa 88"); - alphaToHex.put("(", "2a 0a aa 8a"); - alphaToHex.put(")", "2a 0b aa 8b"); - return Collections.unmodifiableMap(alphaToHex); - } - private static Map createSpecialMap() { - Map special = new HashMap(); - special.put("", "1c 9c"); - special.put("", "0e 8e"); - special.put("", "39 b9"); - special.put("", "1c 9c"); - special.put("", "01 81"); - special.put("", "0f 8f"); - special.put("", "1d 38 0e"); - special.put("", "wait"); - - special.put("", "48 c8"); - special.put("", "50 d0"); - special.put("", "49 c9"); - special.put("", "51 d1"); - special.put("", "4f cf"); - special.put("", "52 d2"); - special.put("", "53 d3"); - special.put("", "4b cb"); - special.put("", "4d cd"); - special.put("", "47 c7"); - - special.put("", "3b"); - special.put("", "3c"); - special.put("", "3d"); - special.put("", "3e"); - special.put("", "3f"); - special.put("", "40"); - special.put("", "41"); - special.put("", "42"); - special.put("", "43"); - special.put("", "44"); - return Collections.unmodifiableMap(special); - } + alphaToHex.put("z", "2c ac"); + alphaToHex.put("x", "2d ad"); + alphaToHex.put("c", "2e ae"); + alphaToHex.put("v", "2f af"); + alphaToHex.put("b", "30 b0"); + alphaToHex.put("n", "31 b1"); + alphaToHex.put("m", "32 b2"); + alphaToHex.put("Z", "2a 2c aa ac"); + alphaToHex.put("X", "2a 2d aa ad"); + alphaToHex.put("C", "2a 2e aa ae"); + alphaToHex.put("V", "2a 2f aa af"); + alphaToHex.put("B", "2a 30 aa b0"); + alphaToHex.put("N", "2a 31 aa b1"); + alphaToHex.put("M", "2a 32 aa b2"); + + alphaToHex.put(",", "33 b3"); + alphaToHex.put(".", "34 b4"); + alphaToHex.put("/", "35 b5"); + alphaToHex.put(":", "2a 27 aa a7"); + alphaToHex.put("%", "2a 06 aa 86"); + alphaToHex.put("_", "2a 0c aa 8c"); + alphaToHex.put("&", "2a 08 aa 88"); + alphaToHex.put("(", "2a 0a aa 8a"); + alphaToHex.put(")", "2a 0b aa 8b"); + return Collections.unmodifiableMap(alphaToHex); + } + + private static Map createSpecialMap() { + Map special = new HashMap(); + special.put("", "1c 9c"); + special.put("", "0e 8e"); + special.put("", "39 b9"); + special.put("", "1c 9c"); + special.put("", "01 81"); + special.put("", "0f 8f"); + special.put("", "1d 38 0e"); + special.put("", "wait"); + + special.put("", "48 c8"); + special.put("", "50 d0"); + special.put("", "49 c9"); + special.put("", "51 d1"); + special.put("", "4f cf"); + special.put("", "52 d2"); + special.put("", "53 d3"); + special.put("", "4b cb"); + special.put("", "4d cd"); + special.put("", "47 c7"); + + special.put("", "3b"); + special.put("", "3c"); + special.put("", "3d"); + special.put("", "3e"); + special.put("", "3f"); + special.put("", "40"); + special.put("", "41"); + special.put("", "42"); + special.put("", "43"); + special.put("", "44"); + return Collections.unmodifiableMap(special); + } } diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java index f4f35dea00..893eb6a392 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java @@ -19,11 +19,12 @@ package org.jclouds.virtualbox.compute; -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; -import com.google.inject.Guice; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; + +import java.net.URI; +import java.util.Map; + import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.Image; @@ -44,11 +45,11 @@ import org.testng.annotations.Test; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.VirtualBoxManager; -import java.net.URI; -import java.util.Map; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; +import com.google.common.base.Function; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; +import com.google.inject.Guice; @Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest") public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest { @@ -57,15 +58,15 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien private IMachine machine; private final Map> osVersionMap = new BaseComputeServiceContextModule() { }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule()) - .getInstance(Json.class)); + .getInstance(Json.class)); - @BeforeGroups(groups = {"live"}) + @BeforeGroups(groups = { "live" }) public void setupClient() { super.setupClient(); final VirtualBoxManager manager = getManager(); Function iMachineToImage = new IMachineToImage(manager, osVersionMap); - adapter = new VirtualBoxComputeServiceAdapter(manager, - new JustProvider(provider, URI.create(endpoint), ImmutableSet.of()), iMachineToImage); + adapter = new VirtualBoxComputeServiceAdapter(manager, new JustProvider(provider, URI.create(endpoint), + ImmutableSet. of()), iMachineToImage); } protected VirtualBoxManager getManager() { @@ -89,15 +90,16 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien // check other things, like cpu correct, mem correct, image/os is correct // (as possible) assert credentialStore.containsKey("node#" + machine.getId()) : "credentials to log into machine not found " - + machine; -// TODO: what's the IP address? -// assert InetAddresses.isInetAddress(machine.getPrimaryBackendIpAddress()) : machine; + + machine; + // TODO: what's the IP address? + // assert + // InetAddresses.isInetAddress(machine.getPrimaryBackendIpAddress()) : + // machine; doConnectViaSsh(machine, credentialStore.get("node#" + machine.getId())); } protected void doConnectViaSsh(IMachine machine, Credentials creds) { - SshClient ssh = context.utils().sshFactory() - .create(new IPSocket("//TODO", 22), creds); + SshClient ssh = context.utils().sshFactory().create(new IPSocket("//TODO", 22), creds); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterTest.java index 96d40a535a..71d6a4f302 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterTest.java @@ -19,9 +19,17 @@ package org.jclouds.virtualbox.compute; -import com.google.common.base.Function; -import com.google.common.collect.Iterators; -import com.google.inject.Guice; +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createNiceMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; +import static org.testng.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + import org.easymock.EasyMock; import org.jclouds.compute.config.BaseComputeServiceContextModule; import org.jclouds.compute.domain.Image; @@ -37,23 +45,16 @@ import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IVirtualBox; import org.virtualbox_4_1.VirtualBoxManager; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import static org.easymock.classextension.EasyMock.expect; -import static org.easymock.classextension.EasyMock.createNiceMock; -import static org.easymock.classextension.EasyMock.replay; -import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX; -import static org.testng.Assert.assertEquals; +import com.google.common.base.Function; +import com.google.common.collect.Iterators; +import com.google.inject.Guice; @Test(groups = "unit") public class VirtualBoxComputeServiceAdapterTest { Map> osMap = new BaseComputeServiceContextModule() { }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule()) - .getInstance(Json.class)); + .getInstance(Json.class)); @Test public void testListImages() throws Exception { @@ -76,14 +77,15 @@ public class VirtualBoxComputeServiceAdapterTest { expect(manager.getVBox()).andReturn(vBox).anyTimes(); expect(vBox.getMachines()).andReturn(machines).anyTimes(); - expect(vBox.getGuestOSType(EasyMock.anyObject())).andReturn(osType).anyTimes(); + expect(vBox.getGuestOSType(EasyMock. anyObject())).andReturn(osType).anyTimes(); expect(osType.getDescription()).andReturn("Ubuntu 10.04").anyTimes(); expect(osType.getIs64Bit()).andReturn(true).anyTimes(); replay(manager, justProvider, vBox, clonedMachine, imageMachine, osType); Function iMachineToImage = new IMachineToImage(manager, osMap); - VirtualBoxComputeServiceAdapter adapter = new VirtualBoxComputeServiceAdapter(manager, justProvider, iMachineToImage); + VirtualBoxComputeServiceAdapter adapter = new VirtualBoxComputeServiceAdapter(manager, justProvider, + iMachineToImage); Iterator iterator = adapter.listImages().iterator(); Image image = Iterators.getOnlyElement(iterator); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java index afe953a031..996dd31c3d 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxExperimentLiveTest.java @@ -27,7 +27,7 @@ import org.testng.annotations.Test; * @author Adrian Cole */ @Test(groups = "live", testName = "VirtualBoxExperimentLiveTest") -public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest{ +public class VirtualBoxExperimentLiveTest extends BaseVirtualBoxClientLiveTest { @Test public void testAndExperiment() { diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxTemplateBuilderLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxTemplateBuilderLiveTest.java index 7936318c65..4dad539af0 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxTemplateBuilderLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxTemplateBuilderLiveTest.java @@ -34,7 +34,6 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableSet; - /** * * @author Andrea Turli @@ -43,40 +42,40 @@ import com.google.common.collect.ImmutableSet; @Test(groups = "live", testName = "VirtualBoxTemplateBuilderLiveTest") public class VirtualBoxTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest { - public VirtualBoxTemplateBuilderLiveTest() { - provider = "virtualbox"; - } + public VirtualBoxTemplateBuilderLiveTest() { + provider = "virtualbox"; + } - @Override - protected Predicate defineUnsupportedOperatingSystems() { - return Predicates.not(new Predicate() { + @Override + protected Predicate defineUnsupportedOperatingSystems() { + return Predicates.not(new Predicate() { - @Override - public boolean apply(OsFamilyVersion64Bit input) { - switch (input.family) { - case UBUNTU: - return input.version.equals("11.04") && !input.is64Bit; - default: - return false; - } - } + @Override + public boolean apply(OsFamilyVersion64Bit input) { + switch (input.family) { + case UBUNTU: + return input.version.equals("11.04") && !input.is64Bit; + default: + return false; + } + } - }); - } + }); + } - @Test - public void testTemplateBuilder() { - System.out.println(this.context.getComputeService().listImages()); - Template defaultTemplate = this.context.getComputeService().templateBuilder().build(); - assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04"); - assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); - assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); - } + @Test + public void testTemplateBuilder() { + System.out.println(this.context.getComputeService().listImages()); + Template defaultTemplate = this.context.getComputeService().templateBuilder().build(); + assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), false); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "10.04"); + assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); + assertEquals(getCores(defaultTemplate.getHardware()), 1.0d); + } - @Override - protected Set getIso3166Codes() { - return ImmutableSet. of(); - } + @Override + protected Set getIso3166Codes() { + return ImmutableSet. of(); + } } diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/SetupVirtualBoxForLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/SetupVirtualBoxForLiveTest.java index 9ed33c02e3..be23f0aa5b 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/SetupVirtualBoxForLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/SetupVirtualBoxForLiveTest.java @@ -1,12 +1,8 @@ /** - * - * Copyright (C) 2009 Global Cloud Specialists, Inc. - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * 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. The ASF licenses this file + * 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 @@ -19,8 +15,8 @@ * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. - * ==================================================================== */ + package org.jclouds.virtualbox.experiment; import static com.google.common.base.Preconditions.checkNotNull; @@ -40,8 +36,8 @@ import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.domain.Credentials; import org.jclouds.logging.Logger; import org.jclouds.virtualbox.config.VirtualBoxConstants; -import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning; import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning; +import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeSuite; @@ -72,7 +68,7 @@ public class SetupVirtualBoxForLiveTest { private String vboxVersionName; private String basebaseResource; private String port; - + private String vboxWebServerCredential; private String vboxWebServerIdentity; @@ -88,18 +84,18 @@ public class SetupVirtualBoxForLiveTest { public void setupConfigurationProperties() { workingDir = System.getProperty("user.home") + File.separator - + System.getProperty("test." + provider + ".workingDir", "jclouds-virtualbox-test"); + + System.getProperty("test." + provider + ".workingDir", "jclouds-virtualbox-test"); if (new File(workingDir).mkdir()) ; gaIsoName = System.getProperty("test." + provider + ".gaIsoName", "VBoxGuestAdditions_" + majorVersion + ".iso"); gaIsoUrl = URI.create(System.getProperty("test." + provider + ".gaIsoUrl", - "http://download.virtualbox.org/virtualbox/" + majorVersion + "/" + gaIsoName)); + "http://download.virtualbox.org/virtualbox/" + majorVersion + "/" + gaIsoName)); distroIsoName = System.getProperty("test." + provider + ".distroIsoName", "ubuntu-11.04-server-i386.iso"); distroIsoUrl = URI.create(System.getProperty("test." + provider + ".distroIsoUrl", - "http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso")); + "http://releases.ubuntu.com/11.04/ubuntu-11.04-server-i386.iso")); vboxDmg = URI.create(System.getProperty("test." + provider + ".vboxDmg", - "http://download.virtualbox.org/virtualbox/4.1.2/VirtualBox-4.1.2-73507-OSX.dmg")); + "http://download.virtualbox.org/virtualbox/4.1.2/VirtualBox-4.1.2-73507-OSX.dmg")); vboxVersionName = System.getProperty("test" + provider + ".vboxVersionName", "VirtualBox-4.1.2-73507-OSX.dmg"); basebaseResource = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_BASE_RESOURCE, "."); port = System.getProperty(VirtualBoxConstants.VIRTUALBOX_JETTY_PORT, "8080"); @@ -120,7 +116,7 @@ public class SetupVirtualBoxForLiveTest { new StartVBoxIfNotAlreadyRunning(context, hostId, new Credentials(vboxWebServerIdentity, vboxWebServerCredential)); new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource); } - + @AfterSuite public void stopVboxWebServer() throws IOException { runScriptOnNode(hostId, "pidof vboxwebsrv | xargs kill"); @@ -133,29 +129,29 @@ public class SetupVirtualBoxForLiveTest { downloadFileUnlessPresent(vboxDmg, workingDir, vboxVersionName); runScriptOnNode(hostId, "hdiutil attach " + workingDir + "/" + vboxVersionName); runScriptOnNode(hostId, - "installer -pkg /Volumes/VirtualBox/VirtualBox.mpkg -target /Volumes/Macintosh\\ HD"); + "installer -pkg /Volumes/VirtualBox/VirtualBox.mpkg -target /Volumes/Macintosh\\ HD"); } else { // TODO other platforms runScriptOnNode(hostId, "cat > /etc/apt/sources.list.d/TODO"); runScriptOnNode(hostId, - "wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | apt-key add -"); + "wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | apt-key add -"); runScriptOnNode(hostId, "apt-get update"); runScriptOnNode(hostId, "apt-get --yes install virtualbox-4.1"); } } } - public void checkVboxVersionExpected() throws IOException, InterruptedException { + public void checkVboxVersionExpected() throws IOException, InterruptedException { logger().debug("checking virtualbox version"); assertEquals(runScriptOnNode(hostId, "VBoxManage -version").getOutput().trim(), apiVersion); } public boolean isOSX(String id) { - return context.getComputeService().getNodeMetadata(hostId).getOperatingSystem().getDescription().equals( - "Mac OS X"); + return context.getComputeService().getNodeMetadata(hostId).getOperatingSystem().getDescription() + .equals("Mac OS X"); } - public File downloadFileUnlessPresent(URI sourceURL, String destinationDir, String filename) throws Exception { + public File downloadFileUnlessPresent(URI sourceURL, String destinationDir, String filename) throws Exception { File iso = new File(destinationDir, filename); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestUtils.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestUtils.java index 2c27a5a80c..38def58dac 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestUtils.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/experiment/TestUtils.java @@ -18,10 +18,11 @@ */ package org.jclouds.virtualbox.experiment; -import com.google.common.cache.Cache; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Map; + import org.jclouds.byon.Node; import org.jclouds.byon.config.CacheNodeStoreModule; import org.jclouds.compute.ComputeServiceContext; @@ -31,75 +32,48 @@ import org.jclouds.domain.Credentials; import org.jclouds.encryption.bouncycastle.config.BouncyCastleCryptoModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.sshj.config.SshjSshClientModule; -import org.jclouds.virtualbox.config.VirtualBoxConstants; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Map; +import com.google.common.cache.Cache; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; public class TestUtils { public static ComputeServiceContext computeServiceForLocalhostAndGuest() throws IOException { - Node host = Node.builder().id("host") - .name("host installing virtualbox") - .hostname("localhost") - .osFamily(OsFamily.LINUX.toString()) - .osDescription(System.getProperty("os.name")) - .osVersion(System.getProperty("os.version")) - .group("ssh") - .username(System.getProperty("user.name")) - .credentialUrl(privateKeyFile()) - .build(); - Node guest = Node.builder().id("guest") - .name("new guest") - .hostname("localhost") - .loginPort(2222) - .osFamily(OsFamily.UBUNTU.toString()) - .osDescription("ubuntu/11.04") - .osVersion(System.getProperty("11.04")) - .group("guest") - .username("toor") - .sudoPassword("password") - .credential("password") - .build(); + Node host = Node.builder().id("host").name("host installing virtualbox").hostname("localhost") + .osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name")) + .osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name")) + .credentialUrl(privateKeyFile()).build(); + Node guest = Node.builder().id("guest").name("new guest").hostname("localhost").loginPort(2222) + .osFamily(OsFamily.UBUNTU.toString()).osDescription("ubuntu/11.04").osVersion(System.getProperty("11.04")) + .group("guest").username("toor").sudoPassword("password").credential("password").build(); - final Map nodeMap = ImmutableMap.builder().put("host", host).put("guest", guest).build(); - return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.of( - new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), new CacheNodeStoreModule(nodeMap))); + final Map nodeMap = ImmutableMap. builder().put("host", host).put("guest", guest) + .build(); + return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet. of( + new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), + new CacheNodeStoreModule(nodeMap))); } - public static ComputeServiceContext computeServiceForLocalhostAndGuest(String hostId, String hostname, String guestId, String guestHostname, - Credentials guestLogin) throws IOException { + public static ComputeServiceContext computeServiceForLocalhostAndGuest(String hostId, String hostname, + String guestId, String guestHostname, Credentials guestLogin) throws IOException { - Node host = Node.builder().id(hostId) - .name("host installing virtualbox") - .hostname(hostname) - .osFamily(OsFamily.LINUX.toString()) - .osDescription(System.getProperty("os.name")) - .osVersion(System.getProperty("os.version")) - .group("ssh") - .username(System.getProperty("user.name")) - .credentialUrl(privateKeyFile()) - .build(); - Node guest = Node.builder().id(guestId) - .name("new guest") - .hostname(guestHostname) - .loginPort(2222) - .osFamily(OsFamily.UBUNTU.toString()) - .osDescription("ubuntu/11.04") - .osVersion(System.getProperty("11.04")) - .group("jclouds-linux-image") - .username(guestLogin.identity) - .sudoPassword(guestLogin.credential) - .credential(guestLogin.credential) - .build(); + Node host = Node.builder().id(hostId).name("host installing virtualbox").hostname(hostname) + .osFamily(OsFamily.LINUX.toString()).osDescription(System.getProperty("os.name")) + .osVersion(System.getProperty("os.version")).group("ssh").username(System.getProperty("user.name")) + .credentialUrl(privateKeyFile()).build(); + Node guest = Node.builder().id(guestId).name("new guest").hostname(guestHostname).loginPort(2222) + .osFamily(OsFamily.UBUNTU.toString()).osDescription("ubuntu/11.04").osVersion(System.getProperty("11.04")) + .group("jclouds-linux-image").username(guestLogin.identity).sudoPassword(guestLogin.credential) + .credential(guestLogin.credential).build(); - - final Map nodeMap = ImmutableMap.builder().put(hostId, host).put(guestId, guest).build(); - return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.of( - new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), new CacheNodeStoreModule(nodeMap))); + final Map nodeMap = ImmutableMap. builder().put(hostId, host).put(guestId, guest) + .build(); + return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet. of( + new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), + new CacheNodeStoreModule(nodeMap))); } private static URI privateKeyFile() { @@ -112,7 +86,8 @@ public class TestUtils { } public static ComputeServiceContext computeServiceForVirtualBox(Cache cache) { - return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet.of( - new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), new CacheNodeStoreModule(cache))); + return new ComputeServiceContextFactory().createContext("byon", "foo", "bar", ImmutableSet. of( + new SshjSshClientModule(), new SLF4JLoggingModule(), new BouncyCastleCryptoModule(), + new CacheNodeStoreModule(cache))); } } diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachineTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachineTest.java index fee8274493..1e0894736e 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachineTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/ApplyMemoryToMachineTest.java @@ -1,4 +1,4 @@ -/* +/** * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -19,12 +19,16 @@ package org.jclouds.virtualbox.functions; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.createNiceMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; + import org.testng.annotations.Test; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.VBoxException; -import static org.easymock.classextension.EasyMock.*; - /** * @author Mattias Holmqvist */ @@ -49,8 +53,8 @@ public class ApplyMemoryToMachineTest { @Test(expectedExceptions = VBoxException.class) public void testRethrowInvalidRamSizeError() throws Exception { // Mainly here for documentation purposes - final String error = "VirtualBox error: Invalid RAM size: " + - "3567587327 MB (must be in range [4, 2097152] MB) (0x80070057)"; + final String error = "VirtualBox error: Invalid RAM size: " + + "3567587327 MB (must be in range [4, 2097152] MB) (0x80070057)"; long memorySize = 1024l; IMachine machine = createMock(IMachine.class); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachDistroMediumToMachineTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachDistroMediumToMachineTest.java index 6e7544f0b0..e4cd4af4e4 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachDistroMediumToMachineTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachDistroMediumToMachineTest.java @@ -18,15 +18,18 @@ */ package org.jclouds.virtualbox.functions; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.createNiceMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; + import org.testng.annotations.Test; import org.virtualbox_4_1.DeviceType; import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IMedium; import org.virtualbox_4_1.VBoxException; -import static org.easymock.classextension.EasyMock.*; - - /** * @author Mattias Holmqvist */ @@ -67,7 +70,8 @@ public class AttachDistroMediumToMachineTest { errorBuilder.append("of this virtual machine (0x80BB000C)"); String isoAlreadyAttachedException = errorBuilder.toString(); - VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException); + VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), + isoAlreadyAttachedException); machine.attachDevice(controllerIDE, 0, 0, DeviceType.DVD, distroMedium); expectLastCall().andThrow(isoAttachedException); @@ -92,7 +96,8 @@ public class AttachDistroMediumToMachineTest { errorBuilder.append("Some other VBox error"); String isoAlreadyAttachedException = errorBuilder.toString(); - VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException); + VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), + isoAlreadyAttachedException); machine.attachDevice(controllerIDE, 0, 0, DeviceType.DVD, distroMedium); expectLastCall().andThrow(isoAttachedException); @@ -102,5 +107,4 @@ public class AttachDistroMediumToMachineTest { } - } diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttachedTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttachedTest.java index c684c44028..b4889b01b3 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttachedTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachMediumToMachineIfNotAlreadyAttachedTest.java @@ -19,12 +19,23 @@ package org.jclouds.virtualbox.functions; -import org.testng.annotations.Test; -import org.virtualbox_4_1.*; - -import static org.easymock.classextension.EasyMock.*; +import static org.easymock.EasyMock.anyLong; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.createNiceMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; import static org.virtualbox_4_1.DeviceType.HardDisk; +import org.testng.annotations.Test; +import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_1.IMedium; +import org.virtualbox_4_1.IProgress; +import org.virtualbox_4_1.IVirtualBox; +import org.virtualbox_4_1.VBoxException; +import org.virtualbox_4_1.VirtualBoxManager; + /** * @author Mattias Holmqvist */ @@ -54,7 +65,8 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest { machine.saveSettings(); replay(manager, machine, vBox, hardDisk); - new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk).apply(machine); + new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk) + .apply(machine); verify(machine); @@ -79,13 +91,15 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest { errorBuilder.append("of this virtual machine (0x80BB000C)"); String isoAlreadyAttachedException = errorBuilder.toString(); - VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException); + VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), + isoAlreadyAttachedException); machine.attachDevice(controllerIDE, controllerPort, device, HardDisk, hardDisk); expectLastCall().andThrow(isoAttachedException); replay(manager, machine, vBox, hardDisk); - new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk).apply(machine); + new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk) + .apply(machine); verify(machine); @@ -108,13 +122,15 @@ public class AttachMediumToMachineIfNotAlreadyAttachedTest { errorBuilder.append("Some other VBox error"); String isoAlreadyAttachedException = errorBuilder.toString(); - VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), isoAlreadyAttachedException); + VBoxException isoAttachedException = new VBoxException(createNiceMock(Throwable.class), + isoAlreadyAttachedException); machine.attachDevice(controllerIDE, controllerPort, device, HardDisk, hardDisk); expectLastCall().andThrow(isoAttachedException); replay(manager, machine, vBox, hardDisk); - new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk).apply(machine); + new AttachMediumToMachineIfNotAlreadyAttached(controllerIDE, hardDisk, controllerPort, device, HardDisk) + .apply(machine); } diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachNATRedirectRuleToMachineTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachNATRedirectRuleToMachineTest.java index be7cdd1fda..22321e9aad 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachNATRedirectRuleToMachineTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/AttachNATRedirectRuleToMachineTest.java @@ -1,4 +1,4 @@ -/* +/** * Licensed to jclouds, Inc. (jclouds) under one or more * contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -19,13 +19,20 @@ package org.jclouds.virtualbox.functions; -import org.testng.annotations.Test; -import org.virtualbox_4_1.*; - -import static org.easymock.classextension.EasyMock.*; +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.createNiceMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; import static org.virtualbox_4_1.NATProtocol.TCP; import static org.virtualbox_4_1.NetworkAttachmentType.NAT; +import org.testng.annotations.Test; +import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_1.INATEngine; +import org.virtualbox_4_1.INetworkAdapter; +import org.virtualbox_4_1.VBoxException; + /** * @author Mattias Holmqvist */ @@ -60,8 +67,8 @@ public class AttachNATRedirectRuleToMachineTest { INetworkAdapter networkAdapter = createMock(INetworkAdapter.class); INATEngine natEngine = createMock(INATEngine.class); - String error = "VirtualBox error: Argument slot is invalid " + - "(must be slot < RT_ELEMENTS(mNetworkAdapters)) (0x80070057)"; + String error = "VirtualBox error: Argument slot is invalid " + + "(must be slot < RT_ELEMENTS(mNetworkAdapters)) (0x80070057)"; VBoxException invalidSlotException = new VBoxException(createNiceMock(Throwable.class), error); expect(machine.getNetworkAdapter(adapterId)).andThrow(invalidSlotException); @@ -73,5 +80,4 @@ public class AttachNATRedirectRuleToMachineTest { verify(machine, networkAdapter, natEngine); } - } 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 890430de89..0cbd5d9126 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 @@ -19,6 +19,15 @@ package org.jclouds.virtualbox.functions; +import static org.easymock.EasyMock.anyBoolean; +import static org.easymock.EasyMock.eq; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.createNiceMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; + import org.easymock.EasyMock; import org.testng.annotations.Test; import org.virtualbox_4_1.IMachine; @@ -26,10 +35,6 @@ import org.virtualbox_4_1.IVirtualBox; import org.virtualbox_4_1.VBoxException; import org.virtualbox_4_1.VirtualBoxManager; -import static org.easymock.EasyMock.anyBoolean; -import static org.easymock.EasyMock.expect; -import static org.easymock.classextension.EasyMock.*; - /** * @author Mattias Holmqvist */ @@ -55,9 +60,10 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest { vBox.findMachine(vmName); expectLastCall().andThrow(vBoxException); - - expect(vBox.createMachine(anyString(), eq(vmName), anyString(), anyString(), anyBoolean())).andReturn(createdMachine).anyTimes(); - + + expect(vBox.createMachine(anyString(), eq(vmName), anyString(), anyString(), anyBoolean())).andReturn( + createdMachine).anyTimes(); + vBox.registerMachine(createdMachine); replay(manager, vBox); @@ -103,10 +109,9 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest { new CreateAndRegisterMachineFromIsoIfNotAlreadyExists("", "", "", false, manager).apply(vmName); - } private String anyString() { - return EasyMock.anyObject(); + return EasyMock. anyObject(); } } diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsTest.java index 240bb60fd7..5d6ff30f33 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/CreateMediumIfNotAlreadyExistsTest.java @@ -19,14 +19,23 @@ package org.jclouds.virtualbox.functions; -import org.testng.annotations.Test; -import org.virtualbox_4_1.*; - import static org.easymock.EasyMock.anyLong; import static org.easymock.EasyMock.expect; -import static org.easymock.classextension.EasyMock.*; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.createNiceMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; import static org.testng.Assert.assertNotSame; +import org.testng.annotations.Test; +import org.virtualbox_4_1.DeviceType; +import org.virtualbox_4_1.IMachine; +import org.virtualbox_4_1.IMedium; +import org.virtualbox_4_1.IProgress; +import org.virtualbox_4_1.IVirtualBox; +import org.virtualbox_4_1.VBoxException; +import org.virtualbox_4_1.VirtualBoxManager; + /** * @author Mattias Holmqvist */ @@ -137,5 +146,4 @@ public class CreateMediumIfNotAlreadyExistsTest { new CreateMediumIfNotAlreadyExists(manager, diskFormat, true).apply(adminDiskPath); } - } diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java index 6c706156fa..62c454f19d 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/IMachineToNodeMetadataTest.java @@ -33,7 +33,6 @@ import org.virtualbox_4_1.VirtualBoxManager; import com.google.common.collect.ImmutableSet; -//@Test(groups = "live") public class IMachineToNodeMetadataTest { @Test 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 98cce45b41..eb7286d382 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 @@ -19,10 +19,6 @@ package org.jclouds.virtualbox.functions; -/** - * @author Andrea Turli, Mattias Holmqvist - */ - import static com.google.common.base.Predicates.equalTo; import static com.google.common.collect.Iterables.any; import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest; @@ -47,13 +43,16 @@ import org.virtualbox_4_1.VirtualBoxManager; import com.google.inject.Guice; +/** + * @author Andrea Turli, Mattias Holmqvist + */ @Test(groups = "live", singleThreaded = true, testName = "IsoToIMachineLiveTest") public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest { - + Map> map = new BaseComputeServiceContextModule() { }.provideOsVersionMap(new ComputeServiceConstants.ReferenceData(), Guice.createInjector(new GsonModule()) - .getInstance(Json.class)); - + .getInstance(Json.class)); + private String settingsFile = null; private boolean forceOverwrite = true; private String vmId = "jclouds-image-iso-1"; @@ -76,24 +75,16 @@ public class IsoToIMachineLiveTest extends BaseVirtualBoxClientLiveTest { public void testCreateImageMachineFromIso() throws Exception { VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi(); - ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest(hostId, "localhost", guestId, "localhost", new Credentials("toor", "password")); - IMachine imageMachine = new IsoToIMachine(manager, - adminDisk, - diskFormat, - settingsFile, - vmName, - osTypeId, - vmId, - forceOverwrite, - controllerIDE, - localHostContext, - hostId, - guestId, - new Credentials("toor", "password")).apply("ubuntu-11.04-server-i386.iso"); + ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest(hostId, "localhost", guestId, + "localhost", new Credentials("toor", "password")); + IMachine imageMachine = new IsoToIMachine(manager, adminDisk, diskFormat, settingsFile, vmName, osTypeId, vmId, + forceOverwrite, controllerIDE, localHostContext, hostId, guestId, new Credentials("toor", "password")) + .apply("ubuntu-11.04-server-i386.iso"); IMachineToImage iMachineToImage = new IMachineToImage(manager, map); Image newImage = iMachineToImage.apply(imageMachine); - //TODO add the description to the cache of the images or serialize to YAML the image desc + // TODO add the description to the cache of the images or serialize to + // YAML the image desc Set images = context.getComputeService().listImages(); assertTrue(any(images, equalTo(newImage))); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunningTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunningTest.java index c512905735..e18781d585 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunningTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/LaunchMachineIfNotAlreadyRunningTest.java @@ -19,6 +19,11 @@ package org.jclouds.virtualbox.functions; +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.easymock.classextension.EasyMock.verify; + import org.jclouds.virtualbox.domain.ExecutionType; import org.testng.annotations.Test; import org.virtualbox_4_1.IMachine; @@ -26,11 +31,6 @@ import org.virtualbox_4_1.IProgress; import org.virtualbox_4_1.ISession; import org.virtualbox_4_1.VirtualBoxManager; -import static org.easymock.classextension.EasyMock.verify; -import static org.easymock.classextension.EasyMock.replay; -import static org.easymock.classextension.EasyMock.createMock; -import static org.easymock.classextension.EasyMock.expect; - @Test(groups = "unit", testName = "LaunchMachineIfNotAlreadyRunningTest") public class LaunchMachineIfNotAlreadyRunningTest { @@ -39,9 +39,10 @@ public class LaunchMachineIfNotAlreadyRunningTest { } -// VirtualBox error: The given session is busy (0x80BB0007) -// VirtualBox error: The machine 'jclouds-image-virtualbox-iso-to-machine-test' is not registered (0x8000FFFF) - + // VirtualBox error: The given session is busy (0x80BB0007) + // VirtualBox error: The machine + // 'jclouds-image-virtualbox-iso-to-machine-test' is not registered + // (0x8000FFFF) @Test public void testLaunchIfNotStarted() throws Exception { diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStreamTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStreamTest.java index 6ada15cb17..3061979225 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStreamTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/ImageFromYamlStreamTest.java @@ -1,3 +1,22 @@ +/** + * 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.functions.admin; import static org.testng.Assert.assertEquals; @@ -13,23 +32,6 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; /** - * - * 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. - * - * * @author Andrea Turli */ @Test(groups = "unit") diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartJettyIfNotAlreadyRunningLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartJettyIfNotAlreadyRunningLiveTest.java index 502348fcea..d9b3f8d08f 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartJettyIfNotAlreadyRunningLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartJettyIfNotAlreadyRunningLiveTest.java @@ -19,17 +19,15 @@ package org.jclouds.virtualbox.functions.admin; -/** - * @author Andrea Turli - */ - import static org.testng.Assert.assertEquals; import org.eclipse.jetty.server.Server; import org.jclouds.virtualbox.BaseVirtualBoxClientLiveTest; import org.testng.annotations.Test; - +/** + * @author Andrea Turli + */ @Test(groups = "live", singleThreaded = true, testName = "StartJettyIfNotAlreadyRunningLiveTest") public class StartJettyIfNotAlreadyRunningLiveTest extends BaseVirtualBoxClientLiveTest { @@ -42,7 +40,7 @@ public class StartJettyIfNotAlreadyRunningLiveTest extends BaseVirtualBoxClientL server.stop(); assertEquals(server.getState(), server.STOPPED); } - + @Test public void testLaunchingSameJettyServer() throws Exception { Server server = new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource); diff --git a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java index d73f59bb18..d87dad2aec 100644 --- a/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java +++ b/sandbox-apis/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java @@ -16,31 +16,33 @@ * specific language governing permissions and limitations * under the License. */ + package org.jclouds.virtualbox.functions.admin; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.domain.Credentials; -import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning; -import org.testng.annotations.Test; -import org.virtualbox_4_1.SessionState; -import org.virtualbox_4_1.VirtualBoxManager; - -import java.net.URI; - import static org.jclouds.virtualbox.experiment.TestUtils.computeServiceForLocalhostAndGuest; import static org.testng.Assert.assertEquals; +import java.net.URI; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.domain.Credentials; +import org.testng.annotations.Test; +import org.virtualbox_4_1.SessionState; +import org.virtualbox_4_1.VirtualBoxManager; + @Test(groups = "live", singleThreaded = true, testName = "startVBoxIfNotAlreadyRunningLiveTest") public class StartVBoxIfNotAlreadyRunningLiveTest { @Test public void testStartVbox() throws Exception { Credentials localhostCredentials = new Credentials("toor", "password"); - ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest("hostId", "localhost", "guestId", "localhost", localhostCredentials); + ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest("hostId", "localhost", "guestId", + "localhost", localhostCredentials); URI endpointUri = URI.create("http://localhost:18083/"); - VirtualBoxManager manager = new StartVBoxIfNotAlreadyRunning(localHostContext, "hostId", localhostCredentials).apply(endpointUri); + VirtualBoxManager manager = new StartVBoxIfNotAlreadyRunning(localHostContext, "hostId", localhostCredentials) + .apply(endpointUri); assertEquals(manager.getSessionObject().getState(), SessionState.Unlocked); }