Issue 129: cargo integration and ant task consolidation

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2636 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2010-01-11 13:38:07 +00:00
parent 54cc272cfe
commit 5b1a2da6a1
28 changed files with 453 additions and 287 deletions

View File

@ -29,6 +29,7 @@ import java.util.SortedSet;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.aws.AWSResponseException;
@ -51,6 +52,7 @@ import org.jclouds.compute.domain.ServerState;
import org.jclouds.compute.domain.internal.CreateServerResponseImpl;
import org.jclouds.compute.domain.internal.ServerIdentityImpl;
import org.jclouds.compute.domain.internal.ServerMetadataImpl;
import org.jclouds.compute.reference.ComputeConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.logging.Logger;
import org.jclouds.scriptbuilder.ScriptBuilder;
@ -69,6 +71,7 @@ import com.google.inject.internal.ImmutableSet;
@Singleton
public class EC2ComputeService implements ComputeService {
@Resource
@Named(ComputeConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final EC2Client ec2Client;
private final Predicate<RunningInstance> instanceStateRunning;

View File

@ -22,5 +22,5 @@ package org.jclouds.compute.domain;
* @author Adrian Cole
*/
public enum Image {
CENTOS_53, RHEL_53, UBUNTU_90, UBUNTU_JEOS
CENTOS_53, RHEL_53, UBUNTU_90, UBUNTU_JEOS_90
}

View File

@ -16,24 +16,14 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.tools.ant;
import java.io.IOException;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
package org.jclouds.compute.reference;
/**
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "compute.ComputeTaskTest")
public class ComputeTaskTest {
private ComputeTask task;
private ServerElement serverElement;
public interface ComputeConstants {
@BeforeTest
protected void setUp() throws IOException {
this.task = new ComputeTask();
public static final String COMPUTE_LOGGER = "jclouds.compute";
}
}

View File

@ -24,7 +24,9 @@ import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeService;
@ -32,6 +34,8 @@ import org.jclouds.compute.domain.CreateServerResponse;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Profile;
import org.jclouds.compute.domain.ServerMetadata;
import org.jclouds.compute.reference.ComputeConstants;
import org.jclouds.logging.Logger;
import org.jclouds.rimuhosting.miro.RimuHostingClient;
import org.jclouds.rimuhosting.miro.domain.NewServerResponse;
import org.jclouds.rimuhosting.miro.domain.Server;
@ -43,6 +47,10 @@ import com.google.common.collect.ImmutableMap;
*/
@Singleton
public class RimuHostingComputeService implements ComputeService {
@Resource
@Named(ComputeConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
RimuHostingClient rhClient;
@Inject
@ -80,7 +88,7 @@ public class RimuHostingComputeService implements ComputeService {
public SortedSet<org.jclouds.compute.domain.ServerIdentity> getServerByName(String id) {
SortedSet<org.jclouds.compute.domain.ServerIdentity> serverSet = new TreeSet<org.jclouds.compute.domain.ServerIdentity>();
for (Server rhServer : rhClient.getServerList()) {
if(rhServer.getName().equals(id)){
if (rhServer.getName().equals(id)) {
serverSet.add(new RimuHostingServer(rhServer, rhClient));
}
}

View File

@ -1,7 +0,0 @@
target
.settings
.classpath
.project
jclouds-ant-plugin.iml
jclouds-ant-plugin.ipr
jclouds-ant-plugin.iws

View File

@ -1,70 +0,0 @@
<!--
Copyright (C) 2009 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.
====================================================================
-->
<project name="compute" default="list" basedir="." xmlns:artifact="urn:maven-artifact-ant">
<path id="maven-ant-tasks.classpath" path="maven-ant-tasks-2.1.0.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant"
classpathref="maven-ant-tasks.classpath"/>
<artifact:localRepository id="local.repository" path="${user.home}/.m2/repository" />
<artifact:remoteRepository id="jclouds-snapshot.repository" url="http://jclouds.rimuhosting.com/maven2/snapshots" />
<artifact:dependencies pathId="jclouds.classpath">
<dependency groupId="org.jclouds" artifactId="jclouds-ant-plugin" version="1.0-SNAPSHOT" />
<dependency groupId="org.jclouds" artifactId="jclouds-terremark" version="1.0-SNAPSHOT" />
<dependency groupId="org.jclouds" artifactId="jclouds-aws" version="1.0-SNAPSHOT" />
<dependency groupId="org.jclouds" artifactId="jclouds-hostingdotcom" version="1.0-SNAPSHOT" />
<dependency groupId="org.jclouds" artifactId="jclouds-rimuhosting" version="1.0-SNAPSHOT" />
<localRepository refid="local.repository" />
<remoteRepository refid="jclouds-snapshot.repository" />
</artifact:dependencies>
<typedef name="compute" classname="org.jclouds.tools.ant.ComputeTask" classpathref="jclouds.classpath" />
<property name="jclouds.compute.url" value="compute://${jclouds.compute.account}:${jclouds.compute.key}@${jclouds.compute.provider}" />
<property name="jclouds.compute.servername" value="testforjcloud2" />
<target name="list" description="list the identity of all servers" >
<compute action="list" provider="${jclouds.compute.url}" />
</target>
<target name="list-details" description="list the details of all servers" >
<compute action="list-details" provider="${jclouds.compute.url}" />
</target>
<target name="destroy" description="destroy the server ${jclouds.compute.servername}" >
<compute action="destroy" provider="${jclouds.compute.url}">
<server name="${jclouds.compute.servername}" />
</compute>
</target>
<target name="get" description="get the server ${jclouds.compute.servername}" >
<compute action="get" provider="${jclouds.compute.url}">
<server name="${jclouds.compute.servername}" />
</compute>
</target>
<target name="create" description="create the server ${jclouds.compute.servername}" >
<compute action="create" provider="${jclouds.compute.url}">
<server name="${jclouds.compute.servername}" image="UBUNTU_90" profile="SMALLEST" />
</compute>
</target>
</project>

View File

@ -1,54 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2009 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.
====================================================================
-->
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-tools-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>jclouds-ant-plugin</artifactId>
<name>Ant plugin for jclouds</name>
<properties>
<jclouds.test.listener></jclouds.test.listener>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-jsch</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -1,61 +0,0 @@
/**
*
* Copyright (C) 2009 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.tools.ant;
/**
* @author Ivan Meredith
*/
public class ServerElement {
private String name;
private String profile;
private String image;
private String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getProfile() {
return profile;
}
public void setProfile(String profile) {
this.profile = profile;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

View File

@ -38,6 +38,11 @@
<artifactId>jclouds-scriptbuilder</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
@ -49,6 +54,11 @@
<artifactId>ant-jsch</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-jsch</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>

View File

@ -20,52 +20,103 @@
-->
<project xmlns:artifact="urn:maven-artifact-ant" name="cargooverssh" default="cargooverssh" basedir=".">
<property name="host" value="204.51.114.84" />
<property name="username" value="vcloud" />
<property name="password" value="p4ssw0rd" />
<property file="build.properties" />
<property name="password" value="" />
<property name="keyfile" value="" />
<input message="Please enter the ip or hostname of the ssh machine" addproperty="host"/>
<input message="Please enter the user you will connect as" addproperty="username"/>
<input message="Please enter the path to the dsa key" addproperty="keyfile"/>
<!-- maven must be available before we use it -->
<delete dir="build/cargo"/>
<mkdir dir="build/cargo"/>
<!--
<get src="http://apache.imghat.com/maven/binaries/maven-ant-tasks-2.1.0.jar" dest="build/maven-ant-tasks-2.1.0.jar"/>
<get src="http://web-actions.googlecode.com/files/samples-blazeds.war" dest="build/samples-blazeds.war"/>
-->
<!-- initialize maven tasks -->
<path id="maven-ant-tasks.classpath" path="build/maven-ant-tasks-2.1.0.jar"/>
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant" classpathref="maven-ant-tasks.classpath"/>
<artifact:localRepository id="local.repository" path="${user.home}/.m2/repository"/>
<artifact:remoteRepository id="jclouds-snapshot.repository" url="http://jclouds.rimuhosting.com/maven2/snapshots"/>
<!-- Setup maven so that we can get latest version of jclouds, jclouds, and jruby -->
<artifact:dependencies pathId="jclouds.classpath">
<dependency groupid="org.codehaus.cargo" artifactId="cargo-ant" version="1.0.1-SNAPSHOT"/>
<dependency groupid="org.codehaus.cargo" artifactId="cargo-core-container-tomcat" version="1.0.1-SNAPSHOT"/>
<dependency groupId="org.jclouds" artifactId="jclouds-terremark" version="1.0-SNAPSHOT"/>
<dependency groupId="org.jclouds" artifactId="jclouds-ant-plugin" version="1.0-SNAPSHOT"/>
<dependency groupId="org.jclouds" artifactId="jclouds-antcontrib" version="1.0-SNAPSHOT"/>
<remoteRepository refid="jclouds-snapshot.repository"/>
<localRepository refid="local.repository"/>
</artifact:dependencies>
<typedef name="compute" classname="org.jclouds.tools.ant.ComputeTask" classpathref="jclouds.classpath"/>
<typedef name="compute" classname="org.jclouds.tools.ant.taskdefs.compute.ComputeTask" classpathref="jclouds.classpath" />
<taskdef name="sshexec" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec" classpathref="jclouds.classpath" />
<taskdef resource="cargo.tasks" classpathref="jclouds.classpath"/>
<property name="service" value="terremark"/>
<input message="What is your account on ${service}?" addproperty="account"/>
<input message="What is the key for ${account}?" addproperty="key"/>
<property name="jclouds.compute.servername" value="terremark-blaze"/>
<property name="jclouds.compute.url" value="compute://${account}:${key}@${service}"/>
<target name="boo">
<input message="What is the container you wish to store ${zip} in?" addproperty="container"/>
<target name="destroy" description="destroy the server ${jclouds.compute.servername}">
<compute action="destroy" provider="${jclouds.compute.url}">
<server name="${jclouds.compute.servername}" />
</compute>
</target>
<target name="cargooverssh">
<compute action="list-details" provider="${jclouds.compute.url}"/>
<cargo containerId="tomcat6x" output="build/output.log" log="build/cargo.log" action="start">
<sysproperty key="myproperty" value="myvalue"/>
<target name="create" description="create the server ${jclouds.compute.servername}" depends="destroy" >
<compute action="create" provider="${jclouds.compute.url}">
<server name="${jclouds.compute.servername}" image="UBUNTU_JEOS_90" profile="SMALLEST"
hostproperty="host" usernameproperty="username" passwordproperty="password" />
</compute>
<echo message="provisioning java on: ${jclouds.compute.servername}" />
<property name="sudo" value="echo ${password}|sudo -S" />
<!-- funny game to get around sudo problems with >>. first sudo is only to prime the password -->
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="${sudo} echo hello;echo nameserver 208.67.222.222 |sudo tee -a /etc/resolv.conf" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="${sudo} apt-get update -qq" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="${sudo} apt-get upgrade -y -qq" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="${sudo} apt-get install -y -qq wget" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="${sudo} apt-get install -y -qq openjdk-6-jdk" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="wget -q http://www.alliedquotes.com/mirrors/apache/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.tar.gz" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="tar xzf apache-tomcat-6.0.20.tar.gz" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="${sudo} mkdir -p /tmp/cargo/containers/" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="${sudo} chmod 1777 /tmp/cargo" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="${sudo} mv apache-tomcat-6.0.20 /tmp/cargo/containers/tomcat6x" />
</target>
<target name="cargooverssh" depends="create">
<echo message="deploying tomcat and blaze to: ${jclouds.compute.servername}" />
<cargo containerId="tomcat6x" output="build/output.log" log="build/cargo.log" action="start" timeout="600000">
<zipurlinstaller installurl="http://www.alliedquotes.com/mirrors/apache/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.zip"/>
<configuration home="build/cargo" type="standalone">
<property name="cargo.java.home" value="/usr/lib/jvm/java-6-openjdk"/>
<property name="cargo.hostname" value="${host}"/>
<property name="cargo.servlet.port" value="8080"/>
<property name="cargo.ssh.host" value="${host}"/>
<property name="cargo.ssh.username" value="${username}"/>
<property name="cargo.ssh.password" value="${password}"/>
<property name="cargo.ssh.keyfile" value="${keyfile}"/>
<property name="cargo.ssh.remotebase" value="/tmp/cargo"/>
<property name="cargo.logging" value="high"/>
<deployable type="war" file="build/samples-blazeds.war"/>
</configuration>

View File

@ -0,0 +1,90 @@
<!--
Copyright (C) 2009 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.
====================================================================
-->
<project name="compute" default="list" basedir="." xmlns:artifact="urn:maven-artifact-ant">
<mkdir dir="build" />
<!--
<get src="http://apache.imghat.com/maven/binaries/maven-ant-tasks-2.1.0.jar" dest="build/maven-ant-tasks-2.1.0.jar"/>
-->
<path id="maven-ant-tasks.classpath" path="build/maven-ant-tasks-2.1.0.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant" classpathref="maven-ant-tasks.classpath" />
<artifact:localRepository id="local.repository" path="${user.home}/.m2/repository" />
<artifact:remoteRepository id="jclouds-snapshot.repository" url="http://jclouds.rimuhosting.com/maven2/snapshots" />
<artifact:dependencies pathId="jclouds.classpath">
<dependency groupId="org.jclouds" artifactId="jclouds-antcontrib" version="1.0-SNAPSHOT" />
<dependency groupId="org.jclouds" artifactId="jclouds-terremark" version="1.0-SNAPSHOT" />
<localRepository refid="local.repository" />
<remoteRepository refid="jclouds-snapshot.repository" />
</artifact:dependencies>
<typedef name="compute" classname="org.jclouds.tools.ant.taskdefs.compute.ComputeTask" classpathref="jclouds.classpath" />
<taskdef name="sshexec" classname="org.apache.tools.ant.taskdefs.optional.ssh.SSHExec" classpathref="jclouds.classpath" />
<property name="jclouds.compute.url" value="compute://${jclouds.compute.account}:${jclouds.compute.key}@${jclouds.compute.provider}" />
<property name="jclouds.compute.servername" value="testforjcloud2" />
<target name="list" description="list the identity of all servers">
<compute action="list" provider="${jclouds.compute.url}" />
</target>
<target name="list-details" description="list the details of all servers">
<compute action="list-details" provider="${jclouds.compute.url}" />
</target>
<target name="destroy" description="destroy the server ${jclouds.compute.servername}">
<compute action="destroy" provider="${jclouds.compute.url}">
<server name="${jclouds.compute.servername}" />
</compute>
</target>
<target name="get" description="get the server ${jclouds.compute.servername}">
<compute action="get" provider="${jclouds.compute.url}">
<server name="${jclouds.compute.servername}" />
</compute>
</target>
<target name="create" description="create the server ${jclouds.compute.servername}">
<compute action="create" provider="${jclouds.compute.url}">
<server name="${jclouds.compute.servername}" image="UBUNTU_JEOS_90" profile="SMALLEST" hostproperty="host" usernameproperty="username" passwordproperty="password" />
</compute>
<property name="sudo" value="echo ${password}|sudo -S" />
<!-- funny game to get around sudo problems with >>. first sudo is only to prime the password -->
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="${sudo} echo hello;echo nameserver 208.67.222.222 |sudo tee -a /etc/resolv.conf" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="${sudo} apt-get update -qq" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="${sudo} apt-get upgrade -y -qq" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="${sudo} apt-get install -y -qq wget" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="${sudo} apt-get install -y -qq openjdk-6-jdk" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="wget -q http://www.alliedquotes.com/mirrors/apache/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.tar.gz" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="tar xzf apache-tomcat-6.0.20.tar.gz" />
<sshexec host="${host}" username="${username}" password="${password}" trust="true"
command="${sudo} mv apache-tomcat-6.0.20 /usr/local/tomcat" />
</target>
</project>

View File

@ -20,10 +20,14 @@ package org.jclouds.tools.ant.logging;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import org.apache.tools.ant.Project;
import org.jclouds.logging.BaseLogger;
import org.jclouds.logging.Logger;
import com.google.common.collect.Sets;
/**
* {@link org.apache.tools.ant.Project} implementation of {@link Logger}.
*
@ -33,22 +37,26 @@ import org.jclouds.logging.Logger;
public class AntLogger extends BaseLogger {
private final Project project;
private final String category;
private boolean alwaysLog;
public static class AntLoggerFactory implements LoggerFactory {
private final Project project;
private final Set<String> upgrades;
public AntLoggerFactory(Project project) {
public AntLoggerFactory(Project project, String... upgrades) {
this.project = checkNotNull(project, "project");
this.upgrades = Sets.newHashSet(upgrades);
}
public Logger getLogger(String category) {
return new AntLogger(project, category);
return new AntLogger(project, category, upgrades.contains(category));
}
}
public AntLogger(Project project, String category) {
public AntLogger(Project project, String category, boolean alwaysLog) {
this.project = checkNotNull(project, "project");
this.category = category;
this.alwaysLog = alwaysLog;
}
@Override
@ -61,7 +69,7 @@ public class AntLogger extends BaseLogger {
@Override
protected void logDebug(String message) {
project.log(message, Project.MSG_DEBUG);
project.log(" " + message, alwaysLog ? Project.MSG_INFO : Project.MSG_DEBUG);
}
public boolean isDebugEnabled() {
@ -70,7 +78,7 @@ public class AntLogger extends BaseLogger {
@Override
protected void logInfo(String message) {
project.log(message);
project.log(" " + message);
}
public boolean isInfoEnabled() {
@ -79,12 +87,12 @@ public class AntLogger extends BaseLogger {
@Override
protected void logWarn(String message) {
project.log(message, Project.MSG_WARN);
project.log(" " + message, Project.MSG_WARN);
}
@Override
protected void logWarn(String message, Throwable e) {
project.log(message, e, Project.MSG_WARN);
project.log(" " + message, e, Project.MSG_WARN);
}
public boolean isWarnEnabled() {
@ -93,12 +101,12 @@ public class AntLogger extends BaseLogger {
@Override
protected void logError(String message) {
project.log(message, Project.MSG_ERR);
project.log(" " + message, Project.MSG_ERR);
}
@Override
protected void logError(String message, Throwable e) {
project.log(message, e, Project.MSG_ERR);
project.log(" " + message, e, Project.MSG_ERR);
}
public boolean isErrorEnabled() {

View File

@ -34,13 +34,15 @@ import org.jclouds.tools.ant.logging.AntLogger;
public class AntLoggingModule extends LoggingModule {
private final Project project;
private final String[] upgrades;
public AntLoggingModule(Project project) {
public AntLoggingModule(Project project, String ... upgrades) {
this.project = project;
this.upgrades = upgrades;
}
@Override
public LoggerFactory createLoggerFactory() {
return new AntLogger.AntLoggerFactory(checkNotNull(project, "project"));
return new AntLogger.AntLoggerFactory(checkNotNull(project, "project"), upgrades);
}
}

View File

@ -16,11 +16,13 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.tools.ant;
package org.jclouds.tools.ant.taskdefs.compute;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.Map;
import java.util.Properties;
import java.util.SortedSet;
@ -35,12 +37,14 @@ import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Profile;
import org.jclouds.compute.domain.ServerIdentity;
import org.jclouds.compute.domain.ServerMetadata;
import org.jclouds.compute.reference.ComputeConstants;
import org.jclouds.http.HttpUtils;
import org.jclouds.tools.ant.logging.config.AntLoggingModule;
import com.google.common.base.CaseFormat;
import com.google.common.base.Function;
import com.google.common.collect.MapMaker;
import com.google.common.io.Files;
import com.google.common.io.Resources;
import com.google.inject.Module;
import com.google.inject.Provider;
@ -59,7 +63,7 @@ public class ComputeTask extends Task {
@Override
public Module[] get() {
return new Module[] { new AntLoggingModule(project) };
return new Module[] { new AntLoggingModule(project, ComputeConstants.COMPUTE_LOGGER) };
}
};
@ -167,6 +171,26 @@ public class ComputeTask extends Task {
createdServer.getCredentials().account, createdServer.getCredentials().key,
createdServer.getPublicAddresses().first().getHostAddress(), createdServer
.getLoginPort()));
if (serverElement.getIdproperty() != null)
getProject().setProperty(serverElement.getIdproperty(), createdServer.getId());
if (serverElement.getHostproperty() != null)
getProject().setProperty(serverElement.getHostproperty(),
createdServer.getPublicAddresses().first().getHostAddress());
if (serverElement.getKeyfile() != null
&& createdServer.getCredentials().key.startsWith("-----BEGIN RSA PRIVATE KEY-----"))
try {
Files.write(createdServer.getCredentials().key, new File(serverElement.getKeyfile()),
Charset.defaultCharset());
} catch (IOException e) {
throw new BuildException(e);
}
if (serverElement.getPasswordproperty() != null
&& !createdServer.getCredentials().key.startsWith("-----BEGIN RSA PRIVATE KEY-----"))
getProject().setProperty(serverElement.getPasswordproperty(),
createdServer.getCredentials().key);
if (serverElement.getUsernameproperty() != null)
getProject().setProperty(serverElement.getUsernameproperty(),
createdServer.getCredentials().account);
}
private void destroy(ComputeService computeService) {

View File

@ -0,0 +1,117 @@
/**
*
* Copyright (C) 2009 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.tools.ant.taskdefs.compute;
/**
* @author Ivan Meredith
*/
public class ServerElement {
private String name;
private String profile;
private String image;
private String passwordproperty;
private String keyfi1le;
private String hostproperty;
private String idproperty;
private String usernameproperty;
String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
String getProfile() {
return profile;
}
public void setProfile(String profile) {
this.profile = profile;
}
String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
String getUsernameproperty() {
return usernameproperty;
}
/**
* The name of a property in which the username of the login user should be stored.
*
*/
public void setUsernameproperty(String usernameproperty) {
this.usernameproperty = usernameproperty;
}
String getPasswordproperty() {
return passwordproperty;
}
/**
* The name of a property in which the password of the login user should be stored.
*
*/
public void setPasswordproperty(String passwordproperty) {
this.passwordproperty = passwordproperty;
}
/**
* The name of a property in which the hostname of the machine should be stored
*
*/
public void setHostproperty(String hostproperty) {
this.hostproperty = hostproperty;
}
String getHostproperty() {
return hostproperty;
}
/**
* The name of a property in which the id of the machine should be stored
*
*/
public void setIdproperty(String idproperty) {
this.idproperty = idproperty;
}
String getIdproperty() {
return idproperty;
}
/**
* The name of a file under which to store the DSA key of the user (if supported)
*/
public void setKeyfile(String keyfile) {
this.keyfi1le = keyfile;
}
String getKeyfile() {
return keyfi1le;
}
}

View File

@ -26,6 +26,7 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.security.SecureRandom;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -37,6 +38,8 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Java;
import org.apache.tools.ant.taskdefs.Replace;
import org.apache.tools.ant.taskdefs.Replace.Replacefilter;
import org.apache.tools.ant.taskdefs.optional.ssh.SSHUserInfo;
import org.apache.tools.ant.taskdefs.optional.ssh.Scp;
import org.apache.tools.ant.types.CommandlineJava;
@ -49,8 +52,11 @@ import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.scriptbuilder.domain.ShellToken;
import org.jclouds.scriptbuilder.domain.Statement;
import org.jclouds.scriptbuilder.domain.StatementList;
import org.jclouds.tools.ant.util.SSHExecute;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@ -67,8 +73,9 @@ public class SSHJava extends Java {
private final Scp scp;
private final SSHUserInfo userInfo;
private File localDirectory;
private File remotebase;
private File remotedir;
File remotebase;
@VisibleForTesting
File remotedir;
@VisibleForTesting
Environment env = new Environment();
@ -77,21 +84,23 @@ public class SSHJava extends Java {
private String errorProperty;
private File outputFile;
private String outputProperty;
private String id = "sshjava" + new SecureRandom().nextLong();
String id = "sshjava" + new SecureRandom().nextLong();
private boolean append;
@VisibleForTesting
final Map<String, String> shiftMap = Maps.newHashMap();
final LinkedHashMap<String, String> shiftMap = Maps.newLinkedHashMap();
@VisibleForTesting
final Map<String, String> replace = Maps.newHashMap();
final LinkedHashMap<String, String> replace = Maps.newLinkedHashMap();
public SSHJava() {
super();
setFork(true);
exec = new SSHExecute();
exec.setProject(getProject());
scp = new Scp();
userInfo = new SSHUserInfo();
scp.init();
setFork(true);
setTrust(true);
}
public SSHJava(Task owner) {
@ -120,15 +129,6 @@ public class SSHJava extends Java {
if (remotedir == null)
remotedir = new File(remotebase, id);
replace.put(localDirectory.getAbsolutePath(), remotedir.getAbsolutePath());
if (osFamily == OsFamily.UNIX) {
log("removing old contents: " + remotedir.getAbsolutePath(), Project.MSG_VERBOSE);
sshexec(exec("rm -rf " + remotedir.getAbsolutePath()).render(osFamily));
} else {
// TODO need recursive remove on windows
}
// must copy the files over first as we are changing the system properties based on this.
String command = createInitScript(osFamily, id, remotedir.getAbsolutePath(), env,
getCommandLine());
@ -141,15 +141,36 @@ public class SSHJava extends Java {
throw new BuildException(e);
}
replaceAllTokensIn(localDirectory);
FileSet cwd = new FileSet();
cwd.setDir(localDirectory);
if (osFamily == OsFamily.UNIX) {
log("removing old contents: " + remotedir.getAbsolutePath(), Project.MSG_VERBOSE);
sshexec(exec("rm -rf " + remotedir.getAbsolutePath()).render(osFamily));
} else {
// TODO need recursive remove on windows
}
mkdirAndCopyTo(remotedir.getAbsolutePath(), ImmutableList.of(cwd));
for (Entry<String, String> entry : shiftMap.entrySet()) {
FileSet set = new FileSet();
set.setDir(new File(entry.getKey()));
mkdirAndCopyTo(remotebase.getAbsolutePath() + ShellToken.FS.to(osFamily)
+ entry.getValue(), ImmutableList.of(set));
File source = new File(entry.getKey());
if (source.isDirectory()) {
set.setDir(new File(entry.getKey()));
mkdirAndCopyTo(remotebase.getAbsolutePath() + ShellToken.FS.to(osFamily)
+ entry.getValue(), ImmutableList.of(set));
} else {
String destination = remotebase.getAbsolutePath() + ShellToken.FS.to(osFamily)
+ new File(entry.getValue()).getParent();
sshexec(exec("{md} " + destination).render(osFamily));
scp.init();
String scpDestination = getScpDir(destination);
log("staging: " + scpDestination, Project.MSG_VERBOSE);
scp.setFile(source.getAbsolutePath());
scp.setTodir(scpDestination);
scp.execute();
}
}
if (getCommandLine().getClasspath() != null) {
@ -177,6 +198,33 @@ public class SSHJava extends Java {
}
}
void replaceAllTokensIn(File directory) {
Replace replacer = new Replace();
replacer.setProject(getProject());
replacer.setDir(directory);
Map<String, String> map = Maps.newLinkedHashMap();
// this has to go first
map.put(directory.getAbsolutePath(), remotedir.getAbsolutePath());
map.putAll(Maps.transformValues(shiftMap, new Function<String, String>() {
@Override
public String apply(String in) {
return remotebase + ShellToken.FS.to(osFamily) + in;
}
}));
map.putAll(replace);
for (Entry<String, String> entry : map.entrySet()) {
Replacefilter filter = replacer.createReplacefilter();
filter.setToken(entry.getKey());
filter.setValue(entry.getValue());
}
replacer.execute();
}
private int sshexec(String command) {
try {
return exec.execute(command);
@ -291,17 +339,15 @@ public class SSHJava extends Java {
String createInitScript(OsFamily osFamily, String id, String basedir, Environment env,
CommandlineJava commandLine) {
Map<String, String> envVariables = Maps.newHashMap();
String[] environment = env.getVariables();
if (environment != null) {
for (int i = 0; i < environment.length; i++) {
log("Setting environment variable: " + environment[i], Project.MSG_DEBUG);
String[] keyValue = environment[i].split("=");
envVariables.put(keyValue[0], reprefix(keyValue[1]));
envVariables.put(keyValue[0], keyValue[1]);
}
}
StringBuilder commandBuilder = new StringBuilder(commandLine.getVmCommand().getExecutable());
if (commandLine.getBootclasspath() != null) {
commandBuilder.append(" -Xbootclasspath:bootclasspath");
@ -311,7 +357,8 @@ public class SSHJava extends Java {
if (commandLine.getVmCommand().getArguments() != null
&& commandLine.getVmCommand().getArguments().length > 0) {
reprefixArgs(commandLine.getVmCommand().getArguments(), commandBuilder);
commandBuilder.append(" ").append(
Joiner.on(' ').join(commandLine.getVmCommand().getArguments()));
}
commandBuilder.append(" -cp classpath");
resetPathToUnderPrefixIfExistsAndIsFileIfNotExistsAddAsIs(commandLine.getClasspath(),
@ -320,14 +367,16 @@ public class SSHJava extends Java {
if (commandLine.getSystemProperties() != null
&& commandLine.getSystemProperties().getVariables() != null
&& commandLine.getSystemProperties().getVariables().length > 0) {
reprefixValues(commandLine.getSystemProperties().getVariables(), commandBuilder);
commandBuilder.append(" ").append(
Joiner.on(' ').join(commandLine.getSystemProperties().getVariables()));
}
commandBuilder.append(" ").append(commandLine.getClassname());
if (commandLine.getJavaCommand().getArguments() != null
&& commandLine.getJavaCommand().getArguments().length > 0) {
reprefixArgs(commandLine.getJavaCommand().getArguments(), commandBuilder);
commandBuilder.append(" ").append(
Joiner.on(' ').join(commandLine.getJavaCommand().getArguments()));
}
InitBuilder testInitBuilder = new InitBuilder(id, basedir, basedir, envVariables,
@ -335,25 +384,6 @@ public class SSHJava extends Java {
return testInitBuilder.build(osFamily);
}
private void reprefixValues(String[] variables, StringBuilder commandBuilder) {
for (String variable : variables) {
commandBuilder.append(" ");
String[] keyValue = variable.split("=");
if (keyValue.length == 2) {
String newVariable = keyValue[0] + '=' + reprefix(keyValue[1]);
commandBuilder.append(newVariable);
} else {
commandBuilder.append(variable);
}
}
}
private void reprefixArgs(String[] args, StringBuilder commandBuilder) {
for (String arg : args) {
commandBuilder.append(" ").append(reprefix(arg));
}
}
@Override
public void addEnv(Environment.Variable var) {
env.addVariable(var);
@ -544,6 +574,16 @@ public class SSHJava extends Java {
replace.put(sysp.getKey().replaceFirst("sshjava.replace.", ""), sysp.getValue());
} else if (sysp.getKey().equals("sshjava.id")) {
setId(sysp.getValue());
} else if (sysp.getKey().equals("sshjava.host")) {
setHost(sysp.getValue());
} else if (sysp.getKey().equals("sshjava.port") && !sysp.getValue().equals("")) {
setPort(Integer.parseInt(sysp.getValue()));
} else if (sysp.getKey().equals("sshjava.username")) {
setUsername(sysp.getValue());
} else if (sysp.getKey().equals("sshjava.password") && !sysp.getValue().equals("")) {
setPassword(sysp.getValue());
} else if (sysp.getKey().equals("sshjava.keyfile") && !sysp.getValue().equals("")) {
setKeyfile(sysp.getValue());
} else if (sysp.getKey().equals("sshjava.remotebase")) {
setRemotebase(new File(sysp.getValue()));
} else {

View File

@ -16,7 +16,7 @@
* limitations under the License.
* ====================================================================
*/
package org.jclouds.tools.ant.taskdefs.sshjava;
package org.jclouds.tools.ant.util;
import java.io.IOException;
import java.util.concurrent.TimeoutException;

View File

@ -40,6 +40,7 @@ import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.io.CharStreams;
import com.google.common.io.Files;
import com.google.common.io.Resources;
/**
@ -59,9 +60,14 @@ public class SSHJavaTest {
+ "/apache-maven-2.2.1", "maven"));
assertEquals(task.replace, ImmutableMap.<String, String> of(System.getProperty("user.name"),
"root"));
assertEquals(task.createInitScript(OsFamily.UNIX, "1", "remotedir", task.env, task
.getCommandLine()), CharStreams.toString(Resources.newReaderSupplier(Resources
.getResource("init.sh"), Charsets.UTF_8)));
new File("build").mkdirs();
Files.write(task.createInitScript(OsFamily.UNIX, "1", "remotedir", task.env, task
.getCommandLine()), new File("build", "init.sh"), Charsets.UTF_8);
task.remotedir=new File(task.remotebase, task.id);
task.replaceAllTokensIn(new File("build"));
assertEquals(Files.toString(new File("build", "init.sh"), Charsets.UTF_8), CharStreams
.toString(Resources.newReaderSupplier(Resources.getResource("init.sh"),
Charsets.UTF_8)));
}
private Java populateTask(Java task) {

View File

@ -32,7 +32,6 @@
<packaging>pom</packaging>
<name>jclouds tools project</name>
<modules>
<module>ant-plugin</module>
<module>getpath</module>
<module>antcontrib</module>
<module>vfs</module>

View File

@ -57,7 +57,7 @@ public class VCloudComputeClient {
private Map<Image, String> imageCatalogIdMap = ImmutableMap.<Image, String> builder().put(
Image.CENTOS_53, "3").put(Image.RHEL_53, "8").put(Image.UBUNTU_90, "10").put(
Image.UBUNTU_JEOS, "11").build();
Image.UBUNTU_JEOS_90, "11").build();
public Map<String, String> start(String name, Image image, int minCores, int minMegs,
long diskSize, Map<String, String> properties) {

View File

@ -77,7 +77,7 @@ public class VCloudComputeClientLiveTest {
Image.RHEL_53,
new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
Image.UBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).put(
Image.UBUNTU_JEOS, new Expectation(4194304, "Ubuntu Linux (32-bit)")).build();
Image.UBUNTU_JEOS_90, new Expectation(4194304, "Ubuntu Linux (32-bit)")).build();
private Predicate<InetAddress> addressTester;

View File

@ -59,7 +59,7 @@ public class HostingDotComVCloudComputeClient {
private Map<Image, String> imageCatalogIdMap = ImmutableMap.<Image, String> builder().put(
Image.CENTOS_53, "3").put(Image.RHEL_53, "8").put(Image.UBUNTU_90, "10").put(
Image.UBUNTU_JEOS, "11").build();
Image.UBUNTU_JEOS_90, "11").build();
public Map<String, String> start(String name, Image image, int minCores, int minMegs,
long diskSize, Map<String, String> properties) {

View File

@ -24,6 +24,7 @@ import java.util.SortedSet;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeService;
@ -36,6 +37,7 @@ import org.jclouds.compute.domain.ServerMetadata;
import org.jclouds.compute.domain.ServerState;
import org.jclouds.compute.domain.internal.CreateServerResponseImpl;
import org.jclouds.compute.domain.internal.ServerMetadataImpl;
import org.jclouds.compute.reference.ComputeConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudMediaType;
@ -56,6 +58,7 @@ import com.google.inject.internal.ImmutableSet;
@Singleton
public class HostingDotComVCloudComputeService implements ComputeService {
@Resource
@Named(ComputeConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final HostingDotComVCloudComputeClient computeClient;
private final HostingDotComVCloudClient hostingClient;

View File

@ -79,7 +79,7 @@ public class HostingDotComVCloudComputeClientLiveTest {
Image.RHEL_53,
new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
Image.UBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).put(
Image.UBUNTU_JEOS, new Expectation(4194304, "Ubuntu Linux (32-bit)")).build();
Image.UBUNTU_JEOS_90, new Expectation(4194304, "Ubuntu Linux (32-bit)")).build();
private Predicate<InetAddress> addressTester;

View File

@ -29,8 +29,10 @@ import java.util.SortedSet;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.reference.ComputeConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VAppStatus;
@ -53,7 +55,8 @@ import com.google.common.collect.Sets;
*/
public class TerremarkVCloudComputeClient {
@Resource
protected Logger logger = Logger.NULL;
@Named(ComputeConstants.COMPUTE_LOGGER)
Logger logger = Logger.NULL;
private final Predicate<String> taskTester;
private final TerremarkVCloudClient tmClient;
@ -67,7 +70,7 @@ public class TerremarkVCloudComputeClient {
private Map<Image, String> imageCatalogIdMap = ImmutableMap.<Image, String> builder().put(
Image.CENTOS_53, "6").put(Image.RHEL_53, "8").put(Image.UBUNTU_90, "10").put(
Image.UBUNTU_JEOS, "11").build();
Image.UBUNTU_JEOS_90, "11").build();
public String start(String name, Image image, int minCores, int minMegs,
Map<String, String> properties) {

View File

@ -25,6 +25,7 @@ import java.util.SortedSet;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.compute.ComputeService;
@ -37,6 +38,7 @@ import org.jclouds.compute.domain.ServerMetadata;
import org.jclouds.compute.domain.ServerState;
import org.jclouds.compute.domain.internal.CreateServerResponseImpl;
import org.jclouds.compute.domain.internal.ServerMetadataImpl;
import org.jclouds.compute.reference.ComputeConstants;
import org.jclouds.domain.Credentials;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudMediaType;
@ -58,6 +60,7 @@ import com.google.inject.internal.ImmutableSet;
@Singleton
public class TerremarkVCloudComputeService implements ComputeService {
@Resource
@Named(ComputeConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
private final TerremarkVCloudComputeClient computeClient;
private final TerremarkVCloudClient tmClient;
@ -80,7 +83,8 @@ public class TerremarkVCloudComputeService implements ComputeService {
public CreateServerResponse createServer(String name, Profile profile, Image image) {
String id = computeClient.start(name, image, 1, 512, ImmutableMap.<String, String> of());
TerremarkVApp vApp = tmClient.getVApp(id);
InetAddress publicIp = computeClient.createPublicAddressMappedToPorts(vApp, 22);
InetAddress publicIp = computeClient
.createPublicAddressMappedToPorts(vApp, 22, 80, 8080, 443);
return new CreateServerResponseImpl(vApp.getId(), vApp.getName(), vAppStatusToServerState
.get(vApp.getStatus()), ImmutableSet.<InetAddress> of(publicIp), vApp
.getNetworkToAddresses().values(), 22, LoginType.SSH, new Credentials("vcloud",

View File

@ -77,7 +77,7 @@ public class TerremarkVCloudComputeClientLiveTest {
.put(Image.CENTOS_53, new Expectation(10485760, "Red Hat Enterprise Linux 5 (64-bit)"))
.put(Image.RHEL_53, new Expectation(10485760, "Red Hat Enterprise Linux 5 (64-bit)"))
.put(Image.UBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).put(
Image.UBUNTU_JEOS, new Expectation(4194304, "Ubuntu Linux (32-bit)")).build();
Image.UBUNTU_JEOS_90, new Expectation(4194304, "Ubuntu Linux (32-bit)")).build();
private Predicate<InetAddress> addressTester;