forked from p15670423/monkey
Island: Make upsert_node method public
Updating/inserting the node into the repository is required outside of repository itself.
This commit is contained in:
parent
73a8c14397
commit
bbcdc1bef4
|
@ -25,6 +25,14 @@ class INodeRepository(ABC):
|
|||
:raises StorageError: If an error occurs while attempting to upsert the Node
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def upsert_node(self, node: Node):
|
||||
"""
|
||||
Store the Node object in the repository by creating a new one or updating an existing one.
|
||||
:param node: Node that will be saved
|
||||
:raises StorageError: If an error occurs while attempting to upsert the Node
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def get_nodes(self) -> Sequence[Node]:
|
||||
"""
|
||||
|
|
|
@ -34,7 +34,7 @@ class MongoNodeRepository(INodeRepository):
|
|||
node, dst, communication_type
|
||||
)
|
||||
|
||||
self._upsert_node(updated_node)
|
||||
self.upsert_node(updated_node)
|
||||
|
||||
@staticmethod
|
||||
def _add_connection_to_node(
|
||||
|
@ -50,7 +50,7 @@ class MongoNodeRepository(INodeRepository):
|
|||
|
||||
return new_node
|
||||
|
||||
def _upsert_node(self, node: Node):
|
||||
def upsert_node(self, node: Node):
|
||||
try:
|
||||
result = self._nodes_collection.replace_one(
|
||||
{SRC_FIELD_NAME: node.machine_id}, node.dict(simplify=True), upsert=True
|
||||
|
|
Loading…
Reference in New Issue