got rid of propertyutils

This commit is contained in:
Adrian Cole 2012-01-06 11:30:50 -08:00
parent 347a12a68f
commit 1255d91eef
10 changed files with 138 additions and 156 deletions

View File

@ -28,8 +28,8 @@ import javax.inject.Named;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.virtualbox.config.VirtualBoxConstants;
import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.domain.VmSpec;
import org.jclouds.virtualbox.util.PropertyUtils;
import org.virtualbox_4_1.CloneMode; import org.virtualbox_4_1.CloneMode;
import org.virtualbox_4_1.CloneOptions; import org.virtualbox_4_1.CloneOptions;
import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IMachine;
@ -42,8 +42,8 @@ import com.google.common.base.Function;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
* CloneAndRegisterMachineFromIMachineIfNotAlreadyExists will take care of the * CloneAndRegisterMachineFromIMachineIfNotAlreadyExists will take care of the followings: - cloning
* followings: - cloning the master - register the clone machine - * the master - register the clone machine -
* *
* @author Andrea Turli * @author Andrea Turli
*/ */
@ -53,14 +53,16 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private VirtualBoxManager manager; private final VirtualBoxManager manager;
private VmSpec vmSpec; private final String workingDir;
boolean isLinkedClone; private final VmSpec vmSpec;
private final boolean isLinkedClone;
@Inject @Inject
public CloneAndRegisterMachineFromIMachineIfNotAlreadyExists( public CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(VirtualBoxManager manager,
VirtualBoxManager manager, VmSpec vmSpec, boolean isLinkedClone) { @Named(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR) String workingDir, VmSpec vmSpec, boolean isLinkedClone) {
this.manager = manager; this.manager = manager;
this.workingDir = workingDir;
this.vmSpec = vmSpec; this.vmSpec = vmSpec;
this.isLinkedClone = isLinkedClone; this.isLinkedClone = isLinkedClone;
} }
@ -83,15 +85,16 @@ public class CloneAndRegisterMachineFromIMachineIfNotAlreadyExists implements Fu
} }
private IMachine cloneMachine(VmSpec vmSpec, IMachine master) { private IMachine cloneMachine(VmSpec vmSpec, IMachine master) {
String workingDir = PropertyUtils.getWorkingDirFromProperty();
String settingsFile = manager.getVBox().composeMachineFilename(vmSpec.getVmName(), workingDir); String settingsFile = manager.getVBox().composeMachineFilename(vmSpec.getVmName(), workingDir);
IMachine clonedMachine = manager.getVBox().createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(), vmSpec.getVmId(), vmSpec.isForceOverwrite()); IMachine clonedMachine = manager.getVBox().createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(),
vmSpec.getVmId(), vmSpec.isForceOverwrite());
List<CloneOptions> options = new ArrayList<CloneOptions>(); List<CloneOptions> options = new ArrayList<CloneOptions>();
if (isLinkedClone) if (isLinkedClone)
options.add(CloneOptions.Link); options.add(CloneOptions.Link);
// TODO snapshot name // TODO snapshot name
ISnapshot currentSnapshot = new TakeSnapshotIfNotAlreadyAttached(manager, "snapshotName", "snapshotDesc").apply(master); ISnapshot currentSnapshot = new TakeSnapshotIfNotAlreadyAttached(manager, "snapshotName", "snapshotDesc")
.apply(master);
// clone // clone
IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine, CloneMode.MachineState, options); IProgress progress = currentSnapshot.getMachine().cloneTo(clonedMachine, CloneMode.MachineState, options);

View File

@ -19,9 +19,23 @@
package org.jclouds.virtualbox.functions; package org.jclouds.virtualbox.functions;
import com.google.common.base.Function; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Predicate; import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
import com.google.inject.Inject; 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.util.MachineUtils.applyForMachine;
import static org.jclouds.virtualbox.util.MachineUtils.lockMachineAndApply;
import static org.jclouds.virtualbox.util.MachineUtils.lockSessionOnMachineAndApply;
import static org.virtualbox_4_1.LockType.Shared;
import static org.virtualbox_4_1.LockType.Write;
import java.io.File;
import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Named;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.compute.options.RunScriptOptions;
@ -29,23 +43,26 @@ import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.net.IPSocket; import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshException; import org.jclouds.ssh.SshException;
import org.jclouds.virtualbox.domain.*; import org.jclouds.virtualbox.config.VirtualBoxConstants;
import org.jclouds.virtualbox.domain.DeviceDetails;
import org.jclouds.virtualbox.domain.ExecutionType;
import org.jclouds.virtualbox.domain.HardDisk;
import org.jclouds.virtualbox.domain.IsoImage;
import org.jclouds.virtualbox.domain.NatAdapter;
import org.jclouds.virtualbox.domain.StorageController;
import org.jclouds.virtualbox.domain.VmSpec;
import org.jclouds.virtualbox.settings.KeyboardScancodes; 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.VirtualBoxManager;
import javax.annotation.Resource; import com.google.common.base.Function;
import javax.inject.Named; import com.google.common.base.Predicate;
import java.io.File; import com.google.inject.Inject;
import java.util.Map;
import java.util.Set;
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.util.MachineUtils.*;
import static org.virtualbox_4_1.LockType.Shared;
import static org.virtualbox_4_1.LockType.Write;
public class CreateAndInstallVm implements Function<VmSpec, IMachine> { public class CreateAndInstallVm implements Function<VmSpec, IMachine> {
@ -54,6 +71,7 @@ public class CreateAndInstallVm implements Function<VmSpec, IMachine> {
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final VirtualBoxManager manager; private final VirtualBoxManager manager;
private final CreateAndRegisterMachineFromIsoIfNotAlreadyExists createAndRegisterMachineFromIsoIfNotAlreadyExists;
private String guestId; private String guestId;
private final ComputeServiceContext context; private final ComputeServiceContext context;
private final String hostId; private final String hostId;
@ -63,10 +81,13 @@ public class CreateAndInstallVm implements Function<VmSpec, IMachine> {
private final ExecutionType executionType; private final ExecutionType executionType;
@Inject @Inject
public CreateAndInstallVm(VirtualBoxManager manager, String guestId, ComputeServiceContext context, public CreateAndInstallVm(VirtualBoxManager manager,
String hostId, Predicate<IPSocket> socketTester, CreateAndRegisterMachineFromIsoIfNotAlreadyExists CreateAndRegisterMachineFromIsoIfNotAlreadyExists,
String webServerHost, int webServerPort, ExecutionType executionType) { @Named(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR) String workingDir, String guestId,
ComputeServiceContext context, String hostId, Predicate<IPSocket> socketTester, String webServerHost,
int webServerPort, ExecutionType executionType) {
this.manager = manager; this.manager = manager;
this.createAndRegisterMachineFromIsoIfNotAlreadyExists = CreateAndRegisterMachineFromIsoIfNotAlreadyExists;
this.guestId = guestId; this.guestId = guestId;
this.context = context; this.context = context;
this.hostId = hostId; this.hostId = hostId;
@ -81,7 +102,7 @@ public class CreateAndInstallVm implements Function<VmSpec, IMachine> {
ensureWebServerIsRunning(); ensureWebServerIsRunning();
final IMachine vm = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(vmSpec); final IMachine vm =createAndRegisterMachineFromIsoIfNotAlreadyExists.apply(vmSpec);
String vmName = vmSpec.getVmName(); String vmName = vmSpec.getVmName();

View File

@ -33,13 +33,13 @@ import javax.inject.Named;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.virtualbox.config.VirtualBoxConstants;
import org.jclouds.virtualbox.domain.DeviceDetails; import org.jclouds.virtualbox.domain.DeviceDetails;
import org.jclouds.virtualbox.domain.HardDisk; import org.jclouds.virtualbox.domain.HardDisk;
import org.jclouds.virtualbox.domain.IsoImage; import org.jclouds.virtualbox.domain.IsoImage;
import org.jclouds.virtualbox.domain.NatAdapter; import org.jclouds.virtualbox.domain.NatAdapter;
import org.jclouds.virtualbox.domain.StorageController; import org.jclouds.virtualbox.domain.StorageController;
import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.domain.VmSpec;
import org.jclouds.virtualbox.util.PropertyUtils;
import org.virtualbox_4_1.AccessMode; import org.virtualbox_4_1.AccessMode;
import org.virtualbox_4_1.DeviceType; import org.virtualbox_4_1.DeviceType;
import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IMachine;
@ -58,10 +58,14 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private VirtualBoxManager manager;
public CreateAndRegisterMachineFromIsoIfNotAlreadyExists(VirtualBoxManager manager) { private final VirtualBoxManager manager;
private final String workingDir;
public CreateAndRegisterMachineFromIsoIfNotAlreadyExists(VirtualBoxManager manager,
@Named(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR) String workingDir) {
this.manager = manager; this.manager = manager;
this.workingDir = workingDir;
} }
@Override @Override
@ -84,11 +88,10 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
} }
private IMachine createMachine(IVirtualBox vBox, VmSpec vmSpec) { private IMachine createMachine(IVirtualBox vBox, VmSpec vmSpec) {
String workingDir = PropertyUtils.getWorkingDirFromProperty();
String settingsFile = vBox.composeMachineFilename(vmSpec.getVmName(), workingDir); String settingsFile = vBox.composeMachineFilename(vmSpec.getVmName(), workingDir);
IMachine newMachine = vBox.createMachine(settingsFile, vmSpec.getVmName(), IMachine newMachine = vBox.createMachine(settingsFile, vmSpec.getVmName(), vmSpec.getOsTypeId(),
vmSpec.getOsTypeId(), vmSpec.getVmId(), vmSpec.isForceOverwrite()); vmSpec.getVmId(), vmSpec.isForceOverwrite());
manager.getVBox().registerMachine(newMachine); manager.getVBox().registerMachine(newMachine);
String vmName = vmSpec.getVmName(); String vmName = vmSpec.getVmName();
@ -119,18 +122,23 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
Set<IsoImage> dvds = controller.getIsoImages(); Set<IsoImage> dvds = controller.getIsoImages();
for (IsoImage dvd : dvds) { for (IsoImage dvd : dvds) {
String dvdSource = dvd.getSourcePath(); String dvdSource = dvd.getSourcePath();
final IMedium dvdMedium = manager.getVBox().openMedium(dvdSource, DeviceType.DVD, final IMedium dvdMedium = manager.getVBox().openMedium(dvdSource, DeviceType.DVD, AccessMode.ReadOnly,
AccessMode.ReadOnly, vmSpecification.isForceOverwrite()); vmSpecification.isForceOverwrite());
ensureMachineDevicesAttached(vmName, dvdMedium, dvd.getDeviceDetails(), controller.getName()); ensureMachineDevicesAttached(vmName, dvdMedium, dvd.getDeviceDetails(), controller.getName());
} }
} }
private void ensureMachineDevicesAttached(String vmName, IMedium medium, DeviceDetails deviceDetails, String controllerName) { private void ensureMachineDevicesAttached(String vmName, IMedium medium, DeviceDetails deviceDetails,
lockMachineAndApply(manager, Write, vmName, new AttachMediumToMachineIfNotAlreadyAttached(deviceDetails, medium, controllerName)); String controllerName) {
lockMachineAndApply(manager, Write, vmName, new AttachMediumToMachineIfNotAlreadyAttached(deviceDetails, medium,
controllerName));
} }
private String missingIDEControllersMessage(VmSpec vmSpecification) { private String missingIDEControllersMessage(VmSpec vmSpecification) {
return String.format("First controller is not an IDE controller. Please verify that the VM spec is a correct master node: %s", vmSpecification); return String
.format(
"First controller is not an IDE controller. Please verify that the VM spec is a correct master node: %s",
vmSpecification);
} }
private void setupHardDisksForController(String vmName, StorageController controller) { private void setupHardDisksForController(String vmName, StorageController controller) {
@ -157,7 +165,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExists implements Functi
} }
public void ensureMachineHasStorageControllerNamed(String vmName, StorageController storageController) { public void ensureMachineHasStorageControllerNamed(String vmName, StorageController storageController) {
lockMachineAndApply(manager, Write, checkNotNull(vmName, "vmName"), lockMachineAndApply(manager, Write, checkNotNull(vmName, "vmName"), new AddIDEControllerIfNotExists(checkNotNull(
new AddIDEControllerIfNotExists(checkNotNull(storageController, "storageController"))); storageController, "storageController")));
} }
} }

View File

@ -29,6 +29,7 @@ import org.jclouds.compute.BaseVersionedServiceLiveTest;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.config.ValueOfConfigurationKeyOrNull;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.InetSocketAddressConnect;
@ -36,19 +37,17 @@ import org.jclouds.sshj.config.SshjSshClientModule;
import org.jclouds.virtualbox.config.VirtualBoxConstants; import org.jclouds.virtualbox.config.VirtualBoxConstants;
import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning; import org.jclouds.virtualbox.functions.admin.StartJettyIfNotAlreadyRunning;
import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning; import org.jclouds.virtualbox.functions.admin.StartVBoxIfNotAlreadyRunning;
import org.jclouds.virtualbox.util.PropertyUtils;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.virtualbox_4_1.SessionState; import org.virtualbox_4_1.SessionState;
import org.virtualbox_4_1.VirtualBoxManager; import org.virtualbox_4_1.VirtualBoxManager;
import com.google.common.base.Function;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.inject.Key;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.name.Names;
/** /**
* Tests behavior of {@code VirtualBoxClient} * Tests behavior of {@code VirtualBoxClient}
@ -68,6 +67,7 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest {
protected String operatingSystemIso; protected String operatingSystemIso;
protected String guestAdditionsIso; protected String guestAdditionsIso;
protected String adminDisk; protected String adminDisk;
protected String workingDir;
@Override @Override
protected void setupCredentials() { protected void setupCredentials() {
@ -89,22 +89,18 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest {
Properties overrides = setupProperties(); Properties overrides = setupProperties();
context = new ComputeServiceContextFactory().createContext(provider, identity, credential, context = new ComputeServiceContextFactory().createContext(provider, identity, credential,
ImmutableSet.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides); ImmutableSet.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()), overrides);
intializeImageIdFromContext(); Function<String, String> configProperties = context.utils().injector().getInstance(ValueOfConfigurationKeyOrNull.class);
imageId = configProperties.apply(ComputeServiceConstants.PROPERTY_IMAGE_ID);
workingDir = configProperties.apply(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR);
jetty = new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource); jetty = new StartJettyIfNotAlreadyRunning(port).apply(basebaseResource);
startVboxIfNotAlreadyRunning(); startVboxIfNotAlreadyRunning();
hostVersion = Iterables.get(Splitter.on('r').split(context.getProviderSpecificContext().getBuildVersion()), 0); hostVersion = Iterables.get(Splitter.on('r').split(context.getProviderSpecificContext().getBuildVersion()), 0);
String workingDir = PropertyUtils.getWorkingDirFromProperty();
adminDisk = workingDir + "/testadmin.vdi"; adminDisk = workingDir + "/testadmin.vdi";
operatingSystemIso = String.format("%s/%s.iso", workingDir, imageId); operatingSystemIso = String.format("%s/%s.iso", workingDir, imageId);
guestAdditionsIso = String.format("%s/VBoxGuestAdditions_%s.iso", workingDir, hostVersion); guestAdditionsIso = String.format("%s/VBoxGuestAdditions_%s.iso", workingDir, hostVersion);
} }
protected void intializeImageIdFromContext() {
imageId = context.utils().injector().getInstance(
Key.get(String.class, Names.named(ComputeServiceConstants.PROPERTY_IMAGE_ID)));
}
@AfterClass(groups = "live") @AfterClass(groups = "live")
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
if (context != null) if (context != null)

View File

@ -77,7 +77,7 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends
.cleanUpMode(mode) .cleanUpMode(mode)
.forceOverwrite(true).build(); .forceOverwrite(true).build();
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists( IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(
manager, clonedVmSpec, IS_LINKED_CLONE).apply(master); manager, workingDir, clonedVmSpec, IS_LINKED_CLONE).apply(master);
assertEquals(clone.getName(), clonedVmSpec.getVmName()); assertEquals(clone.getName(), clonedVmSpec.getVmName());
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(clonedVmSpec); new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(clonedVmSpec);
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(new IMachineToVmSpec().apply(master)); new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(new IMachineToVmSpec().apply(master));
@ -99,7 +99,7 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends
VmSpec vmSpec = VmSpec.builder().id(vmId).name(vmName) VmSpec vmSpec = VmSpec.builder().id(vmId).name(vmName)
.osTypeId(osTypeId).memoryMB(512).cleanUpMode(CleanupMode.Full) .osTypeId(osTypeId).memoryMB(512).cleanUpMode(CleanupMode.Full)
.controller(ideController).forceOverwrite(true).build(); .controller(ideController).forceOverwrite(true).build();
return new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(vmSpec); return new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager, workingDir).apply(vmSpec);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
// already created // already created

View File

@ -105,9 +105,9 @@ public class CreateAndInstallVmLiveTest extends BaseVirtualBoxClientLiveTest {
"localhost", new Credentials("toor", "password")); "localhost", new Credentials("toor", "password"));
Predicate<IPSocket> socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 10, 1, TimeUnit.SECONDS); Predicate<IPSocket> socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 10, 1, TimeUnit.SECONDS);
IMachine imageMachine = new CreateAndInstallVm(manager, guestId, localHostContext, hostId, IMachine imageMachine = new CreateAndInstallVm(manager, new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(
socketTester, "127.0.0.1", 8080, HEADLESS) manager, workingDir), workingDir, guestId, localHostContext, hostId, socketTester, "127.0.0.1", 8080,
.apply(vmSpecification); HEADLESS).apply(vmSpecification);
IMachineToImage iMachineToImage = new IMachineToImage(manager, map); IMachineToImage iMachineToImage = new IMachineToImage(manager, map);
Image newImage = iMachineToImage.apply(imageMachine); Image newImage = iMachineToImage.apply(imageMachine);

View File

@ -71,7 +71,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends
new UnregisterMachineIfExistsAndDeleteItsMedia(manager) new UnregisterMachineIfExistsAndDeleteItsMedia(manager)
.apply(launchSpecification); .apply(launchSpecification);
IMachine debianNode = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists( IMachine debianNode = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(
manager).apply(launchSpecification); manager, workingDir).apply(launchSpecification);
IMachine machine = manager.getVBox().findMachine(vmName); IMachine machine = manager.getVBox().findMachine(vmName);
assertEquals(debianNode.getName(), machine.getName()); assertEquals(debianNode.getName(), machine.getName());
new UnregisterMachineIfExistsAndDeleteItsMedia(manager) new UnregisterMachineIfExistsAndDeleteItsMedia(manager)
@ -88,7 +88,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends
.apply(launchSpecification); .apply(launchSpecification);
try { try {
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager) new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager, workingDir)
.apply(launchSpecification); .apply(launchSpecification);
fail(); fail();
} catch (VBoxException e) { } catch (VBoxException e) {

View File

@ -60,56 +60,43 @@ public class IsLinkedClonesLiveTest extends BaseVirtualBoxClientLiveTest {
public void setupClient() { public void setupClient() {
super.setupClient(); super.setupClient();
HardDisk hardDisk = HardDisk.builder() HardDisk hardDisk = HardDisk.builder().diskpath(adminDisk).autoDelete(true).controllerPort(0).deviceSlot(1)
.diskpath(adminDisk).autoDelete(true)
.controllerPort(0).deviceSlot(1).build();
masterStorageController = StorageController.builder()
.name(ideControllerName).bus(StorageBus.IDE)
.attachISO(0, 0, operatingSystemIso)
.attachHardDisk(hardDisk)
.attachISO(1, 1, guestAdditionsIso)
.build(); .build();
masterSpec = VmSpec.builder().id(vmId).name(vmName).memoryMB(512) masterStorageController = StorageController.builder().name(ideControllerName).bus(StorageBus.IDE).attachISO(0, 0,
.osTypeId(osTypeId).controller(masterStorageController) operatingSystemIso).attachHardDisk(hardDisk).attachISO(1, 1, guestAdditionsIso).build();
.forceOverwrite(true).cleanUpMode(CleanupMode.Full).build(); masterSpec = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId).controller(
masterStorageController).forceOverwrite(true).cleanUpMode(CleanupMode.Full).build();
cloneSpec = VmSpec.builder().id(cloneId).name(cloneName).memoryMB(512) cloneSpec = VmSpec.builder().id(cloneId).name(cloneName).memoryMB(512).osTypeId(osTypeId).forceOverwrite(true)
.osTypeId(osTypeId).forceOverwrite(true)
.cleanUpMode(CleanupMode.Full).build(); .cleanUpMode(CleanupMode.Full).build();
} }
@Test @Test
public void testLinkedClone() { public void testLinkedClone() {
VirtualBoxManager manager = (VirtualBoxManager) context VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi();
.getProviderSpecificContext().getApi();
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec); new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec);
IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists( IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager, workingDir).apply(masterSpec);
manager).apply(masterSpec); IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, cloneSpec,
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists( IS_LINKED_CLONE).apply(master);
manager, cloneSpec, IS_LINKED_CLONE).apply(master);
assertTrue(new IsLinkedClone(manager).apply(clone)); assertTrue(new IsLinkedClone(manager).apply(clone));
new UnregisterMachineIfExistsAndDeleteItsMedia(manager) new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(new IMachineToVmSpec().apply(clone));
.apply(new IMachineToVmSpec().apply(clone));
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec); new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec);
} }
public void testFullClone() { public void testFullClone() {
VirtualBoxManager manager = (VirtualBoxManager) context VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi();
.getProviderSpecificContext().getApi();
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec); new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec);
IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists( IMachine master = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager, workingDir).apply(masterSpec);
manager).apply(masterSpec); IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists(manager, workingDir, cloneSpec,
IMachine clone = new CloneAndRegisterMachineFromIMachineIfNotAlreadyExists( !IS_LINKED_CLONE).apply(master);
manager, cloneSpec, !IS_LINKED_CLONE).apply(master);
assertFalse(new IsLinkedClone(manager).apply(clone)); assertFalse(new IsLinkedClone(manager).apply(clone));
new UnregisterMachineIfExistsAndDeleteItsMedia(manager) new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(new IMachineToVmSpec().apply(clone));
.apply(new IMachineToVmSpec().apply(clone));
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec); new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(masterSpec);
} }
} }

View File

@ -20,6 +20,7 @@ import org.jclouds.virtualbox.domain.HardDisk;
import org.jclouds.virtualbox.domain.StorageController; import org.jclouds.virtualbox.domain.StorageController;
import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.domain.VmSpec;
import org.jclouds.virtualbox.functions.CreateAndInstallVm; import org.jclouds.virtualbox.functions.CreateAndInstallVm;
import org.jclouds.virtualbox.functions.CreateAndRegisterMachineFromIsoIfNotAlreadyExists;
import org.jclouds.virtualbox.functions.LaunchMachineIfNotAlreadyRunning; import org.jclouds.virtualbox.functions.LaunchMachineIfNotAlreadyRunning;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IMachine;
@ -42,13 +43,12 @@ public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest {
@Test @Test
public void testSshDaemonIsRunning() { public void testSshDaemonIsRunning() {
VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi(); VirtualBoxManager manager = (VirtualBoxManager) context.getProviderSpecificContext().getApi();
ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest( ComputeServiceContext localHostContext = computeServiceForLocalhostAndGuest(hostId, "localhost", guestId,
hostId, "localhost", guestId, "localhost", new Credentials("toor", "password")); "localhost", new Credentials("toor", "password"));
getNodeWithSshDaemonRunning(manager, localHostContext); getNodeWithSshDaemonRunning(manager, localHostContext);
ensureMachineIsLaunched(vmName); ensureMachineIsLaunched(vmName);
RetryablePredicate<String> predicate = new RetryablePredicate<String>( RetryablePredicate<String> predicate = new RetryablePredicate<String>(new SshAvailable(localHostContext), 5, 1,
new SshAvailable(localHostContext), 5, 1,
TimeUnit.SECONDS); TimeUnit.SECONDS);
assertTrue(predicate.apply(guestId)); assertTrue(predicate.apply(guestId));
@ -66,20 +66,19 @@ public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest {
private IMachine getNodeWithSshDaemonRunning(VirtualBoxManager manager, ComputeServiceContext localHostContext) { private IMachine getNodeWithSshDaemonRunning(VirtualBoxManager manager, ComputeServiceContext localHostContext) {
try { try {
Predicate<IPSocket> socketTester = new RetryablePredicate<IPSocket>( Predicate<IPSocket> socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 10, 1,
new InetSocketAddressConnect(), 10, 1, TimeUnit.SECONDS); TimeUnit.SECONDS);
String vmId = "jclouds-image-iso-2"; String vmId = "jclouds-image-iso-2";
StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE) StorageController ideController = StorageController.builder().name("IDE Controller").bus(StorageBus.IDE)
.attachISO(0, 0, operatingSystemIso) .attachISO(0, 0, operatingSystemIso).attachHardDisk(
.attachHardDisk(HardDisk.builder().diskpath(adminDisk).controllerPort(0).deviceSlot(1).build()).build(); HardDisk.builder().diskpath(adminDisk).controllerPort(0).deviceSlot(1).build()).build();
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).osTypeId("") VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).osTypeId("").memoryMB(512).controller(
.memoryMB(512) ideController).forceOverwrite(true).build();
.controller(ideController)
.forceOverwrite(true).build();
return new CreateAndInstallVm(manager, guestId, localHostContext, return new CreateAndInstallVm(manager, new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager,
hostId, socketTester, "127.0.0.1", 8080, HEADLESS).apply(vmSpecification); workingDir), guestId, vmId, localHostContext, hostId, socketTester, "127.0.0.1", 8080, HEADLESS)
.apply(vmSpecification);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
// already created // already created
return manager.getVBox().findMachine(vmName); return manager.getVBox().findMachine(vmName);
@ -87,8 +86,7 @@ public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest {
} }
private void ensureMachineIsLaunched(String vmName) { private void ensureMachineIsLaunched(String vmName) {
applyForMachine(manager, vmName, new LaunchMachineIfNotAlreadyRunning( applyForMachine(manager, vmName, new LaunchMachineIfNotAlreadyRunning(manager, ExecutionType.GUI, ""));
manager, ExecutionType.GUI, ""));
} }
} }

View File

@ -1,31 +0,0 @@
/*
* 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.util;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_WORKINGDIR;
public class PropertyUtils {
public static String getWorkingDirFromProperty() {
final String defaultWorkingDir = System.getProperty("user.home") + "/jclouds-virtualbox-test";
return System.getProperty(VIRTUALBOX_WORKINGDIR, defaultWorkingDir);
}
}