draft by
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"oc-scheduler/infrastructure"
|
||||
"strings"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
@@ -86,29 +87,19 @@ var wsUpgrader = gorillaws.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool { return true },
|
||||
}
|
||||
|
||||
// @Title CheckStream
|
||||
// @Description WebSocket stream of slot availability for a workflow.
|
||||
// After the handshake the client sends one JSON frame containing the
|
||||
// WorkflowSchedule parameters (start, end, booking_mode, duration_s, …).
|
||||
// The server responds with a CheckResult frame immediately and again each time
|
||||
// a planner for one of the workflow's storage/compute peers is updated.
|
||||
// When the stream is interrupted the cache entries for those peers are evicted
|
||||
// and a PB_CLOSE_PLANNER event is emitted on NATS.
|
||||
// Query params:
|
||||
// - as_possible=true ignore start date, search from now
|
||||
// - preemption=true validate anyway, raise warnings
|
||||
//
|
||||
// @Param id path string true "workflow id"
|
||||
// @Param as_possible query bool false "find nearest free slot from now"
|
||||
// @Param preemption query bool false "validate anyway, raise warnings"
|
||||
// @Success 101
|
||||
// @router /:id/check [get]
|
||||
func (o *WorkflowSchedulerController) CheckStream() {
|
||||
wfID := o.Ctx.Input.Param(":id")
|
||||
asap, _ := o.GetBool("as_possible", false)
|
||||
preemption, _ := o.GetBool("preemption", false)
|
||||
// CheckStreamHandler is a plain http.HandlerFunc (registered via beego.Handler
|
||||
// to avoid Beego's WriteHeader interference with the WebSocket upgrade).
|
||||
// Path: /oc/:id/check → parts = ["", "oc", "<id>", "check"]
|
||||
// Query params: as_possible=true, preemption=true
|
||||
func CheckStreamHandler(w http.ResponseWriter, r *http.Request) {
|
||||
parts := strings.Split(strings.TrimSuffix(r.URL.Path, "/"), "/")
|
||||
wfID := parts[len(parts)-2] // second-to-last segment
|
||||
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
q := r.URL.Query()
|
||||
asap := q.Get("as_possible") == "true"
|
||||
preemption := q.Get("preemption") == "true"
|
||||
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*r)
|
||||
req := &tools.APIRequest{
|
||||
Username: user,
|
||||
PeerID: peerID,
|
||||
@@ -120,15 +111,16 @@ func (o *WorkflowSchedulerController) CheckStream() {
|
||||
// Resolve the peer IDs concerned by this workflow before upgrading so we
|
||||
// can abort cleanly with a plain HTTP error if the workflow is not found.
|
||||
watchedPeers, err := infrastructure.GetWorkflowPeerIDs(wfID, req)
|
||||
fmt.Println("Here my watched peers involved in workflow", watchedPeers)
|
||||
if err != nil {
|
||||
o.Data["json"] = map[string]interface{}{"code": 404, "error": err.Error()}
|
||||
o.ServeJSON()
|
||||
http.Error(w, `{"code":404,"error":"`+err.Error()+`"}`, http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
// Upgrade to WebSocket.
|
||||
conn, err := wsUpgrader.Upgrade(o.Ctx.ResponseWriter, o.Ctx.Request, nil)
|
||||
conn, err := wsUpgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
// gorilla already wrote the error response
|
||||
return
|
||||
}
|
||||
|
||||
@@ -162,6 +154,7 @@ func (o *WorkflowSchedulerController) CheckStream() {
|
||||
|
||||
push := func() error {
|
||||
result, checkErr := ws.Check(wfID, asap, preemption, req)
|
||||
fmt.Println(result, checkErr)
|
||||
if checkErr != nil {
|
||||
return checkErr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user