Попытка создать файл в datalake из веб-приложения, используя Java - PullRequest
0 голосов
/ 01 ноября 2019

Ниже приведен фрагмент кода для создания файла в datalake. ADLException генерируется в строке client.createfile. Проверяется с разрешения пользователя на чтение, запись и выполнение. Может кто-нибудь помочь, как справиться с этим.

try {

                     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());
                }

1 Ответ

0 голосов
/ 04 ноября 2019

Если вы хотите создать файл в Azure Data Lake Gen1 с Java, мы можем использовать меж сервисную аутентификацию . Подробные шаги приведены ниже.

  1. Создание веб-приложения Active Directory enter image description here

  2. Назначение приложения Azure AD файлу или папке учетной записи Gen1 хранилища озера данных Azure enter 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.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...