mirror of https://github.com/apache/jclouds.git
Issue 838: convert jboss tests and java tests to use InstallJDK
This commit is contained in:
parent
384b8261ca
commit
73cc4a0837
|
@ -31,10 +31,8 @@ import static com.google.common.collect.Sets.newTreeSet;
|
|||
import static java.lang.String.format;
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
import static java.util.logging.Logger.getAnonymousLogger;
|
||||
import static org.jclouds.compute.ComputeTestUtils.buildScript;
|
||||
import static org.jclouds.compute.RunScriptData.JBOSS7_URL;
|
||||
import static org.jclouds.compute.RunScriptData.JBOSS_HOME;
|
||||
import static org.jclouds.compute.RunScriptData.JDK7_URL;
|
||||
import static org.jclouds.compute.RunScriptData.installAdminUserJBossAndOpenPorts;
|
||||
import static org.jclouds.compute.RunScriptData.startJBoss;
|
||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.nameTask;
|
||||
|
@ -78,7 +76,6 @@ import org.jclouds.compute.domain.Image;
|
|||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.NodeState;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.domain.OsFamily;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.domain.TemplateBuilder;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
|
@ -93,6 +90,7 @@ import org.jclouds.predicates.SocketOpen;
|
|||
import org.jclouds.rest.AuthorizationException;
|
||||
import org.jclouds.scriptbuilder.domain.SaveHttpResponseTo;
|
||||
import org.jclouds.scriptbuilder.domain.Statements;
|
||||
import org.jclouds.scriptbuilder.statements.java.InstallJDK;
|
||||
import org.jclouds.scriptbuilder.statements.login.AdminAccess;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.ssh.SshException;
|
||||
|
@ -210,8 +208,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv
|
|||
|
||||
@Test(enabled = true, expectedExceptions = NoSuchElementException.class)
|
||||
public void testCorrectExceptionRunningNodesNotFound() throws Exception {
|
||||
client.runScriptOnNodesMatching(runningInGroup("zebras-are-awesome"), buildScript(new OperatingSystem.Builder()
|
||||
.family(OsFamily.UBUNTU).description("ffoo").build()));
|
||||
client.runScriptOnNodesMatching(runningInGroup("zebras-are-awesome"), InstallJDK.fromURL());
|
||||
}
|
||||
|
||||
// since surefire and eclipse don't otherwise guarantee the order, we are
|
||||
|
@ -373,7 +370,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv
|
|||
|
||||
protected static Template addRunScriptToTemplate(Template template) {
|
||||
template.getOptions().runScript(
|
||||
Statements.newStatementList(AdminAccess.standard(), buildScript(template.getImage().getOperatingSystem())));
|
||||
Statements.newStatementList(AdminAccess.standard(), InstallJDK.fromURL()));
|
||||
return template;
|
||||
}
|
||||
|
||||
|
@ -437,7 +434,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv
|
|||
|
||||
protected Map<? extends NodeMetadata, ExecResponse> runScriptWithCreds(final String group, OperatingSystem os,
|
||||
LoginCredentials creds) throws RunScriptOnNodesException {
|
||||
return client.runScriptOnNodesMatching(runningInGroup(group), buildScript(os), overrideLoginCredentials(creds)
|
||||
return client.runScriptOnNodesMatching(runningInGroup(group), InstallJDK.fromURL(), overrideLoginCredentials(creds)
|
||||
.nameTask("runScriptWithCreds"));
|
||||
}
|
||||
|
||||
|
@ -679,7 +676,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv
|
|||
format("ls %s/bundles/org/jboss/as/osgi/configadmin/main|sed -e 's/.*-//g' -e 's/.jar//g'",
|
||||
JBOSS_HOME)), configureSeconds));
|
||||
|
||||
for (Entry<String, URI> download : ImmutableMap.<String, URI> of("jboss7", JBOSS7_URL, "jdk7", JDK7_URL)
|
||||
for (Entry<String, URI> download : ImmutableMap.<String, URI> of("jboss7", JBOSS7_URL, "jdk7", InstallJDK.FromURL.JDK7_URL)
|
||||
.entrySet()) {
|
||||
// note we cannot use nslookup until we've configured the system, as
|
||||
// it may have not been present checking the address of the download
|
||||
|
|
|
@ -31,9 +31,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.rest.HttpClient;
|
||||
import org.jclouds.scriptbuilder.domain.Statement;
|
||||
import org.jclouds.util.Preconditions2;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
@ -46,9 +44,6 @@ import com.google.common.io.Files;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class ComputeTestUtils {
|
||||
public static Statement buildScript(OperatingSystem os) {
|
||||
return RunScriptData.installJavaAndCurl(os);
|
||||
}
|
||||
|
||||
public static Map<String, String> setupKeyPair() throws FileNotFoundException, IOException {
|
||||
String secretKeyFile;
|
||||
|
|
|
@ -23,23 +23,21 @@ import static org.jclouds.compute.util.ComputeServiceUtils.extractTargzIntoDirec
|
|||
import static org.jclouds.scriptbuilder.domain.Statements.appendFile;
|
||||
import static org.jclouds.scriptbuilder.domain.Statements.exec;
|
||||
import static org.jclouds.scriptbuilder.domain.Statements.interpret;
|
||||
import static org.jclouds.scriptbuilder.domain.Statements.newStatementList;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.compute.domain.OperatingSystem;
|
||||
import org.jclouds.compute.predicates.OperatingSystemPredicates;
|
||||
import org.jclouds.scriptbuilder.InitBuilder;
|
||||
import org.jclouds.scriptbuilder.domain.Statement;
|
||||
import org.jclouds.scriptbuilder.domain.StatementList;
|
||||
import org.jclouds.scriptbuilder.statements.java.InstallJDK;
|
||||
import org.jclouds.scriptbuilder.statements.login.AdminAccess;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -47,24 +45,11 @@ import com.google.common.collect.ImmutableSet;
|
|||
*/
|
||||
public class RunScriptData {
|
||||
|
||||
public static final URI JDK7_URL = URI.create(System.getProperty("test.jdk7-url",
|
||||
"http://download.oracle.com/otn-pub/java/jdk/7u2-b13/jdk-7u2-linux-x64.tar.gz"));
|
||||
public static final URI JBOSS7_URL = URI.create(System.getProperty("test.jboss7-url",//
|
||||
"http://download.jboss.org/jbossas/7.0/jboss-as-7.0.2.Final/jboss-as-web-7.0.2.Final.tar.gz"));
|
||||
|
||||
public static String JBOSS_HOME = "/usr/local/jboss";
|
||||
|
||||
public static Statement installJavaAndCurl(OperatingSystem os) {
|
||||
if (os == null || OperatingSystemPredicates.supportsApt().apply(os))
|
||||
return APT_RUN_SCRIPT;
|
||||
else if (OperatingSystemPredicates.supportsYum().apply(os))
|
||||
return YUM_RUN_SCRIPT;
|
||||
else if (OperatingSystemPredicates.supportsZypper().apply(os))
|
||||
return ZYPPER_RUN_SCRIPT;
|
||||
else
|
||||
throw new IllegalArgumentException("don't know how to handle" + os.toString());
|
||||
}
|
||||
|
||||
public static Statement authorizePortsInIpTables(int... ports) {
|
||||
Builder<Statement> builder = ImmutableList.<Statement> builder();
|
||||
for (int port : ports)
|
||||
|
@ -76,7 +61,7 @@ public class RunScriptData {
|
|||
public static StatementList installAdminUserJBossAndOpenPorts(OperatingSystem os) throws IOException {
|
||||
return new StatementList(//
|
||||
AdminAccess.builder().adminUsername("web").build(),//
|
||||
installJavaAndCurl(os),//
|
||||
InstallJDK.fromURL(),//
|
||||
authorizePortsInIpTables(22, 8080),//
|
||||
extractTargzIntoDirectory(JBOSS7_URL, "/usr/local"),//
|
||||
exec("{md} " + JBOSS_HOME), exec("mv /usr/local/jboss-*/* " + JBOSS_HOME),//
|
||||
|
@ -109,67 +94,10 @@ public class RunScriptData {
|
|||
.toString())));
|
||||
}
|
||||
|
||||
public static Statement normalizeHostAndDNSConfig() {
|
||||
return newStatementList(//
|
||||
addHostnameToEtcHostsIfMissing(),//
|
||||
addDnsToResolverIfMissing());
|
||||
}
|
||||
|
||||
public static Statement addHostnameToEtcHostsIfMissing() {
|
||||
return exec("grep `hostname` /etc/hosts >/dev/null || awk -v hostname=`hostname` 'END { print $1\" \"hostname }' /proc/net/arp >> /etc/hosts");
|
||||
}
|
||||
|
||||
public static Statement addDnsToResolverIfMissing() {
|
||||
return exec("nslookup yahoo.com >/dev/null || echo nameserver 208.67.222.222 >> /etc/resolv.conf");
|
||||
}
|
||||
|
||||
// TODO make this a cli option
|
||||
private static Statement changeStandaloneConfigToListenOnAllIPAddresses() {
|
||||
return exec(format(
|
||||
"(cd %s/standalone/configuration && sed 's~inet-address value=.*/~any-address/~g' standalone.xml > standalone.xml.new && mv standalone.xml.new standalone.xml)",
|
||||
JBOSS_HOME));
|
||||
}
|
||||
|
||||
public static final ImmutableSet<String> exportJavaHomeAndAddToPath = ImmutableSet.of(
|
||||
"export JAVA_HOME=/usr/local/jdk", "export PATH=$JAVA_HOME/bin:$PATH");
|
||||
|
||||
public static final Statement JDK7_INSTALL_TGZ = newStatementList(//
|
||||
exec("{md} /usr/local/jdk"), extractTargzIntoDirectory(JDK7_URL, "/usr/local"),//
|
||||
exec("mv /usr/local/jdk1.7*/* /usr/local/jdk/"),//
|
||||
exec("test -n \"$SUDO_USER\" && "), appendFile("/home/$SUDO_USER/.bashrc", exportJavaHomeAndAddToPath),//
|
||||
appendFile("/etc/bashrc", exportJavaHomeAndAddToPath),//
|
||||
appendFile("$HOME/.bashrc", exportJavaHomeAndAddToPath),//
|
||||
appendFile("/etc/skel/.bashrc", exportJavaHomeAndAddToPath),//
|
||||
// TODO:
|
||||
// eventhough we are setting the above, sometimes images (ex.
|
||||
// cloudservers ubuntu) kick out of .bashrc (ex. [ -z "$PS1" ] &&
|
||||
// return), for this reason, we should also explicitly link.
|
||||
// A better way would be to update using alternatives or the like
|
||||
exec("ln -fs /usr/local/jdk/bin/java /usr/bin/java"));
|
||||
|
||||
public static String aptInstall = "apt-get install -f -y -qq --force-yes";
|
||||
|
||||
public static String aptInstallLazyUpgrade(String packageName) {
|
||||
return aptInstall + " " + packageName + "|| (" + "apt-get update -qq&&" + "apt-get upgrade -y -qq" + ")&&"
|
||||
+ aptInstall + " " + packageName;
|
||||
}
|
||||
|
||||
public static final Statement APT_RUN_SCRIPT = newStatementList(//
|
||||
exec("which nslookup >&- 2>&-|| " + aptInstallLazyUpgrade("dnsutils")),//
|
||||
normalizeHostAndDNSConfig(),//
|
||||
exec("which curl >&- 2>&-|| " + aptInstallLazyUpgrade("curl")),//
|
||||
JDK7_INSTALL_TGZ);
|
||||
|
||||
public static String yumInstall = "yum --nogpgcheck -y install";
|
||||
|
||||
public static final Statement YUM_RUN_SCRIPT = newStatementList(//
|
||||
exec("which nslookup >&- 2>&-|| " + yumInstall + " bind-utils"),//
|
||||
normalizeHostAndDNSConfig(),//
|
||||
exec("which curl >&- 2>&-|| " + yumInstall + " curl"),//
|
||||
JDK7_INSTALL_TGZ);
|
||||
|
||||
public static final Statement ZYPPER_RUN_SCRIPT = newStatementList(//
|
||||
normalizeHostAndDNSConfig(),//
|
||||
exec("which curl >&- 2>&-|| zypper install curl"),//
|
||||
JDK7_INSTALL_TGZ);
|
||||
}
|
||||
|
|
|
@ -73,6 +73,60 @@ export INSTANCE_NAME='bootstrap'
|
|||
export INSTANCE_NAME='$INSTANCE_NAME'
|
||||
export INSTANCE_HOME='$INSTANCE_HOME'
|
||||
export LOG_DIR='$LOG_DIR'
|
||||
function abort {
|
||||
echo "aborting: \$@" 1>&2
|
||||
exit 1
|
||||
}
|
||||
alias apt-get-install="apt-get install -f -y -qq --force-yes"
|
||||
alias apt-get-upgrade="(apt-get update -qq&&apt-get upgrade -y -qq)"
|
||||
|
||||
function ensure_cmd_or_install_package_apt(){
|
||||
local cmd=\$1
|
||||
local pkg=\$2
|
||||
|
||||
hash \$cmd 2>/dev/null || apt-get-install \$pkg || ( apt-get-upgrade && apt-get-install \$pkg )
|
||||
}
|
||||
|
||||
function ensure_cmd_or_install_package_yum(){
|
||||
local cmd=\$1
|
||||
local pkg=\$2
|
||||
hash \$cmd 2>/dev/null || yum --nogpgcheck -y ensure \$pkg
|
||||
}
|
||||
|
||||
function ensure_netutils_apt() {
|
||||
ensure_cmd_or_install_package_apt nslookup dnsutils
|
||||
ensure_cmd_or_install_package_apt curl curl
|
||||
}
|
||||
|
||||
function ensure_netutils_yum() {
|
||||
ensure_cmd_or_install_package_yum nslookup bind-utils
|
||||
ensure_cmd_or_install_package_yum curl curl
|
||||
}
|
||||
|
||||
# most network services require that the hostname is in
|
||||
# the /etc/hosts file, or they won't operate
|
||||
function ensure_hostname_in_hosts() {
|
||||
egrep -q `hostname` /etc/hosts || awk -v hostname=`hostname` 'END { print \$1" "hostname }' /proc/net/arp >> /etc/hosts
|
||||
}
|
||||
|
||||
# download locations for many services are at public dns
|
||||
function ensure_can_resolve_public_dns() {
|
||||
nslookup yahoo.com > /dev/null || echo nameserver 208.67.222.222 >> /etc/resolv.conf
|
||||
}
|
||||
|
||||
function setupPublicCurl() {
|
||||
ensure_hostname_in_hosts
|
||||
if hash apt-get 2>/dev/null; then
|
||||
ensure_netutils_apt
|
||||
elif hash yum 2>/dev/null; then
|
||||
ensure_netutils_yum
|
||||
else
|
||||
abort "we only support apt-get and yum right now... please contribute!"
|
||||
return 1
|
||||
fi
|
||||
ensure_can_resolve_public_dns
|
||||
return 0
|
||||
}
|
||||
END_OF_SCRIPT
|
||||
|
||||
# add desired commands from the user
|
||||
|
@ -99,13 +153,9 @@ PermitRootLogin no
|
|||
/etc/init.d/sshd reload||/etc/init.d/ssh reload
|
||||
awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(randompassword)' 'BEGIN { FS=OFS=":" } $0 ~ user { $2 = password } 1' /etc/shadow >/etc/shadow.${SUDO_USER:=${USER}}
|
||||
test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow
|
||||
which nslookup >&- 2>&-|| apt-get install -f -y -qq --force-yes dnsutils|| (apt-get update -qq&&apt-get upgrade -y -qq)&&apt-get install -f -y -qq --force-yes dnsutils
|
||||
grep `hostname` /etc/hosts >/dev/null || awk -v hostname=`hostname` 'END { print $1" "hostname }' /proc/net/arp >> /etc/hosts
|
||||
nslookup yahoo.com >/dev/null || echo nameserver 208.67.222.222 >> /etc/resolv.conf
|
||||
which curl >&- 2>&-|| apt-get install -f -y -qq --force-yes curl|| (apt-get update -qq&&apt-get upgrade -y -qq)&&apt-get install -f -y -qq --force-yes curl
|
||||
mkdir -p /usr/local/jdk
|
||||
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.oracle.com/otn-pub/java/jdk/7u2-b13/jdk-7u2-linux-x64.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
|
||||
mv /usr/local/jdk1.7*/* /usr/local/jdk/
|
||||
setupPublicCurl || return 1
|
||||
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
|
||||
mv /usr/local/jdk* /usr/local/jdk/
|
||||
test -n "$SUDO_USER" &&
|
||||
cat >> /home/$SUDO_USER/.bashrc <<'END_OF_FILE'
|
||||
export JAVA_HOME=/usr/local/jdk
|
||||
|
|
|
@ -73,6 +73,60 @@ export INSTANCE_NAME='configure-jboss'
|
|||
export INSTANCE_NAME='$INSTANCE_NAME'
|
||||
export INSTANCE_HOME='$INSTANCE_HOME'
|
||||
export LOG_DIR='$LOG_DIR'
|
||||
function abort {
|
||||
echo "aborting: \$@" 1>&2
|
||||
exit 1
|
||||
}
|
||||
alias apt-get-install="apt-get install -f -y -qq --force-yes"
|
||||
alias apt-get-upgrade="(apt-get update -qq&&apt-get upgrade -y -qq)"
|
||||
|
||||
function ensure_cmd_or_install_package_apt(){
|
||||
local cmd=\$1
|
||||
local pkg=\$2
|
||||
|
||||
hash \$cmd 2>/dev/null || apt-get-install \$pkg || ( apt-get-upgrade && apt-get-install \$pkg )
|
||||
}
|
||||
|
||||
function ensure_cmd_or_install_package_yum(){
|
||||
local cmd=\$1
|
||||
local pkg=\$2
|
||||
hash \$cmd 2>/dev/null || yum --nogpgcheck -y ensure \$pkg
|
||||
}
|
||||
|
||||
function ensure_netutils_apt() {
|
||||
ensure_cmd_or_install_package_apt nslookup dnsutils
|
||||
ensure_cmd_or_install_package_apt curl curl
|
||||
}
|
||||
|
||||
function ensure_netutils_yum() {
|
||||
ensure_cmd_or_install_package_yum nslookup bind-utils
|
||||
ensure_cmd_or_install_package_yum curl curl
|
||||
}
|
||||
|
||||
# most network services require that the hostname is in
|
||||
# the /etc/hosts file, or they won't operate
|
||||
function ensure_hostname_in_hosts() {
|
||||
egrep -q `hostname` /etc/hosts || awk -v hostname=`hostname` 'END { print \$1" "hostname }' /proc/net/arp >> /etc/hosts
|
||||
}
|
||||
|
||||
# download locations for many services are at public dns
|
||||
function ensure_can_resolve_public_dns() {
|
||||
nslookup yahoo.com > /dev/null || echo nameserver 208.67.222.222 >> /etc/resolv.conf
|
||||
}
|
||||
|
||||
function setupPublicCurl() {
|
||||
ensure_hostname_in_hosts
|
||||
if hash apt-get 2>/dev/null; then
|
||||
ensure_netutils_apt
|
||||
elif hash yum 2>/dev/null; then
|
||||
ensure_netutils_yum
|
||||
else
|
||||
abort "we only support apt-get and yum right now... please contribute!"
|
||||
return 1
|
||||
fi
|
||||
ensure_can_resolve_public_dns
|
||||
return 0
|
||||
}
|
||||
END_OF_SCRIPT
|
||||
|
||||
# add desired commands from the user
|
||||
|
@ -99,13 +153,9 @@ PermitRootLogin no
|
|||
/etc/init.d/sshd reload||/etc/init.d/ssh reload
|
||||
awk -v user=^${SUDO_USER:=${USER}}: -v password='crypt(randompassword)' 'BEGIN { FS=OFS=":" } $0 ~ user { $2 = password } 1' /etc/shadow >/etc/shadow.${SUDO_USER:=${USER}}
|
||||
test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow
|
||||
which nslookup >&- 2>&-|| apt-get install -f -y -qq --force-yes dnsutils|| (apt-get update -qq&&apt-get upgrade -y -qq)&&apt-get install -f -y -qq --force-yes dnsutils
|
||||
grep `hostname` /etc/hosts >/dev/null || awk -v hostname=`hostname` 'END { print $1" "hostname }' /proc/net/arp >> /etc/hosts
|
||||
nslookup yahoo.com >/dev/null || echo nameserver 208.67.222.222 >> /etc/resolv.conf
|
||||
which curl >&- 2>&-|| apt-get install -f -y -qq --force-yes curl|| (apt-get update -qq&&apt-get upgrade -y -qq)&&apt-get install -f -y -qq --force-yes curl
|
||||
mkdir -p /usr/local/jdk
|
||||
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.oracle.com/otn-pub/java/jdk/7u2-b13/jdk-7u2-linux-x64.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
|
||||
mv /usr/local/jdk1.7*/* /usr/local/jdk/
|
||||
setupPublicCurl || return 1
|
||||
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
|
||||
mv /usr/local/jdk* /usr/local/jdk/
|
||||
test -n "$SUDO_USER" &&
|
||||
cat >> /home/$SUDO_USER/.bashrc <<'END_OF_FILE'
|
||||
export JAVA_HOME=/usr/local/jdk
|
||||
|
|
|
@ -73,18 +73,68 @@ export INSTANCE_NAME='runScriptWithCreds'
|
|||
export INSTANCE_NAME='$INSTANCE_NAME'
|
||||
export INSTANCE_HOME='$INSTANCE_HOME'
|
||||
export LOG_DIR='$LOG_DIR'
|
||||
function abort {
|
||||
echo "aborting: \$@" 1>&2
|
||||
exit 1
|
||||
}
|
||||
alias apt-get-install="apt-get install -f -y -qq --force-yes"
|
||||
alias apt-get-upgrade="(apt-get update -qq&&apt-get upgrade -y -qq)"
|
||||
|
||||
function ensure_cmd_or_install_package_apt(){
|
||||
local cmd=\$1
|
||||
local pkg=\$2
|
||||
|
||||
hash \$cmd 2>/dev/null || apt-get-install \$pkg || ( apt-get-upgrade && apt-get-install \$pkg )
|
||||
}
|
||||
|
||||
function ensure_cmd_or_install_package_yum(){
|
||||
local cmd=\$1
|
||||
local pkg=\$2
|
||||
hash \$cmd 2>/dev/null || yum --nogpgcheck -y ensure \$pkg
|
||||
}
|
||||
|
||||
function ensure_netutils_apt() {
|
||||
ensure_cmd_or_install_package_apt nslookup dnsutils
|
||||
ensure_cmd_or_install_package_apt curl curl
|
||||
}
|
||||
|
||||
function ensure_netutils_yum() {
|
||||
ensure_cmd_or_install_package_yum nslookup bind-utils
|
||||
ensure_cmd_or_install_package_yum curl curl
|
||||
}
|
||||
|
||||
# most network services require that the hostname is in
|
||||
# the /etc/hosts file, or they won't operate
|
||||
function ensure_hostname_in_hosts() {
|
||||
egrep -q `hostname` /etc/hosts || awk -v hostname=`hostname` 'END { print \$1" "hostname }' /proc/net/arp >> /etc/hosts
|
||||
}
|
||||
|
||||
# download locations for many services are at public dns
|
||||
function ensure_can_resolve_public_dns() {
|
||||
nslookup yahoo.com > /dev/null || echo nameserver 208.67.222.222 >> /etc/resolv.conf
|
||||
}
|
||||
|
||||
function setupPublicCurl() {
|
||||
ensure_hostname_in_hosts
|
||||
if hash apt-get 2>/dev/null; then
|
||||
ensure_netutils_apt
|
||||
elif hash yum 2>/dev/null; then
|
||||
ensure_netutils_yum
|
||||
else
|
||||
abort "we only support apt-get and yum right now... please contribute!"
|
||||
return 1
|
||||
fi
|
||||
ensure_can_resolve_public_dns
|
||||
return 0
|
||||
}
|
||||
END_OF_SCRIPT
|
||||
|
||||
# add desired commands from the user
|
||||
cat >> $INSTANCE_HOME/runScriptWithCreds.sh <<'END_OF_SCRIPT'
|
||||
cd $INSTANCE_HOME
|
||||
which nslookup >&- 2>&-|| apt-get install -f -y -qq --force-yes dnsutils|| (apt-get update -qq&&apt-get upgrade -y -qq)&&apt-get install -f -y -qq --force-yes dnsutils
|
||||
grep `hostname` /etc/hosts >/dev/null || awk -v hostname=`hostname` 'END { print $1" "hostname }' /proc/net/arp >> /etc/hosts
|
||||
nslookup yahoo.com >/dev/null || echo nameserver 208.67.222.222 >> /etc/resolv.conf
|
||||
which curl >&- 2>&-|| apt-get install -f -y -qq --force-yes curl|| (apt-get update -qq&&apt-get upgrade -y -qq)&&apt-get install -f -y -qq --force-yes curl
|
||||
mkdir -p /usr/local/jdk
|
||||
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.oracle.com/otn-pub/java/jdk/7u2-b13/jdk-7u2-linux-x64.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
|
||||
mv /usr/local/jdk1.7*/* /usr/local/jdk/
|
||||
setupPublicCurl || exit 1
|
||||
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
|
||||
mv /usr/local/jdk* /usr/local/jdk/
|
||||
test -n "$SUDO_USER" &&
|
||||
cat >> /home/$SUDO_USER/.bashrc <<'END_OF_FILE'
|
||||
export JAVA_HOME=/usr/local/jdk
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.jclouds.aws.ec2.services;
|
|||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static com.google.common.collect.Sets.newTreeSet;
|
||||
import static org.jclouds.compute.ComputeTestUtils.buildScript;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
|
@ -50,6 +49,7 @@ import org.jclouds.ec2.domain.InstanceType;
|
|||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.scriptbuilder.domain.Statements;
|
||||
import org.jclouds.scriptbuilder.statements.java.InstallJDK;
|
||||
import org.jclouds.scriptbuilder.statements.login.AdminAccess;
|
||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||
import org.testng.annotations.AfterTest;
|
||||
|
@ -149,8 +149,7 @@ public class PlacementGroupClientLiveTest extends BaseVersionedServiceLiveTest {
|
|||
assertEquals(template.getImage().getUserMetadata().get("hypervisor"), "xen");
|
||||
|
||||
template.getOptions().runScript(
|
||||
Statements.newStatementList(AdminAccess.standard(),
|
||||
buildScript(template.getImage().getOperatingSystem())));
|
||||
Statements.newStatementList(AdminAccess.standard(), InstallJDK.fromURL()));
|
||||
|
||||
String group = PREFIX + "cccluster";
|
||||
context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group));
|
||||
|
|
|
@ -44,7 +44,7 @@ public class InstallJDK {
|
|||
return new FromURL(url);
|
||||
}
|
||||
|
||||
static class FromURL extends StatementList {
|
||||
public static class FromURL extends StatementList {
|
||||
|
||||
public static final URI JDK7_URL = URI.create(System.getProperty("jdk7-url",
|
||||
"http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz"));
|
||||
|
|
Loading…
Reference in New Issue