distributed research fully operationnal

This commit is contained in:
mr
2026-03-05 13:58:47 +01:00
parent dcd4bd497e
commit d8e3ca4c47
13 changed files with 305 additions and 267 deletions

View File

@@ -8,11 +8,38 @@
package routers
import (
"encoding/json"
"net/http"
"oc-catalog/controllers"
"oc-catalog/infrastructure"
"strings"
oclib "cloud.o-forge.io/core/oc-lib"
"cloud.o-forge.io/core/oc-lib/tools"
beego "github.com/beego/beego/v2/server/web"
)
// wsSearchHandler retourne un http.HandlerFunc qui émet un message NATS puis ouvre la connexion WS.
// dataType == -1 signifie toutes les ressources (ResourceController).
func wsSearchHandler(dataType int) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
parts := strings.Split(strings.TrimSuffix(r.URL.Path, "/"), "/")
search := parts[len(parts)-1]
t := ""
if len(parts) >= 3 {
t = parts[len(parts)-3]
}
user, _, _ := oclib.ExtractTokenInfo(*r)
b, _ := json.Marshal(map[string]string{"search": search, "type": t})
infrastructure.EmitNATS(user, tools.PropalgationMessage{
Action: tools.PB_SEARCH,
DataType: dataType,
Payload: b,
})
controllers.Websocket(user, w, r)
}
}
func init() {
ns := beego.NewNamespace("/oc/",
beego.NSNamespace("/generic",
@@ -67,4 +94,12 @@ func init() {
),
)
beego.AddNamespace(ns)
// Routes WebSocket hors du pipeline Beego (évite le WriteHeader parasite)
beego.Handler("/oc/resource/decentralized/:type/search/:search", wsSearchHandler(-1))
beego.Handler("/oc/compute/decentralized/:type/search/:search", wsSearchHandler(tools.COMPUTE_RESOURCE.EnumIndex()))
beego.Handler("/oc/data/decentralized/:type/search/:search", wsSearchHandler(tools.DATA_RESOURCE.EnumIndex()))
beego.Handler("/oc/processing/decentralized/:type/search/:search", wsSearchHandler(tools.PROCESSING_RESOURCE.EnumIndex()))
beego.Handler("/oc/storage/decentralized/:type/search/:search", wsSearchHandler(tools.STORAGE_RESOURCE.EnumIndex()))
beego.Handler("/oc/workflow/decentralized/:type/search/:search", wsSearchHandler(tools.WORKFLOW_RESOURCE.EnumIndex()))
}