2

我们刚刚开始评估 Azure 的数据湖服务。我们创建了湖,通过门户我们可以看到服务的两个公共 URL。(一个是 https:// 方案,另一个是 adl:// 方案)

datalake 文档指出确实有两个接口:webHDFS REST API 和 ADL。所以,我假设 https:// 方案为我提供了 wehHDFS 接口。但是,我在 Azure 上找不到有关使用此界面的更多信息。

我尝试使用 Web 浏览器和 curl 戳给定的 https:// URL。服务正在响应。回复是 JSON,正如预期的那样,因为数据湖是 Hadoop 的一个实例。但是,我似乎无法访问我的文件 [我通过门户上传到我们的湖中]。

例如,如果我对“/foo.txt”执行 GET,则回复是一个错误,ResourceNotFound。

如果我使用典型的 Hadoop HDFS 语法“/webhdfs/v1/foo.txt”执行 GET,则回复是错误,AuthenticationFailed。附加文本表示缺少访问令牌。这似乎更有希望。但是,找不到任何有关生成此类访问令牌的信息。

有一些关于使用 ADL 接口、.NET 和 Visual Studio 的文档,但这不是我最初想要的。

非常感谢任何帮助!

4

1 回答 1

3

我感谢 Matthew Hicks 的这篇论坛帖子,其中概述了如何使用curl. 我把它包装在 PowerShell 中。我敢肯定有很多方法可以实现这一点,但这里有一种可行。

首先设置一个 AAD 应用程序,以便您可以填写下面提到的 client_id 和 client_secret。(假设您想要自动执行此操作而不是进行交互式登录。如果您想要交互式登录,那么上面的论坛帖子中有指向该方法的链接。)

然后填写前 5 行中的设置并运行以下 PowerShell 脚本:

$client_id = "<client id>";
$client_secret = "<secret>";
$tenant = "<tenant>";
$adlsAccount = "<account>";
cd D:\path\to\curl

#authenticate
$cmd = { .\curl.exe -X POST https://login.microsoftonline.com/$tenant/oauth2/token  -F grant_type=client_credentials       -F resource=https://management.core.windows.net/       -F client_id=$client_id       -F client_secret=$client_secret };
$responseToken = Invoke-Command -scriptblock $cmd;
$accessToken = (ConvertFrom-Json $responseToken).access_token;

#list root folders
$cmd = {.\curl.exe -X GET -H "Authorization: Bearer $accessToken" https://$adlsAccount.azuredatalakestore.net/webhdfs/v1/?op=LISTSTATUS };
$foldersResponse = Invoke-Command -scriptblock $cmd;
#loop through directories directories
(ConvertFrom-Json $foldersResponse).FileStatuses.FileStatus | ForEach-Object { $_.pathSuffix }

#list files in one folder
$cmd = {.\curl.exe -X GET -H "Authorization: Bearer $accessToken" https://$adlsAccount.azuredatalakestore.net/webhdfs/v1/weather/?op=LISTSTATUS };
$weatherResponse = Invoke-Command -scriptblock $cmd;
(ConvertFrom-Json $weatherResponse).FileStatuses.FileStatus | ForEach-Object { $_.pathSuffix }

#download one file
$cmd = {.\curl.exe -L "https://$adlsAccount.azuredatalakestore.net/webhdfs/v1/weather/2007small.csv?op=OPEN" -H "Authorization: Bearer $accessToken" -o d:\temp\curl\2007small.csv };
Invoke-Command -scriptblock $cmd;


#upload one file
$cmd = {.\curl.exe -i -X PUT -L "https://$adlsAccount.azuredatalakestore.net/webhdfs/v1/weather/new2007small.csv?op=CREATE" -T "D:\temp\weather\smallcsv\new2007small.csv" -H "Authorization: Bearer $accessToken" };
Invoke-Command -scriptblock $cmd;
于 2016-04-05T03:56:41.487 回答