Commit 4bd4db2e authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'fix/release-2' into 'develop'

Improvement to show names instead of UUIDs for devices and endpoints in WebUI

See merge request !44
parents 95aba396 372bf3a4
Loading
Loading
Loading
Loading
+75 −50
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ service ContextService {
  rpc ListTopologyIds    (ContextId     ) returns (       TopologyIdList  ) {}
  rpc ListTopologies     (ContextId     ) returns (       TopologyList    ) {}
  rpc GetTopology        (TopologyId    ) returns (       Topology        ) {}
  rpc GetTopologyDetails (TopologyId    ) returns (       TopologyDetails ) {}
  rpc SetTopology        (Topology      ) returns (       TopologyId      ) {}
  rpc RemoveTopology     (TopologyId    ) returns (       Empty           ) {}
  rpc GetTopologyEvents  (Empty         ) returns (stream TopologyEvent   ) {}
@@ -40,6 +41,8 @@ service ContextService {
  rpc RemoveDevice       (DeviceId      ) returns (       Empty           ) {}
  rpc GetDeviceEvents    (Empty         ) returns (stream DeviceEvent     ) {}

  rpc ListEndPointNames  (EndPointIdList) returns (       EndPointNameList) {}

  rpc ListLinkIds        (Empty         ) returns (       LinkIdList      ) {}
  rpc ListLinks          (Empty         ) returns (       LinkList        ) {}
  rpc GetLink            (LinkId        ) returns (       Link            ) {}
@@ -135,6 +138,13 @@ message Topology {
  repeated LinkId link_ids = 4;
}

message TopologyDetails {
  TopologyId topology_id = 1;
  string name = 2;
  repeated Device devices = 3;
  repeated Link links = 4;
}

message TopologyIdList {
  repeated TopologyId topology_ids = 1;
}
@@ -413,6 +423,21 @@ message EndPoint {
  Location endpoint_location = 5;
}

message EndPointName {
  EndPointId endpoint_id = 1;
  string device_name = 2;
  string endpoint_name = 3;
  string endpoint_type = 4;
}

message EndPointIdList {
  repeated EndPointId endpoint_ids = 1;
}

message EndPointNameList {
  repeated EndPointName endpoint_names = 1;
}


// ----- Configuration -------------------------------------------------------------------------------------------------
enum ConfigActionEnum {
+46 −0
Original line number Diff line number Diff line
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
from typing import Dict, List, Set, Tuple
from common.proto.context_pb2 import EndPointId, EndPointIdList
from context.client.ContextClient import ContextClient

LOGGER = logging.getLogger(__name__)

TYPE_DEVICE_NAMES   = Dict[str, str]             # device_uuid => device_name
TYPE_ENDPOINTS_DATA = Dict[str, Tuple[str, str]] # endpoint_uuid => (endpoint_name, endpoint_type)
TYPE_NAME_MAPS      = Tuple[TYPE_DEVICE_NAMES, TYPE_ENDPOINTS_DATA]

def get_endpoint_names(context_client : ContextClient, endpoint_ids : List[EndPointId]) -> TYPE_NAME_MAPS:
    endpoint_uuids_to_names : Set[str] = set()
    endpoint_id_list = EndPointIdList()
    for endpoint_id in endpoint_ids:
        endpoint_uuid = endpoint_id.endpoint_uuid.uuid
        if endpoint_uuid in endpoint_uuids_to_names: continue
        endpoint_id_list.endpoint_ids.add().CopyFrom(endpoint_id)   # pylint: disable=no-member
        endpoint_uuids_to_names.add(endpoint_uuid)

    endpoint_names = context_client.ListEndPointNames(endpoint_id_list)

    device_names   : TYPE_DEVICE_NAMES   = dict()
    endpoints_data : TYPE_ENDPOINTS_DATA = dict()
    for endpoint_name in endpoint_names.endpoint_names:
        device_uuid = endpoint_name.endpoint_id.device_id.device_uuid.uuid
        device_names[device_uuid] = endpoint_name.device_name

        endpoint_uuid = endpoint_name.endpoint_id.endpoint_uuid.uuid
        endpoints_data[endpoint_uuid] = (endpoint_name.endpoint_name, endpoint_name.endpoint_type)

    return device_names, endpoints_data
+16 −2
Original line number Diff line number Diff line
@@ -22,11 +22,11 @@ from common.proto.context_pb2 import (
    Connection, ConnectionEvent, ConnectionId, ConnectionIdList, ConnectionList,
    Context, ContextEvent, ContextId, ContextIdList, ContextList,
    Device, DeviceEvent, DeviceId, DeviceIdList, DeviceList,
    Empty,
    Empty, EndPointIdList, EndPointNameList,
    Link, LinkEvent, LinkId, LinkIdList, LinkList,
    Service, ServiceEvent, ServiceId, ServiceIdList, ServiceList,
    Slice, SliceEvent, SliceId, SliceIdList, SliceList,
    Topology, TopologyEvent, TopologyId, TopologyIdList, TopologyList)
    Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList)
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
@@ -143,6 +143,13 @@ class ContextClient:
        LOGGER.debug('GetTopologyEvents result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def GetTopologyDetails(self, request: TopologyId) -> TopologyDetails:
        LOGGER.debug('GetTopologyDetails request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.GetTopologyDetails(request)
        LOGGER.debug('GetTopologyDetails result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def ListDeviceIds(self, request: Empty) -> DeviceIdList:
        LOGGER.debug('ListDeviceIds request: {:s}'.format(grpc_message_to_json_string(request)))
@@ -185,6 +192,13 @@ class ContextClient:
        LOGGER.debug('GetDeviceEvents result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def ListEndPointNames(self, request: EndPointIdList) -> EndPointNameList:
        LOGGER.debug('ListEndPointNames request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.ListEndPointNames(request)
        LOGGER.debug('ListEndPointNames result: {:s}'.format(grpc_message_to_json_string(response)))
        return response

    @RETRY_DECORATOR
    def ListLinkIds(self, request: Empty) -> LinkIdList:
        LOGGER.debug('ListLinkIds request: {:s}'.format(grpc_message_to_json_string(request)))
+13 −3
Original line number Diff line number Diff line
@@ -19,11 +19,11 @@ from common.proto.context_pb2 import (
    Connection, ConnectionEvent, ConnectionId, ConnectionIdList, ConnectionList,
    Context, ContextEvent, ContextId, ContextIdList, ContextList,
    Device, DeviceEvent, DeviceId, DeviceIdList, DeviceList,
    Empty, EventTypeEnum,
    Empty, EndPointIdList, EndPointNameList, EventTypeEnum,
    Link, LinkEvent, LinkId, LinkIdList, LinkList,
    Service, ServiceEvent, ServiceId, ServiceIdList, ServiceList,
    Slice, SliceEvent, SliceId, SliceIdList, SliceList,
    Topology, TopologyEvent, TopologyId, TopologyIdList, TopologyList)
    Topology, TopologyDetails, TopologyEvent, TopologyId, TopologyIdList, TopologyList)
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
@@ -32,12 +32,14 @@ from .database.Connection import (
    connection_delete, connection_get, connection_list_ids, connection_list_objs, connection_set)
from .database.Context import context_delete, context_get, context_list_ids, context_list_objs, context_set
from .database.Device import device_delete, device_get, device_list_ids, device_list_objs, device_set
from .database.EndPoint import endpoint_list_names
from .database.Link import link_delete, link_get, link_list_ids, link_list_objs, link_set
from .database.PolicyRule import (
    policyrule_delete, policyrule_get, policyrule_list_ids, policyrule_list_objs, policyrule_set)
from .database.Service import service_delete, service_get, service_list_ids, service_list_objs, service_set
from .database.Slice import slice_delete, slice_get, slice_list_ids, slice_list_objs, slice_set, slice_unset
from .database.Topology import topology_delete, topology_get, topology_list_ids, topology_list_objs, topology_set
from .database.Topology import (
    topology_delete, topology_get, topology_get_details, topology_list_ids, topology_list_objs, topology_set)
from .Events import (
    CONSUME_TIMEOUT, TOPIC_CONNECTION, TOPIC_CONTEXT, TOPIC_DEVICE, TOPIC_LINK, TOPIC_POLICY, TOPIC_SERVICE,
    TOPIC_SLICE, TOPIC_TOPOLOGY, notify_event)
@@ -105,6 +107,10 @@ class ContextServiceServicerImpl(ContextServiceServicer, ContextPolicyServiceSer
    def GetTopology(self, request : TopologyId, context : grpc.ServicerContext) -> Topology:
        return Topology(**topology_get(self.db_engine, request))

    @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
    def GetTopologyDetails(self, request : TopologyId, context : grpc.ServicerContext) -> TopologyDetails:
        return TopologyDetails(**topology_get_details(self.db_engine, request))

    @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
    def SetTopology(self, request : Topology, context : grpc.ServicerContext) -> TopologyId:
        topology_id,updated = topology_set(self.db_engine, request)
@@ -160,6 +166,10 @@ class ContextServiceServicerImpl(ContextServiceServicer, ContextPolicyServiceSer
        for message in self.messagebroker.consume({TOPIC_DEVICE}, consume_timeout=CONSUME_TIMEOUT):
            yield DeviceEvent(**json.loads(message.content))

    @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
    def ListEndPointNames(self, request : EndPointIdList, context : grpc.ServicerContext) -> EndPointNameList:
        return EndPointNameList(endpoint_names=endpoint_list_names(self.db_engine, request))


    # ----- Link -------------------------------------------------------------------------------------------------------

+35 −0
Original line number Diff line number Diff line
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
from sqlalchemy.engine import Engine
from sqlalchemy.orm import Session, sessionmaker
from sqlalchemy_cockroachdb import run_transaction
from typing import Dict, List
from common.proto.context_pb2 import EndPointIdList
from .models.EndPointModel import EndPointModel
from .uuids.EndPoint import endpoint_get_uuid

LOGGER = logging.getLogger(__name__)

def endpoint_list_names(db_engine : Engine, request : EndPointIdList) -> List[Dict]:
    endpoint_uuids = {
        endpoint_get_uuid(endpoint_id, allow_random=False)[-1]
        for endpoint_id in request.endpoint_ids
    }
    def callback(session : Session) -> List[Dict]:
        obj_list : List[EndPointModel] = \
            session.query(EndPointModel).filter(EndPointModel.endpoint_uuid.in_(endpoint_uuids)).all()
        return [obj.dump_name() for obj in obj_list]
    return run_transaction(sessionmaker(bind=db_engine), callback)
Loading