mirror of https://github.com/apache/jclouds.git
Issue 474: updated example to use gae sdk 1.4.0
This commit is contained in:
parent
19981da7c7
commit
e0c7e1c0b3
|
@ -22,34 +22,56 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<parent>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-project</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../../project/pom.xml</relativePath>
|
||||
</parent>
|
||||
<groupId>org.jclouds.examples</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<artifactId>googleappengine</artifactId>
|
||||
<artifactId>jclouds-googleappengine-example</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<name>JClouds Sample for Google App Engine</name>
|
||||
<description>JClouds Sample for Google App Engine</description>
|
||||
|
||||
<properties>
|
||||
<!--
|
||||
note you must set the property ${appengine.home} to a valid
|
||||
extraction of appengine-java-sdk
|
||||
-->
|
||||
<appengine.home>YOUR_APPENGINE_HOME</appengine.home>
|
||||
<appengine.applicationid>aws-common-demo</appengine.applicationid>
|
||||
<devappserver.address>localhost</devappserver.address>
|
||||
<devappserver.port>8088</devappserver.port>
|
||||
<jclouds.test.listener></jclouds.test.listener>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-blobstore</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds</groupId>
|
||||
<artifactId>jclouds-compute</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds.provider</groupId>
|
||||
<artifactId>aws-s3</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds.provider</groupId>
|
||||
<artifactId>aws-ec2</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jclouds.driver</groupId>
|
||||
<artifactId>jclouds-gae</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.guice</groupId>
|
||||
<groupId>com.google.inject.extensions</groupId>
|
||||
<artifactId>guice-servlet</artifactId>
|
||||
<version>3.0-snapshot-20101120</version>
|
||||
<version>3.0-rc2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>displaytag</groupId>
|
||||
|
@ -97,10 +119,10 @@
|
|||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-tools-api</artifactId>
|
||||
<version>1.3.5</version>
|
||||
<artifactId>appengine-tools-sdk</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${appengine.home}/lib/appengine-tools-api.jar</systemPath>
|
||||
<systemPath>${env.APPENGINE_HOME}/lib/appengine-tools-api.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
@ -131,10 +153,6 @@
|
|||
</goals>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>appengine.home</name>
|
||||
<value>${appengine.home}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>devappserver.address</name>
|
||||
<value>${devappserver.address}</value>
|
||||
|
@ -149,14 +167,13 @@
|
|||
</property>
|
||||
</systemProperties>
|
||||
<additionalClasspathElements>
|
||||
<additionalClasspathElement>${appengine.home}/lib/appengine-tools-api.jar
|
||||
</additionalClasspathElement>
|
||||
<additionalClasspathElement>${env.APPENGINE_HOME}/lib/appengine-tools-api.jar</additionalClasspathElement>
|
||||
</additionalClasspathElements>
|
||||
<environmentVariables>
|
||||
<DEBUG>true</DEBUG>
|
||||
<SDK_BIN>${appengine.home}/bin</SDK_BIN>
|
||||
<SDK_LIB>${appengine.home}/lib</SDK_LIB>
|
||||
<SDK_CONFIG>${appengine.home}/config/sdk</SDK_CONFIG>
|
||||
<SDK_BIN>${env.APPENGINE_HOME}/bin</SDK_BIN>
|
||||
<SDK_LIB>${env.APPENGINE_HOME}/lib</SDK_LIB>
|
||||
<SDK_CONFIG>${env.APPENGINE_HOME}/config/sdk</SDK_CONFIG>
|
||||
</environmentVariables>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
@ -183,16 +200,16 @@
|
|||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>jclouds.test.identity</name>
|
||||
<name>test.aws.identity</name>
|
||||
<value>${test.aws.identity}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.test.credential</name>
|
||||
<name>test.aws.credential</name>
|
||||
<value>${test.aws.credential}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>appengine.home</name>
|
||||
<value>${appengine.home}</value>
|
||||
<name>appengine.sdk.root</name>
|
||||
<value>${env.APPENGINE_HOME}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>devappserver.address</name>
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.jclouds.samples.googleappengine;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
|
@ -39,11 +38,12 @@ import org.jclouds.logging.Logger;
|
|||
import org.jclouds.samples.googleappengine.functions.BlobStoreContextToStatusResult;
|
||||
import org.jclouds.samples.googleappengine.functions.ComputeServiceContextToStatusResult;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* Shows an example of how to use @{link BlobStoreContext} injected with Guice.
|
||||
* Shows an example of how to use {@link BlobStoreContext} and {@link ComputeServiceContext}
|
||||
* injected with Guice.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
@ -51,8 +51,8 @@ import com.google.common.collect.Sets;
|
|||
public class GetAllStatusController extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Map<String, BlobStoreContext> blobsStoreContexts;
|
||||
private final Map<String, ComputeServiceContext> computeServiceContexts;
|
||||
private final Iterable<BlobStoreContext> blobsStoreContexts;
|
||||
private final Iterable<ComputeServiceContext> computeServiceContexts;
|
||||
private final BlobStoreContextToStatusResult blobStoreContextToContainerResult;
|
||||
private final ComputeServiceContextToStatusResult computeServiceContextToContainerResult;
|
||||
|
||||
|
@ -60,10 +60,10 @@ public class GetAllStatusController extends HttpServlet {
|
|||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
GetAllStatusController(Map<String, BlobStoreContext> blobsStoreContexts,
|
||||
Map<String, ComputeServiceContext> computeServiceContexts,
|
||||
BlobStoreContextToStatusResult blobStoreContextToContainerResult,
|
||||
ComputeServiceContextToStatusResult computeServiceContextToContainerResult) {
|
||||
GetAllStatusController(Iterable<BlobStoreContext> blobsStoreContexts,
|
||||
Iterable<ComputeServiceContext> computeServiceContexts,
|
||||
BlobStoreContextToStatusResult blobStoreContextToContainerResult,
|
||||
ComputeServiceContextToStatusResult computeServiceContextToContainerResult) {
|
||||
this.blobsStoreContexts = blobsStoreContexts;
|
||||
this.computeServiceContexts = computeServiceContexts;
|
||||
this.blobStoreContextToContainerResult = blobStoreContextToContainerResult;
|
||||
|
@ -71,12 +71,10 @@ public class GetAllStatusController extends HttpServlet {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
try {
|
||||
addStatusResultsToRequest(request);
|
||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(
|
||||
"/WEB-INF/jsp/status.jsp");
|
||||
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/jsp/status.jsp");
|
||||
dispatcher.forward(request, response);
|
||||
} catch (Exception e) {
|
||||
logger.error(e, "Error listing status");
|
||||
|
@ -84,12 +82,13 @@ public class GetAllStatusController extends HttpServlet {
|
|||
}
|
||||
}
|
||||
|
||||
private void addStatusResultsToRequest(HttpServletRequest request) throws InterruptedException,
|
||||
ExecutionException, TimeoutException {
|
||||
request.setAttribute("status", Sets
|
||||
.newTreeSet(Iterables.concat(Iterables.transform(blobsStoreContexts.keySet(),
|
||||
blobStoreContextToContainerResult), Iterables.transform(
|
||||
computeServiceContexts.keySet(), computeServiceContextToContainerResult))));
|
||||
private void addStatusResultsToRequest(HttpServletRequest request) throws InterruptedException, ExecutionException,
|
||||
TimeoutException {
|
||||
request.setAttribute(
|
||||
"status",
|
||||
ImmutableSet.copyOf(Iterables.concat(
|
||||
Iterables.transform(blobsStoreContexts, blobStoreContextToContainerResult),
|
||||
Iterables.transform(computeServiceContexts, computeServiceContextToContainerResult))));
|
||||
}
|
||||
|
||||
}
|
|
@ -26,7 +26,6 @@ import static org.jclouds.compute.reference.ComputeServiceConstants.PROPERTY_TIM
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
|
@ -38,7 +37,6 @@ import org.jclouds.compute.ComputeServiceContextFactory;
|
|||
import org.jclouds.gae.config.GoogleAppEngineConfigurationModule;
|
||||
import org.jclouds.samples.googleappengine.GetAllStatusController;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.io.Closeables;
|
||||
import com.google.inject.Guice;
|
||||
|
@ -49,14 +47,14 @@ import com.google.inject.servlet.GuiceServletContextListener;
|
|||
import com.google.inject.servlet.ServletModule;
|
||||
|
||||
/**
|
||||
* Setup Logging and create Injector for use in testing S3.
|
||||
* Setup Logging and create {@link Injector} for use in testing Amazon EC2 and S3.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class GuiceServletConfig extends GuiceServletContextListener {
|
||||
|
||||
private Map<String, BlobStoreContext> blobsStoreContexts;
|
||||
private Map<String, ComputeServiceContext> computeServiceContexts;
|
||||
private Iterable<BlobStoreContext> blobsStoreContexts;
|
||||
private Iterable<ComputeServiceContext> computeServiceContexts;
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent servletContextEvent) {
|
||||
|
@ -66,20 +64,18 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
|||
props.setProperty(PROPERTY_TIMEOUT_SCRIPT_COMPLETE, "25000");
|
||||
props.setProperty(PROPERTY_TIMEOUT_PORT_OPEN, "25000");
|
||||
|
||||
ImmutableSet<Module> modules = ImmutableSet
|
||||
.<Module> of(new GoogleAppEngineConfigurationModule());
|
||||
ImmutableSet<Module> modules = ImmutableSet.<Module> of(new GoogleAppEngineConfigurationModule());
|
||||
|
||||
blobsStoreContexts = ImmutableMap.<String, BlobStoreContext> of("s3",
|
||||
new BlobStoreContextFactory().createContext("s3", modules, props));
|
||||
computeServiceContexts = ImmutableMap.<String, ComputeServiceContext> of("ec2",
|
||||
new ComputeServiceContextFactory().createContext("ec2", modules, props));
|
||||
blobsStoreContexts = ImmutableSet.<BlobStoreContext> of(new BlobStoreContextFactory().createContext("aws-s3",
|
||||
modules, props));
|
||||
computeServiceContexts = ImmutableSet.<ComputeServiceContext> of(new ComputeServiceContextFactory()
|
||||
.createContext("aws-ec2", modules, props));
|
||||
|
||||
super.contextInitialized(servletContextEvent);
|
||||
}
|
||||
|
||||
private Properties loadJCloudsProperties(ServletContextEvent servletContextEvent) {
|
||||
InputStream input = servletContextEvent.getServletContext().getResourceAsStream(
|
||||
"/WEB-INF/jclouds.properties");
|
||||
InputStream input = servletContextEvent.getServletContext().getResourceAsStream("/WEB-INF/jclouds.properties");
|
||||
Properties props = new Properties();
|
||||
try {
|
||||
props.load(input);
|
||||
|
@ -96,9 +92,9 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
|||
return Guice.createInjector(new ServletModule() {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
bind(new TypeLiteral<Map<String, BlobStoreContext>>() {
|
||||
bind(new TypeLiteral<Iterable<BlobStoreContext>>() {
|
||||
}).toInstance(GuiceServletConfig.this.blobsStoreContexts);
|
||||
bind(new TypeLiteral<Map<String, ComputeServiceContext>>() {
|
||||
bind(new TypeLiteral<Iterable<ComputeServiceContext>>() {
|
||||
}).toInstance(GuiceServletConfig.this.computeServiceContexts);
|
||||
serve("*.check").with(GetAllStatusController.class);
|
||||
requestInjection(this);
|
||||
|
@ -110,10 +106,10 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
|||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent servletContextEvent) {
|
||||
for (BlobStoreContext context : blobsStoreContexts.values()) {
|
||||
for (BlobStoreContext context : blobsStoreContexts) {
|
||||
context.close();
|
||||
}
|
||||
for (ComputeServiceContext context : computeServiceContexts.values()) {
|
||||
for (ComputeServiceContext context : computeServiceContexts) {
|
||||
context.close();
|
||||
}
|
||||
super.contextDestroyed(servletContextEvent);
|
||||
|
|
|
@ -19,79 +19,39 @@
|
|||
|
||||
package org.jclouds.samples.googleappengine.functions;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.blobstore.BlobStoreContext;
|
||||
import org.jclouds.blobstore.ContainerNotFoundException;
|
||||
import org.jclouds.blobstore.domain.StorageMetadata;
|
||||
import org.jclouds.blobstore.domain.StorageType;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.samples.googleappengine.domain.StatusResult;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class BlobStoreContextToStatusResult implements Function<String, StatusResult> {
|
||||
private final class BuildContainerResult implements Function<StorageMetadata, StatusResult> {
|
||||
private final String host;
|
||||
private final BlobStoreContext context;
|
||||
private final String contextName;
|
||||
|
||||
private BuildContainerResult(String host, BlobStoreContext context, String contextName) {
|
||||
this.host = host;
|
||||
this.context = context;
|
||||
this.contextName = contextName;
|
||||
}
|
||||
|
||||
public StatusResult apply(StorageMetadata from) {
|
||||
String status;
|
||||
try {
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
context.getBlobStore().containerExists(from.getName());
|
||||
status = ((System.currentTimeMillis() - start) + "ms");
|
||||
} catch (ContainerNotFoundException ex) {
|
||||
status = ("not found");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e, "Error listing container %s//%s", contextName, from);
|
||||
status = (e.getMessage());
|
||||
}
|
||||
return new StatusResult(contextName, host, from.getName(), status);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
private Map<String, BlobStoreContext> contexts;
|
||||
public class BlobStoreContextToStatusResult implements Function<BlobStoreContext, StatusResult> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
public StatusResult apply(final String contextName) {
|
||||
final BlobStoreContext context = contexts.get(contextName);
|
||||
final String host = context.getProviderSpecificContext().getEndpoint().getHost();
|
||||
public StatusResult apply(BlobStoreContext in) {
|
||||
String host = in.getProviderSpecificContext().getEndpoint().getHost();
|
||||
String status;
|
||||
String name = "not found";
|
||||
try {
|
||||
StorageMetadata md = Iterables.getLast(Sets.newTreeSet(Iterables.filter(context
|
||||
.getBlobStore().list(), new Predicate<StorageMetadata>() {
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
public boolean apply(StorageMetadata input) {
|
||||
return input.getType() == StorageType.CONTAINER;
|
||||
}
|
||||
name = String.format("%d containers", in.getBlobStore().list().size());
|
||||
|
||||
})));
|
||||
return new BuildContainerResult(host, context, contextName).apply(md);
|
||||
status = ((System.currentTimeMillis() - start) + "ms");
|
||||
} catch (Exception e) {
|
||||
StatusResult result = new StatusResult(contextName, host, null, e.getMessage());
|
||||
logger.error(e, "Error listing service %s", contextName);
|
||||
return result;
|
||||
logger.error(e, "Error listing context %s", in);
|
||||
status = (e.getMessage());
|
||||
}
|
||||
|
||||
return new StatusResult(in.getProviderSpecificContext().getId(), host, name, status);
|
||||
}
|
||||
}
|
|
@ -19,52 +19,39 @@
|
|||
|
||||
package org.jclouds.samples.googleappengine.functions;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.options.TemplateOptions;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.samples.googleappengine.domain.StatusResult;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ComputeServiceContextToStatusResult implements
|
||||
Function<String, StatusResult> {
|
||||
|
||||
@Inject
|
||||
private Map<String, ComputeServiceContext> contexts;
|
||||
public class ComputeServiceContextToStatusResult implements Function<ComputeServiceContext, StatusResult> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
public StatusResult apply(final String contextName) {
|
||||
final ComputeServiceContext context = contexts.get(contextName);
|
||||
final String host = context.getProviderSpecificContext().getEndpoint()
|
||||
.getHost();
|
||||
public StatusResult apply(ComputeServiceContext in) {
|
||||
String host = in.getProviderSpecificContext().getEndpoint().getHost();
|
||||
String status;
|
||||
String name = "not found";
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
// set options that don't block so that we can avoid
|
||||
// DeadLineExceededExceptions
|
||||
TemplateOptions options = context.getComputeService()
|
||||
.templateOptions().blockUntilRunning(false);
|
||||
|
||||
// set the name to the default template to show that
|
||||
// it works
|
||||
name = context.getComputeService().templateBuilder().options(options)
|
||||
.build().toString();
|
||||
name = String.format("%d nodes", in.getComputeService().listNodes().size());
|
||||
|
||||
status = ((System.currentTimeMillis() - start) + "ms");
|
||||
} catch (Exception e) {
|
||||
logger.error(e, "Error listing service %s", contextName);
|
||||
logger.error(e, "Error listing context %s", in);
|
||||
status = (e.getMessage());
|
||||
}
|
||||
return new StatusResult(contextName, host, name, status);
|
||||
return new StatusResult(in.getProviderSpecificContext().getId(), host, name, status);
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ import org.testng.annotations.Test;
|
|||
|
||||
/**
|
||||
* Starts up the Google App Engine for Java Development environment and deploys an application which
|
||||
* tests S3.
|
||||
* tests Amazon EC2 and S3.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
@ -49,10 +49,10 @@ public class GoogleAppEngineLiveTest {
|
|||
throws Exception {
|
||||
url = new URL(String.format("http://%s:%s", address, port));
|
||||
Properties props = new Properties();
|
||||
String identity = checkNotNull(System.getProperty("jclouds.test.identity"),
|
||||
"jclouds.test.identity");
|
||||
String credential = checkNotNull(System.getProperty("jclouds.test.credential"),
|
||||
"jclouds.test.credential");
|
||||
String identity = checkNotNull(System.getProperty("test.aws.identity"),
|
||||
"test.aws.identity");
|
||||
String credential = checkNotNull(System.getProperty("test.aws.credential"),
|
||||
"test.aws.credential");
|
||||
|
||||
/**
|
||||
* Since both s3 and ec2 use the same credentials, we can take a shortcut and specify both
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
<groupId>com.google.appengine</groupId>
|
||||
<artifactId>appengine-api-1.0-sdk</artifactId>
|
||||
<version>1.4.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
Loading…
Reference in New Issue