Skip to content
Browse files

Merge pull request #64 from roberttheiv/http-4.x-fix

Http 4.x upgrade fix
  • Loading branch information...
2 parents ce113ee + d2694cf commit aee112d9ef0ed960c7bc9955d7e85e6ed6ac91a0 @afeinberg afeinberg committed
View
59 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();
View
21 test/unit/voldemort/store/http/HttpStoreTest.java
@@ -66,6 +66,11 @@ public void setUp() throws Exception {
RequestFormatType.VOLDEMORT_V1,
node.getHttpPort());
server = context.getServer();
+
+ ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(),
+ 5000,
+ TimeUnit.MILLISECONDS);
+ httpClient = new DefaultHttpClient(connectionManager);
httpStore = ServerTestUtils.getHttpStore("users",
RequestFormatType.VOLDEMORT_V1,
node.getHttpPort(),
@@ -76,15 +81,15 @@ public void setUp() throws Exception {
ByteArray key = new ByteArray("test".getBytes());
RequestFormat requestFormat = new RequestFormatFactory().getRequestFormat(RequestFormatType.VOLDEMORT_V1);
- ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(SchemeRegistryFactory.createDefault(),
- 5000,
- TimeUnit.MILLISECONDS);
-
- DefaultHttpClient client = new DefaultHttpClient(connectionManager);
- HttpParams clientParams = client.getParams();
+ HttpParams clientParams = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(clientParams, 5000);
- HttpStore badUrlHttpStore = new HttpStore("test", url, port, client, requestFormat, false);
+ HttpStore badUrlHttpStore = new HttpStore("test",
+ url,
+ port,
+ httpClient,
+ requestFormat,
+ false);
try {
badUrlHttpStore.put(key,
new Versioned<byte[]>("value".getBytes(), new VectorClock()),
@@ -102,8 +107,6 @@ public void setUp() throws Exception {
} catch(Exception e) {
assertTrue(e.getClass().equals(expected));
}
-
- client.getConnectionManager().shutdown();
}
public void testBadUrl() {

0 comments on commit aee112d

Please sign in to comment.
Something went wrong with that request. Please try again.