1111 NodeMigratedNotification ,
1212 NodeMigratingNotification ,
1313 NodeMovingNotification ,
14+ OSSNodeMigratedNotification ,
15+ OSSNodeMigratingNotification ,
1416)
1517
1618if sys .version_info .major >= 3 and sys .version_info .minor >= 11 :
@@ -179,6 +181,34 @@ async def read_response(
179181class MaintenanceNotificationsParser :
180182 """Protocol defining maintenance push notification parsing functionality"""
181183
184+ @staticmethod
185+ def parse_oss_maintenance_start_msg (response ):
186+ # TODO This format is not the final - will be changed later
187+ # Expected message format is: SMIGRATING <seq_number> <src_node> <dest_node> <slots>
188+ id = response [1 ]
189+
190+ address_value = response [3 ]
191+ if isinstance (address_value , bytes ):
192+ address_value = address_value .decode ()
193+ if response [2 ] in ("TO" , b"TO" ):
194+ dest_node = address_value
195+ src_node = None
196+ else :
197+ dest_node = None
198+ src_node = address_value
199+
200+ slots = response [4 ]
201+ return OSSNodeMigratingNotification (id , src_node , dest_node , slots )
202+
203+ @staticmethod
204+ def parse_oss_maintenance_completed_msg (response ):
205+ # TODO This format is not the final - will be changed later
206+ # Expected message format is: SMIGRATED <seq_number> <node_address> <slots>
207+ id = response [1 ]
208+ node_address = response [2 ]
209+ slots = response [3 ]
210+ return OSSNodeMigratedNotification (id , node_address , slots )
211+
182212 @staticmethod
183213 def parse_maintenance_start_msg (response , notification_type ):
184214 # Expected message format is: <notification_type> <seq_number> <time>
@@ -215,12 +245,15 @@ def parse_moving_msg(response):
215245_MIGRATED_MESSAGE = "MIGRATED"
216246_FAILING_OVER_MESSAGE = "FAILING_OVER"
217247_FAILED_OVER_MESSAGE = "FAILED_OVER"
248+ _SMIGRATING_MESSAGE = "SMIGRATING"
249+ _SMIGRATED_MESSAGE = "SMIGRATED"
218250
219251_MAINTENANCE_MESSAGES = (
220252 _MIGRATING_MESSAGE ,
221253 _MIGRATED_MESSAGE ,
222254 _FAILING_OVER_MESSAGE ,
223255 _FAILED_OVER_MESSAGE ,
256+ _SMIGRATING_MESSAGE ,
224257)
225258
226259MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING : dict [
@@ -246,6 +279,14 @@ def parse_moving_msg(response):
246279 NodeMovingNotification ,
247280 MaintenanceNotificationsParser .parse_moving_msg ,
248281 ),
282+ _SMIGRATING_MESSAGE : (
283+ OSSNodeMigratingNotification ,
284+ MaintenanceNotificationsParser .parse_oss_maintenance_start_msg ,
285+ ),
286+ _SMIGRATED_MESSAGE : (
287+ OSSNodeMigratedNotification ,
288+ MaintenanceNotificationsParser .parse_oss_maintenance_completed_msg ,
289+ ),
249290}
250291
251292
@@ -256,6 +297,7 @@ class PushNotificationsParser(Protocol):
256297 invalidation_push_handler_func : Optional [Callable ] = None
257298 node_moving_push_handler_func : Optional [Callable ] = None
258299 maintenance_push_handler_func : Optional [Callable ] = None
300+ oss_maintenance_push_handler_func : Optional [Callable ] = None
259301
260302 def handle_pubsub_push_response (self , response ):
261303 """Handle pubsub push responses"""
@@ -270,6 +312,7 @@ def handle_push_response(self, response, **kwargs):
270312 _INVALIDATION_MESSAGE ,
271313 * _MAINTENANCE_MESSAGES ,
272314 _MOVING_MESSAGE ,
315+ _SMIGRATED_MESSAGE ,
273316 ):
274317 return self .pubsub_push_handler_func (response )
275318
@@ -292,13 +335,27 @@ def handle_push_response(self, response, **kwargs):
292335 parser_function = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
293336 msg_type
294337 ][1 ]
295- notification_type = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
296- msg_type
297- ][0 ]
298- notification = parser_function (response , notification_type )
338+ if msg_type == _SMIGRATING_MESSAGE :
339+ notification = parser_function (response )
340+ else :
341+ notification_type = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
342+ msg_type
343+ ][0 ]
344+ notification = parser_function (response , notification_type )
299345
300346 if notification is not None :
301347 return self .maintenance_push_handler_func (notification )
348+ if (
349+ msg_type == _SMIGRATED_MESSAGE
350+ and self .oss_maintenance_push_handler_func
351+ ):
352+ parser_function = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
353+ msg_type
354+ ][1 ]
355+ notification = parser_function (response )
356+
357+ if notification is not None :
358+ return self .oss_maintenance_push_handler_func (notification )
302359 except Exception as e :
303360 logger .error (
304361 "Error handling {} message ({}): {}" .format (msg_type , response , e )
@@ -318,6 +375,9 @@ def set_node_moving_push_handler(self, node_moving_push_handler_func):
318375 def set_maintenance_push_handler (self , maintenance_push_handler_func ):
319376 self .maintenance_push_handler_func = maintenance_push_handler_func
320377
378+ def set_oss_maintenance_push_handler (self , oss_maintenance_push_handler_func ):
379+ self .oss_maintenance_push_handler_func = oss_maintenance_push_handler_func
380+
321381
322382class AsyncPushNotificationsParser (Protocol ):
323383 """Protocol defining async RESP3-specific parsing functionality"""
@@ -326,6 +386,7 @@ class AsyncPushNotificationsParser(Protocol):
326386 invalidation_push_handler_func : Optional [Callable ] = None
327387 node_moving_push_handler_func : Optional [Callable [..., Awaitable [None ]]] = None
328388 maintenance_push_handler_func : Optional [Callable [..., Awaitable [None ]]] = None
389+ oss_maintenance_push_handler_func : Optional [Callable [..., Awaitable [None ]]] = None
329390
330391 async def handle_pubsub_push_response (self , response ):
331392 """Handle pubsub push responses asynchronously"""
@@ -342,6 +403,7 @@ async def handle_push_response(self, response, **kwargs):
342403 _INVALIDATION_MESSAGE ,
343404 * _MAINTENANCE_MESSAGES ,
344405 _MOVING_MESSAGE ,
406+ _SMIGRATED_MESSAGE ,
345407 ):
346408 return await self .pubsub_push_handler_func (response )
347409
@@ -366,13 +428,28 @@ async def handle_push_response(self, response, **kwargs):
366428 parser_function = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
367429 msg_type
368430 ][1 ]
369- notification_type = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
370- msg_type
371- ][0 ]
372- notification = parser_function (response , notification_type )
431+ if msg_type == _SMIGRATING_MESSAGE :
432+ notification = parser_function (response )
433+ else :
434+ notification_type = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
435+ msg_type
436+ ][0 ]
437+ notification = parser_function (response , notification_type )
373438
374439 if notification is not None :
375440 return await self .maintenance_push_handler_func (notification )
441+ if (
442+ msg_type == _SMIGRATED_MESSAGE
443+ and self .oss_maintenance_push_handler_func
444+ ):
445+ parser_function = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
446+ msg_type
447+ ][1 ]
448+ notification = parser_function (response )
449+ if notification is not None :
450+ return await self .oss_maintenance_push_handler_func (
451+ notification
452+ )
376453 except Exception as e :
377454 logger .error (
378455 "Error handling {} message ({}): {}" .format (msg_type , response , e )
@@ -394,6 +471,9 @@ def set_node_moving_push_handler(self, node_moving_push_handler_func):
394471 def set_maintenance_push_handler (self , maintenance_push_handler_func ):
395472 self .maintenance_push_handler_func = maintenance_push_handler_func
396473
474+ def set_oss_maintenance_push_handler (self , oss_maintenance_push_handler_func ):
475+ self .oss_maintenance_push_handler_func = oss_maintenance_push_handler_func
476+
397477
398478class _AsyncRESPBase (AsyncBaseParser ):
399479 """Base class for async resp parsing"""
0 commit comments