diff --git a/controllers/version.go b/controllers/version.go index 6fa3e9c..5c9af81 100644 --- a/controllers/version.go +++ b/controllers/version.go @@ -1,6 +1,8 @@ package controllers import ( + oclib "cloud.o-forge.io/core/oc-lib" + "cloud.o-forge.io/core/oc-lib/tools" beego "github.com/beego/beego/v2/server/web" ) @@ -17,3 +19,31 @@ func (c *VersionController) GetAll() { c.Data["json"] = map[string]string{"version": "1"} c.ServeJSON() } + +// @Title Status +// @Description get status +// @Success 200 +// @router /status [get] +func (c *VersionController) Status() { + errStr := "" + api := tools.API{} + state, code, err := api.GetState() + + if state == tools.ALIVE { + state, _, err = api.CheckRemoteAPIs([]string{ + "http://" + oclib.LibDataEnum(oclib.BOOKING).String() + oclib.GetPath(oclib.LibDataEnum(oclib.BOOKING)), + }) + } + if err != nil { + errStr = err.Error() + } + c.Data["json"] = map[string]interface{}{ + "data": map[string]interface{}{ + "state": state.String(), + "code": state, + }, + "error": errStr, + "code": code, + } + c.ServeJSON() +} diff --git a/controllers/workflow.go b/controllers/workflow.go index eabd1c4..1d1acfc 100644 --- a/controllers/workflow.go +++ b/controllers/workflow.go @@ -3,7 +3,6 @@ package controllers import ( "encoding/json" "errors" - "fmt" "time" oclib "cloud.o-forge.io/core/oc-lib" @@ -11,7 +10,6 @@ import ( w "cloud.o-forge.io/core/oc-lib/models/workflow" "cloud.o-forge.io/core/oc-lib/tools" beego "github.com/beego/beego/v2/server/web" - "github.com/nats-io/nats.go" ) // Operations about workflow @@ -50,46 +48,10 @@ func (o *WorkflowController) Put() { json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res) caller := tools.NewHTTPCaller(paths) data := oclib.UpdateOne(oclib.LibDataEnum(oclib.WORKFLOW), res, id, caller) - data.Err += o.SetNATSPub(res, data) o.Data["json"] = data o.ServeJSON() } -var NATS_SERVER = "nats://localhost:4222" - -func (o *WorkflowController) SetNATSPub(res map[string]interface{}, data oclib.LibData) string { - if sched, ok := res["schedule"]; ok && sched != nil && data.Code == 200 { - workflow := data.ToWorkflow() - if workflow != nil && workflow.Schedule != nil { - // HERE NATS - fmt.Println("NATS_SERVER", NATS_SERVER) - nc, err := nats.Connect(NATS_SERVER) - if err != nil { - return " -> Could not reach NATS server : " + err.Error() - } - start := "" - if workflow.Schedule.Start != nil { - start = workflow.Schedule.Start.String() - } - end := "" - if workflow.Schedule.End != nil { - end = workflow.Schedule.End.String() - } - str_description, _ := json.Marshal(map[string]string{ - "workflow_id": workflow.UUID, - "start_date": start, - "stop_date": end, - }) - err = nc.Publish("workflowsUpdate", str_description) - time.Sleep(time.Second * 2) - if err != nil { - return " -> " + err.Error() - } - } - } - return "" -} - // @Title Create // @Description create workflows // @Param data body json true "body for data content (Json format)" @@ -106,7 +68,6 @@ func (o *WorkflowController) Post() { json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res) caller := tools.NewHTTPCaller(paths) data := oclib.StoreOne(oclib.LibDataEnum(oclib.WORKFLOW), res, caller) - data.Err += o.SetNATSPub(res, data) o.Data["json"] = data o.ServeJSON() } diff --git a/go.mod b/go.mod index b19cb50..907dbd1 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22.0 toolchain go1.22.4 require ( - cloud.o-forge.io/core/oc-lib v0.0.0-20240820133125-d13249d87ded + cloud.o-forge.io/core/oc-lib v0.0.0-20240821093044-f64563c9ff06 github.com/beego/beego/v2 v2.2.2 github.com/goraz/onion v0.1.3 github.com/nats-io/nats.go v1.37.0 diff --git a/go.sum b/go.sum index 691f531..d8d4532 100644 --- a/go.sum +++ b/go.sum @@ -164,6 +164,16 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240820125906-b6d9b6910fcd h1:77a73Cjf0gVVY cloud.o-forge.io/core/oc-lib v0.0.0-20240820125906-b6d9b6910fcd/go.mod h1:tFM1H8v+lpHt+dTZAhYmYXu3eF+wOEd+HtcOiUbCCvQ= cloud.o-forge.io/core/oc-lib v0.0.0-20240820133125-d13249d87ded h1:BtpPdQts0TMBle+LAEOdrkPlDLEFyF26ypJkSyQA9O4= cloud.o-forge.io/core/oc-lib v0.0.0-20240820133125-d13249d87ded/go.mod h1:tFM1H8v+lpHt+dTZAhYmYXu3eF+wOEd+HtcOiUbCCvQ= +cloud.o-forge.io/core/oc-lib v0.0.0-20240820142206-c6ea2195ed61 h1:i3te8u3MYdwOD2EQgF0UQsDgOBeCPId0e0xg672S1zk= +cloud.o-forge.io/core/oc-lib v0.0.0-20240820142206-c6ea2195ed61/go.mod h1:tFM1H8v+lpHt+dTZAhYmYXu3eF+wOEd+HtcOiUbCCvQ= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821065429-e31815f576dd h1:oeseYEuiIWxzdgRa5O4qiHPRJJv8KuK4nIRHYwDM6VA= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821065429-e31815f576dd/go.mod h1:tFM1H8v+lpHt+dTZAhYmYXu3eF+wOEd+HtcOiUbCCvQ= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821082117-b7ecea25ebf0 h1:0iUOyKVa+wI1tOuBQ1WpbTYqHHFklcjtpdJ3QrmHIW8= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821082117-b7ecea25ebf0/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821085824-c5f45e03f365 h1:Oh5yP25jvfv1nKVGH9Ja4jqJPk9cZik7SaoaHNoguEo= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821085824-c5f45e03f365/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821093044-f64563c9ff06 h1:sYveE1C/0mpSr+ZmOYxuZ3fTWID7mr5hPiq0jQenv3Q= +cloud.o-forge.io/core/oc-lib v0.0.0-20240821093044-f64563c9ff06/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= diff --git a/main.go b/main.go index 6649763..d282132 100644 --- a/main.go +++ b/main.go @@ -1,10 +1,10 @@ package main import ( - "oc-workflow/controllers" _ "oc-workflow/routers" oclib "cloud.o-forge.io/core/oc-lib" + "cloud.o-forge.io/core/oc-lib/tools" beego "github.com/beego/beego/v2/server/web" "github.com/goraz/onion" ) @@ -24,12 +24,12 @@ func main() { } else { o = onion.New(l2, l3) } - oclib.SetConfig( + tools.SetConfig( o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"), o.GetStringDefault("MONGO_DATABASE", "DC_myDC"), + o.GetStringDefault("NATS_URL", "nats://localhost:4222"), ) oclib.Init("oc-workflow") - controllers.NATS_SERVER = o.GetStringDefault("NATS_URL", "nats://localhost:4222") oclib.AddPath(oclib.LibDataEnum(oclib.BOOKING), o.GetStringDefault("BOOKING_URL", ":8092")) // Normal beego init //if beego.BConfig.RunMode == "dev" { diff --git a/oc-workflow b/oc-workflow index 6b54fc2..5e4f646 100755 Binary files a/oc-workflow and b/oc-workflow differ diff --git a/routers/commentsRouter.go b/routers/commentsRouter.go index f967c92..919ef32 100644 --- a/routers/commentsRouter.go +++ b/routers/commentsRouter.go @@ -16,6 +16,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["oc-workflow/controllers:VersionController"] = append(beego.GlobalControllerRouter["oc-workflow/controllers:VersionController"], + beego.ControllerComments{ + Method: "Status", + Router: `/status`, + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["oc-workflow/controllers:WorkflowController"] = append(beego.GlobalControllerRouter["oc-workflow/controllers:WorkflowController"], beego.ControllerComments{ Method: "Post", diff --git a/swagger/swagger.json b/swagger/swagger.json index 2b799f6..36a628f 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -29,6 +29,20 @@ } } }, + "/version/status": { + "get": { + "tags": [ + "version" + ], + "description": "get status\n\u003cbr\u003e", + "operationId": "VersionController.Status", + "responses": { + "200": { + "description": "" + } + } + } + }, "/workflow/": { "get": { "tags": [ diff --git a/swagger/swagger.yml b/swagger/swagger.yml index a2942d5..8638f20 100644 --- a/swagger/swagger.yml +++ b/swagger/swagger.yml @@ -23,6 +23,17 @@ paths: responses: "200": description: "" + /version/status: + get: + tags: + - version + description: |- + get status +
+ operationId: VersionController.Status + responses: + "200": + description: "" /workflow/: get: tags: