Commit ef90cda5 authored by Carlos Manso's avatar Carlos Manso
Browse files

Location add endpoint protobuf and updated service

parent d0b90a60
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -58,9 +58,9 @@ def compose_constraints_data(
        if kind == ConstraintKindEnum.CUSTOM:
            constraint_name = '{:s}:{:s}:{:s}'.format(parent_kind, kind.value, constraint.custom.constraint_type)
        elif kind == ConstraintKindEnum.ENDPOINT_LOCATION:
            _, _, endpoint_uuid = endpoint_get_uuid(constraint.endpoint_location.endpoint_id, allow_random=False)
            # _, _, endpoint_uuid = endpoint_get_uuid(constraint.endpoint_location.endpoint_id, allow_random=False)
            location_kind = constraint.endpoint_location.location.WhichOneof('location')
            constraint_name = '{:s}:{:s}:{:s}:{:s}'.format(parent_kind, kind.value, endpoint_uuid, location_kind)
            constraint_name = '{:s}:{:s}:{:s}:{:s}'.format(parent_kind, kind.value, '', location_kind)
        elif kind == ConstraintKindEnum.ENDPOINT_PRIORITY:
            _, _, endpoint_uuid = endpoint_get_uuid(constraint.endpoint_priority.endpoint_id, allow_random=False)
            constraint_name = '{:s}:{:s}:{:s}'.format(parent_kind, kind.value, endpoint_uuid)
+11 −8
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ from .models.enums.KpiSampleType import grpc_to_enum__kpi_sample_type
from .uuids.Device import device_get_uuid
from .uuids.EndPoint import endpoint_get_uuid
from .ConfigRule import compose_config_rules_data, upsert_config_rules
from common.tools.grpc.Tools import grpc_message_to_json
import json

LOGGER = logging.getLogger(__name__)

@@ -116,6 +118,7 @@ def device_set(db_engine : Engine, request : Device) -> Tuple[Dict, bool]:
            'name'             : endpoint_name,
            'endpoint_type'    : endpoint.endpoint_type,
            'kpi_sample_types' : kpi_sample_types,
            'endpoint_location': json.dumps(grpc_message_to_json(endpoint.endpoint_location)),
            'created_at'       : now,
            'updated_at'       : now,
        })
+15 −12
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ from sqlalchemy.orm import relationship
from typing import Dict
from .enums.KpiSampleType import ORM_KpiSampleTypeEnum
from ._Base import _Base
import json

class EndPointModel(_Base):
    __tablename__ = 'endpoint'
@@ -30,6 +31,7 @@ class EndPointModel(_Base):
    kpi_sample_types  = Column(ARRAY(Enum(ORM_KpiSampleTypeEnum), dimensions=1))
    created_at        = Column(DateTime, nullable=False)
    updated_at        = Column(DateTime, nullable=False)
    endpoint_location = Column(String, nullable=True)

    device            = relationship('DeviceModel',          back_populates='endpoints') # lazy='selectin'
    topology          = relationship('TopologyModel', lazy='selectin')
@@ -50,6 +52,7 @@ class EndPointModel(_Base):
            'name'             : self.name,
            'endpoint_type'    : self.endpoint_type,
            'kpi_sample_types' : [kst.value for kst in self.kpi_sample_types],
            'endpoint_location': json.loads(self.endpoint_location)
        }

    def dump_name(self) -> Dict:
+2 −2
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ class ServiceModel(_Base):
    created_at     = Column(DateTime, nullable=False)
    updated_at     = Column(DateTime, nullable=False)

    context           = relationship('ContextModel', back_populates='services', lazy='selectin')
    context           = relationship('ContextModel', back_populates='services', lazy='selectin',)
    service_endpoints = relationship('ServiceEndPointModel') # lazy='selectin', back_populates='service'
    constraints       = relationship('ConstraintModel', passive_deletes=True) # lazy='selectin', back_populates='service'
    config_rules      = relationship('ConfigRuleModel', passive_deletes=True) # lazy='selectin', back_populates='service'
@@ -79,7 +79,7 @@ class ServiceEndPointModel(_Base):
    __tablename__ = 'service_endpoint'

    service_uuid  = Column(ForeignKey('service.service_uuid',   ondelete='CASCADE' ), primary_key=True)
    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, nullable=True)
    position      = Column(Integer, nullable=False)

    service  = relationship('ServiceModel',  back_populates='service_endpoints') # lazy='selectin'
+6 −1
Original line number Diff line number Diff line
@@ -16,12 +16,13 @@ import json, logging
from typing import Any, Dict, List, Optional, Tuple, Union
from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME
from common.method_wrappers.ServiceExceptions import InvalidArgumentException
from common.proto.context_pb2 import ConfigActionEnum, Device, DeviceConfig, Link
from common.proto.context_pb2 import ConfigActionEnum, Device, DeviceConfig, Link, Location
from common.proto.device_pb2 import MonitoringSettings
from common.proto.kpi_sample_types_pb2 import KpiSampleType
from common.tools.grpc.ConfigRules import update_config_rule_custom
from common.tools.grpc.Tools import grpc_message_to_json
from context.client.ContextClient import ContextClient
from google.protobuf import json_format
from .driver_api._Driver import _Driver, RESOURCE_ENDPOINTS
from .monitoring.MonitoringLoops import MonitoringLoops
from .ErrorMessages import (
@@ -194,6 +195,10 @@ def populate_endpoints(
                device_endpoint.kpi_sample_types.append(kpi_sample_type)
                monitoring_loops.add_resource_key(device_uuid, endpoint_uuid, kpi_sample_type, monitor_resource_key)

            location = resource_value.get('location', {})
            if location:
                json_format.Parse(json.dumps(location), device_endpoint.endpoint_location)

        elif resource_key.startswith('/links/link'):
            # create sub-link
            _sub_link_uuid = resource_value['uuid']
Loading