c# - 通过 .NET SDK 创建链接的自托管集成运行时

标签 c# azure azure-data-factory azure-sdk-.net

在 Azure 数据工厂中,我尝试使用 .NET Azure 管理 SDK 创建链接的自托管集成运行时。

我在 DataFactoryA 中有一个现有的自托管集成运行时。我想在 DataFactoryB 中创建链接的自托管集成运行时。

_client.IntegrationRuntimes.CreateLinkedIntegrationRuntime(
    resourceGroupName: resourceGroup,
    factoryName: sharedDataFactoryName,
    integrationRuntimeName: sharedIntegrationRuntimeName,

    new CreateLinkedIntegrationRuntimeRequest(
        name: integrationRuntimeName,
        subscriptionId: subscriptionId,
        dataFactoryName: dataFactoryName,
        dataFactoryLocation: "UK South"
    )
);

上面的代码执行成功,我可以看到请求返回了预期的有效负载。但是在 Azure 门户中我有以下内容:

  • 现有的自托管集成运行时类型现已列为“共享”。
  • 在现有自托管集成运行时“共享”属性下,链接的集成运行时列在目标数据工厂下。

但是,链接运行时未在目标数据工厂中列出,并且在创建链接服务时不可用。

此外,如果我通过 SDK 列出目标工厂的运行时,则不会列出运行时。

var list = _client.IntegrationRuntimes.ListByFactory(resourceGroup, dataFactoryName);
            
Console.WriteLine($"Data factory {dataFactoryName} has the following runtimes:");
            
foreach (var runtime in list)
{
    Console.WriteLine($"{runtime.Name} | {runtime.Etag}");
}

似乎链接的集成运行时仅部分创建或处于不完整状态,因此在门户中不可见。

目前对此的文档很少,如何实现?

最佳答案

如果我们想在另一个工厂创建链接的自托管集成运行时,我们需要使用以下步骤。更多详情请引用document

  1. 创建共享的自托管集成运行时

  2. 向另一个数据工厂授予权限。然后另一个工厂有权限访问IR

  3. 使用共享自承载集成运行时的资源 ID 创建 IR

如何使用Net SDK实现,请引用以下步骤

  1. 创建服务主体并将所有者分配给sp

  2. 安装包

Install-Package Microsoft.Azure.Management.DataFactory
Install-Package Microsoft.Azure.Management.Authorization-IncludePrerelease
Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory
  • 代码
  • var context = new AuthenticationContext(" https://login.microsoftonline.com/" + "<tenant>");
                ClientCredential cc = new ClientCredential("<sp client id>", " sp client secret");
                AuthenticationResult result = context.AcquireTokenAsync(
                    "https://management.azure.com/", cc).Result;
                ServiceClientCredentials cred = new TokenCredentials(result.AccessToken);
                var client =new DataFactoryManagementClient(cred)
                {
                    SubscriptionId = ""
                };
     
                // get required information
                var linkedFactoryName = "huryDF";
                var linkedFactoryGroupName = "huryTestGroup";
                var sharedFactoryName = "testfactory05";
                var sharedFactoryGroupName = "test001";
                var IRName = "MySelfHostedIR";
                 
                var integrationRuntime = await client.IntegrationRuntimes.GetAsync(sharedFactoryGroupName, sharedFactoryName, IRName);
                var linkedFactory = await client.Factories.GetAsync(linkedFactoryGroupName, linkedFactoryName);
                var sharedFactory= await client.Factories.GetAsync(sharedFactoryGroupName, sharedFactoryName);
                // grant permissions
                var managementClient = new AuthorizationManagementClient(cred);
                IPage<RoleDefinition> roleDefine = await managementClient.RoleDefinitions.ListAsync(sharedFactory.Id, new ODataQuery<RoleDefinitionFilter>()
                {
                    Filter= "roleName eq 'Contributor'"
                });
                await managementClient.RoleAssignments.CreateAsync(integrationRuntime.Id, Guid.NewGuid().ToString(), new RoleAssignmentCreateParameters()
                {
                    RoleDefinitionId = roleDefine.ToList().FirstOrDefault().Id,
                    PrincipalId = linkedFactory.Identity.PrincipalId.ToString()
                }) ;
    
                // create IR
                var res = await client.IntegrationRuntimes.CreateOrUpdateWithHttpMessagesAsync(linkedFactoryGroupName, linkedFactoryName, 
                       "test", 
                       new IntegrationRuntimeResource() { Properties= new SelfHostedIntegrationRuntime() { 
                         LinkedInfo= new LinkedIntegrationRuntimeRbacAuthorization() { 
                           ResourceId= integrationRuntime.Id
                         }
                       } });
    

    enter image description here enter image description here

    关于c# - 通过 .NET SDK 创建链接的自托管集成运行时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65903533/

    相关文章:

    c# - CefSharp - 无法加载文件或程序集 'CefSharp.Core.dll' 或其依赖项之一

    c# - 使这个 SQL 查询更有效率

    c# - 如何模拟静态覆盖?

    azure-data-factory - 在“复制数据”事件中从输出数组中提取元素

    azure-data-factory - 如何在 Databricks 作业集群上安装作业依赖库和 .whl 包

    azure - 一个源到多个汇的 azure 突触管道?

    c# - 在char数组的某个位置添加一个元素?

    azure - ADF 动态表达式 - 连接/如果缺少句点

    azure - 使用具有所有者角色的帐户创建 LoadBalancer 服务时 AKS 授权失败

    azure - 通过应用程序注册门户进行 Microsoft API 授权管理