试图使用Java从webapp在datalake中创建文件

问题描述 投票:0回答:1

下面是在datalake中创建文件的代码段。 ADLException抛出在client.createfile行。经许可检查,用户已读取,写入和执行。有人可以帮忙解决这个问题吗?

尝试{

                     OutputStream stream = client.createFile("/Raw/TEST/"+FuFileName, IfExists.OVERWRITE);

                    PrintStream out = new PrintStream(stream);
                    for (int i = 1; i <= 10; i++) {
                        out.println("This is line #" + i);
                        out.format("This is the same line (%d), but using formatted output. %n", i);
                    }
                    out.close();
                } catch (ADLException ex) {
                    printExceptionDetails(ex);
                } catch (Exception ex) {
                    System.out.format(" Exception: %s%n Message: %s%n", ex.getClass().getName(), ex.getMessage());
                }
java web-applications azure-active-directory azure-data-lake
1个回答
0
投票

如果要使用Java在Azure Data Lake Gen1中创建文件,我们可以使用service-to-service authentication。详细步骤如下。

  1. Create an Active Directory web applicationenter image description here

  2. Assign the Azure AD application to the Azure Data Lake Storage Gen1 account file or folderenter image description here

  3. 代码

 private static String clientId = "FILL-IN-HERE";
 private static String authTokenEndpoint = "FILL-IN-HERE";
 private static String clientKey = "FILL-IN-HERE";

 AccessTokenProvider provider = new ClientCredsTokenProvider(authTokenEndpoint, clientId, clientKey); 
private static String accountFQDN = "FILL-IN-HERE";  // full account FQDN, not just the account name
ADLStoreClient client = ADLStoreClient.createClient(accountFQDN, provider);

try {
String filename = "/a/b/c.txt";
OutputStream stream = client.createFile(filename, IfExists.OVERWRITE  );
PrintStream out = new PrintStream(stream);
for (int i = 1; i <= 10; i++) {
    out.println("This is line #" + i);
    out.format("This is the same line (%d), but using formatted output. %n", i);
}
out.close();
System.out.println("File created.");

}catch(Exception ex){
 System.out.format(" Exception: %s%n Message: %s%n", ex.getClass().getName(), ex.getMessage());
}

有关更多详细信息,请参阅https://docs.microsoft.com/en-us/azure/data-lake-store/data-lake-store-get-started-java-sdk

© www.soinside.com 2019 - 2024. All rights reserved.