init oc-peers
This commit is contained in:
61
controllers/peer.go
Normal file
61
controllers/peer.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// Operations about workflow
|
||||
type PeerController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title Search
|
||||
// @Description search workspace
|
||||
// @Param search path string true "the word search you want to get"
|
||||
// @Success 200 {workspace} models.workspace
|
||||
// @router /search/:search [get]
|
||||
func (o *PeerController) Search() {
|
||||
// store and return Id or post with UUID
|
||||
search := o.Ctx.Input.Param(":search")
|
||||
o.Data["json"] = oclib.Search(nil, search, oclib.LibDataEnum(oclib.PEER))
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Update
|
||||
// @Description create peers
|
||||
// @Param id path string true "the peer id you want to get"
|
||||
// @Param body body models.peer true "The peer content"
|
||||
// @Success 200 {object} models.peer
|
||||
// @router /:id [put]
|
||||
func (o *PeerController) Put() {
|
||||
// store and return Id or post with UUID
|
||||
var res map[string]interface{}
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
|
||||
data := oclib.UpdateOne(oclib.LibDataEnum(oclib.PEER), res, id, nil)
|
||||
o.Data["json"] = data
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description find all peer
|
||||
// @Success 200 {peer} models.peer
|
||||
// @router / [get]
|
||||
func (o *PeerController) GetAll() {
|
||||
o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(oclib.PEER))
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find peer by peerid
|
||||
// @Param id path string true "the peer id you want to get"
|
||||
// @Success 200 {peer} models.peer
|
||||
// @router /:id [get]
|
||||
func (o *PeerController) Get() {
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(oclib.PEER), id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
52
controllers/status.go
Normal file
52
controllers/status.go
Normal file
@@ -0,0 +1,52 @@
|
||||
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()
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
oclib "cloud.o-forge.io/core/oc-lib"
|
||||
dbs "cloud.o-forge.io/core/oc-lib/dbs"
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// Operations about workflow
|
||||
type WorkflowExecutionController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title Search
|
||||
// @Description search workspace
|
||||
// @Param start_date path string true "the word search you want to get"
|
||||
// @Param end_date path string true "the word search you want to get"
|
||||
// @Success 200 {workspace} models.workspace
|
||||
// @router /search/:start_date/:end_date [get]
|
||||
func (o *WorkflowExecutionController) Search() {
|
||||
// store and return Id or post with UUID
|
||||
start_date, _ := time.Parse("2006-01-02", o.Ctx.Input.Param(":start_date"))
|
||||
end_date, _ := time.Parse("2006-01-02", o.Ctx.Input.Param(":end_date"))
|
||||
sd := primitive.NewDateTimeFromTime(start_date)
|
||||
ed := primitive.NewDateTimeFromTime(end_date)
|
||||
f := dbs.Filters{
|
||||
And: map[string][]dbs.Filter{
|
||||
"execution_date": {{Operator: "gte", Value: sd}, {Operator: "lte", Value: ed}},
|
||||
},
|
||||
}
|
||||
o.Data["json"] = oclib.Search(&f, "", oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION))
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title GetAll
|
||||
// @Description find workflow by workflowid
|
||||
// @Success 200 {workflow} models.workflow
|
||||
// @router / [get]
|
||||
func (o *WorkflowExecutionController) GetAll() {
|
||||
o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION))
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// @Title Get
|
||||
// @Description find workflow by workflowid
|
||||
// @Param id path string true "the workflowid you want to get"
|
||||
// @Success 200 {workflow} models.workflow
|
||||
// @router /:id [get]
|
||||
func (o *WorkflowExecutionController) Get() {
|
||||
id := o.Ctx.Input.Param(":id")
|
||||
o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION), id)
|
||||
o.ServeJSON()
|
||||
}
|
||||
Reference in New Issue
Block a user