diff --git a/src/app/service/database/models/enums/__init__.py b/src/app/service/database/models/enums/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/common/Constants.py b/src/common/Constants.py index 7194cf7a2520db706d987adf97dccf36aff87a52..8b2e215a0ee669726430d12ea4ebac334f69c1ce 100644 --- a/src/common/Constants.py +++ b/src/common/Constants.py @@ -61,7 +61,7 @@ class ServiceNameEnum(Enum): E2EORCHESTRATOR = 'e2e-orchestrator' OPTICALCONTROLLER = 'opticalcontroller' BGPLS = 'bgpls-speaker' - APP = 'app' + QKD_APP = 'qkd_app' KPIMANAGER = 'kpi-manager' KPIVALUEAPI = 'kpi-value-api' KPIVALUEWRITER = 'kpi-value-writer' @@ -97,7 +97,7 @@ DEFAULT_SERVICE_GRPC_PORTS = { ServiceNameEnum.FORECASTER .value : 10040, ServiceNameEnum.E2EORCHESTRATOR .value : 10050, ServiceNameEnum.OPTICALCONTROLLER .value : 10060, - ServiceNameEnum.APP .value : 10070, + ServiceNameEnum.QKD_APP .value : 10070, ServiceNameEnum.BGPLS .value : 20030, ServiceNameEnum.KPIMANAGER .value : 30010, ServiceNameEnum.KPIVALUEAPI .value : 30020, @@ -117,12 +117,12 @@ DEFAULT_SERVICE_HTTP_PORTS = { ServiceNameEnum.CONTEXT .value : 8080, ServiceNameEnum.NBI .value : 8080, ServiceNameEnum.WEBUI .value : 8004, - ServiceNameEnum.APP .value : 8005, + ServiceNameEnum.QKD_APP .value : 8005, } # Default HTTP/REST-API service base URLs DEFAULT_SERVICE_HTTP_BASEURLS = { ServiceNameEnum.NBI .value : None, ServiceNameEnum.WEBUI .value : None, - ServiceNameEnum.APP .value : None, + ServiceNameEnum.QKD_APP .value : None, } diff --git a/src/common/tools/object_factory/QKDApp.py b/src/common/tools/object_factory/QKDApp.py new file mode 100644 index 0000000000000000000000000000000000000000..e2ea688b9d7212162ec383b848857c6c4b197747 --- /dev/null +++ b/src/common/tools/object_factory/QKDApp.py @@ -0,0 +1,24 @@ +# Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/) +# +# 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 copy +from typing import Dict, List, Optional +from common.Constants import DEFAULT_CONTEXT_NAME +from common.tools.object_factory.Context import json_context_id + + +def json_app_id(app_uuid : str, context_id : Optional[Dict] = None) -> Dict: + result = {'app_uuid': {'uuid': app_uuid}} + if context_id is not None: result['context_id'] = copy.deepcopy(context_id) + return result diff --git a/src/app/__init__.py b/src/qkd_app/__init__.py similarity index 100% rename from src/app/__init__.py rename to src/qkd_app/__init__.py diff --git a/src/app/__main__.py b/src/qkd_app/__main__.py similarity index 91% rename from src/app/__main__.py rename to src/qkd_app/__main__.py index 1521e49510c17c747749582abbb697ad7ebc7d4b..8cf383c25fc10c14a26c4c73fc1046d9a5c34d73 100644 --- a/src/app/__main__.py +++ b/src/qkd_app/__main__.py @@ -18,13 +18,13 @@ from common.Constants import ServiceNameEnum from common.Settings import ( ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC, get_env_var_name, get_log_level, get_metrics_port, wait_for_environment_variables) -from .AppService import AppService -from .rest_server.RestServer import RestServer -from .rest_server.qkd_app import register_qkd_app +from qkd_app.service.QKDAppService import AppService +from qkd_app.service.rest_server.RestServer import RestServer +from qkd_app.service.rest_server.qkd_app import register_qkd_app from common.message_broker.Factory import get_messagebroker_backend from common.message_broker.MessageBroker import MessageBroker -from .database.Engine import Engine -from .database.models._Base import rebuild_database +from qkd_app.service.database.Engine import Engine +from qkd_app.service.database.models._Base import rebuild_database terminate = threading.Event() LOGGER : logging.Logger = None diff --git a/src/app/client/AppClient.py b/src/qkd_app/client/QKDAppClient.py similarity index 99% rename from src/app/client/AppClient.py rename to src/qkd_app/client/QKDAppClient.py index 845d18f0c556407cbda35929555cc8425fd954c9..d40e79cbd45c395b3f9264eeab082cd0b9dcc812 100644 --- a/src/app/client/AppClient.py +++ b/src/qkd_app/client/QKDAppClient.py @@ -26,7 +26,7 @@ MAX_RETRIES = 15 DELAY_FUNCTION = delay_exponential(initial=0.01, increment=2.0, maximum=5.0) RETRY_DECORATOR = retry(max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION, prepare_method_name='connect') -class AppClient: +class QKDAppClient: def __init__(self, host=None, port=None): if not host: host = get_service_host(ServiceNameEnum.APP) if not port: port = get_service_port_grpc(ServiceNameEnum.APP) diff --git a/src/app/client/__init__.py b/src/qkd_app/client/__init__.py similarity index 100% rename from src/app/client/__init__.py rename to src/qkd_app/client/__init__.py diff --git a/src/app/service/AppService.py b/src/qkd_app/service/QKDAppService.py similarity index 91% rename from src/app/service/AppService.py rename to src/qkd_app/service/QKDAppService.py index 7cee0520221e98c66a85b6e014644bc747e10bb5..ed67d7aaba1f4d7f33f11680628d881aa23daf85 100644 --- a/src/app/service/AppService.py +++ b/src/qkd_app/service/QKDAppService.py @@ -16,9 +16,9 @@ import logging, sqlalchemy from common.Constants import ServiceNameEnum from common.Settings import get_service_port_grpc from common.message_broker.MessageBroker import MessageBroker -from common.proto.app_qkd_pb2_grpc import add_AppServiceServicer_to_server +from common.proto.qkd_app_pb2_grpc import add_AppServiceServicer_to_server from common.tools.service.GenericGrpcService import GenericGrpcService -from app.service.AppServiceServicerImpl import AppServiceServicerImpl +from qkd_app.service.QKDAppServiceServicerImpl import AppServiceServicerImpl # Custom gRPC settings GRPC_MAX_WORKERS = 200 # multiple clients might keep connections alive for Get*Events() RPC methods diff --git a/src/app/AppServiceServicerImpl.py b/src/qkd_app/service/QKDAppServiceServicerImpl.py similarity index 92% rename from src/app/AppServiceServicerImpl.py rename to src/qkd_app/service/QKDAppServiceServicerImpl.py index fbc5ce95ac8fd6e24af361909313f1263ad36758..4c1879f0c9af0a81f910be8c00f8a0116886d460 100644 --- a/src/app/AppServiceServicerImpl.py +++ b/src/qkd_app/service/QKDAppServiceServicerImpl.py @@ -18,8 +18,8 @@ from common.message_broker.MessageBroker import MessageBroker import grpc, json, logging #, deepdiff from common.proto.context_pb2 import ( Empty, Service, ServiceId, ServiceStatusEnum, ServiceTypeEnum, ContextId) -from common.proto.app_qkd_pb2 import (App, AppId, AppList, QKDAppTypesEnum) -from common.proto.app_qkd_pb2_grpc import AppServiceServicer +from common.proto.qkd_app_pb2 import (App, AppId, AppList, QKDAppTypesEnum) +from common.proto.qkd_app_pb2_grpc import AppServiceServicer from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method from common.tools.context_queries.InterDomain import is_inter_domain #, is_multi_domain from common.tools.grpc.ConfigRules import copy_config_rules @@ -28,8 +28,8 @@ from common.tools.grpc.EndPointIds import copy_endpoint_ids from common.tools.grpc.ServiceIds import update_service_ids #from common.tools.grpc.Tools import grpc_message_to_json_string from context.client.ContextClient import ContextClient -from app.client.AppClient import AppClient -from .database.App import app_set, app_list_objs, app_get, app_get_by_server +from qkd_app.client.QKDAppClient import QKDAppClient +from .database.QKDApp import app_set, app_list_objs, app_get, app_get_by_server from common.method_wrappers.ServiceExceptions import NotFoundException LOGGER = logging.getLogger(__name__) diff --git a/src/app/service/database/Engine.py b/src/qkd_app/service/database/Engine.py similarity index 100% rename from src/app/service/database/Engine.py rename to src/qkd_app/service/database/Engine.py diff --git a/src/app/service/database/App.py b/src/qkd_app/service/database/QKDApp.py similarity index 97% rename from src/app/service/database/App.py rename to src/qkd_app/service/database/QKDApp.py index f1c8e59538524591aea8bbc803223b7fae8dbfdd..16f1264c55199a8177e13e3deb2fea9ec77efde6 100644 --- a/src/app/service/database/App.py +++ b/src/qkd_app/service/database/QKDApp.py @@ -21,15 +21,15 @@ from typing import Dict, List, Optional, Set, Tuple from common.method_wrappers.ServiceExceptions import InvalidArgumentException, NotFoundException from common.message_broker.MessageBroker import MessageBroker from common.proto.context_pb2 import Empty -from common.proto.app_qkd_pb2 import ( +from common.proto.qkd_app_pb2 import ( AppList, App, AppId) from common.tools.grpc.Tools import grpc_message_to_json_string -from .models.AppModel import AppModel +from .models.QKDAppModel import AppModel from .models.enums.QKDAppStatus import grpc_to_enum__qkd_app_status from .models.enums.QKDAppTypes import grpc_to_enum__qkd_app_types -from .uuids.App import app_get_uuid +from .uuids.QKDApp import app_get_uuid from common.tools.object_factory.Context import json_context_id -from common.tools.object_factory.App import json_app_id +from common.tools.object_factory.QKDApp import json_app_id from context.service.database.uuids.Context import context_get_uuid diff --git a/src/app/service/database/__init__.py b/src/qkd_app/service/database/__init__.py similarity index 100% rename from src/app/service/database/__init__.py rename to src/qkd_app/service/database/__init__.py diff --git a/src/app/service/database/models/AppModel.py b/src/qkd_app/service/database/models/QKDAppModel.py similarity index 98% rename from src/app/service/database/models/AppModel.py rename to src/qkd_app/service/database/models/QKDAppModel.py index c12102946ba36e011cb51b245d28f4d6180a9ed9..1677a35e525c0d1613e6b7104a9728bb523c7442 100644 --- a/src/app/service/database/models/AppModel.py +++ b/src/qkd_app/service/database/models/QKDAppModel.py @@ -22,7 +22,7 @@ from .enums.QKDAppStatus import ORM_QKDAppStatusEnum from .enums.QKDAppTypes import ORM_QKDAppTypesEnum class AppModel(_Base): - __tablename__ = 'app' + __tablename__ = 'qkd_app' app_uuid = Column(UUID(as_uuid=False), primary_key=True) context_uuid = Column(UUID(as_uuid=False), nullable=False) # Supposed to be Foreign Key diff --git a/src/app/service/database/models/_Base.py b/src/qkd_app/service/database/models/_Base.py similarity index 100% rename from src/app/service/database/models/_Base.py rename to src/qkd_app/service/database/models/_Base.py diff --git a/src/app/service/database/models/__init__.py b/src/qkd_app/service/database/models/__init__.py similarity index 100% rename from src/app/service/database/models/__init__.py rename to src/qkd_app/service/database/models/__init__.py diff --git a/src/app/service/database/models/enums/QKDAppStatus.py b/src/qkd_app/service/database/models/enums/QKDAppStatus.py similarity index 95% rename from src/app/service/database/models/enums/QKDAppStatus.py rename to src/qkd_app/service/database/models/enums/QKDAppStatus.py index 7928992b0656d7f698f942f4acf13bd3fa71a1ea..7a296b76710106b6952d7368571ae24b4a602496 100644 --- a/src/app/service/database/models/enums/QKDAppStatus.py +++ b/src/qkd_app/service/database/models/enums/QKDAppStatus.py @@ -13,7 +13,7 @@ # limitations under the License. import enum, functools -from common.proto.app_qkd_pb2 import QKDAppStatusEnum +from common.proto.qkd_app_pb2 import QKDAppStatusEnum from ._GrpcToEnum import grpc_to_enum class ORM_QKDAppStatusEnum(enum.Enum): diff --git a/src/app/service/database/models/enums/QKDAppTypes.py b/src/qkd_app/service/database/models/enums/QKDAppTypes.py similarity index 94% rename from src/app/service/database/models/enums/QKDAppTypes.py rename to src/qkd_app/service/database/models/enums/QKDAppTypes.py index abca0f1b5e8d59232e93ef3356b8538124c4d9cb..8ce88a9c53a8ead9bc07c2a294524f601249740d 100644 --- a/src/app/service/database/models/enums/QKDAppTypes.py +++ b/src/qkd_app/service/database/models/enums/QKDAppTypes.py @@ -13,7 +13,7 @@ # limitations under the License. import enum, functools -from common.proto.app_qkd_pb2 import QKDAppTypesEnum +from common.proto.qkd_app_pb2 import QKDAppTypesEnum from ._GrpcToEnum import grpc_to_enum class ORM_QKDAppTypesEnum(enum.Enum): diff --git a/src/app/service/database/models/enums/_GrpcToEnum.py b/src/qkd_app/service/database/models/enums/_GrpcToEnum.py similarity index 100% rename from src/app/service/database/models/enums/_GrpcToEnum.py rename to src/qkd_app/service/database/models/enums/_GrpcToEnum.py diff --git a/src/qkd_app/service/database/models/enums/__init__.py b/src/qkd_app/service/database/models/enums/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..5648545ca22c15ffb8a9f58e5e3808ad5ab6504d --- /dev/null +++ b/src/qkd_app/service/database/models/enums/__init__.py @@ -0,0 +1,13 @@ +# 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. diff --git a/src/app/service/database/uuids/App.py b/src/qkd_app/service/database/uuids/QKDApp.py similarity index 92% rename from src/app/service/database/uuids/App.py rename to src/qkd_app/service/database/uuids/QKDApp.py index a682147358152f76a7c3bf27b4b907eff3211849..acc31250ac187cd73f9106a4e83ffdc67f8e6b60 100644 --- a/src/app/service/database/uuids/App.py +++ b/src/qkd_app/service/database/uuids/QKDApp.py @@ -1,4 +1,4 @@ -from common.proto.app_qkd_pb2 import AppId +from common.proto.qkd_app_pb2 import AppId from common.method_wrappers.ServiceExceptions import InvalidArgumentsException from ._Builder import get_uuid_from_string, get_uuid_random diff --git a/src/app/service/database/uuids/_Builder.py b/src/qkd_app/service/database/uuids/_Builder.py similarity index 100% rename from src/app/service/database/uuids/_Builder.py rename to src/qkd_app/service/database/uuids/_Builder.py diff --git a/src/app/service/rest_server/RestServer.py b/src/qkd_app/service/rest_server/RestServer.py similarity index 100% rename from src/app/service/rest_server/RestServer.py rename to src/qkd_app/service/rest_server/RestServer.py diff --git a/src/app/service/rest_server/__init__.py b/src/qkd_app/service/rest_server/__init__.py similarity index 100% rename from src/app/service/rest_server/__init__.py rename to src/qkd_app/service/rest_server/__init__.py diff --git a/src/app/service/rest_server/qkd_app/Resources.py b/src/qkd_app/service/rest_server/qkd_app/Resources.py similarity index 94% rename from src/app/service/rest_server/qkd_app/Resources.py rename to src/qkd_app/service/rest_server/qkd_app/Resources.py index 2c6b790b8662e0875c0696935287f5e31e9031ee..5caa4d58a27dd005fdfe49b6fa9ad18c8fab490c 100644 --- a/src/app/service/rest_server/qkd_app/Resources.py +++ b/src/qkd_app/service/rest_server/qkd_app/Resources.py @@ -16,17 +16,17 @@ import uuid, json from flask import request from flask_restful import Resource from common.proto.context_pb2 import Empty -from common.proto.app_qkd_pb2 import App, QKDAppTypesEnum +from common.proto.qkd_app_pb2 import App, QKDAppTypesEnum from common.Constants import DEFAULT_CONTEXT_NAME from context.client.ContextClient import ContextClient -from app.client.AppClient import AppClient +from qkd_app.client.QKDAppClient import QKDAppClient class _Resource(Resource): def __init__(self) -> None: super().__init__() self.context_client = ContextClient() - self.app_client = AppClient() + self.qkd_app_client = QKDAppClient() class Index(_Resource): def get(self): @@ -79,7 +79,7 @@ class CreateQKDApp(_Resource): # Optare: This will call our internal RegisterApp which supports the creation of both internal and external app. # Optare the verification for knowing if two parties are requesting the same app is done inside RegisterApp's function - self.app_client.RegisterApp(App(**external_app_src_dst)) + self.qkd_app_client.RegisterApp(App(**external_app_src_dst)) # Optare: Todo: Communicate by SBI with both Nodes of the new App diff --git a/src/app/service/rest_server/qkd_app/__init__.py b/src/qkd_app/service/rest_server/qkd_app/__init__.py similarity index 93% rename from src/app/service/rest_server/qkd_app/__init__.py rename to src/qkd_app/service/rest_server/qkd_app/__init__.py index 9a1ec230cc681adf7985d89623593725ff8110cc..469f1224367e422ba39d5358f98df2204180d3a2 100644 --- a/src/app/service/rest_server/qkd_app/__init__.py +++ b/src/qkd_app/service/rest_server/qkd_app/__init__.py @@ -12,11 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -from app.service.rest_server.RestServer import RestServer +from qkd_app.service.rest_server.RestServer import RestServer from .Resources import ( CreateQKDApp, Index) -URL_PREFIX = '/app' +URL_PREFIX = '/qkd_app' # Use 'path' type since some identifiers might contain char '/' and Flask is unable to recognize them in 'string' type. RESOURCES = [ diff --git a/src/service/service/service_handlers/qkd/qkd_service_handler.py b/src/service/service/service_handlers/qkd/qkd_service_handler.py index 30924ee9dba44c52dc7e76e4c638d15d1895fdbb..0977388005ef72fe036de93de2dc73438f0c6163 100644 --- a/src/service/service/service_handlers/qkd/qkd_service_handler.py +++ b/src/service/service/service_handlers/qkd/qkd_service_handler.py @@ -17,7 +17,7 @@ import json, logging, uuid from typing import Any, Dict, List, Optional, Tuple, Union from common.method_wrappers.Decorator import MetricsPool, metered_subclass_method from common.proto.context_pb2 import ConfigRule, DeviceId, Service -from common.proto.app_qkd_pb2 import App, QKDAppStatusEnum, QKDAppTypesEnum +from common.proto.qkd_app_pb2 import App, QKDAppStatusEnum, QKDAppTypesEnum from common.tools.object_factory.ConfigRule import json_config_rule_delete, json_config_rule_set from common.tools.object_factory.Device import json_device_id from common.type_checkers.Checkers import chk_type diff --git a/src/service/service/task_scheduler/TaskExecutor.py b/src/service/service/task_scheduler/TaskExecutor.py index f9260233b4510aaa0593180a212e262e5677fea8..cff9d3aaa6233ce1e189d81e5147c4ed7c014099 100644 --- a/src/service/service/task_scheduler/TaskExecutor.py +++ b/src/service/service/task_scheduler/TaskExecutor.py @@ -20,7 +20,7 @@ from common.proto.context_pb2 import ( Connection, ConnectionId, Device, DeviceDriverEnum, DeviceId, Service, ServiceId, OpticalConfig, OpticalConfigId ) -from common.proto.app_qkd_pb2 import App +from common.proto.qkd_app_pb2 import App from common.tools.context_queries.Connection import get_connection_by_id from common.tools.context_queries.Device import get_device from common.tools.context_queries.Service import get_service_by_id @@ -28,7 +28,7 @@ from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.object_factory.Device import json_device_id from context.client.ContextClient import ContextClient from device.client.DeviceClient import DeviceClient -from app.client.AppClient import AppClient +from app.client.QKDAppClient import QKDAppClient from service.service.service_handler_api.Exceptions import ( UnsatisfiedFilterException, UnsupportedFilterFieldException, UnsupportedFilterFieldValueException ) @@ -53,7 +53,7 @@ class TaskExecutor: self._service_handler_factory = service_handler_factory self._context_client = ContextClient() # DEPENDENCY QKD - self._app_client = AppClient() + self._qkd_app_client = QKDAppClient() self._device_client = DeviceClient() self._grpc_objects_cache : Dict[str, CacheableObject] = dict() @@ -231,6 +231,6 @@ class TaskExecutor: def register_app(self, app: App) -> None: app_key = get_app_key(app.app_id) - self._app_client.RegisterApp(app) + self._qkd_app_client.RegisterApp(app) LOGGER.info("reg registered") self._store_grpc_object(CacheableObjectType.APP, app_key, app) \ No newline at end of file diff --git a/src/service/service/tools/ObjectKeys.py b/src/service/service/tools/ObjectKeys.py index 72c00bcba6e97f70f330e109b0f171cb74f00880..cfc719bba736a4ea0789b028a97ca267b2d04089 100644 --- a/src/service/service/tools/ObjectKeys.py +++ b/src/service/service/tools/ObjectKeys.py @@ -13,7 +13,7 @@ # limitations under the License. from common.proto.context_pb2 import ConnectionId, DeviceId, ServiceId -from common.proto.app_qkd_pb2 import AppId +from common.proto.qkd_app_pb2 import AppId def get_connection_key(connection_id : ConnectionId) -> str: return connection_id.connection_uuid.uuid