Search in sources :

Example 1 with SparkBatchSubmission

use of com.microsoft.azure.hdinsight.spark.common.SparkBatchSubmission in project azure-tools-for-java by Microsoft.

the class JobUtils method authenticate.

public static AbstractMap.SimpleImmutableEntry<Integer, List<Header>> authenticate(IClusterDetail clusterDetail) throws HDIException, IOException {
    final SparkBatchSubmission submission = SparkBatchSubmission.getInstance();
    final String livyUrl = clusterDetail instanceof LivyCluster ? ((LivyCluster) clusterDetail).getLivyBatchUrl() : null;
    if (livyUrl == null) {
        throw new IOException("Can't get livy connection Url");
    }
    if (!StringUtils.isEmpty(clusterDetail.getHttpUserName()) && !StringUtils.isEmpty(clusterDetail.getHttpPassword())) {
        submission.setUsernamePasswordCredential(clusterDetail.getHttpUserName(), clusterDetail.getHttpPassword());
    }
    final com.microsoft.azure.hdinsight.sdk.common.HttpResponse response = clusterDetail instanceof MfaEspCluster ? submission.negotiateAuthMethodWithResp(livyUrl) : submission.getHttpResponseViaHead(livyUrl);
    final int statusCode = response.getCode();
    if (statusCode >= 200 && statusCode <= 302) {
        return new AbstractMap.SimpleImmutableEntry<>(statusCode, response.getHeaders());
    }
    throw new AuthenticationException(response.getContent(), statusCode);
}
Also used : SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) AuthenticationException(com.microsoft.azure.hdinsight.sdk.common.AuthenticationException) MfaEspCluster(com.microsoft.azure.hdinsight.sdk.cluster.MfaEspCluster) SparkBatchSubmission(com.microsoft.azure.hdinsight.spark.common.SparkBatchSubmission) LivyCluster(com.microsoft.azure.hdinsight.sdk.cluster.LivyCluster)

Aggregations

LivyCluster (com.microsoft.azure.hdinsight.sdk.cluster.LivyCluster)1 MfaEspCluster (com.microsoft.azure.hdinsight.sdk.cluster.MfaEspCluster)1 AuthenticationException (com.microsoft.azure.hdinsight.sdk.common.AuthenticationException)1 SparkBatchSubmission (com.microsoft.azure.hdinsight.spark.common.SparkBatchSubmission)1 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1