Issue 440: renamed vsphere->vi, made sure all sandbox modules compile

This commit is contained in:
Adrian Cole 2011-01-11 12:37:46 -08:00
parent 79e5df9ace
commit 0064787912
27 changed files with 258 additions and 116 deletions

View File

@ -45,6 +45,12 @@
<artifactId>libvirt</artifactId>
<version>0.4.6</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.sun.jna</groupId>
<artifactId>jna</artifactId>
@ -57,19 +63,19 @@
<version>0.3</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
@ -82,13 +88,13 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-jsch</artifactId>
<version>${project.version}</version>
<scope>test</scope>

View File

@ -19,18 +19,18 @@
package org.jclouds.libvirt.compute.domain;
import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static org.jclouds.libvirt.LibvirtConstants.PROPERTY_LIBVIRT_DOMAIN_DIR;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.URI;
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;
@ -40,8 +40,8 @@ import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
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.http.functions.ParseSax;
import org.jclouds.libvirt.Datacenter;
import org.jclouds.libvirt.Image;
import org.jclouds.libvirt.compute.functions.DatacenterToLocation;
@ -49,31 +49,29 @@ import org.jclouds.libvirt.compute.functions.DomainToHardware;
import org.jclouds.libvirt.compute.functions.DomainToNodeMetadata;
import org.jclouds.libvirt.compute.functions.LibvirtImageToImage;
import org.jclouds.libvirt.compute.strategy.LibvirtComputeServiceAdapter;
import org.jclouds.rest.annotations.Provider;
import org.jclouds.location.Provider;
import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
import org.libvirt.Connect;
import org.libvirt.Domain;
import org.libvirt.LibvirtException;
import org.xml.sax.InputSource;
import org.xml.sax.Attributes;
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;
/**
*
* @author Adrian Cole
*/
public class LibvirtComputeServiceContextModule extends
ComputeServiceAdapterContextModule<Connect, Connect, Domain, Domain, Image, Datacenter> {
ComputeServiceAdapterContextModule<Connect, Connect, Domain, Domain, Image, Datacenter> {
public LibvirtComputeServiceContextModule() {
super(Connect.class, Connect.class);
@ -85,7 +83,7 @@ public class LibvirtComputeServiceContextModule extends
bind(new TypeLiteral<ComputeServiceAdapter<Domain, Domain, Image, Datacenter>>() {
}).to(LibvirtComputeServiceAdapter.class);
bind(new TypeLiteral<Supplier<Location>>() {
}).to(DefaultLocationSupplier.class);
}).to(OnlyLocationOrFirstZone.class);
bind(new TypeLiteral<Function<Domain, NodeMetadata>>() {
}).to(DomainToNodeMetadata.class);
bind(new TypeLiteral<Function<Image, org.jclouds.compute.domain.Image>>() {
@ -101,7 +99,7 @@ public class LibvirtComputeServiceContextModule extends
@Provides
@Singleton
protected Connect createConnection(@Provider URI endpoint, @Named(Constants.PROPERTY_IDENTITY) String identity,
@Named(Constants.PROPERTY_CREDENTIAL) String credential) throws LibvirtException {
@Named(Constants.PROPERTY_CREDENTIAL) String credential) throws LibvirtException {
// ConnectAuth connectAuth = null;
return new Connect(endpoint.toASCIIString());
}
@ -109,7 +107,8 @@ public class LibvirtComputeServiceContextModule extends
@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 hardwareId = searchForHardwareIdInDomainDir(domainDir, injector.getInstance(ParseSax.Factory.class),
injector.getProvider(UUIDHandler.class));
String image = searchForImageIdInDomainDir(domainDir);
return template.hardwareId(hardwareId).imageId(image);
}
@ -120,24 +119,56 @@ public class LibvirtComputeServiceContextModule extends
}
@SuppressWarnings("unchecked")
private String searchForHardwareIdInDomainDir(String domainDir) {
private String searchForHardwareIdInDomainDir(String domainDir, final ParseSax.Factory factory,
final javax.inject.Provider<UUIDHandler> provider) {
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();
// TODO: remove commons-io dependency
return Iterables.<String> getLast(filter(transform(FileUtils.listFiles(new File(domainDir),
new WildcardFileFilter("*.xml"), null), new Function<File, String>() {
@Override
public String apply(File input) {
try {
return factory.create(provider.get()).parse(new FileInputStream(input));
} catch (FileNotFoundException e) {
// log error.
return null;
}
}
}), notNull()));
}
public static class UUIDHandler extends ParseSax.HandlerWithResult<String> {
private StringBuilder currentText = new StringBuilder();
private boolean inDomain;
private String uuid;
public String getResult() {
return uuid;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
if (qName.equals("domain")) {
inDomain = true;
}
}
@Override
public void endElement(String uri, String localName, String qName) {
if (qName.equalsIgnoreCase("uuid") && inDomain) {
this.uuid = currentText.toString();
} else if (qName.equalsIgnoreCase("domain")) {
inDomain = false;
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
return uuid;
}
/*

View File

@ -29,17 +29,22 @@
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds.api</groupId>
<artifactId>vsphere</artifactId>
<name>jclouds example components for a vijava lib for vSphere</name>
<artifactId>vi</artifactId>
<name>jclouds example components for a vijava lib for VI 4 (VMware Infrastructure)</name>
<properties>
<!-- when instances are hung, open a ticket and add here -->
<jclouds.compute.blacklist.nodes>trmkrun-ccc,test.trmk-924</jclouds.compute.blacklist.nodes>
<test.libvirt.endpoint>test:///default</test.libvirt.endpoint>
<test.libvirt.apiversion>1.0</test.libvirt.apiversion>
<test.libvirt.identity>FIXME</test.libvirt.identity>
<test.libvirt.credential>FIXME</test.libvirt.credential>
<test.vi.endpoint>test:///default</test.vi.endpoint>
<test.vi.apiversion>1.0</test.vi.apiversion>
<test.vi.identity>FIXME</test.vi.identity>
<test.vi.credential>FIXME</test.vi.credential>
</properties>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.jvnet.hudson</groupId>
<artifactId>vijava</artifactId>
@ -107,20 +112,20 @@
<configuration>
<systemProperties>
<property>
<name>test.libvirt.endpoint</name>
<value>${test.libvirt.endpoint}</value>
<name>test.vi.endpoint</name>
<value>${test.vi.endpoint}</value>
</property>
<property>
<name>test.libvirt.apiversion</name>
<value>${test.libvirt.apiversion}</value>
<name>test.vi.apiversion</name>
<value>${test.vi.apiversion}</value>
</property>
<property>
<name>test.libvirt.identity</name>
<value>${test.libvirt.identity}</value>
<name>test.vi.identity</name>
<value>${test.vi.identity}</value>
</property>
<property>
<name>test.libvirt.credential</name>
<value>${test.libvirt.credential}</value>
<name>test.vi.credential</name>
<value>${test.vi.credential}</value>
</property>
<property>
<name>jclouds.compute.blacklist.nodes</name>

View File

@ -19,18 +19,19 @@
package org.jclouds.vi.compute.config;
import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
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;
@ -40,27 +41,25 @@ import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
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.http.functions.ParseSax;
import org.jclouds.location.Provider;
import org.jclouds.location.suppliers.OnlyLocationOrFirstZone;
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.Attributes;
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.Provides;
import com.google.inject.TypeLiteral;
import com.jamesmurty.utils.XMLBuilder;
import com.vmware.vim25.mo.Datacenter;
import com.vmware.vim25.mo.ServiceInstance;
import com.vmware.vim25.mo.VirtualMachine;
@ -70,8 +69,8 @@ import com.vmware.vim25.mo.VirtualMachine;
* @author Adrian Cole
*/
public class ViComputeServiceContextModule
extends
ComputeServiceAdapterContextModule<ServiceInstance, ServiceInstance, VirtualMachine, VirtualMachine, Image, Datacenter> {
extends
ComputeServiceAdapterContextModule<ServiceInstance, ServiceInstance, VirtualMachine, VirtualMachine, Image, Datacenter> {
public ViComputeServiceContextModule() {
super(ServiceInstance.class, ServiceInstance.class);
@ -83,7 +82,7 @@ public class ViComputeServiceContextModule
bind(new TypeLiteral<ComputeServiceAdapter<VirtualMachine, VirtualMachine, Image, Datacenter>>() {
}).to(ViComputeServiceAdapter.class);
bind(new TypeLiteral<Supplier<Location>>() {
}).to(DefaultLocationSupplier.class);
}).to(OnlyLocationOrFirstZone.class);
bind(new TypeLiteral<Function<VirtualMachine, NodeMetadata>>() {
}).to(VirtualMachineToNodeMetadata.class);
bind(new TypeLiteral<Function<Image, org.jclouds.compute.domain.Image>>() {
@ -97,8 +96,8 @@ public class ViComputeServiceContextModule
@Provides
@Singleton
protected ServiceInstance createConnection(@Provider URI endpoint,
@Named(Constants.PROPERTY_IDENTITY) String identity, @Named(Constants.PROPERTY_CREDENTIAL) String credential)
throws RemoteException, MalformedURLException {
@Named(Constants.PROPERTY_IDENTITY) String identity, @Named(Constants.PROPERTY_CREDENTIAL) String credential)
throws RemoteException, MalformedURLException {
return new ServiceInstance(endpoint.toURL(), identity, credential, true);
}
@ -106,9 +105,9 @@ public class ViComputeServiceContextModule
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 image = searchForImageIdInDomainDir(domainDir);
// String domainDir = "";
// String hardwareId = searchForHardwareIdInDomainDir(domainDir);
// String image = searchForImageIdInDomainDir(domainDir);
return template.hardwareId("vm-1221").imageId("winNetEnterprise64Guest");
}
@ -118,24 +117,56 @@ public class ViComputeServiceContextModule
}
@SuppressWarnings("unchecked")
private String searchForHardwareIdInDomainDir(String domainDir) {
private String searchForHardwareIdInDomainDir(String domainDir, final ParseSax.Factory factory,
final javax.inject.Provider<UUIDHandler> provider) {
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();
//TODO: remove commons-io dependency
return Iterables.<String>getLast(filter(transform(FileUtils.listFiles(new File(domainDir), new WildcardFileFilter("*.xml"), null),
new Function<File, String>() {
@Override
public String apply(File input) {
try {
return factory.create(provider.get()).parse(new FileInputStream(input));
} catch (FileNotFoundException e) {
// log error.
return null;
}
}
}), notNull()));
}
public static class UUIDHandler extends ParseSax.HandlerWithResult<String> {
private StringBuilder currentText = new StringBuilder();
private boolean inDomain;
private String uuid;
public String getResult() {
return uuid;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
if (qName.equals("domain")) {
inDomain = true;
}
}
@Override
public void endElement(String uri, String localName, String qName) {
if (qName.equalsIgnoreCase("uuid") && inDomain) {
this.uuid = currentText.toString();
} else if (qName.equalsIgnoreCase("domain")) {
inDomain = false;
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
return uuid;
}
/*

View File

@ -46,10 +46,22 @@
</repositories>
<dependencies>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>

View File

@ -88,7 +88,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>:%s/
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>

View File

@ -33,24 +33,26 @@
<version>1.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds.api</groupId>
<groupId>org.jclouds.provider</groupId>
<artifactId>ibmdev</artifactId>
<name>jclouds IBMDeveloperCloud core</name>
<description>jclouds components to access IBMDeveloperCloud</description>
<!-- bootstrapping: need to fetch the project POM -->
<repositories>
<repository>
<id>jclouds-sonatype-snapshots-nexus</id>
<id>jclouds-sona-snapshots-nexus</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<properties>
<jclouds.test.identity>${jclouds.ibmdev.user}</jclouds.test.identity>
<jclouds.test.credential>${jclouds.ibmdev.password}</jclouds.test.credential>
<jclouds.test.endpoint>https://www-147.ibm.com/computecloud/enterprise/api/rest</jclouds.test.endpoint>
<test.ibmdev.endpoint>https://www-147.ibm.com/computecloud/enterprise/api/rest</test.ibmdev.endpoint>
<test.ibmdev.apiversion>20100331</test.ibmdev.apiversion>
<test.ibmdev.identity>FIXME</test.ibmdev.identity>
<test.ibmdev.credential>FIXME</test.ibmdev.credential>
</properties>
<dependencies>
<dependency>
@ -65,6 +67,18 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute </artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
@ -78,22 +92,53 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-jsch</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-jsch</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>integration</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemProperties>
<property>
<name>test.ibmdev.endpoint</name>
<value>${test.ibmdev.endpoint}</value>
</property>
<property>
<name>test.ibmdev.apiversion</name>
<value>${test.ibmdev.apiversion}</value>
</property>
<property>
<name>test.ibmdev.identity</name>
<value>${test.ibmdev.identity}</value>
</property>
<property>
<name>test.ibmdev.credential</name>
<value>${test.ibmdev.credential}</value>
</property>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -29,7 +29,7 @@
<version>1.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds.api</groupId>
<groupId>org.jclouds.provider</groupId>
<artifactId>rimuhosting</artifactId>
<name>jclouds RimuHosting provider</name>
<description>ComputeService implementation of RimuHosting datacenters </description>

View File

@ -30,7 +30,7 @@
<version>1.0-SNAPSHOT</version>
<relativePath>../../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds.api</groupId>
<groupId>org.jclouds.provider</groupId>
<artifactId>savvis</artifactId>
<name>jclouds savvis core</name>
<description>jclouds components to access savvis</description>

View File

@ -63,6 +63,18 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-blobstore</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>