Shared your Workspace

This commit is contained in:
mr 2024-08-30 10:19:40 +02:00
parent b94ddfa05a
commit 476e3f0beb
2 changed files with 31 additions and 2 deletions

View File

@ -4,6 +4,8 @@ import (
"encoding/json" "encoding/json"
oclib "cloud.o-forge.io/core/oc-lib" 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" beego "github.com/beego/beego/v2/server/web"
) )
@ -32,10 +34,20 @@ func (o *WorkspaceController) Search() {
// @router /:id [put] // @router /:id [put]
func (o *WorkspaceController) Put() { func (o *WorkspaceController) Put() {
// store and return Id or post with UUID // store and return Id or post with UUID
var paths = map[string]map[tools.METHOD]string{
utils.PEER.String(): { // paths to call to status of peers
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc",
},
utils.WORKSPACE.String(): { // paths to call to delete/update workspace on peer destination
tools.PUT: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workspace/:id",
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workspace/:id",
},
}
caller := tools.NewHTTPCaller(paths) // generate a http caller to send to peer shared workspace
var res map[string]interface{} var res map[string]interface{}
id := o.Ctx.Input.Param(":id") id := o.Ctx.Input.Param(":id")
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res) json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.WORKSPACE), res, id) o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.WORKSPACE), res, id, caller)
o.ServeJSON() o.ServeJSON()
} }
@ -78,6 +90,16 @@ func (o *WorkspaceController) Get() {
// @router /:id [delete] // @router /:id [delete]
func (o *WorkspaceController) Delete() { func (o *WorkspaceController) Delete() {
id := o.Ctx.Input.Param(":id") id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.WORKSPACE), id) var paths = map[string]map[tools.METHOD]string{
utils.PEER.String(): { // paths to call to status of peers
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc",
},
utils.WORKSPACE.String(): { // paths to call to delete/update workspace on peer destination
tools.PUT: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workspace/:id",
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workspace/:id",
},
}
caller := tools.NewHTTPCaller(paths) // generate a http caller to send to peer shared workspace
o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.WORKSPACE), id, caller)
o.ServeJSON() o.ServeJSON()
} }

View File

@ -29,7 +29,14 @@ func main() {
o.GetStringDefault("MONGO_DATABASE", "DC_myDC"), o.GetStringDefault("MONGO_DATABASE", "DC_myDC"),
"", "",
) )
// Init OC with hostname and port for discovery purpose
oclib.Init("oc-workspace", o.GetStringDefault("HOSTNAME", "localhost"), o.GetStringDefault("PORT", "8089")) oclib.Init("oc-workspace", o.GetStringDefault("HOSTNAME", "localhost"), o.GetStringDefault("PORT", "8089"))
/* PATHS ARE REFERENCE FOR INNER SERVICE OF DISTANT OC
* PATHS ARE USED TO CALL OTHER OC SERVICES
* NAMES ARE CANONICAL NAMES OF THE SERVICES
*/
oclib.AddPath(oclib.LibDataEnum(oclib.PEER), o.GetStringDefault("PEER_URL", ":8093"))
oclib.AddPath(oclib.LibDataEnum(oclib.WORKFLOW), o.GetStringDefault("WORKFLOW_URL", ":"+o.GetStringDefault("PORT", "8089")))
// Normal beego init // Normal beego init
//if beego.BConfig.RunMode == "dev" { //if beego.BConfig.RunMode == "dev" {
beego.BConfig.WebConfig.DirectoryIndex = true beego.BConfig.WebConfig.DirectoryIndex = true