Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

c# - Azure - ADlsError / WebHDFS error while deleting ADLS file

I am using C# for ADLS authentication and wants to do some file operation like delete, rename. Using below code for authentication and delete operation

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);

I am getting AdlsError,

An unhandled exception of type 'Microsoft.Azure.Management.DataLake.Store.Models.AdlsErrorException' occurred in ConsoleApplication1.exe

which mean WebHDFS should be enabled? How to enable webHDFS on ADLS. I checked the HDInight, webHDFS is enabled.

Please let me know, How I can rectify this problem.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If we don't assgin permission for our file then we will have no permission to operate the file. If it is that case, please refer to my demo. The following is my detail steps and sample code. It works correctly for me.

Assign permission for the file on the Azure portal.

1.In our Data Lake Store account blade, click Data Explorer

enter image description here

2.click the file or folder for which you want to provide access to the Azure AD application, and then click Access enter image description here

3.Add "assign permission" ,in Select User or Group blade, look for the Azure Active Directory application you created earlier. enter image description here 4.select appropriate permission enter image description here
5.Check the file has got permission enter image description here

Demo Code:

 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");

Delete file

enter image description here

Get file status

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...