oc-lib/models/workflow/workflow.go

51 lines
1.6 KiB
Go
Raw Normal View History

2024-07-18 11:51:12 +02:00
package oclib
import (
2024-07-18 14:39:54 +02:00
"encoding/json"
2024-07-18 13:35:14 +02:00
"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"
2024-07-18 11:51:12 +02:00
)
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"`
}
2024-07-18 15:02:39 +02:00
func (d *Workflow) GetAccessor() utils.Accessor {
data := &WorkflowMongoAccessor{}
2024-07-18 11:51:12 +02:00
data.SetLogger()
return data
}
2024-07-18 14:39:54 +02:00
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
}
2024-07-18 11:51:12 +02:00
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
}