Issue 385: exposed way to access synch and asynch classes within skeleton compute provider

This commit is contained in:
Adrian Cole 2010-12-19 18:18:01 +01:00
parent c46bb08835
commit 033277d31c
8 changed files with 138 additions and 114 deletions

View File

@ -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]

View File

@ -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

View File

@ -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<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
protected void configure() {
super.configure();
bindDefaultLocation();
bind(new TypeLiteral<ComputeServiceContext>() {
}).to(new TypeLiteral<ComputeServiceContextImpl<ComputeService, ComputeService>>() {
}).in(Scopes.SINGLETON);
}).to((TypeLiteral) TypeLiteral.get(Types.newParameterizedType(ComputeServiceContextImpl.class, syncClientType,
asyncClientType))).in(Scopes.SINGLETON);
}
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) {
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";
}
}
}

View File

@ -32,12 +32,13 @@ import com.google.inject.TypeLiteral;
*
* @author Adrian Cole
*/
public class JCloudsNativeStandaloneComputeServiceContextModule extends
StandaloneComputeServiceContextModule<NodeMetadata, Hardware, Image, Location> {
private final Class<? extends ComputeServiceAdapter<NodeMetadata, Hardware, Image, Location>> adapter;
public class JCloudsNativeComputeServiceAdapterContextModule<S, A> extends
ComputeServiceAdapterContextModule<S, A, NodeMetadata, Hardware, Image, Location> {
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) {
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<Function<NodeMetadata, NodeMetadata>>() {
}).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class);
}).to((Class) IdentityFunction.class);
bind(new TypeLiteral<Function<Image, Image>>() {
}).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class);
}).to((Class) IdentityFunction.class);
bind(new TypeLiteral<Function<Hardware, Hardware>>() {
}).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class);
}).to((Class) IdentityFunction.class);
bind(new TypeLiteral<Function<Location, Location>>() {
}).to((Class) StandaloneComputeServiceContextModule.IdentityFunction.class);
}).to((Class) IdentityFunction.class);
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";
}
}
}

View File

@ -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,15 +33,15 @@ import com.google.inject.Provides;
*
* @author Adrian Cole
*/
@SuppressWarnings("rawtypes")
@SingleThreaded
public class StubComputeServiceContextModule extends JCloudsNativeStandaloneComputeServiceContextModule {
public class StubComputeServiceContextModule extends
JCloudsNativeComputeServiceAdapterContextModule<ConcurrentMap, ConcurrentMap> {
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<String, NodeMetadata> in) {

View File

@ -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,7 +73,12 @@ import com.jamesmurty.utils.XMLBuilder;
* @author Adrian Cole
*/
public class LibvirtComputeServiceContextModule extends
StandaloneComputeServiceContextModule<Domain, Domain, Image, Datacenter> {
ComputeServiceAdapterContextModule<Connect, Connect, Domain, Domain, Image, Datacenter> {
public LibvirtComputeServiceContextModule() {
super(Connect.class, Connect.class);
}
@Override
protected void configure() {
super.configure();
@ -109,7 +114,6 @@ StandaloneComputeServiceContextModule<Domain, Domain, Image, Datacenter> {
return template.hardwareId(hardwareId).imageId(image);
}
private String searchForImageIdInDomainDir(String domainDir) {
// TODO
return "1";
@ -137,14 +141,10 @@ StandaloneComputeServiceContextModule<Domain, Domain, Image, Datacenter> {
}
/*
* Map<String, URI> 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;
* Map<String, URI> 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;
*/
}

View File

@ -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<VirtualMachine, VirtualMachine, Image, Datacenter> {
public class ViComputeServiceContextModule
extends
ComputeServiceAdapterContextModule<ServiceInstance, ServiceInstance, VirtualMachine, VirtualMachine, Image, Datacenter> {
public ViComputeServiceContextModule() {
super(ServiceInstance.class, ServiceInstance.class);
}
@Override
protected void configure() {
super.configure();
@ -98,7 +104,8 @@ 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 = injector.getInstance(Key.get(String.class,
// Names.named(PROPERTY_LIBVIRT_DOMAIN_DIR)));
String domainDir = "";
String hardwareId = searchForHardwareIdInDomainDir(domainDir);
String image = searchForImageIdInDomainDir(domainDir);

View File

@ -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<Server, Hardware, Image, Datacenter> {
ComputeServiceAdapterContextModule<ServerManager, ServerManager, Server, Hardware, Image, Datacenter> {
public ServerManagerComputeServiceContextModule() {
super(ServerManager.class, ServerManager.class);
}
@Override
protected void configure() {
super.configure();