neo oc-peers

This commit is contained in:
mr 2024-08-26 12:07:54 +02:00
parent 5558ac4298
commit 61c92977fe
12 changed files with 278 additions and 151 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 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
@ -20,11 +20,11 @@ FROM scratch
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 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

@ -2,8 +2,8 @@ package controllers
import (
"encoding/json"
"fmt"
oclib "cloud.o-forge.io/core/oc-lib"
"cloud.o-forge.io/core/oc-lib/tools"
beego "github.com/beego/beego/v2/server/web"
)
@ -32,21 +32,28 @@ type StatusController struct {
// @Success 200 {status} models.status
// @router / [post]
func (o *StatusController) Status() {
var address []string
var address map[string]string
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &address)
fmt.Println(len(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")
for _, host := range []string{"oc-datacenter", "oc-workflow", "oc-workspace", "oc-shared"} {
address[host] = "http://" + host + ":8080/oc"
}
}
api := tools.API{}
state, code, err := api.CheckRemoteAPIs(address)
state, services, err := api.CheckRemoteAPIs(address)
errSTR := ""
if err != nil {
errSTR = err.Error()
}
o.Data["json"] = map[string]interface{}{
"data": map[string]string{
"state": state.String(),
"data": map[string]interface{}{
"state": state.String(),
"code": state.EnumIndex(),
"services": services,
},
"code": code,
"error": err.Error(),
"code": 200,
"error": errSTR,
}
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 (
cloud.o-forge.io/core/oc-lib v0.0.0-20240821140757-39030a0a80e8 // indirect
cloud.o-forge.io/core/oc-lib v0.0.0-20240823091301-5b3779e4cb21 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/beego/bee/v2 v2.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect

14
go.sum
View File

@ -160,6 +160,20 @@ 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-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-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=
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/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=

16
main.go
View File

@ -9,7 +9,7 @@ import (
"github.com/goraz/onion"
)
const defaultConfigFile = "/etc/oc/peers.json"
const defaultConfigFile = "/etc/oc/conf.json"
func main() {
configFile := ""
@ -27,21 +27,15 @@ func main() {
tools.SetConfig(
o.GetStringDefault("MONGO_URL", "mongodb://127.0.0.1:27017"),
o.GetStringDefault("MONGO_DATABASE", "DC_myDC"),
"",
o.GetStringDefault("NATS_URL", "nats://localhost:4222"),
)
oclib.Init("oc-peers")
oclib.Init("oc-peers", o.GetStringDefault("HOSTNAME", "localhost"), o.GetStringDefault("PORT", "8093"))
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.WORKSPACE), 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
beego.BConfig.WebConfig.DirectoryIndex = true
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.ControllerComments{
Method: "Get",
Method: "Status",
Router: `/`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),

View File

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

View File

@ -15,6 +15,123 @@
},
"basePath": "/oc/",
"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/": {
"get": {
"tags": [
@ -28,78 +145,25 @@
}
}
}
}
},
"definitions": {
"list": {
"title": "list",
"type": "object"
},
"/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}": {
"get": {
"tags": [
"workflow_execution"
],
"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"
},
{
"in": "path",
"name": "end_date",
"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"
}
}
}
"models.peer": {
"title": "peer",
"type": "object"
}
},
"tags": [
{
"name": "workflow_execution",
"name": "status",
"description": "Operations about workflow\n"
},
{
"name": "peer",
"description": "Operations about workflow\n"
},
{

View File

@ -12,6 +12,92 @@ info:
url: http://www.apache.org/licenses/LICENSE-2.0.html
basePath: /oc/
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/:
get:
tags:
@ -23,58 +109,18 @@ paths:
responses:
"200":
description: ""
/workflow_execution/:
get:
tags:
- workflow_execution
description: |-
find workflow by workflowid
<br>
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'
definitions:
list:
title: list
type: object
models.peer:
title: peer
type: object
tags:
- name: workflow_execution
- name: status
description: |
Operations about workflow
- name: peer
description: |
Operations about workflow
- name: version