add history
This commit is contained in:
@@ -65,7 +65,7 @@ func (d *Booking) GetName() string {
|
||||
|
||||
func (d *Booking) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(utils.BOOKING, caller) // Initialize the accessor with the BOOKING model type
|
||||
data.Init(tools.BOOKING, caller) // Initialize the accessor with the BOOKING model type
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,12 @@ package models
|
||||
|
||||
import (
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/booking"
|
||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||
d "cloud.o-forge.io/core/oc-lib/models/resources/data"
|
||||
dc "cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
|
||||
p "cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
||||
s "cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
||||
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
||||
@@ -24,28 +24,27 @@ This package contains the models used in the application
|
||||
It's used to create the models dynamically
|
||||
*/
|
||||
var models = map[string]func() utils.DBObject{
|
||||
utils.WORKFLOW_RESOURCE.String(): func() utils.DBObject { return &w.WorkflowResource{} },
|
||||
utils.DATA_RESOURCE.String(): func() utils.DBObject { return &d.DataResource{} },
|
||||
utils.DATACENTER_RESOURCE.String(): func() utils.DBObject { return &dc.DatacenterResource{} },
|
||||
utils.STORAGE_RESOURCE.String(): func() utils.DBObject { return &s.StorageResource{} },
|
||||
utils.PROCESSING_RESOURCE.String(): func() utils.DBObject { return &p.ProcessingResource{} },
|
||||
utils.WORKFLOW.String(): func() utils.DBObject { return &w2.Workflow{} },
|
||||
utils.WORKFLOW_EXECUTION.String(): func() utils.DBObject { return &workflow_execution.WorkflowExecution{} },
|
||||
utils.WORKSPACE.String(): func() utils.DBObject { return &w3.Workspace{} },
|
||||
utils.RESOURCE_MODEL.String(): func() utils.DBObject { return &resource_model.ResourceModel{} },
|
||||
utils.PEER.String(): func() utils.DBObject { return &peer.Peer{} },
|
||||
utils.COLLABORATIVE_AREA.String(): func() utils.DBObject { return &collaborative_area.CollaborativeArea{} },
|
||||
utils.RULE.String(): func() utils.DBObject { return &rule.Rule{} },
|
||||
utils.BOOKING.String(): func() utils.DBObject { return &booking.Booking{} },
|
||||
tools.WORKFLOW_RESOURCE.String(): func() utils.DBObject { return &w.WorkflowResource{} },
|
||||
tools.DATA_RESOURCE.String(): func() utils.DBObject { return &d.DataResource{} },
|
||||
tools.STORAGE_RESOURCE.String(): func() utils.DBObject { return &s.StorageResource{} },
|
||||
tools.PROCESSING_RESOURCE.String(): func() utils.DBObject { return &p.ProcessingResource{} },
|
||||
tools.WORKFLOW.String(): func() utils.DBObject { return &w2.Workflow{} },
|
||||
tools.WORKFLOW_EXECUTION.String(): func() utils.DBObject { return &workflow_execution.WorkflowExecution{} },
|
||||
tools.WORKSPACE.String(): func() utils.DBObject { return &w3.Workspace{} },
|
||||
tools.RESOURCE_MODEL.String(): func() utils.DBObject { return &resource_model.ResourceModel{} },
|
||||
tools.PEER.String(): func() utils.DBObject { return &peer.Peer{} },
|
||||
tools.COLLABORATIVE_AREA.String(): func() utils.DBObject { return &collaborative_area.CollaborativeArea{} },
|
||||
tools.RULE.String(): func() utils.DBObject { return &rule.Rule{} },
|
||||
tools.BOOKING.String(): func() utils.DBObject { return &booking.Booking{} },
|
||||
}
|
||||
|
||||
// Model returns the model object based on the model type
|
||||
func Model(model int) utils.DBObject {
|
||||
log := logs.GetLogger()
|
||||
if _, ok := models[utils.FromInt(model)]; ok {
|
||||
return models[utils.FromInt(model)]()
|
||||
if _, ok := models[tools.FromInt(model)]; ok {
|
||||
return models[tools.FromInt(model)]()
|
||||
}
|
||||
log.Error().Msg("Can't find model " + utils.FromInt(model) + ".")
|
||||
log.Error().Msg("Can't find model " + tools.FromInt(model) + ".")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ func (d *Peer) GetName() string {
|
||||
|
||||
func (d *Peer) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(utils.PEER, caller) // Initialize the accessor with the PEER model type
|
||||
data.Init(tools.PEER, caller) // Initialize the accessor with the PEER model type
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ func (d *ResourceModel) GetName() string {
|
||||
|
||||
func (d *ResourceModel) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := &ResourceModelMongoAccessor{}
|
||||
data.Init(utils.RESOURCE_MODEL, caller)
|
||||
data.Init(tools.RESOURCE_MODEL, caller)
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,6 @@ func (dma *DataResource) Serialize() map[string]interface{} {
|
||||
|
||||
func (d *DataResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(utils.DATA_RESOURCE, caller) // Initialize the accessor with the DATA_RESOURCE model type
|
||||
data.Init(tools.DATA_RESOURCE, caller) // Initialize the accessor with the DATA_RESOURCE model type
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func (dma *DatacenterResource) Serialize() map[string]interface{} {
|
||||
|
||||
func (d *DatacenterResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New()
|
||||
data.Init(utils.DATACENTER_RESOURCE, caller)
|
||||
data.Init(tools.DATACENTER_RESOURCE, caller)
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,6 @@ func (dma *ProcessingResource) Serialize() map[string]interface{} {
|
||||
|
||||
func (d *ProcessingResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(utils.PROCESSING_RESOURCE, caller) // Initialize the accessor with the PROCESSING_RESOURCE model type
|
||||
data.Init(tools.PROCESSING_RESOURCE, caller) // Initialize the accessor with the PROCESSING_RESOURCE model type
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -50,6 +50,6 @@ func (dma *StorageResource) Serialize() map[string]interface{} {
|
||||
|
||||
func (d *StorageResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(utils.STORAGE_RESOURCE, caller) // Initialize the accessor with the STORAGE_RESOURCE model type
|
||||
data.Init(tools.STORAGE_RESOURCE, caller) // Initialize the accessor with the STORAGE_RESOURCE model type
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ type WorkflowResource struct {
|
||||
|
||||
func (d *WorkflowResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(utils.WORKFLOW_RESOURCE, caller) // Initialize the accessor with the WORKFLOW_RESOURCE model type
|
||||
data.Init(tools.WORKFLOW_RESOURCE, caller) // Initialize the accessor with the WORKFLOW_RESOURCE model type
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ func (dma *AbstractAccessor) GetCaller() *tools.HTTPCaller {
|
||||
}
|
||||
|
||||
// Init initializes the accessor with the data type and the http caller
|
||||
func (dma *AbstractAccessor) Init(t DataType, caller *tools.HTTPCaller) {
|
||||
func (dma *AbstractAccessor) Init(t tools.DataType, caller *tools.HTTPCaller) {
|
||||
dma.Logger = logs.CreateLogger(t.String()) // Create a logger with the data type
|
||||
dma.Caller = caller // Set the caller
|
||||
dma.Type = t.String() // Set the data type
|
||||
|
||||
@@ -26,7 +26,7 @@ type DBObject interface {
|
||||
|
||||
// Accessor is an interface that defines the basic methods for an Accessor
|
||||
type Accessor interface {
|
||||
Init(t DataType, caller *tools.HTTPCaller)
|
||||
Init(t tools.DataType, caller *tools.HTTPCaller)
|
||||
GetType() string
|
||||
GetCaller() *tools.HTTPCaller
|
||||
Search(filters *dbs.Filters, search string) ([]ShallowDBObject, int, error)
|
||||
|
||||
@@ -84,7 +84,7 @@ func (d *Workflow) GetName() string {
|
||||
|
||||
func (d *Workflow) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(utils.WORKFLOW, caller) // Initialize the accessor with the WORKFLOW model type
|
||||
data.Init(tools.WORKFLOW, caller) // Initialize the accessor with the WORKFLOW model type
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
34
models/workflow/workflow_history_mongo_accessor.go
Normal file
34
models/workflow/workflow_history_mongo_accessor.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package workflow
|
||||
|
||||
import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type WorkflowHistory struct{ Workflow }
|
||||
|
||||
func (d *WorkflowHistory) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.WORKSPACE_HISTORY, caller) // Initialize the accessor with the WORKSPACE model type
|
||||
return data
|
||||
}
|
||||
func (r *WorkflowHistory) GenerateID() {
|
||||
r.UUID = uuid.New().String()
|
||||
}
|
||||
|
||||
// Workspace is a struct that represents a workspace
|
||||
type workflowHistoryMongoAccessor struct {
|
||||
workflowMongoAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
}
|
||||
|
||||
// New creates a new instance of the workspaceMongoAccessor
|
||||
func NewHistory() *workflowHistoryMongoAccessor {
|
||||
return &workflowHistoryMongoAccessor{}
|
||||
}
|
||||
|
||||
func (r *workflowHistoryMongoAccessor) MapFromWorkflow(w *Workflow) *WorkflowHistory {
|
||||
wh := &WorkflowHistory{Workflow: *w}
|
||||
wh.GenerateID()
|
||||
return wh
|
||||
}
|
||||
@@ -175,6 +175,8 @@ func (wfa *workflowMongoAccessor) share(realData *Workflow, delete bool, caller
|
||||
continue
|
||||
}
|
||||
if delete { // if the workflow is deleted, share the deletion
|
||||
history := NewHistory()
|
||||
history.StoreOne(history.MapFromWorkflow(res.(*Workflow)))
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.DELETE, map[string]interface{}{}, caller)
|
||||
} else { // if the workflow is updated, share the update
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.PUT, res.Serialize(), caller)
|
||||
@@ -196,9 +198,9 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
|
||||
mongo.MONGOService.DeleteMultiple(map[string]interface{}{
|
||||
"state": 1, // only delete the scheduled executions only scheduled if executions are in progress or ended, they should not be deleted for registration
|
||||
"workflow_id": id,
|
||||
}, utils.WORKFLOW_EXECUTION.String())
|
||||
}, tools.WORKFLOW_EXECUTION.String())
|
||||
err := wfa.book(id, realData, []*workflow_execution.WorkflowExecution{}) // delete the booking of the workflow on the peers
|
||||
nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData) // send the deletion to the nats
|
||||
nats.SetNATSPub(tools.WORKFLOW.String(), tools.REMOVE, realData) // send the deletion to the nats
|
||||
if err != nil {
|
||||
return 409, err
|
||||
}
|
||||
@@ -224,7 +226,7 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
|
||||
return code, err
|
||||
}
|
||||
}
|
||||
nats.SetNATSPub(utils.WORKFLOW.String(), tools.CREATE, realData) // send the creation to the nats
|
||||
nats.SetNATSPub(tools.WORKFLOW.String(), tools.CREATE, realData) // send the creation to the nats
|
||||
} else {
|
||||
return 422, err
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ func (d *WorkflowExecution) GetName() string {
|
||||
|
||||
func (d *WorkflowExecution) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(utils.WORKFLOW_EXECUTION, caller) // Initialize the accessor with the WORKFLOW_EXECUTION model type
|
||||
data.Init(tools.WORKFLOW_EXECUTION, caller) // Initialize the accessor with the WORKFLOW_EXECUTION model type
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ func (d *CollaborativeArea) GetName() string {
|
||||
|
||||
func (d *CollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(utils.COLLABORATIVE_AREA, caller) // Initialize the accessor with the SHARED_WORKSPACE model type
|
||||
data.Init(tools.COLLABORATIVE_AREA, caller) // Initialize the accessor with the SHARED_WORKSPACE model type
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ func (d *Rule) GetName() string {
|
||||
|
||||
func (d *Rule) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New()
|
||||
data.Init(utils.RULE, caller)
|
||||
data.Init(tools.RULE, caller)
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ func (d *ShallowCollaborativeArea) GetName() string {
|
||||
|
||||
func (d *ShallowCollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New()
|
||||
data.Init(utils.COLLABORATIVE_AREA, caller)
|
||||
data.Init(tools.COLLABORATIVE_AREA, caller)
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ func (d *Workspace) GetName() string {
|
||||
|
||||
func (d *Workspace) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(utils.WORKSPACE, caller) // Initialize the accessor with the WORKSPACE model type
|
||||
data.Init(tools.WORKSPACE, caller) // Initialize the accessor with the WORKSPACE model type
|
||||
return data
|
||||
}
|
||||
|
||||
|
||||
34
models/workspace/workspace_history_mongo_accessor.go
Normal file
34
models/workspace/workspace_history_mongo_accessor.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package workspace
|
||||
|
||||
import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type WorkspaceHistory struct{ Workspace }
|
||||
|
||||
func (d *WorkspaceHistory) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.WORKSPACE_HISTORY, caller) // Initialize the accessor with the WORKSPACE model type
|
||||
return data
|
||||
}
|
||||
func (r *WorkspaceHistory) GenerateID() {
|
||||
r.UUID = uuid.New().String()
|
||||
}
|
||||
|
||||
// Workspace is a struct that represents a workspace
|
||||
type workspaceHistoryMongoAccessor struct {
|
||||
workspaceMongoAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
}
|
||||
|
||||
// New creates a new instance of the workspaceMongoAccessor
|
||||
func NewHistory() *workspaceHistoryMongoAccessor {
|
||||
return &workspaceHistoryMongoAccessor{}
|
||||
}
|
||||
|
||||
func (r *workspaceHistoryMongoAccessor) MapFromWorkspace(w *Workspace) *WorkspaceHistory {
|
||||
wh := &WorkspaceHistory{Workspace: *w}
|
||||
wh.GenerateID()
|
||||
return wh
|
||||
}
|
||||
@@ -221,6 +221,8 @@ func (wfa *workspaceMongoAccessor) share(realData *Workspace, delete bool, calle
|
||||
continue
|
||||
}
|
||||
if delete { // If the workspace is deleted, share the deletion
|
||||
history := NewHistory()
|
||||
history.StoreOne(history.MapFromWorkspace(res.(*Workspace)))
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.DELETE, map[string]interface{}{}, caller)
|
||||
} else { // If the workspace is updated, share the update
|
||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.PUT, res.Serialize(), caller)
|
||||
|
||||
Reference in New Issue
Block a user