Search in sources :

Example 1 with ADLException

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);
    }
}
Also used : ADLStoreClient(com.microsoft.azure.datalake.store.ADLStoreClient) OutputStream(java.io.OutputStream) AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) HDIException(com.microsoft.azure.hdinsight.sdk.common.HDIException) FileInputStream(java.io.FileInputStream) ADLException(com.microsoft.azure.datalake.store.ADLException)

Aggregations

ADLException (com.microsoft.azure.datalake.store.ADLException)1 ADLStoreClient (com.microsoft.azure.datalake.store.ADLStoreClient)1 HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)1 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)1 FileInputStream (java.io.FileInputStream)1 OutputStream (java.io.OutputStream)1