Commit 2ac5f0f8 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Deployed microservices:

- Added method to check deployed microservices
- Extended WebUI to activate tabs according to deployed microservices
- Extended Service and PathComp to activate selective parts of code depending on deployed microservices
parent 25babf95
Loading
Loading
Loading
Loading
+18 −0
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
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
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
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)
+9 −0
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@ from common.tools.grpc.Tools import grpc_message_to_json
from context.client.ContextClient import ContextClient
from device.client.DeviceClient import DeviceClient
from qkd_app.client.QKDAppClient import QKDAppClient
from common.Settings import (
    is_deployed_bgpls, is_deployed_load_gen, is_deployed_policy, is_deployed_qkd_app, is_deployed_slice
)

def get_working_context() -> str:
    return session['context_uuid'] if 'context_uuid' in session else '---'
@@ -120,6 +123,12 @@ def create_app(use_config=None, web_app_root=None):
        'round'               : round,
        'get_working_context' : get_working_context,
        'get_working_topology': get_working_topology,

        'is_deployed_bgpls'   : is_deployed_bgpls,
        'is_deployed_load_gen': is_deployed_load_gen,
        'is_deployed_policy'  : is_deployed_policy,
        'is_deployed_qkd_app' : is_deployed_qkd_app,
        'is_deployed_slice'   : is_deployed_slice,
    })

    if web_app_root is not None:
Loading