init oc-peers
This commit is contained in:
parent
88e4476c3b
commit
5558ac4298
@ -20,11 +20,11 @@ FROM scratch
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY --from=builder /app/oc-scheduler /usr/bin/
|
COPY --from=builder /app/oc-peers /usr/bin/
|
||||||
COPY --from=builder /app/swagger /app/swagger
|
COPY --from=builder /app/swagger /app/swagger
|
||||||
|
|
||||||
COPY docker_scheduler.json /etc/oc/scheduler.json
|
COPY docker_peers.json /etc/oc/peers.json
|
||||||
|
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
ENTRYPOINT ["oc-scheduler"]
|
ENTRYPOINT ["oc-peers"]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# oc-scheduler OpenCloud scheduler service.
|
# oc-peers OpenCloud scheduler service.
|
||||||
|
|
||||||
Manages user schedulers
|
Manages user schedulers
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
appname = oc-scheduler
|
appname = oc-peers
|
||||||
httpport = 8080
|
httpport = 8080
|
||||||
runmode = dev
|
runmode = dev
|
||||||
autorender = false
|
autorender = false
|
||||||
|
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()
|
|
||||||
}
|
|
@ -1,13 +1,13 @@
|
|||||||
version: '3.4'
|
version: '3.4'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
oc-scheduler:
|
oc-peers:
|
||||||
environment:
|
environment:
|
||||||
- MONGO_DATABASE=DC_myDC
|
- MONGO_DATABASE=DC_myDC
|
||||||
image: 'oc-scheduler:latest'
|
image: 'oc-peers:latest'
|
||||||
ports:
|
ports:
|
||||||
- 8090:8080
|
- 8093:8080
|
||||||
container_name: oc-scheduler
|
container_name: oc-peers
|
||||||
networks:
|
networks:
|
||||||
- catalog
|
- catalog
|
||||||
|
|
||||||
|
9
go.mod
9
go.mod
@ -1,4 +1,4 @@
|
|||||||
module oc-scheduler
|
module oc-peers
|
||||||
|
|
||||||
go 1.22.0
|
go 1.22.0
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240808150044-2ae15c720ab6 // indirect
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240821140757-39030a0a80e8 // indirect
|
||||||
filippo.io/edwards25519 v1.1.0 // indirect
|
filippo.io/edwards25519 v1.1.0 // indirect
|
||||||
github.com/beego/bee/v2 v2.1.0 // indirect
|
github.com/beego/bee/v2 v2.1.0 // indirect
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
@ -50,6 +50,9 @@ require (
|
|||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
|
github.com/nats-io/nats.go v1.37.0 // indirect
|
||||||
|
github.com/nats-io/nkeys v0.4.7 // indirect
|
||||||
|
github.com/nats-io/nuid v1.0.1 // indirect
|
||||||
github.com/pelletier/go-toml v1.9.5 // indirect
|
github.com/pelletier/go-toml v1.9.5 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
|
||||||
github.com/prometheus/client_golang v1.19.1 // indirect
|
github.com/prometheus/client_golang v1.19.1 // indirect
|
||||||
@ -87,7 +90,7 @@ require (
|
|||||||
golang.org/x/mod v0.19.0 // indirect
|
golang.org/x/mod v0.19.0 // indirect
|
||||||
golang.org/x/net v0.28.0 // indirect
|
golang.org/x/net v0.28.0 // indirect
|
||||||
golang.org/x/sync v0.8.0 // indirect
|
golang.org/x/sync v0.8.0 // indirect
|
||||||
golang.org/x/sys v0.23.0 // indirect
|
golang.org/x/sys v0.24.0 // indirect
|
||||||
golang.org/x/text v0.17.0 // indirect
|
golang.org/x/text v0.17.0 // indirect
|
||||||
golang.org/x/tools v0.23.0 // indirect
|
golang.org/x/tools v0.23.0 // indirect
|
||||||
google.golang.org/protobuf v1.34.2 // indirect
|
google.golang.org/protobuf v1.34.2 // indirect
|
||||||
|
14
go.sum
14
go.sum
@ -154,6 +154,12 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240808142619-8dc009564a13 h1:JSkXsMjScEOhi
|
|||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240808142619-8dc009564a13/go.mod h1:V5EL+NV2s9P1/BcFm3/icfLeBYVVMLl1Z0F0eecJZGo=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240808142619-8dc009564a13/go.mod h1:V5EL+NV2s9P1/BcFm3/icfLeBYVVMLl1Z0F0eecJZGo=
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240808150044-2ae15c720ab6 h1:uePDhEWN1kcF3XByLH/WTb/+wPDGe2cuG/jG0VqJOGw=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240808150044-2ae15c720ab6 h1:uePDhEWN1kcF3XByLH/WTb/+wPDGe2cuG/jG0VqJOGw=
|
||||||
cloud.o-forge.io/core/oc-lib v0.0.0-20240808150044-2ae15c720ab6/go.mod h1:V5EL+NV2s9P1/BcFm3/icfLeBYVVMLl1Z0F0eecJZGo=
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240808150044-2ae15c720ab6/go.mod h1:V5EL+NV2s9P1/BcFm3/icfLeBYVVMLl1Z0F0eecJZGo=
|
||||||
|
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-20240821121228-c14e06744938 h1:gMl7U5D+tZ4ui1HE8n4xXOLFBLM/69gxz08FKdsnzm4=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240821121228-c14e06744938/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240821140757-39030a0a80e8 h1:y4hngS1bedPKYXecTCcZk2WkuQNFazD11rMng9dmIzI=
|
||||||
|
cloud.o-forge.io/core/oc-lib v0.0.0-20240821140757-39030a0a80e8/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=
|
||||||
@ -414,6 +420,12 @@ github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt
|
|||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||||
|
github.com/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE=
|
||||||
|
github.com/nats-io/nats.go v1.37.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8=
|
||||||
|
github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
|
||||||
|
github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc=
|
||||||
|
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
||||||
|
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||||
github.com/ogier/pflag v0.0.1/go.mod h1:zkFki7tvTa0tafRvTBIZTvzYyAu6kQhPZFnshFFPE+g=
|
github.com/ogier/pflag v0.0.1/go.mod h1:zkFki7tvTa0tafRvTBIZTvzYyAu6kQhPZFnshFFPE+g=
|
||||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||||
@ -681,6 +693,8 @@ golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
|||||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
|
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
|
||||||
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
|
||||||
|
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
37
main.go
37
main.go
@ -1,46 +1,49 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "oc-scheduler/routers"
|
_ "oc-peers/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"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultConfigFile = "/etc/oc/scheduler.json"
|
const defaultConfigFile = "/etc/oc/peers.json"
|
||||||
const localConfigFile = "./docker_scheduler.json"
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
configFile := ""
|
configFile := ""
|
||||||
var o *onion.Onion
|
var o *onion.Onion
|
||||||
l3 := onion.NewEnvLayerPrefix("_", "OCSCHEDULER_")
|
l3 := onion.NewEnvLayerPrefix("_", "OCSCHEDULER_")
|
||||||
l1, err := onion.NewFileLayer(localConfigFile, nil)
|
|
||||||
if err == nil {
|
|
||||||
configFile = localConfigFile
|
|
||||||
}
|
|
||||||
l2, err := onion.NewFileLayer(defaultConfigFile, nil)
|
l2, err := onion.NewFileLayer(defaultConfigFile, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
configFile = defaultConfigFile
|
configFile = defaultConfigFile
|
||||||
}
|
}
|
||||||
if configFile == "" {
|
if configFile == "" || l2 == nil {
|
||||||
o = onion.New(l3)
|
o = onion.New(l3)
|
||||||
} else if l1 == nil && l2 == nil {
|
} else {
|
||||||
o = onion.New(l1, l2, l3)
|
|
||||||
} else if l1 == nil {
|
|
||||||
o = onion.New(l2, l3)
|
o = onion.New(l2, l3)
|
||||||
} else if l2 == nil {
|
|
||||||
o = onion.New(l1, 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"),
|
||||||
|
"",
|
||||||
)
|
)
|
||||||
oclib.Init("oc-scheduler")
|
oclib.Init("oc-peers")
|
||||||
|
|
||||||
|
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.WORKFLOW), o.GetStringDefault("WORKSPACE_URL", ":8089"))
|
||||||
|
oclib.AddPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), o.GetStringDefault("SHARED_WORKSPACE_URL", ":8091"))
|
||||||
|
|
||||||
|
oclib.AddPath(oclib.LibDataEnum(oclib.DATACENTER_RESOURCE), o.GetStringDefault("CATALOG_URL", ":8087"))
|
||||||
|
oclib.AddPath(oclib.LibDataEnum(oclib.DATA_RESOURCE), o.GetStringDefault("CATALOG_URL", ":8087"))
|
||||||
|
oclib.AddPath(oclib.LibDataEnum(oclib.STORAGE_RESOURCE), o.GetStringDefault("CATALOG_URL", ":8087"))
|
||||||
|
oclib.AddPath(oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE), o.GetStringDefault("CATALOG_URL", ":8087"))
|
||||||
|
oclib.AddPath(oclib.LibDataEnum(oclib.PROCESSING_RESOURCE), o.GetStringDefault("CATALOG_URL", ":8087"))
|
||||||
|
|
||||||
// Normal beego init
|
// Normal beego init
|
||||||
//if beego.BConfig.RunMode == "dev" {
|
|
||||||
beego.BConfig.WebConfig.DirectoryIndex = true
|
beego.BConfig.WebConfig.DirectoryIndex = true
|
||||||
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
|
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
|
||||||
//}
|
|
||||||
beego.Run()
|
beego.Run()
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
beego.GlobalControllerRouter["oc-scheduler/controllers:VersionController"] = append(beego.GlobalControllerRouter["oc-scheduler/controllers:VersionController"],
|
beego.GlobalControllerRouter["oc-peers/controllers:PeerController"] = append(beego.GlobalControllerRouter["oc-peers/controllers:PeerController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "GetAll",
|
Method: "GetAll",
|
||||||
Router: `/`,
|
Router: `/`,
|
||||||
@ -16,16 +16,16 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["oc-scheduler/controllers:WorkflowExecutionController"] = append(beego.GlobalControllerRouter["oc-scheduler/controllers:WorkflowExecutionController"],
|
beego.GlobalControllerRouter["oc-peers/controllers:PeerController"] = append(beego.GlobalControllerRouter["oc-peers/controllers:PeerController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "GetAll",
|
Method: "Put",
|
||||||
Router: `/`,
|
Router: `/:id`,
|
||||||
AllowHTTPMethods: []string{"get"},
|
AllowHTTPMethods: []string{"put"},
|
||||||
MethodParams: param.Make(),
|
MethodParams: param.Make(),
|
||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["oc-scheduler/controllers:WorkflowExecutionController"] = append(beego.GlobalControllerRouter["oc-scheduler/controllers:WorkflowExecutionController"],
|
beego.GlobalControllerRouter["oc-peers/controllers:PeerController"] = append(beego.GlobalControllerRouter["oc-peers/controllers:PeerController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "Get",
|
Method: "Get",
|
||||||
Router: `/:id`,
|
Router: `/:id`,
|
||||||
@ -34,10 +34,28 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["oc-scheduler/controllers:WorkflowExecutionController"] = append(beego.GlobalControllerRouter["oc-scheduler/controllers:WorkflowExecutionController"],
|
beego.GlobalControllerRouter["oc-peers/controllers:PeerController"] = append(beego.GlobalControllerRouter["oc-peers/controllers:PeerController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "Search",
|
Method: "Search",
|
||||||
Router: `/search/:start_date/:end_date`,
|
Router: `/search/:search`,
|
||||||
|
AllowHTTPMethods: []string{"get"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["oc-peers/controllers:StatusController"] = append(beego.GlobalControllerRouter["oc-peers/controllers:StatusController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "Get",
|
||||||
|
Router: `/`,
|
||||||
|
AllowHTTPMethods: []string{"post"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["oc-peers/controllers:VersionController"] = append(beego.GlobalControllerRouter["oc-peers/controllers:VersionController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "GetAll",
|
||||||
|
Router: `/`,
|
||||||
AllowHTTPMethods: []string{"get"},
|
AllowHTTPMethods: []string{"get"},
|
||||||
MethodParams: param.Make(),
|
MethodParams: param.Make(),
|
||||||
Filters: nil,
|
Filters: nil,
|
||||||
|
@ -8,16 +8,21 @@
|
|||||||
package routers
|
package routers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"oc-scheduler/controllers"
|
"oc-peers/controllers"
|
||||||
|
|
||||||
beego "github.com/beego/beego/v2/server/web"
|
beego "github.com/beego/beego/v2/server/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ns := beego.NewNamespace("/oc/",
|
ns := beego.NewNamespace("/oc/",
|
||||||
beego.NSNamespace("/workflow_execution",
|
beego.NSNamespace("/peer/status",
|
||||||
beego.NSInclude(
|
beego.NSInclude(
|
||||||
&controllers.WorkflowExecutionController{},
|
&controllers.StatusController{},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
beego.NSNamespace("/peer",
|
||||||
|
beego.NSInclude(
|
||||||
|
&controllers.PeerController{},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
beego.NSNamespace("/version",
|
beego.NSNamespace("/version",
|
||||||
|
@ -3,19 +3,19 @@ package test
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
_ "oc-peers/routers"
|
||||||
"runtime"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
_ "oc-scheduler/routers"
|
"runtime"
|
||||||
|
"testing"
|
||||||
|
|
||||||
beego "github.com/beego/beego/v2/server/web"
|
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
|
beego "github.com/beego/beego/v2/server/web"
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
_, file, _, _ := runtime.Caller(0)
|
_, file, _, _ := runtime.Caller(0)
|
||||||
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".." + string(filepath.Separator))))
|
apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator))))
|
||||||
beego.TestBeegoInit(apppath)
|
beego.TestBeegoInit(apppath)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,12 +28,11 @@ func TestGet(t *testing.T) {
|
|||||||
logs.Info("testing", "TestGet", "Code[%d]\n%s", w.Code, w.Body.String())
|
logs.Info("testing", "TestGet", "Code[%d]\n%s", w.Code, w.Body.String())
|
||||||
|
|
||||||
Convey("Subject: Test Station Endpoint\n", t, func() {
|
Convey("Subject: Test Station Endpoint\n", t, func() {
|
||||||
Convey("Status Code Should Be 200", func() {
|
Convey("Status Code Should Be 200", func() {
|
||||||
So(w.Code, ShouldEqual, 200)
|
So(w.Code, ShouldEqual, 200)
|
||||||
})
|
})
|
||||||
Convey("The Result Should Not Be Empty", func() {
|
Convey("The Result Should Not Be Empty", func() {
|
||||||
So(w.Body.Len(), ShouldBeGreaterThan, 0)
|
So(w.Body.Len(), ShouldBeGreaterThan, 0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user