Skip to content

Commit fedf9fb

Browse files
committed
Fix the Ambari local user authentication issue
Signed-off-by: Wei Zhang <[email protected]>
1 parent 2dafb7b commit fedf9fb

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

Utils/hdinsight-node-common/src/com/microsoft/azure/hdinsight/spark/common/SparkBatchSubmission.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@
3232
import org.apache.http.impl.client.BasicCredentialsProvider;
3333
import org.apache.http.impl.client.CloseableHttpClient;
3434
import org.apache.http.impl.client.HttpClients;
35+
import rx.Observable;
36+
import rx.schedulers.Schedulers;
3537

3638
import java.io.IOException;
39+
import java.util.concurrent.TimeUnit;
3740

3841
public class SparkBatchSubmission {
3942

@@ -89,17 +92,30 @@ public HttpResponse getHttpResponseViaGet(String connectUrl) throws IOException
8992
}
9093

9194
public HttpResponse getHttpResponseViaHead(String connectUrl) throws IOException {
92-
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
95+
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(getCredentialsProvider())
96+
.build();
9397

9498
HttpHead httpHead = new HttpHead(connectUrl);
9599
httpHead.addHeader("Content-Type", "application/json");
96-
httpHead.addHeader("User-Agent", userAgentName);
100+
httpHead.addHeader("User-Agent", getUserAgentName());
97101
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+
98110
try(CloseableHttpResponse response = httpclient.execute(httpHead)) {
99111
return StreamUtil.getResultFromHttpResponse(response);
100112
}
101113
}
102114

115+
public String getUserAgentName() {
116+
return userAgentName;
117+
}
118+
103119
/**
104120
* get all batches spark jobs
105121
* @param connectUrl : eg http://localhost:8998/batches

0 commit comments

Comments
 (0)