58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package controllers
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"cloud.o-forge.io/core/oc-lib/tools"
|
|
beego "github.com/beego/beego/v2/server/web"
|
|
)
|
|
|
|
type State int
|
|
|
|
const (
|
|
ALIVE State = iota
|
|
REDUCED_SERVICE
|
|
DB_FALLOUT
|
|
DEAD
|
|
)
|
|
|
|
func (s State) String() string {
|
|
return [...]string{"alive", "reduced service", "database fallout", "dead"}[s]
|
|
}
|
|
|
|
// Operations about workflow
|
|
type StatusController struct {
|
|
beego.Controller
|
|
}
|
|
|
|
// @Title Status
|
|
// @Description get peer status if it's alive
|
|
// @Param body body list of addresses true "The addresses list"
|
|
// @Success 200 {status} models.status
|
|
// @router / [post]
|
|
func (o *StatusController) Status() {
|
|
var address map[string]string
|
|
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &address)
|
|
if len(address) == 0 { // default if nothing is send in body
|
|
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) // check if the services are alive
|
|
errSTR := ""
|
|
if err != nil {
|
|
errSTR = err.Error()
|
|
}
|
|
o.Data["json"] = map[string]interface{}{ // return the status
|
|
"data": map[string]interface{}{
|
|
"state": state.String(),
|
|
"code": state.EnumIndex(),
|
|
"services": services,
|
|
},
|
|
"code": 200,
|
|
"error": errSTR,
|
|
}
|
|
o.ServeJSON()
|
|
}
|