mirror of https://github.com/apache/jclouds.git
new GoogleAppEngineConfigurationModule
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2672 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
49f14ca0e8
commit
35b2043e95
|
@ -31,7 +31,7 @@ import javax.servlet.ServletContextEvent;
|
||||||
import org.jclouds.blobstore.BlobStoreContext;
|
import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
||||||
import org.jclouds.blobstore.reference.BlobStoreConstants;
|
import org.jclouds.blobstore.reference.BlobStoreConstants;
|
||||||
import org.jclouds.gae.config.GaeHttpCommandExecutorServiceModule;
|
import org.jclouds.gae.config.GoogleAppEngineConfigurationModule;
|
||||||
import org.jclouds.samples.googleappengine.GetAllContainersController;
|
import org.jclouds.samples.googleappengine.GetAllContainersController;
|
||||||
|
|
||||||
import com.google.appengine.repackaged.com.google.common.collect.ImmutableList;
|
import com.google.appengine.repackaged.com.google.common.collect.ImmutableList;
|
||||||
|
@ -68,7 +68,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
Constructor<BlobStoreContextBuilder<?, ?>> constructor = builderClass
|
Constructor<BlobStoreContextBuilder<?, ?>> constructor = builderClass
|
||||||
.getConstructor(Properties.class);
|
.getConstructor(Properties.class);
|
||||||
contexts.put(name, constructor.newInstance(props).withModules(
|
contexts.put(name, constructor.newInstance(props).withModules(
|
||||||
new GaeHttpCommandExecutorServiceModule()).buildContext());
|
new GoogleAppEngineConfigurationModule()).buildContext());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,16 +24,14 @@ import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.jclouds.date.joda.config.JodaDateServiceModule;
|
import org.jclouds.gae.config.GoogleAppEngineConfigurationModule;
|
||||||
import org.jclouds.encryption.bouncycastle.config.BouncyCastleEncryptionServiceModule;
|
|
||||||
import org.jclouds.gae.config.GaeHttpCommandExecutorServiceModule;
|
|
||||||
import org.jclouds.http.config.ConfiguresHttpCommandExecutorService;
|
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.testng.v6.Maps;
|
import org.testng.v6.Maps;
|
||||||
|
|
||||||
import com.google.appengine.tools.development.ApiProxyLocalImpl;
|
import com.google.appengine.tools.development.ApiProxyLocalImpl;
|
||||||
import com.google.apphosting.api.ApiProxy;
|
import com.google.apphosting.api.ApiProxy;
|
||||||
|
import com.google.inject.Module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -152,16 +150,6 @@ public class JCloudsGaePerformanceLiveTest extends BaseJCloudsPerformanceLiveTes
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfiguresHttpCommandExecutorService
|
|
||||||
private static final class Module extends GaeHttpCommandExecutorServiceModule {
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
super.configure();
|
|
||||||
install(new JodaDateServiceModule());
|
|
||||||
install(new BouncyCastleEncryptionServiceModule());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TestEnvironment implements ApiProxy.Environment {
|
class TestEnvironment implements ApiProxy.Environment {
|
||||||
public String getAppId() {
|
public String getAppId() {
|
||||||
return "Unit Tests";
|
return "Unit Tests";
|
||||||
|
@ -205,6 +193,6 @@ public class JCloudsGaePerformanceLiveTest extends BaseJCloudsPerformanceLiveTes
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Module createHttpModule() {
|
protected Module createHttpModule() {
|
||||||
return new Module();
|
return new GoogleAppEngineConfigurationModule();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -40,7 +40,7 @@ import org.jclouds.blobstore.BlobStoreContextBuilder;
|
||||||
import org.jclouds.demo.tweetstore.controller.AddTweetsController;
|
import org.jclouds.demo.tweetstore.controller.AddTweetsController;
|
||||||
import org.jclouds.demo.tweetstore.controller.StoreTweetsController;
|
import org.jclouds.demo.tweetstore.controller.StoreTweetsController;
|
||||||
import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses;
|
import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses;
|
||||||
import org.jclouds.gae.config.GaeHttpCommandExecutorServiceModule;
|
import org.jclouds.gae.config.GoogleAppEngineConfigurationModule;
|
||||||
import org.jclouds.twitter.TwitterClient;
|
import org.jclouds.twitter.TwitterClient;
|
||||||
import org.jclouds.twitter.TwitterContextFactory;
|
import org.jclouds.twitter.TwitterContextFactory;
|
||||||
import org.springframework.beans.factory.BeanCreationException;
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
|
@ -81,7 +81,7 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA
|
||||||
|
|
||||||
// shared across all blobstores and used to retrieve tweets
|
// shared across all blobstores and used to retrieve tweets
|
||||||
twitterClient = TwitterContextFactory.createContext(props,
|
twitterClient = TwitterContextFactory.createContext(props,
|
||||||
new GaeHttpCommandExecutorServiceModule()).getApi();
|
new GoogleAppEngineConfigurationModule()).getApi();
|
||||||
|
|
||||||
// common namespace for storing tweets
|
// common namespace for storing tweets
|
||||||
container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER),
|
container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER),
|
||||||
|
@ -103,7 +103,7 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA
|
||||||
name = builderClass.getSimpleName().replaceAll("BlobStoreContextBuilder", "");
|
name = builderClass.getSimpleName().replaceAll("BlobStoreContextBuilder", "");
|
||||||
constructor = builderClass.getConstructor(Properties.class);
|
constructor = builderClass.getConstructor(Properties.class);
|
||||||
context = constructor.newInstance(props)
|
context = constructor.newInstance(props)
|
||||||
.withModules(new GaeHttpCommandExecutorServiceModule())
|
.withModules(new GoogleAppEngineConfigurationModule())
|
||||||
.buildContext();
|
.buildContext();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("error instantiating " + className, e);
|
throw new RuntimeException("error instantiating " + className, e);
|
||||||
|
|
|
@ -35,7 +35,7 @@ import org.jclouds.blobstore.BlobStoreContext;
|
||||||
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
import org.jclouds.blobstore.BlobStoreContextBuilder;
|
||||||
import org.jclouds.demo.tweetstore.controller.AddTweetsController;
|
import org.jclouds.demo.tweetstore.controller.AddTweetsController;
|
||||||
import org.jclouds.demo.tweetstore.controller.StoreTweetsController;
|
import org.jclouds.demo.tweetstore.controller.StoreTweetsController;
|
||||||
import org.jclouds.gae.config.GaeHttpCommandExecutorServiceModule;
|
import org.jclouds.gae.config.GoogleAppEngineConfigurationModule;
|
||||||
import org.jclouds.twitter.TwitterClient;
|
import org.jclouds.twitter.TwitterClient;
|
||||||
import org.jclouds.twitter.TwitterContextFactory;
|
import org.jclouds.twitter.TwitterContextFactory;
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
|
|
||||||
// shared across all blobstores and used to retrieve tweets
|
// shared across all blobstores and used to retrieve tweets
|
||||||
twitterClient = TwitterContextFactory.createContext(props,
|
twitterClient = TwitterContextFactory.createContext(props,
|
||||||
new GaeHttpCommandExecutorServiceModule()).getApi();
|
new GoogleAppEngineConfigurationModule()).getApi();
|
||||||
|
|
||||||
// common namespace for storing tweets.
|
// common namespace for storing tweets.
|
||||||
container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER),
|
container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER),
|
||||||
|
@ -92,7 +92,7 @@ public class GuiceServletConfig extends GuiceServletContextListener {
|
||||||
name = builderClass.getSimpleName().replaceAll("BlobStoreContextBuilder", "");
|
name = builderClass.getSimpleName().replaceAll("BlobStoreContextBuilder", "");
|
||||||
constructor = builderClass.getConstructor(Properties.class);
|
constructor = builderClass.getConstructor(Properties.class);
|
||||||
context = constructor.newInstance(props).withModules(
|
context = constructor.newInstance(props).withModules(
|
||||||
new GaeHttpCommandExecutorServiceModule()).buildContext();
|
new GoogleAppEngineConfigurationModule()).buildContext();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("error instantiating " + className, e);
|
throw new RuntimeException("error instantiating " + className, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,23 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!--
|
<!--
|
||||||
|
|
||||||
|
|
||||||
Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
Copyright (C) 2009 Cloud Conscious, LLC.
|
||||||
|
<info@cloudconscious.com>
|
||||||
|
|
||||||
====================================================================
|
====================================================================
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0 Unless required by
|
||||||
|
applicable law or agreed to in writing, software distributed
|
||||||
Unless required by applicable law or agreed to in writing, software
|
under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
See the License for the specific language governing permissions
|
||||||
See the License for the specific language governing permissions and
|
and limitations under the License.
|
||||||
limitations under the License.
|
====================================================================
|
||||||
====================================================================
|
-->
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
@ -40,6 +39,16 @@
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>jclouds-joda</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>${project.groupId}</groupId>
|
||||||
|
<artifactId>jclouds-bouncycastle</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.appengine</groupId>
|
<groupId>com.google.appengine</groupId>
|
||||||
<artifactId>appengine-api</artifactId>
|
<artifactId>appengine-api</artifactId>
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
package org.jclouds.gae.config;
|
package org.jclouds.gae.config;
|
||||||
|
|
||||||
import org.jclouds.concurrent.SingleThreaded;
|
import org.jclouds.concurrent.SingleThreaded;
|
||||||
|
import org.jclouds.concurrent.config.ConfiguresExecutorService;
|
||||||
|
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||||
|
import org.jclouds.date.joda.config.JodaDateServiceModule;
|
||||||
|
import org.jclouds.encryption.bouncycastle.config.BouncyCastleEncryptionServiceModule;
|
||||||
import org.jclouds.gae.GaeHttpCommandExecutorService;
|
import org.jclouds.gae.GaeHttpCommandExecutorService;
|
||||||
import org.jclouds.http.HttpCommandExecutorService;
|
import org.jclouds.http.HttpCommandExecutorService;
|
||||||
import org.jclouds.http.TransformingHttpCommandExecutorService;
|
import org.jclouds.http.TransformingHttpCommandExecutorService;
|
||||||
|
@ -27,7 +31,7 @@ import org.jclouds.http.config.ConfiguresHttpCommandExecutorService;
|
||||||
|
|
||||||
import com.google.appengine.api.urlfetch.URLFetchService;
|
import com.google.appengine.api.urlfetch.URLFetchService;
|
||||||
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;
|
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.common.util.concurrent.Executors;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,11 +40,19 @@ import com.google.inject.Provides;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@ConfiguresHttpCommandExecutorService
|
@ConfiguresHttpCommandExecutorService
|
||||||
|
@ConfiguresExecutorService
|
||||||
@SingleThreaded
|
@SingleThreaded
|
||||||
public class GaeHttpCommandExecutorServiceModule extends AbstractModule {
|
public class GoogleAppEngineConfigurationModule extends ExecutorServiceModule {
|
||||||
|
|
||||||
|
public GoogleAppEngineConfigurationModule() {
|
||||||
|
super(Executors.sameThreadExecutor());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
|
super.configure();
|
||||||
|
install(new BouncyCastleEncryptionServiceModule());
|
||||||
|
install(new JodaDateServiceModule());
|
||||||
bind(HttpCommandExecutorService.class).to(GaeHttpCommandExecutorService.class);
|
bind(HttpCommandExecutorService.class).to(GaeHttpCommandExecutorService.class);
|
||||||
bind(TransformingHttpCommandExecutorService.class).to(
|
bind(TransformingHttpCommandExecutorService.class).to(
|
||||||
TransformingHttpCommandExecutorServiceImpl.class);
|
TransformingHttpCommandExecutorServiceImpl.class);
|
||||||
|
@ -50,5 +62,4 @@ public class GaeHttpCommandExecutorServiceModule extends AbstractModule {
|
||||||
URLFetchService provideURLFetchService() {
|
URLFetchService provideURLFetchService() {
|
||||||
return URLFetchServiceFactory.getURLFetchService();
|
return URLFetchServiceFactory.getURLFetchService();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
|
@ -27,7 +27,7 @@ import java.util.Properties;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import org.jclouds.gae.config.GaeHttpCommandExecutorServiceModule;
|
import org.jclouds.gae.config.GoogleAppEngineConfigurationModule;
|
||||||
import org.jclouds.http.BaseHttpCommandExecutorServiceTest;
|
import org.jclouds.http.BaseHttpCommandExecutorServiceTest;
|
||||||
import org.testng.annotations.BeforeMethod;
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
|
@ -241,7 +241,7 @@ public class GaeHttpCommandExecutorServiceIntegrationTest extends
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Module createConnectionModule() {
|
protected Module createConnectionModule() {
|
||||||
return new GaeHttpCommandExecutorServiceModule();
|
return new GoogleAppEngineConfigurationModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,11 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.gae.config;
|
package org.jclouds.gae.config;
|
||||||
|
|
||||||
import static com.google.common.util.concurrent.Executors.sameThreadExecutor;
|
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
|
||||||
import org.jclouds.gae.GaeHttpCommandExecutorService;
|
import org.jclouds.gae.GaeHttpCommandExecutorService;
|
||||||
import org.jclouds.http.HttpCommandExecutorService;
|
import org.jclouds.http.HttpCommandExecutorService;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
|
@ -34,29 +31,28 @@ import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the ability to configure a {@link GaeHttpCommandExecutorService}
|
* Tests the ability to configure a {@link GoogleAppEngineConfigurationModule}
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public class GaeHttpCommandExecutorServiceModuleTest {
|
public class GoogleAppEngineConfigurationModuleModuleTest {
|
||||||
|
|
||||||
public void testConfigureBindsClient() {
|
public void testConfigureBindsClient() {
|
||||||
final Properties properties = new Properties();
|
final Properties properties = new Properties();
|
||||||
|
|
||||||
Injector i = Guice.createInjector(new ExecutorServiceModule(sameThreadExecutor()),
|
Injector i = Guice.createInjector(new GoogleAppEngineConfigurationModule() {
|
||||||
new GaeHttpCommandExecutorServiceModule() {
|
@Override
|
||||||
@Override
|
protected void configure() {
|
||||||
protected void configure() {
|
Jsr330.bindProperties(binder(), properties);
|
||||||
Jsr330.bindProperties(binder(), properties);
|
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
||||||
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
|
public Logger getLogger(String category) {
|
||||||
public Logger getLogger(String category) {
|
return Logger.NULL;
|
||||||
return Logger.NULL;
|
}
|
||||||
}
|
});
|
||||||
});
|
super.configure();
|
||||||
super.configure();
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
HttpCommandExecutorService client = i.getInstance(HttpCommandExecutorService.class);
|
HttpCommandExecutorService client = i.getInstance(HttpCommandExecutorService.class);
|
||||||
assert client instanceof GaeHttpCommandExecutorService;
|
assert client instanceof GaeHttpCommandExecutorService;
|
||||||
}
|
}
|
|
@ -20,6 +20,7 @@ package org.jclouds.date.joda;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
@ -100,10 +101,29 @@ public class JodaDateService implements DateService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Date iso8601DateParse(String toParse) {
|
public final Date iso8601DateParse(String toParse) {
|
||||||
|
toParse = trimNanosToMillis(toParse);
|
||||||
return iso8601DateFormatter.parseDateTime(toParse).toDate();
|
return iso8601DateFormatter.parseDateTime(toParse).toDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final Pattern NANOS_TO_MILLIS_PATTERN = Pattern
|
||||||
|
.compile(".*[0-9][0-9][0-9][0-9][0-9][0-9]");
|
||||||
|
|
||||||
|
private String trimNanosToMillis(String toParse) {
|
||||||
|
if (NANOS_TO_MILLIS_PATTERN.matcher(toParse).matches())
|
||||||
|
toParse = toParse.substring(0, toParse.length() - 3) + 'Z';
|
||||||
|
return toParse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Pattern SECOND_PATTERN = Pattern.compile(".*[0-2][0-9]:00");
|
||||||
|
|
||||||
|
private String trimTZ(String toParse) {
|
||||||
|
if (toParse.length() == 25 && SECOND_PATTERN.matcher(toParse).matches())
|
||||||
|
toParse = toParse.substring(0, toParse.length() - 6) + 'Z';
|
||||||
|
return toParse;
|
||||||
|
}
|
||||||
|
|
||||||
public final Date iso8601SecondsDateParse(String toParse) {
|
public final Date iso8601SecondsDateParse(String toParse) {
|
||||||
|
toParse = trimTZ(toParse);
|
||||||
return iso8601SecondsDateFormatter.parseDateTime(toParse).toDate();
|
return iso8601SecondsDateFormatter.parseDateTime(toParse).toDate();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue