Simplify but Complete Catalog
This commit is contained in:
@@ -1,124 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Operations about compute
|
||||
type ComputeController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
var comp_collection = oclib.LibDataEnum(oclib.COMPUTE_RESOURCE)
|
||||
var comp_dt = tools.COMPUTE_RESOURCE
|
||||
|
||||
// @Title Update
|
||||
// @Description create computes
|
||||
// @Param id path string true "the compute id you want to get"
|
||||
// @Param body body models.compute true "The compute content"
|
||||
// @Success 200 {compute} models.compute
|
||||
// @router /:id [put]
|
||||
func (o *ComputeController) Put() {
|
||||
user, _, groups := 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.NewRequestAdmin(comp_collection, nil).UpdateOne(res, id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_UPDATE,
|
||||
DataType: comp_dt.EnumIndex(),
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Create
|
||||
// @Description create compute
|
||||
// @Param compute body json true "body for compute content (Json format)"
|
||||
// @Success 200 {compute} models.compute
|
||||
// @router / [post]
|
||||
func (o *ComputeController) Post() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
var res map[string]interface{}
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
||||
data := oclib.NewRequest(comp_collection, user, peerID, groups, nil).StoreOne(res)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_CREATE,
|
||||
DataType: comp_dt.EnumIndex(),
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description find compute by id
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {compute} models.compute
|
||||
// @router / [get]
|
||||
func (o *ComputeController) GetAll() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
o.Data["json"] = oclib.NewRequest(comp_collection, user, peerID, groups, nil).LoadAll(isDraft == "true")
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find compute by key word
|
||||
// @Param search path string true "the search you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {compute} models.compute
|
||||
// @router /search/:search [get]
|
||||
func (o *ComputeController) Search() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
o.Data["json"] = oclib.NewRequest(comp_collection, user, peerID, groups, nil).Search(nil, search, isDraft == "true")
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find compute by id
|
||||
// @Param id path string true "the id you want to get"
|
||||
// @Success 200 {compute} models.compute
|
||||
// @router /:id [get]
|
||||
func (o *ComputeController) Get() {
|
||||
// user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
o.Data["json"] = oclib.NewRequestAdmin(comp_collection, nil).LoadOne(id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Delete
|
||||
// @Description delete the compute
|
||||
// @Param id path string true "The id you want to delete"
|
||||
// @Success 200 {compute} delete success!
|
||||
// @router /:id [delete]
|
||||
func (o *ComputeController) Delete() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
data := oclib.NewRequest(comp_collection, user, peerID, groups, nil).DeleteOne(id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_DELETE,
|
||||
DataType: comp_dt.EnumIndex(),
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = oclib.NewRequest(comp_collection, user, peerID, groups, nil).DeleteOne(id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Operations about data
|
||||
type DataController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
var data_collection = oclib.LibDataEnum(oclib.DATA_RESOURCE)
|
||||
var data_dt = tools.DATA_RESOURCE
|
||||
|
||||
// @Title Update
|
||||
// @Description create datas
|
||||
// @Param id path string true "the data id you want to get"
|
||||
// @Param body body models.data true "The data content"
|
||||
// @Success 200 {data} models.data
|
||||
// @router /:id [put]
|
||||
func (o *DataController) Put() {
|
||||
// store and return Id or post with UUID
|
||||
user, peerID, groups := 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(data_collection, user, peerID, groups, nil).UpdateOne(res, id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_UPDATE,
|
||||
DataType: data_dt.EnumIndex(),
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Create
|
||||
// @Description create data
|
||||
// @Param data body json true "body for data content (Json format)"
|
||||
// @Success 200 {data} models.data
|
||||
// @router / [post]
|
||||
func (o *DataController) Post() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
var res map[string]interface{}
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
||||
data := oclib.NewRequest(data_collection, user, peerID, groups, nil).StoreOne(res)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_CREATE,
|
||||
DataType: data_dt.EnumIndex(),
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description find data by id
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {data} models.data
|
||||
// @router / [get]
|
||||
func (o *DataController) GetAll() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
o.Data["json"] = oclib.NewRequest(data_collection, user, peerID, groups, nil).LoadAll(isDraft == "true")
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find data by key word
|
||||
// @Param search path string true "the search you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
|
||||
// @Success 200 {data} models.data
|
||||
// @router /search/:search [get]
|
||||
func (o *DataController) Search() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
o.Data["json"] = oclib.NewRequest(data_collection, user, peerID, groups, nil).Search(nil, search, isDraft == "true")
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find data by id
|
||||
// @Param id path string true "the id you want to get"
|
||||
// @Success 200 {data} models.data
|
||||
// @router /:id [get]
|
||||
func (o *DataController) Get() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
o.Data["json"] = oclib.NewRequest(data_collection, user, peerID, groups, nil).LoadOne(id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Delete
|
||||
// @Description delete the data
|
||||
// @Param id path string true "The id you want to delete"
|
||||
// @Success 200 {data} delete success!
|
||||
// @router /:id [delete]
|
||||
func (o *DataController) Delete() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
data := oclib.NewRequest(data_collection, user, peerID, groups, nil).DeleteOne(id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_DELETE,
|
||||
DataType: data_dt.EnumIndex(),
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
@@ -2,15 +2,15 @@ package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"oc-catalog/infrastructure"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
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"
|
||||
"golang.org/x/net/websocket"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
// Operations about compute
|
||||
@@ -63,47 +63,49 @@ func (o *GeneralController) GetAll() {
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
func Websocket(ctx context.Context, user string, groups []string, dataType int, r http.ResponseWriter, w *http.Request) {
|
||||
websocket.Handler(func(ws *websocket.Conn) {
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
var discard interface{}
|
||||
for {
|
||||
if websocket.JSON.Receive(ws, &discard) != nil {
|
||||
close(done)
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
ws.Close()
|
||||
if ch, ok := infrastructure.SearchStream[user]; ok {
|
||||
close(ch)
|
||||
infrastructure.SearchMu.Lock()
|
||||
delete(infrastructure.SearchStream, user)
|
||||
infrastructure.SearchMu.Unlock()
|
||||
}
|
||||
fmt.Println("CLOSE !")
|
||||
infrastructure.EmitNATS(user, nil, tools.PropalgationMessage{
|
||||
Action: tools.PB_CLOSE_SEARCH,
|
||||
DataType: dataType,
|
||||
})
|
||||
}()
|
||||
func Websocket(ctx context.Context, user string, groups []string, dataType int, conn *websocket.Conn) {
|
||||
defer conn.Close()
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
var discard interface{}
|
||||
for {
|
||||
select {
|
||||
case msg, ok := <-infrastructure.SearchStream[user]:
|
||||
fmt.Println("FOR", msg, ok)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if websocket.JSON.Send(ws, msg) != nil {
|
||||
continue
|
||||
}
|
||||
case <-done:
|
||||
return
|
||||
case <-ctx.Done():
|
||||
if err := conn.ReadJSON(&discard); err != nil {
|
||||
close(done)
|
||||
return
|
||||
}
|
||||
}
|
||||
}).ServeHTTP(r, w)
|
||||
}()
|
||||
defer func() {
|
||||
if ch, ok := infrastructure.SearchStream[user]; ok {
|
||||
close(ch)
|
||||
infrastructure.SearchMu.Lock()
|
||||
delete(infrastructure.SearchStream, user)
|
||||
infrastructure.SearchMu.Unlock()
|
||||
}
|
||||
fmt.Println("CLOSE !")
|
||||
infrastructure.EmitNATS(user, nil, tools.PropalgationMessage{
|
||||
Action: tools.PB_CLOSE_SEARCH,
|
||||
DataType: dataType,
|
||||
})
|
||||
}()
|
||||
for {
|
||||
select {
|
||||
case msg, ok := <-infrastructure.SearchStream[user]:
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
m := map[string]interface{}{}
|
||||
if err := json.Unmarshal(msg, &m); err == nil {
|
||||
if err := conn.WriteJSON(m); err != nil {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
case <-done:
|
||||
return
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,126 +0,0 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// Operations about processing
|
||||
type ProcessingController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
var processing_collection = oclib.LibDataEnum(oclib.PROCESSING_RESOURCE)
|
||||
var processing_dt = tools.PROCESSING_RESOURCE
|
||||
|
||||
// @Title Update
|
||||
// @Description create processings
|
||||
// @Param id path string true "the processing id you want to get"
|
||||
// @Param body body models.processing true "The processing content"
|
||||
// @Success 200 {processing} models.processing
|
||||
// @router /:id [put]
|
||||
func (o *ProcessingController) Put() {
|
||||
// store and return Id or post with UUID
|
||||
user, _, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
var res map[string]interface{}
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
||||
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, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_UPDATE,
|
||||
DataType: processing_dt.EnumIndex(),
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Create
|
||||
// @Description create processing
|
||||
// @Param processing body json true "body for processing content (Json format)"
|
||||
// @Success 200 {processing} models.processing
|
||||
// @router / [post]
|
||||
func (o *ProcessingController) Post() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
var res map[string]interface{}
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
||||
data := oclib.NewRequest(processing_collection, user, peerID, groups, nil).StoreOne(res)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_CREATE,
|
||||
DataType: processing_dt.EnumIndex(),
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description find processing by id
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {processing} models.processing
|
||||
// @router / [get]
|
||||
func (o *ProcessingController) GetAll() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
o.Data["json"] = oclib.NewRequest(processing_collection, user, peerID, groups, nil).LoadAll(isDraft == "true")
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find processing by key word
|
||||
// @Param search path string true "the search you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {processing} models.processing
|
||||
// @router /search/:search [get]
|
||||
func (o *ProcessingController) Search() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
o.Data["json"] = oclib.NewRequest(processing_collection, user, peerID, groups, nil).Search(nil, search, isDraft == "true")
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find processing by id
|
||||
// @Param id path string true "the id you want to get"
|
||||
// @Success 200 {processing} models.processing
|
||||
// @router /:id [get]
|
||||
func (o *ProcessingController) Get() {
|
||||
// user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
o.Data["json"] = oclib.NewRequestAdmin(processing_collection, nil).LoadOne(id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Delete
|
||||
// @Description delete the processing
|
||||
// @Param id path string true "The id you want to delete"
|
||||
// @Success 200 {processing} delete success!
|
||||
// @router /:id [delete]
|
||||
func (o *ProcessingController) Delete() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
data := oclib.NewRequest(processing_collection, user, peerID, groups, nil).DeleteOne(id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_DELETE,
|
||||
DataType: processing_dt.EnumIndex(),
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
@@ -1,85 +1,221 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"oc-catalog/infrastructure"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// Operations about resource
|
||||
// ResourceController aggregates all resource types.
|
||||
type ResourceController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description find resource by id
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {resource} models.resource
|
||||
// @router / [get]
|
||||
func (o *ResourceController) GetAll() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
results := map[string]interface{}{}
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
for _, resource := range []oclib.LibDataEnum{
|
||||
data_collection, comp_collection, storage_collection,
|
||||
processing_collection, workflow_collection} {
|
||||
d := oclib.NewRequest(resource, user, peerID, groups, nil).LoadAll(isDraft == "true")
|
||||
if d.Code != 200 || len(d.Data) == 0 {
|
||||
results[resource.String()] = []interface{}{}
|
||||
} else {
|
||||
results[resource.String()] = d.Data
|
||||
}
|
||||
func resourceTypeEnum(t string, special bool) []oclib.LibDataEnum {
|
||||
e := []oclib.LibDataEnum{}
|
||||
if special && t == "resource" {
|
||||
return e
|
||||
}
|
||||
o.Data["json"] = map[string]interface{}{"data": results, "code": 200, "error": ""}
|
||||
if t == "compute" || t == "resource" {
|
||||
e = append(e, oclib.LibDataEnum(oclib.COMPUTE_RESOURCE))
|
||||
}
|
||||
if t == "data" || t == "resource" {
|
||||
e = append(e, oclib.LibDataEnum(oclib.DATA_RESOURCE))
|
||||
}
|
||||
if t == "storage" || t == "resource" {
|
||||
e = append(e, oclib.LibDataEnum(oclib.STORAGE_RESOURCE))
|
||||
}
|
||||
if t == "processing" || t == "resource" {
|
||||
e = append(e, oclib.LibDataEnum(oclib.PROCESSING_RESOURCE))
|
||||
}
|
||||
if t == "workflow" || t == "resource" {
|
||||
e = append(e, oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE))
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
func (o *ResourceController) collection(special bool) []oclib.LibDataEnum {
|
||||
// Extrait le type depuis le segment d'URL après "resource"
|
||||
// URL forme: /oc/resource/{type}/...
|
||||
typ := o.Ctx.Input.Param(":type")
|
||||
return resourceTypeEnum(typ, special)
|
||||
}
|
||||
|
||||
func (o *ResourceController) notFound() {
|
||||
o.Ctx.Output.SetStatus(404)
|
||||
o.Data["json"] = map[string]interface{}{"error": "unknown resource type", "code": 404, "data": nil}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find resource by key word
|
||||
// @Title GetAll
|
||||
// @Description list all resources across all types
|
||||
// @Param type path string true "the type you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {resource} models.resource
|
||||
// @router /:type [get]
|
||||
func (o *ResourceController) GetAll() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
|
||||
m := map[string][]utils.ShallowDBObject{}
|
||||
for _, col := range o.collection(false) {
|
||||
if m[col.String()] == nil {
|
||||
m[col.String()] = []utils.ShallowDBObject{}
|
||||
}
|
||||
s := oclib.NewRequest(col, user, peerID, groups, nil).LoadAll(isDraft == "true")
|
||||
m[col.String()] = append(m[col.String()], s.Data...)
|
||||
}
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": m,
|
||||
"code": 200,
|
||||
"err": nil,
|
||||
}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Search
|
||||
// @Description search resources across all types
|
||||
// @Param type path string true "the type you want to get"
|
||||
// @Param search path string true "the search you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {resource} models.resource
|
||||
// @router /search/:search [get]
|
||||
// @router /:type/search/:search [get]
|
||||
func (o *ResourceController) Search() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
results := map[string]interface{}{}
|
||||
for _, resource := range []oclib.LibDataEnum{
|
||||
data_collection, comp_collection, storage_collection,
|
||||
processing_collection, workflow_collection} {
|
||||
fmt.Println("search", search)
|
||||
d := oclib.NewRequest(resource, user, peerID, groups, nil).Search(nil, search, isDraft == "true")
|
||||
if d.Code != 200 || len(d.Data) == 0 {
|
||||
results[resource.String()] = []interface{}{}
|
||||
} else {
|
||||
results[resource.String()] = d.Data
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
|
||||
m := map[string][]utils.ShallowDBObject{}
|
||||
for _, col := range o.collection(false) {
|
||||
if m[col.String()] == nil {
|
||||
m[col.String()] = []utils.ShallowDBObject{}
|
||||
}
|
||||
s := oclib.NewRequest(col, user, peerID, groups, nil).Search(nil, search, isDraft == "true")
|
||||
m[col.String()] = append(m[col.String()], s.Data...)
|
||||
|
||||
}
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": m,
|
||||
"code": 200,
|
||||
"err": nil,
|
||||
}
|
||||
o.Data["json"] = map[string]interface{}{"data": results, "code": 200, "error": ""}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find resource by id
|
||||
// @Description search resources across all types
|
||||
// @Param type path string true "the type you want to get"
|
||||
// @Param id path string true "the id you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {resource} models.resource
|
||||
// @router /:id [get]
|
||||
// @router /:type/:id [get]
|
||||
func (o *ResourceController) Get() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
results := map[string]interface{}{}
|
||||
for _, resource := range []oclib.LibDataEnum{
|
||||
data_collection, comp_collection, storage_collection,
|
||||
processing_collection, workflow_collection} {
|
||||
d := oclib.NewRequest(resource, user, peerID, groups, nil).LoadOne(id)
|
||||
if d.Code != 200 {
|
||||
results[resource.String()] = nil
|
||||
|
||||
for _, col := range o.collection(false) {
|
||||
if d := oclib.NewRequest(col, user, peerID, groups, nil).LoadOne(id); d.Data != nil {
|
||||
o.Data["json"] = d
|
||||
break
|
||||
} else {
|
||||
results[resource.String()] = d.Data
|
||||
o.Data["json"] = d
|
||||
}
|
||||
}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Post
|
||||
// @Description search resources across all types
|
||||
// @Param type path string true "the type you want to get"
|
||||
// @Param data body json true "body for data content (Json format)"
|
||||
// @Success 200 {resource} models.resource
|
||||
// @router /:type [post]
|
||||
func (o *ResourceController) Post() {
|
||||
libs := o.collection(true)
|
||||
if len(libs) == 0 {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
"code": 500,
|
||||
"err": "not a proper type",
|
||||
}
|
||||
}
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
var res map[string]interface{}
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
||||
data := oclib.NewRequest(libs[0], user, peerID, groups, nil).StoreOne(res)
|
||||
if data.Err == "" {
|
||||
payload, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_CREATE,
|
||||
DataType: libs[0].EnumIndex(),
|
||||
Payload: payload,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Put
|
||||
// @Description search resources across all types
|
||||
// @Param type path string true "the type you want to get"
|
||||
// @Param id path string true "the id you want to get"
|
||||
// @Param data body json true "body for data content (Json format)"
|
||||
// @Success 200 {resource} models.resource
|
||||
// @router /:type/:id [put]
|
||||
func (o *ResourceController) Put() {
|
||||
libs := o.collection(true)
|
||||
if len(libs) == 0 {
|
||||
o.Data["json"] = map[string]interface{}{
|
||||
"data": nil,
|
||||
"code": 500,
|
||||
"err": "not a proper type",
|
||||
}
|
||||
}
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
var res map[string]interface{}
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
||||
data := oclib.NewRequest(libs[0], user, peerID, groups, nil).UpdateOne(res, id)
|
||||
if data.Err == "" {
|
||||
payload, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_UPDATE,
|
||||
DataType: libs[0].EnumIndex(),
|
||||
Payload: payload,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Delete
|
||||
// @Description search resources across all types
|
||||
// @Param type path string true "the type you want to get"
|
||||
// @Param id path string true "the id you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {resource} models.resource
|
||||
// @router /:type/:id [delete]
|
||||
func (o *ResourceController) Delete() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
for _, col := range o.collection(false) {
|
||||
data := oclib.NewRequest(col, user, peerID, groups, nil).DeleteOne(id)
|
||||
if data.Err == "" {
|
||||
o.Data["json"] = data
|
||||
payload, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_DELETE,
|
||||
DataType: col.EnumIndex(),
|
||||
Payload: payload,
|
||||
})
|
||||
break
|
||||
} else {
|
||||
o.Data["json"] = data
|
||||
}
|
||||
}
|
||||
o.Data["json"] = map[string]interface{}{"data": results, "code": 200, "error": ""}
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Operations about storage
|
||||
type StorageController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
var storage_collection = oclib.LibDataEnum(oclib.STORAGE_RESOURCE)
|
||||
var storage_dt = tools.STORAGE_RESOURCE
|
||||
|
||||
// @Title Update
|
||||
// @Description create storages
|
||||
// @Param id path string true "the storage id you want to get"
|
||||
// @Param body body models.storage true "The storage content"
|
||||
// @Success 200 {storage} models.storage
|
||||
// @router /:id [put]
|
||||
func (o *StorageController) Put() {
|
||||
// store and return Id or post with UUID
|
||||
user, peerID, groups := 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(storage_collection, user, peerID, groups, nil).UpdateOne(res, id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_UPDATE,
|
||||
DataType: storage_dt.EnumIndex(),
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Create
|
||||
// @Description create storage
|
||||
// @Param storage body json true "body for storage content (Json format)"
|
||||
// @Success 200 {storage} models.storage
|
||||
// @router / [post]
|
||||
func (o *StorageController) Post() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
var res map[string]interface{}
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
||||
data := oclib.NewRequest(storage_collection, user, peerID, groups, nil).StoreOne(res)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_CREATE,
|
||||
DataType: storage_dt.EnumIndex(),
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description find storage by id
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {storage} models.storage
|
||||
// @router / [get]
|
||||
func (o *StorageController) GetAll() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
o.Data["json"] = oclib.NewRequest(storage_collection, user, peerID, groups, nil).LoadAll(isDraft == "true")
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find storage by key word
|
||||
// @Param search path string true "the search you want to get"
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {storage} models.storage
|
||||
// @router /search/:search [get]
|
||||
func (o *StorageController) Search() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
o.Data["json"] = oclib.NewRequest(storage_collection, user, peerID, groups, nil).Search(nil, search, isDraft == "true")
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find storage by id
|
||||
// @Param id path string true "the id you want to get"
|
||||
// @Success 200 {storage} models.storage
|
||||
// @router /:id [get]
|
||||
func (o *StorageController) Get() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
o.Data["json"] = oclib.NewRequest(storage_collection, user, peerID, groups, nil).LoadOne(id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Delete
|
||||
// @Description delete the storage
|
||||
// @Param id path string true "The id you want to delete"
|
||||
// @Success 200 {storage} delete success!
|
||||
// @router /:id [delete]
|
||||
func (o *StorageController) Delete() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
data := oclib.NewRequest(storage_collection, user, peerID, groups, nil).DeleteOne(id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_DELETE,
|
||||
DataType: storage_dt.EnumIndex(),
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Operations about workflow
|
||||
type WorkflowController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
var workflow_collection = oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE)
|
||||
var workflow_dt = tools.WORKFLOW_RESOURCE
|
||||
|
||||
// @Title Update
|
||||
// @Description create workflows
|
||||
// @Param id path string true "the workflow id you want to get"
|
||||
// @Param body body models.workflow true "The workflow content"
|
||||
// @Success 200 {workflow} models.workflow
|
||||
// @router /:id [put]
|
||||
func (o *WorkflowController) Put() {
|
||||
// store and return Id or post with UUID
|
||||
user, peerID, groups := 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(workflow_collection, user, peerID, groups, nil).UpdateOne(res, id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_UPDATE,
|
||||
Payload: data,
|
||||
DataType: workflow_dt.EnumIndex(),
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Create
|
||||
// @Description create workflow
|
||||
// @Param workflow body json true "body for workflow content (Json format)"
|
||||
// @Success 200 {workflow} models.workflow
|
||||
// @router / [post]
|
||||
func (o *WorkflowController) Post() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
var res map[string]interface{}
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
||||
data := oclib.NewRequest(workflow_collection, user, peerID, groups, nil).StoreOne(res)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
Action: tools.PB_CREATE,
|
||||
DataType: workflow_dt.EnumIndex(),
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description find workflow by id
|
||||
// @Param is_draft query string false "draft wished"
|
||||
// @Success 200 {workflow} models.workflow
|
||||
// @router / [get]
|
||||
func (o *WorkflowController) GetAll() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
o.Data["json"] = oclib.NewRequest(workflow_collection, user, peerID, groups, nil).LoadAll(isDraft == "true")
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Search
|
||||
// @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 /search/:search [get]
|
||||
func (o *WorkflowController) Search() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
isDraft := o.Ctx.Input.Query("is_draft")
|
||||
o.Data["json"] = oclib.NewRequest(workflow_collection, user, peerID, groups, nil).Search(nil, search, isDraft == "true")
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find workflow by id
|
||||
// @Param id path string true "the id you want to get"
|
||||
// @Success 200 {workflow} models.workflow
|
||||
// @router /:id [get]
|
||||
func (o *WorkflowController) Get() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
o.Data["json"] = oclib.NewRequest(workflow_collection, user, peerID, groups, nil).LoadOne(id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Delete
|
||||
// @Description delete the workflow
|
||||
// @Param id path string true "The id you want to delete"
|
||||
// @Success 200 {workflow} delete success!
|
||||
// @router /:id [delete]
|
||||
func (o *WorkflowController) Delete() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
data := oclib.NewRequest(workflow_collection, user, peerID, groups, nil).DeleteOne(id)
|
||||
if data.Err == "" {
|
||||
data, _ := json.Marshal(data.Data.Serialize(data.Data))
|
||||
infrastructure.EmitNATS(user, groups, tools.PropalgationMessage{
|
||||
DataType: workflow_dt.EnumIndex(),
|
||||
Action: tools.PB_DELETE,
|
||||
Payload: data,
|
||||
})
|
||||
}
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
Reference in New Issue
Block a user