Integrate wave-based scaling system with WHOOSH server
- Add scaling system components to server initialization - Register scaling API and assignment broker routes - Start bootstrap pool manager in server lifecycle - Add graceful shutdown for scaling controller - Update API routing to use chi.Router instead of gorilla/mux - Fix Docker API compatibility issues - Configure health gates with placeholder URLs for KACHING and BACKBEAT 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/rs/zerolog/log"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
|
||||
@@ -155,15 +155,17 @@ func (ab *AssignmentBroker) initializeDefaultTemplates() {
|
||||
}
|
||||
|
||||
// RegisterRoutes registers HTTP routes for the assignment broker
|
||||
func (ab *AssignmentBroker) RegisterRoutes(router *mux.Router) {
|
||||
router.HandleFunc("/assign", ab.handleAssignRequest).Methods("GET")
|
||||
router.HandleFunc("/assignments", ab.handleListAssignments).Methods("GET")
|
||||
router.HandleFunc("/assignments/{id}", ab.handleGetAssignment).Methods("GET")
|
||||
router.HandleFunc("/assignments/{id}", ab.handleDeleteAssignment).Methods("DELETE")
|
||||
router.HandleFunc("/templates", ab.handleListTemplates).Methods("GET")
|
||||
router.HandleFunc("/templates", ab.handleCreateTemplate).Methods("POST")
|
||||
router.HandleFunc("/templates/{name}", ab.handleGetTemplate).Methods("GET")
|
||||
router.HandleFunc("/assignments/stats", ab.handleGetStats).Methods("GET")
|
||||
func (ab *AssignmentBroker) RegisterRoutes(router chi.Router) {
|
||||
router.Get("/assign", ab.handleAssignRequest)
|
||||
router.Get("/", ab.handleListAssignments)
|
||||
router.Get("/{id}", ab.handleGetAssignment)
|
||||
router.Delete("/{id}", ab.handleDeleteAssignment)
|
||||
router.Route("/templates", func(r chi.Router) {
|
||||
r.Get("/", ab.handleListTemplates)
|
||||
r.Post("/", ab.handleCreateTemplate)
|
||||
r.Get("/{name}", ab.handleGetTemplate)
|
||||
})
|
||||
router.Get("/stats", ab.handleGetStats)
|
||||
}
|
||||
|
||||
// handleAssignRequest handles requests for new assignments
|
||||
@@ -236,8 +238,7 @@ func (ab *AssignmentBroker) handleListAssignments(w http.ResponseWriter, r *http
|
||||
|
||||
// handleGetAssignment returns a specific assignment by ID
|
||||
func (ab *AssignmentBroker) handleGetAssignment(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
assignmentID := vars["id"]
|
||||
assignmentID := chi.URLParam(r, "id")
|
||||
|
||||
ab.mu.RLock()
|
||||
assignment, exists := ab.assignments[assignmentID]
|
||||
@@ -254,8 +255,7 @@ func (ab *AssignmentBroker) handleGetAssignment(w http.ResponseWriter, r *http.R
|
||||
|
||||
// handleDeleteAssignment deletes an assignment
|
||||
func (ab *AssignmentBroker) handleDeleteAssignment(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
assignmentID := vars["id"]
|
||||
assignmentID := chi.URLParam(r, "id")
|
||||
|
||||
ab.mu.Lock()
|
||||
defer ab.mu.Unlock()
|
||||
@@ -311,8 +311,7 @@ func (ab *AssignmentBroker) handleCreateTemplate(w http.ResponseWriter, r *http.
|
||||
|
||||
// handleGetTemplate returns a specific template
|
||||
func (ab *AssignmentBroker) handleGetTemplate(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
templateName := vars["name"]
|
||||
templateName := chi.URLParam(r, "name")
|
||||
|
||||
ab.mu.RLock()
|
||||
template, exists := ab.templates[templateName]
|
||||
@@ -353,7 +352,9 @@ func (ab *AssignmentBroker) CreateAssignment(ctx context.Context, req Assignment
|
||||
if ab.bootstrap != nil {
|
||||
subset := ab.bootstrap.GetSubset(template.BootstrapPeerCount)
|
||||
for _, peer := range subset.Peers {
|
||||
bootstrapPeers = append(bootstrapPeers, fmt.Sprintf("%s/p2p/%s", peer.Addrs[0], peer.ID))
|
||||
if len(peer.Addresses) > 0 {
|
||||
bootstrapPeers = append(bootstrapPeers, fmt.Sprintf("%s/p2p/%s", peer.Addresses[0], peer.ID))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user