neo local peer draft

This commit is contained in:
mr
2024-10-30 11:17:52 +01:00
parent 1a55212378
commit 4de43a301c
8 changed files with 23 additions and 49 deletions

View File

@@ -11,7 +11,6 @@ import (
"cloud.o-forge.io/core/oc-lib/models/utils"
w "cloud.o-forge.io/core/oc-lib/models/workflow"
"cloud.o-forge.io/core/oc-lib/models/workspace"
"cloud.o-forge.io/core/oc-lib/static"
"cloud.o-forge.io/core/oc-lib/tools"
)
@@ -155,7 +154,7 @@ func (wfa *collaborativeAreaMongoAccessor) deleteToPeer(shared *CollaborativeAre
}
paccess := (&peer.Peer{})
for _, v := range shared.Peers {
if (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf() {
if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf(); ok {
continue
}
b, err := paccess.LaunchPeerExecution(v, shared.UUID, tools.COLLABORATIVE_AREA, tools.DELETE, nil, wfa.Caller)
@@ -173,7 +172,7 @@ func (wfa *collaborativeAreaMongoAccessor) sendToPeer(shared *CollaborativeArea)
paccess := (&peer.Peer{})
for _, v := range shared.Peers {
if (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf() || shared.IsSent {
if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: v}}).IsMySelf(); ok || shared.IsSent {
continue
}
shared.IsSent = true
@@ -196,7 +195,7 @@ func (wfa *collaborativeAreaMongoAccessor) UpdateOne(set utils.DBObject, id stri
// StoreOne stores a collaborative area in the database, it automatically share to peers if the workspace is shared
func (wfa *collaborativeAreaMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
id, _ := static.GetMyLocalJsonPeer() // get the local peer
_, id := (&peer.Peer{}).IsMySelf() // get the local peer
data.(*CollaborativeArea).CreatorID = id // set the creator id
data.(*CollaborativeArea).Peers = append(data.(*CollaborativeArea).Peers, id) // add the creator id to the peers
// then reset the shared fields

View File

@@ -5,7 +5,6 @@ import (
"fmt"
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/static"
"cloud.o-forge.io/core/oc-lib/tools"
"github.com/google/uuid"
)
@@ -21,6 +20,14 @@ const (
BLACKLIST
)
func (m PeerState) String() string {
return [...]string{"NONE", "SELF", "PARTNER", "BLACKLIST"}[m]
}
func (m PeerState) EnumIndex() int {
return int(m)
}
// Peer is a struct that represents a peer
type Peer struct {
utils.AbstractObject
@@ -57,9 +64,13 @@ func (ao *Peer) RemoveExecution(exec PeerExecution) {
}
// IsMySelf checks if the peer is the local peer
func (ao *Peer) IsMySelf() bool {
id, _ := static.GetMyLocalJsonPeer()
return ao.UUID == id
func (ao *Peer) IsMySelf() (bool, string) {
d, code, err := ao.GetAccessor(nil).Search(nil, SELF.String())
if code != 200 || err != nil || len(d) == 0 {
return false, ""
}
id := d[0].GetID()
return ao.UUID == id, id
}
// LaunchPeerExecution launches an execution on a peer

View File

@@ -1,6 +1,7 @@
package peer
import (
"fmt"
"strconv"
"cloud.o-forge.io/core/oc-lib/dbs"
@@ -70,6 +71,7 @@ func (wfa *peerMongoAccessor) Search(filters *dbs.Filters, search string) ([]uti
objs := []utils.ShallowDBObject{}
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
s, err := strconv.Atoi(search)
fmt.Println(s, err, search)
if err == nil {
filters = &dbs.Filters{
Or: map[string][]dbs.Filter{ // search by name if no filters are provided

View File

@@ -8,7 +8,6 @@ import (
"cloud.o-forge.io/core/oc-lib/dbs"
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
"cloud.o-forge.io/core/oc-lib/logs"
"cloud.o-forge.io/core/oc-lib/static"
"cloud.o-forge.io/core/oc-lib/tools"
"github.com/go-playground/validator/v10"
"github.com/google/uuid"
@@ -42,7 +41,7 @@ func (ao *AbstractObject) GetName() string {
func (ao *AbstractObject) UpToDate() {
ao.UpdateDate = time.Now()
ao.LastPeerWriter, _ = static.GetMyLocalJsonPeer()
// ao.LastPeerWriter, _ = static.GetMyLocalJsonPeer()
}
// GetAccessor returns the accessor of the object (abstract)

View File

@@ -171,7 +171,7 @@ func (wfa *workflowMongoAccessor) share(realData *Workflow, delete bool, caller
paccess := &peer.Peer{}
for _, p := range res.(*shallow_collaborative_area.ShallowCollaborativeArea).Peers {
paccess.UUID = p
if paccess.IsMySelf() { // if the peer is the current peer, never share because it will create a loop
if ok, _ := paccess.IsMySelf(); ok { // if the peer is the current peer, never share because it will create a loop
continue
}
if delete { // if the workflow is deleted, share the deletion

View File

@@ -217,7 +217,7 @@ func (wfa *workspaceMongoAccessor) share(realData *Workspace, method tools.METHO
paccess := &peer.Peer{}
for _, p := range res.(*shallow_collaborative_area.ShallowCollaborativeArea).Peers {
paccess.UUID = p
if paccess.IsMySelf() { // If the peer is the current peer, never share because it will create a loop
if ok, _ := paccess.IsMySelf(); ok { // If the peer is the current peer, never share because it will create a loop
continue
}
if method == tools.DELETE { // If the workspace is deleted, share the deletion