Why Java Azure Function App freezes when trying to access Azure datalake?

生来就可爱ヽ(ⅴ<●) 提交于 2021-01-29 12:28:00

问题


I am developing a Java Azure function that needs to download a file from Azure Datalake Gen2.
When the function tries to read the file, it freezes and no exception is thrown, and nothing is written to the console.

I am using the azure-storage-file-datalake SDK for Java dependency and this is my code:

import com.azure.storage.common.StorageSharedKeyCredential;
import com.azure.storage.file.datalake.DataLakeDirectoryClient;
import com.azure.storage.file.datalake.DataLakeFileClient;
import com.azure.storage.file.datalake.DataLakeFileSystemClient;
import com.azure.storage.file.datalake.DataLakeServiceClient;
import com.azure.storage.file.datalake.DataLakeServiceClientBuilder;

public DataLakeServiceClient GetDataLakeServiceClient(String accountName, String accountKey)
{
    StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey);
    DataLakeServiceClientBuilder builder = new DataLakeServiceClientBuilder();
    builder.endpoint("https://" + accountName + ".dfs.core.windows.net");
    builder.credential(sharedKeyCredential);
    return builder.buildClient();
}

public void DownloadFile(DataLakeFileSystemClient fileSystemClient, String fileName) throws Exception{

    DataLakeDirectoryClient directoryClient = fileSystemClient.getDirectoryClient("DIR");
    DataLakeDirectoryClient subdirClient= directoryClient.getSubdirectoryClient("SUBDIR");
    DataLakeFileClient fileClient = subdirClient.getFileClient(fileName);

    File file = new File("downloadedFile.txt");
    OutputStream targetStream = new FileOutputStream(file);
    fileClient.read(targetStream);
    targetStream.close();
}

@FunctionName("func")
public HttpResponseMessage run(
        @HttpTrigger(name = "req", methods = {HttpMethod.GET}, authLevel = AuthorizationLevel.ANONYMOUS)
        HttpRequestMessage<Optional<String>> request,
        final ExecutionContext context
    )
{
    String fileName= request.getQueryParameters().get("file");

    DataLakeServiceClient datalakeClient= GetDataLakeServiceClient("datalake", "<the shared key>");
    DataLakeFileSystemClient datalakeFsClient= datalakeClient.getFileSystemClient("fs");

    DownloadFile(datalakeFsClient, fileName);

}   

The app freezes when it hits fileClient.read(targetStream);
I've tried with really small files, I've checked the credentials and the file paths, the access rights to datalake, I've switched to SAS token - the result is the same: no error at all, but the app freezes.

I am using these Maven dependencies:

<dependency>
    <groupId>com.microsoft.azure.functions</groupId>
    <artifactId>azure-functions-java-library</artifactId>
</dependency>

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

回答1:


so i was facing the same problem.Then i came across this.

https://github.com/Azure/azure-functions-java-library/issues/113

This worked for me on java 8,azure function v3.

Set FUNCTIONS_WORKER_JAVA_LOAD_APP_LIBS to True in the function app Application settings.Then save and restart the function app.It will work.

Please check and do update if it worked for you as well.



来源:https://stackoverflow.com/questions/64349012/why-java-azure-function-app-freezes-when-trying-to-access-azure-datalake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!