|
1 | 1 | #include "model_stop_cmd.h"
|
| 2 | +#include "config/yaml_config.h" |
| 3 | +#include "database/models.h" |
2 | 4 | #include "httplib.h"
|
3 | 5 | #include "nlohmann/json.hpp"
|
| 6 | +#include "utils/file_manager_utils.h" |
4 | 7 | #include "utils/logging_utils.h"
|
5 | 8 |
|
6 | 9 | namespace commands {
|
7 |
| -ModelStopCmd::ModelStopCmd(std::string host, int port, |
8 |
| - const config::ModelConfig& mc) |
9 |
| - : host_(std::move(host)), port_(port), mc_(mc) {} |
10 | 10 |
|
11 |
| -void ModelStopCmd::Exec() { |
12 |
| - httplib::Client cli(host_ + ":" + std::to_string(port_)); |
13 |
| - nlohmann::json json_data; |
14 |
| - json_data["model"] = mc_.name; |
15 |
| - json_data["engine"] = mc_.engine; |
| 11 | +void ModelStopCmd::Exec(const std::string& host, int port, |
| 12 | + const std::string& model_handle) { |
| 13 | + cortex::db::Models modellist_handler; |
| 14 | + config::YamlHandler yaml_handler; |
| 15 | + try { |
| 16 | + auto model_entry = modellist_handler.GetModelInfo(model_handle); |
| 17 | + if (model_entry.has_error()) { |
| 18 | + CLI_LOG("Error: " + model_entry.error()); |
| 19 | + return; |
| 20 | + } |
| 21 | + yaml_handler.ModelConfigFromFile(model_entry.value().path_to_model_yaml); |
| 22 | + auto mc = yaml_handler.GetModelConfig(); |
| 23 | + httplib::Client cli(host + ":" + std::to_string(port)); |
| 24 | + nlohmann::json json_data; |
| 25 | + json_data["model"] = mc.name; |
| 26 | + json_data["engine"] = mc.engine; |
16 | 27 |
|
17 |
| - auto data_str = json_data.dump(); |
| 28 | + auto data_str = json_data.dump(); |
18 | 29 |
|
19 |
| - auto res = cli.Post("/inferences/server/unloadmodel", httplib::Headers(), |
20 |
| - data_str.data(), data_str.size(), "application/json"); |
21 |
| - if (res) { |
22 |
| - if (res->status == httplib::StatusCode::OK_200) { |
23 |
| - // LOG_INFO << res->body; |
24 |
| - CLI_LOG("Model unloaded!"); |
| 30 | + auto res = cli.Post("/inferences/server/unloadmodel", httplib::Headers(), |
| 31 | + data_str.data(), data_str.size(), "application/json"); |
| 32 | + if (res) { |
| 33 | + if (res->status == httplib::StatusCode::OK_200) { |
| 34 | + // LOG_INFO << res->body; |
| 35 | + CLI_LOG("Model unloaded!"); |
| 36 | + } else { |
| 37 | + CLI_LOG("Error: could not unload model - " << res->status); |
| 38 | + } |
| 39 | + } else { |
| 40 | + auto err = res.error(); |
| 41 | + CTL_ERR("HTTP error: " << httplib::to_string(err)); |
25 | 42 | }
|
26 |
| - } else { |
27 |
| - auto err = res.error(); |
28 |
| - CTL_ERR("HTTP error: " << httplib::to_string(err)); |
| 43 | + } catch (const std::exception& e) { |
| 44 | + CLI_LOG("Fail to stop model information with ID '" + model_handle + |
| 45 | + "': " + e.what()); |
29 | 46 | }
|
30 | 47 | }
|
31 | 48 |
|
|
0 commit comments