organize + graph
This commit is contained in:
41
models/workflow/graph/graph.go
Normal file
41
models/workflow/graph/graph.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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"`
|
||||
}
|
45
models/workflow/workflow.go
Normal file
45
models/workflow/workflow.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package oclib
|
||||
|
||||
import (
|
||||
"oc-lib/models/resources"
|
||||
"oc-lib/models/resources/data"
|
||||
"oc-lib/models/resources/datacenter"
|
||||
"oc-lib/models/resources/processing"
|
||||
"oc-lib/models/resources/storage"
|
||||
"oc-lib/models/utils"
|
||||
"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(driver utils.Driver) utils.Accessor {
|
||||
var data utils.Accessor
|
||||
switch driver {
|
||||
case utils.MONGO:
|
||||
data = &WorkflowMongoAccessor{}
|
||||
default:
|
||||
data = &WorkflowMongoAccessor{}
|
||||
}
|
||||
data.SetLogger()
|
||||
return data
|
||||
}
|
||||
|
||||
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
|
||||
}
|
43
models/workflow/workflow_mongo_accessor.go
Normal file
43
models/workflow/workflow_mongo_accessor.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package oclib
|
||||
|
||||
import (
|
||||
"oc-lib/dbs/mongo"
|
||||
"oc-lib/logs"
|
||||
"oc-lib/models/utils"
|
||||
)
|
||||
|
||||
type WorkflowMongoAccessor struct {
|
||||
utils.AbstractAccessor
|
||||
}
|
||||
|
||||
func (dma *WorkflowMongoAccessor) DeleteOne(id string) utils.DBObject {
|
||||
return dma.GenericDeleteOne(id, dma)
|
||||
}
|
||||
|
||||
func (dma *WorkflowMongoAccessor) UpdateOne(set map[string]interface{}, id string) utils.DBObject {
|
||||
return dma.GenericUpdateOne(set, id, dma)
|
||||
}
|
||||
|
||||
func (dma *WorkflowMongoAccessor) StoreOne(data utils.DBObject) utils.DBObject {
|
||||
id, err := mongo.StoreOne(data.(*Workflow), "data")
|
||||
if err != nil {
|
||||
dma.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())
|
||||
return &Workflow{}
|
||||
}
|
||||
return dma.LoadOne(id)
|
||||
}
|
||||
|
||||
func (wfa *WorkflowMongoAccessor) LoadOne(id string) utils.DBObject {
|
||||
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
|
||||
}
|
15
models/workflow/workflow_schedule.go
Normal file
15
models/workflow/workflow_schedule.go
Normal 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
|
||||
}
|
43
models/workflow/workflow_test.go
Normal file
43
models/workflow/workflow_test.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package oclib
|
||||
|
||||
import (
|
||||
"oc-lib/models/resources"
|
||||
"testing"
|
||||
|
||||
"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)
|
||||
}
|
Reference in New Issue
Block a user