2010-09-12 05:27:42 -04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 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.aws;
|
|
|
|
|
2010-09-28 18:56:05 -04:00
|
|
|
import static org.jclouds.compute.ComputeTestUtils.buildScript;
|
2010-09-12 05:27:42 -04:00
|
|
|
import static org.jclouds.compute.options.TemplateOptions.Builder.runScript;
|
2010-09-12 20:35:51 -04:00
|
|
|
import static org.jclouds.compute.util.ComputeServiceUtils.execHttpResponse;
|
|
|
|
import static org.jclouds.compute.util.ComputeServiceUtils.extractTargzIntoDirectory;
|
|
|
|
import static org.jclouds.scriptbuilder.domain.Statements.newStatementList;
|
|
|
|
|
|
|
|
import java.net.URI;
|
2010-09-12 05:27:42 -04:00
|
|
|
|
|
|
|
import org.jclouds.aws.ec2.compute.BlobStoreAndComputeServiceLiveTest;
|
2010-09-12 20:35:51 -04:00
|
|
|
import org.jclouds.blobstore.BlobStore;
|
2010-09-12 05:27:42 -04:00
|
|
|
import org.jclouds.compute.RunNodesException;
|
|
|
|
import org.jclouds.compute.domain.NodeMetadata;
|
|
|
|
import org.jclouds.compute.domain.OperatingSystem;
|
|
|
|
import org.jclouds.http.HttpRequest;
|
2010-10-28 02:45:30 -04:00
|
|
|
import org.jclouds.scriptbuilder.domain.OsFamily;
|
2010-09-12 20:35:51 -04:00
|
|
|
import org.jclouds.scriptbuilder.domain.Statement;
|
2010-09-20 00:30:07 -04:00
|
|
|
import org.testng.annotations.BeforeClass;
|
2010-09-12 05:27:42 -04:00
|
|
|
import org.testng.annotations.Test;
|
|
|
|
|
|
|
|
/**
|
2010-09-12 20:35:51 -04:00
|
|
|
* This test helps us understand how we can use the power of blobstores to our favor.
|
2010-10-17 01:24:22 -04:00
|
|
|
* <p/>
|
|
|
|
* This test is in aws only because it happens to have both blobstore and compute
|
|
|
|
*
|
|
|
|
* TODO create a blobstore and compute integration module
|
2010-09-12 05:27:42 -04:00
|
|
|
*
|
|
|
|
* @author Adrian Cole
|
|
|
|
*/
|
2010-12-30 17:40:23 -05:00
|
|
|
@Test(groups = "live")
|
2010-09-12 05:27:42 -04:00
|
|
|
public class ComputeAndBlobStoreTogetherHappilyLiveTest extends BlobStoreAndComputeServiceLiveTest {
|
2010-09-20 00:30:07 -04:00
|
|
|
@BeforeClass
|
2010-09-12 05:27:42 -04:00
|
|
|
protected void setupCredentials() {
|
|
|
|
blobStoreProvider = "s3";
|
|
|
|
computeServiceProvider = "ec2";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This test generates a bootstrap script based on the default operating system of the compute
|
|
|
|
* provider.
|
|
|
|
* <p/>
|
|
|
|
* It then uploads this to a blobstore, in a private location. Now, we want the bootstrap of the
|
|
|
|
* server to be able to load from this location without sending credentials to the starting
|
|
|
|
* machine. Accordingly, we send a signed url instead.
|
|
|
|
* <p/>
|
|
|
|
* Using the {@link BlobStore} api, we get a signed url corresponding to the bootstrap script. We
|
|
|
|
* next convert this into something that can be invoked via the commandline. Looking around, it
|
|
|
|
* seems like alestic runurl is pretty close. However, it is limited as it only works on requests
|
|
|
|
* that can be fully specified without headers (ex. Amazon S3). Instead, we use a variant
|
2010-09-12 20:35:51 -04:00
|
|
|
* (execHttpResponse).
|
2010-09-12 05:27:42 -04:00
|
|
|
* <p/>
|
2010-09-12 20:35:51 -04:00
|
|
|
* execHttpResponse simply assembles an http request, headers and all, and passes it to bash
|
2010-09-12 05:27:42 -04:00
|
|
|
* <p/>
|
|
|
|
* With this script ready, any node or nodes will take instructions from the blobstore when it
|
|
|
|
* boots up. we verify this with an assertion.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
@Test
|
|
|
|
public void testWeCanIndirectBootstrapInstructionsToAnArbitraryAndPrivateBlobStore() throws RunNodesException {
|
|
|
|
|
|
|
|
OperatingSystem defaultOperatingSystem = computeContext.getComputeService().templateBuilder().build().getImage()
|
2010-09-28 18:56:05 -04:00
|
|
|
.getOperatingSystem();
|
2010-09-12 05:27:42 -04:00
|
|
|
|
|
|
|
// using jclouds ability to detect operating systems before we launch them, we can avoid
|
|
|
|
// the bad practice of assuming everything is ubuntu.
|
2010-10-28 02:45:30 -04:00
|
|
|
uploadBlob(tag, "openjdk/install", buildScript(defaultOperatingSystem).render(OsFamily.UNIX));
|
2010-09-12 05:27:42 -04:00
|
|
|
|
|
|
|
// instead of hard-coding to amazon s3, we can use any blobstore, conceding this test is
|
|
|
|
// configured for amz. Note we are getting temporary access to a private blob.
|
2010-09-13 21:24:16 -04:00
|
|
|
HttpRequest signedRequestOfInstallScript = blobContext.getSigner().signGetBlob(tag, "openjdk/install");
|
2010-09-12 05:27:42 -04:00
|
|
|
|
2010-09-12 20:35:51 -04:00
|
|
|
// so one of our commands is to execute the contents of the blob above
|
|
|
|
Statement installOpenJDK = execHttpResponse(signedRequestOfInstallScript);
|
|
|
|
|
|
|
|
// if we want to, we can mix and match batched and ad-hoc commands, such as extracting maven
|
2010-11-06 20:58:45 -04:00
|
|
|
String mavenVersion = "3.0";
|
2010-09-28 18:56:05 -04:00
|
|
|
Statement extractMavenIntoUsrLocal = extractTargzIntoDirectory(
|
|
|
|
URI.create("http://mirrors.ibiblio.org/pub/mirrors/apache//maven/binaries/apache-maven-" + mavenVersion
|
|
|
|
+ "-bin.tar.gz"), "/usr/local");
|
2010-09-12 20:35:51 -04:00
|
|
|
|
|
|
|
// have both of these commands occur on boot
|
|
|
|
Statement bootstrapInstructions = newStatementList(installOpenJDK, extractMavenIntoUsrLocal);
|
2010-09-12 05:27:42 -04:00
|
|
|
|
|
|
|
// now that we have the correct instructions, kick-off the provisioner
|
2010-09-12 20:35:51 -04:00
|
|
|
Iterable<? extends NodeMetadata> nodes = computeContext.getComputeService().runNodesWithTag(tag, 2,
|
2010-09-28 18:56:05 -04:00
|
|
|
runScript(bootstrapInstructions));
|
2010-09-12 05:27:42 -04:00
|
|
|
|
2010-09-12 20:35:51 -04:00
|
|
|
// ensure the bootstrap operated by checking for the components we installed at boot time.
|
|
|
|
// Note this test will ensure both nodes are in sync.
|
|
|
|
assertSshOutputOfCommandContains(nodes, "java -version", "OpenJDK");
|
|
|
|
assertSshOutputOfCommandContains(nodes, "/usr/local/apache-maven-" + mavenVersion + "/bin/mvn -version",
|
2010-09-28 18:56:05 -04:00
|
|
|
"Apache Maven " + mavenVersion + "");
|
2010-09-12 05:27:42 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|