refactored boot script to check if java is installed first, and also stream jboss so that it works with small vms

This commit is contained in:
Adrian Cole 2010-09-28 23:56:05 +01:00
parent 47697d6f7e
commit 546535340f
12 changed files with 256 additions and 200 deletions

View File

@ -19,7 +19,7 @@
package org.jclouds.aws; package org.jclouds.aws;
import static org.jclouds.compute.BaseComputeServiceLiveTest.buildScript; import static org.jclouds.compute.ComputeTestUtils.buildScript;
import static org.jclouds.compute.options.TemplateOptions.Builder.runScript; import static org.jclouds.compute.options.TemplateOptions.Builder.runScript;
import static org.jclouds.compute.util.ComputeServiceUtils.execHttpResponse; import static org.jclouds.compute.util.ComputeServiceUtils.execHttpResponse;
import static org.jclouds.compute.util.ComputeServiceUtils.extractTargzIntoDirectory; import static org.jclouds.compute.util.ComputeServiceUtils.extractTargzIntoDirectory;
@ -89,8 +89,8 @@ public class ComputeAndBlobStoreTogetherHappilyLiveTest extends BlobStoreAndComp
// if we want to, we can mix and match batched and ad-hoc commands, such as extracting maven // if we want to, we can mix and match batched and ad-hoc commands, such as extracting maven
String mavenVersion = "3.0-beta-3"; String mavenVersion = "3.0-beta-3";
Statement extractMavenIntoUsrLocal = extractTargzIntoDirectory(URI Statement extractMavenIntoUsrLocal = extractTargzIntoDirectory(
.create("http://mirrors.ibiblio.org/pub/mirrors/apache//maven/binaries/apache-maven-" + mavenVersion URI.create("http://mirrors.ibiblio.org/pub/mirrors/apache//maven/binaries/apache-maven-" + mavenVersion
+ "-bin.tar.gz"), "/usr/local"); + "-bin.tar.gz"), "/usr/local");
// have both of these commands occur on boot // have both of these commands occur on boot

View File

@ -21,6 +21,7 @@ package org.jclouds.aws.ec2.compute;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.get; import static com.google.common.collect.Iterables.get;
import static org.jclouds.compute.ComputeTestUtils.setupKeyPair;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
@ -31,7 +32,6 @@ import org.jclouds.Constants;
import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.blobstore.BlobStoreContext;
import org.jclouds.blobstore.BlobStoreContextFactory; import org.jclouds.blobstore.BlobStoreContextFactory;
import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.Blob;
import org.jclouds.compute.BaseComputeServiceLiveTest;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
@ -80,16 +80,17 @@ public class BlobStoreAndComputeServiceLiveTest {
} }
protected void setupKeyPairForTest() throws FileNotFoundException, IOException { protected void setupKeyPairForTest() throws FileNotFoundException, IOException {
keyPair = BaseComputeServiceLiveTest.setupKeyPair(); keyPair = setupKeyPair();
} }
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupClient() throws FileNotFoundException, IOException { public void setupClient() throws FileNotFoundException, IOException {
setupKeyPairForTest(); setupKeyPairForTest();
computeContext = new ComputeServiceContextFactory().createContext(computeServiceProvider, ImmutableSet.of( computeContext = new ComputeServiceContextFactory().createContext(computeServiceProvider,
new Log4JLoggingModule(), new JschSshClientModule()), setupCredentials(computeServiceProvider)); ImmutableSet.of(new Log4JLoggingModule(), new JschSshClientModule()),
blobContext = new BlobStoreContextFactory().createContext(blobStoreProvider, ImmutableSet setupCredentials(computeServiceProvider));
.of(new Log4JLoggingModule()), setupCredentials(blobStoreProvider)); blobContext = new BlobStoreContextFactory().createContext(blobStoreProvider,
ImmutableSet.of(new Log4JLoggingModule()), setupCredentials(blobStoreProvider));
blobContext.getAsyncBlobStore().createContainerInLocation(null, tag); blobContext.getAsyncBlobStore().createContainerInLocation(null, tag);
computeContext.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); computeContext.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
} }
@ -98,8 +99,8 @@ public class BlobStoreAndComputeServiceLiveTest {
for (NodeMetadata node : nodes) { for (NodeMetadata node : nodes) {
IPSocket socket = new IPSocket(get(node.getPublicAddresses(), 0), 22); IPSocket socket = new IPSocket(get(node.getPublicAddresses(), 0), 22);
SshClient ssh = computeContext.utils().sshFactory().create(socket, node.getCredentials().identity, SshClient ssh = computeContext.utils().sshFactory()
node.getCredentials().credential.getBytes()); .create(socket, node.getCredentials().identity, node.getCredentials().credential.getBytes());
try { try {
ssh.connect(); ssh.connect();
ExecResponse exec = ssh.exec(cmd); ExecResponse exec = ssh.exec(cmd);

View File

@ -20,7 +20,13 @@
package org.jclouds.aws.ec2.services; package org.jclouds.aws.ec2.services;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.io.Payloads.newStringPayload; import static com.google.common.collect.Iterables.any;
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.jclouds.compute.ComputeTestUtils.setupKeyPair;
import static org.jclouds.scriptbuilder.domain.Statements.exec;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
@ -41,7 +47,6 @@ import org.jclouds.aws.ec2.domain.PlacementGroup;
import org.jclouds.aws.ec2.domain.PlacementGroup.State; import org.jclouds.aws.ec2.domain.PlacementGroup.State;
import org.jclouds.aws.ec2.predicates.PlacementGroupAvailable; import org.jclouds.aws.ec2.predicates.PlacementGroupAvailable;
import org.jclouds.aws.ec2.predicates.PlacementGroupDeleted; import org.jclouds.aws.ec2.predicates.PlacementGroupDeleted;
import org.jclouds.compute.BaseComputeServiceLiveTest;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.RunNodesException; import org.jclouds.compute.RunNodesException;
@ -59,9 +64,6 @@ import org.testng.annotations.Test;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.inject.Module; import com.google.inject.Module;
/** /**
@ -108,9 +110,9 @@ public class PlacementGroupClientLiveTest {
public void setupClient() throws FileNotFoundException, IOException { public void setupClient() throws FileNotFoundException, IOException {
setupCredentials(); setupCredentials();
Properties overrides = setupProperties(); Properties overrides = setupProperties();
context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet context = new ComputeServiceContextFactory().createContext(provider,
.<Module> of(new Log4JLoggingModule()), overrides); ImmutableSet.<Module> of(new Log4JLoggingModule()), overrides);
keyPair = BaseComputeServiceLiveTest.setupKeyPair(); keyPair = setupKeyPair();
client = EC2Client.class.cast(context.getProviderSpecificContext().getApi()); client = EC2Client.class.cast(context.getProviderSpecificContext().getApi());
@ -122,13 +124,13 @@ public class PlacementGroupClientLiveTest {
@Test @Test
void testDescribe() { void testDescribe() {
for (String region : Lists.newArrayList(Region.US_EAST_1)) { for (String region : newArrayList(Region.US_EAST_1)) {
SortedSet<PlacementGroup> allResults = Sets.newTreeSet(client.getPlacementGroupServices() SortedSet<PlacementGroup> allResults = newTreeSet(client.getPlacementGroupServices()
.describePlacementGroupsInRegion(region)); .describePlacementGroupsInRegion(region));
assertNotNull(allResults); assertNotNull(allResults);
if (allResults.size() >= 1) { if (allResults.size() >= 1) {
PlacementGroup group = allResults.last(); PlacementGroup group = allResults.last();
SortedSet<PlacementGroup> result = Sets.newTreeSet(client.getPlacementGroupServices() SortedSet<PlacementGroup> result = newTreeSet(client.getPlacementGroupServices()
.describePlacementGroupsInRegion(region, group.getName())); .describePlacementGroupsInRegion(region, group.getName()));
assertNotNull(result); assertNotNull(result);
PlacementGroup compare = result.last(); PlacementGroup compare = result.last();
@ -136,7 +138,7 @@ public class PlacementGroupClientLiveTest {
} }
} }
for (String region : Lists.newArrayList(Region.EU_WEST_1, Region.US_WEST_1, Region.AP_SOUTHEAST_1)) { for (String region : newArrayList(Region.EU_WEST_1, Region.US_WEST_1, Region.AP_SOUTHEAST_1)) {
try { try {
client.getPlacementGroupServices().describePlacementGroupsInRegion(region); client.getPlacementGroupServices().describePlacementGroupsInRegion(region);
assert false : "should be unsupported"; assert false : "should be unsupported";
@ -169,7 +171,7 @@ public class PlacementGroupClientLiveTest {
public void testStartCCInstance() throws Exception { public void testStartCCInstance() throws Exception {
Set<? extends Hardware> sizes = context.getComputeService().listHardwareProfiles(); Set<? extends Hardware> sizes = context.getComputeService().listHardwareProfiles();
assert Iterables.any(sizes, new Predicate<Hardware>() { assert any(sizes, new Predicate<Hardware>() {
@Override @Override
public boolean apply(Hardware arg0) { public boolean apply(Hardware arg0) {
@ -178,7 +180,7 @@ public class PlacementGroupClientLiveTest {
}) : sizes; }) : sizes;
Set<? extends Image> images = context.getComputeService().listImages(); Set<? extends Image> images = context.getComputeService().listImages();
assert Iterables.any(images, new Predicate<Image>() { assert any(images, new Predicate<Image>() {
@Override @Override
public boolean apply(Image arg0) { public boolean apply(Image arg0) {
@ -193,18 +195,16 @@ public class PlacementGroupClientLiveTest {
assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17"); assertEquals(template.getImage().getId(), "us-east-1/ami-7ea24a17");
template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public")) template.getOptions().installPrivateKey(keyPair.get("private")).authorizePublicKey(keyPair.get("public"))
.runScript( .runScript(exec(buildScript(template.getImage().getOperatingSystem())));
newStringPayload(BaseComputeServiceLiveTest.buildScript(template.getImage()
.getOperatingSystem())));
String tag = PREFIX + "cccluster"; String tag = PREFIX + "cccluster";
context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag)); context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
try { try {
Set<? extends NodeMetadata> nodes = context.getComputeService().runNodesWithTag(tag, 1, template); Set<? extends NodeMetadata> nodes = context.getComputeService().runNodesWithTag(tag, 1, template);
NodeMetadata node = Iterables.getOnlyElement(nodes); NodeMetadata node = getOnlyElement(nodes);
Iterables.getOnlyElement(Iterables.getOnlyElement(client.getInstanceServices().describeInstancesInRegion(null, getOnlyElement(getOnlyElement(client.getInstanceServices().describeInstancesInRegion(null,
node.getProviderId()))); node.getProviderId())));
} catch (RunNodesException e) { } catch (RunNodesException e) {

View File

@ -162,11 +162,12 @@
<priority value="DEBUG" /> <priority value="DEBUG" />
<appender-ref ref="ASYNCSSH" /> <appender-ref ref="ASYNCSSH" />
</category> </category>
<!--
<category name="jclouds.wire"> <category name="jclouds.wire">
<priority value="DEBUG" /> <priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" /> <appender-ref ref="ASYNCWIRE" />
</category> </category>
-->
<category name="jclouds.blobstore"> <category name="jclouds.blobstore">
<priority value="DEBUG" /> <priority value="DEBUG" />
<appender-ref ref="ASYNCBLOBSTORE" /> <appender-ref ref="ASYNCBLOBSTORE" />

View File

@ -30,6 +30,7 @@ import static com.google.common.collect.Maps.newLinkedHashMap;
import static com.google.common.collect.Maps.uniqueIndex; import static com.google.common.collect.Maps.uniqueIndex;
import static com.google.common.collect.Sets.filter; import static com.google.common.collect.Sets.filter;
import static com.google.common.collect.Sets.newTreeSet; import static com.google.common.collect.Sets.newTreeSet;
import static org.jclouds.compute.ComputeTestUtils.buildScript;
import static org.jclouds.compute.options.TemplateOptions.Builder.blockOnComplete; import static org.jclouds.compute.options.TemplateOptions.Builder.blockOnComplete;
import static org.jclouds.compute.options.TemplateOptions.Builder.overrideCredentialsWith; import static org.jclouds.compute.options.TemplateOptions.Builder.overrideCredentialsWith;
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED; import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
@ -41,10 +42,8 @@ import static org.jclouds.io.Payloads.newStringPayload;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -67,7 +66,6 @@ import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.predicates.OperatingSystemPredicates;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
@ -79,16 +77,12 @@ import org.jclouds.rest.AuthorizationException;
import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshException; import org.jclouds.ssh.SshException;
import org.jclouds.util.Utils;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Charsets;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.io.Files;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Module; import com.google.inject.Module;
@ -119,21 +113,7 @@ public abstract class BaseComputeServiceLiveTest {
} }
protected void setupKeyPairForTest() throws FileNotFoundException, IOException { protected void setupKeyPairForTest() throws FileNotFoundException, IOException {
keyPair = setupKeyPair(); keyPair = ComputeTestUtils.setupKeyPair();
}
public static Map<String, String> setupKeyPair() throws FileNotFoundException, IOException {
String secretKeyFile;
try {
secretKeyFile = checkNotNull(System.getProperty("test.ssh.keyfile"), "test.ssh.keyfile");
} catch (NullPointerException e) {
secretKeyFile = System.getProperty("user.home") + "/.ssh/id_rsa";
}
checkSecretKeyFile(secretKeyFile);
String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8);
assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret;
return ImmutableMap.<String, String> of("private", secret, "public", Files.toString(new File(secretKeyFile
+ ".pub"), Charsets.UTF_8));
} }
protected String provider; protected String provider;
@ -178,18 +158,11 @@ public abstract class BaseComputeServiceLiveTest {
if (context != null) if (context != null)
context.close(); context.close();
Properties props = setupProperties(); Properties props = setupProperties();
context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet.of(new Log4JLoggingModule(), context = new ComputeServiceContextFactory().createContext(provider,
getSshModule()), props); ImmutableSet.of(new Log4JLoggingModule(), getSshModule()), props);
client = context.getComputeService(); client = context.getComputeService();
} }
private static void checkSecretKeyFile(String secretKeyFile) throws FileNotFoundException {
Utils.checkNotEmpty(secretKeyFile, "System property: [test.ssh.keyfile] set to an empty string");
if (!new File(secretKeyFile).exists()) {
throw new FileNotFoundException("secretKeyFile not found at: " + secretKeyFile);
}
}
abstract protected Module getSshModule(); abstract protected Module getSshModule();
// wait up to 5 seconds for an auth exception // wait up to 5 seconds for an auth exception
@ -197,8 +170,8 @@ public abstract class BaseComputeServiceLiveTest {
public void testCorrectAuthException() throws Exception { public void testCorrectAuthException() throws Exception {
ComputeServiceContext context = null; ComputeServiceContext context = null;
try { try {
context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA", ImmutableSet context = new ComputeServiceContextFactory().createContext(provider, "MOMMA", "MIA",
.<Module> of(new Log4JLoggingModule())); ImmutableSet.<Module> of(new Log4JLoggingModule()));
context.getComputeService().listNodes(); context.getComputeService().listNodes();
} catch (AuthorizationException e) { } catch (AuthorizationException e) {
throw e; throw e;
@ -273,25 +246,24 @@ public abstract class BaseComputeServiceLiveTest {
} }
template = client.templateBuilder().options(blockOnComplete(false).blockOnPort(8080, 300).inboundPorts(22, 8080)) template = client.templateBuilder().options(blockOnComplete(false).blockOnPort(8080, 600).inboundPorts(22, 8080))
.build(); .build();
// note this is a dependency on the template resolution // note this is a dependency on the template resolution
template.getOptions().runScript( template.getOptions().runScript(
RunScriptData.createScriptInstallAndStartJBoss(keyPair.get("public"), template.getImage() RunScriptData.createScriptInstallAndStartJBoss(keyPair.get("public"), template.getImage()
.getOperatingSystem())); .getOperatingSystem()));
try { try {
TreeSet<NodeMetadata> nodes = newTreeSet(client.runNodesWithTag(tag, 1, template)); NodeMetadata node = getOnlyElement(client.runNodesWithTag(tag, 1, template));
checkHttpGet(nodes); checkHttpGet(node);
} finally { } finally {
client.destroyNodesMatching(withTag(tag)); client.destroyNodesMatching(withTag(tag));
} }
} }
protected void checkHttpGet(TreeSet<NodeMetadata> nodes) { protected void checkHttpGet(NodeMetadata node) {
assert context.utils().http().get( ComputeTestUtils.checkHttpGet(context.utils().http(), node, 8080);
URI.create(String.format("http://%s:8080", get(nodes.last().getPublicAddresses(), 0)))) != null;
} }
@Test(enabled = true, dependsOnMethods = "testCreateAndRunAService") @Test(enabled = true, dependsOnMethods = "testCreateAndRunAService")
@ -338,8 +310,8 @@ public abstract class BaseComputeServiceLiveTest {
protected void checkOsMatchesTemplate(NodeMetadata node) { protected void checkOsMatchesTemplate(NodeMetadata node) {
if (node.getOperatingSystem() != null) if (node.getOperatingSystem() != null)
assert node.getOperatingSystem().getFamily().equals(template.getImage().getOperatingSystem().getFamily()) : String assert node.getOperatingSystem().getFamily().equals(template.getImage().getOperatingSystem().getFamily()) : String
.format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(), node .format("expecting family %s but got %s", template.getImage().getOperatingSystem().getFamily(),
.getOperatingSystem()); node.getOperatingSystem());
} }
void assertLocationSameOrChild(Location test, Location expected) { void assertLocationSameOrChild(Location test, Location expected) {
@ -393,21 +365,10 @@ public abstract class BaseComputeServiceLiveTest {
return templateBuilder.build(); return templateBuilder.build();
} }
public static String buildScript(OperatingSystem os) {
if (OperatingSystemPredicates.supportsApt().apply(os))
return RunScriptData.APT_RUN_SCRIPT;
else if (OperatingSystemPredicates.supportsYum().apply(os))
return RunScriptData.YUM_RUN_SCRIPT;
else if (OperatingSystemPredicates.supportsZypper().apply(os))
return RunScriptData.ZYPPER_RUN_SCRIPT;
else
throw new IllegalArgumentException("don't know how to handle" + os.toString());
}
@Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired") @Test(enabled = true, dependsOnMethods = "testCreateAnotherNodeWithANewContextToEnsureSharedMemIsntRequired")
public void testGet() throws Exception { public void testGet() throws Exception {
Map<String, ? extends NodeMetadata> metadataMap = newLinkedHashMap(uniqueIndex(filter(client Map<String, ? extends NodeMetadata> metadataMap = newLinkedHashMap(uniqueIndex(
.listNodesDetailsMatching(all()), and(withTag(tag), not(TERMINATED))), filter(client.listNodesDetailsMatching(all()), and(withTag(tag), not(TERMINATED))),
new Function<NodeMetadata, String>() { new Function<NodeMetadata, String>() {
@Override @Override
@ -600,8 +561,11 @@ public abstract class BaseComputeServiceLiveTest {
// a socket conection // a socket conection
// state. // state.
SshClient ssh = (node.getCredentials().credential != null && !node.getCredentials().credential SshClient ssh = (node.getCredentials().credential != null && !node.getCredentials().credential
.startsWith("-----BEGIN RSA PRIVATE KEY-----")) ? context.utils().sshFactory().create(socket, .startsWith("-----BEGIN RSA PRIVATE KEY-----")) ? context.utils().sshFactory()
node.getCredentials().identity, node.getCredentials().credential) : context.utils().sshFactory().create( .create(socket, node.getCredentials().identity, node.getCredentials().credential) : context
.utils()
.sshFactory()
.create(
socket, socket,
node.getCredentials().identity, node.getCredentials().identity,
node.getCredentials().credential != null ? node.getCredentials().credential.getBytes() : keyPair.get( node.getCredentials().credential != null ? node.getCredentials().credential.getBytes() : keyPair.get(
@ -611,7 +575,7 @@ public abstract class BaseComputeServiceLiveTest {
ExecResponse hello = ssh.exec("echo hello"); ExecResponse hello = ssh.exec("echo hello");
assertEquals(hello.getOutput().trim(), "hello"); assertEquals(hello.getOutput().trim(), "hello");
ExecResponse exec = ssh.exec("java -version"); ExecResponse exec = ssh.exec("java -version");
assert exec.getError().indexOf("OpenJDK") != -1 || exec.getOutput().indexOf("OpenJDK") != -1 : exec; assert exec.getError().indexOf("1.6") != -1 || exec.getOutput().indexOf("1.6") != -1 : exec;
} finally { } finally {
if (ssh != null) if (ssh != null)
ssh.disconnect(); ssh.disconnect();

View File

@ -0,0 +1,94 @@
/**
*
* Copyright (C) 2010 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.compute;
import static org.jclouds.util.Utils.checkNotEmpty;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import static org.testng.Assert.assertEquals;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.predicates.OperatingSystemPredicates;
import org.jclouds.rest.HttpClient;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files;
import static com.google.common.collect.Iterables.get;
/**
* utilities helpful in testing compute providers
*
* @author Adrian Cole
*/
public class ComputeTestUtils {
public static String buildScript(OperatingSystem os) {
if (OperatingSystemPredicates.supportsApt().apply(os))
return RunScriptData.APT_RUN_SCRIPT;
else if (OperatingSystemPredicates.supportsYum().apply(os))
return RunScriptData.YUM_RUN_SCRIPT;
else if (OperatingSystemPredicates.supportsZypper().apply(os))
return RunScriptData.ZYPPER_RUN_SCRIPT;
else
throw new IllegalArgumentException("don't know how to handle" + os.toString());
}
public static Map<String, String> setupKeyPair() throws FileNotFoundException, IOException {
String secretKeyFile;
try {
secretKeyFile = checkNotNull(System.getProperty("test.ssh.keyfile"), "test.ssh.keyfile");
} catch (NullPointerException e) {
secretKeyFile = System.getProperty("user.home") + "/.ssh/id_rsa";
}
checkSecretKeyFile(secretKeyFile);
String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8);
assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret;
return ImmutableMap.<String, String> of("private", secret, "public",
Files.toString(new File(secretKeyFile + ".pub"), Charsets.UTF_8));
}
public static void checkSecretKeyFile(String secretKeyFile) throws FileNotFoundException {
checkNotEmpty(secretKeyFile, "System property: [test.ssh.keyfile] set to an empty string");
if (!new File(secretKeyFile).exists()) {
throw new FileNotFoundException("secretKeyFile not found at: " + secretKeyFile);
}
}
public static void checkHttpGet(HttpClient client, NodeMetadata node, int port) {
for (int i = 0; i < 5; i++)
try {
assert client.get(URI.create(String.format("http://%s:%d", get(node.getPublicAddresses(), 0), port))) != null;
break;
} catch (UndeclaredThrowableException e) {
assertEquals(e.getCause().getClass(), TimeoutException.class);
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
}
}
}
}

View File

@ -19,7 +19,7 @@
package org.jclouds.compute; package org.jclouds.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.extractZipIntoDirectory; import static org.jclouds.compute.util.ComputeServiceUtils.extractTargzIntoDirectory;
import static org.jclouds.scriptbuilder.domain.Statements.exec; import static org.jclouds.scriptbuilder.domain.Statements.exec;
import static org.jclouds.scriptbuilder.domain.Statements.interpret; import static org.jclouds.scriptbuilder.domain.Statements.interpret;
@ -40,8 +40,7 @@ import com.google.common.collect.ImmutableMap;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class RunScriptData { public class RunScriptData {
private static String jbossVersion = "5.0.0.CR2";
private static String jboss = String.format("jboss-%s-jdk6", jbossVersion);
private static String jbossHome = "/usr/local/jboss"; private static String jbossHome = "/usr/local/jboss";
public static String createScriptInstallBase(OperatingSystem os) { public static String createScriptInstallBase(OperatingSystem os) {
@ -62,11 +61,14 @@ public class RunScriptData {
jbossHome, jbossHome,
jbossHome, jbossHome,
envVariables, envVariables,
ImmutableList.<Statement> of(new AuthorizeRSAPublicKey(publicKey), exec(createScriptInstallBase(os)), ImmutableList.<Statement> of(
extractZipIntoDirectory(URI.create(String.format( new AuthorizeRSAPublicKey(publicKey),
"http://superb-sea2.dl.sourceforge.net/project/jboss/JBoss/JBoss-%s/%s.zip", exec(createScriptInstallBase(os)),
jbossVersion, jboss)), "/usr/local"), exec("{md} " + jbossHome), exec("rm -rf /var/cache/apt /usr/lib/vmware-tools"),// jeos hasn't enough room!
exec("mv /usr/local/jboss-" + jbossVersion + "/* " + jbossHome)), extractTargzIntoDirectory(
URI.create("http://commondatastorage.googleapis.com/jclouds-repo/jboss-as-distribution-6.0.0.20100911-M5.tar.gz"),
"/usr/local"), exec("{md} " + jbossHome), exec("mv /usr/local/jboss-*/* " + jbossHome),
exec("chmod -R oug+r+w " + jbossHome)),
ImmutableList ImmutableList
.<Statement> of(interpret("java -Xms128m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.endorsed.dirs=lib/endorsed -classpath bin/run.jar org.jboss.Main -b 0.0.0.0"))); .<Statement> of(interpret("java -Xms128m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.endorsed.dirs=lib/endorsed -classpath bin/run.jar org.jboss.Main -b 0.0.0.0")));
return toReturn; return toReturn;
@ -77,33 +79,30 @@ public class RunScriptData {
.append("cp /etc/apt/sources.list /etc/apt/sources.list.old\n")// .append("cp /etc/apt/sources.list /etc/apt/sources.list.old\n")//
.append( .append(
"sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list\n")// "sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list\n")//
.append("apt-get update -y -qq\n")// .append("which curl || apt-get update -y -qq && apt-get install -f -y -qq --force-yes curl\n")//
.append("apt-get install -f -y -qq --force-yes curl\n")// .append(
.append("apt-get install -f -y -qq --force-yes unzip\n")// "(which java && java -fullversion 2>&1|egrep -q 1.6 ) || apt-get install -f -y -qq --force-yes openjdk-6-jre\n")//
.append("apt-get install -f -y -qq --force-yes openjdk-6-jdk\n")// .append("rm -rf /var/cache/apt /usr/lib/vmware-tools\n")// jeos hasn't enough room!
.toString(); .toString();
public static final String YUM_RUN_SCRIPT = new StringBuilder() public static final String YUM_RUN_SCRIPT = new StringBuilder()
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n") .append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n") //
// .append("echo \"[jdkrepo]\" >> /etc/yum.repos.d/CentOS-Base.repo\n") //
.append("echo \"[jdkrepo]\" >> /etc/yum.repos.d/CentOS-Base.repo\n") .append("echo \"name=jdkrepository\" >> /etc/yum.repos.d/CentOS-Base.repo\n") //
//
.append("echo \"name=jdkrepository\" >> /etc/yum.repos.d/CentOS-Base.repo\n")
//
.append( .append(
"echo \"baseurl=http://ec2-us-east-mirror.rightscale.com/epel/5/i386/\" >> /etc/yum.repos.d/CentOS-Base.repo\n")// "echo \"baseurl=http://ec2-us-east-mirror.rightscale.com/epel/5/i386/\" >> /etc/yum.repos.d/CentOS-Base.repo\n")//
.append("echo \"enabled=1\" >> /etc/yum.repos.d/CentOS-Base.repo\n")// .append("echo \"enabled=1\" >> /etc/yum.repos.d/CentOS-Base.repo\n")//
.append("yum --nogpgcheck -y install unzip\n")// // .append("which unzip ||yum --nogpgcheck -y install unzip\n")//
.append("yum --nogpgcheck -y install curl\n")// .append("which curl ||yum --nogpgcheck -y install curl\n")//
.append("yum --nogpgcheck -y install java-1.6.0-openjdk\n")// .append(
"(which java && java -fullversion 2>&1|egrep -q 1.6 ) || yum --nogpgcheck -y install java-1.6.0-openjdk&&")//
.append("echo \"export PATH=\\\"/usr/lib/jvm/jre-1.6.0-openjdk/bin/:\\$PATH\\\"\" >> /root/.bashrc\n")// .append("echo \"export PATH=\\\"/usr/lib/jvm/jre-1.6.0-openjdk/bin/:\\$PATH\\\"\" >> /root/.bashrc\n")//
.toString(); .toString();
public static final String ZYPPER_RUN_SCRIPT = new StringBuilder()// public static final String ZYPPER_RUN_SCRIPT = new StringBuilder()//
.append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")// .append("echo nameserver 208.67.222.222 >> /etc/resolv.conf\n")//
.append("sudo zypper install unzip\n")// // .append("which unzip ||sudo zypper install unzip\n")//
.append("sudo zypper install curl\n")// .append("which curl || zypper install curl\n")//
.append("sudo zypper install java-1.6.0-openjdk-devl\n")// .append("(which java && java -fullversion 2>&1|egrep -q 1.6 ) || zypper install java-1.6.0-openjdk\n")//
.toString(); .toString();
} }

View File

@ -32,7 +32,6 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Set; import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -105,7 +104,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
} }
@Override @Override
protected void checkHttpGet(TreeSet<NodeMetadata> nodes) { protected void checkHttpGet(NodeMetadata node) {
} }
@ -228,7 +227,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
client.connect(); client.connect();
expect(client.exec("echo hello")).andReturn(new ExecResponse("hello", "", 0)); expect(client.exec("echo hello")).andReturn(new ExecResponse("hello", "", 0));
expect(client.exec("java -version")).andReturn(new ExecResponse("", "OpenJDK", 0)); expect(client.exec("java -version")).andReturn(new ExecResponse("", "1.6", 0));
client.disconnect(); client.disconnect();
} }

View File

@ -79,10 +79,9 @@ cd $INSTANCE_HOME
echo nameserver 208.67.222.222 >> /etc/resolv.conf echo nameserver 208.67.222.222 >> /etc/resolv.conf
cp /etc/apt/sources.list /etc/apt/sources.list.old cp /etc/apt/sources.list /etc/apt/sources.list.old
sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list
apt-get update -y -qq which curl || apt-get update -y -qq && apt-get install -f -y -qq --force-yes curl
apt-get install -f -y -qq --force-yes curl (which java && java -fullversion 2>&1|egrep -q 1.6 ) || apt-get install -f -y -qq --force-yes openjdk-6-jre
apt-get install -f -y -qq --force-yes unzip rm -rf /var/cache/apt /usr/lib/vmware-tools
apt-get install -f -y -qq --force-yes openjdk-6-jdk
mkdir -p ~/.ssh mkdir -p ~/.ssh
cat >> ~/.ssh/authorized_keys <<'END_OF_FILE' cat >> ~/.ssh/authorized_keys <<'END_OF_FILE'

View File

@ -66,14 +66,15 @@ END_OF_FILE
echo nameserver 208.67.222.222 >> /etc/resolv.conf echo nameserver 208.67.222.222 >> /etc/resolv.conf
cp /etc/apt/sources.list /etc/apt/sources.list.old cp /etc/apt/sources.list /etc/apt/sources.list.old
sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list
apt-get update -y -qq which curl || apt-get update -y -qq && apt-get install -f -y -qq --force-yes curl
apt-get install -f -y -qq --force-yes curl (which java && java -fullversion 2>&1|egrep -q 1.6 ) || apt-get install -f -y -qq --force-yes openjdk-6-jre
apt-get install -f -y -qq --force-yes unzip rm -rf /var/cache/apt /usr/lib/vmware-tools
apt-get install -f -y -qq --force-yes openjdk-6-jdk
(mkdir -p /usr/local &&cd /usr/local &&curl -X GET -s --retry 20 http://superb-sea2.dl.sourceforge.net/project/jboss/JBoss/JBoss-5.0.0.CR2/jboss-5.0.0.CR2-jdk6.zip >extract.zip && unzip -o -qq extract.zip&& rm extract.zip) rm -rf /var/cache/apt /usr/lib/vmware-tools
curl -X GET -s --retry 20 http://commondatastorage.googleapis.com/jclouds-repo/jboss-as-distribution-6.0.0.20100911-M5.tar.gz |(mkdir -p /usr/local &&cd /usr/local &&tar -xpzf -)
mkdir -p /usr/local/jboss mkdir -p /usr/local/jboss
mv /usr/local/jboss-5.0.0.CR2/* /usr/local/jboss mv /usr/local/jboss-*/* /usr/local/jboss
chmod -R oug+r+w /usr/local/jboss
mkdir -p $INSTANCE_HOME mkdir -p $INSTANCE_HOME
# create runscript header # create runscript header

View File

@ -79,10 +79,9 @@ cd $INSTANCE_HOME
echo nameserver 208.67.222.222 >> /etc/resolv.conf echo nameserver 208.67.222.222 >> /etc/resolv.conf
cp /etc/apt/sources.list /etc/apt/sources.list.old cp /etc/apt/sources.list /etc/apt/sources.list.old
sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list sed 's~us.archive.ubuntu.com~mirror.anl.gov/pub~g' /etc/apt/sources.list.old >/etc/apt/sources.list
apt-get update -y -qq which curl || apt-get update -y -qq && apt-get install -f -y -qq --force-yes curl
apt-get install -f -y -qq --force-yes curl (which java && java -fullversion 2>&1|egrep -q 1.6 ) || apt-get install -f -y -qq --force-yes openjdk-6-jre
apt-get install -f -y -qq --force-yes unzip rm -rf /var/cache/apt /usr/lib/vmware-tools
apt-get install -f -y -qq --force-yes openjdk-6-jdk
END_OF_SCRIPT END_OF_SCRIPT

View File

@ -54,7 +54,6 @@ public class InitBuilder extends ScriptBuilder {
this(instanceName, instanceHome, logDir, variables, ImmutableSet.<Statement>of(), statements); this(instanceName, instanceHome, logDir, variables, ImmutableSet.<Statement>of(), statements);
} }
@SuppressWarnings("unchecked")
public InitBuilder(String instanceName, String instanceHome, String logDir, Map<String, String> variables, public InitBuilder(String instanceName, String instanceHome, String logDir, Map<String, String> variables,
Iterable<Statement> initStatements, Iterable<Statement> statements) { Iterable<Statement> initStatements, Iterable<Statement> statements) {
this.instanceName = checkNotNull(instanceName, "instanceName"); this.instanceName = checkNotNull(instanceName, "instanceName");
@ -67,7 +66,7 @@ public class InitBuilder extends ScriptBuilder {
.addStatement( .addStatement(
switchArg( switchArg(
1, 1,
new ImmutableMap.Builder() new ImmutableMap.Builder<String,Statement>()
.put( .put(
"init", "init",
newStatementList(call("default"), call(instanceName), newStatementList(call("default"), call(instanceName),