Search in sources :

Example 1 with MfaEspCluster

use of com.microsoft.azure.hdinsight.sdk.cluster.MfaEspCluster in project azure-tools-for-java by Microsoft.

the class JobUtils method getEntity.

public static HttpEntity getEntity(@NotNull final IClusterDetail clusterDetail, @NotNull final String url) throws IOException, HDIException {
    final HttpClient client;
    if (clusterDetail instanceof MfaEspCluster) {
        final String tenantId = ((MfaEspCluster) clusterDetail).getTenantId();
        if (tenantId == null) {
            throw new UnknownServiceException("Can't get HIB cluster Tenant ID");
        }
        client = new SparkBatchEspMfaSubmission(tenantId, clusterDetail.getName()).getHttpClient();
    } else {
        provider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(clusterDetail.getHttpUserName(), clusterDetail.getHttpPassword()));
        client = HttpClients.custom().useSystemProperties().setDefaultCredentialsProvider(provider).build();
    }
    final HttpGet get = new HttpGet(url);
    final HttpResponse response = client.execute(get);
    final int code = response.getStatusLine().getStatusCode();
    if (code == HttpStatus.SC_OK || code == HttpStatus.SC_CREATED) {
        return response.getEntity();
    } else {
        throw new HDIException(response.getStatusLine().getReasonPhrase(), response.getStatusLine().getStatusCode());
    }
}
Also used : UnknownServiceException(java.net.UnknownServiceException) HttpClient(org.apache.http.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) MfaEspCluster(com.microsoft.azure.hdinsight.sdk.cluster.MfaEspCluster) SparkBatchEspMfaSubmission(com.microsoft.azure.hdinsight.spark.common.SparkBatchEspMfaSubmission) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 2 with MfaEspCluster

use of com.microsoft.azure.hdinsight.sdk.cluster.MfaEspCluster 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

MfaEspCluster (com.microsoft.azure.hdinsight.sdk.cluster.MfaEspCluster)2 LivyCluster (com.microsoft.azure.hdinsight.sdk.cluster.LivyCluster)1 AuthenticationException (com.microsoft.azure.hdinsight.sdk.common.AuthenticationException)1 HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)1 SparkBatchEspMfaSubmission (com.microsoft.azure.hdinsight.spark.common.SparkBatchEspMfaSubmission)1 SparkBatchSubmission (com.microsoft.azure.hdinsight.spark.common.SparkBatchSubmission)1 UnknownServiceException (java.net.UnknownServiceException)1 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 HttpClient (org.apache.http.client.HttpClient)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1