Azure-删除ADLS文件时出现ADlsError/WebHDFS错误 [英] Azure - ADlsError / WebHDFS error while deleting ADLS file

查看:73
本文介绍了Azure-删除ADLS文件时出现ADlsError/WebHDFS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#进行ADLS身份验证,并希望执行一些文件操作,例如删除,重命名.使用下面的代码进行身份验证和删除操作

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

我收到AdlsError,

I am getting AdlsError,

类型的未处理异常 'Microsoft.Azure.Management.DataLake.Store.Models.AdlsErrorException' 发生在ConsoleApplication1.exe

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

这意味着应该启用WebHDFS?如何在ADLS上启用webHDFS.我检查了HDInight,启用了webHDFS.

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.

推荐答案

如果我们没有对文件的权限,那么我们将无权操作该文件.如果是这种情况,请参阅我的演示.以下是我的详细步骤和示例代码.它对我来说正常工作.

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.

在Azure门户上分配文件权限.

1.在我们的Data Lake Store帐户刀片中,单击数据资源管理器"

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

2.单击要为其提供对Azure AD应用程序访问权限的文件或文件夹,然后单击访问".

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

3.添加分配权限",在选择用户或组"刀片中,查找您先前创建的Azure Active Directory应用程序. 4.选择适当的权限
5,检查文件是否有权限

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

演示代码:

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

删除文件

获取文件状态

这篇关于Azure-删除ADLS文件时出现ADlsError/WebHDFS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆