Search in sources :

Example 1 with SparkBatchEspMfaSubmission

use of com.microsoft.azure.hdinsight.spark.common.SparkBatchEspMfaSubmission 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)

Aggregations

MfaEspCluster (com.microsoft.azure.hdinsight.sdk.cluster.MfaEspCluster)1 HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)1 SparkBatchEspMfaSubmission (com.microsoft.azure.hdinsight.spark.common.SparkBatchEspMfaSubmission)1 UnknownServiceException (java.net.UnknownServiceException)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