Skip to content

Commit a014839

Browse files
committed
Fix copilot suggestions
1 parent 7d3b852 commit a014839

File tree

5 files changed

+28
-64
lines changed

5 files changed

+28
-64
lines changed

integration-test/src/test/java/org/apache/iotdb/ainode/it/AINodeModelManageIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ private void userDefinedModelManagementTest(Statement statement)
131131
public void dropBuiltInModelErrorTestInTree() throws SQLException {
132132
try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TREE_SQL_DIALECT);
133133
Statement statement = connection.createStatement()) {
134-
errorTest(statement, "drop model sundial", "1510: Cannot delete built-in model: sundial");
134+
errorTest(statement, "drop model sundial", "1506: Cannot delete built-in model: sundial");
135135
}
136136
}
137137

138138
@Test
139139
public void dropBuiltInModelErrorTestInTable() throws SQLException {
140140
try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
141141
Statement statement = connection.createStatement()) {
142-
errorTest(statement, "drop model sundial", "1510: Cannot delete built-in model: sundial");
142+
errorTest(statement, "drop model sundial", "1506: Cannot delete built-in model: sundial");
143143
}
144144
}
145145

iotdb-core/ainode/iotdb/ainode/core/exception.py

Lines changed: 13 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __str__(self) -> str:
3535

3636
class BadNodeUrlException(_BaseException):
3737
def __init__(self, node_url: str):
38+
super().__init__()
3839
self.message = "Bad node url: {}".format(node_url)
3940

4041

@@ -43,16 +44,19 @@ def __init__(self, node_url: str):
4344

4445
class ModelExistedException(_BaseException):
4546
def __init__(self, model_id: str):
47+
super().__init__()
4648
self.message = "Model {} already exists".format(model_id)
4749

4850

4951
class ModelNotExistException(_BaseException):
5052
def __init__(self, model_id: str):
51-
self.message = "Model {} is not exists".format(model_id)
53+
super().__init__()
54+
self.message = "Model {} does not exist".format(model_id)
5255

5356

5457
class InvalidModelUriException(_BaseException):
5558
def __init__(self, msg: str):
59+
super().__init__()
5660
self.message = (
5761
"Model registration failed because the specified uri is invalid: {}".format(
5862
msg
@@ -62,74 +66,41 @@ def __init__(self, msg: str):
6266

6367
class BuiltInModelDeletionException(_BaseException):
6468
def __init__(self, model_id: str):
69+
super().__init__()
6570
self.message = "Cannot delete built-in model: {}".format(model_id)
6671

6772

6873
class BadConfigValueException(_BaseException):
6974
def __init__(self, config_name: str, config_value, hint: str = ""):
75+
super().__init__()
7076
self.message = "Bad value [{0}] for config {1}. {2}".format(
7177
config_value, config_name, hint
7278
)
7379

7480

75-
class MissingConfigException(_BaseException):
76-
def __init__(self, config_name: str):
77-
self.message = "Missing config: {}".format(config_name)
78-
79-
80-
class MissingOptionException(_BaseException):
81-
def __init__(self, config_name: str):
82-
self.message = "Missing task option: {}".format(config_name)
83-
84-
85-
class RedundantOptionException(_BaseException):
86-
def __init__(self, option_name: str):
87-
self.message = "Redundant task option: {}".format(option_name)
88-
89-
90-
class WrongTypeConfigException(_BaseException):
91-
def __init__(self, config_name: str, expected_type: str):
92-
self.message = "Wrong type for config: {0}, expected: {1}".format(
93-
config_name, expected_type
94-
)
95-
96-
97-
class UnsupportedException(_BaseException):
98-
def __init__(self, msg: str):
99-
self.message = "{0} is not supported in current version".format(msg)
100-
101-
102-
class InvalidUriException(_BaseException):
103-
def __init__(self, uri: str):
104-
self.message = "Invalid uri: {}, there are no {} or {} under this uri.".format(
105-
uri, MODEL_WEIGHTS_FILE_IN_PT, MODEL_CONFIG_FILE_IN_YAML
106-
)
107-
108-
109-
class InvalidWindowArgumentException(_BaseException):
110-
def __init__(self, window_interval, window_step, dataset_length):
111-
self.message = f"Invalid inference input: window_interval {window_interval}, window_step {window_step}, dataset_length {dataset_length}"
112-
113-
11481
class InferenceModelInternalException(_BaseException):
11582
def __init__(self, msg: str):
83+
super().__init__()
11684
self.message = "Inference model internal error: {0}".format(msg)
11785

11886

11987
class BuiltInModelNotSupportException(_BaseException):
12088
def __init__(self, msg: str):
89+
super().__init__()
12190
self.message = "Built-in model not support: {0}".format(msg)
12291

12392

12493
class WrongAttributeTypeException(_BaseException):
12594
def __init__(self, attribute_name: str, expected_type: str):
95+
super().__init__()
12696
self.message = "Wrong type for attribute: {0}, expected: {1}".format(
12797
attribute_name, expected_type
12898
)
12999

130100

131101
class NumericalRangeException(_BaseException):
132102
def __init__(self, attribute_name: str, value, min_value, max_value):
103+
super().__init__()
133104
self.message = (
134105
"Attribute {0} expect value between {1} and {2}, got {3} instead.".format(
135106
attribute_name, min_value, max_value, value
@@ -139,33 +110,17 @@ def __init__(self, attribute_name: str, value, min_value, max_value):
139110

140111
class StringRangeException(_BaseException):
141112
def __init__(self, attribute_name: str, value: str, expect_value):
113+
super().__init__()
142114
self.message = "Attribute {0} expect value in {1}, got {2} instead.".format(
143115
attribute_name, expect_value, value
144116
)
145117

146118

147119
class ListRangeException(_BaseException):
148120
def __init__(self, attribute_name: str, value: list, expected_type: str):
121+
super().__init__()
149122
self.message = (
150123
"Attribute {0} expect value type list[{1}], got {2} instead.".format(
151124
attribute_name, expected_type, value
152125
)
153126
)
154-
155-
156-
class AttributeNotSupportException(_BaseException):
157-
def __init__(self, model_name: str, attribute_name: str):
158-
self.message = "Attribute {0} is not supported in model {1}".format(
159-
attribute_name, model_name
160-
)
161-
162-
163-
# This is used to extract the key message in RuntimeError instead of the traceback message
164-
def runtime_error_extractor(error_message):
165-
pattern = re.compile(r"RuntimeError: (.+)")
166-
match = pattern.search(error_message)
167-
168-
if match:
169-
return match.group(1)
170-
else:
171-
return ""

iotdb-core/ainode/iotdb/ainode/core/manager/model_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# under the License.
1717
#
1818

19-
from typing import List, Optional
19+
from typing import Optional
2020

2121
from iotdb.ainode.core.constant import TSStatusCode
2222
from iotdb.ainode.core.exception import (

iotdb-core/ainode/iotdb/ainode/core/model/model_storage.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ def register_model(self, model_id: str, uri: str):
249249
- file://<local_path>
250250
- repo://<huggingface_repo_id> (Maybe in the future)
251251
Raises:
252-
ModelExistedError: If the model_id already exists.
253-
InvalidModelUriError: If the URI format is invalid.
252+
ModelExistedException: If the model_id already exists.
253+
InvalidModelUriException: If the URI format is invalid.
254254
"""
255255

256256
if self.is_model_registered(model_id):
@@ -490,6 +490,9 @@ def delete_model(self, model_id: str):
490490
logger.info(f"Model directory is deleted: {model_path}")
491491
except Exception as e:
492492
logger.error(f"Failed to delete model directory {model_path}: {e}")
493+
model_info.state = (
494+
ModelStates.ACTIVE
495+
) # Revert state update on failure
493496
raise e
494497
del self._models[category_value][model_id]
495498
logger.info(f"Model {model_id} has been removed from model storage")

iotdb-core/ainode/iotdb/ainode/core/model/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828
from huggingface_hub import snapshot_download
2929

3030
from iotdb.ainode.core.exception import InvalidModelUriException
31+
from iotdb.ainode.core.log import Logger
3132
from iotdb.ainode.core.model.model_constants import (
3233
MODEL_CONFIG_FILE_IN_JSON,
3334
MODEL_WEIGHTS_FILE_IN_SAFETENSORS,
3435
UriType,
3536
)
36-
from iotdb.ainode.core.model.model_storage import logger
37+
38+
logger = Logger()
3739

3840

3941
def parse_uri_type(uri: str) -> UriType:
@@ -109,6 +111,10 @@ def ensure_init_file(dir_path: str):
109111
def _fetch_model_from_local(source_path: str, storage_path: str):
110112
logger.info(f"Copying model from local path: {source_path} -> {storage_path}")
111113
source_dir = Path(source_path)
114+
if not source_dir.exists():
115+
raise InvalidModelUriException(f"Source path does not exist: {source_path}")
116+
if not source_dir.is_dir():
117+
raise InvalidModelUriException(f"Source path is not a directory: {source_path}")
112118
storage_dir = Path(storage_path)
113119
for file in source_dir.iterdir():
114120
if file.is_file():

0 commit comments

Comments
 (0)