Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CosmosDB Adding enable MaterializedViews parameter for create/update database … #4499

Merged
merged 7 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/cosmosdb-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Release History
===============
0.15.0
++++++
* Add `--enable-materialized-views` parameter for create/update database account.

0.14.0
++++++
* List the different versions of databases and graphs that were modified for a gremlin database account.
Expand Down
54 changes: 54 additions & 0 deletions src/cosmosdb-preview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ This package provides commands to
- List the different versions of databases and collections that were modified
- Trigger a point in time restore on the Azure CosmosDB continuous mode backup accounts
- Update the backup interval and backup retention of periodic mode backup accounts
- Create a new Azure Cosmos DB database account with materialized views
- Update an Azure Cosmos DB database account to enable materialized views
- Create/Delete a cosmosdb materialized views builder service resource

## How to use ##

Expand Down Expand Up @@ -186,3 +189,54 @@ az cosmosdb table restorable-resource list \
--restore-location "eastus" \
--restore-timestamp "2020-07-20T16:09:53+0000"
```

#### Create a new CosmosDB materialized views enabled Account ####

```sh
az cosmosdb create \
--resource-group "my-rg" \
--name "my-db-account" \
--enable-materialized-views true \
--capabilities "EnableCassandra" "CassandraEnableMaterializedViews"
```

#### Enable materialized views on a existing CosmosDB Account ####

```sh
az cosmosdb update \
--resource-group "my-rg" \
--name "my-db-account" \
--enable-materialized-views true
```

#### Create a cosmosdb materialized views builder service resource ####

```sh
az cosmosdb service create \
--resource-group "MyResourceGroup" \
--account-name "MyAccount" \
--name "MaterializedViewsBuilder" \
--kind "MaterializedViewsBuilder" \
--count 3 \
--size "Cosmos.D4s"
```

#### Update a cosmosdb materialized views builder service resource ####

```sh
az cosmosdb service update \
--resource-group "MyResourceGroup" \
--account-name "MyAccount" \
--name "MaterializedViewsBuilder" \
--kind "MaterializedViewsBuilder" \
--count 3
```

#### Delete the cosmosdb materialized views builder service resource ####

```sh
az cosmosdb service delete \
--resource-group "MyResourceGroup" \
--account-name "MyAccount"
--name "MaterializedViewsBuilder" \
```
33 changes: 32 additions & 1 deletion src/cosmosdb-preview/azext_cosmosdb_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@
- name: Create a cosmosdb service resource.
text: |
az cosmosdb service create --resource-group MyResourceGroup --account-name MyAccount --name "sqlDedicatedGateway" --kind "SqlDedicatedGateway" --count 3 --size "Cosmos.D4s"
- name: Create a cosmosdb materialized views builder service resource.
text: |
az cosmosdb service create --resource-group MyResourceGroup --account-name MyAccount --name "MaterializedViewsBuilder" --kind "MaterializedViewsBuilder" --count 3 --size "Cosmos.D4s"
"""

helps['cosmosdb service update'] = """
Expand All @@ -188,6 +191,9 @@
- name: Update a cosmosdb service resource.
text: |
az cosmosdb service update --resource-group MyResourceGroup --account-name MyAccount --name "sqlDedicatedGateway" --kind "SqlDedicatedGateway" --count 3
- name: Update a cosmosdb materialized views builder service resource.
text: |
az cosmosdb service update --resource-group MyResourceGroup --account-name MyAccount --name "MaterializedViewsBuilder" --kind "MaterializedViewsBuilder" --count 3
"""

helps['cosmosdb service list'] = """
Expand All @@ -206,6 +212,9 @@
- name: Delete the given cosmosdb service resource.
text: |
az cosmosdb service delete --resource-group MyResourceGroup --account-name MyAccount --name "sqlDedicatedGateway"
- name: Delete the cosmosdb materialized views builder service resource.
text: |
az cosmosdb service delete --resource-group MyResourceGroup --account-name MyAccount --name "MaterializedViewsBuilder"
"""

helps['cosmosdb mongodb role'] = """
Expand Down Expand Up @@ -392,13 +401,35 @@
long-summary: |
Usage: --tables-to-restore tables=table1 [table2 ...]
examples:
- name: Creates a new Azure Cosmos DB database account. (autogenerated)
- name: DB database account. (autogenerated)
text: az cosmosdb create --name MyCosmosDBDatabaseAccount --resource-group MyResourceGroup --subscription MySubscription
crafted: true
- name: Creates a new Azure Cosmos DB database account with two regions. UK South is zone redundant.
text: az cosmosdb create -n myaccount -g mygroup --locations regionName=eastus failoverPriority=0 isZoneRedundant=False --locations regionName=uksouth failoverPriority=1 isZoneRedundant=True --enable-multiple-write-locations --network-acl-bypass AzureServices --network-acl-bypass-resource-ids /subscriptions/subId/resourceGroups/rgName/providers/Microsoft.Synapse/workspaces/wsName
- name: Create a new Azure Cosmos DB database account by restoring from an existing account in the given location
text: az cosmosdb create -n restoredaccount -g mygroup --is-restore-request true --restore-source /subscriptions/2296c272-5d55-40d9-bc05-4d56dc2d7588/providers/Microsoft.DocumentDB/locations/westus/restorableDatabaseAccounts/d056a4f8-044a-436f-80c8-cd3edbc94c68 --restore-timestamp 2020-07-13T16:03:41+0000 --locations regionName=westus failoverPriority=0 isZoneRedundant=False
- name: Creates a new Azure Cosmos DB database account with materialized views and cassandra capability enabled.
text: az cosmosdb create --name MyCosmosDBDatabaseAccount --resource-group MyResourceGroup --enable-materialized-views true --capabilities EnableCassandra CassandraEnableMaterializedViews
"""

helps['cosmosdb update'] = """
type: command
short-summary: Update an Azure Cosmos DB database account.
parameters:
- name: --locations
short-summary: Add a location to the Cosmos DB database account
long-summary: |
Usage: --locations KEY=VALUE [KEY=VALUE ...]
Required Keys: regionName, failoverPriority
Optional Key: isZoneRedundant
Default: single region account in the location of the specified resource group.
Failover priority values are 0 for write regions and greater than 0 for read regions. A failover priority value must be unique and less than the total number of regions.
Multiple locations can be specified by using more than one `--locations` argument.
examples:
- name: Update an Azure Cosmos DB database account. (autogenerated)
text: az cosmosdb update --capabilities EnableGremlin --name MyCosmosDBDatabaseAccount --resource-group MyResourceGroup
- name: Update an Azure Cosmos DB database account to enable materialized views.
text: az cosmosdb update --name MyCosmosDBDatabaseAccount --resource-group MyResourceGroup --enable-materialized-views true
"""

# restore account
Expand Down
1 change: 1 addition & 0 deletions src/cosmosdb-preview/azext_cosmosdb_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def load_arguments(self, _):
c.argument('default_identity', help="The primary identity to access key vault in CMK related features. e.g. 'FirstPartyIdentity', 'SystemAssignedIdentity' and more.", is_preview=True)
c.argument('analytical_storage_schema_type', options_list=['--analytical-storage-schema-type', '--as-schema'], arg_type=get_enum_type(AnalyticalStorageSchemaType), help="Schema type for analytical storage.", arg_group='Analytical Storage Configuration')
c.argument('backup_policy_type', arg_type=get_enum_type(BackupPolicyType), help="The type of backup policy of the account to create", arg_group='Backup Policy')
c.argument('enable_materialized_views', arg_type=get_three_state_flag(), help="Flag to enable MaterializedViews on the account.", is_preview=True)
ajparule marked this conversation as resolved.
Show resolved Hide resolved

with self.argument_context('cosmosdb restore') as c:
c.argument('target_database_account_name', options_list=['--target-database-account-name', '-n'], help='Name of the new target Cosmos DB database account after the restore')
Expand Down
18 changes: 12 additions & 6 deletions src/cosmosdb-preview/azext_cosmosdb_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ def cli_cosmosdb_create(cmd,
tables_to_restore=None,
is_restore_request=None,
restore_source=None,
restore_timestamp=None):
restore_timestamp=None,
enable_materialized_views=None):
"""Create a new Azure Cosmos DB database account."""

from azure.cli.core.commands.client_factory import get_mgmt_service_client
Expand Down Expand Up @@ -579,7 +580,8 @@ def cli_cosmosdb_create(cmd,
databases_to_restore=databases_to_restore,
gremlin_databases_to_restore=gremlin_databases_to_restore,
tables_to_restore=tables_to_restore,
arm_location=resource_group_location)
arm_location=resource_group_location,
enable_materialized_views=enable_materialized_views)


# pylint: disable=too-many-branches
Expand Down Expand Up @@ -608,7 +610,8 @@ def cli_cosmosdb_update(client,
backup_redundancy=None,
default_identity=None,
analytical_storage_schema_type=None,
backup_policy_type=None):
backup_policy_type=None,
enable_materialized_views=None):
"""Update an existing Azure Cosmos DB database account. """
existing = client.get(resource_group_name, account_name)

Expand Down Expand Up @@ -681,7 +684,8 @@ def cli_cosmosdb_update(client,
api_properties=api_properties,
backup_policy=backup_policy,
default_identity=default_identity,
analytical_storage_configuration=analytical_storage_configuration)
analytical_storage_configuration=analytical_storage_configuration,
enable_materialized_views=enable_materialized_views)

async_docdb_update = client.begin_update(resource_group_name, account_name, params)
docdb_account = async_docdb_update.result()
Expand Down Expand Up @@ -839,7 +843,8 @@ def _create_database_account(client,
is_restore_request=None,
restore_source=None,
restore_timestamp=None,
arm_location=None):
arm_location=None,
enable_materialized_views=None):

consistency_policy = None
if default_consistency_level is not None:
Expand Down Expand Up @@ -961,7 +966,8 @@ def _create_database_account(client,
default_identity=default_identity,
analytical_storage_configuration=analytical_storage_configuration,
create_mode=create_mode,
restore_parameters=restore_parameters
restore_parameters=restore_parameters,
enable_materialized_views=enable_materialized_views
)

async_docdb_create = client.begin_create_or_update(resource_group_name, account_name, params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,13 +779,13 @@ interactions:
User-Agent:
- AZURECLI/2.32.0 azsdk-python-mgmt-cosmosdb/7.0.0b2 Python/3.10.1 (Windows-10-10.0.19044-SP0)
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_cosmosdb_mongodb_role000001/providers/Microsoft.DocumentDB/databaseAccounts/cli000002/mongodbDatabases/cli000003?api-version=2021-10-15
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_cosmosdb_mongodb_role000001/providers/Microsoft.DocumentDB/databaseAccounts/cli000002/mongodbDatabases/cli000003?api-version=2021-11-15-preview
response:
body:
string: '{"status":"Enqueued"}'
headers:
azure-asyncoperation:
- https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.DocumentDB/locations/eastus2/operationsStatus/c1e1d393-bfb4-4836-974e-34d490dd6f58?api-version=2021-10-15
- https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.DocumentDB/locations/eastus2/operationsStatus/c1e1d393-bfb4-4836-974e-34d490dd6f58?api-version=2021-11-15-preview
cache-control:
- no-store, no-cache
content-length:
Expand All @@ -795,7 +795,7 @@ interactions:
date:
- Sat, 19 Feb 2022 04:54:46 GMT
location:
- https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_cosmosdb_mongodb_role000001/providers/Microsoft.DocumentDB/databaseAccounts/cli000002/mongodbDatabases/cli000003/operationResults/c1e1d393-bfb4-4836-974e-34d490dd6f58?api-version=2021-10-15
- https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_cosmosdb_mongodb_role000001/providers/Microsoft.DocumentDB/databaseAccounts/cli000002/mongodbDatabases/cli000003/operationResults/c1e1d393-bfb4-4836-974e-34d490dd6f58?api-version=2021-11-15-preview
pragma:
- no-cache
server:
Expand Down Expand Up @@ -827,7 +827,7 @@ interactions:
User-Agent:
- AZURECLI/2.32.0 azsdk-python-mgmt-cosmosdb/7.0.0b2 Python/3.10.1 (Windows-10-10.0.19044-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.DocumentDB/locations/eastus2/operationsStatus/c1e1d393-bfb4-4836-974e-34d490dd6f58?api-version=2021-10-15
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.DocumentDB/locations/eastus2/operationsStatus/c1e1d393-bfb4-4836-974e-34d490dd6f58?api-version=2021-11-15-preview
response:
body:
string: '{"status":"Succeeded"}'
Expand Down Expand Up @@ -873,7 +873,7 @@ interactions:
User-Agent:
- AZURECLI/2.32.0 azsdk-python-mgmt-cosmosdb/7.0.0b2 Python/3.10.1 (Windows-10-10.0.19044-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_cosmosdb_mongodb_role000001/providers/Microsoft.DocumentDB/databaseAccounts/cli000002/mongodbDatabases/cli000003?api-version=2021-10-15
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_cosmosdb_mongodb_role000001/providers/Microsoft.DocumentDB/databaseAccounts/cli000002/mongodbDatabases/cli000003?api-version=2021-11-15-preview
response:
body:
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_cosmosdb_mongodb_role000001/providers/Microsoft.DocumentDB/databaseAccounts/cli000002/mongodbDatabases/cli000003","type":"Microsoft.DocumentDB/databaseAccounts/mongodbDatabases","name":"cli000003","properties":{"resource":{"id":"cli000003"}}}'
Expand Down
Loading