From 69e5969d78469440f5115d1af24fd54a59416204 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 23 Sep 2024 10:39:08 +0300 Subject: [PATCH 1/2] Add DBProxyIntegration.py file --- .../Integration/DBProxyIntegration.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 DB/NEW_KT_DB/Integration/DBProxyIntegration.py diff --git a/DB/NEW_KT_DB/Integration/DBProxyIntegration.py b/DB/NEW_KT_DB/Integration/DBProxyIntegration.py new file mode 100644 index 00000000..0af5e4ce --- /dev/null +++ b/DB/NEW_KT_DB/Integration/DBProxyIntegration.py @@ -0,0 +1,19 @@ + +from DataAccess.ObjectManager import ObjectManager +from Storage.NEW_KT_Storage.DataAccess.StorageManager import StorageManager +from DB.NEW_KT_DB.DataAccess.DBManager import EmptyResultsetError +from DB.NEW_KT_DB.Controller.DBProxyController import DBProxyController +from DB.NEW_KT_DB.DataAccess.ObjectManager import ObjectManager +from DB.NEW_KT_DB.DataAccess.DBProxyManager import DBProxyManager +from Storage.NEW_KT_Storage.DataAccess.StorageManager import StorageManager +from DB.NEW_KT_DB.Service.Classes.DBProxyService import DBProxyService +from datetime import datetime + +object_manager = ObjectManager('../DBs/mainDB.db') +storage_manager = StorageManager('../../s3') +proxy_manager = DBProxyManager(object_manager) +proxy_service = DBProxyService(proxy_manager, storage_manager) +proxy_controller = DBProxyController(proxy_service) + +print("---------------------Start Of session----------------------") +start_integration_date_time = datetime.now() From bf1138aa43138d679aa7e07afa001a117680492a Mon Sep 17 00:00:00 2001 From: = Date: Mon, 23 Sep 2024 13:58:01 +0300 Subject: [PATCH 2/2] Add Integation --- DB/NEW_KT_DB/Controller/DBProxyController.py | 10 ++- .../Integration/DBProxyIntegration.py | 86 ++++++++++++++++++- .../Service/Classes/DBProxyService.py | 5 +- 3 files changed, 91 insertions(+), 10 deletions(-) diff --git a/DB/NEW_KT_DB/Controller/DBProxyController.py b/DB/NEW_KT_DB/Controller/DBProxyController.py index 5865b1dc..8d6a2f78 100644 --- a/DB/NEW_KT_DB/Controller/DBProxyController.py +++ b/DB/NEW_KT_DB/Controller/DBProxyController.py @@ -20,14 +20,14 @@ def create_db_proxy(self, **kwargs): """ self.service.create(**kwargs) - def delete_db_proxy(self, id): + def delete_db_proxy(self, db_proxy_name): """ Delete a DBProxy by its ID. Parameters: id (str): The ID of the DBProxy to delete. """ - self.service.delete(id) + self.service.delete(db_proxy_name) def modify_db_proxy(self, **kwargs): """ @@ -38,7 +38,7 @@ def modify_db_proxy(self, **kwargs): """ self.service.modify(**kwargs) - def describe_db_proxy(self, id): + def describe_db_proxy(self, db_proxy_name): """ Retrieve details of a DBProxy by its ID. @@ -48,5 +48,7 @@ def describe_db_proxy(self, id): Returns: dict: Metadata of the requested DBProxy. """ - return self.service.describe(id) + return self.service.describe(db_proxy_name) + def get(self, db_proxy_name): + return self.service.get(db_proxy_name) diff --git a/DB/NEW_KT_DB/Integration/DBProxyIntegration.py b/DB/NEW_KT_DB/Integration/DBProxyIntegration.py index 0af5e4ce..ebfae232 100644 --- a/DB/NEW_KT_DB/Integration/DBProxyIntegration.py +++ b/DB/NEW_KT_DB/Integration/DBProxyIntegration.py @@ -1,19 +1,97 @@ -from DataAccess.ObjectManager import ObjectManager -from Storage.NEW_KT_Storage.DataAccess.StorageManager import StorageManager -from DB.NEW_KT_DB.DataAccess.DBManager import EmptyResultsetError from DB.NEW_KT_DB.Controller.DBProxyController import DBProxyController from DB.NEW_KT_DB.DataAccess.ObjectManager import ObjectManager from DB.NEW_KT_DB.DataAccess.DBProxyManager import DBProxyManager from Storage.NEW_KT_Storage.DataAccess.StorageManager import StorageManager from DB.NEW_KT_DB.Service.Classes.DBProxyService import DBProxyService from datetime import datetime +import time object_manager = ObjectManager('../DBs/mainDB.db') -storage_manager = StorageManager('../../s3') +storage_manager = StorageManager('../s3/proxies') proxy_manager = DBProxyManager(object_manager) proxy_service = DBProxyService(proxy_manager, storage_manager) proxy_controller = DBProxyController(proxy_service) +time_to_sleep = 1 print("---------------------Start Of session----------------------") start_integration_date_time = datetime.now() +print(f"{start_integration_date_time} demonstration of object DBProxy start") + +print("\n-------------------Create DBProxy-------------------------") +start_creation_date_time = datetime.now() +print(f"{start_creation_date_time} going to create DBProxy names 'proxy-example'") +proxy_controller.create_db_proxy( + db_proxy_name='proxy-example', + engine_family='MYSQL', + role_arn='arn:aws:iam::account-id:role/my-iam-role', + auth={ + 'AuthScheme': 'SECRETS', + 'SecretArn': 'arn:aws:secretsmanager:region:account-id:secret:mysecret', + 'IAMAuth': 'DISABLED' + }, + vpc_subnet_ids=['subnet-12345678', 'subnet-87654321'],) +end_creation_date_time = datetime.now() +total_duration = end_creation_date_time - start_creation_date_time +print(f'''{end_creation_date_time} DBProxy 'proxy-example' created successfully''') +print(f"Total creation time: {total_duration}") +time.sleep(time_to_sleep) + + +print("\n-------------------Describe DBProxy----------------------") +start_description_date_time = datetime.now() +print(f"{start_description_date_time} going to describe db DBProxy 'proxy-example'") +description = proxy_controller.describe_db_proxy(db_proxy_name='proxy-example') +print(f"\nDBProxy 'proxy-example' description: {description}\n") +end_description_date_time = datetime.now() +print(f"{end_description_date_time} DBProxy 'proxy-example' described successfully!") +print(f"Total description time: {end_description_date_time - start_description_date_time}") +time.sleep(time_to_sleep) + + +print("\n---------------------Modify DBProxy----------------------") +start_modification_date_time = datetime.now() +print(f"{start_modification_date_time} going to modify db DBProxy 'proxy-example'") +proxy_controller.modify_db_proxy(db_proxy_name='proxy-example',engine_family='POSTGRESQL',) +end_modification_date_time = datetime.now() +print(f"{end_modification_date_time} DBProxy 'proxy-example' modified successfully!") +print(f"Total modification time: {end_modification_date_time - start_modification_date_time}") +time.sleep(time_to_sleep) + + +print("\n---------------------Describe Modified DBProxy----------------------") +start_description_date_time = datetime.now() +print(f"{start_description_date_time} going to describe db DBProxy 'proxy-example' after modification") +description = proxy_controller.describe_db_proxy(db_proxy_name='proxy-example') +print(f"\nDBProxy 'proxy-example' description after modification: {description}\n") +end_description_date_time = datetime.now() +print(f"{end_description_date_time} DBProxy 'proxy-example' described successfully") +print(f"Total description time: {end_description_date_time - start_description_date_time}") +time.sleep(time_to_sleep) + + +print("\n---------------------Get DBProxy----------------------") +start_get_date_time = datetime.now() +print(f"{start_get_date_time} going to get db DBProxy 'proxy-example'") +proxy_controller.get(db_proxy_name='proxy-example') +end_get_date_time = datetime.now() +print(f"{end_get_date_time} DBProxy 'proxy-example' get successfully") +print(f"Total get time: {end_get_date_time - start_get_date_time}") +time.sleep(time_to_sleep) + + +print("\n---------------------Delete DBProxy----------------------") +start_deletion_date_time = datetime.now() +print(f"{start_deletion_date_time} going to delete db DBProxy 'proxy-example'") +proxy_controller.delete_db_proxy(db_proxy_name='proxy-example') +end_deletion_date_time = datetime.now() +print(f"{end_deletion_date_time} DBProxy 'proxy-example' deleted successfully") +print(f"Total deletion time: {end_deletion_date_time - start_deletion_date_time}") +time.sleep(time_to_sleep) + + +print("\n---------------------End Of session----------------------") +end_integration_date_time = datetime.now() +print(f"{end_integration_date_time} demonstration of object DBProxy ended successfully") +print(f"Total integration time: {end_integration_date_time - start_integration_date_time}") +time.sleep(time_to_sleep) diff --git a/DB/NEW_KT_DB/Service/Classes/DBProxyService.py b/DB/NEW_KT_DB/Service/Classes/DBProxyService.py index f224e2dc..02f8e6bb 100644 --- a/DB/NEW_KT_DB/Service/Classes/DBProxyService.py +++ b/DB/NEW_KT_DB/Service/Classes/DBProxyService.py @@ -2,6 +2,7 @@ from ...DataAccess.DBProxyManager import DBProxyManager from DB.NEW_KT_DB.Models.DBProxyModel import DBProxy from Storage.NEW_KT_Storage.DataAccess.StorageManager import StorageManager +from ...Validation.GeneralValidations import validate_tags_structure from ...Validation.DBProxyValidations import * from ...Exceptions.DBProxyExceptions import * from datetime import datetime @@ -46,7 +47,7 @@ def create(self, **attributes): validate_db_proxy_name(attributes.get('db_proxy_name')) # Validate tags if provided - if 'tags' in attributes and not validate_tags(attributes.get('tags')): + if 'tags' in attributes and not validate_tags_structure(attributes.get('tags')): raise ValueError("Tags not valid!") # Check if the proxy already exists @@ -156,7 +157,7 @@ def get(self, db_proxy_name): Returns: DBProxy: A DBProxy object with the stored attributes. """ - path = 'DB\\Proxies\\' + db_proxy_name + '.json' + path = db_proxy_name + '.json' content = self.storage_manager.get_file_content(path) dict_content = json.loads(content) return DBProxy(**dict_content)