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_FILE_CONFIGURATION_H_ 18 #define MINDSPORE_CCSRC_PS_CORE_FILE_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 #include "ps/core/comm_util.h" 33 #include "nlohmann/json.hpp" 34 #include "ps/core/configuration.h" 35 36 namespace mindspore { 37 namespace ps { 38 namespace core { 39 // File storage persistent information. 40 // for example 41 //{ 42 // "scheduler_ip": "127.0.0.1", 43 // "scheduler_port": 1, 44 // "worker_num": 8, 45 // "server_num": 16, 46 // "total_node_num": 16 47 //} 48 class FileConfiguration : public Configuration { 49 public: FileConfiguration(const std::string & path)50 explicit FileConfiguration(const std::string &path) : file_path_(path), is_initialized_(false) {} 51 ~FileConfiguration() = default; 52 53 bool Initialize() override; 54 55 bool IsInitialized() const override; 56 57 std::string Get(const std::string &key, const std::string &defaultvalue) const override; 58 59 std::string GetString(const std::string &key, const std::string &defaultvalue) const override; 60 61 int64_t GetInt(const std::string &key, int64_t default_value) const override; 62 63 void Put(const std::string &key, const std::string &value) override; 64 65 bool Exists(const std::string &key) const override; 66 67 private: 68 // The path of the configuration file. 69 std::string file_path_; 70 71 nlohmann::json js; 72 73 std::atomic<bool> is_initialized_; 74 }; 75 } // namespace core 76 } // namespace ps 77 } // namespace mindspore 78 #endif // MINDSPORE_CCSRC_PS_CORE_FILE_CONFIGURATION_H_ 79