简体   繁体   English

如何使用 java sdk 在 azure 数据湖 gen1 中创建资源?

[英]How to create resources in azure data lake gen1 with java sdk?

I am new to azure data lake gen1.我是 azure 数据湖 gen1 的新手。 I am trying to create files and directories with the java sdk. SO far, I have written this piece of code to perform the creation operation.我正在尝试使用 java sdk 创建文件和目录。到目前为止,我已经编写了这段代码来执行创建操作。

   final static String clientId =    "b";
   final static String tenantId = "";
   final static String clientSecret = "";

public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {

       String authority = "https://login.microsoftonline.com/b94/oauth2/v2.0/token";
       AuthenticationContext context = new AuthenticationContext(authority, true,    Executors.newFixedThreadPool(1));
       Future<AuthenticationResult> result = context.acquireToken("https://management.core.windows.net/", new    ClientCredential(clientId, clientSecret), null);
       ADLStoreClient client = ADLStoreClient.createClient("kaushal.azuredatalakestore.net",    result.get().getAccessToken());
       client.createDirectory("/test");

   }

I get following error on execution of above code: ---执行上述代码时出现以下错误:---

Exception in thread "main"线程“main”中的异常

com.microsoft.azure.datalake.store.ADLException: Operation MKDIRS failed with HTTP403: AccessControlException Last encountered exception thrown after 1 tries [HTTP403(AccessControlException)] com.microsoft.azure.datalake.store.ADLException:操作 MKDIRS 因 HTTP403 失败:AccessControlException 最后遇到的异常在 1 次尝试后抛出 [HTTP403(AccessControlException)]

What surprises me is that, I am successfully able to create resources via console but not with the code, I am not trying to find the actual root cause of this error.令我惊讶的是,我能够通过控制台成功创建资源,但不能使用代码,我并没有试图找到此错误的实际根本原因。

Your code seems fine, although check out a working example as below.您的代码看起来不错,但请查看下面的工作示例。

From the portal, you need to add the execute permission to the root node, if not done already.从门户中,您需要将执行权限添加到根节点(如果尚未完成)。 And don't forget to grant access ADL permissions to your client.并且不要忘记向您的客户授予访问 ADL 权限。

Navigate to your ADL account and then select Access Control (IAM):导航到您的 ADL 帐户,然后导航到 select 访问控制 (IAM):

  1. Register your application (hope thats done already)注册您的应用程序(希望已经完成)

  2. Navigate to your ADL account and then select Access Control (IAM):导航到您的 ADL 帐户,然后导航到 select 访问控制 (IAM):

  3. Click on +Add to add to add role-based permissions.点击+Add添加添加基于角色的权限。

  4. Under Role select the "Owner".在角色 select“所有者”下。 Under Select, select your application.下Select、select您申请。 This will grant the "Owner" role for this ADL account to your application.这会将此 ADL 帐户的“所有者”角色授予您的应用程序。

Note: If you are not able to assign the "Owner" role, you can set fine-grained RWX ACL permissions for your application, allowing it access to the files and folders of your ADLS account.注意:如果您无法分配“所有者”角色,您可以为您的应用程序设置细粒度的 RWX ACL 权限,允许它访问您的 ADLS 帐户的文件和文件夹。

Refer: Access control in Azure Data Lake Storage Gen1参考: Azure Data Lake Storage Gen1中的访问控制

Example: to create a directory named " kar " in ktestadls.azuredatalakestore.net示例:ktestadls.azuredatalakestore.net中创建名为“ kar ”的目录

import com.microsoft.aad.adal4j.AuthenticationContext;
import com.microsoft.aad.adal4j.AuthenticationResult;
import com.microsoft.aad.adal4j.ClientCredential;
import com.microsoft.azure.datalake.store.ADLStoreClient;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class CreateDirectory {

    static ADLStoreClient client;

    public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
        setup();
    }

    public static void setup() throws IOException, ExecutionException, InterruptedException {
        String APP_ID = "<your app id>";
        String APP_SECRET = "<your app secret>";
        String dirName = "/kar";
        String StoreAcct = "ktestadls";

        String authority = "https://login.microsoftonline.com/<your tenant id>";
        String resourcUrl = "https://management.core.windows.net/";
        ExecutorService service = Executors.newFixedThreadPool(1);

        AuthenticationContext context = new AuthenticationContext(authority, true, service);

        // Acquire Token
        Future<AuthenticationResult> result = context.acquireToken(
                resourcUrl,
                new ClientCredential(APP_ID, APP_SECRET),
                null
        );
        String token = result.get().getAccessToken();
        System.out.println(token);

        String account = StoreAcct + ".azuredatalakestore.net";
        client = ADLStoreClient.createClient(account, token);

        client.createDirectory(dirName);
        System.out.println("finish.....");

    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure DataLake Gen1 python SDK 用于删除目录上的递归 Acl - Azure DataLake Gen1 python SDK for removing recursive Acl on directories 无法使用 python azure-storage-file-datalake SDK 在 Azure Data Lake Gen2 中创建 Append Blob - Cannot create Append Blobs in Azure Data Lake Gen2 using python azure-storage-file-datalake SDK 使用 Databricks /mnt 安装 Azure Data lake Gen2 - Mounting Azure Data lake Gen2 with Databricks /mnt 使用 Azure 数据工厂数据流将 CSV 文件下沉到 Azure Data Lake Gen2 时如何删除额外文件? - How to remove extra files when sinking CSV files to Azure Data Lake Gen2 with Azure Data Factory data flow? 如何创建到 Azure 数据湖存储到 API 的连接? - How to create a connection to Azure data lake storage to API? 如何使用 dbt 将镶木地板文件从 Azure Data Lake Gen2/Azure Blob 存储加载到专用池? - How to load parquet files from Azure Data Lake Gen2/Azure Blob Storage to Dedicated pool using dbt? 使用 Elastic Stack 对驻留在 Azure Data Lake Storage Gen2 中的数据进行实时数据分析 - Realtime data analytics using Elastic Stack on data residing in Azure Data Lake Storage Gen2 Databricks、dbutils、获取 Azure Data Lake gen 2 路径中所有子文件夹的文件计数和文件大小 - Databricks, dbutils, get filecount and filesize of all subfolders in Azure Data Lake gen 2 path Azure Data Lake Gen2 存储帐户 blob 与 adf 选择 - Azure Data Lake Gen2 Storage Account blob vs adf choice 获取列表中数据湖 gen2 文件夹的所有内容 azure 突触工作区 - get all the contents of data lake gen2 folder in a list azure synapse workspace
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM