mirror of https://github.com/apache/jclouds.git
made google sample work across clouds
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2031 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
0c7ac791dc
commit
af2fa174d1
|
@ -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
|
|||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<appengine.home>/path/to/appengine-java-sdk-1.2.1</appengine.home>
|
||||
<appengine.home>/path/to/appengine-java-sdk-1.2.5</appengine.home>
|
||||
</properties>
|
||||
</profile>
|
||||
|
||||
|
|
|
@ -46,6 +46,16 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-azureblob</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-cloudfiles</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-gae</artifactId>
|
||||
|
@ -194,11 +204,27 @@
|
|||
<configuration>
|
||||
<systemProperties>
|
||||
<property>
|
||||
<name>jclouds.test.user</name>
|
||||
<name>jclouds.azure.storage.account</name>
|
||||
<value>${jclouds.azure.storage.account}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.azure.storage.key</name>
|
||||
<value>${jclouds.azure.storage.key}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.rackspace.user</name>
|
||||
<value>${jclouds.rackspace.user}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.rackspace.key</name>
|
||||
<value>${jclouds.rackspace.key}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.aws.accesskeyid</name>
|
||||
<value>${jclouds.aws.accesskeyid}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>jclouds.test.key</name>
|
||||
<name>jclouds.aws.secretaccesskey</name>
|
||||
<value>${jclouds.aws.secretaccesskey}</value>
|
||||
</property>
|
||||
<property>
|
||||
|
|
|
@ -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<S3Client> context;
|
||||
private final Provider<MetadataToBucketResult> metadataToBucketResultProvider;
|
||||
private Map<String, BlobStoreContext<?>> contexts;
|
||||
private final BlobStoreContextToContainerResult blobStoreContextToContainerResult;
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
@Inject
|
||||
public GetAllBucketsController(BlobStoreContext<S3Client> context,
|
||||
Provider<MetadataToBucketResult> metadataToBucketResultProvider) {
|
||||
this.context = context;
|
||||
this.metadataToBucketResultProvider = metadataToBucketResultProvider;
|
||||
public GetAllContainersController(Map<String, BlobStoreContext<?>> 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<BucketMetadata> myBucketMetadata = context.getApi().listOwnedBuckets().get(10,
|
||||
TimeUnit.SECONDS);
|
||||
SortedSet<BucketResult> myBuckets = Sets.newTreeSet(Iterables.transform(myBucketMetadata,
|
||||
metadataToBucketResultProvider.get()));
|
||||
request.setAttribute("buckets", myBuckets);
|
||||
request.setAttribute("containers", Sets.newTreeSet(Iterables.transform(contexts.keySet(),
|
||||
blobStoreContextToContainerResult)));
|
||||
}
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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<S3Client> context;
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
public static class BucketResult implements Comparable<BucketResult> {
|
||||
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<BucketMetadata> myBucketMetadata = context.getApi().listOwnedBuckets().get(10,
|
||||
TimeUnit.SECONDS);
|
||||
SortedSet<BucketResult> 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<S3Client> context;
|
||||
String accessKeyId;
|
||||
String secretAccessKey;
|
||||
|
||||
private Map<String, BlobStoreContext<?>> 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<String> list = ImmutableList.<String> of(checkNotNull(
|
||||
props.getProperty(BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTBUILDERS),
|
||||
BlobStoreConstants.PROPERTY_BLOBSTORE_CONTEXTBUILDERS).split(","));
|
||||
contexts = Maps.newHashMap();
|
||||
for (String className : list) {
|
||||
try {
|
||||
Class<BlobStoreContextBuilder<?>> builderClass;
|
||||
builderClass = (Class<BlobStoreContextBuilder<?>>) Class.forName(className);
|
||||
String name = builderClass.getSimpleName().replaceAll("BlobStoreContextBuilder", "");
|
||||
Constructor<BlobStoreContextBuilder<?>> 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() {
|
||||
return Guice.createInjector(new ServletModule() {
|
||||
@Override
|
||||
protected void configureServlets() {
|
||||
serve("*.s3").with(GetAllBucketsController.class);
|
||||
bind(new TypeLiteral<Map<String, BlobStoreContext<?>>>() {
|
||||
}).toInstance(GuiceServletConfig.this.contexts);
|
||||
serve("*.blobstore").with(GetAllContainersController.class);
|
||||
requestInjection(this);
|
||||
}
|
||||
}).buildInjector();
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent servletContextEvent) {
|
||||
for (BlobStoreContext<?> context : contexts.values()) {
|
||||
context.close();
|
||||
}
|
||||
super.contextDestroyed(servletContextEvent);
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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<BucketResult>{
|
||||
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());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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<ContainerResult>, 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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<String, ContainerResult> {
|
||||
private final class BuildContainerResult implements Function<ResourceMetadata, ContainerResult> {
|
||||
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<String, BlobStoreContext<?>> 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<ResourceMetadata>() {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* 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<BucketMetadata, BucketResult> {
|
||||
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<? extends ResourceMetadata> 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;
|
||||
}
|
||||
}
|
|
@ -30,10 +30,11 @@
|
|||
<title>jclouds: anyweight cloudware for java</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Bucket List</h2>
|
||||
<display:table name="buckets">
|
||||
<display:column property="name" title="Bucket" />
|
||||
<display:column property="size" title="Size" />
|
||||
<h2>Container List</h2>
|
||||
<display:table name="containers" >
|
||||
<display:column property="service" title="Service" />
|
||||
<display:column property="host" title="Host" />
|
||||
<display:column property="name" title="Container" />
|
||||
<display:column property="status" title="Status" />
|
||||
</display:table>
|
||||
</body>
|
|
@ -23,35 +23,12 @@
|
|||
====================================================================
|
||||
|
||||
-->
|
||||
|
||||
<!--
|
||||
|
||||
|
||||
Copyright (C) 2009 Global Cloud Specialists, Inc.
|
||||
<info@globalcloudspecialists.com>
|
||||
|
||||
====================================================================
|
||||
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.
|
||||
====================================================================
|
||||
-->
|
||||
<!DOCTYPE web-app PUBLIC
|
||||
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
|
||||
"http://java.sun.com/dtd/web-app_2_3.dtd">
|
||||
|
||||
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
|
||||
<display-name>jclouds-s3-example</display-name>
|
||||
<display-name>jclouds-blobstore-example</display-name>
|
||||
|
||||
<!-- Servlets -->
|
||||
<filter>
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<body>
|
||||
<h2>Welcome!</h2>
|
||||
Click
|
||||
<a href="/guice/listbuckets.s3">here</a>
|
||||
to list my buckets.
|
||||
<a href="/guice/containers.blobstore">here</a>
|
||||
to list my containers.
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue