通过 .NET SDK 创建链接的自承载集成运行时

Create linked self-hosted integration runtime via .NET SDK

在 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"
    )
);

以上代码执行成功,我可以看到请求 return 预期的有效负载。但是在 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}");
}

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

文档目前对此不甚了解,如何实现?

如果我们想在另一个工厂中创建链接的self-hosted集成运行时,我们需要使用步骤。详情请参考document

  1. 创建共享 self-hosted 集成运行时

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

  3. 使用共享 self-hosted 集成运行时的资源 ID 创建 IR

关于如何使用Net SDK实现,请参考以下步骤

  1. 创建服务主体并将Owner分配给sp

  2. 安装包

Install-Package Microsoft.Azure.Management.DataFactory
Install-Package Microsoft.Azure.Management.Authorization-IncludePrerelease
Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory
  1. 代码
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
                     }
                   } });