Loading src/context/service/database/ConfigRule.py +14 −26 Original line number Diff line number Diff line Loading @@ -16,10 +16,10 @@ import datetime, json, logging from sqlalchemy import delete #from sqlalchemy.dialects import postgresql from sqlalchemy.dialects.postgresql import insert from sqlalchemy.orm import Session from sqlalchemy.engine import Engine from sqlalchemy.orm import Session from typing import Dict, List, Optional, Set from common.proto.context_pb2 import ConfigRule ,ServiceId ,ServiceConfigRule ,Empty from common.proto.context_pb2 import ConfigRule, ServiceConfigRule, Empty from common.tools.grpc.Tools import grpc_message_to_json_string from .models.enums.ConfigAction import ORM_ConfigActionEnum, grpc_to_enum__config_action from .models.ConfigRuleModel import ( Loading @@ -27,7 +27,7 @@ from .models.ConfigRuleModel import ( from .uuids._Builder import get_uuid_from_string from .uuids.EndPoint import endpoint_get_uuid from sqlalchemy_cockroachdb import run_transaction from sqlalchemy.orm import Session, selectinload, sessionmaker from sqlalchemy.orm import Session, sessionmaker LOGGER = logging.getLogger(__name__) Loading @@ -36,10 +36,8 @@ def compose_config_rules_data( device_uuid : Optional[str] = None, service_uuid : Optional[str] = None, slice_uuid : Optional[str] = None ) -> List[Dict]: dict_config_rules : List[Dict] = list() for position,config_rule in enumerate(config_rules): str_kind = config_rule.WhichOneof('config_rule') kind = ConfigRuleKindEnum._member_map_.get(str_kind.upper()) # pylint: disable=no-member dict_config_rule = { 'position' : position, Loading Loading @@ -68,7 +66,6 @@ def compose_config_rules_data( configrule_name = None if kind == ConfigRuleKindEnum.CUSTOM: configrule_name = '{:s}:{:s}:{:s}'.format(parent_kind, kind.value, config_rule.custom.resource_key) elif kind == ConfigRuleKindEnum.ACL: _, _, endpoint_uuid = endpoint_get_uuid(config_rule.acl.endpoint_id, allow_random=False) Loading Loading @@ -158,22 +155,13 @@ def upsert_config_rules( def delete_config_rule(db_engine : Engine, request : ServiceConfigRule): config_rule = request.configrule_custom service_id = request.service_id parent_uuid = service_id.service_uuid.uuid configrule_name = 'service:custom:{:s}'.format( config_rule.resource_key) configrule_uuid = get_uuid_from_string(configrule_name, prefix_for_name=parent_uuid) def callback(session : Session) -> bool: num_deleted = session.query(ServiceConfigRuleModel).filter_by(configrule_uuid=configrule_uuid).delete() return num_deleted > 0 deleted = run_transaction(sessionmaker(bind=db_engine), callback) return Empty() No newline at end of file src/context/service/database/Device.py +0 −5 Original line number Diff line number Diff line Loading @@ -40,7 +40,6 @@ from .ConfigRule import compose_config_rules_data, upsert_config_rules from .Component import compose_components_data from .Events import notify_event_context, notify_event_device, notify_event_topology LOGGER = logging.getLogger(__name__) def device_list_ids(db_engine : Engine) -> DeviceIdList: Loading Loading @@ -151,9 +150,6 @@ def device_set(db_engine : Engine, messagebroker : MessageBroker, request : Devi # 'updated_at' : now, # }) if endpoint_topology_uuid not in topology_uuids: related_topologies.append({ 'topology_uuid': endpoint_topology_uuid, Loading Loading @@ -323,7 +319,6 @@ def device_delete(db_engine : Engine, messagebroker : MessageBroker, request : D return Empty() def device_select(db_engine : Engine, request : DeviceFilter) -> DeviceList: device_uuids = [ device_get_uuid(device_id, allow_random=False) for device_id in request.device_ids.device_ids Loading src/context/service/database/Events.py +21 −22 Original line number Diff line number Diff line Loading @@ -17,8 +17,9 @@ from typing import Dict, Iterator, Set from common.message_broker.Message import Message from common.message_broker.MessageBroker import MessageBroker from common.proto.context_pb2 import ( ConnectionEvent, ContextEvent, DeviceEvent, EventTypeEnum, LinkEvent, ServiceEvent, SliceEvent, TopologyEvent , OpticalConfigEvent) ConnectionEvent, ContextEvent, DeviceEvent, EventTypeEnum, LinkEvent, ServiceEvent, SliceEvent, TopologyEvent, OpticalConfigEvent ) class EventTopicEnum(enum.Enum): CONNECTION = 'connection' Loading @@ -41,8 +42,7 @@ TOPIC_TO_EVENTCLASS = { EventTopicEnum.SERVICE.value : ServiceEvent, EventTopicEnum.SLICE.value : SliceEvent, EventTopicEnum.TOPOLOGY.value : TopologyEvent, EventTopicEnum.OPTICALCONFIG.value : OpticalConfigEvent EventTopicEnum.OPTICALCONFIG.value : OpticalConfigEvent, } CONSUME_TIMEOUT = 0.5 # seconds Loading @@ -69,7 +69,6 @@ def notify_event_device(messagebroker : MessageBroker, event_type : EventTypeEnu def notify_event_opticalconfig(messagebroker : MessageBroker, event_type : EventTypeEnum, opticalconfig_id : Dict) -> None: notify_event(messagebroker, EventTopicEnum.DEVICE, event_type, {'opticalconfig_id': opticalconfig_id}) def notify_event_link(messagebroker : MessageBroker, event_type : EventTypeEnum, link_id : Dict) -> None: notify_event(messagebroker, EventTopicEnum.LINK, event_type, {'link_id': link_id}) Loading src/context/service/database/Link.py +0 −2 Original line number Diff line number Diff line Loading @@ -63,7 +63,6 @@ def link_get(db_engine : Engine, request : LinkId) -> Link: return Link(**obj) def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link) -> LinkId: raw_link_uuid = request.link_id.link_uuid.uuid raw_link_name = request.name link_name = raw_link_uuid if len(raw_link_name) == 0 else raw_link_name Loading @@ -84,7 +83,6 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link) link_endpoints_data : List[Dict] = list() for i,endpoint_id in enumerate(request.link_endpoint_ids): endpoint_topology_uuid, _, endpoint_uuid = endpoint_get_uuid( endpoint_id, allow_random=False) Loading src/context/service/database/Topology.py +7 −9 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ from common.tools.object_factory.Topology import json_topology_id from context.Config import ALLOW_EXPLICIT_ADD_DEVICE_TO_TOPOLOGY, ALLOW_EXPLICIT_ADD_LINK_TO_TOPOLOGY from .models.DeviceModel import DeviceModel from .models.LinkModel import LinkModel from .models.OpticalLinkModel import OpticalLinkModel from .models.TopologyModel import TopologyDeviceModel, TopologyLinkModel, TopologyModel, TopologyOpticalLinkModel from .uuids.Context import context_get_uuid from .uuids.Device import device_get_uuid Loading @@ -34,8 +35,6 @@ from .uuids.Link import link_get_uuid from .uuids.Topology import topology_get_uuid from .Events import notify_event_context, notify_event_topology from .models.OpticalLinkModel import OpticalLinkModel LOGGER = logging.getLogger(__name__) def topology_list_ids(db_engine : Engine, request : ContextId) -> TopologyIdList: Loading Loading @@ -84,7 +83,6 @@ def topology_get_details(db_engine : Engine, request : TopologyId) -> TopologyDe .options(selectinload(TopologyModel.topology_optical_links, TopologyOpticalLinkModel.optical_link, OpticalLinkModel.opticallink_endpoints))\ .filter_by(topology_uuid=topology_uuid).one_or_none() #.options(selectinload(DeviceModel.components))\ return None if obj is None else obj.dump_details() obj = run_transaction(sessionmaker(bind=db_engine), callback) if obj is None: Loading @@ -92,7 +90,7 @@ def topology_get_details(db_engine : Engine, request : TopologyId) -> TopologyDe raw_topology_uuid = '{:s}/{:s}'.format(request.context_id.context_uuid.uuid, request.topology_uuid.uuid) raise NotFoundException('Topology', raw_topology_uuid, extra_details=[ 'context_uuid generated was: {:s}'.format(context_uuid), 'topology_uuid generated was: {:s}'.format(topology_uuid) 'topology_uuid generated was: {:s}'.format(topology_uuid), ]) return TopologyDetails(**obj) Loading Loading
src/context/service/database/ConfigRule.py +14 −26 Original line number Diff line number Diff line Loading @@ -16,10 +16,10 @@ import datetime, json, logging from sqlalchemy import delete #from sqlalchemy.dialects import postgresql from sqlalchemy.dialects.postgresql import insert from sqlalchemy.orm import Session from sqlalchemy.engine import Engine from sqlalchemy.orm import Session from typing import Dict, List, Optional, Set from common.proto.context_pb2 import ConfigRule ,ServiceId ,ServiceConfigRule ,Empty from common.proto.context_pb2 import ConfigRule, ServiceConfigRule, Empty from common.tools.grpc.Tools import grpc_message_to_json_string from .models.enums.ConfigAction import ORM_ConfigActionEnum, grpc_to_enum__config_action from .models.ConfigRuleModel import ( Loading @@ -27,7 +27,7 @@ from .models.ConfigRuleModel import ( from .uuids._Builder import get_uuid_from_string from .uuids.EndPoint import endpoint_get_uuid from sqlalchemy_cockroachdb import run_transaction from sqlalchemy.orm import Session, selectinload, sessionmaker from sqlalchemy.orm import Session, sessionmaker LOGGER = logging.getLogger(__name__) Loading @@ -36,10 +36,8 @@ def compose_config_rules_data( device_uuid : Optional[str] = None, service_uuid : Optional[str] = None, slice_uuid : Optional[str] = None ) -> List[Dict]: dict_config_rules : List[Dict] = list() for position,config_rule in enumerate(config_rules): str_kind = config_rule.WhichOneof('config_rule') kind = ConfigRuleKindEnum._member_map_.get(str_kind.upper()) # pylint: disable=no-member dict_config_rule = { 'position' : position, Loading Loading @@ -68,7 +66,6 @@ def compose_config_rules_data( configrule_name = None if kind == ConfigRuleKindEnum.CUSTOM: configrule_name = '{:s}:{:s}:{:s}'.format(parent_kind, kind.value, config_rule.custom.resource_key) elif kind == ConfigRuleKindEnum.ACL: _, _, endpoint_uuid = endpoint_get_uuid(config_rule.acl.endpoint_id, allow_random=False) Loading Loading @@ -158,22 +155,13 @@ def upsert_config_rules( def delete_config_rule(db_engine : Engine, request : ServiceConfigRule): config_rule = request.configrule_custom service_id = request.service_id parent_uuid = service_id.service_uuid.uuid configrule_name = 'service:custom:{:s}'.format( config_rule.resource_key) configrule_uuid = get_uuid_from_string(configrule_name, prefix_for_name=parent_uuid) def callback(session : Session) -> bool: num_deleted = session.query(ServiceConfigRuleModel).filter_by(configrule_uuid=configrule_uuid).delete() return num_deleted > 0 deleted = run_transaction(sessionmaker(bind=db_engine), callback) return Empty() No newline at end of file
src/context/service/database/Device.py +0 −5 Original line number Diff line number Diff line Loading @@ -40,7 +40,6 @@ from .ConfigRule import compose_config_rules_data, upsert_config_rules from .Component import compose_components_data from .Events import notify_event_context, notify_event_device, notify_event_topology LOGGER = logging.getLogger(__name__) def device_list_ids(db_engine : Engine) -> DeviceIdList: Loading Loading @@ -151,9 +150,6 @@ def device_set(db_engine : Engine, messagebroker : MessageBroker, request : Devi # 'updated_at' : now, # }) if endpoint_topology_uuid not in topology_uuids: related_topologies.append({ 'topology_uuid': endpoint_topology_uuid, Loading Loading @@ -323,7 +319,6 @@ def device_delete(db_engine : Engine, messagebroker : MessageBroker, request : D return Empty() def device_select(db_engine : Engine, request : DeviceFilter) -> DeviceList: device_uuids = [ device_get_uuid(device_id, allow_random=False) for device_id in request.device_ids.device_ids Loading
src/context/service/database/Events.py +21 −22 Original line number Diff line number Diff line Loading @@ -17,8 +17,9 @@ from typing import Dict, Iterator, Set from common.message_broker.Message import Message from common.message_broker.MessageBroker import MessageBroker from common.proto.context_pb2 import ( ConnectionEvent, ContextEvent, DeviceEvent, EventTypeEnum, LinkEvent, ServiceEvent, SliceEvent, TopologyEvent , OpticalConfigEvent) ConnectionEvent, ContextEvent, DeviceEvent, EventTypeEnum, LinkEvent, ServiceEvent, SliceEvent, TopologyEvent, OpticalConfigEvent ) class EventTopicEnum(enum.Enum): CONNECTION = 'connection' Loading @@ -41,8 +42,7 @@ TOPIC_TO_EVENTCLASS = { EventTopicEnum.SERVICE.value : ServiceEvent, EventTopicEnum.SLICE.value : SliceEvent, EventTopicEnum.TOPOLOGY.value : TopologyEvent, EventTopicEnum.OPTICALCONFIG.value : OpticalConfigEvent EventTopicEnum.OPTICALCONFIG.value : OpticalConfigEvent, } CONSUME_TIMEOUT = 0.5 # seconds Loading @@ -69,7 +69,6 @@ def notify_event_device(messagebroker : MessageBroker, event_type : EventTypeEnu def notify_event_opticalconfig(messagebroker : MessageBroker, event_type : EventTypeEnum, opticalconfig_id : Dict) -> None: notify_event(messagebroker, EventTopicEnum.DEVICE, event_type, {'opticalconfig_id': opticalconfig_id}) def notify_event_link(messagebroker : MessageBroker, event_type : EventTypeEnum, link_id : Dict) -> None: notify_event(messagebroker, EventTopicEnum.LINK, event_type, {'link_id': link_id}) Loading
src/context/service/database/Link.py +0 −2 Original line number Diff line number Diff line Loading @@ -63,7 +63,6 @@ def link_get(db_engine : Engine, request : LinkId) -> Link: return Link(**obj) def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link) -> LinkId: raw_link_uuid = request.link_id.link_uuid.uuid raw_link_name = request.name link_name = raw_link_uuid if len(raw_link_name) == 0 else raw_link_name Loading @@ -84,7 +83,6 @@ def link_set(db_engine : Engine, messagebroker : MessageBroker, request : Link) link_endpoints_data : List[Dict] = list() for i,endpoint_id in enumerate(request.link_endpoint_ids): endpoint_topology_uuid, _, endpoint_uuid = endpoint_get_uuid( endpoint_id, allow_random=False) Loading
src/context/service/database/Topology.py +7 −9 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ from common.tools.object_factory.Topology import json_topology_id from context.Config import ALLOW_EXPLICIT_ADD_DEVICE_TO_TOPOLOGY, ALLOW_EXPLICIT_ADD_LINK_TO_TOPOLOGY from .models.DeviceModel import DeviceModel from .models.LinkModel import LinkModel from .models.OpticalLinkModel import OpticalLinkModel from .models.TopologyModel import TopologyDeviceModel, TopologyLinkModel, TopologyModel, TopologyOpticalLinkModel from .uuids.Context import context_get_uuid from .uuids.Device import device_get_uuid Loading @@ -34,8 +35,6 @@ from .uuids.Link import link_get_uuid from .uuids.Topology import topology_get_uuid from .Events import notify_event_context, notify_event_topology from .models.OpticalLinkModel import OpticalLinkModel LOGGER = logging.getLogger(__name__) def topology_list_ids(db_engine : Engine, request : ContextId) -> TopologyIdList: Loading Loading @@ -84,7 +83,6 @@ def topology_get_details(db_engine : Engine, request : TopologyId) -> TopologyDe .options(selectinload(TopologyModel.topology_optical_links, TopologyOpticalLinkModel.optical_link, OpticalLinkModel.opticallink_endpoints))\ .filter_by(topology_uuid=topology_uuid).one_or_none() #.options(selectinload(DeviceModel.components))\ return None if obj is None else obj.dump_details() obj = run_transaction(sessionmaker(bind=db_engine), callback) if obj is None: Loading @@ -92,7 +90,7 @@ def topology_get_details(db_engine : Engine, request : TopologyId) -> TopologyDe raw_topology_uuid = '{:s}/{:s}'.format(request.context_id.context_uuid.uuid, request.topology_uuid.uuid) raise NotFoundException('Topology', raw_topology_uuid, extra_details=[ 'context_uuid generated was: {:s}'.format(context_uuid), 'topology_uuid generated was: {:s}'.format(topology_uuid) 'topology_uuid generated was: {:s}'.format(topology_uuid), ]) return TopologyDetails(**obj) Loading