From e43df10f39fa825c298d2d8c98f0f40e6801407b Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 21 Oct 2012 15:27:45 -0700 Subject: [PATCH] Issue 1111:Move tweetstore to new jclouds-tweetstore repository --- demos/pom.xml | 1 - .../cf-tweetstore-spring/README.txt | 41 -- demos/tweetstore/cf-tweetstore-spring/pom.xml | 191 -------- .../jclouds/demo/paas/PlatformServices.java | 64 --- .../demo/paas/RunnableHttpRequest.java | 126 ------ .../demo/paas/config/HttpClientModule.java | 65 --- .../config/PlatformServicesInitializer.java | 86 ---- .../demo/paas/reference/PaasConstants.java | 28 -- .../service/scheduler/HttpRequestJob.java | 69 --- .../paas/service/scheduler/Scheduler.java | 41 -- ...nlessXmlSchedulingDataProcessorPlugin.java | 401 ----------------- .../paas/service/taskqueue/TaskQueue.java | 107 ----- .../DelegatingAutowireCapableBeanFactory.java | 129 ------ .../demo/tweetstore/config/LoggingConfig.java | 101 ----- .../config/SpringServletConfig.java | 242 ---------- .../config/util/CredentialsCollector.java | 153 ------- .../config/util/PropertiesLoader.java | 59 --- .../controller/AddTweetsController.java | 96 ---- .../controller/ClearTweetsController.java | 96 ---- .../controller/EnqueueStoresController.java | 101 ----- .../controller/StoreTweetsController.java | 130 ------ .../tweetstore/domain/StoredTweetStatus.java | 149 ------- .../functions/KeyToStoredTweetStatus.java | 70 --- .../ServiceToStoredTweetStatuses.java | 72 --- .../reference/TweetStoreConstants.java | 34 -- .../reference/TwitterConstants.java | 31 -- .../src/main/platform/.gitignore | 1 - .../src/main/resources/jobs.xml | 29 -- .../src/main/resources/quartz.properties | 28 -- .../src/main/webapp/WEB-INF/web.xml | 78 ---- .../main/webapp/images/cloudfoundry-logo.png | Bin 6042 -> 0 bytes .../src/main/webapp/index.jsp | 30 -- .../src/main/webapp/tweets.jsp | 108 ----- .../config/util/CredentialsCollectorTest.java | 82 ---- .../controller/AddTweetsControllerTest.java | 78 ---- .../controller/ClearTweetsControllerTest.java | 72 --- .../EnqueueStoresControllerTest.java | 85 ---- .../controller/StoreTweetsControllerTest.java | 120 ----- .../functions/KeyToStoredTweetStatusTest.java | 69 --- .../ServiceToStoredTweetStatusesTest.java | 75 ---- .../integration/CloudFoundryServer.java | 106 ----- .../integration/TweetStoreLiveTest.java | 234 ---------- .../tweetstore/integration/util/Zips.java | 36 -- .../src/test/resources/log4j.xml | 95 ---- .../gae-tweetstore-spring/README.txt | 64 --- .../tweetstore/gae-tweetstore-spring/pom.xml | 156 ------- .../demo/tweetstore/config/LoggingConfig.java | 32 -- .../config/SpringServletConfig.java | 241 ---------- .../config/util/CredentialsCollector.java | 153 ------- .../controller/AddTweetsController.java | 96 ---- .../controller/ClearTweetsController.java | 96 ---- .../controller/EnqueueStoresController.java | 92 ---- .../controller/StoreTweetsController.java | 129 ------ .../tweetstore/domain/StoredTweetStatus.java | 149 ------- .../functions/KeyToStoredTweetStatus.java | 70 --- .../ServiceToStoredTweetStatuses.java | 72 --- .../reference/TweetStoreConstants.java | 34 -- .../reference/TwitterConstants.java | 31 -- .../src/main/platform/appengine-web.xml | 28 -- .../src/main/platform/cron.xml | 28 -- .../src/main/platform/logging.properties | 50 --- .../webapp/WEB-INF/dispatcher-servlet.xml | 38 -- .../src/main/webapp/WEB-INF/queue.xml | 29 -- .../src/main/webapp/WEB-INF/web.xml | 66 --- .../src/main/webapp/index.jsp | 31 -- .../src/main/webapp/tweets.jsp | 109 ----- .../config/util/CredentialsCollectorTest.java | 82 ---- .../controller/AddTweetsControllerTest.java | 78 ---- .../controller/ClearTweetsControllerTest.java | 72 --- .../EnqueueStoresControllerTest.java | 67 --- .../controller/StoreTweetsControllerTest.java | 120 ----- .../functions/KeyToStoredTweetStatusTest.java | 69 --- .../ServiceToStoredTweetStatusesTest.java | 75 ---- .../integration/GoogleDevServer.java | 87 ---- .../integration/TweetStoreLiveTest.java | 234 ---------- .../src/test/resources/log4j.xml | 95 ---- demos/tweetstore/gae-tweetstore/README.txt | 56 --- demos/tweetstore/gae-tweetstore/pom.xml | 138 ------ .../tweetstore/config/GuiceServletConfig.java | 165 ------- .../config/util/CredentialsCollector.java | 153 ------- .../controller/AddTweetsController.java | 96 ---- .../controller/ClearTweetsController.java | 96 ---- .../controller/EnqueueStoresController.java | 92 ---- .../controller/StoreTweetsController.java | 129 ------ .../tweetstore/domain/StoredTweetStatus.java | 149 ------- .../functions/KeyToStoredTweetStatus.java | 70 --- .../ServiceToStoredTweetStatuses.java | 73 --- .../reference/TweetStoreConstants.java | 34 -- .../reference/TwitterConstants.java | 31 -- .../src/main/platform/appengine-web.xml | 28 -- .../gae-tweetstore/src/main/platform/cron.xml | 28 -- .../src/main/platform/logging.properties | 37 -- .../src/main/webapp/WEB-INF/queue.xml | 29 -- .../src/main/webapp/WEB-INF/web.xml | 57 --- .../gae-tweetstore/src/main/webapp/index.jsp | 31 -- .../gae-tweetstore/src/main/webapp/tweets.jsp | 109 ----- .../config/util/CredentialsCollectorTest.java | 82 ---- .../controller/AddTweetsControllerTest.java | 78 ---- .../controller/ClearTweetsControllerTest.java | 72 --- .../EnqueueStoresControllerTest.java | 67 --- .../controller/StoreTweetsControllerTest.java | 120 ----- .../functions/KeyToStoredTweetStatusTest.java | 69 --- .../ServiceToStoredTweetStatusesTest.java | 76 ---- .../integration/GoogleDevServer.java | 87 ---- .../integration/TweetStoreLiveTest.java | 239 ---------- .../src/test/resources/log4j.xml | 95 ---- demos/tweetstore/heroku-tweetstore/README.txt | 41 -- demos/tweetstore/heroku-tweetstore/pom.xml | 148 ------ .../jclouds/demo/paas/PlatformServices.java | 57 --- .../demo/paas/RunnableHttpRequest.java | 126 ------ .../demo/paas/config/HttpClientModule.java | 65 --- .../config/PlatformServicesInitializer.java | 87 ---- .../demo/paas/reference/PaasConstants.java | 28 -- .../paas/service/taskqueue/TaskQueue.java | 107 ----- .../tweetstore/config/GuiceServletConfig.java | 155 ------- .../config/util/CredentialsCollector.java | 153 ------- .../config/util/PropertiesLoader.java | 59 --- .../controller/AddTweetsController.java | 96 ---- .../controller/ClearTweetsController.java | 96 ---- .../controller/EnqueueStoresController.java | 100 ----- .../controller/StoreTweetsController.java | 130 ------ .../tweetstore/domain/StoredTweetStatus.java | 149 ------- .../functions/KeyToStoredTweetStatus.java | 70 --- .../ServiceToStoredTweetStatuses.java | 72 --- .../reference/TweetStoreConstants.java | 34 -- .../reference/TwitterConstants.java | 31 -- .../src/main/platform/.gitignore | 1 - .../src/main/webapp/WEB-INF/web.xml | 51 --- .../src/main/webapp/images/heroku-logo.png | Bin 4239 -> 0 bytes .../src/main/webapp/index.jsp | 30 -- .../src/main/webapp/tweets.jsp | 108 ----- .../config/util/CredentialsCollectorTest.java | 82 ---- .../controller/AddTweetsControllerTest.java | 78 ---- .../controller/ClearTweetsControllerTest.java | 72 --- .../EnqueueStoresControllerTest.java | 85 ---- .../controller/StoreTweetsControllerTest.java | 121 ----- .../functions/KeyToStoredTweetStatusTest.java | 70 --- .../ServiceToStoredTweetStatusesTest.java | 75 ---- .../tweetstore/integration/JettyServer.java | 68 --- .../demo/tweetstore/integration/Runner2.java | 72 --- .../integration/TweetStoreLiveTest.java | 237 ---------- .../integration/util/ObjectFields.java | 56 --- .../src/test/resources/log4j.xml | 95 ---- demos/tweetstore/pom.xml | 422 ------------------ .../tweetstore/rhcloud-tweetstore/README.txt | 41 -- demos/tweetstore/rhcloud-tweetstore/pom.xml | 130 ------ .../jclouds/demo/paas/PlatformServices.java | 57 --- .../demo/paas/RunnableHttpRequest.java | 126 ------ .../demo/paas/config/HttpClientModule.java | 65 --- .../config/PlatformServicesInitializer.java | 87 ---- .../demo/paas/reference/PaasConstants.java | 28 -- .../paas/service/taskqueue/TaskQueue.java | 107 ----- .../tweetstore/config/GuiceServletConfig.java | 155 ------- .../config/util/CredentialsCollector.java | 153 ------- .../config/util/PropertiesLoader.java | 59 --- .../controller/AddTweetsController.java | 96 ---- .../controller/ClearTweetsController.java | 96 ---- .../controller/EnqueueStoresController.java | 100 ----- .../controller/StoreTweetsController.java | 130 ------ .../tweetstore/domain/StoredTweetStatus.java | 149 ------- .../functions/KeyToStoredTweetStatus.java | 70 --- .../ServiceToStoredTweetStatuses.java | 72 --- .../reference/TweetStoreConstants.java | 34 -- .../reference/TwitterConstants.java | 31 -- .../src/main/platform/.gitignore | 1 - .../src/main/webapp/WEB-INF/web.xml | 51 --- .../src/main/webapp/images/openshift-logo.png | Bin 4558 -> 0 bytes .../src/main/webapp/index.jsp | 30 -- .../src/main/webapp/tweets.jsp | 108 ----- .../as/embedded/EmbeddedServerFactory2.java | 96 ---- .../config/util/CredentialsCollectorTest.java | 82 ---- .../controller/AddTweetsControllerTest.java | 78 ---- .../controller/ClearTweetsControllerTest.java | 72 --- .../EnqueueStoresControllerTest.java | 85 ---- .../controller/StoreTweetsControllerTest.java | 120 ----- .../functions/KeyToStoredTweetStatusTest.java | 69 --- .../ServiceToStoredTweetStatusesTest.java | 75 ---- .../tweetstore/integration/RhcloudServer.java | 109 ----- .../integration/TweetStoreLiveTest.java | 238 ---------- .../integration/util/ObjectFields.java | 43 -- .../tweetstore/integration/util/Zips.java | 36 -- .../jbossas7/configuration/standalone.xml | 208 --------- .../src/test/resources/log4j.xml | 95 ---- .../runatcloud-tweetstore/README.txt | 52 --- .../tweetstore/runatcloud-tweetstore/pom.xml | 164 ------- .../jclouds/demo/paas/PlatformServices.java | 64 --- .../demo/paas/RunnableHttpRequest.java | 126 ------ .../demo/paas/config/HttpClientModule.java | 65 --- .../config/PlatformServicesInitializer.java | 87 ---- .../demo/paas/reference/PaasConstants.java | 28 -- .../service/scheduler/HttpRequestJob.java | 69 --- .../paas/service/scheduler/Scheduler.java | 41 -- ...nlessXmlSchedulingDataProcessorPlugin.java | 401 ----------------- .../paas/service/taskqueue/TaskQueue.java | 107 ----- .../tweetstore/config/GuiceServletConfig.java | 155 ------- .../config/util/CredentialsCollector.java | 153 ------- .../config/util/PropertiesLoader.java | 59 --- .../controller/AddTweetsController.java | 96 ---- .../controller/ClearTweetsController.java | 96 ---- .../controller/EnqueueStoresController.java | 101 ----- .../controller/StoreTweetsController.java | 130 ------ .../tweetstore/domain/StoredTweetStatus.java | 149 ------- .../functions/KeyToStoredTweetStatus.java | 70 --- .../ServiceToStoredTweetStatuses.java | 72 --- .../reference/TweetStoreConstants.java | 34 -- .../reference/TwitterConstants.java | 31 -- .../src/main/platform/cloudbees-web.xml | 40 -- .../src/main/resources/jobs.xml | 29 -- .../src/main/resources/quartz.properties | 28 -- .../src/main/webapp/WEB-INF/web.xml | 60 --- .../src/main/webapp/index.jsp | 31 -- .../src/main/webapp/tweets.jsp | 109 ----- .../config/util/CredentialsCollectorTest.java | 82 ---- .../controller/AddTweetsControllerTest.java | 78 ---- .../controller/ClearTweetsControllerTest.java | 72 --- .../EnqueueStoresControllerTest.java | 85 ---- .../controller/StoreTweetsControllerTest.java | 120 ----- .../functions/KeyToStoredTweetStatusTest.java | 69 --- .../ServiceToStoredTweetStatusesTest.java | 75 ---- .../integration/RunAtCloudServer.java | 68 --- .../integration/StaxSdkAppServer2.java | 192 -------- .../integration/TweetStoreLiveTest.java | 239 ---------- .../integration/util/ObjectFields.java | 56 --- .../src/test/resources/log4j.xml | 95 ---- 224 files changed, 20155 deletions(-) delete mode 100644 demos/tweetstore/cf-tweetstore-spring/README.txt delete mode 100644 demos/tweetstore/cf-tweetstore-spring/pom.xml delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/PlatformServices.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/scheduler/HttpRequestJob.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/scheduler/Scheduler.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/scheduler/quartz/plugins/TransactionlessXmlSchedulingDataProcessorPlugin.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/DelegatingAutowireCapableBeanFactory.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/LoggingConfig.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/SpringServletConfig.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/platform/.gitignore delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/resources/jobs.xml delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/resources/quartz.properties delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/webapp/WEB-INF/web.xml delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/webapp/images/cloudfoundry-logo.png delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/webapp/index.jsp delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/main/webapp/tweets.jsp delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/CloudFoundryServer.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/util/Zips.java delete mode 100644 demos/tweetstore/cf-tweetstore-spring/src/test/resources/log4j.xml delete mode 100644 demos/tweetstore/gae-tweetstore-spring/README.txt delete mode 100644 demos/tweetstore/gae-tweetstore-spring/pom.xml delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/LoggingConfig.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/SpringServletConfig.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/platform/appengine-web.xml delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/platform/cron.xml delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/platform/logging.properties delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/webapp/WEB-INF/dispatcher-servlet.xml delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/webapp/WEB-INF/queue.xml delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/webapp/WEB-INF/web.xml delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/webapp/index.jsp delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/main/webapp/tweets.jsp delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java delete mode 100644 demos/tweetstore/gae-tweetstore-spring/src/test/resources/log4j.xml delete mode 100644 demos/tweetstore/gae-tweetstore/README.txt delete mode 100644 demos/tweetstore/gae-tweetstore/pom.xml delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/platform/appengine-web.xml delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/platform/cron.xml delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/platform/logging.properties delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/webapp/WEB-INF/queue.xml delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/webapp/WEB-INF/web.xml delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/webapp/index.jsp delete mode 100644 demos/tweetstore/gae-tweetstore/src/main/webapp/tweets.jsp delete mode 100644 demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java delete mode 100644 demos/tweetstore/gae-tweetstore/src/test/resources/log4j.xml delete mode 100644 demos/tweetstore/heroku-tweetstore/README.txt delete mode 100644 demos/tweetstore/heroku-tweetstore/pom.xml delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/PlatformServices.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/platform/.gitignore delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/webapp/WEB-INF/web.xml delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/webapp/images/heroku-logo.png delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/webapp/index.jsp delete mode 100644 demos/tweetstore/heroku-tweetstore/src/main/webapp/tweets.jsp delete mode 100644 demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/JettyServer.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/Runner2.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/ObjectFields.java delete mode 100644 demos/tweetstore/heroku-tweetstore/src/test/resources/log4j.xml delete mode 100644 demos/tweetstore/pom.xml delete mode 100644 demos/tweetstore/rhcloud-tweetstore/README.txt delete mode 100644 demos/tweetstore/rhcloud-tweetstore/pom.xml delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/PlatformServices.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/platform/.gitignore delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/webapp/WEB-INF/web.xml delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/webapp/images/openshift-logo.png delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/webapp/index.jsp delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/main/webapp/tweets.jsp delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jboss/as/embedded/EmbeddedServerFactory2.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/RhcloudServer.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/ObjectFields.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/Zips.java delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/test/resources/jbossas7/configuration/standalone.xml delete mode 100644 demos/tweetstore/rhcloud-tweetstore/src/test/resources/log4j.xml delete mode 100644 demos/tweetstore/runatcloud-tweetstore/README.txt delete mode 100644 demos/tweetstore/runatcloud-tweetstore/pom.xml delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/PlatformServices.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/scheduler/HttpRequestJob.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/scheduler/Scheduler.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/scheduler/quartz/plugins/TransactionlessXmlSchedulingDataProcessorPlugin.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/platform/cloudbees-web.xml delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/resources/jobs.xml delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/resources/quartz.properties delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/webapp/WEB-INF/web.xml delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/webapp/index.jsp delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/main/webapp/tweets.jsp delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/RunAtCloudServer.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/StaxSdkAppServer2.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/ObjectFields.java delete mode 100644 demos/tweetstore/runatcloud-tweetstore/src/test/resources/log4j.xml diff --git a/demos/pom.xml b/demos/pom.xml index 47ce166ce4..9ccc9f2fc3 100644 --- a/demos/pom.xml +++ b/demos/pom.xml @@ -37,7 +37,6 @@ speedtest-azurequeue speedtest-sqs simpledb - tweetstore diff --git a/demos/tweetstore/cf-tweetstore-spring/README.txt b/demos/tweetstore/cf-tweetstore-spring/README.txt deleted file mode 100644 index c2af578674..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/README.txt +++ /dev/null @@ -1,41 +0,0 @@ -==== - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. -==== - -A guide to generating Twitter consumer keys and access tokens is at http://tinyurl.com/2fhebgb - -Please modify your maven settings.xml like below before attempting to run 'mvn -Plive install' - - - keys - - true - - - YOUR_ACCESS_KEY_ID - YOUR_SECRET_KEY - YOUR_USER - YOUR_HEX_KEY - YOUR_ACCOUNT - YOUR_BASE64_ENCODED_KEY - YOUR_TWITTER_CONSUMER_KEY - YOUR_TWITTER_CONSUMER_SECRET - YOUR_TWITTER_ACCESSTOKEN - YOUR_TWITTER_ACCESSTOKEN_SECRET - - \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/pom.xml b/demos/tweetstore/cf-tweetstore-spring/pom.xml deleted file mode 100644 index ad91a56c1d..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/pom.xml +++ /dev/null @@ -1,191 +0,0 @@ - - - - 4.0.0 - - org.jclouds - jclouds-demos-tweetstore-project - 1.6.0-SNAPSHOT - - jclouds-demo-cf-tweetstore-spring - war - jclouds TweetStore for Cloud Foundry - jclouds TweetStore for Cloud Foundry using Spring for Dependency Injection - - - 0.8.1 - jclouds-tweetstore - http://api.cloudfoundry.com - test-${cloudfoundry.applicationid}.cloudfoundry.com - 80 - jclouds-cf-tweetstore-spring - - - - - - org.springframework - spring-context - 3.0.5.RELEASE - - - - commons-logging - commons-logging - - - - - org.springframework - spring-webmvc - 3.0.5.RELEASE - - - cglib - cglib-nodep - 2.2 - runtime - - - - org.quartz-scheduler - quartz - 2.1.3 - - - org.slf4j - slf4j-api - - - - - - - org.cloudfoundry - cloudfoundry-runtime - ${cloudfoundry.version} - - - org.cloudfoundry - cloudfoundry-client-lib - 0.7.1 - test - - - org.codehaus.plexus - plexus-archiver - 2.1.1 - test - - - - - - org.springframework.maven.milestone - http://maven.springframework.org/milestone - - false - - - - - - - live - - - - maven-surefire-plugin - - - integration - integration-test - - test - - - - ${test.twitter.gae-tweetstore-spring.consumer.identity} - ${test.twitter.gae-tweetstore-spring.consumer.credential} - ${test.twitter.gae-tweetstore-spring.access.identity} - ${test.twitter.gae-tweetstore-spring.access.credential} - ${test.azureblob.identity} - ${test.azureblob.credential} - ${test.cloudfiles-us.identity} - ${test.cloudfiles-us.credential} - ${test.aws-s3.identity} - ${test.aws-s3.credential} - ${test.cloudonestorage.identity} - ${test.cloudonestorage.credential} - ${test.ninefold-storage.identity} - ${test.ninefold-storage.credential} - ${test.cloudfoundry.address} - ${test.cloudfoundry.port} - ${test.cloudfoundry.target} - ${cloudfoundry.username} - ${cloudfoundry.password} - ${jclouds.tweetstore.blobstores} - test.${jclouds.tweetstore.container} - ${project.build.directory}/${project.build.finalName} - - - - - - - - - - - deploy - - - cf-tweetstore-spring - - - - org.springframework.maven.milestone - http://maven.springframework.org/milestone - - false - - - - - - - org.cloudfoundry - cf-maven-plugin - 1.0.0.M1 - - http://api.cloudfoundry.com - ${cloudfoundry.username} - ${cloudfoundry.password} - ${cloudfoundry.applicationid} - 256 - - - - - - - diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/PlatformServices.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/PlatformServices.java deleted file mode 100644 index 0997005157..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/PlatformServices.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.demo.paas.config.PlatformServicesInitializer.PLATFORM_SERVICES_ATTRIBUTE_NAME; - -import java.util.Map; - -import javax.servlet.ServletContext; - -import org.jclouds.demo.paas.service.scheduler.Scheduler; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.javax.annotation.Nullable; - -import com.google.common.collect.ImmutableMap; - -/** - * @author Andrew Phillips - */ -public class PlatformServices { - protected final String baseUrl; - protected final Scheduler scheduler; - private ImmutableMap taskQueues; - - public PlatformServices(String baseUrl, Scheduler scheduler, Map taskQueues) { - this.baseUrl = baseUrl; - this.scheduler = scheduler; - this.taskQueues = ImmutableMap.copyOf(taskQueues); - } - - public String getBaseUrl() { - return baseUrl; - } - - public Scheduler getScheduler() { - return scheduler; - } - - public @Nullable TaskQueue getTaskQueue(String name) { - return taskQueues.get(name); - } - - public static PlatformServices get(ServletContext context) { - return (PlatformServices) checkNotNull(context.getAttribute( - PLATFORM_SERVICES_ATTRIBUTE_NAME), PLATFORM_SERVICES_ATTRIBUTE_NAME); - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java deleted file mode 100644 index ad72a1a58d..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas; - -import static java.lang.String.format; - -import org.jclouds.http.HttpCommand; -import org.jclouds.http.HttpCommandExecutorService; -import org.jclouds.http.HttpRequest; - -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; - -public class RunnableHttpRequest implements Runnable { - public static final String PLATFORM_REQUEST_ORIGINATOR_HEADER = "X-Platform-Originator"; - - public static Factory factory(HttpCommandExecutorService httpClient) { - return factory(httpClient, format("%s@%d", Factory.class.getName(), System.currentTimeMillis())); - } - - public static Factory factory(HttpCommandExecutorService httpClient, String originator) { - return new Factory(httpClient, originator); - } - - public static class Factory { - protected final HttpCommandExecutorService httpClient; - protected final String originator; - - private Factory(HttpCommandExecutorService httpClient, String originator) { - this.httpClient = httpClient; - this.originator = originator; - } - - public RunnableHttpRequest create(HttpRequest request) { - HttpRequest requestWithSubmitter = request.toBuilder() - .headers(copyOfWithEntry(request.getHeaders(), - PLATFORM_REQUEST_ORIGINATOR_HEADER, originator)).build(); - return new RunnableHttpRequest(httpClient, requestWithSubmitter); - } - - private static Multimap copyOfWithEntry( - Multimap multimap, K k1, V v1) { - return ImmutableMultimap.builder().putAll(multimap).put(k1, v1).build(); - } - } - - private final HttpCommandExecutorService httpClient; - private final HttpRequest request; - - private RunnableHttpRequest(HttpCommandExecutorService httpClient, HttpRequest request) { - this.httpClient = httpClient; - this.request = request; - } - - @Override - public void run() { - httpClient.submit(new ImmutableHttpCommand(request)); - } - - private class ImmutableHttpCommand implements HttpCommand { - private final HttpRequest request; - - public ImmutableHttpCommand(HttpRequest request) { - this.request = request; - } - - @Override - public void setException(Exception exception) { - } - - @Override - public void setCurrentRequest(HttpRequest request) { - } - - @Override - public boolean isReplayable() { - return false; - } - - @Override - public int incrementRedirectCount() { - return 0; - } - - @Override - public int incrementFailureCount() { - return 0; - } - - @Override - public int getRedirectCount() { - return 0; - } - - @Override - public int getFailureCount() { - return 0; - } - - @Override - public Exception getException() { - return null; - } - - @Override - public HttpRequest getCurrentRequest() { - return request; - } - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java deleted file mode 100644 index 5aa077b6cd..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.inject.name.Names.bindProperties; -import static org.jclouds.Constants.*; - -import java.util.Properties; - -import javax.servlet.ServletContext; -import javax.ws.rs.core.UriBuilder; - -import org.jclouds.demo.tweetstore.config.util.PropertiesLoader; - -import com.google.inject.AbstractModule; -import com.sun.jersey.api.uri.UriBuilderImpl; - -/** - * @author Andrew Phillips - */ -public class HttpClientModule extends AbstractModule { - private final ServletContext context; - - HttpClientModule(ServletContext context) { - this.context = context; - } - - @Override - protected void configure() { - // URL connection defaults - Properties toBind = defaultProperties(); - toBind.putAll(checkNotNull(new PropertiesLoader(context).get(), "properties")); - toBind.putAll(System.getProperties()); - bindProperties(binder(), toBind); - bind(UriBuilder.class).to(UriBuilderImpl.class); - } - - private static Properties defaultProperties() { - Properties props = new Properties(); - props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_CONTEXT, 20 + ""); - props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_HOST, 0 + ""); - props.setProperty(PROPERTY_SO_TIMEOUT, 60000 + ""); - props.setProperty(PROPERTY_CONNECTION_TIMEOUT, 60000 + ""); - props.setProperty(PROPERTY_USER_THREADS, 0 + ""); - props.setProperty(PROPERTY_IO_WORKER_THREADS, 20 + ""); - return props; - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java deleted file mode 100644 index 7e0aa429ce..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.config; - -import static java.util.concurrent.TimeUnit.SECONDS; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.cloudfoundry.runtime.env.ApplicationInstanceInfo; -import org.cloudfoundry.runtime.env.CloudEnvironment; -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.demo.paas.PlatformServices; -import org.jclouds.demo.paas.service.scheduler.Scheduler; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.http.HttpCommandExecutorService; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; -import com.google.inject.Guice; - -/** - * @author Andrew Phillips - */ -public class PlatformServicesInitializer implements ServletContextListener { - public static final String PLATFORM_SERVICES_ATTRIBUTE_NAME = PlatformServices.class.getName(); - - @Override - public void contextInitialized(ServletContextEvent contextEvent) { - ServletContext context = contextEvent.getServletContext(); - context.setAttribute(PLATFORM_SERVICES_ATTRIBUTE_NAME, createServices(context)); - } - - protected static PlatformServices createServices(ServletContext context) { - HttpCommandExecutorService httpClient = createHttpClient(context); - return new PlatformServices(getBaseUrl(context), new Scheduler(httpClient), - createTaskQueues(httpClient)); - } - - protected static HttpCommandExecutorService createHttpClient( - final ServletContext context) { - return Guice.createInjector(new ExecutorServiceModule(), - new JavaUrlHttpCommandExecutorServiceModule(), - new HttpClientModule(context)) - .getInstance(HttpCommandExecutorService.class); - } - - protected static String getBaseUrl(ServletContext context) { - ApplicationInstanceInfo instanceInfo = new CloudEnvironment().getInstanceInfo(); - // using localhost instead of instanceInfo.getHost(). See http://support.cloudfoundry.com/requests/102117 - return "http://127.0.0.1:" + instanceInfo.getPort() + context.getContextPath(); - } - - // TODO: make the number and names of queues configurable - protected static ImmutableMap createTaskQueues(HttpCommandExecutorService httpClient) { - Builder taskQueues = ImmutableMap.builder(); - taskQueues.put("twitter", TaskQueue.builder(httpClient) - .name("twitter").period(SECONDS.toMillis(30)) - .build()); - return taskQueues.build(); - } - - @Override - public void contextDestroyed(ServletContextEvent servletContextEvent) { - ServletContext context = servletContextEvent.getServletContext(); - context.removeAttribute(PLATFORM_SERVICES_ATTRIBUTE_NAME); - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java deleted file mode 100644 index 8af7021bd2..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.reference; - -/** - * Configuration properties and constants used in PaaS applications. - * - * @author Andrew Phillips - */ -public interface PaasConstants { - static final String PROPERTY_PLATFORM_BASE_URL = "jclouds.paas.baseurl"; -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/scheduler/HttpRequestJob.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/scheduler/HttpRequestJob.java deleted file mode 100644 index 902f5fe356..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/scheduler/HttpRequestJob.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.service.scheduler; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; - -import javax.servlet.ServletContext; - -import org.jclouds.demo.paas.PlatformServices; -import org.jclouds.demo.paas.RunnableHttpRequest; -import org.jclouds.http.HttpRequest; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; -import org.quartz.SchedulerException; - -/** - * @author Andrew Phillips - */ -public class HttpRequestJob implements Job { - protected static final String URL_ATTRIBUTE_NAME = "url"; - - // keep in sync with "quartz:scheduler-context-servlet-context-key" param in web.xml - protected static final String SERVLET_CONTEXT_KEY = "servlet-context"; - - @Override - public void execute(JobExecutionContext context) throws JobExecutionException { - PlatformServices platform = JobContexts.getPlatform(context); - RunnableHttpRequest request = platform.getScheduler().getHttpRequestFactory().create( - HttpRequest.builder() - .endpoint(JobContexts.getTargetUrl(platform.getBaseUrl(), context)) - .method("GET").build()); - request.run(); - } - - private static class JobContexts { - private static URI getTargetUrl(String baseUrl, JobExecutionContext context) { - return URI.create(baseUrl + (String) checkNotNull( - context.getMergedJobDataMap().get(URL_ATTRIBUTE_NAME), URL_ATTRIBUTE_NAME)); - } - - private static PlatformServices getPlatform(JobExecutionContext jobContext) throws JobExecutionException { - try { - return PlatformServices.get((ServletContext) checkNotNull( - jobContext.getScheduler().getContext().get(SERVLET_CONTEXT_KEY), SERVLET_CONTEXT_KEY)); - } catch (SchedulerException exception) { - throw new JobExecutionException("Unable to get platform services from the job execution context", exception); - } - } - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/scheduler/Scheduler.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/scheduler/Scheduler.java deleted file mode 100644 index dabdff877b..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/scheduler/Scheduler.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.service.scheduler; - -import org.jclouds.demo.paas.RunnableHttpRequest; -import org.jclouds.demo.paas.RunnableHttpRequest.Factory; -import org.jclouds.http.HttpCommandExecutorService; - -/** - * @author Andrew Phillips - */ -public class Scheduler { - protected static final String SCHEDULER_ORIGINATOR_NAME = "scheduler"; - - protected final Factory httpRequestFactory; - - public Scheduler(HttpCommandExecutorService httpClient) { - httpRequestFactory = - RunnableHttpRequest.factory(httpClient, SCHEDULER_ORIGINATOR_NAME); - } - - public Factory getHttpRequestFactory() { - return httpRequestFactory; - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/scheduler/quartz/plugins/TransactionlessXmlSchedulingDataProcessorPlugin.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/scheduler/quartz/plugins/TransactionlessXmlSchedulingDataProcessorPlugin.java deleted file mode 100644 index b47f81dfad..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/scheduler/quartz/plugins/TransactionlessXmlSchedulingDataProcessorPlugin.java +++ /dev/null @@ -1,401 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.service.scheduler.quartz.plugins; - -import static org.quartz.SimpleScheduleBuilder.simpleSchedule; -import static org.quartz.TriggerBuilder.newTrigger; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.net.URLDecoder; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; - -import org.jclouds.logging.Logger; -import org.quartz.JobBuilder; -import org.quartz.JobDetail; -import org.quartz.Scheduler; -import org.quartz.SchedulerException; -import org.quartz.SimpleTrigger; -import org.quartz.TriggerKey; -import org.quartz.jobs.FileScanJob; -import org.quartz.jobs.FileScanListener; -import org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin; -import org.quartz.simpl.CascadingClassLoadHelper; -import org.quartz.spi.ClassLoadHelper; -import org.quartz.spi.SchedulerPlugin; -import org.quartz.xml.XMLSchedulingDataProcessor; - -/** - * A copy of {@link XMLSchedulingDataProcessorPlugin} that does not reference - * {@code javax.transaction.UserTransaction} as so does not require a dependency - * on JTA. - * - * @author Andrew Phillips - * @see XMLSchedulingDataProcessorPlugin - */ -public class TransactionlessXmlSchedulingDataProcessorPlugin implements - FileScanListener, SchedulerPlugin { - - /* - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * - * Data members. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - */ - private static final int MAX_JOB_TRIGGER_NAME_LEN = 80; - private static final String JOB_INITIALIZATION_PLUGIN_NAME = "JobSchedulingDataLoaderPlugin"; - private static final String FILE_NAME_DELIMITERS = ","; - - private String name; - private Scheduler scheduler; - private final Logger log = Logger.CONSOLE; - - private boolean failOnFileNotFound = true; - - private String fileNames = XMLSchedulingDataProcessor.QUARTZ_XML_DEFAULT_FILE_NAME; - - // Populated by initialization - private Map jobFiles = new LinkedHashMap(); - - private long scanInterval = 0; - - boolean started = false; - - protected ClassLoadHelper classLoadHelper = null; - - private Set jobTriggerNameSet = new HashSet(); - - /* - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * - * Interface. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - */ - - /** - * Comma separated list of file names (with paths) to the XML files that should be read. - */ - public String getFileNames() { - return fileNames; - } - - /** - * The file name (and path) to the XML file that should be read. - */ - public void setFileNames(String fileNames) { - this.fileNames = fileNames; - } - - /** - * The interval (in seconds) at which to scan for changes to the file. - * If the file has been changed, it is re-loaded and parsed. The default - * value for the interval is 0, which disables scanning. - * - * @return Returns the scanInterval. - */ - public long getScanInterval() { - return scanInterval / 1000; - } - - /** - * The interval (in seconds) at which to scan for changes to the file. - * If the file has been changed, it is re-loaded and parsed. The default - * value for the interval is 0, which disables scanning. - * - * @param scanInterval The scanInterval to set. - */ - public void setScanInterval(long scanInterval) { - this.scanInterval = scanInterval * 1000; - } - - /** - * Whether or not initialization of the plugin should fail (throw an - * exception) if the file cannot be found. Default is true. - */ - public boolean isFailOnFileNotFound() { - return failOnFileNotFound; - } - - /** - * Whether or not initialization of the plugin should fail (throw an - * exception) if the file cannot be found. Default is true. - */ - public void setFailOnFileNotFound(boolean failOnFileNotFound) { - this.failOnFileNotFound = failOnFileNotFound; - } - - /* - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * - * SchedulerPlugin Interface. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - */ - - /** - *

- * Called during creation of the Scheduler in order to give - * the SchedulerPlugin a chance to initialize. - *

- * - * @throws org.quartz.SchedulerConfigException - * if there is an error initializing. - */ - @Override - public void initialize(String name, Scheduler scheduler) - throws SchedulerException { - this.name = name; - this.scheduler = scheduler; - - classLoadHelper = new CascadingClassLoadHelper(); - classLoadHelper.initialize(); - - log.info("Registering Quartz Job Initialization Plug-in."); - - // Create JobFile objects - StringTokenizer stok = new StringTokenizer(fileNames, FILE_NAME_DELIMITERS); - while (stok.hasMoreTokens()) { - final String fileName = stok.nextToken(); - final JobFile jobFile = new JobFile(fileName); - jobFiles.put(fileName, jobFile); - } - } - - @Override - public void start() { - try { - if (jobFiles.isEmpty() == false) { - - if (scanInterval > 0) { - scheduler.getContext().put(JOB_INITIALIZATION_PLUGIN_NAME + '_' + name, this); - } - - Iterator iterator = jobFiles.values().iterator(); - while (iterator.hasNext()) { - JobFile jobFile = iterator.next(); - - if (scanInterval > 0) { - String jobTriggerName = buildJobTriggerName(jobFile.getFileBasename()); - TriggerKey tKey = new TriggerKey(jobTriggerName, JOB_INITIALIZATION_PLUGIN_NAME); - - // remove pre-existing job/trigger, if any - scheduler.unscheduleJob(tKey); - - // TODO: convert to use builder - SimpleTrigger trig = newTrigger() - .withIdentity(jobTriggerName, JOB_INITIALIZATION_PLUGIN_NAME) - .startNow() - .endAt(null) - .withSchedule(simpleSchedule() - .repeatForever() - .withIntervalInMilliseconds(scanInterval)) - .build(); - - JobDetail job = JobBuilder.newJob(FileScanJob.class) - .withIdentity(jobTriggerName, JOB_INITIALIZATION_PLUGIN_NAME) - .build(); - job.getJobDataMap().put(FileScanJob.FILE_NAME, jobFile.getFileName()); - job.getJobDataMap().put(FileScanJob.FILE_SCAN_LISTENER_NAME, JOB_INITIALIZATION_PLUGIN_NAME + '_' + name); - - scheduler.scheduleJob(job, trig); - log.debug("Scheduled file scan job for data file: {}, at interval: {}", jobFile.getFileName(), scanInterval); - } - - processFile(jobFile); - } - } - } catch(SchedulerException se) { - log.error("Error starting background-task for watching jobs file.", se); - } finally { - started = true; - } - } - - /** - * Helper method for generating unique job/trigger name for the - * file scanning jobs (one per FileJob). The unique names are saved - * in jobTriggerNameSet. - */ - private String buildJobTriggerName( - String fileBasename) { - // Name w/o collisions will be prefix + _ + filename (with '.' of filename replaced with '_') - // For example: JobInitializationPlugin_jobInitializer_myjobs_xml - String jobTriggerName = JOB_INITIALIZATION_PLUGIN_NAME + '_' + name + '_' + fileBasename.replace('.', '_'); - - // If name is too long (DB column is 80 chars), then truncate to max length - if (jobTriggerName.length() > MAX_JOB_TRIGGER_NAME_LEN) { - jobTriggerName = jobTriggerName.substring(0, MAX_JOB_TRIGGER_NAME_LEN); - } - - // Make sure this name is unique in case the same file name under different - // directories is being checked, or had a naming collision due to length truncation. - // If there is a conflict, keep incrementing a _# suffix on the name (being sure - // not to get too long), until we find a unique name. - int currentIndex = 1; - while (jobTriggerNameSet.add(jobTriggerName) == false) { - // If not our first time through, then strip off old numeric suffix - if (currentIndex > 1) { - jobTriggerName = jobTriggerName.substring(0, jobTriggerName.lastIndexOf('_')); - } - - String numericSuffix = "_" + currentIndex++; - - // If the numeric suffix would make the name too long, then make room for it. - if (jobTriggerName.length() > (MAX_JOB_TRIGGER_NAME_LEN - numericSuffix.length())) { - jobTriggerName = jobTriggerName.substring(0, (MAX_JOB_TRIGGER_NAME_LEN - numericSuffix.length())); - } - - jobTriggerName += numericSuffix; - } - - return jobTriggerName; - } - - @Override - public void shutdown() { - // nothing to do - } - - private void processFile(JobFile jobFile) { - if (jobFile == null || !jobFile.getFileFound()) { - return; - } - - try { - XMLSchedulingDataProcessor processor = - new XMLSchedulingDataProcessor(this.classLoadHelper); - - processor.addJobGroupToNeverDelete(JOB_INITIALIZATION_PLUGIN_NAME); - processor.addTriggerGroupToNeverDelete(JOB_INITIALIZATION_PLUGIN_NAME); - - processor.processFileAndScheduleJobs( - jobFile.getFileName(), - jobFile.getFileName(), // systemId - scheduler); - } catch (Exception e) { - log.error("Error scheduling jobs: " + e.getMessage(), e); - } - } - - public void processFile(String filePath) { - processFile((JobFile)jobFiles.get(filePath)); - } - - /** - * @see org.quartz.jobs.FileScanListener#fileUpdated(java.lang.String) - */ - public void fileUpdated(String fileName) { - if (started) { - processFile(fileName); - } - } - - class JobFile { - private String fileName; - - // These are set by initialize() - private String filePath; - private String fileBasename; - private boolean fileFound; - - protected JobFile(String fileName) throws SchedulerException { - this.fileName = fileName; - initialize(); - } - - protected String getFileName() { - return fileName; - } - - protected boolean getFileFound() { - return fileFound; - } - - protected String getFilePath() { - return filePath; - } - - protected String getFileBasename() { - return fileBasename; - } - - private void initialize() throws SchedulerException { - InputStream f = null; - try { - String furl = null; - - File file = new File(getFileName()); // files in filesystem - if (!file.exists()) { - URL url = classLoadHelper.getResource(getFileName()); - if(url != null) { - try { - furl = URLDecoder.decode(url.getPath(), "UTF-8"); - } catch (UnsupportedEncodingException e) { - furl = url.getPath(); - } - file = new File(furl); - try { - f = url.openStream(); - } catch (IOException ignore) { - // Swallow the exception - } - } - } else { - try { - f = new java.io.FileInputStream(file); - }catch (FileNotFoundException e) { - // ignore - } - } - - if (f == null) { - if (isFailOnFileNotFound()) { - throw new SchedulerException( - "File named '" + getFileName() + "' does not exist."); - } else { - log.warn("File named '" + getFileName() + "' does not exist."); - } - } else { - fileFound = true; - } - filePath = (furl != null) ? furl : file.getAbsolutePath(); - fileBasename = file.getName(); - } finally { - try { - if (f != null) { - f.close(); - } - } catch (IOException ioe) { - log.warn("Error closing jobs file " + getFileName(), ioe); - } - } - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java deleted file mode 100644 index e317a305cf..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.service.taskqueue; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.lang.String.format; - -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.TimeUnit; - -import org.jclouds.demo.paas.RunnableHttpRequest; -import org.jclouds.demo.paas.RunnableHttpRequest.Factory; -import org.jclouds.http.HttpCommandExecutorService; - -import com.google.inject.Provider; - -public class TaskQueue { - protected final Factory httpRequestFactory; - private final Timer timer; - private final ConcurrentLinkedQueue tasks = new ConcurrentLinkedQueue(); - - private TaskQueue(String name, long pollingIntervalMillis, Factory httpRequestFactory) { - this.httpRequestFactory = httpRequestFactory; - timer = new Timer(name); - timer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - Runnable task = tasks.poll(); - if (task != null) { - task.run(); - } - } - }, 0, pollingIntervalMillis); - } - - public void add(final Runnable task) { - tasks.add(task); - } - - public Factory getHttpRequestFactory() { - return httpRequestFactory; - } - - public void destroy() { - timer.cancel(); - tasks.clear(); - } - - public static Builder builder(HttpCommandExecutorService httpClient) { - return new Builder(httpClient); - } - - public static class Builder implements Provider { - protected final HttpCommandExecutorService httpClient; - protected String name = "default"; - protected long pollingIntervalMillis = TimeUnit.SECONDS.toMillis(1); - - private Builder(HttpCommandExecutorService httpClient) { - this.httpClient = checkNotNull(httpClient, "httpClient"); - } - - public Builder name(String name) { - this.name = checkNotNull(name, "name"); - return this; - } - - public Builder period(TimeUnit period) { - this.pollingIntervalMillis = checkNotNull(period, "period").toMillis(1); - return this; - } - - public Builder period(long pollingIntervalMillis) { - checkArgument(pollingIntervalMillis > 0, "pollingIntervalMillis"); - this.pollingIntervalMillis = pollingIntervalMillis; - return this; - } - - public TaskQueue build() { - return new TaskQueue(name, pollingIntervalMillis, - RunnableHttpRequest.factory(httpClient, format("taskqueue-%s", name))); - } - - @Override - public TaskQueue get() { - return build(); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/DelegatingAutowireCapableBeanFactory.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/DelegatingAutowireCapableBeanFactory.java deleted file mode 100644 index 7fda1bb2f0..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/DelegatingAutowireCapableBeanFactory.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.jclouds.demo.tweetstore.config; - -import java.util.Set; - -import org.springframework.beans.BeansException; -import org.springframework.beans.TypeConverter; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.beans.factory.config.AutowireCapableBeanFactory; -import org.springframework.beans.factory.config.DependencyDescriptor; - -class DelegatingAutowireCapableBeanFactory implements AutowireCapableBeanFactory { - private final AutowireCapableBeanFactory delegate; - - DelegatingAutowireCapableBeanFactory(AutowireCapableBeanFactory delegate) { - this.delegate = delegate; - } - - public T createBean(Class beanClass) throws BeansException { - return delegate.createBean(beanClass); - } - - public void autowireBean(Object existingBean) throws BeansException { - delegate.autowireBean(existingBean); - } - - public Object configureBean(Object existingBean, String beanName) - throws BeansException { - return delegate.configureBean(existingBean, beanName); - } - - public Object getBean(String name) throws BeansException { - return delegate.getBean(name); - } - - public Object resolveDependency(DependencyDescriptor descriptor, - String beanName) throws BeansException { - return delegate.resolveDependency(descriptor, beanName); - } - - public T getBean(String name, Class requiredType) - throws BeansException { - return delegate.getBean(name, requiredType); - } - - @SuppressWarnings("rawtypes") - public Object createBean(Class beanClass, int autowireMode, - boolean dependencyCheck) throws BeansException { - return delegate.createBean(beanClass, autowireMode, dependencyCheck); - } - - public T getBean(Class requiredType) throws BeansException { - return delegate.getBean(requiredType); - } - - @SuppressWarnings("rawtypes") - public Object autowire(Class beanClass, int autowireMode, - boolean dependencyCheck) throws BeansException { - return delegate.autowire(beanClass, autowireMode, dependencyCheck); - } - - public Object getBean(String name, Object... args) throws BeansException { - return delegate.getBean(name, args); - } - - public void autowireBeanProperties(Object existingBean, int autowireMode, - boolean dependencyCheck) throws BeansException { - delegate.autowireBeanProperties(existingBean, autowireMode, - dependencyCheck); - } - - public boolean containsBean(String name) { - return delegate.containsBean(name); - } - - public boolean isSingleton(String name) - throws NoSuchBeanDefinitionException { - return delegate.isSingleton(name); - } - - public void applyBeanPropertyValues(Object existingBean, String beanName) - throws BeansException { - delegate.applyBeanPropertyValues(existingBean, beanName); - } - - public boolean isPrototype(String name) - throws NoSuchBeanDefinitionException { - return delegate.isPrototype(name); - } - - @SuppressWarnings("rawtypes") - public boolean isTypeMatch(String name, Class targetType) - throws NoSuchBeanDefinitionException { - return delegate.isTypeMatch(name, targetType); - } - - public Object initializeBean(Object existingBean, String beanName) - throws BeansException { - return delegate.initializeBean(existingBean, beanName); - } - - public Class getType(String name) throws NoSuchBeanDefinitionException { - return delegate.getType(name); - } - - public Object applyBeanPostProcessorsBeforeInitialization( - Object existingBean, String beanName) throws BeansException { - return delegate.applyBeanPostProcessorsBeforeInitialization( - existingBean, beanName); - } - - public String[] getAliases(String name) { - return delegate.getAliases(name); - } - - public Object applyBeanPostProcessorsAfterInitialization( - Object existingBean, String beanName) throws BeansException { - return delegate.applyBeanPostProcessorsAfterInitialization( - existingBean, beanName); - } - - public Object resolveDependency(DependencyDescriptor descriptor, - String beanName, Set autowiredBeanNames, - TypeConverter typeConverter) throws BeansException { - return delegate.resolveDependency(descriptor, beanName, - autowiredBeanNames, typeConverter); - } - - -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/LoggingConfig.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/LoggingConfig.java deleted file mode 100644 index e322b0551b..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/LoggingConfig.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config; - -import static com.google.common.base.Preconditions.checkArgument; -import static java.lang.String.format; -import static org.jclouds.logging.LoggingModules.firstOrJDKLoggingModule; - -import java.util.Set; - -import javax.annotation.PostConstruct; - -import org.jclouds.logging.Logger; -import org.jclouds.logging.Logger.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.TypeConverter; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.beans.factory.config.AutowireCapableBeanFactory; -import org.springframework.beans.factory.config.DependencyDescriptor; -import org.springframework.context.annotation.AnnotationConfigUtils; -import org.springframework.context.annotation.CommonAnnotationBeanPostProcessor; - -/** - * Spring config that sets up {@link CommonAnnotationBeanPostProcessor} support - * for injecting loggers. - * - * @author Andrew Phillips - */ -abstract class LoggingConfig implements BeanFactoryAware { - protected static final LoggerFactory LOGGER_FACTORY = firstOrJDKLoggingModule().createLoggerFactory(); - - private static final Logger LOGGER = LOGGER_FACTORY.getLogger(LoggingConfig.class.getName()); - - private AutowireCapableBeanFactory beanFactory; - - @PostConstruct - public void initLoggerSupport() { - CommonAnnotationBeanPostProcessor resourceProcessor = - (CommonAnnotationBeanPostProcessor) beanFactory.getBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME); - resourceProcessor.setResourceFactory(new LoggerResourceBeanFactory(beanFactory)); - } - - private static class LoggerResourceBeanFactory extends DelegatingAutowireCapableBeanFactory { - - LoggerResourceBeanFactory(AutowireCapableBeanFactory delegate) { - super(delegate); - } - - @Override - public Object resolveDependency(DependencyDescriptor descriptor, - String beanName, Set autowiredBeanNames, - TypeConverter typeConverter) throws BeansException { - if (descriptor.getDependencyType().equals(Logger.class)) { - Class requestingType = getType(beanName); - LOGGER.trace("About to resolve logger for bean '%s' of type '%s'", - beanName, requestingType); - Logger logger = resolveLogger(requestingType, autowiredBeanNames); - LOGGER.trace("Successfully resolved logger."); - return logger; - } - return super.resolveDependency(descriptor, beanName, autowiredBeanNames, typeConverter); - } - - private Logger resolveLogger(Class type, Set autowiredBeanNames) { - String loggerBeanName = format("%s#logger", type); - if (autowiredBeanNames.contains(loggerBeanName)) { - LOGGER.trace("Returning existing bean '%s'", loggerBeanName); - return (Logger) getBean(loggerBeanName); - } - - LOGGER.trace("About to create logger for type '%s'", type); - Logger logger = LOGGER_FACTORY.getLogger(type.getName()); - LOGGER.trace("Successfully created logger."); - return logger; - } - } - - @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - checkArgument(beanFactory instanceof AutowireCapableBeanFactory, "expected an instance of '%s' but was '%s'", - AutowireCapableBeanFactory.class, beanFactory.getClass()); - this.beanFactory = (AutowireCapableBeanFactory) beanFactory; - } -} \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/SpringServletConfig.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/SpringServletConfig.java deleted file mode 100644 index 3fd8549621..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/SpringServletConfig.java +++ /dev/null @@ -1,242 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Predicates.in; -import static com.google.common.collect.ImmutableSet.copyOf; -import static com.google.common.collect.Sets.filter; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.servlet.Servlet; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.paas.PlatformServices; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector; -import org.jclouds.demo.tweetstore.controller.AddTweetsController; -import org.jclouds.demo.tweetstore.controller.ClearTweetsController; -import org.jclouds.demo.tweetstore.controller.EnqueueStoresController; -import org.jclouds.demo.tweetstore.controller.StoreTweetsController; -import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; -import org.jclouds.logging.Logger; -import org.springframework.beans.factory.BeanCreationException; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.context.ServletConfigAware; -import org.springframework.web.servlet.HandlerAdapter; -import org.springframework.web.servlet.HandlerMapping; -import org.springframework.web.servlet.handler.SimpleServletHandlerAdapter; -import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; - -import twitter4j.Twitter; -import twitter4j.TwitterFactory; -import twitter4j.conf.ConfigurationBuilder; - -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.common.io.Closeables; -import com.google.inject.Module; - -/** - * Creates servlets (using resources from the {@link SpringAppConfig}) and mappings. - * - * @author Andrew Phillips - * @see SpringAppConfig - */ -@Configuration -public class SpringServletConfig extends LoggingConfig implements ServletConfigAware { - public static final String PROPERTY_BLOBSTORE_CONTEXTS = "blobstore.contexts"; - - private static final Logger LOGGER = LOGGER_FACTORY.getLogger(SpringServletConfig.class.getName()); - - private ServletConfig servletConfig; - - private Map providerTypeToBlobStoreMap; - private Twitter twitterClient; - private String container; - private TaskQueue queue; - private String baseUrl; - - @PostConstruct - public void initialize() throws IOException { - Properties props = loadJCloudsProperties(); - LOGGER.trace("About to initialize members."); - - Set modules = ImmutableSet.of(); - // shared across all blobstores and used to retrieve tweets - try { - twitter4j.conf.Configuration twitterConf = new ConfigurationBuilder() - .setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY)) - .setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET)) - .setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN)) - .setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET)) - .build(); - twitterClient = new TwitterFactory(twitterConf).getInstance(); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("properties for twitter not configured properly in " + props.toString(), e); - } - // common namespace for storing tweets - container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER), PROPERTY_TWEETSTORE_CONTAINER); - - // instantiate and store references to all blobstores by provider name - providerTypeToBlobStoreMap = Maps.newHashMap(); - for (String hint : getBlobstoreContexts(props)) { - providerTypeToBlobStoreMap.put(hint, ContextBuilder.newBuilder(hint) - .modules(modules).overrides(props).build(BlobStoreContext.class)); - } - - // get a queue for submitting store tweet requests and the application's base URL - PlatformServices platform = PlatformServices.get(servletConfig.getServletContext()); - queue = platform.getTaskQueue("twitter"); - baseUrl = platform.getBaseUrl(); - - LOGGER.trace("Members initialized. Twitter: '%s', container: '%s', provider types: '%s'", twitterClient, - container, providerTypeToBlobStoreMap.keySet()); - } - - private static Iterable getBlobstoreContexts(Properties props) { - Set contexts = new CredentialsCollector().apply(props).keySet(); - String explicitContexts = props.getProperty(PROPERTY_TWEETSTORE_BLOBSTORES); - if (explicitContexts != null) { - contexts = filter(contexts, in(copyOf(Splitter.on(',').split(explicitContexts)))); - } - checkState(!contexts.isEmpty(), "no credentials available for any requested context"); - return contexts; - } - - private Properties loadJCloudsProperties() { - LOGGER.trace("About to read properties from '%s'", "/WEB-INF/jclouds.properties"); - Properties props = new Properties(); - InputStream input = servletConfig.getServletContext().getResourceAsStream("/WEB-INF/jclouds.properties"); - try { - props.load(input); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - Closeables.closeQuietly(input); - } - LOGGER.trace("Properties successfully read."); - return props; - } - - @Bean - public StoreTweetsController storeTweetsController() { - StoreTweetsController controller = new StoreTweetsController(providerTypeToBlobStoreMap, container, twitterClient); - injectServletConfig(controller); - return controller; - } - - @Bean - public AddTweetsController addTweetsController() { - AddTweetsController controller = new AddTweetsController(providerTypeToBlobStoreMap, - serviceToStoredTweetStatuses()); - injectServletConfig(controller); - return controller; - } - - @Bean - public EnqueueStoresController enqueueStoresController() { - return new EnqueueStoresController(providerTypeToBlobStoreMap, queue, baseUrl); - } - - @Bean - public ClearTweetsController clearTweetsController() { - return new ClearTweetsController(providerTypeToBlobStoreMap, container); - } - - private void injectServletConfig(Servlet servlet) { - LOGGER.trace("About to inject servlet config '%s'", servletConfig); - try { - servlet.init(checkNotNull(servletConfig)); - } catch (ServletException exception) { - throw new BeanCreationException("Unable to instantiate " + servlet, exception); - } - LOGGER.trace("Successfully injected servlet config."); - } - - @Bean - ServiceToStoredTweetStatuses serviceToStoredTweetStatuses() { - return new ServiceToStoredTweetStatuses(providerTypeToBlobStoreMap, container); - } - - @Bean - public HandlerMapping handlerMapping() { - SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); - Map urlMap = Maps.newHashMapWithExpectedSize(2); - urlMap.put("/store/*", storeTweetsController()); - urlMap.put("/tweets/*", addTweetsController()); - urlMap.put("/stores/*", enqueueStoresController()); - urlMap.put("/clear/*", clearTweetsController()); - mapping.setUrlMap(urlMap); - /* - * "/store", "/tweets" and "/stores" are part of the servlet mapping and thus - * stripped by the mapping if using default settings. - */ - mapping.setAlwaysUseFullPath(true); - return mapping; - } - - @Bean - public HandlerAdapter servletHandlerAdapter() { - return new SimpleServletHandlerAdapter(); - } - - @PreDestroy - public void destroy() throws Exception { - LOGGER.trace("About to close contexts."); - for (BlobStoreContext context : providerTypeToBlobStoreMap.values()) { - context.close(); - } - LOGGER.trace("Contexts closed."); - LOGGER.trace("About to purge request queue."); - queue.destroy(); - LOGGER.trace("Request queue purged."); - } - - /* - * (non-Javadoc) - * - * @see - * org.springframework.web.context.ServletConfigAware#setServletConfig(javax.servlet.ServletConfig - * ) - */ - @Override - public void setServletConfig(ServletConfig servletConfig) { - this.servletConfig = servletConfig; - } -} \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java deleted file mode 100644 index ce3943376e..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java +++ /dev/null @@ -1,153 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Predicates.notNull; -import static com.google.common.collect.Collections2.filter; -import static com.google.common.collect.Collections2.transform; -import static com.google.common.collect.ImmutableSet.copyOf; -import static com.google.common.collect.Maps.filterValues; -import static org.jclouds.util.Maps2.fromKeys; - -import java.util.Collection; -import java.util.Map; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector.Credential; - -import com.google.common.annotations.GwtIncompatible; -import com.google.common.base.Function; -import com.google.common.base.Predicate; - -/** - * Reads provider credentials from a {@link Properties} bag. - * - * @author Andrew Phillips - * - */ -public class CredentialsCollector implements Function> { - private static final String IDENTITY_PROPERTY_SUFFIX = ".identity"; - private static final String CREDENTIAL_PROPERTY_SUFFIX = ".credential"; - - // using the identity for provider name extraction - private static final Pattern IDENTITY_PROPERTY_PATTERN = - Pattern.compile("([a-zA-Z0-9-]+)" + Pattern.quote(IDENTITY_PROPERTY_SUFFIX)); - - @Override - public Map apply(final Properties properties) { - Collection providerNames = transform( - filter(properties.stringPropertyNames(), MatchesPattern.matches(IDENTITY_PROPERTY_PATTERN)), - new Function() { - @Override - public String apply(String input) { - Matcher matcher = IDENTITY_PROPERTY_PATTERN.matcher(input); - // as a side-effect, sets the matching group! - checkState(matcher.matches(), "'%s' should match '%s'", input, IDENTITY_PROPERTY_PATTERN); - return matcher.group(1); - } - }); - /* - * Providers without a credential property result in null values, which are - * removed from the returned map. - */ - return filterValues(fromKeys(copyOf(providerNames), new Function() { - @Override - public Credential apply(String providerName) { - String identity = properties.getProperty(providerName + IDENTITY_PROPERTY_SUFFIX); - String credential = properties.getProperty(providerName + CREDENTIAL_PROPERTY_SUFFIX); - return (((identity != null) && (credential != null)) - ? new Credential(identity, credential) - : null); - } - }), notNull()); - } - - public static class Credential { - private final String identity; - private final String credential; - - public Credential(String identity, String credential) { - this.identity = checkNotNull(identity, "identity"); - this.credential = checkNotNull(credential, "credential"); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((credential == null) ? 0 : credential.hashCode()); - result = prime * result - + ((identity == null) ? 0 : identity.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; - Credential other = (Credential) obj; - if (credential == null) { - if (other.credential != null) - return false; - } else if (!credential.equals(other.credential)) - return false; - if (identity == null) { - if (other.identity != null) - return false; - } else if (!identity.equals(other.identity)) - return false; - return true; - } - - public String getIdentity() { - return identity; - } - - public String getCredential() { - return credential; - } - } - - @GwtIncompatible(value = "java.util.regex.Pattern") - private static class MatchesPattern implements Predicate { - private final Pattern pattern; - - private MatchesPattern(Pattern pattern) { - this.pattern = pattern; - } - - @Override - public boolean apply(String input) { - return pattern.matcher(input).matches(); - } - - private static MatchesPattern matches(Pattern pattern) { - return new MatchesPattern(pattern); - } - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java deleted file mode 100644 index dafa5c311b..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import javax.servlet.ServletContext; - -import com.google.common.io.Closeables; -import com.google.inject.Provider; - -/** - * @author Andrew Phillips - */ -public class PropertiesLoader implements Provider{ - private static final String PROPERTIES_FILE = "/WEB-INF/jclouds.properties"; - - private final Properties properties; - - public PropertiesLoader(ServletContext context) { - properties = loadJcloudsProperties(context); - } - - private static Properties loadJcloudsProperties(ServletContext context) { - InputStream input = context.getResourceAsStream(PROPERTIES_FILE); - Properties props = new Properties(); - try { - props.load(input); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - Closeables.closeQuietly(input); - } - return props; - } - - @Override - public Properties get() { - return properties; - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java deleted file mode 100644 index 5a8e6baf4b..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -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.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -/** - * Shows an example of how to use @{link BlobStoreContext} injected with Guice. - * - * @author Adrian Cole - */ -@Singleton -public class AddTweetsController extends HttpServlet implements - Function, List> { - - /** The serialVersionUID */ - private static final long serialVersionUID = 3888348023150822683L; - private final Map contexts; - private final ServiceToStoredTweetStatuses blobStoreContextToContainerResult; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - public AddTweetsController(Map contexts, - ServiceToStoredTweetStatuses blobStoreContextToContainerResult) { - this.contexts = contexts; - this.blobStoreContextToContainerResult = blobStoreContextToContainerResult; - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - try { - addMyTweetsToRequest(request); - RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/tweets.jsp"); - dispatcher.forward(request, response); - } catch (Exception e) { - logger.error(e, "Error listing containers"); - throw new ServletException(e); - } - } - - void addMyTweetsToRequest(HttpServletRequest request) throws InterruptedException, - ExecutionException, TimeoutException { - request.setAttribute("tweets", apply(contexts.keySet())); - } - - public List apply(Set in) { - List statuses = Lists.newArrayList(); - for (Iterable list : Iterables.transform(in, - blobStoreContextToContainerResult)) { - Iterables.addAll(statuses, list); - } - return statuses; - } -} \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java deleted file mode 100644 index e08cfbc19e..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Strings.nullToEmpty; - -import java.io.IOException; -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; - -import com.google.common.annotations.VisibleForTesting; - -/** - * Grab tweets related to me and store them into blobstores - * - * @author Adrian Cole - */ -@Singleton -public class ClearTweetsController extends HttpServlet { - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Map contexts; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - @VisibleForTesting - public ClearTweetsController(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) { - this.container = container; - this.contexts = contexts; - } - - @VisibleForTesting - public void clearContainer(String contextName) { - BlobStoreContext context = checkNotNull(contexts.get(contextName), - "no context for %s in %s", contextName, contexts.keySet()); - try { - context.getBlobStore().clearContainer(container); - } catch (Exception e) { - logger.error(e, "Error clearing tweets in %s/%s", container, context); - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (nullToEmpty(request.getHeader("X-Originator")).equals("admin")) { - try { - String contextName = checkNotNull(request.getHeader("context"), "missing header context"); - logger.info("clearing tweets in %s/%s", container, contextName); - clearContainer(contextName); - logger.debug("done clearing tweets"); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error clearing tweets"); - throw new ServletException(e); - } - } else { - response.sendError(401); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java deleted file mode 100644 index 592eaaa8bd..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Strings.nullToEmpty; -import static org.jclouds.demo.paas.RunnableHttpRequest.PLATFORM_REQUEST_ORIGINATOR_HEADER; - -import java.io.IOException; -import java.net.URI; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.paas.reference.PaasConstants; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.http.HttpRequest; -import org.jclouds.logging.Logger; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableMultimap; - -/** - * Adds tasks to retrieve and store tweets in all registered contexts to an async - * task queue. - * - * @author Andrew Phillips - * @see StoreTweetsController - */ -@Singleton -public class EnqueueStoresController extends HttpServlet { - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Set contextNames; - private final TaskQueue taskQueue; - private final String baseUrl; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - public EnqueueStoresController(Map contexts, TaskQueue taskQueue, - @Named(PaasConstants.PROPERTY_PLATFORM_BASE_URL) String baseUrl) { - contextNames = contexts.keySet(); - this.taskQueue = taskQueue; - this.baseUrl = baseUrl; - } - - @VisibleForTesting - void enqueueStoreTweetTasks() { - for (String contextName : contextNames) { - logger.debug("enqueuing task to store tweets in blobstore '%s'", contextName); - taskQueue.add(taskQueue.getHttpRequestFactory().create(HttpRequest.builder() - .endpoint(URI.create(baseUrl + "/store/do")) - .headers(ImmutableMultimap.of("context", contextName)) - .method("GET").build())); - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (!nullToEmpty(request.getHeader(PLATFORM_REQUEST_ORIGINATOR_HEADER)).equals("scheduler")) { - response.sendError(401); - } - - try { - enqueueStoreTweetTasks(); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error storing tweets"); - throw new ServletException(e); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java deleted file mode 100644 index 725ba128f6..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Strings.nullToEmpty; -import static org.jclouds.demo.paas.RunnableHttpRequest.PLATFORM_REQUEST_ORIGINATOR_HEADER; - -import java.io.IOException; -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; -import org.jclouds.rest.AuthorizationException; - -import twitter4j.Status; -import twitter4j.Twitter; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; - -/** - * Grab tweets related to me and store them into blobstores - * - * @author Adrian Cole - */ -@Singleton -public class StoreTweetsController extends HttpServlet { - - private static final class StatusToBlob implements Function { - private final BlobMap map; - - private StatusToBlob(BlobMap map) { - this.map = map; - } - - public Blob apply(Status from) { - Blob to = map.blobBuilder().name(from.getId() + "").build(); - to.setPayload(from.getText()); - to.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); - to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, from.getUser().getScreenName()); - return to; - } - } - - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Map contexts; - private final Twitter client; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - @VisibleForTesting - public StoreTweetsController(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container, Twitter client) { - this.container = container; - this.contexts = contexts; - this.client = client; - } - - @VisibleForTesting - public void addMyTweets(String contextName, Iterable responseList) { - BlobStoreContext context = checkNotNull(contexts.get(contextName), "no context for " + contextName + " in " - + contexts.keySet()); - BlobMap map = context.createBlobMap(container); - for (Status status : responseList) { - Blob blob = null; - try { - blob = new StatusToBlob(map).apply(status); - map.put(status.getId() + "", blob); - } catch (AuthorizationException e) { - throw e; - } catch (Exception e) { - logger.error(e, "Error storing tweet %s (blob[%s]) on map %s/%s", status.getId(), blob, context, container); - } - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (nullToEmpty(request.getHeader(PLATFORM_REQUEST_ORIGINATOR_HEADER)).equals("taskqueue-twitter")) { - try { - String contextName = checkNotNull(request.getHeader("context"), "missing header context"); - logger.info("retrieving tweets"); - addMyTweets(contextName, client.getMentions()); - logger.debug("done storing tweets"); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error storing tweets"); - throw new ServletException(e); - } - } else { - response.sendError(401); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java deleted file mode 100644 index 42ad65df01..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.domain; - -import java.io.Serializable; - -/** - * - * @author Adrian Cole - */ -public class StoredTweetStatus implements Comparable, Serializable { - - /** The serialVersionUID */ - private static final long serialVersionUID = -3257496189689220018L; - private final String service; - private final String host; - private final String container; - private final String id; - private final String from; - private final String tweet; - private final String status; - - @Override - public String toString() { - return "StoredTweetStatus [container=" + container + ", from=" + from + ", host=" + host - + ", id=" + id + ", service=" + service + ", status=" + status + ", tweet=" + tweet - + "]"; - } - - public StoredTweetStatus(String service, String host, String container, String id, String from, - String tweet, String status) { - this.service = service; - this.host = host; - this.container = container; - this.id = id; - this.from = from; - this.tweet = tweet; - this.status = status; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((container == null) ? 0 : container.hashCode()); - result = prime * result + ((from == null) ? 0 : from.hashCode()); - result = prime * result + ((host == null) ? 0 : host.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((service == null) ? 0 : service.hashCode()); - result = prime * result + ((tweet == null) ? 0 : tweet.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; - StoredTweetStatus other = (StoredTweetStatus) obj; - if (container == null) { - if (other.container != null) - return false; - } else if (!container.equals(other.container)) - return false; - if (from == null) { - if (other.from != null) - return false; - } else if (!from.equals(other.from)) - return false; - if (host == null) { - if (other.host != null) - return false; - } else if (!host.equals(other.host)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (service == null) { - if (other.service != null) - return false; - } else if (!service.equals(other.service)) - return false; - if (tweet == null) { - if (other.tweet != null) - return false; - } else if (!tweet.equals(other.tweet)) - return false; - return true; - } - - - public String getService() { - return service; - } - - public String getHost() { - return host; - } - - public String getContainer() { - return container; - } - - public String getFrom() { - return from; - } - - public String getTweet() { - return tweet; - } - - public String getStatus() { - return status; - } - - public int compareTo(StoredTweetStatus o) { - if (id == null) - return -1; - return (int) ((this == o) ? 0 : id.compareTo(o.id)); - } - - - public String getId() { - return id; - } - -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java deleted file mode 100644 index f831b9780f..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import javax.annotation.Resource; - -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; -import org.jclouds.util.Strings2; - -import com.google.common.base.Function; - -/** - * - * @author Adrian Cole - */ -public class KeyToStoredTweetStatus implements Function { - private final String host; - private final BlobMap map; - private final String service; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - KeyToStoredTweetStatus(BlobMap map, String service, String host, String container) { - this.host = host; - this.map = map; - this.service = service; - this.container = container; - } - - public StoredTweetStatus apply(String id) { - String status; - String from; - String tweet; - try { - long start = System.currentTimeMillis(); - Blob blob = map.get(id); - status = ((System.currentTimeMillis() - start) + "ms"); - from = blob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME); - tweet = Strings2.toString(blob.getPayload()); - } catch (Exception e) { - logger.error(e, "Error listing container %s//%s/%s", service, container, id); - status = (e.getMessage()); - tweet = ""; - from = ""; - } - return new StoredTweetStatus(service, host, container, id, from, tweet, status); - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java deleted file mode 100644 index b2e5884c55..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import java.net.URI; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Context; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; - -@Singleton -public class ServiceToStoredTweetStatuses implements Function> { - - private final Map contexts; - private final String container; - - @Inject - public ServiceToStoredTweetStatuses(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) { - this.contexts = contexts; - this.container = container; - } - - @Resource - protected Logger logger = Logger.NULL; - - public Iterable apply(String service) { - BlobStoreContext context = contexts.get(service); - String host = URI.create(context.unwrap(Context.class).getProviderMetadata().getEndpoint()).getHost(); - try { - BlobMap blobMap = context.createBlobMap(container); - Set blobs = blobMap.keySet(); - return Iterables.transform(blobs, new KeyToStoredTweetStatus(blobMap, service, host, - container)); - } catch (Exception e) { - StoredTweetStatus result = new StoredTweetStatus(service, host, container, null, null, - null, e.getMessage()); - logger.error(e, "Error listing service %s", service); - return ImmutableList.of(result); - } - - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java deleted file mode 100644 index 42ec480ae2..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.reference; - -/** - * Configuration properties and constants used in TweetStore connections. - * - * @author Adrian Cole - */ -public interface TweetStoreConstants { - static final String PROPERTY_TWEETSTORE_BLOBSTORES = "jclouds.tweetstore.blobstores"; - static final String PROPERTY_TWEETSTORE_CONTAINER = "jclouds.tweetstore.container"; - /** - * Note that this has to conform to restrictions of all blobstores. for - * example, azure doesn't support periods. - */ - static final String SENDER_NAME = "sendername"; -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java b/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java deleted file mode 100644 index dc8b97915f..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.reference; - -/** - * Configuration properties and constants used in Twitter connections. - * - * @author Andrew Phillips - */ -public interface TwitterConstants { - static final String PROPERTY_TWITTER_CONSUMER_KEY = "twitter.consumer.identity"; - static final String PROPERTY_TWITTER_CONSUMER_SECRET = "twitter.consumer.credential"; - static final String PROPERTY_TWITTER_ACCESSTOKEN = "twitter.access.identity"; - static final String PROPERTY_TWITTER_ACCESSTOKEN_SECRET = "twitter.access.credential"; -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/platform/.gitignore b/demos/tweetstore/cf-tweetstore-spring/src/main/platform/.gitignore deleted file mode 100644 index 843dfe79c0..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/platform/.gitignore +++ /dev/null @@ -1 +0,0 @@ -# PaaS vendor specific files go in here \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/resources/jobs.xml b/demos/tweetstore/cf-tweetstore-spring/src/main/resources/jobs.xml deleted file mode 100644 index b740fdd52f..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/resources/jobs.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - enqueue-store-tweet-tasks - Enqueue 'store tweet' tasks for all contexts - org.jclouds.demo.paas.service.scheduler.HttpRequestJob - - - url - /stores/do - - - - - - - submit-recurring-job - enqueue-store-tweet-tasks - 10 - MINUTE - - - - \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/resources/quartz.properties b/demos/tweetstore/cf-tweetstore-spring/src/main/resources/quartz.properties deleted file mode 100644 index 12a0fcfe91..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/resources/quartz.properties +++ /dev/null @@ -1,28 +0,0 @@ -#============================================================================ -# Configure Main Scheduler Properties -#============================================================================ - -org.quartz.scheduler.skipUpdateCheck: true - -#============================================================================ -# Configure ThreadPool -#============================================================================ - -org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool -org.quartz.threadPool.threadCount: 1 - -#============================================================================ -# Configure JobStore -#============================================================================ - -org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore - -#============================================================================ -# Configure the Job Initialization Plugin -#============================================================================ - -org.quartz.plugin.jobInitializer.class: org.jclouds.demo.paas.service.scheduler.quartz.plugins.TransactionlessXmlSchedulingDataProcessorPlugin -org.quartz.plugin.jobInitializer.fileNames: jobs.xml -org.quartz.plugin.jobInitializer.failOnFileNotFound: true -org.quartz.plugin.jobInitializer.scanInterval: 0 -#org.quartz.plugin.jobInitializer.wrapInUserTransaction: false \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/webapp/WEB-INF/web.xml b/demos/tweetstore/cf-tweetstore-spring/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 51dd0744e1..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - jclouds-tweetstore - - - quartz:scheduler-context-servlet-context-key - servlet-context - - - - - org.jclouds.demo.paas.config.PlatformServicesInitializer - - - - org.quartz.ee.servlet.QuartzInitializerListener - - - - - dispatcher - org.springframework.web.servlet.DispatcherServlet - - - contextClass - org.springframework.web.context.support.AnnotationConfigWebApplicationContext - - - contextConfigLocation - org.jclouds.demo.tweetstore.config.SpringServletConfig - - - - - - dispatcher - /store/* - - - dispatcher - /tweets/* - - - dispatcher - /stores/* - - - dispatcher - /clear/* - - - - index.jsp - - \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/webapp/images/cloudfoundry-logo.png b/demos/tweetstore/cf-tweetstore-spring/src/main/webapp/images/cloudfoundry-logo.png deleted file mode 100644 index 2df231c26c5ccc254d32fa18468c982beed2c984..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6042 zcmV;L7iH*)P)X0ssI2-$8kU00001b5ch_0Itp) z=>Px#1ZP1_K>z@;j|==^1poj5AY({UO#lFTCIA3{ga82g0001h=l}q9FaQARU;qF* zm;eA5aGbhPJOBU}7)eAyRA@u(T6cJqRk{acb!~tUq!-vR8mNt^hqH-naNBh(=&Z0)90I-{Y}0Qk`Q?A^LYJB zzvr9pIdjf?-u}L)E}fd1TJrt#-O&K-{p~$GqpezI78-5e9*OS`W{1Nel}cqY8J$k& za=9q?_4TRM>fYX7yU1>CX+^^86O{Ku~@ME6ce*J`ywp%C?e$6uXJ_aJ-Q z?e=;8aE~tS4hL6jp-POk0)30fz?d|fZT1CF@F~)*q=c<|(kds=>A_gPBPRPsVp=Q~ zxm*quuu*z?dUSL&4BXY#m5`8t5FZ&C2@4BjGMNH_ATBP>Xfy&65lO7}DWl60#+If}EKB07Or*bdgB{kdkejT|UXH0AzOjviSJ%PO z5f;)F9H448e;?)F$leI+j*bqXfF@H@Q!_I&8yg#&nwqk*vJlXS`@+IPo6UCf=1pH; z-_FiXKqB;!1MX|@VXf7jZmg0L_wv;)(!W~3TAIvzIF9j~>@nARfk&IKzb&= zjTXDoV6#lGn-Gpj4#*xTi*)8q34M=8_Lq%2jcs;JQB{^vtyQA6PN*$XlZ~afnWkrW z_!ZDp&&KvYajmNYXR4LN%-Tjd+>yK%yhJEkUV4t$bms)P|$ z+^{l*Hc1ic&G(t7HVX9#v`I`{;-=r&VI|6Z-OLncR7FG%Do(Xa{Cnh>z0Ptrq$E=5 zlhQd0QHjxp8c3wK*t41Hn;fT#W}iVNkxWyG4OXGv3NVr}a9GXPY41pFwL8kV`V_h* zWmKC?*Cf%@jUvK2t<8*4b){fNS0ql2bt;Ljrb-C(Y7!YbCB`1PsX=I1bUo&nvYM?X zC->(moaLcC+e*d+)2z$Q_LID+urXZ|Q&UTu$FZKUH#5|iDS{tdX?{AQ`)Ku8?uc~K zR?Pu4NC_getKoX08r<>9@{!+Tan4=jrq_+dn^4|M_(?YhZ+G_s$q zUO3|$k{e&oV=jvrghxIR)we8i=!Nu=CV_JWBG6ejCJz2@5p%9uKd9iWjUQB)Y^fuP zrE!d9(e!0e!^@&ZfZ>lhv=-sKr3=~d!*b5jL^haN7S`*0!~1>^)?35VqA8+Jx;nOh zS$IFV1>4KQ`VQCe)Mlrf2Xsl6Mh-U5LD(qJE{z=W>lE{~<~4Bx4@C_YFjcd>UG5Yw zjiw<-R&dk+TNX3TSo8?KFQgBbPG?qw#kMJVcxmh?)beO}??cymz}40p47$?vNi`S1 zH|`*W#y+WHFAYbOs!>iKRU;Atd*ufyq9vG2;UU*cMw^3Yv@6YawwB=PE&X!ibJyB_ z6y2H0(Q=J;Y@SF=_GYwj-u^p8xrQYh`D9tjRRiL&Y#1~zgfxJgOdwEFD?vl|VnL%Z;HuBVe&8K;{^1;}i zV)~kpc8+?U3ybyU-z4@t9z+f46i(>O61^pLPzur;!>Hpblhk1OaZK0Ff|0rQ{$ojmX!5-!^oRYMlLsU{5?!}Q*Co;d z2D6;p5!v#fu2(bq!RMsOIw&*jEg4-N(tGsQ7$}Bz3Ld%A+$L~NV9BS2uX)(N>1sP) zpe6n*s&jd0@4C?Te#s0u)PtWEfu@?RLg837tB$KKXQ}+#1>ow@fYx%R0@J3S#dQBX z?lw(sU{9L*rFze1-tw!R$7@(JgLzYQ7n-04(7HjBFAwZEN8ym9g?bCp2EvIkNjT#h z6aDFYJk_tZoZ?Sq@J+sB22U2TyO#U##o8@-bZ>?(n{RYu+G_4h-2=yT7e}>8JmZl8 zb+gb|&osi=ZX?=cuHo{C`c$vNr%(D$jpWII7MBoe33K5nGS>!VnJ&{l%oXSTi=-t?1T zico!*C2;$XjN6ZURnnx|Xe##!uZlLVau!u9NBQ`Lis0sPq1yCZK-~+WjcdGbZH{e` z>75n|X&(RKg^E_Ls)i|hR4mTnfi!(_Gd47MDRxm#m%@0Pt)%zP%e zY5A$rbIrV5k*QT-N#PN22&5~6%~2>cE=Aj~>GeakloS928lUtg~HXL9pggr8@$|IE7-in!jzdE$6pHF3@#e zbbaKwp-4n{GYseHx(hT-xtQ=D)xil8*oMnYgD*oLHm=9!`76n{f9O$qs8LX%um-aX z;h5kp#zzumWW|BR!mh>b{b_v7e}0|HQ#eOW^0C?N+XG5|c{)ov-#k{k{g0OlUh&Lh zN!7nOm$NtK)?8|?Ne#a^ou$;9vfCJ|TobDLxpQ0J3$NVdmc~=eOX&v^8&(`jaXFm) z^p`1XzesX9oRUPLwJ;`Dy2kmIbT1I4dXT^3U{XxoP$Fe`&B26DmSh%yIwoFyAR)A> zPpHyAe?0B8_!>01XSJ?4oSN25kFFg8!ZxP3Ziv6aH6fv4crIr5tQMC;iNNruO9g8V zCcSv}`tQ!>ymU5u{gITv_?I%pGouDqu6^l3?usK>KE+NCc#ypt<>o*(fk7I5e(F=c z`b^>BnBmNdVB0+mP06P;-@KNaPsGB}5R*6u{KO32LQ87*kg? zVe+BtkoiwAEN(-ZTXO4>TGkJa7d(5l=}7rV5M7fY!0dPtPFhBIPwfu!NUL3x%g@8g zo_CF$m=oUsb4#vq*&EzA#GBh?RH)dvFLYmMu~KLHy?fF--Z^ty-w!DG?Xh@+$&%AF zyn1&~Z6ABKb#y}UW7mkcFJ|kf=a{pPYvj$fdxMIpqXLDND^ueI07t5R-ZkQHJ~<0S z@yl&~YLAnpjD`V-Q`dhNKPsQveKo13cS5QC@qwt%u9bp>&PcrDox5@0wVi&s>pl)? zrwi-)Iji;rrPTJ%G5|sT=S0%WClcA>$v>P*es+KOSBW);Vk@88bM?iq<0X^x(wk=% zW$j17EYaO@WPv_s;v0Np+`@ACSWfq&C-VQE*Iy;K42euV0wYUKP`NsMJGi<&DRF#I z6E*G}&NFz%YAF#tuCJGwBU$=-Ig!9Ml#5|+jT^&yVw5;JsKr*DZ=d|{Db(lB6+Lt~ zeP4RVkVwyv5nVheZJw_5M)Tj!ByZT|Q$U#!)oit8*Y*@r`Z1omUd`XM=kmBnX|Z9^ zXvd4evXjQ&@Q+K|++t|lnJ^N_)VsYiU3Ofo>1IIA{egMwcV24hpUD|L48gPS`|S12 zMpJfO@7j00Dm&=FV**Shqcu3^n1sc8Jfg&9hgT0%$d#ym`fHDd6j>w?DgNbm5E zdNGmTC4MuscGdB`fXWeUuwyF*3*H5;*Eh<4<&!Jx-a7ry)3NR$dE37TS-<_v0l!R} z-Qnt!j`AxX`)%GIfcMqU{69JyZ#0<`ikjDLJGtrIGY5Usj|N=-)dv^XZ9g5DK9j@S z23XJUIQz`@lb?Ae?!T0}>D{x>{newb-#LHIs_0n1-2?Ei?f3uvCw@Qzx_*h}X3N4I zr~Q}G(AqvQzJOb~O1I-g%=)*_zIiYR-0ty+U$@o$cY81Q(4G0lWVRf;nvK>!AG~_h zKkKb8Lf36S^QHfFoJO(uGO)4FGierKdGo;fZSLsa+CNs?Nn5||)X#Qa0AqjLcX{J> z_w{d|I}&(ZgMhGDf4kfJ_xt=vCaqT6N9U8C-s)aMrOl%9j463~>q!Pzyl9$4<&wFZ zokp|uPhL5jPNZKK5Df|o7V~(qKZ@xbc1s4u<}sByS7>UK6FRFyV|B2U=B^1Nd(zw? zFw#_J_(6-pqOsc5RtH6Hf$hbFO>MEu^foNJ)7mFCe3`N{xXfs_A-ESkFyl_hFU1tS z{;A(@cb$9ZaBxg+9pnU;0f}W>_xo?&=lkkjZ@ho{*k{klXoJbQA>Y_d|CeXN%m4Iz z>4WnhorAY&~g7v z;8|2h{)wf3JsdR565QLW)*7O7>b4)c3U0T2df6+g5d6=AX>^8&teUN^{=eMef$z19 zTl(o(7l@S~o`~>`EuM=oGOPNXLxF=#{_SB7$Zgr@2QlB=?+@mS>u!^0mW0`YzXvWR zo6R#$$recee(c&;m(z8InX`$c0t&kG#rKbI?6P7#Hlu!r<8WB<)BD1|?2yL`<_%-m zP^)2@+J#tvX<|7ui<1$dv2H{?C^WS29L)m5p?*ygXJ(0<#4(&?<2=+E#CnsxlBTX4 znf&SDxHrzEAt&F@`^b8DuE99(aK&n~!Ktz7clX5}{T!EpE=tR&^p*{6c5`q%FAedBCur*M*QpBi^e0lm&Pr68uTSEF-GiSQR2t4LXn zDUNxnWzqo)Lssbn6r%6iCXbV;kQ0#h5zF+=H$Dee1WOfqCP1 zuf}?gKeg32cje|ITmBXJZb<2SakUpy>pU~sPAAlzNo)wtYRD{YNiA+Zn^KZ z!_K(6kb>s4(w4-cro_COg#5bX($?tQ+O*>4%#!AFnGGLiba>`8CKWcmelT$Dwv*M= zc^h7{B4NiKXL;D^Lk-S+P=+JovJUET{72T~ncf(9l4oQj?RDamtGa$9$0C)~#DO>uqjs1~5+Yi;Ih4HW)ZNI~yneKnO4Z z01O92XhlaDthKfE#*G^Q19GSm7Xgxzl7IvVahglcokmCXgIzpScXn=aKhifEg1qPBjj-qkf1l>`ILn_=Ii;s^717IT}A_9lg z6bhxiy&Zia9Vmh;zO3)nzh_?9o_X6$XuSll4S>IJq)p7l1Yj$~SPDNWzd0W=a z*23EE^dgG0ro1h?yp62KUzBISDy9o}Dgl5dAfa>&8x4AR=DoB~gHw8(;Nt!Uq{4%X zS`ZA1fO2th2lj(4p&-bQFMJ|2G?dgbR2Cc@3<+UTNDdXiqOdX93ipE300X)M8){lw zS^$Ileq>mn5_d(QrrWn~;}#fn1Z^T53knLLN*D&fKnq}y2n-B_LjVBgK`SuBTId2r z0{|WXRIn?`2v%6v&(9Ah(6Bx5;~F9S0KgzxR#t`rZlRFZ7Vw}Knap5p{6!N?h|_L3 zC17AS-~l<@LIi2lg9I3Zi=YP10S!b&MWF_*&=tH2!2=PXC^GbCp9kGnT=bs8H@S%h zUqdch)ZWl0Tpp~$oFO40unKI30KzpqXcplJ|3w_bsi6*pby`{)qy;M26{12xxCMZE zK;kdl9|&=o3j&k6K-|EMfCQ?KjEsa&keLQ%##In#4VG(bYr_{>gT6oobP=HN6{rjs z$8b9g`~V5Q0DyA@1qGoy;vPxB>v#se)fm%xhGu3ZBF zm;@xr5@3J?+zjEjgs0uO_vzynW0M}L2Re8C%}fCGUa z@JuGB|C7BJHO#kE2}8m{kPz;PSO?SaXlM%LpdbhdeZlq+j|@#zl7kcC8<7Mv!`OHr zJj{jx4+#wdBS}CtfIB(1JR$AcTdb;ex0^0X(A%*nm)AiOl)H43;p&EQs%a1M;-& U<8G{SYybcN07*qoM6N<$f|B;iGXMYp diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/webapp/index.jsp b/demos/tweetstore/cf-tweetstore-spring/src/main/webapp/index.jsp deleted file mode 100644 index 6365c49c09..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/webapp/index.jsp +++ /dev/null @@ -1,30 +0,0 @@ -<%-- - - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. - ---%> - - -jclouds: anyweight cloudware for java - - -

Welcome!

-

Click here to see tweets about jclouds.

-

Powered by Cloud Foundry

- - diff --git a/demos/tweetstore/cf-tweetstore-spring/src/main/webapp/tweets.jsp b/demos/tweetstore/cf-tweetstore-spring/src/main/webapp/tweets.jsp deleted file mode 100644 index b066bd9167..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/main/webapp/tweets.jsp +++ /dev/null @@ -1,108 +0,0 @@ -<%-- - - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. - ---%> -<%@ page buffer="20kb"%> -<%@ taglib uri="http://displaytag.sf.net" prefix="display"%> - - -jclouds: anyweight cloudware for java - - - -

Tweets in Clouds

- - - - - - - -
-
- - - - - - - - -
-
Powered by Cloud Foundry
- - diff --git a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java b/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java deleted file mode 100644 index 031bb199fc..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.util.Map; -import java.util.Properties; - -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector; -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector.Credential; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code CredentialsCollector} - * - * @author Andrew Phillips - */ -@Test(groups = "unit") -public class CredentialsCollectorTest { - private CredentialsCollector collector = new CredentialsCollector(); - - public void testEmptyProperties() { - assertTrue(collector.apply(new Properties()).isEmpty(), - "Expected returned map to be empty"); - } - - public void testNoCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("not-an-identity", - "v1", "not-a-credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - private static Properties propertiesOf(Map entries) { - Properties properties = new Properties(); - properties.putAll(entries); - return properties; - } - - public void testNonMatchingCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("non_matching.identity", "v1", - "non_matching.credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - public void testIncompleteCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("acme.identity", "v1", - "acme-2.credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - public void testCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("acme.identity", "v1", - "acme.credential", "v2", "acme-2.identity", "v3", - "acme-2.credential", "v4")); - assertEquals(collector.apply(properties), - ImmutableMap.of("acme", new Credential("v1", "v2"), - "acme-2", new Credential("v3", "v4"))); - } -} \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java b/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java deleted file mode 100644 index 1c93403650..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; -import org.testng.collections.Maps; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - -/** - * Tests behavior of {@code AddTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class AddTweetsControllerTest { - - Map createServices(String container) throws InterruptedException, - ExecutionException { - Map services = Maps.newHashMap(); - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - for (String name : new String[] { "1", "2" }) { - BlobStoreContext context = ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class); - context.getAsyncBlobStore().createContainerInLocation(null, container).get(); - Blob blob = context.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - context.getAsyncBlobStore().putBlob(container, blob).get(); - services.put(name, context); - } - return services; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - String container = "container"; - Map contexts = createServices(container); - - ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container); - AddTweetsController controller = new AddTweetsController(contexts, function); - List list = controller.apply(ImmutableSet.of("1", "2")); - assertEquals(list.size(), 2); - assertEquals(list, ImmutableList.of(new StoredTweetStatus("1", "localhost", container, "1", - "frank", "I love beans!", null), new StoredTweetStatus("2", "localhost", container, - "1", "frank", "I love beans!", null))); - - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java b/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java deleted file mode 100644 index 81f0b9f3c7..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code AddTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class ClearTweetsControllerTest { - - Map createBlobStores(String container) throws InterruptedException, ExecutionException { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - for (BlobStoreContext blobstore : contexts.values()) { - blobstore.getBlobStore().createContainerInLocation(null, container); - Blob blob = blobstore.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - blobstore.getBlobStore().putBlob(container, blob); - } - return contexts; - } - - public void testClearTweets() throws IOException, InterruptedException, ExecutionException { - String container = ClearTweetsControllerTest.class.getName() + "#container"; - Map contexts = createBlobStores(container); - - ClearTweetsController controller = new ClearTweetsController(contexts, - container); - controller.clearContainer("test1"); - controller.clearContainer("test2"); - - for (BlobStoreContext context : contexts.values()) { - assertEquals(context.getBlobStore().countBlobs(container), 0, context.toString()); - } - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java b/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java deleted file mode 100644 index 3c5e5b1d80..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.easymock.EasyMock.*; - -import java.net.URI; -import java.util.Map; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.demo.paas.RunnableHttpRequest; -import org.jclouds.demo.paas.RunnableHttpRequest.Factory; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.http.HttpRequest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; - -/** - * Tests behavior of {@code EnqueueStoresController} - * - * @author Andrew Phillips - */ -@Test(groups = "unit") -public class EnqueueStoresControllerTest { - - Map createBlobStores() { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - return contexts; - } - - public void testEnqueueStores() { - Map stores = createBlobStores(); - TaskQueue taskQueue = createMock(TaskQueue.class); - Factory httpRequestFactory = createMock(Factory.class); - EnqueueStoresController function = new EnqueueStoresController(stores, - taskQueue, "http://localhost:8080"); - - expect(taskQueue.getHttpRequestFactory()).andStubReturn(httpRequestFactory); - - HttpRequest storeInTest1Request = HttpRequest.builder().endpoint( - URI.create("http://localhost:8080/store/do")) - .headers(ImmutableMultimap.of("context", "test1")).method("GET").build(); - RunnableHttpRequest storeInTest1Task = null; - expect(httpRequestFactory.create(eq(storeInTest1Request))).andReturn(storeInTest1Task); - - HttpRequest storeInTest2Request = HttpRequest.builder().endpoint( - URI.create("http://localhost:8080/store/do")) - .headers(ImmutableMultimap.of("context", "test2")).method("GET").build(); - RunnableHttpRequest storeInTest2Task = null; - expect(httpRequestFactory.create(eq(storeInTest2Request))).andReturn(storeInTest2Task); - - taskQueue.add(storeInTest1Task); - expectLastCall(); - taskQueue.add(storeInTest2Task); - expectLastCall(); - replay(httpRequestFactory, taskQueue); - - function.enqueueStoreTweetTasks(); - - verify(taskQueue); - } -} \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java b/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java deleted file mode 100644 index 53eb8a9302..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.util.Strings2; -import org.testng.annotations.Test; - -import twitter4j.Status; -import twitter4j.Twitter; -import twitter4j.User; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code StoreTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class StoreTweetsControllerTest { - - Twitter createTwitter() { - return createMock(Twitter.class); - } - - Map createBlobStores() throws InterruptedException, ExecutionException { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - for (BlobStoreContext blobstore : contexts.values()) { - blobstore.getAsyncBlobStore().createContainerInLocation(null, "favo").get(); - } - return contexts; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - Map stores = createBlobStores(); - StoreTweetsController function = new StoreTweetsController(stores, "favo", createTwitter()); - - User frank = createMock(User.class); - expect(frank.getScreenName()).andReturn("frank").atLeastOnce(); - - Status frankStatus = createMock(Status.class); - expect(frankStatus.getId()).andReturn(1l).atLeastOnce(); - expect(frankStatus.getUser()).andReturn(frank).atLeastOnce(); - expect(frankStatus.getText()).andReturn("I love beans!").atLeastOnce(); - - User jimmy = createMock(User.class); - expect(jimmy.getScreenName()).andReturn("jimmy").atLeastOnce(); - - Status jimmyStatus = createMock(Status.class); - expect(jimmyStatus.getId()).andReturn(2l).atLeastOnce(); - expect(jimmyStatus.getUser()).andReturn(jimmy).atLeastOnce(); - expect(jimmyStatus.getText()).andReturn("cloud is king").atLeastOnce(); - - replay(frank); - replay(frankStatus); - replay(jimmy); - replay(jimmyStatus); - - function.addMyTweets("test1", ImmutableList.of(frankStatus, jimmyStatus)); - function.addMyTweets("test2", ImmutableList.of(frankStatus, jimmyStatus)); - - verify(frank); - verify(frankStatus); - verify(jimmy); - verify(jimmyStatus); - - for (Entry entry : stores.entrySet()) { - BlobMap map = entry.getValue().createBlobMap("favo"); - Blob frankBlob = map.get("1"); - assertEquals(frankBlob.getMetadata().getName(), "1"); - assertEquals(frankBlob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME), "frank"); - assertEquals(frankBlob.getMetadata().getContentMetadata().getContentType(), "text/plain"); - assertEquals(Strings2.toString(frankBlob.getPayload()), "I love beans!"); - - Blob jimmyBlob = map.get("2"); - assertEquals(jimmyBlob.getMetadata().getName(), "2"); - assertEquals(jimmyBlob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME), "jimmy"); - assertEquals(jimmyBlob.getMetadata().getContentMetadata().getContentType(), "text/plain"); - assertEquals(Strings2.toString(jimmyBlob.getPayload()), "cloud is king"); - } - - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java b/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java deleted file mode 100644 index af74b423d5..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; - -/** - * Tests behavior of {@code KeyToStoredTweetStatus} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class KeyToStoredTweetStatusTest { - - BlobMap createMap() throws InterruptedException, ExecutionException { - BlobStoreContext context = - ContextBuilder.newBuilder(TransientApiMetadata.builder().build()).build(BlobStoreContext.class); - context.getBlobStore().createContainerInLocation(null, "test1"); - return context.createBlobMap("test1"); - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - BlobMap map = createMap(); - Blob blob = map.blobBuilder().name("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - map.put("1", blob); - String host = "localhost"; - String service = "stub"; - String container = "tweetstore"; - - KeyToStoredTweetStatus function = new KeyToStoredTweetStatus(map, service, host, container); - StoredTweetStatus result = function.apply("1"); - - StoredTweetStatus expected = new StoredTweetStatus(service, host, container, "1", "frank", - "I love beans!", null); - - assertEquals(result, expected); - - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java b/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java deleted file mode 100644 index 5fec52711e..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; -import org.testng.collections.Maps; - -import com.google.common.collect.Iterables; - -/** - * Tests behavior of {@code ServiceToStoredTweetStatuses} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class ServiceToStoredTweetStatusesTest { - - Map createServices(String container) throws InterruptedException, - ExecutionException { - Map services = Maps.newHashMap(); - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - for (String name : new String[] { "1", "2" }) { - BlobStoreContext context = ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class); - context.getAsyncBlobStore().createContainerInLocation(null, container).get(); - Blob blob = context.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - context.getAsyncBlobStore().putBlob(container, blob).get(); - services.put(name, context); - } - return services; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - String container = "container"; - Map contexts = createServices(container); - - ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container); - - assertEquals(Iterables.getLast(function.apply("1")), new StoredTweetStatus("1", "localhost", - container, "1", "frank", "I love beans!", null)); - - assertEquals(Iterables.getLast(function.apply("2")), new StoredTweetStatus("2", "localhost", - container, "1", "frank", "I love beans!", null)); - - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/CloudFoundryServer.java b/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/CloudFoundryServer.java deleted file mode 100644 index 6ecebbdfab..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/CloudFoundryServer.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.io.Closeables.closeQuietly; -import static java.lang.String.format; -import static org.jclouds.demo.tweetstore.integration.util.Zips.zipDir; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Properties; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; - -import org.cloudfoundry.client.lib.CloudApplication.AppState; -import org.cloudfoundry.client.lib.CloudFoundryClient; - -/** - * Basic "server facade" functionality to deploy a WAR to Cloud Foundry. - * - * @author Andrew Phillips - */ -public class CloudFoundryServer { - private static final String CLOUD_FOUNDRY_APPLICATION_URL_SUFFIX = ".cloudfoundry.com"; - - protected CloudFoundryClient client; - protected String appName; - - public void writePropertiesAndStartServer(final String address, final String warfile, - String target, String username, String password, Properties props) throws IOException, InterruptedException, ExecutionException { - String propsfile = String.format("%1$s/WEB-INF/jclouds.properties", warfile); - System.err.println("file: " + propsfile); - storeProperties(propsfile, props); - assert new File(propsfile).exists(); - - client = new CloudFoundryClient(username, password, target); - client.login(); - appName = getAppName(address); - deploy(warfile); - client.logout(); - TimeUnit.SECONDS.sleep(10); - } - - private void deploy(String explodedWar) throws IOException { - File war = zipDir(explodedWar, format("%s-cloudfoundry.war", explodedWar)); - client.uploadApplication(appName, war); - - // adapted from https://github.com/cloudfoundry/vcap-java-client/blob/master/cloudfoundry-maven-plugin/src/main/java/org/cloudfoundry/maven/Update.java - AppState appState = client.getApplication(appName).getState(); - switch (appState) { - case STOPPED: - client.startApplication(appName); - break; - case STARTED: - client.restartApplication(appName); - break; - default: - throw new IllegalStateException(format("Unexpected application state '%s'", appState)); - } - } - - private static void storeProperties(String filename, Properties props) - throws IOException { - FileOutputStream targetFile = new FileOutputStream(filename); - try { - props.store(targetFile, "test"); - } finally { - closeQuietly(targetFile); - } - } - - private static String getAppName(String applicationUrl) { - checkArgument(applicationUrl.endsWith(CLOUD_FOUNDRY_APPLICATION_URL_SUFFIX), - "Application URL '%s' does not end in '%s'", applicationUrl, - CLOUD_FOUNDRY_APPLICATION_URL_SUFFIX); - - return applicationUrl.substring(0, - applicationUrl.length() - CLOUD_FOUNDRY_APPLICATION_URL_SUFFIX.length()); - } - - public void stop() throws Exception { - checkState(client != null, "'stop' called before 'writePropertiesAndStartServer'"); - client.login(); - client.stopApplication(appName); - client.logout(); - } -} \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java b/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java deleted file mode 100644 index 3723d5f250..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java +++ /dev/null @@ -1,234 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -import org.jclouds.Context; -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.config.SpringServletConfig; -import org.jclouds.demo.tweetstore.controller.StoreTweetsController; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.util.Strings2; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - -import twitter4j.ResponseList; -import twitter4j.Status; -import twitter4j.Twitter; -import twitter4j.TwitterException; -import twitter4j.TwitterFactory; -import twitter4j.conf.Configuration; -import twitter4j.conf.ConfigurationBuilder; - -import com.google.common.base.Joiner; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.inject.Module; - -/** - * Starts up the Google App Engine for Java Development environment and deploys an application which - * tests accesses twitter and blobstores. - * - * @author Adrian Cole - */ -@Test(groups = "live", singleThreaded = true) -public class TweetStoreLiveTest { - - CloudFoundryServer server; - private URL url; - private Map contexts; - private String container; - - private static final Iterable blobstores = - Splitter.on(',').split(System.getProperty(PROPERTY_TWEETSTORE_BLOBSTORES, - "cloudfiles-us,aws-s3,azureblob")); - private static final Properties props = new Properties(); - - @BeforeTest - void clearAndCreateContainers() throws InterruptedException, ExecutionException, TimeoutException, IOException, - TwitterException { - container = getRequiredSystemProperty(PROPERTY_TWEETSTORE_CONTAINER); - - props.setProperty(PROPERTY_TWEETSTORE_CONTAINER, container); - props.setProperty(SpringServletConfig.PROPERTY_BLOBSTORE_CONTEXTS, Joiner.on(',').join(blobstores)); - - // put all identity/credential pairs into the client - addCredentialsForBlobStores(props); - - // example of an ad-hoc client configuration - addConfigurationForTwitter(props); - - // for testing, capture logs. - final Set wiring = ImmutableSet. of(new Log4JLoggingModule()); - this.contexts = Maps.newConcurrentMap(); - - for (String provider : blobstores) { - contexts.put(provider, ContextBuilder.newBuilder(provider).modules(wiring) - .overrides(props).build(BlobStoreContext.class)); - } - - Configuration conf = new ConfigurationBuilder() - .setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY)) - .setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET)) - .setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN)) - .setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET)) - .build(); - Twitter client = new TwitterFactory(conf).getInstance(); - StoreTweetsController controller = new StoreTweetsController(contexts, container, client); - - ResponseList statuses = client.getMentions(); - - boolean deleted = false; - for (BlobStoreContext context : contexts.values()) { - if (context.getBlobStore().containerExists(container)) { - System.err.printf("deleting container %s at %s%n", container, - context.unwrap(Context.class).getProviderMetadata().getEndpoint()); - context.getBlobStore().deleteContainer(container); - deleted = true; - } - } - if (deleted) { - System.err.println("sleeping 60 seconds to allow containers to clear"); - Thread.sleep(60000); - } - for (BlobStoreContext context : contexts.values()) { - System.err.printf("creating container %s at %s%n", container, - context.unwrap(Context.class).getProviderMetadata().getEndpoint()); - context.getBlobStore().createContainerInLocation(null, container); - } - if (deleted) { - System.err.println("sleeping 5 seconds to allow containers to create"); - Thread.sleep(5000); - } - - for (Entry entry : contexts.entrySet()) { - System.err.printf("filling container %s at %s%n", container, entry.getKey()); - controller.addMyTweets(entry.getKey(), statuses); - } - } - - private static String getRequiredSystemProperty(String key) { - return checkNotNull(System.getProperty(key), key); - } - - private void addConfigurationForTwitter(Properties props) { - props.setProperty(PROPERTY_TWITTER_CONSUMER_KEY, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_KEY)); - props.setProperty(PROPERTY_TWITTER_CONSUMER_SECRET, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_SECRET)); - props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN)); - props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN_SECRET)); - } - - private void addCredentialsForBlobStores(Properties props) { - for (String provider : blobstores) { - props.setProperty(provider + ".identity", - getRequiredSystemProperty("test." + provider + ".identity")); - props.setProperty(provider + ".credential", - getRequiredSystemProperty("test." + provider + ".credential")); - } - } - - @BeforeTest - @Parameters({ "warfile", "cloudfoundry.address", "cloudfoundry.port", "cloudfoundry.target", "cloudfoundry.username", "cloudfoundry.password" }) - public void startDevAppServer(final String warfile, final String address, final String port, - String target, String username, String password) throws Exception { - url = new URL(String.format("http://%s:%s", address, port)); - server = new CloudFoundryServer(); - server.writePropertiesAndStartServer(address, warfile, target, username, password, props); - } - - @Test - public void shouldPass() throws InterruptedException, IOException { - InputStream i = url.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Welcome") >= 0 : string; - } - - @Test(dependsOnMethods = "shouldPass", expectedExceptions = IOException.class) - public void shouldFail() throws InterruptedException, IOException { - new URL(url, "/store/do").openStream(); - } - - @Test(dependsOnMethods = "shouldFail") - public void testPrimeContainers() throws IOException, InterruptedException { - URL gurl = new URL(url, "/store/do"); - for (String context : blobstores) { - System.out.println("storing at context: " + context); - HttpURLConnection connection = (HttpURLConnection) gurl.openConnection(); - connection.addRequestProperty("X-Platform-Originator", "taskqueue-twitter"); - connection.addRequestProperty("context", context); - InputStream i = connection.getInputStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Done!") >= 0 : string; - connection.disconnect(); - } - - System.err.println("sleeping 20 seconds to allow for eventual consistency delay"); - Thread.sleep(20000); - for (BlobStoreContext context : contexts.values()) { - assert context.createInputStreamMap(container).size() > 0 : context.unwrap(Context.class).getProviderMetadata().getEndpoint(); - } - } - - @Test(invocationCount = 5, dependsOnMethods = "testPrimeContainers") - public void testSerial() throws InterruptedException, IOException { - URL gurl = new URL(url, "/tweets/get"); - InputStream i = gurl.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Tweets in Clouds") >= 0 : string; - } - - @Test(invocationCount = 10, dependsOnMethods = "testPrimeContainers", threadPoolSize = 3) - public void testParallel() throws InterruptedException, IOException { - URL gurl = new URL(url, "/tweets/get"); - InputStream i = gurl.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Tweets in Clouds") >= 0 : string; - } - - @AfterTest - public void stopDevAppServer() throws Exception { - server.stop(); - } -} diff --git a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/util/Zips.java b/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/util/Zips.java deleted file mode 100644 index 571c9083a3..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/util/Zips.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration.util; - -import java.io.File; -import java.io.IOException; - -import org.codehaus.plexus.archiver.zip.ZipArchiver; - -public class Zips { - - public static File zipDir(String dirToZip, String zipFile) throws IOException { - ZipArchiver archiver = new ZipArchiver(); - archiver.addDirectory(new File(dirToZip)); - File zip = new File(zipFile); - archiver.setDestFile(zip); - archiver.createArchive(); - return zip; - } -} \ No newline at end of file diff --git a/demos/tweetstore/cf-tweetstore-spring/src/test/resources/log4j.xml b/demos/tweetstore/cf-tweetstore-spring/src/test/resources/log4j.xml deleted file mode 100644 index 2e5d01fb9e..0000000000 --- a/demos/tweetstore/cf-tweetstore-spring/src/test/resources/log4j.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/demos/tweetstore/gae-tweetstore-spring/README.txt b/demos/tweetstore/gae-tweetstore-spring/README.txt deleted file mode 100644 index 0acc6d2ed5..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/README.txt +++ /dev/null @@ -1,64 +0,0 @@ -==== - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. -==== - -This sample is a "port" of jclouds-demo-gae-tweetstore with the initial context setup -and wiring carried out with Spring. It is intended to demonstrate how to integrate -jclouds into your Spring application. - -It should not be regarded as a sample of how to write a web application using Spring, -however! The original jclouds-demo-gae-tweetstore has been modified in as few places as -possible; it has not been rewritten in the style of a Spring MVC application. - -A guide to generating Twitter consumer keys and access tokens is at http://tinyurl.com/2fhebgb - -This sample uses the Google App Engine for Java SDK located at -http://code.google.com/p/googleappengine/downloads/list - -Please unzip the above file and modify your maven settings.xml like below before -attempting to run 'mvn -Plive install' - - - appengine - - true - - - /path/to/appengine-java-sdk-1.4.2 - yourappid - - - - - keys - - true - - - YOUR_ACCESS_KEY_ID - YOUR_SECRET_KEY - YOUR_USER - YOUR_HEX_KEY - YOUR_ACCOUNT - YOUR_BASE64_ENCODED_KEY - YOUR_TWITTER_CONSUMER_KEY - YOUR_TWITTER_CONSUMER_SECRET - YOUR_TWITTER_ACCESSTOKEN - YOUR_TWITTER_ACCESSTOKEN_SECRET - - \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore-spring/pom.xml b/demos/tweetstore/gae-tweetstore-spring/pom.xml deleted file mode 100644 index cb8efcbce1..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/pom.xml +++ /dev/null @@ -1,156 +0,0 @@ - - - - 4.0.0 - - org.jclouds - jclouds-demos-tweetstore-project - 1.6.0-SNAPSHOT - - jclouds-demo-gae-tweetstore-spring - war - jclouds TweetStore for Google App Engine (Spring) - JClouds TweetStore for Google App Engine using Spring for Dependency Injection - - - - jclouds-tweetstore-spring - 1.6.1 - localhost - 8088 - jclouds-gae-tweetstore-spring - - - - - org.jclouds.driver - jclouds-gae - ${project.version} - - - org.springframework - spring-context - 3.0.5.RELEASE - - - - commons-logging - commons-logging - - - - - org.springframework - spring-webmvc - 3.0.5.RELEASE - - - cglib - cglib-nodep - 2.2 - runtime - - - - - com.google.appengine - appengine-api-1.0-sdk - ${appengine.sdk.version} - - - com.google.appengine - appengine-tools-sdk - ${appengine.sdk.version} - test - - - - - - live - - - - maven-surefire-plugin - - - integration - integration-test - - test - - - - ${test.twitter.gae-tweetstore-spring.consumer.identity} - ${test.twitter.gae-tweetstore-spring.consumer.credential} - ${test.twitter.gae-tweetstore-spring.access.identity} - ${test.twitter.gae-tweetstore-spring.access.credential} - ${test.azureblob.identity} - ${test.azureblob.credential} - ${test.cloudfiles-us.identity} - ${test.cloudfiles-us.credential} - ${test.aws-s3.identity} - ${test.aws-s3.credential} - ${test.cloudonestorage.identity} - ${test.cloudonestorage.credential} - ${test.ninefold-storage.identity} - ${test.ninefold-storage.credential} - ${appengine.sdk.root} - ${devappserver.address} - ${devappserver.port} - ${jclouds.tweetstore.blobstores} - test.${jclouds.tweetstore.container} - ${project.build.directory}/${project.artifactId} - - - - - - - - - - - deploy - - - gae-tweetstore-spring - - - - - net.kindleit - maven-gae-plugin - 0.9.2 - - google-appengine - ${appengine.sdk.root} - - - - - - - diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/LoggingConfig.java b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/LoggingConfig.java deleted file mode 100644 index 9852ae59ce..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/LoggingConfig.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config; - -import static org.jclouds.logging.LoggingModules.firstOrJDKLoggingModule; - -import org.jclouds.logging.Logger.LoggerFactory; - -/** - * Spring config that provides a logger. - * - * @author Andrew Phillips - */ -abstract class LoggingConfig { - protected static final LoggerFactory LOGGER_FACTORY = firstOrJDKLoggingModule().createLoggerFactory(); -} diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/SpringServletConfig.java b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/SpringServletConfig.java deleted file mode 100644 index 9bfba4a8cd..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/SpringServletConfig.java +++ /dev/null @@ -1,241 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Predicates.in; -import static com.google.common.collect.ImmutableSet.copyOf; -import static com.google.common.collect.Sets.filter; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.servlet.Servlet; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector; -import org.jclouds.demo.tweetstore.controller.AddTweetsController; -import org.jclouds.demo.tweetstore.controller.ClearTweetsController; -import org.jclouds.demo.tweetstore.controller.EnqueueStoresController; -import org.jclouds.demo.tweetstore.controller.StoreTweetsController; -import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; -import org.jclouds.gae.config.GoogleAppEngineConfigurationModule; -import org.jclouds.logging.Logger; -import org.springframework.beans.factory.BeanCreationException; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.context.ServletConfigAware; -import org.springframework.web.servlet.HandlerAdapter; -import org.springframework.web.servlet.HandlerMapping; -import org.springframework.web.servlet.handler.SimpleServletHandlerAdapter; -import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; - -import twitter4j.Twitter; -import twitter4j.TwitterFactory; -import twitter4j.conf.ConfigurationBuilder; - -import com.google.appengine.api.taskqueue.Queue; -import com.google.appengine.api.taskqueue.QueueFactory; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.common.io.Closeables; -import com.google.inject.Module; - -/** - * Creates servlets (using resources from the {@link SpringAppConfig}) and mappings. - * - * @author Andrew Phillips - * @see SpringAppConfig - */ -@Configuration -public class SpringServletConfig extends LoggingConfig implements ServletConfigAware { - public static final String PROPERTY_BLOBSTORE_CONTEXTS = "blobstore.contexts"; - - private static final Logger LOGGER = LOGGER_FACTORY.getLogger(SpringServletConfig.class.getName()); - - private ServletConfig servletConfig; - - private Map providerTypeToBlobStoreMap; - private Twitter twitterClient; - private String container; - private Queue queue; - - @PostConstruct - public void initialize() throws IOException { - Properties props = loadJCloudsProperties(); - LOGGER.trace("About to initialize members."); - - Module googleModule = new GoogleAppEngineConfigurationModule(); - Set modules = ImmutableSet. of(googleModule); - // shared across all blobstores and used to retrieve tweets - try { - twitter4j.conf.Configuration twitterConf = new ConfigurationBuilder() - .setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY)) - .setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET)) - .setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN)) - .setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET)) - .build(); - twitterClient = new TwitterFactory(twitterConf).getInstance(); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("properties for twitter not configured properly in " + props.toString(), e); - } - // common namespace for storing tweets - container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER), PROPERTY_TWEETSTORE_CONTAINER); - - // instantiate and store references to all blobstores by provider name - providerTypeToBlobStoreMap = Maps.newHashMap(); - for (String hint : getBlobstoreContexts(props)) { - providerTypeToBlobStoreMap.put(hint, ContextBuilder.newBuilder(hint) - .modules(modules).overrides(props).build(BlobStoreContext.class)); - } - - // get a queue for submitting store tweet requests - queue = QueueFactory.getQueue("twitter"); - - LOGGER.trace("Members initialized. Twitter: '%s', container: '%s', provider types: '%s'", twitterClient, - container, providerTypeToBlobStoreMap.keySet()); - } - - private static Iterable getBlobstoreContexts(Properties props) { - Set contexts = new CredentialsCollector().apply(props).keySet(); - String explicitContexts = props.getProperty(PROPERTY_TWEETSTORE_BLOBSTORES); - if (explicitContexts != null) { - contexts = filter(contexts, in(copyOf(Splitter.on(',').split(explicitContexts)))); - } - checkState(!contexts.isEmpty(), "no credentials available for any requested context"); - return contexts; - } - - private Properties loadJCloudsProperties() { - LOGGER.trace("About to read properties from '%s'", "/WEB-INF/jclouds.properties"); - Properties props = new Properties(); - InputStream input = servletConfig.getServletContext().getResourceAsStream("/WEB-INF/jclouds.properties"); - try { - props.load(input); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - Closeables.closeQuietly(input); - } - LOGGER.trace("Properties successfully read."); - return props; - } - - @Bean - public StoreTweetsController storeTweetsController() { - StoreTweetsController controller = new StoreTweetsController(providerTypeToBlobStoreMap, container, twitterClient); - injectServletConfig(controller); - return controller; - } - - @Bean - public AddTweetsController addTweetsController() { - AddTweetsController controller = new AddTweetsController(providerTypeToBlobStoreMap, - serviceToStoredTweetStatuses()); - injectServletConfig(controller); - return controller; - } - - @Bean - public EnqueueStoresController enqueueStoresController() { - return new EnqueueStoresController(providerTypeToBlobStoreMap, queue); - } - - @Bean - public ClearTweetsController clearTweetsController() { - return new ClearTweetsController(providerTypeToBlobStoreMap, container); - } - - private void injectServletConfig(Servlet servlet) { - LOGGER.trace("About to inject servlet config '%s'", servletConfig); - try { - servlet.init(checkNotNull(servletConfig)); - } catch (ServletException exception) { - throw new BeanCreationException("Unable to instantiate " + servlet, exception); - } - LOGGER.trace("Successfully injected servlet config."); - } - - @Bean - ServiceToStoredTweetStatuses serviceToStoredTweetStatuses() { - return new ServiceToStoredTweetStatuses(providerTypeToBlobStoreMap, container); - } - - @Bean - public HandlerMapping handlerMapping() { - SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); - Map urlMap = Maps.newHashMapWithExpectedSize(2); - urlMap.put("/store/*", storeTweetsController()); - urlMap.put("/tweets/*", addTweetsController()); - urlMap.put("/stores/*", enqueueStoresController()); - urlMap.put("/clear/*", clearTweetsController()); - mapping.setUrlMap(urlMap); - /* - * "/store", "/tweets" and "/stores" are part of the servlet mapping and thus - * stripped by the mapping if using default settings. - */ - mapping.setAlwaysUseFullPath(true); - return mapping; - } - - @Bean - public HandlerAdapter servletHandlerAdapter() { - return new SimpleServletHandlerAdapter(); - } - - @PreDestroy - public void destroy() throws Exception { - LOGGER.trace("About to close contexts."); - for (BlobStoreContext context : providerTypeToBlobStoreMap.values()) { - context.close(); - } - LOGGER.trace("Contexts closed."); - LOGGER.trace("About to purge request queue."); - queue.purge(); - LOGGER.trace("Request queue purged."); - } - - /* - * (non-Javadoc) - * - * @see - * org.springframework.web.context.ServletConfigAware#setServletConfig(javax.servlet.ServletConfig - * ) - */ - @Override - public void setServletConfig(ServletConfig servletConfig) { - this.servletConfig = servletConfig; - } -} \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java deleted file mode 100644 index ce3943376e..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java +++ /dev/null @@ -1,153 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Predicates.notNull; -import static com.google.common.collect.Collections2.filter; -import static com.google.common.collect.Collections2.transform; -import static com.google.common.collect.ImmutableSet.copyOf; -import static com.google.common.collect.Maps.filterValues; -import static org.jclouds.util.Maps2.fromKeys; - -import java.util.Collection; -import java.util.Map; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector.Credential; - -import com.google.common.annotations.GwtIncompatible; -import com.google.common.base.Function; -import com.google.common.base.Predicate; - -/** - * Reads provider credentials from a {@link Properties} bag. - * - * @author Andrew Phillips - * - */ -public class CredentialsCollector implements Function> { - private static final String IDENTITY_PROPERTY_SUFFIX = ".identity"; - private static final String CREDENTIAL_PROPERTY_SUFFIX = ".credential"; - - // using the identity for provider name extraction - private static final Pattern IDENTITY_PROPERTY_PATTERN = - Pattern.compile("([a-zA-Z0-9-]+)" + Pattern.quote(IDENTITY_PROPERTY_SUFFIX)); - - @Override - public Map apply(final Properties properties) { - Collection providerNames = transform( - filter(properties.stringPropertyNames(), MatchesPattern.matches(IDENTITY_PROPERTY_PATTERN)), - new Function() { - @Override - public String apply(String input) { - Matcher matcher = IDENTITY_PROPERTY_PATTERN.matcher(input); - // as a side-effect, sets the matching group! - checkState(matcher.matches(), "'%s' should match '%s'", input, IDENTITY_PROPERTY_PATTERN); - return matcher.group(1); - } - }); - /* - * Providers without a credential property result in null values, which are - * removed from the returned map. - */ - return filterValues(fromKeys(copyOf(providerNames), new Function() { - @Override - public Credential apply(String providerName) { - String identity = properties.getProperty(providerName + IDENTITY_PROPERTY_SUFFIX); - String credential = properties.getProperty(providerName + CREDENTIAL_PROPERTY_SUFFIX); - return (((identity != null) && (credential != null)) - ? new Credential(identity, credential) - : null); - } - }), notNull()); - } - - public static class Credential { - private final String identity; - private final String credential; - - public Credential(String identity, String credential) { - this.identity = checkNotNull(identity, "identity"); - this.credential = checkNotNull(credential, "credential"); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((credential == null) ? 0 : credential.hashCode()); - result = prime * result - + ((identity == null) ? 0 : identity.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; - Credential other = (Credential) obj; - if (credential == null) { - if (other.credential != null) - return false; - } else if (!credential.equals(other.credential)) - return false; - if (identity == null) { - if (other.identity != null) - return false; - } else if (!identity.equals(other.identity)) - return false; - return true; - } - - public String getIdentity() { - return identity; - } - - public String getCredential() { - return credential; - } - } - - @GwtIncompatible(value = "java.util.regex.Pattern") - private static class MatchesPattern implements Predicate { - private final Pattern pattern; - - private MatchesPattern(Pattern pattern) { - this.pattern = pattern; - } - - @Override - public boolean apply(String input) { - return pattern.matcher(input).matches(); - } - - private static MatchesPattern matches(Pattern pattern) { - return new MatchesPattern(pattern); - } - } -} diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java deleted file mode 100644 index 918132161e..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -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.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; -import org.jclouds.logging.Logger; - -import com.google.appengine.repackaged.com.google.common.collect.Lists; -import com.google.common.base.Function; -import com.google.common.collect.Iterables; - -/** - * Shows an example of how to use @{link BlobStoreContext} injected with Guice. - * - * @author Adrian Cole - */ -@Singleton -public class AddTweetsController extends HttpServlet implements - Function, List> { - - /** The serialVersionUID */ - private static final long serialVersionUID = 3888348023150822683L; - private final Map contexts; - private final ServiceToStoredTweetStatuses blobStoreContextToContainerResult; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - public AddTweetsController(Map contexts, - ServiceToStoredTweetStatuses blobStoreContextToContainerResult) { - this.contexts = contexts; - this.blobStoreContextToContainerResult = blobStoreContextToContainerResult; - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - try { - addMyTweetsToRequest(request); - RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/tweets.jsp"); - dispatcher.forward(request, response); - } catch (Exception e) { - logger.error(e, "Error listing containers"); - throw new ServletException(e); - } - } - - void addMyTweetsToRequest(HttpServletRequest request) throws InterruptedException, - ExecutionException, TimeoutException { - request.setAttribute("tweets", apply(contexts.keySet())); - } - - public List apply(Set in) { - List statuses = Lists.newArrayList(); - for (Iterable list : Iterables.transform(in, - blobStoreContextToContainerResult)) { - Iterables.addAll(statuses, list); - } - return statuses; - } -} \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java deleted file mode 100644 index e08cfbc19e..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Strings.nullToEmpty; - -import java.io.IOException; -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; - -import com.google.common.annotations.VisibleForTesting; - -/** - * Grab tweets related to me and store them into blobstores - * - * @author Adrian Cole - */ -@Singleton -public class ClearTweetsController extends HttpServlet { - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Map contexts; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - @VisibleForTesting - public ClearTweetsController(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) { - this.container = container; - this.contexts = contexts; - } - - @VisibleForTesting - public void clearContainer(String contextName) { - BlobStoreContext context = checkNotNull(contexts.get(contextName), - "no context for %s in %s", contextName, contexts.keySet()); - try { - context.getBlobStore().clearContainer(container); - } catch (Exception e) { - logger.error(e, "Error clearing tweets in %s/%s", container, context); - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (nullToEmpty(request.getHeader("X-Originator")).equals("admin")) { - try { - String contextName = checkNotNull(request.getHeader("context"), "missing header context"); - logger.info("clearing tweets in %s/%s", container, contextName); - clearContainer(contextName); - logger.debug("done clearing tweets"); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error clearing tweets"); - throw new ServletException(e); - } - } else { - response.sendError(401); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java deleted file mode 100644 index 94568e4dec..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl; -import static com.google.appengine.repackaged.com.google.common.base.Strings.nullToEmpty; - -import java.io.IOException; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.logging.Logger; - -import com.google.appengine.api.taskqueue.Queue; -import com.google.appengine.api.taskqueue.TaskOptions.Method; -import com.google.common.annotations.VisibleForTesting; - -/** - * Adds tasks to retrieve and store tweets in all registered contexts to an async - * task queue. - * - * @author Andrew Phillips - * @see StoreTweetsController - */ -@Singleton -public class EnqueueStoresController extends HttpServlet { - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Set contextNames; - private final Queue taskQueue; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - public EnqueueStoresController(Map contexts, - Queue taskQueue) { - contextNames = contexts.keySet(); - this.taskQueue = taskQueue; - } - - @VisibleForTesting - void enqueueStoreTweetTasks() { - for (String contextName : contextNames) { - logger.debug("enqueuing task to store tweets in blobstore '%s'", contextName); - taskQueue.add(withUrl("/store/do").header("context", contextName).method(Method.GET)); - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (!nullToEmpty(request.getHeader("X-AppEngine-Cron")).equals("true")) { - response.sendError(401); - } - - try { - enqueueStoreTweetTasks(); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error storing tweets"); - throw new ServletException(e); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java deleted file mode 100644 index ae00c69d20..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.io.IOException; -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; -import org.jclouds.rest.AuthorizationException; - -import twitter4j.Status; -import twitter4j.Twitter; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; - -/** - * Grab tweets related to me and store them into blobstores - * - * @author Adrian Cole - */ -@Singleton -public class StoreTweetsController extends HttpServlet { - - private static final class StatusToBlob implements Function { - private final BlobMap map; - - private StatusToBlob(BlobMap map) { - this.map = map; - } - - public Blob apply(Status from) { - Blob to = map.blobBuilder().name(from.getId() + "").build(); - to.setPayload(from.getText()); - to.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); - to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, from.getUser().getScreenName()); - return to; - } - } - - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Map contexts; - private final Twitter client; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - @VisibleForTesting - public StoreTweetsController(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container, Twitter client) { - this.container = container; - this.contexts = contexts; - this.client = client; - } - - @VisibleForTesting - public void addMyTweets(String contextName, Iterable responseList) { - BlobStoreContext context = checkNotNull(contexts.get(contextName), "no context for " + contextName + " in " - + contexts.keySet()); - BlobMap map = context.createBlobMap(container); - for (Status status : responseList) { - Blob blob = null; - try { - blob = new StatusToBlob(map).apply(status); - map.put(status.getId() + "", blob); - } catch (AuthorizationException e) { - throw e; - } catch (Exception e) { - logger.error(e, "Error storing tweet %s (blob[%s]) on map %s/%s", status.getId(), blob, context, container); - } - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (request.getHeader("X-AppEngine-QueueName") != null - && request.getHeader("X-AppEngine-QueueName").equals("twitter")) { - try { - String contextName = checkNotNull(request.getHeader("context"), "missing header context"); - logger.info("retrieving tweets"); - addMyTweets(contextName, client.getMentions()); - logger.debug("done storing tweets"); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error storing tweets"); - throw new ServletException(e); - } - } else { - response.sendError(401); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java deleted file mode 100644 index 42ad65df01..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.domain; - -import java.io.Serializable; - -/** - * - * @author Adrian Cole - */ -public class StoredTweetStatus implements Comparable, Serializable { - - /** The serialVersionUID */ - private static final long serialVersionUID = -3257496189689220018L; - private final String service; - private final String host; - private final String container; - private final String id; - private final String from; - private final String tweet; - private final String status; - - @Override - public String toString() { - return "StoredTweetStatus [container=" + container + ", from=" + from + ", host=" + host - + ", id=" + id + ", service=" + service + ", status=" + status + ", tweet=" + tweet - + "]"; - } - - public StoredTweetStatus(String service, String host, String container, String id, String from, - String tweet, String status) { - this.service = service; - this.host = host; - this.container = container; - this.id = id; - this.from = from; - this.tweet = tweet; - this.status = status; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((container == null) ? 0 : container.hashCode()); - result = prime * result + ((from == null) ? 0 : from.hashCode()); - result = prime * result + ((host == null) ? 0 : host.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((service == null) ? 0 : service.hashCode()); - result = prime * result + ((tweet == null) ? 0 : tweet.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; - StoredTweetStatus other = (StoredTweetStatus) obj; - if (container == null) { - if (other.container != null) - return false; - } else if (!container.equals(other.container)) - return false; - if (from == null) { - if (other.from != null) - return false; - } else if (!from.equals(other.from)) - return false; - if (host == null) { - if (other.host != null) - return false; - } else if (!host.equals(other.host)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (service == null) { - if (other.service != null) - return false; - } else if (!service.equals(other.service)) - return false; - if (tweet == null) { - if (other.tweet != null) - return false; - } else if (!tweet.equals(other.tweet)) - return false; - return true; - } - - - public String getService() { - return service; - } - - public String getHost() { - return host; - } - - public String getContainer() { - return container; - } - - public String getFrom() { - return from; - } - - public String getTweet() { - return tweet; - } - - public String getStatus() { - return status; - } - - public int compareTo(StoredTweetStatus o) { - if (id == null) - return -1; - return (int) ((this == o) ? 0 : id.compareTo(o.id)); - } - - - public String getId() { - return id; - } - -} diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java deleted file mode 100644 index f831b9780f..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import javax.annotation.Resource; - -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; -import org.jclouds.util.Strings2; - -import com.google.common.base.Function; - -/** - * - * @author Adrian Cole - */ -public class KeyToStoredTweetStatus implements Function { - private final String host; - private final BlobMap map; - private final String service; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - KeyToStoredTweetStatus(BlobMap map, String service, String host, String container) { - this.host = host; - this.map = map; - this.service = service; - this.container = container; - } - - public StoredTweetStatus apply(String id) { - String status; - String from; - String tweet; - try { - long start = System.currentTimeMillis(); - Blob blob = map.get(id); - status = ((System.currentTimeMillis() - start) + "ms"); - from = blob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME); - tweet = Strings2.toString(blob.getPayload()); - } catch (Exception e) { - logger.error(e, "Error listing container %s//%s/%s", service, container, id); - status = (e.getMessage()); - tweet = ""; - from = ""; - } - return new StoredTweetStatus(service, host, container, id, from, tweet, status); - } -} diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java deleted file mode 100644 index b2e5884c55..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import java.net.URI; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Context; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; - -@Singleton -public class ServiceToStoredTweetStatuses implements Function> { - - private final Map contexts; - private final String container; - - @Inject - public ServiceToStoredTweetStatuses(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) { - this.contexts = contexts; - this.container = container; - } - - @Resource - protected Logger logger = Logger.NULL; - - public Iterable apply(String service) { - BlobStoreContext context = contexts.get(service); - String host = URI.create(context.unwrap(Context.class).getProviderMetadata().getEndpoint()).getHost(); - try { - BlobMap blobMap = context.createBlobMap(container); - Set blobs = blobMap.keySet(); - return Iterables.transform(blobs, new KeyToStoredTweetStatus(blobMap, service, host, - container)); - } catch (Exception e) { - StoredTweetStatus result = new StoredTweetStatus(service, host, container, null, null, - null, e.getMessage()); - logger.error(e, "Error listing service %s", service); - return ImmutableList.of(result); - } - - } -} diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java deleted file mode 100644 index 42ec480ae2..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.reference; - -/** - * Configuration properties and constants used in TweetStore connections. - * - * @author Adrian Cole - */ -public interface TweetStoreConstants { - static final String PROPERTY_TWEETSTORE_BLOBSTORES = "jclouds.tweetstore.blobstores"; - static final String PROPERTY_TWEETSTORE_CONTAINER = "jclouds.tweetstore.container"; - /** - * Note that this has to conform to restrictions of all blobstores. for - * example, azure doesn't support periods. - */ - static final String SENDER_NAME = "sendername"; -} diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java deleted file mode 100644 index dc8b97915f..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.reference; - -/** - * Configuration properties and constants used in Twitter connections. - * - * @author Andrew Phillips - */ -public interface TwitterConstants { - static final String PROPERTY_TWITTER_CONSUMER_KEY = "twitter.consumer.identity"; - static final String PROPERTY_TWITTER_CONSUMER_SECRET = "twitter.consumer.credential"; - static final String PROPERTY_TWITTER_ACCESSTOKEN = "twitter.access.identity"; - static final String PROPERTY_TWITTER_ACCESSTOKEN_SECRET = "twitter.access.credential"; -} diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/platform/appengine-web.xml b/demos/tweetstore/gae-tweetstore-spring/src/main/platform/appengine-web.xml deleted file mode 100644 index 32d6d68a44..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/platform/appengine-web.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - ${appengine.applicationid} - 1 - - - - diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/platform/cron.xml b/demos/tweetstore/gae-tweetstore-spring/src/main/platform/cron.xml deleted file mode 100644 index 193a5402f6..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/platform/cron.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - /stores/do - Enqueue 'store tweet' tasks for all contexts - every 10 minutes - - \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/platform/logging.properties b/demos/tweetstore/gae-tweetstore-spring/src/main/platform/logging.properties deleted file mode 100644 index 0cc0d79437..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/platform/logging.properties +++ /dev/null @@ -1,50 +0,0 @@ -# -# Licensed to jclouds, Inc. (jclouds) under one or more -# contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. jclouds 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. -# - -# A default java.util.logging configuration. -# (All App Engine logging is through java.util.logging by default). -# -# To use this configuration, copy it into your application's WEB-INF -# folder and add the following to your appengine-web.xml: -# -# -# -# -# - -# Set the default logging level for all loggers to INFO -.level = INFO - -org.jclouds.level=INFO -org.jclouds.demo.tweetstore.config.level=FINEST - -# Set the default logging level for ORM, specifically, to WARNING -DataNucleus.JDO.level=WARNING -DataNucleus.Persistence.level=WARNING -DataNucleus.Cache.level=WARNING -DataNucleus.MetaData.level=WARNING -DataNucleus.General.level=WARNING -DataNucleus.Utility.level=WARNING -DataNucleus.Transaction.level=WARNING -DataNucleus.Datastore.level=WARNING -DataNucleus.ClassLoading.level=WARNING -DataNucleus.Plugin.level=WARNING -DataNucleus.ValueGeneration.level=WARNING -DataNucleus.Enhancer.level=WARNING -DataNucleus.SchemaTool.level=WARNING diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/WEB-INF/dispatcher-servlet.xml b/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/WEB-INF/dispatcher-servlet.xml deleted file mode 100644 index b568634994..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/WEB-INF/dispatcher-servlet.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/WEB-INF/queue.xml b/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/WEB-INF/queue.xml deleted file mode 100644 index 1bc53f398d..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/WEB-INF/queue.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - twitter - - 2/m - 1 - - diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/WEB-INF/web.xml b/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 3853142f26..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - jclouds-tweetstore-spring - - - - dispatcher - org.springframework.web.servlet.DispatcherServlet - - - - - - dispatcher - /store/* - - - dispatcher - /tweets/* - - - dispatcher - /stores/* - - - dispatcher - /clear/* - - - - - - /stores/* - - - admin - - - - - index.jsp - - \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/index.jsp b/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/index.jsp deleted file mode 100644 index fd71a31164..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/index.jsp +++ /dev/null @@ -1,31 +0,0 @@ -<%-- - - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. - ---%> - - -jclouds: anyweight cloudware for java - - -

Welcome!

-

Click here to see tweets about jclouds.

-

- - diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/tweets.jsp b/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/tweets.jsp deleted file mode 100644 index 820278d4ce..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/webapp/tweets.jsp +++ /dev/null @@ -1,109 +0,0 @@ -<%-- - - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. - ---%> -<%@ page buffer="20kb"%> -<%@ taglib uri="http://displaytag.sf.net" prefix="display"%> - - -jclouds: anyweight cloudware for java - - - -

Tweets in Clouds

- - - - - - - -
-
- - - - - - - - -
-
- - diff --git a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java b/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java deleted file mode 100644 index 031bb199fc..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.util.Map; -import java.util.Properties; - -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector; -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector.Credential; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code CredentialsCollector} - * - * @author Andrew Phillips - */ -@Test(groups = "unit") -public class CredentialsCollectorTest { - private CredentialsCollector collector = new CredentialsCollector(); - - public void testEmptyProperties() { - assertTrue(collector.apply(new Properties()).isEmpty(), - "Expected returned map to be empty"); - } - - public void testNoCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("not-an-identity", - "v1", "not-a-credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - private static Properties propertiesOf(Map entries) { - Properties properties = new Properties(); - properties.putAll(entries); - return properties; - } - - public void testNonMatchingCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("non_matching.identity", "v1", - "non_matching.credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - public void testIncompleteCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("acme.identity", "v1", - "acme-2.credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - public void testCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("acme.identity", "v1", - "acme.credential", "v2", "acme-2.identity", "v3", - "acme-2.credential", "v4")); - assertEquals(collector.apply(properties), - ImmutableMap.of("acme", new Credential("v1", "v2"), - "acme-2", new Credential("v3", "v4"))); - } -} \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java b/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java deleted file mode 100644 index 1c93403650..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; -import org.testng.collections.Maps; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - -/** - * Tests behavior of {@code AddTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class AddTweetsControllerTest { - - Map createServices(String container) throws InterruptedException, - ExecutionException { - Map services = Maps.newHashMap(); - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - for (String name : new String[] { "1", "2" }) { - BlobStoreContext context = ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class); - context.getAsyncBlobStore().createContainerInLocation(null, container).get(); - Blob blob = context.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - context.getAsyncBlobStore().putBlob(container, blob).get(); - services.put(name, context); - } - return services; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - String container = "container"; - Map contexts = createServices(container); - - ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container); - AddTweetsController controller = new AddTweetsController(contexts, function); - List list = controller.apply(ImmutableSet.of("1", "2")); - assertEquals(list.size(), 2); - assertEquals(list, ImmutableList.of(new StoredTweetStatus("1", "localhost", container, "1", - "frank", "I love beans!", null), new StoredTweetStatus("2", "localhost", container, - "1", "frank", "I love beans!", null))); - - } -} diff --git a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java b/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java deleted file mode 100644 index 81f0b9f3c7..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code AddTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class ClearTweetsControllerTest { - - Map createBlobStores(String container) throws InterruptedException, ExecutionException { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - for (BlobStoreContext blobstore : contexts.values()) { - blobstore.getBlobStore().createContainerInLocation(null, container); - Blob blob = blobstore.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - blobstore.getBlobStore().putBlob(container, blob); - } - return contexts; - } - - public void testClearTweets() throws IOException, InterruptedException, ExecutionException { - String container = ClearTweetsControllerTest.class.getName() + "#container"; - Map contexts = createBlobStores(container); - - ClearTweetsController controller = new ClearTweetsController(contexts, - container); - controller.clearContainer("test1"); - controller.clearContainer("test2"); - - for (BlobStoreContext context : contexts.values()) { - assertEquals(context.getBlobStore().countBlobs(container), 0, context.toString()); - } - } -} diff --git a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java b/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java deleted file mode 100644 index 5190718e4c..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -import java.util.Map; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.testng.annotations.Test; - -import com.google.appengine.api.taskqueue.Queue; -import com.google.appengine.api.taskqueue.TaskOptions.Method; -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@link EnqueueStoresController} - * - * @author Andrew Phillips - */ -@Test(groups = "unit") -public class EnqueueStoresControllerTest { - - Map createBlobStores() { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - return contexts; - } - - public void testEnqueueStores() { - Map stores = createBlobStores(); - Queue taskQueue = createMock(Queue.class); - EnqueueStoresController function = new EnqueueStoresController(stores, taskQueue); - - expect(taskQueue.add(withUrl("/store/do").header("context", "test1").method(Method.GET))).andReturn(null); - expect(taskQueue.add(withUrl("/store/do").header("context", "test2").method(Method.GET))).andReturn(null); - replay(taskQueue); - - function.enqueueStoreTweetTasks(); - - verify(taskQueue); - } -} diff --git a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java b/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java deleted file mode 100644 index 084b18a8c5..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.util.Strings2; -import org.testng.annotations.Test; - -import twitter4j.Status; -import twitter4j.Twitter; -import twitter4j.User; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code StoreTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class StoreTweetsControllerTest { - - Twitter createTwitter() { - return createMock(Twitter.class); - } - - Map createBlobStores() throws InterruptedException, ExecutionException { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - for (BlobStoreContext blobstore : contexts.values()) { - blobstore.getAsyncBlobStore().createContainerInLocation(null, "favo").get(); - } - return contexts; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - Map stores = createBlobStores(); - StoreTweetsController function = new StoreTweetsController(stores, "favo", createTwitter()); - - User frank = createMock(User.class); - expect(frank.getScreenName()).andReturn("frank").atLeastOnce(); - - Status frankStatus = createMock(Status.class); - expect(frankStatus.getId()).andReturn(1l).atLeastOnce(); - expect(frankStatus.getUser()).andReturn(frank).atLeastOnce(); - expect(frankStatus.getText()).andReturn("I love beans!").atLeastOnce(); - - User jimmy = createMock(User.class); - expect(jimmy.getScreenName()).andReturn("jimmy").atLeastOnce(); - - Status jimmyStatus = createMock(Status.class); - expect(jimmyStatus.getId()).andReturn(2l).atLeastOnce(); - expect(jimmyStatus.getUser()).andReturn(jimmy).atLeastOnce(); - expect(jimmyStatus.getText()).andReturn("cloud is king").atLeastOnce(); - - replay(frank); - replay(frankStatus); - replay(jimmy); - replay(jimmyStatus); - - function.addMyTweets("test1", ImmutableList.of(frankStatus, jimmyStatus)); - function.addMyTweets("test2", ImmutableList.of(frankStatus, jimmyStatus)); - - verify(frank); - verify(frankStatus); - verify(jimmy); - verify(jimmyStatus); - - for (Entry entry : stores.entrySet()) { - BlobMap map = entry.getValue().createBlobMap("favo"); - Blob frankBlob = map.get("1"); - assertEquals(frankBlob.getMetadata().getName(), "1"); - assertEquals(frankBlob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME), "frank"); - assertEquals(frankBlob.getMetadata().getContentMetadata().getContentType(), "text/plain"); - assertEquals(Strings2.toString(frankBlob.getPayload()), "I love beans!"); - - Blob jimmyBlob = map.get("2"); - assertEquals(jimmyBlob.getMetadata().getName(), "2"); - assertEquals(jimmyBlob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME), "jimmy"); - assertEquals(jimmyBlob.getMetadata().getContentMetadata().getContentType(), "text/plain"); - assertEquals(Strings2.toString(jimmyBlob.getPayload()), "cloud is king"); - } - - } -} diff --git a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java b/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java deleted file mode 100644 index af74b423d5..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; - -/** - * Tests behavior of {@code KeyToStoredTweetStatus} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class KeyToStoredTweetStatusTest { - - BlobMap createMap() throws InterruptedException, ExecutionException { - BlobStoreContext context = - ContextBuilder.newBuilder(TransientApiMetadata.builder().build()).build(BlobStoreContext.class); - context.getBlobStore().createContainerInLocation(null, "test1"); - return context.createBlobMap("test1"); - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - BlobMap map = createMap(); - Blob blob = map.blobBuilder().name("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - map.put("1", blob); - String host = "localhost"; - String service = "stub"; - String container = "tweetstore"; - - KeyToStoredTweetStatus function = new KeyToStoredTweetStatus(map, service, host, container); - StoredTweetStatus result = function.apply("1"); - - StoredTweetStatus expected = new StoredTweetStatus(service, host, container, "1", "frank", - "I love beans!", null); - - assertEquals(result, expected); - - } -} diff --git a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java b/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java deleted file mode 100644 index 5fec52711e..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; -import org.testng.collections.Maps; - -import com.google.common.collect.Iterables; - -/** - * Tests behavior of {@code ServiceToStoredTweetStatuses} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class ServiceToStoredTweetStatusesTest { - - Map createServices(String container) throws InterruptedException, - ExecutionException { - Map services = Maps.newHashMap(); - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - for (String name : new String[] { "1", "2" }) { - BlobStoreContext context = ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class); - context.getAsyncBlobStore().createContainerInLocation(null, container).get(); - Blob blob = context.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - context.getAsyncBlobStore().putBlob(container, blob).get(); - services.put(name, context); - } - return services; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - String container = "container"; - Map contexts = createServices(container); - - ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container); - - assertEquals(Iterables.getLast(function.apply("1")), new StoredTweetStatus("1", "localhost", - container, "1", "frank", "I love beans!", null)); - - assertEquals(Iterables.getLast(function.apply("2")), new StoredTweetStatus("2", "localhost", - container, "1", "frank", "I love beans!", null)); - - } -} diff --git a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java b/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java deleted file mode 100644 index 63223607ac..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.io.Closeables.closeQuietly; -import static java.lang.String.format; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -import com.google.appengine.tools.KickStart; -import com.google.appengine.tools.info.SdkInfo; - -/** - * Basic functionality to start a local google app engine instance. - * - * @author Adrian Cole - */ -public class GoogleDevServer { - - Thread server; - - public void writePropertiesAndStartServer(final String address, - final String port, final String warfile, Properties props) - throws IOException, InterruptedException { - String filename = String.format( - "%1$s/WEB-INF/jclouds.properties", warfile); - System.err.println("file: " + filename); - storeProperties(filename, props); - assert new File(filename).exists(); - this.server = new Thread(new Runnable() { - public void run() { - String sdkRoot = checkNotNull(System.getProperty(SdkInfo.SDK_ROOT_PROPERTY), SdkInfo.SDK_ROOT_PROPERTY); - KickStart.main(new String[] { - KickStarter.systemProperty("java.util.logging.config.file", - format("%s/WEB-INF/logging.properties", warfile)), - KickStarter.systemProperty(SdkInfo.SDK_ROOT_PROPERTY, sdkRoot), - "com.google.appengine.tools.development.DevAppServerMain", - "--disable_update_check", - format("--sdk_root=%s", sdkRoot), - "-a", address, "-p", port, warfile }); - } - }); - server.start(); - TimeUnit.SECONDS.sleep(30); - } - - private static void storeProperties(String filename, Properties props) throws IOException { - FileOutputStream targetFile = new FileOutputStream(filename); - try { - props.store(targetFile, "test"); - } finally { - closeQuietly(targetFile); - } - } - - public void stop() throws Exception { - // KickStart.main opens a process and calls process.waitFor(), which is interruptable - server.interrupt(); - } - - private static class KickStarter { - private static String systemProperty(String key, String value) { - return format("--jvm_flag=-D%s=%s", key, value); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java b/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java deleted file mode 100644 index 7ed1008bab..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java +++ /dev/null @@ -1,234 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -import org.jclouds.Context; -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.config.SpringServletConfig; -import org.jclouds.demo.tweetstore.controller.StoreTweetsController; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.util.Strings2; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - -import twitter4j.ResponseList; -import twitter4j.Status; -import twitter4j.Twitter; -import twitter4j.TwitterException; -import twitter4j.TwitterFactory; -import twitter4j.conf.Configuration; -import twitter4j.conf.ConfigurationBuilder; - -import com.google.common.base.Joiner; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.inject.Module; - -/** - * Starts up the Google App Engine for Java Development environment and deploys an application which - * tests accesses twitter and blobstores. - * - * @author Adrian Cole - */ -@Test(groups = "live", singleThreaded = true) -public class TweetStoreLiveTest { - - GoogleDevServer server; - private URL url; - private Map contexts; - private String container; - - private static final Iterable blobstores = - Splitter.on(',').split(System.getProperty(PROPERTY_TWEETSTORE_BLOBSTORES, - "cloudfiles-us,aws-s3,azureblob")); - private static final Properties props = new Properties(); - - @BeforeTest - void clearAndCreateContainers() throws InterruptedException, ExecutionException, TimeoutException, IOException, - TwitterException { - container = getRequiredSystemProperty(PROPERTY_TWEETSTORE_CONTAINER); - - props.setProperty(PROPERTY_TWEETSTORE_CONTAINER, container); - props.setProperty(SpringServletConfig.PROPERTY_BLOBSTORE_CONTEXTS, Joiner.on(',').join(blobstores)); - - // put all identity/credential pairs into the client - addCredentialsForBlobStores(props); - - // example of an ad-hoc client configuration - addConfigurationForTwitter(props); - - // for testing, capture logs. - final Set wiring = ImmutableSet. of(new Log4JLoggingModule()); - this.contexts = Maps.newConcurrentMap(); - - for (String provider : blobstores) { - contexts.put(provider, ContextBuilder.newBuilder(provider) - .modules(wiring).overrides(props).build(BlobStoreContext.class)); - } - - Configuration conf = new ConfigurationBuilder() - .setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY)) - .setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET)) - .setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN)) - .setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET)) - .build(); - Twitter client = new TwitterFactory(conf).getInstance(); - StoreTweetsController controller = new StoreTweetsController(contexts, container, client); - - ResponseList statuses = client.getMentions(); - - boolean deleted = false; - for (BlobStoreContext context : contexts.values()) { - if (context.getBlobStore().containerExists(container)) { - System.err.printf("deleting container %s at %s%n", container, - context.unwrap(Context.class).getProviderMetadata().getEndpoint()); - context.getBlobStore().deleteContainer(container); - deleted = true; - } - } - if (deleted) { - System.err.println("sleeping 60 seconds to allow containers to clear"); - Thread.sleep(60000); - } - for (BlobStoreContext context : contexts.values()) { - System.err.printf("creating container %s at %s%n", container, - context.unwrap(Context.class).getProviderMetadata().getEndpoint()); - context.getBlobStore().createContainerInLocation(null, container); - } - if (deleted) { - System.err.println("sleeping 5 seconds to allow containers to create"); - Thread.sleep(5000); - } - - for (Entry entry : contexts.entrySet()) { - System.err.printf("filling container %s at %s%n", container, entry.getKey()); - controller.addMyTweets(entry.getKey(), statuses); - } - } - - private static String getRequiredSystemProperty(String key) { - return checkNotNull(System.getProperty(key), key); - } - - private void addConfigurationForTwitter(Properties props) { - props.setProperty(PROPERTY_TWITTER_CONSUMER_KEY, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_KEY)); - props.setProperty(PROPERTY_TWITTER_CONSUMER_SECRET, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_SECRET)); - props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN)); - props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN_SECRET)); - } - - private void addCredentialsForBlobStores(Properties props) { - for (String provider : blobstores) { - props.setProperty(provider + ".identity", - getRequiredSystemProperty("test." + provider + ".identity")); - props.setProperty(provider + ".credential", - getRequiredSystemProperty("test." + provider + ".credential")); - } - } - - @BeforeTest - @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://%s:%s", address, port)); - server = new GoogleDevServer(); - server.writePropertiesAndStartServer(address, port, warfile, props); - } - - @Test - public void shouldPass() throws InterruptedException, IOException { - InputStream i = url.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Welcome") >= 0 : string; - } - - @Test(dependsOnMethods = "shouldPass", expectedExceptions = IOException.class) - public void shouldFail() throws InterruptedException, IOException { - new URL(url, "/store/do").openStream(); - } - - @Test(dependsOnMethods = "shouldFail") - public void testPrimeContainers() throws IOException, InterruptedException { - URL gurl = new URL(url, "/store/do"); - // WATCH THIS, you need to add a context each time - for (String context : blobstores) { - System.out.println("storing at context: " + context); - HttpURLConnection connection = (HttpURLConnection) gurl.openConnection(); - connection.addRequestProperty("X-AppEngine-QueueName", "twitter"); - connection.addRequestProperty("context", context); - InputStream i = connection.getInputStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Done!") >= 0 : string; - connection.disconnect(); - } - - System.err.println("sleeping 20 seconds to allow for eventual consistency delay"); - Thread.sleep(20000); - for (BlobStoreContext context : contexts.values()) { - assert context.createInputStreamMap(container).size() > 0 : context.unwrap(Context.class).getProviderMetadata().getEndpoint(); - } - } - - @Test(invocationCount = 5, dependsOnMethods = "testPrimeContainers") - public void testSerial() throws InterruptedException, IOException { - URL gurl = new URL(url, "/tweets/get"); - InputStream i = gurl.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Tweets in Clouds") >= 0 : string; - } - - @Test(invocationCount = 10, dependsOnMethods = "testPrimeContainers", threadPoolSize = 3) - public void testParallel() throws InterruptedException, IOException { - URL gurl = new URL(url, "/tweets/get"); - InputStream i = gurl.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Tweets in Clouds") >= 0 : string; - } - - @AfterTest - public void stopDevAppServer() throws Exception { - server.stop(); - } -} diff --git a/demos/tweetstore/gae-tweetstore-spring/src/test/resources/log4j.xml b/demos/tweetstore/gae-tweetstore-spring/src/test/resources/log4j.xml deleted file mode 100644 index 2e5d01fb9e..0000000000 --- a/demos/tweetstore/gae-tweetstore-spring/src/test/resources/log4j.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/demos/tweetstore/gae-tweetstore/README.txt b/demos/tweetstore/gae-tweetstore/README.txt deleted file mode 100644 index d8dddf3a2d..0000000000 --- a/demos/tweetstore/gae-tweetstore/README.txt +++ /dev/null @@ -1,56 +0,0 @@ -==== - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. -==== - -A guide to generating Twitter consumer keys and access tokens is at http://tinyurl.com/2fhebgb - -This sample uses the Google App Engine for Java SDK located at -http://code.google.com/p/googleappengine/downloads/list - -Please unzip the above file and modify your maven settings.xml like below before -attempting to run 'mvn -Plive install' - - - appengine - - true - - - /path/to/appengine-java-sdk-1.4.2 - yourappid - - - - - keys - - true - - - YOUR_ACCESS_KEY_ID - YOUR_SECRET_KEY - YOUR_USER - YOUR_HEX_KEY - YOUR_ACCOUNT - YOUR_BASE64_ENCODED_KEY - YOUR_TWITTER_CONSUMER_KEY - YOUR_TWITTER_CONSUMER_SECRET - YOUR_TWITTER_ACCESSTOKEN - YOUR_TWITTER_ACCESSTOKEN_SECRET - - \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore/pom.xml b/demos/tweetstore/gae-tweetstore/pom.xml deleted file mode 100644 index 19e6865a4c..0000000000 --- a/demos/tweetstore/gae-tweetstore/pom.xml +++ /dev/null @@ -1,138 +0,0 @@ - - - - 4.0.0 - - org.jclouds - jclouds-demos-tweetstore-project - 1.6.0-SNAPSHOT - - jclouds-demo-gae-tweetstore - war - jclouds TweetStore for Google App Engine - jclouds TweetStore for Google App Engine using Guice for Dependency Injection - - - - jclouds-tweetstore - 1.6.1 - localhost - 8088 - jclouds-gae-tweetstore - - - - - org.jclouds.driver - jclouds-gae - ${project.version} - - - com.google.inject.extensions - guice-servlet - 3.0 - - - - - com.google.appengine - appengine-api-1.0-sdk - ${appengine.sdk.version} - - - com.google.appengine - appengine-tools-sdk - ${appengine.sdk.version} - test - - - - - - live - - - - maven-surefire-plugin - - - integration - integration-test - - test - - - - ${test.twitter.gae-tweetstore.consumer.identity} - ${test.twitter.gae-tweetstore.consumer.credential} - ${test.twitter.gae-tweetstore.access.identity} - ${test.twitter.gae-tweetstore.access.credential} - ${test.azureblob.identity} - ${test.azureblob.credential} - ${test.cloudfiles-us.identity} - ${test.cloudfiles-us.credential} - ${test.aws-s3.identity} - ${test.aws-s3.credential} - ${appengine.sdk.root} - ${test.cloudonestorage.identity} - ${test.cloudonestorage.credential} - ${test.ninefold-storage.identity} - ${test.ninefold-storage.credential} - ${devappserver.address} - ${devappserver.port} - ${jclouds.tweetstore.blobstores} - test.${jclouds.tweetstore.container} - ${project.build.directory}/${project.artifactId} - - - - - - - - - - - deploy - - - gae-tweetstore - - - - - net.kindleit - maven-gae-plugin - 0.9.2 - - google-appengine - ${appengine.sdk.root} - - - - - - - diff --git a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java b/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java deleted file mode 100644 index 4be8fb5d64..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java +++ /dev/null @@ -1,165 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Predicates.in; -import static com.google.common.collect.ImmutableSet.copyOf; -import static com.google.common.collect.Sets.filter; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import javax.servlet.ServletContextEvent; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector; -import org.jclouds.demo.tweetstore.controller.AddTweetsController; -import org.jclouds.demo.tweetstore.controller.ClearTweetsController; -import org.jclouds.demo.tweetstore.controller.EnqueueStoresController; -import org.jclouds.demo.tweetstore.controller.StoreTweetsController; -import org.jclouds.gae.config.GoogleAppEngineConfigurationModule; - -import twitter4j.Twitter; -import twitter4j.TwitterFactory; -import twitter4j.conf.Configuration; -import twitter4j.conf.ConfigurationBuilder; - -import com.google.appengine.api.taskqueue.Queue; -import com.google.appengine.api.taskqueue.QueueFactory; -import com.google.appengine.repackaged.com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -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.name.Names; -import com.google.inject.servlet.GuiceServletContextListener; -import com.google.inject.servlet.ServletModule; - -/** - * Setup Logging and create Injector for use in testing S3. - * - * @author Adrian Cole - */ -public class GuiceServletConfig extends GuiceServletContextListener { - public static final String PROPERTY_BLOBSTORE_CONTEXTS = "blobstore.contexts"; - - private Map providerTypeToBlobStoreMap; - private Twitter twitterClient; - private String container; - private Queue queue; - - @Override - public void contextInitialized(ServletContextEvent servletContextEvent) { - Properties props = loadJCloudsProperties(servletContextEvent); - - Module googleModule = new GoogleAppEngineConfigurationModule(); - Set modules = ImmutableSet. of(googleModule); - // shared across all blobstores and used to retrieve tweets - try { - Configuration twitterConf = new ConfigurationBuilder() - .setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY)) - .setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET)) - .setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN)) - .setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET)) - .build(); - twitterClient = new TwitterFactory(twitterConf).getInstance(); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("properties for twitter not configured properly in " + props.toString(), e); - } - // common namespace for storing tweets - container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER), PROPERTY_TWEETSTORE_CONTAINER); - - // instantiate and store references to all blobstores by provider name - providerTypeToBlobStoreMap = Maps.newHashMap(); - for (String hint : getBlobstoreContexts(props)) { - providerTypeToBlobStoreMap.put(hint, ContextBuilder.newBuilder(hint) - .modules(modules).overrides(props).build(BlobStoreContext.class)); - } - - // get a queue for submitting store tweet requests - queue = QueueFactory.getQueue("twitter"); - - super.contextInitialized(servletContextEvent); - } - - private static Iterable getBlobstoreContexts(Properties props) { - Set contexts = new CredentialsCollector().apply(props).keySet(); - String explicitContexts = props.getProperty(PROPERTY_TWEETSTORE_BLOBSTORES); - if (explicitContexts != null) { - contexts = filter(contexts, in(copyOf(Splitter.on(',').split(explicitContexts)))); - } - checkState(!contexts.isEmpty(), "no credentials available for any requested context"); - return contexts; - } - - private Properties loadJCloudsProperties(ServletContextEvent servletContextEvent) { - InputStream input = servletContextEvent.getServletContext().getResourceAsStream("/WEB-INF/jclouds.properties"); - Properties props = new Properties(); - try { - props.load(input); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - Closeables.closeQuietly(input); - } - return props; - } - - @Override - protected Injector getInjector() { - return Guice.createInjector(new ServletModule() { - @Override - protected void configureServlets() { - bind(new TypeLiteral>() { - }).toInstance(providerTypeToBlobStoreMap); - bind(Twitter.class).toInstance(twitterClient); - bind(Queue.class).toInstance(queue); - bindConstant().annotatedWith(Names.named(PROPERTY_TWEETSTORE_CONTAINER)).to(container); - serve("/store/*").with(StoreTweetsController.class); - serve("/tweets/*").with(AddTweetsController.class); - serve("/stores/*").with(EnqueueStoresController.class); - serve("/clear/*").with(ClearTweetsController.class); - } - }); - } - - @Override - public void contextDestroyed(ServletContextEvent servletContextEvent) { - for (BlobStoreContext context : providerTypeToBlobStoreMap.values()) { - context.close(); - } - queue.purge(); - super.contextDestroyed(servletContextEvent); - } -} \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java b/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java deleted file mode 100644 index ce3943376e..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java +++ /dev/null @@ -1,153 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Predicates.notNull; -import static com.google.common.collect.Collections2.filter; -import static com.google.common.collect.Collections2.transform; -import static com.google.common.collect.ImmutableSet.copyOf; -import static com.google.common.collect.Maps.filterValues; -import static org.jclouds.util.Maps2.fromKeys; - -import java.util.Collection; -import java.util.Map; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector.Credential; - -import com.google.common.annotations.GwtIncompatible; -import com.google.common.base.Function; -import com.google.common.base.Predicate; - -/** - * Reads provider credentials from a {@link Properties} bag. - * - * @author Andrew Phillips - * - */ -public class CredentialsCollector implements Function> { - private static final String IDENTITY_PROPERTY_SUFFIX = ".identity"; - private static final String CREDENTIAL_PROPERTY_SUFFIX = ".credential"; - - // using the identity for provider name extraction - private static final Pattern IDENTITY_PROPERTY_PATTERN = - Pattern.compile("([a-zA-Z0-9-]+)" + Pattern.quote(IDENTITY_PROPERTY_SUFFIX)); - - @Override - public Map apply(final Properties properties) { - Collection providerNames = transform( - filter(properties.stringPropertyNames(), MatchesPattern.matches(IDENTITY_PROPERTY_PATTERN)), - new Function() { - @Override - public String apply(String input) { - Matcher matcher = IDENTITY_PROPERTY_PATTERN.matcher(input); - // as a side-effect, sets the matching group! - checkState(matcher.matches(), "'%s' should match '%s'", input, IDENTITY_PROPERTY_PATTERN); - return matcher.group(1); - } - }); - /* - * Providers without a credential property result in null values, which are - * removed from the returned map. - */ - return filterValues(fromKeys(copyOf(providerNames), new Function() { - @Override - public Credential apply(String providerName) { - String identity = properties.getProperty(providerName + IDENTITY_PROPERTY_SUFFIX); - String credential = properties.getProperty(providerName + CREDENTIAL_PROPERTY_SUFFIX); - return (((identity != null) && (credential != null)) - ? new Credential(identity, credential) - : null); - } - }), notNull()); - } - - public static class Credential { - private final String identity; - private final String credential; - - public Credential(String identity, String credential) { - this.identity = checkNotNull(identity, "identity"); - this.credential = checkNotNull(credential, "credential"); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((credential == null) ? 0 : credential.hashCode()); - result = prime * result - + ((identity == null) ? 0 : identity.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; - Credential other = (Credential) obj; - if (credential == null) { - if (other.credential != null) - return false; - } else if (!credential.equals(other.credential)) - return false; - if (identity == null) { - if (other.identity != null) - return false; - } else if (!identity.equals(other.identity)) - return false; - return true; - } - - public String getIdentity() { - return identity; - } - - public String getCredential() { - return credential; - } - } - - @GwtIncompatible(value = "java.util.regex.Pattern") - private static class MatchesPattern implements Predicate { - private final Pattern pattern; - - private MatchesPattern(Pattern pattern) { - this.pattern = pattern; - } - - @Override - public boolean apply(String input) { - return pattern.matcher(input).matches(); - } - - private static MatchesPattern matches(Pattern pattern) { - return new MatchesPattern(pattern); - } - } -} diff --git a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java b/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java deleted file mode 100644 index b681cfb27d..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -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.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; -import org.jclouds.logging.Logger; - -import com.google.appengine.repackaged.com.google.common.collect.Lists; -import com.google.common.base.Function; -import com.google.common.collect.Iterables; - -/** - * Shows an example of how to use @{link BlobStoreContext} injected with Guice. - * - * @author Adrian Cole - */ -@Singleton -public class AddTweetsController extends HttpServlet implements - Function, List> { - - /** The serialVersionUID */ - private static final long serialVersionUID = 3888348023150822683L; - private final Map contexts; - private final ServiceToStoredTweetStatuses blobStoreContextToContainerResult; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - AddTweetsController(Map contexts, - ServiceToStoredTweetStatuses blobStoreContextToContainerResult) { - this.contexts = contexts; - this.blobStoreContextToContainerResult = blobStoreContextToContainerResult; - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - try { - addMyTweetsToRequest(request); - RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/tweets.jsp"); - dispatcher.forward(request, response); - } catch (Exception e) { - logger.error(e, "Error listing containers"); - throw new ServletException(e); - } - } - - void addMyTweetsToRequest(HttpServletRequest request) throws InterruptedException, - ExecutionException, TimeoutException { - request.setAttribute("tweets", apply(contexts.keySet())); - } - - public List apply(Set in) { - List statuses = Lists.newArrayList(); - for (Iterable list : Iterables.transform(in, - blobStoreContextToContainerResult)) { - Iterables.addAll(statuses, list); - } - return statuses; - } -} diff --git a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java b/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java deleted file mode 100644 index e08cfbc19e..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Strings.nullToEmpty; - -import java.io.IOException; -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; - -import com.google.common.annotations.VisibleForTesting; - -/** - * Grab tweets related to me and store them into blobstores - * - * @author Adrian Cole - */ -@Singleton -public class ClearTweetsController extends HttpServlet { - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Map contexts; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - @VisibleForTesting - public ClearTweetsController(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) { - this.container = container; - this.contexts = contexts; - } - - @VisibleForTesting - public void clearContainer(String contextName) { - BlobStoreContext context = checkNotNull(contexts.get(contextName), - "no context for %s in %s", contextName, contexts.keySet()); - try { - context.getBlobStore().clearContainer(container); - } catch (Exception e) { - logger.error(e, "Error clearing tweets in %s/%s", container, context); - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (nullToEmpty(request.getHeader("X-Originator")).equals("admin")) { - try { - String contextName = checkNotNull(request.getHeader("context"), "missing header context"); - logger.info("clearing tweets in %s/%s", container, contextName); - clearContainer(contextName); - logger.debug("done clearing tweets"); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error clearing tweets"); - throw new ServletException(e); - } - } else { - response.sendError(401); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java b/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java deleted file mode 100644 index 94568e4dec..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl; -import static com.google.appengine.repackaged.com.google.common.base.Strings.nullToEmpty; - -import java.io.IOException; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.logging.Logger; - -import com.google.appengine.api.taskqueue.Queue; -import com.google.appengine.api.taskqueue.TaskOptions.Method; -import com.google.common.annotations.VisibleForTesting; - -/** - * Adds tasks to retrieve and store tweets in all registered contexts to an async - * task queue. - * - * @author Andrew Phillips - * @see StoreTweetsController - */ -@Singleton -public class EnqueueStoresController extends HttpServlet { - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Set contextNames; - private final Queue taskQueue; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - public EnqueueStoresController(Map contexts, - Queue taskQueue) { - contextNames = contexts.keySet(); - this.taskQueue = taskQueue; - } - - @VisibleForTesting - void enqueueStoreTweetTasks() { - for (String contextName : contextNames) { - logger.debug("enqueuing task to store tweets in blobstore '%s'", contextName); - taskQueue.add(withUrl("/store/do").header("context", contextName).method(Method.GET)); - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (!nullToEmpty(request.getHeader("X-AppEngine-Cron")).equals("true")) { - response.sendError(401); - } - - try { - enqueueStoreTweetTasks(); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error storing tweets"); - throw new ServletException(e); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java b/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java deleted file mode 100644 index ae00c69d20..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.io.IOException; -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; -import org.jclouds.rest.AuthorizationException; - -import twitter4j.Status; -import twitter4j.Twitter; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; - -/** - * Grab tweets related to me and store them into blobstores - * - * @author Adrian Cole - */ -@Singleton -public class StoreTweetsController extends HttpServlet { - - private static final class StatusToBlob implements Function { - private final BlobMap map; - - private StatusToBlob(BlobMap map) { - this.map = map; - } - - public Blob apply(Status from) { - Blob to = map.blobBuilder().name(from.getId() + "").build(); - to.setPayload(from.getText()); - to.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); - to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, from.getUser().getScreenName()); - return to; - } - } - - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Map contexts; - private final Twitter client; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - @VisibleForTesting - public StoreTweetsController(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container, Twitter client) { - this.container = container; - this.contexts = contexts; - this.client = client; - } - - @VisibleForTesting - public void addMyTweets(String contextName, Iterable responseList) { - BlobStoreContext context = checkNotNull(contexts.get(contextName), "no context for " + contextName + " in " - + contexts.keySet()); - BlobMap map = context.createBlobMap(container); - for (Status status : responseList) { - Blob blob = null; - try { - blob = new StatusToBlob(map).apply(status); - map.put(status.getId() + "", blob); - } catch (AuthorizationException e) { - throw e; - } catch (Exception e) { - logger.error(e, "Error storing tweet %s (blob[%s]) on map %s/%s", status.getId(), blob, context, container); - } - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (request.getHeader("X-AppEngine-QueueName") != null - && request.getHeader("X-AppEngine-QueueName").equals("twitter")) { - try { - String contextName = checkNotNull(request.getHeader("context"), "missing header context"); - logger.info("retrieving tweets"); - addMyTweets(contextName, client.getMentions()); - logger.debug("done storing tweets"); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error storing tweets"); - throw new ServletException(e); - } - } else { - response.sendError(401); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java b/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java deleted file mode 100644 index 42ad65df01..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.domain; - -import java.io.Serializable; - -/** - * - * @author Adrian Cole - */ -public class StoredTweetStatus implements Comparable, Serializable { - - /** The serialVersionUID */ - private static final long serialVersionUID = -3257496189689220018L; - private final String service; - private final String host; - private final String container; - private final String id; - private final String from; - private final String tweet; - private final String status; - - @Override - public String toString() { - return "StoredTweetStatus [container=" + container + ", from=" + from + ", host=" + host - + ", id=" + id + ", service=" + service + ", status=" + status + ", tweet=" + tweet - + "]"; - } - - public StoredTweetStatus(String service, String host, String container, String id, String from, - String tweet, String status) { - this.service = service; - this.host = host; - this.container = container; - this.id = id; - this.from = from; - this.tweet = tweet; - this.status = status; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((container == null) ? 0 : container.hashCode()); - result = prime * result + ((from == null) ? 0 : from.hashCode()); - result = prime * result + ((host == null) ? 0 : host.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((service == null) ? 0 : service.hashCode()); - result = prime * result + ((tweet == null) ? 0 : tweet.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; - StoredTweetStatus other = (StoredTweetStatus) obj; - if (container == null) { - if (other.container != null) - return false; - } else if (!container.equals(other.container)) - return false; - if (from == null) { - if (other.from != null) - return false; - } else if (!from.equals(other.from)) - return false; - if (host == null) { - if (other.host != null) - return false; - } else if (!host.equals(other.host)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (service == null) { - if (other.service != null) - return false; - } else if (!service.equals(other.service)) - return false; - if (tweet == null) { - if (other.tweet != null) - return false; - } else if (!tweet.equals(other.tweet)) - return false; - return true; - } - - - public String getService() { - return service; - } - - public String getHost() { - return host; - } - - public String getContainer() { - return container; - } - - public String getFrom() { - return from; - } - - public String getTweet() { - return tweet; - } - - public String getStatus() { - return status; - } - - public int compareTo(StoredTweetStatus o) { - if (id == null) - return -1; - return (int) ((this == o) ? 0 : id.compareTo(o.id)); - } - - - public String getId() { - return id; - } - -} diff --git a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java b/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java deleted file mode 100644 index f831b9780f..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import javax.annotation.Resource; - -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; -import org.jclouds.util.Strings2; - -import com.google.common.base.Function; - -/** - * - * @author Adrian Cole - */ -public class KeyToStoredTweetStatus implements Function { - private final String host; - private final BlobMap map; - private final String service; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - KeyToStoredTweetStatus(BlobMap map, String service, String host, String container) { - this.host = host; - this.map = map; - this.service = service; - this.container = container; - } - - public StoredTweetStatus apply(String id) { - String status; - String from; - String tweet; - try { - long start = System.currentTimeMillis(); - Blob blob = map.get(id); - status = ((System.currentTimeMillis() - start) + "ms"); - from = blob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME); - tweet = Strings2.toString(blob.getPayload()); - } catch (Exception e) { - logger.error(e, "Error listing container %s//%s/%s", service, container, id); - status = (e.getMessage()); - tweet = ""; - from = ""; - } - return new StoredTweetStatus(service, host, container, id, from, tweet, status); - } -} diff --git a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java b/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java deleted file mode 100644 index d0b0475ef5..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import java.net.URI; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Context; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; - -@Singleton -public class ServiceToStoredTweetStatuses implements Function> { - - private final Map contexts; - private final String container; - - @Inject - public ServiceToStoredTweetStatuses(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) { - this.contexts = contexts; - this.container = container; - } - - @Resource - protected Logger logger = Logger.NULL; - - public Iterable apply(String service) { - BlobStoreContext context = contexts.get(service); - String host = URI.create(context.unwrap(Context.class).getProviderMetadata() - .getEndpoint()).getHost(); - try { - BlobMap blobMap = context.createBlobMap(container); - Set blobs = blobMap.keySet(); - return Iterables.transform(blobs, new KeyToStoredTweetStatus(blobMap, service, host, - container)); - } catch (Exception e) { - StoredTweetStatus result = new StoredTweetStatus(service, host, container, null, null, - null, e.getMessage()); - logger.error(e, "Error listing service %s", service); - return ImmutableList.of(result); - } - - } -} diff --git a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java b/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java deleted file mode 100644 index 562044e2cd..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.reference; - -/** - * Configuration properties and constants used in TweetStore connections. - * - * @author Adrian Cole - */ -public interface TweetStoreConstants { - static final String PROPERTY_TWEETSTORE_BLOBSTORES = "jclouds.tweetstore.blobstores"; - static final String PROPERTY_TWEETSTORE_CONTAINER = "jclouds.tweetstore.container"; - /** - * Note that this has to conform to restrictions of all blobstores. for example, azure doesn't - * support periods. - */ - static final String SENDER_NAME = "sendername"; -} diff --git a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java b/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java deleted file mode 100644 index dc8b97915f..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.reference; - -/** - * Configuration properties and constants used in Twitter connections. - * - * @author Andrew Phillips - */ -public interface TwitterConstants { - static final String PROPERTY_TWITTER_CONSUMER_KEY = "twitter.consumer.identity"; - static final String PROPERTY_TWITTER_CONSUMER_SECRET = "twitter.consumer.credential"; - static final String PROPERTY_TWITTER_ACCESSTOKEN = "twitter.access.identity"; - static final String PROPERTY_TWITTER_ACCESSTOKEN_SECRET = "twitter.access.credential"; -} diff --git a/demos/tweetstore/gae-tweetstore/src/main/platform/appengine-web.xml b/demos/tweetstore/gae-tweetstore/src/main/platform/appengine-web.xml deleted file mode 100644 index 32d6d68a44..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/platform/appengine-web.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - ${appengine.applicationid} - 1 - - - - diff --git a/demos/tweetstore/gae-tweetstore/src/main/platform/cron.xml b/demos/tweetstore/gae-tweetstore/src/main/platform/cron.xml deleted file mode 100644 index 193a5402f6..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/platform/cron.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - /stores/do - Enqueue 'store tweet' tasks for all contexts - every 10 minutes - - \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore/src/main/platform/logging.properties b/demos/tweetstore/gae-tweetstore/src/main/platform/logging.properties deleted file mode 100644 index 122734b647..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/platform/logging.properties +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed to jclouds, Inc. (jclouds) under one or more -# contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. jclouds 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. -# - -# Set the default logging level for all loggers to WARNING -.level = INFO - -# Set the default logging level for ORM, specifically, to WARNING -org.jclouds.level=INFO -DataNucleus.JDO.level=WARNING -DataNucleus.Persistence.level=WARNING -DataNucleus.Cache.level=WARNING -DataNucleus.MetaData.level=WARNING -DataNucleus.General.level=WARNING -DataNucleus.Utility.level=WARNING -DataNucleus.Transaction.level=WARNING -DataNucleus.Datastore.level=WARNING -DataNucleus.ClassLoading.level=WARNING -DataNucleus.Plugin.level=WARNING -DataNucleus.ValueGeneration.level=WARNING -DataNucleus.Enhancer.level=WARNING -DataNucleus.SchemaTool.level=WARNING diff --git a/demos/tweetstore/gae-tweetstore/src/main/webapp/WEB-INF/queue.xml b/demos/tweetstore/gae-tweetstore/src/main/webapp/WEB-INF/queue.xml deleted file mode 100644 index 1bc53f398d..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/webapp/WEB-INF/queue.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - twitter - - 2/m - 1 - - diff --git a/demos/tweetstore/gae-tweetstore/src/main/webapp/WEB-INF/web.xml b/demos/tweetstore/gae-tweetstore/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index d5b17d7512..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - jclouds-tweetstore - - - - guiceFilter - com.google.inject.servlet.GuiceFilter - - - - guiceFilter - /* - - - - org.jclouds.demo.tweetstore.config.GuiceServletConfig - - - - - - - /stores/* - - - admin - - - - - index.jsp - - - \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore/src/main/webapp/index.jsp b/demos/tweetstore/gae-tweetstore/src/main/webapp/index.jsp deleted file mode 100644 index fd71a31164..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/webapp/index.jsp +++ /dev/null @@ -1,31 +0,0 @@ -<%-- - - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. - ---%> - - -jclouds: anyweight cloudware for java - - -

Welcome!

-

Click here to see tweets about jclouds.

-

- - diff --git a/demos/tweetstore/gae-tweetstore/src/main/webapp/tweets.jsp b/demos/tweetstore/gae-tweetstore/src/main/webapp/tweets.jsp deleted file mode 100644 index cbdabde732..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/main/webapp/tweets.jsp +++ /dev/null @@ -1,109 +0,0 @@ -<%-- - - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. - ---%> -<%@ page buffer="20kb"%> -<%@ taglib uri="http://displaytag.sf.net" prefix="display"%> - - -jclouds: anyweight cloudware for java - - - -

Tweets in Clouds

- - - - - - - -
-
- - - - - - - - -
-
- - diff --git a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java b/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java deleted file mode 100644 index 031bb199fc..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.util.Map; -import java.util.Properties; - -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector; -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector.Credential; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code CredentialsCollector} - * - * @author Andrew Phillips - */ -@Test(groups = "unit") -public class CredentialsCollectorTest { - private CredentialsCollector collector = new CredentialsCollector(); - - public void testEmptyProperties() { - assertTrue(collector.apply(new Properties()).isEmpty(), - "Expected returned map to be empty"); - } - - public void testNoCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("not-an-identity", - "v1", "not-a-credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - private static Properties propertiesOf(Map entries) { - Properties properties = new Properties(); - properties.putAll(entries); - return properties; - } - - public void testNonMatchingCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("non_matching.identity", "v1", - "non_matching.credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - public void testIncompleteCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("acme.identity", "v1", - "acme-2.credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - public void testCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("acme.identity", "v1", - "acme.credential", "v2", "acme-2.identity", "v3", - "acme-2.credential", "v4")); - assertEquals(collector.apply(properties), - ImmutableMap.of("acme", new Credential("v1", "v2"), - "acme-2", new Credential("v3", "v4"))); - } -} \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java b/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java deleted file mode 100644 index 1c93403650..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; -import org.testng.collections.Maps; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - -/** - * Tests behavior of {@code AddTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class AddTweetsControllerTest { - - Map createServices(String container) throws InterruptedException, - ExecutionException { - Map services = Maps.newHashMap(); - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - for (String name : new String[] { "1", "2" }) { - BlobStoreContext context = ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class); - context.getAsyncBlobStore().createContainerInLocation(null, container).get(); - Blob blob = context.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - context.getAsyncBlobStore().putBlob(container, blob).get(); - services.put(name, context); - } - return services; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - String container = "container"; - Map contexts = createServices(container); - - ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container); - AddTweetsController controller = new AddTweetsController(contexts, function); - List list = controller.apply(ImmutableSet.of("1", "2")); - assertEquals(list.size(), 2); - assertEquals(list, ImmutableList.of(new StoredTweetStatus("1", "localhost", container, "1", - "frank", "I love beans!", null), new StoredTweetStatus("2", "localhost", container, - "1", "frank", "I love beans!", null))); - - } -} diff --git a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java b/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java deleted file mode 100644 index 81f0b9f3c7..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code AddTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class ClearTweetsControllerTest { - - Map createBlobStores(String container) throws InterruptedException, ExecutionException { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - for (BlobStoreContext blobstore : contexts.values()) { - blobstore.getBlobStore().createContainerInLocation(null, container); - Blob blob = blobstore.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - blobstore.getBlobStore().putBlob(container, blob); - } - return contexts; - } - - public void testClearTweets() throws IOException, InterruptedException, ExecutionException { - String container = ClearTweetsControllerTest.class.getName() + "#container"; - Map contexts = createBlobStores(container); - - ClearTweetsController controller = new ClearTweetsController(contexts, - container); - controller.clearContainer("test1"); - controller.clearContainer("test2"); - - for (BlobStoreContext context : contexts.values()) { - assertEquals(context.getBlobStore().countBlobs(container), 0, context.toString()); - } - } -} diff --git a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java b/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java deleted file mode 100644 index 5190718e4c..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl; -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; - -import java.util.Map; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.testng.annotations.Test; - -import com.google.appengine.api.taskqueue.Queue; -import com.google.appengine.api.taskqueue.TaskOptions.Method; -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@link EnqueueStoresController} - * - * @author Andrew Phillips - */ -@Test(groups = "unit") -public class EnqueueStoresControllerTest { - - Map createBlobStores() { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - return contexts; - } - - public void testEnqueueStores() { - Map stores = createBlobStores(); - Queue taskQueue = createMock(Queue.class); - EnqueueStoresController function = new EnqueueStoresController(stores, taskQueue); - - expect(taskQueue.add(withUrl("/store/do").header("context", "test1").method(Method.GET))).andReturn(null); - expect(taskQueue.add(withUrl("/store/do").header("context", "test2").method(Method.GET))).andReturn(null); - replay(taskQueue); - - function.enqueueStoreTweetTasks(); - - verify(taskQueue); - } -} diff --git a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java b/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java deleted file mode 100644 index 0976307732..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.util.Strings2; -import org.testng.annotations.Test; - -import twitter4j.Status; -import twitter4j.Twitter; -import twitter4j.User; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code StoreTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class StoreTweetsControllerTest { - - Twitter createTwitter() { - return createMock(Twitter.class); - } - - Map createBlobStores() throws InterruptedException, ExecutionException { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - for (BlobStoreContext blobstore : contexts.values()) { - blobstore.getAsyncBlobStore().createContainerInLocation(null, "favo").get(); - } - return contexts; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - Map stores = createBlobStores(); - StoreTweetsController function = new StoreTweetsController(stores, "favo", createTwitter()); - - User frank = createMock(User.class); - expect(frank.getScreenName()).andReturn("frank").atLeastOnce(); - - Status frankStatus = createMock(Status.class); - expect(frankStatus.getId()).andReturn(1l).atLeastOnce(); - expect(frankStatus.getUser()).andReturn(frank).atLeastOnce(); - expect(frankStatus.getText()).andReturn("I love beans!").atLeastOnce(); - - User jimmy = createMock(User.class); - expect(jimmy.getScreenName()).andReturn("jimmy").atLeastOnce(); - - Status jimmyStatus = createMock(Status.class); - expect(jimmyStatus.getId()).andReturn(2l).atLeastOnce(); - expect(jimmyStatus.getUser()).andReturn(jimmy).atLeastOnce(); - expect(jimmyStatus.getText()).andReturn("cloud is king").atLeastOnce(); - - replay(frank); - replay(frankStatus); - replay(jimmy); - replay(jimmyStatus); - - function.addMyTweets("test1", ImmutableList.of(frankStatus, jimmyStatus)); - function.addMyTweets("test2", ImmutableList.of(frankStatus, jimmyStatus)); - - verify(frank); - verify(frankStatus); - verify(jimmy); - verify(jimmyStatus); - - for (Entry entry : stores.entrySet()) { - BlobMap map = entry.getValue().createBlobMap("favo"); - Blob frankBlob = map.get("1"); - assertEquals(frankBlob.getMetadata().getName(), "1"); - assertEquals(frankBlob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME), "frank"); - assertEquals(frankBlob.getMetadata().getContentMetadata().getContentType(), "text/plain"); - assertEquals(Strings2.toString(frankBlob.getPayload()), "I love beans!"); - - Blob jimmyBlob = map.get("2"); - assertEquals(jimmyBlob.getMetadata().getName(), "2"); - assertEquals(jimmyBlob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME), "jimmy"); - assertEquals(jimmyBlob.getMetadata().getContentMetadata().getContentType(), "text/plain"); - assertEquals(Strings2.toString(jimmyBlob.getPayload()), "cloud is king"); - } - - } -} diff --git a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java b/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java deleted file mode 100644 index 2667a87fd2..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; - -/** - * Tests behavior of {@code KeyToStoredTweetStatus} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class KeyToStoredTweetStatusTest { - - BlobMap createMap() throws InterruptedException, ExecutionException { - BlobStoreContext context = - ContextBuilder.newBuilder(TransientApiMetadata.builder().build()).build(BlobStoreContext.class); - context.getBlobStore().createContainerInLocation(null, "test1"); - return context.createBlobMap("test1"); - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - BlobMap map = createMap(); - Blob blob = map.blobBuilder().name("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - map.put("1", blob); - String host = "localhost"; - String service = "stub"; - String container = "tweetstore"; - - KeyToStoredTweetStatus function = new KeyToStoredTweetStatus(map, service, host, container); - StoredTweetStatus result = function.apply("1"); - - StoredTweetStatus expected = new StoredTweetStatus(service, host, container, "1", "frank", - "I love beans!", null); - - assertEquals(result, expected); - - } -} diff --git a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java b/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java deleted file mode 100644 index 6bce7f8e8e..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; -import org.testng.collections.Maps; - -import com.google.common.collect.Iterables; - -/** - * Tests behavior of {@code ServiceToStoredTweetStatuses} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class ServiceToStoredTweetStatusesTest { - - Map createServices(String container) throws InterruptedException, - ExecutionException { - Map services = Maps.newHashMap(); - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - for (String name : new String[] { "1", "2" }) { - BlobStoreContext context = - ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class); - context.getAsyncBlobStore().createContainerInLocation(null, container).get(); - Blob blob = context.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - context.getAsyncBlobStore().putBlob(container, blob).get(); - services.put(name, context); - } - return services; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - String container = "container"; - Map contexts = createServices(container); - - ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container); - - assertEquals(Iterables.getLast(function.apply("1")), new StoredTweetStatus("1", "localhost", - container, "1", "frank", "I love beans!", null)); - - assertEquals(Iterables.getLast(function.apply("2")), new StoredTweetStatus("2", "localhost", - container, "1", "frank", "I love beans!", null)); - - } -} diff --git a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java b/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java deleted file mode 100644 index 63223607ac..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/GoogleDevServer.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.io.Closeables.closeQuietly; -import static java.lang.String.format; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -import com.google.appengine.tools.KickStart; -import com.google.appengine.tools.info.SdkInfo; - -/** - * Basic functionality to start a local google app engine instance. - * - * @author Adrian Cole - */ -public class GoogleDevServer { - - Thread server; - - public void writePropertiesAndStartServer(final String address, - final String port, final String warfile, Properties props) - throws IOException, InterruptedException { - String filename = String.format( - "%1$s/WEB-INF/jclouds.properties", warfile); - System.err.println("file: " + filename); - storeProperties(filename, props); - assert new File(filename).exists(); - this.server = new Thread(new Runnable() { - public void run() { - String sdkRoot = checkNotNull(System.getProperty(SdkInfo.SDK_ROOT_PROPERTY), SdkInfo.SDK_ROOT_PROPERTY); - KickStart.main(new String[] { - KickStarter.systemProperty("java.util.logging.config.file", - format("%s/WEB-INF/logging.properties", warfile)), - KickStarter.systemProperty(SdkInfo.SDK_ROOT_PROPERTY, sdkRoot), - "com.google.appengine.tools.development.DevAppServerMain", - "--disable_update_check", - format("--sdk_root=%s", sdkRoot), - "-a", address, "-p", port, warfile }); - } - }); - server.start(); - TimeUnit.SECONDS.sleep(30); - } - - private static void storeProperties(String filename, Properties props) throws IOException { - FileOutputStream targetFile = new FileOutputStream(filename); - try { - props.store(targetFile, "test"); - } finally { - closeQuietly(targetFile); - } - } - - public void stop() throws Exception { - // KickStart.main opens a process and calls process.waitFor(), which is interruptable - server.interrupt(); - } - - private static class KickStarter { - private static String systemProperty(String key, String value) { - return format("--jvm_flag=-D%s=%s", key, value); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java b/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java deleted file mode 100644 index 3265e752e9..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java +++ /dev/null @@ -1,239 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -import org.jclouds.Context; -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.config.GuiceServletConfig; -import org.jclouds.demo.tweetstore.controller.StoreTweetsController; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.AuthorizationException; -import org.jclouds.util.Strings2; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - -import twitter4j.ResponseList; -import twitter4j.Status; -import twitter4j.Twitter; -import twitter4j.TwitterException; -import twitter4j.TwitterFactory; -import twitter4j.conf.Configuration; -import twitter4j.conf.ConfigurationBuilder; - -import com.google.common.base.Joiner; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.inject.Module; - -/** - * Starts up the Google App Engine for Java Development environment and deploys an application which - * tests accesses twitter and blobstores. - * - * @author Adrian Cole - */ -@Test(groups = "live", singleThreaded = true) -public class TweetStoreLiveTest { - GoogleDevServer server; - private URL url; - private Map contexts; - private String container; - private static final Iterable blobstores = - Splitter.on(',').split(System.getProperty(PROPERTY_TWEETSTORE_BLOBSTORES, - "cloudfiles-us,aws-s3,azureblob")); - private static final Properties props = new Properties(); - - @BeforeTest - void clearAndCreateContainers() throws InterruptedException, ExecutionException, TimeoutException, IOException, - TwitterException { - container = getRequiredSystemProperty(PROPERTY_TWEETSTORE_CONTAINER); - - props.setProperty(PROPERTY_TWEETSTORE_CONTAINER, container); - props.setProperty(GuiceServletConfig.PROPERTY_BLOBSTORE_CONTEXTS, Joiner.on(',').join(blobstores)); - - // put all identity/credential pairs into the client - addCredentialsForBlobStores(props); - - // example of an ad-hoc client configuration - addConfigurationForTwitter(props); - - // for testing, capture logs. - final Set wiring = ImmutableSet. of(new Log4JLoggingModule()); - this.contexts = Maps.newConcurrentMap(); - - for (String provider : blobstores) { - contexts.put(provider, ContextBuilder.newBuilder(provider) - .modules(wiring).overrides(props).build(BlobStoreContext.class)); - } - - Configuration conf = new ConfigurationBuilder() - .setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY)) - .setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET)) - .setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN)) - .setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET)) - .build(); - Twitter client = new TwitterFactory(conf).getInstance(); - StoreTweetsController controller = new StoreTweetsController(contexts, container, client); - - ResponseList statuses = client.getMentions(); - - boolean deleted = false; - for (BlobStoreContext context : contexts.values()) { - try { - if (context.getBlobStore().containerExists(container)) { - System.err.printf("deleting container %s at %s%n", container, - context.unwrap(Context.class).getProviderMetadata().getEndpoint()); - context.getBlobStore().deleteContainer(container); - deleted = true; - } - } catch (AuthorizationException e) { - throw new AuthorizationException("for context: " + context, e); - } - } - if (deleted) { - System.err.println("sleeping 60 seconds to allow containers to clear"); - Thread.sleep(60000); - } - for (BlobStoreContext context : contexts.values()) { - System.err.printf("creating container %s at %s%n", container, - context.unwrap(Context.class).getProviderMetadata().getEndpoint()); - context.getBlobStore().createContainerInLocation(null, container); - } - - if (deleted) { - System.err.println("sleeping 5 seconds to allow containers to create"); - Thread.sleep(5000); - } - - for (Entry entry : contexts.entrySet()) { - System.err.printf("filling container %s at %s%n", container, entry.getKey()); - controller.addMyTweets(entry.getKey(), statuses); - } - } - - private static String getRequiredSystemProperty(String key) { - return checkNotNull(System.getProperty(key), key); - } - - private void addConfigurationForTwitter(Properties props) { - props.setProperty(PROPERTY_TWITTER_CONSUMER_KEY, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_KEY)); - props.setProperty(PROPERTY_TWITTER_CONSUMER_SECRET, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_SECRET)); - props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN)); - props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN_SECRET)); - } - - private void addCredentialsForBlobStores(Properties props) { - for (String provider : blobstores) { - props.setProperty(provider + ".identity", - getRequiredSystemProperty("test." + provider + ".identity")); - props.setProperty(provider + ".credential", - getRequiredSystemProperty("test." + provider + ".credential")); - } - } - - @BeforeTest(dependsOnMethods = "clearAndCreateContainers") - @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://%s:%s", address, port)); - - server = new GoogleDevServer(); - server.writePropertiesAndStartServer(address, port, warfile, props); - } - - @Test - public void shouldPass() throws InterruptedException, IOException { - InputStream i = url.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Welcome") >= 0 : string; - } - - @Test(dependsOnMethods = "shouldPass", expectedExceptions = IOException.class) - public void shouldFail() throws InterruptedException, IOException { - new URL(url, "/store/do").openStream(); - } - - @Test(dependsOnMethods = "shouldFail") - public void testPrimeContainers() throws IOException, InterruptedException { - URL gurl = new URL(url, "/store/do"); - - for (String context : blobstores) { - System.out.println("storing at context: " + context); - HttpURLConnection connection = (HttpURLConnection) gurl.openConnection(); - connection.addRequestProperty("X-AppEngine-QueueName", "twitter"); - connection.addRequestProperty("context", context); - InputStream i = connection.getInputStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Done!") >= 0 : string; - connection.disconnect(); - } - - System.err.println("sleeping 20 seconds to allow for eventual consistency delay"); - Thread.sleep(20000); - for (BlobStoreContext context : contexts.values()) { - assert context.createInputStreamMap(container).size() > 0 : context.unwrap(Context.class).getProviderMetadata().getEndpoint(); - } - } - - @Test(invocationCount = 5, dependsOnMethods = "testPrimeContainers") - public void testSerial() throws InterruptedException, IOException { - URL gurl = new URL(url, "/tweets/get"); - InputStream i = gurl.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Tweets in Clouds") >= 0 : string; - } - - @Test(invocationCount = 10, dependsOnMethods = "testPrimeContainers", threadPoolSize = 3) - public void testParallel() throws InterruptedException, IOException { - URL gurl = new URL(url, "/tweets/get"); - InputStream i = gurl.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Tweets in Clouds") >= 0 : string; - } - - @AfterTest - public void stopDevAppServer() throws Exception { - server.stop(); - } -} diff --git a/demos/tweetstore/gae-tweetstore/src/test/resources/log4j.xml b/demos/tweetstore/gae-tweetstore/src/test/resources/log4j.xml deleted file mode 100644 index 2e5d01fb9e..0000000000 --- a/demos/tweetstore/gae-tweetstore/src/test/resources/log4j.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/demos/tweetstore/heroku-tweetstore/README.txt b/demos/tweetstore/heroku-tweetstore/README.txt deleted file mode 100644 index c6bf77b0dd..0000000000 --- a/demos/tweetstore/heroku-tweetstore/README.txt +++ /dev/null @@ -1,41 +0,0 @@ -==== - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. -==== - -A guide to generating Twitter consumer keys and access tokens is at http://tinyurl.com/2fhebgb - -Please modify your maven settings.xml like below before attempting to run 'mvn -Plive install' - - - keys - - true - - - YOUR_ACCESS_KEY_ID - YOUR_SECRET_KEY - YOUR_USER - YOUR_HEX_KEY - YOUR_ACCOUNT - YOUR_BASE64_ENCODED_KEY - YOUR_TWITTER_CONSUMER_KEY - YOUR_TWITTER_CONSUMER_SECRET - YOUR_TWITTER_ACCESSTOKEN - YOUR_TWITTER_ACCESSTOKEN_SECRET - - \ No newline at end of file diff --git a/demos/tweetstore/heroku-tweetstore/pom.xml b/demos/tweetstore/heroku-tweetstore/pom.xml deleted file mode 100644 index d861cd8003..0000000000 --- a/demos/tweetstore/heroku-tweetstore/pom.xml +++ /dev/null @@ -1,148 +0,0 @@ - - - - 4.0.0 - - org.jclouds - jclouds-demos-tweetstore-project - 1.6.0-SNAPSHOT - - jclouds-demo-heroku-tweetstore - war - jclouds TweetStore for Heroku - jclouds TweetStore for Heroku's Cedar using Guice for Dependency Injection - - - localhost - 8088 - jclouds-heroku-tweetstore - - - - - com.google.inject.extensions - guice-servlet - 3.0 - - - org.quartz-scheduler - quartz - 2.1.3 - - - org.slf4j - slf4j-api - - - - - - javax.servlet - servlet-api - 2.5 - - - - - org.mortbay.jetty - jetty-runner - 7.5.4.v20111024 - test - - - org.eclipse.jetty - jetty-plus - - - org.eclipse.jetty - jetty-jndi - - - org.mortbay.jetty - jsp-2.1-glassfish - - - javax.transaction - jta - - - - - - - - live - - - - maven-surefire-plugin - - - integration - integration-test - - test - - - - ${test.twitter.runatcloud-tweetstore.consumer.identity} - ${test.twitter.runatcloud-tweetstore.consumer.credential} - ${test.twitter.runatcloud-tweetstore.access.identity} - ${test.twitter.runatcloud-tweetstore.access.credential} - ${test.azureblob.identity} - ${test.azureblob.credential} - ${test.cloudfiles-us.identity} - ${test.cloudfiles-us.credential} - ${test.aws-s3.identity} - ${test.aws-s3.credential} - ${test.cloudonestorage.identity} - ${test.cloudonestorage.credential} - ${test.ninefold-storage.identity} - ${test.ninefold-storage.credential} - ${test.jetty.address} - ${test.jetty.port} - ${project.build.directory}/jetty - ${jclouds.tweetstore.blobstores} - test.${jclouds.tweetstore.container} - ${project.build.directory}/${project.artifactId} - - - ${test.jetty.address} - ${test.jetty.port} - - - - - - - - - - - deploy - - - heroku-tweetstore - - - - diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/PlatformServices.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/PlatformServices.java deleted file mode 100644 index c768b42611..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/PlatformServices.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.demo.paas.config.PlatformServicesInitializer.PLATFORM_SERVICES_ATTRIBUTE_NAME; - -import java.util.Map; - -import javax.servlet.ServletContext; - -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.javax.annotation.Nullable; - -import com.google.common.collect.ImmutableMap; - -/** - * @author Andrew Phillips - */ -public class PlatformServices { - protected final String baseUrl; - private ImmutableMap taskQueues; - - public PlatformServices(String baseUrl, Map taskQueues) { - this.baseUrl = baseUrl; - this.taskQueues = ImmutableMap.copyOf(taskQueues); - } - - public String getBaseUrl() { - return baseUrl; - } - - public @Nullable TaskQueue getTaskQueue(String name) { - return taskQueues.get(name); - } - - public static PlatformServices get(ServletContext context) { - return (PlatformServices) checkNotNull(context.getAttribute( - PLATFORM_SERVICES_ATTRIBUTE_NAME), PLATFORM_SERVICES_ATTRIBUTE_NAME); - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java deleted file mode 100644 index ad72a1a58d..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas; - -import static java.lang.String.format; - -import org.jclouds.http.HttpCommand; -import org.jclouds.http.HttpCommandExecutorService; -import org.jclouds.http.HttpRequest; - -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; - -public class RunnableHttpRequest implements Runnable { - public static final String PLATFORM_REQUEST_ORIGINATOR_HEADER = "X-Platform-Originator"; - - public static Factory factory(HttpCommandExecutorService httpClient) { - return factory(httpClient, format("%s@%d", Factory.class.getName(), System.currentTimeMillis())); - } - - public static Factory factory(HttpCommandExecutorService httpClient, String originator) { - return new Factory(httpClient, originator); - } - - public static class Factory { - protected final HttpCommandExecutorService httpClient; - protected final String originator; - - private Factory(HttpCommandExecutorService httpClient, String originator) { - this.httpClient = httpClient; - this.originator = originator; - } - - public RunnableHttpRequest create(HttpRequest request) { - HttpRequest requestWithSubmitter = request.toBuilder() - .headers(copyOfWithEntry(request.getHeaders(), - PLATFORM_REQUEST_ORIGINATOR_HEADER, originator)).build(); - return new RunnableHttpRequest(httpClient, requestWithSubmitter); - } - - private static Multimap copyOfWithEntry( - Multimap multimap, K k1, V v1) { - return ImmutableMultimap.builder().putAll(multimap).put(k1, v1).build(); - } - } - - private final HttpCommandExecutorService httpClient; - private final HttpRequest request; - - private RunnableHttpRequest(HttpCommandExecutorService httpClient, HttpRequest request) { - this.httpClient = httpClient; - this.request = request; - } - - @Override - public void run() { - httpClient.submit(new ImmutableHttpCommand(request)); - } - - private class ImmutableHttpCommand implements HttpCommand { - private final HttpRequest request; - - public ImmutableHttpCommand(HttpRequest request) { - this.request = request; - } - - @Override - public void setException(Exception exception) { - } - - @Override - public void setCurrentRequest(HttpRequest request) { - } - - @Override - public boolean isReplayable() { - return false; - } - - @Override - public int incrementRedirectCount() { - return 0; - } - - @Override - public int incrementFailureCount() { - return 0; - } - - @Override - public int getRedirectCount() { - return 0; - } - - @Override - public int getFailureCount() { - return 0; - } - - @Override - public Exception getException() { - return null; - } - - @Override - public HttpRequest getCurrentRequest() { - return request; - } - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java deleted file mode 100644 index 5aa077b6cd..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.inject.name.Names.bindProperties; -import static org.jclouds.Constants.*; - -import java.util.Properties; - -import javax.servlet.ServletContext; -import javax.ws.rs.core.UriBuilder; - -import org.jclouds.demo.tweetstore.config.util.PropertiesLoader; - -import com.google.inject.AbstractModule; -import com.sun.jersey.api.uri.UriBuilderImpl; - -/** - * @author Andrew Phillips - */ -public class HttpClientModule extends AbstractModule { - private final ServletContext context; - - HttpClientModule(ServletContext context) { - this.context = context; - } - - @Override - protected void configure() { - // URL connection defaults - Properties toBind = defaultProperties(); - toBind.putAll(checkNotNull(new PropertiesLoader(context).get(), "properties")); - toBind.putAll(System.getProperties()); - bindProperties(binder(), toBind); - bind(UriBuilder.class).to(UriBuilderImpl.class); - } - - private static Properties defaultProperties() { - Properties props = new Properties(); - props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_CONTEXT, 20 + ""); - props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_HOST, 0 + ""); - props.setProperty(PROPERTY_SO_TIMEOUT, 60000 + ""); - props.setProperty(PROPERTY_CONNECTION_TIMEOUT, 60000 + ""); - props.setProperty(PROPERTY_USER_THREADS, 0 + ""); - props.setProperty(PROPERTY_IO_WORKER_THREADS, 20 + ""); - return props; - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java deleted file mode 100644 index e0c3eec312..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static java.lang.String.format; -import static java.util.concurrent.TimeUnit.SECONDS; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.demo.paas.PlatformServices; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.http.HttpCommandExecutorService; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; -import com.google.inject.Guice; - -/** - * @author Andrew Phillips - */ -public class PlatformServicesInitializer implements ServletContextListener { - public static final String PLATFORM_SERVICES_ATTRIBUTE_NAME = PlatformServices.class.getName(); - - protected static final String HOST_VARIABLE = "PUBLIC_HOST"; - protected static final String PORT_VARIABLE = "PUBLIC_PORT"; - - @Override - public void contextInitialized(ServletContextEvent contextEvent) { - ServletContext context = contextEvent.getServletContext(); - context.setAttribute(PLATFORM_SERVICES_ATTRIBUTE_NAME, createServices(context)); - } - - protected static PlatformServices createServices(ServletContext context) { - HttpCommandExecutorService httpClient = createHttpClient(context); - return new PlatformServices(getBaseUrl(context), createTaskQueues(httpClient)); - } - - protected static HttpCommandExecutorService createHttpClient( - final ServletContext context) { - return Guice.createInjector(new ExecutorServiceModule(), - new JavaUrlHttpCommandExecutorServiceModule(), - new HttpClientModule(context)) - .getInstance(HttpCommandExecutorService.class); - } - - protected static String getBaseUrl(ServletContext context) { - // use the public URL while https://support.heroku.com/requests/51088 is open - return format("http://%s:%s/%s", checkNotNull(System.getenv(HOST_VARIABLE), HOST_VARIABLE), - checkNotNull(System.getenv(PORT_VARIABLE), PORT_VARIABLE), context.getContextPath()); - } - - // TODO: make the number and names of queues configurable - protected static ImmutableMap createTaskQueues(HttpCommandExecutorService httpClient) { - Builder taskQueues = ImmutableMap.builder(); - taskQueues.put("twitter", TaskQueue.builder(httpClient) - .name("twitter").period(SECONDS.toMillis(30)) - .build()); - return taskQueues.build(); - } - - @Override - public void contextDestroyed(ServletContextEvent servletContextEvent) { - ServletContext context = servletContextEvent.getServletContext(); - context.removeAttribute(PLATFORM_SERVICES_ATTRIBUTE_NAME); - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java deleted file mode 100644 index 8af7021bd2..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.reference; - -/** - * Configuration properties and constants used in PaaS applications. - * - * @author Andrew Phillips - */ -public interface PaasConstants { - static final String PROPERTY_PLATFORM_BASE_URL = "jclouds.paas.baseurl"; -} diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java deleted file mode 100644 index e317a305cf..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.service.taskqueue; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.lang.String.format; - -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.TimeUnit; - -import org.jclouds.demo.paas.RunnableHttpRequest; -import org.jclouds.demo.paas.RunnableHttpRequest.Factory; -import org.jclouds.http.HttpCommandExecutorService; - -import com.google.inject.Provider; - -public class TaskQueue { - protected final Factory httpRequestFactory; - private final Timer timer; - private final ConcurrentLinkedQueue tasks = new ConcurrentLinkedQueue(); - - private TaskQueue(String name, long pollingIntervalMillis, Factory httpRequestFactory) { - this.httpRequestFactory = httpRequestFactory; - timer = new Timer(name); - timer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - Runnable task = tasks.poll(); - if (task != null) { - task.run(); - } - } - }, 0, pollingIntervalMillis); - } - - public void add(final Runnable task) { - tasks.add(task); - } - - public Factory getHttpRequestFactory() { - return httpRequestFactory; - } - - public void destroy() { - timer.cancel(); - tasks.clear(); - } - - public static Builder builder(HttpCommandExecutorService httpClient) { - return new Builder(httpClient); - } - - public static class Builder implements Provider { - protected final HttpCommandExecutorService httpClient; - protected String name = "default"; - protected long pollingIntervalMillis = TimeUnit.SECONDS.toMillis(1); - - private Builder(HttpCommandExecutorService httpClient) { - this.httpClient = checkNotNull(httpClient, "httpClient"); - } - - public Builder name(String name) { - this.name = checkNotNull(name, "name"); - return this; - } - - public Builder period(TimeUnit period) { - this.pollingIntervalMillis = checkNotNull(period, "period").toMillis(1); - return this; - } - - public Builder period(long pollingIntervalMillis) { - checkArgument(pollingIntervalMillis > 0, "pollingIntervalMillis"); - this.pollingIntervalMillis = pollingIntervalMillis; - return this; - } - - public TaskQueue build() { - return new TaskQueue(name, pollingIntervalMillis, - RunnableHttpRequest.factory(httpClient, format("taskqueue-%s", name))); - } - - @Override - public TaskQueue get() { - return build(); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java deleted file mode 100644 index c03434388a..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java +++ /dev/null @@ -1,155 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Predicates.in; -import static com.google.common.collect.ImmutableSet.copyOf; -import static com.google.common.collect.Sets.filter; -import static org.jclouds.demo.paas.reference.PaasConstants.PROPERTY_PLATFORM_BASE_URL; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET; - -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.paas.PlatformServices; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector; -import org.jclouds.demo.tweetstore.config.util.PropertiesLoader; -import org.jclouds.demo.tweetstore.controller.AddTweetsController; -import org.jclouds.demo.tweetstore.controller.ClearTweetsController; -import org.jclouds.demo.tweetstore.controller.EnqueueStoresController; -import org.jclouds.demo.tweetstore.controller.StoreTweetsController; - -import twitter4j.Twitter; -import twitter4j.TwitterFactory; -import twitter4j.conf.Configuration; -import twitter4j.conf.ConfigurationBuilder; - -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Module; -import com.google.inject.TypeLiteral; -import com.google.inject.name.Names; -import com.google.inject.servlet.GuiceServletContextListener; -import com.google.inject.servlet.ServletModule; - -/** - * Setup Logging and create Injector for use in testing S3. - * - * @author Adrian Cole - */ -public class GuiceServletConfig extends GuiceServletContextListener { - private Map providerTypeToBlobStoreMap; - private Twitter twitterClient; - private String container; - private TaskQueue queue; - private String baseUrl; - - @Override - public void contextInitialized(ServletContextEvent servletContextEvent) { - ServletContext servletContext = servletContextEvent.getServletContext(); - - Properties props = new PropertiesLoader(servletContext).get(); - Set modules = ImmutableSet.of(); - // shared across all blobstores and used to retrieve tweets - try { - Configuration twitterConf = new ConfigurationBuilder() - .setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY)) - .setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET)) - .setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN)) - .setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET)) - .build(); - twitterClient = new TwitterFactory(twitterConf).getInstance(); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("properties for twitter not configured properly in " + props.toString(), e); - } - // common namespace for storing tweets - container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER), PROPERTY_TWEETSTORE_CONTAINER); - - // instantiate and store references to all blobstores by provider name - providerTypeToBlobStoreMap = Maps.newHashMap(); - for (String hint : getBlobstoreContexts(props)) { - providerTypeToBlobStoreMap.put(hint, ContextBuilder.newBuilder(hint) - .modules(modules).overrides(props).build(BlobStoreContext.class)); - } - - // get a queue for submitting store tweet requests and the application's base URL - PlatformServices platform = PlatformServices.get(servletContext); - queue = platform.getTaskQueue("twitter"); - baseUrl = platform.getBaseUrl(); - - super.contextInitialized(servletContextEvent); - } - - private static Iterable getBlobstoreContexts(Properties props) { - Set contexts = new CredentialsCollector().apply(props).keySet(); - String explicitContexts = props.getProperty(PROPERTY_TWEETSTORE_BLOBSTORES); - if (explicitContexts != null) { - contexts = filter(contexts, in(copyOf(Splitter.on(',').split(explicitContexts)))); - } - checkState(!contexts.isEmpty(), "no credentials available for any requested context"); - return contexts; - } - - @Override - protected Injector getInjector() { - return Guice.createInjector(new ServletModule() { - @Override - protected void configureServlets() { - bind(new TypeLiteral>() {}) - .toInstance(providerTypeToBlobStoreMap); - bind(Twitter.class).toInstance(twitterClient); - bind(TaskQueue.class).toInstance(queue); - bindConstant().annotatedWith(Names.named(PROPERTY_PLATFORM_BASE_URL)) - .to(baseUrl); - bindConstant().annotatedWith(Names.named(PROPERTY_TWEETSTORE_CONTAINER)) - .to(container); - serve("/store/*").with(StoreTweetsController.class); - serve("/tweets/*").with(AddTweetsController.class); - serve("/stores/*").with(EnqueueStoresController.class); - serve("/clear/*").with(ClearTweetsController.class); - } - }); - } - - @Override - public void contextDestroyed(ServletContextEvent servletContextEvent) { - for (BlobStoreContext context : providerTypeToBlobStoreMap.values()) { - context.close(); - } - queue.destroy(); - super.contextDestroyed(servletContextEvent); - } -} \ No newline at end of file diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java deleted file mode 100644 index ce3943376e..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java +++ /dev/null @@ -1,153 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Predicates.notNull; -import static com.google.common.collect.Collections2.filter; -import static com.google.common.collect.Collections2.transform; -import static com.google.common.collect.ImmutableSet.copyOf; -import static com.google.common.collect.Maps.filterValues; -import static org.jclouds.util.Maps2.fromKeys; - -import java.util.Collection; -import java.util.Map; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector.Credential; - -import com.google.common.annotations.GwtIncompatible; -import com.google.common.base.Function; -import com.google.common.base.Predicate; - -/** - * Reads provider credentials from a {@link Properties} bag. - * - * @author Andrew Phillips - * - */ -public class CredentialsCollector implements Function> { - private static final String IDENTITY_PROPERTY_SUFFIX = ".identity"; - private static final String CREDENTIAL_PROPERTY_SUFFIX = ".credential"; - - // using the identity for provider name extraction - private static final Pattern IDENTITY_PROPERTY_PATTERN = - Pattern.compile("([a-zA-Z0-9-]+)" + Pattern.quote(IDENTITY_PROPERTY_SUFFIX)); - - @Override - public Map apply(final Properties properties) { - Collection providerNames = transform( - filter(properties.stringPropertyNames(), MatchesPattern.matches(IDENTITY_PROPERTY_PATTERN)), - new Function() { - @Override - public String apply(String input) { - Matcher matcher = IDENTITY_PROPERTY_PATTERN.matcher(input); - // as a side-effect, sets the matching group! - checkState(matcher.matches(), "'%s' should match '%s'", input, IDENTITY_PROPERTY_PATTERN); - return matcher.group(1); - } - }); - /* - * Providers without a credential property result in null values, which are - * removed from the returned map. - */ - return filterValues(fromKeys(copyOf(providerNames), new Function() { - @Override - public Credential apply(String providerName) { - String identity = properties.getProperty(providerName + IDENTITY_PROPERTY_SUFFIX); - String credential = properties.getProperty(providerName + CREDENTIAL_PROPERTY_SUFFIX); - return (((identity != null) && (credential != null)) - ? new Credential(identity, credential) - : null); - } - }), notNull()); - } - - public static class Credential { - private final String identity; - private final String credential; - - public Credential(String identity, String credential) { - this.identity = checkNotNull(identity, "identity"); - this.credential = checkNotNull(credential, "credential"); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((credential == null) ? 0 : credential.hashCode()); - result = prime * result - + ((identity == null) ? 0 : identity.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; - Credential other = (Credential) obj; - if (credential == null) { - if (other.credential != null) - return false; - } else if (!credential.equals(other.credential)) - return false; - if (identity == null) { - if (other.identity != null) - return false; - } else if (!identity.equals(other.identity)) - return false; - return true; - } - - public String getIdentity() { - return identity; - } - - public String getCredential() { - return credential; - } - } - - @GwtIncompatible(value = "java.util.regex.Pattern") - private static class MatchesPattern implements Predicate { - private final Pattern pattern; - - private MatchesPattern(Pattern pattern) { - this.pattern = pattern; - } - - @Override - public boolean apply(String input) { - return pattern.matcher(input).matches(); - } - - private static MatchesPattern matches(Pattern pattern) { - return new MatchesPattern(pattern); - } - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java deleted file mode 100644 index dafa5c311b..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import javax.servlet.ServletContext; - -import com.google.common.io.Closeables; -import com.google.inject.Provider; - -/** - * @author Andrew Phillips - */ -public class PropertiesLoader implements Provider{ - private static final String PROPERTIES_FILE = "/WEB-INF/jclouds.properties"; - - private final Properties properties; - - public PropertiesLoader(ServletContext context) { - properties = loadJcloudsProperties(context); - } - - private static Properties loadJcloudsProperties(ServletContext context) { - InputStream input = context.getResourceAsStream(PROPERTIES_FILE); - Properties props = new Properties(); - try { - props.load(input); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - Closeables.closeQuietly(input); - } - return props; - } - - @Override - public Properties get() { - return properties; - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java deleted file mode 100644 index 007fbafdef..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -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.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -/** - * Shows an example of how to use @{link BlobStoreContext} injected with Guice. - * - * @author Adrian Cole - */ -@Singleton -public class AddTweetsController extends HttpServlet implements - Function, List> { - - /** The serialVersionUID */ - private static final long serialVersionUID = 3888348023150822683L; - private final Map contexts; - private final ServiceToStoredTweetStatuses blobStoreContextToContainerResult; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - AddTweetsController(Map contexts, - ServiceToStoredTweetStatuses blobStoreContextToContainerResult) { - this.contexts = contexts; - this.blobStoreContextToContainerResult = blobStoreContextToContainerResult; - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - try { - addMyTweetsToRequest(request); - RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/tweets.jsp"); - dispatcher.forward(request, response); - } catch (Exception e) { - logger.error(e, "Error listing containers"); - throw new ServletException(e); - } - } - - void addMyTweetsToRequest(HttpServletRequest request) throws InterruptedException, - ExecutionException, TimeoutException { - request.setAttribute("tweets", apply(contexts.keySet())); - } - - public List apply(Set in) { - List statuses = Lists.newArrayList(); - for (Iterable list : Iterables.transform(in, - blobStoreContextToContainerResult)) { - Iterables.addAll(statuses, list); - } - return statuses; - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java deleted file mode 100644 index e08cfbc19e..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Strings.nullToEmpty; - -import java.io.IOException; -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; - -import com.google.common.annotations.VisibleForTesting; - -/** - * Grab tweets related to me and store them into blobstores - * - * @author Adrian Cole - */ -@Singleton -public class ClearTweetsController extends HttpServlet { - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Map contexts; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - @VisibleForTesting - public ClearTweetsController(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) { - this.container = container; - this.contexts = contexts; - } - - @VisibleForTesting - public void clearContainer(String contextName) { - BlobStoreContext context = checkNotNull(contexts.get(contextName), - "no context for %s in %s", contextName, contexts.keySet()); - try { - context.getBlobStore().clearContainer(container); - } catch (Exception e) { - logger.error(e, "Error clearing tweets in %s/%s", container, context); - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (nullToEmpty(request.getHeader("X-Originator")).equals("admin")) { - try { - String contextName = checkNotNull(request.getHeader("context"), "missing header context"); - logger.info("clearing tweets in %s/%s", container, contextName); - clearContainer(contextName); - logger.debug("done clearing tweets"); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error clearing tweets"); - throw new ServletException(e); - } - } else { - response.sendError(401); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java deleted file mode 100644 index 552a7fc69a..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Strings.nullToEmpty; - -import java.io.IOException; -import java.net.URI; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.paas.reference.PaasConstants; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.http.HttpRequest; -import org.jclouds.logging.Logger; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableMultimap; - -/** - * Adds tasks to retrieve and store tweets in all registered contexts to an async - * task queue. - * - * @author Andrew Phillips - * @see StoreTweetsController - */ -@Singleton -public class EnqueueStoresController extends HttpServlet { - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Set contextNames; - private final TaskQueue taskQueue; - private final String baseUrl; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - public EnqueueStoresController(Map contexts, TaskQueue taskQueue, - @Named(PaasConstants.PROPERTY_PLATFORM_BASE_URL) String baseUrl) { - contextNames = contexts.keySet(); - this.taskQueue = taskQueue; - this.baseUrl = baseUrl; - } - - @VisibleForTesting - void enqueueStoreTweetTasks() { - for (String contextName : contextNames) { - logger.debug("enqueuing task to store tweets in blobstore '%s'", contextName); - taskQueue.add(taskQueue.getHttpRequestFactory().create(HttpRequest.builder() - .endpoint(URI.create(baseUrl + "/store/do")) - .headers(ImmutableMultimap.of("context", contextName)) - .method("GET").build())); - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (!nullToEmpty(request.getHeader("X-Heroku-Cron")).equals("true")) { - response.sendError(401); - } - - try { - enqueueStoreTweetTasks(); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error storing tweets"); - throw new ServletException(e); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java deleted file mode 100644 index 948c9ff4ca..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Strings.nullToEmpty; -import static org.jclouds.demo.paas.RunnableHttpRequest.PLATFORM_REQUEST_ORIGINATOR_HEADER; - -import java.io.IOException; -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; -import org.jclouds.rest.AuthorizationException; - -import twitter4j.Status; -import twitter4j.Twitter; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; - -/** - * Grab tweets related to me and store them into blobstores - * - * @author Adrian Cole - */ -@Singleton -public class StoreTweetsController extends HttpServlet { - - private static final class StatusToBlob implements Function { - private final BlobMap map; - - private StatusToBlob(BlobMap map) { - this.map = map; - } - - public Blob apply(Status from) { - Blob to = map.blobBuilder().name(from.getId() + "").build(); - to.setPayload(from.getText()); - to.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); - to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, from.getUser().getScreenName()); - return to; - } - } - - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Map contexts; - private final Twitter client; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - @VisibleForTesting - public StoreTweetsController(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container, Twitter client) { - this.container = container; - this.contexts = contexts; - this.client = client; - } - - @VisibleForTesting - public void addMyTweets(String contextName, Iterable responseList) { - BlobStoreContext context = checkNotNull(contexts.get(contextName), "no context for " + contextName + " in " - + contexts.keySet()); - BlobMap map = context.createBlobMap(container); - for (Status status : responseList) { - Blob blob = null; - try { - blob = new StatusToBlob(map).apply(status); - map.put(status.getId() + "", blob); - } catch (AuthorizationException e) { - throw e; - } catch (Exception e) { - logger.error(e, "Error storing tweet %s (blob[%s]) on map %s/%s", status.getId(), blob, context, container); - } - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (nullToEmpty(request.getHeader(PLATFORM_REQUEST_ORIGINATOR_HEADER)).equals("taskqueue-twitter")) { - try { - String contextName = checkNotNull(request.getHeader("context"), "missing header context"); - logger.info("retrieving tweets"); - addMyTweets(contextName, client.getMentions()); - logger.debug("done storing tweets"); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error storing tweets"); - throw new ServletException(e); - } - } else { - response.sendError(401); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java deleted file mode 100644 index 42ad65df01..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.domain; - -import java.io.Serializable; - -/** - * - * @author Adrian Cole - */ -public class StoredTweetStatus implements Comparable, Serializable { - - /** The serialVersionUID */ - private static final long serialVersionUID = -3257496189689220018L; - private final String service; - private final String host; - private final String container; - private final String id; - private final String from; - private final String tweet; - private final String status; - - @Override - public String toString() { - return "StoredTweetStatus [container=" + container + ", from=" + from + ", host=" + host - + ", id=" + id + ", service=" + service + ", status=" + status + ", tweet=" + tweet - + "]"; - } - - public StoredTweetStatus(String service, String host, String container, String id, String from, - String tweet, String status) { - this.service = service; - this.host = host; - this.container = container; - this.id = id; - this.from = from; - this.tweet = tweet; - this.status = status; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((container == null) ? 0 : container.hashCode()); - result = prime * result + ((from == null) ? 0 : from.hashCode()); - result = prime * result + ((host == null) ? 0 : host.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((service == null) ? 0 : service.hashCode()); - result = prime * result + ((tweet == null) ? 0 : tweet.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; - StoredTweetStatus other = (StoredTweetStatus) obj; - if (container == null) { - if (other.container != null) - return false; - } else if (!container.equals(other.container)) - return false; - if (from == null) { - if (other.from != null) - return false; - } else if (!from.equals(other.from)) - return false; - if (host == null) { - if (other.host != null) - return false; - } else if (!host.equals(other.host)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (service == null) { - if (other.service != null) - return false; - } else if (!service.equals(other.service)) - return false; - if (tweet == null) { - if (other.tweet != null) - return false; - } else if (!tweet.equals(other.tweet)) - return false; - return true; - } - - - public String getService() { - return service; - } - - public String getHost() { - return host; - } - - public String getContainer() { - return container; - } - - public String getFrom() { - return from; - } - - public String getTweet() { - return tweet; - } - - public String getStatus() { - return status; - } - - public int compareTo(StoredTweetStatus o) { - if (id == null) - return -1; - return (int) ((this == o) ? 0 : id.compareTo(o.id)); - } - - - public String getId() { - return id; - } - -} diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java deleted file mode 100644 index f831b9780f..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import javax.annotation.Resource; - -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; -import org.jclouds.util.Strings2; - -import com.google.common.base.Function; - -/** - * - * @author Adrian Cole - */ -public class KeyToStoredTweetStatus implements Function { - private final String host; - private final BlobMap map; - private final String service; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - KeyToStoredTweetStatus(BlobMap map, String service, String host, String container) { - this.host = host; - this.map = map; - this.service = service; - this.container = container; - } - - public StoredTweetStatus apply(String id) { - String status; - String from; - String tweet; - try { - long start = System.currentTimeMillis(); - Blob blob = map.get(id); - status = ((System.currentTimeMillis() - start) + "ms"); - from = blob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME); - tweet = Strings2.toString(blob.getPayload()); - } catch (Exception e) { - logger.error(e, "Error listing container %s//%s/%s", service, container, id); - status = (e.getMessage()); - tweet = ""; - from = ""; - } - return new StoredTweetStatus(service, host, container, id, from, tweet, status); - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java deleted file mode 100644 index b2e5884c55..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import java.net.URI; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Context; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; - -@Singleton -public class ServiceToStoredTweetStatuses implements Function> { - - private final Map contexts; - private final String container; - - @Inject - public ServiceToStoredTweetStatuses(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) { - this.contexts = contexts; - this.container = container; - } - - @Resource - protected Logger logger = Logger.NULL; - - public Iterable apply(String service) { - BlobStoreContext context = contexts.get(service); - String host = URI.create(context.unwrap(Context.class).getProviderMetadata().getEndpoint()).getHost(); - try { - BlobMap blobMap = context.createBlobMap(container); - Set blobs = blobMap.keySet(); - return Iterables.transform(blobs, new KeyToStoredTweetStatus(blobMap, service, host, - container)); - } catch (Exception e) { - StoredTweetStatus result = new StoredTweetStatus(service, host, container, null, null, - null, e.getMessage()); - logger.error(e, "Error listing service %s", service); - return ImmutableList.of(result); - } - - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java deleted file mode 100644 index 42ec480ae2..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.reference; - -/** - * Configuration properties and constants used in TweetStore connections. - * - * @author Adrian Cole - */ -public interface TweetStoreConstants { - static final String PROPERTY_TWEETSTORE_BLOBSTORES = "jclouds.tweetstore.blobstores"; - static final String PROPERTY_TWEETSTORE_CONTAINER = "jclouds.tweetstore.container"; - /** - * Note that this has to conform to restrictions of all blobstores. for - * example, azure doesn't support periods. - */ - static final String SENDER_NAME = "sendername"; -} diff --git a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java b/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java deleted file mode 100644 index dc8b97915f..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.reference; - -/** - * Configuration properties and constants used in Twitter connections. - * - * @author Andrew Phillips - */ -public interface TwitterConstants { - static final String PROPERTY_TWITTER_CONSUMER_KEY = "twitter.consumer.identity"; - static final String PROPERTY_TWITTER_CONSUMER_SECRET = "twitter.consumer.credential"; - static final String PROPERTY_TWITTER_ACCESSTOKEN = "twitter.access.identity"; - static final String PROPERTY_TWITTER_ACCESSTOKEN_SECRET = "twitter.access.credential"; -} diff --git a/demos/tweetstore/heroku-tweetstore/src/main/platform/.gitignore b/demos/tweetstore/heroku-tweetstore/src/main/platform/.gitignore deleted file mode 100644 index 843dfe79c0..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/platform/.gitignore +++ /dev/null @@ -1 +0,0 @@ -# PaaS vendor specific files go in here \ No newline at end of file diff --git a/demos/tweetstore/heroku-tweetstore/src/main/webapp/WEB-INF/web.xml b/demos/tweetstore/heroku-tweetstore/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 5bf6bdf0bb..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - jclouds-tweetstore - - - - guiceFilter - com.google.inject.servlet.GuiceFilter - - - - guiceFilter - /* - - - - - org.jclouds.demo.paas.config.PlatformServicesInitializer - - - - org.jclouds.demo.tweetstore.config.GuiceServletConfig - - - - index.jsp - - - \ No newline at end of file diff --git a/demos/tweetstore/heroku-tweetstore/src/main/webapp/images/heroku-logo.png b/demos/tweetstore/heroku-tweetstore/src/main/webapp/images/heroku-logo.png deleted file mode 100644 index 1964aeefb40991d96a24a7d166fec188bd27edb5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4239 zcmV;A5OD8_P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D5F|-NK~!i%?OSP3 zR96>X2#7T@>1kps2h{h!` zDh3f3kO&%9W#9MJ-Hch>&8kUere?nP9yZ+w29ac@5~^-d@ZP)U-us<%&-u=|muDOu zf=x{(2^yAWE_38}69Uheev^tP3rRi6^?&N7g&gQ?1m!*m^kD5EGKvL(v!m9oTm9i1 zYYuF9ec#a98*BEjdu?x6$TA^c3+0W#ZH@qiH9!H-$(xT~>iVg?=yGmW)9Di}Lu2mi!r-wXeZ6&p}b{%>f?ef>ZNMBpI^5RdQdv*<< zs~W+&FV>qjeDwC_G?uNWY1d1H2DYt_{TKxr+upZd=Zg)&e1OKX^FbGM$Cu8IQ}a)D z#w}P!a(qXy?g#6Xtw(@0^8%>(s~4O&(s=TCb53SU`hjwhKqHe_#5z7t7Zb6%Ah$dF zSkuYlEgv6mQhG(gsDbr(r?7&YuDAv3N3gc=*NhK=U7KSK$O8Q1>ME``R^Mu_y;D+f zQ9yV(NQ~wLQ9x?bQ!85Q?=@82>}dM-;NAjzTNkO=NMSt=Sf6_oYp@-Ht>M_KxGc3q zKy8BmH>=0wnHi#Cw!=HUX9mJr?-yHL@>y;9m-Ur5icg>8bG;lMayWG16S}!E>ziwC z*OYw$m7uAW(*%SsUO9;R#~M?YdqgEC9ov<1diVBIYGsU=uOHsUJf$>D9v1NSmSek9 za#KGjc6SYP5Dq8YgT@+mE$ZoN{jZht#_-mJAejvBuBNwL=ZMX~KBaabCATjdyQ`50?2ww;f8 z(TWbUMyQs{*05}S?5w@1&qm8_ZM?wu;m01OF-#W`KalFh((pKb$jF$9F_ks&AG@e__8WTG)c;|b*BPY5wzJ~Ni-WAjP=Jl0?uL$i5E4;F2`{|hxs}RRb85X{0Aa-||ZqzSc zICo?6=3|>TrgK>eMik%(3S6=+`9ywBCxl?;>8a&O8`CsCbNM_CBWED2>5O6O#Z_P-^6dE7#VIUd-N7vh89Uz21{x-~2Zc35 z>}t!e*H=;yH`M^{I|v|n4j$6p`1QP)S4pmVkg*XFmC|4Fr|8($@KsCQJw|z0e?!%c zAY-h6=T9e}Q;r_0Ip6-ErS2{oqhqwj>f2CxN7L5{YYz}?B>3_892p&hNkk2kDybM$8Z2or25j!CYgMU~k!kzRKn}oyKnRBoibxC2ClUn0DZld4d)Qc%`zpFJ!974o z`b&hyN%C34g|z`WdR9j5n!oRu;BK%UB_mjqgggznJ-ugxg=9cb;0v&whgfIQSPzO{ zQ~tX02J%dlU*K~kA|s-WLLQA>k5{le4%?07`pt=13s=xkb?Zo4#pqGvus301Xs9Tt z6tla)?kjJe&TbX*l?X&jV&4ST=$?C``Okk62?(`_)QLp_1WUbfO=?@iJph`vznEk1 zDkA+Hgpgwt5IU0U11CV0BC2j`H8Da$XMwdx2#4hxWOxxknBYdEon z^Ku>=>f&VJvL=Z5uqISFD2PpD1A!>m5D%|31gy<-8Ac{HsY)@A!Mf;lH;3g$u+^(p z?1an1rrDbG(I5XHu(R>Dvr(YgSRsSepKH61fN>`8yomHBI2seyr?cB^tvzK_&P7SK zw^hLD(_#E>{Nex(pPa{_z;RB@N*+fA4fW(Qt@jnat4?^3n7VY6!{KZNql@inK7B7VTIV9m(H<~7HfOJn`=OFMuy?b+|(zzFWx z)BrS|1ET@3_HcBdb{Kq`lPn~UCLV}^;bAZE35!gXZKvA#?n!uU?1`n%Z{o6iOjtuc zQb$B)jDio|dpC28m7_$|lSU3R){oCke@(2he-Z28o%=L+;fk|Y#gq@}W7j=c!{InP zg)$_ss^pqZJyXE*GhY{qc`3v_dxf|jGFOdbz(sP(|wq+W;p3U zi2rI>W1Z=#rT*%f;8lHEXi!|RVUdH-AK}Z=hxB6YGHxm==@3#=`gu^mJOR(5+6BAb zm6F5Q^)gGlMxc%gUlJO$sI=fRL&Ns%$pc%5I~``M0kp<Wj@abbl zd*_|(Wc+n>_%aKB-S)uEMQ>~E5f$+=ra{q|mhYk?RuJ?_({S1~Sm9*QjFM{s+Gj~F zPGtHP^?zxsNy2YV^qQ{bZ?T0dORm|B8pi}@CZzvzBrY)7k!goo*kji~c^gkThcqe@tJpttT6iEQ?UJ`;e{L)w>0Ws)e zsZ)q@%2`K8tb{XV%o&^)l`kaXNpBodPKuTY10RF6fY8pLy$&V`QPriNE4`5Np`f9| zennooZ%-i#52(T;OLCHGP(}Lk;0+cC!O&&r`T4FewRt1y9IbZYES&ojdkd;v* zIxE10)XMoFc8L4fr{H{`u~<*AaWSG6cmhMbn8FCt027`snztIcHLza#{8kV_*j-_6 z7o04^`Do@E3@e@QH;;SF?Q#G*kauueO0c53iKNEmGG3G*w+ z?UZ|>AZfu&hu}jHZ@nhOe7HORXj=J^v~oY+8A3r11B3fh$Y{Hd(?3Np#?u*FcVgCKx$;$oqG|DL=fX=OQC4W6z> ziHMp8UE9*Geq|?4ppJZ0c4&W*&!p+#e_XcD+E;gD(?A+z!iG@HK=)P4ll@f@w${!l ze^q>;X*ZMN3BHY!{d0PEw)dN>AglxQGFCPtOGmlVLgNHBzm8p2Vcl8LD@ELC3T zshr2^JzRny6OzZt{KZ0)#V6q?l{$vE3~~cv9TXT}c&bb8Y27W3-Jm>kr)2&LRKXl9sth7DpcI4sh@Xf{5JIc1*JP-b ziw#&F^@=XbJlgOLYA=WclpH$fNvZEGwL+5|W`=#(7oJm-M_Hz4bgCnjT?>uO+#nhI z01=|k-1@QWZEt0m?&4s1*wmh`!F(Qo?q}+hL-3p#AD0*(w_(}h#E7ssv5=}sQsJoQ z&O-OdU7SAp?y>8{^#^ySoUpTTGrh)cLJ_WCpdaR`s5dH5|0Gymd_pM|Q6)eIYiGyM zypKDcU$|l9-jg}pG}eR`x2+L>aXpoeoBeFSfs%DchY-5;bYbGYhszAyN?17ewUN7% z7FgpC0jZxcb>+F%`y1EobCMdZ{^n^jT0WF!B}bLg(=8kn7(CQ2iftB<`8vQMN zOx<;-Oq;7&61Tao;>+&V`(Q9bZ76&G1aemVNq2~G9?72cXi)ti002ovPDHLkV1ggMEN=h+ diff --git a/demos/tweetstore/heroku-tweetstore/src/main/webapp/index.jsp b/demos/tweetstore/heroku-tweetstore/src/main/webapp/index.jsp deleted file mode 100644 index 9674294c6e..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/webapp/index.jsp +++ /dev/null @@ -1,30 +0,0 @@ -<%-- - - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. - ---%> - - -jclouds: anyweight cloudware for java - - -

Welcome!

-

Click here to see tweets about jclouds.

-

Powered by Heroku

- - diff --git a/demos/tweetstore/heroku-tweetstore/src/main/webapp/tweets.jsp b/demos/tweetstore/heroku-tweetstore/src/main/webapp/tweets.jsp deleted file mode 100644 index 469bc9cd09..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/main/webapp/tweets.jsp +++ /dev/null @@ -1,108 +0,0 @@ -<%-- - - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. - ---%> -<%@ page buffer="20kb"%> -<%@ taglib uri="http://displaytag.sf.net" prefix="display"%> - - -jclouds: anyweight cloudware for java - - - -

Tweets in Clouds

- - - - - - - -
-
- - - - - - - - -
-
Powered by Heroku
- - diff --git a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java b/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java deleted file mode 100644 index 031bb199fc..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.util.Map; -import java.util.Properties; - -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector; -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector.Credential; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code CredentialsCollector} - * - * @author Andrew Phillips - */ -@Test(groups = "unit") -public class CredentialsCollectorTest { - private CredentialsCollector collector = new CredentialsCollector(); - - public void testEmptyProperties() { - assertTrue(collector.apply(new Properties()).isEmpty(), - "Expected returned map to be empty"); - } - - public void testNoCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("not-an-identity", - "v1", "not-a-credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - private static Properties propertiesOf(Map entries) { - Properties properties = new Properties(); - properties.putAll(entries); - return properties; - } - - public void testNonMatchingCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("non_matching.identity", "v1", - "non_matching.credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - public void testIncompleteCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("acme.identity", "v1", - "acme-2.credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - public void testCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("acme.identity", "v1", - "acme.credential", "v2", "acme-2.identity", "v3", - "acme-2.credential", "v4")); - assertEquals(collector.apply(properties), - ImmutableMap.of("acme", new Credential("v1", "v2"), - "acme-2", new Credential("v3", "v4"))); - } -} \ No newline at end of file diff --git a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java b/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java deleted file mode 100644 index ccdb667ef3..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; -import org.testng.collections.Maps; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - -/** - * Tests behavior of {@code AddTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class AddTweetsControllerTest { - - Map createServices(String container) throws InterruptedException, - ExecutionException { - Map services = Maps.newHashMap(); - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - for (String name : new String[] { "1", "2" }) { - BlobStoreContext context = ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class); - context.getAsyncBlobStore().createContainerInLocation(null, container).get(); - Blob blob = context.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - context.getAsyncBlobStore().putBlob(container, blob).get(); - services.put(name, context); - } - return services; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - String container = AddTweetsControllerTest.class.getName() + "#container"; - Map contexts = createServices(container); - - ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container); - AddTweetsController controller = new AddTweetsController(contexts, function); - List list = controller.apply(ImmutableSet.of("1", "2")); - assertEquals(list.size(), 2); - assertEquals(list, ImmutableList.of(new StoredTweetStatus("1", "localhost", container, "1", - "frank", "I love beans!", null), new StoredTweetStatus("2", "localhost", container, - "1", "frank", "I love beans!", null))); - - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java b/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java deleted file mode 100644 index 81f0b9f3c7..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code AddTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class ClearTweetsControllerTest { - - Map createBlobStores(String container) throws InterruptedException, ExecutionException { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - for (BlobStoreContext blobstore : contexts.values()) { - blobstore.getBlobStore().createContainerInLocation(null, container); - Blob blob = blobstore.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - blobstore.getBlobStore().putBlob(container, blob); - } - return contexts; - } - - public void testClearTweets() throws IOException, InterruptedException, ExecutionException { - String container = ClearTweetsControllerTest.class.getName() + "#container"; - Map contexts = createBlobStores(container); - - ClearTweetsController controller = new ClearTweetsController(contexts, - container); - controller.clearContainer("test1"); - controller.clearContainer("test2"); - - for (BlobStoreContext context : contexts.values()) { - assertEquals(context.getBlobStore().countBlobs(container), 0, context.toString()); - } - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java b/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java deleted file mode 100644 index 3c5e5b1d80..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.easymock.EasyMock.*; - -import java.net.URI; -import java.util.Map; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.demo.paas.RunnableHttpRequest; -import org.jclouds.demo.paas.RunnableHttpRequest.Factory; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.http.HttpRequest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; - -/** - * Tests behavior of {@code EnqueueStoresController} - * - * @author Andrew Phillips - */ -@Test(groups = "unit") -public class EnqueueStoresControllerTest { - - Map createBlobStores() { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - return contexts; - } - - public void testEnqueueStores() { - Map stores = createBlobStores(); - TaskQueue taskQueue = createMock(TaskQueue.class); - Factory httpRequestFactory = createMock(Factory.class); - EnqueueStoresController function = new EnqueueStoresController(stores, - taskQueue, "http://localhost:8080"); - - expect(taskQueue.getHttpRequestFactory()).andStubReturn(httpRequestFactory); - - HttpRequest storeInTest1Request = HttpRequest.builder().endpoint( - URI.create("http://localhost:8080/store/do")) - .headers(ImmutableMultimap.of("context", "test1")).method("GET").build(); - RunnableHttpRequest storeInTest1Task = null; - expect(httpRequestFactory.create(eq(storeInTest1Request))).andReturn(storeInTest1Task); - - HttpRequest storeInTest2Request = HttpRequest.builder().endpoint( - URI.create("http://localhost:8080/store/do")) - .headers(ImmutableMultimap.of("context", "test2")).method("GET").build(); - RunnableHttpRequest storeInTest2Task = null; - expect(httpRequestFactory.create(eq(storeInTest2Request))).andReturn(storeInTest2Task); - - taskQueue.add(storeInTest1Task); - expectLastCall(); - taskQueue.add(storeInTest2Task); - expectLastCall(); - replay(httpRequestFactory, taskQueue); - - function.enqueueStoreTweetTasks(); - - verify(taskQueue); - } -} \ No newline at end of file diff --git a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java b/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java deleted file mode 100644 index 66448df0c5..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.util.Strings2; -import org.testng.annotations.Test; - -import twitter4j.Status; -import twitter4j.Twitter; -import twitter4j.User; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code StoreTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class StoreTweetsControllerTest { - - Twitter createTwitter() { - return createMock(Twitter.class); - } - - Map createBlobStores(String container) throws InterruptedException, ExecutionException { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - for (BlobStoreContext blobstore : contexts.values()) { - blobstore.getAsyncBlobStore().createContainerInLocation(null, container).get(); - } - return contexts; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - String container = StoreTweetsControllerTest.class.getName() + "#container"; - Map stores = createBlobStores(container); - StoreTweetsController function = new StoreTweetsController(stores, container, createTwitter()); - - User frank = createMock(User.class); - expect(frank.getScreenName()).andReturn("frank").atLeastOnce(); - - Status frankStatus = createMock(Status.class); - expect(frankStatus.getId()).andReturn(1l).atLeastOnce(); - expect(frankStatus.getUser()).andReturn(frank).atLeastOnce(); - expect(frankStatus.getText()).andReturn("I love beans!").atLeastOnce(); - - User jimmy = createMock(User.class); - expect(jimmy.getScreenName()).andReturn("jimmy").atLeastOnce(); - - Status jimmyStatus = createMock(Status.class); - expect(jimmyStatus.getId()).andReturn(2l).atLeastOnce(); - expect(jimmyStatus.getUser()).andReturn(jimmy).atLeastOnce(); - expect(jimmyStatus.getText()).andReturn("cloud is king").atLeastOnce(); - - replay(frank); - replay(frankStatus); - replay(jimmy); - replay(jimmyStatus); - - function.addMyTweets("test1", ImmutableList.of(frankStatus, jimmyStatus)); - function.addMyTweets("test2", ImmutableList.of(frankStatus, jimmyStatus)); - - verify(frank); - verify(frankStatus); - verify(jimmy); - verify(jimmyStatus); - - for (Entry entry : stores.entrySet()) { - BlobMap map = entry.getValue().createBlobMap(container); - Blob frankBlob = map.get("1"); - assertEquals(frankBlob.getMetadata().getName(), "1"); - assertEquals(frankBlob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME), "frank"); - assertEquals(frankBlob.getMetadata().getContentMetadata().getContentType(), "text/plain"); - assertEquals(Strings2.toString(frankBlob.getPayload()), "I love beans!"); - - Blob jimmyBlob = map.get("2"); - assertEquals(jimmyBlob.getMetadata().getName(), "2"); - assertEquals(jimmyBlob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME), "jimmy"); - assertEquals(jimmyBlob.getMetadata().getContentMetadata().getContentType(), "text/plain"); - assertEquals(Strings2.toString(jimmyBlob.getPayload()), "cloud is king"); - } - - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java b/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java deleted file mode 100644 index 36981b398a..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; - -/** - * Tests behavior of {@code KeyToStoredTweetStatus} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class KeyToStoredTweetStatusTest { - - BlobMap createMap() throws InterruptedException, ExecutionException { - BlobStoreContext context = - ContextBuilder.newBuilder(TransientApiMetadata.builder().build()).build(BlobStoreContext.class); - String container = KeyToStoredTweetStatusTest.class.getName() + "#container"; - context.getBlobStore().createContainerInLocation(null, container); - return context.createBlobMap(container); - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - BlobMap map = createMap(); - Blob blob = map.blobBuilder().name("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - map.put("1", blob); - String host = "localhost"; - String service = "stub"; - String container = "tweetstore"; - - KeyToStoredTweetStatus function = new KeyToStoredTweetStatus(map, service, host, container); - StoredTweetStatus result = function.apply("1"); - - StoredTweetStatus expected = new StoredTweetStatus(service, host, container, "1", "frank", - "I love beans!", null); - - assertEquals(result, expected); - - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java b/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java deleted file mode 100644 index 70fde3c119..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; -import org.testng.collections.Maps; - -import com.google.common.collect.Iterables; - -/** - * Tests behavior of {@code ServiceToStoredTweetStatuses} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class ServiceToStoredTweetStatusesTest { - - Map createServices(String container) throws InterruptedException, - ExecutionException { - Map services = Maps.newHashMap(); - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - for (String name : new String[] { "1", "2" }) { - BlobStoreContext context = ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class); - context.getAsyncBlobStore().createContainerInLocation(null, container).get(); - Blob blob = context.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - context.getAsyncBlobStore().putBlob(container, blob).get(); - services.put(name, context); - } - return services; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - String container = ServiceToStoredTweetStatusesTest.class.getName() + "#container"; - Map contexts = createServices(container); - - ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container); - - assertEquals(Iterables.getLast(function.apply("1")), new StoredTweetStatus("1", "localhost", - container, "1", "frank", "I love beans!", null)); - - assertEquals(Iterables.getLast(function.apply("2")), new StoredTweetStatus("2", "localhost", - container, "1", "frank", "I love beans!", null)); - - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/JettyServer.java b/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/JettyServer.java deleted file mode 100644 index d358287781..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/JettyServer.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration; - -import static com.google.common.io.Closeables.closeQuietly; -import static java.lang.String.format; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -import javax.servlet.ServletException; - -/** - * Basic functionality to start a local WAR-supporting Jetty instance. - * - * @author Andrew Phillips - */ -public class JettyServer { - protected Runner2 server; - - public void writePropertiesAndStartServer(final String port, final String warfile, - Properties props) throws IOException, InterruptedException, ServletException { - String filename = String.format( - "%1$s/WEB-INF/jclouds.properties", warfile); - System.err.println("file: " + filename); - storeProperties(filename, props); - assert new File(filename).exists(); - // Jetty uses SLF4J by default - System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.JavaUtilLog"); - System.setProperty("java.util.logging.config.file", - format("%s/WEB-INF/logging.properties", warfile)); - server = Runner2.createRunner(new String[] { "--port", port, warfile }); - server.start(); - TimeUnit.SECONDS.sleep(30); - } - - private static void storeProperties(String filename, Properties props) throws IOException { - FileOutputStream targetFile = new FileOutputStream(filename); - try { - props.store(targetFile, "test"); - } finally { - closeQuietly(targetFile); - } - } - - public void stop() { - server.stop(); - } -} \ No newline at end of file diff --git a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/Runner2.java b/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/Runner2.java deleted file mode 100644 index feb9e2c408..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/Runner2.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration; - -import javax.servlet.ServletException; - -import org.mortbay.jetty.runner.Runner; - -/** - * @see Runner - * @author Andrew Phillips - */ -class Runner2 extends Runner { - public static Runner2 createRunner(String[] args) throws ServletException { - Runner2 runner = new Runner2(); - try { - runner.configure(args); - } catch (Exception exception) { - throw new ServletException("Unable to configure runner", exception); - } - return runner; - } - - private final Thread serverThread; - - private Runner2() { - serverThread = new Thread(new Runnable() { - public void run() { - try { - Runner2.this.run(); - } catch (Exception exception) { - System.err.println("exception starting server: " + exception); - } - } - }); - } - - void start() throws ServletException { - Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { - public void run() { - stop(); - } - })); - serverThread.start(); - } - - void stop() { - try { - _server.stop(); - } catch (Exception exception) { - System.err.println("exception stopping server: " + exception); - } - serverThread.interrupt(); - } - -} diff --git a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java b/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java deleted file mode 100644 index 71e483b44b..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java +++ /dev/null @@ -1,237 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.demo.paas.RunnableHttpRequest.PLATFORM_REQUEST_ORIGINATOR_HEADER; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -import org.jclouds.Context; -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.controller.StoreTweetsController; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.AuthorizationException; -import org.jclouds.util.Strings2; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - -import twitter4j.ResponseList; -import twitter4j.Status; -import twitter4j.Twitter; -import twitter4j.TwitterException; -import twitter4j.TwitterFactory; -import twitter4j.conf.Configuration; -import twitter4j.conf.ConfigurationBuilder; - -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.inject.Module; - -/** - * Starts up the RUN@cloud for Java Development environment and deploys an application which - * tests accesses twitter and blobstores. - * - * @author Andrew Phillips - */ -@Test(groups = "live", singleThreaded = true) -public class TweetStoreLiveTest { - - JettyServer server; - private URL url; - private Map contexts; - private String container; - private static final Iterable blobstores = - Splitter.on(',').split(getRequiredSystemProperty(PROPERTY_TWEETSTORE_BLOBSTORES)); - private static final Properties props = new Properties(); - - @BeforeTest - void clearAndCreateContainers() throws InterruptedException, ExecutionException, TimeoutException, IOException, - TwitterException { - container = getRequiredSystemProperty(PROPERTY_TWEETSTORE_CONTAINER); - - props.setProperty(PROPERTY_TWEETSTORE_CONTAINER, container); - - // put all identity/credential pairs into the client - addCredentialsForBlobStores(props); - - // example of an ad-hoc client configuration - addConfigurationForTwitter(props); - - // for testing, capture logs. - final Set wiring = ImmutableSet. of(new Log4JLoggingModule()); - this.contexts = Maps.newConcurrentMap(); - - for (String provider : blobstores) { - contexts.put(provider, ContextBuilder.newBuilder(provider) - .modules(wiring).overrides(props).build(BlobStoreContext.class)); - } - - Configuration conf = new ConfigurationBuilder() - .setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY)) - .setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET)) - .setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN)) - .setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET)) - .build(); - Twitter client = new TwitterFactory(conf).getInstance(); - StoreTweetsController controller = new StoreTweetsController(contexts, container, client); - - ResponseList statuses = client.getMentions(); - - boolean deleted = false; - for (BlobStoreContext context : contexts.values()) { - try { - if (context.getBlobStore().containerExists(container)) { - System.err.printf("deleting container %s at %s%n", container, - context.unwrap(Context.class).getProviderMetadata().getEndpoint()); - context.getBlobStore().deleteContainer(container); - deleted = true; - } - } catch (AuthorizationException e) { - throw new AuthorizationException("for context: " + context, e); - } - } - if (deleted) { - System.err.println("sleeping 60 seconds to allow containers to clear"); - Thread.sleep(60000); - } - for (BlobStoreContext context : contexts.values()) { - System.err.printf("creating container %s at %s%n", container, - context.unwrap(Context.class).getProviderMetadata().getEndpoint()); - context.getBlobStore().createContainerInLocation(null, container); - } - - if (deleted) { - System.err.println("sleeping 5 seconds to allow containers to create"); - Thread.sleep(5000); - } - - for (Entry entry : contexts.entrySet()) { - System.err.printf("filling container %s at %s%n", container, entry.getKey()); - controller.addMyTweets(entry.getKey(), statuses); - } - } - - private static String getRequiredSystemProperty(String key) { - return checkNotNull(System.getProperty(key), key); - } - - private void addConfigurationForTwitter(Properties props) { - props.setProperty(PROPERTY_TWITTER_CONSUMER_KEY, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_KEY)); - props.setProperty(PROPERTY_TWITTER_CONSUMER_SECRET, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_SECRET)); - props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN)); - props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN_SECRET)); - } - - private void addCredentialsForBlobStores(Properties props) { - for (String provider : blobstores) { - props.setProperty(provider + ".identity", - getRequiredSystemProperty("test." + provider + ".identity")); - props.setProperty(provider + ".credential", - getRequiredSystemProperty("test." + provider + ".credential")); - } - } - - @BeforeTest(dependsOnMethods = "clearAndCreateContainers") - @Parameters({ "warfile", "jetty.address", "jetty.port" }) - public void startDevAppServer(final String warfile, final String address, final String port) throws Exception { - url = new URL(String.format("http://%s:%s", address, port)); - - server = new JettyServer(); - server.writePropertiesAndStartServer(port, warfile, props); - } - - @Test - public void shouldPass() throws InterruptedException, IOException { - InputStream i = url.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Welcome") >= 0 : string; - } - - @Test(dependsOnMethods = "shouldPass", expectedExceptions = IOException.class) - public void shouldFail() throws InterruptedException, IOException { - new URL(url, "/store/do").openStream(); - } - - @Test(dependsOnMethods = "shouldFail") - public void testPrimeContainers() throws IOException, InterruptedException { - URL gurl = new URL(url, "/store/do"); - - for (String context : blobstores) { - System.out.println("storing at context: " + context); - HttpURLConnection connection = (HttpURLConnection) gurl.openConnection(); - connection.addRequestProperty(PLATFORM_REQUEST_ORIGINATOR_HEADER, "taskqueue-twitter"); - connection.addRequestProperty("context", context); - InputStream i = connection.getInputStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Done!") >= 0 : string; - connection.disconnect(); - } - - System.err.println("sleeping 20 seconds to allow for eventual consistency delay"); - Thread.sleep(20000); - for (BlobStoreContext context : contexts.values()) { - assert context.createInputStreamMap(container).size() > 0 : context.unwrap(Context.class).getProviderMetadata().getEndpoint(); - } - } - - @Test(invocationCount = 5, dependsOnMethods = "testPrimeContainers") - public void testSerial() throws InterruptedException, IOException { - URL gurl = new URL(url, "/tweets/get"); - InputStream i = gurl.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Tweets in Clouds") >= 0 : string; - } - - @Test(invocationCount = 10, dependsOnMethods = "testPrimeContainers", threadPoolSize = 3) - public void testParallel() throws InterruptedException, IOException { - URL gurl = new URL(url, "/tweets/get"); - InputStream i = gurl.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Tweets in Clouds") >= 0 : string; - } - - @AfterTest - public void stopDevAppServer() throws Exception { - server.stop(); - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/ObjectFields.java b/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/ObjectFields.java deleted file mode 100644 index cc7c696c55..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/ObjectFields.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration.util; - -import java.lang.reflect.Field; - -public class ObjectFields { - - public static Object valueOf(String fieldName, Object source) { - return valueOf(fieldName, source, source.getClass()); - } - - public static Object valueOf(String fieldName, Object source, - Class fieldDeclaringClass) { - try { - return getAccessibleField(fieldName, fieldDeclaringClass).get(source); - } catch (Exception exception) { - throw new IllegalArgumentException(exception); - } - } - - private static Field getAccessibleField(String name, Class declaringClass) throws SecurityException, NoSuchFieldException { - Field field = declaringClass.getDeclaredField(name); - field.setAccessible(true); - return field; - } - - public static void set(String fieldName, Object target, Object value) { - set(fieldName, target, value, target.getClass()); - } - - public static void set(String fieldName, Object target, Object value, - Class fieldDeclaringClass) { - try { - getAccessibleField(fieldName, fieldDeclaringClass).set(target, value); - } catch (Exception exception) { - throw new IllegalArgumentException(exception); - } - } -} diff --git a/demos/tweetstore/heroku-tweetstore/src/test/resources/log4j.xml b/demos/tweetstore/heroku-tweetstore/src/test/resources/log4j.xml deleted file mode 100644 index 2e5d01fb9e..0000000000 --- a/demos/tweetstore/heroku-tweetstore/src/test/resources/log4j.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/demos/tweetstore/pom.xml b/demos/tweetstore/pom.xml deleted file mode 100644 index d195545a52..0000000000 --- a/demos/tweetstore/pom.xml +++ /dev/null @@ -1,422 +0,0 @@ - - - - - jclouds-demos-project - org.jclouds - 1.6.0-SNAPSHOT - - 4.0.0 - jclouds-demos-tweetstore-project - pom - jclouds TweetStore demos project - - cf-tweetstore-spring - heroku-tweetstore - gae-tweetstore - gae-tweetstore-spring - runatcloud-tweetstore - rhcloud-tweetstore - - - - target/maven-shared-archive-resources - cloudonestorage,ninefold-storage - - - - - ${project.groupId} - jclouds-blobstore - ${project.version} - - - org.twitter4j - twitter4j-core - [2.2,) - - - ${project.groupId} - jclouds-blobstore - ${project.version} - test-jar - test - - - org.jclouds.provider - aws-s3 - ${project.version} - runtime - - - org.jclouds.provider - cloudfiles-us - ${project.version} - runtime - - - org.jclouds.provider - azureblob - ${project.version} - runtime - - - org.jclouds.provider - cloudonestorage - ${project.version} - runtime - - - org.jclouds.provider - ninefold-storage - ${project.version} - runtime - - - displaytag - displaytag - 1.2 - runtime - - - org.slf4j - slf4j-log4j12 - - - - - org.slf4j - slf4j-jdk14 - 1.5.6 - runtime - - - jstl - javax.servlet - 1.1.2 - runtime - - - standard - taglibs - 1.1.2 - runtime - - - javax.servlet - servlet-api - 2.5 - provided - - - - - ${project.artifactId} - - - maven-remote-resources-plugin - 1.2 - - - false - - - - maven-war-plugin - 2.1.1 - - - WEB-INF/web.xml - - - src/main/platform - WEB-INF - true - - - .gitignore - - - - ${remoteResourcesDirectory}/META-INF - META-INF - - - - - - com.ning.maven.plugins - maven-duplicate-finder-plugin - 1.0.3 - - - - - - - com.google.appengine - appengine-api-1.0-sdk - 1.6.5 - - - com.google.appengine - appengine-tools-sdk - 1.6.5 - test - - - - com.google - - - - - - - javax.annotation - jsr250-api - 1.0 - runtime - - - org.apache.tomcat - annotations-api - 6.0.32 - test - - - - javax.annotation - - - - - - - commons-beanutils - commons-beanutils - 1.7.0 - runtime - - - commons-collections - commons-collections - 3.1 - runtime - - - - org.apache.commons.collections - - - - - - - javax.servlet - servlet-api - 2.5 - provided - - - com.google.appengine - appengine-tools-sdk - 1.6.5 - test - - - org.apache.tomcat - servlet-api - 6.0.32 - test - - - org.mortbay.jetty - jetty-runner - 7.5.4.v20111024 - test - - - - javax.servlet - - - - javax/servlet/resources/XMLSchema.dtd - javax/servlet/resources/datatypes.dtd - javax/servlet/resources/j2ee_1_4.xsd - javax/servlet/resources/j2ee_web_services_client_1_1.xsd - javax/servlet/resources/javaee_5.xsd - javax/servlet/resources/javaee_web_services_client_1_2.xsd - javax/servlet/resources/jsp_2_0.xsd - javax/servlet/resources/jsp_2_1.xsd - javax/servlet/resources/web-app_2_2.dtd - javax/servlet/resources/web-app_2_3.dtd - javax/servlet/resources/web-app_2_4.xsd - javax/servlet/resources/web-app_2_5.xsd - javax/servlet/resources/xml.xsd - javax/servlet/LocalStrings.properties - javax/servlet/LocalStrings_fr.properties - javax/servlet/LocalStrings_ja.properties - javax/servlet/http/LocalStrings.properties - javax/servlet/http/LocalStrings_es.properties - javax/servlet/http/LocalStrings_fr.properties - javax/servlet/http/LocalStrings_ja.properties - - - - - - - org.apache.tomcat - catalina - 6.0.32 - test - - - org.apache.tomcat - jasper - 6.0.32 - test - - - - org.apache.AnnotationProcessor - org.apache.PeriodicEventListener - - - - - - - javax.servlet - jstl - 1.1.2 - runtime - - - taglibs - standard - 1.1.2 - runtime - - - org.mortbay.jetty - jetty-runner - 7.5.4.v20111024 - test - - - - javax.servlet.jsp.jstl - org.apache.taglibs - - - META-INF/c-1_0-rt.tld - META-INF/c-1_0.tld - META-INF/c.tld - META-INF/fmt-1_0-rt.tld - META-INF/fmt-1_0.tld - META-INF/fmt.tld - META-INF/fn.tld - META-INF/permittedTaglibs.tld - META-INF/scriptfree.tld - META-INF/sql-1_0-rt.tld - META-INF/sql-1_0.tld - META-INF/sql.tld - META-INF/x-1_0-rt.tld - META-INF/x-1_0.tld - META-INF/x.tld - org/apache/taglibs/standard/lang/jstl/Resources.properties - org/apache/taglibs/standard/lang/jstl/Resources_ja.properties - org/apache/taglibs/standard/resources/Resources.properties - org/apache/taglibs/standard/resources/Resources_ja.properties - - - - - - - - - - - deploy - - - - maven-remote-resources-plugin - 1.2 - - - false - - - - include-jclouds-properties - - process - - - - - ${project.groupId}:jclouds-demos-tweetstore-jclouds-properties:2-${tweetstore.instance} - - - - - - - maven-war-plugin - - - WEB-INF/web.xml - - - src/main/platform - WEB-INF - true - - - .gitignore - - - - ${remoteResourcesDirectory}/META-INF - META-INF - - - ${remoteResourcesDirectory} - WEB-INF - true - - jclouds.properties - - - - - - - - - - diff --git a/demos/tweetstore/rhcloud-tweetstore/README.txt b/demos/tweetstore/rhcloud-tweetstore/README.txt deleted file mode 100644 index 559859f1cb..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/README.txt +++ /dev/null @@ -1,41 +0,0 @@ -==== - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. -==== - -A guide to generating Twitter consumer keys and access tokens is at http://tinyurl.com/2fhebgb - -Please modify your maven settings.xml like below before attempting to run 'mvn -Plive install' - - - keys - - true - - - YOUR_ACCESS_KEY_ID - YOUR_SECRET_KEY - YOUR_USER - YOUR_HEX_KEY - YOUR_ACCOUNT - YOUR_BASE64_ENCODED_KEY - YOUR_TWITTER_CONSUMER_KEY - YOUR_TWITTER_CONSUMER_SECRET - YOUR_TWITTER_ACCESSTOKEN - YOUR_TWITTER_ACCESSTOKEN_SECRET - - \ No newline at end of file diff --git a/demos/tweetstore/rhcloud-tweetstore/pom.xml b/demos/tweetstore/rhcloud-tweetstore/pom.xml deleted file mode 100644 index 8f5afb3737..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/pom.xml +++ /dev/null @@ -1,130 +0,0 @@ - - - - 4.0.0 - - org.jclouds - jclouds-demos-tweetstore-project - 1.6.0-SNAPSHOT - - jclouds-demo-rhcloud-tweetstore - war - jclouds TweetStore for OpenShift Express - jclouds TweetStore for RedHat's OpenShift Express using Guice for Dependency Injection - - - 7.0.2.Final - localhost - 8088 - jclouds-rhcloud-tweetstore - - - - - com.google.inject.extensions - guice-servlet - 3.0 - - - - - org.jboss.as - jboss-as-embedded - ${rhcloud.jboss.version} - test - - - - jboss-logmanager - org.jboss.logmanager - - - - - org.codehaus.plexus - plexus-archiver - 2.1.1 - test - - - - - - live - - - - maven-surefire-plugin - - - integration - integration-test - - test - - - - ${test.twitter.runatcloud-tweetstore.consumer.identity} - ${test.twitter.runatcloud-tweetstore.consumer.credential} - ${test.twitter.runatcloud-tweetstore.access.identity} - ${test.twitter.runatcloud-tweetstore.access.credential} - ${test.azureblob.identity} - ${test.azureblob.credential} - ${test.cloudfiles-us.identity} - ${test.cloudfiles-us.credential} - ${test.aws-s3.identity} - ${test.aws-s3.credential} - ${test.cloudonestorage.identity} - ${test.cloudonestorage.credential} - ${test.ninefold-storage.identity} - ${test.ninefold-storage.credential} - ${rhcloud.jboss.home} - ${test.jboss.address} - ${test.jboss.port} - ${jclouds.tweetstore.blobstores} - test.${jclouds.tweetstore.container} - ${project.build.directory}/rhcloud-jboss - ${project.basedir}/src/test/resources/jbossas7/configuration - ${project.build.directory}/${project.build.finalName} - - - ${test.jboss.address} - ${test.jboss.port} - - - - - - - - - - - deploy - - - rhcloud-tweetstore - - - - diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/PlatformServices.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/PlatformServices.java deleted file mode 100644 index c768b42611..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/PlatformServices.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.demo.paas.config.PlatformServicesInitializer.PLATFORM_SERVICES_ATTRIBUTE_NAME; - -import java.util.Map; - -import javax.servlet.ServletContext; - -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.javax.annotation.Nullable; - -import com.google.common.collect.ImmutableMap; - -/** - * @author Andrew Phillips - */ -public class PlatformServices { - protected final String baseUrl; - private ImmutableMap taskQueues; - - public PlatformServices(String baseUrl, Map taskQueues) { - this.baseUrl = baseUrl; - this.taskQueues = ImmutableMap.copyOf(taskQueues); - } - - public String getBaseUrl() { - return baseUrl; - } - - public @Nullable TaskQueue getTaskQueue(String name) { - return taskQueues.get(name); - } - - public static PlatformServices get(ServletContext context) { - return (PlatformServices) checkNotNull(context.getAttribute( - PLATFORM_SERVICES_ATTRIBUTE_NAME), PLATFORM_SERVICES_ATTRIBUTE_NAME); - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java deleted file mode 100644 index ad72a1a58d..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas; - -import static java.lang.String.format; - -import org.jclouds.http.HttpCommand; -import org.jclouds.http.HttpCommandExecutorService; -import org.jclouds.http.HttpRequest; - -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; - -public class RunnableHttpRequest implements Runnable { - public static final String PLATFORM_REQUEST_ORIGINATOR_HEADER = "X-Platform-Originator"; - - public static Factory factory(HttpCommandExecutorService httpClient) { - return factory(httpClient, format("%s@%d", Factory.class.getName(), System.currentTimeMillis())); - } - - public static Factory factory(HttpCommandExecutorService httpClient, String originator) { - return new Factory(httpClient, originator); - } - - public static class Factory { - protected final HttpCommandExecutorService httpClient; - protected final String originator; - - private Factory(HttpCommandExecutorService httpClient, String originator) { - this.httpClient = httpClient; - this.originator = originator; - } - - public RunnableHttpRequest create(HttpRequest request) { - HttpRequest requestWithSubmitter = request.toBuilder() - .headers(copyOfWithEntry(request.getHeaders(), - PLATFORM_REQUEST_ORIGINATOR_HEADER, originator)).build(); - return new RunnableHttpRequest(httpClient, requestWithSubmitter); - } - - private static Multimap copyOfWithEntry( - Multimap multimap, K k1, V v1) { - return ImmutableMultimap.builder().putAll(multimap).put(k1, v1).build(); - } - } - - private final HttpCommandExecutorService httpClient; - private final HttpRequest request; - - private RunnableHttpRequest(HttpCommandExecutorService httpClient, HttpRequest request) { - this.httpClient = httpClient; - this.request = request; - } - - @Override - public void run() { - httpClient.submit(new ImmutableHttpCommand(request)); - } - - private class ImmutableHttpCommand implements HttpCommand { - private final HttpRequest request; - - public ImmutableHttpCommand(HttpRequest request) { - this.request = request; - } - - @Override - public void setException(Exception exception) { - } - - @Override - public void setCurrentRequest(HttpRequest request) { - } - - @Override - public boolean isReplayable() { - return false; - } - - @Override - public int incrementRedirectCount() { - return 0; - } - - @Override - public int incrementFailureCount() { - return 0; - } - - @Override - public int getRedirectCount() { - return 0; - } - - @Override - public int getFailureCount() { - return 0; - } - - @Override - public Exception getException() { - return null; - } - - @Override - public HttpRequest getCurrentRequest() { - return request; - } - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java deleted file mode 100644 index 5aa077b6cd..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.inject.name.Names.bindProperties; -import static org.jclouds.Constants.*; - -import java.util.Properties; - -import javax.servlet.ServletContext; -import javax.ws.rs.core.UriBuilder; - -import org.jclouds.demo.tweetstore.config.util.PropertiesLoader; - -import com.google.inject.AbstractModule; -import com.sun.jersey.api.uri.UriBuilderImpl; - -/** - * @author Andrew Phillips - */ -public class HttpClientModule extends AbstractModule { - private final ServletContext context; - - HttpClientModule(ServletContext context) { - this.context = context; - } - - @Override - protected void configure() { - // URL connection defaults - Properties toBind = defaultProperties(); - toBind.putAll(checkNotNull(new PropertiesLoader(context).get(), "properties")); - toBind.putAll(System.getProperties()); - bindProperties(binder(), toBind); - bind(UriBuilder.class).to(UriBuilderImpl.class); - } - - private static Properties defaultProperties() { - Properties props = new Properties(); - props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_CONTEXT, 20 + ""); - props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_HOST, 0 + ""); - props.setProperty(PROPERTY_SO_TIMEOUT, 60000 + ""); - props.setProperty(PROPERTY_CONNECTION_TIMEOUT, 60000 + ""); - props.setProperty(PROPERTY_USER_THREADS, 0 + ""); - props.setProperty(PROPERTY_IO_WORKER_THREADS, 20 + ""); - return props; - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java deleted file mode 100644 index fd70aaa688..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static java.lang.String.format; -import static java.util.concurrent.TimeUnit.SECONDS; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.demo.paas.PlatformServices; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.http.HttpCommandExecutorService; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; -import com.google.inject.Guice; - -/** - * @author Andrew Phillips - */ -public class PlatformServicesInitializer implements ServletContextListener { - public static final String PLATFORM_SERVICES_ATTRIBUTE_NAME = PlatformServices.class.getName(); - - // from .openshift/config/standalone.xml - protected static final String HOST_VARIABLE = "OPENSHIFT_INTERNAL_IP"; - protected static final String PORT_VARIABLE = "OPENSHIFT_INTERNAL_PORT"; - - @Override - public void contextInitialized(ServletContextEvent contextEvent) { - ServletContext context = contextEvent.getServletContext(); - context.setAttribute(PLATFORM_SERVICES_ATTRIBUTE_NAME, createServices(context)); - } - - protected static PlatformServices createServices(ServletContext context) { - HttpCommandExecutorService httpClient = createHttpClient(context); - return new PlatformServices(getBaseUrl(context), createTaskQueues(httpClient)); - } - - protected static HttpCommandExecutorService createHttpClient( - final ServletContext context) { - return Guice.createInjector(new ExecutorServiceModule(), - new JavaUrlHttpCommandExecutorServiceModule(), - new HttpClientModule(context)) - .getInstance(HttpCommandExecutorService.class); - } - - protected static String getBaseUrl(ServletContext context) { - return format("http://%s:%s%s", checkNotNull(System.getenv(HOST_VARIABLE), HOST_VARIABLE), - checkNotNull(System.getenv(PORT_VARIABLE), PORT_VARIABLE), context.getContextPath()); - } - - // TODO: make the number and names of queues configurable - protected static ImmutableMap createTaskQueues(HttpCommandExecutorService httpClient) { - Builder taskQueues = ImmutableMap.builder(); - taskQueues.put("twitter", TaskQueue.builder(httpClient) - .name("twitter").period(SECONDS.toMillis(30)) - .build()); - return taskQueues.build(); - } - - @Override - public void contextDestroyed(ServletContextEvent servletContextEvent) { - ServletContext context = servletContextEvent.getServletContext(); - context.removeAttribute(PLATFORM_SERVICES_ATTRIBUTE_NAME); - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java deleted file mode 100644 index 8af7021bd2..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.reference; - -/** - * Configuration properties and constants used in PaaS applications. - * - * @author Andrew Phillips - */ -public interface PaasConstants { - static final String PROPERTY_PLATFORM_BASE_URL = "jclouds.paas.baseurl"; -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java deleted file mode 100644 index e317a305cf..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.service.taskqueue; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.lang.String.format; - -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.TimeUnit; - -import org.jclouds.demo.paas.RunnableHttpRequest; -import org.jclouds.demo.paas.RunnableHttpRequest.Factory; -import org.jclouds.http.HttpCommandExecutorService; - -import com.google.inject.Provider; - -public class TaskQueue { - protected final Factory httpRequestFactory; - private final Timer timer; - private final ConcurrentLinkedQueue tasks = new ConcurrentLinkedQueue(); - - private TaskQueue(String name, long pollingIntervalMillis, Factory httpRequestFactory) { - this.httpRequestFactory = httpRequestFactory; - timer = new Timer(name); - timer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - Runnable task = tasks.poll(); - if (task != null) { - task.run(); - } - } - }, 0, pollingIntervalMillis); - } - - public void add(final Runnable task) { - tasks.add(task); - } - - public Factory getHttpRequestFactory() { - return httpRequestFactory; - } - - public void destroy() { - timer.cancel(); - tasks.clear(); - } - - public static Builder builder(HttpCommandExecutorService httpClient) { - return new Builder(httpClient); - } - - public static class Builder implements Provider { - protected final HttpCommandExecutorService httpClient; - protected String name = "default"; - protected long pollingIntervalMillis = TimeUnit.SECONDS.toMillis(1); - - private Builder(HttpCommandExecutorService httpClient) { - this.httpClient = checkNotNull(httpClient, "httpClient"); - } - - public Builder name(String name) { - this.name = checkNotNull(name, "name"); - return this; - } - - public Builder period(TimeUnit period) { - this.pollingIntervalMillis = checkNotNull(period, "period").toMillis(1); - return this; - } - - public Builder period(long pollingIntervalMillis) { - checkArgument(pollingIntervalMillis > 0, "pollingIntervalMillis"); - this.pollingIntervalMillis = pollingIntervalMillis; - return this; - } - - public TaskQueue build() { - return new TaskQueue(name, pollingIntervalMillis, - RunnableHttpRequest.factory(httpClient, format("taskqueue-%s", name))); - } - - @Override - public TaskQueue get() { - return build(); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java deleted file mode 100644 index c03434388a..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java +++ /dev/null @@ -1,155 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Predicates.in; -import static com.google.common.collect.ImmutableSet.copyOf; -import static com.google.common.collect.Sets.filter; -import static org.jclouds.demo.paas.reference.PaasConstants.PROPERTY_PLATFORM_BASE_URL; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET; - -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.paas.PlatformServices; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector; -import org.jclouds.demo.tweetstore.config.util.PropertiesLoader; -import org.jclouds.demo.tweetstore.controller.AddTweetsController; -import org.jclouds.demo.tweetstore.controller.ClearTweetsController; -import org.jclouds.demo.tweetstore.controller.EnqueueStoresController; -import org.jclouds.demo.tweetstore.controller.StoreTweetsController; - -import twitter4j.Twitter; -import twitter4j.TwitterFactory; -import twitter4j.conf.Configuration; -import twitter4j.conf.ConfigurationBuilder; - -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Module; -import com.google.inject.TypeLiteral; -import com.google.inject.name.Names; -import com.google.inject.servlet.GuiceServletContextListener; -import com.google.inject.servlet.ServletModule; - -/** - * Setup Logging and create Injector for use in testing S3. - * - * @author Adrian Cole - */ -public class GuiceServletConfig extends GuiceServletContextListener { - private Map providerTypeToBlobStoreMap; - private Twitter twitterClient; - private String container; - private TaskQueue queue; - private String baseUrl; - - @Override - public void contextInitialized(ServletContextEvent servletContextEvent) { - ServletContext servletContext = servletContextEvent.getServletContext(); - - Properties props = new PropertiesLoader(servletContext).get(); - Set modules = ImmutableSet.of(); - // shared across all blobstores and used to retrieve tweets - try { - Configuration twitterConf = new ConfigurationBuilder() - .setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY)) - .setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET)) - .setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN)) - .setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET)) - .build(); - twitterClient = new TwitterFactory(twitterConf).getInstance(); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("properties for twitter not configured properly in " + props.toString(), e); - } - // common namespace for storing tweets - container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER), PROPERTY_TWEETSTORE_CONTAINER); - - // instantiate and store references to all blobstores by provider name - providerTypeToBlobStoreMap = Maps.newHashMap(); - for (String hint : getBlobstoreContexts(props)) { - providerTypeToBlobStoreMap.put(hint, ContextBuilder.newBuilder(hint) - .modules(modules).overrides(props).build(BlobStoreContext.class)); - } - - // get a queue for submitting store tweet requests and the application's base URL - PlatformServices platform = PlatformServices.get(servletContext); - queue = platform.getTaskQueue("twitter"); - baseUrl = platform.getBaseUrl(); - - super.contextInitialized(servletContextEvent); - } - - private static Iterable getBlobstoreContexts(Properties props) { - Set contexts = new CredentialsCollector().apply(props).keySet(); - String explicitContexts = props.getProperty(PROPERTY_TWEETSTORE_BLOBSTORES); - if (explicitContexts != null) { - contexts = filter(contexts, in(copyOf(Splitter.on(',').split(explicitContexts)))); - } - checkState(!contexts.isEmpty(), "no credentials available for any requested context"); - return contexts; - } - - @Override - protected Injector getInjector() { - return Guice.createInjector(new ServletModule() { - @Override - protected void configureServlets() { - bind(new TypeLiteral>() {}) - .toInstance(providerTypeToBlobStoreMap); - bind(Twitter.class).toInstance(twitterClient); - bind(TaskQueue.class).toInstance(queue); - bindConstant().annotatedWith(Names.named(PROPERTY_PLATFORM_BASE_URL)) - .to(baseUrl); - bindConstant().annotatedWith(Names.named(PROPERTY_TWEETSTORE_CONTAINER)) - .to(container); - serve("/store/*").with(StoreTweetsController.class); - serve("/tweets/*").with(AddTweetsController.class); - serve("/stores/*").with(EnqueueStoresController.class); - serve("/clear/*").with(ClearTweetsController.class); - } - }); - } - - @Override - public void contextDestroyed(ServletContextEvent servletContextEvent) { - for (BlobStoreContext context : providerTypeToBlobStoreMap.values()) { - context.close(); - } - queue.destroy(); - super.contextDestroyed(servletContextEvent); - } -} \ No newline at end of file diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java deleted file mode 100644 index ce3943376e..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java +++ /dev/null @@ -1,153 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Predicates.notNull; -import static com.google.common.collect.Collections2.filter; -import static com.google.common.collect.Collections2.transform; -import static com.google.common.collect.ImmutableSet.copyOf; -import static com.google.common.collect.Maps.filterValues; -import static org.jclouds.util.Maps2.fromKeys; - -import java.util.Collection; -import java.util.Map; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector.Credential; - -import com.google.common.annotations.GwtIncompatible; -import com.google.common.base.Function; -import com.google.common.base.Predicate; - -/** - * Reads provider credentials from a {@link Properties} bag. - * - * @author Andrew Phillips - * - */ -public class CredentialsCollector implements Function> { - private static final String IDENTITY_PROPERTY_SUFFIX = ".identity"; - private static final String CREDENTIAL_PROPERTY_SUFFIX = ".credential"; - - // using the identity for provider name extraction - private static final Pattern IDENTITY_PROPERTY_PATTERN = - Pattern.compile("([a-zA-Z0-9-]+)" + Pattern.quote(IDENTITY_PROPERTY_SUFFIX)); - - @Override - public Map apply(final Properties properties) { - Collection providerNames = transform( - filter(properties.stringPropertyNames(), MatchesPattern.matches(IDENTITY_PROPERTY_PATTERN)), - new Function() { - @Override - public String apply(String input) { - Matcher matcher = IDENTITY_PROPERTY_PATTERN.matcher(input); - // as a side-effect, sets the matching group! - checkState(matcher.matches(), "'%s' should match '%s'", input, IDENTITY_PROPERTY_PATTERN); - return matcher.group(1); - } - }); - /* - * Providers without a credential property result in null values, which are - * removed from the returned map. - */ - return filterValues(fromKeys(copyOf(providerNames), new Function() { - @Override - public Credential apply(String providerName) { - String identity = properties.getProperty(providerName + IDENTITY_PROPERTY_SUFFIX); - String credential = properties.getProperty(providerName + CREDENTIAL_PROPERTY_SUFFIX); - return (((identity != null) && (credential != null)) - ? new Credential(identity, credential) - : null); - } - }), notNull()); - } - - public static class Credential { - private final String identity; - private final String credential; - - public Credential(String identity, String credential) { - this.identity = checkNotNull(identity, "identity"); - this.credential = checkNotNull(credential, "credential"); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((credential == null) ? 0 : credential.hashCode()); - result = prime * result - + ((identity == null) ? 0 : identity.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; - Credential other = (Credential) obj; - if (credential == null) { - if (other.credential != null) - return false; - } else if (!credential.equals(other.credential)) - return false; - if (identity == null) { - if (other.identity != null) - return false; - } else if (!identity.equals(other.identity)) - return false; - return true; - } - - public String getIdentity() { - return identity; - } - - public String getCredential() { - return credential; - } - } - - @GwtIncompatible(value = "java.util.regex.Pattern") - private static class MatchesPattern implements Predicate { - private final Pattern pattern; - - private MatchesPattern(Pattern pattern) { - this.pattern = pattern; - } - - @Override - public boolean apply(String input) { - return pattern.matcher(input).matches(); - } - - private static MatchesPattern matches(Pattern pattern) { - return new MatchesPattern(pattern); - } - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java deleted file mode 100644 index dafa5c311b..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import javax.servlet.ServletContext; - -import com.google.common.io.Closeables; -import com.google.inject.Provider; - -/** - * @author Andrew Phillips - */ -public class PropertiesLoader implements Provider{ - private static final String PROPERTIES_FILE = "/WEB-INF/jclouds.properties"; - - private final Properties properties; - - public PropertiesLoader(ServletContext context) { - properties = loadJcloudsProperties(context); - } - - private static Properties loadJcloudsProperties(ServletContext context) { - InputStream input = context.getResourceAsStream(PROPERTIES_FILE); - Properties props = new Properties(); - try { - props.load(input); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - Closeables.closeQuietly(input); - } - return props; - } - - @Override - public Properties get() { - return properties; - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java deleted file mode 100644 index 007fbafdef..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -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.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -/** - * Shows an example of how to use @{link BlobStoreContext} injected with Guice. - * - * @author Adrian Cole - */ -@Singleton -public class AddTweetsController extends HttpServlet implements - Function, List> { - - /** The serialVersionUID */ - private static final long serialVersionUID = 3888348023150822683L; - private final Map contexts; - private final ServiceToStoredTweetStatuses blobStoreContextToContainerResult; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - AddTweetsController(Map contexts, - ServiceToStoredTweetStatuses blobStoreContextToContainerResult) { - this.contexts = contexts; - this.blobStoreContextToContainerResult = blobStoreContextToContainerResult; - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - try { - addMyTweetsToRequest(request); - RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/tweets.jsp"); - dispatcher.forward(request, response); - } catch (Exception e) { - logger.error(e, "Error listing containers"); - throw new ServletException(e); - } - } - - void addMyTweetsToRequest(HttpServletRequest request) throws InterruptedException, - ExecutionException, TimeoutException { - request.setAttribute("tweets", apply(contexts.keySet())); - } - - public List apply(Set in) { - List statuses = Lists.newArrayList(); - for (Iterable list : Iterables.transform(in, - blobStoreContextToContainerResult)) { - Iterables.addAll(statuses, list); - } - return statuses; - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java deleted file mode 100644 index e08cfbc19e..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Strings.nullToEmpty; - -import java.io.IOException; -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; - -import com.google.common.annotations.VisibleForTesting; - -/** - * Grab tweets related to me and store them into blobstores - * - * @author Adrian Cole - */ -@Singleton -public class ClearTweetsController extends HttpServlet { - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Map contexts; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - @VisibleForTesting - public ClearTweetsController(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) { - this.container = container; - this.contexts = contexts; - } - - @VisibleForTesting - public void clearContainer(String contextName) { - BlobStoreContext context = checkNotNull(contexts.get(contextName), - "no context for %s in %s", contextName, contexts.keySet()); - try { - context.getBlobStore().clearContainer(container); - } catch (Exception e) { - logger.error(e, "Error clearing tweets in %s/%s", container, context); - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (nullToEmpty(request.getHeader("X-Originator")).equals("admin")) { - try { - String contextName = checkNotNull(request.getHeader("context"), "missing header context"); - logger.info("clearing tweets in %s/%s", container, contextName); - clearContainer(contextName); - logger.debug("done clearing tweets"); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error clearing tweets"); - throw new ServletException(e); - } - } else { - response.sendError(401); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java deleted file mode 100644 index 937766c460..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Strings.nullToEmpty; - -import java.io.IOException; -import java.net.URI; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.paas.reference.PaasConstants; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.http.HttpRequest; -import org.jclouds.logging.Logger; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableMultimap; - -/** - * Adds tasks to retrieve and store tweets in all registered contexts to an async - * task queue. - * - * @author Andrew Phillips - * @see StoreTweetsController - */ -@Singleton -public class EnqueueStoresController extends HttpServlet { - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Set contextNames; - private final TaskQueue taskQueue; - private final String baseUrl; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - public EnqueueStoresController(Map contexts, TaskQueue taskQueue, - @Named(PaasConstants.PROPERTY_PLATFORM_BASE_URL) String baseUrl) { - contextNames = contexts.keySet(); - this.taskQueue = taskQueue; - this.baseUrl = baseUrl; - } - - @VisibleForTesting - void enqueueStoreTweetTasks() { - for (String contextName : contextNames) { - logger.debug("enqueuing task to store tweets in blobstore '%s'", contextName); - taskQueue.add(taskQueue.getHttpRequestFactory().create(HttpRequest.builder() - .endpoint(URI.create(baseUrl + "/store/do")) - .headers(ImmutableMultimap.of("context", contextName)) - .method("GET").build())); - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (!nullToEmpty(request.getHeader("X-Rhcloud-Cron")).equals("true")) { - response.sendError(401); - } - - try { - enqueueStoreTweetTasks(); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error storing tweets"); - throw new ServletException(e); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java deleted file mode 100644 index 948c9ff4ca..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Strings.nullToEmpty; -import static org.jclouds.demo.paas.RunnableHttpRequest.PLATFORM_REQUEST_ORIGINATOR_HEADER; - -import java.io.IOException; -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; -import org.jclouds.rest.AuthorizationException; - -import twitter4j.Status; -import twitter4j.Twitter; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; - -/** - * Grab tweets related to me and store them into blobstores - * - * @author Adrian Cole - */ -@Singleton -public class StoreTweetsController extends HttpServlet { - - private static final class StatusToBlob implements Function { - private final BlobMap map; - - private StatusToBlob(BlobMap map) { - this.map = map; - } - - public Blob apply(Status from) { - Blob to = map.blobBuilder().name(from.getId() + "").build(); - to.setPayload(from.getText()); - to.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); - to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, from.getUser().getScreenName()); - return to; - } - } - - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Map contexts; - private final Twitter client; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - @VisibleForTesting - public StoreTweetsController(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container, Twitter client) { - this.container = container; - this.contexts = contexts; - this.client = client; - } - - @VisibleForTesting - public void addMyTweets(String contextName, Iterable responseList) { - BlobStoreContext context = checkNotNull(contexts.get(contextName), "no context for " + contextName + " in " - + contexts.keySet()); - BlobMap map = context.createBlobMap(container); - for (Status status : responseList) { - Blob blob = null; - try { - blob = new StatusToBlob(map).apply(status); - map.put(status.getId() + "", blob); - } catch (AuthorizationException e) { - throw e; - } catch (Exception e) { - logger.error(e, "Error storing tweet %s (blob[%s]) on map %s/%s", status.getId(), blob, context, container); - } - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (nullToEmpty(request.getHeader(PLATFORM_REQUEST_ORIGINATOR_HEADER)).equals("taskqueue-twitter")) { - try { - String contextName = checkNotNull(request.getHeader("context"), "missing header context"); - logger.info("retrieving tweets"); - addMyTweets(contextName, client.getMentions()); - logger.debug("done storing tweets"); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error storing tweets"); - throw new ServletException(e); - } - } else { - response.sendError(401); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java deleted file mode 100644 index 42ad65df01..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.domain; - -import java.io.Serializable; - -/** - * - * @author Adrian Cole - */ -public class StoredTweetStatus implements Comparable, Serializable { - - /** The serialVersionUID */ - private static final long serialVersionUID = -3257496189689220018L; - private final String service; - private final String host; - private final String container; - private final String id; - private final String from; - private final String tweet; - private final String status; - - @Override - public String toString() { - return "StoredTweetStatus [container=" + container + ", from=" + from + ", host=" + host - + ", id=" + id + ", service=" + service + ", status=" + status + ", tweet=" + tweet - + "]"; - } - - public StoredTweetStatus(String service, String host, String container, String id, String from, - String tweet, String status) { - this.service = service; - this.host = host; - this.container = container; - this.id = id; - this.from = from; - this.tweet = tweet; - this.status = status; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((container == null) ? 0 : container.hashCode()); - result = prime * result + ((from == null) ? 0 : from.hashCode()); - result = prime * result + ((host == null) ? 0 : host.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((service == null) ? 0 : service.hashCode()); - result = prime * result + ((tweet == null) ? 0 : tweet.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; - StoredTweetStatus other = (StoredTweetStatus) obj; - if (container == null) { - if (other.container != null) - return false; - } else if (!container.equals(other.container)) - return false; - if (from == null) { - if (other.from != null) - return false; - } else if (!from.equals(other.from)) - return false; - if (host == null) { - if (other.host != null) - return false; - } else if (!host.equals(other.host)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (service == null) { - if (other.service != null) - return false; - } else if (!service.equals(other.service)) - return false; - if (tweet == null) { - if (other.tweet != null) - return false; - } else if (!tweet.equals(other.tweet)) - return false; - return true; - } - - - public String getService() { - return service; - } - - public String getHost() { - return host; - } - - public String getContainer() { - return container; - } - - public String getFrom() { - return from; - } - - public String getTweet() { - return tweet; - } - - public String getStatus() { - return status; - } - - public int compareTo(StoredTweetStatus o) { - if (id == null) - return -1; - return (int) ((this == o) ? 0 : id.compareTo(o.id)); - } - - - public String getId() { - return id; - } - -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java deleted file mode 100644 index f831b9780f..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import javax.annotation.Resource; - -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; -import org.jclouds.util.Strings2; - -import com.google.common.base.Function; - -/** - * - * @author Adrian Cole - */ -public class KeyToStoredTweetStatus implements Function { - private final String host; - private final BlobMap map; - private final String service; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - KeyToStoredTweetStatus(BlobMap map, String service, String host, String container) { - this.host = host; - this.map = map; - this.service = service; - this.container = container; - } - - public StoredTweetStatus apply(String id) { - String status; - String from; - String tweet; - try { - long start = System.currentTimeMillis(); - Blob blob = map.get(id); - status = ((System.currentTimeMillis() - start) + "ms"); - from = blob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME); - tweet = Strings2.toString(blob.getPayload()); - } catch (Exception e) { - logger.error(e, "Error listing container %s//%s/%s", service, container, id); - status = (e.getMessage()); - tweet = ""; - from = ""; - } - return new StoredTweetStatus(service, host, container, id, from, tweet, status); - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java deleted file mode 100644 index b2e5884c55..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import java.net.URI; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Context; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; - -@Singleton -public class ServiceToStoredTweetStatuses implements Function> { - - private final Map contexts; - private final String container; - - @Inject - public ServiceToStoredTweetStatuses(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) { - this.contexts = contexts; - this.container = container; - } - - @Resource - protected Logger logger = Logger.NULL; - - public Iterable apply(String service) { - BlobStoreContext context = contexts.get(service); - String host = URI.create(context.unwrap(Context.class).getProviderMetadata().getEndpoint()).getHost(); - try { - BlobMap blobMap = context.createBlobMap(container); - Set blobs = blobMap.keySet(); - return Iterables.transform(blobs, new KeyToStoredTweetStatus(blobMap, service, host, - container)); - } catch (Exception e) { - StoredTweetStatus result = new StoredTweetStatus(service, host, container, null, null, - null, e.getMessage()); - logger.error(e, "Error listing service %s", service); - return ImmutableList.of(result); - } - - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java deleted file mode 100644 index 42ec480ae2..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.reference; - -/** - * Configuration properties and constants used in TweetStore connections. - * - * @author Adrian Cole - */ -public interface TweetStoreConstants { - static final String PROPERTY_TWEETSTORE_BLOBSTORES = "jclouds.tweetstore.blobstores"; - static final String PROPERTY_TWEETSTORE_CONTAINER = "jclouds.tweetstore.container"; - /** - * Note that this has to conform to restrictions of all blobstores. for - * example, azure doesn't support periods. - */ - static final String SENDER_NAME = "sendername"; -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java b/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java deleted file mode 100644 index dc8b97915f..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.reference; - -/** - * Configuration properties and constants used in Twitter connections. - * - * @author Andrew Phillips - */ -public interface TwitterConstants { - static final String PROPERTY_TWITTER_CONSUMER_KEY = "twitter.consumer.identity"; - static final String PROPERTY_TWITTER_CONSUMER_SECRET = "twitter.consumer.credential"; - static final String PROPERTY_TWITTER_ACCESSTOKEN = "twitter.access.identity"; - static final String PROPERTY_TWITTER_ACCESSTOKEN_SECRET = "twitter.access.credential"; -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/platform/.gitignore b/demos/tweetstore/rhcloud-tweetstore/src/main/platform/.gitignore deleted file mode 100644 index 843dfe79c0..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/platform/.gitignore +++ /dev/null @@ -1 +0,0 @@ -# PaaS vendor specific files go in here \ No newline at end of file diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/webapp/WEB-INF/web.xml b/demos/tweetstore/rhcloud-tweetstore/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 5bf6bdf0bb..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - jclouds-tweetstore - - - - guiceFilter - com.google.inject.servlet.GuiceFilter - - - - guiceFilter - /* - - - - - org.jclouds.demo.paas.config.PlatformServicesInitializer - - - - org.jclouds.demo.tweetstore.config.GuiceServletConfig - - - - index.jsp - - - \ No newline at end of file diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/webapp/images/openshift-logo.png b/demos/tweetstore/rhcloud-tweetstore/src/main/webapp/images/openshift-logo.png deleted file mode 100644 index fc0075f9d4a8832c5a06300c0767760cbe83f0bd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4558 zcmV;<5i#zGP)Px#1ZP1_K>z@;j|==^1poj5AY({UO#lFTCIA3{ga82g0001h=l}q9FaQARU;qF* zm;eA5aGbhPJOBU@Oi4sRRA@u(T8C3qS=L|oPx^Mh-T8KANDUomLet^B?)N$X-GJoK zoDzsA`bR==$+saw?Rd(J)Q z+~4`#bMFf~XkY(7e3-wtZ{Nc3jvYJr=85R-+Z})Wql4(}`Z~Y!!$kMdtpe!nG|I;h zjcY#7|a5J9KU*w*RQHf7nhm1VlfX+|x@g6j4$i+V>se zz>86+lCz8a-QAQDZ+o~^QXid~t?Qrgb#bxpS4yPOaY^{^G$fKXp=hgU;ZEr+shmE> zs=R&ve^aXOMq`*<;7R&7L_VyN zZoTkb$-y4EP-w#%IObF}AZMJ~Cb9!%kvOw*FCS}?0FjvT_K8c*!9uam99dOJfW%wo z;ephm@v-J~RNhk6775-C5$(rr4``t%Ilnq7x5AuNY#BP8Wog9P2Nnn#wAHHAMU8`c zMsFEBl~S^s^m|JIA`wwc;eo!qeI4fPQn}X#*2q&)Q@<@$wkUyx+|$#XUDkSa+2760 zK6*G(2!){$v3n=4?mzu41@ci4gX7K>wG3M$mGBhr-JXVPS;=FHC@2%ZY_GQHj|ycXx$Q9Fvq= z-g6?qX(Y&ClDWBp;|0wl{%)>HktCzKv0~sXtJ1&-tZ8Ysuw@jYivBaEkSL{f{s96( zY40?npf>Z4cnJy&YrXYi-`P2TS62>4z!c!&&M4`kwsDABZak|wdW~>XB2|h+0q$;$ zT$NhUuo|UGFKP1OpeHN8~S%m%yis&UD!OrEjxs#l6WhH zBDp{yb92EElPNMGw^Gj-wuAL=0}aPIMqfI7IkUdsTv{KIlp7Qrp_VBSZh)I>TwZmA zIh(7Gzzd)l492{s!#Pc(QOO0_2ZupM%pYtG)R{{9&c)@{AZI``yLmLg-CZM7RvwvA z`^%9$09QFaqt^x#;{RGYV40=a+OzleUVdD2;x_U}s)0}lm{M!n_Fj6l@5<_)^UHM? zSIQ1w!9b0iib~Ee9lWsb>KaxV#}(1^sC ztjc7|p{$l;S#49X1$F2Ti%AC@8$<&mBvQbt*BX;8ZMp5Izza@9lHn&yDsRd>I0k8Y z{jkE*6B9E8?#$^pNf_$pQZYRrWQwuP2d-&fSwZiGnhTGs&parfxGi(}LMf4i#pjeA z{btw2wd&K$Ri~EFEN52=`Y&lU`jXL`yDvYroO@^!aSAnGt%XD;CsnoXzWi+0#V3}t z59}3SKe_r)pfRF&WTtH5TUgtD=_xunH8jh)70~O01I;pqq`E#Zk*p~~TOonZFCZu+ zCar106q%xu5TNa=DiBl$D3fXjK>T<8ptisxC^Rmo`%-$_Nrk|J)E`gJ$jmBpO}F1? zf6hC6D?F)?t0X9na(CDCmZ`FHYsJU!m7KVrKlTljv%4==eD%EK7`9N(@U^#2>Q@KOMO_i zA#PW{(hf3gAXvf*PeE8lwJ|E)0cZk~)Q6$ixZ0u3qx`WMqK0ZzY(o8*(#w-0JK&2d zZ3#&%PS`&lS-2mSfvf|=BAtF1UDgsDm70HYjW314++)l7!0->uXe-cB zHGP=5Lxoa_M4_3rfstwa2soglEd%^f5NT9QbnOTSv^6Wfl(#fy-(+n4WV8ht6{v(> z!7(`*Q;*Ze7Sl!-NISBW)N_-T${XsWF;6fXWWxY-y6N?P#d$eK6PJvddw83Rg(!&95tl9)LxySMJ zFjfxgQ)<*ojj4Jha_D|U@9ewQzp%6QI_0_1p;cN#^^uT)6;s!&sq^ke>z)s8 zo&lpxJqw%qIfb5upuMNn>L63+tf_16-KdS>vmyQW8IxIG*ly}u;z{qC`j+)MO-xuC zacc8uyFeH{3mWat56fs8i<%B(3cH;^CKhRuYc)nYpvki&UuzwZ&(Wmv%61$5Zcz;8~XOrw!6CSW!h+Fat{%Mn?zP4T}y0cBW+67^*nGQ zJ#<&!zCi0fBGB9|8G%MDrbI%@!$p%)s}72%#6n7f9xu}A7XZSl*${PPE>k*0330;$ z+=VwyJ4rbJEVLALTJ<^Bb^3Difjg?((sr3m zci-1{Ea(o-z?81;g0AV7u4938b}s7MXY~N0V_sW(npOwvx|a3b%lgg*efu2gx3%tN zwb9Jxb&^r`{oHlek~XtZ9g?E&S#cu$xIlLiT(Ie>^lDR*CZUSSX$4rigE!QHu@oDs zjxA;K4zZRgwqjgU*u!KrGHLbNk|E0NbCd#2bRk2ZcSt!ThylsOJ{3N zu=!npSOsteu59%&%1=(v=je}&V#A~jFr^2Ahh`~{FDaprRx;|K1WlratvI4@pV#+2 z()T^q)?WhOHPHo{oK~%6O4srYI|8T8}PiqKOf@=}MTlT34~N+Kb|_wu0Jzf{R-bwoCkvWMhGEJEog{Q?)t%ZsA* zfKQWB$Ciz#gA=U%u2_f^))r$T&?i(fSxs#DD3fTRJl$20`uNk7o;Ji_jvBLt$!^A! zF$-E_M6@697TiiMKU$_F&&Ei_@FJ7JJh?|pX!uDMyM)AHd%}rPI3vr|q}pHzO171! z+#L!D7mqZ>LfXgS+5gs0$Y96$qXs{+i=fnqdCyn5B$1RLW--#R5uWwY=!S>{&q=M* zVT>Sc&_xEA_+s`_PUF$+7pzxi&$2}LcGX?9cHbMORqTf8q$%~$M z3h#|`gG|m}Hd!B|Zx3aJ@vi~Bz1Lm;4iLBXzU@CDfKNbwq!fMv`V-LqUG?e{qdzhF zzm?JCWwY2jKqSGJ0`@QM9bTPqI%o=s^gU{v4%cAN>AnvOwy!vp-acqf)yNA|sW0rv zgksLAQ@@-J6v%@>>-AQjh`KxaKOsCaB{trs7G(T*s&I;Tv-;V1BFJJ<+mPe+HZ$GbNVoSKij;K;~`%@;0KAFs+pn?7tqNCry1 zzHYDec7ASF;Np=m4QOKO^&}pMJuZKElskI$PTSC5Aan1`f0e)#Hbc0@Vzp zfwUT~$fp#WD+7K)bA5ds@F9QTm(yAV>DiMf->knG8y<1_)BjG69qH}pk8No(2Mi)-+l9K zUPh+WS^St0IHC5J!ON4iHJAVSvkhgg#A8i!Y_Qc6!f4n!b$l9O0ceO(=6-nbJ<6Oz z3Byk|K>1{Kb$$H}2>bHKAG1@^0K`_Mqq*V0o~mj<;55$w`s>S=EM*mC`Gt4CyFEHM z)ZN~}XEe8Y({FBwSZ36x5>9ZHlpI4Wb%e-t~ zk!`BK)&fGq%d;m>gr9%O%@LhIue`7*B{nYIoG5h@;6H~o0UFD5S4HL8>Z-5669sOs zrRK%+7h+fUtx899NSMYy0MA)Ke?D8SrNb9rI*Y$_6MXhJFxu%Z!2#W{r_S|Hf0?~= z2eUfV)XWDO)--;yk^TYfJV`Mz9E0H9fzOQ-9TgG!Pv^;5Y%Rqxb-se4x7*yTS(0l++Kk?DeaE+?bhxfVe3t0s8#SP_LxEfBqs=ANZbA zplvfmIXW^tGCgrDDLRIaHGsZ#eWt0tLE_?$(+-?sZ*W?pxl(BR!{YPxz&o%_&*}hl zWg*!B&z?FBu9W8&;Tna@X^n2#e}K4aYjawov9=(sE-eE;la0~n z_Y(-a54DTFa7C5JuCu?kjze<`%$)`fu!1_ s%=L38eeSHXX)}D!q2!b3--W - - -jclouds: anyweight cloudware for java - - -

Welcome!

-

Click here to see tweets about jclouds.

-

Powered by OpenShift Express

- - diff --git a/demos/tweetstore/rhcloud-tweetstore/src/main/webapp/tweets.jsp b/demos/tweetstore/rhcloud-tweetstore/src/main/webapp/tweets.jsp deleted file mode 100644 index bfdf462dde..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/main/webapp/tweets.jsp +++ /dev/null @@ -1,108 +0,0 @@ -<%-- - - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. - ---%> -<%@ page buffer="20kb"%> -<%@ taglib uri="http://displaytag.sf.net" prefix="display"%> - - -jclouds: anyweight cloudware for java - - - -

Tweets in Clouds

- - - - - - - -
-
- - - - - - - - -
-
Powered by OpenShift Express
- - diff --git a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jboss/as/embedded/EmbeddedServerFactory2.java b/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jboss/as/embedded/EmbeddedServerFactory2.java deleted file mode 100644 index 8d5e3d69ab..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jboss/as/embedded/EmbeddedServerFactory2.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.jboss.as.embedded; - -import java.io.File; -import java.util.Map; -import java.util.Properties; -import java.util.logging.LogManager; - -import org.jboss.modules.Module; -import org.jboss.modules.ModuleClassLoader; -import org.jboss.modules.ModuleIdentifier; -import org.jboss.modules.ModuleLoadException; -import org.jboss.modules.ModuleLoader; -import org.jboss.modules.log.JDKModuleLogger; -import org.jclouds.demo.tweetstore.integration.util.ObjectFields; - -/** - * A variant of {@link EmbeddedServerFactory} that resets JDK logging for JBoss, - * which requires its own settings in this area. - * - * Needs to be in the org.jboss.as.embedded package to be able to use - * {@code InitialModuleLoaderFactory}. - * - * @author Andrew Phillips - * @see EmbeddedServerFactory - */ -public class EmbeddedServerFactory2 { - - // mainly copied from EmbeddedServerFactory - public static StandaloneServer create(final File jbossHomeDir, final Properties systemProps, final Map systemEnv, String...systemPackages) { - if (jbossHomeDir == null || jbossHomeDir.isDirectory() == false) - throw new IllegalStateException("Invalid jboss.home.dir: " + jbossHomeDir); - - if (systemProps.getProperty(ServerEnvironment.HOME_DIR) == null) - systemProps.setProperty(ServerEnvironment.HOME_DIR, jbossHomeDir.getAbsolutePath()); - - File modulesDir = new File(jbossHomeDir + "/modules"); - final ModuleLoader moduleLoader = InitialModuleLoaderFactory.getModuleLoader(modulesDir, systemPackages); - - try { - Module.registerURLStreamHandlerFactoryModule(moduleLoader.loadModule(ModuleIdentifier.create("org.jboss.vfs"))); - - // Initialize the Logging system - ModuleIdentifier logModuleId = ModuleIdentifier.create("org.jboss.logmanager"); - ModuleClassLoader logModuleClassLoader = moduleLoader.loadModule(logModuleId).getClassLoader(); - try { - /* - * The original code simply sets the thread context classloader and lets LogManager - * load the class. This causes problems in tests because any other component that - * also happens to use JDK logging will have potentially loaded a *different* - * LogManager. - * If you force the JBoss LogManager to be loaded (by setting the 'java.util.logging.manager' - * system property) earlier in the test run, it will not be loaded by the correct - * classloader and cause ClassCastExceptions. - */ - LogManager jbossLogManager = (LogManager) logModuleClassLoader.loadClass("org.jboss.logmanager.LogManager").newInstance(); - ObjectFields.set("manager", null, jbossLogManager, LogManager.class); - ObjectFields.set("readPrimordialConfiguration", jbossLogManager, false, LogManager.class); - - if (LogManager.getLogManager().getClass() == LogManager.class) { - System.err.println("WARNING: Failed to load the specified logmodule " + logModuleId); - } else { - Module.setModuleLogger(new JDKModuleLogger()); - } - } catch (Exception exception) { - // copied from LogManager - System.err.println("Could not load Logmanager \"org.jboss.logmanager.LogManager\""); - exception.printStackTrace(); - } - - __redirected.__JAXPRedirected.changeAll(ModuleIdentifier.fromString("javax.xml.jaxp-provider"), moduleLoader); - - return EmbeddedServerFactory.create(moduleLoader, jbossHomeDir, systemProps, systemEnv); - } - catch (ModuleLoadException e) { - throw new RuntimeException(e); - } - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java b/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java deleted file mode 100644 index 031bb199fc..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.util.Map; -import java.util.Properties; - -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector; -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector.Credential; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code CredentialsCollector} - * - * @author Andrew Phillips - */ -@Test(groups = "unit") -public class CredentialsCollectorTest { - private CredentialsCollector collector = new CredentialsCollector(); - - public void testEmptyProperties() { - assertTrue(collector.apply(new Properties()).isEmpty(), - "Expected returned map to be empty"); - } - - public void testNoCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("not-an-identity", - "v1", "not-a-credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - private static Properties propertiesOf(Map entries) { - Properties properties = new Properties(); - properties.putAll(entries); - return properties; - } - - public void testNonMatchingCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("non_matching.identity", "v1", - "non_matching.credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - public void testIncompleteCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("acme.identity", "v1", - "acme-2.credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - public void testCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("acme.identity", "v1", - "acme.credential", "v2", "acme-2.identity", "v3", - "acme-2.credential", "v4")); - assertEquals(collector.apply(properties), - ImmutableMap.of("acme", new Credential("v1", "v2"), - "acme-2", new Credential("v3", "v4"))); - } -} \ No newline at end of file diff --git a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java b/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java deleted file mode 100644 index 1c93403650..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; -import org.testng.collections.Maps; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - -/** - * Tests behavior of {@code AddTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class AddTweetsControllerTest { - - Map createServices(String container) throws InterruptedException, - ExecutionException { - Map services = Maps.newHashMap(); - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - for (String name : new String[] { "1", "2" }) { - BlobStoreContext context = ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class); - context.getAsyncBlobStore().createContainerInLocation(null, container).get(); - Blob blob = context.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - context.getAsyncBlobStore().putBlob(container, blob).get(); - services.put(name, context); - } - return services; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - String container = "container"; - Map contexts = createServices(container); - - ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container); - AddTweetsController controller = new AddTweetsController(contexts, function); - List list = controller.apply(ImmutableSet.of("1", "2")); - assertEquals(list.size(), 2); - assertEquals(list, ImmutableList.of(new StoredTweetStatus("1", "localhost", container, "1", - "frank", "I love beans!", null), new StoredTweetStatus("2", "localhost", container, - "1", "frank", "I love beans!", null))); - - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java b/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java deleted file mode 100644 index 81f0b9f3c7..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code AddTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class ClearTweetsControllerTest { - - Map createBlobStores(String container) throws InterruptedException, ExecutionException { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - for (BlobStoreContext blobstore : contexts.values()) { - blobstore.getBlobStore().createContainerInLocation(null, container); - Blob blob = blobstore.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - blobstore.getBlobStore().putBlob(container, blob); - } - return contexts; - } - - public void testClearTweets() throws IOException, InterruptedException, ExecutionException { - String container = ClearTweetsControllerTest.class.getName() + "#container"; - Map contexts = createBlobStores(container); - - ClearTweetsController controller = new ClearTweetsController(contexts, - container); - controller.clearContainer("test1"); - controller.clearContainer("test2"); - - for (BlobStoreContext context : contexts.values()) { - assertEquals(context.getBlobStore().countBlobs(container), 0, context.toString()); - } - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java b/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java deleted file mode 100644 index 3c5e5b1d80..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.easymock.EasyMock.*; - -import java.net.URI; -import java.util.Map; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.demo.paas.RunnableHttpRequest; -import org.jclouds.demo.paas.RunnableHttpRequest.Factory; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.http.HttpRequest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; - -/** - * Tests behavior of {@code EnqueueStoresController} - * - * @author Andrew Phillips - */ -@Test(groups = "unit") -public class EnqueueStoresControllerTest { - - Map createBlobStores() { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - return contexts; - } - - public void testEnqueueStores() { - Map stores = createBlobStores(); - TaskQueue taskQueue = createMock(TaskQueue.class); - Factory httpRequestFactory = createMock(Factory.class); - EnqueueStoresController function = new EnqueueStoresController(stores, - taskQueue, "http://localhost:8080"); - - expect(taskQueue.getHttpRequestFactory()).andStubReturn(httpRequestFactory); - - HttpRequest storeInTest1Request = HttpRequest.builder().endpoint( - URI.create("http://localhost:8080/store/do")) - .headers(ImmutableMultimap.of("context", "test1")).method("GET").build(); - RunnableHttpRequest storeInTest1Task = null; - expect(httpRequestFactory.create(eq(storeInTest1Request))).andReturn(storeInTest1Task); - - HttpRequest storeInTest2Request = HttpRequest.builder().endpoint( - URI.create("http://localhost:8080/store/do")) - .headers(ImmutableMultimap.of("context", "test2")).method("GET").build(); - RunnableHttpRequest storeInTest2Task = null; - expect(httpRequestFactory.create(eq(storeInTest2Request))).andReturn(storeInTest2Task); - - taskQueue.add(storeInTest1Task); - expectLastCall(); - taskQueue.add(storeInTest2Task); - expectLastCall(); - replay(httpRequestFactory, taskQueue); - - function.enqueueStoreTweetTasks(); - - verify(taskQueue); - } -} \ No newline at end of file diff --git a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java b/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java deleted file mode 100644 index 2ac448103b..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.util.Strings2; -import org.testng.annotations.Test; - -import twitter4j.Status; -import twitter4j.Twitter; -import twitter4j.User; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code StoreTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class StoreTweetsControllerTest { - - Twitter createTwitter() { - return createMock(Twitter.class); - } - - Map createBlobStores() throws InterruptedException, ExecutionException { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - for (BlobStoreContext blobstore : contexts.values()) { - blobstore.getAsyncBlobStore().createContainerInLocation(null, "favo").get(); - } - return contexts; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - Map stores = createBlobStores(); - StoreTweetsController function = new StoreTweetsController(stores, "favo", createTwitter()); - - User frank = createMock(User.class); - expect(frank.getScreenName()).andReturn("frank").atLeastOnce(); - - Status frankStatus = createMock(Status.class); - expect(frankStatus.getId()).andReturn(1l).atLeastOnce(); - expect(frankStatus.getUser()).andReturn(frank).atLeastOnce(); - expect(frankStatus.getText()).andReturn("I love beans!").atLeastOnce(); - - User jimmy = createMock(User.class); - expect(jimmy.getScreenName()).andReturn("jimmy").atLeastOnce(); - - Status jimmyStatus = createMock(Status.class); - expect(jimmyStatus.getId()).andReturn(2l).atLeastOnce(); - expect(jimmyStatus.getUser()).andReturn(jimmy).atLeastOnce(); - expect(jimmyStatus.getText()).andReturn("cloud is king").atLeastOnce(); - - replay(frank); - replay(frankStatus); - replay(jimmy); - replay(jimmyStatus); - - function.addMyTweets("test1", ImmutableList.of(frankStatus, jimmyStatus)); - function.addMyTweets("test2", ImmutableList.of(frankStatus, jimmyStatus)); - - verify(frank); - verify(frankStatus); - verify(jimmy); - verify(jimmyStatus); - - for (Entry entry : stores.entrySet()) { - BlobMap map = entry.getValue().createBlobMap("favo"); - Blob frankBlob = map.get("1"); - assertEquals(frankBlob.getMetadata().getName(), "1"); - assertEquals(frankBlob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME), "frank"); - assertEquals(frankBlob.getMetadata().getContentMetadata().getContentType(), "text/plain"); - assertEquals(Strings2.toString(frankBlob.getPayload()), "I love beans!"); - - Blob jimmyBlob = map.get("2"); - assertEquals(jimmyBlob.getMetadata().getName(), "2"); - assertEquals(jimmyBlob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME), "jimmy"); - assertEquals(jimmyBlob.getMetadata().getContentMetadata().getContentType(), "text/plain"); - assertEquals(Strings2.toString(jimmyBlob.getPayload()), "cloud is king"); - } - - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java b/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java deleted file mode 100644 index aab06ec0b6..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; - -/** - * Tests behavior of {@code KeyToStoredTweetStatus} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class KeyToStoredTweetStatusTest { - - BlobMap createMap() throws InterruptedException, ExecutionException { - BlobStoreContext context = - ContextBuilder.newBuilder(TransientApiMetadata.builder().build()).build(BlobStoreContext.class); - context.getBlobStore().createContainerInLocation(null, "test1"); - return context.createBlobMap("test1"); - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - BlobMap map = createMap(); - Blob blob = map.blobBuilder().name("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - map.put("1", blob); - String host = "localhost"; - String service = "stub"; - String container = "tweetstore"; - - KeyToStoredTweetStatus function = new KeyToStoredTweetStatus(map, service, host, container); - StoredTweetStatus result = function.apply("1"); - - StoredTweetStatus expected = new StoredTweetStatus(service, host, container, "1", "frank", - "I love beans!", null); - - assertEquals(result, expected); - - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java b/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java deleted file mode 100644 index 5fec52711e..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; -import org.testng.collections.Maps; - -import com.google.common.collect.Iterables; - -/** - * Tests behavior of {@code ServiceToStoredTweetStatuses} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class ServiceToStoredTweetStatusesTest { - - Map createServices(String container) throws InterruptedException, - ExecutionException { - Map services = Maps.newHashMap(); - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - for (String name : new String[] { "1", "2" }) { - BlobStoreContext context = ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class); - context.getAsyncBlobStore().createContainerInLocation(null, container).get(); - Blob blob = context.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - context.getAsyncBlobStore().putBlob(container, blob).get(); - services.put(name, context); - } - return services; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - String container = "container"; - Map contexts = createServices(container); - - ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container); - - assertEquals(Iterables.getLast(function.apply("1")), new StoredTweetStatus("1", "localhost", - container, "1", "frank", "I love beans!", null)); - - assertEquals(Iterables.getLast(function.apply("2")), new StoredTweetStatus("2", "localhost", - container, "1", "frank", "I love beans!", null)); - - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/RhcloudServer.java b/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/RhcloudServer.java deleted file mode 100644 index 07b695ab65..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/RhcloudServer.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration; - -import static com.google.common.collect.Iterables.find; -import static com.google.common.io.Closeables.closeQuietly; -import static java.lang.String.format; -import static org.jclouds.demo.tweetstore.integration.util.Zips.zipDir; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Properties; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; - -import org.jboss.as.controller.client.helpers.standalone.DeploymentAction; -import org.jboss.as.controller.client.helpers.standalone.DeploymentPlan; -import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentActionResult; -import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentManager; -import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentPlanResult; -import org.jboss.as.embedded.EmbeddedServerFactory2; -import org.jboss.as.embedded.ServerStartException; -import org.jboss.as.embedded.StandaloneServer; - -import com.google.common.base.Predicate; -import com.google.common.io.Files; - -/** - * Basic functionality to start a local JBoss AS 7 instance. - * - * @author Andrew Phillips - */ -public class RhcloudServer { - private static final byte[] CONTEXT_ROOT_XML_BYTES = - "/".getBytes(); - - protected StandaloneServer server; - protected ServerDeploymentManager manager; - - public void writePropertiesAndStartServer(String warfile, - String serverHome, Properties props) throws IOException, - ServerStartException, InterruptedException, ExecutionException { - String propsfile = String.format("%1$s/WEB-INF/jclouds.properties", warfile); - System.err.println("file: " + propsfile); - storeProperties(propsfile, props); - assert new File(propsfile).exists(); - - // in OpenShift, TweetStore runs at the server root - String ctxrootfile = String.format("%1$s/WEB-INF/jboss-web.xml", warfile); - System.err.println("file: " + ctxrootfile); - Files.write(CONTEXT_ROOT_XML_BYTES, new File(ctxrootfile)); - assert new File(ctxrootfile).exists(); - - server = EmbeddedServerFactory2.create(new File(serverHome), System.getProperties(), System.getenv()); - server.start(); - TimeUnit.SECONDS.sleep(30); - manager = ServerDeploymentManager.Factory.create(server.getModelControllerClient()); - ServerDeploymentActionResult deploymentResult = deploy(warfile); - System.err.println("deployment result: " + deploymentResult.getResult()); - } - - private static void storeProperties(String filename, Properties props) - throws IOException { - FileOutputStream targetFile = new FileOutputStream(filename); - try { - props.store(targetFile, "test"); - } finally { - closeQuietly(targetFile); - } - } - - protected ServerDeploymentActionResult deploy(String explodedWar) - throws IOException, InterruptedException, ExecutionException { - File war = zipDir(explodedWar, format("%s-rhcloud.war", explodedWar)); - final String deploymentName = war.getName(); - - DeploymentPlan plan = - manager.newDeploymentPlan().add(deploymentName, war).andDeploy().build(); - ServerDeploymentPlanResult deploymentResult = manager.execute(plan).get(); - return deploymentResult.getDeploymentActionResult(find( - plan.getDeploymentActions(), new Predicate() { - @Override - public boolean apply(DeploymentAction input) { - return input.getDeploymentUnitUniqueName().equals(deploymentName); - } - }).getId()); - } - - public void stop() throws Exception { - server.stop(); - } -} \ No newline at end of file diff --git a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java b/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java deleted file mode 100644 index 30dc27c70f..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java +++ /dev/null @@ -1,238 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.demo.paas.RunnableHttpRequest.PLATFORM_REQUEST_ORIGINATOR_HEADER; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -import org.jclouds.Context; -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.controller.StoreTweetsController; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.AuthorizationException; -import org.jclouds.util.Strings2; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - -import twitter4j.ResponseList; -import twitter4j.Status; -import twitter4j.Twitter; -import twitter4j.TwitterException; -import twitter4j.TwitterFactory; -import twitter4j.conf.Configuration; -import twitter4j.conf.ConfigurationBuilder; - -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.inject.Module; - -/** - * Starts up a JBoss AS 7 server (simulating OpenShift Express) and deploys - * an application which tests accesses twitter and blobstores. - * - * @author Andrew Phillips - */ -@Test(groups = "live", singleThreaded = true) -public class TweetStoreLiveTest { - - RhcloudServer server; - private URL url; - private Map contexts; - private String container; - private static final Iterable blobstores = - Splitter.on(',').split(getRequiredSystemProperty(PROPERTY_TWEETSTORE_BLOBSTORES)); - private static final Properties props = new Properties(); - - @BeforeTest - void clearAndCreateContainers() throws InterruptedException, ExecutionException, TimeoutException, IOException, - TwitterException { - container = getRequiredSystemProperty(PROPERTY_TWEETSTORE_CONTAINER); - - props.setProperty(PROPERTY_TWEETSTORE_CONTAINER, container); - - // put all identity/credential pairs into the client - addCredentialsForBlobStores(props); - - // example of an ad-hoc client configuration - addConfigurationForTwitter(props); - - // for testing, capture logs. - final Set wiring = ImmutableSet. of(new Log4JLoggingModule()); - this.contexts = Maps.newConcurrentMap(); - - for (String provider : blobstores) { - contexts.put(provider, ContextBuilder.newBuilder(provider) - .modules(wiring).overrides(props).build(BlobStoreContext.class)); - } - - Configuration conf = new ConfigurationBuilder() - .setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY)) - .setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET)) - .setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN)) - .setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET)) - .build(); - Twitter client = new TwitterFactory(conf).getInstance(); - StoreTweetsController controller = new StoreTweetsController(contexts, container, client); - - ResponseList statuses = client.getMentions(); - - boolean deleted = false; - for (BlobStoreContext context : contexts.values()) { - try { - if (context.getBlobStore().containerExists(container)) { - System.err.printf("deleting container %s at %s%n", container, - context.unwrap(Context.class).getProviderMetadata().getEndpoint()); - context.getBlobStore().deleteContainer(container); - deleted = true; - } - } catch (AuthorizationException e) { - throw new AuthorizationException("for context: " + context, e); - } - } - if (deleted) { - System.err.println("sleeping 60 seconds to allow containers to clear"); - Thread.sleep(60000); - } - for (BlobStoreContext context : contexts.values()) { - System.err.printf("creating container %s at %s%n", container, - context.unwrap(Context.class).getProviderMetadata().getEndpoint()); - context.getBlobStore().createContainerInLocation(null, container); - } - - if (deleted) { - System.err.println("sleeping 5 seconds to allow containers to create"); - Thread.sleep(5000); - } - - for (Entry entry : contexts.entrySet()) { - System.err.printf("filling container %s at %s%n", container, entry.getKey()); - controller.addMyTweets(entry.getKey(), statuses); - } - } - - private static String getRequiredSystemProperty(String key) { - return checkNotNull(System.getProperty(key), key); - } - - private void addConfigurationForTwitter(Properties props) { - props.setProperty(PROPERTY_TWITTER_CONSUMER_KEY, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_KEY)); - props.setProperty(PROPERTY_TWITTER_CONSUMER_SECRET, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_SECRET)); - props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN)); - props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN_SECRET)); - } - - private void addCredentialsForBlobStores(Properties props) { - for (String provider : blobstores) { - props.setProperty(provider + ".identity", - getRequiredSystemProperty("test." + provider + ".identity")); - props.setProperty(provider + ".credential", - getRequiredSystemProperty("test." + provider + ".credential")); - } - } - - @BeforeTest(dependsOnMethods = "clearAndCreateContainers") - @Parameters({ "warfile", "jboss.address", "jboss.port", "jboss.home" }) - public void startDevAppServer(final String warfile, final String address, final String port, - String serverHome) throws Exception { - url = new URL(String.format("http://%s:%s", address, port)); - - server = new RhcloudServer(); - server.writePropertiesAndStartServer(warfile, serverHome, props); - } - - @Test - public void shouldPass() throws InterruptedException, IOException { - InputStream i = url.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Welcome") >= 0 : string; - } - - @Test(dependsOnMethods = "shouldPass", expectedExceptions = IOException.class) - public void shouldFail() throws InterruptedException, IOException { - new URL(url, "/store/do").openStream(); - } - - @Test(dependsOnMethods = "shouldFail") - public void testPrimeContainers() throws IOException, InterruptedException { - URL gurl = new URL(url, "/store/do"); - - for (String context : blobstores) { - System.out.println("storing at context: " + context); - HttpURLConnection connection = (HttpURLConnection) gurl.openConnection(); - connection.addRequestProperty(PLATFORM_REQUEST_ORIGINATOR_HEADER, "taskqueue-twitter"); - connection.addRequestProperty("context", context); - InputStream i = connection.getInputStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Done!") >= 0 : string; - connection.disconnect(); - } - - System.err.println("sleeping 20 seconds to allow for eventual consistency delay"); - Thread.sleep(20000); - for (BlobStoreContext context : contexts.values()) { - assert context.createInputStreamMap(container).size() > 0 : context.unwrap(Context.class).getProviderMetadata().getEndpoint(); - } - } - - @Test(invocationCount = 5, dependsOnMethods = "testPrimeContainers") - public void testSerial() throws InterruptedException, IOException { - URL gurl = new URL(url, "/tweets/get"); - InputStream i = gurl.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Tweets in Clouds") >= 0 : string; - } - - @Test(invocationCount = 10, dependsOnMethods = "testPrimeContainers", threadPoolSize = 3) - public void testParallel() throws InterruptedException, IOException { - URL gurl = new URL(url, "/tweets/get"); - InputStream i = gurl.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Tweets in Clouds") >= 0 : string; - } - - @AfterTest - public void stopDevAppServer() throws Exception { - server.stop(); - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/ObjectFields.java b/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/ObjectFields.java deleted file mode 100644 index 8c4edd5ea9..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/ObjectFields.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration.util; - -import java.lang.reflect.Field; - -public class ObjectFields { - - private static Field getAccessibleField(String name, Class declaringClass) throws SecurityException, NoSuchFieldException { - Field field = declaringClass.getDeclaredField(name); - field.setAccessible(true); - return field; - } - - public static void set(String fieldName, Object target, Object value) { - set(fieldName, target, value, target.getClass()); - } - - public static void set(String fieldName, Object target, Object value, - Class fieldDeclaringClass) { - try { - getAccessibleField(fieldName, fieldDeclaringClass).set(target, value); - } catch (Exception exception) { - throw new IllegalArgumentException(exception); - } - } -} diff --git a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/Zips.java b/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/Zips.java deleted file mode 100644 index 571c9083a3..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/Zips.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration.util; - -import java.io.File; -import java.io.IOException; - -import org.codehaus.plexus.archiver.zip.ZipArchiver; - -public class Zips { - - public static File zipDir(String dirToZip, String zipFile) throws IOException { - ZipArchiver archiver = new ZipArchiver(); - archiver.addDirectory(new File(dirToZip)); - File zip = new File(zipFile); - archiver.setDestFile(zip); - archiver.createArchive(); - return zip; - } -} \ No newline at end of file diff --git a/demos/tweetstore/rhcloud-tweetstore/src/test/resources/jbossas7/configuration/standalone.xml b/demos/tweetstore/rhcloud-tweetstore/src/test/resources/jbossas7/configuration/standalone.xml deleted file mode 100644 index dcdf6049b6..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/test/resources/jbossas7/configuration/standalone.xml +++ /dev/null @@ -1,208 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - jdbc:h2:${jboss.server.data.dir}/test;DB_CLOSE_DELAY=-1 - h2 - - - sa - sa - - - - - - - jdbc:mysql://${OPENSHIFT_DB_HOST}:${OPENSHIFT_DB_PORT}/${OPENSHIFT_APP_NAME} - mysql - - ${OPENSHIFT_DB_USERNAME} - ${OPENSHIFT_DB_PASSWORD} - - - - - org.h2.jdbcx.JdbcDataSource - - - com.mysql.jdbc.jdbc2.optional.MysqlXADataSource - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/demos/tweetstore/rhcloud-tweetstore/src/test/resources/log4j.xml b/demos/tweetstore/rhcloud-tweetstore/src/test/resources/log4j.xml deleted file mode 100644 index 2e5d01fb9e..0000000000 --- a/demos/tweetstore/rhcloud-tweetstore/src/test/resources/log4j.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/demos/tweetstore/runatcloud-tweetstore/README.txt b/demos/tweetstore/runatcloud-tweetstore/README.txt deleted file mode 100644 index 5488f63442..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/README.txt +++ /dev/null @@ -1,52 +0,0 @@ -==== - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. -==== - -A guide to generating Twitter consumer keys and access tokens is at http://tinyurl.com/2fhebgb - -Please modify your maven settings.xml like below before attempting to run 'mvn -Plive install' - - - cloudbees - - true - - - yourapikey - yoursecret - - - - - keys - - true - - - YOUR_ACCESS_KEY_ID - YOUR_SECRET_KEY - YOUR_USER - YOUR_HEX_KEY - YOUR_ACCOUNT - YOUR_BASE64_ENCODED_KEY - YOUR_TWITTER_CONSUMER_KEY - YOUR_TWITTER_CONSUMER_SECRET - YOUR_TWITTER_ACCESSTOKEN - YOUR_TWITTER_ACCESSTOKEN_SECRET - - \ No newline at end of file diff --git a/demos/tweetstore/runatcloud-tweetstore/pom.xml b/demos/tweetstore/runatcloud-tweetstore/pom.xml deleted file mode 100644 index d42f983232..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/pom.xml +++ /dev/null @@ -1,164 +0,0 @@ - - - - 4.0.0 - - org.jclouds - jclouds-demos-tweetstore-project - 1.6.0-SNAPSHOT - - jclouds-demo-runatcloud-tweetstore - war - jclouds TweetStore for RUN@cloud - jclouds TweetStore for CloudBees' RUN@cloud using Guice for Dependency Injection - - - jclouds/tweetstore - - tweetstore - localhost - 8088 - jclouds-runatcloud-tweetstore - - - - - com.google.inject.extensions - guice-servlet - 3.0 - - - org.quartz-scheduler - quartz - 2.1.3 - - - org.slf4j - slf4j-api - - - - - - - net.stax - stax-appserver - 1.0.20110131-SNAPSHOT - test - - - - - - - bees-snapshots - http://repository-cloudbees.forge.cloudbees.com/public-snapshot - - false - - - true - - - - - - - live - - - - maven-surefire-plugin - - - integration - integration-test - - test - - - - ${test.twitter.runatcloud-tweetstore.consumer.identity} - ${test.twitter.runatcloud-tweetstore.consumer.credential} - ${test.twitter.runatcloud-tweetstore.access.identity} - ${test.twitter.runatcloud-tweetstore.access.credential} - ${test.azureblob.identity} - ${test.azureblob.credential} - ${test.cloudfiles-us.identity} - ${test.cloudfiles-us.credential} - ${test.aws-s3.identity} - ${test.aws-s3.credential} - ${test.cloudonestorage.identity} - ${test.cloudonestorage.credential} - ${test.ninefold-storage.identity} - ${test.ninefold-storage.credential} - ${test.bees.address} - ${test.bees.port} - ${jclouds.tweetstore.blobstores} - - test.${jclouds.tweetstore.container}2 - ${project.build.directory}/bees - ${project.build.directory}/${project.artifactId} - - - - - - - - - - - deploy - - - runatcloud-tweetstore - - - - bees-snapshots - http://repository-cloudbees.forge.cloudbees.com/public-snapshot - - false - - - true - - - - - - - com.cloudbees - bees-maven-plugin - 1.0-SNAPSHOT - - run - ${bees.apikey} - ${bees.secret} - - - - - - - diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/PlatformServices.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/PlatformServices.java deleted file mode 100644 index 0997005157..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/PlatformServices.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.demo.paas.config.PlatformServicesInitializer.PLATFORM_SERVICES_ATTRIBUTE_NAME; - -import java.util.Map; - -import javax.servlet.ServletContext; - -import org.jclouds.demo.paas.service.scheduler.Scheduler; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.javax.annotation.Nullable; - -import com.google.common.collect.ImmutableMap; - -/** - * @author Andrew Phillips - */ -public class PlatformServices { - protected final String baseUrl; - protected final Scheduler scheduler; - private ImmutableMap taskQueues; - - public PlatformServices(String baseUrl, Scheduler scheduler, Map taskQueues) { - this.baseUrl = baseUrl; - this.scheduler = scheduler; - this.taskQueues = ImmutableMap.copyOf(taskQueues); - } - - public String getBaseUrl() { - return baseUrl; - } - - public Scheduler getScheduler() { - return scheduler; - } - - public @Nullable TaskQueue getTaskQueue(String name) { - return taskQueues.get(name); - } - - public static PlatformServices get(ServletContext context) { - return (PlatformServices) checkNotNull(context.getAttribute( - PLATFORM_SERVICES_ATTRIBUTE_NAME), PLATFORM_SERVICES_ATTRIBUTE_NAME); - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java deleted file mode 100644 index ad72a1a58d..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/RunnableHttpRequest.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas; - -import static java.lang.String.format; - -import org.jclouds.http.HttpCommand; -import org.jclouds.http.HttpCommandExecutorService; -import org.jclouds.http.HttpRequest; - -import com.google.common.collect.ImmutableMultimap; -import com.google.common.collect.Multimap; - -public class RunnableHttpRequest implements Runnable { - public static final String PLATFORM_REQUEST_ORIGINATOR_HEADER = "X-Platform-Originator"; - - public static Factory factory(HttpCommandExecutorService httpClient) { - return factory(httpClient, format("%s@%d", Factory.class.getName(), System.currentTimeMillis())); - } - - public static Factory factory(HttpCommandExecutorService httpClient, String originator) { - return new Factory(httpClient, originator); - } - - public static class Factory { - protected final HttpCommandExecutorService httpClient; - protected final String originator; - - private Factory(HttpCommandExecutorService httpClient, String originator) { - this.httpClient = httpClient; - this.originator = originator; - } - - public RunnableHttpRequest create(HttpRequest request) { - HttpRequest requestWithSubmitter = request.toBuilder() - .headers(copyOfWithEntry(request.getHeaders(), - PLATFORM_REQUEST_ORIGINATOR_HEADER, originator)).build(); - return new RunnableHttpRequest(httpClient, requestWithSubmitter); - } - - private static Multimap copyOfWithEntry( - Multimap multimap, K k1, V v1) { - return ImmutableMultimap.builder().putAll(multimap).put(k1, v1).build(); - } - } - - private final HttpCommandExecutorService httpClient; - private final HttpRequest request; - - private RunnableHttpRequest(HttpCommandExecutorService httpClient, HttpRequest request) { - this.httpClient = httpClient; - this.request = request; - } - - @Override - public void run() { - httpClient.submit(new ImmutableHttpCommand(request)); - } - - private class ImmutableHttpCommand implements HttpCommand { - private final HttpRequest request; - - public ImmutableHttpCommand(HttpRequest request) { - this.request = request; - } - - @Override - public void setException(Exception exception) { - } - - @Override - public void setCurrentRequest(HttpRequest request) { - } - - @Override - public boolean isReplayable() { - return false; - } - - @Override - public int incrementRedirectCount() { - return 0; - } - - @Override - public int incrementFailureCount() { - return 0; - } - - @Override - public int getRedirectCount() { - return 0; - } - - @Override - public int getFailureCount() { - return 0; - } - - @Override - public Exception getException() { - return null; - } - - @Override - public HttpRequest getCurrentRequest() { - return request; - } - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java deleted file mode 100644 index 5aa077b6cd..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/HttpClientModule.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.inject.name.Names.bindProperties; -import static org.jclouds.Constants.*; - -import java.util.Properties; - -import javax.servlet.ServletContext; -import javax.ws.rs.core.UriBuilder; - -import org.jclouds.demo.tweetstore.config.util.PropertiesLoader; - -import com.google.inject.AbstractModule; -import com.sun.jersey.api.uri.UriBuilderImpl; - -/** - * @author Andrew Phillips - */ -public class HttpClientModule extends AbstractModule { - private final ServletContext context; - - HttpClientModule(ServletContext context) { - this.context = context; - } - - @Override - protected void configure() { - // URL connection defaults - Properties toBind = defaultProperties(); - toBind.putAll(checkNotNull(new PropertiesLoader(context).get(), "properties")); - toBind.putAll(System.getProperties()); - bindProperties(binder(), toBind); - bind(UriBuilder.class).to(UriBuilderImpl.class); - } - - private static Properties defaultProperties() { - Properties props = new Properties(); - props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_CONTEXT, 20 + ""); - props.setProperty(PROPERTY_MAX_CONNECTIONS_PER_HOST, 0 + ""); - props.setProperty(PROPERTY_SO_TIMEOUT, 60000 + ""); - props.setProperty(PROPERTY_CONNECTION_TIMEOUT, 60000 + ""); - props.setProperty(PROPERTY_USER_THREADS, 0 + ""); - props.setProperty(PROPERTY_IO_WORKER_THREADS, 20 + ""); - return props; - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java deleted file mode 100644 index ee74adaf6e..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/config/PlatformServicesInitializer.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static java.util.concurrent.TimeUnit.SECONDS; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.demo.paas.PlatformServices; -import org.jclouds.demo.paas.service.scheduler.Scheduler; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.http.HttpCommandExecutorService; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; -import com.google.inject.Guice; - -/** - * @author Andrew Phillips - */ -public class PlatformServicesInitializer implements ServletContextListener { - public static final String PLATFORM_SERVICES_ATTRIBUTE_NAME = PlatformServices.class.getName(); - - // keep in sync with cloudbees-web.xml - protected static final String HOST_PARAMETER = "application.host"; - - @Override - public void contextInitialized(ServletContextEvent contextEvent) { - ServletContext context = contextEvent.getServletContext(); - context.setAttribute(PLATFORM_SERVICES_ATTRIBUTE_NAME, createServices(context)); - } - - protected static PlatformServices createServices(ServletContext context) { - HttpCommandExecutorService httpClient = createHttpClient(context); - return new PlatformServices(getBaseUrl(context), new Scheduler(httpClient), - createTaskQueues(httpClient)); - } - - protected static HttpCommandExecutorService createHttpClient( - final ServletContext context) { - return Guice.createInjector(new ExecutorServiceModule(), - new JavaUrlHttpCommandExecutorServiceModule(), - new HttpClientModule(context)) - .getInstance(HttpCommandExecutorService.class); - } - - protected static String getBaseUrl(ServletContext context) { - return "http://" + checkNotNull(context.getInitParameter(HOST_PARAMETER), HOST_PARAMETER) - + context.getContextPath(); - } - - // TODO: make the number and names of queues configurable - protected static ImmutableMap createTaskQueues(HttpCommandExecutorService httpClient) { - Builder taskQueues = ImmutableMap.builder(); - taskQueues.put("twitter", TaskQueue.builder(httpClient) - .name("twitter").period(SECONDS.toMillis(30)) - .build()); - return taskQueues.build(); - } - - @Override - public void contextDestroyed(ServletContextEvent servletContextEvent) { - ServletContext context = servletContextEvent.getServletContext(); - context.removeAttribute(PLATFORM_SERVICES_ATTRIBUTE_NAME); - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java deleted file mode 100644 index 8af7021bd2..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/reference/PaasConstants.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.reference; - -/** - * Configuration properties and constants used in PaaS applications. - * - * @author Andrew Phillips - */ -public interface PaasConstants { - static final String PROPERTY_PLATFORM_BASE_URL = "jclouds.paas.baseurl"; -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/scheduler/HttpRequestJob.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/scheduler/HttpRequestJob.java deleted file mode 100644 index 902f5fe356..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/scheduler/HttpRequestJob.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.service.scheduler; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; - -import javax.servlet.ServletContext; - -import org.jclouds.demo.paas.PlatformServices; -import org.jclouds.demo.paas.RunnableHttpRequest; -import org.jclouds.http.HttpRequest; -import org.quartz.Job; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; -import org.quartz.SchedulerException; - -/** - * @author Andrew Phillips - */ -public class HttpRequestJob implements Job { - protected static final String URL_ATTRIBUTE_NAME = "url"; - - // keep in sync with "quartz:scheduler-context-servlet-context-key" param in web.xml - protected static final String SERVLET_CONTEXT_KEY = "servlet-context"; - - @Override - public void execute(JobExecutionContext context) throws JobExecutionException { - PlatformServices platform = JobContexts.getPlatform(context); - RunnableHttpRequest request = platform.getScheduler().getHttpRequestFactory().create( - HttpRequest.builder() - .endpoint(JobContexts.getTargetUrl(platform.getBaseUrl(), context)) - .method("GET").build()); - request.run(); - } - - private static class JobContexts { - private static URI getTargetUrl(String baseUrl, JobExecutionContext context) { - return URI.create(baseUrl + (String) checkNotNull( - context.getMergedJobDataMap().get(URL_ATTRIBUTE_NAME), URL_ATTRIBUTE_NAME)); - } - - private static PlatformServices getPlatform(JobExecutionContext jobContext) throws JobExecutionException { - try { - return PlatformServices.get((ServletContext) checkNotNull( - jobContext.getScheduler().getContext().get(SERVLET_CONTEXT_KEY), SERVLET_CONTEXT_KEY)); - } catch (SchedulerException exception) { - throw new JobExecutionException("Unable to get platform services from the job execution context", exception); - } - } - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/scheduler/Scheduler.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/scheduler/Scheduler.java deleted file mode 100644 index dabdff877b..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/scheduler/Scheduler.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.service.scheduler; - -import org.jclouds.demo.paas.RunnableHttpRequest; -import org.jclouds.demo.paas.RunnableHttpRequest.Factory; -import org.jclouds.http.HttpCommandExecutorService; - -/** - * @author Andrew Phillips - */ -public class Scheduler { - protected static final String SCHEDULER_ORIGINATOR_NAME = "scheduler"; - - protected final Factory httpRequestFactory; - - public Scheduler(HttpCommandExecutorService httpClient) { - httpRequestFactory = - RunnableHttpRequest.factory(httpClient, SCHEDULER_ORIGINATOR_NAME); - } - - public Factory getHttpRequestFactory() { - return httpRequestFactory; - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/scheduler/quartz/plugins/TransactionlessXmlSchedulingDataProcessorPlugin.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/scheduler/quartz/plugins/TransactionlessXmlSchedulingDataProcessorPlugin.java deleted file mode 100644 index b47f81dfad..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/scheduler/quartz/plugins/TransactionlessXmlSchedulingDataProcessorPlugin.java +++ /dev/null @@ -1,401 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.service.scheduler.quartz.plugins; - -import static org.quartz.SimpleScheduleBuilder.simpleSchedule; -import static org.quartz.TriggerBuilder.newTrigger; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.URL; -import java.net.URLDecoder; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; - -import org.jclouds.logging.Logger; -import org.quartz.JobBuilder; -import org.quartz.JobDetail; -import org.quartz.Scheduler; -import org.quartz.SchedulerException; -import org.quartz.SimpleTrigger; -import org.quartz.TriggerKey; -import org.quartz.jobs.FileScanJob; -import org.quartz.jobs.FileScanListener; -import org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin; -import org.quartz.simpl.CascadingClassLoadHelper; -import org.quartz.spi.ClassLoadHelper; -import org.quartz.spi.SchedulerPlugin; -import org.quartz.xml.XMLSchedulingDataProcessor; - -/** - * A copy of {@link XMLSchedulingDataProcessorPlugin} that does not reference - * {@code javax.transaction.UserTransaction} as so does not require a dependency - * on JTA. - * - * @author Andrew Phillips - * @see XMLSchedulingDataProcessorPlugin - */ -public class TransactionlessXmlSchedulingDataProcessorPlugin implements - FileScanListener, SchedulerPlugin { - - /* - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * - * Data members. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - */ - private static final int MAX_JOB_TRIGGER_NAME_LEN = 80; - private static final String JOB_INITIALIZATION_PLUGIN_NAME = "JobSchedulingDataLoaderPlugin"; - private static final String FILE_NAME_DELIMITERS = ","; - - private String name; - private Scheduler scheduler; - private final Logger log = Logger.CONSOLE; - - private boolean failOnFileNotFound = true; - - private String fileNames = XMLSchedulingDataProcessor.QUARTZ_XML_DEFAULT_FILE_NAME; - - // Populated by initialization - private Map jobFiles = new LinkedHashMap(); - - private long scanInterval = 0; - - boolean started = false; - - protected ClassLoadHelper classLoadHelper = null; - - private Set jobTriggerNameSet = new HashSet(); - - /* - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * - * Interface. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - */ - - /** - * Comma separated list of file names (with paths) to the XML files that should be read. - */ - public String getFileNames() { - return fileNames; - } - - /** - * The file name (and path) to the XML file that should be read. - */ - public void setFileNames(String fileNames) { - this.fileNames = fileNames; - } - - /** - * The interval (in seconds) at which to scan for changes to the file. - * If the file has been changed, it is re-loaded and parsed. The default - * value for the interval is 0, which disables scanning. - * - * @return Returns the scanInterval. - */ - public long getScanInterval() { - return scanInterval / 1000; - } - - /** - * The interval (in seconds) at which to scan for changes to the file. - * If the file has been changed, it is re-loaded and parsed. The default - * value for the interval is 0, which disables scanning. - * - * @param scanInterval The scanInterval to set. - */ - public void setScanInterval(long scanInterval) { - this.scanInterval = scanInterval * 1000; - } - - /** - * Whether or not initialization of the plugin should fail (throw an - * exception) if the file cannot be found. Default is true. - */ - public boolean isFailOnFileNotFound() { - return failOnFileNotFound; - } - - /** - * Whether or not initialization of the plugin should fail (throw an - * exception) if the file cannot be found. Default is true. - */ - public void setFailOnFileNotFound(boolean failOnFileNotFound) { - this.failOnFileNotFound = failOnFileNotFound; - } - - /* - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * - * SchedulerPlugin Interface. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - */ - - /** - *

- * Called during creation of the Scheduler in order to give - * the SchedulerPlugin a chance to initialize. - *

- * - * @throws org.quartz.SchedulerConfigException - * if there is an error initializing. - */ - @Override - public void initialize(String name, Scheduler scheduler) - throws SchedulerException { - this.name = name; - this.scheduler = scheduler; - - classLoadHelper = new CascadingClassLoadHelper(); - classLoadHelper.initialize(); - - log.info("Registering Quartz Job Initialization Plug-in."); - - // Create JobFile objects - StringTokenizer stok = new StringTokenizer(fileNames, FILE_NAME_DELIMITERS); - while (stok.hasMoreTokens()) { - final String fileName = stok.nextToken(); - final JobFile jobFile = new JobFile(fileName); - jobFiles.put(fileName, jobFile); - } - } - - @Override - public void start() { - try { - if (jobFiles.isEmpty() == false) { - - if (scanInterval > 0) { - scheduler.getContext().put(JOB_INITIALIZATION_PLUGIN_NAME + '_' + name, this); - } - - Iterator iterator = jobFiles.values().iterator(); - while (iterator.hasNext()) { - JobFile jobFile = iterator.next(); - - if (scanInterval > 0) { - String jobTriggerName = buildJobTriggerName(jobFile.getFileBasename()); - TriggerKey tKey = new TriggerKey(jobTriggerName, JOB_INITIALIZATION_PLUGIN_NAME); - - // remove pre-existing job/trigger, if any - scheduler.unscheduleJob(tKey); - - // TODO: convert to use builder - SimpleTrigger trig = newTrigger() - .withIdentity(jobTriggerName, JOB_INITIALIZATION_PLUGIN_NAME) - .startNow() - .endAt(null) - .withSchedule(simpleSchedule() - .repeatForever() - .withIntervalInMilliseconds(scanInterval)) - .build(); - - JobDetail job = JobBuilder.newJob(FileScanJob.class) - .withIdentity(jobTriggerName, JOB_INITIALIZATION_PLUGIN_NAME) - .build(); - job.getJobDataMap().put(FileScanJob.FILE_NAME, jobFile.getFileName()); - job.getJobDataMap().put(FileScanJob.FILE_SCAN_LISTENER_NAME, JOB_INITIALIZATION_PLUGIN_NAME + '_' + name); - - scheduler.scheduleJob(job, trig); - log.debug("Scheduled file scan job for data file: {}, at interval: {}", jobFile.getFileName(), scanInterval); - } - - processFile(jobFile); - } - } - } catch(SchedulerException se) { - log.error("Error starting background-task for watching jobs file.", se); - } finally { - started = true; - } - } - - /** - * Helper method for generating unique job/trigger name for the - * file scanning jobs (one per FileJob). The unique names are saved - * in jobTriggerNameSet. - */ - private String buildJobTriggerName( - String fileBasename) { - // Name w/o collisions will be prefix + _ + filename (with '.' of filename replaced with '_') - // For example: JobInitializationPlugin_jobInitializer_myjobs_xml - String jobTriggerName = JOB_INITIALIZATION_PLUGIN_NAME + '_' + name + '_' + fileBasename.replace('.', '_'); - - // If name is too long (DB column is 80 chars), then truncate to max length - if (jobTriggerName.length() > MAX_JOB_TRIGGER_NAME_LEN) { - jobTriggerName = jobTriggerName.substring(0, MAX_JOB_TRIGGER_NAME_LEN); - } - - // Make sure this name is unique in case the same file name under different - // directories is being checked, or had a naming collision due to length truncation. - // If there is a conflict, keep incrementing a _# suffix on the name (being sure - // not to get too long), until we find a unique name. - int currentIndex = 1; - while (jobTriggerNameSet.add(jobTriggerName) == false) { - // If not our first time through, then strip off old numeric suffix - if (currentIndex > 1) { - jobTriggerName = jobTriggerName.substring(0, jobTriggerName.lastIndexOf('_')); - } - - String numericSuffix = "_" + currentIndex++; - - // If the numeric suffix would make the name too long, then make room for it. - if (jobTriggerName.length() > (MAX_JOB_TRIGGER_NAME_LEN - numericSuffix.length())) { - jobTriggerName = jobTriggerName.substring(0, (MAX_JOB_TRIGGER_NAME_LEN - numericSuffix.length())); - } - - jobTriggerName += numericSuffix; - } - - return jobTriggerName; - } - - @Override - public void shutdown() { - // nothing to do - } - - private void processFile(JobFile jobFile) { - if (jobFile == null || !jobFile.getFileFound()) { - return; - } - - try { - XMLSchedulingDataProcessor processor = - new XMLSchedulingDataProcessor(this.classLoadHelper); - - processor.addJobGroupToNeverDelete(JOB_INITIALIZATION_PLUGIN_NAME); - processor.addTriggerGroupToNeverDelete(JOB_INITIALIZATION_PLUGIN_NAME); - - processor.processFileAndScheduleJobs( - jobFile.getFileName(), - jobFile.getFileName(), // systemId - scheduler); - } catch (Exception e) { - log.error("Error scheduling jobs: " + e.getMessage(), e); - } - } - - public void processFile(String filePath) { - processFile((JobFile)jobFiles.get(filePath)); - } - - /** - * @see org.quartz.jobs.FileScanListener#fileUpdated(java.lang.String) - */ - public void fileUpdated(String fileName) { - if (started) { - processFile(fileName); - } - } - - class JobFile { - private String fileName; - - // These are set by initialize() - private String filePath; - private String fileBasename; - private boolean fileFound; - - protected JobFile(String fileName) throws SchedulerException { - this.fileName = fileName; - initialize(); - } - - protected String getFileName() { - return fileName; - } - - protected boolean getFileFound() { - return fileFound; - } - - protected String getFilePath() { - return filePath; - } - - protected String getFileBasename() { - return fileBasename; - } - - private void initialize() throws SchedulerException { - InputStream f = null; - try { - String furl = null; - - File file = new File(getFileName()); // files in filesystem - if (!file.exists()) { - URL url = classLoadHelper.getResource(getFileName()); - if(url != null) { - try { - furl = URLDecoder.decode(url.getPath(), "UTF-8"); - } catch (UnsupportedEncodingException e) { - furl = url.getPath(); - } - file = new File(furl); - try { - f = url.openStream(); - } catch (IOException ignore) { - // Swallow the exception - } - } - } else { - try { - f = new java.io.FileInputStream(file); - }catch (FileNotFoundException e) { - // ignore - } - } - - if (f == null) { - if (isFailOnFileNotFound()) { - throw new SchedulerException( - "File named '" + getFileName() + "' does not exist."); - } else { - log.warn("File named '" + getFileName() + "' does not exist."); - } - } else { - fileFound = true; - } - filePath = (furl != null) ? furl : file.getAbsolutePath(); - fileBasename = file.getName(); - } finally { - try { - if (f != null) { - f.close(); - } - } catch (IOException ioe) { - log.warn("Error closing jobs file " + getFileName(), ioe); - } - } - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java deleted file mode 100644 index e317a305cf..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/paas/service/taskqueue/TaskQueue.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.paas.service.taskqueue; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static java.lang.String.format; - -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.TimeUnit; - -import org.jclouds.demo.paas.RunnableHttpRequest; -import org.jclouds.demo.paas.RunnableHttpRequest.Factory; -import org.jclouds.http.HttpCommandExecutorService; - -import com.google.inject.Provider; - -public class TaskQueue { - protected final Factory httpRequestFactory; - private final Timer timer; - private final ConcurrentLinkedQueue tasks = new ConcurrentLinkedQueue(); - - private TaskQueue(String name, long pollingIntervalMillis, Factory httpRequestFactory) { - this.httpRequestFactory = httpRequestFactory; - timer = new Timer(name); - timer.scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - Runnable task = tasks.poll(); - if (task != null) { - task.run(); - } - } - }, 0, pollingIntervalMillis); - } - - public void add(final Runnable task) { - tasks.add(task); - } - - public Factory getHttpRequestFactory() { - return httpRequestFactory; - } - - public void destroy() { - timer.cancel(); - tasks.clear(); - } - - public static Builder builder(HttpCommandExecutorService httpClient) { - return new Builder(httpClient); - } - - public static class Builder implements Provider { - protected final HttpCommandExecutorService httpClient; - protected String name = "default"; - protected long pollingIntervalMillis = TimeUnit.SECONDS.toMillis(1); - - private Builder(HttpCommandExecutorService httpClient) { - this.httpClient = checkNotNull(httpClient, "httpClient"); - } - - public Builder name(String name) { - this.name = checkNotNull(name, "name"); - return this; - } - - public Builder period(TimeUnit period) { - this.pollingIntervalMillis = checkNotNull(period, "period").toMillis(1); - return this; - } - - public Builder period(long pollingIntervalMillis) { - checkArgument(pollingIntervalMillis > 0, "pollingIntervalMillis"); - this.pollingIntervalMillis = pollingIntervalMillis; - return this; - } - - public TaskQueue build() { - return new TaskQueue(name, pollingIntervalMillis, - RunnableHttpRequest.factory(httpClient, format("taskqueue-%s", name))); - } - - @Override - public TaskQueue get() { - return build(); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java deleted file mode 100644 index c03434388a..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/GuiceServletConfig.java +++ /dev/null @@ -1,155 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Predicates.in; -import static com.google.common.collect.ImmutableSet.copyOf; -import static com.google.common.collect.Sets.filter; -import static org.jclouds.demo.paas.reference.PaasConstants.PROPERTY_PLATFORM_BASE_URL; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET; - -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.paas.PlatformServices; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector; -import org.jclouds.demo.tweetstore.config.util.PropertiesLoader; -import org.jclouds.demo.tweetstore.controller.AddTweetsController; -import org.jclouds.demo.tweetstore.controller.ClearTweetsController; -import org.jclouds.demo.tweetstore.controller.EnqueueStoresController; -import org.jclouds.demo.tweetstore.controller.StoreTweetsController; - -import twitter4j.Twitter; -import twitter4j.TwitterFactory; -import twitter4j.conf.Configuration; -import twitter4j.conf.ConfigurationBuilder; - -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Module; -import com.google.inject.TypeLiteral; -import com.google.inject.name.Names; -import com.google.inject.servlet.GuiceServletContextListener; -import com.google.inject.servlet.ServletModule; - -/** - * Setup Logging and create Injector for use in testing S3. - * - * @author Adrian Cole - */ -public class GuiceServletConfig extends GuiceServletContextListener { - private Map providerTypeToBlobStoreMap; - private Twitter twitterClient; - private String container; - private TaskQueue queue; - private String baseUrl; - - @Override - public void contextInitialized(ServletContextEvent servletContextEvent) { - ServletContext servletContext = servletContextEvent.getServletContext(); - - Properties props = new PropertiesLoader(servletContext).get(); - Set modules = ImmutableSet.of(); - // shared across all blobstores and used to retrieve tweets - try { - Configuration twitterConf = new ConfigurationBuilder() - .setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY)) - .setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET)) - .setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN)) - .setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET)) - .build(); - twitterClient = new TwitterFactory(twitterConf).getInstance(); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("properties for twitter not configured properly in " + props.toString(), e); - } - // common namespace for storing tweets - container = checkNotNull(props.getProperty(PROPERTY_TWEETSTORE_CONTAINER), PROPERTY_TWEETSTORE_CONTAINER); - - // instantiate and store references to all blobstores by provider name - providerTypeToBlobStoreMap = Maps.newHashMap(); - for (String hint : getBlobstoreContexts(props)) { - providerTypeToBlobStoreMap.put(hint, ContextBuilder.newBuilder(hint) - .modules(modules).overrides(props).build(BlobStoreContext.class)); - } - - // get a queue for submitting store tweet requests and the application's base URL - PlatformServices platform = PlatformServices.get(servletContext); - queue = platform.getTaskQueue("twitter"); - baseUrl = platform.getBaseUrl(); - - super.contextInitialized(servletContextEvent); - } - - private static Iterable getBlobstoreContexts(Properties props) { - Set contexts = new CredentialsCollector().apply(props).keySet(); - String explicitContexts = props.getProperty(PROPERTY_TWEETSTORE_BLOBSTORES); - if (explicitContexts != null) { - contexts = filter(contexts, in(copyOf(Splitter.on(',').split(explicitContexts)))); - } - checkState(!contexts.isEmpty(), "no credentials available for any requested context"); - return contexts; - } - - @Override - protected Injector getInjector() { - return Guice.createInjector(new ServletModule() { - @Override - protected void configureServlets() { - bind(new TypeLiteral>() {}) - .toInstance(providerTypeToBlobStoreMap); - bind(Twitter.class).toInstance(twitterClient); - bind(TaskQueue.class).toInstance(queue); - bindConstant().annotatedWith(Names.named(PROPERTY_PLATFORM_BASE_URL)) - .to(baseUrl); - bindConstant().annotatedWith(Names.named(PROPERTY_TWEETSTORE_CONTAINER)) - .to(container); - serve("/store/*").with(StoreTweetsController.class); - serve("/tweets/*").with(AddTweetsController.class); - serve("/stores/*").with(EnqueueStoresController.class); - serve("/clear/*").with(ClearTweetsController.class); - } - }); - } - - @Override - public void contextDestroyed(ServletContextEvent servletContextEvent) { - for (BlobStoreContext context : providerTypeToBlobStoreMap.values()) { - context.close(); - } - queue.destroy(); - super.contextDestroyed(servletContextEvent); - } -} \ No newline at end of file diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java deleted file mode 100644 index ce3943376e..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollector.java +++ /dev/null @@ -1,153 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Predicates.notNull; -import static com.google.common.collect.Collections2.filter; -import static com.google.common.collect.Collections2.transform; -import static com.google.common.collect.ImmutableSet.copyOf; -import static com.google.common.collect.Maps.filterValues; -import static org.jclouds.util.Maps2.fromKeys; - -import java.util.Collection; -import java.util.Map; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector.Credential; - -import com.google.common.annotations.GwtIncompatible; -import com.google.common.base.Function; -import com.google.common.base.Predicate; - -/** - * Reads provider credentials from a {@link Properties} bag. - * - * @author Andrew Phillips - * - */ -public class CredentialsCollector implements Function> { - private static final String IDENTITY_PROPERTY_SUFFIX = ".identity"; - private static final String CREDENTIAL_PROPERTY_SUFFIX = ".credential"; - - // using the identity for provider name extraction - private static final Pattern IDENTITY_PROPERTY_PATTERN = - Pattern.compile("([a-zA-Z0-9-]+)" + Pattern.quote(IDENTITY_PROPERTY_SUFFIX)); - - @Override - public Map apply(final Properties properties) { - Collection providerNames = transform( - filter(properties.stringPropertyNames(), MatchesPattern.matches(IDENTITY_PROPERTY_PATTERN)), - new Function() { - @Override - public String apply(String input) { - Matcher matcher = IDENTITY_PROPERTY_PATTERN.matcher(input); - // as a side-effect, sets the matching group! - checkState(matcher.matches(), "'%s' should match '%s'", input, IDENTITY_PROPERTY_PATTERN); - return matcher.group(1); - } - }); - /* - * Providers without a credential property result in null values, which are - * removed from the returned map. - */ - return filterValues(fromKeys(copyOf(providerNames), new Function() { - @Override - public Credential apply(String providerName) { - String identity = properties.getProperty(providerName + IDENTITY_PROPERTY_SUFFIX); - String credential = properties.getProperty(providerName + CREDENTIAL_PROPERTY_SUFFIX); - return (((identity != null) && (credential != null)) - ? new Credential(identity, credential) - : null); - } - }), notNull()); - } - - public static class Credential { - private final String identity; - private final String credential; - - public Credential(String identity, String credential) { - this.identity = checkNotNull(identity, "identity"); - this.credential = checkNotNull(credential, "credential"); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((credential == null) ? 0 : credential.hashCode()); - result = prime * result - + ((identity == null) ? 0 : identity.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; - Credential other = (Credential) obj; - if (credential == null) { - if (other.credential != null) - return false; - } else if (!credential.equals(other.credential)) - return false; - if (identity == null) { - if (other.identity != null) - return false; - } else if (!identity.equals(other.identity)) - return false; - return true; - } - - public String getIdentity() { - return identity; - } - - public String getCredential() { - return credential; - } - } - - @GwtIncompatible(value = "java.util.regex.Pattern") - private static class MatchesPattern implements Predicate { - private final Pattern pattern; - - private MatchesPattern(Pattern pattern) { - this.pattern = pattern; - } - - @Override - public boolean apply(String input) { - return pattern.matcher(input).matches(); - } - - private static MatchesPattern matches(Pattern pattern) { - return new MatchesPattern(pattern); - } - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java deleted file mode 100644 index dafa5c311b..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/config/util/PropertiesLoader.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import javax.servlet.ServletContext; - -import com.google.common.io.Closeables; -import com.google.inject.Provider; - -/** - * @author Andrew Phillips - */ -public class PropertiesLoader implements Provider{ - private static final String PROPERTIES_FILE = "/WEB-INF/jclouds.properties"; - - private final Properties properties; - - public PropertiesLoader(ServletContext context) { - properties = loadJcloudsProperties(context); - } - - private static Properties loadJcloudsProperties(ServletContext context) { - InputStream input = context.getResourceAsStream(PROPERTIES_FILE); - Properties props = new Properties(); - try { - props.load(input); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - Closeables.closeQuietly(input); - } - return props; - } - - @Override - public Properties get() { - return properties; - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java deleted file mode 100644 index 007fbafdef..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/AddTweetsController.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -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.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - -/** - * Shows an example of how to use @{link BlobStoreContext} injected with Guice. - * - * @author Adrian Cole - */ -@Singleton -public class AddTweetsController extends HttpServlet implements - Function, List> { - - /** The serialVersionUID */ - private static final long serialVersionUID = 3888348023150822683L; - private final Map contexts; - private final ServiceToStoredTweetStatuses blobStoreContextToContainerResult; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - AddTweetsController(Map contexts, - ServiceToStoredTweetStatuses blobStoreContextToContainerResult) { - this.contexts = contexts; - this.blobStoreContextToContainerResult = blobStoreContextToContainerResult; - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - try { - addMyTweetsToRequest(request); - RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/tweets.jsp"); - dispatcher.forward(request, response); - } catch (Exception e) { - logger.error(e, "Error listing containers"); - throw new ServletException(e); - } - } - - void addMyTweetsToRequest(HttpServletRequest request) throws InterruptedException, - ExecutionException, TimeoutException { - request.setAttribute("tweets", apply(contexts.keySet())); - } - - public List apply(Set in) { - List statuses = Lists.newArrayList(); - for (Iterable list : Iterables.transform(in, - blobStoreContextToContainerResult)) { - Iterables.addAll(statuses, list); - } - return statuses; - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java deleted file mode 100644 index e08cfbc19e..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/ClearTweetsController.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Strings.nullToEmpty; - -import java.io.IOException; -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; - -import com.google.common.annotations.VisibleForTesting; - -/** - * Grab tweets related to me and store them into blobstores - * - * @author Adrian Cole - */ -@Singleton -public class ClearTweetsController extends HttpServlet { - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Map contexts; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - @VisibleForTesting - public ClearTweetsController(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) { - this.container = container; - this.contexts = contexts; - } - - @VisibleForTesting - public void clearContainer(String contextName) { - BlobStoreContext context = checkNotNull(contexts.get(contextName), - "no context for %s in %s", contextName, contexts.keySet()); - try { - context.getBlobStore().clearContainer(container); - } catch (Exception e) { - logger.error(e, "Error clearing tweets in %s/%s", container, context); - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (nullToEmpty(request.getHeader("X-Originator")).equals("admin")) { - try { - String contextName = checkNotNull(request.getHeader("context"), "missing header context"); - logger.info("clearing tweets in %s/%s", container, contextName); - clearContainer(contextName); - logger.debug("done clearing tweets"); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error clearing tweets"); - throw new ServletException(e); - } - } else { - response.sendError(401); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java deleted file mode 100644 index 592eaaa8bd..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresController.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Strings.nullToEmpty; -import static org.jclouds.demo.paas.RunnableHttpRequest.PLATFORM_REQUEST_ORIGINATOR_HEADER; - -import java.io.IOException; -import java.net.URI; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.paas.reference.PaasConstants; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.http.HttpRequest; -import org.jclouds.logging.Logger; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableMultimap; - -/** - * Adds tasks to retrieve and store tweets in all registered contexts to an async - * task queue. - * - * @author Andrew Phillips - * @see StoreTweetsController - */ -@Singleton -public class EnqueueStoresController extends HttpServlet { - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Set contextNames; - private final TaskQueue taskQueue; - private final String baseUrl; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - public EnqueueStoresController(Map contexts, TaskQueue taskQueue, - @Named(PaasConstants.PROPERTY_PLATFORM_BASE_URL) String baseUrl) { - contextNames = contexts.keySet(); - this.taskQueue = taskQueue; - this.baseUrl = baseUrl; - } - - @VisibleForTesting - void enqueueStoreTweetTasks() { - for (String contextName : contextNames) { - logger.debug("enqueuing task to store tweets in blobstore '%s'", contextName); - taskQueue.add(taskQueue.getHttpRequestFactory().create(HttpRequest.builder() - .endpoint(URI.create(baseUrl + "/store/do")) - .headers(ImmutableMultimap.of("context", contextName)) - .method("GET").build())); - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (!nullToEmpty(request.getHeader(PLATFORM_REQUEST_ORIGINATOR_HEADER)).equals("scheduler")) { - response.sendError(401); - } - - try { - enqueueStoreTweetTasks(); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error storing tweets"); - throw new ServletException(e); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java deleted file mode 100644 index 948c9ff4ca..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/controller/StoreTweetsController.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Strings.nullToEmpty; -import static org.jclouds.demo.paas.RunnableHttpRequest.PLATFORM_REQUEST_ORIGINATOR_HEADER; - -import java.io.IOException; -import java.util.Map; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; -import org.jclouds.rest.AuthorizationException; - -import twitter4j.Status; -import twitter4j.Twitter; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; - -/** - * Grab tweets related to me and store them into blobstores - * - * @author Adrian Cole - */ -@Singleton -public class StoreTweetsController extends HttpServlet { - - private static final class StatusToBlob implements Function { - private final BlobMap map; - - private StatusToBlob(BlobMap map) { - this.map = map; - } - - public Blob apply(Status from) { - Blob to = map.blobBuilder().name(from.getId() + "").build(); - to.setPayload(from.getText()); - to.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN); - to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, from.getUser().getScreenName()); - return to; - } - } - - /** The serialVersionUID */ - private static final long serialVersionUID = 7215420527854203714L; - - private final Map contexts; - private final Twitter client; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - @Inject - @VisibleForTesting - public StoreTweetsController(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container, Twitter client) { - this.container = container; - this.contexts = contexts; - this.client = client; - } - - @VisibleForTesting - public void addMyTweets(String contextName, Iterable responseList) { - BlobStoreContext context = checkNotNull(contexts.get(contextName), "no context for " + contextName + " in " - + contexts.keySet()); - BlobMap map = context.createBlobMap(container); - for (Status status : responseList) { - Blob blob = null; - try { - blob = new StatusToBlob(map).apply(status); - map.put(status.getId() + "", blob); - } catch (AuthorizationException e) { - throw e; - } catch (Exception e) { - logger.error(e, "Error storing tweet %s (blob[%s]) on map %s/%s", status.getId(), blob, context, container); - } - } - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - if (nullToEmpty(request.getHeader(PLATFORM_REQUEST_ORIGINATOR_HEADER)).equals("taskqueue-twitter")) { - try { - String contextName = checkNotNull(request.getHeader("context"), "missing header context"); - logger.info("retrieving tweets"); - addMyTweets(contextName, client.getMentions()); - logger.debug("done storing tweets"); - response.setContentType(MediaType.TEXT_PLAIN); - response.getWriter().println("Done!"); - } catch (Exception e) { - logger.error(e, "Error storing tweets"); - throw new ServletException(e); - } - } else { - response.sendError(401); - } - } -} \ No newline at end of file diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java deleted file mode 100644 index 42ad65df01..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/domain/StoredTweetStatus.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.domain; - -import java.io.Serializable; - -/** - * - * @author Adrian Cole - */ -public class StoredTweetStatus implements Comparable, Serializable { - - /** The serialVersionUID */ - private static final long serialVersionUID = -3257496189689220018L; - private final String service; - private final String host; - private final String container; - private final String id; - private final String from; - private final String tweet; - private final String status; - - @Override - public String toString() { - return "StoredTweetStatus [container=" + container + ", from=" + from + ", host=" + host - + ", id=" + id + ", service=" + service + ", status=" + status + ", tweet=" + tweet - + "]"; - } - - public StoredTweetStatus(String service, String host, String container, String id, String from, - String tweet, String status) { - this.service = service; - this.host = host; - this.container = container; - this.id = id; - this.from = from; - this.tweet = tweet; - this.status = status; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((container == null) ? 0 : container.hashCode()); - result = prime * result + ((from == null) ? 0 : from.hashCode()); - result = prime * result + ((host == null) ? 0 : host.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((service == null) ? 0 : service.hashCode()); - result = prime * result + ((tweet == null) ? 0 : tweet.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; - StoredTweetStatus other = (StoredTweetStatus) obj; - if (container == null) { - if (other.container != null) - return false; - } else if (!container.equals(other.container)) - return false; - if (from == null) { - if (other.from != null) - return false; - } else if (!from.equals(other.from)) - return false; - if (host == null) { - if (other.host != null) - return false; - } else if (!host.equals(other.host)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (service == null) { - if (other.service != null) - return false; - } else if (!service.equals(other.service)) - return false; - if (tweet == null) { - if (other.tweet != null) - return false; - } else if (!tweet.equals(other.tweet)) - return false; - return true; - } - - - public String getService() { - return service; - } - - public String getHost() { - return host; - } - - public String getContainer() { - return container; - } - - public String getFrom() { - return from; - } - - public String getTweet() { - return tweet; - } - - public String getStatus() { - return status; - } - - public int compareTo(StoredTweetStatus o) { - if (id == null) - return -1; - return (int) ((this == o) ? 0 : id.compareTo(o.id)); - } - - - public String getId() { - return id; - } - -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java deleted file mode 100644 index f831b9780f..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatus.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import javax.annotation.Resource; - -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; -import org.jclouds.util.Strings2; - -import com.google.common.base.Function; - -/** - * - * @author Adrian Cole - */ -public class KeyToStoredTweetStatus implements Function { - private final String host; - private final BlobMap map; - private final String service; - private final String container; - - @Resource - protected Logger logger = Logger.NULL; - - KeyToStoredTweetStatus(BlobMap map, String service, String host, String container) { - this.host = host; - this.map = map; - this.service = service; - this.container = container; - } - - public StoredTweetStatus apply(String id) { - String status; - String from; - String tweet; - try { - long start = System.currentTimeMillis(); - Blob blob = map.get(id); - status = ((System.currentTimeMillis() - start) + "ms"); - from = blob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME); - tweet = Strings2.toString(blob.getPayload()); - } catch (Exception e) { - logger.error(e, "Error listing container %s//%s/%s", service, container, id); - status = (e.getMessage()); - tweet = ""; - from = ""; - } - return new StoredTweetStatus(service, host, container, id, from, tweet, status); - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java deleted file mode 100644 index b2e5884c55..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatuses.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import java.net.URI; -import java.util.Map; -import java.util.Set; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import org.jclouds.Context; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.logging.Logger; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; - -@Singleton -public class ServiceToStoredTweetStatuses implements Function> { - - private final Map contexts; - private final String container; - - @Inject - public ServiceToStoredTweetStatuses(Map contexts, - @Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) String container) { - this.contexts = contexts; - this.container = container; - } - - @Resource - protected Logger logger = Logger.NULL; - - public Iterable apply(String service) { - BlobStoreContext context = contexts.get(service); - String host = URI.create(context.unwrap(Context.class).getProviderMetadata().getEndpoint()).getHost(); - try { - BlobMap blobMap = context.createBlobMap(container); - Set blobs = blobMap.keySet(); - return Iterables.transform(blobs, new KeyToStoredTweetStatus(blobMap, service, host, - container)); - } catch (Exception e) { - StoredTweetStatus result = new StoredTweetStatus(service, host, container, null, null, - null, e.getMessage()); - logger.error(e, "Error listing service %s", service); - return ImmutableList.of(result); - } - - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java deleted file mode 100644 index 42ec480ae2..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TweetStoreConstants.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.reference; - -/** - * Configuration properties and constants used in TweetStore connections. - * - * @author Adrian Cole - */ -public interface TweetStoreConstants { - static final String PROPERTY_TWEETSTORE_BLOBSTORES = "jclouds.tweetstore.blobstores"; - static final String PROPERTY_TWEETSTORE_CONTAINER = "jclouds.tweetstore.container"; - /** - * Note that this has to conform to restrictions of all blobstores. for - * example, azure doesn't support periods. - */ - static final String SENDER_NAME = "sendername"; -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java b/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java deleted file mode 100644 index dc8b97915f..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/java/org/jclouds/demo/tweetstore/reference/TwitterConstants.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.reference; - -/** - * Configuration properties and constants used in Twitter connections. - * - * @author Andrew Phillips - */ -public interface TwitterConstants { - static final String PROPERTY_TWITTER_CONSUMER_KEY = "twitter.consumer.identity"; - static final String PROPERTY_TWITTER_CONSUMER_SECRET = "twitter.consumer.credential"; - static final String PROPERTY_TWITTER_ACCESSTOKEN = "twitter.access.identity"; - static final String PROPERTY_TWITTER_ACCESSTOKEN_SECRET = "twitter.access.credential"; -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/platform/cloudbees-web.xml b/demos/tweetstore/runatcloud-tweetstore/src/main/platform/cloudbees-web.xml deleted file mode 100644 index 3fb9478938..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/platform/cloudbees-web.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - ${bees.appid} - - - - application.host - ${test.bees.address}:${test.bees.port} - - - - - - - application.host - ${bees.apptitle}.jclouds.cloudbees.net - - - \ No newline at end of file diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/resources/jobs.xml b/demos/tweetstore/runatcloud-tweetstore/src/main/resources/jobs.xml deleted file mode 100644 index b740fdd52f..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/resources/jobs.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - enqueue-store-tweet-tasks - Enqueue 'store tweet' tasks for all contexts - org.jclouds.demo.paas.service.scheduler.HttpRequestJob - - - url - /stores/do - - - - - - - submit-recurring-job - enqueue-store-tweet-tasks - 10 - MINUTE - - - - \ No newline at end of file diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/resources/quartz.properties b/demos/tweetstore/runatcloud-tweetstore/src/main/resources/quartz.properties deleted file mode 100644 index 12a0fcfe91..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/resources/quartz.properties +++ /dev/null @@ -1,28 +0,0 @@ -#============================================================================ -# Configure Main Scheduler Properties -#============================================================================ - -org.quartz.scheduler.skipUpdateCheck: true - -#============================================================================ -# Configure ThreadPool -#============================================================================ - -org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool -org.quartz.threadPool.threadCount: 1 - -#============================================================================ -# Configure JobStore -#============================================================================ - -org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore - -#============================================================================ -# Configure the Job Initialization Plugin -#============================================================================ - -org.quartz.plugin.jobInitializer.class: org.jclouds.demo.paas.service.scheduler.quartz.plugins.TransactionlessXmlSchedulingDataProcessorPlugin -org.quartz.plugin.jobInitializer.fileNames: jobs.xml -org.quartz.plugin.jobInitializer.failOnFileNotFound: true -org.quartz.plugin.jobInitializer.scanInterval: 0 -#org.quartz.plugin.jobInitializer.wrapInUserTransaction: false \ No newline at end of file diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/webapp/WEB-INF/web.xml b/demos/tweetstore/runatcloud-tweetstore/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 9482bd9d9e..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - jclouds-tweetstore - - - quartz:scheduler-context-servlet-context-key - servlet-context - - - - - guiceFilter - com.google.inject.servlet.GuiceFilter - - - - guiceFilter - /* - - - - - org.jclouds.demo.paas.config.PlatformServicesInitializer - - - - org.quartz.ee.servlet.QuartzInitializerListener - - - - org.jclouds.demo.tweetstore.config.GuiceServletConfig - - - - index.jsp - - - \ No newline at end of file diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/webapp/index.jsp b/demos/tweetstore/runatcloud-tweetstore/src/main/webapp/index.jsp deleted file mode 100644 index d8d1724bcf..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/webapp/index.jsp +++ /dev/null @@ -1,31 +0,0 @@ -<%-- - - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. - ---%> - - -jclouds: anyweight cloudware for java - - -

Welcome!

-

Click here to see tweets about jclouds.

-

- - diff --git a/demos/tweetstore/runatcloud-tweetstore/src/main/webapp/tweets.jsp b/demos/tweetstore/runatcloud-tweetstore/src/main/webapp/tweets.jsp deleted file mode 100644 index 1b30f7ea11..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/main/webapp/tweets.jsp +++ /dev/null @@ -1,109 +0,0 @@ -<%-- - - Licensed to jclouds, Inc. (jclouds) under one or more - contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. jclouds 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. - ---%> -<%@ page buffer="20kb"%> -<%@ taglib uri="http://displaytag.sf.net" prefix="display"%> - - -jclouds: anyweight cloudware for java - - - -

Tweets in Clouds

- - - - - - - -
-
- - - - - - - - -
-
- - diff --git a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java b/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java deleted file mode 100644 index 031bb199fc..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/config/util/CredentialsCollectorTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.config.util; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.util.Map; -import java.util.Properties; - -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector; -import org.jclouds.demo.tweetstore.config.util.CredentialsCollector.Credential; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code CredentialsCollector} - * - * @author Andrew Phillips - */ -@Test(groups = "unit") -public class CredentialsCollectorTest { - private CredentialsCollector collector = new CredentialsCollector(); - - public void testEmptyProperties() { - assertTrue(collector.apply(new Properties()).isEmpty(), - "Expected returned map to be empty"); - } - - public void testNoCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("not-an-identity", - "v1", "not-a-credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - private static Properties propertiesOf(Map entries) { - Properties properties = new Properties(); - properties.putAll(entries); - return properties; - } - - public void testNonMatchingCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("non_matching.identity", "v1", - "non_matching.credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - public void testIncompleteCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("acme.identity", "v1", - "acme-2.credential", "v2")); - assertTrue(collector.apply(properties).isEmpty(), - "Expected returned map to be empty"); - } - - public void testCredentials() { - Properties properties = propertiesOf(ImmutableMap.of("acme.identity", "v1", - "acme.credential", "v2", "acme-2.identity", "v3", - "acme-2.credential", "v4")); - assertEquals(collector.apply(properties), - ImmutableMap.of("acme", new Credential("v1", "v2"), - "acme-2", new Credential("v3", "v4"))); - } -} \ No newline at end of file diff --git a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java b/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java deleted file mode 100644 index 1c93403650..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/AddTweetsControllerTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; -import org.testng.collections.Maps; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; - -/** - * Tests behavior of {@code AddTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class AddTweetsControllerTest { - - Map createServices(String container) throws InterruptedException, - ExecutionException { - Map services = Maps.newHashMap(); - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - for (String name : new String[] { "1", "2" }) { - BlobStoreContext context = ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class); - context.getAsyncBlobStore().createContainerInLocation(null, container).get(); - Blob blob = context.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - context.getAsyncBlobStore().putBlob(container, blob).get(); - services.put(name, context); - } - return services; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - String container = "container"; - Map contexts = createServices(container); - - ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container); - AddTweetsController controller = new AddTweetsController(contexts, function); - List list = controller.apply(ImmutableSet.of("1", "2")); - assertEquals(list.size(), 2); - assertEquals(list, ImmutableList.of(new StoredTweetStatus("1", "localhost", container, "1", - "frank", "I love beans!", null), new StoredTweetStatus("2", "localhost", container, - "1", "frank", "I love beans!", null))); - - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java b/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java deleted file mode 100644 index 81f0b9f3c7..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/ClearTweetsControllerTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code AddTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class ClearTweetsControllerTest { - - Map createBlobStores(String container) throws InterruptedException, ExecutionException { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - for (BlobStoreContext blobstore : contexts.values()) { - blobstore.getBlobStore().createContainerInLocation(null, container); - Blob blob = blobstore.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - blobstore.getBlobStore().putBlob(container, blob); - } - return contexts; - } - - public void testClearTweets() throws IOException, InterruptedException, ExecutionException { - String container = ClearTweetsControllerTest.class.getName() + "#container"; - Map contexts = createBlobStores(container); - - ClearTweetsController controller = new ClearTweetsController(contexts, - container); - controller.clearContainer("test1"); - controller.clearContainer("test2"); - - for (BlobStoreContext context : contexts.values()) { - assertEquals(context.getBlobStore().countBlobs(container), 0, context.toString()); - } - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java b/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java deleted file mode 100644 index 3c5e5b1d80..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/EnqueueStoresControllerTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.easymock.EasyMock.*; - -import java.net.URI; -import java.util.Map; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.demo.paas.RunnableHttpRequest; -import org.jclouds.demo.paas.RunnableHttpRequest.Factory; -import org.jclouds.demo.paas.service.taskqueue.TaskQueue; -import org.jclouds.http.HttpRequest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMultimap; - -/** - * Tests behavior of {@code EnqueueStoresController} - * - * @author Andrew Phillips - */ -@Test(groups = "unit") -public class EnqueueStoresControllerTest { - - Map createBlobStores() { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - return contexts; - } - - public void testEnqueueStores() { - Map stores = createBlobStores(); - TaskQueue taskQueue = createMock(TaskQueue.class); - Factory httpRequestFactory = createMock(Factory.class); - EnqueueStoresController function = new EnqueueStoresController(stores, - taskQueue, "http://localhost:8080"); - - expect(taskQueue.getHttpRequestFactory()).andStubReturn(httpRequestFactory); - - HttpRequest storeInTest1Request = HttpRequest.builder().endpoint( - URI.create("http://localhost:8080/store/do")) - .headers(ImmutableMultimap.of("context", "test1")).method("GET").build(); - RunnableHttpRequest storeInTest1Task = null; - expect(httpRequestFactory.create(eq(storeInTest1Request))).andReturn(storeInTest1Task); - - HttpRequest storeInTest2Request = HttpRequest.builder().endpoint( - URI.create("http://localhost:8080/store/do")) - .headers(ImmutableMultimap.of("context", "test2")).method("GET").build(); - RunnableHttpRequest storeInTest2Task = null; - expect(httpRequestFactory.create(eq(storeInTest2Request))).andReturn(storeInTest2Task); - - taskQueue.add(storeInTest1Task); - expectLastCall(); - taskQueue.add(storeInTest2Task); - expectLastCall(); - replay(httpRequestFactory, taskQueue); - - function.enqueueStoreTweetTasks(); - - verify(taskQueue); - } -} \ No newline at end of file diff --git a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java b/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java deleted file mode 100644 index 2eb77041d3..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/controller/StoreTweetsControllerTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.controller; - -import static org.easymock.EasyMock.createMock; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.jclouds.util.Strings2; -import org.testng.annotations.Test; - -import twitter4j.Status; -import twitter4j.Twitter; -import twitter4j.User; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - -/** - * Tests behavior of {@code StoreTweetsController} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class StoreTweetsControllerTest { - - Twitter createTwitter() { - return createMock(Twitter.class); - } - - Map createBlobStores() throws InterruptedException, ExecutionException { - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - Map contexts = ImmutableMap.of( - "test1", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class), - "test2", ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class)); - for (BlobStoreContext blobstore : contexts.values()) { - blobstore.getAsyncBlobStore().createContainerInLocation(null, "favo").get(); - } - return contexts; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - Map stores = createBlobStores(); - StoreTweetsController function = new StoreTweetsController(stores, "favo", createTwitter()); - - User frank = createMock(User.class); - expect(frank.getScreenName()).andReturn("frank").atLeastOnce(); - - Status frankStatus = createMock(Status.class); - expect(frankStatus.getId()).andReturn(1l).atLeastOnce(); - expect(frankStatus.getUser()).andReturn(frank).atLeastOnce(); - expect(frankStatus.getText()).andReturn("I love beans!").atLeastOnce(); - - User jimmy = createMock(User.class); - expect(jimmy.getScreenName()).andReturn("jimmy").atLeastOnce(); - - Status jimmyStatus = createMock(Status.class); - expect(jimmyStatus.getId()).andReturn(2l).atLeastOnce(); - expect(jimmyStatus.getUser()).andReturn(jimmy).atLeastOnce(); - expect(jimmyStatus.getText()).andReturn("cloud is king").atLeastOnce(); - - replay(frank); - replay(frankStatus); - replay(jimmy); - replay(jimmyStatus); - - function.addMyTweets("test1", ImmutableList.of(frankStatus, jimmyStatus)); - function.addMyTweets("test2", ImmutableList.of(frankStatus, jimmyStatus)); - - verify(frank); - verify(frankStatus); - verify(jimmy); - verify(jimmyStatus); - - for (Entry entry : stores.entrySet()) { - BlobMap map = entry.getValue().createBlobMap("favo"); - Blob frankBlob = map.get("1"); - assertEquals(frankBlob.getMetadata().getName(), "1"); - assertEquals(frankBlob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME), "frank"); - assertEquals(frankBlob.getMetadata().getContentMetadata().getContentType(), "text/plain"); - assertEquals(Strings2.toString(frankBlob.getPayload()), "I love beans!"); - - Blob jimmyBlob = map.get("2"); - assertEquals(jimmyBlob.getMetadata().getName(), "2"); - assertEquals(jimmyBlob.getMetadata().getUserMetadata().get(TweetStoreConstants.SENDER_NAME), "jimmy"); - assertEquals(jimmyBlob.getMetadata().getContentMetadata().getContentType(), "text/plain"); - assertEquals(Strings2.toString(jimmyBlob.getPayload()), "cloud is king"); - } - - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java b/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java deleted file mode 100644 index aab06ec0b6..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/KeyToStoredTweetStatusTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobMap; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; - -/** - * Tests behavior of {@code KeyToStoredTweetStatus} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class KeyToStoredTweetStatusTest { - - BlobMap createMap() throws InterruptedException, ExecutionException { - BlobStoreContext context = - ContextBuilder.newBuilder(TransientApiMetadata.builder().build()).build(BlobStoreContext.class); - context.getBlobStore().createContainerInLocation(null, "test1"); - return context.createBlobMap("test1"); - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - BlobMap map = createMap(); - Blob blob = map.blobBuilder().name("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - map.put("1", blob); - String host = "localhost"; - String service = "stub"; - String container = "tweetstore"; - - KeyToStoredTweetStatus function = new KeyToStoredTweetStatus(map, service, host, container); - StoredTweetStatus result = function.apply("1"); - - StoredTweetStatus expected = new StoredTweetStatus(service, host, container, "1", "frank", - "I love beans!", null); - - assertEquals(result, expected); - - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java b/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java deleted file mode 100644 index 5fec52711e..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/functions/ServiceToStoredTweetStatusesTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.blobstore.TransientApiMetadata; -import org.jclouds.blobstore.domain.Blob; -import org.jclouds.demo.tweetstore.domain.StoredTweetStatus; -import org.jclouds.demo.tweetstore.reference.TweetStoreConstants; -import org.testng.annotations.Test; -import org.testng.collections.Maps; - -import com.google.common.collect.Iterables; - -/** - * Tests behavior of {@code ServiceToStoredTweetStatuses} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class ServiceToStoredTweetStatusesTest { - - Map createServices(String container) throws InterruptedException, - ExecutionException { - Map services = Maps.newHashMap(); - TransientApiMetadata transientApiMetadata = TransientApiMetadata.builder().build(); - for (String name : new String[] { "1", "2" }) { - BlobStoreContext context = ContextBuilder.newBuilder(transientApiMetadata).build(BlobStoreContext.class); - context.getAsyncBlobStore().createContainerInLocation(null, container).get(); - Blob blob = context.getAsyncBlobStore().blobBuilder("1").build(); - blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank"); - blob.setPayload("I love beans!"); - context.getAsyncBlobStore().putBlob(container, blob).get(); - services.put(name, context); - } - return services; - } - - public void testStoreTweets() throws IOException, InterruptedException, ExecutionException { - String container = "container"; - Map contexts = createServices(container); - - ServiceToStoredTweetStatuses function = new ServiceToStoredTweetStatuses(contexts, container); - - assertEquals(Iterables.getLast(function.apply("1")), new StoredTweetStatus("1", "localhost", - container, "1", "frank", "I love beans!", null)); - - assertEquals(Iterables.getLast(function.apply("2")), new StoredTweetStatus("2", "localhost", - container, "1", "frank", "I love beans!", null)); - - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/RunAtCloudServer.java b/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/RunAtCloudServer.java deleted file mode 100644 index 2ce1ec21aa..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/RunAtCloudServer.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration; - -import static com.google.common.io.Closeables.closeQuietly; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -import javax.servlet.ServletException; - -import org.apache.commons.cli.ParseException; - -/** - * Basic functionality to start a local RUN@cloud instance. - * - * @author Andrew Phillips - */ -public class RunAtCloudServer { - protected StaxSdkAppServer2 server; - - public void writePropertiesAndStartServer(final String port, final String warfile, - final String environments, final String serverBaseDirectory, - Properties props) throws IOException, InterruptedException, ParseException, ServletException { - String filename = String.format( - "%1$s/WEB-INF/jclouds.properties", warfile); - System.err.println("file: " + filename); - storeProperties(filename, props); - assert new File(filename).exists(); - server = StaxSdkAppServer2.createServer(new String[] { "-web", warfile, "-port", port, "-env", environments, - "-dir", serverBaseDirectory }, new String[0], Thread.currentThread().getContextClassLoader()); - server.start(); - TimeUnit.SECONDS.sleep(30); - } - - private static void storeProperties(String filename, Properties props) throws IOException { - FileOutputStream targetFile = new FileOutputStream(filename); - try { - props.store(targetFile, "test"); - } finally { - closeQuietly(targetFile); - } - } - - public void stop() throws Exception { - server.stop(); - } - -} \ No newline at end of file diff --git a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/StaxSdkAppServer2.java b/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/StaxSdkAppServer2.java deleted file mode 100644 index 4dbece1747..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/StaxSdkAppServer2.java +++ /dev/null @@ -1,192 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration; - -import static com.google.common.base.Predicates.instanceOf; -import static java.util.Arrays.asList; -import static org.jclouds.demo.tweetstore.integration.util.ObjectFields.set; -import static org.jclouds.demo.tweetstore.integration.util.ObjectFields.valueOf; - -import java.io.File; -import java.io.IOException; -import java.util.Timer; - -import javax.servlet.ServletException; - -import net.stax.appserver.webapp.RequestMonitorValve; -import net.stax.appserver.webapp.WebAppEngine; - -import org.apache.catalina.Engine; -import org.apache.commons.cli.ParseException; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.staxnet.appserver.IAppServerConfiguration; -import com.staxnet.appserver.IEngineFactory; -import com.staxnet.appserver.ServerCallbackClient; -import com.staxnet.appserver.StaxAppServerBase; -import com.staxnet.appserver.StaxSdkAppServer; -import com.staxnet.appserver.StaxSdkAppServerCLI; -import com.staxnet.appserver.TomcatServerBase; -import com.staxnet.appserver.WarBasedServerConfiguration; -import com.staxnet.appserver.config.AppServerConfig; - -class StaxSdkAppServer2 { - // code more or less exactly from StaxSdkAppServer.java - public static StaxSdkAppServer2 createServer(String[] args, String[] classPaths, - ClassLoader cl) throws ParseException, ServletException { - StaxSdkAppServerCLI cli = StaxSdkAppServerCLI.parse(args); - if (cli.getMissingOptions().length > 0) { - throw new ParseException("Missing required options: " + cli.formatMissingOptions(", ")); - } - - String[] environments = cli.getEnvironment(); - File serverConfig = cli.getServerConfigFile(); - File baseDir = new File(cli.getBaseDir()); - File webRoot = new File(cli.getWebdir()); - File workDir = new File(baseDir, "work"); - - File staxWebXml = new File(webRoot, "WEB-INF/cloudbees-web.xml"); - if (!(staxWebXml.exists())) - staxWebXml = new File(webRoot, "WEB-INF/stax-web.xml"); - IAppServerConfiguration config = WarBasedServerConfiguration.load( - serverConfig, webRoot, staxWebXml, environments); - // force the RequestMonitorValve to sleep for only a short period - set("statusInterval", StaxReflect.getAppServerConfig(config), 5); - StaxSdkAppServer server = new StaxSdkAppServer( - baseDir.getAbsolutePath(), workDir.getAbsolutePath(), cl, - classPaths, cli.getPort(), config, cli.getRepositoryPath()); - return new StaxSdkAppServer2(server); - } - - private final StaxSdkAppServer server; - private final Thread serverThread; - - private StaxSdkAppServer2(StaxSdkAppServer server) { - this.server = server; - serverThread = new Thread(new Runnable() { - public void run() { - try { - StaxSdkAppServer2.this.server.start(); - } catch (ServletException exception) { - System.err.println("exception starting server: " + exception); - } - } - }); - } - - void start() throws ServletException { - Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { - public void run() { - stop(); - } - })); - serverThread.start(); - } - - void stop() { - server.stop(); - serverThread.interrupt(); - StaxReflect.getStaxAppQueryTimer(server).cancel(); - KillerCallback requestMonitorAssassin = new KillerCallback(StaxReflect.getRequestMonitorTimerCallback(server)); - /* - * Hoping for the best here in terms of visibility - we're setting a variable in a - * different thread which isn't guaranteed to see the change. - * But we can't set the callbackClient before serverThread starts (which would create - * a happens-before relationship) because the objects on which the callbackClient is - * set have not been created yet at that point. - */ - set("callbackClient", StaxReflect.getRequestMonitorTimer(server), requestMonitorAssassin); - requestMonitorAssassin.setToKill(); - } - - private class KillerCallback extends ServerCallbackClient { - private final ServerCallbackClient delegate; - private volatile boolean killCaller = false; - - private KillerCallback(ServerCallbackClient delegate) { - super("", ""); - this.delegate = delegate; - } - - @Override - public AuthenticationResult getApplicationTicket(String username, - String password) throws IOException { - return delegate.getApplicationTicket(username, password); - } - - @Override - public AuthenticationResult renewApplicationTicket(String userAuthTicket) - throws IOException { - return delegate.renewApplicationTicket(userAuthTicket); - } - - @Override - public void updateStatus(State state) throws ServletException, - IOException { - if (killCaller) { - throw new ThreadDeath(); - } - delegate.updateStatus(state); - } - - private void setToKill() { - killCaller = true; - } - } - - private static class StaxReflect { - private static WebAppEngine getWebAppEngine(StaxSdkAppServer server) { - return (WebAppEngine) Iterables.find(asList((IEngineFactory[]) - valueOf("engineFactories", server, StaxAppServerBase.class)), - instanceOf(WebAppEngine.class)); - } - - private static Timer getStaxAppQueryTimer(StaxSdkAppServer server) { - return (Timer) valueOf("timer", getWebAppEngine(server)); - } - - private static AppServerConfig getAppServerConfig(IAppServerConfiguration config) { - return (AppServerConfig) valueOf("appServerConfig", config); - } - - private static Engine getLocalEngine(StaxSdkAppServer server) { - return (Engine) Iterables.find(asList((Engine[]) - valueOf("engines", valueOf("container", server, TomcatServerBase.class))), - new Predicate() { - @Override - public boolean apply(Engine input) { - return input.getName().equals("localEngine"); - } - }); - } - - private static Runnable getRequestMonitorTimer(StaxSdkAppServer server) { - return (Runnable) valueOf("idleTimer", Iterables.find( - asList(getLocalEngine(server).getPipeline().getValves()), - instanceOf(RequestMonitorValve.class))); - } - - private static ServerCallbackClient getRequestMonitorTimerCallback( - StaxSdkAppServer server) { - return (ServerCallbackClient) valueOf("callbackClient", - getRequestMonitorTimer(server)); - } - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java b/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java deleted file mode 100644 index 207ec2b6e6..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/TweetStoreLiveTest.java +++ /dev/null @@ -1,239 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.demo.paas.RunnableHttpRequest.PLATFORM_REQUEST_ORIGINATOR_HEADER; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_BLOBSTORES; -import static org.jclouds.demo.tweetstore.reference.TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_ACCESSTOKEN_SECRET; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_KEY; -import static org.jclouds.demo.tweetstore.reference.TwitterConstants.PROPERTY_TWITTER_CONSUMER_SECRET; - -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -import org.jclouds.Context; -import org.jclouds.ContextBuilder; -import org.jclouds.blobstore.BlobStoreContext; -import org.jclouds.demo.tweetstore.controller.StoreTweetsController; -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.rest.AuthorizationException; -import org.jclouds.util.Strings2; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - -import twitter4j.ResponseList; -import twitter4j.Status; -import twitter4j.Twitter; -import twitter4j.TwitterException; -import twitter4j.TwitterFactory; -import twitter4j.conf.Configuration; -import twitter4j.conf.ConfigurationBuilder; - -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.inject.Module; - -/** - * Starts up the RUN@cloud for Java Development environment and deploys an application which - * tests accesses twitter and blobstores. - * - * @author Andrew Phillips - */ -@Test(groups = "live", singleThreaded = true) -public class TweetStoreLiveTest { - - RunAtCloudServer server; - private URL url; - private Map contexts; - private String container; - private static final Iterable blobstores = - Splitter.on(',').split(getRequiredSystemProperty(PROPERTY_TWEETSTORE_BLOBSTORES)); - private static final Properties props = new Properties(); - - @BeforeTest - void clearAndCreateContainers() throws InterruptedException, ExecutionException, TimeoutException, IOException, - TwitterException { - container = getRequiredSystemProperty(PROPERTY_TWEETSTORE_CONTAINER); - - props.setProperty(PROPERTY_TWEETSTORE_CONTAINER, container); - - // put all identity/credential pairs into the client - addCredentialsForBlobStores(props); - - // example of an ad-hoc client configuration - addConfigurationForTwitter(props); - - // for testing, capture logs. - final Set wiring = ImmutableSet. of(new Log4JLoggingModule()); - this.contexts = Maps.newConcurrentMap(); - - for (String provider : blobstores) { - contexts.put(provider, ContextBuilder.newBuilder(provider) - .modules(wiring).overrides(props).build(BlobStoreContext.class)); - } - - Configuration conf = new ConfigurationBuilder() - .setOAuthConsumerKey(props.getProperty(PROPERTY_TWITTER_CONSUMER_KEY)) - .setOAuthConsumerSecret(props.getProperty(PROPERTY_TWITTER_CONSUMER_SECRET)) - .setOAuthAccessToken(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN)) - .setOAuthAccessTokenSecret(props.getProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET)) - .build(); - Twitter client = new TwitterFactory(conf).getInstance(); - StoreTweetsController controller = new StoreTweetsController(contexts, container, client); - - ResponseList statuses = client.getMentions(); - - boolean deleted = false; - for (BlobStoreContext context : contexts.values()) { - try { - if (context.getBlobStore().containerExists(container)) { - System.err.printf("deleting container %s at %s%n", container, - context.unwrap(Context.class).getProviderMetadata().getEndpoint()); - context.getBlobStore().deleteContainer(container); - deleted = true; - } - } catch (AuthorizationException e) { - throw new AuthorizationException("for context: " + context, e); - } - } - if (deleted) { - System.err.println("sleeping 60 seconds to allow containers to clear"); - Thread.sleep(60000); - } - for (BlobStoreContext context : contexts.values()) { - System.err.printf("creating container %s at %s%n", container, - context.unwrap(Context.class).getProviderMetadata().getEndpoint()); - context.getBlobStore().createContainerInLocation(null, container); - } - - if (deleted) { - System.err.println("sleeping 5 seconds to allow containers to create"); - Thread.sleep(5000); - } - - for (Entry entry : contexts.entrySet()) { - System.err.printf("filling container %s at %s%n", container, entry.getKey()); - controller.addMyTweets(entry.getKey(), statuses); - } - } - - private static String getRequiredSystemProperty(String key) { - return checkNotNull(System.getProperty(key), key); - } - - private void addConfigurationForTwitter(Properties props) { - props.setProperty(PROPERTY_TWITTER_CONSUMER_KEY, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_KEY)); - props.setProperty(PROPERTY_TWITTER_CONSUMER_SECRET, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_CONSUMER_SECRET)); - props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN)); - props.setProperty(PROPERTY_TWITTER_ACCESSTOKEN_SECRET, - getRequiredSystemProperty("test." + PROPERTY_TWITTER_ACCESSTOKEN_SECRET)); - } - - private void addCredentialsForBlobStores(Properties props) { - for (String provider : blobstores) { - props.setProperty(provider + ".identity", - getRequiredSystemProperty("test." + provider + ".identity")); - props.setProperty(provider + ".credential", - getRequiredSystemProperty("test." + provider + ".credential")); - } - } - - @BeforeTest(dependsOnMethods = "clearAndCreateContainers") - @Parameters({ "warfile", "bees.address", "bees.port", "bees.basedir" }) - public void startDevAppServer(final String warfile, final String address, final String port, - String serverBaseDirectory) throws Exception { - url = new URL(String.format("http://%s:%s", address, port)); - - server = new RunAtCloudServer(); - server.writePropertiesAndStartServer(port, warfile, "itest", - serverBaseDirectory, props); - } - - @Test - public void shouldPass() throws InterruptedException, IOException { - InputStream i = url.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Welcome") >= 0 : string; - } - - @Test(dependsOnMethods = "shouldPass", expectedExceptions = IOException.class) - public void shouldFail() throws InterruptedException, IOException { - new URL(url, "/store/do").openStream(); - } - - @Test(dependsOnMethods = "shouldFail") - public void testPrimeContainers() throws IOException, InterruptedException { - URL gurl = new URL(url, "/store/do"); - - for (String context : blobstores) { - System.out.println("storing at context: " + context); - HttpURLConnection connection = (HttpURLConnection) gurl.openConnection(); - connection.addRequestProperty(PLATFORM_REQUEST_ORIGINATOR_HEADER, "taskqueue-twitter"); - connection.addRequestProperty("context", context); - InputStream i = connection.getInputStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Done!") >= 0 : string; - connection.disconnect(); - } - - System.err.println("sleeping 20 seconds to allow for eventual consistency delay"); - Thread.sleep(20000); - for (BlobStoreContext context : contexts.values()) { - assert context.createInputStreamMap(container).size() > 0 : context.unwrap(Context.class).getProviderMetadata().getEndpoint(); - } - } - - @Test(invocationCount = 5, dependsOnMethods = "testPrimeContainers") - public void testSerial() throws InterruptedException, IOException { - URL gurl = new URL(url, "/tweets/get"); - InputStream i = gurl.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Tweets in Clouds") >= 0 : string; - } - - @Test(invocationCount = 10, dependsOnMethods = "testPrimeContainers", threadPoolSize = 3) - public void testParallel() throws InterruptedException, IOException { - URL gurl = new URL(url, "/tweets/get"); - InputStream i = gurl.openStream(); - String string = Strings2.toStringAndClose(i); - assert string.indexOf("Tweets in Clouds") >= 0 : string; - } - - @AfterTest - public void stopDevAppServer() throws Exception { - server.stop(); - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/ObjectFields.java b/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/ObjectFields.java deleted file mode 100644 index cc7c696c55..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/test/java/org/jclouds/demo/tweetstore/integration/util/ObjectFields.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.demo.tweetstore.integration.util; - -import java.lang.reflect.Field; - -public class ObjectFields { - - public static Object valueOf(String fieldName, Object source) { - return valueOf(fieldName, source, source.getClass()); - } - - public static Object valueOf(String fieldName, Object source, - Class fieldDeclaringClass) { - try { - return getAccessibleField(fieldName, fieldDeclaringClass).get(source); - } catch (Exception exception) { - throw new IllegalArgumentException(exception); - } - } - - private static Field getAccessibleField(String name, Class declaringClass) throws SecurityException, NoSuchFieldException { - Field field = declaringClass.getDeclaredField(name); - field.setAccessible(true); - return field; - } - - public static void set(String fieldName, Object target, Object value) { - set(fieldName, target, value, target.getClass()); - } - - public static void set(String fieldName, Object target, Object value, - Class fieldDeclaringClass) { - try { - getAccessibleField(fieldName, fieldDeclaringClass).set(target, value); - } catch (Exception exception) { - throw new IllegalArgumentException(exception); - } - } -} diff --git a/demos/tweetstore/runatcloud-tweetstore/src/test/resources/log4j.xml b/demos/tweetstore/runatcloud-tweetstore/src/test/resources/log4j.xml deleted file mode 100644 index 2e5d01fb9e..0000000000 --- a/demos/tweetstore/runatcloud-tweetstore/src/test/resources/log4j.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -