在 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}");
}
似乎链接的集成运行时只是部分创建或处于不完整状态,因此它在门户中不可见。
文档目前对此很清楚,如何实现?
答案 0 :(得分:1)
如果我们想在另一个工厂中创建一个链接的自托管集成运行时,我们需要使用这些步骤。有关详细信息,请参阅 document
创建共享的自托管集成运行时
向另一个数据工厂授予权限。然后另一个工厂有权访问IR
使用共享自托管集成运行时的资源 ID 创建 IR
关于如何使用Net SDK实现,请参考以下步骤
创建服务主体并将 Owner
分配给 sp
安装包
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
}
} });