53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
|
package controllers
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
|
||
|
oclib "cloud.o-forge.io/core/oc-lib"
|
||
|
"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 []string
|
||
|
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &address)
|
||
|
if len(address) == 0 { // default if nothing is send in body
|
||
|
for k, v := range oclib.GetPaths() {
|
||
|
address = append(address, "http://"+k.API()+v+"/oc")
|
||
|
}
|
||
|
}
|
||
|
api := tools.API{}
|
||
|
state, code, err := api.CheckRemoteAPIs(address)
|
||
|
o.Data["json"] = map[string]interface{}{
|
||
|
"data": map[string]string{
|
||
|
"state": state.String(),
|
||
|
},
|
||
|
"code": code,
|
||
|
"error": err.Error(),
|
||
|
}
|
||
|
o.ServeJSON()
|
||
|
}
|