From c6630a2a97f24168faa26c7445215c788f8e3395 Mon Sep 17 00:00:00 2001 From: Mehdi Hosseini <116847813+shosseinimotlagh@users.noreply.github.com> Date: Tue, 26 Mar 2024 10:49:02 -0700 Subject: [PATCH] SDSTOR-13146 : Update AM's /api/v1/utilization endpoint (#362) --- conanfile.py | 2 +- src/homeblks/homeblks_http_server.cpp | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/conanfile.py b/conanfile.py index 048f46f9b..384e38a22 100644 --- a/conanfile.py +++ b/conanfile.py @@ -2,7 +2,7 @@ class HomestoreConan(ConanFile): name = "homestore" - version = "3.8.1" + version = "3.8.2" homepage = "https://github.corp.ebay.com/SDS/homestore" description = "HomeStore" diff --git a/src/homeblks/homeblks_http_server.cpp b/src/homeblks/homeblks_http_server.cpp index f7bffcd92..208fc0f29 100644 --- a/src/homeblks/homeblks_http_server.cpp +++ b/src/homeblks/homeblks_http_server.cpp @@ -155,12 +155,13 @@ void HomeBlksHttpServer::set_log_level(const Pistache::Rest::Request& request, response.send(Pistache::Http::Code::Ok, resp); } -void HomeBlksHttpServer::get_utilization(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) -{ - const std::string vol_uuid = request.hasParam(":volumeUUID") ? request.param(":volumeUUID").as():""; +void HomeBlksHttpServer::get_utilization(const Pistache::Rest::Request& request, + Pistache::Http::ResponseWriter response) { + const std::string vol_uuid = + request.hasParam(":volumeUUID") ? request.param(":volumeUUID").as< std::string >() : ""; VolumePtr vol = nullptr; - if (vol_uuid.length() != 0) { + if (vol_uuid.length()) { boost::uuids::string_generator gen; boost::uuids::uuid uuid = gen(vol_uuid); vol = VolInterface::get_instance()->lookup_volume(uuid); @@ -170,10 +171,14 @@ void HomeBlksHttpServer::get_utilization(const Pistache::Rest::Request& request, } } nlohmann::json resp; - const auto total_data_size = VolInterface::get_instance()->get_system_capacity().initial_total_data_meta_size; + nlohmann::json partitions = nlohmann::json::array(); for (auto [uuid, vol_used] : VolInterface::get_instance()->get_used_size(vol)) { - resp[boost::uuids::to_string(uuid)] = std::to_string(static_cast (vol_used)/ total_data_size); + nlohmann::json partition; + partition["id"] = boost::uuids::to_string(uuid); + partition["usedCapacity"] = vol_used; + partitions.push_back(partition); } + resp["partitions"] = partitions; response.send(Pistache::Http::Code::Ok, resp.dump()); } void HomeBlksHttpServer::get_log_level(const Pistache::Rest::Request& request,