diff --git a/src/context/client/ContextClient.py b/src/context/client/ContextClient.py index 47d93c8536176fcbe4ee9fa91cb9d06c30c7ed88..35f9121b33f60034340cbe2492e1bd26a622f6e7 100644 --- a/src/context/client/ContextClient.py +++ b/src/context/client/ContextClient.py @@ -24,10 +24,10 @@ from common.proto.context_pb2 import ( Device, DeviceEvent, DeviceFilter, DeviceId, DeviceIdList, DeviceList, Empty, EndPointIdList, EndPointNameList, Link, LinkEvent, LinkId, LinkIdList, LinkList, - Service, ServiceEvent, ServiceFilter, ServiceId, ServiceIdList, ServiceList, + OpticalConfig, OpticalConfigId, OpticalConfigList , OpticalLink, OpticalLinkList, + Service, ServiceConfigRule, ServiceEvent, ServiceFilter, ServiceId, ServiceIdList, ServiceList, Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList, - OpticalConfig, OpticalConfigId, OpticalConfigList , OpticalLink ,OpticalLinkList,ServiceConfigRule ) from common.proto.context_pb2_grpc import ContextServiceStub from common.proto.context_policy_pb2_grpc import ContextPolicyServiceStub diff --git a/src/context/service/database/models/OpticalConfig/OpticalConfigModel.py b/src/context/service/database/models/OpticalConfig/OpticalConfigModel.py index f93fc819b68d9fba219f3099aa6825247798e696..fa77898337055c88edc120aa53e517ffcd6ed2b1 100644 --- a/src/context/service/database/models/OpticalConfig/OpticalConfigModel.py +++ b/src/context/service/database/models/OpticalConfig/OpticalConfigModel.py @@ -12,12 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json , logging -from sqlalchemy import Column, String, Integer , ForeignKey, Boolean +import json +from sqlalchemy import Column, String, ForeignKey from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.orm import relationship from context.service.database.models._Base import _Base -from .RoadmModel import RoadmTypeModel class OpticalConfigModel(_Base): __tablename__ = 'optical_config' @@ -25,21 +24,16 @@ class OpticalConfigModel(_Base): channel_namespace = Column(String, nullable=True) endpoints = Column(ARRAY(String), nullable=True) type = Column(String,nullable=False) - - # transcievers = Column(ARRAY(String), nullable=True) - # interfaces = Column(String, nullable=True) - - - #channels = relationship("OpticalChannelModel") + + # transcievers = Column(ARRAY(String), nullable=True) + # interfaces = Column(String, nullable=True) + # channels = relationship("OpticalChannelModel") transponders = relationship("TransponderTypeModel") roadms = relationship("RoadmTypeModel") - - + device_uuid = Column(ForeignKey("device.device_uuid",ondelete="CASCADE"),index=True ,nullable=False) - device= relationship("DeviceModel", back_populates='optical_config') - + device = relationship("DeviceModel", back_populates='optical_config') - def dump_id (self ): return { "opticalconfig_uuid":self.opticalconfig_uuid, @@ -67,8 +61,4 @@ class OpticalConfigModel(_Base): channels=[roadms.dump() for roadms in self.roadms ][0] obj['channels']=channels['channels'] if 'channels' in channels else None obj['roadm_uuid']=channels['roadm_uuid'] if 'roadm_uuid' in channels else None - - - return obj - diff --git a/src/context/service/database/models/OpticalConfig/RoadmModel.py b/src/context/service/database/models/OpticalConfig/RoadmModel.py index 187a55710d271337255d59f594a7c990fa432513..31ebf4cfabb2b91252b3c80884d47b93d07db033 100644 --- a/src/context/service/database/models/OpticalConfig/RoadmModel.py +++ b/src/context/service/database/models/OpticalConfig/RoadmModel.py @@ -1,4 +1,3 @@ - # Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,71 +12,63 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json , logging -from sqlalchemy import Column, String, Integer , ForeignKey, Boolean -from sqlalchemy.dialects.postgresql import ARRAY +from sqlalchemy import Column, String, Integer , ForeignKey from sqlalchemy.orm import relationship from context.service.database.models._Base import _Base - - - class RoadmTypeModel (_Base): - - __tablename__ = 'roadm_type' - roadm_uuid = Column(String, primary_key=True) + __tablename__ = 'roadm_type' + roadm_uuid = Column(String, primary_key=True) + circuits = Column(String, nullable=True) + opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE'), index=True, nullable=False) + channels = relationship("ChannelModel") + opticalconfig = relationship('OpticalConfigModel', back_populates='roadms') - channels = relationship("ChannelModel") - circuits = Column (String,nullable=True) - - opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE' ),index=True ,nullable=False) - opticalconfig = relationship('OpticalConfigModel', back_populates='roadms') - def dump_id (self): return { - "roadm_uuid":self.roadm_uuid + "roadm_uuid" : self.roadm_uuid } - + def dump (self): return { - "channels" : [channel.dump() for channel in self.channels], - "roadm_uuid" : self.dump_id() + "channels" : [channel.dump() for channel in self.channels], + "roadm_uuid" : self.dump_id(), } class ChannelModel(_Base): - __tablename__ = 'channel' - channel_uuid = Column(String, primary_key=True) - band_name = Column (String,nullable=True) - lower_frequency = Column(Integer, nullable=True) - upper_frequency = Column(Integer, nullable=True) - channel_index = Column(String , nullable=True) - status = Column(String , nullable=True) - src_port = Column(String, nullable=True) - dest_port = Column(String, nullable=True) - - type = Column(String, nullable=False) - optical_band_parent = Column(String, nullable=True) - - roadm_uuid = Column(ForeignKey('roadm_type.roadm_uuid', ondelete='CASCADE' ),nullable=False) - roadm = relationship('RoadmTypeModel',back_populates='channels') - # opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE' ), primary_key=True) - # opticalconfig = relationship('OpticalConfigModel', back_populates='channels') + __tablename__ = 'channel' + + channel_uuid = Column(String, primary_key=True) + band_name = Column(String, nullable=True) + lower_frequency = Column(Integer, nullable=True) + upper_frequency = Column(Integer, nullable=True) + channel_index = Column(String, nullable=True) + status = Column(String, nullable=True) + src_port = Column(String, nullable=True) + dest_port = Column(String, nullable=True) + type = Column(String, nullable=False) + optical_band_parent = Column(String, nullable=True) + roadm_uuid = Column(ForeignKey('roadm_type.roadm_uuid', ondelete='CASCADE'), nullable=False) + + roadm = relationship('RoadmTypeModel',back_populates='channels') + + # opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE'), primary_key=True) + # opticalconfig = relationship('OpticalConfigModel', back_populates='channels') + def dump_id (self ): return { - "channel_uuid":self.channel_uuid + "channel_uuid": self.channel_uuid } def dump(self): return { - "band_name" :self.band_name, - "lower_frequency" : self.lower_frequency, - "upper_frequency" : self.upper_frequency, - "type" : self.type, - "src_port" : self.src_port, - "dest_port" : self.dest_port, - - "status":self.status, - "optical_band_parent":self.optical_band_parent, - "channel_index":self.channel_index + "band_name" : self.band_name, + "lower_frequency" : self.lower_frequency, + "upper_frequency" : self.upper_frequency, + "type" : self.type, + "src_port" : self.src_port, + "dest_port" : self.dest_port, + "status" : self.status, + "optical_band_parent" : self.optical_band_parent, + "channel_index" : self.channel_index, } - diff --git a/src/context/service/database/models/OpticalConfig/TransponderModel.py b/src/context/service/database/models/OpticalConfig/TransponderModel.py index bd3e3d8050b580c918a51000f885440b02b087ca..33e509d354b257d380d61c9795e86fdce7a68348 100644 --- a/src/context/service/database/models/OpticalConfig/TransponderModel.py +++ b/src/context/service/database/models/OpticalConfig/TransponderModel.py @@ -1,4 +1,3 @@ - # Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/) # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,66 +12,61 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json , logging -from sqlalchemy import Column, String, Integer , ForeignKey, Boolean +import json +from sqlalchemy import Column, String, Integer , ForeignKey from sqlalchemy.dialects.postgresql import ARRAY from sqlalchemy.orm import relationship from context.service.database.models._Base import _Base +class TransponderTypeModel (_Base): + __tablename__ = 'transponder_type' + transponder_uuid = Column(String, primary_key=True) + transcievers = Column(ARRAY(String), nullable=True) + interfaces = Column(String, nullable=True) + opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE'), index=True, nullable=False) + channels = relationship("OpticalChannelModel") + opticalconfig = relationship('OpticalConfigModel', back_populates='transponders') - -class TransponderTypeModel (_Base): - - __tablename__ = 'transponder_type' - transponder_uuid = Column(String, primary_key=True) - - transcievers = Column(ARRAY(String), nullable=True) - interfaces = Column(String, nullable=True) - channels = relationship("OpticalChannelModel") - - opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE' ),index=True ,nullable=False) - opticalconfig = relationship('OpticalConfigModel', back_populates='transponders') - def dump_id (self): return { - "transponder_uuid":self.transponder_uuid + "transponder_uuid": self.transponder_uuid } - + def dump (self): return { - "channels" : [channel.dump() for channel in self.channels], - "transceivers" : {"transceiver": [transciever for transciever in self.transcievers]}, - "interfaces" : {"interface":json.loads(self.interfaces) if self.interfaces else ''}, - "trasponder_uuid" : self.dump_id() + "channels" : [channel.dump() for channel in self.channels], + "transceivers" : {"transceiver": [transciever for transciever in self.transcievers]}, + "interfaces" : {"interface":json.loads(self.interfaces) if self.interfaces else ''}, + "trasponder_uuid" : self.dump_id() } class OpticalChannelModel(_Base): - __tablename__ = 'optical_channel' - channel_uuid = Column(String, primary_key=True) - - channel_name = Column (String,nullable=True) - frequency = Column(Integer, nullable=True) - operational_mode = Column(Integer, nullable=True) - status = Column(String , nullable=True) - target_output_power = Column(String, nullable=True) - - transponder_uuid = Column(ForeignKey('transponder_type.transponder_uuid', ondelete='CASCADE' ),nullable=False) - transponder = relationship('TransponderTypeModel',back_populates='channels') - # opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE' ), primary_key=True) - # opticalconfig = relationship('OpticalConfigModel', back_populates='channels') + __tablename__ = 'optical_channel' + + channel_uuid = Column(String, primary_key=True) + channel_name = Column(String, nullable=True) + frequency = Column(Integer, nullable=True) + operational_mode = Column(Integer, nullable=True) + status = Column(String, nullable=True) + target_output_power = Column(String, nullable=True) + transponder_uuid = Column(ForeignKey('transponder_type.transponder_uuid', ondelete='CASCADE'), nullable=False) + transponder = relationship('TransponderTypeModel', back_populates='channels') + + # opticalconfig_uuid = Column(ForeignKey('optical_config.opticalconfig_uuid', ondelete='CASCADE'), primary_key=True) + # opticalconfig = relationship('OpticalConfigModel', back_populates='channels') + def dump_id (self ): return { - "channel_uuid":self.channel_uuid + "channel_uuid": self.channel_uuid } def dump(self): return { - "name" :{'index':self.channel_name}, - "frequency" : self.frequency, - "target-output-power" : self.target_output_power, - "operational-mode" : self.operational_mode, - "status":self.status + "name" : {'index':self.channel_name}, + "frequency" : self.frequency, + "target-output-power" : self.target_output_power, + "operational-mode" : self.operational_mode, + "status" : self.status, } - diff --git a/src/context/service/database/models/OpticalLinkModel.py b/src/context/service/database/models/OpticalLinkModel.py index 272c5adff188943c1bc3b8f4e5b62db1fc13e436..6db1b316160aeb3f01d6d70b74338ba67d9b528a 100644 --- a/src/context/service/database/models/OpticalLinkModel.py +++ b/src/context/service/database/models/OpticalLinkModel.py @@ -13,20 +13,12 @@ # limitations under the License. - - -import operator -from sqlalchemy import CheckConstraint, Column, DateTime, Float, ForeignKey, Integer, String ,Boolean +from sqlalchemy import Column, DateTime, ForeignKey, Integer, String ,Boolean from sqlalchemy.dialects.postgresql import UUID -from sqlalchemy.types import PickleType , TypeDecorator ,Integer from sqlalchemy.orm import relationship -import json,logging from typing import Dict from ._Base import _Base from .Slot import C_Slot ,S_Slot , L_Slot -from common.tools.object_factory.OpticalLink import order_dict - - class OpticalLinkModel(_Base): __tablename__ = 'opticallink' @@ -44,52 +36,39 @@ class OpticalLinkModel(_Base): c_slots = Column (C_Slot,nullable=True) l_slots = Column (L_Slot,nullable=True) s_slots = Column (S_Slot,nullable=True) - opticallink_endpoints = relationship("OpticalLinkEndPointModel") + opticallink_endpoints = relationship('OpticalLinkEndPointModel') topology_optical_links = relationship('TopologyOpticalLinkModel', back_populates='optical_link') - - - - def dump_id(self) -> Dict: return {'link_uuid': {'uuid': self.opticallink_uuid}} def dump(self) -> Dict: - result = { - 'link_id' : self.dump_id(), 'name' : self.name, - 'optical_details' :{ - - 'length' : self.length, - "src_port" : self.src_port, - "dst_port" : self.dst_port, - "local_peer_port" : self.local_peer_port, - "remote_peer_port" : self.remote_peer_port, - "used" : self.used, - "c_slots" : order_dict(self.c_slots) if self.c_slots is not None else {} , - "l_slots" : order_dict(self.l_slots) if self.l_slots is not None else {}, - "s_slots" : order_dict(self.s_slots) if self.s_slots is not None else {} - }, - "link_endpoint_ids" : [optical_endpoint.endpoint.dump_id() for optical_endpoint in self.opticallink_endpoints] - + 'optical_details' : { + 'length' : self.length, + 'src_port' : self.src_port, + 'dst_port' : self.dst_port, + 'local_peer_port' : self.local_peer_port, + 'remote_peer_port' : self.remote_peer_port, + 'used' : self.used, + 'c_slots' : self.c_slots if self.c_slots is not None else {}, + 'l_slots' : self.l_slots if self.l_slots is not None else {}, + 's_slots' : self.s_slots if self.s_slots is not None else {}, + }, + 'link_endpoint_ids' : [ + optical_endpoint.endpoint.dump_id() + for optical_endpoint in self.opticallink_endpoints + ], } - return result - - - class OpticalLinkEndPointModel(_Base): __tablename__ = 'opticallink_endpoint' - link_uuid = Column(ForeignKey('opticallink.opticallink_uuid', ondelete='CASCADE' ), primary_key=True) - endpoint_uuid = Column(ForeignKey('endpoint.endpoint_uuid', ondelete='RESTRICT'), primary_key=True, index=True) - - - optical_link = relationship('OpticalLinkModel', back_populates='opticallink_endpoints') - endpoint = relationship('EndPointModel', lazy='selectin') - - + link_uuid = Column(ForeignKey('opticallink.opticallink_uuid', ondelete='CASCADE' ), primary_key=True) + endpoint_uuid = Column(ForeignKey('endpoint.endpoint_uuid', ondelete='RESTRICT'), primary_key=True, index=True) + optical_link = relationship('OpticalLinkModel', back_populates='opticallink_endpoints') + endpoint = relationship('EndPointModel', lazy='selectin')