apropriate db

This commit is contained in:
mr
2024-07-18 16:46:54 +02:00
parent d273fdc57f
commit 3e9eae007b
17 changed files with 92 additions and 93 deletions

View File

@@ -1,41 +0,0 @@
package graph
type Graph struct {
Items map[string]GraphItem `bson:"items" json:"items" default:"{}" required:"true"`
Links []GraphLink `bson:"links" json:"links" default:"{}" required:"true"`
}
type GraphItem struct {
ID string `bson:"ID" json:"ID" required:"true"`
Width float64 `bson:"width" json:"width" required:"true"`
Height float64 `bson:"height" json:"height" required:"true"`
Position Position `bson:"position" json:"position" required:"true"`
ResourceID string `bson:"resource_id" json:"resource_id" required:"true"`
}
type GraphLink struct {
Source Position `bson:"source" json:"source" required:"true"`
Destination Position `bson:"destination" json:"destination" required:"true"`
Style GraphLinkStyle `bson:"style" json:"style" required:"true"`
}
type GraphLinkStyle struct {
Color int64 `bson:"color" json:"color" required:"true"`
Stroke float64 `bson:"stroke" json:"stroke" required:"true"`
Tension float64 `bson:"tension" json:"tension"`
HeadRadius float64 `bson:"head_radius" json:"head_radius"`
DashWidth float64 `bson:"dash_width" json:"dash_width"`
DashSpace float64 `bson:"dash_space" json:"dash_space"`
EndArrow Position `bson:"end_arrow" json:"end_arrow"`
StartArrow Position `bson:"start_arrow" json:"start_arrow"`
ArrowStyle int64 `bson:"arrow_style" json:"arrow_style" required:"true"`
ArrowDirection int64 `bson:"arrow_direction" json:"arrow_direction" required:"true"`
StartArrowWidth float64 `bson:"start_arrow_style" json:"start_arrow_style"`
EndArrowWidth float64 `bson:"end_arrow_style" json:"end_arrow_style"`
}
type Position struct {
ID string `json:"ID" required:"true"`
X float64 `json:"x" required:"true"`
Y float64 `json:"y" required:"true"`
}

View File

@@ -1,50 +0,0 @@
package oclib
import (
"encoding/json"
"cloud.o-forge.io/core/oc-lib/models/resources"
"cloud.o-forge.io/core/oc-lib/models/resources/data"
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/models/workflow/graph"
)
const WORKFLOW = "workflow"
type Workflow struct {
resources.AbstractResource
Graph graph.Graph `bson:"graph,omitempty" json:"graph,omitempty"`
Datas map[string]data.Data `bson:"datas,omitempty" json:"datas,omitempty"`
Storages map[string]storage.Storage `bson:"storages,omitempty" json:"storages,omitempty"`
Processing map[string]processing.Processing `bson:"processing,omitempty" json:"processing,omitempty"`
Datacenters map[string]datacenter.Datacenter `bson:"datacenters,omitempty" json:"datacenters,omitempty"`
Schedule WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
}
func (d *Workflow) GetAccessor() utils.Accessor {
data := &WorkflowMongoAccessor{}
data.SetLogger()
return data
}
func (dma *Workflow) Deserialize(j map[string]interface{}) utils.DBObject {
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return dma
}
func (w *Workflow) isDCLink(link graph.GraphLink) bool {
if _, exists := w.Datacenters[link.Destination.ID]; exists {
return true
} else if _, exists := w.Datacenters[link.Source.ID]; exists {
return true
}
return false
}

View File

@@ -1,41 +0,0 @@
package oclib
import (
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
"cloud.o-forge.io/core/oc-lib/logs"
"cloud.o-forge.io/core/oc-lib/models/utils"
)
type WorkflowMongoAccessor struct {
utils.AbstractAccessor
}
func (dma *WorkflowMongoAccessor) DeleteOne(id string) (utils.DBObject, error) {
return dma.GenericDeleteOne(id, dma)
}
func (dma *WorkflowMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, error) {
return dma.GenericUpdateOne(set, id, dma)
}
func (dma *WorkflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) {
id, err := mongo.MONGOService.StoreOne(data.(*Workflow), "data")
if err != nil {
dma.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())
return nil, err
}
return dma.LoadOne(id)
}
func (wfa *WorkflowMongoAccessor) LoadOne(id string) (utils.DBObject, error) {
var workflow Workflow
res_mongo, err := mongo.MONGOService.LoadOne(id, "workflow")
if err != nil {
l := logs.CreateLogger("oclib", "")
l.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
return nil, err
}
res_mongo.Decode(&workflow)
return &workflow, nil
}

View File

@@ -1,15 +0,0 @@
package oclib
import "time"
type WorkflowSchedule struct {
Id string `json:"id"`
Start time.Time
End time.Time
Cron string
}
func (ws *WorkflowSchedule) GetAllDates() (timetable []time.Time){
// Return all the execution time generated by the Cron
return
}

View File

@@ -1,44 +0,0 @@
package oclib
import (
"testing"
"cloud.o-forge.io/core/oc-lib/models/resources"
"github.com/stretchr/testify/assert"
)
func TestStoreOneWorkflow(t *testing.T) {
w := Workflow{AbstractResource: resources.AbstractResource{
Uuid: "123",
Name: "testWorkflow",
Description: "Lorem Ipsum",
Logo: "azerty.com",
Owner: "toto",
OwnerLogo: "totoLogo",
SourceUrl: "azerty.fr",
},
}
wma := WorkflowMongoAccessor{}
id, _ := wma.StoreOne(&w)
assert.NotEmpty(t, id)
}
func TestLoadOneWorkflow(t *testing.T) {
w := Workflow{AbstractResource: resources.AbstractResource{
Uuid: "123",
Name: "testWorkflow",
Description: "Lorem Ipsum",
Logo: "azerty.com",
Owner: "toto",
OwnerLogo: "totoLogo",
SourceUrl: "azerty.fr",
},
}
wma := WorkflowMongoAccessor{}
new_w, _ := wma.StoreOne(&w)
assert.Equal(t, w, new_w)
}