oc-lib/models/resources/workflow/workflow.go
2024-07-18 16:46:54 +02:00

49 lines
1.6 KiB
Go

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/resources/workflow/graph"
"cloud.o-forge.io/core/oc-lib/models/utils"
)
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(resources.WORKFLOW)
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
}