packaged every model

This commit is contained in:
pb
2024-07-17 18:02:30 +02:00
parent 2684703da5
commit 2eb74da9d2
16 changed files with 731 additions and 0 deletions

34
workflow/workflow.go Normal file
View File

@@ -0,0 +1,34 @@
package oclib
import (
oclib "oc-lib"
"oc-lib/data"
"oc-lib/datacenter"
"oc-lib/link"
"oc-lib/processing"
"oc-lib/storage"
)
type Workflow struct {
oclib.AbstractResource `json:"abstract_resource" required:"true"`
Datas map[string]data.Data `json:"datas,omitempty"`
Storages map[string]storage.Storage `json:"storages,omitempty"`
Processing map[string]processing.Processing `json:"processing,omitempty"`
Datacenters map[string]datacenter.Datacenter `json:"datacenters,omitempty"`
Links map[string]link.Link `json:"links,omitempty"`
Schedule WorkflowSchedule `json:"schedule,omitempty"`
}
func (w *Workflow) isDCLink(link link.Link) bool {
if _, exists := w.Datacenters[link.Destination]; exists {
return true
} else if _, exists := w.Datacenters[link.Source]; exists {
return true
}
return false
}

View File

@@ -0,0 +1,34 @@
package oclib
import (
"oc-lib/logs"
"oc-lib/mongo"
)
type WorkflowMongoAccessor struct{}
func (wfa *WorkflowMongoAccessor) StoreOne(workflow Workflow) string {
id, err := mongo.StoreOne(workflow, "workflow")
if err != nil {
l := logs.CreateLogger("oclib", "")
l.Error().Msg("Could not store " + workflow.Name + " to db. Error: " + err.Error())
return ""
}
return id
}
func (wfa *WorkflowMongoAccessor) LoadOne(id string) Workflow {
var workflow Workflow
res_mongo, err := mongo.LoadOne(id, "workflow")
if err != nil {
l := logs.CreateLogger("oclib", "")
l.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
return Workflow{}
}
res_mongo.Decode(&workflow)
return workflow
}

View File

@@ -0,0 +1,15 @@
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
}

45
workflow/workflow_test.go Normal file
View File

@@ -0,0 +1,45 @@
package oclib
import (
oclib "oc-lib"
"testing"
"github.com/stretchr/testify/assert"
)
func TestStoreOneWorkflow(t *testing.T){
w := Workflow{AbstractResource: oclib.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: oclib.AbstractResource{
Uuid: "123",
Name: "testWorkflow",
Description: "Lorem Ipsum",
Logo : "azerty.com",
Owner: "toto",
OwnerLogo: "totoLogo",
SourceUrl: "azerty.fr",
},
}
wma := WorkflowMongoAccessor{}
id := wma.StoreOne(w)
new_w := wma.LoadOne(id)
assert.Equal(t,w, new_w)
}