Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
101 views
in Technique[技术] by (71.8m points)

c# - Create linked self-hosted integration runtime via .NET SDK

Within Azure Data Factory, I am trying to create a linked self-hosted integrated runtime using the .NET Azure Management SDKs.

I have an existing self-hosted integrated runtime in DataFactoryA. I want to create a linked self-hosted integrated runtime in DataFactoryB.

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

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

The above code executes successfully and I can see the requests return the expected payloads. However within the Azure Portal I have the following:

  • The existing self-hosted integration runtime type is now listed as "Shared".
  • Under the existing self-hosted integration runtime "Shared" properties the linked integration runtime is listed under the target data factory.

However the linked runtime is not listed in the target data factory and is not available when creating linked services.

Additionally if I list the runtimes for the target factory via the SDK, the runtime is not listed.

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

It seems as though the linked integration runtime is only partially created or in an incomplete state such that it is not visible in the portal.

Documentation is currently light on this, how can it be achieved?

question from:https://stackoverflow.com/questions/65903533/create-linked-self-hosted-integration-runtime-via-net-sdk

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If we want to create a linked self-hosted integrated runtime in another factory, we need to use the steps. For more details, please refer to the document

  1. Create a shared self-hosted integration runtime

  2. Grant permission to another Data factory. Then another factory has permissions to access the IR

  3. Create IR with the resource id of shared self-hosted integration runtime

Regarding how to implement it with Net SDK, please refer to the following steps

  1. Create a service principal and assign Owner to the sp

  2. Install Package

Install-Package Microsoft.Azure.Management.DataFactory
Install-Package Microsoft.Azure.Management.Authorization-IncludePrerelease
Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory
  1. Code
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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...