From 127d073b2521653ea7e6361af0cddfc7ecd645f9 Mon Sep 17 00:00:00 2001 From: teo Date: Fri, 6 Sep 2024 16:58:11 +0300 Subject: [PATCH 01/13] remove get_service_method --- packages/syft/src/syft/client/client.py | 3 +- packages/syft/src/syft/server/routes.py | 9 ++---- packages/syft/src/syft/server/server.py | 13 +++----- packages/syft/src/syft/service/api/api.py | 5 +-- .../syft/service/code/user_code_service.py | 8 ++--- .../data_subject/data_subject_service.py | 6 +--- .../syft/src/syft/service/dataset/dataset.py | 3 +- .../syft/service/network/network_service.py | 18 +++-------- .../syft/service/project/project_service.py | 3 +- .../syft/src/syft/service/request/request.py | 3 +- .../syft/service/request/request_service.py | 32 ++++--------------- .../src/syft/service/user/user_service.py | 15 +++------ .../service/worker/worker_pool_service.py | 6 ++-- 13 files changed, 31 insertions(+), 93 deletions(-) diff --git a/packages/syft/src/syft/client/client.py b/packages/syft/src/syft/client/client.py index 093dee625db..ff1d7625387 100644 --- a/packages/syft/src/syft/client/client.py +++ b/packages/syft/src/syft/client/client.py @@ -615,8 +615,7 @@ def register(self, new_user: UserCreate) -> SyftSigningKey | None: ) else: service_context = ServerServiceContext(server=self.server) - method = self.server.get_service_method(UserService.register) - response = method(context=service_context, new_user=new_user) + response = self.server.services.user.register(context=service_context, new_user=new_user) response = post_process_result(response, unwrap_on_success=False) return response diff --git a/packages/syft/src/syft/server/routes.py b/packages/syft/src/syft/server/routes.py index ec5bedd6d01..f32527242b0 100644 --- a/packages/syft/src/syft/server/routes.py +++ b/packages/syft/src/syft/server/routes.py @@ -168,9 +168,8 @@ def syft_new_api_call( def handle_forgot_password(email: str, server: AbstractServer) -> Response: try: - method = server.get_service_method(UserService.forgot_password) context = UnauthedServiceContext(server=server) - result = method(context=context, email=email) + result = server.services.user.forgot_password(context=context, email=email) except SyftException as e: result = SyftError.from_public_exception(e) @@ -186,9 +185,8 @@ def handle_reset_password( token: str, new_password: str, server: AbstractServer ) -> Response: try: - method = server.get_service_method(UserService.reset_password) context = UnauthedServiceContext(server=server) - result = method(context=context, token=token, new_password=new_password) + result = server.services.user.reset_password(context=context, token=token, new_password=new_password) except SyftException as e: result = SyftError.from_public_exception(e) @@ -206,12 +204,11 @@ def handle_login(email: str, password: str, server: AbstractServer) -> Response: except ValidationError as e: return {"Error": e.json()} - method = server.get_service_method(UserService.exchange_credentials) context = UnauthedServiceContext( server=server, login_credentials=login_credentials ) try: - result = method(context=context).value + result = server.services.user.exchange_credentials(context=context).value if not isinstance(result, UserPrivateKey): response = SyftError(message=f"Incorrect return type: {type(result)}") else: diff --git a/packages/syft/src/syft/server/server.py b/packages/syft/src/syft/server/server.py index 102b34ad99a..7393594da56 100644 --- a/packages/syft/src/syft/server/server.py +++ b/packages/syft/src/syft/server/server.py @@ -1266,7 +1266,7 @@ def handle_api_call_with_unsigned_result( try: logger.info(f"API Call: {api_call}") - result = method(context, *api_call.args, **api_call.kwargs) + result = self.services(context, *api_call.args, **api_call.kwargs) if isinstance(result, SyftError): raise TypeError( @@ -1835,9 +1835,8 @@ def create_default_worker_pool(server: Server) -> None: if not default_image.is_built: logger.info(f"Building default worker image with tag={default_worker_tag}. ") - image_build_method = server.get_service_method(SyftWorkerImageService.build) # Build the Image for given tag - result = image_build_method( + result = server.services.worker_image.build( context, image_uid=default_image.id, tag=DEFAULT_WORKER_IMAGE_TAG, @@ -1854,8 +1853,7 @@ def create_default_worker_pool(server: Server) -> None: ) if default_worker_pool is None: worker_to_add_ = worker_count - create_pool_method = server.get_service_method(SyftWorkerPoolService.launch) - result = create_pool_method( + result = server.services.worker_pool.launch( context, pool_name=default_pool_name, image_uid=default_image.id, @@ -1869,10 +1867,7 @@ def create_default_worker_pool(server: Server) -> None: default_worker_pool.worker_list ) if worker_to_add_ > 0: - add_worker_method = server.get_service_method( - SyftWorkerPoolService.add_workers - ) - result = add_worker_method( + result = server.services.worker_pool.add_workers( context=context, number=worker_to_add_, pool_name=default_pool_name, diff --git a/packages/syft/src/syft/service/api/api.py b/packages/syft/src/syft/service/api/api.py index 82881ef99d3..3e8eabe62c1 100644 --- a/packages/syft/src/syft/service/api/api.py +++ b/packages/syft/src/syft/service/api/api.py @@ -506,10 +506,7 @@ def get_user_client_from_server(self, context: AuthedServiceContext) -> SyftClie # get a user client guest_client = context.server.get_guest_client() user_client = guest_client - signing_key_for_verify_key = context.server.get_service_method( - UserService.signing_key_for_verify_key - ) - private_key = signing_key_for_verify_key(context.credentials) + private_key = context.server.services.user.signing_key_for_verify_key(context.credentials) signing_key = private_key.signing_key user_client.credentials = signing_key return user_client diff --git a/packages/syft/src/syft/service/code/user_code_service.py b/packages/syft/src/syft/service/code/user_code_service.py index 696f961932c..013c110780b 100644 --- a/packages/syft/src/syft/service/code/user_code_service.py +++ b/packages/syft/src/syft/service/code/user_code_service.py @@ -225,11 +225,8 @@ def _request_code_execution( reason: str | None = "", ) -> Request: # Cannot make multiple requests for the same code - get_by_usercode_id = context.server.get_service_method( - RequestService.get_by_usercode_id - ) # FIX: Change requestservice result type - existing_requests = get_by_usercode_id(context, user_code.id) + existing_requests = context.server.services.request.get_by_usercode_id(context, user_code.id) if len(existing_requests) > 0: raise SyftException( @@ -266,8 +263,7 @@ def _request_code_execution( changes = [status_change] request = SubmitRequest(changes=changes) - method = context.server.get_service_method(RequestService.submit) - result = method(context=context, request=request, reason=reason) + result = context.server.services.request.submit(context=context, request=request, reason=reason) return result diff --git a/packages/syft/src/syft/service/data_subject/data_subject_service.py b/packages/syft/src/syft/service/data_subject/data_subject_service.py index b386fd1ec8d..2ef703140fa 100644 --- a/packages/syft/src/syft/service/data_subject/data_subject_service.py +++ b/packages/syft/src/syft/service/data_subject/data_subject_service.py @@ -100,11 +100,7 @@ def get_all(self, context: AuthedServiceContext) -> list[DataSubject]: def get_members( self, context: AuthedServiceContext, data_subject_name: str ) -> list[DataSubject]: - get_relatives = context.server.get_service_method( - DataSubjectMemberService.get_relatives - ) - - relatives = get_relatives(context, data_subject_name) + relatives = context.server.services.data_subject.get_relatives(context, data_subject_name) members = [] for relative in relatives: diff --git a/packages/syft/src/syft/service/dataset/dataset.py b/packages/syft/src/syft/service/dataset/dataset.py index 22a8b09c462..55b851beb0a 100644 --- a/packages/syft/src/syft/service/dataset/dataset.py +++ b/packages/syft/src/syft/service/dataset/dataset.py @@ -795,10 +795,9 @@ def set_data_subjects(context: TransformContext) -> TransformContext: public_message="f{context}'s server is None, please log in. No trasformation happened" ) data_subjects = context.output["data_subjects"] - get_data_subject = context.server.get_service_method(DataSubjectService.get_by_name) resultant_data_subjects = [] for data_subject in data_subjects: - result = get_data_subject(context=context, name=data_subject.name) + result = context.server.services.data_subject.get_by_name(context=context, name=data_subject.name) resultant_data_subjects.append(result) context.output["data_subjects"] = resultant_data_subjects return context diff --git a/packages/syft/src/syft/service/network/network_service.py b/packages/syft/src/syft/service/network/network_service.py index 5e4dfdbadf4..189e564576e 100644 --- a/packages/syft/src/syft/service/network/network_service.py +++ b/packages/syft/src/syft/service/network/network_service.py @@ -347,16 +347,12 @@ def add_peer( changes=[association_request_change], requesting_user_verify_key=context.credentials, ) - request_submit_method = context.server.get_service_method(RequestService.submit) - request = request_submit_method(context, submit_request) + request = context.server.services.request.submit(context, submit_request) if ( isinstance(request, Request) and context.server.settings.association_request_auto_approval ): - request_apply_method = context.server.get_service_method( - RequestService.apply - ) - return request_apply_method(context, uid=request.id) + return context.server.services.request.apply(context, uid=request.id) return request @@ -519,10 +515,7 @@ def delete_peer_by_id(self, context: AuthedServiceContext, uid: UID) -> SyftSucc context=context, peer_id=uid ) for request in association_requests: - request_delete_method = context.server.get_service_method( - RequestService.delete_by_uid - ) - request_delete_method(context, request.id) + context.server.services.request.delete_by_uid(context, request.id) # TODO: Notify the peer (either by email or by other form of notifications) # that it has been deleted from the network return SyftSuccess(message=f"Server Peer with id {uid} deleted.") @@ -860,10 +853,7 @@ def _get_association_requests_by_peer_id( """ Get all the association requests from a peer. The association requests are sorted by request_time. """ - request_get_all_method: Callable = context.server.get_service_method( - RequestService.get_all - ) - all_requests: list[Request] = request_get_all_method(context) + all_requests: list[Request] = context.server.services.request.get_all(context) association_requests: list[Request] = [ request for request in all_requests diff --git a/packages/syft/src/syft/service/project/project_service.py b/packages/syft/src/syft/service/project/project_service.py index 30af109ee09..39c7d97d419 100644 --- a/packages/syft/src/syft/service/project/project_service.py +++ b/packages/syft/src/syft/service/project/project_service.py @@ -388,8 +388,7 @@ def check_for_project_request( ) # TODO: Update noteificationservice result - method = context.server.get_service_method(NotificationService.send) - result = method(context=context, notification=message) + result = context.server.services.notifications.send(context=context, notification=message) if isinstance(result, SyftError): raise SyftException(public_message=result) diff --git a/packages/syft/src/syft/service/request/request.py b/packages/syft/src/syft/service/request/request.py index 437a160c728..e8cf324d5d3 100644 --- a/packages/syft/src/syft/service/request/request.py +++ b/packages/syft/src/syft/service/request/request.py @@ -703,8 +703,7 @@ def save(self, context: AuthedServiceContext) -> SyftSuccess: # relative from .request_service import RequestService - save_method = context.server.get_service_method(RequestService.save) - return save_method(context=context, request=self) + return context.server.services.request.save(context=context, request=self) def _create_action_object_for_deposited_result( self, diff --git a/packages/syft/src/syft/service/request/request_service.py b/packages/syft/src/syft/service/request/request_service.py index 5c2859331b4..d10afb1e411 100644 --- a/packages/syft/src/syft/service/request/request_service.py +++ b/packages/syft/src/syft/service/request/request_service.py @@ -62,10 +62,7 @@ def submit( request, ).unwrap() - admin_verify_key = context.server.get_service_method( - UserService.admin_verify_key - ) - root_verify_key = admin_verify_key() + root_verify_key = context.server.services.user.admin_verify_key() if send_message: message_subject = f"Result to request {str(request.id)[:4]}...{str(request.id)[-3:]}\ @@ -158,18 +155,10 @@ def get_all_info( ) -> list[list[RequestInfo]] | list[RequestInfo]: """Get the information of all requests""" result = self.stash.get_all(context.credentials).unwrap() - - get_user_by_verify_key = context.server.get_service_method( - UserService.get_by_verify_key - ) - get_message = context.server.get_service_method( - NotificationService.filter_by_obj - ) - requests: list[RequestInfo] = [] for req in result: - user = get_user_by_verify_key(req.requesting_user_verify_key).to(UserView) - message = get_message(context=context, obj_uid=req.id).unwrap() + user = context.server.services.user.get_by_verify_key(req.requesting_user_verify_key).to(UserView) + message = context.server.services.notifications.filter_by_obj(context=context, obj_uid=req.id).unwrap() requests.append(RequestInfo(user=user, request=req, notification=message)) if not page_size: return requests @@ -231,18 +220,11 @@ def apply( context.extra_kwargs = kwargs result = request.apply(context=context).unwrap() - - filter_by_obj = context.server.get_service_method( - NotificationService.filter_by_obj - ) - request_notification = filter_by_obj(context=context, obj_uid=uid).unwrap() + request_notification = context.server.services.notifications.filter_by_obj(context=context, obj_uid=uid).unwrap() if not request.get_status(context) == RequestStatus.PENDING: if request_notification is not None: - mark_as_read = context.server.get_service_method( - NotificationService.mark_as_read - ) - mark_as_read(context=context, uid=request_notification.id) + context.server.services.notifications.mark_as_read(context=context, uid=request_notification.id) self._send_email_notification( context=context, @@ -272,9 +254,7 @@ def _send_email_notification( notifier_types=[NOTIFIERS.EMAIL], email_template=email_template, ) - - send_notification = context.server.get_service_method(NotificationService.send) - send_notification(context=context, notification=notification) + context.server.sercices.notifications.send(context=context, notification=notification) @service_method(path="request.undo", name="undo", unwrap_on_success=False) def undo(self, context: AuthedServiceContext, uid: UID, reason: str) -> SyftSuccess: diff --git a/packages/syft/src/syft/service/user/user_service.py b/packages/syft/src/syft/service/user/user_service.py index c276ea08cb0..52f944b45ef 100644 --- a/packages/syft/src/syft/service/user/user_service.py +++ b/packages/syft/src/syft/service/user/user_service.py @@ -183,10 +183,7 @@ def forgot_password( to_user_verify_key=user.verify_key, linked_obj=link, ) - - method = root_context.server.get_service_method(NotificationService.send) - result = method(context=root_context, notification=message) - + result = root_context.server.services.notifications.send(context=root_context, notification=message) message = CreateNotification( subject="User requested password reset.", from_user_verify_key=user.verify_key, @@ -194,7 +191,7 @@ def forgot_password( linked_obj=link, ) - result = method(context=root_context, notification=message) + result = root_context.server.services.notifications.send(context=root_context, notification=message) else: # Email notification is Enabled # Therefore, we can directly send a message to the @@ -207,9 +204,7 @@ def forgot_password( notifier_types=[NOTIFIERS.EMAIL], email_template=PasswordResetTemplate, ) - - method = root_context.server.get_service_method(NotificationService.send) - result = method(context=root_context, notification=message) + result = root_context.server.services.notifications.send(context=root_context, notification=message) return SyftSuccess(message=success_msg) @@ -630,9 +625,7 @@ def register( notifier_types=[NOTIFIERS.EMAIL], email_template=OnBoardEmailTemplate, ) - - method = context.server.get_service_method(NotificationService.send) - method(context=root_context, notification=message) + context.server.notifications.send(context=root_context, notification=message) if request_user_role in DATA_OWNER_ROLE_LEVEL: success_message += " To see users, run `[your_client].users`" diff --git a/packages/syft/src/syft/service/worker/worker_pool_service.py b/packages/syft/src/syft/service/worker/worker_pool_service.py index dc4885e5077..28b098cb227 100644 --- a/packages/syft/src/syft/service/worker/worker_pool_service.py +++ b/packages/syft/src/syft/service/worker/worker_pool_service.py @@ -215,8 +215,7 @@ def create_pool_request( # Create a the request object with the changes and submit it # for approval. request = SubmitRequest(changes=changes) - method = context.server.get_service_method(RequestService.submit) - return method(context=context, request=request, reason=reason) + return context.server.services.request.submit(context=context, request=request, reason=reason) @service_method( path="worker_pool.create_image_and_pool_request", @@ -319,8 +318,7 @@ def create_image_and_pool_request( # Create a request object and submit a request for approval request = SubmitRequest(changes=changes) - method = context.server.get_service_method(RequestService.submit) - return method(context=context, request=request, reason=reason) + return context.server.services.request.submit(context=context, request=request, reason=reason) @service_method( path="worker_pool.get_all", From c145e4da294a7337eaaecba49c49f620e1867124 Mon Sep 17 00:00:00 2001 From: teo Date: Fri, 6 Sep 2024 17:02:21 +0300 Subject: [PATCH 02/13] fix lint --- packages/syft/src/syft/client/client.py | 4 +++- packages/syft/src/syft/server/routes.py | 4 +++- packages/syft/src/syft/server/server.py | 2 +- packages/syft/src/syft/service/api/api.py | 5 +++-- .../syft/service/code/user_code_service.py | 9 +++++--- .../data_subject/data_subject_service.py | 4 +++- .../syft/src/syft/service/dataset/dataset.py | 5 +++-- .../syft/service/network/network_service.py | 1 - .../syft/service/project/project_service.py | 5 +++-- .../syft/src/syft/service/request/request.py | 1 - .../syft/service/request/request_service.py | 22 +++++++++++++------ .../src/syft/service/user/user_service.py | 13 +++++++---- .../service/worker/worker_pool_service.py | 9 +++++--- 13 files changed, 55 insertions(+), 29 deletions(-) diff --git a/packages/syft/src/syft/client/client.py b/packages/syft/src/syft/client/client.py index ff1d7625387..692bd017565 100644 --- a/packages/syft/src/syft/client/client.py +++ b/packages/syft/src/syft/client/client.py @@ -615,7 +615,9 @@ def register(self, new_user: UserCreate) -> SyftSigningKey | None: ) else: service_context = ServerServiceContext(server=self.server) - response = self.server.services.user.register(context=service_context, new_user=new_user) + response = self.server.services.user.register( + context=service_context, new_user=new_user + ) response = post_process_result(response, unwrap_on_success=False) return response diff --git a/packages/syft/src/syft/server/routes.py b/packages/syft/src/syft/server/routes.py index f32527242b0..7fead9ac393 100644 --- a/packages/syft/src/syft/server/routes.py +++ b/packages/syft/src/syft/server/routes.py @@ -186,7 +186,9 @@ def handle_reset_password( ) -> Response: try: context = UnauthedServiceContext(server=server) - result = server.services.user.reset_password(context=context, token=token, new_password=new_password) + result = server.services.user.reset_password( + context=context, token=token, new_password=new_password + ) except SyftException as e: result = SyftError.from_public_exception(e) diff --git a/packages/syft/src/syft/server/server.py b/packages/syft/src/syft/server/server.py index 7393594da56..c44c2f11b9a 100644 --- a/packages/syft/src/syft/server/server.py +++ b/packages/syft/src/syft/server/server.py @@ -1266,7 +1266,7 @@ def handle_api_call_with_unsigned_result( try: logger.info(f"API Call: {api_call}") - result = self.services(context, *api_call.args, **api_call.kwargs) + result = method(context, *api_call.args, **api_call.kwargs) if isinstance(result, SyftError): raise TypeError( diff --git a/packages/syft/src/syft/service/api/api.py b/packages/syft/src/syft/service/api/api.py index 3e8eabe62c1..a5f95867534 100644 --- a/packages/syft/src/syft/service/api/api.py +++ b/packages/syft/src/syft/service/api/api.py @@ -37,7 +37,6 @@ from ..context import AuthedServiceContext from ..response import SyftError from ..user.user import UserView -from ..user.user_service import UserService from .utils import print as log_print NOT_ACCESSIBLE_STRING = "N / A" @@ -506,7 +505,9 @@ def get_user_client_from_server(self, context: AuthedServiceContext) -> SyftClie # get a user client guest_client = context.server.get_guest_client() user_client = guest_client - private_key = context.server.services.user.signing_key_for_verify_key(context.credentials) + private_key = context.server.services.user.signing_key_for_verify_key( + context.credentials + ) signing_key = private_key.signing_key user_client.credentials = signing_key return user_client diff --git a/packages/syft/src/syft/service/code/user_code_service.py b/packages/syft/src/syft/service/code/user_code_service.py index 013c110780b..1d7b4e736e6 100644 --- a/packages/syft/src/syft/service/code/user_code_service.py +++ b/packages/syft/src/syft/service/code/user_code_service.py @@ -26,7 +26,6 @@ from ..request.request import SubmitRequest from ..request.request import SyncedUserCodeStatusChange from ..request.request import UserCodeStatusChange -from ..request.request_service import RequestService from ..response import SyftSuccess from ..service import AbstractService from ..service import SERVICE_TO_TYPES @@ -226,7 +225,9 @@ def _request_code_execution( ) -> Request: # Cannot make multiple requests for the same code # FIX: Change requestservice result type - existing_requests = context.server.services.request.get_by_usercode_id(context, user_code.id) + existing_requests = context.server.services.request.get_by_usercode_id( + context, user_code.id + ) if len(existing_requests) > 0: raise SyftException( @@ -263,7 +264,9 @@ def _request_code_execution( changes = [status_change] request = SubmitRequest(changes=changes) - result = context.server.services.request.submit(context=context, request=request, reason=reason) + result = context.server.services.request.submit( + context=context, request=request, reason=reason + ) return result diff --git a/packages/syft/src/syft/service/data_subject/data_subject_service.py b/packages/syft/src/syft/service/data_subject/data_subject_service.py index 2ef703140fa..9106386ef63 100644 --- a/packages/syft/src/syft/service/data_subject/data_subject_service.py +++ b/packages/syft/src/syft/service/data_subject/data_subject_service.py @@ -100,7 +100,9 @@ def get_all(self, context: AuthedServiceContext) -> list[DataSubject]: def get_members( self, context: AuthedServiceContext, data_subject_name: str ) -> list[DataSubject]: - relatives = context.server.services.data_subject.get_relatives(context, data_subject_name) + relatives = context.server.services.data_subject.get_relatives( + context, data_subject_name + ) members = [] for relative in relatives: diff --git a/packages/syft/src/syft/service/dataset/dataset.py b/packages/syft/src/syft/service/dataset/dataset.py index 55b851beb0a..600e3dfcb62 100644 --- a/packages/syft/src/syft/service/dataset/dataset.py +++ b/packages/syft/src/syft/service/dataset/dataset.py @@ -40,7 +40,6 @@ from ..action.action_object import ActionObject from ..data_subject.data_subject import DataSubject from ..data_subject.data_subject import DataSubjectCreate -from ..data_subject.data_subject_service import DataSubjectService from ..response import SyftError from ..response import SyftSuccess from ..response import SyftWarning @@ -797,7 +796,9 @@ def set_data_subjects(context: TransformContext) -> TransformContext: data_subjects = context.output["data_subjects"] resultant_data_subjects = [] for data_subject in data_subjects: - result = context.server.services.data_subject.get_by_name(context=context, name=data_subject.name) + result = context.server.services.data_subject.get_by_name( + context=context, name=data_subject.name + ) resultant_data_subjects.append(result) context.output["data_subjects"] = resultant_data_subjects return context diff --git a/packages/syft/src/syft/service/network/network_service.py b/packages/syft/src/syft/service/network/network_service.py index 189e564576e..428501fb92d 100644 --- a/packages/syft/src/syft/service/network/network_service.py +++ b/packages/syft/src/syft/service/network/network_service.py @@ -41,7 +41,6 @@ from ..request.request import Request from ..request.request import RequestStatus from ..request.request import SubmitRequest -from ..request.request_service import RequestService from ..response import SyftInfo from ..response import SyftSuccess from ..service import AbstractService diff --git a/packages/syft/src/syft/service/project/project_service.py b/packages/syft/src/syft/service/project/project_service.py index 39c7d97d419..713a001d0fc 100644 --- a/packages/syft/src/syft/service/project/project_service.py +++ b/packages/syft/src/syft/service/project/project_service.py @@ -14,7 +14,6 @@ from ...types.uid import UID from ..context import AuthedServiceContext from ..network.network_service import NetworkService -from ..notification.notification_service import NotificationService from ..notification.notifications import CreateNotification from ..response import SyftError from ..response import SyftSuccess @@ -388,7 +387,9 @@ def check_for_project_request( ) # TODO: Update noteificationservice result - result = context.server.services.notifications.send(context=context, notification=message) + result = context.server.services.notifications.send( + context=context, notification=message + ) if isinstance(result, SyftError): raise SyftException(public_message=result) diff --git a/packages/syft/src/syft/service/request/request.py b/packages/syft/src/syft/service/request/request.py index e8cf324d5d3..717c1ceb7c5 100644 --- a/packages/syft/src/syft/service/request/request.py +++ b/packages/syft/src/syft/service/request/request.py @@ -701,7 +701,6 @@ def undo(self, context: AuthedServiceContext) -> SyftSuccess: def save(self, context: AuthedServiceContext) -> SyftSuccess: # relative - from .request_service import RequestService return context.server.services.request.save(context=context, request=self) diff --git a/packages/syft/src/syft/service/request/request_service.py b/packages/syft/src/syft/service/request/request_service.py index d10afb1e411..a6285d24d29 100644 --- a/packages/syft/src/syft/service/request/request_service.py +++ b/packages/syft/src/syft/service/request/request_service.py @@ -14,7 +14,6 @@ from ..notification.email_templates import RequestEmailTemplate from ..notification.email_templates import RequestUpdateEmailTemplate from ..notification.notification_service import CreateNotification -from ..notification.notification_service import NotificationService from ..notifier.notifier_enums import NOTIFIERS from ..notifier.notifier_service import RateLimitException from ..response import SyftSuccess @@ -26,7 +25,6 @@ from ..user.user_roles import ADMIN_ROLE_LEVEL from ..user.user_roles import DATA_SCIENTIST_ROLE_LEVEL from ..user.user_roles import GUEST_ROLE_LEVEL -from ..user.user_service import UserService from .request import Change from .request import Request from .request import RequestInfo @@ -157,8 +155,12 @@ def get_all_info( result = self.stash.get_all(context.credentials).unwrap() requests: list[RequestInfo] = [] for req in result: - user = context.server.services.user.get_by_verify_key(req.requesting_user_verify_key).to(UserView) - message = context.server.services.notifications.filter_by_obj(context=context, obj_uid=req.id).unwrap() + user = context.server.services.user.get_by_verify_key( + req.requesting_user_verify_key + ).to(UserView) + message = context.server.services.notifications.filter_by_obj( + context=context, obj_uid=req.id + ).unwrap() requests.append(RequestInfo(user=user, request=req, notification=message)) if not page_size: return requests @@ -220,11 +222,15 @@ def apply( context.extra_kwargs = kwargs result = request.apply(context=context).unwrap() - request_notification = context.server.services.notifications.filter_by_obj(context=context, obj_uid=uid).unwrap() + request_notification = context.server.services.notifications.filter_by_obj( + context=context, obj_uid=uid + ).unwrap() if not request.get_status(context) == RequestStatus.PENDING: if request_notification is not None: - context.server.services.notifications.mark_as_read(context=context, uid=request_notification.id) + context.server.services.notifications.mark_as_read( + context=context, uid=request_notification.id + ) self._send_email_notification( context=context, @@ -254,7 +260,9 @@ def _send_email_notification( notifier_types=[NOTIFIERS.EMAIL], email_template=email_template, ) - context.server.sercices.notifications.send(context=context, notification=notification) + context.server.sercices.notifications.send( + context=context, notification=notification + ) @service_method(path="request.undo", name="undo", unwrap_on_success=False) def undo(self, context: AuthedServiceContext, uid: UID, reason: str) -> SyftSuccess: diff --git a/packages/syft/src/syft/service/user/user_service.py b/packages/syft/src/syft/service/user/user_service.py index 52f944b45ef..927ec4fc7a1 100644 --- a/packages/syft/src/syft/service/user/user_service.py +++ b/packages/syft/src/syft/service/user/user_service.py @@ -28,7 +28,6 @@ from ..notification.email_templates import OnBoardEmailTemplate from ..notification.email_templates import PasswordResetTemplate from ..notification.notification_service import CreateNotification -from ..notification.notification_service import NotificationService from ..notifier.notifier_enums import NOTIFIERS from ..response import SyftSuccess from ..service import AbstractService @@ -183,7 +182,9 @@ def forgot_password( to_user_verify_key=user.verify_key, linked_obj=link, ) - result = root_context.server.services.notifications.send(context=root_context, notification=message) + result = root_context.server.services.notifications.send( + context=root_context, notification=message + ) message = CreateNotification( subject="User requested password reset.", from_user_verify_key=user.verify_key, @@ -191,7 +192,9 @@ def forgot_password( linked_obj=link, ) - result = root_context.server.services.notifications.send(context=root_context, notification=message) + result = root_context.server.services.notifications.send( + context=root_context, notification=message + ) else: # Email notification is Enabled # Therefore, we can directly send a message to the @@ -204,7 +207,9 @@ def forgot_password( notifier_types=[NOTIFIERS.EMAIL], email_template=PasswordResetTemplate, ) - result = root_context.server.services.notifications.send(context=root_context, notification=message) + result = root_context.server.services.notifications.send( + context=root_context, notification=message + ) return SyftSuccess(message=success_msg) diff --git a/packages/syft/src/syft/service/worker/worker_pool_service.py b/packages/syft/src/syft/service/worker/worker_pool_service.py index 28b098cb227..09964dba1f2 100644 --- a/packages/syft/src/syft/service/worker/worker_pool_service.py +++ b/packages/syft/src/syft/service/worker/worker_pool_service.py @@ -27,7 +27,6 @@ from ..request.request import CreateCustomWorkerPoolChange from ..request.request import Request from ..request.request import SubmitRequest -from ..request.request_service import RequestService from ..response import SyftSuccess from ..service import AbstractService from ..service import SERVICE_TO_TYPES @@ -215,7 +214,9 @@ def create_pool_request( # Create a the request object with the changes and submit it # for approval. request = SubmitRequest(changes=changes) - return context.server.services.request.submit(context=context, request=request, reason=reason) + return context.server.services.request.submit( + context=context, request=request, reason=reason + ) @service_method( path="worker_pool.create_image_and_pool_request", @@ -318,7 +319,9 @@ def create_image_and_pool_request( # Create a request object and submit a request for approval request = SubmitRequest(changes=changes) - return context.server.services.request.submit(context=context, request=request, reason=reason) + return context.server.services.request.submit( + context=context, request=request, reason=reason + ) @service_method( path="worker_pool.get_all", From 4748858c3d7e490839f9a605f272afc7ff4ffc69 Mon Sep 17 00:00:00 2001 From: teo Date: Mon, 9 Sep 2024 10:00:24 +0300 Subject: [PATCH 03/13] fix naming --- packages/syft/src/syft/server/server.py | 4 ++-- packages/syft/src/syft/service/project/project_service.py | 2 +- packages/syft/src/syft/service/request/request_service.py | 8 ++++---- packages/syft/src/syft/service/settings/settings.py | 2 +- packages/syft/src/syft/service/user/user_service.py | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/syft/src/syft/server/server.py b/packages/syft/src/syft/server/server.py index c44c2f11b9a..267e1c200d2 100644 --- a/packages/syft/src/syft/server/server.py +++ b/packages/syft/src/syft/server/server.py @@ -1853,7 +1853,7 @@ def create_default_worker_pool(server: Server) -> None: ) if default_worker_pool is None: worker_to_add_ = worker_count - result = server.services.worker_pool.launch( + result = server.services.syft_worker_pool.launch( context, pool_name=default_pool_name, image_uid=default_image.id, @@ -1867,7 +1867,7 @@ def create_default_worker_pool(server: Server) -> None: default_worker_pool.worker_list ) if worker_to_add_ > 0: - result = server.services.worker_pool.add_workers( + result = server.services.syft_worker_pool.add_workers( context=context, number=worker_to_add_, pool_name=default_pool_name, diff --git a/packages/syft/src/syft/service/project/project_service.py b/packages/syft/src/syft/service/project/project_service.py index 713a001d0fc..98fc2a3fcef 100644 --- a/packages/syft/src/syft/service/project/project_service.py +++ b/packages/syft/src/syft/service/project/project_service.py @@ -387,7 +387,7 @@ def check_for_project_request( ) # TODO: Update noteificationservice result - result = context.server.services.notifications.send( + result = context.server.services.notification.send( context=context, notification=message ) if isinstance(result, SyftError): diff --git a/packages/syft/src/syft/service/request/request_service.py b/packages/syft/src/syft/service/request/request_service.py index a6285d24d29..835ee398958 100644 --- a/packages/syft/src/syft/service/request/request_service.py +++ b/packages/syft/src/syft/service/request/request_service.py @@ -158,7 +158,7 @@ def get_all_info( user = context.server.services.user.get_by_verify_key( req.requesting_user_verify_key ).to(UserView) - message = context.server.services.notifications.filter_by_obj( + message = context.server.services.notification.filter_by_obj( context=context, obj_uid=req.id ).unwrap() requests.append(RequestInfo(user=user, request=req, notification=message)) @@ -222,13 +222,13 @@ def apply( context.extra_kwargs = kwargs result = request.apply(context=context).unwrap() - request_notification = context.server.services.notifications.filter_by_obj( + request_notification = context.server.services.notification.filter_by_obj( context=context, obj_uid=uid ).unwrap() if not request.get_status(context) == RequestStatus.PENDING: if request_notification is not None: - context.server.services.notifications.mark_as_read( + context.server.services.notification.mark_as_read( context=context, uid=request_notification.id ) @@ -260,7 +260,7 @@ def _send_email_notification( notifier_types=[NOTIFIERS.EMAIL], email_template=email_template, ) - context.server.sercices.notifications.send( + context.server.services.notification.send( context=context, notification=notification ) diff --git a/packages/syft/src/syft/service/settings/settings.py b/packages/syft/src/syft/service/settings/settings.py index 52177507ab3..15323f17015 100644 --- a/packages/syft/src/syft/service/settings/settings.py +++ b/packages/syft/src/syft/service/settings/settings.py @@ -279,7 +279,7 @@ def _repr_html_(self) -> Any: # 2) .....settings().x_enabled # 3) .....user_settings().x - preferences = self._get_api().services.notifications.settings() + preferences = self._get_api().services.notification.settings() if not preferences: notification_print_str = "Create notification settings using enable_notifications from user_service" else: diff --git a/packages/syft/src/syft/service/user/user_service.py b/packages/syft/src/syft/service/user/user_service.py index 927ec4fc7a1..909621aae56 100644 --- a/packages/syft/src/syft/service/user/user_service.py +++ b/packages/syft/src/syft/service/user/user_service.py @@ -182,7 +182,7 @@ def forgot_password( to_user_verify_key=user.verify_key, linked_obj=link, ) - result = root_context.server.services.notifications.send( + result = root_context.server.services.notification.send( context=root_context, notification=message ) message = CreateNotification( @@ -192,7 +192,7 @@ def forgot_password( linked_obj=link, ) - result = root_context.server.services.notifications.send( + result = root_context.server.services.notification.send( context=root_context, notification=message ) else: @@ -207,7 +207,7 @@ def forgot_password( notifier_types=[NOTIFIERS.EMAIL], email_template=PasswordResetTemplate, ) - result = root_context.server.services.notifications.send( + result = root_context.server.services.notification.send( context=root_context, notification=message ) @@ -630,7 +630,7 @@ def register( notifier_types=[NOTIFIERS.EMAIL], email_template=OnBoardEmailTemplate, ) - context.server.notifications.send(context=root_context, notification=message) + context.server.services.notification.send(context=root_context, notification=message) if request_user_role in DATA_OWNER_ROLE_LEVEL: success_message += " To see users, run `[your_client].users`" From b38c56d92fe042d2c97d93bfd8766944f7f97329 Mon Sep 17 00:00:00 2001 From: teo Date: Mon, 9 Sep 2024 10:04:41 +0300 Subject: [PATCH 04/13] fix lint --- packages/syft/src/syft/service/user/user_service.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/syft/src/syft/service/user/user_service.py b/packages/syft/src/syft/service/user/user_service.py index 909621aae56..fd8874f3107 100644 --- a/packages/syft/src/syft/service/user/user_service.py +++ b/packages/syft/src/syft/service/user/user_service.py @@ -630,7 +630,9 @@ def register( notifier_types=[NOTIFIERS.EMAIL], email_template=OnBoardEmailTemplate, ) - context.server.services.notification.send(context=root_context, notification=message) + context.server.services.notification.send( + context=root_context, notification=message + ) if request_user_role in DATA_OWNER_ROLE_LEVEL: success_message += " To see users, run `[your_client].users`" From b1aa60868299186ab3ea21796c9fff3367d28f4b Mon Sep 17 00:00:00 2001 From: teo Date: Mon, 9 Sep 2024 10:10:16 +0300 Subject: [PATCH 05/13] fix notification name for api --- packages/syft/src/syft/service/settings/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/src/syft/service/settings/settings.py b/packages/syft/src/syft/service/settings/settings.py index 15323f17015..52177507ab3 100644 --- a/packages/syft/src/syft/service/settings/settings.py +++ b/packages/syft/src/syft/service/settings/settings.py @@ -279,7 +279,7 @@ def _repr_html_(self) -> Any: # 2) .....settings().x_enabled # 3) .....user_settings().x - preferences = self._get_api().services.notification.settings() + preferences = self._get_api().services.notifications.settings() if not preferences: notification_print_str = "Create notification settings using enable_notifications from user_service" else: From a99d8b416cdc228e5cfe4d9bb0464aad9a7d10a6 Mon Sep 17 00:00:00 2001 From: teo Date: Mon, 9 Sep 2024 12:46:31 +0300 Subject: [PATCH 06/13] remove get_service --- packages/syft/src/syft/server/routes.py | 3 +- packages/syft/src/syft/server/server.py | 51 ++++++---------- .../syft/service/action/action_endpoint.py | 8 +-- .../src/syft/service/action/action_object.py | 3 +- .../src/syft/service/action/action_service.py | 29 +++------- packages/syft/src/syft/service/api/api.py | 7 +-- .../syft/src/syft/service/api/api_service.py | 20 +++---- packages/syft/src/syft/service/api/utils.py | 3 +- .../syft/src/syft/service/code/user_code.py | 58 ++++--------------- .../syft/service/code/user_code_service.py | 26 +++------ .../code_history/code_history_service.py | 18 ++---- .../data_subject/data_subject_service.py | 9 +-- .../syft/src/syft/service/dataset/dataset.py | 3 +- .../syft/service/dataset/dataset_service.py | 5 +- .../syft/src/syft/service/job/job_service.py | 15 ++--- .../syft/src/syft/service/job/job_stash.py | 5 +- .../syft/service/metadata/metadata_service.py | 6 -- .../service/network/association_request.py | 11 +--- .../syft/src/syft/service/network/utils.py | 6 +- .../service/notification/email_templates.py | 4 +- .../notification/notification_service.py | 25 ++------ .../src/syft/service/notifier/notifier.py | 3 +- .../syft/service/notifier/notifier_service.py | 22 ++----- .../src/syft/service/output/output_service.py | 3 +- .../syft/src/syft/service/policy/policy.py | 17 ++---- .../syft/service/project/project_service.py | 13 ++--- .../src/syft/service/queue/zmq_producer.py | 8 +-- .../syft/src/syft/service/request/request.py | 30 ++++------ .../syft/service/settings/settings_service.py | 20 ++----- .../src/syft/service/sync/sync_service.py | 29 ++++------ .../src/syft/service/user/user_service.py | 3 +- .../service/worker/worker_image_service.py | 5 +- .../service/worker/worker_pool_service.py | 19 ++---- .../src/syft/service/worker/worker_service.py | 16 +---- packages/syft/tests/syft/action_test.py | 6 +- packages/syft/tests/syft/api_test.py | 2 +- .../syft/blob_storage/blob_storage_test.py | 10 ++-- .../syft/service/action/action_object_test.py | 2 +- .../service/action/action_service_test.py | 2 +- .../syft/tests/syft/users/user_code_test.py | 2 +- packages/syft/tests/syft/users/user_test.py | 2 +- packages/syft/tests/syft/worker_test.py | 2 +- 42 files changed, 161 insertions(+), 370 deletions(-) diff --git a/packages/syft/src/syft/server/routes.py b/packages/syft/src/syft/server/routes.py index 7fead9ac393..a492e999f8e 100644 --- a/packages/syft/src/syft/server/routes.py +++ b/packages/syft/src/syft/server/routes.py @@ -49,8 +49,7 @@ def _get_server_connection(peer_uid: UID) -> ServerConnection: # relative from ..service.network.server_peer import route_to_connection - network_service = worker.get_service("NetworkService") - peer = network_service.stash.get_by_uid(worker.verify_key, peer_uid).unwrap() + peer = worker.network.stash.get_by_uid(worker.verify_key, peer_uid).unwrap() peer_server_route = peer.pick_highest_priority_route() connection = route_to_connection(route=peer_server_route) return connection diff --git a/packages/syft/src/syft/server/server.py b/packages/syft/src/syft/server/server.py index 267e1c200d2..177c7184ec5 100644 --- a/packages/syft/src/syft/server/server.py +++ b/packages/syft/src/syft/server/server.py @@ -528,8 +528,7 @@ def init_blob_storage(self, config: BlobStorageConfig | None = None) -> None: from ..store.blob_storage.seaweedfs import SeaweedFSConfig if isinstance(config, SeaweedFSConfig) and self.signing_key: - blob_storage_service = self.get_service(BlobStorageService) - remote_profiles = blob_storage_service.remote_profile_stash.get_all( + remote_profiles = self.services.blob_storage.remote_profile_stash.get_all( credentials=self.signing_key.verify_key, has_permission=True ).unwrap() for remote_profile in remote_profiles: @@ -815,8 +814,7 @@ def find_and_migrate_data( credentials=self.verify_key, role=ServiceRole.ADMIN, ) - migration_service = self.get_service("migrationservice") - return migration_service.migrate_data(context, document_store_object_types) + return self.services.migration.migrate_data(context, document_store_object_types) @property def guest_client(self) -> SyftClient: @@ -868,11 +866,10 @@ def post_init(self) -> None: ) if "usercodeservice" in self.service_path_map: - user_code_service = self.get_service(UserCodeService) - user_code_service.load_user_code(context=context) + self.services.user_code.load_user_code(context=context) def reload_user_code() -> None: - user_code_service.load_user_code(context=context) + self.services.user_code.load_user_code(context=context) ti = thread_ident() if ti is not None: @@ -929,11 +926,11 @@ def init_stores( @property def job_stash(self) -> JobStash: - return self.get_service("jobservice").stash + return self.services.job.stash @property def worker_stash(self) -> WorkerStash: - return self.get_service("workerservice").stash + return self.services.worker.stash @property def service_path_map(self) -> dict[str, AbstractService]: @@ -1116,9 +1113,7 @@ def forward_message( ) client = None - - network_service = self.get_service(NetworkService) - peer = network_service.stash.get_by_uid(self.verify_key, server_uid).unwrap() + peer = self.services.network.stash.get_by_uid(self.verify_key, server_uid).unwrap() # Since we have several routes to a peer # we need to cache the client for a given server_uid along with the route @@ -1163,7 +1158,7 @@ def forward_message( def get_role_for_credentials(self, credentials: SyftVerifyKey) -> ServiceRole: return ( - self.get_service("userservice") + self.services.user .get_role_for_credentials(credentials=credentials) .unwrap() ) @@ -1413,10 +1408,7 @@ def add_action_to_queue( has_execute_permissions=has_execute_permissions, worker_pool=worker_pool_ref, # set worker pool reference as part of queue item ) - - user_service = self.get_service("UserService") - user_service = cast(UserService, user_service) - user_id = user_service.get_user_id_for_credentials(credentials).unwrap() + user_id = self.services.user.get_user_id_for_credentials(credentials).unwrap() return self.add_queueitem_to_queue( queue_item=queue_item, @@ -1444,9 +1436,6 @@ def add_queueitem_to_queue( role = self.get_role_for_credentials(credentials=credentials) context = AuthedServiceContext(server=self, credentials=credentials, role=role) - action_service = self.get_service("actionservice") - log_service = self.get_service("logservice") - result_obj = ActionObject.empty() if action is not None: result_obj = ActionObject.obj_not_ready( @@ -1459,10 +1448,8 @@ def add_queueitem_to_queue( result_obj.syft_server_location = self.id result_obj.syft_client_verify_key = credentials - action_service = self.get_service("actionservice") - - if not action_service.store.exists(uid=action.result_id): - action_service.set_result_to_store( + if not self.services.action.store.exists(uid=action.result_id): + self.services.action.set_result_to_store( result_action_object=result_obj, context=context, ).unwrap() @@ -1485,7 +1472,7 @@ def add_queueitem_to_queue( self.job_stash.set(credentials, job).unwrap() self.queue_stash.set_placeholder(credentials, queue_item).unwrap() - log_service.add(context, log_id, queue_item.job_id) + self.services.log.add(context, log_id, queue_item.job_id) return job @@ -1509,8 +1496,7 @@ def _sort_jobs(self, jobs: list[Job]) -> list[Job]: def _get_existing_user_code_jobs( self, context: AuthedServiceContext, user_code_id: UID ) -> list[Job]: - job_service = self.get_service("jobservice") - jobs = job_service.get_by_user_code_id( + jobs = self.services.job.get_by_user_code_id( context=context, user_code_id=user_code_id ) return self._sort_jobs(jobs) @@ -1523,8 +1509,7 @@ def _is_usercode_call_on_owned_kwargs( ) -> bool: if api_call.path != "code.call": return False - user_code_service = self.get_service("usercodeservice") - return user_code_service.is_execution_on_owned_args( + return self.services.user_code.is_execution_on_owned_args( context, user_code_id, api_call.kwargs ) @@ -1552,7 +1537,7 @@ def add_api_call_to_queue( action = Action.from_api_call(unsigned_call) user_code_id = action.user_code_id - user = self.get_service(UserService).get_current_user(context) + user = self.services.user.get_current_user(context) user = cast(UserView, user) is_execution_on_owned_kwargs_allowed = ( @@ -1627,11 +1612,11 @@ def add_api_call_to_queue( @property def pool_stash(self) -> SyftWorkerPoolStash: - return self.get_service(SyftWorkerPoolService).stash + return self.services.syft_worker_pool.stash @property def user_code_stash(self) -> UserCodeStash: - return self.get_service(UserCodeService).stash + return self.services.user_code.stash @as_result(NotFoundException) def get_default_worker_pool(self) -> WorkerPool | None: @@ -1803,7 +1788,7 @@ def get_default_worker_tag_by_env(dev_mode: bool = False) -> str | None: def create_default_worker_pool(server: Server) -> None: credentials = server.verify_key pull_image = not server.dev_mode - image_stash = server.get_service(SyftWorkerImageService).stash + image_stash = server.services.syft_worker_image.stash default_pool_name = server.settings.default_worker_pool try: diff --git a/packages/syft/src/syft/service/action/action_endpoint.py b/packages/syft/src/syft/service/action/action_endpoint.py index 32cc2128541..b0083fc0192 100644 --- a/packages/syft/src/syft/service/action/action_endpoint.py +++ b/packages/syft/src/syft/service/action/action_endpoint.py @@ -75,16 +75,14 @@ def __call_function( self, call_mode: EXECUTION_MODE, *args: Any, **kwargs: Any ) -> Any: self.context = self.__check_context() - endpoint_service = self.context.server.get_service("apiservice") - if call_mode == EXECUTION_MODE.MOCK: - __endpoint_mode = endpoint_service.execute_server_side_endpoint_mock_by_id + __endpoint_mode = self.context.server.services.api.execute_server_side_endpoint_mock_by_id elif call_mode == EXECUTION_MODE.PRIVATE: __endpoint_mode = ( - endpoint_service.execute_service_side_endpoint_private_by_id + self.context.server.services.api.execute_service_side_endpoint_private_by_id ) else: - __endpoint_mode = endpoint_service.execute_server_side_endpoint_by_id + __endpoint_mode = self.context.server.services.api.execute_server_side_endpoint_by_id return __endpoint_mode( *args, diff --git a/packages/syft/src/syft/service/action/action_object.py b/packages/syft/src/syft/service/action/action_object.py index 43054d01974..4ee377aa14b 100644 --- a/packages/syft/src/syft/service/action/action_object.py +++ b/packages/syft/src/syft/service/action/action_object.py @@ -1175,8 +1175,7 @@ def get_sync_dependencies( # relative from ..job.job_stash import Job - job_service = context.server.get_service("jobservice") # type: ignore - job: Job | None = job_service.get_by_result_id(context, self.id.id) # type: ignore + job: Job | None = context.server.services.job.get_by_result_id(context, self.id.id) # type: ignore if job is not None: return [job.id] else: diff --git a/packages/syft/src/syft/service/action/action_service.py b/packages/syft/src/syft/service/action/action_service.py index 843880a1db6..b5326ae45de 100644 --- a/packages/syft/src/syft/service/action/action_service.py +++ b/packages/syft/src/syft/service/action/action_service.py @@ -194,9 +194,8 @@ def _set( if action_object.mock_obj.syft_action_saved_to_blob_store: blob_id = action_object.mock_obj.syft_blob_storage_entry_id permission = ActionObjectPermission(blob_id, ActionPermission.ALL_READ) - blob_storage_service = context.server.get_service(BlobStorageService) # add_permission is not resultified. - blob_storage_service.stash.add_permission(permission) + context.server.services.blob_storage.stash.add_permission(permission) if has_result_read_permission: action_object = action_object.private @@ -358,9 +357,6 @@ def _user_code_execute( override_execution_permission = ( context.has_execute_permissions or context.role == ServiceRole.ADMIN ) - if context.server: - user_code_service = context.server.get_service("usercodeservice") - input_policy = code_item.get_input_policy(context) output_policy = code_item.get_output_policy(context) @@ -427,7 +423,7 @@ def _user_code_execute( update_policy=not override_execution_permission, ) code_item.output_policy = output_policy # type: ignore - user_code_service.update_code_state(context, code_item) + context.server.services.user_code.update_code_state(context, code_item) if isinstance(exec_result.result, ActionObject): result_action_object = ActionObject.link( result_id=result_id, pointer_id=exec_result.result.id @@ -454,7 +450,7 @@ def _user_code_execute( update_policy=not override_execution_permission, ) code_item.output_policy = output_policy # type: ignore - user_code_service.update_code_state(context, code_item) + context.server.services.user_code.update_code_state(context, code_item) result_action_object_private = wrap_result( result_id, private_exec_result.result ) @@ -552,10 +548,6 @@ def set_result_to_store( has_result_read_permission=True, ).unwrap() - blob_storage_service: AbstractService = context.server.get_service( - BlobStorageService - ) - def store_permission( x: SyftVerifyKey | None = None, ) -> ActionObjectPermission: @@ -572,7 +564,7 @@ def blob_permission( if result_blob_id is not None: blob_permissions = [blob_permission(x) for x in output_readers] - blob_storage_service.stash.add_permissions(blob_permissions) + context.server.blob_storage.stash.add_permissions(blob_permissions) return set_result @@ -816,12 +808,11 @@ def execute(self, context: AuthedServiceContext, action: Action) -> ActionObject if action.action_type == ActionType.CREATEOBJECT: result_action_object = action.create_object elif action.action_type == ActionType.SYFTFUNCTION: - usercode_service = context.server.get_service("usercodeservice") kwarg_ids = {} for k, v in action.kwargs.items(): # transform lineage ids into ids kwarg_ids[k] = v.id - return usercode_service._call( # type: ignore[union-attr] + return context.server.services.user_code._call( # type: ignore[union-attr] context, action.user_code_id, action.result_id, **kwarg_ids ).unwrap() elif action.action_type == ActionType.FUNCTION: @@ -933,25 +924,21 @@ def _delete_blob_storage_entry( ) -> SyftSuccess: deleted_blob_ids = [] - blob_store_service = cast( - BlobStorageService, context.server.get_service(BlobStorageService) - ) - if isinstance(obj, ActionObject) and obj.syft_blob_storage_entry_id: - blob_store_service.delete( + context.server.services.blob_storage.delete( context=context, uid=obj.syft_blob_storage_entry_id ) deleted_blob_ids.append(obj.syft_blob_storage_entry_id) if isinstance(obj, TwinObject): if obj.private.syft_blob_storage_entry_id: - blob_store_service.delete( + context.server.services.blob_storage.delete( context=context, uid=obj.private.syft_blob_storage_entry_id ) deleted_blob_ids.append(obj.private.syft_blob_storage_entry_id) if obj.mock.syft_blob_storage_entry_id: - blob_store_service.delete( + context.server.services.blob_storage.delete( context=context, uid=obj.mock.syft_blob_storage_entry_id ) deleted_blob_ids.append(obj.mock.syft_blob_storage_entry_id) diff --git a/packages/syft/src/syft/service/api/api.py b/packages/syft/src/syft/service/api/api.py index a5f95867534..298f3f30ab0 100644 --- a/packages/syft/src/syft/service/api/api.py +++ b/packages/syft/src/syft/service/api/api.py @@ -223,8 +223,7 @@ def build_internal_context( helper_function_set = HelperFunctionSet(helper_function_dict) - user_service = context.server.get_service("userservice") - user = user_service.get_current_user(context) + user = context.service.services.user.get_current_user(context) return TwinAPIAuthedContext( credentials=context.credentials, @@ -576,7 +575,7 @@ def exec_code( api_service = context.server.get_service("apiservice") api_service.stash.upsert( - context.server.get_service("userservice").admin_verify_key(), self + context.server.services.user.admin_verify_key(), self ).unwrap() print = original_print # type: ignore @@ -651,7 +650,7 @@ def code_string(context: TransformContext) -> TransformContext: ) context.server = cast(AbstractServer, context.server) - admin_key = context.server.get_service("userservice").admin_verify_key() + admin_key = context.server.services.user.admin_verify_key() # If endpoint exists **AND** (has visible access **OR** the user is admin) if endpoint_type is not None and ( diff --git a/packages/syft/src/syft/service/api/api_service.py b/packages/syft/src/syft/service/api/api_service.py index 2f530b207bd..fed9fe6e250 100644 --- a/packages/syft/src/syft/service/api/api_service.py +++ b/packages/syft/src/syft/service/api/api_service.py @@ -82,8 +82,7 @@ def set( syft_server_location=context.server.id, syft_client_verify_key=context.credentials, ) - action_service = context.server.get_service("actionservice") - action_service.set_result_to_store( + context.server.services.action.set_result_to_store( context=context, result_action_object=action_obj, has_result_read_permission=True, @@ -265,7 +264,7 @@ def api_endpoints( context: AuthedServiceContext, ) -> list[TwinAPIEndpointView]: """Retrieves a list of available API endpoints view available to the user.""" - admin_key = context.server.get_service("userservice").admin_verify_key() + admin_key = context.server.services.user.admin_verify_key() all_api_endpoints = self.stash.get_all(admin_key).unwrap() api_endpoint_view = [ @@ -350,7 +349,6 @@ def _call_in_jobs( from ..job.job_stash import JobStatus # So result is a Job object - job_service = context.server.get_service("jobservice") job_id = job.id # Question: For a small moment, when job status is updated, it doesn't return the job during the .get() as if # it's not in the stash. Then afterwards if appears again. Is this a bug? @@ -363,7 +361,7 @@ def _call_in_jobs( or job.status == JobStatus.PROCESSING or job.status == JobStatus.CREATED ): - job = job_service.get(context, job_id) + job = context.server.services.job.get(context, job_id) time.sleep(0.1) if (time.time() - custom_endpoint.endpoint_timeout) > start: raise SyftException( @@ -447,9 +445,8 @@ def call( context, *args, log_id=log_id, **kwargs ).unwrap() action_obj = ActionObject.from_obj(exec_result) - action_service = cast(ActionService, context.server.get_service(ActionService)) try: - return action_service.set_result_to_store( + return context.server.services.action.set_result_to_store( context=context, result_action_object=action_obj, has_result_read_permission=True, @@ -481,9 +478,8 @@ def call_public( ).unwrap() action_obj = ActionObject.from_obj(exec_result) - action_service = cast(ActionService, context.server.get_service(ActionService)) try: - return action_service.set_result_to_store( + return context.server.services.action.set_result_to_store( context=context, result_action_object=action_obj, has_result_read_permission=True, @@ -518,10 +514,8 @@ def call_private( ).unwrap() action_obj = ActionObject.from_obj(exec_result) - - action_service = cast(ActionService, context.server.get_service(ActionService)) try: - return action_service.set_result_to_store( + return context.server.services.action.set_result_to_store( context=context, result_action_object=action_obj ).unwrap() except Exception as e: @@ -594,7 +588,7 @@ def execute_server_side_endpoint_mock_by_id( def get_endpoint_by_uid( self, context: AuthedServiceContext, uid: UID ) -> TwinAPIEndpoint: - admin_key = context.server.get_service("userservice").admin_verify_key() + admin_key = context.server.services.user.admin_verify_key() return self.stash.get_by_uid(admin_key, uid).unwrap() @as_result(StashException) diff --git a/packages/syft/src/syft/service/api/utils.py b/packages/syft/src/syft/service/api/utils.py index 5194d7de9cf..8680c4512ee 100644 --- a/packages/syft/src/syft/service/api/utils.py +++ b/packages/syft/src/syft/service/api/utils.py @@ -33,8 +33,7 @@ def to_str(arg: Any) -> str: new_args = [to_str(arg) for arg in args] new_str = sep.join(new_args) + end if context.server is not None: - log_service = context.server.get_service("LogService") - log_service.append(context=context, uid=log_id, new_str=new_str) + context.server.services.log.append(context=context, uid=log_id, new_str=new_str) time = datetime.datetime.now().strftime("%d/%m/%y %H:%M:%S") return __builtin__.print( f"{time} FUNCTION LOG :", diff --git a/packages/syft/src/syft/service/code/user_code.py b/packages/syft/src/syft/service/code/user_code.py index 3ba1b20a00f..fbb259abcea 100644 --- a/packages/syft/src/syft/service/code/user_code.py +++ b/packages/syft/src/syft/service/code/user_code.py @@ -415,8 +415,7 @@ def _compute_status_l0( else: # Serverside server_identity = ServerIdentity.from_server(context.server) - output_service = context.server.get_service("outputservice") - is_approved = output_service.has_output_read_permissions( + is_approved = context.server.services.output.has_output_read_permissions( context, self.id, self.user_verify_key ) is_denied = self.l0_deny_reason is not None @@ -666,10 +665,7 @@ def output_history(self) -> list[ExecutionOutput]: def get_output_history( self, context: AuthedServiceContext ) -> list[ExecutionOutput]: - output_service = cast( - OutputService, context.server.get_service("outputservice") - ) - return output_service.get_by_user_code_id(context, self.id) + return context.server.services.output.get_by_user_code_id(context, self.id) @as_result(SyftException) def store_execution_output( @@ -689,10 +685,7 @@ def store_execution_output( ) output_ids = filter_only_uids(outputs) - - output_service = context.server.get_service("outputservice") - output_service = cast(OutputService, output_service) - return output_service.create( + return context.server.services.output.create( context, user_code_id=self.id, output_ids=output_ids, @@ -1460,9 +1453,8 @@ def locate_launch_jobs(context: TransformContext) -> TransformContext: v = LaunchJobVisitor() v.visit(tree) nested_calls = v.nested_calls - user_code_service = context.server.get_service("usercodeService") for call in nested_calls: - user_codes = user_code_service.get_by_service_name(context, call) + user_codes = context.server.services.user_code.get_by_service_name(context, call) # TODO: Not great user_code = user_codes[-1] user_code_link = LinkedObject.from_obj( @@ -1511,11 +1503,10 @@ def add_credentials(context: TransformContext) -> TransformContext: def check_policy(policy: Any, context: TransformContext) -> TransformContext: if context.server is not None: - policy_service = context.server.get_service(PolicyService) if isinstance(policy, SubmitUserPolicy): policy = policy.to(UserPolicy, context=context) elif isinstance(policy, UID): - policy = policy_service.get_policy_by_uid(context, policy) + policy = context.server.services.policy.get_policy_by_uid(context, policy) return policy @@ -1581,7 +1572,7 @@ def create_code_status(context: TransformContext) -> TransformContext: f"Invalid server type:{context.server.server_type} for code submission" ) - res = context.server.get_service("usercodestatusservice").create(context, status) + res = context.server.services.user_code_status.create(context, status) # relative from .status_service import UserCodeStatusService @@ -1685,43 +1676,20 @@ def __init__(self, context: AuthedServiceContext) -> None: if server is None: raise ValueError(f"{context}'s server is None") - job_service = server.get_service("jobservice") - action_service = server.get_service("actionservice") - # user_service = server.get_service("userservice") - def job_set_n_iters(n_iters: int) -> None: job = context.job job.n_iters = n_iters - job_service.update(context, job) + server.services.job.update(context, job) def job_set_current_iter(current_iter: int) -> None: job = context.job job.current_iter = current_iter - job_service.update(context, job) + server.services.job.update(context, job) def job_increase_current_iter(current_iter: int) -> None: job = context.job job.current_iter += current_iter - job_service.update(context, job) - - # def set_api_registry(): - # user_signing_key = [ - # x.signing_key - # for x in user_service.stash.partition.data.values() - # if x.verify_key == context.credentials - # ][0] - # data_protcol = get_data_protocol() - # user_api = server.get_api(context.credentials, data_protcol.latest_version) - # user_api.signing_key = user_signing_key - # # We hardcode a python connection here since we have access to the server - # # TODO: this is not secure - # user_api.connection = PythonConnection(server=server) - - # APIRegistry.set_api_for( - # server_uid=server.id, - # user_verify_key=context.credentials, - # api=user_api, - # ) + server.services.job.update(context, job) def launch_job(func: UserCode, **kwargs: Any) -> Job | None: # relative @@ -1729,7 +1697,7 @@ def launch_job(func: UserCode, **kwargs: Any) -> Job | None: kw2id = {} for k, v in kwargs.items(): value = ActionObject.from_obj(v) - ptr = action_service.set_result_to_store( + ptr = server.services.action.set_result_to_store( value, context, has_result_read_permission=False ).unwrap() kw2id[k] = ptr.id @@ -1820,8 +1788,7 @@ def to_str(arg: Any) -> str: new_args = [to_str(arg) for arg in args] new_str = sep.join(new_args) + end if context.server is not None: - log_service = context.server.get_service("LogService") - log_service.append(context=context, uid=log_id, new_str=new_str) + context.server.services.log.append(context=context, uid=log_id, new_str=new_str) time = datetime.datetime.now().strftime("%d/%m/%y %H:%M:%S") return __builtin__.print( f"{time} FUNCTION LOG ({job_id}):", @@ -1886,8 +1853,7 @@ def to_str(arg: Any) -> str: and context.job.log_id is not None ): log_id = context.job.log_id - log_service = context.server.get_service("LogService") - log_service.append(context=context, uid=log_id, new_err=error_msg) + context.server.services.log.append(context=context, uid=log_id, new_err=error_msg) result_message = ( f"Exception encountered while running {code_item.service_func_name}" diff --git a/packages/syft/src/syft/service/code/user_code_service.py b/packages/syft/src/syft/service/code/user_code_service.py index 1d7b4e736e6..6fa6e370666 100644 --- a/packages/syft/src/syft/service/code/user_code_service.py +++ b/packages/syft/src/syft/service/code/user_code_service.py @@ -128,7 +128,7 @@ def _submit( ) if code.status_link is not None: - _ = context.server.get_service("usercodestatusservice").remove( + _ = context.server.services.user_code_status.remove( root_context, code.status_link.object_uid ) @@ -203,16 +203,13 @@ def _post_user_code_transform_ops( raise SyftException( public_message="outputs can only be distributed to input owners" ) - - worker_pool_service = context.server.get_service("SyftWorkerPoolService") - worker_pool_service._get_worker_pool( + context.server.services.syft_worker_pool._get_worker_pool( context, pool_name=user_code.worker_pool_name, ) # Create a code history - code_history_service = context.server.get_service("codehistoryservice") - code_history_service.submit_version(context=context, code=user_code) + context.server.services.code_history.submit_version(context=context, code=user_code) return user_code @@ -382,22 +379,19 @@ def is_execution_allowed( def is_execution_on_owned_args_allowed(self, context: AuthedServiceContext) -> bool: if context.role == ServiceRole.ADMIN: return True - user_service = context.server.get_service("userservice") - current_user = user_service.get_current_user(context=context) + current_user = context.server.services.user.get_current_user(context=context) return current_user.mock_execution_permission def keep_owned_kwargs( self, kwargs: dict[str, Any], context: AuthedServiceContext ) -> dict[str, Any]: """Return only the kwargs that are owned by the user""" - action_service = context.server.get_service("actionservice") - mock_kwargs = {} for k, v in kwargs.items(): if isinstance(v, UID): # Jobs have UID kwargs instead of ActionObject try: - v = action_service.get(context, uid=v) + v = context.server.services.action.get(context, uid=v) except Exception: # nosec: we are skipping when dont find it pass if ( @@ -575,14 +569,11 @@ def _call( "which is currently not supported. Run your function with `blocking=False` to run" " as a job on your worker pool." ) - - action_service = context.server.get_service("actionservice") - - action_obj = action_service._user_code_execute( + action_obj = context.server.services.action._user_code_execute( context, code, kwarg2id, result_id ).unwrap() - result = action_service.set_result_to_store( + result = context.server.services.action.set_result_to_store( action_obj, context, code.get_output_policy(context) ).unwrap() @@ -680,8 +671,7 @@ def resolve_outputs( outputs = [] for output_id in output_ids: if context.server is not None: - action_service = context.server.get_service("actionservice") - output = action_service.get( + output = context.server.services.action.get( context, uid=output_id, twin_mode=TwinMode.PRIVATE ) outputs.append(output) diff --git a/packages/syft/src/syft/service/code_history/code_history_service.py b/packages/syft/src/syft/service/code_history/code_history_service.py index 5383e8c9dcb..bcff8b6698d 100644 --- a/packages/syft/src/syft/service/code_history/code_history_service.py +++ b/packages/syft/src/syft/service/code_history/code_history_service.py @@ -44,9 +44,8 @@ def submit_version( code: SubmitUserCode | UserCode, comment: str | None = None, ) -> SyftSuccess: - user_code_service = context.server.get_service("usercodeservice") if isinstance(code, SubmitUserCode): - code = user_code_service._submit(context=context, code=code) + code = context.server.services.user_code._submit(context=context, code=code) try: code_history = self.stash.get_by_service_func_name_and_verify_key( @@ -100,12 +99,8 @@ def fetch_histories_for_user( credentials=context.credentials, user_verify_key=user_verify_key ).unwrap() - user_code_service: UserCodeService = context.server.get_service( - "usercodeservice" - ) # type: ignore - def get_code(uid: UID) -> UserCode: - return user_code_service.stash.get_by_uid( + return context.server.services.user_code.stash.get_by_uid( credentials=context.server.verify_key, uid=uid, ).unwrap() @@ -142,8 +137,7 @@ def get_histories_for_current_user( def get_history_for_user( self, context: AuthedServiceContext, email: str ) -> CodeHistoriesDict: - user_service = context.server.get_service("userservice") - user = user_service.stash.get_by_email( + user = context.server.services.user.stash.get_by_email( credentials=context.credentials, email=email ).unwrap() return self.fetch_histories_for_user( @@ -165,8 +159,7 @@ def get_histories_group_by_user( else: code_histories = self.stash.get_all(context.credentials).unwrap() - user_service = context.server.get_service("userservice") - users = user_service.stash.get_all(context.credentials).unwrap() + users = context.server.services.user.stash.get_all(context.credentials).unwrap() user_code_histories = UsersCodeHistoriesDict(server_uid=context.server.id) verify_key_2_user_email = {} @@ -193,8 +186,7 @@ def get_by_func_name_and_user_email( user_email: str, user_id: UID, ) -> list[CodeHistory]: - user_service = context.server.get_service("userservice") - user_verify_key = user_service.user_verify_key(user_email) + user_verify_key = context.server.services.user.user_verify_key(user_email) kwargs = { "id": user_id, diff --git a/packages/syft/src/syft/service/data_subject/data_subject_service.py b/packages/syft/src/syft/service/data_subject/data_subject_service.py index 9106386ef63..9b2a0c8bd54 100644 --- a/packages/syft/src/syft/service/data_subject/data_subject_service.py +++ b/packages/syft/src/syft/service/data_subject/data_subject_service.py @@ -63,11 +63,7 @@ def __init__(self, store: DocumentStore) -> None: def add( self, context: AuthedServiceContext, data_subject: DataSubjectCreate ) -> SyftSuccess: - """Register a data subject.""" - - member_relationship_add = context.server.get_service_method( - DataSubjectMemberService.add - ) + """Register a data subject."""# member_relationships: set[tuple[str, str]] = data_subject.member_relationships if len(member_relationships) == 0: @@ -84,7 +80,8 @@ def add( ds.to(DataSubject, context=context), ignore_duplicates=True, ).unwrap() - member_relationship_add(context, parent_ds.name, child_ds.name) + # TODO: this name seems wrong, but CI might not test it + context.server.services.data_subject.add(context, parent_ds.name, child_ds.name) return SyftSuccess( message=f"{len(member_relationships)+1} Data Subjects Registered", diff --git a/packages/syft/src/syft/service/dataset/dataset.py b/packages/syft/src/syft/service/dataset/dataset.py index 600e3dfcb62..6c4a91e06c2 100644 --- a/packages/syft/src/syft/service/dataset/dataset.py +++ b/packages/syft/src/syft/service/dataset/dataset.py @@ -764,8 +764,7 @@ def create_and_store_twin(context: TransformContext) -> TransformContext: raise ValueError( "f{context}'s server is None, please log in. No trasformation happened" ) - action_service = context.server.get_service("actionservice") - action_service._set( + context.server.services.action._set( context=context.to_server_context(), action_object=twin, ).unwrap(public_message="Failed to create and store twin") diff --git a/packages/syft/src/syft/service/dataset/dataset_service.py b/packages/syft/src/syft/service/dataset/dataset_service.py index cd347c11b35..3a16b7f1862 100644 --- a/packages/syft/src/syft/service/dataset/dataset_service.py +++ b/packages/syft/src/syft/service/dataset/dataset_service.py @@ -228,10 +228,7 @@ def delete( f"in Dataset {uid}" ) - action_service = cast( - ActionService, context.server.get_service(ActionService) - ) - action_service.delete( + context.server.services.action.delete( context=context, uid=asset.action_id, soft_delete=True ) diff --git a/packages/syft/src/syft/service/job/job_service.py b/packages/syft/src/syft/service/job/job_service.py index 0ad153e4bda..de4a1939cc9 100644 --- a/packages/syft/src/syft/service/job/job_service.py +++ b/packages/syft/src/syft/service/job/job_service.py @@ -135,9 +135,7 @@ def restart(self, context: AuthedServiceContext, uid: UID) -> SyftSuccess: ).unwrap() context.server.job_stash.set(context.credentials, job).unwrap() - - log_service = context.server.get_service("logservice") - log_service.restart(context, job.log_id) + context.server.services.log.restart(context, job.log_id) return SyftSuccess(message="Great Success!") @@ -232,9 +230,7 @@ def add_read_permission_job_for_code_owner( def add_read_permission_log_for_code_owner( self, context: AuthedServiceContext, log_id: UID, user_code: UserCode ) -> None: - log_service = context.server.get_service("logservice") - log_service = cast(LogService, log_service) - return log_service.stash.add_permission( + return context.server.services.log.stash.add_permission( ActionObjectPermission( log_id, ActionPermission.READ, user_code.user_verify_key ) @@ -268,14 +264,11 @@ def create_job_for_user_code_id( user_code_id=user_code_id, resolved=is_resolved, ) - user_code_service = context.server.get_service("usercodeservice") - user_code = user_code_service.get_by_uid(context=context, uid=user_code_id) + user_code = context.server.services.user_code.get_by_uid(context=context, uid=user_code_id) # The owner of the code should be able to read the job self.stash.set(context.credentials, job).unwrap() - - log_service = context.server.get_service("logservice") - log_service.add( + context.server.services.log.add( context, job.log_id, job.id, diff --git a/packages/syft/src/syft/service/job/job_stash.py b/packages/syft/src/syft/service/job/job_stash.py index 413d36ba753..fc83b675503 100644 --- a/packages/syft/src/syft/service/job/job_stash.py +++ b/packages/syft/src/syft/service/job/job_stash.py @@ -313,8 +313,7 @@ def subjobs(self) -> list["Job"]: return api.services.job.get_subjobs(self.id) def get_subjobs(self, context: AuthedServiceContext) -> list["Job"]: - job_service = context.server.get_service("jobservice") - return job_service.get_subjobs(context, self.id) + return context.server.services.job.get_subjobs(context, self.id) @property def owner(self) -> UserView: @@ -647,7 +646,7 @@ def get_sync_dependencies(self, context: AuthedServiceContext) -> list[UID]: # dependencies.append(self.user_code_id) try: - output = context.server.get_service("outputservice").get_by_job_id( # type: ignore + output = context.server.services.output.get_by_job_id( # type: ignore context, self.id ) if output is not None: diff --git a/packages/syft/src/syft/service/metadata/metadata_service.py b/packages/syft/src/syft/service/metadata/metadata_service.py index 4e4e84d1364..70453d9b084 100644 --- a/packages/syft/src/syft/service/metadata/metadata_service.py +++ b/packages/syft/src/syft/service/metadata/metadata_service.py @@ -21,12 +21,6 @@ def __init__(self, store: DocumentStore) -> None: def get_metadata(self, context: AuthedServiceContext) -> ServerMetadata: return context.server.metadata # type: ignore - # @service_method(path="metadata.get_admin", name="get_admin", roles=GUEST_ROLE_LEVEL) - # def get_admin(self, context: AuthedServiceContext): - # user_service = context.server.get_service("userservice") - # admin_user = user_service.get_all(context=context)[0] - # return admin_user - @service_method(path="metadata.get_env", name="get_env", roles=GUEST_ROLE_LEVEL) def get_env(self, context: AuthedServiceContext) -> str: return context.server.packages diff --git a/packages/syft/src/syft/service/network/association_request.py b/packages/syft/src/syft/service/network/association_request.py index a9ed93b1adf..bfafe33bdbd 100644 --- a/packages/syft/src/syft/service/network/association_request.py +++ b/packages/syft/src/syft/service/network/association_request.py @@ -41,9 +41,6 @@ def _run( tuple[bytes, ServerPeer]: The result of the association request. Raises on errors. """ - # relative - from .network_service import NetworkService - if not apply: # TODO: implement undo for AssociationRequestChange raise SyftException( @@ -52,10 +49,6 @@ def _run( # Get the network service service_ctx = context.to_service_ctx() - network_service = cast( - NetworkService, service_ctx.server.get_service(NetworkService) - ) - network_stash = network_service.stash # Check if remote peer to be added is via reverse tunnel rtunnel_route = self.remote_peer.get_rtunnel_route() @@ -66,7 +59,7 @@ def _run( # If the remote peer is added via reverse tunnel, we skip ping to peer if add_rtunnel_route: - network_service.set_reverse_tunnel_config( + service_ctx.server.services.network.set_reverse_tunnel_config( context=context, remote_server_peer=self.remote_peer, ) @@ -99,7 +92,7 @@ def _run( raise SyftException(public_message=str(e)) # Adding the remote peer to the network stash - network_stash.create_or_update_peer( + service_ctx.server.services.network.stash.create_or_update_peer( service_ctx.server.verify_key, self.remote_peer ) # this way they can match up who we are with who they think we are diff --git a/packages/syft/src/syft/service/network/utils.py b/packages/syft/src/syft/service/network/utils.py index 62fff066e35..a2a6ca6e1f0 100644 --- a/packages/syft/src/syft/service/network/utils.py +++ b/packages/syft/src/syft/service/network/utils.py @@ -40,11 +40,7 @@ def peer_route_heathcheck(self, context: AuthedServiceContext) -> None: Returns: None """ - - network_service = cast( - NetworkService, context.server.get_service(NetworkService) - ) - network_stash = network_service.stash + network_stash = context.server.services.network.stash try: all_peers: list[ServerPeer] = network_stash.get_all( diff --git a/packages/syft/src/syft/service/notification/email_templates.py b/packages/syft/src/syft/service/notification/email_templates.py index 2a17a662086..372091b626f 100644 --- a/packages/syft/src/syft/service/notification/email_templates.py +++ b/packages/syft/src/syft/service/notification/email_templates.py @@ -31,7 +31,7 @@ def email_title(notification: "Notification", context: AuthedServiceContext) -> @staticmethod def email_body(notification: "Notification", context: AuthedServiceContext) -> str: - user_service = context.server.get_service("userservice") + user_service = context.server.services.user admin_verify_key = user_service.admin_verify_key() user = user_service.stash.get_by_verify_key( credentials=admin_verify_key, verify_key=notification.to_user_verify_key @@ -118,7 +118,7 @@ def email_title(notification: "Notification", context: AuthedServiceContext) -> @staticmethod def email_body(notification: "Notification", context: AuthedServiceContext) -> str: - user_service = context.server.get_service("userservice") + user_service = context.server.services.user admin_verify_key = user_service.admin_verify_key() admin = user_service.get_by_verify_key(admin_verify_key).unwrap() admin_name = admin.name diff --git a/packages/syft/src/syft/service/notification/notification_service.py b/packages/syft/src/syft/service/notification/notification_service.py index 89e15738376..2bf7d17c21f 100644 --- a/packages/syft/src/syft/service/notification/notification_service.py +++ b/packages/syft/src/syft/service/notification/notification_service.py @@ -54,9 +54,7 @@ def send( context.credentials, new_notification, add_permissions=permissions ).unwrap() - notifier_service = context.server.get_service("notifierservice") - notifier_service.dispatch_notification(context, new_notification).unwrap() - + context.server.services.notifier.dispatch_notification(context, new_notification).unwrap() return new_notification @service_method(path="notifications.reply", name="reply", roles=GUEST_ROLE_LEVEL) @@ -84,8 +82,7 @@ def user_settings( self, context: AuthedServiceContext, ) -> NotifierSettings: - notifier_service = context.server.get_service("notifierservice") - return notifier_service.user_settings(context) + return context.server.services.notifier.user_settings(context) @service_method( path="notifications.settings", @@ -96,9 +93,8 @@ def settings( self, context: AuthedServiceContext, ) -> NotifierSettings: - notifier_service = context.server.get_service("notifierservice") - result = notifier_service.settings(context).unwrap() - return result + return context.server.services.notifier.settings(context).unwrap() + @service_method( path="notifications.activate", @@ -110,12 +106,7 @@ def activate( self, context: AuthedServiceContext, ) -> Notification: - notifier_service = context.server.get_service("notifierservice") - result = notifier_service.activate(context) - if isinstance(result, OkErr) and result.is_ok(): - # sad, TODO: remove upstream Ok - result = result.ok() - return result + return context.server.services.notifier.activate(context).unwrap() @service_method( path="notifications.deactivate", @@ -127,11 +118,7 @@ def deactivate( self, context: AuthedServiceContext, ) -> SyftSuccess: - notifier_service = context.server.get_service("notifierservice") - result = notifier_service.deactivate(context) - if isinstance(result, OkErr): - result = result.ok() - return result + return context.server.services.notifier.deactivate(context).unwrap() @service_method( path="notifications.get_all", diff --git a/packages/syft/src/syft/service/notifier/notifier.py b/packages/syft/src/syft/service/notifier/notifier.py index 8400082303d..3cf784f5095 100644 --- a/packages/syft/src/syft/service/notifier/notifier.py +++ b/packages/syft/src/syft/service/notifier/notifier.py @@ -103,8 +103,7 @@ def send( sender = None try: sender = self.sender - user_service = context.server.get_service("userservice") - receiver = user_service.get_by_verify_key( + receiver = context.server.services.user.get_by_verify_key( notification.to_user_verify_key ).unwrap() if not receiver.notifications_enabled[NOTIFIERS.EMAIL]: diff --git a/packages/syft/src/syft/service/notifier/notifier_service.py b/packages/syft/src/syft/service/notifier/notifier_service.py index b407e7b38df..95b81c05629 100644 --- a/packages/syft/src/syft/service/notifier/notifier_service.py +++ b/packages/syft/src/syft/service/notifier/notifier_service.py @@ -62,8 +62,7 @@ def user_settings( self, context: AuthedServiceContext, ) -> NotificationPreferences: - user_service = context.server.get_service("userservice") - user_view = user_service.get_current_user(context) + user_view = context.server.services.user.get_current_user(context) notifications = user_view.notifications_enabled return NotificationPreferences( email=notifications[NOTIFIERS.EMAIL], @@ -190,8 +189,7 @@ def turn_on( ) self.stash.update(credentials=context.credentials, obj=notifier).unwrap() - settings_service = context.server.get_service("settingsservice") - settings_service.update(context, notifications_enabled=True) + context.server.services.settings.update(context, notifications_enabled=True) return SyftSuccess(message="Notifications enabled successfully.") @as_result(StashException) @@ -207,9 +205,7 @@ def turn_off( notifier.active = False self.stash.update(credentials=context.credentials, obj=notifier).unwrap() - - settings_service = context.server.get_service("settingsservice") - settings_service.update(context, notifications_enabled=False) + context.server.services.settings.update(context, notifications_enabled=False) return SyftSuccess(message="Notifications disabled succesfullly") @as_result(SyftException) @@ -220,12 +216,7 @@ def activate( Activate email notifications for the authenticated user. This will only work if the datasite owner has enabled notifications. """ - user_service = context.server.get_service("userservice") - result = user_service.enable_notifications(context, notifier_type=notifier_type) - if isinstance(result, OkErr) and result.is_ok(): - # sad, TODO: remove upstream Ok - result = result.ok() - return result + return context.server.services.user.enable_notifications(context, notifier_type=notifier_type).unwrap() @as_result(SyftException) def deactivate( @@ -234,8 +225,7 @@ def deactivate( """Deactivate email notifications for the authenticated user This will only work if the datasite owner has enabled notifications. """ - user_service = context.server.get_service("userservice") - result = user_service.disable_notifications( + result = context.server.services.user.disable_notifications( context, notifier_type=notifier_type ) return result @@ -333,7 +323,7 @@ def set_email_rate_limit( def dispatch_notification( self, context: AuthedServiceContext, notification: Notification ) -> SyftSuccess: - admin_key = context.server.get_service("userservice").admin_verify_key() + admin_key = context.server.services.user.admin_verify_key() # Silently fail on notification not delivered try: diff --git a/packages/syft/src/syft/service/output/output_service.py b/packages/syft/src/syft/service/output/output_service.py index e62a4baafc7..422788d22f5 100644 --- a/packages/syft/src/syft/service/output/output_service.py +++ b/packages/syft/src/syft/service/output/output_service.py @@ -295,7 +295,6 @@ def has_output_read_permissions( user_code_id: UID, user_verify_key: SyftVerifyKey, ) -> bool: - action_service = context.server.get_service("actionservice") all_outputs = self.get_by_user_code_id(context, user_code_id) for output in all_outputs: # TODO tech debt: unclear why code owner can see outputhistory without permissions. @@ -311,7 +310,7 @@ def has_output_read_permissions( ActionObjectREAD(uid=_id.id, credentials=user_verify_key) for _id in result_ids ] - if action_service.store.has_permissions(permissions): + if context.server.services.action.store.has_permissions(permissions): return True return False diff --git a/packages/syft/src/syft/service/policy/policy.py b/packages/syft/src/syft/service/policy/policy.py index 6c40eaccf16..96a562cf0cf 100644 --- a/packages/syft/src/syft/service/policy/policy.py +++ b/packages/syft/src/syft/service/policy/policy.py @@ -297,7 +297,7 @@ def is_met(self, context: AuthedServiceContext, *args: Any, **kwargs: Any) -> bo def transform_kwarg(self, context: AuthedServiceContext, val: Any) -> Any: if isinstance(self.val, UID): if issubclass(self.klass, CustomEndpointActionObject): - obj = context.server.get_service("actionservice").get( + obj = context.server.services.action.get( context.as_root_context(), self.val ) return obj.syft_action_data @@ -335,7 +335,7 @@ class UserOwned(PolicyRule): def is_owned( self, context: AuthedServiceContext, action_object: ActionObject ) -> bool: - action_store = context.server.get_service("actionservice").store + action_store = context.server.services.action.store return action_store.has_permission( ActionObjectPermission( action_object.id, ActionPermission.OWNER, context.credentials @@ -369,12 +369,10 @@ def user_code_arg2id(arg: Any) -> UID: def retrieve_item_from_db(id: UID, context: AuthedServiceContext) -> ActionObject: # relative from ...service.action.action_object import TwinMode - - action_service = context.server.get_service("actionservice") root_context = AuthedServiceContext( server=context.server, credentials=context.server.verify_key ) - return action_service._get( + return context.server.services.action._get( context=root_context, uid=id, twin_mode=TwinMode.NONE, @@ -420,9 +418,8 @@ def _inputs_for_context(self, context: ChangeContext) -> dict: server=context.server, credentials=context.approving_user_credentials ).as_root_context() - action_service = context.server.get_service("actionservice") for var_name, uid in inputs.items(): - action_object_value = action_service.get( + action_object_value = context.server.services.action.get( uid=uid, context=root_context ).unwrap() # resolve syft action data from blob store @@ -605,7 +602,6 @@ def retrieve_from_db( # relative pass - action_service = context.server.get_service("actionservice") code_inputs = {} # When we are retrieving the code from the database, we need to use the server's @@ -622,7 +618,7 @@ def retrieve_from_db( ) for var_name, arg_id in allowed_inputs.items(): - code_inputs[var_name] = action_service._get( + code_inputs[var_name] = context.server.services.action._get( context=root_context, uid=arg_id, twin_mode=TwinMode.NONE, @@ -785,8 +781,7 @@ def count(self, context: AuthedServiceContext | None = None) -> int: output_history = output_service.get_by_output_policy_id(self.id) else: # server side - output_service = context.server.get_service("outputservice") - output_history = output_service.get_by_output_policy_id( + output_history = context.server.services.output.get_by_output_policy_id( context, self.id ) # raises diff --git a/packages/syft/src/syft/service/project/project_service.py b/packages/syft/src/syft/service/project/project_service.py index 98fc2a3fcef..e5a033f5585 100644 --- a/packages/syft/src/syft/service/project/project_service.py +++ b/packages/syft/src/syft/service/project/project_service.py @@ -94,8 +94,7 @@ def is_project_leader( roles=DATA_SCIENTIST_ROLE_LEVEL, ) def can_create_project(self, context: AuthedServiceContext) -> bool: - user_service: UserService = context.server.get_service("userservice") # type: ignore[assignment] - role = user_service.get_role_for_credentials( + role = context.server.services.user.get_role_for_credentials( credentials=context.credentials ).unwrap() @@ -136,10 +135,8 @@ def create_project( # For followers the leader server route is retrieved from its peer if leader_server.verify_key != context.server.verify_key: # FIX: networkservice stash to new BaseStash - network_service = context.server.get_service("networkservice") - network_service = cast(NetworkService, network_service) peer_id = context.server.id.short() if context.server.id else "" - leader_server_peer = network_service.stash.get_by_verify_key( + leader_server_peer = context.server.services.network.stash.get_by_verify_key( credentials=context.server.verify_key, verify_key=leader_server.verify_key, ).unwrap( @@ -243,11 +240,10 @@ def broadcast_event( self.check_for_project_request(project, project_event, context) # Broadcast the event to all the members of the project - network_service = context.server.get_service("networkservice") for member in project.members: if member.verify_key != context.server.verify_key: # Retrieving the ServerPeer Object to communicate with the server - peer = network_service.stash.get_by_verify_key( + peer = context.server.services.network.stash.get_by_verify_key( credentials=context.server.verify_key, verify_key=member.verify_key, ).unwrap( @@ -335,9 +331,8 @@ def get_by_uid(self, context: AuthedServiceContext, uid: UID) -> Project: def add_signing_key_to_project( self, context: AuthedServiceContext, project: Project ) -> Project: - user_service = context.server.get_service("userservice") try: - user = user_service.stash.get_by_verify_key( + user = context.server.services.user.stash.get_by_verify_key( credentials=context.credentials, verify_key=context.credentials ).unwrap() except NotFoundException as exc: diff --git a/packages/syft/src/syft/service/queue/zmq_producer.py b/packages/syft/src/syft/service/queue/zmq_producer.py index 85dbb0edbf0..dd2ee0d585e 100644 --- a/packages/syft/src/syft/service/queue/zmq_producer.py +++ b/packages/syft/src/syft/service/queue/zmq_producer.py @@ -115,7 +115,7 @@ def close(self) -> None: @property def action_service(self) -> AbstractService: if self.auth_context.server is not None: - return self.auth_context.server.get_service("ActionService") + return self.auth_context.server.services.action else: raise Exception(f"{self.auth_context} does not have a server.") @@ -266,11 +266,7 @@ def purge_workers(self) -> None: # relative from ...service.worker.worker_service import WorkerService - - worker_service = cast( - WorkerService, self.auth_context.server.get_service(WorkerService) - ) - worker_service._delete(self.auth_context, syft_worker) + self.auth_context.server.services.worker._delete(self.auth_context, syft_worker) def update_consumer_state_for_worker( self, syft_worker_id: UID, consumer_state: ConsumerState diff --git a/packages/syft/src/syft/service/request/request.py b/packages/syft/src/syft/service/request/request.py index 717c1ceb7c5..4d434a1294d 100644 --- a/packages/syft/src/syft/service/request/request.py +++ b/packages/syft/src/syft/service/request/request.py @@ -114,11 +114,7 @@ class ActionStoreChange(Change): @as_result(SyftException) def _run(self, context: ChangeContext, apply: bool) -> SyftSuccess: - action_service: ActionService = context.server.get_service(ActionService) # type: ignore[assignment] - blob_storage_service: BlobStorageService = context.server.get_service( - BlobStorageService - ) # type: ignore[assignment] - action_store = action_service.store + action_store = context.server.services.action.store # can we ever have a lineage ID in the store? obj_uid = self.linked_obj.object_uid @@ -169,7 +165,7 @@ def _run(self, context: ChangeContext, apply: bool) -> SyftSuccess: ) action_store.add_permission(requesting_permission_action_obj) ( - blob_storage_service.stash.add_permission( + context.server.services.blob_storage.stash.add_permission( requesting_permission_blob_obj ) if requesting_permission_blob_obj @@ -180,11 +176,11 @@ def _run(self, context: ChangeContext, apply: bool) -> SyftSuccess: action_store.remove_permission(requesting_permission_action_obj) if ( requesting_permission_blob_obj - and blob_storage_service.stash.has_permission( + and context.server.services.blob_storage.stash.has_permission( requesting_permission_blob_obj ) ): - blob_storage_service.stash.remove_permission( + context.server.services.blob_storage.stash.remove_permission( requesting_permission_blob_obj ) else: @@ -227,12 +223,10 @@ def _tag_required_for_dockerworkerconfig(self) -> Self: @as_result(SyftException) def _run(self, context: ChangeContext, apply: bool) -> SyftSuccess: - worker_image_service = context.server.get_service("SyftWorkerImageService") - service_context = context.to_service_ctx() - worker_image_service.submit(service_context, worker_config=self.config) + context.server.services.syft_worker_image.submit(service_context, worker_config=self.config) - worker_image = worker_image_service.stash.get_by_worker_config( + worker_image = context.server.services.syft_worker_image.stash.get_by_worker_config( service_context.credentials, config=self.config ).unwrap() if worker_image is None: @@ -241,7 +235,7 @@ def _run(self, context: ChangeContext, apply: bool) -> SyftSuccess: build_success_message = "Image was pre-built." if not worker_image.is_prebuilt: - build_result = worker_image_service.build( + build_result = context.server.services.syft_worker_image.build( service_context, image_uid=worker_image.id, tag=self.tag, @@ -252,7 +246,7 @@ def _run(self, context: ChangeContext, apply: bool) -> SyftSuccess: build_success = f"Build result: {build_success_message}" if IN_KUBERNETES and not worker_image.is_prebuilt: - push_result = worker_image_service.push( + push_result = context.server.services.syft_worker_image.push( service_context, image_uid=worker_image.id, username=context.extra_kwargs.get("registry_username", None), @@ -298,16 +292,15 @@ def _run(self, context: ChangeContext, apply: bool) -> SyftSuccess: """ if apply: # get the worker pool service and try to launch a pool - worker_pool_service = context.server.get_service("SyftWorkerPoolService") service_context: AuthedServiceContext = context.to_service_ctx() if self.config is not None: - worker_image = worker_pool_service.image_stash.get_by_worker_config( + worker_image = context.server.services.syft_worker_pool.image_stash.get_by_worker_config( service_context.credentials, self.config ).unwrap() self.image_uid = worker_image.id - result = worker_pool_service.launch( + result = context.server.services.syft_worker_pool.launch( context=service_context, pool_name=self.pool_name, image_uid=self.image_uid, @@ -1161,8 +1154,7 @@ def add_requesting_user_info(context: TransformContext) -> TransformContext: if context.output is not None and context.server is not None: try: user_key = context.output["requesting_user_verify_key"] - user_service = context.server.get_service("UserService") - user = user_service.get_by_verify_key(user_key).unwrap() + user = context.server.services.user.get_by_verify_key(user_key).unwrap() context.output["requesting_user_name"] = user.name context.output["requesting_user_email"] = user.email context.output["requesting_user_institution"] = ( diff --git a/packages/syft/src/syft/service/settings/settings_service.py b/packages/syft/src/syft/service/settings/settings_service.py index ca307ef2567..faa52bdff6d 100644 --- a/packages/syft/src/syft/service/settings/settings_service.py +++ b/packages/syft/src/syft/service/settings/settings_service.py @@ -135,13 +135,9 @@ def _update( context.credentials, settings=new_settings ).unwrap() - notifier_service = cast( - NotifierService, context.server.get_service("notifierservice") - ) - # If notifications_enabled is present in the update, we need to update the notifier settings if settings.notifications_enabled is not Empty: # type: ignore[comparison-overlap] - notifier_settings_res = notifier_service.settings(context) + notifier_settings_res = context.server.services.notifier.settings(context) if ( not notifier_settings_res.is_ok() or notifier_settings_res.ok() is None @@ -153,7 +149,7 @@ def _update( ) ) - notifier_service._set_notifier( + context.server.services.notifier._set_notifier( context, active=settings.notifications_enabled ) @@ -209,8 +205,7 @@ def enable_notifications( email_server: str | None = None, email_port: str | None = None, ) -> SyftSuccess: - notifier_service = context.server.get_service("notifierservice") - notifier_service.turn_on( + context.server.services.notifier.turn_on( context=context, email_username=email_username, email_password=email_password, @@ -229,8 +224,7 @@ def disable_notifications( self, context: AuthedServiceContext, ) -> SyftSuccess: - notifier_service = context.server.get_service("notifierservice") - notifier_service.turn_off(context=context).unwrap() + context.server.services.notifier.turn_off(context=context).unwrap() return SyftSuccess(message="Notifications disabled") @service_method( @@ -272,8 +266,7 @@ def enable_eager_execution( def set_email_rate_limit( self, context: AuthedServiceContext, email_type: EMAIL_TYPES, daily_limit: int ) -> SyftSuccess: - notifier_service = context.server.get_service("notifierservice") - return notifier_service.set_email_rate_limit(context, email_type, daily_limit) + return context.server.services.notifier.set_email_rate_limit(context, email_type, daily_limit) @service_method( path="settings.allow_association_request_auto_approval", @@ -352,8 +345,7 @@ def welcome_show( all_settings = self.stash.get_all( context.server.signing_key.verify_key ).unwrap() - user_service = context.server.get_service("userservice") - role = user_service.get_role_for_credentials(context.credentials).unwrap() + role = context.server.services.user.get_role_for_credentials(context.credentials).unwrap() # check if the settings list is empty if len(all_settings) == 0: diff --git a/packages/syft/src/syft/service/sync/sync_service.py b/packages/syft/src/syft/service/sync/sync_service.py index 760a7d3bfa0..c42060b3125 100644 --- a/packages/syft/src/syft/service/sync/sync_service.py +++ b/packages/syft/src/syft/service/sync/sync_service.py @@ -39,7 +39,7 @@ def get_store(context: AuthedServiceContext, item: SyncableSyftObject) -> Any: if isinstance(item, ActionObject): - service = context.server.get_service("actionservice") # type: ignore + service = context.server.services.action # type: ignore return service.store # type: ignore service = context.server.get_service(TYPE_TO_SERVICE[type(item)]) # type: ignore return service.stash.partition @@ -61,16 +61,14 @@ def add_actionobject_read_permissions( action_object: ActionObject, new_permissions: list[ActionObjectPermission], ) -> None: - store_to = context.server.get_service("actionservice").store # type: ignore + store_to = context.server.services.action.store # type: ignore for permission in new_permissions: if permission.permission == ActionPermission.READ: store_to.add_permission(permission) blob_id = action_object.syft_blob_storage_entry_id if blob_id: - store_to_blob = context.server.get_service( - "blobstorageservice" - ).stash.partition # type: ignore + store_to_blob = context.server.services.blob_sotrage.stash.partition # type: ignore for permission in new_permissions: if permission.permission == ActionPermission.READ: permission_blob = ActionObjectPermission( @@ -166,9 +164,7 @@ def set_object( if isinstance(item, TwinAPIEndpoint): # we need the side effect of set function # to create an action object - apiservice: APIService = context.server.get_service("apiservice") # type: ignore - - res = apiservice.set(context=context, endpoint=item) + res = context.server.services.api.set(context=context, endpoint=item) return item if exists: @@ -280,9 +276,7 @@ def _get_all_items_for_jobs( """ items_for_jobs: list[SyncableSyftObject] = [] errors = {} - - job_service = context.server.get_service("jobservice") - jobs = job_service.get_all(context) + jobs = context.server.services.job.get_all(context) for job in jobs: try: @@ -301,14 +295,12 @@ def _get_job_batch( self, context: AuthedServiceContext, job: Job ) -> list[SyncableSyftObject]: job_batch = [job] - - log_service = context.server.get_service("logservice") - log = log_service.get(context, job.log_id) + + log = context.server.services.log.get(context, job.log_id) job_batch.append(log) - - output_service = context.server.get_service("outputservice") + try: - output = output_service.get_by_job_id(context, job.id) + output = context.server.services.output.get_by_job_id(context, job.id) except NotFoundException: output = None @@ -321,10 +313,9 @@ def _get_job_batch( if isinstance(job.result, ActionObject): job_result_ids.add(job.result.id.id) - action_service = context.server.get_service("actionservice") for result_id in job_result_ids: # TODO: unwrap - action_object = action_service.get(context, result_id) + action_object = context.server.services.action.get(context, result_id) job_batch.append(action_object) return job_batch diff --git a/packages/syft/src/syft/service/user/user_service.py b/packages/syft/src/syft/service/user/user_service.py index fd8874f3107..6229829926c 100644 --- a/packages/syft/src/syft/service/user/user_service.py +++ b/packages/syft/src/syft/service/user/user_service.py @@ -158,9 +158,8 @@ def forgot_password( # Notifications Enabled # Instead of changing the password here, we would change it in email template generation. link = LinkedObject.with_context(user, context=root_context) - notifier_service = root_context.server.get_service("notifierservice") # Notifier is active - notifier = notifier_service.settings(context=root_context).unwrap() + notifier = root_context.server.services.notifier.settings(context=root_context).unwrap() notification_is_enabled = notifier.active # Email is enabled email_is_enabled = notifier.email_enabled diff --git a/packages/syft/src/syft/service/worker/worker_image_service.py b/packages/syft/src/syft/service/worker/worker_image_service.py index de205213655..b82956c3a03 100644 --- a/packages/syft/src/syft/service/worker/worker_image_service.py +++ b/packages/syft/src/syft/service/worker/worker_image_service.py @@ -105,10 +105,7 @@ def build( ).unwrap() if registry_uid: # get registry from image registry service - image_registry_service: AbstractService = context.server.get_service( - SyftImageRegistryService - ) - registry = image_registry_service.get_by_id(context, registry_uid) + registry = context.server.services.image_registry.get_by_id(context, registry_uid) try: if registry: diff --git a/packages/syft/src/syft/service/worker/worker_pool_service.py b/packages/syft/src/syft/service/worker/worker_pool_service.py index 09964dba1f2..000cac067c2 100644 --- a/packages/syft/src/syft/service/worker/worker_pool_service.py +++ b/packages/syft/src/syft/service/worker/worker_pool_service.py @@ -126,8 +126,7 @@ def launch( credentials=context.credentials, uid=image_uid ).unwrap() - worker_service: AbstractService = context.server.get_service("WorkerService") - worker_stash = worker_service.stash + worker_stash = context.server.services.worker.stash # Create worker pool from given image, with the given worker pool # and with the desired number of workers @@ -385,8 +384,7 @@ def add_workers( uid=worker_pool.image_id, ).unwrap() - worker_service: AbstractService = context.server.get_service("WorkerService") - worker_stash = worker_service.stash + worker_stash = context.server.services.worker.stash # Add workers to given pool from the given image worker_list, container_statuses = _create_workers_in_pool( @@ -465,7 +463,7 @@ def scale( -(current_worker_count - number) : ] - worker_stash = context.server.get_service("WorkerService").stash + worker_stash = context.server.services.worker.stash # delete linkedobj workers for worker in workers_to_delete: worker_stash.delete_by_uid( @@ -594,8 +592,7 @@ def delete( from ..queue.queue_service import QueueService from ..queue.queue_stash import Status - queue_service = cast(QueueService, context.server.get_service(QueueService)) - queue_items = queue_service.stash._get_by_worker_pool( + queue_items = context.server.services.queue.stash._get_by_worker_pool( credentials=context.credentials, worker_pool=LinkedObject.from_obj( obj=worker_pool, @@ -614,15 +611,11 @@ def delete( for item in items_to_interrupt: item.status = Status.INTERRUPTED - queue_service.stash.update( + context.server.services.queue.stash.update( credentials=context.credentials, obj=item, ).unwrap() - worker_service = cast( - WorkerService, context.server.get_service("WorkerService") - ) - if IN_KUBERNETES: # Scale the workers to zero self.scale(context=context, number=0, pool_id=uid) @@ -639,7 +632,7 @@ def delete( worker_ids.append(worker.id) for id_ in worker_ids: - worker_service.delete(context=context, uid=id_, force=True) + context.server.services.worker.delete(context=context, uid=id_, force=True) self.stash.delete_by_uid(credentials=context.credentials, uid=uid).unwrap( public_message=f"Failed to delete WorkerPool: {worker_pool.name} from stash" diff --git a/packages/syft/src/syft/service/worker/worker_service.py b/packages/syft/src/syft/service/worker/worker_service.py index a324035b2d2..625a88a46b4 100644 --- a/packages/syft/src/syft/service/worker/worker_service.py +++ b/packages/syft/src/syft/service/worker/worker_service.py @@ -56,8 +56,7 @@ def start_workers( ) -> list[ContainerSpawnStatus]: """Add a Container Image.""" - worker_pool_service = context.server.get_service("SyftWorkerPoolService") - return worker_pool_service.add_workers( + return context.server.services.syft_worker_pool.add_workers( context, number=n, pool_name=DEFAULT_WORKER_POOL_NAME ) @@ -138,19 +137,10 @@ def _delete( self, context: AuthedServiceContext, worker: SyftWorker, force: bool = False ) -> SyftSuccess: uid = worker.id - - # relative - from ...service.job.job_service import JobService - from .worker_pool_service import SyftWorkerPoolService - if force and worker.job_id is not None: - job_service = cast(JobService, context.server.get_service(JobService)) - job_service.kill(context=context, id=worker.job_id) + context.server.services.job.kill(context=context, id=worker.job_id) - worker_pool_service = cast( - SyftWorkerPoolService, context.server.get_service(SyftWorkerPoolService) - ) - worker_pool_stash = worker_pool_service.stash + worker_pool_stash = context.server.services.syft_worker_pool.stash worker_pool = worker_pool_stash.get_by_name( credentials=context.credentials, pool_name=worker.worker_pool_name ).unwrap() diff --git a/packages/syft/tests/syft/action_test.py b/packages/syft/tests/syft/action_test.py index c7829daa9d3..39d6b1871bc 100644 --- a/packages/syft/tests/syft/action_test.py +++ b/packages/syft/tests/syft/action_test.py @@ -23,7 +23,7 @@ def test_actionobject_method(worker): root_datasite_client = worker.root_client assert root_datasite_client.settings.enable_eager_execution(enable=True) - action_store = worker.get_service("actionservice").store + action_store = worker.services.action.store obj = ActionObject.from_obj("abc") pointer = obj.send(root_datasite_client) assert len(action_store.data) == 1 @@ -75,7 +75,7 @@ def test_lib_function_action(worker): assert isinstance(res, ActionObject) assert all(res == np.array([0, 0, 0])) - assert len(worker.get_service("actionservice").store.data) > 0 + assert len(worker.services.action.store.data) > 0 def test_call_lib_function_action2(worker): @@ -90,7 +90,7 @@ def test_lib_class_init_action(worker): assert isinstance(res, ActionObject) assert res == np.float32(4.0) - assert len(worker.get_service("actionservice").store.data) > 0 + assert len(worker.services.action.store.data) > 0 def test_call_lib_wo_permission(worker): diff --git a/packages/syft/tests/syft/api_test.py b/packages/syft/tests/syft/api_test.py index 67febf838b0..6c511b45d48 100644 --- a/packages/syft/tests/syft/api_test.py +++ b/packages/syft/tests/syft/api_test.py @@ -48,7 +48,7 @@ def test_api_cache_invalidation_login(root_verify_key, worker): user_id = worker.document_store.partitions["User"].all(root_verify_key).value[-1].id def get_role(verify_key): - users = worker.get_service("UserService").stash.get_all(root_verify_key).ok() + users = worker.services.user.stash.get_all(root_verify_key).ok() user = [u for u in users if u.verify_key == verify_key][0] return user.role diff --git a/packages/syft/tests/syft/blob_storage/blob_storage_test.py b/packages/syft/tests/syft/blob_storage/blob_storage_test.py index 4204ffc6ade..8b8613498fb 100644 --- a/packages/syft/tests/syft/blob_storage/blob_storage_test.py +++ b/packages/syft/tests/syft/blob_storage/blob_storage_test.py @@ -33,7 +33,7 @@ def authed_context(worker): @pytest.fixture(scope="function") def blob_storage(worker): - yield worker.get_service("BlobStorageService") + yield worker.services.blob_storage def test_blob_storage_allocate(authed_context, blob_storage): @@ -46,7 +46,7 @@ def test_blob_storage_write(): random.seed() name = "".join(str(random.randint(0, 9)) for i in range(8)) worker = sy.Worker.named(name=name) - blob_storage = worker.get_service("BlobStorageService") + blob_storage = worker.services.blob_storage authed_context = AuthedServiceContext( server=worker, credentials=worker.signing_key.verify_key ) @@ -64,7 +64,7 @@ def test_blob_storage_write_syft_object(): random.seed() name = "".join(str(random.randint(0, 9)) for i in range(8)) worker = sy.Worker.named(name=name) - blob_storage = worker.get_service("BlobStorageService") + blob_storage = worker.services.blob_storage authed_context = AuthedServiceContext( server=worker, credentials=worker.signing_key.verify_key ) @@ -82,7 +82,7 @@ def test_blob_storage_read(): random.seed() name = "".join(str(random.randint(0, 9)) for i in range(8)) worker = sy.Worker.named(name=name) - blob_storage = worker.get_service("BlobStorageService") + blob_storage = worker.services.blob_storage authed_context = AuthedServiceContext( server=worker, credentials=worker.signing_key.verify_key ) @@ -142,7 +142,7 @@ def test_action_obj_send_save_to_blob_storage(worker): root_authed_ctx = AuthedServiceContext( server=worker, credentials=root_client.verify_key ) - blob_storage = worker.get_service("BlobStorageService") + blob_storage = worker.services.blob_storage syft_retrieved_data = blob_storage.read( root_authed_ctx, action_obj_2.syft_blob_storage_entry_id ) diff --git a/packages/syft/tests/syft/service/action/action_object_test.py b/packages/syft/tests/syft/service/action/action_object_test.py index e53412d7b84..76fd4d82685 100644 --- a/packages/syft/tests/syft/service/action/action_object_test.py +++ b/packages/syft/tests/syft/service/action/action_object_test.py @@ -506,7 +506,7 @@ def test_actionobject_syft_get_path(testcase): def test_actionobject_syft_send_get(worker, testcase): root_datasite_client = worker.root_client root_datasite_client._fetch_api(root_datasite_client.credentials) - action_store = worker.get_service("actionservice").store + action_store = worker.services.action.store orig_obj = testcase obj = helper_make_action_obj(orig_obj) diff --git a/packages/syft/tests/syft/service/action/action_service_test.py b/packages/syft/tests/syft/service/action/action_service_test.py index bb8057d4ee3..5a6b5561d99 100644 --- a/packages/syft/tests/syft/service/action/action_service_test.py +++ b/packages/syft/tests/syft/service/action/action_service_test.py @@ -16,7 +16,7 @@ def get_auth_ctx(worker): def test_action_service_sanity(worker): - service = worker.get_service("actionservice") + service = worker.services.action root_datasite_client = worker.root_client obj = ActionObject.from_obj("abc") diff --git a/packages/syft/tests/syft/users/user_code_test.py b/packages/syft/tests/syft/users/user_code_test.py index a1fa1a3925d..9410cecd695 100644 --- a/packages/syft/tests/syft/users/user_code_test.py +++ b/packages/syft/tests/syft/users/user_code_test.py @@ -72,7 +72,7 @@ def test_new_admin_can_list_user_code( res = root_client.api.services.user.delete(root_client.account.id) assert not isinstance(res, SyftError) - user_code_stash = worker.get_service("usercodeservice").stash + user_code_stash = worker.services.user_code.stash user_code = user_code_stash.get_all(user_code_stash.store.root_verify_key).ok() assert len(user_code) == len(admin.code.get_all()) diff --git a/packages/syft/tests/syft/users/user_test.py b/packages/syft/tests/syft/users/user_test.py index 99d525fe857..1a9830ed48c 100644 --- a/packages/syft/tests/syft/users/user_test.py +++ b/packages/syft/tests/syft/users/user_test.py @@ -31,7 +31,7 @@ def get_users(worker): - return worker.get_service("UserService").get_all( + return worker.services.user.get_all( AuthedServiceContext(server=worker, credentials=worker.signing_key.verify_key) ) diff --git a/packages/syft/tests/syft/worker_test.py b/packages/syft/tests/syft/worker_test.py index 3f2e22eea31..c3e4d93c560 100644 --- a/packages/syft/tests/syft/worker_test.py +++ b/packages/syft/tests/syft/worker_test.py @@ -133,7 +133,7 @@ def test_user_transform() -> None: def test_user_service(worker) -> None: test_signing_key = SyftSigningKey.from_string(test_signing_key_string) - user_service = worker.get_service(UserService) + user_service = worker.services.user # create a user new_user = UserCreate( From 3d184c6fb5cd4148e65c746a7601275b3f466d28 Mon Sep 17 00:00:00 2001 From: teo Date: Mon, 9 Sep 2024 12:47:41 +0300 Subject: [PATCH 07/13] fix lint --- packages/syft/src/syft/server/server.py | 21 ++++++++----------- .../syft/service/action/action_endpoint.py | 10 +++++---- .../src/syft/service/action/action_object.py | 4 +++- .../src/syft/service/action/action_service.py | 2 -- .../syft/src/syft/service/api/api_service.py | 1 - .../syft/src/syft/service/code/user_code.py | 14 ++++++++----- .../syft/service/code/user_code_service.py | 4 +++- .../code_history/code_history_service.py | 1 - .../data_subject/data_subject_service.py | 7 ++++--- .../syft/service/dataset/dataset_service.py | 2 -- .../syft/src/syft/service/job/job_service.py | 6 +++--- .../service/network/association_request.py | 1 - .../syft/src/syft/service/network/utils.py | 2 -- .../notification/notification_service.py | 6 +++--- .../syft/service/notifier/notifier_service.py | 5 +++-- .../syft/src/syft/service/policy/policy.py | 1 + .../syft/service/project/project_service.py | 19 ++++++++--------- .../src/syft/service/queue/zmq_producer.py | 7 ++++--- .../syft/src/syft/service/request/request.py | 14 +++++++------ .../syft/service/settings/settings_service.py | 14 ++++++++----- .../src/syft/service/sync/sync_service.py | 5 ++--- .../src/syft/service/user/user_service.py | 4 +++- .../service/worker/worker_image_service.py | 5 +++-- .../service/worker/worker_pool_service.py | 6 +++--- packages/syft/tests/syft/worker_test.py | 1 - tests/integration/local/twin_api_sync_test.py | 6 ++---- 26 files changed, 87 insertions(+), 81 deletions(-) diff --git a/packages/syft/src/syft/server/server.py b/packages/syft/src/syft/server/server.py index 177c7184ec5..6e0fc0f97b0 100644 --- a/packages/syft/src/syft/server/server.py +++ b/packages/syft/src/syft/server/server.py @@ -42,8 +42,6 @@ from ..service.action.action_store import DictActionStore from ..service.action.action_store import MongoActionStore from ..service.action.action_store import SQLiteActionStore -from ..service.blob_storage.service import BlobStorageService -from ..service.code.user_code_service import UserCodeService from ..service.code.user_code_stash import UserCodeStash from ..service.context import AuthedServiceContext from ..service.context import ServerServiceContext @@ -54,7 +52,6 @@ from ..service.job.job_stash import JobStatus from ..service.job.job_stash import JobType from ..service.metadata.server_metadata import ServerMetadata -from ..service.network.network_service import NetworkService from ..service.network.utils import PeerHealthCheckTask from ..service.notifier.notifier_service import NotifierService from ..service.queue.base_queue import AbstractMessageHandler @@ -81,12 +78,10 @@ from ..service.user.user import UserCreate from ..service.user.user import UserView from ..service.user.user_roles import ServiceRole -from ..service.user.user_service import UserService from ..service.user.user_stash import UserStash from ..service.worker.utils import DEFAULT_WORKER_IMAGE_TAG from ..service.worker.utils import DEFAULT_WORKER_POOL_NAME from ..service.worker.utils import create_default_image -from ..service.worker.worker_image_service import SyftWorkerImageService from ..service.worker.worker_pool import WorkerPool from ..service.worker.worker_pool_service import SyftWorkerPoolService from ..service.worker.worker_pool_stash import SyftWorkerPoolStash @@ -814,7 +809,9 @@ def find_and_migrate_data( credentials=self.verify_key, role=ServiceRole.ADMIN, ) - return self.services.migration.migrate_data(context, document_store_object_types) + return self.services.migration.migrate_data( + context, document_store_object_types + ) @property def guest_client(self) -> SyftClient: @@ -1113,7 +1110,9 @@ def forward_message( ) client = None - peer = self.services.network.stash.get_by_uid(self.verify_key, server_uid).unwrap() + peer = self.services.network.stash.get_by_uid( + self.verify_key, server_uid + ).unwrap() # Since we have several routes to a peer # we need to cache the client for a given server_uid along with the route @@ -1157,11 +1156,9 @@ def forward_message( raise SyftException(public_message=(f"Server has no route to {server_uid}")) def get_role_for_credentials(self, credentials: SyftVerifyKey) -> ServiceRole: - return ( - self.services.user - .get_role_for_credentials(credentials=credentials) - .unwrap() - ) + return self.services.user.get_role_for_credentials( + credentials=credentials + ).unwrap() @instrument def handle_api_call( diff --git a/packages/syft/src/syft/service/action/action_endpoint.py b/packages/syft/src/syft/service/action/action_endpoint.py index b0083fc0192..966794a1ac0 100644 --- a/packages/syft/src/syft/service/action/action_endpoint.py +++ b/packages/syft/src/syft/service/action/action_endpoint.py @@ -76,13 +76,15 @@ def __call_function( ) -> Any: self.context = self.__check_context() if call_mode == EXECUTION_MODE.MOCK: - __endpoint_mode = self.context.server.services.api.execute_server_side_endpoint_mock_by_id - elif call_mode == EXECUTION_MODE.PRIVATE: __endpoint_mode = ( - self.context.server.services.api.execute_service_side_endpoint_private_by_id + self.context.server.services.api.execute_server_side_endpoint_mock_by_id ) + elif call_mode == EXECUTION_MODE.PRIVATE: + __endpoint_mode = self.context.server.services.api.execute_service_side_endpoint_private_by_id else: - __endpoint_mode = self.context.server.services.api.execute_server_side_endpoint_by_id + __endpoint_mode = ( + self.context.server.services.api.execute_server_side_endpoint_by_id + ) return __endpoint_mode( *args, diff --git a/packages/syft/src/syft/service/action/action_object.py b/packages/syft/src/syft/service/action/action_object.py index 4ee377aa14b..d7e566b733a 100644 --- a/packages/syft/src/syft/service/action/action_object.py +++ b/packages/syft/src/syft/service/action/action_object.py @@ -1175,7 +1175,9 @@ def get_sync_dependencies( # relative from ..job.job_stash import Job - job: Job | None = context.server.services.job.get_by_result_id(context, self.id.id) # type: ignore + job: Job | None = context.server.services.job.get_by_result_id( + context, self.id.id + ) # type: ignore if job is not None: return [job.id] else: diff --git a/packages/syft/src/syft/service/action/action_service.py b/packages/syft/src/syft/service/action/action_service.py index b5326ae45de..94935631f01 100644 --- a/packages/syft/src/syft/service/action/action_service.py +++ b/packages/syft/src/syft/service/action/action_service.py @@ -2,7 +2,6 @@ import importlib import logging from typing import Any -from typing import cast # third party import numpy as np @@ -18,7 +17,6 @@ from ...types.syft_object import SyftObject from ...types.twin_object import TwinObject from ...types.uid import UID -from ..blob_storage.service import BlobStorageService from ..code.user_code import UserCode from ..code.user_code import execute_byte_code from ..context import AuthedServiceContext diff --git a/packages/syft/src/syft/service/api/api_service.py b/packages/syft/src/syft/service/api/api_service.py index fed9fe6e250..a8c443a6271 100644 --- a/packages/syft/src/syft/service/api/api_service.py +++ b/packages/syft/src/syft/service/api/api_service.py @@ -16,7 +16,6 @@ from ...types.errors import SyftException from ...types.result import as_result from ...types.uid import UID -from ..action.action_service import ActionService from ..context import AuthedServiceContext from ..response import SyftSuccess from ..service import AbstractService diff --git a/packages/syft/src/syft/service/code/user_code.py b/packages/syft/src/syft/service/code/user_code.py index fbb259abcea..0921ea9e704 100644 --- a/packages/syft/src/syft/service/code/user_code.py +++ b/packages/syft/src/syft/service/code/user_code.py @@ -74,7 +74,6 @@ from ..dataset.dataset import Asset from ..job.job_stash import Job from ..output.output_service import ExecutionOutput -from ..output.output_service import OutputService from ..policy.policy import Constant from ..policy.policy import CustomInputPolicy from ..policy.policy import CustomOutputPolicy @@ -89,7 +88,6 @@ from ..policy.policy import init_policy from ..policy.policy import load_policy_code from ..policy.policy import partition_by_server -from ..policy.policy_service import PolicyService from ..response import SyftError from ..response import SyftInfo from ..response import SyftSuccess @@ -1454,7 +1452,9 @@ def locate_launch_jobs(context: TransformContext) -> TransformContext: v.visit(tree) nested_calls = v.nested_calls for call in nested_calls: - user_codes = context.server.services.user_code.get_by_service_name(context, call) + user_codes = context.server.services.user_code.get_by_service_name( + context, call + ) # TODO: Not great user_code = user_codes[-1] user_code_link = LinkedObject.from_obj( @@ -1788,7 +1788,9 @@ def to_str(arg: Any) -> str: new_args = [to_str(arg) for arg in args] new_str = sep.join(new_args) + end if context.server is not None: - context.server.services.log.append(context=context, uid=log_id, new_str=new_str) + context.server.services.log.append( + context=context, uid=log_id, new_str=new_str + ) time = datetime.datetime.now().strftime("%d/%m/%y %H:%M:%S") return __builtin__.print( f"{time} FUNCTION LOG ({job_id}):", @@ -1853,7 +1855,9 @@ def to_str(arg: Any) -> str: and context.job.log_id is not None ): log_id = context.job.log_id - context.server.services.log.append(context=context, uid=log_id, new_err=error_msg) + context.server.services.log.append( + context=context, uid=log_id, new_err=error_msg + ) result_message = ( f"Exception encountered while running {code_item.service_func_name}" diff --git a/packages/syft/src/syft/service/code/user_code_service.py b/packages/syft/src/syft/service/code/user_code_service.py index 6fa6e370666..32863990a6a 100644 --- a/packages/syft/src/syft/service/code/user_code_service.py +++ b/packages/syft/src/syft/service/code/user_code_service.py @@ -209,7 +209,9 @@ def _post_user_code_transform_ops( ) # Create a code history - context.server.services.code_history.submit_version(context=context, code=user_code) + context.server.services.code_history.submit_version( + context=context, code=user_code + ) return user_code diff --git a/packages/syft/src/syft/service/code_history/code_history_service.py b/packages/syft/src/syft/service/code_history/code_history_service.py index bcff8b6698d..75a54e79b5e 100644 --- a/packages/syft/src/syft/service/code_history/code_history_service.py +++ b/packages/syft/src/syft/service/code_history/code_history_service.py @@ -8,7 +8,6 @@ from ...types.uid import UID from ..code.user_code import SubmitUserCode from ..code.user_code import UserCode -from ..code.user_code_service import UserCodeService from ..context import AuthedServiceContext from ..response import SyftSuccess from ..service import AbstractService diff --git a/packages/syft/src/syft/service/data_subject/data_subject_service.py b/packages/syft/src/syft/service/data_subject/data_subject_service.py index 9b2a0c8bd54..420d6b66d2d 100644 --- a/packages/syft/src/syft/service/data_subject/data_subject_service.py +++ b/packages/syft/src/syft/service/data_subject/data_subject_service.py @@ -20,7 +20,6 @@ from .data_subject import DataSubject from .data_subject import DataSubjectCreate from .data_subject import NamePartitionKey -from .data_subject_member_service import DataSubjectMemberService @serializable(canonical_name="DataSubjectStash", version=1) @@ -63,7 +62,7 @@ def __init__(self, store: DocumentStore) -> None: def add( self, context: AuthedServiceContext, data_subject: DataSubjectCreate ) -> SyftSuccess: - """Register a data subject."""# + """Register a data subject.""" # member_relationships: set[tuple[str, str]] = data_subject.member_relationships if len(member_relationships) == 0: @@ -81,7 +80,9 @@ def add( ignore_duplicates=True, ).unwrap() # TODO: this name seems wrong, but CI might not test it - context.server.services.data_subject.add(context, parent_ds.name, child_ds.name) + context.server.services.data_subject.add( + context, parent_ds.name, child_ds.name + ) return SyftSuccess( message=f"{len(member_relationships)+1} Data Subjects Registered", diff --git a/packages/syft/src/syft/service/dataset/dataset_service.py b/packages/syft/src/syft/service/dataset/dataset_service.py index 3a16b7f1862..43cbfacb117 100644 --- a/packages/syft/src/syft/service/dataset/dataset_service.py +++ b/packages/syft/src/syft/service/dataset/dataset_service.py @@ -2,7 +2,6 @@ from collections.abc import Collection from collections.abc import Sequence import logging -from typing import cast # relative from ...serde.serializable import serializable @@ -11,7 +10,6 @@ from ...types.uid import UID from ..action.action_permissions import ActionObjectPermission from ..action.action_permissions import ActionPermission -from ..action.action_service import ActionService from ..context import AuthedServiceContext from ..response import SyftSuccess from ..service import AbstractService diff --git a/packages/syft/src/syft/service/job/job_service.py b/packages/syft/src/syft/service/job/job_service.py index de4a1939cc9..fbbdfd7d856 100644 --- a/packages/syft/src/syft/service/job/job_service.py +++ b/packages/syft/src/syft/service/job/job_service.py @@ -2,7 +2,6 @@ from collections.abc import Callable import inspect import time -from typing import cast # relative from ...serde.serializable import serializable @@ -15,7 +14,6 @@ from ..action.action_permissions import ActionPermission from ..code.user_code import UserCode from ..context import AuthedServiceContext -from ..log.log_service import LogService from ..queue.queue_stash import ActionQueueItem from ..response import SyftSuccess from ..service import AbstractService @@ -264,7 +262,9 @@ def create_job_for_user_code_id( user_code_id=user_code_id, resolved=is_resolved, ) - user_code = context.server.services.user_code.get_by_uid(context=context, uid=user_code_id) + user_code = context.server.services.user_code.get_by_uid( + context=context, uid=user_code_id + ) # The owner of the code should be able to read the job self.stash.set(context.credentials, job).unwrap() diff --git a/packages/syft/src/syft/service/network/association_request.py b/packages/syft/src/syft/service/network/association_request.py index bfafe33bdbd..49071512ff1 100644 --- a/packages/syft/src/syft/service/network/association_request.py +++ b/packages/syft/src/syft/service/network/association_request.py @@ -1,6 +1,5 @@ # stdlib import secrets -from typing import cast # relative from ...client.client import SyftClient diff --git a/packages/syft/src/syft/service/network/utils.py b/packages/syft/src/syft/service/network/utils.py index a2a6ca6e1f0..280e836f17b 100644 --- a/packages/syft/src/syft/service/network/utils.py +++ b/packages/syft/src/syft/service/network/utils.py @@ -2,7 +2,6 @@ import logging import threading import time -from typing import cast # relative from ...serde.serializable import serializable @@ -10,7 +9,6 @@ from ...types.errors import SyftException from ..context import AuthedServiceContext from ..response import SyftError -from .network_service import NetworkService from .network_service import ServerPeerAssociationStatus from .server_peer import ServerPeer from .server_peer import ServerPeerConnectionStatus diff --git a/packages/syft/src/syft/service/notification/notification_service.py b/packages/syft/src/syft/service/notification/notification_service.py index 2bf7d17c21f..15b2b9725d8 100644 --- a/packages/syft/src/syft/service/notification/notification_service.py +++ b/packages/syft/src/syft/service/notification/notification_service.py @@ -5,7 +5,6 @@ from ...store.document_store import DocumentStore from ...store.document_store_errors import StashException from ...types.errors import SyftException -from ...types.result import OkErr from ...types.result import as_result from ...types.uid import UID from ..action.action_permissions import ActionObjectREAD @@ -54,7 +53,9 @@ def send( context.credentials, new_notification, add_permissions=permissions ).unwrap() - context.server.services.notifier.dispatch_notification(context, new_notification).unwrap() + context.server.services.notifier.dispatch_notification( + context, new_notification + ).unwrap() return new_notification @service_method(path="notifications.reply", name="reply", roles=GUEST_ROLE_LEVEL) @@ -94,7 +95,6 @@ def settings( context: AuthedServiceContext, ) -> NotifierSettings: return context.server.services.notifier.settings(context).unwrap() - @service_method( path="notifications.activate", diff --git a/packages/syft/src/syft/service/notifier/notifier_service.py b/packages/syft/src/syft/service/notifier/notifier_service.py index 95b81c05629..d8c1da2530f 100644 --- a/packages/syft/src/syft/service/notifier/notifier_service.py +++ b/packages/syft/src/syft/service/notifier/notifier_service.py @@ -12,7 +12,6 @@ from ...store.document_store_errors import NotFoundException from ...store.document_store_errors import StashException from ...types.errors import SyftException -from ...types.result import OkErr from ...types.result import as_result from ..context import AuthedServiceContext from ..notification.email_templates import PasswordResetTemplate @@ -216,7 +215,9 @@ def activate( Activate email notifications for the authenticated user. This will only work if the datasite owner has enabled notifications. """ - return context.server.services.user.enable_notifications(context, notifier_type=notifier_type).unwrap() + return context.server.services.user.enable_notifications( + context, notifier_type=notifier_type + ).unwrap() @as_result(SyftException) def deactivate( diff --git a/packages/syft/src/syft/service/policy/policy.py b/packages/syft/src/syft/service/policy/policy.py index 96a562cf0cf..3b1f33c0a08 100644 --- a/packages/syft/src/syft/service/policy/policy.py +++ b/packages/syft/src/syft/service/policy/policy.py @@ -369,6 +369,7 @@ def user_code_arg2id(arg: Any) -> UID: def retrieve_item_from_db(id: UID, context: AuthedServiceContext) -> ActionObject: # relative from ...service.action.action_object import TwinMode + root_context = AuthedServiceContext( server=context.server, credentials=context.server.verify_key ) diff --git a/packages/syft/src/syft/service/project/project_service.py b/packages/syft/src/syft/service/project/project_service.py index e5a033f5585..3a2543e38a1 100644 --- a/packages/syft/src/syft/service/project/project_service.py +++ b/packages/syft/src/syft/service/project/project_service.py @@ -1,7 +1,6 @@ # stdlib # stdlib -from typing import cast # relative from ...serde.serializable import serializable @@ -13,7 +12,6 @@ from ...types.result import as_result from ...types.uid import UID from ..context import AuthedServiceContext -from ..network.network_service import NetworkService from ..notification.notifications import CreateNotification from ..response import SyftError from ..response import SyftSuccess @@ -24,7 +22,6 @@ from ..user.user_roles import DATA_SCIENTIST_ROLE_LEVEL from ..user.user_roles import GUEST_ROLE_LEVEL from ..user.user_roles import ServiceRole -from ..user.user_service import UserService from .project import Project from .project import ProjectEvent from .project import ProjectRequest @@ -136,13 +133,15 @@ def create_project( if leader_server.verify_key != context.server.verify_key: # FIX: networkservice stash to new BaseStash peer_id = context.server.id.short() if context.server.id else "" - leader_server_peer = context.server.services.network.stash.get_by_verify_key( - credentials=context.server.verify_key, - verify_key=leader_server.verify_key, - ).unwrap( - public_message=( - f"Leader Server(id={leader_server.id.short()}) is not a " - f"peer of this Server(id={peer_id})" + leader_server_peer = ( + context.server.services.network.stash.get_by_verify_key( + credentials=context.server.verify_key, + verify_key=leader_server.verify_key, + ).unwrap( + public_message=( + f"Leader Server(id={leader_server.id.short()}) is not a " + f"peer of this Server(id={peer_id})" + ) ) ) else: diff --git a/packages/syft/src/syft/service/queue/zmq_producer.py b/packages/syft/src/syft/service/queue/zmq_producer.py index dd2ee0d585e..5cb5056f8a2 100644 --- a/packages/syft/src/syft/service/queue/zmq_producer.py +++ b/packages/syft/src/syft/service/queue/zmq_producer.py @@ -7,7 +7,6 @@ from threading import Event from time import sleep from typing import Any -from typing import cast # third party import zmq @@ -265,8 +264,10 @@ def purge_workers(self) -> None: self.delete_worker(worker, syft_worker.to_be_deleted) # relative - from ...service.worker.worker_service import WorkerService - self.auth_context.server.services.worker._delete(self.auth_context, syft_worker) + + self.auth_context.server.services.worker._delete( + self.auth_context, syft_worker + ) def update_consumer_state_for_worker( self, syft_worker_id: UID, consumer_state: ConsumerState diff --git a/packages/syft/src/syft/service/request/request.py b/packages/syft/src/syft/service/request/request.py index 4d434a1294d..1a492ea1d53 100644 --- a/packages/syft/src/syft/service/request/request.py +++ b/packages/syft/src/syft/service/request/request.py @@ -40,10 +40,8 @@ from ...util.notebook_ui.icons import Icon from ...util.util import prompt_warning_message from ..action.action_object import ActionObject -from ..action.action_service import ActionService from ..action.action_store import ActionObjectPermission from ..action.action_store import ActionPermission -from ..blob_storage.service import BlobStorageService from ..code.user_code import UserCode from ..code.user_code import UserCodeStatus from ..code.user_code import UserCodeStatusCollection @@ -224,11 +222,15 @@ def _tag_required_for_dockerworkerconfig(self) -> Self: @as_result(SyftException) def _run(self, context: ChangeContext, apply: bool) -> SyftSuccess: service_context = context.to_service_ctx() - context.server.services.syft_worker_image.submit(service_context, worker_config=self.config) + context.server.services.syft_worker_image.submit( + service_context, worker_config=self.config + ) - worker_image = context.server.services.syft_worker_image.stash.get_by_worker_config( - service_context.credentials, config=self.config - ).unwrap() + worker_image = ( + context.server.services.syft_worker_image.stash.get_by_worker_config( + service_context.credentials, config=self.config + ).unwrap() + ) if worker_image is None: raise SyftException(public_message="The worker image does not exist.") diff --git a/packages/syft/src/syft/service/settings/settings_service.py b/packages/syft/src/syft/service/settings/settings_service.py index faa52bdff6d..43fe685b7e5 100644 --- a/packages/syft/src/syft/service/settings/settings_service.py +++ b/packages/syft/src/syft/service/settings/settings_service.py @@ -1,7 +1,6 @@ # stdlib from string import Template from typing import Any -from typing import cast # third party from pydantic import ValidationError @@ -27,7 +26,6 @@ from ..context import AuthedServiceContext from ..context import UnauthedServiceContext from ..notifier.notifier_enums import EMAIL_TYPES -from ..notifier.notifier_service import NotifierService from ..response import SyftSuccess from ..service import AbstractService from ..service import service_method @@ -137,7 +135,9 @@ def _update( # If notifications_enabled is present in the update, we need to update the notifier settings if settings.notifications_enabled is not Empty: # type: ignore[comparison-overlap] - notifier_settings_res = context.server.services.notifier.settings(context) + notifier_settings_res = context.server.services.notifier.settings( + context + ) if ( not notifier_settings_res.is_ok() or notifier_settings_res.ok() is None @@ -266,7 +266,9 @@ def enable_eager_execution( def set_email_rate_limit( self, context: AuthedServiceContext, email_type: EMAIL_TYPES, daily_limit: int ) -> SyftSuccess: - return context.server.services.notifier.set_email_rate_limit(context, email_type, daily_limit) + return context.server.services.notifier.set_email_rate_limit( + context, email_type, daily_limit + ) @service_method( path="settings.allow_association_request_auto_approval", @@ -345,7 +347,9 @@ def welcome_show( all_settings = self.stash.get_all( context.server.signing_key.verify_key ).unwrap() - role = context.server.services.user.get_role_for_credentials(context.credentials).unwrap() + role = context.server.services.user.get_role_for_credentials( + context.credentials + ).unwrap() # check if the settings list is empty if len(all_settings) == 0: diff --git a/packages/syft/src/syft/service/sync/sync_service.py b/packages/syft/src/syft/service/sync/sync_service.py index c42060b3125..00393543636 100644 --- a/packages/syft/src/syft/service/sync/sync_service.py +++ b/packages/syft/src/syft/service/sync/sync_service.py @@ -22,7 +22,6 @@ from ..action.action_permissions import ActionPermission from ..action.action_permissions import StoragePermission from ..api.api import TwinAPIEndpoint -from ..api.api_service import APIService from ..code.user_code import UserCodeStatusCollection from ..context import AuthedServiceContext from ..job.job_stash import Job @@ -295,10 +294,10 @@ def _get_job_batch( self, context: AuthedServiceContext, job: Job ) -> list[SyncableSyftObject]: job_batch = [job] - + log = context.server.services.log.get(context, job.log_id) job_batch.append(log) - + try: output = context.server.services.output.get_by_job_id(context, job.id) except NotFoundException: diff --git a/packages/syft/src/syft/service/user/user_service.py b/packages/syft/src/syft/service/user/user_service.py index 6229829926c..38ea9d5f005 100644 --- a/packages/syft/src/syft/service/user/user_service.py +++ b/packages/syft/src/syft/service/user/user_service.py @@ -159,7 +159,9 @@ def forgot_password( # Instead of changing the password here, we would change it in email template generation. link = LinkedObject.with_context(user, context=root_context) # Notifier is active - notifier = root_context.server.services.notifier.settings(context=root_context).unwrap() + notifier = root_context.server.services.notifier.settings( + context=root_context + ).unwrap() notification_is_enabled = notifier.active # Email is enabled email_is_enabled = notifier.email_enabled diff --git a/packages/syft/src/syft/service/worker/worker_image_service.py b/packages/syft/src/syft/service/worker/worker_image_service.py index b82956c3a03..cb5facd125f 100644 --- a/packages/syft/src/syft/service/worker/worker_image_service.py +++ b/packages/syft/src/syft/service/worker/worker_image_service.py @@ -22,7 +22,6 @@ from ..user.user_roles import DATA_OWNER_ROLE_LEVEL from ..user.user_roles import DATA_SCIENTIST_ROLE_LEVEL from .image_registry import SyftImageRegistry -from .image_registry_service import SyftImageRegistryService from .utils import image_build from .utils import image_push from .worker_image import SyftWorkerImage @@ -105,7 +104,9 @@ def build( ).unwrap() if registry_uid: # get registry from image registry service - registry = context.server.services.image_registry.get_by_id(context, registry_uid) + registry = context.server.services.image_registry.get_by_id( + context, registry_uid + ) try: if registry: diff --git a/packages/syft/src/syft/service/worker/worker_pool_service.py b/packages/syft/src/syft/service/worker/worker_pool_service.py index 000cac067c2..4ceced2bf26 100644 --- a/packages/syft/src/syft/service/worker/worker_pool_service.py +++ b/packages/syft/src/syft/service/worker/worker_pool_service.py @@ -1,7 +1,6 @@ # stdlib import logging from typing import Any -from typing import cast # third party import pydantic @@ -589,7 +588,6 @@ def delete( uid = worker_pool.id # relative - from ..queue.queue_service import QueueService from ..queue.queue_stash import Status queue_items = context.server.services.queue.stash._get_by_worker_pool( @@ -632,7 +630,9 @@ def delete( worker_ids.append(worker.id) for id_ in worker_ids: - context.server.services.worker.delete(context=context, uid=id_, force=True) + context.server.services.worker.delete( + context=context, uid=id_, force=True + ) self.stash.delete_by_uid(credentials=context.credentials, uid=uid).unwrap( public_message=f"Failed to delete WorkerPool: {worker_pool.name} from stash" diff --git a/packages/syft/tests/syft/worker_test.py b/packages/syft/tests/syft/worker_test.py index c3e4d93c560..ce0f027a101 100644 --- a/packages/syft/tests/syft/worker_test.py +++ b/packages/syft/tests/syft/worker_test.py @@ -23,7 +23,6 @@ from syft.service.user.user import User from syft.service.user.user import UserCreate from syft.service.user.user import UserView -from syft.service.user.user_service import UserService from syft.types.errors import SyftException from syft.types.result import Ok from syft.types.uid import UID diff --git a/tests/integration/local/twin_api_sync_test.py b/tests/integration/local/twin_api_sync_test.py index 7fac899a925..9e8d28adaa7 100644 --- a/tests/integration/local/twin_api_sync_test.py +++ b/tests/integration/local/twin_api_sync_test.py @@ -124,8 +124,7 @@ def compute(query): # verify updating twin api endpoint works timeout_before = ( - full_low_worker.python_server.get_service("apiservice") - .stash.get_all( + full_low_worker.python_server.services.api.stash.get_all( credentials=full_low_worker.client.credentials, has_permission=True ) .ok()[0] @@ -141,8 +140,7 @@ def compute(query): assert result, result timeout_after = ( - full_low_worker.python_server.get_service("apiservice") - .stash.get_all( + full_low_worker.python_server.services.api.stash.get_all( credentials=full_low_worker.client.credentials, has_permission=True ) .ok()[0] From 7e189dd47cd122fa3ed09a7afac2bc1f9ade144e Mon Sep 17 00:00:00 2001 From: teo Date: Mon, 9 Sep 2024 13:03:17 +0300 Subject: [PATCH 08/13] fix server instead of service --- packages/syft/src/syft/service/api/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/src/syft/service/api/api.py b/packages/syft/src/syft/service/api/api.py index 298f3f30ab0..44567e8d8ef 100644 --- a/packages/syft/src/syft/service/api/api.py +++ b/packages/syft/src/syft/service/api/api.py @@ -223,7 +223,7 @@ def build_internal_context( helper_function_set = HelperFunctionSet(helper_function_dict) - user = context.service.services.user.get_current_user(context) + user = context.server.services.user.get_current_user(context) return TwinAPIAuthedContext( credentials=context.credentials, From 050cb85bf524c332979b7d8301355771a51e3ced Mon Sep 17 00:00:00 2001 From: teo Date: Mon, 9 Sep 2024 16:19:04 +0300 Subject: [PATCH 09/13] fix test --- .../syft/src/syft/service/data_subject/data_subject_service.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/syft/src/syft/service/data_subject/data_subject_service.py b/packages/syft/src/syft/service/data_subject/data_subject_service.py index 420d6b66d2d..b8d5e6b8528 100644 --- a/packages/syft/src/syft/service/data_subject/data_subject_service.py +++ b/packages/syft/src/syft/service/data_subject/data_subject_service.py @@ -79,8 +79,7 @@ def add( ds.to(DataSubject, context=context), ignore_duplicates=True, ).unwrap() - # TODO: this name seems wrong, but CI might not test it - context.server.services.data_subject.add( + context.server.services.data_subject_member.add( context, parent_ds.name, child_ds.name ) From bd24b7923754b2a72551ee84dfc24bca02a828f3 Mon Sep 17 00:00:00 2001 From: teo Date: Mon, 9 Sep 2024 16:32:19 +0300 Subject: [PATCH 10/13] fix k8s test --- packages/syft/src/syft/service/worker/worker_image_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/src/syft/service/worker/worker_image_service.py b/packages/syft/src/syft/service/worker/worker_image_service.py index cb5facd125f..3db3de87181 100644 --- a/packages/syft/src/syft/service/worker/worker_image_service.py +++ b/packages/syft/src/syft/service/worker/worker_image_service.py @@ -104,7 +104,7 @@ def build( ).unwrap() if registry_uid: # get registry from image registry service - registry = context.server.services.image_registry.get_by_id( + registry = context.server.services.syftimage_registry.get_by_id( context, registry_uid ) From f9a4797b4c2aea07a7d06d177de35a22e7b139fa Mon Sep 17 00:00:00 2001 From: teo Date: Mon, 9 Sep 2024 16:40:28 +0300 Subject: [PATCH 11/13] fix typo --- packages/syft/src/syft/service/worker/worker_image_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/src/syft/service/worker/worker_image_service.py b/packages/syft/src/syft/service/worker/worker_image_service.py index 3db3de87181..37622a36d71 100644 --- a/packages/syft/src/syft/service/worker/worker_image_service.py +++ b/packages/syft/src/syft/service/worker/worker_image_service.py @@ -104,7 +104,7 @@ def build( ).unwrap() if registry_uid: # get registry from image registry service - registry = context.server.services.syftimage_registry.get_by_id( + registry = context.server.services.syft_image_registry.get_by_id( context, registry_uid ) From 314cf9f7b5bc867aeb41c7ad1b71cdaa489c1ce2 Mon Sep 17 00:00:00 2001 From: teo Date: Mon, 9 Sep 2024 17:18:59 +0300 Subject: [PATCH 12/13] fix autocomplete --- packages/syft/src/syft/abstract_server.py | 2 ++ packages/syft/src/syft/service/action/action_endpoint.py | 2 +- .../src/syft/service/code_history/code_history_service.py | 4 +++- packages/syft/src/syft/service/request/request_service.py | 3 +-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/syft/src/syft/abstract_server.py b/packages/syft/src/syft/abstract_server.py index 4f0fba356c5..8123fb3ad49 100644 --- a/packages/syft/src/syft/abstract_server.py +++ b/packages/syft/src/syft/abstract_server.py @@ -9,6 +9,7 @@ if TYPE_CHECKING: # relative + from .server.service_registry import ServiceRegistry from .service.service import AbstractService @@ -39,6 +40,7 @@ class AbstractServer: server_type: ServerType | None server_side_type: ServerSideType | None in_memory_workers: bool + services: ServiceRegistry def get_service(self, path_or_func: str | Callable) -> "AbstractService": raise NotImplementedError diff --git a/packages/syft/src/syft/service/action/action_endpoint.py b/packages/syft/src/syft/service/action/action_endpoint.py index 966794a1ac0..2237b3963a6 100644 --- a/packages/syft/src/syft/service/action/action_endpoint.py +++ b/packages/syft/src/syft/service/action/action_endpoint.py @@ -86,7 +86,7 @@ def __call_function( self.context.server.services.api.execute_server_side_endpoint_by_id ) - return __endpoint_mode( + return __endpoint_mode( # type: ignore[misc] *args, context=self.context, endpoint_uid=self.endpoint_id, diff --git a/packages/syft/src/syft/service/code_history/code_history_service.py b/packages/syft/src/syft/service/code_history/code_history_service.py index 75a54e79b5e..a3d06bdb4fa 100644 --- a/packages/syft/src/syft/service/code_history/code_history_service.py +++ b/packages/syft/src/syft/service/code_history/code_history_service.py @@ -44,7 +44,9 @@ def submit_version( comment: str | None = None, ) -> SyftSuccess: if isinstance(code, SubmitUserCode): - code = context.server.services.user_code._submit(context=context, code=code) + code = context.server.services.user_code._submit( + context=context, submit_code=code + ) try: code_history = self.stash.get_by_service_func_name_and_verify_key( diff --git a/packages/syft/src/syft/service/request/request_service.py b/packages/syft/src/syft/service/request/request_service.py index 835ee398958..6343007f6ca 100644 --- a/packages/syft/src/syft/service/request/request_service.py +++ b/packages/syft/src/syft/service/request/request_service.py @@ -21,7 +21,6 @@ from ..service import SERVICE_TO_TYPES from ..service import TYPE_TO_SERVICE from ..service import service_method -from ..user.user import UserView from ..user.user_roles import ADMIN_ROLE_LEVEL from ..user.user_roles import DATA_SCIENTIST_ROLE_LEVEL from ..user.user_roles import GUEST_ROLE_LEVEL @@ -157,7 +156,7 @@ def get_all_info( for req in result: user = context.server.services.user.get_by_verify_key( req.requesting_user_verify_key - ).to(UserView) + ).unwrap() message = context.server.services.notification.filter_by_obj( context=context, obj_uid=req.id ).unwrap() From 48e434fee4abb0301efbcfc1bf1d99815374e902 Mon Sep 17 00:00:00 2001 From: teo Date: Mon, 9 Sep 2024 17:21:14 +0300 Subject: [PATCH 13/13] fix typing --- packages/syft/src/syft/abstract_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/syft/src/syft/abstract_server.py b/packages/syft/src/syft/abstract_server.py index 8123fb3ad49..c222cf4ea5a 100644 --- a/packages/syft/src/syft/abstract_server.py +++ b/packages/syft/src/syft/abstract_server.py @@ -40,7 +40,7 @@ class AbstractServer: server_type: ServerType | None server_side_type: ServerSideType | None in_memory_workers: bool - services: ServiceRegistry + services: "ServiceRegistry" def get_service(self, path_or_func: str | Callable) -> "AbstractService": raise NotImplementedError