Commit 179d28fb authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

PathComp component - Frontend:

- Updated to use RPC method GetTopologyDetails
parent 8d7f1fd9
Loading
Loading
Loading
Loading
+15 −9
Original line number Original line Diff line number Diff line
@@ -13,9 +13,9 @@
# limitations under the License.
# limitations under the License.


import grpc, logging, threading
import grpc, logging, threading
from common.Constants import DEFAULT_CONTEXT_NAME, INTERDOMAIN_TOPOLOGY_NAME
from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME, INTERDOMAIN_TOPOLOGY_NAME
from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method
from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method
from common.proto.context_pb2 import ContextId, Empty
from common.proto.context_pb2 import ContextId, Empty, TopologyId
from common.proto.pathcomp_pb2 import PathCompReply, PathCompRequest
from common.proto.pathcomp_pb2 import PathCompReply, PathCompRequest
from common.proto.pathcomp_pb2_grpc import PathCompServiceServicer
from common.proto.pathcomp_pb2_grpc import PathCompServiceServicer
from common.tools.context_queries.Device import get_devices_in_topology
from common.tools.context_queries.Device import get_devices_in_topology
@@ -23,6 +23,7 @@ from common.tools.context_queries.Link import get_links_in_topology
from common.tools.context_queries.InterDomain import is_inter_domain
from common.tools.context_queries.InterDomain import is_inter_domain
from common.tools.grpc.Tools import grpc_message_to_json_string
from common.tools.grpc.Tools import grpc_message_to_json_string
from common.tools.object_factory.Context import json_context_id
from common.tools.object_factory.Context import json_context_id
from common.tools.object_factory.Topology import json_topology_id
from context.client.ContextClient import ContextClient
from context.client.ContextClient import ContextClient
from pathcomp.frontend.service.algorithms.Factory import get_algorithm
from pathcomp.frontend.service.algorithms.Factory import get_algorithm


@@ -30,7 +31,7 @@ LOGGER = logging.getLogger(__name__)


METRICS_POOL = MetricsPool('PathComp', 'RPC')
METRICS_POOL = MetricsPool('PathComp', 'RPC')


ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME))
#ADMIN_CONTEXT_ID = ContextId(**json_context_id(DEFAULT_CONTEXT_NAME))


class PathCompServiceServicerImpl(PathCompServiceServicer):
class PathCompServiceServicerImpl(PathCompServiceServicer):
    def __init__(self) -> None:
    def __init__(self) -> None:
@@ -44,18 +45,23 @@ class PathCompServiceServicerImpl(PathCompServiceServicer):


        context_client = ContextClient()
        context_client = ContextClient()


        context_id = json_context_id(DEFAULT_CONTEXT_NAME)
        if (len(request.services) == 1) and is_inter_domain(context_client, request.services[0].service_endpoint_ids):
        if (len(request.services) == 1) and is_inter_domain(context_client, request.services[0].service_endpoint_ids):
            devices = get_devices_in_topology(context_client, ADMIN_CONTEXT_ID, INTERDOMAIN_TOPOLOGY_NAME)
            #devices = get_devices_in_topology(context_client, ADMIN_CONTEXT_ID, INTERDOMAIN_TOPOLOGY_NAME)
            links = get_links_in_topology(context_client, ADMIN_CONTEXT_ID, INTERDOMAIN_TOPOLOGY_NAME)
            #links = get_links_in_topology(context_client, ADMIN_CONTEXT_ID, INTERDOMAIN_TOPOLOGY_NAME)
            topology_id = json_topology_id(INTERDOMAIN_TOPOLOGY_NAME, context_id)
        else:
        else:
            # TODO: improve filtering of devices and links
            # TODO: improve filtering of devices and links
            # TODO: add contexts, topologies, and membership of devices/links in topologies
            # TODO: add contexts, topologies, and membership of devices/links in topologies
            devices = context_client.ListDevices(Empty())
            #devices = context_client.ListDevices(Empty())
            links = context_client.ListLinks(Empty())
            #links = context_client.ListLinks(Empty())
            topology_id = json_topology_id(DEFAULT_TOPOLOGY_NAME, context_id)

        topology_details = context_client.GetTopologyDetails(TopologyId(**topology_id))


        algorithm = get_algorithm(request)
        algorithm = get_algorithm(request)
        algorithm.add_devices(devices)
        algorithm.add_devices(topology_details.devices)
        algorithm.add_links(links)
        algorithm.add_links(topology_details.links)
        algorithm.add_service_requests(request)
        algorithm.add_service_requests(request)


        #LOGGER.debug('device_list = {:s}'  .format(str(algorithm.device_list  )))
        #LOGGER.debug('device_list = {:s}'  .format(str(algorithm.device_list  )))