oc-lib/models/resources/workflow/workflow.go
2024-07-24 09:53:30 +02:00

58 lines
1.7 KiB
Go

package oclib
import (
"encoding/json"
"slices"
"cloud.o-forge.io/core/oc-lib/models/resources"
"cloud.o-forge.io/core/oc-lib/models/resources/workflow/graph"
"cloud.o-forge.io/core/oc-lib/models/utils"
)
type AbstractWorkflow struct {
Graph *graph.Graph `bson:"graph,omitempty" json:"graph,omitempty"`
Datas []string `bson:"datas,omitempty" json:"datas,omitempty"`
Storages []string `bson:"storages,omitempty" json:"storages,omitempty"`
ProcessingResource []string `bson:"processing,omitempty" json:"processing,omitempty"`
Datacenters []string `bson:"datacenters,omitempty" json:"datacenters,omitempty"`
Workflows []string `bson:"workflows,omitempty" json:"workflows,omitempty"`
Schedule *WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
}
func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) bool {
if slices.Contains(w.Datacenters, link.Destination.ID) || slices.Contains(w.Datacenters, link.Source.ID) {
return true
}
return false
}
type WorkflowResource struct {
resources.AbstractResource
WorkflowID string `bson:"workflow_id,omitempty" json:"workflow_id,omitempty"`
}
func (d *WorkflowResource) GetAccessor() utils.Accessor {
data := &WorkflowResourceMongoAccessor{}
data.SetLogger(utils.WORKFLOW_RESOURCE)
return data
}
func (dma *WorkflowResource) Deserialize(j map[string]interface{}) utils.DBObject {
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return dma
}
func (dma *WorkflowResource) Serialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(dma)
if err != nil {
return nil
}
json.Unmarshal(b, &m)
return m
}