diff --git a/aws/s3/samples/googleappengine/README.txt b/aws/s3/samples/googleappengine/README.txt index d3734b58f4..bb31761a5e 100644 --- a/aws/s3/samples/googleappengine/README.txt +++ b/aws/s3/samples/googleappengine/README.txt @@ -21,7 +21,7 @@ under the License. ==================================================================== ==== -This samples uses the Google App Engine for Java SDK located at http://googleappengine.googlecode.com/files/appengine-java-sdk-1.2.1.zip +This samples uses the Google App Engine for Java SDK located at http://googleappengine.googlecode.com/files/appengine-java-sdk-1.2.5.zip Please unzip the above file and modify your maven settings.xml like below before attempting to run 'mvn -Plive install' @@ -31,7 +31,7 @@ Please unzip the above file and modify your maven settings.xml like below before true - /path/to/appengine-java-sdk-1.2.1 + /path/to/appengine-java-sdk-1.2.5 diff --git a/aws/s3/samples/googleappengine/pom.xml b/aws/s3/samples/googleappengine/pom.xml index d882bd10af..db32569b49 100644 --- a/aws/s3/samples/googleappengine/pom.xml +++ b/aws/s3/samples/googleappengine/pom.xml @@ -46,6 +46,16 @@ + + ${project.groupId} + jclouds-azureblob + ${project.version} + + + ${project.groupId} + jclouds-cloudfiles + ${project.version} + ${project.groupId} jclouds-gae @@ -161,7 +171,7 @@ ${appengine.home}/lib/appengine-tools-api.jar - + true @@ -194,11 +204,27 @@ - jclouds.test.user + 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} - jclouds.test.key + jclouds.aws.secretaccesskey ${jclouds.aws.secretaccesskey} diff --git a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/GetAllBucketsController.java b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/GetAllContainersController.java old mode 100644 new mode 100755 similarity index 58% rename from aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/GetAllBucketsController.java rename to aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/GetAllContainersController.java index 869ffc7e1f..fcab7f0fcc --- a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/GetAllBucketsController.java +++ b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/GetAllContainersController.java @@ -24,14 +24,12 @@ package org.jclouds.samples.googleappengine; import java.io.IOException; -import java.util.SortedSet; +import java.util.Map; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import javax.annotation.Resource; import javax.inject.Inject; -import javax.inject.Provider; import javax.inject.Singleton; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; @@ -39,59 +37,52 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.jclouds.aws.s3.S3Client; -import org.jclouds.aws.s3.domain.BucketMetadata; import org.jclouds.blobstore.BlobStoreContext; import org.jclouds.logging.Logger; -import org.jclouds.samples.googleappengine.domain.BucketResult; -import org.jclouds.samples.googleappengine.functions.MetadataToBucketResult; +import org.jclouds.samples.googleappengine.functions.BlobStoreContextToContainerResult; -import com.google.appengine.repackaged.com.google.common.collect.Sets; import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; /** - * Shows an example of how to use @{link S3Client} injected with Guice. + * Shows an example of how to use @{link BlobStoreContext} injected with Guice. * * @author Adrian Cole */ @Singleton -public class GetAllBucketsController extends HttpServlet { +public class GetAllContainersController extends HttpServlet { private static final long serialVersionUID = 1L; - private final BlobStoreContext context; - private final Provider metadataToBucketResultProvider; + private Map> contexts; + private final BlobStoreContextToContainerResult blobStoreContextToContainerResult; @Resource protected Logger logger = Logger.NULL; @Inject - public GetAllBucketsController(BlobStoreContext context, - Provider metadataToBucketResultProvider) { - this.context = context; - this.metadataToBucketResultProvider = metadataToBucketResultProvider; + public GetAllContainersController(Map> contexts, + BlobStoreContextToContainerResult blobStoreContextToContainerResult) { + this.contexts = contexts; + this.blobStoreContextToContainerResult = blobStoreContextToContainerResult; } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { - addMyBucketsToRequest(request); + addMyContainersToRequest(request); RequestDispatcher dispatcher = getServletContext().getRequestDispatcher( - "/WEB-INF/jsp/buckets.jsp"); + "/WEB-INF/jsp/containers.jsp"); dispatcher.forward(request, response); } catch (Exception e) { - logger.error(e, "Error listing buckets"); + logger.error(e, "Error listing containers"); throw new ServletException(e); } } - private void addMyBucketsToRequest(HttpServletRequest request) throws InterruptedException, + private void addMyContainersToRequest(HttpServletRequest request) throws InterruptedException, ExecutionException, TimeoutException { - System.err.println(context.getAccount() + ":" + context.getEndPoint()); - SortedSet myBucketMetadata = context.getApi().listOwnedBuckets().get(10, - TimeUnit.SECONDS); - SortedSet myBuckets = Sets.newTreeSet(Iterables.transform(myBucketMetadata, - metadataToBucketResultProvider.get())); - request.setAttribute("buckets", myBuckets); + request.setAttribute("containers", Sets.newTreeSet(Iterables.transform(contexts.keySet(), + blobStoreContextToContainerResult))); } } \ No newline at end of file diff --git a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/JCloudsServlet.java b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/JCloudsServlet.java deleted file mode 100644 index 7e2ef902eb..0000000000 --- a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/JCloudsServlet.java +++ /dev/null @@ -1,142 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.samples.googleappengine; - -import java.io.IOException; -import java.util.SortedSet; -import java.util.concurrent.TimeUnit; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Singleton; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.jclouds.aws.s3.S3Client; -import org.jclouds.aws.s3.domain.BucketMetadata; -import org.jclouds.aws.s3.domain.ListBucketResponse; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.ContainerNotFoundException; -import org.jclouds.logging.Logger; - -import com.google.common.collect.Sets; - -/** - * Shows an example of how to use @{link S3Client} injected with Guice. - * - * @author Adrian Cole - */ -@Singleton -public class JCloudsServlet extends HttpServlet { - private static final long serialVersionUID = 1L; - - private final static String className; - - /** - * Tests google's behaviour in static context - */ - static { - StackTraceElement[] sTrace = new Exception().getStackTrace(); - // sTrace[0] will be always there - className = sTrace[0].getClassName(); - } - - @Inject - BlobStoreContext context; - - @Resource - protected Logger logger = Logger.NULL; - - public static class BucketResult implements Comparable { - private String name; - private String size = "unknown"; - private String status = "ok"; - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setSize(String size) { - this.size = size; - } - - public String getSize() { - return size; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getStatus() { - return status; - } - - public int compareTo(BucketResult o) { - return (this == o) ? 0 : getName().compareTo(o.getName()); - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - try { - SortedSet myBucketMetadata = context.getApi().listOwnedBuckets().get(10, - TimeUnit.SECONDS); - SortedSet myBuckets = Sets.newTreeSet(); - for (BucketMetadata metadata : myBucketMetadata) { - BucketResult result = new BucketResult(); - result.setName(metadata.getName()); - try { - try { - ListBucketResponse bucket = context.getApi().listBucket(metadata.getName()).get( - 10, TimeUnit.SECONDS); - result.setSize(bucket.size() + ""); - } catch (ContainerNotFoundException ex) { - result.setStatus("not found"); - } - } catch (Exception e) { - logger.error(e, "Error listing bucket %1$s", result.getName()); - result.setStatus(e.getMessage()); - } - myBuckets.add(result); - } - request.setAttribute("buckets", myBuckets); - request.setAttribute("className", className); - String nextJSP = "/WEB-INF/jsp/buckets.jsp"; - RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextJSP); - dispatcher.forward(request, response); - } catch (Exception e) { - logger.error(e, "Error listing buckets"); - throw new ServletException(e); - } - } -} \ No newline at end of file diff --git a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java index e1d02bed70..a347a42ab3 100644 --- a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java +++ b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java @@ -23,23 +23,28 @@ */ 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.inject.Inject; import javax.servlet.ServletContextEvent; import org.apache.commons.io.IOUtils; -import org.jclouds.aws.s3.S3Client; -import org.jclouds.aws.s3.blobstore.S3BlobStoreContextBuilder; -import org.jclouds.aws.s3.blobstore.S3BlobStorePropertiesBuilder; -import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.blobstore.BlobStoreContext; +import org.jclouds.blobstore.BlobStoreContextBuilder; +import org.jclouds.blobstore.reference.BlobStoreConstants; import org.jclouds.gae.config.GaeHttpCommandExecutorServiceModule; -import org.jclouds.samples.googleappengine.GetAllBucketsController; +import org.jclouds.samples.googleappengine.GetAllContainersController; +import com.google.appengine.repackaged.com.google.common.collect.ImmutableList; +import com.google.common.collect.Maps; +import com.google.inject.Guice; import com.google.inject.Injector; +import com.google.inject.TypeLiteral; import com.google.inject.servlet.GuiceServletContextListener; import com.google.inject.servlet.ServletModule; @@ -49,16 +54,30 @@ import com.google.inject.servlet.ServletModule; * @author Adrian Cole */ public class GuiceServletConfig extends GuiceServletContextListener { - @Inject - BlobStoreContext context; - String accessKeyId; - String secretAccessKey; + private Map> contexts; + + @SuppressWarnings("unchecked") @Override public void contextInitialized(ServletContextEvent servletContextEvent) { Properties props = loadJCloudsProperties(servletContextEvent); - this.accessKeyId = props.getProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID); - this.secretAccessKey = props.getProperty(S3Constants.PROPERTY_AWS_SECRETACCESSKEY); + ImmutableList list = ImmutableList. of(checkNotNull( + props.getProperty(BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTBUILDERS), + BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTBUILDERS).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 GaeHttpCommandExecutorServiceModule()).buildContext()); + } catch (Exception e) { + throw new RuntimeException(e); + } + } super.contextInitialized(servletContextEvent); } @@ -78,20 +97,24 @@ public class GuiceServletConfig extends GuiceServletContextListener { @Override protected Injector getInjector() { - return new S3BlobStoreContextBuilder(new S3BlobStorePropertiesBuilder(accessKeyId, - secretAccessKey).build()).withModules(new GaeHttpCommandExecutorServiceModule(), - new ServletModule() { - @Override - protected void configureServlets() { - serve("*.s3").with(GetAllBucketsController.class); - requestInjection(this); - } - }).buildInjector(); + return Guice.createInjector(new ServletModule() { + @Override + protected void configureServlets() { + bind(new TypeLiteral>>() { + }).toInstance(GuiceServletConfig.this.contexts); + serve("*.blobstore").with(GetAllContainersController.class); + requestInjection(this); + } + } + + ); } @Override public void contextDestroyed(ServletContextEvent servletContextEvent) { - context.close(); + for (BlobStoreContext context : contexts.values()) { + context.close(); + } super.contextDestroyed(servletContextEvent); } } \ No newline at end of file diff --git a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/domain/BucketResult.java b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/domain/BucketResult.java deleted file mode 100644 index 5bffa3eb2f..0000000000 --- a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/domain/BucketResult.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.samples.googleappengine.domain; - - -public class BucketResult implements Comparable{ - private String name; - private String size = "unknown"; - private String status = "ok"; - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setSize(String size) { - this.size = size; - } - - public String getSize() { - return size; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getStatus() { - return status; - } - - public int compareTo(BucketResult o) { - return (this == o) ? 0 : getName().compareTo(o.getName()); - } -} diff --git a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/domain/ContainerResult.java b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/domain/ContainerResult.java new file mode 100755 index 0000000000..6f1183fbd5 --- /dev/null +++ b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/domain/ContainerResult.java @@ -0,0 +1,110 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.samples.googleappengine.domain; + +import java.io.Serializable; + +/** + * + * @author Adrian Cole + */ +public class ContainerResult implements Comparable, Serializable { + /** The serialVersionUID */ + private static final long serialVersionUID = -3257496189689220018L; + private final String service; + private final String host; + private final String name; + private final String status; + + public ContainerResult(String service, String host, String name, String status) { + this.service = service; + this.host = host; + this.name = name; + this.status = status; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((host == null) ? 0 : host.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((service == null) ? 0 : service.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ContainerResult other = (ContainerResult) obj; + if (host == null) { + if (other.host != null) + return false; + } else if (!host.equals(other.host)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (service == null) { + if (other.service != null) + return false; + } else if (!service.equals(other.service)) + return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + return false; + return true; + } + + public int compareTo(ContainerResult o) { + return (this == o) ? 0 : getService().compareTo(o.getService()); + } + + public String getHost() { + return host; + } + + public String getName() { + return name; + } + + public String getStatus() { + return status; + } + + public String getService() { + return service; + } + +} diff --git a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/BlobStoreContextToContainerResult.java b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/BlobStoreContextToContainerResult.java new file mode 100755 index 0000000000..1f14b99ed6 --- /dev/null +++ b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/BlobStoreContextToContainerResult.java @@ -0,0 +1,103 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.samples.googleappengine.functions; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +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.ResourceMetadata; +import org.jclouds.blobstore.domain.ResourceType; +import org.jclouds.logging.Logger; +import org.jclouds.samples.googleappengine.domain.ContainerResult; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; + +@Singleton +public class BlobStoreContextToContainerResult implements Function { + private final class BuildContainerResult implements Function { + 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 ContainerResult apply(ResourceMetadata from) { + String status; + try { + try { + long start = System.currentTimeMillis(); + context.getBlobStore().exists(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 ContainerResult(contextName, host, from.getName(), status); + } + } + + @Inject + private Map> contexts; + + @Resource + protected Logger logger = Logger.NULL; + + public ContainerResult apply(final String contextName) { + final BlobStoreContext context = contexts.get(contextName); + final String host = context.getEndPoint().getHost(); + try { + ResourceMetadata md = Iterables.getLast(Sets.newTreeSet(Iterables.filter(context + .getBlobStore().list().get(10, TimeUnit.SECONDS), + new Predicate() { + + public boolean apply(ResourceMetadata input) { + return input.getType() == ResourceType.CONTAINER; + } + + }))); + return new BuildContainerResult(host, context, contextName).apply(md); + } catch (Exception e) { + ContainerResult result = new ContainerResult(contextName, host, null, e.getMessage()); + logger.error(e, "Error listing service %s", contextName); + return result; + } + + } +} \ No newline at end of file diff --git a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/MetadataToBucketResult.java b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/MetadataToBucketResult.java deleted file mode 100644 index 96aa7d805d..0000000000 --- a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/functions/MetadataToBucketResult.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.samples.googleappengine.functions; - -import java.util.concurrent.TimeUnit; - -import javax.annotation.Resource; -import javax.inject.Inject; - -import org.jclouds.aws.s3.blobstore.S3BlobStore; -import org.jclouds.aws.s3.domain.BucketMetadata; -import org.jclouds.blobstore.ContainerNotFoundException; -import org.jclouds.blobstore.domain.BoundedSortedSet; -import org.jclouds.blobstore.domain.ResourceMetadata; -import org.jclouds.logging.Logger; -import org.jclouds.samples.googleappengine.domain.BucketResult; - -import com.google.common.base.Function; - -public class MetadataToBucketResult implements Function { - private final S3BlobStore connection; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - public MetadataToBucketResult(S3BlobStore connection) { - this.connection = connection; - } - - public BucketResult apply(BucketMetadata from) { - BucketResult result = new BucketResult(); - result.setName(from.getName()); - try { - try { - BoundedSortedSet bucket = connection.list(from.getName()).get(10, - TimeUnit.SECONDS); - result.setSize(bucket.size() + ""); - } catch (ContainerNotFoundException ex) { - result.setStatus("not found"); - } - } catch (Exception e) { - logger.error(e, "Error listing bucket %1$s", result.getName()); - result.setStatus(e.getMessage()); - } - return result; - } -} \ No newline at end of file diff --git a/aws/s3/samples/googleappengine/src/main/webapp/WEB-INF/jsp/buckets.jsp b/aws/s3/samples/googleappengine/src/main/webapp/WEB-INF/jsp/containers.jsp old mode 100644 new mode 100755 similarity index 81% rename from aws/s3/samples/googleappengine/src/main/webapp/WEB-INF/jsp/buckets.jsp rename to aws/s3/samples/googleappengine/src/main/webapp/WEB-INF/jsp/containers.jsp index 91de40102f..420554d39c --- a/aws/s3/samples/googleappengine/src/main/webapp/WEB-INF/jsp/buckets.jsp +++ b/aws/s3/samples/googleappengine/src/main/webapp/WEB-INF/jsp/containers.jsp @@ -30,11 +30,12 @@ jclouds: anyweight cloudware for java -

Bucket List

- - - - +

Container List

+ + + + + diff --git a/aws/s3/samples/googleappengine/src/main/webapp/WEB-INF/web.xml b/aws/s3/samples/googleappengine/src/main/webapp/WEB-INF/web.xml index 8411f98696..060ee1efe1 100644 --- a/aws/s3/samples/googleappengine/src/main/webapp/WEB-INF/web.xml +++ b/aws/s3/samples/googleappengine/src/main/webapp/WEB-INF/web.xml @@ -23,35 +23,12 @@ ==================================================================== --> - - - jclouds-s3-example + jclouds-blobstore-example diff --git a/aws/s3/samples/googleappengine/src/main/webapp/index.jsp b/aws/s3/samples/googleappengine/src/main/webapp/index.jsp index 85ea92c211..e096ce23dc 100644 --- a/aws/s3/samples/googleappengine/src/main/webapp/index.jsp +++ b/aws/s3/samples/googleappengine/src/main/webapp/index.jsp @@ -30,7 +30,7 @@

Welcome!

Click -here -to list my buckets. +here +to list my containers. diff --git a/aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java b/aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java index b7ddba62be..03c27a21b7 100644 --- a/aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java +++ b/aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java @@ -24,6 +24,13 @@ 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.blobstore.reference.BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTBUILDERS; +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; @@ -31,7 +38,12 @@ import java.net.URL; import java.util.Properties; import org.apache.commons.io.IOUtils; -import org.jclouds.aws.s3.reference.S3Constants; +import org.jclouds.aws.s3.S3PropertiesBuilder; +import org.jclouds.aws.s3.blobstore.S3BlobStoreContextBuilder; +import org.jclouds.azure.storage.blob.AzureBlobPropertiesBuilder; +import org.jclouds.azure.storage.blob.blobstore.AzureBlobStoreContextBuilder; +import org.jclouds.rackspace.cloudfiles.CloudFilesPropertiesBuilder; +import org.jclouds.rackspace.cloudfiles.blobstore.CloudFilesBlobStoreContextBuilder; import org.testng.annotations.BeforeTest; import org.testng.annotations.Parameters; import org.testng.annotations.Test; @@ -52,16 +64,29 @@ public class GoogleAppEngineLiveTest { @Parameters( { "warfile", "devappserver.address", "devappserver.port" }) public void startDevAppServer(final String warfile, final String address, final String port) throws Exception { - url = new URL(String.format("http://%1$s:%2$s", address, port)); - String account = System.getProperty("jclouds.test.user"); - String key = System.getProperty("jclouds.test.key"); - - checkNotNull(account, "account"); - checkNotNull(key, "key"); - + url = new URL(String.format("http://%s:%s", address, port)); Properties props = new Properties(); - props.put(S3Constants.PROPERTY_AWS_ACCESSKEYID, account); - props.put(S3Constants.PROPERTY_AWS_SECRETACCESSKEY, key); + + props.setProperty(PROPERTY_BLOBSTORE_CONTEXTBUILDERS, String.format("%s,%s,%s", + S3BlobStoreContextBuilder.class.getName(), CloudFilesBlobStoreContextBuilder.class + .getName(), AzureBlobStoreContextBuilder.class.getName())); + + props = new S3PropertiesBuilder(props) + .withCredentials( + checkNotNull(System.getProperty(PROPERTY_AWS_ACCESSKEYID), + PROPERTY_AWS_ACCESSKEYID), + 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(); + server = new GoogleDevServer(); server.writePropertiesAndStartServer(address, port, warfile, props); } @@ -75,15 +100,15 @@ public class GoogleAppEngineLiveTest { @Test(invocationCount = 5, enabled = true) public void testGuiceJCloudsSerial() throws InterruptedException, IOException { - URL gurl = new URL(url, "/guice/listbuckets.s3"); + URL gurl = new URL(url, "/guice/containers.blobstore"); InputStream i = gurl.openStream(); String string = IOUtils.toString(i); assert string.indexOf("List") >= 0 : string; } - @Test(invocationCount = 50, enabled = true, threadPoolSize = 10) + @Test(invocationCount = 10, enabled = true, threadPoolSize = 3) public void testGuiceJCloudsParallel() throws InterruptedException, IOException { - URL gurl = new URL(url, "/guice/listbuckets.s3"); + URL gurl = new URL(url, "/guice/containers.blobstore"); InputStream i = gurl.openStream(); String string = IOUtils.toString(i); assert string.indexOf("List") >= 0 : string;