|
32 | 32 | import org.apache.http.impl.client.BasicCredentialsProvider; |
33 | 33 | import org.apache.http.impl.client.CloseableHttpClient; |
34 | 34 | import org.apache.http.impl.client.HttpClients; |
| 35 | +import rx.Observable; |
| 36 | +import rx.schedulers.Schedulers; |
35 | 37 |
|
36 | 38 | import java.io.IOException; |
| 39 | +import java.util.concurrent.TimeUnit; |
37 | 40 |
|
38 | 41 | public class SparkBatchSubmission { |
39 | 42 |
|
@@ -89,17 +92,30 @@ public HttpResponse getHttpResponseViaGet(String connectUrl) throws IOException |
89 | 92 | } |
90 | 93 |
|
91 | 94 | public HttpResponse getHttpResponseViaHead(String connectUrl) throws IOException { |
92 | | - CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build(); |
| 95 | + CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(getCredentialsProvider()) |
| 96 | + .build(); |
93 | 97 |
|
94 | 98 | HttpHead httpHead = new HttpHead(connectUrl); |
95 | 99 | httpHead.addHeader("Content-Type", "application/json"); |
96 | | - httpHead.addHeader("User-Agent", userAgentName); |
| 100 | + httpHead.addHeader("User-Agent", getUserAgentName()); |
97 | 101 | httpHead.addHeader("X-Requested-By", "ambari"); |
| 102 | + |
| 103 | + // WORKAROUND: https://github.com/Microsoft/azure-tools-for-java/issues/1358 |
| 104 | + // The Ambari local account will cause Kerberos authentication initializing infinitely. |
| 105 | + // Set a timer here to cancel the progress. |
| 106 | + Observable.timer(3, TimeUnit.SECONDS, Schedulers.io()) |
| 107 | + .take(1) |
| 108 | + .subscribe(i -> httpHead.abort()); |
| 109 | + |
98 | 110 | try(CloseableHttpResponse response = httpclient.execute(httpHead)) { |
99 | 111 | return StreamUtil.getResultFromHttpResponse(response); |
100 | 112 | } |
101 | 113 | } |
102 | 114 |
|
| 115 | + public String getUserAgentName() { |
| 116 | + return userAgentName; |
| 117 | + } |
| 118 | + |
103 | 119 | /** |
104 | 120 | * get all batches spark jobs |
105 | 121 | * @param connectUrl : eg http://localhost:8998/batches |
|
0 commit comments