感谢您的链接,它们是有用的资源。我已经设法让这个管道工作,该管道调用运行手册来调整天蓝色分析服务的大小。没有很好地记录运行手册返回失败和成功信息。
这里有一些代码可以提供一点帮助,我从几个地方获取了这些代码,但其中很多来自此 Microsoft 页面上的未解决问题 (https://github.com/MicrosoftDocs/azure-docs/issues/43897):https://docs.microsoft.com/en-us/azure/data-factory/control-flow-webhook-activity
datafactory Webhook 活动传入一些“Headers”,SourceHost 是 @pipeline().DataFactory 和 SourceProcess 是 @pipeline().Pipeline。这样我们就可以进行一些检查以确认运行手册是否由可接受的进程运行。
调用的主体是我们需要的其他变量:
@json(concat('{"AnalysisServer":"', pipeline().parameters.AASName, '", "MinimumSKU":"', pipeline().parameters.SKU,'"}') )
您的 Runbook 需要 WebhookData 参数
param
(
[Parameter (Mandatory=$false)]
[object] $WebhookData
)
然后您可以获取所有需要的信息,包括检查是否提供了回调:
if ($WebhookData)
{
# Split apart the WebhookData
$WebhookName = $WebhookData.WebhookName
$WebhookHeaders = $WebhookData.RequestHeader
$WebhookBody = $WebhookData.RequestBody | Convertfrom-Json
$WebhookADF = $WebhookHeaders.SourceHost
$WebhookPipeline = $WebhookHeaders.SourceProcess
Write-Output -InputObject ('Runbook started through webhook {0} called by {1} on {2}.' -f $WebhookName, $WebhookPipeline, $WebhookADF)
# if there's a callBackURI then we've been called by something that is waiting for a response
If ($WebhookBody.callBackUri)
{
$WebhookCallbackURI = $WebhookBody.callBackUri
}
...
}
变量$WebHookHeaders:@{Connection=Keep-Alive; Expect=100-continue; Host=sXXevents.azure-automation.net; SourceHost=**MYDATAFACTORYNAME**; SourceProcess=**MYPIPELINENAME**; x-ms-request-id=**UNIQUEIDENTIFIER**}
然后您可以从 json 正文中获取信息:$AzureAnalysisServerName = $WebHookBody.AnalysisServer
将错误/失败传回 Runbook 相对容易,请注意,我将成功/更新消息放入 $Message 中,并且只有在出现错误时才会在 $ErrorMessage 中包含内容:
$ErrorMessage = "Failed to do stuff I wanted"
if ($ErrorMessage)
{
$Output = [ordered]@{ output= @{
AzureAnalysisServerResize = "Failed" }
error = @{
ErrorCode = "ResizeError"
Message = $ErrorMessage
}
statusCode = "500"
}
} else {
$Output = [ordered]@{
output= @{
"AzureAnalysisServerResize" = "Success"
"message" = $Outputmessage
}
statusCode = "200"
}
}
$OutputJson = $Output | ConvertTo-Json -Depth 10
# if we have a callbackuri let the ADF Webhook activity know that the script is complete
# Otherwise it waits until its timeout
If ($WebhookCallBackURI)
{
$WebhookCallbackHeaders = @{
"Content-Type"="application/json"
}
Invoke-WebRequest -UseBasicParsing -Uri $WebhookCallBackURI -Method Post -Body $OutputJson -Header $WebhookCallbackHeaders
}
然后我用 else 结束 if ($WebhookData) { 调用,说明如果不是从 webhook 调用 runbook,则不应运行:
} else {
Write-Error -Message 'Runbook was not started from Webhook' -ErrorAction stop
}
传回错误消息很容易,传回成功消息很痛苦,但上述方法似乎有效,并且在我的数据工厂管道中我可以访问结果。
Output
{
"message": "Analysis Server MYSERVERNAME which is SKU XX is already at or above required SKU XX.",
"AzureAnalysisServerResize": "Success"
}
请注意,对于 Invoke-WebRequest,一些在线示例未指定 -UseBasicParsing,但我们不得不按照运行手册的抱怨:Invoke-WebRequest :无法解析响应内容,因为 Internet Explorer 引擎不可用,或 Internet Explorer 的首次启动配置不完整。