Neo Workflow

This commit is contained in:
mr 2024-10-02 14:16:18 +02:00
parent f735342855
commit 57906e481c
4 changed files with 58 additions and 72 deletions

View File

@ -5,7 +5,6 @@ import (
"errors"
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"
)
@ -15,6 +14,20 @@ type WorkflowController struct {
beego.Controller
}
var paths = map[tools.DataType]map[tools.METHOD]string{ // paths to call other OC services
tools.BOOKING: {
tools.POST: "/oc/booking/",
tools.DELETE: "/oc/booking/:id",
},
tools.PEER: {
tools.POST: "/oc/peer",
},
tools.WORKFLOW: {
tools.PUT: "/oc/workflow/:id?is_remote=true",
tools.DELETE: "/oc/workflow/:id?is_remote=true",
},
}
// @Title Search
// @Description search workspace
// @Param search path string true "the word search you want to get"
@ -34,24 +47,13 @@ func (o *WorkflowController) Search() {
// @Success 200 {object} models.workflow
// @router /:id [put]
func (o *WorkflowController) Put() {
var paths = map[string]map[tools.METHOD]string{ // paths to call other OC services
utils.BOOKING.String(): {
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/",
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/:id",
},
utils.PEER.String(): {
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc",
},
utils.WORKFLOW.String(): {
tools.PUT: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
},
}
// 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(10000000), &res)
caller := tools.NewHTTPCaller(paths) // create a new HTTP caller
caller.Disabled = oclib.IsQueryParamsEquals(o.Ctx.Input, "is_remote", true)
o.Ctx.Input.Param("is_remote")
data := oclib.UpdateOne(oclib.LibDataEnum(oclib.WORKFLOW), res, id, caller)
o.Data["json"] = data
o.ServeJSON()
@ -63,22 +65,11 @@ func (o *WorkflowController) Put() {
// @Success 200 {object} models.workflow
// @router / [post]
func (o *WorkflowController) Post() {
var paths = map[string]map[tools.METHOD]string{ // paths to call other OC services
utils.BOOKING.String(): {
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/",
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/:id",
},
utils.PEER.String(): {
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc",
},
utils.WORKFLOW.String(): {
tools.PUT: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
},
}
var res map[string]interface{}
json.Unmarshal(o.Ctx.Input.CopyBody(10000000), &res)
caller := tools.NewHTTPCaller(paths) // create a new HTTP caller
caller.Disabled = oclib.IsQueryParamsEquals(o.Ctx.Input, "is_remote", true)
data := oclib.StoreOne(oclib.LibDataEnum(oclib.WORKFLOW), res, caller)
o.Data["json"] = data
o.ServeJSON()
@ -126,21 +117,9 @@ func (o *WorkflowController) Get() {
// @Success 200 {string} delete success!
// @router /:id [delete]
func (o *WorkflowController) Delete() {
var paths = map[string]map[tools.METHOD]string{ // paths to call other OC services
utils.BOOKING.String(): {
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/",
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/:id",
},
utils.PEER.String(): {
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc",
},
utils.WORKFLOW.String(): {
tools.PUT: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
tools.DELETE: oclib.GetPath(oclib.LibDataEnum(oclib.WORKFLOW)) + "/oc/workflow/:id",
},
}
id := o.Ctx.Input.Param(":id")
caller := tools.NewHTTPCaller(paths) // create a new HTTP caller
caller.Disabled = oclib.IsQueryParamsEquals(o.Ctx.Input, "is_remote", true)
o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.WORKFLOW), id, caller)
o.ServeJSON()
}
@ -170,12 +149,12 @@ func (o *WorkflowController) Check() {
res := oclib.LoadOne(oclib.LibDataEnum(oclib.WORKFLOW), id)
if res.Code == 200 {
workflow := res.ToWorkflow()
caller := tools.NewHTTPCaller(map[string]map[tools.METHOD]string{ // paths to call other OC services
utils.PEER.String(): {
tools.POST: oclib.GetPath(oclib.LibDataEnum(oclib.PEER)) + "/oc",
caller := tools.NewHTTPCaller(map[tools.DataType]map[tools.METHOD]string{ // paths to call other OC services
tools.PEER: {
tools.POST: "/oc/peer",
},
utils.BOOKING.String(): {
tools.GET: oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)) + "/oc/booking/check/:id/" + o.Ctx.Input.Param(":start_date") + "/" + o.Ctx.Input.Param(":end_date"),
tools.BOOKING: {
tools.GET: "/oc/booking/check/:id/" + o.Ctx.Input.Param(":start_date") + "/" + o.Ctx.Input.Param(":end_date"),
},
})
isAvailable, err := workflow.CheckBooking(caller) // check booking

6
go.mod
View File

@ -5,8 +5,8 @@ go 1.22.0
toolchain go1.22.4
require (
cloud.o-forge.io/core/oc-lib v0.0.0-20240923141540-95a4acff3656
github.com/beego/beego/v2 v2.3.0
cloud.o-forge.io/core/oc-lib v0.0.0-20241002120813-a09a04e1a71e
github.com/beego/beego/v2 v2.3.1
github.com/nats-io/nats.go v1.37.0
github.com/smartystreets/goconvey v1.7.2
golang.org/x/mod v0.20.0
@ -50,7 +50,7 @@ require (
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
go.mongodb.org/mongo-driver v1.17.0 // indirect
go.mongodb.org/mongo-driver v1.17.1 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect

30
go.sum
View File

@ -6,9 +6,37 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240923125141-50ea0969e6e6 h1:5V+BkL3vURL28
cloud.o-forge.io/core/oc-lib v0.0.0-20240923125141-50ea0969e6e6/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
cloud.o-forge.io/core/oc-lib v0.0.0-20240923141540-95a4acff3656 h1:rTb5ygkGqJlCqlY6QtCCnQSkFGijMyP0ltLsm6nb0q0=
cloud.o-forge.io/core/oc-lib v0.0.0-20240923141540-95a4acff3656/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
cloud.o-forge.io/core/oc-lib v0.0.0-20240924071456-92bb274d03ff h1:liYeH58lKmTft/TTouM8dvEeuqiCC7fGNEmpOSnWxjU=
cloud.o-forge.io/core/oc-lib v0.0.0-20240924071456-92bb274d03ff/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
cloud.o-forge.io/core/oc-lib v0.0.0-20240924072959-5c9adcf59744 h1:MrsMEKKGAxqp7Y6XI7cTo30EF6j6kHwL/qtOScBr+3k=
cloud.o-forge.io/core/oc-lib v0.0.0-20240924072959-5c9adcf59744/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
cloud.o-forge.io/core/oc-lib v0.0.0-20240924075418-021b461b0a7d h1:f8cT/NunF+eoZLU5B9gmiT4ky99zPmnQBbj4tj23KuA=
cloud.o-forge.io/core/oc-lib v0.0.0-20240924075418-021b461b0a7d/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
cloud.o-forge.io/core/oc-lib v0.0.0-20240925073610-89a1ab3f6ee7 h1:jsSCDHF1z20dMU48j7GGh2/qUZ07lcDVh5CztYN9cHc=
cloud.o-forge.io/core/oc-lib v0.0.0-20240925073610-89a1ab3f6ee7/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
cloud.o-forge.io/core/oc-lib v0.0.0-20240925080607-a48bcf25e4ee h1:PXLMHg4jQZ2e0Wl04r06HT+aNgHAs12UeJ8V45cY8IU=
cloud.o-forge.io/core/oc-lib v0.0.0-20240925080607-a48bcf25e4ee/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
cloud.o-forge.io/core/oc-lib v0.0.0-20240925082513-8953e2cd423d h1:qq3x7lDMawAwk9lpzD6oGcrlSW/Di/iNRESGcRRmTvQ=
cloud.o-forge.io/core/oc-lib v0.0.0-20240925082513-8953e2cd423d/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
cloud.o-forge.io/core/oc-lib v0.0.0-20240927112324-cdf513c2c454 h1:F5/oBMypnb6Mdvcf6N8y8v/DgfglPQ6VsQUY7hjC2zA=
cloud.o-forge.io/core/oc-lib v0.0.0-20240927112324-cdf513c2c454/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
cloud.o-forge.io/core/oc-lib v0.0.0-20241001081722-4ec32bafa7b6 h1:skTKCsFU5UlSSrc+AWgc4wsXMoZktZK/23eAjVFBEvo=
cloud.o-forge.io/core/oc-lib v0.0.0-20241001081722-4ec32bafa7b6/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
cloud.o-forge.io/core/oc-lib v0.0.0-20241002082508-f9bfafa0048b h1:TXMJIEs0ayuRsfNgH3qBY7FNPj01xySVZvvoUmk9Csk=
cloud.o-forge.io/core/oc-lib v0.0.0-20241002082508-f9bfafa0048b/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
cloud.o-forge.io/core/oc-lib v0.0.0-20241002084552-3c1a84011ecc h1:1R4stJxXDMQ6joJZl9gQ2TUGW6S2jct2lhHUubPChs0=
cloud.o-forge.io/core/oc-lib v0.0.0-20241002084552-3c1a84011ecc/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
cloud.o-forge.io/core/oc-lib v0.0.0-20241002093522-93903b493819 h1:B7FGEouTX3h/A5ODnBrmd6Exaw9m3WuJ3/LyGeBPyaY=
cloud.o-forge.io/core/oc-lib v0.0.0-20241002093522-93903b493819/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
cloud.o-forge.io/core/oc-lib v0.0.0-20241002102322-c309d9762350 h1:ybK3Qz1inr9xgrJwbHjSOTNaFIyX+AVINyzqcsvpATY=
cloud.o-forge.io/core/oc-lib v0.0.0-20241002102322-c309d9762350/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
cloud.o-forge.io/core/oc-lib v0.0.0-20241002120813-a09a04e1a71e h1:77QHk5JSf0q13B/Ai3xjcsGSS7nX+9AfxcsYz5oDo/A=
cloud.o-forge.io/core/oc-lib v0.0.0-20241002120813-a09a04e1a71e/go.mod h1:t+zpCTVKVdHH/BImwtMYY2QIWLMXKgY4n/JhFm3Vpu8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/beego/beego/v2 v2.3.0 h1:iECVwzm6egw6iw6tkWrEDqXG4NQtKLQ6QBSYqlM6T/I=
github.com/beego/beego/v2 v2.3.0/go.mod h1:Ob/5BJ9fIKZLd4s9ZV3o9J6odkkIyL83et+p98gyYXo=
github.com/beego/beego/v2 v2.3.1 h1:7MUKMpJYzOXtCUsTEoXOxsDV/UcHw6CPbaWMlthVNsc=
github.com/beego/beego/v2 v2.3.1/go.mod h1:5cqHsOHJIxkq44tBpRvtDe59GuVRVv/9/tyVDxd5ce4=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
@ -138,6 +166,8 @@ go.mongodb.org/mongo-driver v1.16.1 h1:rIVLL3q0IHM39dvE+z2ulZLp9ENZKThVfuvN/IiN4
go.mongodb.org/mongo-driver v1.16.1/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw=
go.mongodb.org/mongo-driver v1.17.0 h1:Hp4q2MCjvY19ViwimTs00wHi7G4yzxh4/2+nTx8r40k=
go.mongodb.org/mongo-driver v1.17.0/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM=
go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=

25
main.go
View File

@ -7,7 +7,6 @@ import (
oclib "cloud.o-forge.io/core/oc-lib"
beego "github.com/beego/beego/v2/server/web"
"golang.org/x/mod/modfile"
)
const appname = "oc-workflow"
@ -28,33 +27,11 @@ func main() {
o.GetStringDefault("LOKI_URL", ""),
o.GetStringDefault("LOG_LEVEL", "info"),
)
fmt.Println("Config file:", o.GetStringDefault("HOSTNAME", "localhost"))
// Init OC with hostname and port for discovery purpose
/* 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.BOOKING), o.GetStringDefault("BOOKING_URL", ":8092"))
oclib.AddPath(oclib.LibDataEnum(oclib.PEER), o.GetStringDefault("PEER_URL", ":8093"))
oclib.AddPath(oclib.LibDataEnum(oclib.WORKFLOW), o.GetStringDefault("WORKFLOW_URL", ":"+o.GetStringDefault("PORT", "8088")))
// Beego init
beego.BConfig.AppName = appname
beego.BConfig.Listen.HTTPPort = o.GetIntDefault("port", 8080)
beego.BConfig.Listen.HTTPPort = 8080
beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
beego.Run()
}
func GetModuleName() string {
goModBytes, err := os.ReadFile("go.mod")
if err != nil {
return "prrr"
}
modName := modfile.ModulePath(goModBytes)
fmt.Fprintf(os.Stdout, "modName=%+v\n", modName)
return modName
}