Issue 385: exposed underlying client and means to test

This commit is contained in:
Adrian Cole 2010-12-05 12:46:34 +00:00
parent 1063924f6a
commit 73c27dce6d
36 changed files with 648 additions and 324 deletions

View File

@ -35,11 +35,10 @@ import com.google.inject.Module;
*
* @author Adrian Cole
*/
public class StandaloneComputeServiceContextBuilder extends
ComputeServiceContextBuilder<ComputeService, ComputeService> {
public class StandaloneComputeServiceContextBuilder<D> extends ComputeServiceContextBuilder<D, D> {
public StandaloneComputeServiceContextBuilder(Properties props) {
super(ComputeService.class, ComputeService.class, props);
public StandaloneComputeServiceContextBuilder(Class<D> driverClass, Properties props) {
super(driverClass, driverClass, props);
if (properties.size() == 0)
properties.putAll(new PropertiesBuilder().build());
if (!properties.containsKey("jclouds.provider"))
@ -54,7 +53,7 @@ public class StandaloneComputeServiceContextBuilder extends
@Override
protected void addClientModule(List<Module> modules) {
modules.add(new StandaloneComputeServiceClientModule<ComputeService>(ComputeService.class));
modules.add(new StandaloneComputeServiceClientModule<D>(syncClientType));
}
}

View File

@ -20,24 +20,34 @@
package org.jclouds.compute;
import org.jclouds.PropertiesBuilder;
import org.jclouds.compute.config.StandaloneComputeServiceContextModule;
import org.jclouds.rest.RestContextSpec;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.Module;
/**
* @author Adrian Cole
*/
public class StandaloneComputeServiceContextSpec<N, H, I, L> extends RestContextSpec<ComputeService, ComputeService> {
public class StandaloneComputeServiceContextSpec<D, N, H, I, L> extends RestContextSpec<D, D> {
public StandaloneComputeServiceContextSpec(String provider, String endpoint, String apiVersion, String identity,
String credential, Class<D> driverClass,
Class<? extends StandaloneComputeServiceContextBuilder<D>> contextBuilderClass) {
this(provider, endpoint, apiVersion, identity, credential, driverClass, contextBuilderClass, ImmutableSet
.<Module> of());
}
public StandaloneComputeServiceContextSpec(String provider, String endpoint, String apiVersion, String identity,
String credential, Class<D> driverClass,
Class<? extends StandaloneComputeServiceContextBuilder<D>> contextBuilderClass, Iterable<Module> modules) {
this(provider, endpoint, apiVersion, identity, credential, driverClass, PropertiesBuilder.class,
contextBuilderClass, modules);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public StandaloneComputeServiceContextSpec(String provider, String endpoint, String apiVersion, String identity,
String credential, StandaloneComputeServiceContextModule<N, H, I, L> contextModule, Iterable<Module> modules) {
super(provider, endpoint, apiVersion, identity, credential, ComputeService.class, ComputeService.class,
PropertiesBuilder.class, (Class) StandaloneComputeServiceContextBuilder.class, Iterables.concat(
ImmutableSet.of(contextModule), modules));
String credential, Class<D> driverClass, Class<? extends PropertiesBuilder> propertiesBuilderClass,
Class<? extends StandaloneComputeServiceContextBuilder<D>> contextBuilderClass, Iterable<Module> modules) {
super(provider, endpoint, apiVersion, identity, credential, driverClass, driverClass,
(Class) propertiesBuilderClass, (Class) contextBuilderClass, modules);
}
}

View File

@ -1,7 +1,25 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.compute.config;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.config.StandaloneComputeServiceContextModule;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
@ -10,6 +28,10 @@ import org.jclouds.domain.Location;
import com.google.common.base.Function;
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;

View File

@ -21,6 +21,7 @@ package org.jclouds.compute.stub;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ConcurrentMap;
import org.jclouds.compute.StandaloneComputeServiceContextBuilder;
import org.jclouds.compute.stub.config.StubComputeServiceContextModule;
@ -31,10 +32,11 @@ import com.google.inject.Module;
*
* @author Adrian Cole
*/
public class StubComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder {
@SuppressWarnings("rawtypes")
public class StubComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder<ConcurrentMap> {
public StubComputeServiceContextBuilder(Properties props) {
super(props);
super(ConcurrentMap.class, props);
}
@Override

View File

@ -19,9 +19,16 @@
package org.jclouds.compute.stub.config;
import java.util.concurrent.ConcurrentMap;
import javax.inject.Singleton;
import org.jclouds.compute.config.JCloudsNativeStandaloneComputeServiceContextModule;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.concurrent.SingleThreaded;
import com.google.inject.Provides;
/**
*
* @author Adrian Cole
@ -33,6 +40,14 @@ public class StubComputeServiceContextModule extends JCloudsNativeStandaloneComp
super(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) {
return in;
}
@Override
protected void configure() {
install(new StubComputeServiceDependenciesModule());

View File

@ -74,6 +74,7 @@ import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.RestContextFactory;
import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient;
@ -161,11 +162,15 @@ public abstract class BaseComputeServiceLiveTest {
if (context != null)
context.close();
Properties props = setupProperties();
context = new ComputeServiceContextFactory().createContext(provider,
context = new ComputeServiceContextFactory(getRestProperties()).createContext(provider,
ImmutableSet.of(new Log4JLoggingModule(), getSshModule()), props);
client = context.getComputeService();
}
protected Properties getRestProperties() {
return RestContextFactory.getPropertiesFromResource("/rest.properties");
}
abstract protected Module getSshModule();
// wait up to 5 seconds for an auth exception

View File

@ -19,10 +19,12 @@
package org.jclouds.compute;
import java.util.concurrent.ConcurrentMap;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.stub.config.StubComputeServiceContextModule;
import org.jclouds.compute.stub.StubComputeServiceContextBuilder;
import org.jclouds.domain.Location;
import org.testng.annotations.Test;
@ -39,10 +41,11 @@ public class ComputeServiceContextFactoryTest {
@Test
public void testStandalone() {
@SuppressWarnings("rawtypes")
ComputeServiceContext context = new ComputeServiceContextFactory()
.createContext(new StandaloneComputeServiceContextSpec<NodeMetadata, Hardware, Image, Location>("stub",
"stub", "1", "identity", "credential", new StubComputeServiceContextModule(), ImmutableSet
.<Module> of()));
.createContext(new StandaloneComputeServiceContextSpec<ConcurrentMap, NodeMetadata, Hardware, Image, Location>(
"stub", "stub", "1", "identity", "credential", ConcurrentMap.class,
StubComputeServiceContextBuilder.class, ImmutableSet.<Module> of()));
context.getComputeService().listNodes();
}

View File

@ -195,10 +195,12 @@ public class Utils {
public static <T extends Throwable> T getFirstThrowableOfType(ProvisionException e, Class<T> clazz) {
for (Message message : e.getErrorMessages()) {
T cause = getFirstThrowableOfType(message.getCause(), clazz);
if (cause instanceof ProvisionException)
return getFirstThrowableOfType(ProvisionException.class.cast(cause), clazz);
return cause;
if (message.getCause() != null) {
T cause = getFirstThrowableOfType(message.getCause(), clazz);
if (cause instanceof ProvisionException)
return getFirstThrowableOfType(ProvisionException.class.cast(cause), clazz);
return cause;
}
}
return null;
}

View File

@ -105,6 +105,12 @@ public class UtilsTest {
ProvisionException pex = new ProvisionException(ImmutableSet.of(message));
assertEquals(Utils.getFirstThrowableOfType(pex, AuthorizationException.class), null);
}
public void testGetFirstThrowableOfTypeWhenCauseIsNull() {
Message message = new Message(ImmutableList.of(), "test", null);
ProvisionException pex = new ProvisionException(ImmutableSet.of(message));
assertEquals(Utils.getFirstThrowableOfType(pex, AuthorizationException.class), null);
}
public void testReplaceTokens() throws UnsupportedEncodingException {
assertEquals(Utils.replaceTokens("hello {where}", ImmutableMap.of("where", "world")), "hello world");

View File

@ -25,11 +25,8 @@ import java.util.List;
import java.util.Properties;
import org.jclouds.compute.StandaloneComputeServiceContextBuilder;
import org.jclouds.compute.config.StandaloneComputeServiceContextModule;
import org.jclouds.libvirt.Datacenter;
import org.jclouds.libvirt.Image;
import org.jclouds.libvirt.compute.domain.LibvirtComputeServiceContextModule;
import org.libvirt.Domain;
import org.libvirt.Connect;
import com.google.inject.Module;
@ -37,22 +34,17 @@ import com.google.inject.Module;
*
* @author Adrian Cole
*/
public class LibvirtComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder {
public class LibvirtComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder<Connect> {
public LibvirtComputeServiceContextBuilder(Properties props) {
super(props);
super(Connect.class, props);
if (!properties.containsKey(PROPERTY_LIBVIRT_DOMAIN_DIR))
properties.setProperty(PROPERTY_LIBVIRT_DOMAIN_DIR, "/etc/libvirt/qemu");
properties.setProperty(PROPERTY_LIBVIRT_DOMAIN_DIR, "/etc/libvirt/qemu");
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(createContextModule());
modules.add(new LibvirtComputeServiceContextModule());
}
public StandaloneComputeServiceContextModule<Domain, Domain, Image, Datacenter> createContextModule() {
return new LibvirtComputeServiceContextModule();
}
}

View File

@ -1,11 +1,13 @@
package org.jclouds.libvirt.compute;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertEquals;
import java.util.Properties;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.rest.RestContext;
import org.libvirt.Connect;
import org.testng.annotations.Test;
/**
@ -16,11 +18,6 @@ import org.testng.annotations.Test;
@Test(groups = "unit")
public class LibvirtComputeServiceContextBuilderTest {
@Test
public void testCreateContextModule() {
assertNotNull(new LibvirtComputeServiceContextBuilder(new Properties()).createContextModule());
}
@Test
public void testCanBuildWithComputeService() {
ComputeServiceContext context = new ComputeServiceContextFactory()
@ -28,4 +25,34 @@ public class LibvirtComputeServiceContextBuilderTest {
// System.err.println(context.getComputeService().
context.close();
}
@Test
public void testCanBuildWithRestProperties() {
Properties restProperties = new Properties();
restProperties.setProperty("libvirt.contextbuilder", LibvirtComputeServiceContextBuilder.class.getName());
restProperties.setProperty("libvirt.propertiesbuilder", LibvirtPropertiesBuilder.class.getName());
restProperties.setProperty("libvirt.endpoint", "test:///default");
ComputeServiceContext context = new ComputeServiceContextFactory(restProperties).createContext("libvirt",
"identity", "credential");
context.close();
}
@Test
public void testProviderSpecificContextIsCorrectType() {
Properties restProperties = new Properties();
restProperties.setProperty("libvirt.contextbuilder", LibvirtComputeServiceContextBuilder.class.getName());
restProperties.setProperty("libvirt.propertiesbuilder", LibvirtPropertiesBuilder.class.getName());
restProperties.setProperty("libvirt.endpoint", "test:///default");
ComputeServiceContext context = new ComputeServiceContextFactory(restProperties).createContext("libvirt",
"identity", "credential");
RestContext<Connect, Connect> providerContext = context.getProviderSpecificContext();
assertEquals(providerContext.getApi().getClass(), Connect.class);
context.close();
}
}

View File

@ -0,0 +1,55 @@
package org.jclouds.libvirt.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.util.Properties;
import org.jclouds.compute.BaseComputeServiceLiveTest;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.rest.RestContext;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.libvirt.Connect;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, sequential = true, testName = "libvirt.LibvirtComputeServiceLiveTest")
public class LibvirtComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public LibvirtComputeServiceLiveTest() {
provider = "libvirt";
}
@Override
protected Properties getRestProperties() {
Properties restProperties = new Properties();
restProperties.setProperty("libvirt.contextbuilder", LibvirtComputeServiceContextBuilder.class.getName());
restProperties.setProperty("libvirt.propertiesbuilder", LibvirtPropertiesBuilder.class.getName());
restProperties.setProperty("libvirt.endpoint", "test:///default");
return restProperties;
}
@Test
public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "5.3");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
assertEquals(defaultTemplate.getLocation().getId(), "1");
assertEquals(getCores(defaultTemplate.getHardware()), 0.5d);
}
@Override
protected JschSshClientModule getSshModule() {
return new JschSshClientModule();
}
public void testAssignability() throws Exception {
@SuppressWarnings("unused")
RestContext<Connect, Connect> goGridContext = new ComputeServiceContextFactory().createContext(provider,
identity, credential).getProviderSpecificContext();
}
}

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.vsphere;
package org.jclouds.vi;
import com.google.common.base.Objects;

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.vsphere;
package org.jclouds.vi;
import com.google.common.base.Objects;

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.vsphere;
package org.jclouds.vi;
/**
* Configuration properties and constants used in libvirt local connections.

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.vsphere.compute;
package org.jclouds.vi.compute;
import java.io.StringReader;
import java.util.Map;

View File

@ -17,42 +17,35 @@
* ====================================================================
*/
package org.jclouds.vsphere.compute;
package org.jclouds.vi.compute;
import static org.jclouds.vsphere.ViConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
import static org.jclouds.vi.ViConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
import java.util.List;
import java.util.Properties;
import org.jclouds.compute.StandaloneComputeServiceContextBuilder;
import org.jclouds.compute.config.StandaloneComputeServiceContextModule;
import org.jclouds.vsphere.Datacenter;
import org.jclouds.vsphere.Image;
import org.jclouds.vsphere.compute.domain.ViComputeServiceContextModule;
import org.jclouds.vi.compute.config.ViComputeServiceContextModule;
import com.google.inject.Module;
import com.vmware.vim25.mo.VirtualMachine;
import com.vmware.vim25.mo.ServiceInstance;
/**
*
* @author Adrian Cole
*/
public class ViComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder {
public class ViComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder<ServiceInstance> {
public ViComputeServiceContextBuilder(Properties props) {
super(props);
super(ServiceInstance.class, props);
if (!properties.containsKey(PROPERTY_LIBVIRT_DOMAIN_DIR))
properties.setProperty(PROPERTY_LIBVIRT_DOMAIN_DIR, "/etc/libvirt/qemu");
properties.setProperty(PROPERTY_LIBVIRT_DOMAIN_DIR, "/etc/libvirt/qemu");
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(createContextModule());
}
public StandaloneComputeServiceContextModule<VirtualMachine, VirtualMachine, Image, Datacenter> createContextModule() {
return new ViComputeServiceContextModule();
modules.add(new ViComputeServiceContextModule());
}
}

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.vsphere.compute;
package org.jclouds.vi.compute;
import org.jclouds.PropertiesBuilder;
import org.jclouds.compute.ComputeService;

View File

@ -17,11 +17,11 @@
* ====================================================================
*/
package org.jclouds.vsphere.compute;
package org.jclouds.vi.compute;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.vsphere.ViConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
import static org.jclouds.vi.ViConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIMEOUT_NODE_SUSPENDED;
import java.util.Properties;

View File

@ -0,0 +1,147 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vi.compute.config;
import static org.jclouds.vi.ViConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.rmi.RemoteException;
import java.util.Collection;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathExpressionException;
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.domain.Hardware;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.suppliers.DefaultLocationSupplier;
import org.jclouds.domain.Location;
import org.jclouds.rest.annotations.Provider;
import org.jclouds.vi.Datacenter;
import org.jclouds.vi.Image;
import org.jclouds.vi.compute.functions.DatacenterToLocation;
import org.jclouds.vi.compute.functions.ViImageToImage;
import org.jclouds.vi.compute.functions.VirtualMachineToHardware;
import org.jclouds.vi.compute.functions.VirtualMachineToNodeMetadata;
import org.jclouds.vi.compute.strategy.ViComputeServiceAdapter;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import com.google.common.io.Files;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import com.jamesmurty.utils.XMLBuilder;
import com.vmware.vim25.mo.ServiceInstance;
import com.vmware.vim25.mo.VirtualMachine;
/**
*
* @author Adrian Cole
*/
public class ViComputeServiceContextModule extends
StandaloneComputeServiceContextModule<VirtualMachine, VirtualMachine, Image, Datacenter> {
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<ComputeServiceAdapter<VirtualMachine, VirtualMachine, Image, Datacenter>>() {
}).to(ViComputeServiceAdapter.class);
bind(new TypeLiteral<Supplier<Location>>() {
}).to(DefaultLocationSupplier.class);
bind(new TypeLiteral<Function<VirtualMachine, NodeMetadata>>() {
}).to(VirtualMachineToNodeMetadata.class);
bind(new TypeLiteral<Function<Image, org.jclouds.compute.domain.Image>>() {
}).to(ViImageToImage.class);
bind(new TypeLiteral<Function<VirtualMachine, Hardware>>() {
}).to(VirtualMachineToHardware.class);
bind(new TypeLiteral<Function<Datacenter, Location>>() {
}).to(DatacenterToLocation.class);
}
@Provides
@Singleton
protected ServiceInstance createConnection(@Provider URI endpoint,
@Named(Constants.PROPERTY_IDENTITY) String identity, @Named(Constants.PROPERTY_CREDENTIAL) String credential)
throws RemoteException, MalformedURLException {
System.out.println(endpoint);
System.out.println(identity);
System.out.println(credential);
return new ServiceInstance(endpoint.toURL(), identity, credential, true);
}
@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);
}
private String searchForImageIdInDomainDir(String domainDir) {
// TODO
return "1";
}
@SuppressWarnings("unchecked")
private String searchForHardwareIdInDomainDir(String domainDir) {
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;
}
/*
* 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

@ -17,14 +17,14 @@
* ====================================================================
*/
package org.jclouds.vsphere.compute.functions;
package org.jclouds.vi.compute.functions;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.vsphere.Datacenter;
import org.jclouds.vi.Datacenter;
import com.google.common.base.Function;

View File

@ -17,14 +17,14 @@
* ====================================================================
*/
package org.jclouds.vsphere.compute.functions;
package org.jclouds.vi.compute.functions;
import javax.inject.Singleton;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
import org.jclouds.domain.internal.LocationImpl;
import org.jclouds.vsphere.Datacenter;
import org.jclouds.vi.Datacenter;
import com.google.common.base.Function;

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.vsphere.compute.functions;
package org.jclouds.vi.compute.functions;
import javax.annotation.Resource;
import javax.inject.Named;
@ -36,13 +36,13 @@ import com.google.common.base.Function;
* @author Adrian Cole
*/
@Singleton
public class ViImageToImage implements Function<org.jclouds.vsphere.Image, Image> {
public class ViImageToImage implements Function<org.jclouds.vi.Image, Image> {
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
@Override
public Image apply(org.jclouds.vsphere.Image from) {
public Image apply(org.jclouds.vi.Image from) {
ImageBuilder builder = new ImageBuilder();
builder.ids(from.id + "");

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.vsphere.compute.functions;
package org.jclouds.vi.compute.functions;
import java.io.IOException;
import java.io.StringReader;

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.vsphere.compute.functions;
package org.jclouds.vi.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.compute.util.ComputeServiceUtils.parseTagFromName;

View File

@ -17,10 +17,10 @@
* ====================================================================
*/
package org.jclouds.vsphere.compute.strategy;
package org.jclouds.vi.compute.strategy;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vsphere.ViConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
import static org.jclouds.vi.ViConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
import java.rmi.RemoteException;
import java.util.List;
@ -33,8 +33,8 @@ import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.domain.Template;
import org.jclouds.domain.Credentials;
import org.jclouds.vsphere.Datacenter;
import org.jclouds.vsphere.Image;
import org.jclouds.vi.Datacenter;
import org.jclouds.vi.Image;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;

View File

@ -1,151 +0,0 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vsphere.compute.domain;
import static org.jclouds.vsphere.ViConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.rmi.RemoteException;
import java.util.Collection;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathExpressionException;
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.domain.Hardware;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.suppliers.DefaultLocationSupplier;
import org.jclouds.domain.Location;
import org.jclouds.rest.annotations.Provider;
import org.jclouds.vsphere.Datacenter;
import org.jclouds.vsphere.Image;
import org.jclouds.vsphere.compute.functions.DatacenterToLocation;
import org.jclouds.vsphere.compute.functions.ViImageToImage;
import org.jclouds.vsphere.compute.functions.VirtualMachineToHardware;
import org.jclouds.vsphere.compute.functions.VirtualMachineToNodeMetadata;
import org.jclouds.vsphere.compute.strategy.ViComputeServiceAdapter;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.google.common.base.Charsets;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import com.google.common.io.Files;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import com.jamesmurty.utils.XMLBuilder;
import com.vmware.vim25.mo.ServiceInstance;
import com.vmware.vim25.mo.VirtualMachine;
/**
*
* @author Adrian Cole
*/
public class ViComputeServiceContextModule extends
StandaloneComputeServiceContextModule<VirtualMachine, VirtualMachine, Image, Datacenter> {
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<ComputeServiceAdapter<VirtualMachine, VirtualMachine, Image, Datacenter>>() {
}).to(ViComputeServiceAdapter.class);
bind(new TypeLiteral<Supplier<Location>>() {
}).to(DefaultLocationSupplier.class);
bind(new TypeLiteral<Function<VirtualMachine, NodeMetadata>>() {
}).to(VirtualMachineToNodeMetadata.class);
bind(new TypeLiteral<Function<Image, org.jclouds.compute.domain.Image>>() {
}).to(ViImageToImage.class);
bind(new TypeLiteral<Function<VirtualMachine, Hardware>>() {
}).to(VirtualMachineToHardware.class);
bind(new TypeLiteral<Function<Datacenter, Location>>() {
}).to(DatacenterToLocation.class);
}
@Provides
@Singleton
protected ServiceInstance createConnection(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity,
@Named(Constants.PROPERTY_CREDENTIAL) String credential) throws RemoteException, MalformedURLException {
System.out.println(endpoint);
System.out.println(identity);
System.out.println(credential);
return new ServiceInstance(endpoint.toURL(), identity, credential, true);
}
@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) ;
}
private String searchForImageIdInDomainDir(String domainDir) {
// TODO
return "1";
}
@SuppressWarnings("unchecked")
private String searchForHardwareIdInDomainDir(String domainDir) {
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;
}
/*
* 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

@ -0,0 +1,53 @@
package org.jclouds.vi.compute;
import static org.testng.Assert.assertEquals;
import java.util.Properties;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.rest.RestContext;
import org.testng.annotations.Test;
import com.vmware.vim25.mo.ServiceInstance;
/**
*
* @author andrea.turli
*
*/
@Test(groups = "unit")
public class ViComputeServiceContextBuilderTest {
@Test
public void testCanBuildWithContextSpec() {
ComputeServiceContext context = new ComputeServiceContextFactory().createContext(new ViComputeServiceContextSpec(
"https://localhost/sdk", "Administrator", "password"));
context.getComputeService().listNodes();
context.close();
}
@Test
public void testCanBuildWithRestProperties() {
Properties restProperties = new Properties();
restProperties.setProperty("vi.contextbuilder", ViComputeServiceContextBuilder.class.getName());
restProperties.setProperty("vi.propertiesbuilder", ViPropertiesBuilder.class.getName());
restProperties.setProperty("vi.endpoint", "https://localhost/sdk");
ComputeServiceContext context = new ComputeServiceContextFactory(restProperties).createContext("vi",
"identity", "credential");
context.close();
}
@Test
public void testProviderSpecificContextIsCorrectType() {
ComputeServiceContext context = new ViComputeServiceContextBuilder(new Properties()).buildComputeServiceContext();
RestContext<ServiceInstance, ServiceInstance> providerContext = context.getProviderSpecificContext();
assertEquals(providerContext.getApi().getClass(), ServiceInstance.class);
context.close();
}
}

View File

@ -0,0 +1,56 @@
package org.jclouds.vi.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.util.Properties;
import org.jclouds.compute.BaseComputeServiceLiveTest;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.rest.RestContext;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.Test;
import com.vmware.vim25.mo.ServiceInstance;
/**
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, sequential = true, testName = "vi.ViComputeServiceLiveTest")
public class ViComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public ViComputeServiceLiveTest() {
provider = "vi";
}
@Override
protected Properties getRestProperties() {
Properties restProperties = new Properties();
restProperties.setProperty("vi.contextbuilder", ViComputeServiceContextBuilder.class.getName());
restProperties.setProperty("vi.propertiesbuilder", ViPropertiesBuilder.class.getName());
restProperties.setProperty("vi.endpoint", "https://localhost/sdk");
return restProperties;
}
@Test
public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "5.3");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
assertEquals(defaultTemplate.getLocation().getId(), "1");
assertEquals(getCores(defaultTemplate.getHardware()), 0.5d);
}
@Override
protected JschSshClientModule getSshModule() {
return new JschSshClientModule();
}
public void testAssignability() throws Exception {
@SuppressWarnings("unused")
RestContext<ServiceInstance, ServiceInstance> goGridContext = new ComputeServiceContextFactory().createContext(
provider, identity, credential).getProviderSpecificContext();
}
}

View File

@ -17,7 +17,7 @@
* ====================================================================
*/
package org.jclouds.vsphere.compute;
package org.jclouds.vi.compute;
import static com.google.common.base.Preconditions.checkNotNull;
@ -27,7 +27,7 @@ import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
import org.jclouds.vsphere.compute.ViComputeServiceContextSpec;
import org.jclouds.vi.compute.ViComputeServiceContextSpec;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

View File

@ -1,33 +0,0 @@
package org.jclouds.vsphere.compute;
import static org.testng.Assert.assertNotNull;
import java.util.Properties;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.vsphere.compute.ViComputeServiceContextBuilder;
import org.jclouds.vsphere.compute.ViComputeServiceContextSpec;
import org.testng.annotations.Test;
/**
*
* @author andrea.turli
*
*/
@Test(groups = "unit")
public class ViComputeServiceContextBuilderTest {
@Test
public void testCreateContextModule() {
assertNotNull(new ViComputeServiceContextBuilder(new Properties()).createContextModule());
}
@Test
public void testCanBuildWithComputeService() {
ComputeServiceContext context = new ComputeServiceContextFactory()
.createContext(new ViComputeServiceContextSpec("https://localhost/sdk", "Administrator", "password"));
context.getComputeService().listNodes();
context.close();
}
}

View File

@ -22,63 +22,24 @@ package org.jclouds.servermanager.compute;
import java.util.List;
import java.util.Properties;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.StandaloneComputeServiceContextBuilder;
import org.jclouds.compute.config.StandaloneComputeServiceContextModule;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.suppliers.DefaultLocationSupplier;
import org.jclouds.domain.Location;
import org.jclouds.servermanager.Datacenter;
import org.jclouds.servermanager.Hardware;
import org.jclouds.servermanager.Image;
import org.jclouds.servermanager.Server;
import org.jclouds.servermanager.compute.functions.DatacenterToLocation;
import org.jclouds.servermanager.compute.functions.ServerManagerHardwareToHardware;
import org.jclouds.servermanager.compute.functions.ServerManagerImageToImage;
import org.jclouds.servermanager.compute.functions.ServerToNodeMetadata;
import org.jclouds.servermanager.compute.strategy.ServerManagerComputeServiceAdapter;
import org.jclouds.servermanager.ServerManager;
import org.jclouds.servermanager.compute.config.ServerManagerComputeServiceContextModule;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
public class ServerManagerComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder {
public class ServerManagerComputeServiceContextBuilder extends StandaloneComputeServiceContextBuilder<ServerManager> {
public ServerManagerComputeServiceContextBuilder(Properties props) {
super(props);
super(ServerManager.class, props);
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(createContextModule());
modules.add(new ServerManagerComputeServiceContextModule());
}
public static StandaloneComputeServiceContextModule<Server, Hardware, Image, Datacenter> createContextModule() {
return new StandaloneComputeServiceContextModule<Server, Hardware, Image, Datacenter>() {
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<ComputeServiceAdapter<Server, Hardware, Image, Datacenter>>() {
}).to(ServerManagerComputeServiceAdapter.class);
bind(new TypeLiteral<Supplier<Location>>() {
}).to(DefaultLocationSupplier.class);
bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
}).to(ServerToNodeMetadata.class);
bind(new TypeLiteral<Function<Image, org.jclouds.compute.domain.Image>>() {
}).to(ServerManagerImageToImage.class);
bind(new TypeLiteral<Function<Hardware, org.jclouds.compute.domain.Hardware>>() {
}).to(ServerManagerHardwareToHardware.class);
bind(new TypeLiteral<Function<Datacenter, Location>>() {
}).to(DatacenterToLocation.class);
}
};
}
}

View File

@ -0,0 +1,63 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.servermanager.compute.config;
import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.config.StandaloneComputeServiceContextModule;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.suppliers.DefaultLocationSupplier;
import org.jclouds.domain.Location;
import org.jclouds.servermanager.Datacenter;
import org.jclouds.servermanager.Hardware;
import org.jclouds.servermanager.Image;
import org.jclouds.servermanager.Server;
import org.jclouds.servermanager.compute.functions.DatacenterToLocation;
import org.jclouds.servermanager.compute.functions.ServerManagerHardwareToHardware;
import org.jclouds.servermanager.compute.functions.ServerManagerImageToImage;
import org.jclouds.servermanager.compute.functions.ServerToNodeMetadata;
import org.jclouds.servermanager.compute.strategy.ServerManagerComputeServiceAdapter;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.inject.TypeLiteral;
/**
*
* @author Adrian Cole
*/
public class ServerManagerComputeServiceContextModule extends
StandaloneComputeServiceContextModule<Server, Hardware, Image, Datacenter> {
@Override
protected void configure() {
super.configure();
bind(new TypeLiteral<ComputeServiceAdapter<Server, Hardware, Image, Datacenter>>() {
}).to(ServerManagerComputeServiceAdapter.class);
bind(new TypeLiteral<Supplier<Location>>() {
}).to(DefaultLocationSupplier.class);
bind(new TypeLiteral<Function<Server, NodeMetadata>>() {
}).to(ServerToNodeMetadata.class);
bind(new TypeLiteral<Function<Image, org.jclouds.compute.domain.Image>>() {
}).to(ServerManagerImageToImage.class);
bind(new TypeLiteral<Function<Hardware, org.jclouds.compute.domain.Hardware>>() {
}).to(ServerManagerHardwareToHardware.class);
bind(new TypeLiteral<Function<Datacenter, Location>>() {
}).to(DatacenterToLocation.class);
}
}

View File

@ -1,16 +1,37 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.servermanager.compute;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertEquals;
import java.util.Properties;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.StandaloneComputeServiceContextSpec;
import org.jclouds.rest.RestContext;
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.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
@ -24,11 +45,6 @@ import com.google.inject.Module;
@Test(groups = "unit")
public class ServerManagerComputeServiceContextBuilderTest {
@Test
public void testCreateContextModule() {
assertNotNull(ServerManagerComputeServiceContextBuilder.createContextModule());
}
@Test
public void testCanBuildDirectly() {
ComputeServiceContext context = new ServerManagerComputeServiceContextBuilder(new Properties())
@ -37,13 +53,37 @@ public class ServerManagerComputeServiceContextBuilderTest {
}
@Test
public void testCanBuildWithComputeService() {
public void testCanBuildWithContextSpec() {
ComputeServiceContext context = new ComputeServiceContextFactory()
.createContext(new StandaloneComputeServiceContextSpec<Server, Hardware, Image, Datacenter>(
"servermanager", "http://host", "1", "identity", "credential",
ServerManagerComputeServiceContextBuilder.createContextModule(), ImmutableSet.<Module> of()));
.createContext(new StandaloneComputeServiceContextSpec<ServerManager, Server, Hardware, Image, Datacenter>(
"servermanager", "http://host", "1", "identity", "credential", ServerManager.class,
ServerManagerComputeServiceContextBuilder.class, ImmutableSet.<Module> of()));
context.close();
}
@Test
public void testCanBuildWithRestProperties() {
Properties restProperties = new Properties();
restProperties.setProperty("servermanager.contextbuilder",
ServerManagerComputeServiceContextBuilder.class.getName());
restProperties.setProperty("servermanager.endpoint", "http://host");
restProperties.setProperty("servermanager.apiversion", "1");
ComputeServiceContext context = new ComputeServiceContextFactory(restProperties).createContext("servermanager",
"identity", "credential");
context.close();
}
@Test
public void testProviderSpecificContextIsCorrectType() {
ComputeServiceContext context = new ServerManagerComputeServiceContextBuilder(new Properties())
.buildComputeServiceContext();
RestContext<ServerManager, ServerManager> providerContext = context.getProviderSpecificContext();
assertEquals(providerContext.getApi().getClass(), ServerManager.class);
context.close();
}
}

View File

@ -0,0 +1,56 @@
package org.jclouds.servermanager.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
import java.util.Properties;
import org.jclouds.compute.BaseComputeServiceLiveTest;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Template;
import org.jclouds.rest.RestContext;
import org.jclouds.servermanager.ServerManager;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, sequential = true, testName = "servermanager.ServerManagerComputeServiceLiveTest")
public class ServerManagerComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public ServerManagerComputeServiceLiveTest() {
provider = "servermanager";
}
@Override
protected Properties getRestProperties() {
Properties restProperties = new Properties();
restProperties.setProperty("servermanager.contextbuilder",
ServerManagerComputeServiceContextBuilder.class.getName());
restProperties.setProperty("servermanager.endpoint", "http://host");
restProperties.setProperty("servermanager.apiversion", "1");
return restProperties;
}
@Test
public void testTemplateBuilder() {
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "5.3");
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.CENTOS);
assertEquals(defaultTemplate.getLocation().getId(), "1");
assertEquals(getCores(defaultTemplate.getHardware()), 0.5d);
}
@Override
protected JschSshClientModule getSshModule() {
return new JschSshClientModule();
}
public void testAssignability() throws Exception {
@SuppressWarnings("unused")
RestContext<ServerManager, ServerManager> goGridContext = new ComputeServiceContextFactory().createContext(
provider, identity, credential).getProviderSpecificContext();
}
}

View File

@ -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.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@ -59,9 +60,9 @@ public class ServerManagerExperimentLiveTest {
ComputeServiceContext context = null;
try {
context = new ComputeServiceContextFactory()
.createContext(new StandaloneComputeServiceContextSpec<Server, Hardware, Image, Datacenter>(
"servermanager", endpoint, apiversion, identity, credential,
ServerManagerComputeServiceContextBuilder.createContextModule(), ImmutableSet.<Module> of()));
.createContext(new StandaloneComputeServiceContextSpec<ServerManager, Server, Hardware, Image, Datacenter>(
"servermanager", endpoint, apiversion, identity, credential, ServerManager.class,
ServerManagerComputeServiceContextBuilder.class, ImmutableSet.<Module> of()));
context.getComputeService().listNodes();