Skip to content
Snippets Groups Projects
Commit 6ee25c26 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Context component:

- Corrected lazy mode of link relationships
- Corrected TopologyModel dump_detailed method to avoid retrieving config rules and components
- Added missing selectinload options in Topology
parent f56b9295
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!81Context Performance Scalability
...@@ -22,7 +22,9 @@ from common.proto.context_pb2 import ContextId, Topology, TopologyId ...@@ -22,7 +22,9 @@ from common.proto.context_pb2 import ContextId, Topology, TopologyId
from common.method_wrappers.ServiceExceptions import NotFoundException from common.method_wrappers.ServiceExceptions import NotFoundException
from common.tools.object_factory.Context import json_context_id from common.tools.object_factory.Context import json_context_id
from common.tools.object_factory.Topology import json_topology_id from common.tools.object_factory.Topology import json_topology_id
from .models.TopologyModel import TopologyModel from .models.DeviceModel import DeviceModel
from .models.LinkModel import LinkModel
from .models.TopologyModel import TopologyDeviceModel, TopologyLinkModel, TopologyModel
from .uuids.Context import context_get_uuid from .uuids.Context import context_get_uuid
from .uuids.Topology import topology_get_uuid from .uuids.Topology import topology_get_uuid
...@@ -67,9 +69,10 @@ def topology_get_details(db_engine : Engine, request : TopologyId) -> Dict: ...@@ -67,9 +69,10 @@ def topology_get_details(db_engine : Engine, request : TopologyId) -> Dict:
_,topology_uuid = topology_get_uuid(request, allow_random=False) _,topology_uuid = topology_get_uuid(request, allow_random=False)
def callback(session : Session) -> Optional[Dict]: def callback(session : Session) -> Optional[Dict]:
obj : Optional[TopologyModel] = session.query(TopologyModel)\ obj : Optional[TopologyModel] = session.query(TopologyModel)\
.options(selectinload(TopologyModel.topology_devices))\ .options(selectinload(TopologyModel.topology_devices, TopologyDeviceModel.device, DeviceModel.endpoints))\
.options(selectinload(TopologyModel.topology_links))\ .options(selectinload(TopologyModel.topology_links, TopologyLinkModel.link, LinkModel.link_endpoints))\
.filter_by(topology_uuid=topology_uuid).one_or_none() .filter_by(topology_uuid=topology_uuid).one_or_none()
#.options(selectinload(DeviceModel.components))\
return None if obj is None else obj.dump_details() return None if obj is None else obj.dump_details()
obj = run_transaction(sessionmaker(bind=db_engine), callback) obj = run_transaction(sessionmaker(bind=db_engine), callback)
if obj is None: if obj is None:
......
...@@ -50,8 +50,8 @@ class LinkEndPointModel(_Base): ...@@ -50,8 +50,8 @@ class LinkEndPointModel(_Base):
endpoint_uuid = Column(ForeignKey('endpoint.endpoint_uuid', ondelete='RESTRICT'), primary_key=True, index=True) endpoint_uuid = Column(ForeignKey('endpoint.endpoint_uuid', ondelete='RESTRICT'), primary_key=True, index=True)
position = Column(Integer, nullable=False) position = Column(Integer, nullable=False)
link = relationship('LinkModel', back_populates='link_endpoints', lazy='joined') link = relationship('LinkModel', back_populates='link_endpoints') #, lazy='selectin'
endpoint = relationship('EndPointModel', lazy='joined') # back_populates='link_endpoints' endpoint = relationship('EndPointModel', lazy='selectin') # back_populates='link_endpoints'
__table_args__ = ( __table_args__ = (
CheckConstraint(position >= 0, name='check_position_value'), CheckConstraint(position >= 0, name='check_position_value'),
......
...@@ -46,11 +46,19 @@ class TopologyModel(_Base): ...@@ -46,11 +46,19 @@ class TopologyModel(_Base):
} }
def dump_details(self) -> Dict: def dump_details(self) -> Dict:
devices = [
td.device.dump(include_config_rules=False, include_components=False)
for td in self.topology_devices
]
links = [
tl.link.dump()
for tl in self.topology_links
]
return { return {
'topology_id': self.dump_id(), 'topology_id': self.dump_id(),
'name' : self.topology_name, 'name' : self.topology_name,
'devices' : [td.device.dump() for td in self.topology_devices], 'devices' : devices,
'links' : [tl.link.dump() for tl in self.topology_links ], 'links' : links,
} }
class TopologyDeviceModel(_Base): class TopologyDeviceModel(_Base):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment