baerwang commented on code in PR #658:
URL: https://github.com/apache/dubbo-go-pixiu/pull/658#discussion_r2061313883


##########
pkg/server/router_manager.go:
##########
@@ -55,3 +59,58 @@ func (rm *RouterManager) DeleteRouter(r *model.Router) {
                l.OnDeleteRouter(r)
        }
 }
+
+// UpdateRoutes updates the routes in RouterManager with the provided new 
routes.
+func (rm *RouterManager) UpdateRoutes(oldRoutes []*model.Router, newRoutes 
[]*model.Router) error {
+       logger.Infof("Starting route update with %d new routes", len(newRoutes))
+
+       // Validate new routes
+       if err := validateRoutes(newRoutes); err != nil {
+               logger.Errorf("Invalid routes provided: %v", err)
+               return errors.Wrap(err, "route validation failed")
+       }
+
+       // Notify listeners to delete existing routes
+       for _, route := range oldRoutes {
+               logger.Debugf("Notifying listeners to delete route: %s", 
route.String())
+               for _, listener := range rm.rls {
+                       listener.OnDeleteRouter(route)
+               }
+       }
+
+       // Notify listeners to add new routes
+       for _, route := range newRoutes {
+               logger.Debugf("Notifying listeners to add route: %s", 
route.String())
+               for _, listener := range rm.rls {
+                       listener.OnAddRouter(route)
+               }
+       }
+
+       // Atomically update the active configuration
+       logger.Infof("Routes updated successfully with %d routes", 
len(newRoutes))
+
+       return nil
+}
+
+// validateRoutes performs basic validation on the provided routes.
+func validateRoutes(routes []*model.Router) error {
+       routeIDs := make(map[string]struct{})

Review Comment:
   add cap



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to