oc-lib/models/resources/workflow/workflow.go

88 lines
2.7 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"
2024-07-18 16:46:54 +02:00
"cloud.o-forge.io/core/oc-lib/models/resources/workflow/graph"
2024-07-18 13:35:14 +02:00
"cloud.o-forge.io/core/oc-lib/models/utils"
2024-07-18 11:51:12 +02:00
)
2024-07-19 10:54:58 +02:00
type AbstractWorkflow struct {
Graph graph.Graph `bson:"graph,omitempty" json:"graph,omitempty"`
Datas map[string]data.DataResource `bson:"datas,omitempty" json:"datas,omitempty"`
Storages map[string]storage.StorageResource `bson:"storages,omitempty" json:"storages,omitempty"`
ProcessingResource map[string]processing.ProcessingResource `bson:"processing,omitempty" json:"processing,omitempty"`
Datacenters map[string]datacenter.DatacenterResource `bson:"datacenters,omitempty" json:"datacenters,omitempty"`
Workflows map[string]WorkflowResource `bson:"workflows,omitempty" json:"workflows,omitempty"`
Schedule WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
}
2024-07-19 13:15:51 +02:00
func (w *AbstractWorkflow) ObjDeserialize(j map[string]interface{}) *AbstractWorkflow {
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, w)
return w
}
func (w *AbstractWorkflow) ObjSerialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(w)
if err != nil {
return nil
}
json.Unmarshal(b, w)
return m
}
2024-07-19 10:54:58 +02:00
func (w *AbstractWorkflow) 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
}
type WorkflowResource struct {
2024-07-18 11:51:12 +02:00
resources.AbstractResource
2024-07-19 10:54:58 +02:00
AbstractWorkflow
WorkflowID string `bson:"workflow_id,omitempty" json:"workflow_id,omitempty"`
2024-07-18 11:51:12 +02:00
}
2024-07-19 13:27:34 +02:00
func (d *WorkflowResource) BindID(id string) { d.WorkflowID = id }
2024-07-19 10:54:58 +02:00
func (d *WorkflowResource) GetAccessor() utils.Accessor {
data := &WorkflowResourceMongoAccessor{}
data.SetLogger(utils.WORKFLOW_RESOURCE)
2024-07-18 11:51:12 +02:00
return data
}
2024-07-19 10:54:58 +02:00
func (dma *WorkflowResource) Deserialize(j map[string]interface{}) utils.DBObject {
2024-07-18 14:39:54 +02:00
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
2024-07-19 13:15:51 +02:00
dma.AbstractResource.ObjDeserialize(j)
2024-07-18 14:39:54 +02:00
return dma
}
2024-07-19 10:54:58 +02:00
func (dma *WorkflowResource) Serialize() map[string]interface{} {
2024-07-19 09:32:58 +02:00
var m map[string]interface{}
b, err := json.Marshal(dma)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
2024-07-19 13:15:51 +02:00
dma.AbstractResource.ObjSerialize()
2024-07-19 09:32:58 +02:00
return m
}