1 /** 2 * Copyright 2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CCSRC_PS_CORE_CONFIGURATION_H_ 18 #define MINDSPORE_CCSRC_PS_CORE_CONFIGURATION_H_ 19 20 #include <atomic> 21 #include <cstdlib> 22 #include <iostream> 23 #include <memory> 24 #include <string> 25 #include <vector> 26 #include <thread> 27 #include <mutex> 28 #include <unordered_map> 29 30 #include "ps/constants.h" 31 #include "utils/log_adapter.h" 32 33 namespace mindspore { 34 namespace ps { 35 namespace core { 36 // This is a basic configuration class to store persistent information, which can be stored in a database or file 37 class Configuration { 38 public: 39 Configuration() = default; 40 virtual ~Configuration() = default; 41 42 // Initialize database connection or load config file. 43 virtual bool Initialize() = 0; 44 45 // Determine whether the initialization has been completed. 46 virtual bool IsInitialized() const = 0; 47 48 // Get configuration data from database or config file. 49 virtual std::string Get(const std::string &key, const std::string &defaultvalue) const = 0; 50 51 // Get configuration data from database or config file. 52 virtual std::string GetString(const std::string &key, const std::string &defaultvalue) const = 0; 53 54 // Get configuration data from database or config file. 55 virtual int64_t GetInt(const std::string &key, int64_t default_value) const = 0; 56 57 // Put configuration data to database or config file. 58 virtual void Put(const std::string &key, const std::string &defaultvalue) = 0; 59 60 // Determine whether the configuration item exists. 61 virtual bool Exists(const std::string &key) const = 0; 62 }; 63 } // namespace core 64 } // namespace ps 65 } // namespace mindspore 66 #endif // MINDSPORE_CCSRC_PS_CORE_CONFIGURATION_H_ 67