Resolve "Improve common framework to identify deployed components"

Closes #198 (closed)

Merge request reports

Loading
+18 −0
Changes for src/common/Settings.py: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -108,3 +108,21 @@ def get_grpc_grace_period():

def get_http_bind_address():
    return get_setting(ENVVAR_HTTP_BIND_ADDRESS, default=DEFAULT_HTTP_BIND_ADDRESS)


##### ----- Detect deployed microservices ----- #####

def is_microservice_deployed(service_name : ServiceNameEnum) -> bool:
    host_env_var_name = get_env_var_name(service_name, ENVVAR_SUFIX_SERVICE_HOST     )
    port_env_var_name = get_env_var_name(service_name, ENVVAR_SUFIX_SERVICE_PORT_GRPC)
    return (host_env_var_name in os.environ) and (port_env_var_name in os.environ)

def is_deployed_bgpls     () -> bool: return is_microservice_deployed(ServiceNameEnum.BGPLS            )
def is_deployed_e2e_orch  () -> bool: return is_microservice_deployed(ServiceNameEnum.E2EORCHESTRATOR  )
def is_deployed_forecaster() -> bool: return is_microservice_deployed(ServiceNameEnum.FORECASTER       )
def is_deployed_load_gen  () -> bool: return is_microservice_deployed(ServiceNameEnum.LOAD_GENERATOR   )
def is_deployed_optical   () -> bool: return is_microservice_deployed(ServiceNameEnum.OPTICALCONTROLLER)
def is_deployed_policy    () -> bool: return is_microservice_deployed(ServiceNameEnum.POLICY           )
def is_deployed_qkd_app   () -> bool: return is_microservice_deployed(ServiceNameEnum.QKD_APP          )
def is_deployed_slice     () -> bool: return is_microservice_deployed(ServiceNameEnum.SLICE            )
def is_deployed_te        () -> bool: return is_microservice_deployed(ServiceNameEnum.TE               )
+2 −1
Changes for src/pathcomp/frontend/Config.py: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
# limitations under the License.

import os
from common.Settings import get_setting
from common.Settings import get_setting, is_deployed_forecaster

DEFAULT_PATHCOMP_BACKEND_SCHEME  = 'http'
DEFAULT_PATHCOMP_BACKEND_HOST    = '127.0.0.1'
@@ -44,6 +44,7 @@ SETTING_NAME_ENABLE_FORECASTER = 'ENABLE_FORECASTER'
TRUE_VALUES = {'Y', 'YES', 'TRUE', 'T', 'E', 'ENABLE', 'ENABLED'}

def is_forecaster_enabled() -> bool:
    if not is_deployed_forecaster(): return False
    is_enabled = get_setting(SETTING_NAME_ENABLE_FORECASTER, default=None)
    if is_enabled is None: return False
    str_is_enabled = str(is_enabled).upper()
+8 −5
Changes for src/service/service/ServiceServiceServicerImpl.py: 8 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@ from common.tools.grpc.Tools import grpc_message_to_json, grpc_message_to_json_s
from common.tools.object_factory.Context import json_context_id
from common.tools.object_factory.Topology import json_topology_id
from common.Constants import DEFAULT_CONTEXT_NAME, DEFAULT_TOPOLOGY_NAME
from common.Settings import (
    is_deployed_e2e_orch, is_deployed_optical, is_deployed_te
)
from context.client.ContextClient import ContextClient
from e2e_orchestrator.client.E2EOrchestratorClient import E2EOrchestratorClient
from pathcomp.frontend.client.PathCompClient import PathCompClient
@@ -142,7 +145,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
            service.service_type = request.service_type                                     # pylint: disable=no-member
        service.service_status.service_status = ServiceStatusEnum.SERVICESTATUS_PLANNED     # pylint: disable=no-member

        if service.service_type == ServiceTypeEnum.SERVICETYPE_TE:
        if is_deployed_te() and service.service_type == ServiceTypeEnum.SERVICETYPE_TE:
            # TE service:
            context_client.SetService(request)

@@ -164,7 +167,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
                str_service_status = ServiceStatusEnum.Name(service_status.service_status)
                raise Exception(MSG.format(service_key, str_service_status))

        if service.service_type == ServiceTypeEnum.SERVICETYPE_E2E:
        if is_deployed_e2e_orch() and service.service_type == ServiceTypeEnum.SERVICETYPE_E2E:
            # End-to-End service:
            service_id_with_uuids = context_client.SetService(request)

@@ -248,7 +251,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):

        tasks_scheduler = TasksScheduler(self.service_handler_factory)

        if service.service_type == ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY:
        if is_deployed_optical() and service.service_type == ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY:
            context_id_x = json_context_id(DEFAULT_CONTEXT_NAME)
            topology_id_x = json_topology_id(
                DEFAULT_TOPOLOGY_NAME, context_id_x)
@@ -341,14 +344,14 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
        service.service_status.service_status = ServiceStatusEnum.SERVICESTATUS_PENDING_REMOVAL
        context_client.SetService(service)

        if service.service_type == ServiceTypeEnum.SERVICETYPE_TE:
        if is_deployed_te() and service.service_type == ServiceTypeEnum.SERVICETYPE_TE:
            # TE service
            te_service_client = TEServiceClient()
            te_service_client.DeleteLSP(request)
            context_client.RemoveService(request)
            return Empty()

        if service.service_type == ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY:
        if is_deployed_optical() and service.service_type == ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY:
            devs = []

            context_id_x = json_context_id(DEFAULT_CONTEXT_NAME)
+0 −2
Changes for src/service/service/__main__.py: 0 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -44,8 +44,6 @@ def main():
        get_env_var_name(ServiceNameEnum.DEVICE,   ENVVAR_SUFIX_SERVICE_PORT_GRPC),
        get_env_var_name(ServiceNameEnum.PATHCOMP, ENVVAR_SUFIX_SERVICE_HOST     ),
        get_env_var_name(ServiceNameEnum.PATHCOMP, ENVVAR_SUFIX_SERVICE_PORT_GRPC),
        # get_env_var_name(ServiceNameEnum.QKD_APP,  ENVVAR_SUFIX_SERVICE_HOST     ),
        # get_env_var_name(ServiceNameEnum.QKD_APP,  ENVVAR_SUFIX_SERVICE_PORT_GRPC),
    ])

    signal.signal(signal.SIGINT,  signal_handler)
+31 −12
Changes for src/webui/service/templates/base.html: 31 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@
                  <a class="nav-link" href="{{ url_for('main.home') }}">Home</a>
                  {% endif %}
                </li>

                <li class="nav-item">
                  {% if '/device/' in request.path %}
                  <a class="nav-link active" aria-current="page" href="{{ url_for('device.home') }}">Device</a>
@@ -62,6 +63,7 @@
                  <a class="nav-link" href="{{ url_for('device.home') }}">Device</a>
                  {% endif %}
                </li>

                <li class="nav-item">
                  {% if '/link/' in request.path %}
                  <a class="nav-link active" aria-current="page" href="{{ url_for('link.home') }}">Link</a>
@@ -69,6 +71,7 @@
                  <a class="nav-link" href="{{ url_for('link.home') }}">Link</a>
                  {% endif %}
                </li>

                <li class="nav-item">
                  {% if '/service/' in request.path %}
                  <a class="nav-link active" aria-current="page" href="{{ url_for('service.home') }}">Service</a>
@@ -76,6 +79,8 @@
                  <a class="nav-link" href="{{ url_for('service.home') }}">Service</a>
                  {% endif %}
                </li>

                {% if is_deployed_slice() %}
                  <li class="nav-item">
                    {% if '/slice/' in request.path %}
                    <a class="nav-link active" aria-current="page" href="{{ url_for('slice.home') }}">Slice</a>
@@ -83,6 +88,9 @@
                    <a class="nav-link" href="{{ url_for('slice.home') }}">Slice</a>
                    {% endif %}
                  </li>
                {% endif %}

                {% if is_deployed_policy() %}
                  <li class="nav-item">
                    {% if '/policy_rule/' in request.path %}
                    <a class="nav-link active" aria-current="page" href="{{ url_for('policy_rule.home') }}">Policy Rules</a>
@@ -90,19 +98,9 @@
                    <a class="nav-link" href="{{ url_for('policy_rule.home') }}">Policy Rules</a>
                    {% endif %}
                  </li>
                <li class="nav-item">
                  <a class="nav-link" href="/grafana" id="grafana_link" target="grafana">Grafana</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="{{ url_for('main.debug') }}">Debug</a>
                </li>
                <li class="nav-item">
                  {% if '/load-gen/' in request.path %}
                  <a class="nav-link active" aria-current="page" href="{{ url_for('load_gen.home') }}">Load Generator</a>
                  {% else %}
                  <a class="nav-link" href="{{ url_for('load_gen.home') }}">Load Generator</a>
                {% endif %}
                </li>

                {% if is_deployed_qkd_app() %}
                  <li class="nav-item">
                    {% if '/qkd_app/' in request.path %}
                    <a class="nav-link active" aria-current="page" href="{{ url_for('qkd_app.home') }}">QKD Apps</a>
@@ -110,6 +108,9 @@
                    <a class="nav-link" href="{{ url_for('qkd_app.home') }}">QKD Apps</a>
                    {% endif %}
                  </li> 
                {% endif %}

                {% if is_deployed_bgpls() %}
                  <li class="nav-item">
                    {% if '/bgpls/' in request.path %}
                    <a class="nav-link active" aria-current="page" href="{{ url_for('bgpls.home') }}">BGPLS</a>
@@ -117,6 +118,24 @@
                    <a class="nav-link" href="{{ url_for('bgpls.home') }}">BGPLS</a>
                    {% endif %}
                  </li>
                {% endif %}

                {% if is_deployed_load_gen() %}
                  <li class="nav-item">
                    {% if '/load-gen/' in request.path %}
                    <a class="nav-link active" aria-current="page" href="{{ url_for('load_gen.home') }}">Load Generator</a>
                    {% else %}
                    <a class="nav-link" href="{{ url_for('load_gen.home') }}">Load Generator</a>
                    {% endif %}
                  </li>
                {% endif %}

                <li class="nav-item">
                  <a class="nav-link" href="/grafana" id="grafana_link" target="grafana">Grafana</a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="{{ url_for('main.debug') }}">Debug</a>
                </li>
  
                <!-- <li class="nav-item">
                  <a class="nav-link" href="#">Context</a>
Loading
Loading