尝试从 Azure Data Lake 中删除文件时引发异常
Exception raised while trying to delete file from Azure Data Lake
小序言: 我正在使用 ADF
将文件从 Azure Data Lake Store
存档(复制和删除)到 Azure Blob Storage
,我的管道有两项活动 1. Copy Activity
(将文件从 ADLS
复制到 Blob
) 2.Custom .NET Activity
(从 ADLS
删除文件)。
现在 ADF
已完美安排,运行 顺利无误 - Copy Activity
一切正常,可以看到复制到 Blob
的文件。我的问题是 Custom .NET Activity
- 没有记录错误(我使用的是 IActivityLogger logger
),但文件没有被删除。因此,我开始通过 ADL .NET SDK code
部分进行调试并面临以下问题 -
Microsoft.Azure.Management.DataLake.Store.Models.AdlsErrorException was unhandled by user code
HResult=-2146233088
Message=Operation returned an invalid status code 'Forbidden'
Source=Microsoft.Azure.Management.DataLake.Store
StackTrace:
at Microsoft.Azure.Management.DataLake.Store.FileSystemOperations.d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Management.DataLake.Store.FileSystemOperationsExtensions.d__39.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.Management.DataLake.Store.FileSystemOperationsExtensions.Delete(IFileSystemOperations operations, String accountName, String filePath, Nullable'1 recursive)
at DataLakeApplication.DotNetADLApplication.ADLApplication(List'1 dataSetsToDelete) in C:\Projects\C#\DataLakeApplication\DataLakeApplication\Program.cs:line 117
InnerException:
delete
操作的代码片段:
var fileDeleterResult =
_adlsFileSystemClient.FileSystem.Delete(_adlsAccountName, strInputToDelete, null);
我在我的 .NET 代码中使用 AAD Service Principal
与 ADLS
进行通信,身份验证部分没问题,甚至我已经尝试了其他几个 FileSystemOperations
ListFileStatus
& GetFileStatus
- 这些工作正常。只有我的 Delete
抛出上述错误,所以我想重新检查我的 Service Principal
对 ADLS
的权限,它被赋予了 Owner
- 角色和 RWX
对 ADLS
个文件夹的权限。
任何线索都将不胜感激,如果需要这方面的任何进一步信息,请告诉我。
我在 ADLS 中注意到一些具有权限的有趣业务。
需要仔细检查的几件事:
如果你还没有读过(我相信你已经读过)再读一遍:
Access control in Azure Data Lake Store
密切关注权限的非级联性质以及掩码的工作原理。
不过你说的用户有Owner权限,应该是all mighty powerful.
尝试重新应用包括子权限在内的权限(如果适用于您的安全模型),看看是否能解决问题。
我也想知道data lake diagnostics是否能找到一些东西(我不确定,我自己没看过)。
终于能够解决它,我的错误基本上是我试图传递 Azure Data Lake
文件夹路径而不是给我 Forbidden
错误消息的文件路径。
我实现的删除文件夹内文件的代码 -
foreach (string strInputToDelete in dataSetsToDelete)
{
Console.WriteLine("Listing files and directories.");
var itemList = _adlsFileSystemClient.FileSystem.ListFileStatus(_adlsAccountName, strInputToDelete).FileStatuses.FileStatus.ToList();
var fileMenuItems = itemList.Select(a => String.Format("{0,15} {1}", a.Type, a.PathSuffix));
Console.WriteLine(String.Join("\r\n", fileMenuItems));
Console.WriteLine("Files and directories listed.");
for (int i = 0; i < itemList.Count; i++)
{
Console.WriteLine("Deleting files...");
var fileDeleteResult =_adlsFileSystemClient.FileSystem.Delete(_adlsAccountName, strInputToDelete + itemList[i].PathSuffix);
Console.WriteLine("Deletion result: " + fileDeleteResult.OperationResult.ToString());
Console.WriteLine("Files deleted");
}
}
小序言: 我正在使用 ADF
将文件从 Azure Data Lake Store
存档(复制和删除)到 Azure Blob Storage
,我的管道有两项活动 1. Copy Activity
(将文件从 ADLS
复制到 Blob
) 2.Custom .NET Activity
(从 ADLS
删除文件)。
现在 ADF
已完美安排,运行 顺利无误 - Copy Activity
一切正常,可以看到复制到 Blob
的文件。我的问题是 Custom .NET Activity
- 没有记录错误(我使用的是 IActivityLogger logger
),但文件没有被删除。因此,我开始通过 ADL .NET SDK code
部分进行调试并面临以下问题 -
Microsoft.Azure.Management.DataLake.Store.Models.AdlsErrorException was unhandled by user code HResult=-2146233088 Message=Operation returned an invalid status code 'Forbidden' Source=Microsoft.Azure.Management.DataLake.Store StackTrace: at Microsoft.Azure.Management.DataLake.Store.FileSystemOperations.d__28.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Management.DataLake.Store.FileSystemOperationsExtensions.d__39.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Azure.Management.DataLake.Store.FileSystemOperationsExtensions.Delete(IFileSystemOperations operations, String accountName, String filePath, Nullable'1 recursive) at DataLakeApplication.DotNetADLApplication.ADLApplication(List'1 dataSetsToDelete) in C:\Projects\C#\DataLakeApplication\DataLakeApplication\Program.cs:line 117 InnerException:
delete
操作的代码片段:
var fileDeleterResult =
_adlsFileSystemClient.FileSystem.Delete(_adlsAccountName, strInputToDelete, null);
我在我的 .NET 代码中使用 AAD Service Principal
与 ADLS
进行通信,身份验证部分没问题,甚至我已经尝试了其他几个 FileSystemOperations
ListFileStatus
& GetFileStatus
- 这些工作正常。只有我的 Delete
抛出上述错误,所以我想重新检查我的 Service Principal
对 ADLS
的权限,它被赋予了 Owner
- 角色和 RWX
对 ADLS
个文件夹的权限。
任何线索都将不胜感激,如果需要这方面的任何进一步信息,请告诉我。
我在 ADLS 中注意到一些具有权限的有趣业务。
需要仔细检查的几件事:
如果你还没有读过(我相信你已经读过)再读一遍:
Access control in Azure Data Lake Store
密切关注权限的非级联性质以及掩码的工作原理。
不过你说的用户有Owner权限,应该是all mighty powerful.
尝试重新应用包括子权限在内的权限(如果适用于您的安全模型),看看是否能解决问题。
我也想知道data lake diagnostics是否能找到一些东西(我不确定,我自己没看过)。
终于能够解决它,我的错误基本上是我试图传递 Azure Data Lake
文件夹路径而不是给我 Forbidden
错误消息的文件路径。
我实现的删除文件夹内文件的代码 -
foreach (string strInputToDelete in dataSetsToDelete)
{
Console.WriteLine("Listing files and directories.");
var itemList = _adlsFileSystemClient.FileSystem.ListFileStatus(_adlsAccountName, strInputToDelete).FileStatuses.FileStatus.ToList();
var fileMenuItems = itemList.Select(a => String.Format("{0,15} {1}", a.Type, a.PathSuffix));
Console.WriteLine(String.Join("\r\n", fileMenuItems));
Console.WriteLine("Files and directories listed.");
for (int i = 0; i < itemList.Count; i++)
{
Console.WriteLine("Deleting files...");
var fileDeleteResult =_adlsFileSystemClient.FileSystem.Delete(_adlsAccountName, strInputToDelete + itemList[i].PathSuffix);
Console.WriteLine("Deletion result: " + fileDeleteResult.OperationResult.ToString());
Console.WriteLine("Files deleted");
}
}