add history
This commit is contained in:
parent
3c1a84011e
commit
93903b4938
@ -36,28 +36,28 @@ type LibDataEnum int
|
|||||||
// init accessible constant to retrieve data from the database
|
// init accessible constant to retrieve data from the database
|
||||||
const (
|
const (
|
||||||
INVALID LibDataEnum = iota
|
INVALID LibDataEnum = iota
|
||||||
DATA_RESOURCE = utils.DATA_RESOURCE
|
DATA_RESOURCE = tools.DATA_RESOURCE
|
||||||
PROCESSING_RESOURCE = utils.PROCESSING_RESOURCE
|
PROCESSING_RESOURCE = tools.PROCESSING_RESOURCE
|
||||||
STORAGE_RESOURCE = utils.STORAGE_RESOURCE
|
STORAGE_RESOURCE = tools.STORAGE_RESOURCE
|
||||||
DATACENTER_RESOURCE = utils.DATACENTER_RESOURCE
|
DATACENTER_RESOURCE = tools.DATACENTER_RESOURCE
|
||||||
WORKFLOW_RESOURCE = utils.WORKFLOW_RESOURCE
|
WORKFLOW_RESOURCE = tools.WORKFLOW_RESOURCE
|
||||||
WORKFLOW = utils.WORKFLOW
|
WORKFLOW = tools.WORKFLOW
|
||||||
WORKSPACE = utils.WORKSPACE
|
WORKSPACE = tools.WORKSPACE
|
||||||
WORKFLOW_EXECUTION = utils.WORKFLOW_EXECUTION
|
WORKFLOW_EXECUTION = tools.WORKFLOW_EXECUTION
|
||||||
PEER = utils.PEER
|
PEER = tools.PEER
|
||||||
SHARED_WORKSPACE = utils.COLLABORATIVE_AREA
|
SHARED_WORKSPACE = tools.COLLABORATIVE_AREA
|
||||||
RULE = utils.RULE
|
RULE = tools.RULE
|
||||||
BOOKING = utils.BOOKING
|
BOOKING = tools.BOOKING
|
||||||
)
|
)
|
||||||
|
|
||||||
// will turn into standards api hostnames
|
// will turn into standards api hostnames
|
||||||
func (d LibDataEnum) API() string {
|
func (d LibDataEnum) API() string {
|
||||||
return utils.DefaultAPI[d]
|
return tools.DefaultAPI[d]
|
||||||
}
|
}
|
||||||
|
|
||||||
// will turn into standards name
|
// will turn into standards name
|
||||||
func (d LibDataEnum) String() string {
|
func (d LibDataEnum) String() string {
|
||||||
return utils.Str[d]
|
return tools.Str[d]
|
||||||
}
|
}
|
||||||
|
|
||||||
// will turn into enum index
|
// will turn into enum index
|
||||||
@ -121,13 +121,13 @@ func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string,
|
|||||||
Resource model is the model that will define the structure of the resources
|
Resource model is the model that will define the structure of the resources
|
||||||
*/
|
*/
|
||||||
accessor := (&resource_model.ResourceModel{}).GetAccessor(nil)
|
accessor := (&resource_model.ResourceModel{}).GetAccessor(nil)
|
||||||
for _, model := range []string{utils.DATA_RESOURCE.String(), utils.PROCESSING_RESOURCE.String(), utils.STORAGE_RESOURCE.String(), utils.DATACENTER_RESOURCE.String(), utils.WORKFLOW_RESOURCE.String()} {
|
for _, model := range []string{tools.DATA_RESOURCE.String(), tools.PROCESSING_RESOURCE.String(), tools.STORAGE_RESOURCE.String(), tools.DATACENTER_RESOURCE.String(), tools.WORKFLOW_RESOURCE.String()} {
|
||||||
data, code, _ := accessor.Search(nil, model)
|
data, code, _ := accessor.Search(nil, model)
|
||||||
if code == 404 || len(data) == 0 {
|
if code == 404 || len(data) == 0 {
|
||||||
m := map[string]resource_model.Model{}
|
m := map[string]resource_model.Model{}
|
||||||
// TODO Specify the model for each resource
|
// TODO Specify the model for each resource
|
||||||
// for now only processing is specified here (not an elegant way)
|
// for now only processing is specified here (not an elegant way)
|
||||||
if model == utils.PROCESSING_RESOURCE.String() {
|
if model == tools.PROCESSING_RESOURCE.String() {
|
||||||
m["command"] = resource_model.Model{
|
m["command"] = resource_model.Model{
|
||||||
Type: "string",
|
Type: "string",
|
||||||
ReadOnly: false,
|
ReadOnly: false,
|
||||||
@ -378,72 +378,72 @@ func CopyOne(collection LibDataEnum, object map[string]interface{}, c ...*tools.
|
|||||||
// ================ CAST ========================= //
|
// ================ CAST ========================= //
|
||||||
|
|
||||||
func (l *LibData) ToDataResource() *data.DataResource {
|
func (l *LibData) ToDataResource() *data.DataResource {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.DATA_RESOURCE.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.DATA_RESOURCE.String() {
|
||||||
return l.Data.(*data.DataResource)
|
return l.Data.(*data.DataResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToDatacenterResource() *datacenter.DatacenterResource {
|
func (l *LibData) ToDatacenterResource() *datacenter.DatacenterResource {
|
||||||
if l.Data != nil && l.Data.GetAccessor(nil).GetType() == utils.DATACENTER_RESOURCE.String() {
|
if l.Data != nil && l.Data.GetAccessor(nil).GetType() == tools.DATACENTER_RESOURCE.String() {
|
||||||
return l.Data.(*datacenter.DatacenterResource)
|
return l.Data.(*datacenter.DatacenterResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToStorageResource() *storage.StorageResource {
|
func (l *LibData) ToStorageResource() *storage.StorageResource {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.STORAGE_RESOURCE.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.STORAGE_RESOURCE.String() {
|
||||||
return l.Data.(*storage.StorageResource)
|
return l.Data.(*storage.StorageResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToProcessingResource() *processing.ProcessingResource {
|
func (l *LibData) ToProcessingResource() *processing.ProcessingResource {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.PROCESSING_RESOURCE.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.PROCESSING_RESOURCE.String() {
|
||||||
return l.Data.(*processing.ProcessingResource)
|
return l.Data.(*processing.ProcessingResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToWorkflowResource() *w.WorkflowResource {
|
func (l *LibData) ToWorkflowResource() *w.WorkflowResource {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.WORKFLOW_RESOURCE.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW_RESOURCE.String() {
|
||||||
return l.Data.(*w.WorkflowResource)
|
return l.Data.(*w.WorkflowResource)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToPeer() *peer.Peer {
|
func (l *LibData) ToPeer() *peer.Peer {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.PEER.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.PEER.String() {
|
||||||
return l.Data.(*peer.Peer)
|
return l.Data.(*peer.Peer)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToWorkflow() *w2.Workflow {
|
func (l *LibData) ToWorkflow() *w2.Workflow {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.WORKFLOW.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW.String() {
|
||||||
return l.Data.(*w2.Workflow)
|
return l.Data.(*w2.Workflow)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (l *LibData) ToWorkspace() *workspace.Workspace {
|
func (l *LibData) ToWorkspace() *workspace.Workspace {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.WORKSPACE.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.WORKSPACE.String() {
|
||||||
return l.Data.(*workspace.Workspace)
|
return l.Data.(*workspace.Workspace)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToCollaborativeArea() *collaborative_area.CollaborativeArea {
|
func (l *LibData) ToCollaborativeArea() *collaborative_area.CollaborativeArea {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.COLLABORATIVE_AREA.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.COLLABORATIVE_AREA.String() {
|
||||||
return l.Data.(*collaborative_area.CollaborativeArea)
|
return l.Data.(*collaborative_area.CollaborativeArea)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToRule() *rule.Rule {
|
func (l *LibData) ToRule() *rule.Rule {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.COLLABORATIVE_AREA.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.COLLABORATIVE_AREA.String() {
|
||||||
return l.Data.(*rule.Rule)
|
return l.Data.(*rule.Rule)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecution {
|
func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecution {
|
||||||
if l.Data.GetAccessor(nil).GetType() == utils.WORKFLOW_EXECUTION.String() {
|
if l.Data.GetAccessor(nil).GetType() == tools.WORKFLOW_EXECUTION.String() {
|
||||||
return l.Data.(*workflow_execution.WorkflowExecution)
|
return l.Data.(*workflow_execution.WorkflowExecution)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -65,7 +65,7 @@ func (d *Booking) GetName() string {
|
|||||||
|
|
||||||
func (d *Booking) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Booking) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the 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
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,12 +2,12 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"cloud.o-forge.io/core/oc-lib/logs"
|
"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/booking"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
"cloud.o-forge.io/core/oc-lib/models/resource_model"
|
||||||
d "cloud.o-forge.io/core/oc-lib/models/resources/data"
|
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"
|
p "cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
||||||
s "cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
s "cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
||||||
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
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
|
It's used to create the models dynamically
|
||||||
*/
|
*/
|
||||||
var models = map[string]func() utils.DBObject{
|
var models = map[string]func() utils.DBObject{
|
||||||
utils.WORKFLOW_RESOURCE.String(): func() utils.DBObject { return &w.WorkflowResource{} },
|
tools.WORKFLOW_RESOURCE.String(): func() utils.DBObject { return &w.WorkflowResource{} },
|
||||||
utils.DATA_RESOURCE.String(): func() utils.DBObject { return &d.DataResource{} },
|
tools.DATA_RESOURCE.String(): func() utils.DBObject { return &d.DataResource{} },
|
||||||
utils.DATACENTER_RESOURCE.String(): func() utils.DBObject { return &dc.DatacenterResource{} },
|
tools.STORAGE_RESOURCE.String(): func() utils.DBObject { return &s.StorageResource{} },
|
||||||
utils.STORAGE_RESOURCE.String(): func() utils.DBObject { return &s.StorageResource{} },
|
tools.PROCESSING_RESOURCE.String(): func() utils.DBObject { return &p.ProcessingResource{} },
|
||||||
utils.PROCESSING_RESOURCE.String(): func() utils.DBObject { return &p.ProcessingResource{} },
|
tools.WORKFLOW.String(): func() utils.DBObject { return &w2.Workflow{} },
|
||||||
utils.WORKFLOW.String(): func() utils.DBObject { return &w2.Workflow{} },
|
tools.WORKFLOW_EXECUTION.String(): func() utils.DBObject { return &workflow_execution.WorkflowExecution{} },
|
||||||
utils.WORKFLOW_EXECUTION.String(): func() utils.DBObject { return &workflow_execution.WorkflowExecution{} },
|
tools.WORKSPACE.String(): func() utils.DBObject { return &w3.Workspace{} },
|
||||||
utils.WORKSPACE.String(): func() utils.DBObject { return &w3.Workspace{} },
|
tools.RESOURCE_MODEL.String(): func() utils.DBObject { return &resource_model.ResourceModel{} },
|
||||||
utils.RESOURCE_MODEL.String(): func() utils.DBObject { return &resource_model.ResourceModel{} },
|
tools.PEER.String(): func() utils.DBObject { return &peer.Peer{} },
|
||||||
utils.PEER.String(): func() utils.DBObject { return &peer.Peer{} },
|
tools.COLLABORATIVE_AREA.String(): func() utils.DBObject { return &collaborative_area.CollaborativeArea{} },
|
||||||
utils.COLLABORATIVE_AREA.String(): func() utils.DBObject { return &collaborative_area.CollaborativeArea{} },
|
tools.RULE.String(): func() utils.DBObject { return &rule.Rule{} },
|
||||||
utils.RULE.String(): func() utils.DBObject { return &rule.Rule{} },
|
tools.BOOKING.String(): func() utils.DBObject { return &booking.Booking{} },
|
||||||
utils.BOOKING.String(): func() utils.DBObject { return &booking.Booking{} },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Model returns the model object based on the model type
|
// Model returns the model object based on the model type
|
||||||
func Model(model int) utils.DBObject {
|
func Model(model int) utils.DBObject {
|
||||||
log := logs.GetLogger()
|
log := logs.GetLogger()
|
||||||
if _, ok := models[utils.FromInt(model)]; ok {
|
if _, ok := models[tools.FromInt(model)]; ok {
|
||||||
return models[utils.FromInt(model)]()
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ func (d *Peer) GetName() string {
|
|||||||
|
|
||||||
func (d *Peer) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Peer) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the 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
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ func (d *ResourceModel) GetName() string {
|
|||||||
|
|
||||||
func (d *ResourceModel) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *ResourceModel) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := &ResourceModelMongoAccessor{}
|
data := &ResourceModelMongoAccessor{}
|
||||||
data.Init(utils.RESOURCE_MODEL, caller)
|
data.Init(tools.RESOURCE_MODEL, caller)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,6 @@ func (dma *DataResource) Serialize() map[string]interface{} {
|
|||||||
|
|
||||||
func (d *DataResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *DataResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the 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
|
return data
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ func (dma *DatacenterResource) Serialize() map[string]interface{} {
|
|||||||
|
|
||||||
func (d *DatacenterResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *DatacenterResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New()
|
data := New()
|
||||||
data.Init(utils.DATACENTER_RESOURCE, caller)
|
data.Init(tools.DATACENTER_RESOURCE, caller)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,6 @@ func (dma *ProcessingResource) Serialize() map[string]interface{} {
|
|||||||
|
|
||||||
func (d *ProcessingResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *ProcessingResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the 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
|
return data
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,6 @@ func (dma *StorageResource) Serialize() map[string]interface{} {
|
|||||||
|
|
||||||
func (d *StorageResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *StorageResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the 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
|
return data
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ type WorkflowResource struct {
|
|||||||
|
|
||||||
func (d *WorkflowResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *WorkflowResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the 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
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ func (dma *AbstractAccessor) GetCaller() *tools.HTTPCaller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Init initializes the accessor with the data type and the http caller
|
// 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.Logger = logs.CreateLogger(t.String()) // Create a logger with the data type
|
||||||
dma.Caller = caller // Set the caller
|
dma.Caller = caller // Set the caller
|
||||||
dma.Type = t.String() // Set the data type
|
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
|
// Accessor is an interface that defines the basic methods for an Accessor
|
||||||
type Accessor interface {
|
type Accessor interface {
|
||||||
Init(t DataType, caller *tools.HTTPCaller)
|
Init(t tools.DataType, caller *tools.HTTPCaller)
|
||||||
GetType() string
|
GetType() string
|
||||||
GetCaller() *tools.HTTPCaller
|
GetCaller() *tools.HTTPCaller
|
||||||
Search(filters *dbs.Filters, search string) ([]ShallowDBObject, int, error)
|
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 {
|
func (d *Workflow) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the 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
|
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
|
continue
|
||||||
}
|
}
|
||||||
if delete { // if the workflow is deleted, share the deletion
|
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)
|
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.DELETE, map[string]interface{}{}, caller)
|
||||||
} else { // if the workflow is updated, share the update
|
} else { // if the workflow is updated, share the update
|
||||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.PUT, res.Serialize(), caller)
|
_, 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{}{
|
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
|
"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,
|
"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
|
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 {
|
if err != nil {
|
||||||
return 409, err
|
return 409, err
|
||||||
}
|
}
|
||||||
@ -224,7 +226,7 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
|
|||||||
return code, err
|
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 {
|
} else {
|
||||||
return 422, err
|
return 422, err
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ func (d *WorkflowExecution) GetName() string {
|
|||||||
|
|
||||||
func (d *WorkflowExecution) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *WorkflowExecution) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the 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
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ func (d *CollaborativeArea) GetName() string {
|
|||||||
|
|
||||||
func (d *CollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *CollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the 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
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ func (d *Rule) GetName() string {
|
|||||||
|
|
||||||
func (d *Rule) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Rule) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New()
|
data := New()
|
||||||
data.Init(utils.RULE, caller)
|
data.Init(tools.RULE, caller)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ func (d *ShallowCollaborativeArea) GetName() string {
|
|||||||
|
|
||||||
func (d *ShallowCollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *ShallowCollaborativeArea) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New()
|
data := New()
|
||||||
data.Init(utils.COLLABORATIVE_AREA, caller)
|
data.Init(tools.COLLABORATIVE_AREA, caller)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ func (d *Workspace) GetName() string {
|
|||||||
|
|
||||||
func (d *Workspace) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
func (d *Workspace) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||||
data := New() // Create a new instance of the 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
|
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
|
continue
|
||||||
}
|
}
|
||||||
if delete { // If the workspace is deleted, share the deletion
|
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)
|
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.DELETE, map[string]interface{}{}, caller)
|
||||||
} else { // If the workspace is updated, share the update
|
} else { // If the workspace is updated, share the update
|
||||||
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.PUT, res.Serialize(), caller)
|
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKSPACE, tools.PUT, res.Serialize(), caller)
|
||||||
|
@ -18,6 +18,8 @@ const (
|
|||||||
COLLABORATIVE_AREA
|
COLLABORATIVE_AREA
|
||||||
RULE
|
RULE
|
||||||
BOOKING
|
BOOKING
|
||||||
|
WORKFLOW_HISTORY
|
||||||
|
WORKSPACE_HISTORY
|
||||||
)
|
)
|
||||||
|
|
||||||
var NOAPI = ""
|
var NOAPI = ""
|
||||||
@ -44,6 +46,8 @@ var DefaultAPI = [...]string{
|
|||||||
SHAREDAPI,
|
SHAREDAPI,
|
||||||
SHAREDAPI,
|
SHAREDAPI,
|
||||||
DATACENTERAPI,
|
DATACENTERAPI,
|
||||||
|
NOAPI,
|
||||||
|
NOAPI,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind the standard data name to the data type
|
// Bind the standard data name to the data type
|
||||||
@ -62,6 +66,8 @@ var Str = [...]string{
|
|||||||
"shared_workspace",
|
"shared_workspace",
|
||||||
"rule",
|
"rule",
|
||||||
"booking",
|
"booking",
|
||||||
|
"workflow_history",
|
||||||
|
"workspace_history",
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromInt(i int) string {
|
func FromInt(i int) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user