Merge pull request #426 from dralves/jclouds-vbox-nat-host-only-working-cluster-and-live-test

improved hardware matching based on images and not vms (since they are lazy built)
This commit is contained in:
Adrian Cole 2012-03-12 09:07:40 -07:00
commit 36a95f3900
4 changed files with 22 additions and 16 deletions

View File

@ -24,8 +24,8 @@ import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_PRECO
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import javax.inject.Named; import javax.inject.Named;
@ -78,6 +78,7 @@ import org.jclouds.virtualbox.functions.admin.ImagesToYamlImagesFromYamlDescript
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.predicates.SshResponds; import org.jclouds.virtualbox.predicates.SshResponds;
import org.testng.internal.annotations.Sets;
import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.LockType; import org.virtualbox_4_1.LockType;
import org.virtualbox_4_1.MachineState; import org.virtualbox_4_1.MachineState;
@ -218,7 +219,13 @@ public class VirtualBoxComputeServiceContextModule extends
@Override @Override
protected Supplier provideHardware(ComputeServiceAdapter<IMachine, IMachine, Image, Location> adapter, protected Supplier provideHardware(ComputeServiceAdapter<IMachine, IMachine, Image, Location> adapter,
Function<IMachine, Hardware> transformer) { Function<IMachine, Hardware> transformer) {
return Suppliers.ofInstance(Collections.singleton(new HardwareBuilder().id("").build())); // since no vms might be available we need to list images
Iterable<Image> images = adapter.listImages();
Set<Hardware> hardware = Sets.newHashSet();
for (Image image : images) {
hardware.add(new HardwareBuilder().ids(image.getId()).hypervisor("VirtualBox").name(image.getName()).build());
}
return Suppliers.ofInstance(hardware);
} }
@Override @Override

View File

@ -25,6 +25,7 @@ import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder; import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.predicates.ImagePredicates; import org.jclouds.compute.predicates.ImagePredicates;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.virtualbox.config.VirtualBoxConstants;
import org.virtualbox_4_1.IGuestOSType; import org.virtualbox_4_1.IGuestOSType;
import org.virtualbox_4_1.IMachine; import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.VirtualBoxManager; import org.virtualbox_4_1.VirtualBoxManager;
@ -44,14 +45,14 @@ public class IMachineToHardware implements Function<IMachine, Hardware> {
@Override @Override
public Hardware apply(@Nullable IMachine vm) { public Hardware apply(@Nullable IMachine vm) {
String osTypeId = vm.getOSTypeId(); String osTypeId = vm.getOSTypeId();
String vmNameWithoutPrefix = vm.getName().replace(VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX, "");
IGuestOSType guestOSType = virtualBoxManager.get().getVBox().getGuestOSType(osTypeId); IGuestOSType guestOSType = virtualBoxManager.get().getVBox().getGuestOSType(osTypeId);
Boolean is64Bit = guestOSType.getIs64Bit(); Boolean is64Bit = guestOSType.getIs64Bit();
HardwareBuilder hardwareBuilder = new HardwareBuilder(); HardwareBuilder hardwareBuilder = new HardwareBuilder();
hardwareBuilder.ids(vm.getId()); hardwareBuilder.ids(vmNameWithoutPrefix);
hardwareBuilder.supportsImage(ImagePredicates.idEquals(vm.getId()));
hardwareBuilder.is64Bit(is64Bit); hardwareBuilder.is64Bit(is64Bit);
hardwareBuilder.supportsImage(ImagePredicates.idEquals(vm.getId())); hardwareBuilder.supportsImage(ImagePredicates.idEquals(vmNameWithoutPrefix));
hardwareBuilder.hypervisor("VirtualBox"); hardwareBuilder.hypervisor("VirtualBox");
return hardwareBuilder.build(); return hardwareBuilder.build();
} }

View File

@ -70,7 +70,7 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager>
@Provider Supplier<URI> providerSupplier, @Identity String identity, @Credential String credential) { @Provider Supplier<URI> providerSupplier, @Identity String identity, @Credential String credential) {
this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory"); this.runScriptOnNodeFactory = checkNotNull(runScriptOnNodeFactory, "runScriptOnNodeFactory");
this.socketTester = checkNotNull(socketTester, "socketTester"); this.socketTester = checkNotNull(socketTester, "socketTester");
this.socketTester.seconds(1L); this.socketTester.seconds(3L);
this.host = checkNotNull(host, "host"); this.host = checkNotNull(host, "host");
this.providerSupplier = checkNotNull(providerSupplier, "endpoint to virtualbox websrvd is needed"); this.providerSupplier = checkNotNull(providerSupplier, "endpoint to virtualbox websrvd is needed");
this.identity = checkNotNull(identity, "identity"); this.identity = checkNotNull(identity, "identity");
@ -94,10 +94,8 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager>
runScriptOnNodeFactory.create(host.get(), Statements.exec(vboxwebsrv), runScriptOnNodeFactory.create(host.get(), Statements.exec(vboxwebsrv),
runAsRoot(false).wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv")).init().call(); runAsRoot(false).wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv")).init().call();
try { if (!socketTester.apply(new IPSocket(provider.getHost(), provider.getPort()))){
// wait for a couple of seconds to make sure vbox has correctly started throw new RuntimeException("could not connect to virtualbox");
Thread.sleep(2000L);
} catch (InterruptedException e) {
} }
} }
manager = managerForNode.apply(host); manager = managerForNode.apply(host);

View File

@ -46,10 +46,10 @@ public class IMachineToHardwareTest {
IGuestOSType guestOsType = createNiceMock(IGuestOSType.class); IGuestOSType guestOsType = createNiceMock(IGuestOSType.class);
String linuxDescription = "Ubuntu Linux 10.04"; String linuxDescription = "Ubuntu Linux 10.04";
String machineId = "hw-machineId"; String machineName = "hw-machineId";
expect(vm.getOSTypeId()).andReturn("os-type").anyTimes(); expect(vm.getOSTypeId()).andReturn("os-type").anyTimes();
expect(vm.getId()).andReturn(machineId).anyTimes(); expect(vm.getName()).andReturn(machineName).anyTimes();
expect(vm.getDescription()).andReturn(linuxDescription).anyTimes(); expect(vm.getDescription()).andReturn(linuxDescription).anyTimes();
@ -61,11 +61,11 @@ public class IMachineToHardwareTest {
Hardware hardware = new IMachineToHardware(Suppliers.ofInstance(vbm)).apply(vm); Hardware hardware = new IMachineToHardware(Suppliers.ofInstance(vbm)).apply(vm);
assertEquals(hardware.getId(), machineId); assertEquals(hardware.getId(), machineName);
assertEquals(hardware.getProviderId(), machineId); assertEquals(hardware.getProviderId(), machineName);
// for starters assume 1-to-1 relationship hardware to image (which // for starters assume 1-to-1 relationship hardware to image (which
// correlate to a single source IMachine) // correlate to a single source IMachine)
assertEquals(hardware.supportsImage().toString(), ImagePredicates.idEquals(machineId).toString()); assertEquals(hardware.supportsImage().toString(), ImagePredicates.idEquals(machineName).toString());
} }