ADAPT-Chase commited on
Commit
2acf95e
·
verified ·
1 Parent(s): 06d96dc

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +28 -0
  2. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/column_encryption/__pycache__/_policies.cpython-312.pyc +0 -0
  3. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/column_encryption/__pycache__/policies.cpython-312.pyc +0 -0
  4. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/__init__.cpython-312.pyc +0 -0
  5. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/columns.cpython-312.pyc +0 -0
  6. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/connection.cpython-312.pyc +0 -0
  7. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/functions.cpython-312.pyc +0 -0
  8. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/management.cpython-312.pyc +0 -0
  9. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/models.cpython-312.pyc +0 -0
  10. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/named.cpython-312.pyc +0 -0
  11. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/operators.cpython-312.pyc +0 -0
  12. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/query.cpython-312.pyc +0 -0
  13. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/statements.cpython-312.pyc +0 -0
  14. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/usertype.cpython-312.pyc +0 -0
  15. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/__pycache__/__init__.cpython-312.pyc +0 -0
  16. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/cloud/__init__.py +193 -0
  17. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/cloud/__pycache__/__init__.cpython-312.pyc +0 -0
  18. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/__init__.py +23 -0
  19. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/__pycache__/__init__.cpython-312.pyc +0 -0
  20. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/__pycache__/graphson.cpython-312.pyc +0 -0
  21. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/__pycache__/query.cpython-312.pyc +0 -0
  22. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/__pycache__/types.cpython-312.pyc +0 -0
  23. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__init__.py +303 -0
  24. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__pycache__/__init__.cpython-312.pyc +0 -0
  25. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__pycache__/_predicates.cpython-312.pyc +0 -0
  26. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__pycache__/_query.cpython-312.pyc +0 -0
  27. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__pycache__/_serializers.cpython-312.pyc +0 -0
  28. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__pycache__/predicates.cpython-312.pyc +0 -0
  29. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__pycache__/query.cpython-312.pyc +0 -0
  30. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__pycache__/serializers.cpython-312.pyc +0 -0
  31. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/_predicates.py +202 -0
  32. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/_query.py +228 -0
  33. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/_serializers.py +260 -0
  34. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/predicates.py +20 -0
  35. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/query.py +20 -0
  36. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/serializers.py +20 -0
  37. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/__init__.py +13 -0
  38. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/__pycache__/__init__.cpython-312.pyc +0 -0
  39. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/__pycache__/registry.cpython-312.pyc +0 -0
  40. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/__pycache__/reporter.cpython-312.pyc +0 -0
  41. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/__pycache__/serializers.cpython-312.pyc +0 -0
  42. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/__pycache__/util.cpython-312.pyc +0 -0
  43. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/registry.py +122 -0
  44. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/reporter.py +221 -0
  45. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/serializers.py +219 -0
  46. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/util.py +75 -0
  47. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/io/__pycache__/__init__.cpython-312.pyc +0 -0
  48. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/io/__pycache__/asyncioreactor.cpython-312.pyc +0 -0
  49. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/io/__pycache__/asyncorereactor.cpython-312.pyc +0 -0
  50. platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/io/__pycache__/eventletreactor.cpython-312.pyc +0 -0
.gitattributes CHANGED
@@ -3414,3 +3414,31 @@ platform/dataops/dto/.venv/lib/python3.12/site-packages/pymdownx/__pycache__/twe
3414
  platform/dataops/dto/.venv/lib/python3.12/site-packages/jinja2/__pycache__/compiler.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
3415
  platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/__pycache__/cluster.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
3416
  platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/__pycache__/metadata.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3414
  platform/dataops/dto/.venv/lib/python3.12/site-packages/jinja2/__pycache__/compiler.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
3415
  platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/__pycache__/cluster.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
3416
  platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/__pycache__/metadata.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
3417
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/rich/__pycache__/_emoji_codes.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
3418
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/rich/__pycache__/console.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
3419
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/index.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3420
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/testing.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3421
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/internals.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3422
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/reshape.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3423
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/interval.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3424
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/lib.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3425
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/parsers.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3426
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/ops.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3427
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/hashing.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3428
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/missing.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3429
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/sas.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3430
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/hashtable.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3431
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/join.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3432
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/writers.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3433
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/sparse.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3434
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/algos.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3435
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/groupby.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3436
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/_libs/tslib.cpython-312-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
3437
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/core/__pycache__/frame.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
3438
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/core/__pycache__/generic.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
3439
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/core/__pycache__/indexing.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
3440
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/core/__pycache__/series.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
3441
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/core/indexes/__pycache__/base.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
3442
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/core/indexes/__pycache__/multi.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
3443
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/core/groupby/__pycache__/generic.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
3444
+ platform/dataops/dto/.venv/lib/python3.12/site-packages/pandas/core/groupby/__pycache__/groupby.cpython-312.pyc filter=lfs diff=lfs merge=lfs -text
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/column_encryption/__pycache__/_policies.cpython-312.pyc ADDED
Binary file (6.57 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/column_encryption/__pycache__/policies.cpython-312.pyc ADDED
Binary file (362 Bytes). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (1.02 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/columns.cpython-312.pyc ADDED
Binary file (50.1 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/connection.cpython-312.pyc ADDED
Binary file (16.3 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/functions.cpython-312.pyc ADDED
Binary file (6.42 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/management.cpython-312.pyc ADDED
Binary file (27.3 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/models.cpython-312.pyc ADDED
Binary file (51.1 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/named.cpython-312.pyc ADDED
Binary file (7.73 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/operators.cpython-312.pyc ADDED
Binary file (3.94 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/query.cpython-312.pyc ADDED
Binary file (72.6 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/statements.cpython-312.pyc ADDED
Binary file (49.1 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/cqlengine/__pycache__/usertype.cpython-312.pyc ADDED
Binary file (12 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (197 Bytes). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/cloud/__init__.py ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright DataStax, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import os
16
+ import logging
17
+ import json
18
+ import sys
19
+ import tempfile
20
+ import shutil
21
+ from urllib.request import urlopen
22
+
23
+ _HAS_SSL = True
24
+ try:
25
+ from ssl import SSLContext, PROTOCOL_TLS, CERT_REQUIRED
26
+ except:
27
+ _HAS_SSL = False
28
+
29
+ from zipfile import ZipFile
30
+
31
+ # 2.7 vs 3.x
32
+ try:
33
+ from zipfile import BadZipFile
34
+ except:
35
+ from zipfile import BadZipfile as BadZipFile
36
+
37
+ from cassandra import DriverException
38
+
39
+ log = logging.getLogger(__name__)
40
+
41
+ __all__ = ['get_cloud_config']
42
+
43
+ DATASTAX_CLOUD_PRODUCT_TYPE = "DATASTAX_APOLLO"
44
+
45
+
46
+ class CloudConfig(object):
47
+
48
+ username = None
49
+ password = None
50
+ host = None
51
+ port = None
52
+ keyspace = None
53
+ local_dc = None
54
+ ssl_context = None
55
+
56
+ sni_host = None
57
+ sni_port = None
58
+ host_ids = None
59
+
60
+ @classmethod
61
+ def from_dict(cls, d):
62
+ c = cls()
63
+
64
+ c.port = d.get('port', None)
65
+ try:
66
+ c.port = int(d['port'])
67
+ except:
68
+ pass
69
+
70
+ c.username = d.get('username', None)
71
+ c.password = d.get('password', None)
72
+ c.host = d.get('host', None)
73
+ c.keyspace = d.get('keyspace', None)
74
+ c.local_dc = d.get('localDC', None)
75
+
76
+ return c
77
+
78
+
79
+ def get_cloud_config(cloud_config, create_pyopenssl_context=False):
80
+ if not _HAS_SSL:
81
+ raise DriverException("A Python installation with SSL is required to connect to a cloud cluster.")
82
+
83
+ if 'secure_connect_bundle' not in cloud_config:
84
+ raise ValueError("The cloud config doesn't have a secure_connect_bundle specified.")
85
+
86
+ try:
87
+ config = read_cloud_config_from_zip(cloud_config, create_pyopenssl_context)
88
+ except BadZipFile:
89
+ raise ValueError("Unable to open the zip file for the cloud config. Check your secure connect bundle.")
90
+
91
+ config = read_metadata_info(config, cloud_config)
92
+ if create_pyopenssl_context:
93
+ config.ssl_context = config.pyopenssl_context
94
+ return config
95
+
96
+
97
+ def read_cloud_config_from_zip(cloud_config, create_pyopenssl_context):
98
+ secure_bundle = cloud_config['secure_connect_bundle']
99
+ use_default_tempdir = cloud_config.get('use_default_tempdir', None)
100
+ with ZipFile(secure_bundle) as zipfile:
101
+ base_dir = tempfile.gettempdir() if use_default_tempdir else os.path.dirname(secure_bundle)
102
+ tmp_dir = tempfile.mkdtemp(dir=base_dir)
103
+ try:
104
+ zipfile.extractall(path=tmp_dir)
105
+ return parse_cloud_config(os.path.join(tmp_dir, 'config.json'), cloud_config, create_pyopenssl_context)
106
+ finally:
107
+ shutil.rmtree(tmp_dir)
108
+
109
+
110
+ def parse_cloud_config(path, cloud_config, create_pyopenssl_context):
111
+ with open(path, 'r') as stream:
112
+ data = json.load(stream)
113
+
114
+ config = CloudConfig.from_dict(data)
115
+ config_dir = os.path.dirname(path)
116
+
117
+ if 'ssl_context' in cloud_config:
118
+ config.ssl_context = cloud_config['ssl_context']
119
+ else:
120
+ # Load the ssl_context before we delete the temporary directory
121
+ ca_cert_location = os.path.join(config_dir, 'ca.crt')
122
+ cert_location = os.path.join(config_dir, 'cert')
123
+ key_location = os.path.join(config_dir, 'key')
124
+ # Regardless of if we create a pyopenssl context, we still need the builtin one
125
+ # to connect to the metadata service
126
+ config.ssl_context = _ssl_context_from_cert(ca_cert_location, cert_location, key_location)
127
+ if create_pyopenssl_context:
128
+ config.pyopenssl_context = _pyopenssl_context_from_cert(ca_cert_location, cert_location, key_location)
129
+
130
+ return config
131
+
132
+
133
+ def read_metadata_info(config, cloud_config):
134
+ url = "https://{}:{}/metadata".format(config.host, config.port)
135
+ timeout = cloud_config['connect_timeout'] if 'connect_timeout' in cloud_config else 5
136
+ try:
137
+ response = urlopen(url, context=config.ssl_context, timeout=timeout)
138
+ except Exception as e:
139
+ log.exception(e)
140
+ raise DriverException("Unable to connect to the metadata service at %s. "
141
+ "Check the cluster status in the cloud console. " % url)
142
+
143
+ if response.code != 200:
144
+ raise DriverException(("Error while fetching the metadata at: %s. "
145
+ "The service returned error code %d." % (url, response.code)))
146
+ return parse_metadata_info(config, response.read().decode('utf-8'))
147
+
148
+
149
+ def parse_metadata_info(config, http_data):
150
+ try:
151
+ data = json.loads(http_data)
152
+ except:
153
+ msg = "Failed to load cluster metadata"
154
+ raise DriverException(msg)
155
+
156
+ contact_info = data['contact_info']
157
+ config.local_dc = contact_info['local_dc']
158
+
159
+ proxy_info = contact_info['sni_proxy_address'].split(':')
160
+ config.sni_host = proxy_info[0]
161
+ try:
162
+ config.sni_port = int(proxy_info[1])
163
+ except:
164
+ config.sni_port = 9042
165
+
166
+ config.host_ids = [host_id for host_id in contact_info['contact_points']]
167
+
168
+ return config
169
+
170
+
171
+ def _ssl_context_from_cert(ca_cert_location, cert_location, key_location):
172
+ ssl_context = SSLContext(PROTOCOL_TLS)
173
+ ssl_context.load_verify_locations(ca_cert_location)
174
+ ssl_context.verify_mode = CERT_REQUIRED
175
+ ssl_context.load_cert_chain(certfile=cert_location, keyfile=key_location)
176
+
177
+ return ssl_context
178
+
179
+
180
+ def _pyopenssl_context_from_cert(ca_cert_location, cert_location, key_location):
181
+ try:
182
+ from OpenSSL import SSL
183
+ except ImportError as e:
184
+ raise ImportError(
185
+ "PyOpenSSL must be installed to connect to Astra with the Eventlet or Twisted event loops")\
186
+ .with_traceback(e.__traceback__)
187
+ ssl_context = SSL.Context(SSL.TLSv1_METHOD)
188
+ ssl_context.set_verify(SSL.VERIFY_PEER, callback=lambda _1, _2, _3, _4, ok: ok)
189
+ ssl_context.use_certificate_file(cert_location)
190
+ ssl_context.use_privatekey_file(key_location)
191
+ ssl_context.load_verify_locations(ca_cert_location)
192
+
193
+ return ssl_context
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/cloud/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (8.31 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/__init__.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright DataStax, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ from cassandra.datastax.graph.types import Element, Vertex, VertexProperty, Edge, Path, T
17
+ from cassandra.datastax.graph.query import (
18
+ GraphOptions, GraphProtocol, GraphStatement, SimpleGraphStatement, Result,
19
+ graph_object_row_factory, single_object_row_factory,
20
+ graph_result_row_factory, graph_graphson2_row_factory,
21
+ graph_graphson3_row_factory
22
+ )
23
+ from cassandra.datastax.graph.graphson import *
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (772 Bytes). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/__pycache__/graphson.cpython-312.pyc ADDED
Binary file (50.8 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/__pycache__/query.cpython-312.pyc ADDED
Binary file (16.9 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/__pycache__/types.cpython-312.pyc ADDED
Binary file (9.56 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__init__.py ADDED
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright DataStax, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import logging
16
+ import copy
17
+
18
+ from concurrent.futures import Future
19
+
20
+ HAVE_GREMLIN = False
21
+ try:
22
+ import gremlin_python
23
+ HAVE_GREMLIN = True
24
+ except ImportError:
25
+ # gremlinpython is not installed.
26
+ pass
27
+
28
+ if HAVE_GREMLIN:
29
+ from gremlin_python.structure.graph import Graph
30
+ from gremlin_python.driver.remote_connection import RemoteConnection, RemoteTraversal
31
+ from gremlin_python.process.traversal import Traverser, TraversalSideEffects
32
+ from gremlin_python.process.graph_traversal import GraphTraversal
33
+
34
+ from cassandra.cluster import Session, GraphExecutionProfile, EXEC_PROFILE_GRAPH_DEFAULT
35
+ from cassandra.datastax.graph import GraphOptions, GraphProtocol
36
+ from cassandra.datastax.graph.query import _GraphSONContextRowFactory
37
+
38
+ from cassandra.datastax.graph.fluent.serializers import (
39
+ GremlinGraphSONReaderV2,
40
+ GremlinGraphSONReaderV3,
41
+ dse_graphson2_deserializers,
42
+ gremlin_graphson2_deserializers,
43
+ dse_graphson3_deserializers,
44
+ gremlin_graphson3_deserializers
45
+ )
46
+ from cassandra.datastax.graph.fluent.query import _DefaultTraversalBatch, _query_from_traversal
47
+
48
+ log = logging.getLogger(__name__)
49
+
50
+ __all__ = ['BaseGraphRowFactory', 'graph_traversal_row_factory',
51
+ 'graph_traversal_dse_object_row_factory', 'DSESessionRemoteGraphConnection', 'DseGraph']
52
+
53
+ # Traversal result keys
54
+ _bulk_key = 'bulk'
55
+ _result_key = 'result'
56
+
57
+
58
+ class BaseGraphRowFactory(_GraphSONContextRowFactory):
59
+ """
60
+ Base row factory for graph traversal. This class basically wraps a
61
+ graphson reader function to handle additional features of Gremlin/DSE
62
+ and is callable as a normal row factory.
63
+
64
+ Currently supported:
65
+ - bulk results
66
+ """
67
+
68
+ def __call__(self, column_names, rows):
69
+ for row in rows:
70
+ parsed_row = self.graphson_reader.readObject(row[0])
71
+ yield parsed_row[_result_key]
72
+ bulk = parsed_row.get(_bulk_key, 1)
73
+ for _ in range(bulk - 1):
74
+ yield copy.deepcopy(parsed_row[_result_key])
75
+
76
+
77
+ class _GremlinGraphSON2RowFactory(BaseGraphRowFactory):
78
+ """Row Factory that returns the decoded graphson2."""
79
+ graphson_reader_class = GremlinGraphSONReaderV2
80
+ graphson_reader_kwargs = {'deserializer_map': gremlin_graphson2_deserializers}
81
+
82
+
83
+ class _DseGraphSON2RowFactory(BaseGraphRowFactory):
84
+ """Row Factory that returns the decoded graphson2 as DSE types."""
85
+ graphson_reader_class = GremlinGraphSONReaderV2
86
+ graphson_reader_kwargs = {'deserializer_map': dse_graphson2_deserializers}
87
+
88
+ gremlin_graphson2_traversal_row_factory = _GremlinGraphSON2RowFactory
89
+ # TODO remove in next major
90
+ graph_traversal_row_factory = gremlin_graphson2_traversal_row_factory
91
+
92
+ dse_graphson2_traversal_row_factory = _DseGraphSON2RowFactory
93
+ # TODO remove in next major
94
+ graph_traversal_dse_object_row_factory = dse_graphson2_traversal_row_factory
95
+
96
+
97
+ class _GremlinGraphSON3RowFactory(BaseGraphRowFactory):
98
+ """Row Factory that returns the decoded graphson2."""
99
+ graphson_reader_class = GremlinGraphSONReaderV3
100
+ graphson_reader_kwargs = {'deserializer_map': gremlin_graphson3_deserializers}
101
+
102
+
103
+ class _DseGraphSON3RowFactory(BaseGraphRowFactory):
104
+ """Row Factory that returns the decoded graphson3 as DSE types."""
105
+ graphson_reader_class = GremlinGraphSONReaderV3
106
+ graphson_reader_kwargs = {'deserializer_map': dse_graphson3_deserializers}
107
+
108
+
109
+ gremlin_graphson3_traversal_row_factory = _GremlinGraphSON3RowFactory
110
+ dse_graphson3_traversal_row_factory = _DseGraphSON3RowFactory
111
+
112
+
113
+ class DSESessionRemoteGraphConnection(RemoteConnection):
114
+ """
115
+ A Tinkerpop RemoteConnection to execute traversal queries on DSE.
116
+
117
+ :param session: A DSE session
118
+ :param graph_name: (Optional) DSE Graph name.
119
+ :param execution_profile: (Optional) Execution profile for traversal queries. Default is set to `EXEC_PROFILE_GRAPH_DEFAULT`.
120
+ """
121
+
122
+ session = None
123
+ graph_name = None
124
+ execution_profile = None
125
+
126
+ def __init__(self, session, graph_name=None, execution_profile=EXEC_PROFILE_GRAPH_DEFAULT):
127
+ super(DSESessionRemoteGraphConnection, self).__init__(None, None)
128
+
129
+ if not isinstance(session, Session):
130
+ raise ValueError('A DSE Session must be provided to execute graph traversal queries.')
131
+
132
+ self.session = session
133
+ self.graph_name = graph_name
134
+ self.execution_profile = execution_profile
135
+
136
+ @staticmethod
137
+ def _traversers_generator(traversers):
138
+ for t in traversers:
139
+ yield Traverser(t)
140
+
141
+ def _prepare_query(self, bytecode):
142
+ ep = self.session.execution_profile_clone_update(self.execution_profile)
143
+ graph_options = ep.graph_options
144
+ graph_options.graph_name = self.graph_name or graph_options.graph_name
145
+ graph_options.graph_language = DseGraph.DSE_GRAPH_QUERY_LANGUAGE
146
+ # We resolve the execution profile options here , to know how what gremlin factory to set
147
+ self.session._resolve_execution_profile_options(ep)
148
+
149
+ context = None
150
+ if graph_options.graph_protocol == GraphProtocol.GRAPHSON_2_0:
151
+ row_factory = gremlin_graphson2_traversal_row_factory
152
+ elif graph_options.graph_protocol == GraphProtocol.GRAPHSON_3_0:
153
+ row_factory = gremlin_graphson3_traversal_row_factory
154
+ context = {
155
+ 'cluster': self.session.cluster,
156
+ 'graph_name': graph_options.graph_name.decode('utf-8')
157
+ }
158
+ else:
159
+ raise ValueError('Unknown graph protocol: {}'.format(graph_options.graph_protocol))
160
+
161
+ ep.row_factory = row_factory
162
+ query = DseGraph.query_from_traversal(bytecode, graph_options.graph_protocol, context)
163
+
164
+ return query, ep
165
+
166
+ @staticmethod
167
+ def _handle_query_results(result_set, gremlin_future):
168
+ try:
169
+ gremlin_future.set_result(
170
+ RemoteTraversal(DSESessionRemoteGraphConnection._traversers_generator(result_set), TraversalSideEffects())
171
+ )
172
+ except Exception as e:
173
+ gremlin_future.set_exception(e)
174
+
175
+ @staticmethod
176
+ def _handle_query_error(response, gremlin_future):
177
+ gremlin_future.set_exception(response)
178
+
179
+ def submit(self, bytecode):
180
+ # the only reason I don't use submitAsync here
181
+ # is to avoid an unuseful future wrap
182
+ query, ep = self._prepare_query(bytecode)
183
+
184
+ traversers = self.session.execute_graph(query, execution_profile=ep)
185
+ return RemoteTraversal(self._traversers_generator(traversers), TraversalSideEffects())
186
+
187
+ def submitAsync(self, bytecode):
188
+ query, ep = self._prepare_query(bytecode)
189
+
190
+ # to be compatible with gremlinpython, we need to return a concurrent.futures.Future
191
+ gremlin_future = Future()
192
+ response_future = self.session.execute_graph_async(query, execution_profile=ep)
193
+ response_future.add_callback(self._handle_query_results, gremlin_future)
194
+ response_future.add_errback(self._handle_query_error, gremlin_future)
195
+
196
+ return gremlin_future
197
+
198
+ def __str__(self):
199
+ return "<DSESessionRemoteGraphConnection: graph_name='{0}'>".format(self.graph_name)
200
+
201
+ __repr__ = __str__
202
+
203
+
204
+ class DseGraph(object):
205
+ """
206
+ Dse Graph utility class for GraphTraversal construction and execution.
207
+ """
208
+
209
+ DSE_GRAPH_QUERY_LANGUAGE = 'bytecode-json'
210
+ """
211
+ Graph query language, Default is 'bytecode-json' (GraphSON).
212
+ """
213
+
214
+ DSE_GRAPH_QUERY_PROTOCOL = GraphProtocol.GRAPHSON_2_0
215
+ """
216
+ Graph query language, Default is GraphProtocol.GRAPHSON_2_0.
217
+ """
218
+
219
+ @staticmethod
220
+ def query_from_traversal(traversal, graph_protocol=DSE_GRAPH_QUERY_PROTOCOL, context=None):
221
+ """
222
+ From a GraphTraversal, return a query string based on the language specified in `DseGraph.DSE_GRAPH_QUERY_LANGUAGE`.
223
+
224
+ :param traversal: The GraphTraversal object
225
+ :param graph_protocol: The graph protocol. Default is `DseGraph.DSE_GRAPH_QUERY_PROTOCOL`.
226
+ :param context: The dict of the serialization context, needed for GraphSON3 (tuple, udt).
227
+ e.g: {'cluster': cluster, 'graph_name': name}
228
+ """
229
+
230
+ if isinstance(traversal, GraphTraversal):
231
+ for strategy in traversal.traversal_strategies.traversal_strategies:
232
+ rc = strategy.remote_connection
233
+ if (isinstance(rc, DSESessionRemoteGraphConnection) and
234
+ rc.session or rc.graph_name or rc.execution_profile):
235
+ log.warning("GraphTraversal session, graph_name and execution_profile are "
236
+ "only taken into account when executed with TinkerPop.")
237
+
238
+ return _query_from_traversal(traversal, graph_protocol, context)
239
+
240
+ @staticmethod
241
+ def traversal_source(session=None, graph_name=None, execution_profile=EXEC_PROFILE_GRAPH_DEFAULT,
242
+ traversal_class=None):
243
+ """
244
+ Returns a TinkerPop GraphTraversalSource binded to the session and graph_name if provided.
245
+
246
+ :param session: (Optional) A DSE session
247
+ :param graph_name: (Optional) DSE Graph name
248
+ :param execution_profile: (Optional) Execution profile for traversal queries. Default is set to `EXEC_PROFILE_GRAPH_DEFAULT`.
249
+ :param traversal_class: (Optional) The GraphTraversalSource class to use (DSL).
250
+
251
+ .. code-block:: python
252
+
253
+ from cassandra.cluster import Cluster
254
+ from cassandra.datastax.graph.fluent import DseGraph
255
+
256
+ c = Cluster()
257
+ session = c.connect()
258
+
259
+ g = DseGraph.traversal_source(session, 'my_graph')
260
+ print(g.V().valueMap().toList())
261
+
262
+ """
263
+
264
+ graph = Graph()
265
+ traversal_source = graph.traversal(traversal_class)
266
+
267
+ if session:
268
+ traversal_source = traversal_source.withRemote(
269
+ DSESessionRemoteGraphConnection(session, graph_name, execution_profile))
270
+
271
+ return traversal_source
272
+
273
+ @staticmethod
274
+ def create_execution_profile(graph_name, graph_protocol=DSE_GRAPH_QUERY_PROTOCOL, **kwargs):
275
+ """
276
+ Creates an ExecutionProfile for GraphTraversal execution. You need to register that execution profile to the
277
+ cluster by using `cluster.add_execution_profile`.
278
+
279
+ :param graph_name: The graph name
280
+ :param graph_protocol: (Optional) The graph protocol, default is `DSE_GRAPH_QUERY_PROTOCOL`.
281
+ """
282
+
283
+ if graph_protocol == GraphProtocol.GRAPHSON_2_0:
284
+ row_factory = dse_graphson2_traversal_row_factory
285
+ elif graph_protocol == GraphProtocol.GRAPHSON_3_0:
286
+ row_factory = dse_graphson3_traversal_row_factory
287
+ else:
288
+ raise ValueError('Unknown graph protocol: {}'.format(graph_protocol))
289
+
290
+ ep = GraphExecutionProfile(row_factory=row_factory,
291
+ graph_options=GraphOptions(graph_name=graph_name,
292
+ graph_language=DseGraph.DSE_GRAPH_QUERY_LANGUAGE,
293
+ graph_protocol=graph_protocol),
294
+ **kwargs)
295
+ return ep
296
+
297
+ @staticmethod
298
+ def batch(*args, **kwargs):
299
+ """
300
+ Returns the :class:`cassandra.datastax.graph.fluent.query.TraversalBatch` object allowing to
301
+ execute multiple traversals in the same transaction.
302
+ """
303
+ return _DefaultTraversalBatch(*args, **kwargs)
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (13.5 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__pycache__/_predicates.cpython-312.pyc ADDED
Binary file (9.47 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__pycache__/_query.cpython-312.pyc ADDED
Binary file (10.6 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__pycache__/_serializers.cpython-312.pyc ADDED
Binary file (9.73 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__pycache__/predicates.cpython-312.pyc ADDED
Binary file (376 Bytes). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__pycache__/query.cpython-312.pyc ADDED
Binary file (366 Bytes). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/__pycache__/serializers.cpython-312.pyc ADDED
Binary file (378 Bytes). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/_predicates.py ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright DataStax, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import math
16
+
17
+ from gremlin_python.process.traversal import P
18
+
19
+ from cassandra.util import Distance
20
+
21
+ __all__ = ['GeoP', 'TextDistanceP', 'Search', 'GeoUnit', 'Geo', 'CqlCollection']
22
+
23
+
24
+ class GeoP(object):
25
+
26
+ def __init__(self, operator, value, other=None):
27
+ self.operator = operator
28
+ self.value = value
29
+ self.other = other
30
+
31
+ @staticmethod
32
+ def inside(*args, **kwargs):
33
+ return GeoP("inside", *args, **kwargs)
34
+
35
+ def __eq__(self, other):
36
+ return isinstance(other,
37
+ self.__class__) and self.operator == other.operator and self.value == other.value and self.other == other.other
38
+
39
+ def __repr__(self):
40
+ return self.operator + "(" + str(self.value) + ")" if self.other is None else self.operator + "(" + str(
41
+ self.value) + "," + str(self.other) + ")"
42
+
43
+
44
+ class TextDistanceP(object):
45
+
46
+ def __init__(self, operator, value, distance):
47
+ self.operator = operator
48
+ self.value = value
49
+ self.distance = distance
50
+
51
+ @staticmethod
52
+ def fuzzy(*args):
53
+ return TextDistanceP("fuzzy", *args)
54
+
55
+ @staticmethod
56
+ def token_fuzzy(*args):
57
+ return TextDistanceP("tokenFuzzy", *args)
58
+
59
+ @staticmethod
60
+ def phrase(*args):
61
+ return TextDistanceP("phrase", *args)
62
+
63
+ def __eq__(self, other):
64
+ return isinstance(other,
65
+ self.__class__) and self.operator == other.operator and self.value == other.value and self.distance == other.distance
66
+
67
+ def __repr__(self):
68
+ return self.operator + "(" + str(self.value) + "," + str(self.distance) + ")"
69
+
70
+
71
+ class Search(object):
72
+
73
+ @staticmethod
74
+ def token(value):
75
+ """
76
+ Search any instance of a certain token within the text property targeted.
77
+ :param value: the value to look for.
78
+ """
79
+ return P('token', value)
80
+
81
+ @staticmethod
82
+ def token_prefix(value):
83
+ """
84
+ Search any instance of a certain token prefix withing the text property targeted.
85
+ :param value: the value to look for.
86
+ """
87
+ return P('tokenPrefix', value)
88
+
89
+ @staticmethod
90
+ def token_regex(value):
91
+ """
92
+ Search any instance of the provided regular expression for the targeted property.
93
+ :param value: the value to look for.
94
+ """
95
+ return P('tokenRegex', value)
96
+
97
+ @staticmethod
98
+ def prefix(value):
99
+ """
100
+ Search for a specific prefix at the beginning of the text property targeted.
101
+ :param value: the value to look for.
102
+ """
103
+ return P('prefix', value)
104
+
105
+ @staticmethod
106
+ def regex(value):
107
+ """
108
+ Search for this regular expression inside the text property targeted.
109
+ :param value: the value to look for.
110
+ """
111
+ return P('regex', value)
112
+
113
+ @staticmethod
114
+ def fuzzy(value, distance):
115
+ """
116
+ Search for a fuzzy string inside the text property targeted.
117
+ :param value: the value to look for.
118
+ :param distance: The distance for the fuzzy search. ie. 1, to allow a one-letter misspellings.
119
+ """
120
+ return TextDistanceP.fuzzy(value, distance)
121
+
122
+ @staticmethod
123
+ def token_fuzzy(value, distance):
124
+ """
125
+ Search for a token fuzzy inside the text property targeted.
126
+ :param value: the value to look for.
127
+ :param distance: The distance for the token fuzzy search. ie. 1, to allow a one-letter misspellings.
128
+ """
129
+ return TextDistanceP.token_fuzzy(value, distance)
130
+
131
+ @staticmethod
132
+ def phrase(value, proximity):
133
+ """
134
+ Search for a phrase inside the text property targeted.
135
+ :param value: the value to look for.
136
+ :param proximity: The proximity for the phrase search. ie. phrase('David Felcey', 2).. to find 'David Felcey' with up to two middle names.
137
+ """
138
+ return TextDistanceP.phrase(value, proximity)
139
+
140
+
141
+ class CqlCollection(object):
142
+
143
+ @staticmethod
144
+ def contains(value):
145
+ """
146
+ Search for a value inside a cql list/set column.
147
+ :param value: the value to look for.
148
+ """
149
+ return P('contains', value)
150
+
151
+ @staticmethod
152
+ def contains_value(value):
153
+ """
154
+ Search for a map value.
155
+ :param value: the value to look for.
156
+ """
157
+ return P('containsValue', value)
158
+
159
+ @staticmethod
160
+ def contains_key(value):
161
+ """
162
+ Search for a map key.
163
+ :param value: the value to look for.
164
+ """
165
+ return P('containsKey', value)
166
+
167
+ @staticmethod
168
+ def entry_eq(value):
169
+ """
170
+ Search for a map entry.
171
+ :param value: the value to look for.
172
+ """
173
+ return P('entryEq', value)
174
+
175
+
176
+ class GeoUnit(object):
177
+ _EARTH_MEAN_RADIUS_KM = 6371.0087714
178
+ _DEGREES_TO_RADIANS = math.pi / 180
179
+ _DEG_TO_KM = _DEGREES_TO_RADIANS * _EARTH_MEAN_RADIUS_KM
180
+ _KM_TO_DEG = 1 / _DEG_TO_KM
181
+ _MILES_TO_KM = 1.609344001
182
+
183
+ MILES = _MILES_TO_KM * _KM_TO_DEG
184
+ KILOMETERS = _KM_TO_DEG
185
+ METERS = _KM_TO_DEG / 1000.0
186
+ DEGREES = 1
187
+
188
+
189
+ class Geo(object):
190
+
191
+ @staticmethod
192
+ def inside(value, units=GeoUnit.DEGREES):
193
+ """
194
+ Search any instance of geometry inside the Distance targeted.
195
+ :param value: A Distance to look for.
196
+ :param units: The units for ``value``. See GeoUnit enum. (Can also
197
+ provide an integer to use as a multiplier to convert ``value`` to
198
+ degrees.)
199
+ """
200
+ return GeoP.inside(
201
+ value=Distance(x=value.x, y=value.y, radius=value.radius * units)
202
+ )
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/_query.py ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright DataStax, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import logging
16
+
17
+ from cassandra.graph import SimpleGraphStatement, GraphProtocol
18
+ from cassandra.cluster import EXEC_PROFILE_GRAPH_DEFAULT
19
+
20
+ from gremlin_python.process.graph_traversal import GraphTraversal
21
+ from gremlin_python.structure.io.graphsonV2d0 import GraphSONWriter as GraphSONWriterV2
22
+ from gremlin_python.structure.io.graphsonV3d0 import GraphSONWriter as GraphSONWriterV3
23
+
24
+ from cassandra.datastax.graph.fluent.serializers import GremlinUserTypeIO, \
25
+ dse_graphson2_serializers, dse_graphson3_serializers
26
+
27
+ log = logging.getLogger(__name__)
28
+
29
+
30
+ __all__ = ['TraversalBatch', '_query_from_traversal', '_DefaultTraversalBatch']
31
+
32
+
33
+ class _GremlinGraphSONWriterAdapter(object):
34
+
35
+ def __init__(self, context, **kwargs):
36
+ super(_GremlinGraphSONWriterAdapter, self).__init__(**kwargs)
37
+ self.context = context
38
+ self.user_types = None
39
+
40
+ def serialize(self, value, _):
41
+ return self.toDict(value)
42
+
43
+ def get_serializer(self, value):
44
+ serializer = None
45
+ try:
46
+ serializer = self.serializers[type(value)]
47
+ except KeyError:
48
+ for key, ser in self.serializers.items():
49
+ if isinstance(value, key):
50
+ serializer = ser
51
+
52
+ if self.context:
53
+ # Check if UDT
54
+ if self.user_types is None:
55
+ try:
56
+ user_types = self.context['cluster']._user_types[self.context['graph_name']]
57
+ self.user_types = dict(map(reversed, user_types.items()))
58
+ except KeyError:
59
+ self.user_types = {}
60
+
61
+ # Custom detection to map a namedtuple to udt
62
+ if (tuple in self.serializers and serializer is self.serializers[tuple] and hasattr(value, '_fields') or
63
+ (not serializer and type(value) in self.user_types)):
64
+ serializer = GremlinUserTypeIO
65
+
66
+ if serializer:
67
+ try:
68
+ # A serializer can have specialized serializers (e.g for Int32 and Int64, so value dependant)
69
+ serializer = serializer.get_specialized_serializer(value)
70
+ except AttributeError:
71
+ pass
72
+
73
+ return serializer
74
+
75
+ def toDict(self, obj):
76
+ serializer = self.get_serializer(obj)
77
+ return serializer.dictify(obj, self) if serializer else obj
78
+
79
+ def definition(self, value):
80
+ serializer = self.get_serializer(value)
81
+ return serializer.definition(value, self)
82
+
83
+
84
+ class GremlinGraphSON2Writer(_GremlinGraphSONWriterAdapter, GraphSONWriterV2):
85
+ pass
86
+
87
+
88
+ class GremlinGraphSON3Writer(_GremlinGraphSONWriterAdapter, GraphSONWriterV3):
89
+ pass
90
+
91
+
92
+ graphson2_writer = GremlinGraphSON2Writer
93
+ graphson3_writer = GremlinGraphSON3Writer
94
+
95
+
96
+ def _query_from_traversal(traversal, graph_protocol, context=None):
97
+ """
98
+ From a GraphTraversal, return a query string.
99
+
100
+ :param traversal: The GraphTraversal object
101
+ :param graphson_protocol: The graph protocol to determine the output format.
102
+ """
103
+ if graph_protocol == GraphProtocol.GRAPHSON_2_0:
104
+ graphson_writer = graphson2_writer(context, serializer_map=dse_graphson2_serializers)
105
+ elif graph_protocol == GraphProtocol.GRAPHSON_3_0:
106
+ if context is None:
107
+ raise ValueError('Missing context for GraphSON3 serialization requires.')
108
+ graphson_writer = graphson3_writer(context, serializer_map=dse_graphson3_serializers)
109
+ else:
110
+ raise ValueError('Unknown graph protocol: {}'.format(graph_protocol))
111
+
112
+ try:
113
+ query = graphson_writer.writeObject(traversal)
114
+ except Exception:
115
+ log.exception("Error preparing graphson traversal query:")
116
+ raise
117
+
118
+ return query
119
+
120
+
121
+ class TraversalBatch(object):
122
+ """
123
+ A `TraversalBatch` is used to execute multiple graph traversals in a
124
+ single transaction. If any traversal in the batch fails, the entire
125
+ batch will fail to apply.
126
+
127
+ If a TraversalBatch is bounded to a DSE session, it can be executed using
128
+ `traversal_batch.execute()`.
129
+ """
130
+
131
+ _session = None
132
+ _execution_profile = None
133
+
134
+ def __init__(self, session=None, execution_profile=None):
135
+ """
136
+ :param session: (Optional) A DSE session
137
+ :param execution_profile: (Optional) The execution profile to use for the batch execution
138
+ """
139
+ self._session = session
140
+ self._execution_profile = execution_profile
141
+
142
+ def add(self, traversal):
143
+ """
144
+ Add a traversal to the batch.
145
+
146
+ :param traversal: A gremlin GraphTraversal
147
+ """
148
+ raise NotImplementedError()
149
+
150
+ def add_all(self, traversals):
151
+ """
152
+ Adds a sequence of traversals to the batch.
153
+
154
+ :param traversals: A sequence of gremlin GraphTraversal
155
+ """
156
+ raise NotImplementedError()
157
+
158
+ def execute(self):
159
+ """
160
+ Execute the traversal batch if bounded to a `DSE Session`.
161
+ """
162
+ raise NotImplementedError()
163
+
164
+ def as_graph_statement(self, graph_protocol=GraphProtocol.GRAPHSON_2_0):
165
+ """
166
+ Return the traversal batch as GraphStatement.
167
+
168
+ :param graph_protocol: The graph protocol for the GraphSONWriter. Default is GraphProtocol.GRAPHSON_2_0.
169
+ """
170
+ raise NotImplementedError()
171
+
172
+ def clear(self):
173
+ """
174
+ Clear a traversal batch for reuse.
175
+ """
176
+ raise NotImplementedError()
177
+
178
+ def __len__(self):
179
+ raise NotImplementedError()
180
+
181
+ def __str__(self):
182
+ return u'<TraversalBatch traversals={0}>'.format(len(self))
183
+ __repr__ = __str__
184
+
185
+
186
+ class _DefaultTraversalBatch(TraversalBatch):
187
+
188
+ _traversals = None
189
+
190
+ def __init__(self, *args, **kwargs):
191
+ super(_DefaultTraversalBatch, self).__init__(*args, **kwargs)
192
+ self._traversals = []
193
+
194
+ def add(self, traversal):
195
+ if not isinstance(traversal, GraphTraversal):
196
+ raise ValueError('traversal should be a gremlin GraphTraversal')
197
+
198
+ self._traversals.append(traversal)
199
+ return self
200
+
201
+ def add_all(self, traversals):
202
+ for traversal in traversals:
203
+ self.add(traversal)
204
+
205
+ def as_graph_statement(self, graph_protocol=GraphProtocol.GRAPHSON_2_0, context=None):
206
+ statements = [_query_from_traversal(t, graph_protocol, context) for t in self._traversals]
207
+ query = u"[{0}]".format(','.join(statements))
208
+ return SimpleGraphStatement(query)
209
+
210
+ def execute(self):
211
+ if self._session is None:
212
+ raise ValueError('A DSE Session must be provided to execute the traversal batch.')
213
+
214
+ execution_profile = self._execution_profile if self._execution_profile else EXEC_PROFILE_GRAPH_DEFAULT
215
+ graph_options = self._session.get_execution_profile(execution_profile).graph_options
216
+ context = {
217
+ 'cluster': self._session.cluster,
218
+ 'graph_name': graph_options.graph_name
219
+ }
220
+ statement = self.as_graph_statement(graph_options.graph_protocol, context=context) \
221
+ if graph_options.graph_protocol else self.as_graph_statement(context=context)
222
+ return self._session.execute_graph(statement, execution_profile=execution_profile)
223
+
224
+ def clear(self):
225
+ del self._traversals[:]
226
+
227
+ def __len__(self):
228
+ return len(self._traversals)
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/_serializers.py ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright DataStax, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from collections import OrderedDict
16
+
17
+ from gremlin_python.structure.io.graphsonV2d0 import (
18
+ GraphSONReader as GraphSONReaderV2,
19
+ GraphSONUtil as GraphSONUtil, # no difference between v2 and v3
20
+ VertexDeserializer as VertexDeserializerV2,
21
+ VertexPropertyDeserializer as VertexPropertyDeserializerV2,
22
+ PropertyDeserializer as PropertyDeserializerV2,
23
+ EdgeDeserializer as EdgeDeserializerV2,
24
+ PathDeserializer as PathDeserializerV2
25
+ )
26
+
27
+ from gremlin_python.structure.io.graphsonV3d0 import (
28
+ GraphSONReader as GraphSONReaderV3,
29
+ VertexDeserializer as VertexDeserializerV3,
30
+ VertexPropertyDeserializer as VertexPropertyDeserializerV3,
31
+ PropertyDeserializer as PropertyDeserializerV3,
32
+ EdgeDeserializer as EdgeDeserializerV3,
33
+ PathDeserializer as PathDeserializerV3
34
+ )
35
+
36
+ try:
37
+ from gremlin_python.structure.io.graphsonV2d0 import (
38
+ TraversalMetricsDeserializer as TraversalMetricsDeserializerV2,
39
+ MetricsDeserializer as MetricsDeserializerV2
40
+ )
41
+ from gremlin_python.structure.io.graphsonV3d0 import (
42
+ TraversalMetricsDeserializer as TraversalMetricsDeserializerV3,
43
+ MetricsDeserializer as MetricsDeserializerV3
44
+ )
45
+ except ImportError:
46
+ TraversalMetricsDeserializerV2 = MetricsDeserializerV2 = None
47
+ TraversalMetricsDeserializerV3 = MetricsDeserializerV3 = None
48
+
49
+ from cassandra.graph import (
50
+ GraphSON2Serializer,
51
+ GraphSON2Deserializer,
52
+ GraphSON3Serializer,
53
+ GraphSON3Deserializer
54
+ )
55
+ from cassandra.graph.graphson import UserTypeIO, TypeWrapperTypeIO
56
+ from cassandra.datastax.graph.fluent.predicates import GeoP, TextDistanceP
57
+ from cassandra.util import Distance
58
+
59
+
60
+ __all__ = ['GremlinGraphSONReader', 'GeoPSerializer', 'TextDistancePSerializer',
61
+ 'DistanceIO', 'gremlin_deserializers', 'deserializers', 'serializers',
62
+ 'GremlinGraphSONReaderV2', 'GremlinGraphSONReaderV3', 'dse_graphson2_serializers',
63
+ 'dse_graphson2_deserializers', 'dse_graphson3_serializers', 'dse_graphson3_deserializers',
64
+ 'gremlin_graphson2_deserializers', 'gremlin_graphson3_deserializers', 'GremlinUserTypeIO']
65
+
66
+
67
+ class _GremlinGraphSONTypeSerializer(object):
68
+ TYPE_KEY = "@type"
69
+ VALUE_KEY = "@value"
70
+ serializer = None
71
+
72
+ def __init__(self, serializer):
73
+ self.serializer = serializer
74
+
75
+ def dictify(self, v, writer):
76
+ value = self.serializer.serialize(v, writer)
77
+ if self.serializer is TypeWrapperTypeIO:
78
+ graphson_base_type = v.type_io.graphson_base_type
79
+ graphson_type = v.type_io.graphson_type
80
+ else:
81
+ graphson_base_type = self.serializer.graphson_base_type
82
+ graphson_type = self.serializer.graphson_type
83
+
84
+ if graphson_base_type is None:
85
+ out = value
86
+ else:
87
+ out = {self.TYPE_KEY: graphson_type}
88
+ if value is not None:
89
+ out[self.VALUE_KEY] = value
90
+
91
+ return out
92
+
93
+ def definition(self, value, writer=None):
94
+ return self.serializer.definition(value, writer)
95
+
96
+ def get_specialized_serializer(self, value):
97
+ ser = self.serializer.get_specialized_serializer(value)
98
+ if ser is not self.serializer:
99
+ return _GremlinGraphSONTypeSerializer(ser)
100
+ return self
101
+
102
+
103
+ class _GremlinGraphSONTypeDeserializer(object):
104
+
105
+ deserializer = None
106
+
107
+ def __init__(self, deserializer):
108
+ self.deserializer = deserializer
109
+
110
+ def objectify(self, v, reader):
111
+ return self.deserializer.deserialize(v, reader)
112
+
113
+
114
+ def _make_gremlin_graphson2_deserializer(graphson_type):
115
+ return _GremlinGraphSONTypeDeserializer(
116
+ GraphSON2Deserializer.get_deserializer(graphson_type.graphson_type)
117
+ )
118
+
119
+
120
+ def _make_gremlin_graphson3_deserializer(graphson_type):
121
+ return _GremlinGraphSONTypeDeserializer(
122
+ GraphSON3Deserializer.get_deserializer(graphson_type.graphson_type)
123
+ )
124
+
125
+
126
+ class _GremlinGraphSONReader(object):
127
+ """Gremlin GraphSONReader Adapter, required to use gremlin types"""
128
+
129
+ context = None
130
+
131
+ def __init__(self, context, deserializer_map=None):
132
+ self.context = context
133
+ super(_GremlinGraphSONReader, self).__init__(deserializer_map)
134
+
135
+ def deserialize(self, obj):
136
+ return self.toObject(obj)
137
+
138
+
139
+ class GremlinGraphSONReaderV2(_GremlinGraphSONReader, GraphSONReaderV2):
140
+ pass
141
+
142
+ # TODO remove next major
143
+ GremlinGraphSONReader = GremlinGraphSONReaderV2
144
+
145
+ class GremlinGraphSONReaderV3(_GremlinGraphSONReader, GraphSONReaderV3):
146
+ pass
147
+
148
+
149
+ class GeoPSerializer(object):
150
+ @classmethod
151
+ def dictify(cls, p, writer):
152
+ out = {
153
+ "predicateType": "Geo",
154
+ "predicate": p.operator,
155
+ "value": [writer.toDict(p.value), writer.toDict(p.other)] if p.other is not None else writer.toDict(p.value)
156
+ }
157
+ return GraphSONUtil.typedValue("P", out, prefix='dse')
158
+
159
+
160
+ class TextDistancePSerializer(object):
161
+ @classmethod
162
+ def dictify(cls, p, writer):
163
+ out = {
164
+ "predicate": p.operator,
165
+ "value": {
166
+ 'query': writer.toDict(p.value),
167
+ 'distance': writer.toDict(p.distance)
168
+ }
169
+ }
170
+ return GraphSONUtil.typedValue("P", out)
171
+
172
+
173
+ class DistanceIO(object):
174
+ @classmethod
175
+ def dictify(cls, v, _):
176
+ return GraphSONUtil.typedValue('Distance', str(v), prefix='dse')
177
+
178
+
179
+ GremlinUserTypeIO = _GremlinGraphSONTypeSerializer(UserTypeIO)
180
+
181
+ # GraphSON2
182
+ dse_graphson2_serializers = OrderedDict([
183
+ (t, _GremlinGraphSONTypeSerializer(s))
184
+ for t, s in GraphSON2Serializer.get_type_definitions().items()
185
+ ])
186
+
187
+ dse_graphson2_serializers.update(OrderedDict([
188
+ (Distance, DistanceIO),
189
+ (GeoP, GeoPSerializer),
190
+ (TextDistanceP, TextDistancePSerializer)
191
+ ]))
192
+
193
+ # TODO remove next major, this is just in case someone was using it
194
+ serializers = dse_graphson2_serializers
195
+
196
+ dse_graphson2_deserializers = {
197
+ k: _make_gremlin_graphson2_deserializer(v)
198
+ for k, v in GraphSON2Deserializer.get_type_definitions().items()
199
+ }
200
+
201
+ dse_graphson2_deserializers.update({
202
+ "dse:Distance": DistanceIO,
203
+ })
204
+
205
+ # TODO remove next major, this is just in case someone was using it
206
+ deserializers = dse_graphson2_deserializers
207
+
208
+ gremlin_graphson2_deserializers = dse_graphson2_deserializers.copy()
209
+ gremlin_graphson2_deserializers.update({
210
+ 'g:Vertex': VertexDeserializerV2,
211
+ 'g:VertexProperty': VertexPropertyDeserializerV2,
212
+ 'g:Edge': EdgeDeserializerV2,
213
+ 'g:Property': PropertyDeserializerV2,
214
+ 'g:Path': PathDeserializerV2
215
+ })
216
+
217
+ if TraversalMetricsDeserializerV2:
218
+ gremlin_graphson2_deserializers.update({
219
+ 'g:TraversalMetrics': TraversalMetricsDeserializerV2,
220
+ 'g:lMetrics': MetricsDeserializerV2
221
+ })
222
+
223
+ # TODO remove next major, this is just in case someone was using it
224
+ gremlin_deserializers = gremlin_graphson2_deserializers
225
+
226
+ # GraphSON3
227
+ dse_graphson3_serializers = OrderedDict([
228
+ (t, _GremlinGraphSONTypeSerializer(s))
229
+ for t, s in GraphSON3Serializer.get_type_definitions().items()
230
+ ])
231
+
232
+ dse_graphson3_serializers.update(OrderedDict([
233
+ (Distance, DistanceIO),
234
+ (GeoP, GeoPSerializer),
235
+ (TextDistanceP, TextDistancePSerializer)
236
+ ]))
237
+
238
+ dse_graphson3_deserializers = {
239
+ k: _make_gremlin_graphson3_deserializer(v)
240
+ for k, v in GraphSON3Deserializer.get_type_definitions().items()
241
+ }
242
+
243
+ dse_graphson3_deserializers.update({
244
+ "dse:Distance": DistanceIO
245
+ })
246
+
247
+ gremlin_graphson3_deserializers = dse_graphson3_deserializers.copy()
248
+ gremlin_graphson3_deserializers.update({
249
+ 'g:Vertex': VertexDeserializerV3,
250
+ 'g:VertexProperty': VertexPropertyDeserializerV3,
251
+ 'g:Edge': EdgeDeserializerV3,
252
+ 'g:Property': PropertyDeserializerV3,
253
+ 'g:Path': PathDeserializerV3
254
+ })
255
+
256
+ if TraversalMetricsDeserializerV3:
257
+ gremlin_graphson3_deserializers.update({
258
+ 'g:TraversalMetrics': TraversalMetricsDeserializerV3,
259
+ 'g:Metrics': MetricsDeserializerV3
260
+ })
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/predicates.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright DataStax, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ try:
16
+ import gremlin_python
17
+ from cassandra.datastax.graph.fluent._predicates import *
18
+ except ImportError:
19
+ # gremlinpython is not installed.
20
+ pass
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/query.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright DataStax, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ try:
16
+ import gremlin_python
17
+ from cassandra.datastax.graph.fluent._query import *
18
+ except ImportError:
19
+ # gremlinpython is not installed.
20
+ pass
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/graph/fluent/serializers.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright DataStax, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ try:
16
+ import gremlin_python
17
+ from cassandra.datastax.graph.fluent._serializers import *
18
+ except ImportError:
19
+ # gremlinpython is not installed.
20
+ pass
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/__init__.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright DataStax, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (206 Bytes). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/__pycache__/registry.cpython-312.pyc ADDED
Binary file (5.61 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/__pycache__/reporter.cpython-312.pyc ADDED
Binary file (12.4 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/__pycache__/serializers.cpython-312.pyc ADDED
Binary file (11.8 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/__pycache__/util.cpython-312.pyc ADDED
Binary file (2.5 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/registry.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright DataStax, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from collections import OrderedDict
16
+ from warnings import warn
17
+
18
+ from cassandra.datastax.insights.util import namespace
19
+
20
+ _NOT_SET = object()
21
+
22
+
23
+ def _default_serializer_for_object(obj, policy):
24
+ # the insights server expects an 'options' dict for policy
25
+ # objects, but not for other objects
26
+ if policy:
27
+ return {'type': obj.__class__.__name__,
28
+ 'namespace': namespace(obj.__class__),
29
+ 'options': {}}
30
+ else:
31
+ return {'type': obj.__class__.__name__,
32
+ 'namespace': namespace(obj.__class__)}
33
+
34
+
35
+ class InsightsSerializerRegistry(object):
36
+
37
+ initialized = False
38
+
39
+ def __init__(self, mapping_dict=None):
40
+ mapping_dict = mapping_dict or {}
41
+ class_order = self._class_topological_sort(mapping_dict)
42
+ self._mapping_dict = OrderedDict(
43
+ ((cls, mapping_dict[cls]) for cls in class_order)
44
+ )
45
+
46
+ def serialize(self, obj, policy=False, default=_NOT_SET, cls=None):
47
+ try:
48
+ return self._get_serializer(cls if cls is not None else obj.__class__)(obj)
49
+ except Exception:
50
+ if default is _NOT_SET:
51
+ result = _default_serializer_for_object(obj, policy)
52
+ else:
53
+ result = default
54
+
55
+ return result
56
+
57
+ def _get_serializer(self, cls):
58
+ try:
59
+ return self._mapping_dict[cls]
60
+ except KeyError:
61
+ for registered_cls, serializer in self._mapping_dict.items():
62
+ if issubclass(cls, registered_cls):
63
+ return self._mapping_dict[registered_cls]
64
+ raise ValueError
65
+
66
+ def register(self, cls, serializer):
67
+ self._mapping_dict[cls] = serializer
68
+ self._mapping_dict = OrderedDict(
69
+ ((cls, self._mapping_dict[cls])
70
+ for cls in self._class_topological_sort(self._mapping_dict))
71
+ )
72
+
73
+ def register_serializer_for(self, cls):
74
+ """
75
+ Parameterized registration helper decorator. Given a class `cls`,
76
+ produces a function that registers the decorated function as a
77
+ serializer for it.
78
+ """
79
+ def decorator(serializer):
80
+ self.register(cls, serializer)
81
+ return serializer
82
+
83
+ return decorator
84
+
85
+ @staticmethod
86
+ def _class_topological_sort(classes):
87
+ """
88
+ A simple topological sort for classes. Takes an iterable of class objects
89
+ and returns a list A of those classes, ordered such that A[X] is never a
90
+ superclass of A[Y] for X < Y.
91
+
92
+ This is an inefficient sort, but that's ok because classes are infrequently
93
+ registered. It's more important that this be maintainable than fast.
94
+
95
+ We can't use `.sort()` or `sorted()` with a custom `key` -- those assume
96
+ a total ordering, which we don't have.
97
+ """
98
+ unsorted, sorted_ = list(classes), []
99
+ while unsorted:
100
+ head, tail = unsorted[0], unsorted[1:]
101
+
102
+ # if head has no subclasses remaining, it can safely go in the list
103
+ if not any(issubclass(x, head) for x in tail):
104
+ sorted_.append(head)
105
+ else:
106
+ # move to the back -- head has to wait until all its subclasses
107
+ # are sorted into the list
108
+ tail.append(head)
109
+
110
+ unsorted = tail
111
+
112
+ # check that sort is valid
113
+ for i, head in enumerate(sorted_):
114
+ for after_head_value in sorted_[(i + 1):]:
115
+ if issubclass(after_head_value, head):
116
+ warn('Sorting classes produced an invalid ordering.\n'
117
+ 'In: {classes}\n'
118
+ 'Out: {sorted_}'.format(classes=classes, sorted_=sorted_))
119
+ return sorted_
120
+
121
+
122
+ insights_registry = InsightsSerializerRegistry()
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/reporter.py ADDED
@@ -0,0 +1,221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright DataStax, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from collections import Counter
16
+ import datetime
17
+ import json
18
+ import logging
19
+ import multiprocessing
20
+ import random
21
+ import platform
22
+ import socket
23
+ import ssl
24
+ import sys
25
+ from threading import Event, Thread
26
+ import time
27
+
28
+ from cassandra.policies import HostDistance
29
+ from cassandra.util import ms_timestamp_from_datetime
30
+ from cassandra.datastax.insights.registry import insights_registry
31
+ from cassandra.datastax.insights.serializers import initialize_registry
32
+
33
+ log = logging.getLogger(__name__)
34
+
35
+
36
+ class MonitorReporter(Thread):
37
+
38
+ def __init__(self, interval_sec, session):
39
+ """
40
+ takes an int indicating interval between requests, a function returning
41
+ the connection to be used, and the timeout per request
42
+ """
43
+ # Thread is an old-style class so we can't super()
44
+ Thread.__init__(self, name='monitor_reporter')
45
+
46
+ initialize_registry(insights_registry)
47
+
48
+ self._interval, self._session = interval_sec, session
49
+
50
+ self._shutdown_event = Event()
51
+ self.daemon = True
52
+ self.start()
53
+
54
+ def run(self):
55
+ self._send_via_rpc(self._get_startup_data())
56
+
57
+ # introduce some jitter -- send up to 1/10 of _interval early
58
+ self._shutdown_event.wait(self._interval * random.uniform(.9, 1))
59
+
60
+ while not self._shutdown_event.is_set():
61
+ start_time = time.time()
62
+
63
+ self._send_via_rpc(self._get_status_data())
64
+
65
+ elapsed = time.time() - start_time
66
+ self._shutdown_event.wait(max(self._interval - elapsed, 0.01))
67
+
68
+ # TODO: redundant with ConnectionHeartbeat.ShutdownException
69
+ class ShutDownException(Exception):
70
+ pass
71
+
72
+ def _send_via_rpc(self, data):
73
+ try:
74
+ self._session.execute(
75
+ "CALL InsightsRpc.reportInsight(%s)", (json.dumps(data),)
76
+ )
77
+ log.debug('Insights RPC data: {}'.format(data))
78
+ except Exception as e:
79
+ log.debug('Insights RPC send failed with {}'.format(e))
80
+ log.debug('Insights RPC data: {}'.format(data))
81
+
82
+ def _get_status_data(self):
83
+ cc = self._session.cluster.control_connection
84
+
85
+ connected_nodes = {
86
+ host.address: {
87
+ 'connections': state['open_count'],
88
+ 'inFlightQueries': state['in_flights']
89
+ }
90
+ for (host, state) in self._session.get_pool_state().items()
91
+ }
92
+
93
+ return {
94
+ 'metadata': {
95
+ # shared across drivers; never change
96
+ 'name': 'driver.status',
97
+ # format version
98
+ 'insightMappingId': 'v1',
99
+ 'insightType': 'EVENT',
100
+ # since epoch
101
+ 'timestamp': ms_timestamp_from_datetime(datetime.datetime.utcnow()),
102
+ 'tags': {
103
+ 'language': 'python'
104
+ }
105
+ },
106
+ # // 'clientId', 'sessionId' and 'controlConnection' are mandatory
107
+ # // the rest of the properties are optional
108
+ 'data': {
109
+ # // 'clientId' must be the same as the one provided in the startup message
110
+ 'clientId': str(self._session.cluster.client_id),
111
+ # // 'sessionId' must be the same as the one provided in the startup message
112
+ 'sessionId': str(self._session.session_id),
113
+ 'controlConnection': cc._connection.host if cc._connection else None,
114
+ 'connectedNodes': connected_nodes
115
+ }
116
+ }
117
+
118
+ def _get_startup_data(self):
119
+ cc = self._session.cluster.control_connection
120
+ try:
121
+ local_ipaddr = cc._connection._socket.getsockname()[0]
122
+ except Exception as e:
123
+ local_ipaddr = None
124
+ log.debug('Unable to get local socket addr from {}: {}'.format(cc._connection, e))
125
+ hostname = socket.getfqdn()
126
+
127
+ host_distances_counter = Counter(
128
+ self._session.cluster.profile_manager.distance(host)
129
+ for host in self._session.hosts
130
+ )
131
+ host_distances_dict = {
132
+ 'local': host_distances_counter[HostDistance.LOCAL],
133
+ 'remote': host_distances_counter[HostDistance.REMOTE],
134
+ 'ignored': host_distances_counter[HostDistance.IGNORED]
135
+ }
136
+
137
+ try:
138
+ compression_type = cc._connection._compression_type
139
+ except AttributeError:
140
+ compression_type = 'NONE'
141
+
142
+ cert_validation = None
143
+ try:
144
+ if self._session.cluster.ssl_context:
145
+ if isinstance(self._session.cluster.ssl_context, ssl.SSLContext):
146
+ cert_validation = self._session.cluster.ssl_context.verify_mode == ssl.CERT_REQUIRED
147
+ else: # pyopenssl
148
+ from OpenSSL import SSL
149
+ cert_validation = self._session.cluster.ssl_context.get_verify_mode() != SSL.VERIFY_NONE
150
+ elif self._session.cluster.ssl_options:
151
+ cert_validation = self._session.cluster.ssl_options.get('cert_reqs') == ssl.CERT_REQUIRED
152
+ except Exception as e:
153
+ log.debug('Unable to get the cert validation: {}'.format(e))
154
+
155
+ uname_info = platform.uname()
156
+
157
+ return {
158
+ 'metadata': {
159
+ 'name': 'driver.startup',
160
+ 'insightMappingId': 'v1',
161
+ 'insightType': 'EVENT',
162
+ 'timestamp': ms_timestamp_from_datetime(datetime.datetime.utcnow()),
163
+ 'tags': {
164
+ 'language': 'python'
165
+ },
166
+ },
167
+ 'data': {
168
+ 'driverName': 'DataStax Python Driver',
169
+ 'driverVersion': sys.modules['cassandra'].__version__,
170
+ 'clientId': str(self._session.cluster.client_id),
171
+ 'sessionId': str(self._session.session_id),
172
+ 'applicationName': self._session.cluster.application_name or 'python',
173
+ 'applicationNameWasGenerated': not self._session.cluster.application_name,
174
+ 'applicationVersion': self._session.cluster.application_version,
175
+ 'contactPoints': self._session.cluster._endpoint_map_for_insights,
176
+ 'dataCenters': list(set(h.datacenter for h in self._session.cluster.metadata.all_hosts()
177
+ if (h.datacenter and
178
+ self._session.cluster.profile_manager.distance(h) == HostDistance.LOCAL))),
179
+ 'initialControlConnection': cc._connection.host if cc._connection else None,
180
+ 'protocolVersion': self._session.cluster.protocol_version,
181
+ 'localAddress': local_ipaddr,
182
+ 'hostName': hostname,
183
+ 'executionProfiles': insights_registry.serialize(self._session.cluster.profile_manager),
184
+ 'configuredConnectionLength': host_distances_dict,
185
+ 'heartbeatInterval': self._session.cluster.idle_heartbeat_interval,
186
+ 'compression': compression_type.upper() if compression_type else 'NONE',
187
+ 'reconnectionPolicy': insights_registry.serialize(self._session.cluster.reconnection_policy),
188
+ 'sslConfigured': {
189
+ 'enabled': bool(self._session.cluster.ssl_options or self._session.cluster.ssl_context),
190
+ 'certValidation': cert_validation
191
+ },
192
+ 'authProvider': {
193
+ 'type': (self._session.cluster.auth_provider.__class__.__name__
194
+ if self._session.cluster.auth_provider else
195
+ None)
196
+ },
197
+ 'otherOptions': {
198
+ },
199
+ 'platformInfo': {
200
+ 'os': {
201
+ 'name': uname_info.system,
202
+ 'version': uname_info.release,
203
+ 'arch': uname_info.machine
204
+ },
205
+ 'cpus': {
206
+ 'length': multiprocessing.cpu_count(),
207
+ 'model': platform.processor()
208
+ },
209
+ 'runtime': {
210
+ 'python': sys.version,
211
+ 'event_loop': self._session.cluster.connection_class.__name__
212
+ }
213
+ },
214
+ 'periodicStatusInterval': self._interval
215
+ }
216
+ }
217
+
218
+ def stop(self):
219
+ log.debug("Shutting down Monitor Reporter")
220
+ self._shutdown_event.set()
221
+ self.join()
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/serializers.py ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright DataStax, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ def initialize_registry(insights_registry):
17
+ # This will be called from the cluster module, so we put all this behavior
18
+ # in a function to avoid circular imports
19
+
20
+ if insights_registry.initialized:
21
+ return False
22
+
23
+ from cassandra import ConsistencyLevel
24
+ from cassandra.cluster import (
25
+ ExecutionProfile, GraphExecutionProfile,
26
+ ProfileManager, ContinuousPagingOptions,
27
+ EXEC_PROFILE_DEFAULT, EXEC_PROFILE_GRAPH_DEFAULT,
28
+ EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT,
29
+ EXEC_PROFILE_GRAPH_SYSTEM_DEFAULT,
30
+ _NOT_SET
31
+ )
32
+ from cassandra.datastax.graph import GraphOptions
33
+ from cassandra.datastax.insights.registry import insights_registry
34
+ from cassandra.datastax.insights.util import namespace
35
+ from cassandra.policies import (
36
+ RoundRobinPolicy,
37
+ DCAwareRoundRobinPolicy,
38
+ TokenAwarePolicy,
39
+ WhiteListRoundRobinPolicy,
40
+ HostFilterPolicy,
41
+ ConstantReconnectionPolicy,
42
+ ExponentialReconnectionPolicy,
43
+ RetryPolicy,
44
+ SpeculativeExecutionPolicy,
45
+ ConstantSpeculativeExecutionPolicy,
46
+ WrapperPolicy
47
+ )
48
+
49
+ import logging
50
+
51
+ log = logging.getLogger(__name__)
52
+
53
+ @insights_registry.register_serializer_for(RoundRobinPolicy)
54
+ def round_robin_policy_insights_serializer(policy):
55
+ return {'type': policy.__class__.__name__,
56
+ 'namespace': namespace(policy.__class__),
57
+ 'options': {}}
58
+
59
+ @insights_registry.register_serializer_for(DCAwareRoundRobinPolicy)
60
+ def dc_aware_round_robin_policy_insights_serializer(policy):
61
+ return {'type': policy.__class__.__name__,
62
+ 'namespace': namespace(policy.__class__),
63
+ 'options': {'local_dc': policy.local_dc,
64
+ 'used_hosts_per_remote_dc': policy.used_hosts_per_remote_dc}
65
+ }
66
+
67
+ @insights_registry.register_serializer_for(TokenAwarePolicy)
68
+ def token_aware_policy_insights_serializer(policy):
69
+ return {'type': policy.__class__.__name__,
70
+ 'namespace': namespace(policy.__class__),
71
+ 'options': {'child_policy': insights_registry.serialize(policy._child_policy,
72
+ policy=True),
73
+ 'shuffle_replicas': policy.shuffle_replicas}
74
+ }
75
+
76
+ @insights_registry.register_serializer_for(WhiteListRoundRobinPolicy)
77
+ def whitelist_round_robin_policy_insights_serializer(policy):
78
+ return {'type': policy.__class__.__name__,
79
+ 'namespace': namespace(policy.__class__),
80
+ 'options': {'allowed_hosts': policy._allowed_hosts}
81
+ }
82
+
83
+ @insights_registry.register_serializer_for(HostFilterPolicy)
84
+ def host_filter_policy_insights_serializer(policy):
85
+ return {
86
+ 'type': policy.__class__.__name__,
87
+ 'namespace': namespace(policy.__class__),
88
+ 'options': {'child_policy': insights_registry.serialize(policy._child_policy,
89
+ policy=True),
90
+ 'predicate': policy.predicate.__name__}
91
+ }
92
+
93
+ @insights_registry.register_serializer_for(ConstantReconnectionPolicy)
94
+ def constant_reconnection_policy_insights_serializer(policy):
95
+ return {'type': policy.__class__.__name__,
96
+ 'namespace': namespace(policy.__class__),
97
+ 'options': {'delay': policy.delay,
98
+ 'max_attempts': policy.max_attempts}
99
+ }
100
+
101
+ @insights_registry.register_serializer_for(ExponentialReconnectionPolicy)
102
+ def exponential_reconnection_policy_insights_serializer(policy):
103
+ return {'type': policy.__class__.__name__,
104
+ 'namespace': namespace(policy.__class__),
105
+ 'options': {'base_delay': policy.base_delay,
106
+ 'max_delay': policy.max_delay,
107
+ 'max_attempts': policy.max_attempts}
108
+ }
109
+
110
+ @insights_registry.register_serializer_for(RetryPolicy)
111
+ def retry_policy_insights_serializer(policy):
112
+ return {'type': policy.__class__.__name__,
113
+ 'namespace': namespace(policy.__class__),
114
+ 'options': {}}
115
+
116
+ @insights_registry.register_serializer_for(SpeculativeExecutionPolicy)
117
+ def speculative_execution_policy_insights_serializer(policy):
118
+ return {'type': policy.__class__.__name__,
119
+ 'namespace': namespace(policy.__class__),
120
+ 'options': {}}
121
+
122
+ @insights_registry.register_serializer_for(ConstantSpeculativeExecutionPolicy)
123
+ def constant_speculative_execution_policy_insights_serializer(policy):
124
+ return {'type': policy.__class__.__name__,
125
+ 'namespace': namespace(policy.__class__),
126
+ 'options': {'delay': policy.delay,
127
+ 'max_attempts': policy.max_attempts}
128
+ }
129
+
130
+ @insights_registry.register_serializer_for(WrapperPolicy)
131
+ def wrapper_policy_insights_serializer(policy):
132
+ return {'type': policy.__class__.__name__,
133
+ 'namespace': namespace(policy.__class__),
134
+ 'options': {
135
+ 'child_policy': insights_registry.serialize(policy._child_policy,
136
+ policy=True)
137
+ }}
138
+
139
+ @insights_registry.register_serializer_for(ExecutionProfile)
140
+ def execution_profile_insights_serializer(profile):
141
+ return {
142
+ 'loadBalancing': insights_registry.serialize(profile.load_balancing_policy,
143
+ policy=True),
144
+ 'retry': insights_registry.serialize(profile.retry_policy,
145
+ policy=True),
146
+ 'readTimeout': profile.request_timeout,
147
+ 'consistency': ConsistencyLevel.value_to_name.get(profile.consistency_level, None),
148
+ 'serialConsistency': ConsistencyLevel.value_to_name.get(profile.serial_consistency_level, None),
149
+ 'continuousPagingOptions': (insights_registry.serialize(profile.continuous_paging_options)
150
+ if (profile.continuous_paging_options is not None and
151
+ profile.continuous_paging_options is not _NOT_SET) else
152
+ None),
153
+ 'speculativeExecution': insights_registry.serialize(profile.speculative_execution_policy),
154
+ 'graphOptions': None
155
+ }
156
+
157
+ @insights_registry.register_serializer_for(GraphExecutionProfile)
158
+ def graph_execution_profile_insights_serializer(profile):
159
+ rv = insights_registry.serialize(profile, cls=ExecutionProfile)
160
+ rv['graphOptions'] = insights_registry.serialize(profile.graph_options)
161
+ return rv
162
+
163
+ _EXEC_PROFILE_DEFAULT_KEYS = (EXEC_PROFILE_DEFAULT,
164
+ EXEC_PROFILE_GRAPH_DEFAULT,
165
+ EXEC_PROFILE_GRAPH_SYSTEM_DEFAULT,
166
+ EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT)
167
+
168
+ @insights_registry.register_serializer_for(ProfileManager)
169
+ def profile_manager_insights_serializer(manager):
170
+ defaults = {
171
+ # Insights's expected default
172
+ 'default': insights_registry.serialize(manager.profiles[EXEC_PROFILE_DEFAULT]),
173
+ # remaining named defaults for driver's defaults, including duplicated default
174
+ 'EXEC_PROFILE_DEFAULT': insights_registry.serialize(manager.profiles[EXEC_PROFILE_DEFAULT]),
175
+ 'EXEC_PROFILE_GRAPH_DEFAULT': insights_registry.serialize(manager.profiles[EXEC_PROFILE_GRAPH_DEFAULT]),
176
+ 'EXEC_PROFILE_GRAPH_SYSTEM_DEFAULT': insights_registry.serialize(
177
+ manager.profiles[EXEC_PROFILE_GRAPH_SYSTEM_DEFAULT]
178
+ ),
179
+ 'EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT': insights_registry.serialize(
180
+ manager.profiles[EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT]
181
+ )
182
+ }
183
+ other = {
184
+ key: insights_registry.serialize(value)
185
+ for key, value in manager.profiles.items()
186
+ if key not in _EXEC_PROFILE_DEFAULT_KEYS
187
+ }
188
+ overlapping_keys = set(defaults) & set(other)
189
+ if overlapping_keys:
190
+ log.debug('The following key names overlap default key sentinel keys '
191
+ 'and these non-default EPs will not be displayed in Insights '
192
+ ': {}'.format(list(overlapping_keys)))
193
+
194
+ other.update(defaults)
195
+ return other
196
+
197
+ @insights_registry.register_serializer_for(GraphOptions)
198
+ def graph_options_insights_serializer(options):
199
+ rv = {
200
+ 'source': options.graph_source,
201
+ 'language': options.graph_language,
202
+ 'graphProtocol': options.graph_protocol
203
+ }
204
+ updates = {k: v.decode('utf-8') for k, v in rv.items()
205
+ if isinstance(v, bytes)}
206
+ rv.update(updates)
207
+ return rv
208
+
209
+ @insights_registry.register_serializer_for(ContinuousPagingOptions)
210
+ def continuous_paging_options_insights_serializer(paging_options):
211
+ return {
212
+ 'page_unit': paging_options.page_unit,
213
+ 'max_pages': paging_options.max_pages,
214
+ 'max_pages_per_second': paging_options.max_pages_per_second,
215
+ 'max_queue_size': paging_options.max_queue_size
216
+ }
217
+
218
+ insights_registry.initialized = True
219
+ return True
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/datastax/insights/util.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright DataStax, Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import logging
16
+ import traceback
17
+ from warnings import warn
18
+
19
+ from cassandra.util import Version
20
+
21
+
22
+ DSE_60 = Version('6.0.0')
23
+ DSE_51_MIN_SUPPORTED = Version('5.1.13')
24
+ DSE_60_MIN_SUPPORTED = Version('6.0.5')
25
+
26
+
27
+ log = logging.getLogger(__name__)
28
+
29
+
30
+ def namespace(cls):
31
+ """
32
+ Best-effort method for getting the namespace in which a class is defined.
33
+ """
34
+ try:
35
+ # __module__ can be None
36
+ module = cls.__module__ or ''
37
+ except Exception:
38
+ warn("Unable to obtain namespace for {cls} for Insights, returning ''. "
39
+ "Exception: \n{e}".format(e=traceback.format_exc(), cls=cls))
40
+ module = ''
41
+
42
+ module_internal_namespace = _module_internal_namespace_or_emtpy_string(cls)
43
+ if module_internal_namespace:
44
+ return '.'.join((module, module_internal_namespace))
45
+ return module
46
+
47
+
48
+ def _module_internal_namespace_or_emtpy_string(cls):
49
+ """
50
+ Best-effort method for getting the module-internal namespace in which a
51
+ class is defined -- i.e. the namespace _inside_ the module.
52
+ """
53
+ try:
54
+ qualname = cls.__qualname__
55
+ except AttributeError:
56
+ return ''
57
+
58
+ return '.'.join(
59
+ # the last segment is the name of the class -- use everything else
60
+ qualname.split('.')[:-1]
61
+ )
62
+
63
+
64
+ def version_supports_insights(dse_version):
65
+ if dse_version:
66
+ try:
67
+ dse_version = Version(dse_version)
68
+ return (DSE_51_MIN_SUPPORTED <= dse_version < DSE_60
69
+ or
70
+ DSE_60_MIN_SUPPORTED <= dse_version)
71
+ except Exception:
72
+ warn("Unable to check version {v} for Insights compatibility, returning False. "
73
+ "Exception: \n{e}".format(e=traceback.format_exc(), v=dse_version))
74
+
75
+ return False
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/io/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (191 Bytes). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/io/__pycache__/asyncioreactor.cpython-312.pyc ADDED
Binary file (11.8 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/io/__pycache__/asyncorereactor.cpython-312.pyc ADDED
Binary file (23.5 kB). View file
 
platform/dataops/dto/.venv/lib/python3.12/site-packages/cassandra/io/__pycache__/eventletreactor.cpython-312.pyc ADDED
Binary file (10.5 kB). View file