forked from p15670423/monkey
parent
174392848f
commit
28f60d51ff
|
@ -1,6 +1,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
import threading
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
|
@ -10,6 +11,8 @@ from monkey_island.cc.models.edge import Edge
|
||||||
|
|
||||||
RIGHT_ARROW = "\u2192"
|
RIGHT_ARROW = "\u2192"
|
||||||
|
|
||||||
|
lock = threading.Lock()
|
||||||
|
|
||||||
|
|
||||||
class EdgeService(Edge):
|
class EdgeService(Edge):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -18,16 +21,17 @@ class EdgeService(Edge):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_or_create_edge(src_node_id, dst_node_id, src_label, dst_label) -> EdgeService:
|
def get_or_create_edge(src_node_id, dst_node_id, src_label, dst_label) -> EdgeService:
|
||||||
edge = None
|
with lock:
|
||||||
try:
|
edge = None
|
||||||
edge = EdgeService.objects.get(src_node_id=src_node_id, dst_node_id=dst_node_id)
|
try:
|
||||||
except DoesNotExist:
|
edge = EdgeService.objects.get(src_node_id=src_node_id, dst_node_id=dst_node_id)
|
||||||
edge = EdgeService(src_node_id=src_node_id, dst_node_id=dst_node_id)
|
except DoesNotExist:
|
||||||
finally:
|
edge = EdgeService(src_node_id=src_node_id, dst_node_id=dst_node_id)
|
||||||
if edge:
|
finally:
|
||||||
edge.update_label(node_id=src_node_id, label=src_label)
|
if edge:
|
||||||
edge.update_label(node_id=dst_node_id, label=dst_label)
|
edge.update_label(node_id=src_node_id, label=src_label)
|
||||||
return edge
|
edge.update_label(node_id=dst_node_id, label=dst_label)
|
||||||
|
return edge
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_by_dst_node(dst_node_id: ObjectId) -> List[EdgeService]:
|
def get_by_dst_node(dst_node_id: ObjectId) -> List[EdgeService]:
|
||||||
|
|
Loading…
Reference in New Issue