Issue 191: more progress on compute integration

This commit is contained in:
Adrian Cole 2010-08-31 17:03:51 -07:00
parent 6a4c93840d
commit be23e73207
4 changed files with 233 additions and 163 deletions

View File

@ -1,169 +1,179 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
$HeadURL$ $Revision$ $Date$ Copyright (C) 2010 Cloud Conscious, LLC $HeadURL$ $Revision$ $Date$ Copyright (C) 2010 Cloud Conscious,
<info@cloudconscious.com> LLC <info@cloudconscious.com>
==================================================================== ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or
contributor license agreements. See the NOTICE file distributed with more contributor license agreements. See the NOTICE file
this work for additional information regarding copyright ownership. distributed with this work for additional information regarding
The ASF licenses this file to you under the Apache License, Version copyright ownership. The ASF licenses this file to you under the
2.0 (the "License"); you may not use this file except in compliance Apache License, Version 2.0 (the "License"); you may not use
with the License. You may obtain a copy of the License at 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.html Unless required by http://www.apache.org/licenses/LICENSE-2.0.html Unless required
applicable law or agreed to in writing, software distributed under the by applicable law or agreed to in writing, software distributed
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR under the License is distributed on an "AS IS" BASIS, WITHOUT
CONDITIONS OF ANY KIND, either express or implied. See the License for WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
the specific language governing permissions and limitations under the See the License for the specific language governing permissions
License. and limitations under the License.
==================================================================== ====================================================================
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>org.jclouds</groupId> <groupId>org.jclouds</groupId>
<artifactId>jclouds-chef-project</artifactId> <artifactId>jclouds-chef-project</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>org.jclouds</groupId> <groupId>org.jclouds</groupId>
<artifactId>jclouds-chef-compute</artifactId> <artifactId>jclouds-chef-compute</artifactId>
<name>jclouds chef compute integration</name> <name>jclouds chef compute integration</name>
<description>provisions nodes with jclouds and kick's off chef to configure and integrate</description> <description>provisions nodes with jclouds and kick's off chef to configure and integrate</description>
<properties> <properties>
<!-- for example: ec2, trmk-ecloud, bluelock-vclouddirector, cloudservers, etc --> <!--
<jclouds.compute.provider>YOUR_PREFERRED_PROVIDER</jclouds.compute.provider> for example: ec2, trmk-ecloud, bluelock-vclouddirector,
<!-- leave blank unless you have a different url to override --> cloudservers, etc
<jclouds.compute.endpoint></jclouds.compute.endpoint> -->
<jclouds.compute.identity>YOUR_ACCOUNT</jclouds.compute.identity> <jclouds.compute.provider>YOUR_PREFERRED_PROVIDER</jclouds.compute.provider>
<jclouds.compute.credential>YOUR_CREDENTIAL</jclouds.compute.credential> <!-- leave blank unless you have a different url to override -->
<jclouds.chef.identity>YOUR_USER</jclouds.chef.identity> <jclouds.compute.endpoint></jclouds.compute.endpoint>
<jclouds.chef.credential.pem>${user.home}/.chef/${jclouds.chef.identity}.pem</jclouds.chef.credential.pem> <jclouds.compute.identity>YOUR_ACCOUNT</jclouds.compute.identity>
<jclouds.opscodeplatform.org>YOUR_ORG</jclouds.opscodeplatform.org> <jclouds.compute.credential>YOUR_CREDENTIAL</jclouds.compute.credential>
<jclouds.chef.endpoint>https://api.opscode.com/organizations/${jclouds.opscodeplatform.org}</jclouds.chef.endpoint> <!-- tag for nodes used in the tests -->
</properties> <jclouds.compute.tag>jcloudschef</jclouds.compute.tag>
<jclouds.chef.identity>YOUR_USER</jclouds.chef.identity>
<jclouds.chef.credential.pem>${user.home}/.chef/${jclouds.chef.identity}.pem</jclouds.chef.credential.pem>
<jclouds.opscodeplatform.org>YOUR_ORG</jclouds.opscodeplatform.org>
<jclouds.chef.endpoint>https://api.opscode.com/organizations/${jclouds.opscodeplatform.org}</jclouds.chef.endpoint>
</properties>
<!-- bootstrapping: need to fetch the project POM --> <!-- bootstrapping: need to fetch the project POM -->
<repositories> <repositories>
<repository> <repository>
<id>jclouds-googlecode-deploy</id> <id>jclouds-googlecode-deploy</id>
<url>http://jclouds.googlecode.com/svn/repo</url> <url>http://jclouds.googlecode.com/svn/repo</url>
</repository> </repository>
<repository> <repository>
<id>jclouds-rimu-snapshots-nexus</id> <id>jclouds-rimu-snapshots-nexus</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url> <url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots> <snapshots>
<enabled>true</enabled> <enabled>true</enabled>
</snapshots> </snapshots>
</repository> </repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>jclouds-chef</artifactId> <artifactId>jclouds-chef</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>jclouds-compute</artifactId> <artifactId>jclouds-compute</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>jclouds-log4j</artifactId> <artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>log4j</groupId> <groupId>log4j</groupId>
<artifactId>log4j</artifactId> <artifactId>log4j</artifactId>
<version>1.2.14</version> <version>1.2.14</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>jclouds-core</artifactId> <artifactId>jclouds-core</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<type>test-jar</type> <type>test-jar</type>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>jclouds-compute</artifactId> <artifactId>jclouds-compute</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<type>test-jar</type> <type>test-jar</type>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>jclouds-allcompute</artifactId> <artifactId>jclouds-allcompute</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
</dependencies> </dependencies>
<profiles> <profiles>
<profile> <profile>
<id>live</id> <id>live</id>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<executions> <executions>
<execution> <execution>
<id>integration</id> <id>integration</id>
<phase>integration-test</phase> <phase>integration-test</phase>
<goals> <goals>
<goal>test</goal> <goal>test</goal>
</goals> </goals>
<configuration> <configuration>
<excludes> <excludes>
<exclude>none</exclude> <exclude>none</exclude>
</excludes> </excludes>
<includes> <includes>
<include>**/*LiveTest.java</include> <include>**/*LiveTest.java</include>
</includes> </includes>
<systemProperties> <systemProperties>
<property> <property>
<name>jclouds.compute.provider</name> <name>jclouds.compute.provider</name>
<value>${jclouds.compute.provider}</value> <value>${jclouds.compute.provider}</value>
</property> </property>
<property> <property>
<name>jclouds.compute.endpoint</name> <name>jclouds.compute.endpoint</name>
<value>${jclouds.compute.endpoint}</value> <value>${jclouds.compute.endpoint}</value>
</property> </property>
<property> <property>
<name>jclouds.compute.identity</name> <name>jclouds.compute.identity</name>
<value>${jclouds.compute.identity}</value> <value>${jclouds.compute.identity}</value>
</property> </property>
<property> <property>
<name>jclouds.compute.credential</name> <name>jclouds.compute.credential</name>
<value>${jclouds.compute.credential}</value> <value>${jclouds.compute.credential}</value>
</property> </property>
<property> <property>
<name>jclouds.chef.identity</name> <name>jclouds.compute.tag</name>
<value>${jclouds.chef.identity}</value> <value>${jclouds.compute.tag}</value>
</property> </property>
<property> <property>
<name>jclouds.chef.credential.pem</name> <name>jclouds.compute.credential</name>
<value>${jclouds.chef.credential.pem}</value> <value>${jclouds.compute.credential}</value>
</property> </property>
<property> <property>
<name>jclouds.chef.endpoint</name> <name>jclouds.chef.credential.pem</name>
<value>${jclouds.chef.endpoint}</value> <value>${jclouds.chef.credential.pem}</value>
</property> </property>
</systemProperties> <property>
</configuration> <name>jclouds.chef.endpoint</name>
</execution> <value>${jclouds.chef.endpoint}</value>
</executions> </property>
</plugin> </systemProperties>
</plugins> </configuration>
</build> </execution>
</profile> </executions>
</profiles> </plugin>
</plugins>
</build>
</profile>
</profiles>
</project> </project>

View File

@ -0,0 +1,14 @@
if [ ! -f /usr/bin/chef-client ]; then
apt-get update
apt-get install -y ruby ruby1.8-dev build-essential wget libruby-extras libruby1.8-extras
mkdir -p /tmp/bootchef
(
cd /tmp/bootchef
curl http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz| tar -xzf -
cd rubygems-1.3.6
ruby setup.rb
cp /usr/bin/gem1.8 /usr/bin/gem
)
rm -rf /tmp/bootchef
gem install chef ohai --no-rdoc --no-ri --verbose
fi

View File

@ -0,0 +1,5 @@
(
cat <<'EOP'
@herefile@
EOP
) > @destination@

View File

@ -20,15 +20,19 @@
package org.jclouds.chef.compute; package org.jclouds.chef.compute;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Sets.newHashSet;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import org.jclouds.chef.ChefContext; import org.jclouds.chef.ChefContext;
import org.jclouds.chef.ChefContextFactory; import org.jclouds.chef.ChefContextFactory;
import org.jclouds.chef.ChefService;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.crypto.Pems;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
@ -48,9 +52,13 @@ public class ChefComputeServiceLiveTest {
private ComputeServiceContext computeContext; private ComputeServiceContext computeContext;
private ChefContext chefContext; private ChefContext chefContext;
private String tag;
private String clientName;
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupCompute() { public void setupCompute() {
tag = System.getProperty("jclouds.compute.tag") != null ? System.getProperty("jclouds.compute.tag")
: "jcloudschef";
String computeProvider = checkNotNull(System.getProperty("jclouds.compute.provider"), "jclouds.compute.provider"); String computeProvider = checkNotNull(System.getProperty("jclouds.compute.provider"), "jclouds.compute.provider");
String computeEndpoint = System.getProperty("jclouds.compute.endpoint"); String computeEndpoint = System.getProperty("jclouds.compute.endpoint");
Properties props = new Properties(); Properties props = new Properties();
@ -77,11 +85,41 @@ public class ChefComputeServiceLiveTest {
} }
@Test @Test
public void test() { public void test() throws IOException {
clientName = findNextClientName(chefContext, tag + "-%d");
String clientKey = Pems.pem(chefContext.getApi().createClient(clientName).getPrivateKey());
// herefile /etc/chef/client.rb
// log_level :info
// log_location STDOUT
// chef_server_url "@chef_server_url@"
// herefile /etc/chef/client.pem
// clientKey
// herefile /etc/chef/first-boot.json
// { "run_list": [ "recipe[apache]" ] }
// then run /usr/bin/chef-client -j /etc/chef/first-boot.json
System.out.println("created new client: " + clientName);
computeContext.getComputeService().listNodes(); computeContext.getComputeService().listNodes();
chefContext.getChefService().listNodesDetails(); chefContext.getChefService().listNodesDetails();
} }
private String findNextClientName(ChefContext context, String pattern) {
Set<String> nodes = context.getApi().listClients();
String nodeName;
Set<String> names = newHashSet(nodes);
int index = 0;
while (true) {
nodeName = String.format(pattern, index++);
if (!names.contains(nodeName))
break;
}
return nodeName;
}
@AfterGroups(groups = { "live" }) @AfterGroups(groups = { "live" })
public void teardownCompute() { public void teardownCompute() {
if (computeContext != null) if (computeContext != null)
@ -90,7 +128,10 @@ public class ChefComputeServiceLiveTest {
@AfterGroups(groups = { "live" }) @AfterGroups(groups = { "live" })
public void teardownChef() { public void teardownChef() {
if (chefContext != null) if (chefContext != null) {
if (clientName != null && chefContext.getApi().clientExists(clientName))
chefContext.getApi().deleteClient(clientName);
chefContext.close(); chefContext.close();
}
} }
} }