2016-12-26 30 views
0

我正在使用C#進行ADLS身份驗證,並希望做一些文件操作,如刪除,重命名。用下面的代碼進行驗證和刪除操作Azure - ADlsError/WebHDFS錯誤,同時刪除ADLS文件

var context = new AuthenticationContext("https://login.windows.net/" + tenantId); 
ClientCredential clientCredential = new ClientCredential(appId, secretKey); 
var tokenResponse = context.AcquireTokenAsync("https://management.azure.com/", clientCredential).Result; 
var accessToken = tokenResponse.AccessToken; 
using (var client = new HttpClient()) 
{ 
    client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken); 
    client.BaseAddress = new Uri("https://management.azure.com/"); 
} 

ServiceClientCredentials creds = new TokenCredentials(tokenResponse.AccessToken);// tokenResponse.IdToken, tokenResponse.AccessTokenType); 

DataLakeStoreFileSystemManagementClient _adlsFileSystemClient = new DataLakeStoreFileSystemManagementClient(creds); 

_adlsFileSystemClient.FileSystem.Delete(_adlsAccountName, FilenameWPath); 

我越來越AdlsError,

類型的未處理的異常 「Microsoft.Azure.Management.DataLake.Store.Models.AdlsErrorException」 發生在ConsoleApplication1.exe

這意味着WebHDFS應該啓用?如何在ADLS上啓用webHDFS。我檢查了HDInight,啓用了webHDFS。

請讓我知道,我該如何解決這個問題。

回答

1

如果我們不對我們的文件進行許可,那麼我們將無權操作該文件。如果是這種情況,請參考我的演示。以下是我的詳細步驟和示例代碼。它適用於我。

在Azure門戶上爲文件分配權限。

1.In我們的數據湖Store帳戶刀片,單擊數據瀏覽器

enter image description here

2.click您要提供訪問Azure的AD應用程序的文件或文件夾,然後單擊訪問 enter image description here

3.在選擇用戶或組刀片中添加「分配權限」,查找先前創建的Azure Active Directory應用程序。 enter image description here 4.select適當的權限 enter image description here
5.檢查該文件已得到許可 enter image description here

演示代碼:

var applicationId = "Application Id"; 
var secretKey = "Secret Key"; 
var tenantId = "Tenant Id"; 
var adlsAccountName = "ADLS Account Name"; 
var creds = ApplicationTokenProvider.LoginSilentAsync(tenantId, applicationId, secretKey).Result; 
var adlsFileSystemClient = new DataLakeStoreFileSystemManagementClient(creds); 
var status = adlsFileSystemClient.FileSystem.GetFileStatus(adlsAccountName, "/mytempdir/myinputfile.txt"); 
var deletResult = adlsFileSystemClient.FileSystem.Delete(adlsAccountName, "/mytempdir/myinputfile.txt"); 

刪除文件

enter image description here

獲取文件狀態

enter image description here

+0

我說我爲「數據分析湖開發者」的角色,一切角色是工作的罰款...感謝湯姆你的努力。你能幫助我http://stackoverflow.com/questions/41330565/u-sql-error-while-using-reference-assembly?noredirect=1 – Ajay