1 /** 2 * Copyright 2020-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 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_CACHE_ADMIN_ARG_H_ 17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_CACHE_ADMIN_ARG_H_ 18 19 #include <iostream> 20 #include <map> 21 #include <memory> 22 #include <string> 23 #include <sstream> 24 #include <thread> 25 #include <vector> 26 #include "minddata/dataset/util/status.h" 27 #include "minddata/dataset/engine/cache/cache_client.h" 28 29 namespace mindspore { 30 namespace dataset { 31 32 class CacheAdminArgHandler { 33 public: 34 static constexpr int32_t kAlarmDeadline = 60; 35 static constexpr int32_t kMaxNumWorkers = 100; 36 static const char kServerBinary[]; 37 38 // These are the actual command types to execute 39 enum class CommandId : int16_t { 40 kCmdHelp = 0, 41 kCmdStart = 1, 42 kCmdStop = 2, 43 kCmdGenerateSession = 3, 44 kCmdDestroySession = 4, 45 kCmdListSessions = 5, 46 kCmdServerInfo = 6, 47 kCmdUnknown = 32767 48 }; 49 50 CacheAdminArgHandler(); 51 52 virtual ~CacheAdminArgHandler(); 53 54 Status ParseArgStream(std::stringstream *arg_stream); 55 56 Status RunCommand(); 57 58 void Help(); 59 60 private: 61 // These are the supported argument string integer mappings 62 enum class ArgValue : int16_t { 63 kArgUnknown = 0, // Must be at position 0. invalid map lookups in arg_map_ default to value 0 64 kArgStart = 1, 65 kArgStop = 2, 66 kArgHost = 3, 67 kArgPort = 4, 68 kArgHelp = 5, 69 kArgGenerateSession = 6, 70 kArgDestroySession = 7, 71 kArgSpillDir = 8, 72 kArgNumWorkers = 9, 73 kArgSharedMemorySize = 10, 74 kArgLogLevel = 11, 75 kArgMemoryCapRatio = 12, 76 kArgListSessions = 13, 77 kArgServerInfo = 14, 78 kArgNumArgs = 15 // Must be the last position to provide a count 79 }; 80 81 Status StartServer(); 82 83 Status StopServer(); 84 85 Status ShowServerInfo(); 86 87 Status AssignArg(const std::string &option, int32_t *out_arg, std::stringstream *arg_stream, 88 CommandId command_id = CommandId::kCmdUnknown); 89 90 Status AssignArg(const std::string &option, std::string *out_arg, std::stringstream *arg_stream, 91 CommandId command_id = CommandId::kCmdUnknown); 92 93 Status AssignArg(const std::string &option, float *out_arg, std::stringstream *arg_stream, 94 CommandId command_id = CommandId::kCmdUnknown); 95 96 Status AssignArg(const std::string &option, std::vector<uint32_t> *out_arg, std::stringstream *arg_stream, 97 CommandId command_id = CommandId::kCmdUnknown); 98 99 Status Validate(); 100 101 CommandId command_id_; 102 std::vector<session_id_type> session_ids_; 103 int32_t num_workers_; 104 int32_t shm_mem_sz_; 105 int32_t log_level_; 106 float memory_cap_ratio_; 107 std::string hostname_; 108 int32_t port_; 109 std::string spill_dir_; 110 std::string trailing_args_; 111 std::map<std::string, ArgValue> arg_map_; 112 std::map<ArgValue, bool> used_args_; 113 }; 114 } // namespace dataset 115 } // namespace mindspore 116 117 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_CACHE_ADMIN_ARG_H_ 118