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

Commit 554ecb0

Browse files
committed
fix downloading engines with progress bar
1 parent e0f4880 commit 554ecb0

14 files changed

+127
-173
lines changed

engine/cli/commands/engine_get_cmd.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ void EngineGetCmd::Exec(const std::string& host, int port,
3535
};
3636
auto result = curl_utils::SimpleGetJson(url.ToFullPath());
3737
if (result.has_error()) {
38-
CTL_ERR(result.error());
38+
// TODO: refactor this
39+
Json::Value root;
40+
Json::Reader reader;
41+
if (!reader.parse(result.error(), root)) {
42+
CLI_LOG(result.error());
43+
return;
44+
}
45+
CLI_LOG(root["message"].asString());
3946
return;
4047
}
4148

engine/cli/commands/engine_install_cmd.cc

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ namespace commands {
99
bool EngineInstallCmd::Exec(const std::string& engine,
1010
const std::string& version,
1111
const std::string& src) {
12+
// Start server if server is not started yet
13+
if (!commands::IsServerAlive(host_, port_)) {
14+
CLI_LOG("Starting server ...");
15+
commands::ServerStartCmd ssc;
16+
if (!ssc.Exec(host_, port_)) {
17+
return false;
18+
}
19+
}
1220
// Handle local install, if fails, fallback to remote install
1321
if (!src.empty()) {
1422
auto res = engine_service_.UnzipEngine(engine, version, src);
@@ -23,20 +31,12 @@ bool EngineInstallCmd::Exec(const std::string& engine,
2331
}
2432

2533
if (show_menu_) {
26-
// Start server if server is not started yet
27-
if (!commands::IsServerAlive(host_, port_)) {
28-
CLI_LOG("Starting server ...");
29-
commands::ServerStartCmd ssc;
30-
if (!ssc.Exec(host_, port_)) {
31-
return false;
32-
}
33-
}
34-
3534
DownloadProgress dp;
3635
dp.Connect(host_, port_);
3736
// engine can be small, so need to start ws first
38-
auto dp_res = std::async(std::launch::deferred,
39-
[&dp, &engine] { return dp.Handle(engine); });
37+
auto dp_res = std::async(std::launch::deferred, [&dp, &engine] {
38+
return dp.Handle(DownloadType::Engine);
39+
});
4040
CLI_LOG("Validating download items, please wait..")
4141

4242
auto versions_url = url_parser::Url{
@@ -118,7 +118,7 @@ bool EngineInstallCmd::Exec(const std::string& engine,
118118

119119
bool check_cuda_download = !system_info_utils::GetCudaVersion().empty();
120120
if (check_cuda_download) {
121-
if (!dp.Handle("cuda"))
121+
if (!dp.Handle(DownloadType::CudaToolkit))
122122
return false;
123123
}
124124

@@ -130,10 +130,8 @@ bool EngineInstallCmd::Exec(const std::string& engine,
130130
DownloadProgress dp;
131131
dp.Connect(host_, port_);
132132
// engine can be small, so need to start ws first
133-
auto dp_res = std::async(std::launch::deferred, [&dp] {
134-
return dp.Handle(DownloadType::Engine);
135-
});
136-
CLI_LOG("Validating download items, please wait..")
133+
auto dp_res = std::async(std::launch::deferred,
134+
[&dp] { return dp.Handle(DownloadType::Engine); });
137135

138136
auto install_url = url_parser::Url{
139137
.protocol = "http",
@@ -146,12 +144,25 @@ bool EngineInstallCmd::Exec(const std::string& engine,
146144
},
147145
};
148146

147+
if (!version.empty()) {
148+
install_url.queries = {{"version", version}};
149+
}
150+
149151
auto response = curl_utils::SimplePostJson(install_url.ToFullPath());
150152
if (response.has_error()) {
151-
CTL_ERR(response.error());
153+
// TODO: namh refactor later
154+
Json::Value root;
155+
Json::Reader reader;
156+
if (!reader.parse(response.error(), root)) {
157+
CLI_LOG(response.error());
158+
return false;
159+
}
160+
CLI_LOG(root["message"].asString());
152161
return false;
153162
}
154163

164+
CLI_LOG("Validating download items, please wait..")
165+
155166
if (!dp_res.get())
156167
return false;
157168

engine/cli/commands/engine_release_cmd.cc

Lines changed: 0 additions & 86 deletions
This file was deleted.

engine/cli/commands/engine_release_cmd.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

engine/cli/commands/engine_update_cmd.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ bool EngineUpdateCmd::Exec(const std::string& host, int port,
2323
DownloadProgress dp;
2424
dp.Connect(host, port);
2525
// engine can be small, so need to start ws first
26-
auto dp_res = std::async(std::launch::deferred,
27-
[&dp, &engine] { return dp.Handle(engine); });
26+
auto dp_res = std::async(std::launch::deferred, [&dp, &engine] {
27+
return dp.Handle(DownloadType::Engine);
28+
});
2829
CLI_LOG("Validating download items, please wait..")
2930

3031
auto update_url = url_parser::Url{
@@ -43,7 +44,7 @@ bool EngineUpdateCmd::Exec(const std::string& host, int port,
4344

4445
bool check_cuda_download = !system_info_utils::GetCudaVersion().empty();
4546
if (check_cuda_download) {
46-
if (!dp.Handle("cuda"))
47+
if (!dp.Handle(DownloadType::CudaToolkit))
4748
return false;
4849
}
4950

engine/controllers/engines.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ void Engines::ListEngine(
2929
for (const auto& engine : supported_engines) {
3030
auto installed_engines =
3131
engine_service_->GetInstalledEngineVariants(engine);
32+
if (installed_engines.has_error()) {
33+
continue;
34+
}
3235
Json::Value variants(Json::arrayValue);
33-
for (const auto& variant : installed_engines) {
36+
for (const auto& variant : installed_engines.value()) {
3437
variants.append(variant.ToJson());
3538
}
3639
ret[engine] = variants;
@@ -157,8 +160,16 @@ void Engines::GetInstalledEngineVariants(
157160
std::function<void(const HttpResponsePtr&)>&& callback,
158161
const std::string& engine) const {
159162
auto result = engine_service_->GetInstalledEngineVariants(engine);
163+
if (result.has_error()) {
164+
Json::Value res;
165+
res["message"] = result.error();
166+
auto resp = cortex_utils::CreateCortexHttpJsonResponse(res);
167+
resp->setStatusCode(k400BadRequest);
168+
callback(resp);
169+
return;
170+
}
160171
Json::Value releases(Json::arrayValue);
161-
for (const auto& variant : result) {
172+
for (const auto& variant : result.value()) {
162173
releases.append(variant.ToJson());
163174
}
164175
auto resp = cortex_utils::CreateCortexHttpJsonResponse(releases);

engine/e2e-test/test_api_model_delete.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pytest
22
import requests
3-
from test_runner import popen, run
43
from test_runner import start_server, stop_server
54

65

engine/e2e-test/test_cli_engine_get.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import platform
22

33
import pytest
4-
from test_runner import run
5-
from test_runner import start_server, stop_server
4+
from test_runner import run, start_server, stop_server
5+
66

77
class TestCliEngineGet:
8-
8+
99
@pytest.fixture(autouse=True)
1010
def setup_and_teardown(self):
1111
# Setup
@@ -20,9 +20,7 @@ def setup_and_teardown(self):
2020

2121
@pytest.mark.skipif(platform.system() != "Windows", reason="Windows-specific test")
2222
def test_engines_get_tensorrt_llm_should_not_be_incompatible(self):
23-
exit_code, output, error = run(
24-
"Get engine", ["engines", "get", "tensorrt-llm"]
25-
)
23+
exit_code, output, error = run("Get engine", ["engines", "get", "tensorrt-llm"])
2624
assert exit_code == 0, f"Get engine failed with error: {error}"
2725
assert (
2826
"Incompatible" not in output
@@ -37,29 +35,27 @@ def test_engines_get_onnx_should_not_be_incompatible(self):
3735
), "onnxruntime should be Ready or Not Installed on Windows"
3836

3937
def test_engines_get_llamacpp_should_not_be_incompatible(self):
40-
exit_code, output, error = run(
41-
"Get engine", ["engines", "get", "llama-cpp"]
42-
)
38+
exit_code, output, error = run("Get engine", ["engines", "get", "llama-cpp"])
4339
assert exit_code == 0, f"Get engine failed with error: {error}"
4440
assert (
4541
"Incompatible" not in output
4642
), "llama-cpp should be compatible for Windows, MacOs and Linux"
4743

4844
@pytest.mark.skipif(platform.system() != "Darwin", reason="macOS-specific test")
4945
def test_engines_get_tensorrt_llm_should_be_incompatible_on_macos(self):
50-
exit_code, output, error = run(
51-
"Get engine", ["engines", "get", "tensorrt-llm"]
52-
)
46+
exit_code, output, error = run("Get engine", ["engines", "get", "tensorrt-llm"])
5347
assert exit_code == 0, f"Get engine failed with error: {error}"
5448
assert (
55-
"Incompatible" in output
49+
"is not supported on" in output
5650
), "tensorrt-llm should be Incompatible on MacOS"
5751

5852
@pytest.mark.skipif(platform.system() != "Darwin", reason="macOS-specific test")
5953
def test_engines_get_onnx_should_be_incompatible_on_macos(self):
6054
exit_code, output, error = run("Get engine", ["engines", "get", "onnxruntime"])
6155
assert exit_code == 0, f"Get engine failed with error: {error}"
62-
assert "Incompatible" in output, "onnxruntime should be Incompatible on MacOS"
56+
assert (
57+
"is not supported on" in output
58+
), "onnxruntime should be Incompatible on MacOS"
6359

6460
@pytest.mark.skipif(platform.system() != "Linux", reason="Linux-specific test")
6561
def test_engines_get_onnx_should_be_incompatible_on_linux(self):

0 commit comments

Comments
 (0)