簡體   English   中英

Azure數據湖連接與數據工廠自定義活動

[英]Azure data lake connection with data factory custom activity

我在azure數據工廠中遇到自定義活動的問題。 我想連接到其中的azure數據湖。 我正在使用以下命名空間:

using Microsoft.Azure.Management.DataLake.Store;
using Microsoft.IdentityModel.Clients.ActiveDirectory
using Microsoft.Rest.Azure.Authentication;

這是我的代碼:

    public ConnectDataLakeStore(string applicationId, string applicationSecretKey, string tenantId)
    {
        var credentials = new ClientCredential(applicationId, applicationSecretKey);
        var creds = ApplicationTokenProvider.LoginSilentAsync(tenantId, credentials).Result;
        var fileSystemClient = new DataLakeStoreFileSystemManagementClient(creds);
    }

我得到以下異常:

Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.Azure.Management.DataLake.Store.Models.AdlsErrorException: Operation returned an invalid status code 'Forbidden'
   at Microsoft.Azure.Management.DataLake.Store.FileSystemOperations.<ListFileStatusWithHttpMessagesAsync>d__12.MoveNext()

當我在本地環境中運行自定義活動時,一切正常。 部署到azure后出現問題。 我還為廣告應用程序提供了所有可能的權限。

任何提示?

我從你上面的評論中得知你已經解決了這個問題。 但仍然認為值得為未來的類似問題增加一些細節。

首先使用您的服務主體和域詳細信息創建憑據。

方法:

    private static ServiceClientCredentials AuthenticateAzure(string domainName, string clientID, string clientSecret)
    {
        SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

        var clientCredential = new ClientCredential(clientID, clientSecret);
        return ApplicationTokenProvider.LoginSilentAsync(domainName, clientCredential).Result;
    }

也許從庫配置或項目屬性中獲取值。

var creds = AuthenticateAzure(domainName, appId, appPass);

接下來,根據您的需要創建數據湖帳戶管理器或文件系統管理器的實例。

    private static DataLakeStoreFileSystemManagementClient adlsFileSystemClient;
    private static DataLakeStoreAccountManagementClient adlsAccountManagementClient;

    adlsFileSystemClient = new DataLakeStoreFileSystemManagementClient(creds);
    adlsAccountManagementClient = new DataLakeStoreAccountManagementClient(creds);

接下來創建類似下面的方法來將文件上傳到data lake store。

上傳器的執行速度比創建文件方法快。

    private static void UploadFile(string srcFilePath, string destFilePath, string accName, bool force = true)
    {
        var parameters = new UploadParameters(srcFilePath, destFilePath, accName, isOverwrite: force);
        var frontend = new DataLakeStoreFrontEndAdapter(accName, adlsFileSystemClient);
        var uploader = new DataLakeStoreUploader(parameters, frontend);
        uploader.Execute();
    }

資料來源:

ADF自定義活動 https://www.purplefrogsystems.com/paul/2016/11/creating-azure-data-factory-custom-activities/

ADL Auth https://www.purplefrogsystems.com/paul/2016/12/azure-data-lake-authentication-from-azure-data-factory/

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM