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,25 @@ 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+ src_node = response [2 ]
190+ dest_node = response [3 ]
191+ slots = response [4 ]
192+ return OSSNodeMigratingNotification (id , src_node , dest_node , slots )
193+
194+ @staticmethod
195+ def parse_oss_maintenance_completed_msg (response ):
196+ # TODO This format is not the final - will be changed later
197+ # Expected message format is: SMIGRATED <seq_number> <node_address> <slots>
198+ id = response [1 ]
199+ node_address = response [2 ]
200+ slots = response [3 ]
201+ return OSSNodeMigratedNotification (id , node_address , slots )
202+
182203 @staticmethod
183204 def parse_maintenance_start_msg (response , notification_type ):
184205 # Expected message format is: <notification_type> <seq_number> <time>
@@ -215,12 +236,15 @@ def parse_moving_msg(response):
215236_MIGRATED_MESSAGE = "MIGRATED"
216237_FAILING_OVER_MESSAGE = "FAILING_OVER"
217238_FAILED_OVER_MESSAGE = "FAILED_OVER"
239+ _SMIGRATING_MESSAGE = "SMIGRATING"
240+ _SMIGRATED_MESSAGE = "SMIGRATED"
218241
219242_MAINTENANCE_MESSAGES = (
220243 _MIGRATING_MESSAGE ,
221244 _MIGRATED_MESSAGE ,
222245 _FAILING_OVER_MESSAGE ,
223246 _FAILED_OVER_MESSAGE ,
247+ _SMIGRATING_MESSAGE ,
224248)
225249
226250MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING : dict [
@@ -246,6 +270,14 @@ def parse_moving_msg(response):
246270 NodeMovingNotification ,
247271 MaintenanceNotificationsParser .parse_moving_msg ,
248272 ),
273+ _SMIGRATING_MESSAGE : (
274+ OSSNodeMigratingNotification ,
275+ MaintenanceNotificationsParser .parse_oss_maintenance_start_msg ,
276+ ),
277+ _SMIGRATED_MESSAGE : (
278+ OSSNodeMigratedNotification ,
279+ MaintenanceNotificationsParser .parse_oss_maintenance_completed_msg ,
280+ ),
249281}
250282
251283
@@ -256,6 +288,7 @@ class PushNotificationsParser(Protocol):
256288 invalidation_push_handler_func : Optional [Callable ] = None
257289 node_moving_push_handler_func : Optional [Callable ] = None
258290 maintenance_push_handler_func : Optional [Callable ] = None
291+ oss_maintenance_push_handler_func : Optional [Callable ] = None
259292
260293 def handle_pubsub_push_response (self , response ):
261294 """Handle pubsub push responses"""
@@ -270,6 +303,7 @@ def handle_push_response(self, response, **kwargs):
270303 _INVALIDATION_MESSAGE ,
271304 * _MAINTENANCE_MESSAGES ,
272305 _MOVING_MESSAGE ,
306+ _SMIGRATED_MESSAGE ,
273307 ):
274308 return self .pubsub_push_handler_func (response )
275309
@@ -292,13 +326,27 @@ def handle_push_response(self, response, **kwargs):
292326 parser_function = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
293327 msg_type
294328 ][1 ]
295- notification_type = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
296- msg_type
297- ][0 ]
298- notification = parser_function (response , notification_type )
329+ if msg_type == _SMIGRATING_MESSAGE :
330+ notification = parser_function (response )
331+ else :
332+ notification_type = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
333+ msg_type
334+ ][0 ]
335+ notification = parser_function (response , notification_type )
299336
300337 if notification is not None :
301338 return self .maintenance_push_handler_func (notification )
339+ if (
340+ msg_type == _SMIGRATED_MESSAGE
341+ and self .oss_maintenance_push_handler_func
342+ ):
343+ parser_function = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
344+ msg_type
345+ ][1 ]
346+ notification = parser_function (response )
347+
348+ if notification is not None :
349+ return self .oss_maintenance_push_handler_func (notification )
302350 except Exception as e :
303351 logger .error (
304352 "Error handling {} message ({}): {}" .format (msg_type , response , e )
@@ -318,6 +366,9 @@ def set_node_moving_push_handler(self, node_moving_push_handler_func):
318366 def set_maintenance_push_handler (self , maintenance_push_handler_func ):
319367 self .maintenance_push_handler_func = maintenance_push_handler_func
320368
369+ def set_oss_maintenance_push_handler (self , oss_maintenance_push_handler_func ):
370+ self .oss_maintenance_push_handler_func = oss_maintenance_push_handler_func
371+
321372
322373class AsyncPushNotificationsParser (Protocol ):
323374 """Protocol defining async RESP3-specific parsing functionality"""
@@ -326,6 +377,7 @@ class AsyncPushNotificationsParser(Protocol):
326377 invalidation_push_handler_func : Optional [Callable ] = None
327378 node_moving_push_handler_func : Optional [Callable [..., Awaitable [None ]]] = None
328379 maintenance_push_handler_func : Optional [Callable [..., Awaitable [None ]]] = None
380+ oss_maintenance_push_handler_func : Optional [Callable [..., Awaitable [None ]]] = None
329381
330382 async def handle_pubsub_push_response (self , response ):
331383 """Handle pubsub push responses asynchronously"""
@@ -342,6 +394,7 @@ async def handle_push_response(self, response, **kwargs):
342394 _INVALIDATION_MESSAGE ,
343395 * _MAINTENANCE_MESSAGES ,
344396 _MOVING_MESSAGE ,
397+ _SMIGRATED_MESSAGE ,
345398 ):
346399 return await self .pubsub_push_handler_func (response )
347400
@@ -366,13 +419,28 @@ async def handle_push_response(self, response, **kwargs):
366419 parser_function = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
367420 msg_type
368421 ][1 ]
369- notification_type = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
370- msg_type
371- ][0 ]
372- notification = parser_function (response , notification_type )
422+ if msg_type == _SMIGRATING_MESSAGE :
423+ notification = parser_function (response )
424+ else :
425+ notification_type = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
426+ msg_type
427+ ][0 ]
428+ notification = parser_function (response , notification_type )
373429
374430 if notification is not None :
375431 return await self .maintenance_push_handler_func (notification )
432+ if (
433+ msg_type == _SMIGRATED_MESSAGE
434+ and self .oss_maintenance_push_handler_func
435+ ):
436+ parser_function = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
437+ msg_type
438+ ][1 ]
439+ notification = parser_function (response )
440+ if notification is not None :
441+ return await self .oss_maintenance_push_handler_func (
442+ notification
443+ )
376444 except Exception as e :
377445 logger .error (
378446 "Error handling {} message ({}): {}" .format (msg_type , response , e )
@@ -394,6 +462,9 @@ def set_node_moving_push_handler(self, node_moving_push_handler_func):
394462 def set_maintenance_push_handler (self , maintenance_push_handler_func ):
395463 self .maintenance_push_handler_func = maintenance_push_handler_func
396464
465+ def set_oss_maintenance_push_handler (self , oss_maintenance_push_handler_func ):
466+ self .oss_maintenance_push_handler_func = oss_maintenance_push_handler_func
467+
397468
398469class _AsyncRESPBase (AsyncBaseParser ):
399470 """Base class for async resp parsing"""
0 commit comments