forked from Azure/azure-docs-powershell-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathps-cassandra-autoscale.ps1
65 lines (59 loc) · 2.72 KB
/
ps-cassandra-autoscale.ps1
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
60
61
62
63
64
65
# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Create Cosmos Cassandra API account with automatic failover,
# a keyspace, and a table with defined schema with autoscale throughput
# --------------------------------------------------
Function New-RandomString{Param ([Int]$Length = 10) return $(-join ((97..122) + (48..57) | Get-Random -Count $Length | ForEach-Object {[char]$_}))}
# --------------------------------------------------
$uniqueId = New-RandomString -Length 7 # Random alphanumeric string for unique resource names
$apiKind = "Cassandra"
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$locations = @()
$locations += New-AzCosmosDBLocationObject -LocationName "East Us" -FailoverPriority 0 -IsZoneRedundant 0
$locations += New-AzCosmosDBLocationObject -LocationName "West Us" -FailoverPriority 1 -IsZoneRedundant 0
$resourceGroupName = "mjbArmTest"#"myResourceGroup" # Resource Group must already exist
$accountName = "cosmos-$uniqueId" # Must be all lower case
$consistencyLevel = "Session"
$keyspaceName = "mykeyspace"
$tableName = "mytable"
$autoscaleMaxThroughput = 4000 #minimum = 4000
$partitionKeys = @("machine", "cpu", "mtime")
$clusterKeys = @(
@{ name = "loadid"; orderBy = "Asc" };
@{ name = "duration"; orderBy = "Desc" }
)
$columns = @(
@{ name = "loadid"; type = "uuid" };
@{ name = "machine"; type = "uuid" };
@{ name = "cpu"; type = "int" };
@{ name = "mtime"; type = "int" };
@{ name = "load"; type = "float" };
@{ name = "duration"; type = "float" }
)
# --------------------------------------------------
Write-Host "Creating account $accountName"
$account = New-AzCosmosDBAccount -ResourceGroupName $resourceGroupName `
-LocationObject $locations -Name $accountName -ApiKind $apiKind `
-DefaultConsistencyLevel $consistencyLevel `
-EnableAutomaticFailover:$true
Write-Host "Creating keyspace $keyspaceName"
$keyspace = New-AzCosmosDBCassandraKeyspace -ParentObject $account `
-Name $keyspaceName
# Table Schema
$psClusterKeys = @()
ForEach ($clusterKey in $clusterKeys) {
$psClusterKeys += New-AzCosmosDBCassandraClusterKey -Name $clusterKey.name -OrderBy $clusterKey.orderBy
}
$psColumns = @()
ForEach ($column in $columns) {
$psColumns += New-AzCosmosDBCassandraColumn -Name $column.name -Type $column.type
}
$schema = New-AzCosmosDBCassandraSchema `
-PartitionKey $partitionKeys `
-ClusterKey $psClusterKeys `
-Column $psColumns
Write-Host "Creating table $tableName"
$table = New-AzCosmosDBCassandraTable -ParentObject $keyspace `
-Name $tableName -Schema $schema -AutoscaleMaxThroughput $autoscaleMaxThroughput