ycycse commented on code in PR #9365:
URL: https://github.com/apache/iotdb/pull/9365#discussion_r1141027996
##########
mlnode/iotdb/mlnode/client.py:
##########
@@ -15,12 +15,45 @@
# specific language governing permissions and limitations
# under the License.
#
-from thrift.protocol import TCompactProtocol
+
+
+import time
+
+from thrift.protocol import TBinaryProtocol, TCompactProtocol
from thrift.transport import TSocket, TTransport
+from iotdb.mlnode.config import config
from iotdb.mlnode.log import logger
+from iotdb.thrift.common.ttypes import TEndPoint
+from iotdb.thrift.confignode import IConfigNodeRPCService
+from iotdb.thrift.confignode.ttypes import (TCreateModelReq, TDropModelReq,
+ TShowModelReq, TShowTrailReq,
+ TUpdateModelInfoReq)
+from iotdb.thrift.datanode import IDataNodeRPCService
+from iotdb.thrift.datanode.ttypes import (TDeleteModelMetricsReq,
+ TFetchTimeseriesReq,
+ TFetchWindowBatchReq,
+ TGroupByTimeParameter,
+ TRecordModelMetricsReq)
from iotdb.thrift.mlnode import IMLNodeRPCService
-from iotdb.thrift.mlnode.ttypes import TDeleteModelReq
+from iotdb.thrift.mlnode.ttypes import (TCreateTrainingTaskReq,
+ TDeleteModelReq, TForecastReq)
+
+
+class ClientManager(object):
+ def __init__(self,
+ config_node_address: TEndPoint,
+ data_node_address: TEndPoint):
+ self.data_node_address = data_node_address
+ self.config_node_address = config_node_address
+
+ def borrow_data_node_client(self):
+ return DataNodeClient(host=self.data_node_address.ip,
+ port=self.data_node_address.port)
+
+ def borrow_config_node_client(self):
+ return DataNodeClient(host=self.config_node_address.ip,
+ port=self.config_node_address.port)
Review Comment:
Why `DataNodeClient`?
##########
mlnode/iotdb/mlnode/client.py:
##########
@@ -40,12 +73,117 @@ def __init__(self, host, port):
protocol = TCompactProtocol.TCompactProtocol(transport)
self.__client = IMLNodeRPCService.Client(protocol)
- def delete_model(self, model_path: str):
- req = TDeleteModelReq(model_path)
- return self.__client.deleteModel(req)
+ def create_training_task(self,
+ model_id: str = 'test',
+ is_auto: bool = False,
+ model_configs: dict = {},
+ query_expressions: list = [],
+ query_filter: str = ''):
+ req = TCreateTrainingTaskReq(
+ modelId=model_id,
+ isAuto=is_auto,
+ modelConfigs={k: str(v) for k, v in model_configs.items()},
+ queryExpressions=[str(query) for query in query_expressions],
+ queryFilter=query_filter,
+ )
+ return self.__client.createTrainingTask(req)
+
+ def create_forecast_task(self):
+ req = TForecastReq()
+ return self.__client.forecast(req)
+
+ def delete_model(self,
+ model_id: str = '',
+ trial_id: str = ''):
+ req = TDeleteModelReq(modelId=model_id, trialId=trial_id)
+ res = self.__client.deleteModel(req)
+ return res
+
+
+class DataNodeClient(object):
+ def __init__(self, host, port):
+ self.__host = host
+ self.__port = port
+
+ transport = TTransport.TFramedTransport(
+ TSocket.TSocket(self.__host, self.__port)
+ )
+ if not transport.isOpen():
+ try:
+ transport.open()
+ except TTransport.TTransportException as e:
+ logger.exception("TTransportException!", exc_info=e)
Review Comment:
What will happen if `transport.open()` causes exception? Should we raise the
exception?
##########
mlnode/test/test_client.py:
##########
@@ -0,0 +1,25 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+from iotdb.mlnode.client import client_manager
+
+
+def test_client_manager():
+ assert client_manager.borrow_data_node_client()
+ assert client_manager.borrow_config_node_client()
Review Comment:
How will the test codes work if there isn' a working IoTDB? Maybe try
IoTDBContainer.
##########
mlnode/iotdb/mlnode/model_storage.py:
##########
Review Comment:
These codes already in the pr of storage should be removed or merge the
master after https://github.com/apache/iotdb/pull/9337 is committed because
they are duplicate.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]