|
17 | 17 | # |
18 | 18 | import os |
19 | 19 | import re |
| 20 | +import threading |
20 | 21 |
|
21 | | -from ainode.core.constant import ( |
| 22 | +from iotdb.ainode.core.constant import ( |
22 | 23 | AINODE_BUILD_INFO, |
23 | 24 | AINODE_BUILTIN_MODELS_DIR, |
24 | 25 | AINODE_CLUSTER_INGRESS_ADDRESS, |
|
47 | 48 | AINODE_VERSION_INFO, |
48 | 49 | ) |
49 | 50 | from iotdb.ainode.core.exception import BadNodeUrlError |
50 | | -from ainode.core.log import Logger |
51 | | -from ainode.core.util.decorator import singleton |
52 | | -from ainode.thrift.common.ttypes import TEndPoint |
| 51 | +from iotdb.ainode.core.log import Logger |
| 52 | +from iotdb.ainode.core.util.decorator import singleton |
| 53 | +from iotdb.thrift.common.ttypes import TEndPoint |
53 | 54 |
|
54 | 55 | logger = Logger() |
55 | 56 |
|
@@ -101,15 +102,37 @@ def __init__(self): |
101 | 102 | # Whether to enable compression for thrift |
102 | 103 | self._ain_thrift_compression_enabled = AINODE_THRIFT_COMPRESSION_ENABLED |
103 | 104 |
|
| 105 | + # use for ssl |
| 106 | + self._ain_cluster_ingress_ssl_enabled = False |
| 107 | + self._ain_internal_ssl_enabled = False |
| 108 | + self._ain_thrift_ssl_cert_file = None |
| 109 | + self._ain_thrift_ssl_key_file = None |
| 110 | + |
104 | 111 | # Cache number of model storage to avoid repeated loading |
105 | 112 | self._ain_model_storage_cache_size = 30 |
106 | 113 |
|
| 114 | + # activation |
| 115 | + self._ain_activated = threading.Event() |
| 116 | + |
107 | 117 | def get_cluster_name(self) -> str: |
108 | 118 | return self._cluster_name |
109 | 119 |
|
110 | 120 | def set_cluster_name(self, cluster_name: str) -> None: |
111 | 121 | self._cluster_name = cluster_name |
112 | 122 |
|
| 123 | + def is_activated(self) -> bool: |
| 124 | + return self._ain_activated.is_set() |
| 125 | + |
| 126 | + def set_activated(self, is_activated: bool) -> None: |
| 127 | + if is_activated: |
| 128 | + if not self._ain_activated.is_set(): |
| 129 | + logger.info("TimechoDB-AINode is activated.") |
| 130 | + self._ain_activated.set() |
| 131 | + else: |
| 132 | + if self._ain_activated.is_set(): |
| 133 | + logger.info("TimechoDB-AINode is deactivated.") |
| 134 | + self._ain_activated.clear() |
| 135 | + |
113 | 136 | def get_version_info(self) -> str: |
114 | 137 | return self._version_info |
115 | 138 |
|
@@ -218,6 +241,32 @@ def set_ain_thrift_compression_enabled( |
218 | 241 | ) -> None: |
219 | 242 | self._ain_thrift_compression_enabled = ain_thrift_compression_enabled |
220 | 243 |
|
| 244 | + def get_ain_cluster_ingress_ssl_enabled(self) -> bool: |
| 245 | + return self._ain_cluster_ingress_ssl_enabled |
| 246 | + |
| 247 | + def set_ain_cluster_ingress_ssl_enabled( |
| 248 | + self, ain_cluster_ingress_ssl_enabled: int |
| 249 | + ) -> None: |
| 250 | + self._ain_cluster_ingress_ssl_enabled = ain_cluster_ingress_ssl_enabled |
| 251 | + |
| 252 | + def get_ain_internal_ssl_enabled(self) -> bool: |
| 253 | + return self._ain_internal_ssl_enabled |
| 254 | + |
| 255 | + def set_ain_internal_ssl_enabled(self, ain_internal_ssl_enabled: int) -> None: |
| 256 | + self._ain_internal_ssl_enabled = ain_internal_ssl_enabled |
| 257 | + |
| 258 | + def get_ain_thrift_ssl_cert_file(self) -> str: |
| 259 | + return self._ain_thrift_ssl_cert_file |
| 260 | + |
| 261 | + def set_ain_thrift_ssl_cert_file(self, ain_thrift_ssl_cert_file: str) -> None: |
| 262 | + self._ain_thrift_ssl_cert_file = ain_thrift_ssl_cert_file |
| 263 | + |
| 264 | + def get_ain_thrift_ssl_key_file(self) -> str: |
| 265 | + return self._ain_thrift_ssl_key_file |
| 266 | + |
| 267 | + def set_ain_thrift_ssl_key_file(self, ain_thrift_ssl_key_file: str) -> None: |
| 268 | + self._ain_thrift_ssl_key_file = ain_thrift_ssl_key_file |
| 269 | + |
221 | 270 | def get_ain_model_storage_cache_size(self) -> int: |
222 | 271 | return self._ain_model_storage_cache_size |
223 | 272 |
|
@@ -358,6 +407,26 @@ def _load_config_from_file(self) -> None: |
358 | 407 | int(file_configs["ain_thrift_compression_enabled"]) |
359 | 408 | ) |
360 | 409 |
|
| 410 | + if "ain_cluster_ingress_ssl_enabled" in config_keys: |
| 411 | + self._config.set_ain_cluster_ingress_ssl_enabled( |
| 412 | + int(file_configs["ain_cluster_ingress_ssl_enabled"]) |
| 413 | + ) |
| 414 | + |
| 415 | + if "ain_internal_ssl_enabled" in config_keys: |
| 416 | + self._config.set_ain_internal_ssl_enabled( |
| 417 | + int(file_configs["ain_internal_ssl_enabled"]) |
| 418 | + ) |
| 419 | + |
| 420 | + if "ain_thrift_ssl_cert_file" in config_keys: |
| 421 | + self._config.set_ain_thrift_ssl_cert_file( |
| 422 | + file_configs["ain_thrift_ssl_cert_file"] |
| 423 | + ) |
| 424 | + |
| 425 | + if "ain_thrift_ssl_key_file" in config_keys: |
| 426 | + self._config.set_ain_thrift_ssl_key_file( |
| 427 | + file_configs["ain_thrift_ssl_key_file"] |
| 428 | + ) |
| 429 | + |
361 | 430 | if "ain_logs_dir" in config_keys: |
362 | 431 | log_dir = file_configs["ain_logs_dir"] |
363 | 432 | self._config.set_ain_logs_dir(log_dir) |
|
0 commit comments