我使用 ARM 模板创建了带有少量链接服务的 Azure 数据工厂。我想使用 PowerShell 或 CLI 或任何其他方式测试链接服务的连接性。
答案 0 :(得分:1)
链接服务连通性测试
function connect($SubscriptionID)
{
if($null -eq (Get-AzureRMContext).Account)
{
Connect-AzureRmAccount
Select-AzureRmSubscription -Subscription $SubscriptionID
}
}
function getBearer([string]$TenantID, [string]$ClientID, [string]$ClientSecret)
{
$TokenEndpoint = {https://login.windows.net/{0}/oauth2/token} -f $TenantID
$ARMResource = "https://management.core.windows.net/";
$Body = @{
'resource'= $ARMResource
'client_id' = $ClientID
'grant_type' = 'client_credentials'
'client_secret' = $ClientSecret
}
$params = @{
ContentType = 'application/x-www-form-urlencoded'
Headers = @{'accept'='application/json'}
Body = $Body
Method = 'Post'
URI = $TokenEndpoint
}
$token = Invoke-RestMethod @params
Return "Bearer " + ($token.access_token).ToString()
}
function getLinkedService([string]$LinkedService)
{
$ADFEndpoint = "https://management.azure.com/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroup/providers/Microsoft.DataFactory/factories/$DataFactoryName/linkedservices/$($LinkedService)?api-version=2018-06-01"
$params = @{
ContentType = 'application/json'
Headers = @{'accept'='application/json';'Authorization'=$BearerToken}
Method = 'GET'
URI = $ADFEndpoint
}
$a = Invoke-RestMethod @params
Return ConvertTo-Json -InputObject @{"linkedService" = $a} -Depth 10
}
function testLinkedServiceConnection($Body)
{
$AzureEndpoint = "https://management.azure.com/subscriptions/$SubscriptionID/resourcegroups/$ResourceGroup/providers/Microsoft.DataFactory/factories/$DataFactoryName/testConnectivity?api-version=2017-09-01-preview"
$params = @{
ContentType = 'application/json'
Headers = @{'accept'='application/json';'Authorization'=$BearerToken}
Body = $Body
Method = 'Post'
URI = $AzureEndpoint
}
Return (Invoke-RestMethod @params).succeeded
}
# These are dummy secrets!
$ClientID = "d8e4efe0-f335-4da8-9adb-38942dca3783"
$ClientSecret = "TNALx46f08RIMui8iUvTCFbbWb/yIS+AQA1WlwBN7oo="
$DataFactoryName = "dataThirstADFv2Test1"
$ResourceGroup = "dataThirstTestBed8"
$SubscriptionID = "d4c56897-10e7-4c62-a139-326bcf267f68"
connect $SubscriptionID
$BearerToken = getBearer "bb0280d2-a9cf-46e8-9485-19d65b1b2c84" $ClientID $ClientSecret
$LinkedServiceBody = getLinkedService "LS_DataThirst_TestBed8_ADLS"
testLinkedServiceConnection $LinkedServiceBody
为了进一步参考,您可以通过Testing linked services 对于代码 Github link