Skip to content

Commit

Permalink
SDSTOR-13146 : Update AM's /api/v1/utilization endpoint (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
shosseinimotlagh authored Mar 26, 2024
1 parent 44519c8 commit c6630a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 11 additions & 6 deletions src/homeblks/homeblks_http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>():"";
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);
Expand All @@ -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<double> (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,
Expand Down

0 comments on commit c6630a2

Please sign in to comment.