Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 22dacf6

Browse files
committed
update
1 parent 3f1ea0b commit 22dacf6

File tree

4 files changed

+58
-41
lines changed

4 files changed

+58
-41
lines changed

engine/commands/engine_init_cmd.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bool EngineInitCmd::Exec() const {
2929
if (system_info.arch == system_info_utils::kUnsupported ||
3030
system_info.os == system_info_utils::kUnsupported) {
3131
CTL_ERR("Unsupported OS or architecture: " << system_info.os << ", "
32-
<< system_info.arch);
32+
<< system_info.arch);
3333
return false;
3434
}
3535
CTL_INF("OS: " << system_info.os << ", Arch: " << system_info.arch);
@@ -192,9 +192,10 @@ bool EngineInitCmd::Exec() const {
192192
// cuda driver version should be greater than toolkit version to ensure compatibility
193193
if (semantic_version_utils::CompareSemanticVersion(
194194
cuda_driver_version, suitable_toolkit_version) < 0) {
195-
CTL_ERR("Your Cuda driver version " << cuda_driver_version
196-
<< " is not compatible with cuda toolkit version "
197-
<< suitable_toolkit_version);
195+
CTL_ERR("Your Cuda driver version "
196+
<< cuda_driver_version
197+
<< " is not compatible with cuda toolkit version "
198+
<< suitable_toolkit_version);
198199
return false;
199200
}
200201

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "engine_uninstall_cmd.h"
2-
#include <filesystem>
3-
#include "utils/file_manager_utils.h"
2+
#include "services/engine_service.h"
43
#include "utils/logging_utils.h"
54

65
namespace commands {
@@ -10,24 +9,13 @@ EngineUninstallCmd::EngineUninstallCmd(std::string engine)
109

1110
void EngineUninstallCmd::Exec() const {
1211
CTL_INF("Uninstall engine " + engine_);
12+
auto engine_service = EngineService();
1313

14-
// TODO: Unload the model which is currently running on engine_
15-
16-
// TODO: Unload engine if is loaded
17-
18-
auto ecp = file_manager_utils::GetEnginesContainerPath();
19-
auto engine_path = ecp / engine_;
20-
if (!std::filesystem::exists(engine_path)) {
21-
CLI_LOG("Engine " << engine_ << " is not installed!");
22-
return;
23-
}
24-
25-
// remove
2614
try {
27-
std::filesystem::remove_all(engine_path);
28-
CTL_INF("Engine " << engine_ << " uninstalled successfully!");
15+
engine_service.UninstallEngine(engine_);
16+
CLI_LOG("Engine " << engine_ << " uninstalled successfully!")
2917
} catch (const std::exception& e) {
30-
CTL_ERR("Failed to uninstall engine " << engine_ + ": " << e.what());
18+
CLI_LOG("Failed to uninstall engine " << engine_ << ": " << e.what());
3119
}
3220
}
3321
}; // namespace commands

engine/controllers/engines.cc

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -180,24 +180,28 @@ void Engines::UninstallEngine(
180180
std::function<void(const HttpResponsePtr&)>&& callback,
181181
const std::string& engine) const {
182182
LOG_INFO << "[Http] Uninstall engine " << engine;
183-
// TODO: think of a way to prevent code duplication. This should be shared with cmd as well
184-
185-
// TODO: Unload the model which is currently running on engine_
186-
187-
// TODO: Unload engine if is loaded
188-
189-
// auto ecp = file_manager_utils::GetEnginesContainerPath();
190-
// auto engine_path = ecp / engine;
191-
// if (!std::filesystem::exists(engine_path)) {
192-
// ("Engine " << engine_ << " is not installed!");
193-
// return;
194-
// }
195-
//
196-
// // remove
197-
// try {
198-
// std::filesystem::remove_all(engine_path);
199-
// CTL_INF("Engine " << engine_ << " uninstalled successfully!");
200-
// } catch (const std::exception& e) {
201-
// CTL_ERR("Failed to uninstall engine " << engine_ + ": " << e.what());
202-
// }
183+
auto engine_service = EngineService();
184+
185+
Json::Value ret;
186+
try {
187+
// TODO: Unload the model which is currently running on engine_
188+
// TODO: Unload engine if is loaded
189+
engine_service.UninstallEngine(engine);
190+
191+
ret["message"] = "Engine " + engine + " uninstalled successfully!";
192+
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
193+
resp->setStatusCode(k200OK);
194+
callback(resp);
195+
} catch (const std::runtime_error& e) {
196+
CLI_LOG("Runtime exception");
197+
ret["message"] = "Engine " + engine + " is not installed!";
198+
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
199+
resp->setStatusCode(k400BadRequest);
200+
callback(resp);
201+
} catch (const std::exception& e) {
202+
ret["message"] = "Engine " + engine + " failed to uninstall: " + e.what();
203+
auto resp = cortex_utils::CreateCortexHttpJsonResponse(ret);
204+
resp->setStatusCode(k400BadRequest);
205+
callback(resp);
206+
}
203207
}

engine/services/engine_service.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "engine_service.h"
2+
#include <stdexcept>
23
#include "algorithm"
34
#include "utils/file_manager_utils.h"
45

@@ -61,3 +62,26 @@ std::vector<EngineInfo> EngineService::GetEngineInfoList() const {
6162

6263
return engines;
6364
}
65+
66+
void EngineService::UninstallEngine(const std::string& engine) {
67+
CTL_INF("Uninstall engine " + engine);
68+
69+
// TODO: Unload the model which is currently running on engine_
70+
71+
// TODO: Unload engine if is loaded
72+
73+
auto ecp = file_manager_utils::GetEnginesContainerPath();
74+
auto engine_path = ecp / engine;
75+
76+
if (!std::filesystem::exists(engine_path)) {
77+
throw std::runtime_error("Engine " + engine + " is not installed!");
78+
}
79+
80+
try {
81+
std::filesystem::remove_all(engine_path);
82+
CTL_INF("Engine " << engine << " uninstalled successfully!");
83+
} catch (const std::exception& e) {
84+
CTL_ERR("Failed to uninstall engine " << engine << ": " << e.what());
85+
throw;
86+
}
87+
}

0 commit comments

Comments
 (0)