Issue 1075:switch to use jetty for java install/web service tests

This commit is contained in:
Adrian Cole 2012-08-26 23:37:15 -07:00
parent 7f53d74250
commit a70e3adb20
9 changed files with 175 additions and 704 deletions

View File

@ -23,6 +23,7 @@ import org.jclouds.javax.annotation.Nullable;
import org.jclouds.ovf.Envelope;
import com.google.common.annotations.Beta;
import com.google.common.base.Objects.ToStringHelper;
/**
* Operating system based on DMTF CIM model.
@ -175,8 +176,7 @@ public class CIMOperatingSystem extends OperatingSystem {
}
@Override
public String toString() {
return "[name=" + name + ", family=" + family + ", version=" + version + ", arch=" + arch + ", is64Bit="
+ is64Bit + ", description=" + description + ", osType=" + osType+ "]";
protected ToStringHelper string() {
return super.string().add("osType", osType);
}
}

View File

@ -0,0 +1,74 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.compute;
import static org.jclouds.scriptbuilder.domain.Statements.exec;
import static org.jclouds.scriptbuilder.domain.Statements.extractTargzAndFlattenIntoDirectory;
import java.net.URI;
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;
/**
*
* @author Adrian Cole
*/
public class JettyStatements {
public static final URI JETTY_URL = URI.create(System.getProperty("test.jetty-url",//
"http://download.eclipse.org/jetty/8.1.5.v20120716/dist/jetty-distribution-8.1.5.v20120716.tar.gz"));
public static final String JETTY_HOME = "/usr/local/jetty";
public static final int port = 8080;
public static Statement version() {
return exec(String.format("head -1 %s/VERSION.txt | cut -f1 -d ' '", JETTY_HOME));
}
public static Statement install() {
return new StatementList(
AdminAccess.builder().adminUsername("web").build(),
InstallJDK.fromOpenJDK(),
authorizePortInIpTables(),
extractTargzAndFlattenIntoDirectory(JETTY_URL, JETTY_HOME),
exec("chown -R web " + JETTY_HOME));
}
private static Statement authorizePortInIpTables() {
return new StatementList(
exec("iptables -I INPUT 1 -p tcp --dport " + port + " -j ACCEPT"),
exec("iptables-save"));
}
public static Statement start() {
return new StatementList(
exec("cd " + JETTY_HOME),
exec("./bin/jetty.sh start"));
}
public static Statement stop() {
return new StatementList(
exec("cd " + JETTY_HOME),
exec("./bin/jetty.sh stop"));
}
}

View File

@ -1,101 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.compute;
import static java.lang.String.format;
import static org.jclouds.compute.util.ComputeServiceUtils.extractTargzIntoDirectory;
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 java.io.IOException;
import java.net.URI;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.scriptbuilder.InitScript;
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.ImmutableMap;
import com.google.common.collect.ImmutableList.Builder;
/**
*
* @author Adrian Cole
*/
public class RunScriptData {
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 authorizePortsInIpTables(int... ports) {
Builder<Statement> builder = ImmutableList.builder();
for (int port : ports)
builder.add(exec("iptables -I INPUT 1 -p tcp --dport " + port + " -j ACCEPT"));
builder.add(exec("iptables-save"));
return new StatementList(builder.build());
}
public static StatementList installAdminUserJBossAndOpenPorts(OperatingSystem os) throws IOException {
return new StatementList(//
AdminAccess.builder().adminUsername("web").build(),//
InstallJDK.fromOpenJDK(),//
authorizePortsInIpTables(22, 8080),//
extractTargzIntoDirectory(JBOSS7_URL, "/usr/local"),//
exec("{md} " + JBOSS_HOME), exec("mv /usr/local/jboss-*/* " + JBOSS_HOME),//
changeStandaloneConfigToListenOnAllIPAddresses(),
exec("chmod -R oug+r+w " + JBOSS_HOME),
exec("chown -R web " + JBOSS_HOME));
}
// NOTE do not name this the same as your login user, or the init process may kill you!
public static InitScript startJBoss(String configuration) {
return InitScript.builder()
.name("jboss")
.home(JBOSS_HOME)
.exportVariables(ImmutableMap.of("JBOSS_HOME", JBOSS_HOME))
.init(appendFile(JBOSS_HOME + "/standalone/configuration/standalone-custom.xml", Splitter.on('\n').split(configuration)))
.run(interpret(new StringBuilder().append("java ").append(' ')
.append("-server -Xms128m -Xmx128m -XX:MaxPermSize=128m -Djava.net.preferIPv4Stack=true -XX:+UseFastAccessorMethods -XX:+TieredCompilation -Xverify:none -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000").append(' ')
.append("-Djboss.modules.system.pkgs=org.jboss.byteman").append(' ')
.append("-Dorg.jboss.boot.log.file=$JBOSS_HOME/standalone/log/boot.log").append(' ')
.append("-Dlogging.configuration=file:$JBOSS_HOME/standalone/configuration/logging.properties").append(' ')
.append("-jar $JBOSS_HOME/jboss-modules.jar").append(' ')
.append("-mp $JBOSS_HOME/modules").append(' ')
.append("-logmodule org.jboss.logmanager").append(' ')
.append("-jaxpmodule javax.xml.jaxp-provider").append(' ')
.append("org.jboss.as.standalone").append(' ')
.append("-Djboss.home.dir=$JBOSS_HOME").append(' ')
.append("--server-config=standalone-custom.xml")
.toString())).build();
}
// 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));
}
}

View File

@ -36,6 +36,7 @@ import org.easymock.IArgumentMatcher;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
import org.jclouds.compute.util.OpenSocketFinder;
import org.jclouds.crypto.Pems;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.io.Payload;
@ -81,12 +82,19 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
SocketOpen socketOpen = createMock(SocketOpen.class);
expect(socketOpen.apply(HostAndPort.fromParts("144.175.1.1", 22))).andReturn(true).times(5);
// restart of jboss
expect(socketOpen.apply(HostAndPort.fromParts("144.175.1.1", 8080))).andReturn(true).times(2);
replay(socketOpen);
preciseSocketTester = socketTester = new RetryablePredicate<HostAndPort>(socketOpen, 1, 1, TimeUnit.MILLISECONDS);
socketTester = new RetryablePredicate<HostAndPort>(socketOpen, 1, 1, TimeUnit.MILLISECONDS);
openSocketFinder = new OpenSocketFinder(){
@Override
public HostAndPort findOpenSocketOnNode(NodeMetadata node, int port, long timeoutValue, TimeUnit timeUnits) {
return HostAndPort.fromParts("144.175.1.1", 8080);
}
};
}
@Override
@ -283,9 +291,9 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
client.connect();
try {
String scriptName = "configure-jboss";
String scriptName = "configure-jetty";
client.put("/tmp/init-" + scriptName, Strings2.toStringAndClose(StubComputeServiceIntegrationTest.class
.getResourceAsStream("/initscript_with_jboss.sh")));
.getResourceAsStream("/initscript_with_jetty.sh")));
expect(client.exec("chmod 755 /tmp/init-" + scriptName)).andReturn(EXEC_GOOD);
expect(client.exec("ln -fs /tmp/init-" + scriptName + " " + scriptName)).andReturn(EXEC_GOOD);
expect(client.getUsername()).andReturn("root").atLeastOnce();
@ -303,19 +311,9 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
client.disconnect();
clientNew.connect();
expect(clientNew.exec("ls /usr/local/jboss/bundles/org/jboss/as/osgi/configadmin/main|sed -e 's/.*-//g' -e 's/.jar//g'\n")).andReturn(EXEC_GOOD);
clientNew.disconnect();
clientNew.connect();
expect(clientNew.exec("nslookup -query=a -timeout=5 download.jboss.org|grep Address|tail -1|sed 's/.* //g'\n")).andReturn(EXEC_GOOD);
clientNew.disconnect();
clientNew.connect();
expect(clientNew.exec("nslookup -query=a -timeout=5 download.oracle.com|grep Address|tail -1|sed 's/.* //g'\n")).andReturn(EXEC_GOOD);
clientNew.disconnect();
clientNew.connect();
expect(clientNew.exec("curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 http://checkip.amazonaws.com/\n")).andReturn(EXEC_GOOD);
expect(clientNew.getUsername()).andReturn("web").atLeastOnce();
expect(clientNew.getHostAddress()).andReturn("localhost").atLeastOnce();
expect(clientNew.exec("head -1 /usr/local/jetty/VERSION.txt | cut -f1 -d ' '\n")).andReturn(EXEC_GOOD);
clientNew.disconnect();
clientNew.connect();
@ -323,32 +321,17 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
clientNew.disconnect();
clientNew.connect();
scriptName = "jboss";
clientNew.put("/tmp/init-" + scriptName, Strings2
.toStringAndClose(StubComputeServiceIntegrationTest.class
.getResourceAsStream("/runscript_jboss.sh")));
expect(clientNew.exec("chmod 755 /tmp/init-" + scriptName)).andReturn(EXEC_GOOD);
expect(clientNew.exec("ln -fs /tmp/init-" + scriptName + " " + scriptName)).andReturn(EXEC_GOOD);
expect(clientNew.getUsername()).andReturn("web").atLeastOnce();
expect(clientNew.getHostAddress()).andReturn("localhost").atLeastOnce();
expect(clientNew.exec("/tmp/init-" + scriptName + " init")).andReturn(EXEC_GOOD);
expect(clientNew.exec("/tmp/init-" + scriptName + " start")).andReturn(EXEC_GOOD);
clientNew.disconnect();
clientNew.connect();
expect(clientNew.exec("/tmp/init-" + scriptName + " stdout\n")).andReturn(EXEC_GOOD);
expect(clientNew.exec("cd /usr/local/jetty\n./bin/jetty.sh start\n")).andReturn(EXEC_GOOD);
clientNew.disconnect();
clientNew.connect();
expect(clientNew.exec("/tmp/init-" + scriptName + " stop\n")).andReturn(EXEC_GOOD);
expect(clientNew.exec("cd /usr/local/jetty\n./bin/jetty.sh stop\n")).andReturn(EXEC_GOOD);
clientNew.disconnect();
clientNew.connect();
expect(clientNew.exec("/tmp/init-" + scriptName + " start\n")).andReturn(EXEC_GOOD);
expect(clientNew.exec("cd /usr/local/jetty\n./bin/jetty.sh start\n")).andReturn(EXEC_GOOD);
clientNew.disconnect();
clientNew.connect();
expect(clientNew.exec("/tmp/init-" + scriptName + " stdout\n")).andReturn(EXEC_GOOD);
clientNew.disconnect();
} catch (IOException e) {
Throwables.propagate(e);
}

View File

@ -31,9 +31,6 @@ 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.RunScriptData.JBOSS_HOME;
import static org.jclouds.compute.RunScriptData.installAdminUserJBossAndOpenPorts;
import static org.jclouds.compute.RunScriptData.startJBoss;
import static org.jclouds.compute.options.RunScriptOptions.Builder.nameTask;
import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript;
import static org.jclouds.compute.options.TemplateOptions.Builder.inboundPorts;
@ -60,17 +57,14 @@ import java.util.SortedSet;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeTestUtils;
import org.jclouds.compute.JettyStatements;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.RunScriptData;
import org.jclouds.compute.RunScriptOnNodesException;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.ComputeType;
@ -83,6 +77,7 @@ import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.util.OpenSocketFinder;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope;
@ -90,12 +85,12 @@ import org.jclouds.domain.LoginCredentials;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.scriptbuilder.domain.Statement;
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;
import org.jclouds.util.Strings2;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -124,7 +119,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
protected String group;
protected Predicate<HostAndPort> socketTester;
protected Predicate<HostAndPort> preciseSocketTester;
protected OpenSocketFinder openSocketFinder;
protected SortedSet<NodeMetadata> nodes;
protected ComputeService client;
@ -159,12 +154,9 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
SocketOpen socketOpen = view.utils().injector().getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<HostAndPort>(socketOpen, 60, 1, TimeUnit.SECONDS);
// wait a maximum of 60 seconds for port 8080 to open.
long maxWait = TimeUnit.SECONDS.toMillis(60);
long interval = 50;
// get more precise than default socket tester
preciseSocketTester = new RetryablePredicate<HostAndPort>(socketOpen, maxWait, interval, interval,
TimeUnit.MILLISECONDS);
openSocketFinder = context.utils().injector().getInstance(OpenSocketFinder.class);
}
@Override
protected void initializeContext() {
super.initializeContext();
@ -606,54 +598,38 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
static class ServiceStats {
long backgroundProcessMilliseconds;
long socketOpenMilliseconds;
long reportedStartupTimeMilliseconds;
@Override
public String toString() {
return String.format(
"[backgroundProcessMilliseconds=%s, socketOpenMilliseconds=%s, reportedStartupTimeMilliseconds=%s]",
backgroundProcessMilliseconds, socketOpenMilliseconds, reportedStartupTimeMilliseconds);
return String.format("[backgroundProcessMilliseconds=%s, socketOpenMilliseconds=%s]",
backgroundProcessMilliseconds, socketOpenMilliseconds);
}
}
protected ServiceStats trackAvailabilityOfProcessOnNode(Future<ExecResponse> bgProcess, String processName,
NodeMetadata node, Pattern parseReported) throws InterruptedException, ExecutionException {
protected ServiceStats trackAvailabilityOfProcessOnNode(Statement process, String processName, NodeMetadata node) {
ServiceStats stats = new ServiceStats();
Stopwatch watch = new Stopwatch().start();
ExecResponse exec = bgProcess.get();
ExecResponse exec = client.runScriptOnNode(node.getId(), process, runAsRoot(false).wrapInInitScript(false));
stats.backgroundProcessMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS);
watch.reset().start();
HostAndPort socket = HostAndPort.fromParts(Iterables.get(node.getPublicAddresses(), 0), 8080);
assert preciseSocketTester.apply(socket) : String.format("failed to open socket %s on node %s:%n%s%s", socket,
node, init(node, processName, "stdout"), init(node, processName, "stderr"));
HostAndPort socket = null;
try {
socket = openSocketFinder.findOpenSocketOnNode(node, 8080, 60, TimeUnit.SECONDS);
} catch (NoSuchElementException e) {
throw new NoSuchElementException(String.format("%s%n%s%s", e.getMessage(), exec.getOutput(), exec.getError()));
}
stats.socketOpenMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS);
exec = init(node, processName, "stdout");
Matcher matcher = parseReported.matcher(exec.getOutput());
if (matcher.find())
stats.reportedStartupTimeMilliseconds = Long.valueOf(matcher.group(1));
getAnonymousLogger().info(format("<< %s on node(%s) %s", bgProcess, node.getId(), stats));
getAnonymousLogger().info(format("<< %s on node(%s)[%s] %s", processName, node.getId(), socket, stats));
return stats;
}
public ExecResponse init(NodeMetadata node, String processName, String command) {
return client.runScriptOnNode(node.getId(), "/tmp/init-" + processName + " " + command, runAsRoot(false)
.wrapInInitScript(false));
}
// started in 6462ms -
public static final Pattern JBOSS_PATTERN = Pattern.compile("started in ([0-9]+)ms -");
@Test(enabled = true)
public void testCreateAndRunAService() throws Exception {
String group = this.group + "s";
final String configuration = Strings2.toStringAndClose(RunScriptData.class
.getResourceAsStream("/standalone-basic.xml"));
try {
client.destroyNodesMatching(inGroup(group));
} catch (Exception e) {
@ -661,6 +637,14 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
}
try {
createAndRunAServiceInGroup(group);
} finally {
client.destroyNodesMatching(inGroup(group));
}
}
protected void createAndRunAServiceInGroup(String group) throws RunNodesException {
ImmutableMap<String, String> userMetadata = ImmutableMap.<String, String> of("Name", group);
ImmutableSet<String> tags = ImmutableSet. of(group);
Stopwatch watch = new Stopwatch().start();
@ -678,63 +662,29 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
watch.reset().start();
// note this is a dependency on the template resolution so we have the
// right process per
// operating system. moreover, we wish this to run as root, so that it
// can change ip
// tables rules and setup our admin user
client.runScriptOnNode(nodeId, installAdminUserJBossAndOpenPorts(node.getOperatingSystem()),
nameTask("configure-jboss"));
client.runScriptOnNode(nodeId, JettyStatements.install(), nameTask("configure-jetty"));
long configureSeconds = watch.elapsedTime(TimeUnit.SECONDS);
getAnonymousLogger().info(
format(
"<< configured node(%s) with %s and JBoss %s in %ss",
"<< configured node(%s) with %s and jetty %s in %ss",
nodeId,
exec(nodeId, "java -fullversion"),
// version of the jboss jar
exec(nodeId,
format("ls %s/bundles/org/jboss/as/osgi/configadmin/main|sed -e 's/.*-//g' -e 's/.jar//g'",
JBOSS_HOME)), configureSeconds));
exec(nodeId, JettyStatements.version()), configureSeconds));
trackAvailabilityOfProcessOnNode(view.utils().userExecutor().submit(new Callable<ExecResponse>() {
@Override
public ExecResponse call() {
return client.runScriptOnNode(nodeId, startJBoss(configuration), runAsRoot(false).blockOnComplete(false)
.nameTask("jboss"));
}
trackAvailabilityOfProcessOnNode(JettyStatements.start(), "start jetty", node);
@Override
public String toString() {
return "initial start of jboss";
}
}), "jboss", node, JBOSS_PATTERN);
client.runScriptOnNode(nodeId, "/tmp/init-jboss stop", runAsRoot(false).wrapInInitScript(false));
trackAvailabilityOfProcessOnNode(view.utils().userExecutor().submit(new Callable<ExecResponse>() {
@Override
public ExecResponse call() {
return client.runScriptOnNode(nodeId, "/tmp/init-jboss start", runAsRoot(false).wrapInInitScript(false));
}
@Override
public String toString() {
return "warm start of jboss";
}
}), "jboss", node, JBOSS_PATTERN);
} finally {
client.destroyNodesMatching(inGroup(group));
}
client.runScriptOnNode(nodeId, JettyStatements.stop(), runAsRoot(false).wrapInInitScript(false));
trackAvailabilityOfProcessOnNode(JettyStatements.start(), "start jetty", node);
}
protected String exec(final String nodeId, String command) {
return exec(nodeId, Statements.exec(command));
}
protected String exec(final String nodeId, Statement command) {
return client.runScriptOnNode(nodeId, command, runAsRoot(false).wrapInInitScript(false)).getOutput().trim();
}

View File

@ -8,12 +8,12 @@ function abort {
exit 1
}
function default {
export INSTANCE_NAME="configure-jboss"
export INSTANCE_HOME="/tmp/configure-jboss"
export INSTANCE_NAME="configure-jetty"
export INSTANCE_HOME="/tmp/configure-jetty"
export LOG_DIR="$INSTANCE_HOME"
return $?
}
function configure-jboss {
function configure-jetty {
return $?
}
function findPid {
@ -58,27 +58,27 @@ export PATH=/usr/ucb/bin:/bin:/sbin:/usr/bin:/usr/sbin
case $1 in
init)
default || exit 1
configure-jboss || exit 1
configure-jetty || exit 1
mkdir -p $INSTANCE_HOME
# create runscript header
cat > $INSTANCE_HOME/configure-jboss.sh <<-'END_OF_JCLOUDS_SCRIPT'
cat > $INSTANCE_HOME/configure-jetty.sh <<-'END_OF_JCLOUDS_SCRIPT'
#!/bin/bash
set +u
shopt -s xpg_echo
shopt -s expand_aliases
PROMPT_COMMAND='echo -ne \"\033]0;configure-jboss\007\"'
PROMPT_COMMAND='echo -ne \"\033]0;configure-jetty\007\"'
export PATH=/usr/ucb/bin:/bin:/sbin:/usr/bin:/usr/sbin
export INSTANCE_NAME='configure-jboss'
export INSTANCE_NAME='configure-jetty'
END_OF_JCLOUDS_SCRIPT
cat >> $INSTANCE_HOME/configure-jboss.sh <<-END_OF_JCLOUDS_SCRIPT
cat >> $INSTANCE_HOME/configure-jetty.sh <<-END_OF_JCLOUDS_SCRIPT
export INSTANCE_NAME='$INSTANCE_NAME'
export INSTANCE_HOME='$INSTANCE_HOME'
export LOG_DIR='$LOG_DIR'
END_OF_JCLOUDS_SCRIPT
cat >> $INSTANCE_HOME/configure-jboss.sh <<-'END_OF_JCLOUDS_SCRIPT'
cat >> $INSTANCE_HOME/configure-jetty.sh <<-'END_OF_JCLOUDS_SCRIPT'
function abort {
echo "aborting: $@" 1>&2
exit 1
@ -191,7 +191,7 @@ function installOpenJDK() {
END_OF_JCLOUDS_SCRIPT
# add desired commands from the user
cat >> $INSTANCE_HOME/configure-jboss.sh <<-'END_OF_JCLOUDS_SCRIPT'
cat >> $INSTANCE_HOME/configure-jetty.sh <<-'END_OF_JCLOUDS_SCRIPT'
cd $INSTANCE_HOME
rm -f $INSTANCE_HOME/rc
trap 'echo $?>$INSTANCE_HOME/rc' 0 1 2 3 15
@ -217,25 +217,24 @@ END_OF_JCLOUDS_SCRIPT
test -f /etc/shadow.${SUDO_USER:=${USER}} && mv /etc/shadow.${SUDO_USER:=${USER}} /etc/shadow
setupPublicCurl || 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
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.jboss.org/jbossas/7.0/jboss-as-7.0.2.Final/jboss-as-web-7.0.2.Final.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
mkdir -p /usr/local/jboss
mv /usr/local/jboss-*/* /usr/local/jboss
(cd /usr/local/jboss/standalone/configuration && sed 's~inet-address value=.*/~any-address/~g' standalone.xml > standalone.xml.new && mv standalone.xml.new standalone.xml)
chmod -R oug+r+w /usr/local/jboss
chown -R web /usr/local/jboss
mkdir /tmp/$$
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.eclipse.org/jetty/8.1.5.v20120716/dist/jetty-distribution-8.1.5.v20120716.tar.gz |(mkdir -p /tmp/$$ &&cd /tmp/$$ &&tar -xpzf -)
mkdir -p /usr/local/jetty
mv /tmp/$$/*/* /usr/local/jetty
rm -rf /tmp/$$
chown -R web /usr/local/jetty
END_OF_JCLOUDS_SCRIPT
# add runscript footer
cat >> $INSTANCE_HOME/configure-jboss.sh <<-'END_OF_JCLOUDS_SCRIPT'
cat >> $INSTANCE_HOME/configure-jetty.sh <<-'END_OF_JCLOUDS_SCRIPT'
exit $?
END_OF_JCLOUDS_SCRIPT
chmod u+x $INSTANCE_HOME/configure-jboss.sh
chmod u+x $INSTANCE_HOME/configure-jetty.sh
;;
status)
default || exit 1

View File

@ -1,247 +0,0 @@
#!/bin/bash
set +u
shopt -s xpg_echo
shopt -s expand_aliases
unset PATH JAVA_HOME LD_LIBRARY_PATH
function abort {
echo "aborting: $@" 1>&2
exit 1
}
function default {
export INSTANCE_NAME="jboss"
export INSTANCE_HOME="/usr/local/jboss"
export LOG_DIR="$INSTANCE_HOME"
return $?
}
function jboss {
export JBOSS_HOME="/usr/local/jboss"
return $?
}
function findPid {
unset FOUND_PID;
[ $# -eq 1 ] || {
abort "findPid requires a parameter of pattern to match"
return 1
}
local PATTERN="$1"; shift
local _FOUND=`ps auxwww|grep "$PATTERN"|grep -v " $0"|grep -v grep|grep -v $$|awk '{print $2}'`
[ -n "$_FOUND" ] && {
export FOUND_PID=$_FOUND
return 0
} || {
return 1
}
}
function forget {
unset FOUND_PID;
[ $# -eq 3 ] || {
abort "forget requires parameters INSTANCE_NAME SCRIPT LOG_DIR"
return 1
}
local INSTANCE_NAME="$1"; shift
local SCRIPT="$1"; shift
local LOG_DIR="$1"; shift
mkdir -p $LOG_DIR
findPid $INSTANCE_NAME
[ -n "$FOUND_PID" -a -f $LOG_DIR/stdout.log ] && {
echo $INSTANCE_NAME already running pid $FOUND_PID
return 1;
} || {
nohup $SCRIPT >$LOG_DIR/stdout.log 2>$LOG_DIR/stderr.log &
RETURN=$?
# this is generally followed by findPid, so we shouldn't exit
# immediately as the proc may not have registered in ps, yet
test $RETURN && sleep 1
return $RETURN;
}
}
export PATH=/usr/ucb/bin:/bin:/sbin:/usr/bin:/usr/sbin
case $1 in
init)
default || exit 1
jboss || exit 1
cat >> /usr/local/jboss/standalone/configuration/standalone-custom.xml <<-'END_OF_JCLOUDS_FILE'
<?xml version='1.0' encoding='UTF-8'?>
<server name="basic" xmlns="urn:jboss:domain:1.0">
<extensions>
<extension module="org.jboss.as.connector"/>
<extension module="org.jboss.as.deployment-scanner"/>
<extension module="org.jboss.as.ee"/>
<extension module="org.jboss.as.logging"/>
<extension module="org.jboss.as.naming"/>
<extension module="org.jboss.as.security"/>
<extension module="org.jboss.as.threads"/>
<extension module="org.jboss.as.transactions"/>
<extension module="org.jboss.as.web"/>
<!--
<extension module="org.jboss.as.weld"/>
-->
</extensions>
<profile>
<subsystem xmlns="urn:jboss:domain:logging:1.0">
<console-handler name="CONSOLE" autoflush="true">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
</console-handler>
<periodic-rotating-file-handler name="FILE" autoflush="true">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<suffix value=".yyyy-MM-dd"/>
</periodic-rotating-file-handler>
<logger category="com.arjuna">
<level name="WARN"/>
</logger>
<logger category="org.apache.tomcat.util.modeler">
<level name="WARN"/>
</logger>
<logger category="sun.rmi">
<level name="WARN"/>
</logger>
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
</subsystem>
<subsystem xmlns="urn:jboss:domain:deployment-scanner:1.0">
<deployment-scanner name="default" path="deployments" scan-enabled="true" scan-interval="5000" relative-to="jboss.server.base.dir" deployment-timeout="60"/>
</subsystem>
<subsystem xmlns="urn:jboss:domain:ee:1.0"/>
<subsystem xmlns="urn:jboss:domain:naming:1.0"/>
<subsystem xmlns="urn:jboss:domain:resource-adapters:1.0"/>
<subsystem xmlns="urn:jboss:domain:security:1.0">
<security-domains>
<security-domain name="other" cache-type="default">
<authentication>
<login-module code="UsersRoles" flag="required"/>
</authentication>
</security-domain>
</security-domains>
</subsystem>
<subsystem xmlns="urn:jboss:domain:threads:1.0"/>
<subsystem xmlns="urn:jboss:domain:transactions:1.0">
<core-environment>
<process-id>
<uuid/>
</process-id>
</core-environment>
<recovery-environment socket-binding="txn-recovery-environment" status-socket-binding="txn-status-manager"/>
<coordinator-environment default-timeout="300"/>
<object-store/>
</subsystem>
<subsystem xmlns="urn:jboss:domain:web:1.0">
<connector name="http" protocol="HTTP/1.1" socket-binding="http" scheme="http"/>
<virtual-server name="localhost" enable-welcome-root="true">
<alias name="example.com"/>
</virtual-server>
</subsystem>
<!--
<subsystem xmlns="urn:jboss:domain:weld:1.0"/>
-->
</profile>
<interfaces>
<interface name="public">
<any-address/>
</interface>
</interfaces>
<socket-binding-group name="standard-sockets" default-interface="public">
<socket-binding name="http" port="8080"/>
<socket-binding name="https" port="8443"/>
<socket-binding name="jmx-connector-registry" port="1090"/>
<socket-binding name="jmx-connector-server" port="1091"/>
<socket-binding name="jndi" port="1099"/>
<socket-binding name="osgi-http" port="8090"/>
<socket-binding name="remoting" port="4447"/>
<socket-binding name="txn-recovery-environment" port="4712"/>
<socket-binding name="txn-status-manager" port="4713"/>
</socket-binding-group>
</server>
END_OF_JCLOUDS_FILE
mkdir -p $INSTANCE_HOME
# create runscript header
cat > $INSTANCE_HOME/jboss.sh <<-'END_OF_JCLOUDS_SCRIPT'
#!/bin/bash
set +u
shopt -s xpg_echo
shopt -s expand_aliases
PROMPT_COMMAND='echo -ne \"\033]0;jboss\007\"'
export PATH=/usr/ucb/bin:/bin:/sbin:/usr/bin:/usr/sbin
export INSTANCE_NAME='jboss'
END_OF_JCLOUDS_SCRIPT
cat >> $INSTANCE_HOME/jboss.sh <<-END_OF_JCLOUDS_SCRIPT
export JBOSS_HOME='$JBOSS_HOME'
export INSTANCE_NAME='$INSTANCE_NAME'
export INSTANCE_HOME='$INSTANCE_HOME'
export LOG_DIR='$LOG_DIR'
END_OF_JCLOUDS_SCRIPT
# add desired commands from the user
cat >> $INSTANCE_HOME/jboss.sh <<-'END_OF_JCLOUDS_SCRIPT'
cd $INSTANCE_HOME
rm -f $INSTANCE_HOME/rc
trap 'echo $?>$INSTANCE_HOME/rc' 0 1 2 3 15
java -server -Xms128m -Xmx128m -XX:MaxPermSize=128m -Djava.net.preferIPv4Stack=true -XX:+UseFastAccessorMethods -XX:+TieredCompilation -Xverify:none -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.modules.system.pkgs=org.jboss.byteman -Dorg.jboss.boot.log.file=$JBOSS_HOME/standalone/log/boot.log -Dlogging.configuration=file:$JBOSS_HOME/standalone/configuration/logging.properties -jar $JBOSS_HOME/jboss-modules.jar -mp $JBOSS_HOME/modules -logmodule org.jboss.logmanager -jaxpmodule javax.xml.jaxp-provider org.jboss.as.standalone -Djboss.home.dir=$JBOSS_HOME --server-config=standalone-custom.xml
END_OF_JCLOUDS_SCRIPT
# add runscript footer
cat >> $INSTANCE_HOME/jboss.sh <<-'END_OF_JCLOUDS_SCRIPT'
exit $?
END_OF_JCLOUDS_SCRIPT
chmod u+x $INSTANCE_HOME/jboss.sh
;;
status)
default || exit 1
findPid $INSTANCE_NAME || exit 1
echo $FOUND_PID
;;
stop)
default || exit 1
findPid $INSTANCE_NAME || exit 1
[ -n "$FOUND_PID" ] && {
echo stopping $FOUND_PID
kill -9 $FOUND_PID
}
;;
start)
default || exit 1
forget $INSTANCE_NAME $INSTANCE_HOME/$INSTANCE_NAME.sh $LOG_DIR || exit 1
;;
stdout)
default || exit 1
cat $LOG_DIR/stdout.log
;;
stderr)
default || exit 1
cat $LOG_DIR/stderr.log
;;
exitstatus)
default || exit 1
[ -f $LOG_DIR/rc ] && cat $LOG_DIR/rc;;
tail)
default || exit 1
tail $LOG_DIR/stdout.log
;;
tailerr)
default || exit 1
tail $LOG_DIR/stderr.log
;;
run)
default || exit 1
$INSTANCE_HOME/$INSTANCE_NAME.sh
;;
esac
exit $?

View File

@ -1,103 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<server name="basic" xmlns="urn:jboss:domain:1.0">
<extensions>
<extension module="org.jboss.as.connector"/>
<extension module="org.jboss.as.deployment-scanner"/>
<extension module="org.jboss.as.ee"/>
<extension module="org.jboss.as.logging"/>
<extension module="org.jboss.as.naming"/>
<extension module="org.jboss.as.security"/>
<extension module="org.jboss.as.threads"/>
<extension module="org.jboss.as.transactions"/>
<extension module="org.jboss.as.web"/>
<!--
<extension module="org.jboss.as.weld"/>
-->
</extensions>
<profile>
<subsystem xmlns="urn:jboss:domain:logging:1.0">
<console-handler name="CONSOLE" autoflush="true">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
</console-handler>
<periodic-rotating-file-handler name="FILE" autoflush="true">
<level name="INFO"/>
<formatter>
<pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<suffix value=".yyyy-MM-dd"/>
</periodic-rotating-file-handler>
<logger category="com.arjuna">
<level name="WARN"/>
</logger>
<logger category="org.apache.tomcat.util.modeler">
<level name="WARN"/>
</logger>
<logger category="sun.rmi">
<level name="WARN"/>
</logger>
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
</subsystem>
<subsystem xmlns="urn:jboss:domain:deployment-scanner:1.0">
<deployment-scanner name="default" path="deployments" scan-enabled="true" scan-interval="5000" relative-to="jboss.server.base.dir" deployment-timeout="60"/>
</subsystem>
<subsystem xmlns="urn:jboss:domain:ee:1.0"/>
<subsystem xmlns="urn:jboss:domain:naming:1.0"/>
<subsystem xmlns="urn:jboss:domain:resource-adapters:1.0"/>
<subsystem xmlns="urn:jboss:domain:security:1.0">
<security-domains>
<security-domain name="other" cache-type="default">
<authentication>
<login-module code="UsersRoles" flag="required"/>
</authentication>
</security-domain>
</security-domains>
</subsystem>
<subsystem xmlns="urn:jboss:domain:threads:1.0"/>
<subsystem xmlns="urn:jboss:domain:transactions:1.0">
<core-environment>
<process-id>
<uuid/>
</process-id>
</core-environment>
<recovery-environment socket-binding="txn-recovery-environment" status-socket-binding="txn-status-manager"/>
<coordinator-environment default-timeout="300"/>
<object-store/>
</subsystem>
<subsystem xmlns="urn:jboss:domain:web:1.0">
<connector name="http" protocol="HTTP/1.1" socket-binding="http" scheme="http"/>
<virtual-server name="localhost" enable-welcome-root="true">
<alias name="example.com"/>
</virtual-server>
</subsystem>
<!--
<subsystem xmlns="urn:jboss:domain:weld:1.0"/>
-->
</profile>
<interfaces>
<interface name="public">
<any-address/>
</interface>
</interfaces>
<socket-binding-group name="standard-sockets" default-interface="public">
<socket-binding name="http" port="8080"/>
<socket-binding name="https" port="8443"/>
<socket-binding name="jmx-connector-registry" port="1090"/>
<socket-binding name="jmx-connector-server" port="1091"/>
<socket-binding name="jndi" port="1099"/>
<socket-binding name="osgi-http" port="8090"/>
<socket-binding name="remoting" port="4447"/>
<socket-binding name="txn-recovery-environment" port="4712"/>
<socket-binding name="txn-status-manager" port="4713"/>
</socket-binding-group>
</server>

View File

@ -19,17 +19,8 @@
package org.jclouds.nodepool;
import static com.google.common.collect.Iterables.getOnlyElement;
import static java.lang.String.format;
import static java.util.logging.Logger.getAnonymousLogger;
import static org.jclouds.compute.RunScriptData.JBOSS_HOME;
import static org.jclouds.compute.RunScriptData.installAdminUserJBossAndOpenPorts;
import static org.jclouds.compute.RunScriptData.startJBoss;
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_PORT_OPEN;
import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_SCRIPT_COMPLETE;
import static org.jclouds.compute.options.RunScriptOptions.Builder.nameTask;
import static org.jclouds.compute.options.TemplateOptions.Builder.inboundPorts;
import static org.jclouds.compute.options.TemplateOptions.Builder.runAsRoot;
import static org.jclouds.nodepool.config.NodePoolProperties.BASEDIR;
import static org.jclouds.nodepool.config.NodePoolProperties.MAX_SIZE;
import static org.jclouds.nodepool.config.NodePoolProperties.MIN_SIZE;
@ -41,12 +32,8 @@ import static org.testng.Assert.assertTrue;
import java.util.NoSuchElementException;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.RunScriptData;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
import org.jclouds.compute.predicates.NodePredicates;
@ -54,13 +41,9 @@ import org.jclouds.logging.config.LoggingModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.rest.AuthorizationException;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.jclouds.util.Strings2;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.common.io.Closeables;
@ -108,74 +91,7 @@ public class NodePoolComputeServiceLiveTest extends BaseComputeServiceLiveTest {
@Override
@Test(enabled = true, groups = "live")
public void testCreateAndRunAService() throws Exception {
final String configuration = Strings2.toStringAndClose(RunScriptData.class
.getResourceAsStream("/standalone-basic.xml"));
ImmutableMap<String, String> userMetadata = ImmutableMap.<String, String> of("Name", group);
ImmutableSet<String> tags = ImmutableSet.of(group);
Stopwatch watch = new Stopwatch().start();
NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, inboundPorts(22, 8080)
.blockOnPort(22, 300).userMetadata(userMetadata).tags(tags)));
long createSeconds = watch.elapsedTime(TimeUnit.SECONDS);
final String nodeId = node.getId();
checkUserMetadataInNodeEquals(node, userMetadata);
checkTagsInNodeEquals(node, tags);
getAnonymousLogger().info(
format("<< available node(%s) os(%s) in %ss", node.getId(), node.getOperatingSystem(), createSeconds));
watch.reset().start();
// note this is a dependency on the template resolution so we have the
// right process per
// operating system. moreover, we wish this to run as root, so that it
// can change ip
// tables rules and setup our admin user
client.runScriptOnNode(nodeId, installAdminUserJBossAndOpenPorts(node.getOperatingSystem()),
nameTask("configure-jboss"));
long configureSeconds = watch.elapsedTime(TimeUnit.SECONDS);
getAnonymousLogger()
.info(format("<< configured node(%s) with %s and JBoss %s in %ss",
nodeId,
exec(nodeId, "java -fullversion"),
// version of the jboss jar
exec(nodeId,
format("ls %s/bundles/org/jboss/as/osgi/configadmin/main|sed -e 's/.*-//g' -e 's/.jar//g'",
JBOSS_HOME)), configureSeconds));
trackAvailabilityOfProcessOnNode(view.utils().userExecutor().submit(new Callable<ExecResponse>() {
@Override
public ExecResponse call() {
return client.runScriptOnNode(nodeId, startJBoss(configuration), runAsRoot(false).blockOnComplete(false)
.nameTask("jboss"));
}
@Override
public String toString() {
return "initial start of jboss";
}
}), "jboss", node, JBOSS_PATTERN);
client.runScriptOnNode(nodeId, "/tmp/init-jboss stop", runAsRoot(false).wrapInInitScript(false));
trackAvailabilityOfProcessOnNode(view.utils().userExecutor().submit(new Callable<ExecResponse>() {
@Override
public ExecResponse call() {
return client.runScriptOnNode(nodeId, "/tmp/init-jboss start", runAsRoot(false).wrapInInitScript(false));
}
@Override
public String toString() {
return "warm start of jboss";
}
}), "jboss", node, JBOSS_PATTERN);
createAndRunAServiceInGroup(group);
}
@Test(enabled = true, groups = "live", dependsOnMethods = "testCreateAndRunAService")