use of com.microsoft.azure.hdinsight.sdk.common.HDIException in project azure-tools-for-java by Microsoft.
the class SparkSubmitModel method tryToCreateBatchSparkDebugJob.
public SparkBatchRemoteDebugJob tryToCreateBatchSparkDebugJob(@NotNull final IClusterDetail selectedClusterDetail) throws HDIException, IOException {
SparkBatchSubmission.getInstance().setCredentialsProvider(selectedClusterDetail.getHttpUserName(), selectedClusterDetail.getHttpPassword());
try {
SparkBatchRemoteDebugJob debugJob = SparkBatchRemoteDebugJob.factory(SparkSubmitHelper.getLivyConnectionURL(selectedClusterDetail), submissionParameter, SparkBatchSubmission.getInstance());
debugJob.createBatchSparkJobWithDriverDebugging();
return debugJob;
} catch (URISyntaxException ex) {
throw new HDIException("Bad Livy Connection URL " + SparkSubmitHelper.getLivyConnectionURL(selectedClusterDetail), ex);
} catch (IOException ex) {
HDInsightUtil.showErrorMessageOnSubmissionMessageWindow(project, String.format("Error : Failed to submit to spark cluster. error message : %s.", ex.getMessage()));
throw ex;
}
}
use of com.microsoft.azure.hdinsight.sdk.common.HDIException in project azure-tools-for-java by Microsoft.
the class WebHDFSUtils method uploadFileToADLS.
public static void uploadFileToADLS(@NotNull IHDIStorageAccount storageAccount, @NotNull File localFile, @NotNull String remotePath, boolean overWrite) throws Exception {
com.microsoft.azuretools.sdkmanage.AzureManager manager = AuthMethodManager.getInstance().getAzureManager();
String tid = manager.getSubscriptionManager().getSubscriptionTenant(storageAccount.getSubscriptionId());
String accessToken = manager.getAccessToken(tid);
// TODO: accountFQDN should work for Mooncake
String storageName = storageAccount.getName();
ADLStoreClient client = ADLStoreClient.createClient(String.format("%s.azuredatalakestore.net", storageName), accessToken);
OutputStream stream = null;
try {
stream = client.createFile(remotePath, IfExists.OVERWRITE);
IOUtils.copy(new FileInputStream(localFile), stream);
stream.flush();
stream.close();
} catch (ADLException e) {
// we just popup the exception message for customers to guide customers login under interactive model
if (e.httpResponseCode == 403 || HttpStatusCode.valueOf(e.httpResponseMessage) == HttpStatusCode.FORBIDDEN) {
throw new HDIException("Forbidden. Attached Azure DataLake Store is not supported in Automated login model. Please logout first and try Interactive login model", 403);
}
} finally {
IOUtils.closeQuietly(stream);
}
}
use of com.microsoft.azure.hdinsight.sdk.common.HDIException in project azure-tools-for-java by Microsoft.
the class AddHDInsightAdditionalClusterImpl method getStorageAccount.
public static HDStorageAccount getStorageAccount(String clusterName, String storageName, String storageKey, String userName, String password) throws HDIException, AzureCmdException {
String responseMessage = getMessageByAmbari(clusterName, userName, password);
responseMessage = responseMessage.replace(" ", "");
if (StringHelper.isNullOrWhiteSpace(responseMessage)) {
throw new HDIException("Failed to get storage account");
}
Matcher matcher = PATTERN_DEFAULT_STORAGE.matcher(responseMessage);
String defaultContainer = "";
if (matcher.find()) {
defaultContainer = matcher.group(1);
}
if (StringHelper.isNullOrWhiteSpace(defaultContainer)) {
throw new HDIException("Failed to get default container for storage account");
}
HDStorageAccount account = new HDStorageAccount(null, storageName + BLOB_URL_SUFFIX, storageKey, true, defaultContainer);
//getting container to check the storage key is correct or not
try {
StorageClientSDKManager.getManager().getBlobContainers(account.getConnectionString());
} catch (AzureCmdException e) {
throw new AzureCmdException("Invalid Storage Key");
}
return account;
}
use of com.microsoft.azure.hdinsight.sdk.common.HDIException in project azure-tools-for-java by Microsoft.
the class MultiRestTask method call.
@Override
public List<String> call() throws Exception {
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
List<String> results = new ArrayList<>();
for (String path : paths) {
HttpGet httpGet = new HttpGet(path);
httpGet.addHeader("Content-Type", "application/json");
CloseableHttpResponse response = httpclient.execute(httpGet);
int code = response.getStatusLine().getStatusCode();
if (code == 200 || code == 201) {
results.add(EntityUtils.toString(response.getEntity()));
} else {
throw new HDIException(response.getStatusLine().getReasonPhrase(), code);
}
}
return results;
}
use of com.microsoft.azure.hdinsight.sdk.common.HDIException in project azure-tools-for-java by Microsoft.
the class RestTask method call.
@Override
public String call() throws Exception {
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
HttpGet httpGet = new HttpGet(path);
httpGet.addHeader("Content-Type", "application/json");
CloseableHttpResponse response = httpclient.execute(httpGet);
HttpResponseWithoutHeader header = getResultFromHttpResponse(response);
if (header.getStatusCode() == 200 || header.getStatusCode() == 201) {
return header.getMessage();
} else {
throw new HDIException(header.getReason(), header.getStatusCode());
}
}
Aggregations