use of com.microsoft.azure.datalake.store.ADLException 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);
}
}
Aggregations