Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Cortex CLI should be a layer on top of the API Server #1489

Merged
merged 19 commits into from
Oct 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: engine uninstall
vansangpfiev committed Oct 15, 2024
commit ca7b23551aa8dcb250747f3f68f09fc1cff065b7
29 changes: 23 additions & 6 deletions engine/commands/engine_uninstall_cmd.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
#include "engine_uninstall_cmd.h"
#include "services/engine_service.h"
#include "httplib.h"
#include "server_start_cmd.h"
#include "utils/logging_utils.h"

namespace commands {

void EngineUninstallCmd::Exec(const std::string& engine) {
auto result = engine_service_.UninstallEngine(engine);
void EngineUninstallCmd::Exec(const std::string& host, int port,
const std::string& engine) {
// Start server if server is not started yet
if (!commands::IsServerAlive(host, port)) {
CLI_LOG("Starting server ...");
commands::ServerStartCmd ssc;
if (!ssc.Exec(host, port)) {
return;
}
}

if (result.has_error()) {
CLI_LOG(result.error());
// Call API to delete engine
httplib::Client cli(host + ":" + std::to_string(port));
auto res = cli.Delete("/v1/engines/" + engine);
if (res) {
if (res->status == httplib::StatusCode::OK_200) {
CLI_LOG("Engine " + engine + " uninstalled successfully");
} else {
CTL_ERR("Engine failed to uninstall with status code: " << res->status);
}
} else {
CLI_LOG("Engine " + engine + " uninstalled successfully!");
auto err = res.error();
CTL_ERR("HTTP error: " << httplib::to_string(err));
}
}
}; // namespace commands
9 changes: 1 addition & 8 deletions engine/commands/engine_uninstall_cmd.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
#pragma once

#include <memory>
#include <string>
#include "services/engine_service.h"

namespace commands {
class EngineUninstallCmd {
public:
explicit EngineUninstallCmd()
: engine_service_{EngineService(std::make_shared<DownloadService>())} {};
void Exec(const std::string& host, int port, const std::string& engine);

void Exec(const std::string& engine);

private:
EngineService engine_service_;
};
} // namespace commands
6 changes: 0 additions & 6 deletions engine/commands/model_del_cmd.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
#pragma once

#include <string>
#include "services/model_service.h"

namespace commands {

class ModelDelCmd {
public:
explicit ModelDelCmd()
: model_service_{ModelService(std::make_shared<DownloadService>())} {};

void Exec(const std::string& host, int port, const std::string& model_handle);

private:
ModelService model_service_;
};
} // namespace commands
4 changes: 3 additions & 1 deletion engine/controllers/command_line_parser.cc
Original file line number Diff line number Diff line change
@@ -498,7 +498,9 @@ void CommandLineParser::EngineUninstall(CLI::App* parent,
if (std::exchange(executed_, true))
return;
try {
commands::EngineUninstallCmd().Exec(engine_name);
commands::EngineUninstallCmd().Exec(
cml_data_.config.apiServerHost,
std::stoi(cml_data_.config.apiServerPort), engine_name);
} catch (const std::exception& e) {
CTL_ERR(e.what());
}