AzureDataLake-Gen2 with JavaSdk and Proxy



我有一个相对简单的目标:

升级访问ADLS-Gen1的软件(使用maven包:https://github.com/Azure/azure-data-lake-store-java),这是非常直接的使用。应用程序使用服务主体进行身份验证和一个简单的http代理。

pom.xml代码片段

<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-data-lake-store-sdk</artifactId>
<version>2.1.5</version>
</dependency>
...
</dependencies>

访问ADLS-Gen1的示例类

public class AdlsService {
// ... Some initialisation for AUTH_TOKEN_ENDPOINT, CLIENT_KEY, CLIENT_ID and ACCOUNT_FQDN
private ADLStoreClient buildClient() throws IOException {
AccessTokenProvider accessTokenProvider = new ClientCredsTokenProvider(AUTH_TOKEN_ENDPOINT, CLIENT_ID, CLIENT_KEY);
return ADLStoreClient.createClient(ACCOUNT_FQDN, accessTokenProvider);
}
public boolean checkExists(final String filePath) throws IOException {
ADLStoreClient adlStoreClient = buildClient();
return adlStoreClient.checkExists(filePath);
}
}

新版本应该使用官方推荐的Maven包(https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/storage/azure-storage-file-datalake)访问ADLS-Gen2。

pom.xml代码片段

<dependencies>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-file-datalake</artifactId>
<version>12.4.0</version>
</dependency>
...
</dependencies>

有几件事没有像最初预期的那样顺利:许多依赖项是隐式要求的,并且没有在任何地方记录,代理配置没有做它应该做的事情,并且由于我是Netty的新手,我很难按照我想要的方式配置它。


因此问题:如果我有一个简单的应用程序,它通过HTTP代理从ADLS-Gen1读取文件。什么是使它与ADLS-GEN2一起工作的必要步骤,以及我的调试选项可以帮助我找到问题和错误配置。

这方面的文档是分散的,并且没有提到所需的所有内容。(证明是在1-2天之后,我仍然在努力使连接工作)

根据我的理解,您有一个HTTP代理服务器。您希望通过代理服务器访问Azure数据湖gen2。如果是,请参考以下代码

String accountName = "";
String accountKey = "";
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);
String endpoint = String.format(Locale.ROOT, "https://%s.dfs.core.windows.net", accountName);
ProxyOptions proxyOptions = new new ProxyOptions(ProxyOptions.Type.HTTP,
new InetSocketAddress("proxyURL", "proxyPort"))
.setCredentials("proxyUsername", "proxyPassword");
HttpClient httpClient = new NettyAsyncHttpClientBuilder()
.proxy(proxyOptions).build();
DataLakeServiceClientBuilder builder = new DataLakeServiceClientBuilder();
DataLakeServiceClient dataLakeServiceClient = builder.credential(clientSecretCredential)
.endpoint(endpoint).httpClient(httpClient).buildClient();

详情请参阅文件

最新更新