A question refers to the comment ! And if not Ooopsy
This commit is contained in:
@@ -12,14 +12,21 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
/*
|
||||
* AbstractWorkflow is a struct that represents a workflow for resource or native workflow
|
||||
* Warning: there is 2 types of workflows, the resource workflow and the native workflow
|
||||
* native workflow is the one that you create to schedule an execution
|
||||
* resource workflow is the one that is created to set our native workflow in catalog
|
||||
*/
|
||||
type AbstractWorkflow struct {
|
||||
resources.ResourceSet
|
||||
Graph *graph.Graph `bson:"graph,omitempty" json:"graph,omitempty"`
|
||||
ScheduleActive bool `json:"schedule_active" bson:"schedule_active"`
|
||||
Schedule *WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
|
||||
Shared []string `json:"shared,omitempty" bson:"shared,omitempty"`
|
||||
Graph *graph.Graph `bson:"graph,omitempty" json:"graph,omitempty"` // Graph UI & logic representation of the workflow
|
||||
ScheduleActive bool `json:"schedule_active" bson:"schedule_active"` // ScheduleActive is a flag that indicates if the schedule is active, if not the workflow is not scheduled and no execution or booking will be set
|
||||
Schedule *WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"` // Schedule is the schedule of the workflow
|
||||
Shared []string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workflow
|
||||
}
|
||||
|
||||
// tool function to check if a link is a link between a datacenter and a resource
|
||||
func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) (bool, string) {
|
||||
if w.Graph == nil || w.Graph.Items == nil {
|
||||
return false, ""
|
||||
@@ -33,28 +40,35 @@ func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) (bool, string) {
|
||||
return false, ""
|
||||
}
|
||||
|
||||
/*
|
||||
* Workflow is a struct that represents a workflow
|
||||
* it defines the native workflow
|
||||
*/
|
||||
type Workflow struct {
|
||||
utils.AbstractObject
|
||||
AbstractWorkflow
|
||||
utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name)
|
||||
AbstractWorkflow // AbstractWorkflow contains the basic fields of a workflow
|
||||
}
|
||||
|
||||
/*
|
||||
* CheckBooking is a function that checks the booking of the workflow on peers (even ourselves)
|
||||
*/
|
||||
func (wfa *Workflow) CheckBooking(caller *tools.HTTPCaller) (bool, error) {
|
||||
// check if
|
||||
if wfa.Graph == nil {
|
||||
if wfa.Graph == nil { // no graph no booking
|
||||
return false, nil
|
||||
}
|
||||
accessor := (&datacenter.DatacenterResource{}).GetAccessor(nil)
|
||||
for _, link := range wfa.Graph.Links {
|
||||
if ok, dc_id := wfa.isDCLink(link); ok {
|
||||
if ok, dc_id := wfa.isDCLink(link); ok { // check if the link is a link between a datacenter and a resource
|
||||
dc, code, _ := accessor.LoadOne(dc_id)
|
||||
if code != 200 {
|
||||
continue
|
||||
}
|
||||
// CHECK BOOKING
|
||||
// CHECK BOOKING ON PEER, datacenter could be a remote one
|
||||
peerID := dc.(*datacenter.DatacenterResource).PeerID
|
||||
if peerID == "" {
|
||||
return false, errors.New("no peer id")
|
||||
}
|
||||
} // no peer id no booking, we need to know where to book
|
||||
_, err := (&peer.Peer{}).LaunchPeerExecution(peerID, dc_id, utils.BOOKING, tools.GET, nil, caller)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -69,8 +83,8 @@ func (d *Workflow) GetName() string {
|
||||
}
|
||||
|
||||
func (d *Workflow) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New()
|
||||
data.Init(utils.WORKFLOW, caller)
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(utils.WORKFLOW, caller) // Initialize the accessor with the WORKFLOW model type
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user