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

查看:18
本文介绍了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 帐户边栏选项卡中,单击 Data Explorer

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天全站免登陆