diff --git a/src/common/Settings.py b/src/common/Settings.py index 936c0387b5ad989621680b9f6f848e69fcc00e39..13fcfc76966301599b0f5f39f2b188aea4e4d52a 100644 --- a/src/common/Settings.py +++ b/src/common/Settings.py @@ -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 ) diff --git a/src/pathcomp/frontend/Config.py b/src/pathcomp/frontend/Config.py index 08de81b47dd05ce19ac8335b5b31df8ef4ee461e..ab431acb92ac3732ff98bf7228d825c92d279986 100644 --- a/src/pathcomp/frontend/Config.py +++ b/src/pathcomp/frontend/Config.py @@ -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() diff --git a/src/service/service/ServiceServiceServicerImpl.py b/src/service/service/ServiceServiceServicerImpl.py index eb821972a6447a85990261586e656f2f365dda0d..45a8e0b6c0fd9a26b45fc47d55074d8863c0caed 100644 --- a/src/service/service/ServiceServiceServicerImpl.py +++ b/src/service/service/ServiceServiceServicerImpl.py @@ -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) diff --git a/src/service/service/__main__.py b/src/service/service/__main__.py index 589d3f67317643bf76e454822a9fea40dd7e01e3..ae8a9e960cf6a0d720b508fe3ea5592632420c18 100644 --- a/src/service/service/__main__.py +++ b/src/service/service/__main__.py @@ -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) diff --git a/src/webui/service/__init__.py b/src/webui/service/__init__.py index f269408e4450de87bd33a3b075250f47f9123df8..f137c247e1c4d2f4be5707e72e4140ab75f8e886 100644 --- a/src/webui/service/__init__.py +++ b/src/webui/service/__init__.py @@ -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: diff --git a/src/webui/service/__main__.py b/src/webui/service/__main__.py index 3c7be34954a42edd4f1d376a8d2a431f30507b20..bb6b8bfc7187dec41cda3e8bcf7b5a1b9f8a601d 100644 --- a/src/webui/service/__main__.py +++ b/src/webui/service/__main__.py @@ -43,8 +43,6 @@ def main(): get_env_var_name(ServiceNameEnum.SERVICE, ENVVAR_SUFIX_SERVICE_PORT_GRPC), get_env_var_name(ServiceNameEnum.SLICE, ENVVAR_SUFIX_SERVICE_HOST ), get_env_var_name(ServiceNameEnum.SLICE, 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), ]) logger.info('Starting...') diff --git a/src/webui/service/templates/base.html b/src/webui/service/templates/base.html index 9cea0a59dff935aab3018ac0652cd7c96182f4e9..432f1a095be1a682624a45decf2355310e58238b 100644 --- a/src/webui/service/templates/base.html +++ b/src/webui/service/templates/base.html @@ -55,6 +55,7 @@ Home {% endif %} + + + - - + + {% if is_deployed_slice() %} + + {% endif %} + + {% if is_deployed_policy() %} + + {% endif %} + + {% if is_deployed_qkd_app() %} + + {% endif %} + + {% if is_deployed_bgpls() %} + + {% endif %} + + {% if is_deployed_load_gen() %} + + {% endif %} + - - -