Compare commits

..

2 Commits

Author SHA1 Message Date
mr
e89c70a9bd latest oclib for glory + comments 2024-08-30 10:44:47 +02:00
mr
61c92977fe neo oc-peers 2024-08-26 12:07:54 +02:00
12 changed files with 283 additions and 153 deletions

View File

@ -12,7 +12,7 @@ RUN timeout 15 bee run -gendoc=true -downdoc=true -runmode=dev || :
RUN sed -i 's/http:\/\/127.0.0.1:8080\/swagger\/swagger.json/swagger.json/g' swagger/index.html RUN sed -i 's/http:\/\/127.0.0.1:8080\/swagger\/swagger.json/swagger.json/g' swagger/index.html
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" . RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o setup .
RUN ls /app RUN ls /app
@ -20,11 +20,11 @@ FROM scratch
WORKDIR /app WORKDIR /app
COPY --from=builder /app/oc-peers /usr/bin/ COPY --from=builder /app/setup /usr/bin/
COPY --from=builder /app/swagger /app/swagger COPY --from=builder /app/swagger /app/swagger
COPY docker_peers.json /etc/oc/peers.json COPY docker_conf.json /etc/oc/conf.json
EXPOSE 8080 EXPOSE $PORT
ENTRYPOINT ["oc-peers"] ENTRYPOINT ["setup"]

View File

@ -3,7 +3,6 @@ package controllers
import ( import (
"encoding/json" "encoding/json"
oclib "cloud.o-forge.io/core/oc-lib"
"cloud.o-forge.io/core/oc-lib/tools" "cloud.o-forge.io/core/oc-lib/tools"
beego "github.com/beego/beego/v2/server/web" beego "github.com/beego/beego/v2/server/web"
) )
@ -32,21 +31,27 @@ type StatusController struct {
// @Success 200 {status} models.status // @Success 200 {status} models.status
// @router / [post] // @router / [post]
func (o *StatusController) Status() { func (o *StatusController) Status() {
var address []string var address map[string]string
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &address) json.Unmarshal(o.Ctx.Input.CopyBody(10000), &address)
if len(address) == 0 { // default if nothing is send in body if len(address) == 0 { // default if nothing is send in body
for k, v := range oclib.GetPaths() { for _, host := range []string{"oc-datacenter", "oc-workflow", "oc-workspace", "oc-shared", "oc-workspace"} {
address = append(address, "http://"+k.API()+v+"/oc") address[host] = "http://" + host + ":8080/oc"
} }
} }
api := tools.API{} api := tools.API{}
state, code, err := api.CheckRemoteAPIs(address) state, services, err := api.CheckRemoteAPIs(address) // check if the services are alive
o.Data["json"] = map[string]interface{}{ errSTR := ""
"data": map[string]string{ if err != nil {
errSTR = err.Error()
}
o.Data["json"] = map[string]interface{}{ // return the status
"data": map[string]interface{}{
"state": state.String(), "state": state.String(),
"code": state.EnumIndex(),
"services": services,
}, },
"code": code, "code": 200,
"error": err.Error(), "error": errSTR,
} }
o.ServeJSON() o.ServeJSON()
} }

7
docker_conf.json Normal file
View File

@ -0,0 +1,7 @@
{
"MONGO_URL":"mongodb://mongo:27017/",
"MONGO_DATABASE":"DC_myDC",
"NATS_URL": "nats://nats:4222",
"HOSTNAME": "oc-peers",
"PORT" : 8080
}

View File

@ -1,4 +0,0 @@
{
"MONGO_URL":"mongodb://mongo:27017/",
"MONGO_DATABASE":"DC_myDC"
}

2
go.mod
View File

@ -11,7 +11,7 @@ require (
) )
require ( require (
cloud.o-forge.io/core/oc-lib v0.0.0-20240821140757-39030a0a80e8 // indirect cloud.o-forge.io/core/oc-lib v0.0.0-20240830071403-db78c70dc349 // 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

16
go.sum
View File

@ -160,6 +160,22 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20240821121228-c14e06744938 h1:gMl7U5D+tZ4ui
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-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 h1:y4hngS1bedPKYXecTCcZk2WkuQNFazD11rMng9dmIzI=
cloud.o-forge.io/core/oc-lib v0.0.0-20240821140757-39030a0a80e8/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU= cloud.o-forge.io/core/oc-lib v0.0.0-20240821140757-39030a0a80e8/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
cloud.o-forge.io/core/oc-lib v0.0.0-20240821143829-498ec3e9d8b5 h1:xgB9hmFg6kQfk0Hpb/yjdVK6Q3IzDihSPSbQfnOJQEY=
cloud.o-forge.io/core/oc-lib v0.0.0-20240821143829-498ec3e9d8b5/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
cloud.o-forge.io/core/oc-lib v0.0.0-20240821151922-b8b62dc2c8bf h1:s+Ow2r6UPXRbxAEHalPx7+89M3f99Fpl1HMMpMFIcTI=
cloud.o-forge.io/core/oc-lib v0.0.0-20240821151922-b8b62dc2c8bf/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
cloud.o-forge.io/core/oc-lib v0.0.0-20240822081914-4abf59a10d97 h1:6tbeTQvRnD0vDUl+5SLMgAh9ukjGxQ9WKjNcvvxN7cQ=
cloud.o-forge.io/core/oc-lib v0.0.0-20240822081914-4abf59a10d97/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
cloud.o-forge.io/core/oc-lib v0.0.0-20240822083903-bfa176a7c5ce h1:nJqBNioYDdki6O6N8m6AKChbBjpzcSwt1ixvpkIg+so=
cloud.o-forge.io/core/oc-lib v0.0.0-20240822083903-bfa176a7c5ce/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
cloud.o-forge.io/core/oc-lib v0.0.0-20240822112243-e69e13d8daf8 h1:35Hrl4lwqUom5Rbfi9wLRg2yMou3bTeL2ZAaDY0N79Y=
cloud.o-forge.io/core/oc-lib v0.0.0-20240822112243-e69e13d8daf8/go.mod h1:1hhYh5QWAbYw9cKplQ0ZD9PMgU8t6gPqiYF8sldv1HU=
cloud.o-forge.io/core/oc-lib v0.0.0-20240823082553-98fa1f6ca807 h1:BqqCAnV2pbrX09IoE3EaVgrKIJPTvzqPeMnt2nYhCs4=
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= 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=

21
main.go
View File

@ -9,7 +9,7 @@ import (
"github.com/goraz/onion" "github.com/goraz/onion"
) )
const defaultConfigFile = "/etc/oc/peers.json" const defaultConfigFile = "/etc/oc/conf.json"
func main() { func main() {
configFile := "" configFile := ""
@ -27,21 +27,18 @@ func main() {
tools.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"),
"", o.GetStringDefault("NATS_URL", "nats://localhost:4222"),
) )
oclib.Init("oc-peers") // 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.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("WORKFLOW_URL", ":8088"))
oclib.AddPath(oclib.LibDataEnum(oclib.WORKFLOW), o.GetStringDefault("WORKSPACE_URL", ":8089")) oclib.AddPath(oclib.LibDataEnum(oclib.WORKSPACE), o.GetStringDefault("WORKSPACE_URL", ":8089"))
oclib.AddPath(oclib.LibDataEnum(oclib.SHARED_WORKSPACE), o.GetStringDefault("SHARED_WORKSPACE_URL", ":8091")) 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
beego.BConfig.WebConfig.DirectoryIndex = true beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"

Binary file not shown.

View File

@ -45,7 +45,7 @@ func init() {
beego.GlobalControllerRouter["oc-peers/controllers:StatusController"] = append(beego.GlobalControllerRouter["oc-peers/controllers:StatusController"], beego.GlobalControllerRouter["oc-peers/controllers:StatusController"] = append(beego.GlobalControllerRouter["oc-peers/controllers:StatusController"],
beego.ControllerComments{ beego.ControllerComments{
Method: "Get", Method: "Status",
Router: `/`, Router: `/`,
AllowHTTPMethods: []string{"post"}, AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(), MethodParams: param.Make(),

View File

@ -15,7 +15,7 @@ import (
func init() { func init() {
ns := beego.NewNamespace("/oc/", ns := beego.NewNamespace("/oc/",
beego.NSNamespace("/peer/status", beego.NSNamespace("/status",
beego.NSInclude( beego.NSInclude(
&controllers.StatusController{}, &controllers.StatusController{},
), ),
@ -31,6 +31,5 @@ func init() {
), ),
), ),
) )
beego.AddNamespace(ns) beego.AddNamespace(ns)
} }

View File

@ -15,6 +15,123 @@
}, },
"basePath": "/oc/", "basePath": "/oc/",
"paths": { "paths": {
"/peer/": {
"get": {
"tags": [
"peer"
],
"description": "find all peer\n\u003cbr\u003e",
"operationId": "PeerController.GetAll",
"responses": {
"200": {
"description": "{peer} models.peer"
}
}
}
},
"/peer/search/{search}": {
"get": {
"tags": [
"peer"
],
"description": "search workspace\n\u003cbr\u003e",
"operationId": "PeerController.Search",
"parameters": [
{
"in": "path",
"name": "search",
"description": "the word search you want to get",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "{workspace} models.workspace"
}
}
}
},
"/peer/{id}": {
"get": {
"tags": [
"peer"
],
"description": "find peer by peerid\n\u003cbr\u003e",
"operationId": "PeerController.Get",
"parameters": [
{
"in": "path",
"name": "id",
"description": "the peer id you want to get",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "{peer} models.peer"
}
}
},
"put": {
"tags": [
"peer"
],
"description": "create peers\n\u003cbr\u003e",
"operationId": "PeerController.Update",
"parameters": [
{
"in": "path",
"name": "id",
"description": "the peer id you want to get",
"required": true,
"type": "string"
},
{
"in": "body",
"name": "body",
"description": "The peer content",
"required": true,
"schema": {
"$ref": "#/definitions/models.peer"
}
}
],
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/models.peer"
}
}
}
}
},
"/status/": {
"post": {
"tags": [
"status"
],
"description": "get peer status if it's alive\n\u003cbr\u003e",
"operationId": "StatusController.Status",
"parameters": [
{
"in": "body",
"name": "body",
"description": "of",
"schema": {
"$ref": "#/definitions/list"
}
}
],
"responses": {
"200": {
"description": "{status} models.status"
}
}
}
},
"/version/": { "/version/": {
"get": { "get": {
"tags": [ "tags": [
@ -28,78 +145,25 @@
} }
} }
} }
},
"/workflow_execution/": {
"get": {
"tags": [
"workflow_execution"
],
"description": "find workflow by workflowid\n\u003cbr\u003e",
"operationId": "WorkflowExecutionController.GetAll",
"responses": {
"200": {
"description": "{workflow} models.workflow"
}
}
} }
}, },
"/workflow_execution/search/{start_date}/{end_date}": { "definitions": {
"get": { "list": {
"tags": [ "title": "list",
"workflow_execution" "type": "object"
],
"description": "search workspace\n\u003cbr\u003e",
"operationId": "WorkflowExecutionController.Search",
"parameters": [
{
"in": "path",
"name": "start_date",
"description": "the word search you want to get",
"required": true,
"type": "string"
}, },
{ "models.peer": {
"in": "path", "title": "peer",
"name": "end_date", "type": "object"
"description": "the word search you want to get",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "{workspace} models.workspace"
}
}
}
},
"/workflow_execution/{id}": {
"get": {
"tags": [
"workflow_execution"
],
"description": "find workflow by workflowid\n\u003cbr\u003e",
"operationId": "WorkflowExecutionController.Get",
"parameters": [
{
"in": "path",
"name": "id",
"description": "the workflowid you want to get",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "{workflow} models.workflow"
}
}
}
} }
}, },
"tags": [ "tags": [
{ {
"name": "workflow_execution", "name": "status",
"description": "Operations about workflow\n"
},
{
"name": "peer",
"description": "Operations about workflow\n" "description": "Operations about workflow\n"
}, },
{ {

View File

@ -12,6 +12,92 @@ info:
url: http://www.apache.org/licenses/LICENSE-2.0.html url: http://www.apache.org/licenses/LICENSE-2.0.html
basePath: /oc/ basePath: /oc/
paths: paths:
/peer/:
get:
tags:
- peer
description: |-
find all peer
<br>
operationId: PeerController.GetAll
responses:
"200":
description: '{peer} models.peer'
/peer/{id}:
get:
tags:
- peer
description: |-
find peer by peerid
<br>
operationId: PeerController.Get
parameters:
- in: path
name: id
description: the peer id you want to get
required: true
type: string
responses:
"200":
description: '{peer} models.peer'
put:
tags:
- peer
description: |-
create peers
<br>
operationId: PeerController.Update
parameters:
- in: path
name: id
description: the peer id you want to get
required: true
type: string
- in: body
name: body
description: The peer content
required: true
schema:
$ref: '#/definitions/models.peer'
responses:
"200":
description: ""
schema:
$ref: '#/definitions/models.peer'
/peer/search/{search}:
get:
tags:
- peer
description: |-
search workspace
<br>
operationId: PeerController.Search
parameters:
- in: path
name: search
description: the word search you want to get
required: true
type: string
responses:
"200":
description: '{workspace} models.workspace'
/status/:
post:
tags:
- status
description: |-
get peer status if it's alive
<br>
operationId: StatusController.Status
parameters:
- in: body
name: body
description: of
schema:
$ref: '#/definitions/list'
responses:
"200":
description: '{status} models.status'
/version/: /version/:
get: get:
tags: tags:
@ -23,58 +109,18 @@ paths:
responses: responses:
"200": "200":
description: "" description: ""
/workflow_execution/: definitions:
get: list:
tags: title: list
- workflow_execution type: object
description: |- models.peer:
find workflow by workflowid title: peer
<br> type: object
operationId: WorkflowExecutionController.GetAll
responses:
"200":
description: '{workflow} models.workflow'
/workflow_execution/{id}:
get:
tags:
- workflow_execution
description: |-
find workflow by workflowid
<br>
operationId: WorkflowExecutionController.Get
parameters:
- in: path
name: id
description: the workflowid you want to get
required: true
type: string
responses:
"200":
description: '{workflow} models.workflow'
/workflow_execution/search/{start_date}/{end_date}:
get:
tags:
- workflow_execution
description: |-
search workspace
<br>
operationId: WorkflowExecutionController.Search
parameters:
- in: path
name: start_date
description: the word search you want to get
required: true
type: string
- in: path
name: end_date
description: the word search you want to get
required: true
type: string
responses:
"200":
description: '{workspace} models.workspace'
tags: tags:
- name: workflow_execution - name: status
description: |
Operations about workflow
- name: peer
description: | description: |
Operations about workflow Operations about workflow
- name: version - name: version