From 384c3c04258af23a46bb1ea3db79ca65120419c2 Mon Sep 17 00:00:00 2001 From: Paul-Sanga Date: Fri, 26 Jun 2026 15:20:48 +0300 Subject: [PATCH 1/2] [Implemeted the delete experiment by ID endpoint from mlflow REST API] --- include/mlflow/client.hpp | 1 + include/mlflow/experiments.hpp | 1 + src/client.cpp | 6 ++++++ src/experiments.cpp | 25 +++++++++++++++++++++++++ tests/test_experiments.cpp | 15 +++++++++++++-- 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/include/mlflow/client.hpp b/include/mlflow/client.hpp index 2648510..6cf0066 100644 --- a/include/mlflow/client.hpp +++ b/include/mlflow/client.hpp @@ -41,6 +41,7 @@ class MlflowClient { Result get_experiment_by_id(const std::string &experiment_id); Result get_experiment_by_name(const std::string &name); + Result delete_experiment(const std::string& experiment_id); private: std::unique_ptr transport_; diff --git a/include/mlflow/experiments.hpp b/include/mlflow/experiments.hpp index 276c9f4..ad7955f 100644 --- a/include/mlflow/experiments.hpp +++ b/include/mlflow/experiments.hpp @@ -25,6 +25,7 @@ class Experiments { Result get_experiment_by_id(const std::string &experiment_id); Result get_experiment_by_name(const std::string &name); + Result delete_experiment(const std::string& experiment_id); private: HttpTransport &transport_; diff --git a/src/client.cpp b/src/client.cpp index db9a75d..b894430 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -26,6 +26,12 @@ MlflowClient::get_experiment_by_name(const std::string &name) { return experiments_sub_.get_experiment_by_name(name); } +Result +MlflowClient::delete_experiment(const std::string& experiment_id) +{ + return experiments_sub_.delete_experiment(experiment_id); +} + Result MlflowClient::create_run(const std::string &experiment_id, const TimestampMs &start_time) { return runs_sub_.create_run(experiment_id, start_time); diff --git a/src/experiments.cpp b/src/experiments.cpp index be2aba9..157c3d3 100644 --- a/src/experiments.cpp +++ b/src/experiments.cpp @@ -77,4 +77,29 @@ Experiments::get_experiment_by_name(const std::string &name) { .error_message = ""}; } +Result +Experiments::delete_experiment(const std::string& experiment_id) +{ + json payload = {{ "experiment_id", experiment_id }}; + auto res = transport_.post("/experiments/delete", payload.dump()); + + if(res.status_code != 200) + { + return + { + .data = "", + .success = false, + .error_message = "HTTP " + std::to_string(res.status_code) + }; + } + + auto res_json = json::parse(res.body); + return + { + .data = "", + .success = true, + .error_message = "" + }; +} + } // namespace mlflow \ No newline at end of file diff --git a/tests/test_experiments.cpp b/tests/test_experiments.cpp index 9a26b25..035022d 100644 --- a/tests/test_experiments.cpp +++ b/tests/test_experiments.cpp @@ -66,7 +66,6 @@ TEST_F(MlflowCppClientFixture, GetExperimentByID) { EXPECT_FALSE(exp_res.data.empty()); auto res = client.get_experiment_by_id(exp_id); - ASSERT_TRUE(res.success); EXPECT_FALSE(res.data.empty()); } @@ -81,5 +80,17 @@ TEST_F(MlflowCppClientFixture, GetExperimentByName) { auto res = client.get_experiment_by_name(name); ASSERT_TRUE(res.success); EXPECT_FALSE(res.data.empty()); - std::cout << res.value() << std::endl; } + +TEST_F(MlflowCppClientFixture, DeleteExperiment) +{ + std::string name = unique_name("delete_experiment"); + auto exp_res = client.create_experiment(name); + + ASSERT_TRUE(exp_res.success); + EXPECT_FALSE(exp_res.data.empty()); + + auto res = client.delete_experiment(exp_res.data); + ASSERT_TRUE(res.success); + ASSERT_TRUE(res.data.empty()); +} \ No newline at end of file From 41362f8c9a7b9f2dc23823c86d2b7fedf05a0e18 Mon Sep 17 00:00:00 2001 From: Paul-Sanga Date: Fri, 26 Jun 2026 16:05:31 +0300 Subject: [PATCH 2/2] [Implemented the restore experiment by ID endpoint from mlflow REST API] --- include/mlflow/client.hpp | 1 + include/mlflow/experiments.hpp | 1 + src/client.cpp | 6 ++++++ src/experiments.cpp | 25 +++++++++++++++++++++++++ tests/test_experiments.cpp | 17 +++++++++++++++++ 5 files changed, 50 insertions(+) diff --git a/include/mlflow/client.hpp b/include/mlflow/client.hpp index 6cf0066..f679aa1 100644 --- a/include/mlflow/client.hpp +++ b/include/mlflow/client.hpp @@ -42,6 +42,7 @@ class MlflowClient { Result get_experiment_by_id(const std::string &experiment_id); Result get_experiment_by_name(const std::string &name); Result delete_experiment(const std::string& experiment_id); + Result restore_experiment(const std::string& experiment_id); private: std::unique_ptr transport_; diff --git a/include/mlflow/experiments.hpp b/include/mlflow/experiments.hpp index ad7955f..722cbeb 100644 --- a/include/mlflow/experiments.hpp +++ b/include/mlflow/experiments.hpp @@ -26,6 +26,7 @@ class Experiments { Result get_experiment_by_id(const std::string &experiment_id); Result get_experiment_by_name(const std::string &name); Result delete_experiment(const std::string& experiment_id); + Result restore_experiment(const std::string& experiment_id); private: HttpTransport &transport_; diff --git a/src/client.cpp b/src/client.cpp index b894430..fec776f 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -32,6 +32,12 @@ MlflowClient::delete_experiment(const std::string& experiment_id) return experiments_sub_.delete_experiment(experiment_id); } +Result +MlflowClient::restore_experiment(const std::string& experiment_id) +{ + return experiments_sub_.restore_experiment(experiment_id); +} + Result MlflowClient::create_run(const std::string &experiment_id, const TimestampMs &start_time) { return runs_sub_.create_run(experiment_id, start_time); diff --git a/src/experiments.cpp b/src/experiments.cpp index 157c3d3..e782384 100644 --- a/src/experiments.cpp +++ b/src/experiments.cpp @@ -102,4 +102,29 @@ Experiments::delete_experiment(const std::string& experiment_id) }; } +Result +Experiments::restore_experiment(const std::string& experiment_id) +{ + json payload = {{ "experiment_id", experiment_id }}; + auto res = transport_.post("/experiments/restore", payload.dump()); + + if(res.status_code != 200) + { + return + { + .data = "", + .success = false, + .error_message = "" + }; + } + + auto res_json = json::parse(res.body); + return + { + .data = "", + .success = true, + .error_message = "" + }; +} + } // namespace mlflow \ No newline at end of file diff --git a/tests/test_experiments.cpp b/tests/test_experiments.cpp index 035022d..1dce399 100644 --- a/tests/test_experiments.cpp +++ b/tests/test_experiments.cpp @@ -93,4 +93,21 @@ TEST_F(MlflowCppClientFixture, DeleteExperiment) auto res = client.delete_experiment(exp_res.data); ASSERT_TRUE(res.success); ASSERT_TRUE(res.data.empty()); +} + +TEST_F(MlflowCppClientFixture, RestoreExperiment) +{ + std::string name = unique_name("restore_experiment"); + auto exp_res = client.create_experiment(name); + + ASSERT_TRUE(exp_res.success); + EXPECT_FALSE(exp_res.data.empty()); + + auto del_exp_res = client.delete_experiment(exp_res.data); + ASSERT_TRUE(del_exp_res.success); + ASSERT_TRUE(del_exp_res.data.empty()); + + auto res = client.restore_experiment(exp_res.data); + ASSERT_TRUE(res.success); + ASSERT_TRUE(res.data.empty()); } \ No newline at end of file