Discovery Nats Related
This commit is contained in:
@@ -32,7 +32,12 @@ func (o *ComputeController) Put() {
|
||||
data := oclib.NewRequest(comp_collection, user, peerID, groups, nil).UpdateOne(res, id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.UpdatePublishEvent(o.Ctx.Request.Context(), &comp_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_UPDATE,
|
||||
DataType: comp_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
@@ -50,7 +55,12 @@ func (o *ComputeController) Post() {
|
||||
data := oclib.NewRequest(comp_collection, user, peerID, groups, nil).StoreOne(res)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.CreatePublishEvent(o.Ctx.Request.Context(), &comp_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_CREATE,
|
||||
DataType: comp_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
@@ -105,7 +115,12 @@ func (o *ComputeController) Delete() {
|
||||
data := oclib.NewRequest(comp_collection, user, peerID, groups, nil).DeleteOne(id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.DeletePublishEvent(o.Ctx.Request.Context(), &comp_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_DELETE,
|
||||
DataType: comp_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = oclib.NewRequest(comp_collection, user, peerID, groups, nil).DeleteOne(id)
|
||||
o.ServeJSON()
|
||||
@@ -121,7 +136,16 @@ func (o *ComputeController) SearchDecentralized() {
|
||||
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
t := o.Ctx.Input.Param(":type")
|
||||
err := infrastructure.Singleton.SearchPublishEvent(o.Ctx.Request.Context(), &comp_dt, t, user, search)
|
||||
b, err := json.Marshal(map[string]string{
|
||||
"search": search,
|
||||
"type": t,
|
||||
})
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_SEARCH,
|
||||
DataType: comp_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: b,
|
||||
})
|
||||
if err != nil {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
|
||||
@@ -32,7 +32,12 @@ func (o *DataController) Put() {
|
||||
data := oclib.NewRequest(data_collection, user, peerID, groups, nil).UpdateOne(res, id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.UpdatePublishEvent(o.Ctx.Request.Context(), &data_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_UPDATE,
|
||||
DataType: data_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
@@ -50,7 +55,12 @@ func (o *DataController) Post() {
|
||||
data := oclib.NewRequest(data_collection, user, peerID, groups, nil).StoreOne(res)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.CreatePublishEvent(o.Ctx.Request.Context(), &data_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_CREATE,
|
||||
DataType: data_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
@@ -106,7 +116,12 @@ func (o *DataController) Delete() {
|
||||
data := oclib.NewRequest(data_collection, user, peerID, groups, nil).DeleteOne(id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.DeletePublishEvent(o.Ctx.Request.Context(), &data_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_DELETE,
|
||||
DataType: data_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
@@ -122,7 +137,16 @@ func (o *DataController) SearchDecentralized() {
|
||||
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
t := o.Ctx.Input.Param(":type")
|
||||
err := infrastructure.Singleton.SearchPublishEvent(o.Ctx.Request.Context(), &data_dt, t, user, search)
|
||||
b, err := json.Marshal(map[string]string{
|
||||
"search": search,
|
||||
"type": t,
|
||||
})
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_SEARCH,
|
||||
DataType: data_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: b,
|
||||
})
|
||||
if err != nil {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
|
||||
@@ -66,7 +66,7 @@ func Websocket(ctx cx.Context, user string, r *context.Response, w *http.Request
|
||||
websocket.Handler(func(ws *websocket.Conn) {
|
||||
defer ws.Close()
|
||||
for {
|
||||
if msg, ok := <-infrastructure.Singleton.SearchStream[user]; !ok || websocket.Message.Send(ws, msg) != nil {
|
||||
if msg, ok := <-infrastructure.SearchStream[user]; !ok || websocket.Message.Send(ws, msg) != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,12 @@ func (o *ProcessingController) Put() {
|
||||
data := oclib.NewRequest(processing_collection, user, peerID, groups, nil).UpdateOne(res, id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.UpdatePublishEvent(o.Ctx.Request.Context(), &processing_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_UPDATE,
|
||||
DataType: processing_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
@@ -50,7 +55,12 @@ func (o *ProcessingController) Post() {
|
||||
data := oclib.NewRequest(processing_collection, user, peerID, groups, nil).StoreOne(res)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.CreatePublishEvent(o.Ctx.Request.Context(), &processing_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_CREATE,
|
||||
DataType: processing_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
@@ -105,7 +115,12 @@ func (o *ProcessingController) Delete() {
|
||||
data := oclib.NewRequest(processing_collection, user, peerID, groups, nil).DeleteOne(id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.DeletePublishEvent(o.Ctx.Request.Context(), &processing_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_DELETE,
|
||||
DataType: processing_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
@@ -121,7 +136,16 @@ func (o *ProcessingController) SearchDecentralized() {
|
||||
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
t := o.Ctx.Input.Param(":type")
|
||||
err := infrastructure.Singleton.SearchPublishEvent(o.Ctx.Request.Context(), &processing_dt, t, user, search)
|
||||
b, err := json.Marshal(map[string]string{
|
||||
"search": search,
|
||||
"type": t,
|
||||
})
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_SEARCH,
|
||||
DataType: processing_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: b,
|
||||
})
|
||||
if err != nil {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
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"
|
||||
)
|
||||
|
||||
@@ -95,7 +97,16 @@ func (o *ResourceController) SearchDecentralized() {
|
||||
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
t := o.Ctx.Input.Param(":type")
|
||||
err := infrastructure.Singleton.SearchPublishEvent(o.Ctx.Request.Context(), nil, t, user, search)
|
||||
b, err := json.Marshal(map[string]string{
|
||||
"search": search,
|
||||
"type": t,
|
||||
})
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_SEARCH,
|
||||
DataType: -1,
|
||||
User: user,
|
||||
Payload: b,
|
||||
})
|
||||
if err != nil {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
|
||||
@@ -32,7 +32,12 @@ func (o *StorageController) Put() {
|
||||
data := oclib.NewRequest(storage_collection, user, peerID, groups, nil).UpdateOne(res, id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.UpdatePublishEvent(o.Ctx.Request.Context(), &storage_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_UPDATE,
|
||||
DataType: storage_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
@@ -50,7 +55,12 @@ func (o *StorageController) Post() {
|
||||
data := oclib.NewRequest(storage_collection, user, peerID, groups, nil).StoreOne(res)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.CreatePublishEvent(o.Ctx.Request.Context(), &storage_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_CREATE,
|
||||
DataType: storage_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
@@ -105,7 +115,12 @@ func (o *StorageController) Delete() {
|
||||
data := oclib.NewRequest(storage_collection, user, peerID, groups, nil).DeleteOne(id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.DeletePublishEvent(o.Ctx.Request.Context(), &storage_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_DELETE,
|
||||
DataType: storage_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
@@ -121,7 +136,16 @@ func (o *StorageController) SearchDecentralized() {
|
||||
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
t := o.Ctx.Input.Param(":type")
|
||||
err := infrastructure.Singleton.SearchPublishEvent(o.Ctx.Request.Context(), &storage_dt, t, user, search)
|
||||
b, err := json.Marshal(map[string]string{
|
||||
"search": search,
|
||||
"type": t,
|
||||
})
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_SEARCH,
|
||||
DataType: storage_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: b,
|
||||
})
|
||||
if err != nil {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
|
||||
@@ -32,7 +32,12 @@ func (o *WorkflowController) Put() {
|
||||
data := oclib.NewRequest(workflow_collection, user, peerID, groups, nil).UpdateOne(res, id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.UpdatePublishEvent(o.Ctx.Request.Context(), &workflow_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_UPDATE,
|
||||
Payload: data,
|
||||
DataType: workflow_dt.EnumIndex(),
|
||||
User: user,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
@@ -50,7 +55,12 @@ func (o *WorkflowController) Post() {
|
||||
data := oclib.NewRequest(workflow_collection, user, peerID, groups, nil).StoreOne(res)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.CreatePublishEvent(o.Ctx.Request.Context(), &workflow_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_CREATE,
|
||||
DataType: workflow_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
@@ -92,7 +102,10 @@ func (o *WorkflowController) SearchDecentralized() {
|
||||
user, _, _ := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
t := o.Ctx.Input.Param(":type")
|
||||
err := infrastructure.Singleton.SearchPublishEvent(o.Ctx.Request.Context(), &workflow_dt, t, user, search)
|
||||
b, err := json.Marshal(map[string]string{
|
||||
"search": search,
|
||||
"type": t,
|
||||
})
|
||||
if err != nil {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
@@ -102,6 +115,12 @@ func (o *WorkflowController) SearchDecentralized() {
|
||||
o.ServeJSON()
|
||||
return
|
||||
}
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
Action: tools.PB_SEARCH,
|
||||
DataType: workflow_dt.EnumIndex(),
|
||||
User: user,
|
||||
Payload: b,
|
||||
})
|
||||
Websocket(o.Ctx.Request.Context(), user, o.Ctx.ResponseWriter, o.Ctx.Request)
|
||||
}
|
||||
|
||||
@@ -128,7 +147,12 @@ func (o *WorkflowController) Delete() {
|
||||
data := oclib.NewRequest(workflow_collection, user, peerID, groups, nil).DeleteOne(id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.Singleton.DeletePublishEvent(o.Ctx.Request.Context(), &workflow_dt, user, data)
|
||||
infrastructure.EmitNATS(tools.PropalgationMessage{
|
||||
DataType: workflow_dt.EnumIndex(),
|
||||
Action: tools.PB_DELETE,
|
||||
User: user,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
|
||||
Reference in New Issue
Block a user