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());
}
}
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);
}
Aggregations