Skip to content

Commit

Permalink
Set Presto User in header of HTTP request of Presto Node Info API (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
Harmandeep Singh authored Sep 11, 2020
1 parent 7e797a5 commit e6e4ad9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@
import java.util.Objects;
import java.util.Set;

import static java.util.Objects.requireNonNull;

/**
* Created by stagra on 14/1/16.
*/
public class PrestoClusterManager extends ClusterManager
{
private static final String DEFAULT_USER = "rubix";
private int serverPort = 8081;
private String serverAddress = "localhost";

Expand All @@ -69,9 +72,7 @@ public List<String> getNodesInternal()
URL allNodesRequest = getNodeUrl();
URL failedNodesRequest = getFailedNodeUrl();

HttpURLConnection allHttpCon = (HttpURLConnection) allNodesRequest.openConnection();
allHttpCon.setConnectTimeout(500); //ms
allHttpCon.setRequestMethod("GET");
HttpURLConnection allHttpCon = getHttpURLConnection(allNodesRequest);

int allNodesResponseCode = allHttpCon.getResponseCode();

Expand Down Expand Up @@ -105,9 +106,7 @@ public List<String> getNodesInternal()
allHttpCon.disconnect();
}

HttpURLConnection failHttpConn = (HttpURLConnection) failedNodesRequest.openConnection();
failHttpConn.setConnectTimeout(500); //ms
failHttpConn.setRequestMethod("GET");
HttpURLConnection failHttpConn = getHttpURLConnection(failedNodesRequest);
int failedNodesResponseCode = failHttpConn.getResponseCode();
// check on failed nodes
try {
Expand Down Expand Up @@ -164,6 +163,17 @@ public List<String> getNodesInternal()
}
}

private HttpURLConnection getHttpURLConnection(URL urlRequest)
throws IOException
{
requireNonNull(urlRequest, "urlRequest is null");
HttpURLConnection allHttpCon = (HttpURLConnection) urlRequest.openConnection();
allHttpCon.setConnectTimeout(500); //ms
allHttpCon.setRequestMethod("GET");
allHttpCon.setRequestProperty("X-Presto-User", DEFAULT_USER);
return allHttpCon;
}

@Override
public ClusterType getClusterType()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
*/
public class PrestoClusterManager extends ClusterManager
{
private static final String DEFAULT_USER = "rubix";
private int serverPort = 8081;
private String serverAddress = "localhost";

Expand Down Expand Up @@ -80,9 +81,7 @@ public List<String> getNodesInternal()
URL allNodesRequest = getNodeUrl();
URL failedNodesRequest = getFailedNodeUrl();

HttpURLConnection allHttpCon = (HttpURLConnection) allNodesRequest.openConnection();
allHttpCon.setConnectTimeout(500); //ms
allHttpCon.setRequestMethod("GET");
HttpURLConnection allHttpCon = getHttpURLConnection(allNodesRequest);

int allNodesResponseCode = allHttpCon.getResponseCode();

Expand Down Expand Up @@ -116,9 +115,7 @@ public List<String> getNodesInternal()
allHttpCon.disconnect();
}

HttpURLConnection failHttpConn = (HttpURLConnection) failedNodesRequest.openConnection();
failHttpConn.setConnectTimeout(500); //ms
failHttpConn.setRequestMethod("GET");
HttpURLConnection failHttpConn = getHttpURLConnection(failedNodesRequest);
int failedNodesResponseCode = failHttpConn.getResponseCode();
// check on failed nodes
try {
Expand Down Expand Up @@ -172,6 +169,17 @@ public List<String> getNodesInternal()
}
}

private HttpURLConnection getHttpURLConnection(URL urlRequest)
throws IOException
{
requireNonNull(urlRequest, "urlRequest is null");
HttpURLConnection allHttpCon = (HttpURLConnection) urlRequest.openConnection();
allHttpCon.setConnectTimeout(500); //ms
allHttpCon.setRequestMethod("GET");
allHttpCon.setRequestProperty("X-Presto-User", DEFAULT_USER);
return allHttpCon;
}

private List<String> getNodesFromNodeManager()
{
requireNonNull(nodeManager, "nodeManager is null");
Expand Down

0 comments on commit e6e4ad9

Please sign in to comment.