如何为成功导入SQL DacPac创建事件网格订阅?

时间:2019-06-10 19:30:40

标签: azure azure-sql-database azure-eventgrid

我无法为“从DacPac创建新数据库”操作创建事件网格订阅。

我尝试为包含SQL Server的资源组创建事件网格订阅。我已启用所有事件以发送给资源组,并注册了一个Webhook以便发送资源组中的事件。我已经测试了事件网格订阅,它正在发送ResourceWriteSuccess,ResourceDeleteSuccess等的webhooks。因此,我知道我的应用程序和Azure之间的实现正常运行。

这是我要为其创建事件网格订阅的事件的有效负载。

{
    "authorization": {
        "action": "Microsoft.Sql/servers/import/action",
        "scope": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-resource-group/providers/Microsoft.Sql/servers/my-sql-server"
    },
    "caller": "00000000-0000-0000-0000-000000000000",
    "channels": "Operation",
    "claims": {
        "aud": "https://management.azure.com/",
        "iss": "https://sts.windows.net/00000000-0000-0000-0000-000000000000/",
        "iat": "1560193452",
        "nbf": "1560193452",
        "exp": "1560197352",
        "aio": "82WgYJi2DHbwKEodlmt4/lNKdx2cDQA=",
        "appid": "00000000-0000-0000-0000-000000000000",
        "appidacr": "1",
        "http://schemas.microsoft.com/identity/claims/identityprovider": "https://sts.windows.net/00000000-0000-0000-0000-000000000000/",
        "http://schemas.microsoft.com/identity/claims/objectidentifier": "00000000-0000-0000-0000-000000000000",
        "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "00000000-0000-0000-0000-000000000000",
        "http://schemas.microsoft.com/identity/claims/tenantid": "00000000-0000-0000-0000-000000000000",
        "uti": "OzdZ2AA_HkCWRjLQ0E9hAQ",
        "ver": "1.0"
    },
    "correlationId": "00000000-0000-0000-0000-000000000000",
    "description": "",
    "eventDataId": "00000000-0000-0000-0000-000000000000",
    "eventName": {
        "value": "EndRequest",
        "localizedValue": "End request"
    },
    "category": {
        "value": "Administrative",
        "localizedValue": "Administrative"
    },
    "eventTimestamp": "2019-06-10T19:09:14.4117972Z",
    "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-resource-group/providers/Microsoft.Sql/servers/my-sql-server/events/00000000-0000-0000-0000-000000000000/ticks/636957905544117972",
    "level": "Informational",
    "operationId": "5b1a45c6-297c-4c1e-81c5-31a10375a9e0",
    "operationName": {
        "value": "Microsoft.Sql/servers/import/action",
        "localizedValue": "Create new database from DacPac"
    },
    "resourceGroupName": "my-resource-group",
    "resourceProviderName": {
        "value": "Microsoft.Sql",
        "localizedValue": "Microsoft SQL"
    },
    "resourceType": {
        "value": "Microsoft.Sql/servers",
        "localizedValue": "Microsoft.Sql/servers"
    },
    "resourceId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-resource-group/providers/Microsoft.Sql/servers/my-sql-server",
    "status": {
        "value": "Accepted",
        "localizedValue": "Accepted"
    },
    "subStatus": {
        "value": "Accepted",
        "localizedValue": "Accepted (HTTP Status Code: 202)"
    },
    "submissionTimestamp": "2019-06-10T19:10:57.1665135Z",
    "subscriptionId": "00000000-0000-0000-0000-000000000000",
    "properties": {
        "statusCode": "Accepted",
        "serviceRequestId": "00000000-0000-0000-0000-000000000000"
    },
    "relatedEvents": []
}

我希望为启用了所有事件的资源组创建事件网格订阅将为上面显示的事件发送一个webhook;但是,我没有收到任何表示此操作已成功执行的webhook。

1 个答案:

答案 0 :(得分:1)

基于我们的讨论和测试:

    使用Azure门户上的功能
  1. 导入数据库效果很好,门户 Activity Log 显示了导入后台异步过程的所有步骤,以及AEG事件已发布。

  2. 使用REST POST Databases - Import Export - Import
  3. 导入数据库活动日志中具有不同的行为,并且没有发布任何AEG事件。 以下示例显示了此问题:

    POST: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Default-SQL-NorthCentralUS/providers/Microsoft.Sql/servers/h000000000/import?api-version=2014-04-01
    {
      "databaseName": "TestDbImport",
      "edition": "Basic",
      "serviceObjectiveName": "Basic",
      "maxSizeBytes": "2147483648",
      "storageKeyType": "StorageAccessKey",
      "storageKey": "....",
      "storageUri": "https://xxxxxxx.blob.core.windows.net/database/testbacpac.bacpac",
      "administratorLogin": "myadmin",
      "administratorLoginPassword": "********",
      "authenticationType": "SQL"
    }
    

    POST已被接受,门户网站活动日志正在推送以下内容:

activelog1

以上日志消息将永久保留,表明已接受导入操作,但是此导入后台进程中没有其他活动日志。没有日志消息,表明该过程已完成,等等。此外,此导入过程中没有发布任何AEG事件。另一方面,已经创建,更新了数据库等,但是我们没有完成的任何迹象。请注意,活动日志状态应以 Failed Succeeded 状态完成。

我可以在这里看到一个问题。如果没有活动日志消息,我们将无法从该资源组获得AEG事件。看来,“活动”日志消息的“导入”操作过程中可能存在检测错误。

请注意,其他REST API(例如导出,创建数据库,删除等)运行良好,包括所有活动日志和AEG事件。

因此,以下是此暂时性错误的解决方法。它基于在使用导入操作之前创建一个空数据库。

以下是示例:

创建空数据库:

    PUT: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Default-SQL-NorthCentralUS/providers/Microsoft.Sql/servers/h000000000/databases/TestDbImport?api-version=2017-10-01-preview
    {
      "location": "NorthCentralUS"
    }

传递有关成功编写数据库的AEG事件后,

 "eventType": "Microsoft.Resources.ResourceWriteSuccess",
 "resourceUri": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/Default-SQL-NorthCentralUS/providers/Microsoft.Sql/servers/h000000000/databases/TestDbImport",
 "operationName": "Microsoft.Sql/servers/databases/write",
 "status": "Succeeded",

导入操作可以过帐(请参见上面的url和有效负载)。

以下来自我的门户的活动日志显示了对空数据库执行导入操作的所有活动:

enter image description here

对于此问题,我建议通过导入操作向Azure SQL团队反馈。