def registrate_microservice(dto: RequestDto[UrlInfo]) -> BaseResponseDto: url_info: UrlInfo = dto.data if not hasattr(url_info, "ip_address") or not hasattr(url_info, "port"): raise ServerLogicException(401, "Received wrong data from client !") RegistrateManager.__registrate_microservice_impl(url_info) return BaseResponseDto(200)
def __set_config_impl(cls, web_config: ClientConfig) -> bool: if not hasattr(web_config, "check_state_period") or not hasattr(web_config, "send_data_period"): raise ServerLogicException(401, "Received wrong data from client !") if ConfigManager.__validate_config(web_config): with open(cls.__file_name, "w") as config_file: config_file.write(JsonFormatter.serialize(web_config)) return True return False
def run_clustering( dto: RequestDto[RunClusteringDto]) -> ResponseDto[ImageView]: data: RunClusteringDto = dto.data if not hasattr(data, "image_view"): raise ServerLogicException( 401, "Received wrong data from client ! Empty ComputerFlow !") image_view: ImageView = ClusteringManager.__run_clustering_impl( data.image_view) return ResponseDto[RunClusteringDto](200, image_view)
def get_request_dto(self, json_request_dto: str, method_name: str, client_address: Tuple[str, int]) -> BaseRequestDto: dto_type = self.__get_request_type(method_name) request_dto = JsonFormatter.deserialize(json_request_dto, dto_type) if not hasattr(request_dto, "data"): raise ServerLogicException( 400, f"Server work only with dto types ! Stop spam !") UrlManager.resolve_client_address(request_dto, client_address) return request_dto
def __get_request_type(self, server_method: str): handler = self.__method_handler.get(server_method, None) if handler is None: raise ServerLogicException( 400, f"Unsupported server method {server_method}!") return handler.__annotations__["dto"]
def do_get(self, server_method: str) -> BaseResponseDto: handler = self.__method_handler.get(server_method, None) if handler is None: raise ServerLogicException( 400, f"Unsupported server method {server_method}!") return handler()