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 "include/backend/distributed/ps/constants.h" 31 #include "nlohmann/json.hpp" 32 #include "utils/log_adapter.h" 33 34 namespace mindspore { 35 namespace ps { 36 namespace core { 37 // This is a basic configuration class to store persistent information, which can be stored in a database or file 38 class Configuration { 39 public: 40 Configuration() = default; 41 virtual ~Configuration() = default; 42 43 // Initialize database connection or load config file. 44 virtual bool Initialize() = 0; 45 46 // Determine whether the initialization has been completed. 47 virtual bool IsInitialized() const = 0; 48 49 // Get configuration data from database or config file. 50 virtual std::string Get(const std::string &key, const std::string &defaultvalue) const = 0; 51 52 // Get configuration data from database or config file. 53 virtual std::string GetString(const std::string &key, const std::string &defaultvalue) const = 0; 54 55 // Get configuration vector data from database or config file. 56 virtual std::vector<nlohmann::json> GetVector(const std::string &key) const = 0; 57 58 // Get configuration data from database or config file. 59 virtual int64_t GetInt(const std::string &key, int64_t default_value) const = 0; 60 61 // Put configuration data to database or config file. 62 virtual void Put(const std::string &key, const std::string &defaultvalue) = 0; 63 64 // Determine whether the configuration item exists. 65 virtual bool Exists(const std::string &key) const = 0; 66 67 // storage meta data 68 virtual void PersistFile(const core::ClusterConfig &clusterConfig) const = 0; 69 70 // storage meta data without nodes 71 virtual void PersistNodes(const core::ClusterConfig &clusterConfig) const = 0; 72 73 virtual std::string file_path() const = 0; 74 }; 75 } // namespace core 76 } // namespace ps 77 } // namespace mindspore 78 #endif // MINDSPORE_CCSRC_PS_CORE_CONFIGURATION_H_ 79