forked from ModelEngine-Group/fit-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity.py
More file actions
233 lines (165 loc) · 6.27 KB
/
entity.py
File metadata and controls
233 lines (165 loc) · 6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# -- encoding: utf-8 --
# Copyright (c) 2024 Huawei Technologies Co., Ltd. All Rights Reserved.
# This file is a part of the ModelEngine Project.
# Licensed under the MIT License. See License.txt in the project root for license information.
# ======================================================================================================================
"""
功 能:注册中心交互用数据结构。
"""
from typing import Dict, List
from numpy import int32
from fit_common_struct.core import Address as AddressInner
from fit_common_struct.core import Fitable
def safe_hash_dict(obj_dict):
"""安全地计算包含列表的字典的哈希值"""
hashable_values = []
for value in obj_dict.values():
if isinstance(value, list):
hashable_values.append(tuple(value))
elif isinstance(value, dict):
hashable_values.append(tuple(sorted(value.items())))
else:
hashable_values.append(value)
return hash(tuple(hashable_values))
class FitableMeta(object):
def __init__(self, fitable: Fitable, aliases: List[str], formats: List[int32]):
self.fitable = fitable
self.aliases = aliases
"""
protobuf-----0
json------1
"""
self.formats = formats
def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return self.__dict__ == other.__dict__
def __hash__(self):
# 使用安全的哈希函数处理包含列表的对象
return safe_hash_dict(self.__dict__)
def __repr__(self):
return str(tuple(self.__dict__.values()))
class Application(object):
def __init__(self, name: str, nameVersion: str):
self.name = name
self.nameVersion = nameVersion
def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return self.__dict__ == other.__dict__
def __hash__(self):
return hash(tuple(self.__dict__.values()))
def __repr__(self):
return str(tuple(self.__dict__.values()))
class Endpoint(object):
def __init__(self, port: int32, protocol: int32):
self.port = port
"""
rsocket------0
socket-------1
http---------2
grpc---------3
uc-----------10
shareMemory--11
"""
self.protocol = protocol
def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return self.__dict__ == other.__dict__
def __hash__(self):
return hash(tuple(self.__dict__.values()))
def __repr__(self):
return str(tuple(self.__dict__.values()))
class Address(object):
def __init__(self, host: str, endpoints: List[Endpoint]):
self.host = host
self.endpoints = endpoints
def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return self.__dict__ == other.__dict__
def __hash__(self):
return safe_hash_dict(self.__dict__)
def __repr__(self):
return str(tuple(self.__dict__.values()))
class Worker(object):
def __init__(self, addresses: List[Address], id: str, environment: str, extensions: Dict[str, str]):
self.addresses = addresses
# 地址所在进程唯一标识,正常ip网络下可用host:port拼接或uuid作为唯一标识,心跳时进程上报给心跳服务时应使用该标识,用于进程下线时更新对应服务的状态
self.id = id
self.environment = environment
self.extensions = extensions
def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return self.__dict__ == other.__dict__
def __hash__(self):
return safe_hash_dict(self.__dict__)
def __repr__(self):
return str(tuple(self.__dict__.values()))
class ApplicationInstance(object):
def __init__(self, workers: List[Worker], application: Application, formats: List[int32]):
self.workers = workers
self.application = application
"""
protobuf-----0
json------1
"""
self.formats = formats
def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return self.__dict__ == other.__dict__
def __hash__(self):
return safe_hash_dict(self.__dict__)
def __repr__(self):
return str(tuple(self.__dict__.values()))
class FitableAddressInstance(object):
def __init__(self, applicationInstances: List[ApplicationInstance], fitable: Fitable):
self.applicationInstances = applicationInstances
self.fitable = fitable
def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return self.__dict__ == other.__dict__
def __hash__(self):
return safe_hash_dict(self.__dict__)
def __repr__(self):
return str(tuple(self.__dict__.values()))
class FitableMetaInstance(object):
def __init__(self, meta: FitableMeta, environments: List[str]):
self.meta = meta
self.environments = environments
def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return self.__dict__ == other.__dict__
def __hash__(self):
return safe_hash_dict(self.__dict__)
def __repr__(self):
return str(tuple(self.__dict__.values()))
class HeartBeatInfo(object):
def __init__(self, sceneType: str, aliveTime: int, initDelay: int):
self.sceneType: str = sceneType
self.aliveTime: int = aliveTime
self.initDelay: int = initDelay
def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return self.__dict__ == other.__dict__
def __hash__(self):
return safe_hash_dict(self.__dict__)
def __repr__(self):
return str(tuple(self.__dict__.values()))
class HeartBeatAddress(object):
def __init__(self, id_: str):
self.id = id_
def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
return self.__dict__ == other.__dict__
def __hash__(self):
return safe_hash_dict(self.__dict__)
def __repr__(self):
return str(tuple(self.__dict__.values()))