MindsDB 25.8.3.0__py3-none-any.whl → 25.9.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of MindsDB might be problematic. Click here for more details.
- mindsdb/__about__.py +1 -1
- mindsdb/__main__.py +3 -45
- mindsdb/api/a2a/__init__.py +52 -0
- mindsdb/api/a2a/agent.py +11 -12
- mindsdb/api/a2a/common/server/server.py +17 -36
- mindsdb/api/a2a/common/server/task_manager.py +14 -28
- mindsdb/api/a2a/task_manager.py +20 -21
- mindsdb/api/a2a/utils.py +1 -1
- mindsdb/api/common/middleware.py +106 -0
- mindsdb/api/executor/utilities/mysql_to_duckdb_functions.py +466 -18
- mindsdb/api/executor/utilities/sql.py +9 -31
- mindsdb/api/http/initialize.py +34 -43
- mindsdb/api/http/namespaces/auth.py +6 -14
- mindsdb/api/http/namespaces/config.py +0 -2
- mindsdb/api/http/namespaces/default.py +74 -106
- mindsdb/api/http/namespaces/file.py +9 -3
- mindsdb/api/http/namespaces/handlers.py +77 -87
- mindsdb/api/http/start.py +29 -47
- mindsdb/api/litellm/start.py +11 -10
- mindsdb/api/mcp/__init__.py +165 -0
- mindsdb/api/mysql/mysql_proxy/mysql_proxy.py +33 -64
- mindsdb/api/postgres/postgres_proxy/postgres_proxy.py +86 -85
- mindsdb/integrations/handlers/autogluon_handler/requirements.txt +1 -1
- mindsdb/integrations/handlers/autosklearn_handler/requirements.txt +1 -1
- mindsdb/integrations/handlers/crate_handler/crate_handler.py +3 -7
- mindsdb/integrations/handlers/derby_handler/derby_handler.py +32 -34
- mindsdb/integrations/handlers/documentdb_handler/requirements.txt +1 -0
- mindsdb/integrations/handlers/dummy_data_handler/dummy_data_handler.py +12 -13
- mindsdb/integrations/handlers/flaml_handler/requirements.txt +1 -1
- mindsdb/integrations/handlers/google_books_handler/google_books_handler.py +45 -44
- mindsdb/integrations/handlers/google_calendar_handler/google_calendar_handler.py +101 -95
- mindsdb/integrations/handlers/google_content_shopping_handler/google_content_shopping_handler.py +129 -129
- mindsdb/integrations/handlers/google_fit_handler/google_fit_handler.py +59 -43
- mindsdb/integrations/handlers/google_search_handler/google_search_handler.py +38 -39
- mindsdb/integrations/handlers/informix_handler/informix_handler.py +5 -18
- mindsdb/integrations/handlers/lightfm_handler/requirements.txt +1 -1
- mindsdb/integrations/handlers/lightwood_handler/requirements.txt +4 -4
- mindsdb/integrations/handlers/maxdb_handler/maxdb_handler.py +22 -28
- mindsdb/integrations/handlers/monetdb_handler/monetdb_handler.py +3 -7
- mindsdb/integrations/handlers/mongodb_handler/mongodb_handler.py +53 -67
- mindsdb/integrations/handlers/mongodb_handler/requirements.txt +1 -0
- mindsdb/{api/mongo/utilities → integrations/handlers/mongodb_handler/utils}/mongodb_ast.py +43 -68
- mindsdb/{api/mongo/utilities → integrations/handlers/mongodb_handler/utils}/mongodb_parser.py +17 -25
- mindsdb/{api/mongo/utilities → integrations/handlers/mongodb_handler/utils}/mongodb_query.py +10 -16
- mindsdb/integrations/handlers/mongodb_handler/utils/mongodb_render.py +43 -69
- mindsdb/integrations/handlers/tpot_handler/requirements.txt +1 -1
- mindsdb/integrations/libs/base.py +1 -1
- mindsdb/integrations/libs/llm/config.py +15 -0
- mindsdb/integrations/libs/llm/utils.py +15 -0
- mindsdb/interfaces/agents/constants.py +1 -0
- mindsdb/interfaces/agents/langchain_agent.py +4 -0
- mindsdb/interfaces/agents/providers.py +20 -0
- mindsdb/interfaces/knowledge_base/controller.py +25 -7
- mindsdb/utilities/config.py +15 -158
- mindsdb/utilities/log.py +0 -25
- mindsdb/utilities/render/sqlalchemy_render.py +7 -1
- mindsdb/utilities/starters.py +0 -39
- {mindsdb-25.8.3.0.dist-info → mindsdb-25.9.1.1.dist-info}/METADATA +269 -267
- {mindsdb-25.8.3.0.dist-info → mindsdb-25.9.1.1.dist-info}/RECORD +62 -105
- mindsdb/api/a2a/__main__.py +0 -144
- mindsdb/api/a2a/run_a2a.py +0 -86
- mindsdb/api/common/check_auth.py +0 -42
- mindsdb/api/http/gunicorn_wrapper.py +0 -17
- mindsdb/api/mcp/start.py +0 -205
- mindsdb/api/mongo/__init__.py +0 -0
- mindsdb/api/mongo/classes/__init__.py +0 -5
- mindsdb/api/mongo/classes/query_sql.py +0 -19
- mindsdb/api/mongo/classes/responder.py +0 -45
- mindsdb/api/mongo/classes/responder_collection.py +0 -34
- mindsdb/api/mongo/classes/scram.py +0 -86
- mindsdb/api/mongo/classes/session.py +0 -23
- mindsdb/api/mongo/functions/__init__.py +0 -19
- mindsdb/api/mongo/responders/__init__.py +0 -73
- mindsdb/api/mongo/responders/add_shard.py +0 -13
- mindsdb/api/mongo/responders/aggregate.py +0 -90
- mindsdb/api/mongo/responders/buildinfo.py +0 -17
- mindsdb/api/mongo/responders/coll_stats.py +0 -63
- mindsdb/api/mongo/responders/company_id.py +0 -25
- mindsdb/api/mongo/responders/connection_status.py +0 -22
- mindsdb/api/mongo/responders/count.py +0 -21
- mindsdb/api/mongo/responders/db_stats.py +0 -32
- mindsdb/api/mongo/responders/delete.py +0 -105
- mindsdb/api/mongo/responders/describe.py +0 -23
- mindsdb/api/mongo/responders/end_sessions.py +0 -13
- mindsdb/api/mongo/responders/find.py +0 -175
- mindsdb/api/mongo/responders/get_cmd_line_opts.py +0 -18
- mindsdb/api/mongo/responders/get_free_monitoring_status.py +0 -14
- mindsdb/api/mongo/responders/get_parameter.py +0 -23
- mindsdb/api/mongo/responders/getlog.py +0 -14
- mindsdb/api/mongo/responders/host_info.py +0 -28
- mindsdb/api/mongo/responders/insert.py +0 -270
- mindsdb/api/mongo/responders/is_master.py +0 -20
- mindsdb/api/mongo/responders/is_master_lower.py +0 -13
- mindsdb/api/mongo/responders/list_collections.py +0 -55
- mindsdb/api/mongo/responders/list_databases.py +0 -37
- mindsdb/api/mongo/responders/list_indexes.py +0 -22
- mindsdb/api/mongo/responders/ping.py +0 -13
- mindsdb/api/mongo/responders/recv_chunk_start.py +0 -13
- mindsdb/api/mongo/responders/replsetgetstatus.py +0 -13
- mindsdb/api/mongo/responders/sasl_continue.py +0 -34
- mindsdb/api/mongo/responders/sasl_start.py +0 -33
- mindsdb/api/mongo/responders/update_range_deletions.py +0 -12
- mindsdb/api/mongo/responders/whatsmyuri.py +0 -18
- mindsdb/api/mongo/server.py +0 -388
- mindsdb/api/mongo/start.py +0 -15
- mindsdb/api/mongo/utilities/__init__.py +0 -0
- {mindsdb-25.8.3.0.dist-info → mindsdb-25.9.1.1.dist-info}/WHEEL +0 -0
- {mindsdb-25.8.3.0.dist-info → mindsdb-25.9.1.1.dist-info}/licenses/LICENSE +0 -0
- {mindsdb-25.8.3.0.dist-info → mindsdb-25.9.1.1.dist-info}/top_level.txt +0 -0
mindsdb/api/mongo/server.py
DELETED
|
@@ -1,388 +0,0 @@
|
|
|
1
|
-
import socketserver as SocketServer
|
|
2
|
-
import socket
|
|
3
|
-
import struct
|
|
4
|
-
import bson
|
|
5
|
-
import traceback
|
|
6
|
-
from bson import codec_options
|
|
7
|
-
from collections import OrderedDict
|
|
8
|
-
from abc import abstractmethod
|
|
9
|
-
from bson.codec_options import CodecOptions
|
|
10
|
-
from bson.codec_options import TypeCodec
|
|
11
|
-
from bson.codec_options import TypeRegistry
|
|
12
|
-
import numpy as np
|
|
13
|
-
import datetime as dt
|
|
14
|
-
|
|
15
|
-
import mindsdb.api.mongo.functions as helpers
|
|
16
|
-
from mindsdb.api.mongo.classes import RespondersCollection, Session
|
|
17
|
-
from mindsdb.interfaces.storage import db
|
|
18
|
-
from mindsdb.interfaces.model.model_controller import ModelController
|
|
19
|
-
from mindsdb.interfaces.database.integrations import integration_controller
|
|
20
|
-
from mindsdb.interfaces.database.projects import ProjectController
|
|
21
|
-
from mindsdb.interfaces.database.database import DatabaseController
|
|
22
|
-
from mindsdb.utilities.context import context as ctx
|
|
23
|
-
from mindsdb.utilities import log
|
|
24
|
-
|
|
25
|
-
OP_REPLY = 1
|
|
26
|
-
OP_UPDATE = 2001
|
|
27
|
-
OP_INSERT = 2002
|
|
28
|
-
OP_QUERY = 2004
|
|
29
|
-
OP_GET_MORE = 2005
|
|
30
|
-
OP_DELETE = 2006
|
|
31
|
-
OP_KILL_CURSORS = 2007
|
|
32
|
-
OP_MSG = 2013
|
|
33
|
-
|
|
34
|
-
BYTE = '<b'
|
|
35
|
-
INT = '<i'
|
|
36
|
-
UINT = '<I'
|
|
37
|
-
LONG = '<q'
|
|
38
|
-
|
|
39
|
-
logger = log.getLogger(__name__)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
class NPIntCodec(TypeCodec):
|
|
43
|
-
python_type = np.int64
|
|
44
|
-
bson_type = bson.int64.Int64
|
|
45
|
-
|
|
46
|
-
def transform_python(self, value):
|
|
47
|
-
return bson.int64.Int64(value)
|
|
48
|
-
|
|
49
|
-
def transform_bson(self, value):
|
|
50
|
-
return np.int(value)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
class DateCodec(TypeCodec):
|
|
54
|
-
python_type = dt.date
|
|
55
|
-
bson_type = bson.datetime.datetime
|
|
56
|
-
|
|
57
|
-
def transform_python(self, value):
|
|
58
|
-
return dt.datetime(value.year, value.month, value.day)
|
|
59
|
-
|
|
60
|
-
def transform_bson(self, value):
|
|
61
|
-
return dt.datetime(value.year, value.month, value.day)
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def fallback_encoder(value):
|
|
65
|
-
return str(value)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
type_registry = TypeRegistry([NPIntCodec(), DateCodec()], fallback_encoder=fallback_encoder)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def unpack(format, buffer, start=0):
|
|
72
|
-
end = start + struct.calcsize(format)
|
|
73
|
-
return struct.unpack(format, buffer[start:end])[0], end
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def get_utf8_string(buffer, start=0):
|
|
77
|
-
end = buffer.index(b"\x00", start)
|
|
78
|
-
s = buffer[start:end].decode('utf8')
|
|
79
|
-
return s, end + 1
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
CODEC_OPTIONS = codec_options.CodecOptions(document_class=OrderedDict)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def decode_documents(buffer, start, content_size):
|
|
86
|
-
docs = bson.decode_all(buffer[start:start + content_size], CODEC_OPTIONS)
|
|
87
|
-
return docs, start + content_size
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
class OperationResponder():
|
|
91
|
-
def __init__(self, responders):
|
|
92
|
-
self.responders = responders
|
|
93
|
-
|
|
94
|
-
@abstractmethod
|
|
95
|
-
def handle(self, query_bytes):
|
|
96
|
-
pass
|
|
97
|
-
|
|
98
|
-
@abstractmethod
|
|
99
|
-
def to_bytes(self, response, request_id):
|
|
100
|
-
pass
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
# NOTE probably, it need only for mongo version < 3.6
|
|
104
|
-
class OpInsertResponder(OperationResponder):
|
|
105
|
-
def handle(self, buffer, request_id, mindsdb_env, session):
|
|
106
|
-
flags, pos = unpack(UINT, buffer)
|
|
107
|
-
namespace, pos = get_utf8_string(buffer, pos)
|
|
108
|
-
query = bson.decode_all(buffer[pos:], CODEC_OPTIONS)
|
|
109
|
-
responder = self.responders.find_match(query)
|
|
110
|
-
assert responder is not None, 'query cant be processed'
|
|
111
|
-
|
|
112
|
-
request_args = {
|
|
113
|
-
'request_id': request_id
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
documents = responder.handle(query, request_args, mindsdb_env, session)
|
|
117
|
-
|
|
118
|
-
return documents
|
|
119
|
-
|
|
120
|
-
def to_bytes(self, response, request_id):
|
|
121
|
-
pass
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
OP_MSG_FLAGS = {
|
|
125
|
-
'checksumPresent': 0,
|
|
126
|
-
'moreToCome': 1,
|
|
127
|
-
'exhaustAllowed': 16
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
# NOTE used in mongo version > 3.6
|
|
132
|
-
class OpMsgResponder(OperationResponder):
|
|
133
|
-
def handle(self, buffer, request_id, mindsdb_env, session):
|
|
134
|
-
query = OrderedDict()
|
|
135
|
-
flags, pos = unpack(UINT, buffer)
|
|
136
|
-
|
|
137
|
-
checksum_present = bool(flags & (1 << OP_MSG_FLAGS['checksumPresent']))
|
|
138
|
-
if checksum_present:
|
|
139
|
-
msg_len = len(buffer) - 4
|
|
140
|
-
else:
|
|
141
|
-
msg_len = len(buffer)
|
|
142
|
-
|
|
143
|
-
# sections
|
|
144
|
-
while pos < msg_len:
|
|
145
|
-
kind, pos = unpack(BYTE, buffer, pos)
|
|
146
|
-
if kind == 0:
|
|
147
|
-
# body
|
|
148
|
-
section_size, _ = unpack(INT, buffer, pos)
|
|
149
|
-
docs, pos = decode_documents(buffer, pos, section_size)
|
|
150
|
-
query.update(docs[0])
|
|
151
|
-
elif kind == 1:
|
|
152
|
-
# Document
|
|
153
|
-
section_size, pos = unpack(INT, buffer, pos)
|
|
154
|
-
seq_id, pos = get_utf8_string(buffer, pos)
|
|
155
|
-
docs_len = section_size - struct.calcsize(INT) - len(seq_id) - 1
|
|
156
|
-
docs, pos = decode_documents(buffer, pos, docs_len)
|
|
157
|
-
query[seq_id] = docs
|
|
158
|
-
|
|
159
|
-
remaining = len(buffer) - pos
|
|
160
|
-
if checksum_present:
|
|
161
|
-
if remaining != 4:
|
|
162
|
-
raise Exception('should be checksum at the end of message')
|
|
163
|
-
# TODO read and check checksum
|
|
164
|
-
elif remaining != 0:
|
|
165
|
-
raise Exception('is bytes left after msg parsing')
|
|
166
|
-
|
|
167
|
-
logger.debug(f'GET OpMSG={query}')
|
|
168
|
-
|
|
169
|
-
responder = self.responders.find_match(query)
|
|
170
|
-
assert responder is not None, 'query cant be processed'
|
|
171
|
-
|
|
172
|
-
request_args = {
|
|
173
|
-
'request_id': request_id,
|
|
174
|
-
'database': query['$db']
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
documents = responder.handle(query, request_args, mindsdb_env, session)
|
|
178
|
-
|
|
179
|
-
return documents
|
|
180
|
-
|
|
181
|
-
def to_bytes(self, response, request_id, is_error=False):
|
|
182
|
-
if is_error:
|
|
183
|
-
flags = struct.pack("<I", 2)
|
|
184
|
-
else:
|
|
185
|
-
flags = struct.pack("<I", 0) # TODO
|
|
186
|
-
payload_type = struct.pack("<b", 0) # TODO
|
|
187
|
-
|
|
188
|
-
codec_options = CodecOptions(type_registry=type_registry)
|
|
189
|
-
payload_data = bson.BSON.encode(response, codec_options=codec_options)
|
|
190
|
-
data = b''.join([flags, payload_type, payload_data])
|
|
191
|
-
|
|
192
|
-
reply_id = 0 # TODO add seq here
|
|
193
|
-
response_to = request_id
|
|
194
|
-
|
|
195
|
-
header = struct.pack("<iiii", 16 + len(data), reply_id, response_to, OP_MSG)
|
|
196
|
-
return header + data
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
# NOTE used in any mongo shell version
|
|
200
|
-
class OpQueryResponder(OperationResponder):
|
|
201
|
-
def handle(self, buffer, request_id, mindsdb_env, session):
|
|
202
|
-
# https://docs.mongodb.com/manual/reference/mongodb-wire-protocol/#wire-op-query
|
|
203
|
-
flags, pos = unpack(UINT, buffer)
|
|
204
|
-
namespace, pos = get_utf8_string(buffer, pos)
|
|
205
|
-
is_command = namespace.endswith('.$cmd')
|
|
206
|
-
num_to_skip, pos = unpack(INT, buffer, pos)
|
|
207
|
-
num_to_return, pos = unpack(INT, buffer, pos)
|
|
208
|
-
docs = bson.decode_all(buffer[pos:], CODEC_OPTIONS)
|
|
209
|
-
|
|
210
|
-
query = docs[0] # docs = [query, returnFieldsSelector]
|
|
211
|
-
|
|
212
|
-
logger.debug(f'GET OpQuery={query}')
|
|
213
|
-
|
|
214
|
-
responder = self.responders.find_match(query)
|
|
215
|
-
assert responder is not None, 'query cant be processed'
|
|
216
|
-
|
|
217
|
-
request_args = {
|
|
218
|
-
'num_to_skip': num_to_skip,
|
|
219
|
-
'num_to_return': num_to_return,
|
|
220
|
-
'request_id': request_id,
|
|
221
|
-
'is_command': is_command
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
documents = responder.handle(query, request_args, mindsdb_env, session)
|
|
225
|
-
|
|
226
|
-
return documents
|
|
227
|
-
|
|
228
|
-
def to_bytes(self, request, request_id):
|
|
229
|
-
flags = struct.pack("<i", 0) # TODO
|
|
230
|
-
cursor_id = struct.pack("<q", 0) # TODO
|
|
231
|
-
starting_from = struct.pack("<i", 0) # TODO
|
|
232
|
-
number_returned = struct.pack("<i", len([request]))
|
|
233
|
-
reply_id = 123 # TODO
|
|
234
|
-
response_to = request_id
|
|
235
|
-
|
|
236
|
-
logger.debug(f'RET docs={request}')
|
|
237
|
-
|
|
238
|
-
data = b''.join([flags, cursor_id, starting_from, number_returned])
|
|
239
|
-
data += b''.join([bson.BSON.encode(doc) for doc in [request]])
|
|
240
|
-
|
|
241
|
-
message = struct.pack("<i", 16 + len(data))
|
|
242
|
-
message += struct.pack("<i", reply_id)
|
|
243
|
-
message += struct.pack("<i", response_to)
|
|
244
|
-
message += struct.pack("<i", OP_REPLY)
|
|
245
|
-
|
|
246
|
-
return message + data
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
class MongoRequestHandler(SocketServer.BaseRequestHandler):
|
|
250
|
-
_stopped = False
|
|
251
|
-
|
|
252
|
-
def _init_ssl(self):
|
|
253
|
-
import ssl
|
|
254
|
-
|
|
255
|
-
ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
|
|
256
|
-
|
|
257
|
-
ssl_socket = ssl_context.wrap_socket(
|
|
258
|
-
self.request,
|
|
259
|
-
server_side=True,
|
|
260
|
-
do_handshake_on_connect=True
|
|
261
|
-
)
|
|
262
|
-
self.request = ssl_socket
|
|
263
|
-
|
|
264
|
-
def handle(self):
|
|
265
|
-
ctx.set_default()
|
|
266
|
-
logger.debug('connect')
|
|
267
|
-
logger.debug(str(self.server.socket))
|
|
268
|
-
|
|
269
|
-
self.session = Session(self.server.mindsdb_env)
|
|
270
|
-
|
|
271
|
-
first_byte = self.request.recv(1, socket.MSG_PEEK)
|
|
272
|
-
if first_byte == b'\x16':
|
|
273
|
-
# TLS 'client hello' starts from \x16
|
|
274
|
-
self._init_ssl()
|
|
275
|
-
|
|
276
|
-
while True:
|
|
277
|
-
header = self._read_bytes(16)
|
|
278
|
-
if header is False:
|
|
279
|
-
# connection closed by client
|
|
280
|
-
break
|
|
281
|
-
length, pos = unpack(INT, header)
|
|
282
|
-
request_id, pos = unpack(INT, header, pos)
|
|
283
|
-
response_to, pos = unpack(INT, header, pos)
|
|
284
|
-
opcode, pos = unpack(INT, header, pos)
|
|
285
|
-
logger.debug(f'GET length={length} id={request_id} opcode={opcode}')
|
|
286
|
-
msg_bytes = self._read_bytes(length - pos)
|
|
287
|
-
answer = self.get_answer(request_id, opcode, msg_bytes)
|
|
288
|
-
if answer is not None:
|
|
289
|
-
self.request.send(answer)
|
|
290
|
-
|
|
291
|
-
db.session.close()
|
|
292
|
-
|
|
293
|
-
def get_answer(self, request_id, opcode, msg_bytes):
|
|
294
|
-
if opcode not in self.server.operationsHandlersMap:
|
|
295
|
-
raise NotImplementedError(f'Unknown opcode {opcode}')
|
|
296
|
-
responder = self.server.operationsHandlersMap[opcode]
|
|
297
|
-
assert responder is not None, 'error'
|
|
298
|
-
try:
|
|
299
|
-
response = responder.handle(msg_bytes, request_id, self.session.mindsdb_env, self.session)
|
|
300
|
-
if response is None:
|
|
301
|
-
return None
|
|
302
|
-
except Exception as e:
|
|
303
|
-
logger.error(e)
|
|
304
|
-
response = {
|
|
305
|
-
"ok": 0,
|
|
306
|
-
"errmsg": f'{str(e)} : {traceback.format_exc()}',
|
|
307
|
-
"code": 2,
|
|
308
|
-
"codeName": "BadValue"
|
|
309
|
-
}
|
|
310
|
-
return responder.to_bytes(response, request_id, is_error=True)
|
|
311
|
-
|
|
312
|
-
return responder.to_bytes(response, request_id)
|
|
313
|
-
|
|
314
|
-
def _read_bytes(self, length):
|
|
315
|
-
buffer = b''
|
|
316
|
-
while length:
|
|
317
|
-
chunk = self.request.recv(length)
|
|
318
|
-
if chunk == b'':
|
|
319
|
-
logger.debug('Connection closed')
|
|
320
|
-
return False
|
|
321
|
-
|
|
322
|
-
length -= len(chunk)
|
|
323
|
-
buffer += chunk
|
|
324
|
-
return buffer
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
class MongoServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
|
|
328
|
-
def __init__(self, config):
|
|
329
|
-
mongodb_config = config['api'].get('mongodb')
|
|
330
|
-
assert mongodb_config is not None, 'is no mongodb config!'
|
|
331
|
-
host = mongodb_config['host']
|
|
332
|
-
port = mongodb_config['port']
|
|
333
|
-
logger.debug(f'start mongo server on {host}:{port}')
|
|
334
|
-
|
|
335
|
-
super().__init__((host, int(port)), MongoRequestHandler)
|
|
336
|
-
|
|
337
|
-
self.mindsdb_env = {
|
|
338
|
-
'config': config,
|
|
339
|
-
'model_controller': ModelController(),
|
|
340
|
-
'integration_controller': integration_controller,
|
|
341
|
-
'project_controller': ProjectController(),
|
|
342
|
-
'database_controller': DatabaseController()
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
respondersCollection = RespondersCollection()
|
|
346
|
-
|
|
347
|
-
opQueryResponder = OpQueryResponder(respondersCollection)
|
|
348
|
-
opMsgResponder = OpMsgResponder(respondersCollection)
|
|
349
|
-
opInsertResponder = OpInsertResponder(respondersCollection)
|
|
350
|
-
|
|
351
|
-
self.operationsHandlersMap = {
|
|
352
|
-
OP_QUERY: opQueryResponder,
|
|
353
|
-
OP_MSG: opMsgResponder,
|
|
354
|
-
OP_INSERT: opInsertResponder
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
respondersCollection.add(
|
|
358
|
-
when={'drop': 'system.sessions'},
|
|
359
|
-
result={'ok': 1}
|
|
360
|
-
)
|
|
361
|
-
respondersCollection.add(
|
|
362
|
-
when={'update': 'system.version'},
|
|
363
|
-
result={'ok': 1}
|
|
364
|
-
)
|
|
365
|
-
respondersCollection.add(
|
|
366
|
-
when={'setFeatureCompatibilityVersion': helpers.is_true},
|
|
367
|
-
result={'ok': 1}
|
|
368
|
-
)
|
|
369
|
-
# OpMSG=OrderedDict([('features', 1), ('$clusterTime', OrderedDict([('clusterTime', Timestamp(1599748325, 1)), ('signature', OrderedDict([('hash', b'\xb8\xc3\x03\x18\xca\xe6bh\xf0\xcb47,\x924\x8a >\xfc\x91'), ('keyId', 6870854312365391875)]))])), ('$configServerState', OrderedDict([('opTime', OrderedDict([('ts', Timestamp(1599748325, 1)), ('t', 1)]))])), ('$db', 'admin')])
|
|
370
|
-
respondersCollection.add(
|
|
371
|
-
when={'features': helpers.is_true},
|
|
372
|
-
result={'ok': 1}
|
|
373
|
-
)
|
|
374
|
-
# OpMSG=OrderedDict([('serverStatus', 1), ('$clusterTime', OrderedDict([('clusterTime', Timestamp(1599748366, 1)), ('signature', OrderedDict([('hash', b'\xa1E}\xbbIU\xc2D\x95++\x82\x88\xb5\x84\xf5\xda)+B'), ('keyId', 6870854312365391875)]))])), ('$configServerState', OrderedDict([('opTime', OrderedDict([('ts', Timestamp(1599748366, 1)), ('t', 1)]))])), ('$db', 'admin')])
|
|
375
|
-
respondersCollection.add(
|
|
376
|
-
when={'serverStatus': helpers.is_true},
|
|
377
|
-
result={'ok': 1}
|
|
378
|
-
)
|
|
379
|
-
# OpMSG=OrderedDict([('ismaster', 1), ('$db', 'admin'), ('$clusterTime', OrderedDict([('clusterTime', Timestamp(1599749031, 1)), ('signature', OrderedDict([('hash', b'6\x87\xd5Y\xa7\xc7\xcf$\xab\x1e\xa2{\xe5B\xe5\x99\xdbl\x8d\xf4'), ('keyId', 6870854312365391875)]))])), ('$client', OrderedDict([('application', OrderedDict([('name', 'MongoDB Shell')])), ('driver', OrderedDict([('name', 'MongoDB Internal Client'), ('version', '3.6.3')])), ('os', OrderedDict([('type', 'Linux'), ('name', 'Ubuntu'), ('architecture', 'x86_64'), ('version', '18.04')])), ('mongos', OrderedDict([('host', 'maxs-comp:27103'), ('client', '127.0.0.1:52148'), ('version', '3.6.3')]))])), ('$configServerState', OrderedDict([('opTime', OrderedDict([('ts', Timestamp(1599749031, 1)), ('t', 1)]))]))])
|
|
380
|
-
|
|
381
|
-
from mindsdb.api.mongo.responders import responders
|
|
382
|
-
respondersCollection.responders += responders
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
def run_server(config):
|
|
386
|
-
SocketServer.TCPServer.allow_reuse_address = True
|
|
387
|
-
with MongoServer(config) as srv:
|
|
388
|
-
srv.serve_forever()
|
mindsdb/api/mongo/start.py
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
from mindsdb.api.mongo.server import run_server
|
|
2
|
-
from mindsdb.interfaces.storage import db
|
|
3
|
-
from mindsdb.utilities import log
|
|
4
|
-
from mindsdb.utilities.config import Config
|
|
5
|
-
from mindsdb.utilities.functions import init_lexer_parsers
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def start(verbose=False):
|
|
9
|
-
logger = log.getLogger(__name__)
|
|
10
|
-
logger.info("Mongo API is starting..")
|
|
11
|
-
config = Config()
|
|
12
|
-
db.init()
|
|
13
|
-
init_lexer_parsers()
|
|
14
|
-
|
|
15
|
-
run_server(config)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|