oclib latest majr version

This commit is contained in:
mr 2024-08-21 12:35:06 +02:00
parent 1be4d79c75
commit ad46694516
9 changed files with 78 additions and 43 deletions

View File

@ -1,6 +1,8 @@
package controllers package controllers
import ( 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" 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.Data["json"] = map[string]string{"version": "1"}
c.ServeJSON() 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()
}

View File

@ -3,7 +3,6 @@ package controllers
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"time" "time"
oclib "cloud.o-forge.io/core/oc-lib" oclib "cloud.o-forge.io/core/oc-lib"
@ -11,7 +10,6 @@ import (
w "cloud.o-forge.io/core/oc-lib/models/workflow" w "cloud.o-forge.io/core/oc-lib/models/workflow"
"cloud.o-forge.io/core/oc-lib/tools" "cloud.o-forge.io/core/oc-lib/tools"
beego "github.com/beego/beego/v2/server/web" beego "github.com/beego/beego/v2/server/web"
"github.com/nats-io/nats.go"
) )
// Operations about workflow // Operations about workflow
@ -50,46 +48,10 @@ func (o *WorkflowController) Put() {
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res) json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
caller := tools.NewHTTPCaller(paths) caller := tools.NewHTTPCaller(paths)
data := oclib.UpdateOne(oclib.LibDataEnum(oclib.WORKFLOW), res, id, caller) data := oclib.UpdateOne(oclib.LibDataEnum(oclib.WORKFLOW), res, id, caller)
data.Err += o.SetNATSPub(res, data)
o.Data["json"] = data o.Data["json"] = data
o.ServeJSON() 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 // @Title Create
// @Description create workflows // @Description create workflows
// @Param data body json true "body for data content (Json format)" // @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) json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
caller := tools.NewHTTPCaller(paths) caller := tools.NewHTTPCaller(paths)
data := oclib.StoreOne(oclib.LibDataEnum(oclib.WORKFLOW), res, caller) data := oclib.StoreOne(oclib.LibDataEnum(oclib.WORKFLOW), res, caller)
data.Err += o.SetNATSPub(res, data)
o.Data["json"] = data o.Data["json"] = data
o.ServeJSON() o.ServeJSON()
} }

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.22.0
toolchain go1.22.4 toolchain go1.22.4
require ( 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/beego/beego/v2 v2.2.2
github.com/goraz/onion v0.1.3 github.com/goraz/onion v0.1.3
github.com/nats-io/nats.go v1.37.0 github.com/nats-io/nats.go v1.37.0

10
go.sum
View File

@ -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-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 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-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= 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 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=

View File

@ -1,10 +1,10 @@
package main package main
import ( import (
"oc-workflow/controllers"
_ "oc-workflow/routers" _ "oc-workflow/routers"
oclib "cloud.o-forge.io/core/oc-lib" oclib "cloud.o-forge.io/core/oc-lib"
"cloud.o-forge.io/core/oc-lib/tools"
beego "github.com/beego/beego/v2/server/web" beego "github.com/beego/beego/v2/server/web"
"github.com/goraz/onion" "github.com/goraz/onion"
) )
@ -24,12 +24,12 @@ func main() {
} else { } else {
o = onion.New(l2, l3) o = onion.New(l2, l3)
} }
oclib.SetConfig( tools.SetConfig(
o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"), o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"),
o.GetStringDefault("MONGO_DATABASE", "DC_myDC"), o.GetStringDefault("MONGO_DATABASE", "DC_myDC"),
o.GetStringDefault("NATS_URL", "nats://localhost:4222"),
) )
oclib.Init("oc-workflow") 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")) oclib.AddPath(oclib.LibDataEnum(oclib.BOOKING), o.GetStringDefault("BOOKING_URL", ":8092"))
// Normal beego init // Normal beego init
//if beego.BConfig.RunMode == "dev" { //if beego.BConfig.RunMode == "dev" {

Binary file not shown.

View File

@ -16,6 +16,15 @@ func init() {
Filters: nil, Filters: nil,
Params: 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.GlobalControllerRouter["oc-workflow/controllers:WorkflowController"] = append(beego.GlobalControllerRouter["oc-workflow/controllers:WorkflowController"],
beego.ControllerComments{ beego.ControllerComments{
Method: "Post", Method: "Post",

View File

@ -29,6 +29,20 @@
} }
} }
}, },
"/version/status": {
"get": {
"tags": [
"version"
],
"description": "get status\n\u003cbr\u003e",
"operationId": "VersionController.Status",
"responses": {
"200": {
"description": ""
}
}
}
},
"/workflow/": { "/workflow/": {
"get": { "get": {
"tags": [ "tags": [

View File

@ -23,6 +23,17 @@ paths:
responses: responses:
"200": "200":
description: "" description: ""
/version/status:
get:
tags:
- version
description: |-
get status
<br>
operationId: VersionController.Status
responses:
"200":
description: ""
/workflow/: /workflow/:
get: get:
tags: tags: