diff --git a/CrestApi/CrestApi.h b/CrestApi/CrestApi.h index 87a00134c8fce438722a7c29470bb8f8ee2134fb..284caf33fe3e17e5a93ba485fbc927e99abf4aa6 100644 --- a/CrestApi/CrestApi.h +++ b/CrestApi/CrestApi.h @@ -491,6 +491,17 @@ namespace Crest */ std::string getCrestVersion(); +/** + * This method retrieves monitoring information on payload as a list of payload tag information. + * @param tagname - tag name pattern, "%" can be used for any symbols, + * @param size - page size, + * @param page - page number, + * @param sort - sorting order (name:ASC or name:DESC), + * @return JSON payload tag info list as a PayloadTagInfoSetDto.<br> + */ + PayloadTagInfoSetDto listPayloadTagInfo(const std::string &tagname, int size, int page, const std::string &sort); + + }; } // namespace Crest diff --git a/CrestApi/CrestModel.h b/CrestApi/CrestModel.h index b8938d9644fb24e3b8fd7be22232608c825badb0..a9333a62c0d739e361838ceceb12c372d958624d 100644 --- a/CrestApi/CrestModel.h +++ b/CrestApi/CrestModel.h @@ -390,4 +390,36 @@ public: static PayloadSetDto from_json(const json &j); }; +class PayloadTagInfoDto +{ +public: + std::string tagname; + int niovs; + double totvolume; + double avgvolume; + + // Ctor + PayloadTagInfoDto(std::string _tagname, int _niovs, double _totvolume, double _avgvolume): + tagname(_tagname), niovs(_niovs), totvolume(_totvolume), avgvolume(_avgvolume){ + + } + // Default Ctor + PayloadTagInfoDto(): tagname(""), niovs(0), totvolume(0.0), avgvolume(0.0) {} + json to_json() const; + static PayloadTagInfoDto from_json(const json &j); +}; + +class PayloadTagInfoSetDto : public CrestBaseResponse +{ +public: + std::vector<PayloadTagInfoDto> resources; + const char* getFormat() const {return "PayloadTagInfoSetDto";} + int64_t getSize() const{return resources.size();} + + json to_json() const; + + static PayloadTagInfoSetDto from_json(const json &j); +}; + + #endif // CREST_DTOS_HPP diff --git a/examples/crest_example_server.cxx b/examples/crest_example_server.cxx index 7ea3c5d46d66f70508fb9657a2e9c456af9f8ec5..041e25343d72d04e1826d6b4336b27b1eb67e89e 100644 --- a/examples/crest_example_server.cxx +++ b/examples/crest_example_server.cxx @@ -539,6 +539,21 @@ void testFindExistingTagMeta(const std::string &tagname) } } +void testListPayloadTagInfo(const std::string& tagname, int size, int page, const std::string &sort) { + std::cout << std::endl << "test: listPayloadTagInfo" << std::endl; + CrestClient myCrestClient = CrestClient(SURL,false); + + try { + PayloadTagInfoSetDto dto = myCrestClient.listPayloadTagInfo(tagname,size,page,sort); + std::cout << std::endl << "test: listPayloadTagInfo (result) = " << std::endl + << dto.to_json().dump(4) << std::endl; + } + catch (const std::exception& e) { + std::cout << std::endl << "test: listPayloadTagInfo (failed)" << std::endl; + std::cout << e.what() << std::endl; + } +} + int main(int argc, char* argv[]) { diff --git a/src/CrestApi.cxx b/src/CrestApi.cxx index a2548def000baafbb64f676f797cc7be52f4c1ba..8d80309235bfe562824d643b5fe9696a341048fa 100644 --- a/src/CrestApi.cxx +++ b/src/CrestApi.cxx @@ -829,6 +829,32 @@ namespace Crest PayloadDto dto = PayloadDto::from_json(response); return dto; } + + PayloadTagInfoSetDto CrestClient::listPayloadTagInfo(const std::string &tagname, int size, int page, const std::string &sort) + { + const char *method_name = "CrestClient::listPayloadTagInfo"; + + std::string current_path = m_PATH; + current_path += s_MONITORING_PAYLOAD_PATH; + current_path += "?tagname="; + current_path += tagname; + + current_path += "&size="; + current_path += std::to_string(size); + current_path += "&page="; + current_path += std::to_string(page); + current_path += "&sort="; + current_path += sort; + + std::string retv; + nlohmann::json js = nullptr; + retv = m_request.performRequest(current_path, GET, js, method_name); + nlohmann::json response = getJson(retv, method_name); + PayloadTagInfoSetDto dto = PayloadTagInfoSetDto::from_json(response); + + return dto; + } + } // namespace Crest diff --git a/src/CrestApiFs.cxx b/src/CrestApiFs.cxx index 3ae52c74024c34713904903b01372d1be9c1e5a1..d8ab237fbe907e547cfea4e88833910f80421620 100644 --- a/src/CrestApiFs.cxx +++ b/src/CrestApiFs.cxx @@ -667,7 +667,7 @@ namespace Crest IovSetDto CrestFsClient::storeIovs(const IovSetDto &iovsetdto) { - checkFsException("CrestFsClient::selectGroups"); + checkFsException("CrestFsClient::storeIovs"); return IovSetDto(); } diff --git a/src/CrestModel.cxx b/src/CrestModel.cxx index a1905c29d130ac8bf4ab8837abb342e05a286bad..84886c374c448bead81d73f0ca0f3ab0865fa961 100644 --- a/src/CrestModel.cxx +++ b/src/CrestModel.cxx @@ -206,7 +206,8 @@ TagDto TagDto::from_json(const json &j) tag.endOfValidity = j.value<uint64_t>("endOfValidity", 0); if (j.contains(std::string{"insertionTime"})) tag.insertionTime = j.value("insertionTime", ""); - tag.modificationTime = j.value("modificationTime", ""); + if (j.contains(std::string{"modificationTime"})) + tag.modificationTime = j.value("modificationTime", ""); return tag; } json TagSetDto::to_json() const @@ -627,3 +628,58 @@ PayloadSetDto PayloadSetDto::from_json(const json &j) return payloadSetDto; } + +// PayloadTagInfoDto + +json PayloadTagInfoDto::to_json() const +{ + json js = {}; + js["tagname"] = tagname; + js["niovs"] = niovs; + js["totvolume"] = totvolume; + js["avgvolume"] = avgvolume; + return js; +} + +PayloadTagInfoDto PayloadTagInfoDto::from_json(const json &j) +{ + PayloadTagInfoDto dto; + auto it = j.find("tagname"); + if (it != j.end()) + { + dto.tagname = j["tagname"]; + } + else + { + throw Crest::CrestException("ERROR in PayloadTagInfoDto.from_json: JSON contains no tag name."); + } + dto.niovs = j.value("niovs", 0); + dto.totvolume = j.value("totvolume", 0.0); + dto.avgvolume = j.value("avgvolume", 0.0); + return dto; +} + +json PayloadTagInfoSetDto::to_json() const +{ + json baseJson = CrestBaseResponse::to_json(); + json jsonResources = json::array(); + for (const auto &resource : resources) + { + jsonResources.push_back(((PayloadTagInfoDto)resource).to_json()); + } + baseJson["resources"] = jsonResources; + return baseJson; +} + +PayloadTagInfoSetDto PayloadTagInfoSetDto::from_json(const json &j) +{ + PayloadTagInfoSetDto pSet; + pSet.load_from_json(j); + json jsonResources = j.value("resources", json::array()); + for (auto it = jsonResources.begin(); it != jsonResources.end(); ++it) + { + pSet.resources.push_back(PayloadTagInfoDto::from_json(*it)); + } + + return pSet; +}