在 Azure 门户中,可以在创建流分析作业输出的步骤中创建 documentDB 数据库和集合。在使用 ARM 模板创建流作业和输出时是否可以这样做?
我发现只能使用 ARM 模板将 documentDB 帐户创建为资源,但是是否可以在设置作业输出的同时创建数据库和集合,就像在门户中一样?
在 Azure 门户中,可以在创建流分析作业输出的步骤中创建 documentDB 数据库和集合。在使用 ARM 模板创建流作业和输出时是否可以这样做?
我发现只能使用 ARM 模板将 documentDB 帐户创建为资源,但是是否可以在设置作业输出的同时创建数据库和集合,就像在门户中一样?
根据我的经验,目前不支持在 ARM 模板中创建 documentDB 数据库和集合。我将与 Azure 团队确认。如果有任何反馈我会在这里发布。
我的解决方法是我们可以使用REST API来做到这一点。如果 documentDB 数据库和集合存在,那么我们可以通过 ARM 模板使用 documentDb 数据库和集合创建作业的输出。
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.1.0.0",
"parameters": {
"databaseAccountName": {
"type": "string",
"metadata": {
"description": "The DocumentDB database account name."
}
},
"dbname": {
"type": "string",
"metadata": {
"description": "The database name"
}
},
"collectionname": {
"type": "string",
"metadata": {
"description": "collectionname"
}
},
"streamAnalyticsJobName": {
"type": "string",
"minLength": 3,
"maxLength": 63,
"metadata": {
"description": "Stream Analytics Job Name, can contain alphanumeric characters and hypen and must be 3-63 characters long"
}
},
"numberOfStreamingUnits": {
"type": "int",
"minValue": 1,
"maxValue": 48,
"allowedValues": [
1,
3,
6,
12,
18,
24,
30,
36,
42,
48
],
"metadata": {
"description": "Number of Streaming Units"
}
}
},
"variables": {
"offerType": "Standard"
},
"resources": [
{
"type": "Microsoft.StreamAnalytics/StreamingJobs",
"apiVersion": "2016-03-01",
"name": "[parameters('streamAnalyticsJobName')]",
"location": "[resourceGroup().location]",
"properties": {
"sku": {
"name": "Standard"
},
"outputErrorPolicy": "stop",
"eventsOutOfOrderPolicy": "adjust",
"eventsOutOfOrderMaxDelayInSeconds": 0,
"eventsLateArrivalMaxDelayInSeconds": 5,
"dataLocale": "en-US",
"inputs": [],
"Outputs": [
{
"Name": "relateddb",
"Properties": {
"DataSource": {
"Properties": {
"AccountId": "[parameters('databaseAccountName')]",
"AccountKey": "[listKeys(resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('databaseAccountName')), '2015-11-06').primaryMasterKey]",
"CollectionNamePattern": "[parameters('collectionname')]",
"Database": "[parameters('dbname')]",
"DocumentId": null,
"PartitionKey": null
},
"Type": "Microsoft.Storage/DocumentDB"
},
"Diagnostics": null,
"Etag": null,
"Serialization": null
}
}
],
"transformation": {
"name": "Transformation",
"properties": {
"streamingUnits": "[parameters('numberOfStreamingUnits')]",
"query": "SELECT\r\n *\r\nINTO\r\n [YourOutputAlias]\r\nFROM\r\n [YourInputAlias]"
}
}
}
}
]
}
万一有人偶然发现:现在可以通过 ARM 创建数据库和容器。
ARM 对 Azure 资源管理器中的数据库、容器和其他资源的支持
Azure Cosmos DB 现在为 Azure 资源管理器中的数据库、容器和产品提供支持。用户现在可以预配数据库和容器,并使用 Azure 资源管理器模板或 PowerShell 设置吞吐量。此支持适用于所有 API,包括 SQL (Core)、MongoDB、Cassandra、Gremlin 和 Table。此功能还允许客户创建自定义 RBAC 角色,以创建、删除或修改 Azure Cosmos DB 中数据库和容器的设置。若要了解详细信息并开始使用,请参阅 Azure Cosmos DB Azure 资源管理器模板。
https://docs.microsoft.com/en-us/azure/cosmos-db/manage-sql-with-resource-manager
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"accountName": {
"type": "string",
"defaultValue": "[concat('sql-', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Cosmos DB account name"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for the Cosmos DB account."
}
},
"primaryRegion":{
"type":"string",
"metadata": {
"description": "The primary replica region for the Cosmos DB account."
}
},
"secondaryRegion":{
"type":"string",
"metadata": {
"description": "The secondary replica region for the Cosmos DB account."
}
},
"defaultConsistencyLevel": {
"type": "string",
"defaultValue": "Session",
"allowedValues": [ "Eventual", "ConsistentPrefix", "Session", "BoundedStaleness", "Strong" ],
"metadata": {
"description": "The default consistency level of the Cosmos DB account."
}
},
"maxStalenessPrefix": {
"type": "int",
"minValue": 10,
"defaultValue": 100000,
"maxValue": 2147483647,
"metadata": {
"description": "Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 1000000. Multi Region: 100000 to 1000000."
}
},
"maxIntervalInSeconds": {
"type": "int",
"minValue": 5,
"defaultValue": 300,
"maxValue": 86400,
"metadata": {
"description": "Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400."
}
},
"multipleWriteLocations": {
"type": "bool",
"defaultValue": true,
"allowedValues": [ true, false ],
"metadata": {
"description": "Enable multi-master to make all regions writable."
}
},
"automaticFailover": {
"type": "bool",
"defaultValue": false,
"allowedValues": [ true, false ],
"metadata": {
"description": "Enable automatic failover for regions. Ignored when Multi-Master is enabled"
}
},
"databaseName": {
"type": "string",
"metadata": {
"description": "The name for the SQL database"
}
},
"throughput": {
"type": "int",
"defaultValue": 400,
"minValue": 400,
"maxValue": 1000000,
"metadata": {
"description": "The throughput for the database"
}
},
"container1Name": {
"type": "string",
"defaultValue": "container1",
"metadata": {
"description": "The name for the first SQL container"
}
},
"container2Name": {
"type": "string",
"defaultValue": "container2",
"metadata": {
"description": "The name for the second SQL container"
}
}
},
"variables": {
"accountName": "[toLower(parameters('accountName'))]",
"consistencyPolicy": {
"Eventual": {
"defaultConsistencyLevel": "Eventual"
},
"ConsistentPrefix": {
"defaultConsistencyLevel": "ConsistentPrefix"
},
"Session": {
"defaultConsistencyLevel": "Session"
},
"BoundedStaleness": {
"defaultConsistencyLevel": "BoundedStaleness",
"maxStalenessPrefix": "[parameters('maxStalenessPrefix')]",
"maxIntervalInSeconds": "[parameters('maxIntervalInSeconds')]"
},
"Strong": {
"defaultConsistencyLevel": "Strong"
}
},
"locations":
[
{
"locationName": "[parameters('primaryRegion')]",
"failoverPriority": 0
},
{
"locationName": "[parameters('secondaryRegion')]",
"failoverPriority": 1
}
]
},
"resources":
[
{
"type": "Microsoft.DocumentDB/databaseAccounts",
"name": "[variables('accountName')]",
"apiVersion": "2016-03-31",
"location": "[parameters('location')]",
"kind": "GlobalDocumentDB",
"properties": {
"consistencyPolicy": "[variables('consistencyPolicy')[parameters('defaultConsistencyLevel')]]",
"locations": "[variables('locations')]",
"databaseAccountOfferType": "Standard",
"enableAutomaticFailover": "[parameters('automaticFailover')]",
"enableMultipleWriteLocations": "[parameters('multipleWriteLocations')]"
}
},
{
"type": "Microsoft.DocumentDB/databaseAccounts/apis/databases",
"name": "[concat(variables('accountName'), '/sql/', parameters('databaseName'))]",
"apiVersion": "2016-03-31",
"dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/', variables('accountName'))]" ],
"properties":{
"resource":{
"id": "[parameters('databaseName')]"
},
"options": { "throughput": "[parameters('throughput')]" }
}
},
{
"type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers",
"name": "[concat(variables('accountName'), '/sql/', parameters('databaseName'), '/', parameters('container1Name'))]",
"apiVersion": "2016-03-31",
"dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/apis/databases', variables('accountName'), 'sql', parameters('databaseName'))]" ],
"properties":
{
"resource":{
"id": "[parameters('container1Name')]",
"partitionKey": {
"paths": [
"/MyPartitionKey1"
],
"kind": "Hash"
},
"indexingPolicy": {
"indexingMode": "consistent",
"includedPaths": [{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "number",
"precision": -1
},
{
"kind": "Range",
"dataType": "string",
"precision": -1
}
]
}
],
"excludedPaths": [{
"path": "/MyPathToNotIndex/*"
}
]
}
}
}
},
{
"type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers",
"name": "[concat(variables('accountName'), '/sql/', parameters('databaseName'), '/', parameters('container2Name'))]",
"apiVersion": "2016-03-31",
"dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/apis/databases', variables('accountName'), 'sql', parameters('databaseName'))]" ],
"properties":
{
"resource":{
"id": "[parameters('container2Name')]",
"partitionKey": {
"paths": [
"/MyPartitionKey2"
],
"kind": "Hash"
},
"indexingPolicy": {
"indexingMode": "consistent",
"includedPaths": [{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "number",
"precision": -1
},
{
"kind": "Range",
"dataType": "string",
"precision": -1
}
]
}
]
}
}
}
}
]
}