-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathhttp_handler.go
More file actions
593 lines (521 loc) · 21.3 KB
/
http_handler.go
File metadata and controls
593 lines (521 loc) · 21.3 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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
package scheduling
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/http/httptest"
"strings"
"sync"
"time"
"github.com/docker/model-runner/pkg/distribution/distribution"
"github.com/docker/model-runner/pkg/inference"
"github.com/docker/model-runner/pkg/inference/backends/vllm"
"github.com/docker/model-runner/pkg/inference/models"
"github.com/docker/model-runner/pkg/metrics"
"github.com/docker/model-runner/pkg/middleware"
)
type contextKey bool
// readRequestBody reads up to maxSize bytes from the request body and writes
// an appropriate HTTP error if reading fails. Returns (body, true) on success
// or (nil, false) after writing the error response.
func readRequestBody(w http.ResponseWriter, r *http.Request, maxSize int64) ([]byte, bool) {
body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, maxSize))
if err != nil {
var maxBytesError *http.MaxBytesError
if errors.As(err, &maxBytesError) {
http.Error(w, "request too large", http.StatusBadRequest)
} else {
http.Error(w, "failed to read request body", http.StatusInternalServerError)
}
return nil, false
}
return body, true
}
const preloadOnlyKey contextKey = false
// HTTPHandler handles HTTP requests for the scheduler.
// It wraps the Scheduler to provide HTTP endpoint functionality without
// coupling the core scheduling logic to HTTP concerns.
type HTTPHandler struct {
scheduler *Scheduler
router *http.ServeMux
httpHandler http.Handler
// modelHandler is the shared model handler.
modelHandler *models.HTTPHandler
lock sync.RWMutex
}
// NewHTTPHandler creates a new HTTP handler that wraps the scheduler.
// This is the primary HTTP interface for the scheduling package.
func NewHTTPHandler(s *Scheduler, modelHandler *models.HTTPHandler, allowedOrigins []string) *HTTPHandler {
h := &HTTPHandler{
scheduler: s,
modelHandler: modelHandler,
router: http.NewServeMux(),
}
// Register routes
h.router.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
http.Error(w, "not found", http.StatusNotFound)
})
for route, handler := range h.routeHandlers() {
h.router.HandleFunc(route, handler)
}
h.RebuildRoutes(allowedOrigins)
return h
}
// routeHandlers returns a map of HTTP routes to their handler functions.
func (h *HTTPHandler) routeHandlers() map[string]http.HandlerFunc {
openAIRoutes := []string{
"POST " + inference.InferencePrefix + "/{backend}/v1/chat/completions",
"POST " + inference.InferencePrefix + "/{backend}/v1/completions",
"POST " + inference.InferencePrefix + "/{backend}/v1/embeddings",
"POST " + inference.InferencePrefix + "/v1/chat/completions",
"POST " + inference.InferencePrefix + "/v1/completions",
"POST " + inference.InferencePrefix + "/v1/embeddings",
"POST " + inference.InferencePrefix + "/{backend}/rerank",
"POST " + inference.InferencePrefix + "/rerank",
"POST " + inference.InferencePrefix + "/{backend}/score",
"POST " + inference.InferencePrefix + "/score",
// Image generation routes
"POST " + inference.InferencePrefix + "/{backend}/v1/images/generations",
"POST " + inference.InferencePrefix + "/v1/images/generations",
}
// Anthropic Messages API routes
anthropicRoutes := []string{
"POST " + inference.InferencePrefix + "/{backend}/v1/messages",
"POST " + inference.InferencePrefix + "/v1/messages",
"POST " + inference.InferencePrefix + "/{backend}/v1/messages/count_tokens",
"POST " + inference.InferencePrefix + "/v1/messages/count_tokens",
}
m := make(map[string]http.HandlerFunc)
for _, route := range append(openAIRoutes, anthropicRoutes...) {
m[route] = h.handleOpenAIInference
}
// Register /v1/models routes - these delegate to the model manager
m["GET "+inference.InferencePrefix+"/{backend}/v1/models"] = h.handleModels
m["GET "+inference.InferencePrefix+"/{backend}/v1/models/{name...}"] = h.handleModels
m["GET "+inference.InferencePrefix+"/v1/models"] = h.handleModels
m["GET "+inference.InferencePrefix+"/v1/models/{name...}"] = h.handleModels
m["POST "+inference.InferencePrefix+"/install-backend"] = h.InstallBackend
m["POST "+inference.InferencePrefix+"/uninstall-backend"] = h.UninstallBackend
m["GET "+inference.InferencePrefix+"/status"] = h.GetBackendStatus
m["GET "+inference.InferencePrefix+"/ps"] = h.GetRunningBackends
m["GET "+inference.InferencePrefix+"/df"] = h.GetDiskUsage
m["GET "+inference.ModelsPrefix+"/backend"] = h.GetModelBackend
m["POST "+inference.InferencePrefix+"/unload"] = h.Unload
m["POST "+inference.InferencePrefix+"/{backend}/_configure"] = h.Configure
m["POST "+inference.InferencePrefix+"/_configure"] = h.Configure
m["GET "+inference.InferencePrefix+"/_configure"] = h.GetModelConfigs
m["GET "+inference.InferencePrefix+"/requests"] = h.scheduler.openAIRecorder.GetRecordsHandler()
return m
}
// handleOpenAIInference handles scheduling and responding to OpenAI inference
// requests, including:
// - POST <inference-prefix>/{backend}/v1/chat/completions
// - POST <inference-prefix>/{backend}/v1/completions
// - POST <inference-prefix>/{backend}/v1/embeddings
// and 2 extras:
// - POST <inference-prefix>/{backend}/rerank
// - POST <inference-prefix>/{backend}/score
func (h *HTTPHandler) handleOpenAIInference(w http.ResponseWriter, r *http.Request) {
// Determine the requested backend and ensure that it's valid.
var backend inference.Backend
if b := r.PathValue("backend"); b == "" {
backend = h.scheduler.defaultBackend
} else {
backend = h.scheduler.backends[b]
}
if backend == nil {
http.Error(w, ErrBackendNotFound.Error(), http.StatusNotFound)
return
}
// Read the entire request body. We put some basic size constraints in place
// to avoid DoS attacks. We do this early to avoid client write timeouts.
body, ok := readRequestBody(w, r, maximumOpenAIInferenceRequestSize)
if !ok {
return
}
// Determine the backend operation mode.
backendMode, ok := backendModeForRequest(r.URL.Path)
if !ok {
http.Error(w, "unknown request path", http.StatusInternalServerError)
return
}
// Set origin header for Anthropic Messages API requests if not already set.
// This enables proper response format detection in the recorder.
if strings.HasSuffix(r.URL.Path, "/v1/messages") && r.Header.Get(inference.RequestOriginHeader) == "" {
r.Header.Set(inference.RequestOriginHeader, inference.OriginAnthropicMessages)
}
// Decode the model specification portion of the request body.
var request OpenAIInferenceRequest
if err := json.Unmarshal(body, &request); err != nil {
http.Error(w, "invalid request", http.StatusBadRequest)
return
}
if request.Model == "" {
http.Error(w, "model is required", http.StatusBadRequest)
return
}
// Check if the shared model manager has the requested model available.
if !backend.UsesExternalModelManagement() {
model, err := h.scheduler.modelManager.GetLocal(request.Model)
if err != nil {
if errors.Is(err, distribution.ErrModelNotFound) {
http.Error(w, err.Error(), http.StatusNotFound)
} else {
http.Error(w, "model unavailable", http.StatusInternalServerError)
}
return
}
// Determine the action for tracking
action := "inference/" + backendMode.String()
// Check if there's a request origin header to provide more specific tracking
// Only trust whitelisted values to prevent header spoofing
if origin := r.Header.Get(inference.RequestOriginHeader); origin != "" {
switch origin {
case inference.OriginOllamaCompletion:
action = origin
// If an unknown origin is provided, ignore it and use the default action
// This prevents untrusted clients from spoofing tracking data
}
}
// Non-blocking call to track the model usage.
h.scheduler.tracker.TrackModel(model, r.UserAgent(), action)
// Automatically select backend for given model.
backend = h.scheduler.selectBackendForModel(model, backend, request.Model)
}
// If a deferred backend needs on-demand installation and the request
// comes from the model CLI, stream progress messages so the user sees
// what is happening while the download runs.
autoInstall := h.scheduler.installer.deferredBackends[backend.Name()] &&
!h.scheduler.installer.isInstalled(backend.Name()) &&
strings.Contains(r.UserAgent(), modelCLIUserAgentPrefix)
if autoInstall {
fmt.Fprintf(w, "Installing %s backend...\n", backend.Name())
if f, ok := w.(http.Flusher); ok {
f.Flush()
}
}
// Wait for the corresponding backend installation to complete or fail. We
// don't allow any requests to be scheduled for a backend until it has
// completed installation.
if err := h.scheduler.installer.wait(r.Context(), backend.Name()); err != nil {
if autoInstall {
// Headers are already sent (200 OK) from the progress
// line, so we can only write the error as plain text.
fmt.Fprintf(w, "backend installation failed: %v\n", err)
} else if errors.Is(err, ErrBackendNotFound) {
http.Error(w, err.Error(), http.StatusNotFound)
} else if errors.Is(err, errInstallerNotStarted) {
http.Error(w, err.Error(), http.StatusServiceUnavailable)
} else if errors.Is(err, context.Canceled) {
// This could be due to the client aborting the request (in which
// case this response will be ignored) or the inference service
// shutting down (since that will also cancel the request context).
// Either way, provide a response, even if it's ignored.
http.Error(w, "service unavailable", http.StatusServiceUnavailable)
} else if errors.Is(err, errBackendNotInstalled) {
http.Error(w, fmt.Sprintf("backend %q is not installed; run: docker model install-runner --backend %s", backend.Name(), backend.Name()), http.StatusPreconditionFailed)
} else if errors.Is(err, vllm.ErrorNotFound) {
http.Error(w, err.Error(), http.StatusPreconditionFailed)
} else {
http.Error(w, fmt.Errorf("backend installation failed: %w", err).Error(), http.StatusServiceUnavailable)
}
return
}
if autoInstall {
fmt.Fprintf(w, "%s backend installed successfully\n", backend.Name())
if f, ok := w.(http.Flusher); ok {
f.Flush()
}
}
modelID := h.scheduler.modelManager.ResolveID(request.Model)
// Request a runner to execute the request and defer its release.
runner, err := h.scheduler.loader.load(r.Context(), backend.Name(), modelID, request.Model, backendMode)
if err != nil {
http.Error(w, fmt.Errorf("unable to load runner: %w", err).Error(), http.StatusInternalServerError)
return
}
defer h.scheduler.loader.release(runner)
// If this is a preload-only request, return here without running inference.
// Can be triggered via context (internal) or X-Preload-Only header (external).
if r.Context().Value(preloadOnlyKey) != nil || r.Header.Get("X-Preload-Only") == "true" {
return
}
// Record the request in the OpenAI recorder.
recordID := h.scheduler.openAIRecorder.RecordRequest(request.Model, r, body)
w = h.scheduler.openAIRecorder.NewResponseRecorder(w)
defer func() {
// Record the response in the OpenAI recorder.
h.scheduler.openAIRecorder.RecordResponse(recordID, request.Model, w)
}()
// Create a request with the body replaced for forwarding upstream.
// Set ContentLength explicitly so the backend always receives a Content-Length
// header. Without this, HTTP/2 requests (where clients may omit Content-Length)
// are forwarded with Transfer-Encoding: chunked, which some backends (e.g.
// vLLM's Python/uvicorn server) fail to parse, resulting in an empty body and
// a 422 response.
upstreamRequest := r.Clone(r.Context())
upstreamRequest.Body = io.NopCloser(bytes.NewReader(body))
upstreamRequest.ContentLength = int64(len(body))
// Perform the request.
runner.ServeHTTP(w, upstreamRequest)
}
// handleModels handles GET /engines/{backend}/v1/models* requests
// by delegating to the model manager
func (h *HTTPHandler) handleModels(w http.ResponseWriter, r *http.Request) {
h.modelHandler.ServeHTTP(w, r)
}
// GetBackendStatus returns the status of all backends.
func (h *HTTPHandler) GetBackendStatus(w http.ResponseWriter, r *http.Request) {
status := make(map[string]string)
for backendName, backend := range h.scheduler.backends {
status[backendName] = backend.Status()
}
data, err := json.Marshal(status)
if err != nil {
http.Error(w, "failed to encode response", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write(data)
}
// GetRunningBackends returns information about all running backends
func (h *HTTPHandler) GetRunningBackends(w http.ResponseWriter, r *http.Request) {
runningBackends := h.scheduler.getLoaderStatus(r.Context())
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(runningBackends); err != nil {
http.Error(w, fmt.Sprintf("Failed to encode response: %v", err), http.StatusInternalServerError)
return
}
}
// GetDiskUsage returns disk usage information for models and backends.
func (h *HTTPHandler) GetDiskUsage(w http.ResponseWriter, _ *http.Request) {
modelsDiskUsage, err := h.scheduler.modelManager.GetDiskUsage()
if err != nil {
http.Error(w, fmt.Sprintf("Failed to get models disk usage: %v", err), http.StatusInternalServerError)
return
}
// TODO: Get disk usage for each backend once the backends are implemented.
defaultBackendDiskUsage, err := h.scheduler.defaultBackend.GetDiskUsage()
if err != nil {
http.Error(w, fmt.Sprintf("Failed to get disk usage for %s: %v", h.scheduler.defaultBackend.Name(), err), http.StatusInternalServerError)
return
}
diskUsage := DiskUsage{modelsDiskUsage, defaultBackendDiskUsage}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(diskUsage); err != nil {
http.Error(w, fmt.Sprintf("Failed to encode response: %v", err), http.StatusInternalServerError)
return
}
}
// Unload unloads the specified runners (backend, model) from the backend.
// Currently, this doesn't work for runners that are handling an OpenAI request.
func (h *HTTPHandler) Unload(w http.ResponseWriter, r *http.Request) {
body, ok := readRequestBody(w, r, maximumOpenAIInferenceRequestSize)
if !ok {
return
}
var unloadRequest UnloadRequest
if err := json.Unmarshal(body, &unloadRequest); err != nil {
http.Error(w, "invalid request", http.StatusBadRequest)
return
}
unloadedRunners := UnloadResponse{h.scheduler.loader.Unload(r.Context(), unloadRequest)}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(unloadedRunners); err != nil {
http.Error(w, fmt.Sprintf("Failed to encode response: %v", err), http.StatusInternalServerError)
return
}
}
// installBackendRequest is the JSON body for the install-backend endpoint.
type installBackendRequest struct {
Backend string `json:"backend"`
}
// InstallBackend handles POST <inference-prefix>/install-backend requests.
// It triggers on-demand installation of a deferred backend.
func (h *HTTPHandler) InstallBackend(w http.ResponseWriter, r *http.Request) {
body, ok := readRequestBody(w, r, maximumOpenAIInferenceRequestSize)
if !ok {
return
}
var req installBackendRequest
if err := json.Unmarshal(body, &req); err != nil || req.Backend == "" {
http.Error(w, "invalid request: backend is required", http.StatusBadRequest)
return
}
if err := h.scheduler.InstallBackend(r.Context(), req.Backend); err != nil {
if errors.Is(err, ErrBackendNotFound) {
http.Error(w, err.Error(), http.StatusNotFound)
} else {
http.Error(w, fmt.Sprintf("backend installation failed: %v", err), http.StatusInternalServerError)
}
return
}
w.WriteHeader(http.StatusOK)
}
// uninstallBackendRequest is the JSON body for the uninstall-backend endpoint.
type uninstallBackendRequest struct {
Backend string `json:"backend"`
}
// UninstallBackend handles POST <inference-prefix>/uninstall-backend requests.
// It removes a backend's local installation.
func (h *HTTPHandler) UninstallBackend(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, maximumOpenAIInferenceRequestSize))
if err != nil {
var maxBytesError *http.MaxBytesError
if errors.As(err, &maxBytesError) {
http.Error(w, "request too large", http.StatusBadRequest)
} else {
http.Error(w, "failed to read request body", http.StatusInternalServerError)
}
return
}
var req uninstallBackendRequest
if err := json.Unmarshal(body, &req); err != nil || req.Backend == "" {
http.Error(w, "invalid request: backend is required", http.StatusBadRequest)
return
}
if err := h.scheduler.UninstallBackend(r.Context(), req.Backend); err != nil {
if errors.Is(err, ErrBackendNotFound) {
http.Error(w, err.Error(), http.StatusNotFound)
} else {
http.Error(w, fmt.Sprintf("backend uninstall failed: %v", err), http.StatusInternalServerError)
}
return
}
w.WriteHeader(http.StatusOK)
}
// Configure handles POST <inference-prefix>/{backend}/_configure requests.
func (h *HTTPHandler) Configure(w http.ResponseWriter, r *http.Request) {
// Determine the requested backend and ensure that it's valid.
var backend inference.Backend
var err error
if b := r.PathValue("backend"); b == "" {
backend = h.scheduler.defaultBackend
} else {
backend = h.scheduler.backends[b]
}
if backend == nil {
http.Error(w, ErrBackendNotFound.Error(), http.StatusNotFound)
return
}
body, ok := readRequestBody(w, r, maximumOpenAIInferenceRequestSize)
if !ok {
return
}
configureRequest := ConfigureRequest{
BackendConfiguration: inference.BackendConfiguration{},
}
if err := json.Unmarshal(body, &configureRequest); err != nil {
http.Error(w, "invalid request", http.StatusBadRequest)
return
}
backend, err = h.scheduler.ConfigureRunner(r.Context(), backend, configureRequest, r.UserAgent())
if err != nil {
if errors.Is(err, errRunnerAlreadyActive) {
http.Error(w, err.Error(), http.StatusConflict)
} else {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
return
}
// Preload the model in the background by calling handleOpenAIInference with preload-only context.
// This makes Compose preload the model as well as it calls `configure` by default.
go func() {
preloadBody, err := json.Marshal(OpenAIInferenceRequest{Model: configureRequest.Model})
if err != nil {
h.scheduler.log.Warn("failed to marshal preload request body", "error", err)
return
}
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
preloadReq, err := http.NewRequestWithContext(
context.WithValue(ctx, preloadOnlyKey, true),
http.MethodPost,
inference.InferencePrefix+"/v1/chat/completions",
bytes.NewReader(preloadBody),
)
if err != nil {
h.scheduler.log.Warn("failed to create preload request", "error", err)
return
}
preloadReq.Header.Set("User-Agent", r.UserAgent())
if backend != nil {
preloadReq.SetPathValue("backend", backend.Name())
}
recorder := httptest.NewRecorder()
h.handleOpenAIInference(recorder, preloadReq)
if recorder.Code != http.StatusOK {
h.scheduler.log.Warn("background model preload failed", "status", recorder.Code, "body", recorder.Body.String())
}
}()
w.WriteHeader(http.StatusAccepted)
}
// GetModelConfigs returns model configurations. If a model is specified in the query parameter,
// returns only configs for that model; otherwise returns all configs.
func (h *HTTPHandler) GetModelConfigs(w http.ResponseWriter, r *http.Request) {
model := r.URL.Query().Get("model")
configs := h.scheduler.loader.getAllRunnerConfigs(r.Context())
if model != "" {
modelID := h.scheduler.modelManager.ResolveID(model)
filtered := configs[:0]
for _, entry := range configs {
if entry.ModelID == modelID {
filtered = append(filtered, entry)
}
}
configs = filtered
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(configs); err != nil {
http.Error(w, fmt.Sprintf("Failed to encode response: %v", err), http.StatusInternalServerError)
return
}
}
// GetModelBackend resolves the backend selected by the scheduler for the provided model.
func (h *HTTPHandler) GetModelBackend(w http.ResponseWriter, r *http.Request) {
modelRef := r.URL.Query().Get("model")
if modelRef == "" {
http.Error(w, "model is required", http.StatusBadRequest)
return
}
backend, err := h.scheduler.ResolveBackendForModel(r.Context(), modelRef)
if err != nil {
http.Error(w, fmt.Sprintf("failed to resolve backend: %v", err), http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(ModelBackendSelection{
Backend: backend.Name(),
Installed: h.scheduler.installer.isInstalled(backend.Name()),
}); err != nil {
http.Error(w, fmt.Sprintf("Failed to encode response: %v", err), http.StatusInternalServerError)
return
}
}
// ServeHTTP implements net/http.Handler.ServeHTTP.
func (h *HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.lock.RLock()
defer h.lock.RUnlock()
h.httpHandler.ServeHTTP(w, r)
}
// RebuildRoutes updates the HTTP routes with new allowed origins.
func (h *HTTPHandler) RebuildRoutes(allowedOrigins []string) {
h.lock.Lock()
defer h.lock.Unlock()
// Update handlers that depend on the allowed origins.
h.httpHandler = middleware.CorsMiddleware(allowedOrigins, h.router)
}
// GetLlamaCppSocket delegates to the scheduler's business logic.
// Required by metrics.SchedulerInterface.
func (h *HTTPHandler) GetLlamaCppSocket() (string, error) {
return h.scheduler.GetLlamaCppSocket()
}
// GetAllActiveRunners delegates to the scheduler's business logic.
// Required by metrics.SchedulerInterface.
func (h *HTTPHandler) GetAllActiveRunners() []metrics.ActiveRunner {
return h.scheduler.GetAllActiveRunners()
}