mirror of https://github.com/apache/jclouds.git
Fixed code that was broken after the getBlob API change.
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2633 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
befd1f0a4e
commit
c0e08d54ec
|
@ -3,22 +3,17 @@
|
||||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
*
|
*
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* you may not use this file except in compliance with the License.
|
||||||
* distributed with this work for additional information
|
* You may obtain a copy of the License at
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* software distributed under the License is distributed on an
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* KIND, either express or implied. See the License for the
|
* See the License for the specific language governing permissions and
|
||||||
* specific language governing permissions and limitations
|
* limitations under the License.
|
||||||
* under the License.
|
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*/
|
*/
|
||||||
package org.jclouds.demo.tweetstore.controller;
|
package org.jclouds.demo.tweetstore.controller;
|
||||||
|
|
|
@ -53,77 +53,78 @@ import com.google.common.base.Function;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class StoreTweetsController extends HttpServlet {
|
public class StoreTweetsController extends HttpServlet {
|
||||||
|
|
||||||
private static final class StatusToBlob implements Function<Status, Blob> {
|
private static final class StatusToBlob implements Function<Status, Blob> {
|
||||||
private final BlobMap map;
|
private final BlobMap map;
|
||||||
|
|
||||||
private StatusToBlob(BlobMap map) {
|
private StatusToBlob(BlobMap map) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Blob apply(Status from) {
|
public Blob apply(Status from) {
|
||||||
Blob to = map.newBlob();
|
Blob to = map.newBlob(from.getId() + "");
|
||||||
to.getMetadata().setContentType(MediaType.TEXT_PLAIN);
|
to.getMetadata().setContentType(MediaType.TEXT_PLAIN);
|
||||||
to.getMetadata().setName(from.getId() + "");
|
to.getMetadata().setName(from.getId() + "");
|
||||||
to.setPayload(from.getText());
|
to.setPayload(from.getText());
|
||||||
to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME,
|
to.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME,
|
||||||
from.getUser().getScreenName());
|
from.getUser().getScreenName());
|
||||||
return to;
|
return to;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The serialVersionUID */
|
/** The serialVersionUID */
|
||||||
private static final long serialVersionUID = 7215420527854203714L;
|
private static final long serialVersionUID = 7215420527854203714L;
|
||||||
|
|
||||||
private final Map<String, BlobStoreContext<?, ?>> contexts;
|
private final Map<String, BlobStoreContext<?, ?>> contexts;
|
||||||
private final TwitterClient client;
|
private final TwitterClient client;
|
||||||
private final String container;
|
private final String container;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public StoreTweetsController(Map<String, BlobStoreContext<?, ?>> contexts,
|
public StoreTweetsController(
|
||||||
|
Map<String, BlobStoreContext<?, ?>> contexts,
|
||||||
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) final String container,
|
@Named(TweetStoreConstants.PROPERTY_TWEETSTORE_CONTAINER) final String container,
|
||||||
TwitterClient client) {
|
TwitterClient client) {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.contexts = contexts;
|
this.contexts = contexts;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void addMyTweets(String contextName, SortedSet<Status> allAboutMe) {
|
void addMyTweets(String contextName, SortedSet<Status> allAboutMe) {
|
||||||
BlobStoreContext<?, ?> context = checkNotNull(contexts.get(contextName), "no context for "
|
BlobStoreContext<?, ?> context = checkNotNull(contexts.get(contextName),
|
||||||
+ contextName + " in " + contexts.keySet());
|
"no context for " + contextName + " in " + contexts.keySet());
|
||||||
BlobMap map = context.createBlobMap(container);
|
BlobMap map = context.createBlobMap(container);
|
||||||
for (Status status : allAboutMe) {
|
for (Status status : allAboutMe) {
|
||||||
try {
|
try {
|
||||||
map.put(status.getId() + "", new StatusToBlob(map).apply(status));
|
map.put(status.getId() + "", new StatusToBlob(map).apply(status));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e, "Error storing tweet %s on map %s/%s", status.getId(), context,
|
logger.error(e, "Error storing tweet %s on map %s/%s", status.getId(),
|
||||||
container);
|
context, container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
protected void doGet(HttpServletRequest request,
|
||||||
throws ServletException, IOException {
|
HttpServletResponse response) throws ServletException, IOException {
|
||||||
if (request.getHeader("X-AppEngine-QueueName") != null
|
if (request.getHeader("X-AppEngine-QueueName") != null
|
||||||
&& request.getHeader("X-AppEngine-QueueName").equals("twitter")) {
|
&& request.getHeader("X-AppEngine-QueueName").equals("twitter")) {
|
||||||
try {
|
try {
|
||||||
String contextName = checkNotNull(request.getHeader("context"),
|
String contextName =
|
||||||
"missing header context");
|
checkNotNull(request.getHeader("context"), "missing header context");
|
||||||
logger.info("retrieving tweets");
|
logger.info("retrieving tweets");
|
||||||
addMyTweets(contextName, client.getMyMentions());
|
addMyTweets(contextName, client.getMyMentions());
|
||||||
logger.debug("done storing tweets");
|
logger.debug("done storing tweets");
|
||||||
response.setContentType(MediaType.TEXT_PLAIN);
|
response.setContentType(MediaType.TEXT_PLAIN);
|
||||||
response.getWriter().println("Done!");
|
response.getWriter().println("Done!");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e, "Error storing tweets");
|
logger.error(e, "Error storing tweets");
|
||||||
throw new ServletException(e);
|
throw new ServletException(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
response.sendError(401);
|
response.sendError(401);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -54,8 +54,7 @@ public class AddTweetsControllerTest {
|
||||||
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
|
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
|
||||||
.buildContext();
|
.buildContext();
|
||||||
context.getAsyncBlobStore().createContainer(container).get();
|
context.getAsyncBlobStore().createContainer(container).get();
|
||||||
Blob blob = context.getAsyncBlobStore().newBlob();
|
Blob blob = context.getAsyncBlobStore().newBlob("1");
|
||||||
blob.getMetadata().setName("1");
|
|
||||||
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
||||||
blob.setPayload("I love beans!");
|
blob.setPayload("I love beans!");
|
||||||
context.getAsyncBlobStore().putBlob(container, blob).get();
|
context.getAsyncBlobStore().putBlob(container, blob).get();
|
||||||
|
|
|
@ -50,8 +50,7 @@ public class KeyToStoredTweetStatusTest {
|
||||||
|
|
||||||
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
public void testStoreTweets() throws IOException, InterruptedException, ExecutionException {
|
||||||
BlobMap map = createMap();
|
BlobMap map = createMap();
|
||||||
Blob blob = map.newBlob();
|
Blob blob = map.newBlob("1");
|
||||||
blob.getMetadata().setName("1");
|
|
||||||
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
||||||
blob.setPayload("I love beans!");
|
blob.setPayload("I love beans!");
|
||||||
map.put("1", blob);
|
map.put("1", blob);
|
||||||
|
|
|
@ -51,8 +51,7 @@ public class ServiceToStoredTweetStatusesTest {
|
||||||
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
|
BlobStoreContext<AsyncBlobStore, BlobStore> context = new StubBlobStoreContextBuilder()
|
||||||
.buildContext();
|
.buildContext();
|
||||||
context.getAsyncBlobStore().createContainer(container).get();
|
context.getAsyncBlobStore().createContainer(container).get();
|
||||||
Blob blob = context.getAsyncBlobStore().newBlob();
|
Blob blob = context.getAsyncBlobStore().newBlob("1");
|
||||||
blob.getMetadata().setName("1");
|
|
||||||
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
blob.getMetadata().getUserMetadata().put(TweetStoreConstants.SENDER_NAME, "frank");
|
||||||
blob.setPayload("I love beans!");
|
blob.setPayload("I love beans!");
|
||||||
context.getAsyncBlobStore().putBlob(container, blob).get();
|
context.getAsyncBlobStore().putBlob(container, blob).get();
|
||||||
|
|
Loading…
Reference in New Issue