Skip to content

Commit 0647afd

Browse files
przepeckdtrawins
andauthored
add_to_config and remove_from_config user interface improvements (#3602)
* changed in logging config path assuming configPath field containing path to the file * changed a way to parse config path * changed error message to show examples of commands * clang format change * changed --help and error infos regarding add_to_config and remove_from_config * changed of config management commands examples, removed [OPTION...] suffix * fixed OvmsConfigDeathTest tests * fixed ConfigCreationTest tests, added to updating config check if configPath is empty * corrected info about config options in --help --------- Co-authored-by: Trawinski, Dariusz <dariusz.trawinski@intel.com>
1 parent 5c3752d commit 0647afd

File tree

7 files changed

+87
-68
lines changed

7 files changed

+87
-68
lines changed

src/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ ovms_cc_library(
305305
"libovms_server_settings",
306306
"libovms_version",
307307
"libovmsfilesystem",
308+
"libovmslocalfilesystem",
308309
"//src/graph_export:graph_cli_parser",
309310
"//src/graph_export:rerank_graph_cli_parser",
310311
"//src/graph_export:embeddings_graph_cli_parser",

src/cli_parser.cpp

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,30 @@
2828
#include "graph_export/image_generation_graph_cli_parser.hpp"
2929
#include "ovms_exit_codes.hpp"
3030
#include "filesystem.hpp"
31+
#include "localfilesystem.hpp"
3132
#include "stringutils.hpp"
3233
#include "version.hpp"
3334

3435
namespace ovms {
3536

3637
constexpr const char* CONFIG_MANAGEMENT_HELP_GROUP{"config management"};
3738

39+
std::string getConfigPath(const std::string& configPath) {
40+
bool isDir = false;
41+
auto status = LocalFileSystem::isDir(configPath, &isDir);
42+
if (!status.ok()) {
43+
throw std::logic_error("Invalid path for the config: " + configPath);
44+
}
45+
if (isDir) {
46+
return FileSystem::joinPath({configPath, "config.json"});
47+
}
48+
return configPath;
49+
}
50+
3851
void CLIParser::parse(int argc, char** argv) {
3952
try {
4053
options = std::make_unique<cxxopts::Options>(argv[0], "OpenVINO Model Server");
54+
auto configOptions = std::make_unique<cxxopts::Options>("ovms --model_name <MODEL_NAME> --add_to_config <CONFIG_PATH> --model_repository_path <MODEL_REPO_PATH> \n ovms --model_path <MODEL_PATH> --model_name <MODEL_NAME> --add_to_config <CONFIG_PATH> \n ovms --remove_from_config <CONFIG_PATH> --model_name <MODEL_NAME>", "config management commands:");
4155
// Adding this option to parse unrecognised options in another parser
4256
options->allow_unrecognised_options();
4357

@@ -254,6 +268,33 @@ void CLIParser::parse(int argc, char** argv) {
254268
"Determines how many sequences can be processed concurrently by one model instance. When that value is reached, attempt to start a new sequence will result in error.",
255269
cxxopts::value<uint32_t>(),
256270
"MAX_SEQUENCE_NUMBER");
271+
configOptions->custom_help("");
272+
configOptions->add_options(CONFIG_MANAGEMENT_HELP_GROUP)
273+
("list_models",
274+
"Directive to show available servables in models repository",
275+
cxxopts::value<bool>()->default_value("false"),
276+
"LIST_MODELS")
277+
("add_to_config",
278+
"Either path to directory containing config.json file for OVMS, or path to ovms configuration file, to add specific model to. This parameter should be executed with --model_name and either with --model_path or --model_repository_path.",
279+
cxxopts::value<std::string>(),
280+
"ADD_TO_CONFIG")
281+
("remove_from_config",
282+
"Either path to directory containing config.json file for OVMS, or path to ovms configuration file, to remove specific model from. This parameter should be executed with --model_name to specify which model we want to remove.",
283+
cxxopts::value<std::string>(),
284+
"REMOVE_FROM_CONFIG")
285+
("model_repository_path",
286+
"Absolute or relative path from the config directory to the model repository",
287+
cxxopts::value<std::string>(),
288+
"MODEL_REPOSITORY_PATH")
289+
("model_path",
290+
"Absolute or relative path from the config directory to the model. By default is a combination of the model_repository_path and model_name.",
291+
cxxopts::value<std::string>(),
292+
"MODEL_PATH")
293+
("model_name",
294+
"Name of the model",
295+
cxxopts::value<std::string>(),
296+
"MODEL_NAME");
297+
257298
result = std::make_unique<cxxopts::ParseResult>(options->parse(argc, argv));
258299

259300
// HF pull mode or pull and start mode
@@ -358,7 +399,8 @@ void CLIParser::parse(int argc, char** argv) {
358399
}
359400

360401
if (result->count("help") || result->arguments().size() == 0) {
361-
std::cout << options->help({"", "multi model", "single model", "pull hf model", CONFIG_MANAGEMENT_HELP_GROUP}) << std::endl;
402+
std::cout << options->help({"", "multi model", "single model", "pull hf model"}) << std::endl;
403+
std::cout << configOptions->help({CONFIG_MANAGEMENT_HELP_GROUP}) << std::endl;
362404
GraphCLIParser parser1;
363405
RerankGraphCLIParser parser2;
364406
EmbeddingsGraphCLIParser parser3;
@@ -461,7 +503,7 @@ void CLIParser::prepareModel(ModelsSettingsImpl& modelsSettings, HFSettingsImpl&
461503
}
462504
if (result->count("model_path")) {
463505
modelsSettings.modelPath = result->operator[]("model_path").as<std::string>();
464-
modelsSettings.userSetSingleModelArguments.push_back("model_name");
506+
modelsSettings.userSetSingleModelArguments.push_back("model_path");
465507
}
466508
if (result->count("max_sequence_number")) {
467509
modelsSettings.maxSequenceNumber = result->operator[]("max_sequence_number").as<uint32_t>();
@@ -637,9 +679,9 @@ void CLIParser::prepareConfigExport(ModelsSettingsImpl& modelsSettings) {
637679
modelsSettings.modelPath = FileSystem::joinPath({result->operator[]("model_repository_path").as<std::string>(), modelsSettings.modelName});
638680
}
639681
if (result->count("add_to_config")) {
640-
modelsSettings.configPath = result->operator[]("add_to_config").as<std::string>();
682+
modelsSettings.configPath = ovms::getConfigPath(result->operator[]("add_to_config").as<std::string>());
641683
} else if (result->count("remove_from_config")) {
642-
modelsSettings.configPath = result->operator[]("remove_from_config").as<std::string>();
684+
modelsSettings.configPath = ovms::getConfigPath(result->operator[]("remove_from_config").as<std::string>());
643685
}
644686
}
645687

src/config.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,22 @@ bool Config::validate() {
230230
}
231231
} else {
232232
if (configPath().empty()) {
233-
std::cerr << "Set config_path with add_to_config, remove_from_config" << std::endl;
233+
std::cerr << "Set config_path with add_to_config/remove_from_config" << std::endl;
234234
return false;
235235
}
236236
if (modelName().empty()) {
237-
std::cerr << "Set model_name with add_to_config, remove_from_config" << std::endl;
237+
std::cerr << "Set model_name with add_to_config/remove_from_config" << std::endl
238+
<< "Usage: " << std::endl
239+
<< " ovms --model_name <model_name> --model_repository_path <repo_path> --add_to_config <config_path>" << std::endl
240+
<< " ovms --model_name <model_name> --model_path <model_path> --add_to_config <config_path>" << std::endl
241+
<< " ovms --model_name <model_name> --remove_from_config <config_path>" << std::endl;
238242
return false;
239243
}
240244
if (modelPath().empty() && this->serverSettings.exportConfigType == ENABLE_MODEL) {
241-
std::cerr << "Set model_path or model_repository_path and model_name with add_to_config, remove_from_config" << std::endl;
245+
std::cerr << "Set model_name either with model_path or model_repository_path with add_to_config" << std::endl
246+
<< "Usage: " << std::endl
247+
<< " ovms --model_name <model_name> --model_repository_path <repo_path> --add_to_config <config_path>" << std::endl
248+
<< " ovms --model_name <model_name> --model_path <model_path> --add_to_config <config_path>" << std::endl;
242249
return false;
243250
}
244251

src/config_export_module/config_export.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -190,28 +190,11 @@ Status DisableModel(const std::string& configFilePath, const ModelsSettingsImpl&
190190
}
191191
}
192192

193-
static Status validateAndPrepareConfigFilePath(std::string& configDirOrFilePath) {
194-
if (configDirOrFilePath.empty()) {
195-
SPDLOG_ERROR("Config path empty: {}", configDirOrFilePath);
196-
return StatusCode::PATH_INVALID;
197-
}
198-
// check if the config path is a directory and if it is, append config.json
199-
bool isDir = false;
200-
auto status = LocalFileSystem::isDir(configDirOrFilePath, &isDir);
201-
if (!status.ok()) {
202-
return status;
203-
}
204-
if (isDir) {
205-
configDirOrFilePath = FileSystem::joinPath({configDirOrFilePath, "config.json"});
206-
}
207-
return StatusCode::OK;
208-
}
209-
210193
Status updateConfig(const ModelsSettingsImpl& modelSettings, const ConfigExportType& exportType) {
211194
std::string configFilePath = modelSettings.configPath;
212-
auto status = validateAndPrepareConfigFilePath(configFilePath);
213-
if (!status.ok()) {
214-
return status;
195+
if (configFilePath.empty()) {
196+
SPDLOG_ERROR("Config path is empty.");
197+
return StatusCode::PATH_INVALID;
215198
}
216199
if (exportType == ENABLE_MODEL) {
217200
return EnableModel(configFilePath, modelSettings);

src/servables_config_manager_module/servablesconfigmanagermodule.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@ Status ServablesConfigManagerModule::start(const ovms::Config& config) {
4747
} else {
4848
auto status = updateConfig(config.getModelSettings(), config.getServerSettings().exportConfigType);
4949
if (status.ok()) {
50-
std::cout << "Config updated: " << config.getModelSettings().configPath << std::string(1, std::filesystem::path::preferred_separator) << "config.json" << std::endl;
50+
std::cout << "Config updated: " << config.getModelSettings().configPath << std::endl;
5151
} else {
52-
std::cout << config.getModelSettings().configPath << std::string(1, std::filesystem::path::preferred_separator) << "config.json"
53-
<< " error on config update : " << status.string() << std::endl;
52+
std::cout << config.getModelSettings().configPath << " error on config update : " << status.string() << std::endl;
5453
}
5554
return status;
5655
}

0 commit comments

Comments
 (0)