Loading proto/context.proto +25 −0 Original line number Diff line number Diff line Loading @@ -93,6 +93,9 @@ service ContextService { rpc GetOpticalBand (Empty ) returns (OpticalBandList) {} rpc SelectOpticalBand (OpticalBandId ) returns (OpticalBand) {} rpc ListChildTopology (Empty ) returns (ChildTopologyList) {} rpc GetChildTopology (TopologyId ) returns (ChildTopology) {} rpc SetChildTopology (ChildTopology ) returns (TopologyId) {} rpc DeleteServiceConfigRule(ServiceConfigRule) returns (Empty ) {} } Loading Loading @@ -762,6 +765,28 @@ message OpticalBandList { } message ChildEndpoint { EndPointId endpoint_id =1 ; DeviceId device_id = 2 ; string endpoint_name = 3; string device_name =4 ; } message ChildTopology { TopologyId topology_id = 2 ; string host = 3; int32 port = 4 ; repeated ChildEndpoint endpoints =5; } message ChildTopologyList { repeated ChildTopology topology_list = 1 ; } ////////////////// Config Rule Delete //////////// message ServiceConfigRule { Loading proto/tapi.proto +0 −20 Original line number Diff line number Diff line Loading @@ -41,23 +41,3 @@ message CheckStat { int32 res = 1 ; } message ChildEndpoint { context.EndPointId endpoint_id =1 ; context.DeviceId device_id = 2 ; string endpoint_name = 3; string device_name =4 ; } message ChildTopology { context.TopologyId topology_id = 2 ; string host = 3; int32 port = 4 ; repeated ChildEndpoint endpoints =5; } message ListChildTopology { repeated ChildTopology topology_list = 1 ; } src/context/client/ContextClient.py +3 −3 Original line number Diff line number Diff line Loading @@ -28,12 +28,12 @@ from common.proto.context_pb2 import ( Service, ServiceConfigRule, ServiceEvent, ServiceFilter, ServiceId, ServiceIdList, ServiceList, Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList,OpticalBand ,OpticalBandId, OpticalBandList OpticalBandList , ChildTopologyList , ChildTopology , ChildEndpoint ) from common.proto.context_pb2_grpc import ContextServiceStub from common.proto.context_policy_pb2_grpc import ContextPolicyServiceStub from common.proto.policy_pb2 import PolicyRuleIdList, PolicyRuleId, PolicyRuleList, PolicyRule from common.proto.tapi_pb2 import ChildTopology , ChildEndpoint ,ListChildTopology LOGGER = logging.getLogger(__name__) MAX_RETRIES = 15 Loading Loading @@ -551,7 +551,7 @@ class ContextClient: return response @RETRY_DECORATOR def ListChildTopology(self, request: Empty) -> ListChildTopology: def ListChildTopology(self, request: Empty) -> ChildTopologyList: LOGGER.debug('GetChildTopology request: {:s}'.format(grpc_message_to_json_string(request))) response = self.stub.GetChildTopology(request) LOGGER.debug('GetChildTopology result: {:s}'.format(grpc_message_to_json_string(response))) Loading src/context/service/ContextServiceServicerImpl.py +6 −5 Original line number Diff line number Diff line Loading @@ -25,12 +25,12 @@ from common.proto.context_pb2 import ( Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList, OpticalConfigList, OpticalConfigId, OpticalConfig, OpticalLink, OpticalLinkList, ServiceConfigRule,OpticalBand,OpticalBandId,OpticalBandList ServiceConfigRule,OpticalBand,OpticalBandId,OpticalBandList , ChildTopologyList , ChildTopology , ChildEndpoint ) from common.proto.policy_pb2 import PolicyRuleIdList, PolicyRuleId, PolicyRuleList, PolicyRule from common.proto.context_pb2_grpc import ContextServiceServicer from common.proto.context_policy_pb2_grpc import ContextPolicyServiceServicer from common.proto.tapi_pb2 import ChildTopology , ChildEndpoint , ListChildTopology from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method from .database.Connection import ( connection_delete, connection_get, connection_list_ids, connection_list_objs, connection_set Loading Loading @@ -329,7 +329,7 @@ class ContextServiceServicerImpl(ContextServiceServicer, ContextPolicyServiceSer def RemovePolicyRule(self, request : PolicyRuleId, context: grpc.ServicerContext) -> Empty: return policyrule_delete(self.db_engine, self.messagebroker, request) # ---------------------------- Experimental ------------------- # ---------------------------- Optical Configuration ------------------- @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) def GetOpticalConfig(self, request : Empty, context : grpc.ServicerContext) -> OpticalConfigList: Loading Loading @@ -409,9 +409,10 @@ class ContextServiceServicerImpl(ContextServiceServicer, ContextPolicyServiceSer return get_child_topology(self.db_engine, request) @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) def ListChildTopology(self, request : Empty, context : grpc.ServicerContext) -> ListChildTopology: def ListChildTopology(self, request : Empty, context : grpc.ServicerContext) -> ChildTopologyList: return get_children_topology(self.db_engine, request) @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) def SetChildTopology(self, request : ChildTopology, context : grpc.ServicerContext) -> TopologyId: return set_child_topology(self.db_engine, request) No newline at end of file topo_id= set_child_topology(self.db_engine, request) return TopologyId(topology_uuid=topo_id) No newline at end of file src/context/service/database/Tapi.py +17 −14 Original line number Diff line number Diff line Loading @@ -20,9 +20,9 @@ from sqlalchemy import inspect from sqlalchemy.engine import Engine from sqlalchemy.orm import Session, sessionmaker from sqlalchemy_cockroachdb import run_transaction from common.proto.context_pb2 import OpticalConfig, OpticalConfigId, Empty, EventTypeEnum from common.proto.tapi_pb2 import ChildTopology , ChildEndpoint from .models.TapiModel import ChildTopology ,ChildEndpoints from common.proto.context_pb2 import OpticalConfig, OpticalConfigId, Empty, EventTypeEnum ,ChildTopology , ChildEndpoint from .models.TapiModel import ChildTopologyModel ,ChildEndpointsModel from context.service.database.uuids.EndPoint import endpoint_get_uuid from context.service.database.uuids.Device import device_get_uuid from context.service.database.uuids.Topology import topology_get_uuid Loading @@ -35,7 +35,7 @@ now = datetime.datetime.utcnow() def get_children_topology(db_engine : Engine): def callback(session:Session): results = session.query(ChildTopology).all() results = session.query(ChildTopologyModel).all() return [r.dump() for r in results] obj = run_transaction(sessionmaker(bind=db_engine), callback) Loading @@ -45,7 +45,7 @@ def get_child_topology(db_engine : Engine , request:ChildTopology ): _topology_uuid = request.topology_id.topology_uuid.uuid def callback(session:Session): result = session.query(ChildEndpoints).filter_by(topology_uuid=_topology_uuid).one_or_none() result = session.query(ChildEndpointsModel).filter_by(topology_uuid=_topology_uuid).one_or_none() return result.dump() if result else {} obj = run_transaction(sessionmaker(bind=db_engine), callback) Loading @@ -62,6 +62,8 @@ def set_child_topology(db_engine : Engine, request : ChildTopology): #is_transpondre = False now = datetime.datetime.now(datetime.timezone.utc) _,topo_uuid= topology_get_uuid(request.topology_id) for endpoint in request.endpoints: endpoints_list.append({ 'endpoint_uuid':endpoint.endpoint_id.endpoint_uuid.uuid, Loading @@ -70,32 +72,33 @@ def set_child_topology(db_engine : Engine, request : ChildTopology): 'device_name':endpoint.device_name, 'updated_at':now , 'created_at':now, 'topology_uuid':topology_get_uuid(request.topology_id) 'topology_uuid':topo_uuid }) topology = { 'topology_uuid':topology_get_uuid(request.topology_id), 'topology_uuid':topo_uuid, 'host':request.host, 'port':request.port } def callback(session:Session)->bool: stmt = insert(ChildTopology).values([topology]) stmt = insert(ChildTopologyModel).values(topology) stmt = stmt.on_conflict_do_update( index_elements=[ChildTopology.topology_uuid], index_elements=[ChildTopologyModel.topology_uuid], set_=dict( host = stmt.excluded.host, port= stmt.excluded.port, ) ) stmt = stmt.returning(ChildTopology.topology_uuid) stmt = stmt.returning(ChildTopologyModel.topology_uuid) topology_uuid = session.execute(stmt).fetchone() if topology_uuid and len(endpoints_list) > 0: en_list=[] for en in endpoints_list : stmt = insert(ChildEndpoint).values(**en) stmt = insert(ChildEndpointsModel).values(**en) update_stmt = stmt.on_conflict_do_update( index_elements=[ChildEndpoint.endpoint_uuid], index_elements=[ChildEndpointsModel.endpoint_uuid], set_=dict( endpoint_name = stmt.excluded.endpoint_name, device_name = stmt.excluded.device_name, Loading @@ -103,9 +106,9 @@ def set_child_topology(db_engine : Engine, request : ChildTopology): updated_at = stmt.excluded.updated_at, ) ).returning(ChildEndpoint.endpoint_uuid) ).returning(ChildEndpointsModel.endpoint_uuid) result = session.execute(update_stmt).fetchone() en_list.append(result) topology_uuid = run_transaction(sessionmaker(bind=db_engine), callback) return {'topology_uuid':{'uuid': topology_uuid}} No newline at end of file return {'uuid': topology_uuid} No newline at end of file Loading
proto/context.proto +25 −0 Original line number Diff line number Diff line Loading @@ -93,6 +93,9 @@ service ContextService { rpc GetOpticalBand (Empty ) returns (OpticalBandList) {} rpc SelectOpticalBand (OpticalBandId ) returns (OpticalBand) {} rpc ListChildTopology (Empty ) returns (ChildTopologyList) {} rpc GetChildTopology (TopologyId ) returns (ChildTopology) {} rpc SetChildTopology (ChildTopology ) returns (TopologyId) {} rpc DeleteServiceConfigRule(ServiceConfigRule) returns (Empty ) {} } Loading Loading @@ -762,6 +765,28 @@ message OpticalBandList { } message ChildEndpoint { EndPointId endpoint_id =1 ; DeviceId device_id = 2 ; string endpoint_name = 3; string device_name =4 ; } message ChildTopology { TopologyId topology_id = 2 ; string host = 3; int32 port = 4 ; repeated ChildEndpoint endpoints =5; } message ChildTopologyList { repeated ChildTopology topology_list = 1 ; } ////////////////// Config Rule Delete //////////// message ServiceConfigRule { Loading
proto/tapi.proto +0 −20 Original line number Diff line number Diff line Loading @@ -41,23 +41,3 @@ message CheckStat { int32 res = 1 ; } message ChildEndpoint { context.EndPointId endpoint_id =1 ; context.DeviceId device_id = 2 ; string endpoint_name = 3; string device_name =4 ; } message ChildTopology { context.TopologyId topology_id = 2 ; string host = 3; int32 port = 4 ; repeated ChildEndpoint endpoints =5; } message ListChildTopology { repeated ChildTopology topology_list = 1 ; }
src/context/client/ContextClient.py +3 −3 Original line number Diff line number Diff line Loading @@ -28,12 +28,12 @@ from common.proto.context_pb2 import ( Service, ServiceConfigRule, ServiceEvent, ServiceFilter, ServiceId, ServiceIdList, ServiceList, Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList,OpticalBand ,OpticalBandId, OpticalBandList OpticalBandList , ChildTopologyList , ChildTopology , ChildEndpoint ) from common.proto.context_pb2_grpc import ContextServiceStub from common.proto.context_policy_pb2_grpc import ContextPolicyServiceStub from common.proto.policy_pb2 import PolicyRuleIdList, PolicyRuleId, PolicyRuleList, PolicyRule from common.proto.tapi_pb2 import ChildTopology , ChildEndpoint ,ListChildTopology LOGGER = logging.getLogger(__name__) MAX_RETRIES = 15 Loading Loading @@ -551,7 +551,7 @@ class ContextClient: return response @RETRY_DECORATOR def ListChildTopology(self, request: Empty) -> ListChildTopology: def ListChildTopology(self, request: Empty) -> ChildTopologyList: LOGGER.debug('GetChildTopology request: {:s}'.format(grpc_message_to_json_string(request))) response = self.stub.GetChildTopology(request) LOGGER.debug('GetChildTopology result: {:s}'.format(grpc_message_to_json_string(response))) Loading
src/context/service/ContextServiceServicerImpl.py +6 −5 Original line number Diff line number Diff line Loading @@ -25,12 +25,12 @@ from common.proto.context_pb2 import ( Slice, SliceEvent, SliceFilter, SliceId, SliceIdList, SliceList, Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList, OpticalConfigList, OpticalConfigId, OpticalConfig, OpticalLink, OpticalLinkList, ServiceConfigRule,OpticalBand,OpticalBandId,OpticalBandList ServiceConfigRule,OpticalBand,OpticalBandId,OpticalBandList , ChildTopologyList , ChildTopology , ChildEndpoint ) from common.proto.policy_pb2 import PolicyRuleIdList, PolicyRuleId, PolicyRuleList, PolicyRule from common.proto.context_pb2_grpc import ContextServiceServicer from common.proto.context_policy_pb2_grpc import ContextPolicyServiceServicer from common.proto.tapi_pb2 import ChildTopology , ChildEndpoint , ListChildTopology from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method from .database.Connection import ( connection_delete, connection_get, connection_list_ids, connection_list_objs, connection_set Loading Loading @@ -329,7 +329,7 @@ class ContextServiceServicerImpl(ContextServiceServicer, ContextPolicyServiceSer def RemovePolicyRule(self, request : PolicyRuleId, context: grpc.ServicerContext) -> Empty: return policyrule_delete(self.db_engine, self.messagebroker, request) # ---------------------------- Experimental ------------------- # ---------------------------- Optical Configuration ------------------- @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) def GetOpticalConfig(self, request : Empty, context : grpc.ServicerContext) -> OpticalConfigList: Loading Loading @@ -409,9 +409,10 @@ class ContextServiceServicerImpl(ContextServiceServicer, ContextPolicyServiceSer return get_child_topology(self.db_engine, request) @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) def ListChildTopology(self, request : Empty, context : grpc.ServicerContext) -> ListChildTopology: def ListChildTopology(self, request : Empty, context : grpc.ServicerContext) -> ChildTopologyList: return get_children_topology(self.db_engine, request) @safe_and_metered_rpc_method(METRICS_POOL, LOGGER) def SetChildTopology(self, request : ChildTopology, context : grpc.ServicerContext) -> TopologyId: return set_child_topology(self.db_engine, request) No newline at end of file topo_id= set_child_topology(self.db_engine, request) return TopologyId(topology_uuid=topo_id) No newline at end of file
src/context/service/database/Tapi.py +17 −14 Original line number Diff line number Diff line Loading @@ -20,9 +20,9 @@ from sqlalchemy import inspect from sqlalchemy.engine import Engine from sqlalchemy.orm import Session, sessionmaker from sqlalchemy_cockroachdb import run_transaction from common.proto.context_pb2 import OpticalConfig, OpticalConfigId, Empty, EventTypeEnum from common.proto.tapi_pb2 import ChildTopology , ChildEndpoint from .models.TapiModel import ChildTopology ,ChildEndpoints from common.proto.context_pb2 import OpticalConfig, OpticalConfigId, Empty, EventTypeEnum ,ChildTopology , ChildEndpoint from .models.TapiModel import ChildTopologyModel ,ChildEndpointsModel from context.service.database.uuids.EndPoint import endpoint_get_uuid from context.service.database.uuids.Device import device_get_uuid from context.service.database.uuids.Topology import topology_get_uuid Loading @@ -35,7 +35,7 @@ now = datetime.datetime.utcnow() def get_children_topology(db_engine : Engine): def callback(session:Session): results = session.query(ChildTopology).all() results = session.query(ChildTopologyModel).all() return [r.dump() for r in results] obj = run_transaction(sessionmaker(bind=db_engine), callback) Loading @@ -45,7 +45,7 @@ def get_child_topology(db_engine : Engine , request:ChildTopology ): _topology_uuid = request.topology_id.topology_uuid.uuid def callback(session:Session): result = session.query(ChildEndpoints).filter_by(topology_uuid=_topology_uuid).one_or_none() result = session.query(ChildEndpointsModel).filter_by(topology_uuid=_topology_uuid).one_or_none() return result.dump() if result else {} obj = run_transaction(sessionmaker(bind=db_engine), callback) Loading @@ -62,6 +62,8 @@ def set_child_topology(db_engine : Engine, request : ChildTopology): #is_transpondre = False now = datetime.datetime.now(datetime.timezone.utc) _,topo_uuid= topology_get_uuid(request.topology_id) for endpoint in request.endpoints: endpoints_list.append({ 'endpoint_uuid':endpoint.endpoint_id.endpoint_uuid.uuid, Loading @@ -70,32 +72,33 @@ def set_child_topology(db_engine : Engine, request : ChildTopology): 'device_name':endpoint.device_name, 'updated_at':now , 'created_at':now, 'topology_uuid':topology_get_uuid(request.topology_id) 'topology_uuid':topo_uuid }) topology = { 'topology_uuid':topology_get_uuid(request.topology_id), 'topology_uuid':topo_uuid, 'host':request.host, 'port':request.port } def callback(session:Session)->bool: stmt = insert(ChildTopology).values([topology]) stmt = insert(ChildTopologyModel).values(topology) stmt = stmt.on_conflict_do_update( index_elements=[ChildTopology.topology_uuid], index_elements=[ChildTopologyModel.topology_uuid], set_=dict( host = stmt.excluded.host, port= stmt.excluded.port, ) ) stmt = stmt.returning(ChildTopology.topology_uuid) stmt = stmt.returning(ChildTopologyModel.topology_uuid) topology_uuid = session.execute(stmt).fetchone() if topology_uuid and len(endpoints_list) > 0: en_list=[] for en in endpoints_list : stmt = insert(ChildEndpoint).values(**en) stmt = insert(ChildEndpointsModel).values(**en) update_stmt = stmt.on_conflict_do_update( index_elements=[ChildEndpoint.endpoint_uuid], index_elements=[ChildEndpointsModel.endpoint_uuid], set_=dict( endpoint_name = stmt.excluded.endpoint_name, device_name = stmt.excluded.device_name, Loading @@ -103,9 +106,9 @@ def set_child_topology(db_engine : Engine, request : ChildTopology): updated_at = stmt.excluded.updated_at, ) ).returning(ChildEndpoint.endpoint_uuid) ).returning(ChildEndpointsModel.endpoint_uuid) result = session.execute(update_stmt).fetchone() en_list.append(result) topology_uuid = run_transaction(sessionmaker(bind=db_engine), callback) return {'topology_uuid':{'uuid': topology_uuid}} No newline at end of file return {'uuid': topology_uuid} No newline at end of file