Permalink
Browse files

Fixed HttpStoreSwapper

The parameters were being passed incorrectly via POST methods over HTTP.
  • Loading branch information...
1 parent f7d05f9 commit d2694cf111d71e45c188c049befc6f03046171e5 @roberttheiv roberttheiv committed Jan 5, 2012
Showing with 36 additions and 23 deletions.
  1. +36 −23 src/java/voldemort/store/readonly/swapper/HttpStoreSwapper.java
@@ -3,6 +3,7 @@
import java.io.File;
import java.io.InputStream;
import java.net.HttpURLConnection;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -12,9 +13,11 @@
import java.util.concurrent.Future;
import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
-import org.apache.http.params.HttpParams;
+import org.apache.http.message.BasicNameValuePair;
import org.apache.log4j.Logger;
import voldemort.VoldemortException;
@@ -70,13 +73,15 @@ public HttpStoreSwapper(Cluster cluster,
public String call() throws Exception {
String url = node.getHttpUrl() + "/" + readOnlyMgmtPath;
HttpPost post = new HttpPost(url);
- HttpParams params = post.getParams();
- params.setParameter("operation", "fetch");
+
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+ params.add(new BasicNameValuePair("operation", "fetch"));
String storeDir = basePath + "/node-" + node.getId();
- params.setParameter("dir", storeDir);
- params.setParameter("store", storeName);
+ params.add(new BasicNameValuePair("dir", storeDir));
+ params.add(new BasicNameValuePair("store", storeName));
if(pushVersion > 0)
- params.setParameter("pushVersion", Long.toString(pushVersion));
+ params.add(new BasicNameValuePair("pushVersion", Long.toString(pushVersion)));
+ post.setEntity(new UrlEncodedFormEntity(params));
logger.info("Invoking fetch for node " + node.getId() + " for " + storeDir);
@@ -127,10 +132,13 @@ public String call() throws Exception {
String url = cluster.getNodeById(successfulNodeId).getHttpUrl() + "/"
+ readOnlyMgmtPath;
HttpPost post = new HttpPost(url);
- HttpParams params = post.getParams();
- params.setParameter("operation", "failed-fetch");
- params.setParameter("dir", results.get(successfulNodeId));
- params.setParameter("store", storeName);
+
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+ params.add(new BasicNameValuePair("operation", "failed-fetch"));
+ params.add(new BasicNameValuePair("dir", results.get(successfulNodeId)));
+ params.add(new BasicNameValuePair("store", storeName));
+ post.setEntity(new UrlEncodedFormEntity(params));
+
logger.info("Deleting fetched data from node " + successfulNodeId);
httpResponse = httpClient.execute(post);
@@ -175,12 +183,14 @@ public void invokeSwap(final String storeName, final List<String> fetchFiles) {
try {
String url = node.getHttpUrl() + "/" + readOnlyMgmtPath;
HttpPost post = new HttpPost(url);
- HttpParams params = post.getParams();
- params.setParameter("operation", "swap");
+
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+ params.add(new BasicNameValuePair("operation", "swap"));
String dir = fetchFiles.get(node.getId());
logger.info("Attempting swap for node " + node.getId() + " dir = " + dir);
- params.setParameter("dir", dir);
- params.setParameter("store", storeName);
+ params.add(new BasicNameValuePair("dir", dir));
+ params.add(new BasicNameValuePair("store", storeName));
+ post.setEntity(new UrlEncodedFormEntity(params));
httpResponse = httpClient.execute(post);
int responseCode = httpResponse.getStatusLine().getStatusCode();
@@ -211,11 +221,13 @@ public void invokeSwap(final String storeName, final List<String> fetchFiles) {
String url = cluster.getNodeById(successfulNodeId).getHttpUrl() + "/"
+ readOnlyMgmtPath;
HttpPost post = new HttpPost(url);
- HttpParams params = post.getParams();
- params.setParameter("operation", "rollback");
- params.setParameter("store", storeName);
- params.setParameter("pushVersion",
- Long.toString(ReadOnlyUtils.getVersionId(new File(previousDirs.get(successfulNodeId)))));
+
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+ params.add(new BasicNameValuePair("operation", "rollback"));
+ params.add(new BasicNameValuePair("store", storeName));
+ params.add(new BasicNameValuePair("pushVersion",
+ Long.toString(ReadOnlyUtils.getVersionId(new File(previousDirs.get(successfulNodeId))))));
+ post.setEntity(new UrlEncodedFormEntity(params));
logger.info("Rolling back data on successful node " + successfulNodeId);
@@ -260,11 +272,12 @@ public void invokeRollback(String storeName, final long pushVersion) {
+ storeName);
String url = node.getHttpUrl() + "/" + readOnlyMgmtPath;
HttpPost post = new HttpPost(url);
- HttpParams params = post.getParams();
- params.setParameter("operation", "rollback");
- params.setParameter("store", storeName);
- params.setParameter("pushVersion", Long.toString(pushVersion));
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+ params.add(new BasicNameValuePair("operation", "rollback"));
+ params.add(new BasicNameValuePair("store", storeName));
+ params.add(new BasicNameValuePair("pushVersion", Long.toString(pushVersion)));
+ post.setEntity(new UrlEncodedFormEntity(params));
httpResponse = httpClient.execute(post);
int responseCode = httpResponse.getStatusLine().getStatusCode();

0 comments on commit d2694cf

Please sign in to comment.