diff --git a/compute/src/main/clojure/org/jclouds/modules.clj b/compute/src/main/clojure/org/jclouds/modules.clj index a8d3ceda81..f49e6a9d5c 100644 --- a/compute/src/main/clojure/org/jclouds/modules.clj +++ b/compute/src/main/clojure/org/jclouds/modules.clj @@ -34,7 +34,9 @@ (defn compute-module [] - (org.jclouds.compute.config.JCloudsNativeStandaloneComputeServiceContextModule + (org.jclouds.compute.config.JCloudsNativeComputeServiceAdapterContextModule + (class ComputeService) + (class ComputeService) (defrecord ClojureComputeServiceAdapter [] org.jclouds.compute.JCloudsNativeComputeServiceAdapter (^NodeMetadata runNodeWithTagAndNameAndStoreCredentials [this ^String tag ^String name ^Template template ^Map credentialStore] diff --git a/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java b/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java index bf13254eaa..55ec6ad6b1 100644 --- a/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java @@ -25,7 +25,7 @@ import org.jclouds.compute.domain.Template; import org.jclouds.domain.Credentials; /** - * A means of specifying the interface between the {@link ComputeServices} and a concrete compute + * A means of specifying the interface between the {@link ComputeService ComputeServices} and a concrete compute * cloud implementation, jclouds or otherwise. * * @author Adrian Cole diff --git a/compute/src/main/java/org/jclouds/compute/config/StandaloneComputeServiceContextModule.java b/compute/src/main/java/org/jclouds/compute/config/ComputeServiceAdapterContextModule.java similarity index 87% rename from compute/src/main/java/org/jclouds/compute/config/StandaloneComputeServiceContextModule.java rename to compute/src/main/java/org/jclouds/compute/config/ComputeServiceAdapterContextModule.java index d9788657d5..160b147d84 100644 --- a/compute/src/main/java/org/jclouds/compute/config/StandaloneComputeServiceContextModule.java +++ b/compute/src/main/java/org/jclouds/compute/config/ComputeServiceAdapterContextModule.java @@ -27,7 +27,6 @@ import java.util.Set; import javax.inject.Singleton; -import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.Hardware; @@ -49,20 +48,30 @@ import com.google.common.base.Supplier; import com.google.inject.Provides; import com.google.inject.Scopes; import com.google.inject.TypeLiteral; +import com.google.inject.util.Types; /** * * @author Adrian Cole */ -public class StandaloneComputeServiceContextModule extends BaseComputeServiceContextModule { +public class ComputeServiceAdapterContextModule extends BaseComputeServiceContextModule { + private Class asyncClientType; + private Class syncClientType; + + public ComputeServiceAdapterContextModule(Class syncClientType, Class asyncClientType) { + this.syncClientType = syncClientType; + this.asyncClientType = asyncClientType; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected void configure() { super.configure(); bindDefaultLocation(); bind(new TypeLiteral() { - }).to(new TypeLiteral>() { - }).in(Scopes.SINGLETON); + }).to((TypeLiteral) TypeLiteral.get(Types.newParameterizedType(ComputeServiceContextImpl.class, syncClientType, + asyncClientType))).in(Scopes.SINGLETON); } public class TransformingSetSupplier implements Supplier> { @@ -84,7 +93,7 @@ public class StandaloneComputeServiceContextModule extends BaseCompu @Provides @Singleton protected Supplier> provideHardware(final ComputeServiceAdapter adapter, - Function transformer) { + Function transformer) { return new TransformingSetSupplier(new Supplier>() { @Override @@ -98,7 +107,7 @@ public class StandaloneComputeServiceContextModule extends BaseCompu @Provides @Singleton protected Supplier> provideImages(final ComputeServiceAdapter adapter, - Function transformer) { + Function transformer) { return new TransformingSetSupplier(new Supplier>() { @Override @@ -117,7 +126,7 @@ public class StandaloneComputeServiceContextModule extends BaseCompu @Provides @Singleton protected Supplier> provideLocations(final ComputeServiceAdapter adapter, - Function transformer) { + Function transformer) { return new TransformingSetSupplier(new Supplier>() { @Override @@ -169,19 +178,4 @@ public class StandaloneComputeServiceContextModule extends BaseCompu protected SuspendNodeStrategy defineStopNodeStrategy(AdaptingComputeServiceStrategies in) { return in; } - - // enum singleton pattern - public static enum IdentityFunction implements Function { - INSTANCE; - - public Object apply(Object o) { - return o; - } - - @Override - public String toString() { - return "identity"; - } - } - } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/config/JCloudsNativeStandaloneComputeServiceContextModule.java b/compute/src/main/java/org/jclouds/compute/config/JCloudsNativeComputeServiceAdapterContextModule.java similarity index 68% rename from compute/src/main/java/org/jclouds/compute/config/JCloudsNativeStandaloneComputeServiceContextModule.java rename to compute/src/main/java/org/jclouds/compute/config/JCloudsNativeComputeServiceAdapterContextModule.java index 48502b3c89..507f03c248 100644 --- a/compute/src/main/java/org/jclouds/compute/config/JCloudsNativeStandaloneComputeServiceContextModule.java +++ b/compute/src/main/java/org/jclouds/compute/config/JCloudsNativeComputeServiceAdapterContextModule.java @@ -32,12 +32,13 @@ import com.google.inject.TypeLiteral; * * @author Adrian Cole */ -public class JCloudsNativeStandaloneComputeServiceContextModule extends - StandaloneComputeServiceContextModule { - private final Class> adapter; +public class JCloudsNativeComputeServiceAdapterContextModule extends + ComputeServiceAdapterContextModule { + protected final Class> adapter; - public JCloudsNativeStandaloneComputeServiceContextModule( + public JCloudsNativeComputeServiceAdapterContextModule(Class syncClientType, Class asyncClientType, Class> adapter) { + super(syncClientType, asyncClientType); this.adapter = adapter; } @@ -52,14 +53,28 @@ public class JCloudsNativeStandaloneComputeServiceContextModule extends }).to(adapter); bind(IdentityFunction.class).toInstance(IdentityFunction.INSTANCE); bind(new TypeLiteral>() { - }).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class); + }).to((Class) IdentityFunction.class); bind(new TypeLiteral>() { - }).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class); + }).to((Class) IdentityFunction.class); bind(new TypeLiteral>() { - }).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class); + }).to((Class) IdentityFunction.class); bind(new TypeLiteral>() { - }).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class); + }).to((Class) IdentityFunction.class); super.configure(); } + // enum singleton pattern + public static enum IdentityFunction implements Function { + INSTANCE; + + public Object apply(Object o) { + return o; + } + + @Override + public String toString() { + return "identity"; + } + } + } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceContextModule.java b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceContextModule.java index fe61f1df32..a9547a6192 100644 --- a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceContextModule.java +++ b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceContextModule.java @@ -23,7 +23,7 @@ import java.util.concurrent.ConcurrentMap; import javax.inject.Singleton; -import org.jclouds.compute.config.JCloudsNativeStandaloneComputeServiceContextModule; +import org.jclouds.compute.config.JCloudsNativeComputeServiceAdapterContextModule; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.concurrent.SingleThreaded; @@ -33,21 +33,21 @@ import com.google.inject.Provides; * * @author Adrian Cole */ +@SuppressWarnings("rawtypes") @SingleThreaded -public class StubComputeServiceContextModule extends JCloudsNativeStandaloneComputeServiceContextModule { +public class StubComputeServiceContextModule extends + JCloudsNativeComputeServiceAdapterContextModule { public StubComputeServiceContextModule() { - super(StubComputeServiceAdapter.class); + super(ConcurrentMap.class, ConcurrentMap.class, StubComputeServiceAdapter.class); } - // Ensure that a plain class is able to be bound as getProviderSpecificContext.getApi() - @SuppressWarnings("rawtypes") @Provides @Singleton ConcurrentMap provideApi(ConcurrentMap in) { return in; } - + @Override protected void configure() { install(new StubComputeServiceDependenciesModule()); diff --git a/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/domain/LibvirtComputeServiceContextModule.java b/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/domain/LibvirtComputeServiceContextModule.java index 223b8ed737..c8932334f8 100644 --- a/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/domain/LibvirtComputeServiceContextModule.java +++ b/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/domain/LibvirtComputeServiceContextModule.java @@ -36,7 +36,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.WildcardFileFilter; import org.jclouds.Constants; import org.jclouds.compute.ComputeServiceAdapter; -import org.jclouds.compute.config.StandaloneComputeServiceContextModule; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.TemplateBuilder; @@ -73,78 +73,78 @@ import com.jamesmurty.utils.XMLBuilder; * @author Adrian Cole */ public class LibvirtComputeServiceContextModule extends -StandaloneComputeServiceContextModule { - @Override - protected void configure() { - super.configure(); - bind(new TypeLiteral>() { - }).to(LibvirtComputeServiceAdapter.class); - bind(new TypeLiteral>() { - }).to(DefaultLocationSupplier.class); - bind(new TypeLiteral>() { - }).to(DomainToNodeMetadata.class); - bind(new TypeLiteral>() { - }).to(LibvirtImageToImage.class); - bind(new TypeLiteral>() { - }).to(DomainToHardware.class); - bind(new TypeLiteral>() { - }).to(DatacenterToLocation.class); - - //bind(ComputeService.class).to(LibvirtComputeService.class); - } + ComputeServiceAdapterContextModule { + + public LibvirtComputeServiceContextModule() { + super(Connect.class, Connect.class); + } - @Provides - @Singleton - protected Connect createConnection(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity, - @Named(Constants.PROPERTY_CREDENTIAL) String credential) throws LibvirtException { - // ConnectAuth connectAuth = null; - return new Connect(endpoint.toASCIIString()); - } + @Override + protected void configure() { + super.configure(); + bind(new TypeLiteral>() { + }).to(LibvirtComputeServiceAdapter.class); + bind(new TypeLiteral>() { + }).to(DefaultLocationSupplier.class); + bind(new TypeLiteral>() { + }).to(DomainToNodeMetadata.class); + bind(new TypeLiteral>() { + }).to(LibvirtImageToImage.class); + bind(new TypeLiteral>() { + }).to(DomainToHardware.class); + bind(new TypeLiteral>() { + }).to(DatacenterToLocation.class); - @Override - protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - String domainDir = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR))); - String hardwareId = searchForHardwareIdInDomainDir(domainDir); - String image = searchForImageIdInDomainDir(domainDir); - return template.hardwareId(hardwareId).imageId(image) ; - } + // bind(ComputeService.class).to(LibvirtComputeService.class); + } + @Provides + @Singleton + protected Connect createConnection(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity, + @Named(Constants.PROPERTY_CREDENTIAL) String credential) throws LibvirtException { + // ConnectAuth connectAuth = null; + return new Connect(endpoint.toASCIIString()); + } - private String searchForImageIdInDomainDir(String domainDir) { - // TODO - return "1"; - } - - @SuppressWarnings("unchecked") - private String searchForHardwareIdInDomainDir(String domainDir) { + @Override + protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { + String domainDir = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR))); + String hardwareId = searchForHardwareIdInDomainDir(domainDir); + String image = searchForImageIdInDomainDir(domainDir); + return template.hardwareId(hardwareId).imageId(image); + } - Collection xmlDomains = FileUtils.listFiles( new File(domainDir), new WildcardFileFilter("*.xml"), null); - String uuid = ""; - try { - String fromXML = Files.toString(Iterables.get(xmlDomains, 0), Charsets.UTF_8); - XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(fromXML))); - uuid = builder.xpathFind("/domain/uuid").getElement().getTextContent(); - } catch (IOException e) { - e.printStackTrace(); - } catch (ParserConfigurationException e) { - e.printStackTrace(); - } catch (SAXException e) { - e.printStackTrace(); - } catch (XPathExpressionException e) { - e.printStackTrace(); - } - return uuid; - } + private String searchForImageIdInDomainDir(String domainDir) { + // TODO + return "1"; + } - /* - * Map regions = newLinkedHashMap(); - for (String region : Splitter.on(',').split(regionString)) { - regions.put( - region, - URI.create(injector.getInstance(Key.get(String.class, - Names.named(Constants.PROPERTY_ENDPOINT + "." + region))))); + @SuppressWarnings("unchecked") + private String searchForHardwareIdInDomainDir(String domainDir) { + + Collection xmlDomains = FileUtils.listFiles(new File(domainDir), new WildcardFileFilter("*.xml"), null); + String uuid = ""; + try { + String fromXML = Files.toString(Iterables.get(xmlDomains, 0), Charsets.UTF_8); + XMLBuilder builder = XMLBuilder.parse(new InputSource(new StringReader(fromXML))); + uuid = builder.xpathFind("/domain/uuid").getElement().getTextContent(); + } catch (IOException e) { + e.printStackTrace(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + } catch (SAXException e) { + e.printStackTrace(); + } catch (XPathExpressionException e) { + e.printStackTrace(); } - return regions; - */ - + return uuid; + } + + /* + * Map regions = newLinkedHashMap(); for (String region : + * Splitter.on(',').split(regionString)) { regions.put( region, + * URI.create(injector.getInstance(Key.get(String.class, Names.named(Constants.PROPERTY_ENDPOINT + * + "." + region))))); } return regions; + */ + } \ No newline at end of file diff --git a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/config/ViComputeServiceContextModule.java b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/config/ViComputeServiceContextModule.java index 0d908458f4..3abcba9e90 100644 --- a/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/config/ViComputeServiceContextModule.java +++ b/sandbox/vsphere/src/main/java/org/jclouds/vi/compute/config/ViComputeServiceContextModule.java @@ -36,7 +36,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.WildcardFileFilter; import org.jclouds.Constants; import org.jclouds.compute.ComputeServiceAdapter; -import org.jclouds.compute.config.StandaloneComputeServiceContextModule; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.TemplateBuilder; @@ -69,8 +69,14 @@ import com.vmware.vim25.mo.VirtualMachine; * * @author Adrian Cole */ -public class ViComputeServiceContextModule extends - StandaloneComputeServiceContextModule { +public class ViComputeServiceContextModule + extends + ComputeServiceAdapterContextModule { + + public ViComputeServiceContextModule() { + super(ServiceInstance.class, ServiceInstance.class); + } + @Override protected void configure() { super.configure(); @@ -98,9 +104,10 @@ public class ViComputeServiceContextModule extends @Override protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { - //String domainDir = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR))); - String domainDir = ""; - String hardwareId = searchForHardwareIdInDomainDir(domainDir); + // String domainDir = injector.getInstance(Key.get(String.class, + // Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR))); + String domainDir = ""; + String hardwareId = searchForHardwareIdInDomainDir(domainDir); String image = searchForImageIdInDomainDir(domainDir); return template.hardwareId(hardwareId).imageId(image); } diff --git a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/config/ServerManagerComputeServiceContextModule.java b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/config/ServerManagerComputeServiceContextModule.java index 82f434858f..fac7624399 100644 --- a/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/config/ServerManagerComputeServiceContextModule.java +++ b/skeletons/standalone-compute/src/main/java/org/jclouds/servermanager/compute/config/ServerManagerComputeServiceContextModule.java @@ -20,7 +20,7 @@ package org.jclouds.servermanager.compute.config; import org.jclouds.compute.ComputeServiceAdapter; -import org.jclouds.compute.config.StandaloneComputeServiceContextModule; +import org.jclouds.compute.config.ComputeServiceAdapterContextModule; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.suppliers.DefaultLocationSupplier; import org.jclouds.domain.Location; @@ -28,6 +28,7 @@ import org.jclouds.servermanager.Datacenter; import org.jclouds.servermanager.Hardware; import org.jclouds.servermanager.Image; import org.jclouds.servermanager.Server; +import org.jclouds.servermanager.ServerManager; import org.jclouds.servermanager.compute.functions.DatacenterToLocation; import org.jclouds.servermanager.compute.functions.ServerManagerHardwareToHardware; import org.jclouds.servermanager.compute.functions.ServerManagerImageToImage; @@ -43,7 +44,12 @@ import com.google.inject.TypeLiteral; * @author Adrian Cole */ public class ServerManagerComputeServiceContextModule extends - StandaloneComputeServiceContextModule { + ComputeServiceAdapterContextModule { + + public ServerManagerComputeServiceContextModule() { + super(ServerManager.class, ServerManager.class); + } + @Override protected void configure() { super.configure();