Compare commits
	
		
			62 Commits
		
	
	
		
			namespace
			...
			23a9d648d2
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					23a9d648d2 | ||
| 
						 | 
					a3029fa3f9 | ||
| 
						 | 
					387785b40c | ||
| 
						 | 
					03dea55131 | ||
| 
						 | 
					7b8aa989f6 | ||
| 
						 | 
					6ab6383144 | ||
| 
						 | 
					690d60f9d6 | ||
| 
						 | 
					da0de80afd | ||
| 
						 | 
					cd7ae788b1 | ||
| 
						 | 
					0d96cc53bf | ||
| 
						 | 
					66fc3c5b35 | ||
| 
						 | 
					5ab3eb8a38 | ||
| 
						 | 
					fec23b4acd | ||
| 
						 | 
					901622fee0 | ||
| 
						 | 
					527e622774 | ||
| 
						 | 
					7223b79fe8 | ||
| 
						 | 
					1ade41aeae | ||
| 
						 | 
					58dc579255 | ||
| 
						 | 
					370dac201b | ||
| 
						 | 
					2a763006db | ||
| 
						 | 
					522c66653b | ||
| 
						 | 
					b57f050b81 | ||
| 
						 | 
					41ebcf150a | ||
| 
						 | 
					1499def6ad | ||
| 
						 | 
					adbab0f5d7 | ||
| 88c88cac5b | |||
| 1ae38c98ad | |||
| 2d517cc594 | |||
| a9c82bd261 | |||
| 79aec86f5f | |||
| 9b3dfc7576 | |||
| 037ae74782 | |||
| b81c60a3ce | |||
| 363ac94c47 | |||
| 378f9e5095 | |||
| 659b494ee4 | |||
| 92965c6af2 | |||
| 70cb5aec9f | |||
| d59e77d5a2 | |||
| ff1b857ab0 | |||
| dbdccdb920 | |||
| fd3fef72d3 | |||
| 1890fd4f71 | |||
| 95af3cb515 | |||
| 3acebc451e | |||
| 
						 | 
					5111c9c8be | ||
| 
						 | 
					3ecb0e9d96 | ||
| 
						 | 
					b4a1766677 | ||
| 
						 | 
					241c6a5a08 | ||
| 
						 | 
					7c30633bde | ||
| 
						 | 
					81d3406305 | ||
| 
						 | 
					04f7537066 | ||
| 
						 | 
					6bf058ab5c | ||
| 
						 | 
					b771b5d25e | ||
| 
						 | 
					6e6ed4ea2c | ||
| 
						 | 
					a098f0a672 | ||
| 5255ffc2f7 | |||
| fd1c579ec4 | |||
| 0f4adeea86 | |||
| 245f3adea3 | |||
| 21d08204b5 | |||
| 1de4888599 | 
@@ -26,12 +26,12 @@ import (
 | 
				
			|||||||
func GetConfLoader() *onion.Onion {
 | 
					func GetConfLoader() *onion.Onion {
 | 
				
			||||||
	logger := zerolog.New(os.Stdout).With().Timestamp().Logger()
 | 
						logger := zerolog.New(os.Stdout).With().Timestamp().Logger()
 | 
				
			||||||
	AppName := GetAppName()
 | 
						AppName := GetAppName()
 | 
				
			||||||
	EnvPrefix := strings.ToUpper(AppName[0:2]+AppName[3:]) + "_"
 | 
						EnvPrefix := "OC_"
 | 
				
			||||||
	defaultConfigFile := "/etc/oc/" + AppName[3:] + ".json"
 | 
						defaultConfigFile := "/etc/oc/" + AppName[3:] + ".json"
 | 
				
			||||||
	localConfigFile := "./" + AppName[3:] + ".json"
 | 
						localConfigFile := "./" + AppName[3:] + ".json"
 | 
				
			||||||
	var configFile string
 | 
						var configFile string
 | 
				
			||||||
	var o *onion.Onion
 | 
						var o *onion.Onion
 | 
				
			||||||
	l3 := onion.NewEnvLayerPrefix("_", EnvPrefix)
 | 
						l3 := GetEnvVarLayer(EnvPrefix)
 | 
				
			||||||
	l2, err := onion.NewFileLayer(localConfigFile, nil)
 | 
						l2, err := onion.NewFileLayer(localConfigFile, nil)
 | 
				
			||||||
	if err == nil {
 | 
						if err == nil {
 | 
				
			||||||
		logger.Info().Msg("Local config file found " + localConfigFile + ", overriding default file")
 | 
							logger.Info().Msg("Local config file found " + localConfigFile + ", overriding default file")
 | 
				
			||||||
@@ -54,3 +54,17 @@ func GetConfLoader() *onion.Onion {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	return o
 | 
						return o
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func GetEnvVarLayer(prefix string) onion.Layer {
 | 
				
			||||||
 | 
						envVars := make(map[string]interface{})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, e := range os.Environ() {
 | 
				
			||||||
 | 
							pair := strings.SplitN(e, "=", 2)
 | 
				
			||||||
 | 
							key := pair[0]
 | 
				
			||||||
 | 
							if strings.HasPrefix(key, prefix) {
 | 
				
			||||||
 | 
								envVars[strings.TrimPrefix(key, prefix)] = pair[1]
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return onion.NewMapLayer(envVars)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -287,7 +287,7 @@ func (m *MongoDB) Search(filters *dbs.Filters, collection_name string) (*mongo.C
 | 
				
			|||||||
		return nil, 503, err
 | 
							return nil, 503, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	opts := options.Find()
 | 
						opts := options.Find()
 | 
				
			||||||
	opts.SetLimit(100)
 | 
						opts.SetLimit(1000)
 | 
				
			||||||
	targetDBCollection := CollectionMap[collection_name]
 | 
						targetDBCollection := CollectionMap[collection_name]
 | 
				
			||||||
	orList := bson.A{}
 | 
						orList := bson.A{}
 | 
				
			||||||
	andList := bson.A{}
 | 
						andList := bson.A{}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,7 +15,7 @@ import (
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
type Booking struct {
 | 
					type Booking struct {
 | 
				
			||||||
	utils.AbstractObject                    // AbstractObject contains the basic fields of an object (id, name)
 | 
						utils.AbstractObject                    // AbstractObject contains the basic fields of an object (id, name)
 | 
				
			||||||
	ExecutionsID         string             `json:"executions_id,omitempty" bson:"executions_id,omitempty"` // ExecutionsID is the ID of the executions
 | 
						ExecutionsID         string             `json:"executions_id,omitempty" bson:"executions_id,omitempty" validate:"required"` // ExecutionsID is the ID of the executions
 | 
				
			||||||
	DestPeerID           string             `json:"dest_peer_id,omitempty"`                                 // DestPeerID is the ID of the destination peer
 | 
						DestPeerID           string             `json:"dest_peer_id,omitempty"`                                 // DestPeerID is the ID of the destination peer
 | 
				
			||||||
	WorkflowID           string             `json:"workflow_id,omitempty" bson:"workflow_id,omitempty"`     // WorkflowID is the ID of the workflow
 | 
						WorkflowID           string             `json:"workflow_id,omitempty" bson:"workflow_id,omitempty"`     // WorkflowID is the ID of the workflow
 | 
				
			||||||
	ExecutionID          string             `json:"execution_id,omitempty" bson:"execution_id,omitempty" validate:"required"`
 | 
						ExecutionID          string             `json:"execution_id,omitempty" bson:"execution_id,omitempty" validate:"required"`
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,13 +51,15 @@ func (a *bookingMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (a *bookingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
 | 
					func (a *bookingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
 | 
				
			||||||
	return utils.GenericLoadOne[*Booking](id, func(d utils.DBObject) (utils.DBObject, int, error) {
 | 
						return utils.GenericLoadOne[*Booking](id, func(d utils.DBObject) (utils.DBObject, int, error) {
 | 
				
			||||||
		if d.(*Booking).State == enum.DRAFT && time.Now().UTC().After(d.(*Booking).ExpectedStartDate) {
 | 
							now := time.Now()
 | 
				
			||||||
 | 
							now = now.Add(time.Second * -60)
 | 
				
			||||||
 | 
							if d.(*Booking).State == enum.DRAFT && now.UTC().After(d.(*Booking).ExpectedStartDate) {
 | 
				
			||||||
			return utils.GenericDeleteOne(d.GetID(), a)
 | 
								return utils.GenericDeleteOne(d.GetID(), a)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (d.(*Booking).ExpectedEndDate) == nil {
 | 
							if (d.(*Booking).ExpectedEndDate) == nil {
 | 
				
			||||||
			d.(*Booking).State = enum.FORGOTTEN
 | 
								d.(*Booking).State = enum.FORGOTTEN
 | 
				
			||||||
			utils.GenericRawUpdateOne(d, id, a)
 | 
								utils.GenericRawUpdateOne(d, id, a)
 | 
				
			||||||
		} else if d.(*Booking).State == enum.SCHEDULED && time.Now().UTC().After(*&d.(*Booking).ExpectedStartDate) {
 | 
							} else if d.(*Booking).State == enum.SCHEDULED && now.UTC().After(d.(*Booking).ExpectedStartDate) {
 | 
				
			||||||
			d.(*Booking).State = enum.DELAYED
 | 
								d.(*Booking).State = enum.DELAYED
 | 
				
			||||||
			utils.GenericRawUpdateOne(d, id, a)
 | 
								utils.GenericRawUpdateOne(d, id, a)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -75,11 +77,13 @@ func (a *bookingMongoAccessor) Search(filters *dbs.Filters, search string, isDra
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (a *bookingMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
 | 
					func (a *bookingMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
 | 
				
			||||||
	return func(d utils.DBObject) utils.ShallowDBObject {
 | 
						return func(d utils.DBObject) utils.ShallowDBObject {
 | 
				
			||||||
		if d.(*Booking).State == enum.DRAFT && time.Now().UTC().After(d.(*Booking).ExpectedStartDate) {
 | 
							now := time.Now()
 | 
				
			||||||
 | 
							now = now.Add(time.Second * -60)
 | 
				
			||||||
 | 
							if d.(*Booking).State == enum.DRAFT && now.UTC().After(d.(*Booking).ExpectedStartDate) {
 | 
				
			||||||
			utils.GenericDeleteOne(d.GetID(), a)
 | 
								utils.GenericDeleteOne(d.GetID(), a)
 | 
				
			||||||
			return nil
 | 
								return nil
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if d.(*Booking).State == enum.SCHEDULED && time.Now().UTC().After(*&d.(*Booking).ExpectedStartDate) {
 | 
							if d.(*Booking).State == enum.SCHEDULED && now.UTC().After(d.(*Booking).ExpectedStartDate) {
 | 
				
			||||||
			d.(*Booking).State = enum.DELAYED
 | 
								d.(*Booking).State = enum.DELAYED
 | 
				
			||||||
			utils.GenericRawUpdateOne(d, d.GetID(), a)
 | 
								utils.GenericRawUpdateOne(d, d.GetID(), a)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,6 @@ import (
 | 
				
			|||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"regexp"
 | 
					 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/tools"
 | 
						"cloud.o-forge.io/core/oc-lib/tools"
 | 
				
			||||||
@@ -29,47 +28,19 @@ type PeerCache struct {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// urlFormat formats the URL of the peer with the data type API function
 | 
					// urlFormat formats the URL of the peer with the data type API function
 | 
				
			||||||
func (p *PeerCache) urlFormat(url string, dt tools.DataType) string {
 | 
					func (p *PeerCache) urlFormat(hostUrl string, dt tools.DataType) string {
 | 
				
			||||||
	// localhost is replaced by the local peer URL
 | 
						return hostUrl + "/" + strings.ReplaceAll(dt.API(), "oc-", "")
 | 
				
			||||||
	// because localhost must collide on a web request security protocol
 | 
					 | 
				
			||||||
	localhost := ""
 | 
					 | 
				
			||||||
	if strings.Contains(url, "localhost") {
 | 
					 | 
				
			||||||
		localhost = "localhost"
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if strings.Contains(url, "127.0.0.1") {
 | 
					 | 
				
			||||||
		localhost = "127.0.0.1"
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if localhost != "" {
 | 
					 | 
				
			||||||
		r := regexp.MustCompile("(" + localhost + ":[0-9]+)")
 | 
					 | 
				
			||||||
		t := r.FindString(url)
 | 
					 | 
				
			||||||
		if t != "" {
 | 
					 | 
				
			||||||
			url = strings.Replace(url, t, dt.API()+":8080/oc", -1)
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			url = strings.ReplaceAll(url, localhost, dt.API()+":8080/oc")
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		url = url + "/" + dt.API()
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return url
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// checkPeerStatus checks the status of a peer
 | 
					// checkPeerStatus checks the status of a peer
 | 
				
			||||||
func (p *PeerCache) checkPeerStatus(peerID string, appName string, caller *tools.HTTPCaller) (*Peer, bool) {
 | 
					func (p *PeerCache) checkPeerStatus(peerID string, appName string) (*Peer, bool) {
 | 
				
			||||||
	api := tools.API{}
 | 
						api := tools.API{}
 | 
				
			||||||
	access := NewShallowAccessor()
 | 
						access := NewShallowAccessor()
 | 
				
			||||||
	res, code, _ := access.LoadOne(peerID) // Load the peer from db
 | 
						res, code, _ := access.LoadOne(peerID) // Load the peer from db
 | 
				
			||||||
	if code != 200 {                       // no peer no party
 | 
						if code != 200 {                       // no peer no party
 | 
				
			||||||
		return nil, false
 | 
							return nil, false
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	methods := caller.URLS[tools.PEER] // Get the methods url of the peer
 | 
						url := p.urlFormat(res.(*Peer).Url, tools.PEER) + "/status" // Format the URL
 | 
				
			||||||
	if methods == nil {
 | 
					 | 
				
			||||||
		return res.(*Peer), false
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	meth := methods[tools.POST] // Get the POST method to check status
 | 
					 | 
				
			||||||
	if meth == "" {
 | 
					 | 
				
			||||||
		return res.(*Peer), false
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	url := p.urlFormat(res.(*Peer).Url, tools.PEER) + meth // Format the URL
 | 
					 | 
				
			||||||
	state, services := api.CheckRemotePeer(url)
 | 
						state, services := api.CheckRemotePeer(url)
 | 
				
			||||||
	res.(*Peer).ServicesState = services                              // Update the services states of the peer
 | 
						res.(*Peer).ServicesState = services                              // Update the services states of the peer
 | 
				
			||||||
	access.UpdateOne(res, peerID)                                     // Update the peer in the db
 | 
						access.UpdateOne(res, peerID)                                     // Update the peer in the db
 | 
				
			||||||
@@ -77,36 +48,37 @@ func (p *PeerCache) checkPeerStatus(peerID string, appName string, caller *tools
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// LaunchPeerExecution launches an execution on a peer
 | 
					// LaunchPeerExecution launches an execution on a peer
 | 
				
			||||||
 | 
					// The method contacts the path described by : peer.Url + datatype path (from enums) + replacement of id by dataID
 | 
				
			||||||
func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
 | 
					func (p *PeerCache) LaunchPeerExecution(peerID string, dataID string,
 | 
				
			||||||
	dt tools.DataType, method tools.METHOD, body interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
 | 
						dt tools.DataType, method tools.METHOD, body interface{}, caller *tools.HTTPCaller) (*PeerExecution, error) {
 | 
				
			||||||
	fmt.Println("Launching peer execution on", caller.URLS, dt, method)
 | 
						fmt.Println("Launching peer execution on", caller.URLS, dt, method)
 | 
				
			||||||
	methods := caller.URLS[dt] // Get the methods url of the data type
 | 
						methods := caller.URLS[dt] // Get the methods url of the data type
 | 
				
			||||||
	if m, ok := methods[method]; !ok || m == "" {
 | 
						if m, ok := methods[method]; !ok || m == "" {
 | 
				
			||||||
		return nil, errors.New("no path found")
 | 
							return nil, errors.New("Requested method " + method.String() + " not declared in HTTPCaller")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	meth := methods[method]                        // Get the method url to execute
 | 
						path := methods[method]                        // Get the path corresponding to the action we want to execute
 | 
				
			||||||
	meth = strings.ReplaceAll(meth, ":id", dataID) // Replace the id in the url in case of a DELETE / UPDATE method (it's a standard naming in OC)
 | 
						path = strings.ReplaceAll(path, ":id", dataID) // Replace the id in the path in case of a DELETE / UPDATE method (it's a standard naming in OC)
 | 
				
			||||||
	url := ""
 | 
						url := ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check the status of the peer
 | 
						// Check the status of the peer
 | 
				
			||||||
	if mypeer, ok := p.checkPeerStatus(peerID, dt.API(), caller); !ok && mypeer != nil {
 | 
						if mypeer, ok := p.checkPeerStatus(peerID, dt.API()); !ok && mypeer != nil {
 | 
				
			||||||
		// If the peer is not reachable, add the execution to the failed executions list
 | 
							// If the peer is not reachable, add the execution to the failed executions list
 | 
				
			||||||
		pexec := &PeerExecution{
 | 
							pexec := &PeerExecution{
 | 
				
			||||||
			Method:   method.String(),
 | 
								Method:   method.String(),
 | 
				
			||||||
			Url:      p.urlFormat((mypeer.Url)+meth, dt),
 | 
								Url:      p.urlFormat((mypeer.Url), dt) + path, // the url is constitued of : host URL + resource path + action path (ex : mypeer.com/datacenter/resourcetype/path/to/action)
 | 
				
			||||||
			Body:     body,
 | 
								Body:     body,
 | 
				
			||||||
			DataType: dt.EnumIndex(),
 | 
								DataType: dt.EnumIndex(),
 | 
				
			||||||
			DataID:   dataID,
 | 
								DataID:   dataID,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		mypeer.AddExecution(*pexec)
 | 
							mypeer.AddExecution(*pexec)
 | 
				
			||||||
		NewShallowAccessor().UpdateOne(mypeer, peerID) // Update the peer in the db
 | 
							NewShallowAccessor().UpdateOne(mypeer, peerID) // Update the peer in the db
 | 
				
			||||||
		return nil, errors.New("peer is not reachable")
 | 
							return nil, errors.New("peer is " + peerID + " not reachable")
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		if mypeer == nil {
 | 
							if mypeer == nil {
 | 
				
			||||||
			return nil, errors.New("peer not found")
 | 
								return nil, errors.New("peer " + peerID + " not found")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		// If the peer is reachable, launch the execution
 | 
							// If the peer is reachable, launch the execution
 | 
				
			||||||
		url = p.urlFormat((mypeer.Url)+meth, dt)       // Format the URL
 | 
							url = p.urlFormat((mypeer.Url), dt) + path     // Format the URL
 | 
				
			||||||
		tmp := mypeer.FailedExecution                  // Get the failed executions list
 | 
							tmp := mypeer.FailedExecution                  // Get the failed executions list
 | 
				
			||||||
		mypeer.FailedExecution = []PeerExecution{}     // Reset the failed executions list
 | 
							mypeer.FailedExecution = []PeerExecution{}     // Reset the failed executions list
 | 
				
			||||||
		NewShallowAccessor().UpdateOne(mypeer, peerID) // Update the peer in the db
 | 
							NewShallowAccessor().UpdateOne(mypeer, peerID) // Update the peer in the db
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -89,6 +89,9 @@ func (r *AbstractInstanciatedResource[T]) GetSelectedInstance() utils.DBObject {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (abs *AbstractInstanciatedResource[T]) SetAllowedInstances(request *tools.APIRequest) {
 | 
					func (abs *AbstractInstanciatedResource[T]) SetAllowedInstances(request *tools.APIRequest) {
 | 
				
			||||||
 | 
						if request != nil && request.PeerID == abs.CreatorID && request.PeerID != "" {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	abs.Instances = verifyAuthAction[T](abs.Instances, request)
 | 
						abs.Instances = verifyAuthAction[T](abs.Instances, request)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -65,6 +65,12 @@ func (wfa *resourceMongoAccessor[T]) LoadAll(isDraft bool) ([]utils.ShallowDBObj
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (wfa *resourceMongoAccessor[T]) Search(filters *dbs.Filters, search string, isDraft bool) ([]utils.ShallowDBObject, int, error) {
 | 
					func (wfa *resourceMongoAccessor[T]) Search(filters *dbs.Filters, search string, isDraft bool) ([]utils.ShallowDBObject, int, error) {
 | 
				
			||||||
 | 
						if filters == nil && search == "*" {
 | 
				
			||||||
 | 
							return utils.GenericLoadAll[T](func(d utils.DBObject) utils.ShallowDBObject {
 | 
				
			||||||
 | 
								d.(T).SetAllowedInstances(wfa.Request)
 | 
				
			||||||
 | 
								return d
 | 
				
			||||||
 | 
							}, isDraft, wfa)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return utils.GenericSearch[T](filters, search, wfa.getResourceFilter(search),
 | 
						return utils.GenericSearch[T](filters, search, wfa.getResourceFilter(search),
 | 
				
			||||||
		func(d utils.DBObject) utils.ShallowDBObject {
 | 
							func(d utils.DBObject) utils.ShallowDBObject {
 | 
				
			||||||
			d.(T).SetAllowedInstances(wfa.Request)
 | 
								d.(T).SetAllowedInstances(wfa.Request)
 | 
				
			||||||
@@ -73,9 +79,6 @@ func (wfa *resourceMongoAccessor[T]) Search(filters *dbs.Filters, search string,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (abs *resourceMongoAccessor[T]) getResourceFilter(search string) *dbs.Filters {
 | 
					func (abs *resourceMongoAccessor[T]) getResourceFilter(search string) *dbs.Filters {
 | 
				
			||||||
	if search == "*" {
 | 
					 | 
				
			||||||
		search = ""
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return &dbs.Filters{
 | 
						return &dbs.Filters{
 | 
				
			||||||
		Or: map[string][]dbs.Filter{ // filter by like name, short_description, description, owner, url if no filters are provided
 | 
							Or: map[string][]dbs.Filter{ // filter by like name, short_description, description, owner, url if no filters are provided
 | 
				
			||||||
			"abstractintanciatedresource.abstractresource.abstractobject.name":       {{Operator: dbs.LIKE.String(), Value: search}},
 | 
								"abstractintanciatedresource.abstractresource.abstractobject.name":       {{Operator: dbs.LIKE.String(), Value: search}},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -91,7 +91,7 @@ func (ao *AbstractObject) UpToDate(user string, peer string, create bool) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (ao *AbstractObject) VerifyAuth(request *tools.APIRequest) bool {
 | 
					func (ao *AbstractObject) VerifyAuth(request *tools.APIRequest) bool {
 | 
				
			||||||
	return ao.AccessMode == Public || (request != nil && ao.CreatorID == request.PeerID)
 | 
						return ao.AccessMode == Public || (request != nil && ao.CreatorID == request.PeerID && request.PeerID != "")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (ao *AbstractObject) GetObjectFilters(search string) *dbs.Filters {
 | 
					func (ao *AbstractObject) GetObjectFilters(search string) *dbs.Filters {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -31,6 +31,43 @@ func (d *Workflow) GetAccessor(request *tools.APIRequest) utils.Accessor {
 | 
				
			|||||||
	return NewAccessor(request) // Create a new instance of the accessor
 | 
						return NewAccessor(request) // Create a new instance of the accessor
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Deps struct {
 | 
				
			||||||
 | 
						Source string
 | 
				
			||||||
 | 
						Dest   string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (w *Workflow) isDependancy(id string) []Deps {
 | 
				
			||||||
 | 
						dependancyOfIDs := []Deps{}
 | 
				
			||||||
 | 
						for _, link := range w.Graph.Links {
 | 
				
			||||||
 | 
							if _, ok := w.Graph.Items[link.Destination.ID]; !ok {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							source := w.Graph.Items[link.Destination.ID].Processing
 | 
				
			||||||
 | 
							if id == link.Source.ID && source != nil {
 | 
				
			||||||
 | 
								dependancyOfIDs = append(dependancyOfIDs, Deps{Source: source.GetName(), Dest: link.Destination.ID})
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							sourceWF := w.Graph.Items[link.Destination.ID].Workflow
 | 
				
			||||||
 | 
							if id == link.Source.ID && sourceWF != nil {
 | 
				
			||||||
 | 
								dependancyOfIDs = append(dependancyOfIDs, Deps{Source: sourceWF.GetName(), Dest: link.Destination.ID})
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return dependancyOfIDs
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (w *Workflow) GetDependencies(id string) (dependencies []Deps) {
 | 
				
			||||||
 | 
						for _, link := range w.Graph.Links {
 | 
				
			||||||
 | 
							if _, ok := w.Graph.Items[link.Source.ID]; !ok {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							source := w.Graph.Items[link.Source.ID].Processing
 | 
				
			||||||
 | 
							if id == link.Destination.ID && source != nil {
 | 
				
			||||||
 | 
								dependencies = append(dependencies, Deps{Source: source.GetName(), Dest: link.Source.ID})
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (w *Workflow) GetGraphItems(f func(item graph.GraphItem) bool) (list_datas []graph.GraphItem) {
 | 
					func (w *Workflow) GetGraphItems(f func(item graph.GraphItem) bool) (list_datas []graph.GraphItem) {
 | 
				
			||||||
	for _, item := range w.Graph.Items {
 | 
						for _, item := range w.Graph.Items {
 | 
				
			||||||
		if f(item) {
 | 
							if f(item) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -95,7 +95,7 @@ func (a *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.
 | 
				
			|||||||
	if set.(*Workflow).Graph != nil && set.(*Workflow).Graph.Partial {
 | 
						if set.(*Workflow).Graph != nil && set.(*Workflow).Graph.Partial {
 | 
				
			||||||
		return nil, 403, errors.New("you are not allowed to update a partial workflow")
 | 
							return nil, 403, errors.New("you are not allowed to update a partial workflow")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	res, code, err := utils.GenericUpdateOne(a.verifyResource(set), id, a, &Workflow{})
 | 
						res, code, err := utils.GenericUpdateOne(set, id, a, &Workflow{})
 | 
				
			||||||
	if code != 200 {
 | 
						if code != 200 {
 | 
				
			||||||
		return nil, code, err
 | 
							return nil, code, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -112,6 +112,8 @@ func (d *WorkflowExecution) VerifyAuth(request *tools.APIRequest) bool {
 | 
				
			|||||||
func (d *WorkflowExecution) Book(executionsID string, wfID string, priceds map[tools.DataType]map[string]pricing.PricedItemITF) []*booking.Booking {
 | 
					func (d *WorkflowExecution) Book(executionsID string, wfID string, priceds map[tools.DataType]map[string]pricing.PricedItemITF) []*booking.Booking {
 | 
				
			||||||
	booking := d.bookEach(executionsID, wfID, tools.STORAGE_RESOURCE, priceds[tools.STORAGE_RESOURCE])
 | 
						booking := d.bookEach(executionsID, wfID, tools.STORAGE_RESOURCE, priceds[tools.STORAGE_RESOURCE])
 | 
				
			||||||
	booking = append(booking, d.bookEach(executionsID, wfID, tools.PROCESSING_RESOURCE, priceds[tools.PROCESSING_RESOURCE])...)
 | 
						booking = append(booking, d.bookEach(executionsID, wfID, tools.PROCESSING_RESOURCE, priceds[tools.PROCESSING_RESOURCE])...)
 | 
				
			||||||
 | 
						booking = append(booking,d.bookEach(executionsID, wfID, tools.COMPUTE_RESOURCE, priceds[tools.COMPUTE_RESOURCE])...)
 | 
				
			||||||
 | 
						booking = append(booking,d.bookEach(executionsID, wfID, tools.DATA_RESOURCE, priceds[tools.DATA_RESOURCE])...)
 | 
				
			||||||
	return booking
 | 
						return booking
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -60,11 +60,13 @@ func (wfa *workflowExecutionMongoAccessor) CopyOne(data utils.DBObject) (utils.D
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (a *workflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
 | 
					func (a *workflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
 | 
				
			||||||
	return utils.GenericLoadOne[*WorkflowExecution](id, func(d utils.DBObject) (utils.DBObject, int, error) {
 | 
						return utils.GenericLoadOne[*WorkflowExecution](id, func(d utils.DBObject) (utils.DBObject, int, error) {
 | 
				
			||||||
		if d.(*WorkflowExecution).State == enum.DRAFT && !a.shallow && time.Now().UTC().After(d.(*WorkflowExecution).ExecDate) {
 | 
							now := time.Now()
 | 
				
			||||||
 | 
							now = now.Add(time.Second * -60)
 | 
				
			||||||
 | 
							if d.(*WorkflowExecution).State == enum.DRAFT && !a.shallow && now.UTC().After(d.(*WorkflowExecution).ExecDate) {
 | 
				
			||||||
			utils.GenericDeleteOne(d.GetID(), newShallowAccessor(a.Request))
 | 
								utils.GenericDeleteOne(d.GetID(), newShallowAccessor(a.Request))
 | 
				
			||||||
			return nil, 404, errors.New("not found")
 | 
								return nil, 404, errors.New("not found")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if d.(*WorkflowExecution).State == enum.SCHEDULED && !a.shallow && time.Now().UTC().After(d.(*WorkflowExecution).ExecDate) {
 | 
							if d.(*WorkflowExecution).State == enum.SCHEDULED && !a.shallow && now.UTC().After(d.(*WorkflowExecution).ExecDate) {
 | 
				
			||||||
			d.(*WorkflowExecution).State = enum.FORGOTTEN
 | 
								d.(*WorkflowExecution).State = enum.FORGOTTEN
 | 
				
			||||||
			utils.GenericRawUpdateOne(d, id, newShallowAccessor(a.Request))
 | 
								utils.GenericRawUpdateOne(d, id, newShallowAccessor(a.Request))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -82,11 +84,13 @@ func (a *workflowExecutionMongoAccessor) Search(filters *dbs.Filters, search str
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (a *workflowExecutionMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
 | 
					func (a *workflowExecutionMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
 | 
				
			||||||
	return func(d utils.DBObject) utils.ShallowDBObject {
 | 
						return func(d utils.DBObject) utils.ShallowDBObject {
 | 
				
			||||||
		if d.(*WorkflowExecution).State == enum.DRAFT && time.Now().UTC().After(d.(*WorkflowExecution).ExecDate) {
 | 
							now := time.Now()
 | 
				
			||||||
 | 
							now = now.Add(time.Second * -60)
 | 
				
			||||||
 | 
							if d.(*WorkflowExecution).State == enum.DRAFT && now.UTC().After(d.(*WorkflowExecution).ExecDate) {
 | 
				
			||||||
			utils.GenericDeleteOne(d.GetID(), newShallowAccessor(a.Request))
 | 
								utils.GenericDeleteOne(d.GetID(), newShallowAccessor(a.Request))
 | 
				
			||||||
			return nil
 | 
								return nil
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if d.(*WorkflowExecution).State == enum.SCHEDULED && time.Now().UTC().After(d.(*WorkflowExecution).ExecDate) {
 | 
							if d.(*WorkflowExecution).State == enum.SCHEDULED && now.UTC().After(d.(*WorkflowExecution).ExecDate) {
 | 
				
			||||||
			d.(*WorkflowExecution).State = enum.FORGOTTEN
 | 
								d.(*WorkflowExecution).State = enum.FORGOTTEN
 | 
				
			||||||
			utils.GenericRawUpdateOne(d, d.GetID(), newShallowAccessor(a.Request))
 | 
								utils.GenericRawUpdateOne(d, d.GetID(), newShallowAccessor(a.Request))
 | 
				
			||||||
			return d
 | 
								return d
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,6 +4,7 @@ import (
 | 
				
			|||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
 | 
						"sync"
 | 
				
			||||||
	"time"
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/models/booking"
 | 
						"cloud.o-forge.io/core/oc-lib/models/booking"
 | 
				
			||||||
@@ -77,22 +78,60 @@ func (ws *WorkflowSchedule) CheckBooking(wfID string, request *tools.APIRequest)
 | 
				
			|||||||
	bookings := []*booking.Booking{}
 | 
						bookings := []*booking.Booking{}
 | 
				
			||||||
	for _, exec := range execs {
 | 
						for _, exec := range execs {
 | 
				
			||||||
		bookings = append(bookings, exec.Book(ws.UUID, wfID, priceds)...)
 | 
							bookings = append(bookings, exec.Book(ws.UUID, wfID, priceds)...)
 | 
				
			||||||
		for _, b := range bookings {
 | 
					 | 
				
			||||||
			meth := request.Caller.URLS[tools.BOOKING][tools.GET]
 | 
					 | 
				
			||||||
			meth = strings.ReplaceAll(meth, ":id", b.ResourceID)
 | 
					 | 
				
			||||||
			meth = strings.ReplaceAll(meth, ":start_date", b.ExpectedStartDate.Format("2006-01-02T15:04:05"))
 | 
					 | 
				
			||||||
			meth = strings.ReplaceAll(meth, ":end_date", b.ExpectedEndDate.Format("2006-01-02T15:04:05"))
 | 
					 | 
				
			||||||
			request.Caller.URLS[tools.BOOKING][tools.GET] = meth
 | 
					 | 
				
			||||||
			_, err := (&peer.Peer{}).LaunchPeerExecution(b.DestPeerID, b.ResourceID, tools.BOOKING, tools.GET, nil, request.Caller)
 | 
					 | 
				
			||||||
			if err != nil {
 | 
					 | 
				
			||||||
				return false, wf, execs, bookings, err
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						errCh := make(chan error, len(bookings))
 | 
				
			||||||
 | 
						var m sync.Mutex
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for _, b := range bookings {
 | 
				
			||||||
 | 
							go getBooking(b, request, wf, execs, bookings, errCh, &m)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for i := 0; i < len(bookings); i++ {
 | 
				
			||||||
 | 
							if err := <-errCh; err != nil {
 | 
				
			||||||
 | 
								return false, wf, execs, bookings, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return true, wf, execs, bookings, nil
 | 
						return true, wf, execs, bookings, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getBooking( b *booking.Booking, request *tools.APIRequest, wf *workflow.Workflow, execs []*WorkflowExecution, bookings []*booking.Booking, errCh chan error, m *sync.Mutex) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m.Lock()
 | 
				
			||||||
 | 
						c, err := getCallerCopy(request, errCh)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							errCh <- err
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						m.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						meth := c.URLS[tools.BOOKING][tools.GET]
 | 
				
			||||||
 | 
						meth = strings.ReplaceAll(meth, ":id", b.ResourceID)
 | 
				
			||||||
 | 
						meth = strings.ReplaceAll(meth, ":start_date", b.ExpectedStartDate.Format("2006-01-02T15:04:05"))
 | 
				
			||||||
 | 
						meth = strings.ReplaceAll(meth, ":end_date", b.ExpectedEndDate.Format("2006-01-02T15:04:05"))
 | 
				
			||||||
 | 
						c.URLS[tools.BOOKING][tools.GET] = meth
 | 
				
			||||||
 | 
						_, err = (&peer.Peer{}).LaunchPeerExecution(b.DestPeerID, b.ResourceID, tools.BOOKING, tools.GET, nil, &c)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							errCh <- err
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						errCh <- nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func getCallerCopy(request *tools.APIRequest, errCh chan error) (tools.HTTPCaller, error) {
 | 
				
			||||||
 | 
						var c tools.HTTPCaller
 | 
				
			||||||
 | 
						err := request.Caller.DeepCopy(c)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							errCh <- err
 | 
				
			||||||
 | 
							return tools.HTTPCaller{}, nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						c.URLS = request.Caller.URLS
 | 
				
			||||||
 | 
						return c, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (ws *WorkflowSchedule) Schedules(wfID string, request *tools.APIRequest) (*WorkflowSchedule, *workflow.Workflow, []*WorkflowExecution, error) {
 | 
					func (ws *WorkflowSchedule) Schedules(wfID string, request *tools.APIRequest) (*WorkflowSchedule, *workflow.Workflow, []*WorkflowExecution, error) {
 | 
				
			||||||
	if request == nil {
 | 
						if request == nil {
 | 
				
			||||||
		return ws, nil, []*WorkflowExecution{}, errors.New("no request found")
 | 
							return ws, nil, []*WorkflowExecution{}, errors.New("no request found")
 | 
				
			||||||
@@ -111,25 +150,54 @@ func (ws *WorkflowSchedule) Schedules(wfID string, request *tools.APIRequest) (*
 | 
				
			|||||||
		return ws, nil, executions, errors.New("could not book the workflow : " + fmt.Sprintf("%v", err))
 | 
							return ws, nil, executions, errors.New("could not book the workflow : " + fmt.Sprintf("%v", err))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	ws.Workflow = wf
 | 
						ws.Workflow = wf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var errCh = make(chan error, len(bookings))
 | 
				
			||||||
 | 
						var m sync.Mutex
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, booking := range bookings {
 | 
						for _, booking := range bookings {
 | 
				
			||||||
		_, err := (&peer.Peer{}).LaunchPeerExecution(booking.DestPeerID, "",
 | 
							go ws.BookExecs(booking, request, errCh, &m)
 | 
				
			||||||
			tools.BOOKING, tools.POST, booking.Serialize(booking), request.Caller)
 | 
						}
 | 
				
			||||||
		if err != nil {
 | 
						
 | 
				
			||||||
 | 
						for i := 0; i < len(bookings); i++ {
 | 
				
			||||||
 | 
							if err := <- errCh ; err != nil {
 | 
				
			||||||
			return ws, wf, executions, errors.New("could not launch the peer execution : " + fmt.Sprintf("%v", err))
 | 
								return ws, wf, executions, errors.New("could not launch the peer execution : " + fmt.Sprintf("%v", err))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fmt.Println("Schedules")
 | 
				
			||||||
	for _, exec := range executions {
 | 
						for _, exec := range executions {
 | 
				
			||||||
		err := exec.PurgeDraft(request)
 | 
							err := exec.PurgeDraft(request)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			return ws, nil, []*WorkflowExecution{}, errors.New("purge draft" + fmt.Sprintf("%v", err))
 | 
								return ws, nil, []*WorkflowExecution{}, errors.New("purge draft" + fmt.Sprintf("%v", err))
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		exec.StoreDraftDefault()
 | 
							exec.StoreDraftDefault()
 | 
				
			||||||
		// Should DELETE the previous execution2
 | 
							utils.GenericStoreOne(exec, NewAccessor(request))
 | 
				
			||||||
		fmt.Println(utils.GenericStoreOne(exec, NewAccessor(request)))
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						fmt.Println("Schedules")
 | 
				
			||||||
	return ws, wf, executions, nil
 | 
						return ws, wf, executions, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (ws *WorkflowSchedule) BookExecs(booking *booking.Booking, request *tools.APIRequest, errCh chan error, m *sync.Mutex) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						m.Lock()
 | 
				
			||||||
 | 
						c, err := getCallerCopy(request, errCh)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							errCh <- err
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						m.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_, err = (&peer.Peer{}).LaunchPeerExecution(booking.DestPeerID, "",
 | 
				
			||||||
 | 
							tools.BOOKING, tools.POST, booking.Serialize(booking), &c)
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							errCh <- err
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						errCh <- nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
BOOKING IMPLIED TIME, not of subscription but of execution
 | 
					BOOKING IMPLIED TIME, not of subscription but of execution
 | 
				
			||||||
so is processing time execution time applied on computes
 | 
					so is processing time execution time applied on computes
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,9 +72,11 @@ func (a *workspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils
 | 
				
			|||||||
func (a *workspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
 | 
					func (a *workspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
 | 
				
			||||||
	filters := &dbs.Filters{
 | 
						filters := &dbs.Filters{
 | 
				
			||||||
		Or: map[string][]dbs.Filter{
 | 
							Or: map[string][]dbs.Filter{
 | 
				
			||||||
			"abstractobject.name": {{Operator: dbs.LIKE.String(), Value: data.GetName() + "_workspace"}},
 | 
								"abstractobject.name":       {{Operator: dbs.LIKE.String(), Value: data.GetName() + "_workspace"}},
 | 
				
			||||||
 | 
								"abstractobject.creator_id": {{Operator: dbs.EQUAL.String(), Value: a.GetPeerID()}},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// filters *dbs.Filters, word string, isDraft bool
 | 
				
			||||||
	res, _, err := a.Search(filters, "", true) // Search for the workspace
 | 
						res, _, err := a.Search(filters, "", true) // Search for the workspace
 | 
				
			||||||
	if err == nil && len(res) > 0 {            // If the workspace already exists, return an error
 | 
						if err == nil && len(res) > 0 {            // If the workspace already exists, return an error
 | 
				
			||||||
		return nil, 409, errors.New("a workspace with the same name already exists")
 | 
							return nil, 409, errors.New("a workspace with the same name already exists")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/config"
 | 
						"cloud.o-forge.io/core/oc-lib/config"
 | 
				
			||||||
	"cloud.o-forge.io/core/oc-lib/dbs/mongo"
 | 
						"cloud.o-forge.io/core/oc-lib/dbs/mongo"
 | 
				
			||||||
 | 
						"cloud.o-forge.io/core/oc-lib/logs"
 | 
				
			||||||
	beego "github.com/beego/beego/v2/server/web"
 | 
						beego "github.com/beego/beego/v2/server/web"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -115,8 +116,8 @@ func (a *API) SubscribeRouter(infos []*beego.ControllerInfo) {
 | 
				
			|||||||
// CheckRemotePeer checks the state of a remote peer
 | 
					// CheckRemotePeer checks the state of a remote peer
 | 
				
			||||||
func (a *API) CheckRemotePeer(url string) (State, map[string]int) {
 | 
					func (a *API) CheckRemotePeer(url string) (State, map[string]int) {
 | 
				
			||||||
	// Check if the database is up
 | 
						// Check if the database is up
 | 
				
			||||||
	caller := NewHTTPCaller(map[DataType]map[METHOD]string{}) // Create a new http caller
 | 
					 | 
				
			||||||
	var resp APIStatusResponse
 | 
						var resp APIStatusResponse
 | 
				
			||||||
 | 
						caller := NewHTTPCaller(map[DataType]map[METHOD]string{}) // Create a new http caller
 | 
				
			||||||
	b, err := caller.CallPost(url, "", map[string]interface{}{}) // Call the status endpoint of the peer
 | 
						b, err := caller.CallPost(url, "", map[string]interface{}{}) // Call the status endpoint of the peer
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return DEAD, map[string]int{} // If the peer is not reachable, return dead
 | 
							return DEAD, map[string]int{} // If the peer is not reachable, return dead
 | 
				
			||||||
@@ -135,6 +136,7 @@ func (a *API) CheckRemotePeer(url string) (State, map[string]int) {
 | 
				
			|||||||
// CheckRemoteAPIs checks the state of remote APIs from your proper OC
 | 
					// CheckRemoteAPIs checks the state of remote APIs from your proper OC
 | 
				
			||||||
func (a *API) CheckRemoteAPIs(apis []DataType) (State, map[string]string, error) {
 | 
					func (a *API) CheckRemoteAPIs(apis []DataType) (State, map[string]string, error) {
 | 
				
			||||||
	// Check if the database is up
 | 
						// Check if the database is up
 | 
				
			||||||
 | 
						l := logs.GetLogger()
 | 
				
			||||||
	new := map[string]string{}
 | 
						new := map[string]string{}
 | 
				
			||||||
	caller := NewHTTPCaller(map[DataType]map[METHOD]string{}) // Create a new http caller
 | 
						caller := NewHTTPCaller(map[DataType]map[METHOD]string{}) // Create a new http caller
 | 
				
			||||||
	code := 0
 | 
						code := 0
 | 
				
			||||||
@@ -145,6 +147,7 @@ func (a *API) CheckRemoteAPIs(apis []DataType) (State, map[string]string, error)
 | 
				
			|||||||
		var resp APIStatusResponse
 | 
							var resp APIStatusResponse
 | 
				
			||||||
		b, err := caller.CallGet("http://"+api.API()+":8080", "/oc/version/status") // Call the status endpoint of the remote API (standard OC status endpoint)
 | 
							b, err := caller.CallGet("http://"+api.API()+":8080", "/oc/version/status") // Call the status endpoint of the remote API (standard OC status endpoint)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
 | 
								l.Error().Msg(api.String() + " not reachable")
 | 
				
			||||||
			state = REDUCED_SERVICE // If a remote API is not reachable, return reduced service
 | 
								state = REDUCED_SERVICE // If a remote API is not reachable, return reduced service
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -161,6 +164,7 @@ func (a *API) CheckRemoteAPIs(apis []DataType) (State, map[string]string, error)
 | 
				
			|||||||
		reachable = true // If the remote API is reachable, set reachable to true cause we are not dead
 | 
							reachable = true // If the remote API is reachable, set reachable to true cause we are not dead
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if !reachable {
 | 
						if !reachable {
 | 
				
			||||||
 | 
							l.Error().Msg("Peer check returned no answers")
 | 
				
			||||||
		state = DEAD // If no remote API is reachable, return dead, nobody is alive
 | 
							state = DEAD // If no remote API is reachable, return dead, nobody is alive
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if code > 0 {
 | 
						if code > 0 {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,11 @@ const (
 | 
				
			|||||||
	WORKSPACE_HISTORY
 | 
						WORKSPACE_HISTORY
 | 
				
			||||||
	ORDER
 | 
						ORDER
 | 
				
			||||||
	PURCHASE_RESOURCE
 | 
						PURCHASE_RESOURCE
 | 
				
			||||||
 | 
						ADMIRALTY_SOURCE
 | 
				
			||||||
 | 
						ADMIRALTY_TARGET
 | 
				
			||||||
 | 
						ADMIRALTY_SECRET
 | 
				
			||||||
 | 
						ADMIRALTY_KUBECONFIG
 | 
				
			||||||
 | 
						ADMIRALTY_NODES
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var NOAPI = ""
 | 
					var NOAPI = ""
 | 
				
			||||||
@@ -30,6 +35,11 @@ var WORKFLOWAPI = "oc-workflow"
 | 
				
			|||||||
var WORKSPACEAPI = "oc-workspace"
 | 
					var WORKSPACEAPI = "oc-workspace"
 | 
				
			||||||
var PEERSAPI = "oc-peer"
 | 
					var PEERSAPI = "oc-peer"
 | 
				
			||||||
var DATACENTERAPI = "oc-datacenter"
 | 
					var DATACENTERAPI = "oc-datacenter"
 | 
				
			||||||
 | 
					var ADMIRALTY_SOURCEAPI = DATACENTERAPI+"/admiralty/source"
 | 
				
			||||||
 | 
					var ADMIRALTY_TARGETAPI = DATACENTERAPI+"/admiralty/target"
 | 
				
			||||||
 | 
					var ADMIRALTY_SECRETAPI = DATACENTERAPI+"/admiralty/secret"
 | 
				
			||||||
 | 
					var ADMIRALTY_KUBECONFIGAPI = DATACENTERAPI+"/admiralty/kubeconfig"
 | 
				
			||||||
 | 
					var ADMIRALTY_NODESAPI = DATACENTERAPI+"/admiralty/node"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Bind the standard API name to the data type
 | 
					// Bind the standard API name to the data type
 | 
				
			||||||
var DefaultAPI = [...]string{
 | 
					var DefaultAPI = [...]string{
 | 
				
			||||||
@@ -50,6 +60,11 @@ var DefaultAPI = [...]string{
 | 
				
			|||||||
	NOAPI,
 | 
						NOAPI,
 | 
				
			||||||
	NOAPI,
 | 
						NOAPI,
 | 
				
			||||||
	NOAPI,
 | 
						NOAPI,
 | 
				
			||||||
 | 
						ADMIRALTY_SOURCEAPI,
 | 
				
			||||||
 | 
						ADMIRALTY_TARGETAPI,
 | 
				
			||||||
 | 
						ADMIRALTY_SECRETAPI,
 | 
				
			||||||
 | 
						ADMIRALTY_KUBECONFIGAPI,
 | 
				
			||||||
 | 
						ADMIRALTY_NODESAPI,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Bind the standard data name to the data type
 | 
					// Bind the standard data name to the data type
 | 
				
			||||||
@@ -71,6 +86,11 @@ var Str = [...]string{
 | 
				
			|||||||
	"workspace_history",
 | 
						"workspace_history",
 | 
				
			||||||
	"order",
 | 
						"order",
 | 
				
			||||||
	"purchase_resource",
 | 
						"purchase_resource",
 | 
				
			||||||
 | 
						"admiralty_source",
 | 
				
			||||||
 | 
						"admiralty_target",
 | 
				
			||||||
 | 
						"admiralty_secret",
 | 
				
			||||||
 | 
						"admiralty_kubeconfig",
 | 
				
			||||||
 | 
						"admiralty_node",
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func FromInt(i int) string {
 | 
					func FromInt(i int) string {
 | 
				
			||||||
@@ -91,5 +111,5 @@ func (d DataType) EnumIndex() int {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func DataTypeList() []DataType {
 | 
					func DataTypeList() []DataType {
 | 
				
			||||||
	return []DataType{DATA_RESOURCE, PROCESSING_RESOURCE, STORAGE_RESOURCE, COMPUTE_RESOURCE, WORKFLOW_RESOURCE, WORKFLOW, WORKFLOW_EXECUTION, WORKSPACE, PEER, COLLABORATIVE_AREA, RULE, BOOKING, WORKFLOW_HISTORY, WORKSPACE_HISTORY, ORDER, PURCHASE_RESOURCE}
 | 
						return []DataType{DATA_RESOURCE, PROCESSING_RESOURCE, STORAGE_RESOURCE, COMPUTE_RESOURCE, WORKFLOW_RESOURCE, WORKFLOW, WORKFLOW_EXECUTION, WORKSPACE, PEER, COLLABORATIVE_AREA, RULE, BOOKING, WORKFLOW_HISTORY, WORKSPACE_HISTORY, ORDER, PURCHASE_RESOURCE,ADMIRALTY_SOURCE,ADMIRALTY_TARGET,ADMIRALTY_SECRET,ADMIRALTY_KUBECONFIG,ADMIRALTY_NODES}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@ package tools
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"bytes"
 | 
						"bytes"
 | 
				
			||||||
	"encoding/json"
 | 
						"encoding/json"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
@@ -49,8 +50,9 @@ func ToMethod(str string) METHOD {
 | 
				
			|||||||
var HTTPCallerInstance = &HTTPCaller{} // Singleton instance of the HTTPCaller
 | 
					var HTTPCallerInstance = &HTTPCaller{} // Singleton instance of the HTTPCaller
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type HTTPCaller struct {
 | 
					type HTTPCaller struct {
 | 
				
			||||||
	URLS     map[DataType]map[METHOD]string // Map of the different methods and their urls
 | 
						URLS     	map[DataType]map[METHOD]string 	// Map of the different methods and their urls
 | 
				
			||||||
	Disabled bool                           // Disabled flag
 | 
						Disabled 	bool                           	// Disabled flag
 | 
				
			||||||
 | 
						LastResults map[string]interface{}			// Used to store information regarding the last execution of a given method on a given data type
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NewHTTPCaller creates a new instance of the HTTP Caller
 | 
					// NewHTTPCaller creates a new instance of the HTTP Caller
 | 
				
			||||||
@@ -61,6 +63,16 @@ func NewHTTPCaller(urls map[DataType]map[METHOD]string) *HTTPCaller {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Creates a copy of the current caller, in order to have parallelized executions without race condition 
 | 
				
			||||||
 | 
					func (c* HTTPCaller) DeepCopy(dst HTTPCaller) error {
 | 
				
			||||||
 | 
						bytes, err := json.Marshal(c)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return json.Unmarshal(bytes, &dst)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CallGet calls the GET method on the HTTP server
 | 
					// CallGet calls the GET method on the HTTP server
 | 
				
			||||||
func (caller *HTTPCaller) CallGet(url string, subpath string, types ...string) ([]byte, error) {
 | 
					func (caller *HTTPCaller) CallGet(url string, subpath string, types ...string) ([]byte, error) {
 | 
				
			||||||
	req, err := http.NewRequest(http.MethodGet, url+subpath, bytes.NewBuffer([]byte("")))
 | 
						req, err := http.NewRequest(http.MethodGet, url+subpath, bytes.NewBuffer([]byte("")))
 | 
				
			||||||
@@ -76,17 +88,33 @@ func (caller *HTTPCaller) CallGet(url string, subpath string, types ...string) (
 | 
				
			|||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer resp.Body.Close()
 | 
						defer resp.Body.Close()
 | 
				
			||||||
	return io.ReadAll(resp.Body)
 | 
						err = caller.StoreResp(resp)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return caller.LastResults["body"].([]byte), nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CallPut calls the DELETE method on the HTTP server
 | 
					// CallPut calls the DELETE method on the HTTP server
 | 
				
			||||||
func (caller *HTTPCaller) CallDelete(url string, subpath string) ([]byte, error) {
 | 
					func (caller *HTTPCaller) CallDelete(url string, subpath string) ([]byte, error) {
 | 
				
			||||||
	resp, err := http.NewRequest("DELETE", url+subpath, nil)
 | 
						req, err := http.NewRequest("DELETE", url+subpath, nil)
 | 
				
			||||||
	if err != nil || resp == nil || resp.Body == nil {
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						client := &http.Client{}
 | 
				
			||||||
 | 
						resp, err := client.Do(req)
 | 
				
			||||||
 | 
						if err != nil || req == nil || req.Body == nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer resp.Body.Close()
 | 
						defer resp.Body.Close()
 | 
				
			||||||
	return io.ReadAll(resp.Body)
 | 
					
 | 
				
			||||||
 | 
						err = caller.StoreResp(resp)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return caller.LastResults["body"].([]byte), nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CallPost calls the POST method on the HTTP server
 | 
					// CallPost calls the POST method on the HTTP server
 | 
				
			||||||
@@ -105,7 +133,12 @@ func (caller *HTTPCaller) CallPost(url string, subpath string, body interface{},
 | 
				
			|||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer resp.Body.Close()
 | 
						defer resp.Body.Close()
 | 
				
			||||||
	return io.ReadAll(resp.Body)
 | 
						err = caller.StoreResp(resp)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return caller.LastResults["body"].([]byte), nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CallPost calls the POST method on the HTTP server
 | 
					// CallPost calls the POST method on the HTTP server
 | 
				
			||||||
@@ -123,7 +156,12 @@ func (caller *HTTPCaller) CallPut(url string, subpath string, body map[string]in
 | 
				
			|||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	defer resp.Body.Close()
 | 
						defer resp.Body.Close()
 | 
				
			||||||
	return io.ReadAll(resp.Body)
 | 
						err = caller.StoreResp(resp)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return caller.LastResults["body"].([]byte), nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CallRaw calls the Raw method on the HTTP server
 | 
					// CallRaw calls the Raw method on the HTTP server
 | 
				
			||||||
@@ -143,7 +181,12 @@ func (caller *HTTPCaller) CallRaw(method string, url string, subpath string,
 | 
				
			|||||||
		req.AddCookie(c)
 | 
							req.AddCookie(c)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	client := &http.Client{}
 | 
						client := &http.Client{}
 | 
				
			||||||
	return client.Do(req)
 | 
						resp, err := client.Do(req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return resp, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CallRaw calls the Raw method on the HTTP server
 | 
					// CallRaw calls the Raw method on the HTTP server
 | 
				
			||||||
@@ -163,3 +206,17 @@ func (caller *HTTPCaller) CallForm(method string, url string, subpath string,
 | 
				
			|||||||
	client := &http.Client{}
 | 
						client := &http.Client{}
 | 
				
			||||||
	return client.Do(req)
 | 
						return client.Do(req)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (caller *HTTPCaller) StoreResp(resp *http.Response) error {
 | 
				
			||||||
 | 
						caller.LastResults = make(map[string]interface{})
 | 
				
			||||||
 | 
						caller.LastResults["header"] = resp.Header
 | 
				
			||||||
 | 
						caller.LastResults["code"] = resp.StatusCode
 | 
				
			||||||
 | 
						data, err := io.ReadAll(resp.Body)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println("Error reading the body of the last request")
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						caller.LastResults["body"] = data
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user