Gérer les ressources d’Azure Cosmos DB for Apache Cassandra à l’aide de modèles Azure Resource Manager
S’APPLIQUE À : Cassandra
Dans cet article, vous apprenez à utiliser des modèles Azure Resource Manager pour faciliter le déploiement et la gestion de vos espaces de clés, tables et comptes Azure Cosmos DB.
Les exemples qu’il contient ne portent que sur les comptes d’API pour Cassandra. Pour obtenir des exemples liés à d’autres comptes de type d’API, consultez les articles Utiliser des modèles Azure Resource Manager avec l’API d’Azure Cosmos DB pour NoSQL, Gremlin, MongoDB et Table.
Important
- Les noms de compte sont limités à 44 caractères, tout en minuscules.
- Pour changer les valeurs de débit, redéployez le modèle avec les valeurs de RU/s mises à jour.
- Quand vous ajoutez ou supprimez des emplacements dans un compte Azure Cosmos DB, vous ne pouvez pas simultanément modifier d’autres propriétés. Ces opérations doivent être effectuées séparément.
Pour créer l’une des ressources Azure Cosmos DB ci-dessous, copiez l’exemple de modèle suivant dans un nouveau fichier json. Vous pouvez éventuellement créer un fichier json de paramètres à utiliser lors du déploiement de plusieurs instances de la même ressource avec des valeurs et noms différents. Il existe de nombreuses façons de déployer des modèles Azure Resource Manager, notamment : le Portail Azure, Azure CLI, Azure PowerShell et GitHub.
Compte Azure Cosmos DB pour Cassandra avec débit approvisionné en mode de mise à l’échelle automatique
Ce modèle crée un compte Azure Cosmos DB dans deux régions avec des options de cohérence et de basculement, ainsi qu’un espace de clés et une table configurés pour le débit approvisionné en mode de mise à l’échelle automatique. Ce modèle est également disponible pour un déploiement en un clic à partir de la galerie de modèles de démarrage rapide Azure.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.8.9.13224",
"templateHash": "9558567034094647188"
}
},
"parameters": {
"accountName": {
"type": "string",
"defaultValue": "[format('cassandra-{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Cosmos DB account name, max length 44 characters"
}
},
"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": "Eventual",
"metadata": {
"description": "The default consistency level of the Cosmos DB account."
},
"allowedValues": [
"Eventual",
"ConsistentPrefix",
"Session",
"BoundedStaleness",
"Strong"
]
},
"maxStalenessPrefix": {
"type": "int",
"defaultValue": 100000,
"metadata": {
"description": "Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 2,147,483,647. Multi Region: 100,000 to 2,147,483,647."
},
"maxValue": 1000000,
"minValue": 10
},
"maxIntervalInSeconds": {
"type": "int",
"defaultValue": 300,
"metadata": {
"description": "Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84,600. Multi Region: 300 to 86,400."
},
"maxValue": 86400,
"minValue": 5
},
"systemManagedFailover": {
"type": "bool",
"defaultValue": true,
"metadata": {
"description": "Enable system managed failover for regions"
},
"allowedValues": [
true,
false
]
},
"keyspaceName": {
"type": "string",
"metadata": {
"description": "The name for the Cassandra Keyspace"
}
},
"tableName": {
"type": "string",
"metadata": {
"description": "The name for the Cassandra table"
}
},
"autoscaleMaxThroughput": {
"type": "int",
"defaultValue": 1000,
"metadata": {
"description": "Maximum autoscale throughput for the Cassandra table"
},
"maxValue": 1000000,
"minValue": 1000
}
},
"variables": {
"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,
"isZoneRedundant": false
},
{
"locationName": "[parameters('secondaryRegion')]",
"failoverPriority": 1,
"isZoneRedundant": false
}
]
},
"resources": [
{
"type": "Microsoft.DocumentDB/databaseAccounts",
"apiVersion": "2022-05-15",
"name": "[toLower(parameters('accountName'))]",
"location": "[parameters('location')]",
"kind": "GlobalDocumentDB",
"properties": {
"capabilities": [
{
"name": "EnableCassandra"
}
],
"consistencyPolicy": "[variables('consistencyPolicy')[parameters('defaultConsistencyLevel')]]",
"locations": "[variables('locations')]",
"databaseAccountOfferType": "Standard",
"enableAutomaticFailover": "[parameters('systemManagedFailover')]"
}
},
{
"type": "Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces",
"apiVersion": "2022-05-15",
"name": "[format('{0}/{1}', toLower(parameters('accountName')), parameters('keyspaceName'))]",
"properties": {
"resource": {
"id": "[parameters('keyspaceName')]"
}
},
"dependsOn": [
"[resourceId('Microsoft.DocumentDB/databaseAccounts', toLower(parameters('accountName')))]"
]
},
{
"type": "Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces/tables",
"apiVersion": "2022-05-15",
"name": "[format('{0}/{1}', format('{0}/{1}', toLower(parameters('accountName')), parameters('keyspaceName')), parameters('tableName'))]",
"properties": {
"resource": {
"id": "[parameters('tableName')]",
"schema": {
"columns": [
{
"name": "loadid",
"type": "uuid"
},
{
"name": "machine",
"type": "uuid"
},
{
"name": "cpu",
"type": "int"
},
{
"name": "mtime",
"type": "int"
},
{
"name": "load",
"type": "float"
}
],
"partitionKeys": [
{
"name": "machine"
},
{
"name": "cpu"
},
{
"name": "mtime"
}
],
"clusterKeys": [
{
"name": "loadid",
"orderBy": "asc"
}
]
}
},
"options": {
"autoscaleSettings": {
"maxThroughput": "[parameters('autoscaleMaxThroughput')]"
}
}
},
"dependsOn": [
"[resourceId('Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces', split(format('{0}/{1}', toLower(parameters('accountName')), parameters('keyspaceName')), '/')[0], split(format('{0}/{1}', toLower(parameters('accountName')), parameters('keyspaceName')), '/')[1])]"
]
}
]
}
Compte Azure Cosmos DB for Cassandra avec débit approvisionné en mode standard
Ce modèle crée un compte Azure Cosmos DB dans deux régions avec des options de cohérence et de basculement, ainsi qu’un espace de clés et une table configurés pour le débit standard. Ce modèle est également disponible pour un déploiement en un clic à partir de la galerie de modèles de démarrage rapide Azure.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.8.9.13224",
"templateHash": "16028185346043260848"
}
},
"parameters": {
"accountName": {
"type": "string",
"defaultValue": "[format('cassandra-{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Cosmos DB account name, max length 44 characters"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for the Cosmos DB account."
}
},
"primaryRegion": {
"type": "string",
"metadata": {
"description": "The primary region for the Cosmos DB account."
}
},
"secondaryRegion": {
"type": "string",
"metadata": {
"description": "The secondary region for the Cosmos DB account."
}
},
"defaultConsistencyLevel": {
"type": "string",
"defaultValue": "Session",
"metadata": {
"description": "The default consistency level of the Cosmos DB account."
},
"allowedValues": [
"Eventual",
"ConsistentPrefix",
"Session",
"BoundedStaleness",
"Strong"
]
},
"maxStalenessPrefix": {
"type": "int",
"defaultValue": 100000,
"metadata": {
"description": "Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 2,147,483,647. Multi Region: 100,000 to 2,147,483,647."
},
"maxValue": 2147483647,
"minValue": 10
},
"maxIntervalInSeconds": {
"type": "int",
"defaultValue": 300,
"metadata": {
"description": "Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400."
},
"maxValue": 86400,
"minValue": 5
},
"systemManagedFailover": {
"type": "bool",
"defaultValue": true,
"metadata": {
"description": "Enable system managed failover for regions"
},
"allowedValues": [
true,
false
]
},
"keyspaceName": {
"type": "string",
"metadata": {
"description": "The name for the Cassandra Keyspace"
}
},
"tableName": {
"type": "string",
"metadata": {
"description": "The name for the Cassandra table"
}
},
"throughput": {
"type": "int",
"defaultValue": 400,
"metadata": {
"description": "The throughput for Cassandra table"
},
"maxValue": 1000000,
"minValue": 400
}
},
"variables": {
"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,
"isZoneRedundant": false
},
{
"locationName": "[parameters('secondaryRegion')]",
"failoverPriority": 1,
"isZoneRedundant": false
}
]
},
"resources": [
{
"type": "Microsoft.DocumentDB/databaseAccounts",
"apiVersion": "2022-05-15",
"name": "[toLower(parameters('accountName'))]",
"location": "[parameters('location')]",
"kind": "GlobalDocumentDB",
"properties": {
"capabilities": [
{
"name": "EnableCassandra"
}
],
"consistencyPolicy": "[variables('consistencyPolicy')[parameters('defaultConsistencyLevel')]]",
"locations": "[variables('locations')]",
"databaseAccountOfferType": "Standard",
"enableAutomaticFailover": "[parameters('systemManagedFailover')]"
}
},
{
"type": "Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces",
"apiVersion": "2022-05-15",
"name": "[format('{0}/{1}', toLower(parameters('accountName')), parameters('keyspaceName'))]",
"properties": {
"resource": {
"id": "[parameters('keyspaceName')]"
}
},
"dependsOn": [
"[resourceId('Microsoft.DocumentDB/databaseAccounts', toLower(parameters('accountName')))]"
]
},
{
"type": "Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces/tables",
"apiVersion": "2022-05-15",
"name": "[format('{0}/{1}', format('{0}/{1}', toLower(parameters('accountName')), parameters('keyspaceName')), parameters('tableName'))]",
"properties": {
"resource": {
"id": "[parameters('tableName')]",
"schema": {
"columns": [
{
"name": "loadid",
"type": "uuid"
},
{
"name": "machine",
"type": "uuid"
},
{
"name": "cpu",
"type": "int"
},
{
"name": "mtime",
"type": "int"
},
{
"name": "load",
"type": "float"
}
],
"partitionKeys": [
{
"name": "machine"
},
{
"name": "cpu"
},
{
"name": "mtime"
}
],
"clusterKeys": [
{
"name": "loadid",
"orderBy": "asc"
}
]
},
"options": {
"throughput": "[parameters('throughput')]"
}
}
},
"dependsOn": [
"[resourceId('Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces', split(format('{0}/{1}', toLower(parameters('accountName')), parameters('keyspaceName')), '/')[0], split(format('{0}/{1}', toLower(parameters('accountName')), parameters('keyspaceName')), '/')[1])]"
]
}
]
}
Étapes suivantes
Voici quelques ressources supplémentaires :