-
Notifications
You must be signed in to change notification settings - Fork 338
/
Copy pathautoscale.sh
59 lines (50 loc) · 1.89 KB
/
autoscale.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# Passed validation in Cloud Shell on 2/20/2022
# <FullScript>
# Create a Cassandra keyspace and table with autoscale
# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="autoscale-casandra-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
keySpace="keyspace1-$randomIdentifier"
table="table1-$randomIdentifier"
maxThroughput=1000 #minimum = 1000
# Create a resource group
echo "Creating $resourceGroup in $location..."
az group create --name $resourceGroup --location "$location" --tags $tag
# Create a Cosmos account for Cassandra API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup --capabilities EnableCassandra --default-consistency-level Eventual --locations regionName="$location" failoverPriority=0 isZoneRedundant=False
# Create a Cassandra Keyspace
echo "Create $keySpace"
az cosmosdb cassandra keyspace create --account-name $account --resource-group $resourceGroup --name $keySpace
# Define the schema for the table
schema=$(cat << EOF
{
"columns": [
{"name": "columna","type": "uuid"},
{"name": "columnb","type": "int"},
{"name": "columnc","type": "text"}
],
"partitionKeys": [
{"name": "columna"}
],
"clusterKeys": [
{ "name": "columnb", "orderBy": "asc" }
]
}
EOF
)
# Persist schema to json file
echo "$schema" > "schema-$randomIdentifier.json"
# Create the Cassandra table
echo "Creating $table"
az cosmosdb cassandra table create --account-name $account --resource-group $resourceGroup --keyspace-name $keySpace --name $table --max-throughput $maxThroughput --schema @schema-$randomIdentifier.json
# Clean up temporary schema file
rm -f "schema-$randomIdentifier.json"
# </FullScript>
# </FullScript>
# echo "Deleting all resources"
# az group delete --name $resourceGroup -y