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-preview] Add support for Priority Based Execution, cross account container copy, api-version 2023-09-15-preview #6703

Merged
merged 44 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9dbb596
init changes for 20230915-preview api
Aug 29, 2023
997e00b
Changes to add enablePriorityBasedExecution and defaultPriorityLevel
Aug 29, 2023
fbfcca2
Removed isPreview flag from CMK related properties and added key-uri …
AdrianSibajaRetana Sep 7, 2023
cc2b6a5
Added test and test recording for priority based execution
Sep 19, 2023
db8f723
corrected resource group name and whitespace corrections
Sep 19, 2023
820598f
white space corrections
Sep 19, 2023
afeeb43
Add cosmosdb copy command
niteshvijay-ms Sep 22, 2023
4b94d16
Add tests
niteshvijay-ms Sep 22, 2023
74ea880
Merge pull request #1 from niteshvijay1995/dts/cross-account-copy
Achint-Agrawal Sep 22, 2023
4cafea1
Dts/cross account copy (#3)
niteshvijay1995 Sep 22, 2023
b4cfbc7
Fix build error
niteshvijay-ms Sep 22, 2023
3b7a3f3
Fix Static Analysis
niteshvijay-ms Sep 22, 2023
f4403a3
Use boolean type
niteshvijay-ms Sep 25, 2023
84aff79
Change help text
niteshvijay-ms Sep 26, 2023
1ab9a82
Update help text
niteshvijay-ms Sep 26, 2023
f59ec30
Updated Vendored SDK
Sep 26, 2023
507199e
Merge branch 'Azure:main' into ag.achint-RPAPI20230915-preview
Achint-Agrawal Sep 26, 2023
c103101
Updated test account name in test_cosmosdb-merge-scenario.py
Sep 28, 2023
06e14dc
Whitespace correction and added linter exclution for enable pbe
Sep 28, 2023
f6d31f6
Updated linter_exclusions
Sep 28, 2023
6d55d96
Remove id part
niteshvijay-ms Sep 28, 2023
6ad68b0
Merge branch 'ag.achint-RPAPI20230915-preview' of https://github.com/…
niteshvijay-ms Sep 28, 2023
76a74b9
Corrected account name in test_cosmosdb-merge-scenario.py and generat…
Oct 4, 2023
e71a53a
Merge branch 'ag.achint-RPAPI20230915-preview' of https://github.com/…
Oct 4, 2023
c555f78
Generated test recording for test_cosmosdb_materializedview
Oct 4, 2023
5c9af2d
Add support for MI Cassandra in 2023-09-15
guanzhousongmicrosoft Oct 9, 2023
6108ce4
Add -n for jobname
niteshvijay-ms Oct 10, 2023
d5510c0
Fix breaking change
niteshvijay-ms Oct 10, 2023
0c38709
Modified setup.py and history.rst
Oct 10, 2023
d3e2829
Fix static check
niteshvijay-ms Oct 10, 2023
e770730
Merge branch 'ag.achint-RPAPI20230915-preview' of https://github.com/…
Oct 10, 2023
5f0d379
Merge pull request #4 from guanzhousongmicrosoft/main
Achint-Agrawal Oct 11, 2023
6b50c4f
Whitespace correction
Oct 11, 2023
8a229ec
Re-recorded tests
Oct 11, 2023
a2e11b5
rerecorded test test_cosmosdb_sql_materializedview_scenario
Oct 11, 2023
c2b01d2
removed linter exclusion for enable_priority_based_execution
Oct 11, 2023
6639176
Merge branch 'Azure:main' into ag.achint-RPAPI20230915-preview
Achint-Agrawal Oct 11, 2023
c8d4357
Rerecorded all tests
Oct 11, 2023
1b966c5
Updated HISTORY.rst
Oct 11, 2023
f0855da
Merge branch 'Azure:main' into ag.achint-RPAPI20230915-preview
Achint-Agrawal Oct 12, 2023
b21c2ec
Rerecorded tests
Oct 12, 2023
10e82c2
rerecorded test_cosmosdb_sql_materializedview_scenario
Oct 12, 2023
2e32a65
rerecorded test_cosmosdb_sql_materializedview_scenario
Oct 12, 2023
e5c11a6
rerecorded tests
Oct 12, 2023
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
6 changes: 6 additions & 0 deletions src/cosmosdb-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Release History
===============
0.26.0
* Add '--enable-priority-based-execution' and '--default-priority-level' parameter for create/update database account.
* Add support for cross account container copy
* Add Non-CMK to CMK support
* Removed preview tag from CMK related properties

0.25.0
* Add support for performing database merge for Sql and MongoDB database account.

Expand Down
106 changes: 106 additions & 0 deletions src/cosmosdb-preview/azext_cosmosdb_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,112 @@
az cosmosdb dts cancel --account-name "ddb1" --job-name "j1" -g "rg1"
"""

helps['cosmosdb copy'] = """
type: group
short-summary: Manage container copy job
"""

helps['cosmosdb copy create'] = """
type: command
short-summary: "Creates a container copy job."
parameters:
- name: --src-cassandra
short-summary: "Source table"
long-summary: |
Usage: --src-cassandra keyspace=XX table=XX'
keyspace: Keyspace name.
table: Table name.
- name: --dest-cassandra
short-summary: "Destination table"
long-summary: |
Usage: --dest-cassandra keyspace=XX table=XX'
keyspace: Keyspace name.
table: Table name.
- name: --src-nosql
short-summary: "Source container"
long-summary: |
Usage: --src-nosql database=XX container=XX'
database: Database name.
container: Container name.
- name: --dest-nosql
short-summary: "Destination container"
long-summary: |
Usage: --dest-nosql database=XX container=XX'
database: Database name.
container: Container name.
- name: --src-mongo
short-summary: "Source collection"
long-summary: |
Usage: --src-mongo database=XX collection=XX'
database: Database name.
collection: Collection name.
- name: --dest-mongo
short-summary: "Destination collection"
long-summary: |
Usage: --dest-mongo database=XX collection=XX'
database: Database name.
collection: Collection name.

examples:
- name: Copy Azure Cosmos DB API for NoSQL container in same account
text: |-
az cosmosdb copy create -g "rg1" --job-name "j1" --src-account "acc1" --dest-account "acc1" --src-nosql database=db1 container=c1 --dest-nosql database=db2 container=c2
- name: Copy Azure Cosmos DB API for NoSQL container in different account
text: |-
az cosmosdb copy create -g "rg1" --job-name "j1" --src-account "acc1" --dest-account "acc2" --src-nosql database=db1 container=c1 --dest-nosql database=db2 container=c2
- name: Copy Azure Cosmos DB API for Apache Cassandra table
text: |-
az cosmosdb copy create -g "rg1" --job-name "j1" --src-account "acc1" --dest-account "acc1" --src-cassandra keyspace=k1 table=t1 --dest-cassandra keyspace=k2 table=t2
- name: Copy Azure Cosmos DB API for MongoDB collection
text: |-
az cosmosdb copy create -g "rg1" --job-name "j1" --src-account "acc1" --dest-account "acc1" --src-mongo database=d1 collection=c1 --dest-mongo database=d2 collection=c2
"""

helps['cosmosdb copy list'] = """
type: command
short-summary: "Get a container copy job."
examples:
- name: List all jobs
text: |-
az cosmosdb copy list -g "rg1" --account-name "acc1"
"""

helps['cosmosdb copy show'] = """
type: command
short-summary: "Get a container copy job."
examples:
- name: Show details of job j1
text: |-
az cosmosdb copy show -g "rg1" --account-name "acc1" --job-name "j1"
"""

helps['cosmosdb copy pause'] = """
type: command
short-summary: "Pause a container copy job."
examples:
- name: Pause job j1
text: |-
az cosmosdb copy pause -g "rg1" --account-name "acc1" --job-name "j1"
"""

helps['cosmosdb copy resume'] = """
type: command
short-summary: "Resume a container copy job."
examples:
- name: Resume job j1
text: |-
az cosmosdb copy resume -g "rg1" --account-name "acc1" --job-name "j1"
"""

helps['cosmosdb copy cancel'] = """
type: command
short-summary: "Cancel a container copy job."
examples:
- name: Cancel job j1
text: |-
az cosmosdb copy cancel -g "rg1" --account-name "acc1" --job-name "j1"
"""

helps['cosmosdb sql container merge'] = """
type: command
short-summary: "Merges the partitions of a sql container."
Expand Down
57 changes: 50 additions & 7 deletions src/cosmosdb-preview/azext_cosmosdb_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long, too-many-statements

import argparse
from argcomplete.completers import FilesCompleter

from azext_cosmosdb_preview._validators import (
Expand All @@ -28,7 +29,7 @@
CreatePhysicalPartitionIdListAction)

from azext_cosmosdb_preview.vendored_sdks.azure_mgmt_cosmosdb.models import (
ContinuousTier
ContinuousTier, DefaultPriorityLevel
)

from azure.cli.core.util import shell_safe_json_parse
Expand Down Expand Up @@ -108,11 +109,16 @@ def load_arguments(self, _):
'managed-cassandra cluster update',
'managed-cassandra cluster show',
'managed-cassandra cluster delete',
'managed-cassandra cluster deallocate',
'managed-cassandra cluster backup list',
'managed-cassandra cluster backup show']:
with self.argument_context(scope) as c:
c.argument('cluster_name', options_list=['--cluster-name', '-c'], help="Cluster Name", required=True)

# Managed Cassandra Cluster
with self.argument_context('managed-cassandra cluster deallocate') as c:
c.argument('force', options_list=['--force', '-f'], help="Force to deallocate the cluster", required=False)

# Managed Cassandra Cluster
for scope in [
'managed-cassandra cluster create',
Expand All @@ -128,6 +134,8 @@ def load_arguments(self, _):
c.argument('gossip_certificates', help="A list of certificates that should be accepted by on-premise data centers.")
c.argument('external_seed_nodes', nargs='+', validator=validate_seednodes, help="A list of ip addresses of the seed nodes of on-premise data centers.")
c.argument('identity_type', options_list=['--identity-type'], arg_type=get_enum_type(['None', 'SystemAssigned']), help="Type of identity used for Customer Managed Disk Key.")
c.argument("cluster_type", options_list=['--cluster-type'], help="Type of the cluster, can be Production or NonProduction. If set to Production, operations on cluster might have restrictions.", arg_type=get_enum_type(['Production', 'NonProduction']))
c.argument('extensions', nargs='*', help="A set of extensions that will be effective on the cluster. It will replace the entire set of extensions with new set. Use \"\" to remove all. Now Available: cassandra-lucene-index.")

# Managed Cassandra Cluster
with self.argument_context('managed-cassandra cluster create') as c:
Expand Down Expand Up @@ -290,9 +298,9 @@ def load_arguments(self, _):
# CosmosDB account create with gremlin and tables to restore
with self.argument_context('cosmosdb create') as c:
c.argument('account_name', completer=None)
c.argument('key_uri', help="The URI of the key vault", is_preview=True)
c.argument('enable_free_tier', arg_type=get_three_state_flag(), help="If enabled the account is free-tier.", is_preview=True)
c.argument('assign_identity', nargs='*', help="Assign system or user assigned identities separated by spaces. Use '[system]' to refer system assigned identity.", is_preview=True)
c.argument('assign_identity', nargs='*', help="Assign system or user assigned identities separated by spaces. Use '[system]' to refer system assigned identity.")
c.argument('key_uri', help="The URI of the key vault")
c.argument('is_restore_request', options_list=['--is-restore-request', '-r'], arg_type=get_three_state_flag(), help="Restore from an existing/deleted account.", is_preview=True, arg_group='Restore')
c.argument('restore_source', help="The restorable-database-account Id of the source account from which the account has to be restored. Required if --is-restore-request is set to true.", is_preview=True, arg_group='Restore')
c.argument('restore_timestamp', action=UtcDatetimeAction, help="The timestamp to which the account has to be restored to. Required if --is-restore-request is set to true.", is_preview=True, arg_group='Restore')
Expand Down Expand Up @@ -324,12 +332,17 @@ def load_arguments(self, _):
c.argument('backup_retention', type=int, help="the time(in hours) for which each backup is retained (only for accounts with periodic mode backups)", arg_group='Backup Policy')
c.argument('backup_redundancy', arg_type=get_enum_type(BackupStorageRedundancy), help="The redundancy type of the backup Storage account", arg_group='Backup Policy')
c.argument('server_version', arg_type=get_enum_type(ServerVersion), help="Valid only for MongoDB accounts.")
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('default_identity', help="The primary identity to access key vault in CMK related features. e.g. 'FirstPartyIdentity', 'SystemAssignedIdentity' and more.")
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('continuous_tier', arg_type=get_enum_type(ContinuousTier), help="The tier of Continuous backup", arg_group='Backup Policy')
c.argument('enable_materialized_views', options_list=['--enable-materialized-views', '--enable-mv'], arg_type=get_three_state_flag(), help="Flag to enable MaterializedViews on the account.", is_preview=True)
c.argument('enable_burst_capacity', arg_type=get_three_state_flag(), help="Flag to enable burst capacity on the account.", is_preview=True)
c.argument('enable_priority_based_execution', options_list=['--enable-priority-based-execution', '--enable-pbe'], arg_type=get_three_state_flag(), help="Flag to enable priority based execution on the account.", is_preview=True)
c.argument('default_priority_level', arg_type=get_enum_type(DefaultPriorityLevel), help="Default Priority Level of Request if not specified.", is_preview=True)

with self.argument_context('cosmosdb update') as c:
c.argument('key_uri', help="The URI of the key vault", is_preview=True)

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 All @@ -339,8 +352,8 @@ def load_arguments(self, _):
c.argument('databases_to_restore', nargs='+', action=CreateDatabaseRestoreResource)
c.argument('gremlin_databases_to_restore', nargs='+', action=CreateGremlinDatabaseRestoreResource, is_preview=True)
c.argument('tables_to_restore', nargs='+', action=CreateTableRestoreResource, is_preview=True)
c.argument('assign_identity', nargs='*', help="Assign system or user assigned identities separated by spaces. Use '[system]' to refer system assigned identity.", is_preview=True)
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('assign_identity', nargs='*', help="Assign system or user assigned identities separated by spaces. Use '[system]' to refer system assigned identity.")
c.argument('default_identity', help="The primary identity to access key vault in CMK related features. e.g. 'FirstPartyIdentity', 'SystemAssignedIdentity' and more.")
c.argument('enable_public_network', options_list=['--enable-public-network', '-e'], arg_type=get_three_state_flag(), help="Enable or disable public network access to server.", is_preview=True)
c.argument('source_backup_location', help="This is the location of the source account where backups are located. Provide this value if the source and target are in different locations.", is_preview=True)

Expand Down Expand Up @@ -437,7 +450,37 @@ def load_arguments(self, _):
'cosmosdb dts resume',
'cosmosdb dts cancel']:
with self.argument_context(scope) as c:
c.argument('job_name', options_list=['--job-name', '-n'], help='Name of the Data Transfer Job.')
c.argument('job_name', options_list=['--job-name', '-n'], help='Name of the Data Transfer Job.', required=True)

with self.argument_context('cosmosdb copy create') as c:
c.argument('job_name', job_name_type)
c.argument('src_account', help='Name of the Azure Cosmos DB source database account.', completer=get_resource_name_completion_list('Microsoft.DocumentDb/databaseAccounts'), id_part='name')
c.argument('dest_account', help='Name of the Azure Cosmos DB destination database account.', completer=get_resource_name_completion_list('Microsoft.DocumentDb/databaseAccounts'), id_part='name')
c.argument('src_cassandra', nargs='+', arg_group='Azure Cosmos DB API for Apache Cassandra table copy', action=AddCassandraTableAction, help='Source Cassandra table details')
c.argument('src_mongo', nargs='+', arg_group='Azure Cosmos DB API for MongoDB collection copy', action=AddMongoCollectionAction, help='Source Mongo collection details')
c.argument('src_nosql', nargs='+', arg_group='Azure Cosmos DB API for NoSQL container copy', action=AddSqlContainerAction, help='Source NoSql container details')
c.argument('dest_cassandra', nargs='+', arg_group='Azure Cosmos DB API for Apache Cassandra table copy', action=AddCassandraTableAction, help='Destination Cassandra table details')
c.argument('dest_mongo', nargs='+', arg_group='Azure Cosmos DB API for MongoDB collection copy', action=AddMongoCollectionAction, help='Destination Mongo collection details')
c.argument('dest_nosql', nargs='+', arg_group='Azure Cosmos DB API for NoSQL container copy', action=AddSqlContainerAction, help='Destination NoSql container details')
c.argument('host_copy_on_src', arg_type=get_three_state_flag(), help=argparse.SUPPRESS)
c.argument('worker_count', type=int, help=argparse.SUPPRESS)
Comment on lines +465 to +466
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I know why you use argparse.SUPPRESS for these two parameters?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not want it to be documented in help section, so that it is not discoverable by default.

Copy link
Member

@evelyn-ys evelyn-ys Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I guess what you want is c.ignore() for defining these arguments

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore will remove the param completely? It is not coming from reflection, rather we are adding it so that only selected customers can use it


for scope in [
'cosmosdb copy list',
'cosmosdb copy show',
'cosmosdb copy pause',
'cosmosdb copy resume',
'cosmosdb copy cancel']:
with self.argument_context(scope) as c:
c.argument('account_name', options_list=["--account-name", "-a"], id_part=None, required=True, help='Azure Cosmos DB account name where the job is created. Use --dest-account value from create job command.')

for scope in [
'cosmosdb copy show',
'cosmosdb copy pause',
'cosmosdb copy resume',
'cosmosdb copy cancel']:
with self.argument_context(scope) as c:
c.argument('job_name', options_list=['--job-name', '-n'], help='Name of the container copy job.', required=True)

max_throughput_type = CLIArgumentType(options_list=['--max-throughput'], help='The maximum throughput resource can scale to (RU/s). Provided when the resource is autoscale enabled. The minimum value can be 4000 (RU/s)')

Expand Down
18 changes: 14 additions & 4 deletions src/cosmosdb-preview/azext_cosmosdb_preview/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def __call__(self, parser, namespace, values, option_string=None):
namespace.source_cassandra_table = cassandra_table
elif option_string == "--dest-cassandra-table":
namespace.dest_cassandra_table = cassandra_table
elif option_string == "--src-cassandra":
namespace.src_cassandra = cassandra_table
elif option_string == "--dest-cassandra":
namespace.dest_cassandra = cassandra_table
else:
namespace.cassandra_table = cassandra_table

Expand Down Expand Up @@ -174,6 +178,8 @@ def __call__(self, parser, namespace, values, option_string=None):
namespace.source_mongo = mongo_collection
elif option_string == "--dest-mongo":
namespace.dest_mongo = mongo_collection
elif option_string == "--src-mongo":
namespace.src_mongo = mongo_collection
else:
namespace.mongo_collection = mongo_collection

Expand Down Expand Up @@ -207,14 +213,18 @@ def __call__(self, parser, namespace, values, option_string=None):
if container_name is None:
raise CLIError(f'usage error: missing key container in {option_string} component')

sql_container = CosmosSqlDataTransferDataSourceSink(database_name=database_name, container_name=container_name)
nosql_container = CosmosSqlDataTransferDataSourceSink(database_name=database_name, container_name=container_name)

if option_string == "--source-sql-container":
namespace.source_sql_container = sql_container
namespace.source_sql_container = nosql_container
elif option_string == "--dest-sql-container":
namespace.dest_sql_container = sql_container
namespace.dest_sql_container = nosql_container
elif option_string == "--src-nosql":
namespace.src_nosql = nosql_container
elif option_string == "--dest-nosql":
namespace.dest_nosql = nosql_container
else:
namespace.sql_container = sql_container
namespace.sql_container = nosql_container


# pylint: disable=protected-access, too-few-public-methods
Expand Down
Loading