This commit is contained in:
mr 2024-11-07 13:42:19 +01:00
parent 21b3041783
commit 5f5072f176
10 changed files with 182 additions and 177 deletions

82
controllers/compute.go Normal file
View File

@ -0,0 +1,82 @@
package controllers
import (
"encoding/json"
oclib "cloud.o-forge.io/core/oc-lib"
beego "github.com/beego/beego/v2/server/web"
)
// Operations about compute
type ComputeController struct {
beego.Controller
}
// @Title Update
// @Description create computes
// @Param id path string true "the compute id you want to get"
// @Param body body models.compute true "The compute content"
// @Success 200 {compute} models.compute
// @router /:id [put]
func (o *ComputeController) 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)
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.COMPUTE_RESOURCE), res, id)
o.ServeJSON()
}
// @Title Create
// @Description create compute
// @Param compute body json true "body for compute content (Json format)"
// @Success 200 {compute} models.compute
// @router / [post]
func (o *ComputeController) Post() {
var res map[string]interface{}
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
o.Data["json"] = oclib.StoreOne(oclib.LibDataEnum(oclib.COMPUTE_RESOURCE), res)
o.ServeJSON()
}
// @Title GetAll
// @Description find compute by id
// @Success 200 {compute} models.compute
// @router / [get]
func (o *ComputeController) GetAll() {
o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(oclib.COMPUTE_RESOURCE))
o.ServeJSON()
}
// @Title Get
// @Description find compute by key word
// @Param search path string true "the search you want to get"
// @Success 200 {compute} models.compute
// @router /search/:search [get]
func (o *ComputeController) Search() {
search := o.Ctx.Input.Param(":search")
o.Data["json"] = oclib.Search(nil, search, oclib.LibDataEnum(oclib.COMPUTE_RESOURCE))
o.ServeJSON()
}
// @Title Get
// @Description find compute by id
// @Param id path string true "the id you want to get"
// @Success 200 {compute} models.compute
// @router /:id [get]
func (o *ComputeController) Get() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(oclib.COMPUTE_RESOURCE), id)
o.ServeJSON()
}
// @Title Delete
// @Description delete the compute
// @Param id path string true "The id you want to delete"
// @Success 200 {compute} delete success!
// @router /:id [delete]
func (o *ComputeController) Delete() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.COMPUTE_RESOURCE), id)
o.ServeJSON()
}

View File

@ -1,82 +0,0 @@
package controllers
import (
"encoding/json"
oclib "cloud.o-forge.io/core/oc-lib"
beego "github.com/beego/beego/v2/server/web"
)
// Operations about datacenter
type DatacenterController struct {
beego.Controller
}
// @Title Update
// @Description create datacenters
// @Param id path string true "the datacenter id you want to get"
// @Param body body models.datacenter true "The datacenter content"
// @Success 200 {datacenter} models.datacenter
// @router /:id [put]
func (o *DatacenterController) 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)
o.Data["json"] = oclib.UpdateOne(oclib.LibDataEnum(oclib.DATACENTER_RESOURCE), res, id)
o.ServeJSON()
}
// @Title Create
// @Description create datacenter
// @Param datacenter body json true "body for datacenter content (Json format)"
// @Success 200 {datacenter} models.datacenter
// @router / [post]
func (o *DatacenterController) Post() {
var res map[string]interface{}
json.Unmarshal(o.Ctx.Input.CopyBody(10000), &res)
o.Data["json"] = oclib.StoreOne(oclib.LibDataEnum(oclib.DATACENTER_RESOURCE), res)
o.ServeJSON()
}
// @Title GetAll
// @Description find datacenter by id
// @Success 200 {datacenter} models.datacenter
// @router / [get]
func (o *DatacenterController) GetAll() {
o.Data["json"] = oclib.LoadAll(oclib.LibDataEnum(oclib.DATACENTER_RESOURCE))
o.ServeJSON()
}
// @Title Get
// @Description find datacenter by key word
// @Param search path string true "the search you want to get"
// @Success 200 {datacenter} models.datacenter
// @router /search/:search [get]
func (o *DatacenterController) Search() {
search := o.Ctx.Input.Param(":search")
o.Data["json"] = oclib.Search(nil, search, oclib.LibDataEnum(oclib.DATACENTER_RESOURCE))
o.ServeJSON()
}
// @Title Get
// @Description find datacenter by id
// @Param id path string true "the id you want to get"
// @Success 200 {datacenter} models.datacenter
// @router /:id [get]
func (o *DatacenterController) Get() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.LoadOne(oclib.LibDataEnum(oclib.DATACENTER_RESOURCE), id)
o.ServeJSON()
}
// @Title Delete
// @Description delete the datacenter
// @Param id path string true "The id you want to delete"
// @Success 200 {datacenter} delete success!
// @router /:id [delete]
func (o *DatacenterController) Delete() {
id := o.Ctx.Input.Param(":id")
o.Data["json"] = oclib.DeleteOne(oclib.LibDataEnum(oclib.DATACENTER_RESOURCE), id)
o.ServeJSON()
}

View File

@ -18,7 +18,7 @@ func (o *ResourceController) GetAll() {
results := map[string]interface{}{}
for _, resource := range []oclib.LibDataEnum{
oclib.LibDataEnum(oclib.DATA_RESOURCE),
oclib.LibDataEnum(oclib.DATACENTER_RESOURCE),
oclib.LibDataEnum(oclib.COMPUTE_RESOURCE),
oclib.LibDataEnum(oclib.STORAGE_RESOURCE),
oclib.LibDataEnum(oclib.PROCESSING_RESOURCE),
oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE)} {
@ -43,7 +43,7 @@ func (o *ResourceController) Search() {
results := map[string]interface{}{}
for _, resource := range []oclib.LibDataEnum{
oclib.LibDataEnum(oclib.DATA_RESOURCE),
oclib.LibDataEnum(oclib.DATACENTER_RESOURCE),
oclib.LibDataEnum(oclib.COMPUTE_RESOURCE),
oclib.LibDataEnum(oclib.STORAGE_RESOURCE),
oclib.LibDataEnum(oclib.PROCESSING_RESOURCE),
oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE)} {
@ -68,7 +68,7 @@ func (o *ResourceController) Get() {
results := map[string]interface{}{}
for _, resource := range []oclib.LibDataEnum{
oclib.LibDataEnum(oclib.DATA_RESOURCE),
oclib.LibDataEnum(oclib.DATACENTER_RESOURCE),
oclib.LibDataEnum(oclib.COMPUTE_RESOURCE),
oclib.LibDataEnum(oclib.STORAGE_RESOURCE),
oclib.LibDataEnum(oclib.PROCESSING_RESOURCE),
oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE)} {
@ -93,7 +93,7 @@ func (o *ResourceController) Delete() {
results := map[string]interface{}{}
for _, resource := range []oclib.LibDataEnum{
oclib.LibDataEnum(oclib.DATA_RESOURCE),
oclib.LibDataEnum(oclib.DATACENTER_RESOURCE),
oclib.LibDataEnum(oclib.COMPUTE_RESOURCE),
oclib.LibDataEnum(oclib.STORAGE_RESOURCE),
oclib.LibDataEnum(oclib.PROCESSING_RESOURCE),
oclib.LibDataEnum(oclib.WORKFLOW_RESOURCE)} {

View File

@ -627,19 +627,19 @@
]
},
{
"api": "/oc/datacenter/",
"api": "/oc/compute/",
"content": [
{
"name": "Mundi datacenter",
"name": "Mundi compute",
"acronym": "DC_myDC",
"hosts": [
"localhost:49618",
"oc-catalog:49618"
],
"short_description": "Mundi Opencloud Instance",
"logo": "https://cloud.o-forge.io/core/deperecated-oc-catalog/raw/branch/main/scripts/local_imgs/Mundi datacenter.png",
"logo": "https://cloud.o-forge.io/core/deperecated-oc-catalog/raw/branch/main/scripts/local_imgs/Mundi compute.png",
"description": "A very long description of what this data is",
"type": "datacenter",
"type": "compute",
"bookingPrice": 650,
"owner": "IRT",
"cpus": [{
@ -662,16 +662,16 @@
"source_url": "http://www.google.com"
},
{
"name": "CNES datacenter",
"name": "CNES compute",
"acronym": "DC_superDC1",
"hosts": [
"localhost:49619",
"dc1:49618"
],
"short_description": "CNES Opencloud Instance",
"logo": "https://cloud.o-forge.io/core/deperecated-oc-catalog/raw/branch/main/scripts/local_imgs/CNES datacenter.png",
"logo": "https://cloud.o-forge.io/core/deperecated-oc-catalog/raw/branch/main/scripts/local_imgs/CNES compute.png",
"description": "A very long description of what this data is",
"type": "datacenter",
"type": "compute",
"bookingPrice": 650,
"owner": "IRT",
"cpus": [{
@ -687,16 +687,16 @@
"source_url": "http://www.google.com"
},
{
"name": "Meteo France datacenter",
"name": "Meteo France compute",
"acronym": "DC_superDC2",
"hosts": [
"localhost:49620",
"dc2:49618"
],
"short_description": "Meteo France Opencloud Instance",
"logo": "https://cloud.o-forge.io/core/deperecated-oc-catalog/raw/branch/main/scripts/local_imgs/Meteo France datacenter.png",
"logo": "https://cloud.o-forge.io/core/deperecated-oc-catalog/raw/branch/main/scripts/local_imgs/Meteo France compute.png",
"description": "A very long description of what this data is",
"type": "datacenter",
"type": "compute",
"bookingPrice": 650,
"owner": "Meteo France",
"cpus": [{

2
go.mod Normal file → Executable file
View File

@ -5,7 +5,7 @@ go 1.22.0
toolchain go1.22.4
require (
cloud.o-forge.io/core/oc-lib v0.0.0-20241030105814-5f05b73366ab
cloud.o-forge.io/core/oc-lib v0.0.0-20241107122526-f3df1e42b9ba
github.com/beego/beego/v2 v2.3.1
github.com/smartystreets/goconvey v1.7.2
)

5
go.sum Normal file → Executable file
View File

@ -16,11 +16,16 @@ cloud.o-forge.io/core/oc-lib v0.0.0-20241030091613-1a5521237800 h1:uZ4Qrxk/KEpOf
cloud.o-forge.io/core/oc-lib v0.0.0-20241030091613-1a5521237800/go.mod h1:t+zpCTVKVdHH/BImwtMYY2QIWLMXKgY4n/JhFm3Vpu8=
cloud.o-forge.io/core/oc-lib v0.0.0-20241030105814-5f05b73366ab h1:hYUf9xXpqhp9w0eBfOWVi7c17iWpN+FL2FbhsAkmQ2E=
cloud.o-forge.io/core/oc-lib v0.0.0-20241030105814-5f05b73366ab/go.mod h1:t+zpCTVKVdHH/BImwtMYY2QIWLMXKgY4n/JhFm3Vpu8=
cloud.o-forge.io/core/oc-lib v0.0.0-20241107114600-4c0c75be9161 h1:so5V7C6kiJ9tpuxtgK/KcgjXQC2ythInAH8X2gohuaM=
cloud.o-forge.io/core/oc-lib v0.0.0-20241107114600-4c0c75be9161/go.mod h1:ya7Q+zHhaKM+XF6sAJ+avqHEVzaMnFJQih2X3TlTlGo=
cloud.o-forge.io/core/oc-lib v0.0.0-20241107122526-f3df1e42b9ba h1:MGd8N7bY1LWXMhAp7gibDNwMS2hsatLQ3rfayvy5rGs=
cloud.o-forge.io/core/oc-lib v0.0.0-20241107122526-f3df1e42b9ba/go.mod h1:ya7Q+zHhaKM+XF6sAJ+avqHEVzaMnFJQih2X3TlTlGo=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/beego/beego/v2 v2.3.0 h1:iECVwzm6egw6iw6tkWrEDqXG4NQtKLQ6QBSYqlM6T/I=
github.com/beego/beego/v2 v2.3.0/go.mod h1:Ob/5BJ9fIKZLd4s9ZV3o9J6odkkIyL83et+p98gyYXo=
github.com/beego/beego/v2 v2.3.1 h1:7MUKMpJYzOXtCUsTEoXOxsDV/UcHw6CPbaWMlthVNsc=
github.com/beego/beego/v2 v2.3.1/go.mod h1:5cqHsOHJIxkq44tBpRvtDe59GuVRVv/9/tyVDxd5ce4=
github.com/beego/beego/v2 v2.3.2/go.mod h1:5cqHsOHJIxkq44tBpRvtDe59GuVRVv/9/tyVDxd5ce4=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=

View File

@ -61,7 +61,7 @@ func init() {
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["oc-catalog/controllers:DatacenterController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:DatacenterController"],
beego.GlobalControllerRouter["oc-catalog/controllers:ComputeController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:ComputeController"],
beego.ControllerComments{
Method: "Post",
Router: `/`,
@ -70,7 +70,7 @@ func init() {
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["oc-catalog/controllers:DatacenterController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:DatacenterController"],
beego.GlobalControllerRouter["oc-catalog/controllers:ComputeController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:ComputeController"],
beego.ControllerComments{
Method: "GetAll",
Router: `/`,
@ -79,7 +79,7 @@ func init() {
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["oc-catalog/controllers:DatacenterController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:DatacenterController"],
beego.GlobalControllerRouter["oc-catalog/controllers:ComputeController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:ComputeController"],
beego.ControllerComments{
Method: "Put",
Router: `/:id`,
@ -88,7 +88,7 @@ func init() {
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["oc-catalog/controllers:DatacenterController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:DatacenterController"],
beego.GlobalControllerRouter["oc-catalog/controllers:ComputeController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:ComputeController"],
beego.ControllerComments{
Method: "Get",
Router: `/:id`,
@ -97,7 +97,7 @@ func init() {
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["oc-catalog/controllers:DatacenterController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:DatacenterController"],
beego.GlobalControllerRouter["oc-catalog/controllers:ComputeController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:ComputeController"],
beego.ControllerComments{
Method: "Delete",
Router: `/:id`,
@ -106,7 +106,7 @@ func init() {
Filters: nil,
Params: nil})
beego.GlobalControllerRouter["oc-catalog/controllers:DatacenterController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:DatacenterController"],
beego.GlobalControllerRouter["oc-catalog/controllers:ComputeController"] = append(beego.GlobalControllerRouter["oc-catalog/controllers:ComputeController"],
beego.ControllerComments{
Method: "Search",
Router: `/search/:search`,

View File

@ -25,9 +25,9 @@ func init() {
&controllers.DataController{},
),
),
beego.NSNamespace("/datacenter",
beego.NSNamespace("/compute",
beego.NSInclude(
&controllers.DatacenterController{},
&controllers.ComputeController{},
),
),
beego.NSNamespace("/storage",

View File

@ -149,30 +149,30 @@
}
}
},
"/datacenter/": {
"/compute/": {
"get": {
"tags": [
"datacenter"
"compute"
],
"description": "find datacenter by id\n\u003cbr\u003e",
"operationId": "DatacenterController.GetAll",
"description": "find compute by id\n\u003cbr\u003e",
"operationId": "ComputeController.GetAll",
"responses": {
"200": {
"description": "{datacenter} models.datacenter"
"description": "{compute} models.compute"
}
}
},
"post": {
"tags": [
"datacenter"
"compute"
],
"description": "create datacenter\n\u003cbr\u003e",
"operationId": "DatacenterController.Create",
"description": "create compute\n\u003cbr\u003e",
"operationId": "ComputeController.Create",
"parameters": [
{
"in": "body",
"name": "datacenter",
"description": "body for datacenter content (Json format)",
"name": "compute",
"description": "body for compute content (Json format)",
"required": true,
"schema": {
"$ref": "#/definitions/json"
@ -181,18 +181,18 @@
],
"responses": {
"200": {
"description": "{datacenter} models.datacenter"
"description": "{compute} models.compute"
}
}
}
},
"/datacenter/search/{search}": {
"/compute/search/{search}": {
"get": {
"tags": [
"datacenter"
"compute"
],
"description": "find datacenter by key word\n\u003cbr\u003e",
"operationId": "DatacenterController.Get",
"description": "find compute by key word\n\u003cbr\u003e",
"operationId": "ComputeController.Get",
"parameters": [
{
"in": "path",
@ -204,18 +204,18 @@
],
"responses": {
"200": {
"description": "{datacenter} models.datacenter"
"description": "{compute} models.compute"
}
}
}
},
"/datacenter/{id}": {
"/compute/{id}": {
"get": {
"tags": [
"datacenter"
"compute"
],
"description": "find datacenter by id\n\u003cbr\u003e",
"operationId": "DatacenterController.Get",
"description": "find compute by id\n\u003cbr\u003e",
"operationId": "ComputeController.Get",
"parameters": [
{
"in": "path",
@ -227,46 +227,46 @@
],
"responses": {
"200": {
"description": "{datacenter} models.datacenter"
"description": "{compute} models.compute"
}
}
},
"put": {
"tags": [
"datacenter"
"compute"
],
"description": "create datacenters\n\u003cbr\u003e",
"operationId": "DatacenterController.Update",
"description": "create computes\n\u003cbr\u003e",
"operationId": "ComputeController.Update",
"parameters": [
{
"in": "path",
"name": "id",
"description": "the datacenter id you want to get",
"description": "the compute id you want to get",
"required": true,
"type": "string"
},
{
"in": "body",
"name": "body",
"description": "The datacenter content",
"description": "The compute content",
"required": true,
"schema": {
"$ref": "#/definitions/models.datacenter"
"$ref": "#/definitions/models.compute"
}
}
],
"responses": {
"200": {
"description": "{datacenter} models.datacenter"
"description": "{compute} models.compute"
}
}
},
"delete": {
"tags": [
"datacenter"
"compute"
],
"description": "delete the datacenter\n\u003cbr\u003e",
"operationId": "DatacenterController.Delete",
"description": "delete the compute\n\u003cbr\u003e",
"operationId": "ComputeController.Delete",
"parameters": [
{
"in": "path",
@ -278,7 +278,7 @@
],
"responses": {
"200": {
"description": "{datacenter} delete success!"
"description": "{compute} delete success!"
}
}
}
@ -804,8 +804,8 @@
"title": "data",
"type": "object"
},
"models.datacenter": {
"title": "datacenter",
"models.compute": {
"title": "compute",
"type": "object"
},
"models.processing": {
@ -831,8 +831,8 @@
"description": "Operations about data\n"
},
{
"name": "datacenter",
"description": "Operations about datacenter\n"
"name": "compute",
"description": "Operations about compute\n"
},
{
"name": "storage",

View File

@ -112,42 +112,42 @@ paths:
responses:
"200":
description: '{data} models.data'
/datacenter/:
/compute/:
get:
tags:
- datacenter
- compute
description: |-
find datacenter by id
find compute by id
<br>
operationId: DatacenterController.GetAll
operationId: ComputeController.GetAll
responses:
"200":
description: '{datacenter} models.datacenter'
description: '{compute} models.compute'
post:
tags:
- datacenter
- compute
description: |-
create datacenter
create compute
<br>
operationId: DatacenterController.Create
operationId: ComputeController.Create
parameters:
- in: body
name: datacenter
description: body for datacenter content (Json format)
name: compute
description: body for compute content (Json format)
required: true
schema:
$ref: '#/definitions/json'
responses:
"200":
description: '{datacenter} models.datacenter'
/datacenter/{id}:
description: '{compute} models.compute'
/compute/{id}:
get:
tags:
- datacenter
- compute
description: |-
find datacenter by id
find compute by id
<br>
operationId: DatacenterController.Get
operationId: ComputeController.Get
parameters:
- in: path
name: id
@ -156,36 +156,36 @@ paths:
type: string
responses:
"200":
description: '{datacenter} models.datacenter'
description: '{compute} models.compute'
put:
tags:
- datacenter
- compute
description: |-
create datacenters
create computes
<br>
operationId: DatacenterController.Update
operationId: ComputeController.Update
parameters:
- in: path
name: id
description: the datacenter id you want to get
description: the compute id you want to get
required: true
type: string
- in: body
name: body
description: The datacenter content
description: The compute content
required: true
schema:
$ref: '#/definitions/models.datacenter'
$ref: '#/definitions/models.compute'
responses:
"200":
description: '{datacenter} models.datacenter'
description: '{compute} models.compute'
delete:
tags:
- datacenter
- compute
description: |-
delete the datacenter
delete the compute
<br>
operationId: DatacenterController.Delete
operationId: ComputeController.Delete
parameters:
- in: path
name: id
@ -194,15 +194,15 @@ paths:
type: string
responses:
"200":
description: '{datacenter} delete success!'
/datacenter/search/{search}:
description: '{compute} delete success!'
/compute/search/{search}:
get:
tags:
- datacenter
- compute
description: |-
find datacenter by key word
find compute by key word
<br>
operationId: DatacenterController.Get
operationId: ComputeController.Get
parameters:
- in: path
name: search
@ -211,7 +211,7 @@ paths:
type: string
responses:
"200":
description: '{datacenter} models.datacenter'
description: '{compute} models.compute'
/processing/:
get:
tags:
@ -602,8 +602,8 @@ definitions:
models.data:
title: data
type: object
models.datacenter:
title: datacenter
models.compute:
title: compute
type: object
models.processing:
title: processing
@ -621,9 +621,9 @@ tags:
- name: data
description: |
Operations about data
- name: datacenter
- name: compute
description: |
Operations about datacenter
Operations about compute
- name: storage
description: |
Operations about storage