From f7de4b9df456cb3802f7bde6ea84b5b390ffe260 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 30 Mar 2012 16:57:31 -0700 Subject: [PATCH] Issue 891: switch to openjdk; tested on ubuntu --- .../compute/BaseComputeServiceLiveTest.java | 6 +- .../org/jclouds/compute/RunScriptData.java | 2 +- .../test/resources/initscript_with_java.sh | 65 +++++++++---------- .../test/resources/initscript_with_jboss.sh | 65 +++++++++---------- compute/src/test/resources/runscript.sh | 65 +++++++++---------- .../PlacementGroupClientLiveTest.java | 2 +- .../statements/java/InstallJDK.java | 27 +++++++- .../{installJDK.sh => installJDKFromURL.sh} | 5 +- .../resources/functions/installOpenJDK.sh | 35 ++++++++++ .../statements/java/InstallJDKTest.java | 8 +-- .../test_install_jdk_scriptbuilder.sh | 65 +++++++++---------- 11 files changed, 200 insertions(+), 145 deletions(-) rename scriptbuilder/src/main/resources/functions/{installJDK.sh => installJDKFromURL.sh} (87%) create mode 100644 scriptbuilder/src/main/resources/functions/installOpenJDK.sh diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index 6824f909ee..4322ebf777 100644 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -208,7 +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"), InstallJDK.fromURL()); + client.runScriptOnNodesMatching(runningInGroup("zebras-are-awesome"), InstallJDK.fromOpenJDK()); } // since surefire and eclipse don't otherwise guarantee the order, we are @@ -370,7 +370,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv protected static Template addRunScriptToTemplate(Template template) { template.getOptions().runScript( - Statements.newStatementList(AdminAccess.standard(), InstallJDK.fromURL())); + Statements.newStatementList(AdminAccess.standard(), InstallJDK.fromOpenJDK())); return template; } @@ -434,7 +434,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseVersionedServiceLiv protected Map runScriptWithCreds(final String group, OperatingSystem os, LoginCredentials creds) throws RunScriptOnNodesException { - return client.runScriptOnNodesMatching(runningInGroup(group), InstallJDK.fromURL(), overrideLoginCredentials(creds) + return client.runScriptOnNodesMatching(runningInGroup(group), InstallJDK.fromOpenJDK(), overrideLoginCredentials(creds) .nameTask("runScriptWithCreds")); } diff --git a/compute/src/test/java/org/jclouds/compute/RunScriptData.java b/compute/src/test/java/org/jclouds/compute/RunScriptData.java index 16f3601b29..e62fd67348 100644 --- a/compute/src/test/java/org/jclouds/compute/RunScriptData.java +++ b/compute/src/test/java/org/jclouds/compute/RunScriptData.java @@ -61,7 +61,7 @@ public class RunScriptData { public static StatementList installAdminUserJBossAndOpenPorts(OperatingSystem os) throws IOException { return new StatementList(// AdminAccess.builder().adminUsername("web").build(),// - InstallJDK.fromURL(),// + InstallJDK.fromOpenJDK(),// authorizePortsInIpTables(22, 8080),// extractTargzIntoDirectory(JBOSS7_URL, "/usr/local"),// exec("{md} " + JBOSS_HOME), exec("mv /usr/local/jboss-*/* " + JBOSS_HOME),// diff --git a/compute/src/test/resources/initscript_with_java.sh b/compute/src/test/resources/initscript_with_java.sh index b085af364d..927da887cf 100644 --- a/compute/src/test/resources/initscript_with_java.sh +++ b/compute/src/test/resources/initscript_with_java.sh @@ -133,41 +133,40 @@ function setupPublicCurl() { ensure_can_resolve_public_dns return 0 } +function setupJavaHomeInProfile() { + test -n \"$SUDO_USER\" && cat >> `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE +} + function installJDK() { - if hash curl 2>/dev/null; then - if [ `uname -m` == 'x86_64' ]; then - local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz} - else - local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586.tar.gz} - fi - curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET $url |(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_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - # 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 - ln -fs /usr/local/jdk/bin/java /usr/bin/java - /usr/bin/java -version || abort "cannot run /usr/bin/java" + if hash apt-get 2>/dev/null; then + export pkg=openjdk-7-jdk + apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg ) + elif hash yum 2>/dev/null; then + export pkg=java-1.7.0-openjdk + yum --nogpgcheck -y ensure $pkg else - abort "curl not available.. cannot install openjdk" + abort "we only support apt-get and yum right now... please contribute!" + return 1 fi - return 0 + JAVA_HOME=`ls -d /usr/lib/jvm/java-7-openjdk-*|grep -v common` + ln -Fs $JAVA_HOME /usr/local/jdk + /usr/local/jdk/bin/java -version || abort "cannot run java" + setupJavaHomeInProfile } END_OF_JCLOUDS_SCRIPT @@ -198,7 +197,7 @@ END_OF_JCLOUDS_SCRIPT 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 setupPublicCurl || return 1 - installJDK || return 1 + installOpenJDK || return 1 END_OF_JCLOUDS_SCRIPT diff --git a/compute/src/test/resources/initscript_with_jboss.sh b/compute/src/test/resources/initscript_with_jboss.sh index 1a9052097f..e848b851b0 100644 --- a/compute/src/test/resources/initscript_with_jboss.sh +++ b/compute/src/test/resources/initscript_with_jboss.sh @@ -133,41 +133,40 @@ function setupPublicCurl() { ensure_can_resolve_public_dns return 0 } +function setupJavaHomeInProfile() { + test -n \"$SUDO_USER\" && cat >> `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE +} + function installJDK() { - if hash curl 2>/dev/null; then - if [ `uname -m` == 'x86_64' ]; then - local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz} - else - local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586.tar.gz} - fi - curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET $url |(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_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - # 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 - ln -fs /usr/local/jdk/bin/java /usr/bin/java - /usr/bin/java -version || abort "cannot run /usr/bin/java" + if hash apt-get 2>/dev/null; then + export pkg=openjdk-7-jdk + apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg ) + elif hash yum 2>/dev/null; then + export pkg=java-1.7.0-openjdk + yum --nogpgcheck -y ensure $pkg else - abort "curl not available.. cannot install openjdk" + abort "we only support apt-get and yum right now... please contribute!" + return 1 fi - return 0 + JAVA_HOME=`ls -d /usr/lib/jvm/java-7-openjdk-*|grep -v common` + ln -Fs $JAVA_HOME /usr/local/jdk + /usr/local/jdk/bin/java -version || abort "cannot run java" + setupJavaHomeInProfile } END_OF_JCLOUDS_SCRIPT @@ -198,7 +197,7 @@ END_OF_JCLOUDS_SCRIPT 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 setupPublicCurl || return 1 - installJDK || return 1 + installOpenJDK || return 1 iptables -I INPUT 1 -p tcp --dport 22 -j ACCEPT iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT iptables-save diff --git a/compute/src/test/resources/runscript.sh b/compute/src/test/resources/runscript.sh index 844ba16f3c..7f8977c047 100644 --- a/compute/src/test/resources/runscript.sh +++ b/compute/src/test/resources/runscript.sh @@ -133,41 +133,40 @@ function setupPublicCurl() { ensure_can_resolve_public_dns return 0 } +function setupJavaHomeInProfile() { + test -n \"$SUDO_USER\" && cat >> `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE +} + function installJDK() { - if hash curl 2>/dev/null; then - if [ `uname -m` == 'x86_64' ]; then - local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz} - else - local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586.tar.gz} - fi - curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET $url |(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_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - # 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 - ln -fs /usr/local/jdk/bin/java /usr/bin/java - /usr/bin/java -version || abort "cannot run /usr/bin/java" + if hash apt-get 2>/dev/null; then + export pkg=openjdk-7-jdk + apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg ) + elif hash yum 2>/dev/null; then + export pkg=java-1.7.0-openjdk + yum --nogpgcheck -y ensure $pkg else - abort "curl not available.. cannot install openjdk" + abort "we only support apt-get and yum right now... please contribute!" + return 1 fi - return 0 + JAVA_HOME=`ls -d /usr/lib/jvm/java-7-openjdk-*|grep -v common` + ln -Fs $JAVA_HOME /usr/local/jdk + /usr/local/jdk/bin/java -version || abort "cannot run java" + setupJavaHomeInProfile } END_OF_JCLOUDS_SCRIPT @@ -178,7 +177,7 @@ END_OF_JCLOUDS_SCRIPT rm -f $INSTANCE_HOME/rc trap 'echo $?>$INSTANCE_HOME/rc' 0 1 2 3 15 setupPublicCurl || exit 1 - installJDK || exit 1 + installOpenJDK || exit 1 END_OF_JCLOUDS_SCRIPT diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java index f5cbb645d1..a39c976178 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java @@ -149,7 +149,7 @@ public class PlacementGroupClientLiveTest extends BaseVersionedServiceLiveTest { assertEquals(template.getImage().getUserMetadata().get("hypervisor"), "xen"); template.getOptions().runScript( - Statements.newStatementList(AdminAccess.standard(), InstallJDK.fromURL())); + Statements.newStatementList(AdminAccess.standard(), InstallJDK.fromOpenJDK())); String group = PREFIX + "cccluster"; context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group)); diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/java/InstallJDK.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/java/InstallJDK.java index 5f24f1decf..ad15a5cb59 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/java/InstallJDK.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/java/InstallJDK.java @@ -31,22 +31,43 @@ import org.jclouds.scriptbuilder.domain.StatementList; * @author Adrian Cole */ public class InstallJDK { + // TODO: this doesn't work + public static Statement fromOracle() { + throw new UnsupportedOperationException("Oracle JDK install doesn't currently work due to license agreement"); + } + + public static Statement fromOpenJDK() { + return new FromOpenJDK(); + } + + /** + * @see fromOpenJDK + */ + @Deprecated public static Statement fromURL() { - return new FromURL(); + return fromOpenJDK(); } public static Statement fromURL(URI url) { return new FromURL(url); } + public static class FromOpenJDK extends StatementList { + + public FromOpenJDK() { + super(call("setupPublicCurl"), call("installOpenJDK")); + } + + } + public static class FromURL extends StatementList { public FromURL() { - super(call("setupPublicCurl"), call("installJDK")); + super(call("setupPublicCurl"), call("installJDKFromURL")); } public FromURL(URI jdk7Url) { - super(call("setupPublicCurl"), call("installJDK", jdk7Url.toASCIIString())); + super(call("setupPublicCurl"), call("installJDKFromURL", jdk7Url.toASCIIString())); } } } \ No newline at end of file diff --git a/scriptbuilder/src/main/resources/functions/installJDK.sh b/scriptbuilder/src/main/resources/functions/installJDKFromURL.sh similarity index 87% rename from scriptbuilder/src/main/resources/functions/installJDK.sh rename to scriptbuilder/src/main/resources/functions/installJDKFromURL.sh index a800582483..a42b3a1e61 100644 --- a/scriptbuilder/src/main/resources/functions/installJDK.sh +++ b/scriptbuilder/src/main/resources/functions/installJDKFromURL.sh @@ -1,4 +1,7 @@ -function installJDK() { +# note this does not work until someone addresses user auth +# https://issues.jenkins-ci.org/browse/JENKINS-10556 +# https://forums.oracle.com/forums/thread.jspa?messageID=10236239&tstart=0 +function installJDKFromURL() { if hash curl 2>/dev/null; then if [ `uname -m` == 'x86_64' ]; then local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz} diff --git a/scriptbuilder/src/main/resources/functions/installOpenJDK.sh b/scriptbuilder/src/main/resources/functions/installOpenJDK.sh new file mode 100644 index 0000000000..cf7ef59be2 --- /dev/null +++ b/scriptbuilder/src/main/resources/functions/installOpenJDK.sh @@ -0,0 +1,35 @@ +function setupJavaHomeInProfile() { + test -n \"$SUDO_USER\" && cat >> `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE +} + +function installJDK() { + if hash apt-get 2>/dev/null; then + export pkg=openjdk-7-jdk + apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg ) + elif hash yum 2>/dev/null; then + export pkg=java-1.7.0-openjdk + yum --nogpgcheck -y ensure $pkg + else + abort "we only support apt-get and yum right now... please contribute!" + return 1 + fi + JAVA_HOME=`ls -d /usr/lib/jvm/java-7-openjdk-*|grep -v common` + ln -Fs $JAVA_HOME /usr/local/jdk + /usr/local/jdk/bin/java -version || abort "cannot run java" + setupJavaHomeInProfile +} \ No newline at end of file diff --git a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/java/InstallJDKTest.java b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/java/InstallJDKTest.java index dee09e0e3b..8bb7033d4b 100644 --- a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/java/InstallJDKTest.java +++ b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/java/InstallJDKTest.java @@ -39,14 +39,14 @@ import com.google.common.io.Resources; @Test(groups = "unit", testName = "InstallJDKTest") public class InstallJDKTest { - Statement installJDK = InstallJDK.fromURL(); + Statement installJDK = InstallJDK.fromOpenJDK(); public void testInstallJDKUNIX() throws IOException { - assertEquals(InstallJDK.fromURL().render(OsFamily.UNIX), "setupPublicCurl || return 1\ninstallJDK || return 1\n"); + assertEquals(InstallJDK.fromOpenJDK().render(OsFamily.UNIX), "setupPublicCurl || return 1\ninstallOpenJDK || return 1\n"); } public void testInstallJDKUNIXInScriptBuilderSourcesSetupPublicCurl() throws IOException { - assertEquals(InitScript.builder().name("install_jdk").run(InstallJDK.fromURL()).build().render(OsFamily.UNIX), + assertEquals(InitScript.builder().name("install_jdk").run(InstallJDK.fromOpenJDK()).build().render(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier( Resources.getResource("test_install_jdk_scriptbuilder." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8))); @@ -54,7 +54,7 @@ public class InstallJDKTest { public void testInstallJDKUNIXWithURL() throws IOException { assertEquals(InstallJDK.fromURL(URI.create("http://foo")).render(OsFamily.UNIX), - "setupPublicCurl || return 1\ninstallJDK http://foo || return 1\n"); + "setupPublicCurl || return 1\ninstallJDKFromURL http://foo || return 1\n"); } } diff --git a/scriptbuilder/src/test/resources/test_install_jdk_scriptbuilder.sh b/scriptbuilder/src/test/resources/test_install_jdk_scriptbuilder.sh index a253c0f725..905599a088 100644 --- a/scriptbuilder/src/test/resources/test_install_jdk_scriptbuilder.sh +++ b/scriptbuilder/src/test/resources/test_install_jdk_scriptbuilder.sh @@ -133,41 +133,40 @@ function setupPublicCurl() { ensure_can_resolve_public_dns return 0 } +function setupJavaHomeInProfile() { + test -n \"$SUDO_USER\" && cat >> `getent passwd $SUDO_USER| cut -f6 -d:`/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE + cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE' + export JAVA_HOME=/usr/local/jdk + export PATH=$JAVA_HOME/bin:$PATH +END_OF_JCLOUDS_FILE +} + function installJDK() { - if hash curl 2>/dev/null; then - if [ `uname -m` == 'x86_64' ]; then - local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-x64.tar.gz} - else - local url=${1:-http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586.tar.gz} - fi - curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET $url |(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_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> $HOME/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - cat >> /etc/skel/.bashrc <<-'END_OF_JCLOUDS_FILE' - export JAVA_HOME=/usr/local/jdk - export PATH=$JAVA_HOME/bin:$PATH -END_OF_JCLOUDS_FILE - # 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 - ln -fs /usr/local/jdk/bin/java /usr/bin/java - /usr/bin/java -version || abort "cannot run /usr/bin/java" + if hash apt-get 2>/dev/null; then + export pkg=openjdk-7-jdk + apt-get-install $pkg || ( apt-get-upgrade && apt-get-install $pkg ) + elif hash yum 2>/dev/null; then + export pkg=java-1.7.0-openjdk + yum --nogpgcheck -y ensure $pkg else - abort "curl not available.. cannot install openjdk" + abort "we only support apt-get and yum right now... please contribute!" + return 1 fi - return 0 + JAVA_HOME=`ls -d /usr/lib/jvm/java-7-openjdk-*|grep -v common` + ln -Fs $JAVA_HOME /usr/local/jdk + /usr/local/jdk/bin/java -version || abort "cannot run java" + setupJavaHomeInProfile } END_OF_JCLOUDS_SCRIPT @@ -178,7 +177,7 @@ END_OF_JCLOUDS_SCRIPT rm -f $INSTANCE_HOME/rc trap 'echo $?>$INSTANCE_HOME/rc' 0 1 2 3 15 setupPublicCurl || exit 1 - installJDK || exit 1 + installOpenJDK || exit 1 END_OF_JCLOUDS_SCRIPT