gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 02:28:57 25 4
gpt4 key购买 nike

在 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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com