latest oclib for glory + comments

This commit is contained in:
mr 2024-08-30 10:44:47 +02:00
parent 61c92977fe
commit e89c70a9bd
4 changed files with 11 additions and 8 deletions

View File

@ -2,7 +2,6 @@ package controllers
import (
"encoding/json"
"fmt"
"cloud.o-forge.io/core/oc-lib/tools"
beego "github.com/beego/beego/v2/server/web"
@ -34,19 +33,18 @@ type StatusController struct {
func (o *StatusController) Status() {
var address map[string]string
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &address)
fmt.Println(len(address))
if len(address) == 0 { // default if nothing is send in body
for _, host := range []string{"oc-datacenter", "oc-workflow", "oc-workspace", "oc-shared"} {
for _, host := range []string{"oc-datacenter", "oc-workflow", "oc-workspace", "oc-shared", "oc-workspace"} {
address[host] = "http://" + host + ":8080/oc"
}
}
api := tools.API{}
state, services, err := api.CheckRemoteAPIs(address)
state, services, err := api.CheckRemoteAPIs(address) // check if the services are alive
errSTR := ""
if err != nil {
errSTR = err.Error()
}
o.Data["json"] = map[string]interface{}{
o.Data["json"] = map[string]interface{}{ // return the status
"data": map[string]interface{}{
"state": state.String(),
"code": state.EnumIndex(),

2
go.mod
View File

@ -11,7 +11,7 @@ require (
)
require (
cloud.o-forge.io/core/oc-lib v0.0.0-20240823091301-5b3779e4cb21 // indirect
cloud.o-forge.io/core/oc-lib v0.0.0-20240830071403-db78c70dc349 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/beego/bee/v2 v2.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect

2
go.sum
View File

@ -174,6 +174,8 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240823082553-98fa1f6ca807 h1:BqqCAnV2pbrX0
cloud.o-forge.io/core/oc-lib v0.0.0-20240823082553-98fa1f6ca807/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
cloud.o-forge.io/core/oc-lib v0.0.0-20240823091301-5b3779e4cb21 h1:OzsSJVL2jaLewUWfW4C30SVrY4y20+mxI3rbOGLCPyo=
cloud.o-forge.io/core/oc-lib v0.0.0-20240823091301-5b3779e4cb21/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
cloud.o-forge.io/core/oc-lib v0.0.0-20240830071403-db78c70dc349 h1:bEIY1lCsA78/mJqFE0gV6likAv5ZifH3RMnLJxiSk3o=
cloud.o-forge.io/core/oc-lib v0.0.0-20240830071403-db78c70dc349/go.mod h1:FIJD0taWLJ5pjQLJ6sfE2KlTkvbmk5SMcyrxdjsaVz0=
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=

View File

@ -29,9 +29,12 @@ func main() {
o.GetStringDefault("MONGO_DATABASE", "DC_myDC"),
o.GetStringDefault("NATS_URL", "nats://localhost:4222"),
)
// Init OC with hostname and port for discovery purpose
oclib.Init("oc-peers", o.GetStringDefault("HOSTNAME", "localhost"), o.GetStringDefault("PORT", "8093"))
/* 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.WORKFLOW), o.GetStringDefault("WORKFLOW_URL", ":8088"))
oclib.AddPath(oclib.LibDataEnum(oclib.WORKSPACE), o.GetStringDefault("WORKSPACE_URL", ":8089"))