virtualbox related changes for Issue 826

This commit is contained in:
Adrian Cole 2012-02-02 07:42:55 -08:00
parent c32d72084e
commit d225df57e4
3 changed files with 9 additions and 17 deletions

View File

@ -31,7 +31,6 @@ import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Template;
import org.jclouds.domain.Location;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.suppliers.JustProvider;
import org.virtualbox_4_1.CleanupMode;
import org.virtualbox_4_1.IMachine;
import org.virtualbox_4_1.IProgress;
@ -43,6 +42,7 @@ import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.Singleton;
@ -57,15 +57,13 @@ import com.google.inject.Singleton;
public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IMachine, IMachine, Image, Location> {
private final Supplier<VirtualBoxManager> manager;
private final JustProvider justProvider;
private final Function<IMachine, Image> iMachineToImage;
@Inject
public VirtualBoxComputeServiceAdapter(Supplier<VirtualBoxManager> manager, JustProvider justProvider,
public VirtualBoxComputeServiceAdapter(Supplier<VirtualBoxManager> manager,
Function<IMachine, Image> iMachineToImage) {
this.iMachineToImage = iMachineToImage;
this.manager = checkNotNull(manager, "manager");
this.justProvider = checkNotNull(justProvider, "justProvider");
}
@Override
@ -107,10 +105,10 @@ public class VirtualBoxComputeServiceAdapter implements ComputeServiceAdapter<IM
return imageMachines;
}
@SuppressWarnings("unchecked")
@Override
public Iterable<Location> listLocations() {
return (Iterable<Location>) justProvider.get();
// Not using the adapter to determine locations
return ImmutableSet.<Location>of();
}
@Override

View File

@ -44,7 +44,6 @@ import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
import org.jclouds.domain.Location;
import org.jclouds.functions.IdentityFunction;
import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.ssh.SshClient;
import org.jclouds.virtualbox.Preconfiguration;
@ -103,8 +102,6 @@ public class VirtualBoxComputeServiceContextModule extends
}).to(IMachineToHardware.class);
bind(new TypeLiteral<Function<IMachine, Image>>() {
}).to(IMachineToImage.class);
bind(new TypeLiteral<Supplier<Location>>() {
}).to(OnlyLocationOrFirstZone.class);
bind(new TypeLiteral<CacheLoader<IsoSpec, URI>>() {
}).to((Class) StartJettyIfNotAlreadyRunning.class);
bind(new TypeLiteral<Supplier<VirtualBoxManager>>() {
@ -120,7 +117,7 @@ public class VirtualBoxComputeServiceContextModule extends
bind(LockType.class).toInstance(LockType.Write);
}
@Provides
@Singleton
@Preconfiguration

View File

@ -19,9 +19,9 @@
package org.jclouds.virtualbox.compute;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createNiceMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.EasyMock.replay;
import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_IMAGE_PREFIX;
import static org.testng.Assert.assertEquals;
@ -37,7 +37,6 @@ import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.jclouds.location.suppliers.JustProvider;
import org.jclouds.virtualbox.functions.IMachineToImage;
import org.testng.annotations.Test;
import org.virtualbox_4_1.IGuestOSType;
@ -61,7 +60,6 @@ public class VirtualBoxComputeServiceAdapterTest {
public void testListImages() throws Exception {
VirtualBoxManager manager = createNiceMock(VirtualBoxManager.class);
JustProvider justProvider = createNiceMock(JustProvider.class);
IVirtualBox vBox = createNiceMock(IVirtualBox.class);
IGuestOSType osType = createNiceMock(IGuestOSType.class);
@ -82,11 +80,10 @@ public class VirtualBoxComputeServiceAdapterTest {
expect(osType.getDescription()).andReturn("Ubuntu 10.04").anyTimes();
expect(osType.getIs64Bit()).andReturn(true).anyTimes();
replay(manager, justProvider, vBox, clonedMachine, imageMachine, osType);
replay(manager, vBox, clonedMachine, imageMachine, osType);
Function<IMachine, Image> iMachineToImage = new IMachineToImage(Suppliers.ofInstance(manager), osMap);
VirtualBoxComputeServiceAdapter adapter = new VirtualBoxComputeServiceAdapter(Suppliers.ofInstance(manager), justProvider,
iMachineToImage);
VirtualBoxComputeServiceAdapter adapter = new VirtualBoxComputeServiceAdapter(Suppliers.ofInstance(manager), iMachineToImage);
Iterator<Image> iterator = adapter.listImages().iterator();
Image image = Iterators.getOnlyElement(iterator);