# # Copyright 2019 The FATE Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from abc import ABC, abstractmethod from contextlib import AbstractContextManager class ModelStorageBase(ABC): @abstractmethod def exists(self, model_id: str, model_version: str, store_address: dict): pass @abstractmethod def store(self, model_id: str, model_version: str, store_address: dict, force_update: bool = False): """ Store the model from local cache to a reliable system :param model_id: :param model_version: :param store_address: :return: """ pass @abstractmethod def restore(self, model_id: str, model_version: str, store_address: dict, force_update: bool = False, hash_: str = None): """ Restore model from storage system to local cache :param model_id: :param model_version: :param store_address: :return: """ pass class ComponentStorageBase(AbstractContextManager): def __exit__(self, *exc): pass @abstractmethod def exists(self, party_model_id, model_version, component_name): pass @abstractmethod def upload(self, party_model_id, model_version, component_name): pass @abstractmethod def download(self, party_model_id, model_version, component_name, hash_=None): pass @abstractmethod def copy(self, party_model_id, model_version, component_name, source_model_version): pass