From c7d0ce6099415566c89c3ed7a52367d9dffb979d Mon Sep 17 00:00:00 2001 From: naman108 Date: Sat, 19 Aug 2023 16:07:26 -0300 Subject: [PATCH] added support for depedencies in manifest --- .../impl/component_registration_handler.py | 55 +++++++++++++++---- digitalpy/core/main/controller.py | 2 + ...ice_management_communication_controller.py | 1 + 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/digitalpy/core/component_management/impl/component_registration_handler.py b/digitalpy/core/component_management/impl/component_registration_handler.py index cc6a46f..f2afc71 100644 --- a/digitalpy/core/component_management/impl/component_registration_handler.py +++ b/digitalpy/core/component_management/impl/component_registration_handler.py @@ -8,6 +8,7 @@ from digitalpy.core.component_management.impl.default_facade import DefaultFacade from digitalpy.core.digipy_configuration.configuration import Configuration from digitalpy.core.digipy_configuration.impl.inifile_configuration import InifileConfiguration +from digitalpy.core.main.object_factory import ObjectFactory MANIFEST = "manifest" DIGITALPY = "digitalpy" @@ -16,13 +17,15 @@ VERSION = "version" ID = "UUID" VERSION_DELIMITER = "." - +DEPENDENCIES = "dependencies" class ComponentRegistrationHandler(RegistrationHandler): """this class is used to manage component registration""" registered_components = {} + pending_components = {} + @staticmethod def discover_components(component_folder_path: PurePath) -> List[str]: """this method is used to discover all available components @@ -72,19 +75,28 @@ def register_component( ), f"{''.join([name.capitalize() if name[0].isupper()==False else name for name in component_name.split('_')])}", ) + facade_instance: DefaultFacade = component_facade( - None, None, None, None + ObjectFactory.get_instance("SyncActionMapper"), + ObjectFactory.get_new_instance("request"), + ObjectFactory.get_new_instance("response"), + config ) - - if ComponentRegistrationHandler.validate_manifest( - facade_instance.get_manifest(), component_name - ): + valid_manifest, pending = ComponentRegistrationHandler.validate_manifest( + facade_instance.get_manifest(), component_name, facade_instance + ) + ComponentRegistrationHandler.save_component(facade_instance, component_name) + if valid_manifest and not pending: facade_instance.register(config) + ComponentRegistrationHandler.register_pending(component_name, config) + return True + elif valid_manifest and pending: + return True else: return False else: return False - ComponentRegistrationHandler.save_component(facade_instance.get_manifest(), component_name) + return True except Exception as e: # must use a print because logger may not be available @@ -92,12 +104,16 @@ def register_component( return False @staticmethod - def save_component(manifest: Configuration, component_name: str): - section = manifest.get_section(component_name + MANIFEST, include_meta=True) - ComponentRegistrationHandler.registered_components[section[NAME]] = section + def save_component(facade, component_name: str): + ComponentRegistrationHandler.registered_components[component_name] = facade + + @staticmethod + def register_pending(component_name, config): + for facade_instance in ComponentRegistrationHandler.pending_components.pop(component_name, []): + facade_instance.register(config) @staticmethod - def validate_manifest(manifest: Configuration, component_name: str) -> bool: + def validate_manifest(manifest: Configuration, component_name: str, component_facade) -> bool: #TODO: determine better way to inform the caller that the manifest is invalid """validate that the component is compatible with the current digitalpy version @@ -156,4 +172,19 @@ def validate_manifest(manifest: Configuration, component_name: str) -> bool: ): return False - return True + pending = False + + if ( + section.get(DEPENDENCIES, None) is not None + and section[DEPENDENCIES] != "" + ): + for dependency in section[DEPENDENCIES].split(","): + if dependency not in ComponentRegistrationHandler.registered_components: + pending = True + if ComponentRegistrationHandler.pending_components.get(dependency) is not None: + ComponentRegistrationHandler.pending_components[dependency].append(component_facade) + + else: + ComponentRegistrationHandler.pending_components[dependency] = [component_facade] + + return True, pending diff --git a/digitalpy/core/main/controller.py b/digitalpy/core/main/controller.py index 826f277..d2247ff 100644 --- a/digitalpy/core/main/controller.py +++ b/digitalpy/core/main/controller.py @@ -32,6 +32,8 @@ def __init__( action_mapper: ActionMapper, configuration: Configuration, ): + self.request = request + self.response = response self.action_mapper = action_mapper self.configuration = configuration diff --git a/digitalpy/core/service_management/controllers/service_management_communication_controller.py b/digitalpy/core/service_management/controllers/service_management_communication_controller.py index 51a9fcb..3c54ecd 100644 --- a/digitalpy/core/service_management/controllers/service_management_communication_controller.py +++ b/digitalpy/core/service_management/controllers/service_management_communication_controller.py @@ -31,6 +31,7 @@ def make_request(self, action: str, context: str = "", values: dict={}, target_s Returns: _type_: _description_ """ + print("making request to service: " + str(self._service_id) + " with action: " + str(action) + " and context: " + str(context) + " and values: " + str(values)) if target_service_name is None: target_service_name = self._service_id