Skip to content

Commit 93bce74

Browse files
fix: make cortex models stop works again (#1364)
Co-authored-by: vansangpfiev <[email protected]>
1 parent e3f2f46 commit 93bce74

File tree

3 files changed

+39
-36
lines changed

3 files changed

+39
-36
lines changed

engine/commands/model_stop_cmd.cc

+35-18
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
11
#include "model_stop_cmd.h"
2+
#include "config/yaml_config.h"
3+
#include "database/models.h"
24
#include "httplib.h"
35
#include "nlohmann/json.hpp"
6+
#include "utils/file_manager_utils.h"
47
#include "utils/logging_utils.h"
58

69
namespace commands {
7-
ModelStopCmd::ModelStopCmd(std::string host, int port,
8-
const config::ModelConfig& mc)
9-
: host_(std::move(host)), port_(port), mc_(mc) {}
1010

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;
1627

17-
auto data_str = json_data.dump();
28+
auto data_str = json_data.dump();
1829

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));
2542
}
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());
2946
}
3047
}
3148

engine/commands/model_stop_cmd.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ namespace commands {
77

88
class ModelStopCmd {
99
public:
10-
ModelStopCmd(std::string host, int port, const config::ModelConfig& mc);
11-
void Exec();
12-
13-
private:
14-
std::string host_;
15-
int port_;
16-
const config::ModelConfig& mc_;
10+
void Exec(const std::string& host, int port, const std::string& model_handle);
1711
};
1812
} // namespace commands

engine/controllers/command_line_parser.cc

+3-11
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,9 @@ void CommandLineParser::SetupModelCommands() {
220220
CLI_LOG(stop_model_cmd->help());
221221
return;
222222
};
223-
commands::CmdInfo ci(cml_data_.model_id);
224-
std::string model_file =
225-
ci.branch == "main" ? ci.model_name : ci.model_name + "-" + ci.branch;
226-
config::YamlHandler yaml_handler;
227-
yaml_handler.ModelConfigFromFile(
228-
file_manager_utils::GetModelsContainerPath().string() + "/" +
229-
model_file + ".yaml");
230-
commands::ModelStopCmd smc(cml_data_.config.apiServerHost,
231-
std::stoi(cml_data_.config.apiServerPort),
232-
yaml_handler.GetModelConfig());
233-
smc.Exec();
223+
commands::ModelStopCmd().Exec(cml_data_.config.apiServerHost,
224+
std::stoi(cml_data_.config.apiServerPort),
225+
cml_data_.model_id);
234226
});
235227

236228
auto list_models_cmd =

0 commit comments

Comments
 (0)