Skip to content

Commit d098679

Browse files
[CosmosDB] API Version 2024-12-01-preview (#8323)
* Adding custom SDK from azure-rest-api-specs PR * Recordings * Changes to add "sql container throughput" commands * Added throughput type to sql container throughput migrate * Added throughput bucket param * Changes to add "sql container throughput" commands * Added throughput type to sql container throughput migrate * Added throughput bucket param * Removed unused imports * Remaining test recordings * Fixed linters * Fixed examples * Flake8 changes * Updated to --throughput-buckets and rerecorded test * Added final recording --------- Co-authored-by: Achint-Agrawal <[email protected]>
1 parent 7c2f589 commit d098679

File tree

163 files changed

+33549
-28081
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+33549
-28081
lines changed

src/cosmosdb-preview/azext_cosmosdb_preview/_help.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,35 @@
10081008
az cosmosdb sql container restore --resource-group resource_group --account-name database_account_name --database-name parent_database_name --name name_of_container_needs_to_be_restored --restore-timestamp 2020-07-13T16:03:41+0000
10091009
"""
10101010

1011+
# sql container throughput commands
1012+
helps['cosmosdb sql container throughput'] = """
1013+
type: group
1014+
short-summary: Manage throughput of SQL container under an Azure Cosmos DB account.
1015+
"""
1016+
1017+
helps['cosmosdb sql container throughput show'] = """
1018+
type: command
1019+
short-summary: Get the throughput of the SQL container under an Azure Cosmos DB SQL database.
1020+
"""
1021+
1022+
helps['cosmosdb sql container throughput update'] = """
1023+
type: command
1024+
short-summary: Update the throughput of the SQL container under an Azure Cosmos DB SQL database.
1025+
examples:
1026+
- name: Update the throughput of the SQL container under an Azure Cosmos DB SQL database.
1027+
text: |-
1028+
az cosmosdb sql container throughput update --resource-group resource_group --account-name database_account_name --database-name parent_database_name --name name_of_collection_needs_to_be_restored --throughput 1000
1029+
"""
1030+
1031+
helps['cosmosdb sql container throughput migrate'] = """
1032+
type: command
1033+
short-summary: Migrate the throughput of the SQL container between autoscale and manually provisioned.
1034+
examples:
1035+
- name: Migrate the throughput of the SQL container between autoscale and manually provisioned.
1036+
text: |-
1037+
az cosmosdb sql container throughput migrate --resource-group resource_group --account-name database_account_name --database-name parent_database_name --name name_of_collection_needs_to_be_restored --throughput-type Manual
1038+
"""
1039+
10111040
# in-account restore of a deleted mongodb database
10121041
helps['cosmosdb mongodb database restore'] = """
10131042
type: command

src/cosmosdb-preview/azext_cosmosdb_preview/_params.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# --------------------------------------------------------------------------------------------
55
# pylint: disable=line-too-long, too-many-statements
66

7+
from enum import Enum
78
import argparse
89
from argcomplete.completers import FilesCompleter
910

@@ -104,6 +105,17 @@
104105
}"
105106
"""
106107

108+
SQL_THROUGHPUT_BUCKETS_EXAMPLE = """--throughput-buckets "[
109+
{ \\"id\\": 1, \\"maxThroughputPercentage\\" : 10 },
110+
{ \\"id\\": 2, \\"maxThroughputPercentage\\" : 20 }
111+
]"
112+
"""
113+
114+
115+
class ThroughputTypes(str, Enum):
116+
autoscale = "autoscale"
117+
manual = "manual"
118+
107119

108120
def load_arguments(self, _):
109121
from knack.arguments import CLIArgumentType
@@ -499,6 +511,7 @@ def load_arguments(self, _):
499511
c.argument('job_name', options_list=['--job-name', '-n'], help='Name of the container copy job.', required=True)
500512

501513
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)')
514+
throughput_type = CLIArgumentType(options_list=['--throughput-type', '-t'], arg_type=get_enum_type(ThroughputTypes), help='The type of throughput to migrate to.')
502515

503516

504517
# SQL container
@@ -558,6 +571,19 @@ def load_arguments(self, _):
558571
c.argument('target_partition_info', nargs='+', action=CreateTargetPhysicalPartitionThroughputInfoAction, required=False, help="information about desired target physical partition throughput eg: 0=1200 1=1200")
559572
c.argument('source_partition_info', nargs='+', action=CreateSourcePhysicalPartitionThroughputInfoAction, required=False, help="space separated source physical partition ids eg: 1 2")
560573

574+
# Sql container throughput
575+
with self.argument_context('cosmosdb sql container throughput') as c:
576+
c.argument('account_name', account_name_type, id_part=None)
577+
c.argument('database_name', database_name_type)
578+
c.argument('container_name', options_list=['--name', '-n'], help="Container name")
579+
c.argument('throughput', type=int, help='The throughput of SQL container (RU/s).')
580+
c.argument('max_throughput', max_throughput_type)
581+
c.argument('throughput_buckets', options_list=['--throughput-buckets'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Throughput Buckets, you can enter it as a string or as a file, e.g., --throughput-buckets @throughput-buckets-file.json or ' + SQL_THROUGHPUT_BUCKETS_EXAMPLE)
582+
583+
for scope in ['sql container throughput migrate']:
584+
with self.argument_context('cosmosdb {}'.format(scope)) as c:
585+
c.argument('throughput_type', throughput_type)
586+
561587
# Mongodb collection partition retrieve throughput
562588
with self.argument_context('cosmosdb mongodb collection retrieve-partition-throughput') as c:
563589
c.argument('account_name', account_name_type, id_part=None, required=True, help='Name of the CosmosDB database account')

src/cosmosdb-preview/azext_cosmosdb_preview/commands.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ def load_command_table(self, _):
234234
with self.command_group('cosmosdb sql container', cosmosdb_sql_sdk, client_factory=cf_sql_resources) as g:
235235
g.custom_command('retrieve-partition-throughput', 'cli_begin_retrieve_sql_container_partition_throughput', is_preview=True)
236236

237+
# Get and update offer throughput for Sql containers
238+
with self.command_group('cosmosdb sql container throughput', cosmosdb_sql_sdk, client_factory=cf_sql_resources) as g:
239+
g.show_command('show', 'get_sql_container_throughput')
240+
g.custom_command('update', 'cli_cosmosdb_sql_container_throughput_update')
241+
g.custom_command('migrate', 'cli_cosmosdb_sql_container_throughput_migrate')
242+
237243
# Merge partitions for Sql databases
238244
with self.command_group('cosmosdb sql database', cosmosdb_sql_sdk, client_factory=cf_sql_resources) as g:
239245
g.custom_command('merge', 'cli_begin_sql_database_partition_merge', is_preview=True)

src/cosmosdb-preview/azext_cosmosdb_preview/custom.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
GraphAPIComputeServiceResourceCreateUpdateProperties,
6464
MaterializedViewsBuilderServiceResourceCreateUpdateProperties,
6565
DedicatedGatewayType,
66-
ServiceType
66+
ServiceType,
67+
ThroughputSettingsResource,
68+
ThroughputSettingsUpdateParameters
6769
)
6870

6971
from azext_cosmosdb_preview.vendored_sdks.azure_mgmt_mongocluster.models import (
@@ -2355,6 +2357,53 @@ def cli_begin_retrieve_sql_container_partition_throughput(client,
23552357
return async_partition_retrieve_throughput_result.result()
23562358

23572359

2360+
def cli_cosmosdb_sql_container_throughput_update(client,
2361+
resource_group_name,
2362+
account_name,
2363+
database_name,
2364+
container_name,
2365+
throughput=None,
2366+
max_throughput=None,
2367+
throughput_buckets=None):
2368+
"""Update an Azure Cosmos DB SQL container throughput"""
2369+
throughput_update_resource = _get_throughput_settings_update_parameters(throughput=throughput,
2370+
max_throughput=max_throughput,
2371+
throughput_buckets=throughput_buckets)
2372+
return client.begin_update_sql_container_throughput(resource_group_name,
2373+
account_name,
2374+
database_name,
2375+
container_name,
2376+
throughput_update_resource)
2377+
2378+
2379+
def cli_cosmosdb_sql_container_throughput_migrate(client,
2380+
resource_group_name,
2381+
account_name,
2382+
database_name,
2383+
container_name,
2384+
throughput_type):
2385+
"""Migrate an Azure Cosmos DB SQL container throughput"""
2386+
if throughput_type == "autoscale":
2387+
return client.begin_migrate_sql_container_to_autoscale(resource_group_name, account_name,
2388+
database_name, container_name)
2389+
return client.begin_migrate_sql_container_to_manual_throughput(resource_group_name, account_name,
2390+
database_name, container_name)
2391+
2392+
2393+
def _get_throughput_settings_update_parameters(throughput=None, max_throughput=None, throughput_buckets=None):
2394+
throughput_resource = None
2395+
if throughput and max_throughput:
2396+
raise CLIError("Please provide max-throughput if your resource is autoscale enabled otherwise provide throughput.")
2397+
if throughput:
2398+
throughput_resource = ThroughputSettingsResource(throughput=throughput, throughput_buckets=throughput_buckets)
2399+
elif max_throughput:
2400+
throughput_resource = ThroughputSettingsResource(
2401+
autoscale_settings=AutoscaleSettings(max_throughput=max_throughput),
2402+
throughput_buckets=throughput_buckets)
2403+
2404+
return ThroughputSettingsUpdateParameters(resource=throughput_resource)
2405+
2406+
23582407
# pylint: disable=dangerous-default-value
23592408
def cli_begin_redistribute_sql_container_partition_throughput(client,
23602409
resource_group_name,

0 commit comments

Comments
 (0)