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"?>
<!--
$HeadURL$ $Revision$ $Date$ Copyright (C) 2010 Cloud Conscious, LLC
<info@cloudconscious.com>
<!--
$HeadURL$ $Revision$ $Date$ Copyright (C) 2010 Cloud Conscious,
LLC <info@cloudconscious.com>
====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you 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
====================================================================
Licensed to the Apache Software Foundation (ASF) under one or
more contributor license agreements. See the NOTICE file
distributed with this work for additional information regarding
copyright ownership. The ASF licenses this file to you 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.html 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.
====================================================================
-->
http://www.apache.org/licenses/LICENSE-2.0.html 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.
====================================================================
-->
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-chef-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-chef-compute</artifactId>
<name>jclouds chef compute integration</name>
<description>provisions nodes with jclouds and kick's off chef to configure and integrate</description>
<properties>
<!-- for example: ec2, trmk-ecloud, bluelock-vclouddirector, cloudservers, etc -->
<jclouds.compute.provider>YOUR_PREFERRED_PROVIDER</jclouds.compute.provider>
<!-- leave blank unless you have a different url to override -->
<jclouds.compute.endpoint></jclouds.compute.endpoint>
<jclouds.compute.identity>YOUR_ACCOUNT</jclouds.compute.identity>
<jclouds.compute.credential>YOUR_CREDENTIAL</jclouds.compute.credential>
<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>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-chef-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-chef-compute</artifactId>
<name>jclouds chef compute integration</name>
<description>provisions nodes with jclouds and kick's off chef to configure and integrate</description>
<properties>
<!--
for example: ec2, trmk-ecloud, bluelock-vclouddirector,
cloudservers, etc
-->
<jclouds.compute.provider>YOUR_PREFERRED_PROVIDER</jclouds.compute.provider>
<!-- leave blank unless you have a different url to override -->
<jclouds.compute.endpoint></jclouds.compute.endpoint>
<jclouds.compute.identity>YOUR_ACCOUNT</jclouds.compute.identity>
<jclouds.compute.credential>YOUR_CREDENTIAL</jclouds.compute.credential>
<!-- tag for nodes used in the tests -->
<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 -->
<repositories>
<repository>
<id>jclouds-googlecode-deploy</id>
<url>http://jclouds.googlecode.com/svn/repo</url>
</repository>
<repository>
<id>jclouds-rimu-snapshots-nexus</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- bootstrapping: need to fetch the project POM -->
<repositories>
<repository>
<id>jclouds-googlecode-deploy</id>
<url>http://jclouds.googlecode.com/svn/repo</url>
</repository>
<repository>
<id>jclouds-rimu-snapshots-nexus</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-chef</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-allcompute</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<optional>true</optional>
</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>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*LiveTest.java</include>
</includes>
<systemProperties>
<property>
<name>jclouds.compute.provider</name>
<value>${jclouds.compute.provider}</value>
</property>
<property>
<name>jclouds.compute.endpoint</name>
<value>${jclouds.compute.endpoint}</value>
</property>
<property>
<name>jclouds.compute.identity</name>
<value>${jclouds.compute.identity}</value>
</property>
<property>
<name>jclouds.compute.credential</name>
<value>${jclouds.compute.credential}</value>
</property>
<property>
<name>jclouds.chef.identity</name>
<value>${jclouds.chef.identity}</value>
</property>
<property>
<name>jclouds.chef.credential.pem</name>
<value>${jclouds.chef.credential.pem}</value>
</property>
<property>
<name>jclouds.chef.endpoint</name>
<value>${jclouds.chef.endpoint}</value>
</property>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-chef</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-compute</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-allcompute</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<optional>true</optional>
</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>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/*LiveTest.java</include>
</includes>
<systemProperties>
<property>
<name>jclouds.compute.provider</name>
<value>${jclouds.compute.provider}</value>
</property>
<property>
<name>jclouds.compute.endpoint</name>
<value>${jclouds.compute.endpoint}</value>
</property>
<property>
<name>jclouds.compute.identity</name>
<value>${jclouds.compute.identity}</value>
</property>
<property>
<name>jclouds.compute.credential</name>
<value>${jclouds.compute.credential}</value>
</property>
<property>
<name>jclouds.compute.tag</name>
<value>${jclouds.compute.tag}</value>
</property>
<property>
<name>jclouds.compute.credential</name>
<value>${jclouds.compute.credential}</value>
</property>
<property>
<name>jclouds.chef.credential.pem</name>
<value>${jclouds.chef.credential.pem}</value>
</property>
<property>
<name>jclouds.chef.endpoint</name>
<value>${jclouds.chef.endpoint}</value>
</property>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</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;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Sets.newHashSet;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import java.util.Set;
import org.jclouds.chef.ChefContext;
import org.jclouds.chef.ChefContextFactory;
import org.jclouds.chef.ChefService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.crypto.Pems;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
@ -48,9 +52,13 @@ public class ChefComputeServiceLiveTest {
private ComputeServiceContext computeContext;
private ChefContext chefContext;
private String tag;
private String clientName;
@BeforeGroups(groups = { "live" })
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 computeEndpoint = System.getProperty("jclouds.compute.endpoint");
Properties props = new Properties();
@ -77,11 +85,41 @@ public class ChefComputeServiceLiveTest {
}
@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();
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" })
public void teardownCompute() {
if (computeContext != null)
@ -90,7 +128,10 @@ public class ChefComputeServiceLiveTest {
@AfterGroups(groups = { "live" })
public void teardownChef() {
if (chefContext != null)
if (chefContext != null) {
if (clientName != null && chefContext.getApi().clientExists(clientName))
chefContext.getApi().deleteClient(clientName);
chefContext.close();
}
}
}