mirror of https://github.com/apache/jclouds.git
Issue 385: exposed way to access synch and asynch classes within skeleton compute provider
This commit is contained in:
parent
c46bb08835
commit
033277d31c
|
@ -34,7 +34,9 @@
|
||||||
|
|
||||||
(defn compute-module
|
(defn compute-module
|
||||||
[]
|
[]
|
||||||
(org.jclouds.compute.config.JCloudsNativeStandaloneComputeServiceContextModule
|
(org.jclouds.compute.config.JCloudsNativeComputeServiceAdapterContextModule
|
||||||
|
(class ComputeService)
|
||||||
|
(class ComputeService)
|
||||||
(defrecord ClojureComputeServiceAdapter []
|
(defrecord ClojureComputeServiceAdapter []
|
||||||
org.jclouds.compute.JCloudsNativeComputeServiceAdapter
|
org.jclouds.compute.JCloudsNativeComputeServiceAdapter
|
||||||
(^NodeMetadata runNodeWithTagAndNameAndStoreCredentials [this ^String tag ^String name ^Template template ^Map credentialStore]
|
(^NodeMetadata runNodeWithTagAndNameAndStoreCredentials [this ^String tag ^String name ^Template template ^Map credentialStore]
|
||||||
|
|
|
@ -25,7 +25,7 @@ import org.jclouds.compute.domain.Template;
|
||||||
import org.jclouds.domain.Credentials;
|
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.
|
* cloud implementation, jclouds or otherwise.
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
|
|
|
@ -27,7 +27,6 @@ import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.compute.ComputeService;
|
|
||||||
import org.jclouds.compute.ComputeServiceAdapter;
|
import org.jclouds.compute.ComputeServiceAdapter;
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.domain.Hardware;
|
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.Provides;
|
||||||
import com.google.inject.Scopes;
|
import com.google.inject.Scopes;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
import com.google.inject.util.Types;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class StandaloneComputeServiceContextModule<N, H, I, L> extends BaseComputeServiceContextModule {
|
public class ComputeServiceAdapterContextModule<S, A, N, H, I, L> extends BaseComputeServiceContextModule {
|
||||||
|
|
||||||
|
private Class<A> asyncClientType;
|
||||||
|
private Class<S> syncClientType;
|
||||||
|
|
||||||
|
public ComputeServiceAdapterContextModule(Class<S> syncClientType, Class<A> asyncClientType) {
|
||||||
|
this.syncClientType = syncClientType;
|
||||||
|
this.asyncClientType = asyncClientType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
super.configure();
|
super.configure();
|
||||||
bindDefaultLocation();
|
bindDefaultLocation();
|
||||||
bind(new TypeLiteral<ComputeServiceContext>() {
|
bind(new TypeLiteral<ComputeServiceContext>() {
|
||||||
}).to(new TypeLiteral<ComputeServiceContextImpl<ComputeService, ComputeService>>() {
|
}).to((TypeLiteral) TypeLiteral.get(Types.newParameterizedType(ComputeServiceContextImpl.class, syncClientType,
|
||||||
}).in(Scopes.SINGLETON);
|
asyncClientType))).in(Scopes.SINGLETON);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TransformingSetSupplier<F, T> implements Supplier<Set<? extends T>> {
|
public class TransformingSetSupplier<F, T> implements Supplier<Set<? extends T>> {
|
||||||
|
@ -169,19 +178,4 @@ public class StandaloneComputeServiceContextModule<N, H, I, L> extends BaseCompu
|
||||||
protected SuspendNodeStrategy defineStopNodeStrategy(AdaptingComputeServiceStrategies<N, H, I, L> in) {
|
protected SuspendNodeStrategy defineStopNodeStrategy(AdaptingComputeServiceStrategies<N, H, I, L> in) {
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
// enum singleton pattern
|
|
||||||
public static enum IdentityFunction implements Function<Object, Object> {
|
|
||||||
INSTANCE;
|
|
||||||
|
|
||||||
public Object apply(Object o) {
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "identity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -32,12 +32,13 @@ import com.google.inject.TypeLiteral;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class JCloudsNativeStandaloneComputeServiceContextModule extends
|
public class JCloudsNativeComputeServiceAdapterContextModule<S, A> extends
|
||||||
StandaloneComputeServiceContextModule<NodeMetadata, Hardware, Image, Location> {
|
ComputeServiceAdapterContextModule<S, A, NodeMetadata, Hardware, Image, Location> {
|
||||||
private final Class<? extends ComputeServiceAdapter<NodeMetadata, Hardware, Image, Location>> adapter;
|
protected final Class<? extends ComputeServiceAdapter<NodeMetadata, Hardware, Image, Location>> adapter;
|
||||||
|
|
||||||
public JCloudsNativeStandaloneComputeServiceContextModule(
|
public JCloudsNativeComputeServiceAdapterContextModule(Class<S> syncClientType, Class<A> asyncClientType,
|
||||||
Class<? extends ComputeServiceAdapter<NodeMetadata, Hardware, Image, Location>> adapter) {
|
Class<? extends ComputeServiceAdapter<NodeMetadata, Hardware, Image, Location>> adapter) {
|
||||||
|
super(syncClientType, asyncClientType);
|
||||||
this.adapter = adapter;
|
this.adapter = adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,14 +53,28 @@ public class JCloudsNativeStandaloneComputeServiceContextModule extends
|
||||||
}).to(adapter);
|
}).to(adapter);
|
||||||
bind(IdentityFunction.class).toInstance(IdentityFunction.INSTANCE);
|
bind(IdentityFunction.class).toInstance(IdentityFunction.INSTANCE);
|
||||||
bind(new TypeLiteral<Function<NodeMetadata, NodeMetadata>>() {
|
bind(new TypeLiteral<Function<NodeMetadata, NodeMetadata>>() {
|
||||||
}).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class);
|
}).to((Class) IdentityFunction.class);
|
||||||
bind(new TypeLiteral<Function<Image, Image>>() {
|
bind(new TypeLiteral<Function<Image, Image>>() {
|
||||||
}).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class);
|
}).to((Class) IdentityFunction.class);
|
||||||
bind(new TypeLiteral<Function<Hardware, Hardware>>() {
|
bind(new TypeLiteral<Function<Hardware, Hardware>>() {
|
||||||
}).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class);
|
}).to((Class) IdentityFunction.class);
|
||||||
bind(new TypeLiteral<Function<Location, Location>>() {
|
bind(new TypeLiteral<Function<Location, Location>>() {
|
||||||
}).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class);
|
}).to((Class) IdentityFunction.class);
|
||||||
super.configure();
|
super.configure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// enum singleton pattern
|
||||||
|
public static enum IdentityFunction implements Function<Object, Object> {
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
public Object apply(Object o) {
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "identity";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -23,7 +23,7 @@ import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
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.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.concurrent.SingleThreaded;
|
import org.jclouds.concurrent.SingleThreaded;
|
||||||
|
|
||||||
|
@ -33,15 +33,15 @@ import com.google.inject.Provides;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
@SingleThreaded
|
@SingleThreaded
|
||||||
public class StubComputeServiceContextModule extends JCloudsNativeStandaloneComputeServiceContextModule {
|
public class StubComputeServiceContextModule extends
|
||||||
|
JCloudsNativeComputeServiceAdapterContextModule<ConcurrentMap, ConcurrentMap> {
|
||||||
|
|
||||||
public StubComputeServiceContextModule() {
|
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
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
ConcurrentMap provideApi(ConcurrentMap<String, NodeMetadata> in) {
|
ConcurrentMap provideApi(ConcurrentMap<String, NodeMetadata> in) {
|
||||||
|
|
|
@ -36,7 +36,7 @@ import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.filefilter.WildcardFileFilter;
|
import org.apache.commons.io.filefilter.WildcardFileFilter;
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.compute.ComputeServiceAdapter;
|
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.Hardware;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
|
@ -73,7 +73,12 @@ import com.jamesmurty.utils.XMLBuilder;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class LibvirtComputeServiceContextModule extends
|
public class LibvirtComputeServiceContextModule extends
|
||||||
StandaloneComputeServiceContextModule<Domain, Domain, Image, Datacenter> {
|
ComputeServiceAdapterContextModule<Connect, Connect, Domain, Domain, Image, Datacenter> {
|
||||||
|
|
||||||
|
public LibvirtComputeServiceContextModule() {
|
||||||
|
super(Connect.class, Connect.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
super.configure();
|
super.configure();
|
||||||
|
@ -90,7 +95,7 @@ StandaloneComputeServiceContextModule<Domain, Domain, Image, Datacenter> {
|
||||||
bind(new TypeLiteral<Function<Datacenter, Location>>() {
|
bind(new TypeLiteral<Function<Datacenter, Location>>() {
|
||||||
}).to(DatacenterToLocation.class);
|
}).to(DatacenterToLocation.class);
|
||||||
|
|
||||||
//bind(ComputeService.class).to(LibvirtComputeService.class);
|
// bind(ComputeService.class).to(LibvirtComputeService.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ -106,10 +111,9 @@ StandaloneComputeServiceContextModule<Domain, Domain, Image, Datacenter> {
|
||||||
String domainDir = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR)));
|
String domainDir = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR)));
|
||||||
String hardwareId = searchForHardwareIdInDomainDir(domainDir);
|
String hardwareId = searchForHardwareIdInDomainDir(domainDir);
|
||||||
String image = searchForImageIdInDomainDir(domainDir);
|
String image = searchForImageIdInDomainDir(domainDir);
|
||||||
return template.hardwareId(hardwareId).imageId(image) ;
|
return template.hardwareId(hardwareId).imageId(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String searchForImageIdInDomainDir(String domainDir) {
|
private String searchForImageIdInDomainDir(String domainDir) {
|
||||||
// TODO
|
// TODO
|
||||||
return "1";
|
return "1";
|
||||||
|
@ -118,7 +122,7 @@ StandaloneComputeServiceContextModule<Domain, Domain, Image, Datacenter> {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private String searchForHardwareIdInDomainDir(String domainDir) {
|
private String searchForHardwareIdInDomainDir(String domainDir) {
|
||||||
|
|
||||||
Collection<File> xmlDomains = FileUtils.listFiles( new File(domainDir), new WildcardFileFilter("*.xml"), null);
|
Collection<File> xmlDomains = FileUtils.listFiles(new File(domainDir), new WildcardFileFilter("*.xml"), null);
|
||||||
String uuid = "";
|
String uuid = "";
|
||||||
try {
|
try {
|
||||||
String fromXML = Files.toString(Iterables.get(xmlDomains, 0), Charsets.UTF_8);
|
String fromXML = Files.toString(Iterables.get(xmlDomains, 0), Charsets.UTF_8);
|
||||||
|
@ -137,14 +141,10 @@ StandaloneComputeServiceContextModule<Domain, Domain, Image, Datacenter> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Map<String, URI> regions = newLinkedHashMap();
|
* Map<String, URI> regions = newLinkedHashMap(); for (String region :
|
||||||
for (String region : Splitter.on(',').split(regionString)) {
|
* Splitter.on(',').split(regionString)) { regions.put( region,
|
||||||
regions.put(
|
* URI.create(injector.getInstance(Key.get(String.class, Names.named(Constants.PROPERTY_ENDPOINT
|
||||||
region,
|
* + "." + region))))); } return regions;
|
||||||
URI.create(injector.getInstance(Key.get(String.class,
|
|
||||||
Names.named(Constants.PROPERTY_ENDPOINT + "." + region)))));
|
|
||||||
}
|
|
||||||
return regions;
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
|
@ -36,7 +36,7 @@ import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.filefilter.WildcardFileFilter;
|
import org.apache.commons.io.filefilter.WildcardFileFilter;
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
import org.jclouds.compute.ComputeServiceAdapter;
|
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.Hardware;
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
|
@ -69,8 +69,14 @@ import com.vmware.vim25.mo.VirtualMachine;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ViComputeServiceContextModule extends
|
public class ViComputeServiceContextModule
|
||||||
StandaloneComputeServiceContextModule<VirtualMachine, VirtualMachine, Image, Datacenter> {
|
extends
|
||||||
|
ComputeServiceAdapterContextModule<ServiceInstance, ServiceInstance, VirtualMachine, VirtualMachine, Image, Datacenter> {
|
||||||
|
|
||||||
|
public ViComputeServiceContextModule() {
|
||||||
|
super(ServiceInstance.class, ServiceInstance.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
super.configure();
|
super.configure();
|
||||||
|
@ -98,7 +104,8 @@ public class ViComputeServiceContextModule extends
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) {
|
||||||
//String domainDir = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR)));
|
// String domainDir = injector.getInstance(Key.get(String.class,
|
||||||
|
// Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR)));
|
||||||
String domainDir = "";
|
String domainDir = "";
|
||||||
String hardwareId = searchForHardwareIdInDomainDir(domainDir);
|
String hardwareId = searchForHardwareIdInDomainDir(domainDir);
|
||||||
String image = searchForImageIdInDomainDir(domainDir);
|
String image = searchForImageIdInDomainDir(domainDir);
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
package org.jclouds.servermanager.compute.config;
|
package org.jclouds.servermanager.compute.config;
|
||||||
|
|
||||||
import org.jclouds.compute.ComputeServiceAdapter;
|
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.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.suppliers.DefaultLocationSupplier;
|
import org.jclouds.compute.suppliers.DefaultLocationSupplier;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
|
@ -28,6 +28,7 @@ import org.jclouds.servermanager.Datacenter;
|
||||||
import org.jclouds.servermanager.Hardware;
|
import org.jclouds.servermanager.Hardware;
|
||||||
import org.jclouds.servermanager.Image;
|
import org.jclouds.servermanager.Image;
|
||||||
import org.jclouds.servermanager.Server;
|
import org.jclouds.servermanager.Server;
|
||||||
|
import org.jclouds.servermanager.ServerManager;
|
||||||
import org.jclouds.servermanager.compute.functions.DatacenterToLocation;
|
import org.jclouds.servermanager.compute.functions.DatacenterToLocation;
|
||||||
import org.jclouds.servermanager.compute.functions.ServerManagerHardwareToHardware;
|
import org.jclouds.servermanager.compute.functions.ServerManagerHardwareToHardware;
|
||||||
import org.jclouds.servermanager.compute.functions.ServerManagerImageToImage;
|
import org.jclouds.servermanager.compute.functions.ServerManagerImageToImage;
|
||||||
|
@ -43,7 +44,12 @@ import com.google.inject.TypeLiteral;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class ServerManagerComputeServiceContextModule extends
|
public class ServerManagerComputeServiceContextModule extends
|
||||||
StandaloneComputeServiceContextModule<Server, Hardware, Image, Datacenter> {
|
ComputeServiceAdapterContextModule<ServerManager, ServerManager, Server, Hardware, Image, Datacenter> {
|
||||||
|
|
||||||
|
public ServerManagerComputeServiceContextModule() {
|
||||||
|
super(ServerManager.class, ServerManager.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
super.configure();
|
super.configure();
|
||||||
|
|
Loading…
Reference in New Issue