Brett Postin
Brett Postin

Reputation: 11375

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:

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?

Upvotes: 1

Views: 376

Answers (1)

Jim Xu
Jim Xu

Reputation: 23141

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

Upvotes: 1

Related Questions