From 72da36bf337f4d98ebb827c90a6bd645c734522e Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sat, 20 Mar 2010 12:40:52 -0700 Subject: [PATCH] switched aws demo to use s3 and ec2 --- aws/demos/googleappengine/pom.xml | 36 ----------- ...oller.java => GetAllStatusController.java} | 37 +++++++---- .../config/GuiceServletConfig.java | 58 +++++++++--------- ...ContainerResult.java => StatusResult.java} | 8 +-- ...va => BlobStoreContextToStatusResult.java} | 14 ++--- .../ComputeServiceContextToStatusResult.java | 61 +++++++++++++++++++ .../jsp/{containers.jsp => status.jsp} | 8 +-- .../googleappengine/src/main/webapp/index.jsp | 5 +- .../functest/GoogleAppEngineLiveTest.java | 33 +++------- 9 files changed, 139 insertions(+), 121 deletions(-) rename aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/{GetAllContainersController.java => GetAllStatusController.java} (58%) rename aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/domain/{ContainerResult.java => StatusResult.java} (91%) rename aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/{BlobStoreContextToContainerResult.java => BlobStoreContextToStatusResult.java} (86%) create mode 100644 aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/ComputeServiceContextToStatusResult.java rename aws/demos/googleappengine/src/main/webapp/WEB-INF/jsp/{containers.jsp => status.jsp} (86%) diff --git a/aws/demos/googleappengine/pom.xml b/aws/demos/googleappengine/pom.xml index 06dc823be6..620404c015 100644 --- a/aws/demos/googleappengine/pom.xml +++ b/aws/demos/googleappengine/pom.xml @@ -44,26 +44,6 @@ - - ${project.groupId} - jclouds-blobstore - ${project.version} - - - ${project.groupId} - jclouds-azure - ${project.version} - - - ${project.groupId} - jclouds-rackspace - ${project.version} - - - ${project.groupId} - jclouds-enterprise - ${project.version} - ${project.groupId} jclouds-gae @@ -205,22 +185,6 @@ - - jclouds.azure.storage.account - ${jclouds.azure.storage.account} - - - jclouds.azure.storage.key - ${jclouds.azure.storage.key} - - - jclouds.rackspace.user - ${jclouds.rackspace.user} - - - jclouds.rackspace.key - ${jclouds.rackspace.key} - jclouds.aws.accesskeyid ${jclouds.aws.accesskeyid} diff --git a/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/GetAllContainersController.java b/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/GetAllStatusController.java similarity index 58% rename from aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/GetAllContainersController.java rename to aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/GetAllStatusController.java index 155da630df..ddca57b87d 100755 --- a/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/GetAllContainersController.java +++ b/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/GetAllStatusController.java @@ -33,8 +33,10 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.compute.ComputeServiceContext; import org.jclouds.logging.Logger; -import org.jclouds.samples.googleappengine.functions.BlobStoreContextToContainerResult; +import org.jclouds.samples.googleappengine.functions.BlobStoreContextToStatusResult; +import org.jclouds.samples.googleappengine.functions.ComputeServiceContextToStatusResult; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; @@ -45,39 +47,48 @@ import com.google.common.collect.Sets; * @author Adrian Cole */ @Singleton -public class GetAllContainersController extends HttpServlet { +public class GetAllStatusController extends HttpServlet { private static final long serialVersionUID = 1L; - private Map contexts; - private final BlobStoreContextToContainerResult blobStoreContextToContainerResult; + private final Map blobsStoreContexts; + private final Map computeServiceContexts; + private final BlobStoreContextToStatusResult blobStoreContextToContainerResult; + private final ComputeServiceContextToStatusResult computeServiceContextToContainerResult; @Resource protected Logger logger = Logger.NULL; @Inject - public GetAllContainersController(Map contexts, - BlobStoreContextToContainerResult blobStoreContextToContainerResult) { - this.contexts = contexts; + GetAllStatusController(Map blobsStoreContexts, + Map computeServiceContexts, + BlobStoreContextToStatusResult blobStoreContextToContainerResult, + ComputeServiceContextToStatusResult computeServiceContextToContainerResult) { + this.blobsStoreContexts = blobsStoreContexts; + this.computeServiceContexts = computeServiceContexts; this.blobStoreContextToContainerResult = blobStoreContextToContainerResult; + this.computeServiceContextToContainerResult = computeServiceContextToContainerResult; } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { - addMyContainersToRequest(request); + addStatusResultsToRequest(request); RequestDispatcher dispatcher = getServletContext().getRequestDispatcher( - "/WEB-INF/jsp/containers.jsp"); + "/WEB-INF/jsp/status.jsp"); dispatcher.forward(request, response); } catch (Exception e) { - logger.error(e, "Error listing containers"); + logger.error(e, "Error listing status"); throw new ServletException(e); } } - private void addMyContainersToRequest(HttpServletRequest request) throws InterruptedException, + private void addStatusResultsToRequest(HttpServletRequest request) throws InterruptedException, ExecutionException, TimeoutException { - request.setAttribute("containers", Sets.newTreeSet(Iterables.transform(contexts.keySet(), - blobStoreContextToContainerResult))); + request.setAttribute("status", Sets + .newTreeSet(Iterables.concat(Iterables.transform(blobsStoreContexts.keySet(), + blobStoreContextToContainerResult), Iterables.transform( + computeServiceContexts.keySet(), computeServiceContextToContainerResult)))); } + } \ No newline at end of file diff --git a/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java b/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java index 742f0f9e69..45ddfc0170 100755 --- a/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java +++ b/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java @@ -18,26 +18,27 @@ */ package org.jclouds.samples.googleappengine.config; -import static com.google.common.base.Preconditions.checkNotNull; - import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Constructor; import java.util.Map; import java.util.Properties; import javax.servlet.ServletContextEvent; import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.BlobStoreContextBuilder; +import org.jclouds.blobstore.BlobStoreContextFactory; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.gae.config.GoogleAppEngineConfigurationModule; -import org.jclouds.samples.googleappengine.GetAllContainersController; +import org.jclouds.samples.googleappengine.GetAllStatusController; -import com.google.appengine.repackaged.com.google.common.collect.ImmutableList; -import com.google.common.collect.Maps; +import com.google.appengine.repackaged.com.google.common.base.Throwables; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.common.io.Closeables; import com.google.inject.Guice; import com.google.inject.Injector; +import com.google.inject.Module; import com.google.inject.TypeLiteral; import com.google.inject.servlet.GuiceServletContextListener; import com.google.inject.servlet.ServletModule; @@ -49,31 +50,23 @@ import com.google.inject.servlet.ServletModule; */ public class GuiceServletConfig extends GuiceServletContextListener { - public static final String PROPERTY_BLOBSTORE_CONTEXTS = "blobstore.contexts"; + private Map blobsStoreContexts; + private Map computeServiceContexts; - private Map contexts; - - @SuppressWarnings("unchecked") @Override public void contextInitialized(ServletContextEvent servletContextEvent) { Properties props = loadJCloudsProperties(servletContextEvent); - ImmutableList list = ImmutableList. of(checkNotNull( - props.getProperty(PROPERTY_BLOBSTORE_CONTEXTS), PROPERTY_BLOBSTORE_CONTEXTS).split( - ",")); - contexts = Maps.newHashMap(); - for (String className : list) { - try { - Class> builderClass; - builderClass = (Class>) Class.forName(className); - String name = builderClass.getSimpleName().replaceAll("BlobStoreContextBuilder", ""); - Constructor> constructor = builderClass - .getConstructor(Properties.class); - contexts.put(name, constructor.newInstance(props).withModules( - new GoogleAppEngineConfigurationModule()).buildBlobStoreContext()); - } catch (Exception e) { - throw new RuntimeException(e); - } + ImmutableSet modules = ImmutableSet + . of(new GoogleAppEngineConfigurationModule()); + try { + blobsStoreContexts = ImmutableMap. of("s3", + new BlobStoreContextFactory().createContext("s3", modules, props)); + computeServiceContexts = ImmutableMap. of("ec2", + new ComputeServiceContextFactory().createContext("ec2", modules, props)); + } catch (IOException e) { + Throwables.propagate(e); } + super.contextInitialized(servletContextEvent); } @@ -97,8 +90,10 @@ public class GuiceServletConfig extends GuiceServletContextListener { @Override protected void configureServlets() { bind(new TypeLiteral>() { - }).toInstance(GuiceServletConfig.this.contexts); - serve("*.blobstore").with(GetAllContainersController.class); + }).toInstance(GuiceServletConfig.this.blobsStoreContexts); + bind(new TypeLiteral>() { + }).toInstance(GuiceServletConfig.this.computeServiceContexts); + serve("*.check").with(GetAllStatusController.class); requestInjection(this); } } @@ -108,7 +103,10 @@ public class GuiceServletConfig extends GuiceServletContextListener { @Override public void contextDestroyed(ServletContextEvent servletContextEvent) { - for (BlobStoreContext context : contexts.values()) { + for (BlobStoreContext context : blobsStoreContexts.values()) { + context.close(); + } + for (ComputeServiceContext context : computeServiceContexts.values()) { context.close(); } super.contextDestroyed(servletContextEvent); diff --git a/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/domain/ContainerResult.java b/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/domain/StatusResult.java similarity index 91% rename from aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/domain/ContainerResult.java rename to aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/domain/StatusResult.java index 64769a93af..d9fbec68cf 100755 --- a/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/domain/ContainerResult.java +++ b/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/domain/StatusResult.java @@ -24,7 +24,7 @@ import java.io.Serializable; * * @author Adrian Cole */ -public class ContainerResult implements Comparable, Serializable { +public class StatusResult implements Comparable, Serializable { /** The serialVersionUID */ private static final long serialVersionUID = -3257496189689220018L; private final String service; @@ -32,7 +32,7 @@ public class ContainerResult implements Comparable, Serializabl private final String name; private final String status; - public ContainerResult(String service, String host, String name, String status) { + public StatusResult(String service, String host, String name, String status) { this.service = service; this.host = host; this.name = name; @@ -58,7 +58,7 @@ public class ContainerResult implements Comparable, Serializabl return false; if (getClass() != obj.getClass()) return false; - ContainerResult other = (ContainerResult) obj; + StatusResult other = (StatusResult) obj; if (host == null) { if (other.host != null) return false; @@ -82,7 +82,7 @@ public class ContainerResult implements Comparable, Serializabl return true; } - public int compareTo(ContainerResult o) { + public int compareTo(StatusResult o) { return (this == o) ? 0 : getService().compareTo(o.getService()); } diff --git a/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/BlobStoreContextToContainerResult.java b/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/BlobStoreContextToStatusResult.java similarity index 86% rename from aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/BlobStoreContextToContainerResult.java rename to aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/BlobStoreContextToStatusResult.java index 5e3cc11fbe..4350b3671d 100755 --- a/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/BlobStoreContextToContainerResult.java +++ b/aws/demos/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/BlobStoreContextToStatusResult.java @@ -29,7 +29,7 @@ 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.ContainerResult; +import org.jclouds.samples.googleappengine.domain.StatusResult; import com.google.common.base.Function; import com.google.common.base.Predicate; @@ -37,8 +37,8 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Sets; @Singleton -public class BlobStoreContextToContainerResult implements Function { - private final class BuildContainerResult implements Function { +public class BlobStoreContextToStatusResult implements Function { + private final class BuildContainerResult implements Function { private final String host; private final BlobStoreContext context; private final String contextName; @@ -49,7 +49,7 @@ public class BlobStoreContextToContainerResult implements Function + * + * ==================================================================== + * 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.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.domain.ComputeMetadata; +import org.jclouds.logging.Logger; +import org.jclouds.samples.googleappengine.domain.StatusResult; + +import com.google.common.base.Function; +import com.google.common.collect.Iterables; + +@Singleton +public class ComputeServiceContextToStatusResult implements Function { + + @Inject + private Map contexts; + + @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(); + String status; + String name = "not found"; + try { + long start = System.currentTimeMillis(); + Map nodes = context.getComputeService().getNodes(); + if (nodes.size() > 0) + name = Iterables.get(nodes.keySet(), 0); + status = ((System.currentTimeMillis() - start) + "ms"); + } catch (Exception e) { + logger.error(e, "Error listing service %s", contextName); + status = (e.getMessage()); + } + return new StatusResult(contextName, host, name, status); + } +} \ No newline at end of file diff --git a/aws/demos/googleappengine/src/main/webapp/WEB-INF/jsp/containers.jsp b/aws/demos/googleappengine/src/main/webapp/WEB-INF/jsp/status.jsp similarity index 86% rename from aws/demos/googleappengine/src/main/webapp/WEB-INF/jsp/containers.jsp rename to aws/demos/googleappengine/src/main/webapp/WEB-INF/jsp/status.jsp index 130fbe7823..4d1c4c9e6f 100755 --- a/aws/demos/googleappengine/src/main/webapp/WEB-INF/jsp/containers.jsp +++ b/aws/demos/googleappengine/src/main/webapp/WEB-INF/jsp/status.jsp @@ -22,14 +22,14 @@ <%@ taglib uri="http://displaytag.sf.net" prefix="display"%> -jclouds: anyweight cloudware for java +jclouds: multi-cloud framework -

Container List

- +

Status List

+ - + diff --git a/aws/demos/googleappengine/src/main/webapp/index.jsp b/aws/demos/googleappengine/src/main/webapp/index.jsp index bd52a49730..7d4b453580 100755 --- a/aws/demos/googleappengine/src/main/webapp/index.jsp +++ b/aws/demos/googleappengine/src/main/webapp/index.jsp @@ -20,12 +20,11 @@ --%> -jclouds: anyweight cloudware for java +jclouds: multi-cloud framework

Welcome!

Click -here -to list my containers. +here to get status of cloud services. diff --git a/aws/demos/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java b/aws/demos/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java index 68ce4a4401..5844eaa0ef 100755 --- a/aws/demos/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java +++ b/aws/demos/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java @@ -21,23 +21,14 @@ package org.jclouds.samples.googleappengine.functest; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_ACCESSKEYID; import static org.jclouds.aws.reference.AWSConstants.PROPERTY_AWS_SECRETACCESSKEY; -import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_ACCOUNT; -import static org.jclouds.azure.storage.reference.AzureStorageConstants.PROPERTY_AZURESTORAGE_KEY; -import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_KEY; -import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_USER; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Properties; -import org.jclouds.aws.s3.S3ContextBuilder; +import org.jclouds.aws.ec2.EC2PropertiesBuilder; import org.jclouds.aws.s3.S3PropertiesBuilder; -import org.jclouds.azure.storage.blob.AzureBlobPropertiesBuilder; -import org.jclouds.azure.storage.blob.AzureBlobContextBuilder; -import org.jclouds.rackspace.cloudfiles.CloudFilesContextBuilder; -import org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder; -import org.jclouds.samples.googleappengine.config.GuiceServletConfig; import org.jclouds.util.Utils; import org.testng.annotations.BeforeTest; import org.testng.annotations.Parameters; @@ -62,10 +53,6 @@ public class GoogleAppEngineLiveTest { url = new URL(String.format("http://%s:%s", address, port)); Properties props = new Properties(); - props.setProperty(GuiceServletConfig.PROPERTY_BLOBSTORE_CONTEXTS, String.format("%s,%s,%s", - S3ContextBuilder.class.getName(), CloudFilesContextBuilder.class.getName(), - AzureBlobContextBuilder.class.getName())); - props = new S3PropertiesBuilder(props) .withCredentials( checkNotNull(System.getProperty(PROPERTY_AWS_ACCESSKEYID), @@ -73,14 +60,12 @@ public class GoogleAppEngineLiveTest { System.getProperty(PROPERTY_AWS_SECRETACCESSKEY, PROPERTY_AWS_SECRETACCESSKEY)).build(); - props = new CloudFilesPropertiesBuilder(props).withCredentials( - checkNotNull(System.getProperty(PROPERTY_RACKSPACE_USER), PROPERTY_RACKSPACE_USER), - System.getProperty(PROPERTY_RACKSPACE_KEY, PROPERTY_RACKSPACE_KEY)).build(); - - props = new AzureBlobPropertiesBuilder(props).withCredentials( - checkNotNull(System.getProperty(PROPERTY_AZURESTORAGE_ACCOUNT), - PROPERTY_AZURESTORAGE_ACCOUNT), - System.getProperty(PROPERTY_AZURESTORAGE_KEY, PROPERTY_AZURESTORAGE_KEY)).build(); + props = new EC2PropertiesBuilder(props) + .withCredentials( + checkNotNull(System.getProperty(PROPERTY_AWS_ACCESSKEYID), + PROPERTY_AWS_ACCESSKEYID), + System.getProperty(PROPERTY_AWS_SECRETACCESSKEY, + PROPERTY_AWS_SECRETACCESSKEY)).build(); server = new GoogleDevServer(); server.writePropertiesAndStartServer(address, port, warfile, props); @@ -95,7 +80,7 @@ public class GoogleAppEngineLiveTest { @Test(invocationCount = 5, enabled = true) public void testGuiceJCloudsSerial() throws InterruptedException, IOException { - URL gurl = new URL(url, "/guice/containers.blobstore"); + URL gurl = new URL(url, "/guice/status.check"); InputStream i = gurl.openStream(); String string = Utils.toStringAndClose(i); assert string.indexOf("List") >= 0 : string; @@ -103,7 +88,7 @@ public class GoogleAppEngineLiveTest { @Test(invocationCount = 10, enabled = true, threadPoolSize = 3) public void testGuiceJCloudsParallel() throws InterruptedException, IOException { - URL gurl = new URL(url, "/guice/containers.blobstore"); + URL gurl = new URL(url, "/guice/status.check"); InputStream i = gurl.openStream(); String string = Utils.toStringAndClose(i); assert string.indexOf("List") >= 0 : string;