config pb
This commit is contained in:
parent
070f2d063e
commit
53811538c0
@ -4,6 +4,7 @@ import (
|
|||||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||||
"cloud.o-forge.io/core/oc-lib/logs"
|
"cloud.o-forge.io/core/oc-lib/logs"
|
||||||
"cloud.o-forge.io/core/oc-lib/models"
|
"cloud.o-forge.io/core/oc-lib/models"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
@ -12,12 +13,11 @@ type LibDataEnum int
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
INVALID LibDataEnum = iota
|
INVALID LibDataEnum = iota
|
||||||
DATA_RESOURCE = utils.DATA_RESOURCE
|
DATA = resources.DATA
|
||||||
PROCESSING_RESOURCE = utils.PROCESSING_RESOURCE
|
PROCESSING = resources.PROCESSING
|
||||||
STORAGE_RESOURCE = utils.STORAGE_RESOURCE
|
STORAGE = resources.STORAGE
|
||||||
DATACENTER_RESOURCE = utils.DATACENTER_RESOURCE
|
DATACENTER = resources.DATACENTER
|
||||||
WORKFLOW_RESOURCE = utils.WORKFLOW_RESOURCE
|
WORKFLOW = resources.WORKFLOW
|
||||||
WORKFLOW = utils.WORKFLOW
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d LibDataEnum) EnumIndex() int {
|
func (d LibDataEnum) EnumIndex() int {
|
||||||
@ -25,9 +25,8 @@ func (d LibDataEnum) EnumIndex() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type LibData struct {
|
type LibData struct {
|
||||||
DataResource utils.DBObject `bson:"data" json:"data"`
|
Data utils.DBObject `bson:"data" json:"data"`
|
||||||
Code int `bson:"code" json:"code"`
|
Err error `bson:"error" json:"error"`
|
||||||
Err string `bson:"error" json:"error"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Init(appName string) {
|
func Init(appName string) {
|
||||||
@ -41,30 +40,22 @@ func GetLogger() zerolog.Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func LoadOne(collection LibDataEnum, id string) LibData {
|
func LoadOne(collection LibDataEnum, id string) LibData {
|
||||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().LoadOne(id)
|
d, err := models.Model(collection.EnumIndex()).GetAccessor().LoadOne(id)
|
||||||
return LibData{DataResource: d, Code: code, Err: err.Error()}
|
return LibData{Data: d, Err: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string) LibData {
|
func UpdateOne(collection LibDataEnum, set map[string]interface{}, id string) LibData {
|
||||||
model := models.Model(collection.EnumIndex())
|
d, err := models.Model(collection.EnumIndex()).GetAccessor().UpdateOne(set, id)
|
||||||
set = model.Deserialize(set).Serialize()
|
return LibData{Data: d, Err: err}
|
||||||
d, code, err := model.GetAccessor().UpdateOne(set, id)
|
|
||||||
return LibData{DataResource: d, Code: code, Err: err.Error()}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteOne(collection LibDataEnum, id string) LibData {
|
func DeleteOne(collection LibDataEnum, id string) LibData {
|
||||||
d, code, err := models.Model(collection.EnumIndex()).GetAccessor().DeleteOne(id)
|
d, err := models.Model(collection.EnumIndex()).GetAccessor().DeleteOne(id)
|
||||||
return LibData{DataResource: d, Code: code, Err: err.Error()}
|
return LibData{Data: d, Err: err}
|
||||||
}
|
|
||||||
|
|
||||||
func CopyOne(collection LibDataEnum, object map[string]interface{}) LibData {
|
|
||||||
model := models.Model(collection.EnumIndex())
|
|
||||||
d, code, err := model.GetAccessor().CopyOne(model.Deserialize(object))
|
|
||||||
return LibData{DataResource: d, Code: code, Err: err.Error()}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func StoreOne(collection LibDataEnum, object map[string]interface{}) LibData {
|
func StoreOne(collection LibDataEnum, object map[string]interface{}) LibData {
|
||||||
model := models.Model(collection.EnumIndex())
|
model := models.Model(collection.EnumIndex())
|
||||||
d, code, err := model.GetAccessor().StoreOne(model.Deserialize(object))
|
d, err := model.GetAccessor().StoreOne(model.Deserialize(object))
|
||||||
return LibData{DataResource: d, Code: code, Err: err.Error()}
|
return LibData{Data: d, Err: err}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ import (
|
|||||||
type DataResource struct {
|
type DataResource struct {
|
||||||
resources.AbstractResource
|
resources.AbstractResource
|
||||||
Protocols []string `json:"protocol,omitempty" bson:"protocol,omitempty"` //TODO Enum type
|
Protocols []string `json:"protocol,omitempty" bson:"protocol,omitempty"` //TODO Enum type
|
||||||
DataType string `json:"datatype" required:"true" bson:"datatype"`
|
DataType string `json:"datatype" bson:"datatype"`
|
||||||
Example string `json:"example" bson:"example" required:"true" validate:"required" description:"base64 encoded data"`
|
Example string `json:"example" bson:"example" description:"base64 encoded data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dma *DataResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
func (dma *DataResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||||
|
@ -9,8 +9,7 @@ import (
|
|||||||
|
|
||||||
type DatacenterResource struct {
|
type DatacenterResource struct {
|
||||||
resources.AbstractResource
|
resources.AbstractResource
|
||||||
Owner string `bson:"owner" json:"owner" required:"true"`
|
BookingPrice int `bson:"booking_price" json:"booking_price"`
|
||||||
BookingPrice int `bson:"booking_price" json:"booking_price" required:"true"`
|
|
||||||
|
|
||||||
CPU DatacenterCpuModel `bson:"cpu,omitempty" json:"cpu,omitempty"`
|
CPU DatacenterCpuModel `bson:"cpu,omitempty" json:"cpu,omitempty"`
|
||||||
RAM DatacenterMemoryModel `bson:"ram,omitempty" json:"ram,omitempty"`
|
RAM DatacenterMemoryModel `bson:"ram,omitempty" json:"ram,omitempty"`
|
||||||
|
@ -18,12 +18,12 @@ type Resource interface {
|
|||||||
|
|
||||||
type AbstractResource struct {
|
type AbstractResource struct {
|
||||||
utils.AbstractObject
|
utils.AbstractObject
|
||||||
ShortDescription string `json:"short_description" required:"true" bson:"short_description" validate:"required"`
|
ShortDescription string `json:"short_description" bson:"short_description" validate:"required"`
|
||||||
Description string `json:"description,omitempty" bson:"description"`
|
Description string `json:"description,omitempty" bson:"description"`
|
||||||
Logo string `json:"logo" required:"true" bson:"logo" validate:"required"`
|
Logo string `json:"logo" bson:"logo" validate:"required"`
|
||||||
Owner string `json:"owner" required:"true" bson:"owner" validate:"required"`
|
Owner string `json:"owner" bson:"owner" validate:"required"`
|
||||||
OwnerLogo string `json:"owner_logo" required:"true" bson:"owner_logo"`
|
OwnerLogo string `json:"owner_logo" bson:"owner_logo"`
|
||||||
SourceUrl string `json:"source_url" required:"true" bson:"source_url" validate:"required"`
|
SourceUrl string `json:"source_url" bson:"source_url" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dma *AbstractResource) ObjDeserialize(j map[string]interface{}) *AbstractResource {
|
func (dma *AbstractResource) ObjDeserialize(j map[string]interface{}) *AbstractResource {
|
||||||
|
@ -1,41 +1,41 @@
|
|||||||
package graph
|
package graph
|
||||||
|
|
||||||
type Graph struct {
|
type Graph struct {
|
||||||
Items map[string]GraphItem `bson:"items" json:"items" default:"{}" required:"true"`
|
Items map[string]GraphItem `bson:"items" json:"items" default:"{}" validate:"required"`
|
||||||
Links []GraphLink `bson:"links" json:"links" default:"{}" required:"true"`
|
Links []GraphLink `bson:"links" json:"links" default:"{}" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GraphItem struct {
|
type GraphItem struct {
|
||||||
ID string `bson:"ID" json:"ID" required:"true"`
|
ID string `bson:"ID" json:"ID" validate:"required"`
|
||||||
Width float64 `bson:"width" json:"width" required:"true"`
|
Width float64 `bson:"width" json:"width" validate:"required"`
|
||||||
Height float64 `bson:"height" json:"height" required:"true"`
|
Height float64 `bson:"height" json:"height" validate:"required"`
|
||||||
Position Position `bson:"position" json:"position" required:"true"`
|
Position Position `bson:"position" json:"position" validate:"required"`
|
||||||
ResourceID string `bson:"resource_id" json:"resource_id" required:"true"`
|
ResourceID string `bson:"resource_id" json:"resource_id" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GraphLink struct {
|
type GraphLink struct {
|
||||||
Source Position `bson:"source" json:"source" required:"true"`
|
Source Position `bson:"source" json:"source" validate:"required"`
|
||||||
Destination Position `bson:"destination" json:"destination" required:"true"`
|
Destination Position `bson:"destination" json:"destination" validate:"required"`
|
||||||
Style GraphLinkStyle `bson:"style" json:"style" required:"true"`
|
Style GraphLinkStyle `bson:"style" json:"style" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GraphLinkStyle struct {
|
type GraphLinkStyle struct {
|
||||||
Color int64 `bson:"color" json:"color" required:"true"`
|
Color int64 `bson:"color" json:"color" validate:"required"`
|
||||||
Stroke float64 `bson:"stroke" json:"stroke" required:"true"`
|
Stroke float64 `bson:"stroke" json:"stroke" validate:"required"`
|
||||||
Tension float64 `bson:"tension" json:"tension"`
|
Tension float64 `bson:"tension" json:"tension"`
|
||||||
HeadRadius float64 `bson:"head_radius" json:"head_radius"`
|
HeadRadius float64 `bson:"head_radius" json:"head_radius"`
|
||||||
DashWidth float64 `bson:"dash_width" json:"dash_width"`
|
DashWidth float64 `bson:"dash_width" json:"dash_width"`
|
||||||
DashSpace float64 `bson:"dash_space" json:"dash_space"`
|
DashSpace float64 `bson:"dash_space" json:"dash_space"`
|
||||||
EndArrow Position `bson:"end_arrow" json:"end_arrow"`
|
EndArrow Position `bson:"end_arrow" json:"end_arrow"`
|
||||||
StartArrow Position `bson:"start_arrow" json:"start_arrow"`
|
StartArrow Position `bson:"start_arrow" json:"start_arrow"`
|
||||||
ArrowStyle int64 `bson:"arrow_style" json:"arrow_style" required:"true"`
|
ArrowStyle int64 `bson:"arrow_style" json:"arrow_style" validate:"required"`
|
||||||
ArrowDirection int64 `bson:"arrow_direction" json:"arrow_direction" required:"true"`
|
ArrowDirection int64 `bson:"arrow_direction" json:"arrow_direction" validate:"required"`
|
||||||
StartArrowWidth float64 `bson:"start_arrow_style" json:"start_arrow_style"`
|
StartArrowWidth float64 `bson:"start_arrow_style" json:"start_arrow_style"`
|
||||||
EndArrowWidth float64 `bson:"end_arrow_style" json:"end_arrow_style"`
|
EndArrowWidth float64 `bson:"end_arrow_style" json:"end_arrow_style"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Position struct {
|
type Position struct {
|
||||||
ID string `json:"ID" required:"true"`
|
ID string `json:"ID" validate:"required"`
|
||||||
X float64 `json:"x" required:"true"`
|
X float64 `json:"x" validate:"required"`
|
||||||
Y float64 `json:"y" required:"true"`
|
Y float64 `json:"y" validate:"required"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user