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
|
||||
[]
|
||||
(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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>> {
|
||||
|
@ -84,7 +93,7 @@ public class StandaloneComputeServiceContextModule<N, H, I, L> extends BaseCompu
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Set<? extends Hardware>> provideHardware(final ComputeServiceAdapter<N, H, I, L> adapter,
|
||||
Function<H, Hardware> transformer) {
|
||||
Function<H, Hardware> transformer) {
|
||||
return new TransformingSetSupplier<H, Hardware>(new Supplier<Iterable<H>>() {
|
||||
|
||||
@Override
|
||||
|
@ -98,7 +107,7 @@ public class StandaloneComputeServiceContextModule<N, H, I, L> extends BaseCompu
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Set<? extends Image>> provideImages(final ComputeServiceAdapter<N, H, I, L> adapter,
|
||||
Function<I, Image> transformer) {
|
||||
Function<I, Image> transformer) {
|
||||
return new TransformingSetSupplier<I, Image>(new Supplier<Iterable<I>>() {
|
||||
|
||||
@Override
|
||||
|
@ -117,7 +126,7 @@ public class StandaloneComputeServiceContextModule<N, H, I, L> extends BaseCompu
|
|||
@Provides
|
||||
@Singleton
|
||||
protected Supplier<Set<? extends Location>> provideLocations(final ComputeServiceAdapter<N, H, I, L> adapter,
|
||||
Function<L, Location> transformer) {
|
||||
Function<L, Location> transformer) {
|
||||
return new TransformingSetSupplier<L, Location>(new Supplier<Iterable<L>>() {
|
||||
|
||||
@Override
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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<Domain, Domain, Image, Datacenter> {
|
||||
@Override
|
||||
protected void configure() {
|
||||
super.configure();
|
||||
bind(new TypeLiteral<ComputeServiceAdapter<Domain, Domain, Image, Datacenter>>() {
|
||||
}).to(LibvirtComputeServiceAdapter.class);
|
||||
bind(new TypeLiteral<Supplier<Location>>() {
|
||||
}).to(DefaultLocationSupplier.class);
|
||||
bind(new TypeLiteral<Function<Domain, NodeMetadata>>() {
|
||||
}).to(DomainToNodeMetadata.class);
|
||||
bind(new TypeLiteral<Function<Image, org.jclouds.compute.domain.Image>>() {
|
||||
}).to(LibvirtImageToImage.class);
|
||||
bind(new TypeLiteral<Function<Domain, Hardware>>() {
|
||||
}).to(DomainToHardware.class);
|
||||
bind(new TypeLiteral<Function<Datacenter, Location>>() {
|
||||
}).to(DatacenterToLocation.class);
|
||||
ComputeServiceAdapterContextModule<Connect, Connect, Domain, Domain, Image, Datacenter> {
|
||||
|
||||
//bind(ComputeService.class).to(LibvirtComputeService.class);
|
||||
}
|
||||
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<ComputeServiceAdapter<Domain, Domain, Image, Datacenter>>() {
|
||||
}).to(LibvirtComputeServiceAdapter.class);
|
||||
bind(new TypeLiteral<Supplier<Location>>() {
|
||||
}).to(DefaultLocationSupplier.class);
|
||||
bind(new TypeLiteral<Function<Domain, NodeMetadata>>() {
|
||||
}).to(DomainToNodeMetadata.class);
|
||||
bind(new TypeLiteral<Function<Image, org.jclouds.compute.domain.Image>>() {
|
||||
}).to(LibvirtImageToImage.class);
|
||||
bind(new TypeLiteral<Function<Domain, Hardware>>() {
|
||||
}).to(DomainToHardware.class);
|
||||
bind(new TypeLiteral<Function<Datacenter, Location>>() {
|
||||
}).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";
|
||||
}
|
||||
@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);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private String searchForHardwareIdInDomainDir(String domainDir) {
|
||||
private String searchForImageIdInDomainDir(String domainDir) {
|
||||
// TODO
|
||||
return "1";
|
||||
}
|
||||
|
||||
Collection<File> 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;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
private String searchForHardwareIdInDomainDir(String domainDir) {
|
||||
|
||||
/*
|
||||
* 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)))));
|
||||
Collection<File> 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<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;
|
||||
*/
|
||||
|
||||
}
|
|
@ -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,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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue