distributed research fully operationnal
This commit is contained in:
@@ -24,12 +24,12 @@ var comp_dt = tools.COMPUTE_RESOURCE
|
||||
// @Success 200 {compute} models.compute
|
||||
// @router /:id [put]
|
||||
func (o *ComputeController) Put() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
// store and return Id or post with UUID
|
||||
var res map[string]interface{}
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
||||
data := oclib.NewRequest(comp_collection, user, peerID, groups, nil).UpdateOne(res, id)
|
||||
data := oclib.NewRequestAdmin(comp_collection, nil).UpdateOne(res, id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, tools.PropalgationMessage{
|
||||
@@ -96,9 +96,9 @@ func (o *ComputeController) Search() {
|
||||
// @Success 200 {compute} models.compute
|
||||
// @router /:id [get]
|
||||
func (o *ComputeController) Get() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
// user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
o.Data["json"] = oclib.NewRequest(comp_collection, user, peerID, groups, nil).LoadOne(id)
|
||||
o.Data["json"] = oclib.NewRequestAdmin(comp_collection, nil).LoadOne(id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
@@ -122,34 +122,3 @@ func (o *ComputeController) Delete() {
|
||||
o.Data["json"] = oclib.NewRequest(comp_collection, user, peerID, groups, nil).DeleteOne(id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Search Decentralized
|
||||
// @Description find workflow by key word
|
||||
// @Param search path string true "the search you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {workflow} models.workflow
|
||||
// @router /decentralized/:type/search/:search[get]
|
||||
func (o *ComputeController) SearchDecentralized() {
|
||||
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
t := o.Ctx.Input.Param(":type")
|
||||
b, err := json.Marshal(map[string]string{
|
||||
"search": search,
|
||||
"type": t,
|
||||
})
|
||||
infrastructure.EmitNATS(user, tools.PropalgationMessage{
|
||||
Action: tools.PB_SEARCH,
|
||||
DataType: comp_dt.EnumIndex(),
|
||||
Payload: b,
|
||||
})
|
||||
if err != nil {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
"code": 400,
|
||||
"error": err,
|
||||
}
|
||||
o.ServeJSON()
|
||||
return
|
||||
}
|
||||
Websocket(o.Ctx.Request.Context(), user, o.Ctx.ResponseWriter, o.Ctx.Request)
|
||||
}
|
||||
|
||||
@@ -123,34 +123,3 @@ func (o *DataController) Delete() {
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Search Decentralized
|
||||
// @Description find workflow by key word
|
||||
// @Param search path string true "the search you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {workflow} models.workflow
|
||||
// @router /decentralized/:type/search/:search[get]
|
||||
func (o *DataController) SearchDecentralized() {
|
||||
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
t := o.Ctx.Input.Param(":type")
|
||||
b, err := json.Marshal(map[string]string{
|
||||
"search": search,
|
||||
"type": t,
|
||||
})
|
||||
infrastructure.EmitNATS(user, tools.PropalgationMessage{
|
||||
Action: tools.PB_SEARCH,
|
||||
DataType: data_dt.EnumIndex(),
|
||||
Payload: b,
|
||||
})
|
||||
if err != nil {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
"code": 400,
|
||||
"error": err,
|
||||
}
|
||||
o.ServeJSON()
|
||||
return
|
||||
}
|
||||
Websocket(o.Ctx.Request.Context(), user, o.Ctx.ResponseWriter, o.Ctx.Request)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
cx "context"
|
||||
"net/http"
|
||||
"oc-catalog/infrastructure"
|
||||
|
||||
@@ -9,7 +8,6 @@ import (
|
||||
w "cloud.o-forge.io/core/oc-lib/models/workflow"
|
||||
tools "cloud.o-forge.io/core/oc-lib/tools"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
"github.com/beego/beego/v2/server/web/context"
|
||||
"golang.org/x/net/websocket"
|
||||
)
|
||||
|
||||
@@ -62,13 +60,13 @@ func (o *GeneralController) GetAll() {
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
func Websocket(ctx cx.Context, user string, r *context.Response, w *http.Request) {
|
||||
func Websocket(user string, w http.ResponseWriter, r *http.Request) {
|
||||
websocket.Handler(func(ws *websocket.Conn) {
|
||||
defer ws.Close()
|
||||
for {
|
||||
if msg, ok := <-infrastructure.SearchStream[user]; !ok || websocket.Message.Send(ws, msg) != nil {
|
||||
for msg := range infrastructure.SearchStream[user] {
|
||||
if websocket.JSON.Send(ws, msg) != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}).ServeHTTP(r, w)
|
||||
}).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"oc-catalog/infrastructure"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
@@ -25,11 +26,12 @@ var processing_dt = tools.PROCESSING_RESOURCE
|
||||
// @router /:id [put]
|
||||
func (o *ProcessingController) Put() {
|
||||
// store and return Id or post with UUID
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
var res map[string]interface{}
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
||||
data := oclib.NewRequest(processing_collection, user, peerID, groups, nil).UpdateOne(res, id)
|
||||
fmt.Println("Sqdqsqsd")
|
||||
data := oclib.NewRequestAdmin(processing_collection, nil).UpdateOne(res, id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, tools.PropalgationMessage{
|
||||
@@ -96,9 +98,9 @@ func (o *ProcessingController) Search() {
|
||||
// @Success 200 {processing} models.processing
|
||||
// @router /:id [get]
|
||||
func (o *ProcessingController) Get() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
// user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
o.Data["json"] = oclib.NewRequest(processing_collection, user, peerID, groups, nil).LoadOne(id)
|
||||
o.Data["json"] = oclib.NewRequestAdmin(processing_collection, nil).LoadOne(id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
@@ -122,34 +124,3 @@ func (o *ProcessingController) Delete() {
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Search Decentralized
|
||||
// @Description find workflow by key word
|
||||
// @Param search path string true "the search you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {workflow} models.workflow
|
||||
// @router /decentralized/:type/search/:search[get]
|
||||
func (o *ProcessingController) SearchDecentralized() {
|
||||
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
t := o.Ctx.Input.Param(":type")
|
||||
b, err := json.Marshal(map[string]string{
|
||||
"search": search,
|
||||
"type": t,
|
||||
})
|
||||
infrastructure.EmitNATS(user, tools.PropalgationMessage{
|
||||
Action: tools.PB_SEARCH,
|
||||
DataType: processing_dt.EnumIndex(),
|
||||
Payload: b,
|
||||
})
|
||||
if err != nil {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
"code": 400,
|
||||
"error": err,
|
||||
}
|
||||
o.ServeJSON()
|
||||
return
|
||||
}
|
||||
Websocket(o.Ctx.Request.Context(), user, o.Ctx.ResponseWriter, o.Ctx.Request)
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"oc-catalog/infrastructure"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
@@ -86,34 +83,3 @@ func (o *ResourceController) Get() {
|
||||
o.Data["json"] = map[string]interface{}{"data": results, "code": 200, "error": ""}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Search Decentralized
|
||||
// @Description find workflow by key word
|
||||
// @Param search path string true "the search you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {workflow} models.workflow
|
||||
// @router /decentralized/:type/search/:search [get]
|
||||
func (o *ResourceController) SearchDecentralized() {
|
||||
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
t := o.Ctx.Input.Param(":type")
|
||||
b, err := json.Marshal(map[string]string{
|
||||
"search": search,
|
||||
"type": t,
|
||||
})
|
||||
infrastructure.EmitNATS(user, tools.PropalgationMessage{
|
||||
Action: tools.PB_SEARCH,
|
||||
DataType: -1,
|
||||
Payload: b,
|
||||
})
|
||||
if err != nil {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
"code": 400,
|
||||
"error": err,
|
||||
}
|
||||
o.ServeJSON()
|
||||
return
|
||||
}
|
||||
Websocket(o.Ctx.Request.Context(), user, o.Ctx.ResponseWriter, o.Ctx.Request)
|
||||
}
|
||||
|
||||
@@ -122,34 +122,3 @@ func (o *StorageController) Delete() {
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Search Decentralized
|
||||
// @Description find workflow by key word
|
||||
// @Param search path string true "the search you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {workflow} models.workflow
|
||||
// @router /decentralized/:type/search/:search[get]
|
||||
func (o *StorageController) SearchDecentralized() {
|
||||
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
t := o.Ctx.Input.Param(":type")
|
||||
b, err := json.Marshal(map[string]string{
|
||||
"search": search,
|
||||
"type": t,
|
||||
})
|
||||
infrastructure.EmitNATS(user, tools.PropalgationMessage{
|
||||
Action: tools.PB_SEARCH,
|
||||
DataType: storage_dt.EnumIndex(),
|
||||
Payload: b,
|
||||
})
|
||||
if err != nil {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
"code": 400,
|
||||
"error": err,
|
||||
}
|
||||
o.ServeJSON()
|
||||
return
|
||||
}
|
||||
Websocket(o.Ctx.Request.Context(), user, o.Ctx.ResponseWriter, o.Ctx.Request)
|
||||
}
|
||||
|
||||
@@ -90,37 +90,6 @@ func (o *WorkflowController) Search() {
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Search Decentralized
|
||||
// @Description find workflow by key word
|
||||
// @Param search path string true "the search you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {workflow} models.workflow
|
||||
// @router /decentralized/:type/search/:search[get]
|
||||
func (o *WorkflowController) SearchDecentralized() {
|
||||
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
t := o.Ctx.Input.Param(":type")
|
||||
b, err := json.Marshal(map[string]string{
|
||||
"search": search,
|
||||
"type": t,
|
||||
})
|
||||
if err != nil {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
"code": 400,
|
||||
"error": err,
|
||||
}
|
||||
o.ServeJSON()
|
||||
return
|
||||
}
|
||||
infrastructure.EmitNATS(user, tools.PropalgationMessage{
|
||||
Action: tools.PB_SEARCH,
|
||||
DataType: workflow_dt.EnumIndex(),
|
||||
Payload: b,
|
||||
})
|
||||
Websocket(o.Ctx.Request.Context(), user, o.Ctx.ResponseWriter, o.Ctx.Request)
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find workflow by id
|
||||
// @Param id path string true "the id you want to get"
|
||||
|
||||
Reference in New Issue
Block a user