Skip to content

Commit c6ebc93

Browse files
authored
Make private Cosmos modules private [WIP] (Azure#6329)
* make consistent_hash_ring private * make default_retry_policy private * make endpoint_discovery_retry_policy private * make hash_partition_resolver private * make location_cache private * make murmur_hash private * make range private * make range_partition_resolver private * make vector_session_token private * make resource_throttle_retry_policy private * make retry_utility private * make utils private * make routing private * make execution_context private * make cosmos_client_connection private * make retry_options private * make query_iterable private * make constants private * make synchronized_request private * make session_retry_policy private * make partition private * make global_endpoint_manager private * make runtime_constants private * make session private * make request_object private * make base private
1 parent 37c46c6 commit c6ebc93

Some content is hidden

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

61 files changed

+344
-347
lines changed

sdk/cosmos/azure-cosmos/azure/cosmos/base.py renamed to sdk/cosmos/azure-cosmos/azure/cosmos/_base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
from . import documents
3434
from . import partition_key
3535
from . import http_constants
36-
from . import constants
37-
from . import runtime_constants
36+
from . import _constants as constants
37+
from . import _runtime_constants
3838

3939
import six
4040
from six.moves.urllib.parse import quote as urllib_quote
@@ -178,10 +178,10 @@ def GetHeaders(cosmos_client_connection,
178178

179179
if verb == 'post' or verb == 'put':
180180
if not headers.get(http_constants.HttpHeaders.ContentType):
181-
headers[http_constants.HttpHeaders.ContentType] = runtime_constants.MediaTypes.Json
181+
headers[http_constants.HttpHeaders.ContentType] = _runtime_constants.MediaTypes.Json
182182

183183
if not headers.get(http_constants.HttpHeaders.Accept):
184-
headers[http_constants.HttpHeaders.Accept] = runtime_constants.MediaTypes.Json
184+
headers[http_constants.HttpHeaders.Accept] = _runtime_constants.MediaTypes.Json
185185

186186
if partition_key_range_id is not None:
187187
headers[http_constants.HttpHeaders.PartitionKeyRangeID] = partition_key_range_id

sdk/cosmos/azure-cosmos/azure/cosmos/consistent_hash_ring.py renamed to sdk/cosmos/azure-cosmos/azure/cosmos/_consistent_hash_ring.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
import six
2727
from six.moves import xrange
2828

29-
from . import partition
29+
from . import _partition
3030

3131

32-
class _ConsistentHashRing(object):
32+
class ConsistentHashRing(object):
3333
"""The ConsistentHashRing class implements a consistent hash ring using the
3434
hash generator specified.
3535
"""
@@ -79,13 +79,13 @@ def _ConstructPartitions(self, collection_links, partitions_per_node):
7979
using the hashing algorithm and then finally sorting the partitions based on the hash value.
8080
"""
8181
collections_node_count = len(collection_links)
82-
partitions = [partition._Partition() for _ in xrange(0, partitions_per_node * collections_node_count)]
82+
partitions = [_partition.Partition() for _ in xrange(0, partitions_per_node * collections_node_count)]
8383

8484
index = 0
8585
for collection_node in collection_links:
8686
hash_value = self.hash_generator.ComputeHash(self._GetBytes(collection_node))
8787
for _ in xrange(0, partitions_per_node):
88-
partitions[index] = partition._Partition(hash_value, collection_node)
88+
partitions[index] = _partition.Partition(hash_value, collection_node)
8989
index += 1
9090
hash_value = self.hash_generator.ComputeHash(hash_value)
9191

sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client_connection.py renamed to sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@
2525

2626
import six
2727
from typing import cast
28-
from . import base
28+
from . import _base as base
2929
from . import documents
30-
from . import constants
30+
from . import _constants as constants
3131
from . import http_constants
32-
from . import query_iterable
33-
from . import runtime_constants
34-
from . import request_object
35-
from . import synchronized_request
36-
from . import global_endpoint_manager
37-
from .routing import routing_map_provider as routing_map_provider
38-
from . import session
39-
from . import utils
32+
from . import _query_iterable as query_iterable
33+
from . import _runtime_constants as runtime_constants
34+
from . import _request_object
35+
from . import _synchronized_request as synchronized_request
36+
from . import _global_endpoint_manager as global_endpoint_manager
37+
from ._routing import routing_map_provider as routing_map_provider
38+
from . import _session
39+
from . import _utils
4040
from .partition_key import _Undefined, _Empty
4141

4242

@@ -110,7 +110,7 @@ def __init__(self,
110110
http_constants.HttpHeaders.Version:
111111
http_constants.Versions.CurrentVersion,
112112
http_constants.HttpHeaders.UserAgent:
113-
utils._get_user_agent(),
113+
_utils.get_user_agent(),
114114
# For single partition query with aggregate functions we would try to accumulate the results on the SDK.
115115
# We need to set continuation as not expected.
116116
http_constants.HttpHeaders.IsContinuationExpected: False
@@ -127,7 +127,7 @@ def __init__(self,
127127
'''create a session - this is maintained only if the default consistency level
128128
on the client is set to session, or if the user explicitly sets it as a property
129129
via setter'''
130-
self.session = session.Session(self.url_connection)
130+
self.session = _session.Session(self.url_connection)
131131
else:
132132
self.session = None
133133

@@ -150,7 +150,7 @@ def __init__(self,
150150
self._query_compatibility_mode = CosmosClientConnection._QueryCompatibilityMode.Default
151151

152152
# Routing map provider
153-
self._routing_map_provider = routing_map_provider._SmartRoutingMapProvider(self)
153+
self._routing_map_provider = routing_map_provider.SmartRoutingMapProvider(self)
154154

155155
database_account = self._global_endpoint_manager._GetDatabaseAccount()
156156
self._global_endpoint_manager.force_refresh(database_account)
@@ -1932,7 +1932,7 @@ def ReadMedia(self, media_link):
19321932
{})
19331933

19341934
# ReadMedia will always use WriteEndpoint since it's not replicated in readable Geo regions
1935-
request = request_object._RequestObject('media', documents._OperationType.Read)
1935+
request = _request_object.RequestObject('media', documents._OperationType.Read)
19361936
result, self.last_response_headers = self.__Get(path,
19371937
request,
19381938
headers)
@@ -1981,7 +1981,7 @@ def UpdateMedia(self, media_link, readable_stream, options=None):
19811981
options)
19821982

19831983
# UpdateMedia will use WriteEndpoint since it uses PUT operation
1984-
request = request_object._RequestObject('media', documents._OperationType.Update)
1984+
request = _request_object.RequestObject('media', documents._OperationType.Update)
19851985
result, self.last_response_headers = self.__Put(path,
19861986
request,
19871987
readable_stream,
@@ -2200,7 +2200,7 @@ def ExecuteStoredProcedure(self, sproc_link, params, options=None):
22002200
options)
22012201

22022202
# ExecuteStoredProcedure will use WriteEndpoint since it uses POST operation
2203-
request = request_object._RequestObject('sprocs', documents._OperationType.ExecuteJavaScript)
2203+
request = _request_object.RequestObject('sprocs', documents._OperationType.ExecuteJavaScript)
22042204
result, self.last_response_headers = self.__Post(path,
22052205
request,
22062206
params,
@@ -2389,7 +2389,7 @@ def GetDatabaseAccount(self, url_connection=None):
23892389
'', # type
23902390
{})
23912391

2392-
request = request_object._RequestObject('databaseaccount', documents._OperationType.Read, url_connection)
2392+
request = _request_object.RequestObject('databaseaccount', documents._OperationType.Read, url_connection)
23932393
result, self.last_response_headers = self.__Get('',
23942394
request,
23952395
headers)
@@ -2449,7 +2449,7 @@ def Create(self, body, path, type, id, initial_headers, options=None):
24492449
options)
24502450
# Create will use WriteEndpoint since it uses POST operation
24512451

2452-
request = request_object._RequestObject(type, documents._OperationType.Create)
2452+
request = _request_object.RequestObject(type, documents._OperationType.Create)
24532453
result, self.last_response_headers = self.__Post(path,
24542454
request,
24552455
body,
@@ -2491,7 +2491,7 @@ def Upsert(self, body, path, type, id, initial_headers, options=None):
24912491
headers[http_constants.HttpHeaders.IsUpsert] = True
24922492

24932493
# Upsert will use WriteEndpoint since it uses POST operation
2494-
request = request_object._RequestObject(type, documents._OperationType.Upsert)
2494+
request = _request_object.RequestObject(type, documents._OperationType.Upsert)
24952495
result, self.last_response_headers = self.__Post(path,
24962496
request,
24972497
body,
@@ -2529,7 +2529,7 @@ def Replace(self, resource, path, type, id, initial_headers, options=None):
25292529
type,
25302530
options)
25312531
# Replace will use WriteEndpoint since it uses PUT operation
2532-
request = request_object._RequestObject(type, documents._OperationType.Replace)
2532+
request = _request_object.RequestObject(type, documents._OperationType.Replace)
25332533
result, self.last_response_headers = self.__Put(path,
25342534
request,
25352535
resource,
@@ -2567,7 +2567,7 @@ def Read(self, path, type, id, initial_headers, options=None):
25672567
type,
25682568
options)
25692569
# Read will use ReadEndpoint since it uses GET operation
2570-
request = request_object._RequestObject(type, documents._OperationType.Read)
2570+
request = _request_object.RequestObject(type, documents._OperationType.Read)
25712571
result, self.last_response_headers = self.__Get(path,
25722572
request,
25732573
headers)
@@ -2601,7 +2601,7 @@ def DeleteResource(self, path, type, id, initial_headers, options=None):
26012601
type,
26022602
options)
26032603
# Delete will use WriteEndpoint since it uses DELETE operation
2604-
request = request_object._RequestObject(type, documents._OperationType.Delete)
2604+
request = _request_object.RequestObject(type, documents._OperationType.Delete)
26052605
result, self.last_response_headers = self.__Delete(path,
26062606
request,
26072607
headers)
@@ -2783,7 +2783,7 @@ def __GetBodiesFromQueryResult(result):
27832783
# Copy to make sure that default_headers won't be changed.
27842784
if query is None:
27852785
# Query operations will use ReadEndpoint even though it uses GET(for feed requests)
2786-
request = request_object._RequestObject(type, documents._OperationType.ReadFeed)
2786+
request = _request_object.RequestObject(type, documents._OperationType.ReadFeed)
27872787
headers = base.GetHeaders(self,
27882788
initial_headers,
27892789
'get',
@@ -2811,7 +2811,7 @@ def __GetBodiesFromQueryResult(result):
28112811
raise SystemError('Unexpected query compatibility mode.')
28122812

28132813
# Query operations will use ReadEndpoint even though it uses POST(for regular query operations)
2814-
request = request_object._RequestObject(type, documents._OperationType.SqlQuery)
2814+
request = _request_object.RequestObject(type, documents._OperationType.SqlQuery)
28152815
headers = base.GetHeaders(self,
28162816
initial_headers,
28172817
'post',

sdk/cosmos/azure-cosmos/azure/cosmos/default_retry_policy.py renamed to sdk/cosmos/azure-cosmos/azure/cosmos/_default_retry_policy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"""
2424
from . import http_constants
2525

26-
class _DefaultRetryPolicy(object):
26+
class DefaultRetryPolicy(object):
2727

2828
error_codes = http_constants._ErrorCodes
2929
CONNECTION_ERROR_CODES = [
@@ -52,7 +52,7 @@ def __init__(self, *args):
5252
self.args = args
5353

5454
def needsRetry(self, error_code):
55-
if error_code in _DefaultRetryPolicy.CONNECTION_ERROR_CODES:
55+
if error_code in DefaultRetryPolicy.CONNECTION_ERROR_CODES:
5656
if (len(self.args) > 0):
5757
if (self.args[4]['method'] == 'GET') or (http_constants.HttpHeaders.IsQuery in self.args[4]['headers']):
5858
return True

sdk/cosmos/azure-cosmos/azure/cosmos/endpoint_discovery_retry_policy.py renamed to sdk/cosmos/azure-cosmos/azure/cosmos/_endpoint_discovery_retry_policy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
logger.addHandler(log_handler)
3434

3535

36-
class _EndpointDiscoveryRetryPolicy(object):
36+
class EndpointDiscoveryRetryPolicy(object):
3737
"""The endpoint discovery retry policy class used for geo-replicated database accounts
3838
to handle the write forbidden exceptions due to writable/readable location changes
3939
(say, after a failover).
@@ -44,9 +44,9 @@ class _EndpointDiscoveryRetryPolicy(object):
4444

4545
def __init__(self, connection_policy, global_endpoint_manager, *args):
4646
self.global_endpoint_manager = global_endpoint_manager
47-
self._max_retry_attempt_count = _EndpointDiscoveryRetryPolicy.Max_retry_attempt_count
47+
self._max_retry_attempt_count = EndpointDiscoveryRetryPolicy.Max_retry_attempt_count
4848
self.failover_retry_count = 0
49-
self.retry_after_in_milliseconds = _EndpointDiscoveryRetryPolicy.Retry_after_in_milliseconds
49+
self.retry_after_in_milliseconds = EndpointDiscoveryRetryPolicy.Retry_after_in_milliseconds
5050
self.connection_policy = connection_policy
5151
self.request = args[0] if args else None
5252
#clear previous location-based routing directive

sdk/cosmos/azure-cosmos/azure/cosmos/execution_context/aggregators.py renamed to sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/aggregators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"""Internal class for aggregation queries implementation in the Azure Cosmos database service.
2323
"""
2424
from abc import abstractmethod, ABCMeta
25-
from azure.cosmos.execution_context.document_producer import _OrderByHelper
25+
from azure.cosmos._execution_context.document_producer import _OrderByHelper
2626

2727

2828
class _Aggregator(object):

sdk/cosmos/azure-cosmos/azure/cosmos/execution_context/base_execution_context.py renamed to sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/base_execution_context.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"""
2424

2525
from collections import deque
26-
from .. import retry_utility
26+
from .. import _retry_utility
2727
from .. import http_constants
28-
from .. import base
28+
from .. import _base
2929

3030
class _QueryExecutionContextBase(object):
3131
"""
@@ -140,7 +140,7 @@ def _fetch_items_helper_with_retries(self, fetch_function):
140140
def callback():
141141
return self._fetch_items_helper_no_retries(fetch_function)
142142

143-
return retry_utility._Execute(self._client, self._client._global_endpoint_manager, callback)
143+
return _retry_utility.Execute(self._client, self._client._global_endpoint_manager, callback)
144144

145145

146146
class _DefaultQueryExecutionContext(_QueryExecutionContextBase):
@@ -208,8 +208,8 @@ def __init__(self, client, options, database_link, query, partition_key):
208208
raise ValueError("_collection_links_length is not greater than 0.")
209209

210210
# Creating the QueryFeed for the first collection
211-
path = base.GetPathFromLink(self._collection_links[self._current_collection_index], 'docs')
212-
collection_id = base.GetResourceIdOrFullNameFromLink(self._collection_links[self._current_collection_index])
211+
path = _base.GetPathFromLink(self._collection_links[self._current_collection_index], 'docs')
212+
collection_id = _base.GetResourceIdOrFullNameFromLink(self._collection_links[self._current_collection_index])
213213

214214
self._current_collection_index += 1
215215

@@ -241,8 +241,8 @@ def _fetch_next_block(self):
241241
# creating separate feed queries for each collection and fetching the items
242242
while not fetched_items:
243243
if self._collection_links and self._current_collection_index < self._collection_links_length:
244-
path = base.GetPathFromLink(self._collection_links[self._current_collection_index], 'docs')
245-
collection_id = base.GetResourceIdOrFullNameFromLink(self._collection_links[self._current_collection_index])
244+
path = _base.GetPathFromLink(self._collection_links[self._current_collection_index], 'docs')
245+
collection_id = _base.GetResourceIdOrFullNameFromLink(self._collection_links[self._current_collection_index])
246246

247247
self._continuation = None
248248
self._has_started = False

sdk/cosmos/azure-cosmos/azure/cosmos/execution_context/document_producer.py renamed to sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/document_producer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import six
2626
import numbers
2727
from collections import deque
28-
from azure.cosmos import base
29-
from azure.cosmos.execution_context.base_execution_context import _DefaultQueryExecutionContext
28+
from azure.cosmos import _base
29+
from azure.cosmos._execution_context.base_execution_context import _DefaultQueryExecutionContext
3030
from six.moves import xrange
3131

3232
class _DocumentProducer(object):
@@ -51,8 +51,8 @@ def __init__(self, partition_key_target_range, client, collection_link, query, d
5151
self._cur_item = None
5252
# initiate execution context
5353

54-
path = base.GetPathFromLink(collection_link, 'docs')
55-
collection_id = base.GetResourceIdOrFullNameFromLink(collection_link)
54+
path = _base.GetPathFromLink(collection_link, 'docs')
55+
collection_id = _base.GetResourceIdOrFullNameFromLink(collection_link)
5656
def fetch_fn(options):
5757
return self._client.QueryFeed(path,
5858
collection_id,

sdk/cosmos/azure-cosmos/azure/cosmos/execution_context/endpoint_component.py renamed to sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/endpoint_component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"""
2424
import numbers
2525

26-
from azure.cosmos.execution_context.aggregators import _AverageAggregator, _CountAggregator, _MaxAggregator, \
26+
from azure.cosmos._execution_context.aggregators import _AverageAggregator, _CountAggregator, _MaxAggregator, \
2727
_MinAggregator, _SumAggregator
2828

2929

sdk/cosmos/azure-cosmos/azure/cosmos/execution_context/execution_dispatcher.py renamed to sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/execution_dispatcher.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import json
2626
from six.moves import xrange
2727
from azure.cosmos.errors import HTTPFailure
28-
from azure.cosmos.execution_context.base_execution_context import _QueryExecutionContextBase
29-
from azure.cosmos.execution_context.base_execution_context import _DefaultQueryExecutionContext
30-
from azure.cosmos.execution_context.query_execution_info import _PartitionedQueryExecutionInfo
31-
from azure.cosmos.execution_context import endpoint_component
32-
from azure.cosmos.execution_context import multi_execution_aggregator
28+
from azure.cosmos._execution_context.base_execution_context import _QueryExecutionContextBase
29+
from azure.cosmos._execution_context.base_execution_context import _DefaultQueryExecutionContext
30+
from azure.cosmos._execution_context.query_execution_info import _PartitionedQueryExecutionInfo
31+
from azure.cosmos._execution_context import endpoint_component
32+
from azure.cosmos._execution_context import multi_execution_aggregator
3333
from azure.cosmos.http_constants import StatusCodes, SubStatusCodes
3434

3535
class _ProxyQueryExecutionContext(_QueryExecutionContextBase):

sdk/cosmos/azure-cosmos/azure/cosmos/execution_context/multi_execution_aggregator.py renamed to sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/multi_execution_aggregator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"""
2424

2525
import heapq
26-
from azure.cosmos.execution_context.base_execution_context import _QueryExecutionContextBase
27-
from azure.cosmos.execution_context import document_producer
28-
from azure.cosmos.routing import routing_range
26+
from azure.cosmos._execution_context.base_execution_context import _QueryExecutionContextBase
27+
from azure.cosmos._execution_context import document_producer
28+
from azure.cosmos._routing import routing_range
2929

3030
class _MultiExecutionContextAggregator(_QueryExecutionContextBase):
3131
"""This class is capable of queries which requires rewriting based on
@@ -147,4 +147,4 @@ def _createTargetPartitionQueryExecutionContext(self, partition_key_target_range
147147
def _get_target_parition_key_range(self):
148148

149149
query_ranges = self._partitioned_query_ex_info.get_query_ranges()
150-
return self._routing_provider.get_overlapping_ranges(self._resource_link, [routing_range._Range.ParseFromDict(range_as_dict) for range_as_dict in query_ranges])
150+
return self._routing_provider.get_overlapping_ranges(self._resource_link, [routing_range.Range.ParseFromDict(range_as_dict) for range_as_dict in query_ranges])

sdk/cosmos/azure-cosmos/azure/cosmos/global_endpoint_manager.py renamed to sdk/cosmos/azure-cosmos/azure/cosmos/_global_endpoint_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
from six.moves.urllib.parse import urlparse
2626
import threading
27-
from . import constants
27+
from . import _constants as constants
2828
from . import errors
29-
from .location_cache import LocationCache
29+
from ._location_cache import LocationCache
3030

3131
class _GlobalEndpointManager(object):
3232
"""

0 commit comments

Comments
 (0)