|
ATLAS Offline Software
|
Go to the documentation of this file.
9 #include <boost/uuid/uuid.hpp>
10 #include <boost/uuid/uuid_generators.hpp>
11 #include <boost/uuid/uuid_io.hpp>
12 #include <boost/asio.hpp>
36 CrestClient::CrestClient(
const std::string &_host,
const std::string &_port,
bool check_version) : m_host(_host), m_port(_port)
38 if (check_version ==
true)
63 size_t found =
url.find_first_of(
':');
64 size_t n =
url.size();
66 std::string_view url_new =
url.substr(
found + 3);
69 size_t found1 = url_new.find_first_of(
':');
70 size_t found2 = url_new.find_first_of(
'/');
72 std::string_view host;
73 std::string_view port;
74 std::string_view resources;
75 if (found1 != std::string::npos && found2 != std::string::npos) {
76 host = url_new.substr(0, found1);
77 port = url_new.substr(found1 + 1, found2 - found1 - 1);
78 }
else if (found1 != std::string::npos) {
79 host = url_new.substr(0, found1);
80 port = url_new.substr(found1 + 1);
81 }
else if (found2 != std::string::npos) {
86 host = url_new.substr(0, found2);
97 resources = url_new.substr(found2,
n - 1);
101 m_port = std::string(port);
102 m_host = std::string(host);
107 if (check_version ==
true)
111 std::cout <<
"CrestClient::CrestClient: host = " <<
m_host <<
", port = " <<
m_port <<
", path = " <<
m_PATH << std::endl;
125 std::string plainString =
"";
128 for (
long unsigned int i = 0;
i < xmlBuffer.length();
i++)
130 char convertc = xmlBuffer[
i];
134 else if (convertc ==
'>')
141 plainString += convertc;
151 std::string str2 =
str;
155 while ((
pos = str2.find(needle)) != str2.npos)
176 catch (nlohmann::json::parse_error &
e)
182 std::string
wh =
e.what();
201 const char *method_name =
"getMgmtInfo";
224 buildInfo =
info[
"build"];
225 version = buildInfo[
"version"];
238 int n =
str.find(
'.');
242 throw CrestException(
"ERROR in CrestClient::getMajorVersion: string \"" +
str +
"\" does not contain major version.");
245 std::string vers =
str.substr(0,
n);
253 throw CrestException(
"ERROR in CrestClient::getMajorVersion: string \"" +
str +
"\" does not contain major version.");
267 if (clientVersion != serverVersion)
269 throw CrestException(
"ERROR in CrestClient::checkCrestVersion: CrestApi version \"" +
client +
"\" does not correspond to the server version \"" +
server +
"\".");
286 const char *method_name =
"CrestClient::createGlobalTag";
288 std::string current_path =
m_PATH;
297 const char *method_name =
"CrestClient::findGlobalTag";
299 std::string current_path =
m_PATH;
302 current_path +=
name;
317 const char *method_name =
"CrestClient::listGlobalTags";
319 std::string current_path =
m_PATH;
324 current_path +=
"name=";
325 current_path +=
name;
330 current_path +=
"size=";
336 current_path +=
"page=";
342 current_path +=
"sort=";
343 current_path += sort;
360 const char *method_name =
"CrestClient::removeGlobalTag";
362 std::string current_path =
m_PATH;
366 current_path +=
name;
376 const char *method_name =
"CrestClient::createTag";
378 std::string current_path =
m_PATH;
388 const char *method_name =
"CrestClient::findTag";
390 std::string current_path =
m_PATH;
393 current_path +=
name;
407 const char *method_name =
"CrestClient::listTags";
409 std::string current_path =
m_PATH;
414 current_path +=
"name=";
415 current_path +=
name;
420 current_path +=
"size=";
426 current_path +=
"page=";
432 current_path +=
"sort=";
433 current_path += sort;
450 const char *method_name =
"CrestClient::removeTag";
452 std::string current_path =
m_PATH;
456 current_path +=
name;
466 const char *method_name =
"CrestClient::createTagMeta";
468 std::string current_path =
m_PATH;
481 const char *method_name =
"CrestClient::updateTagMeta";
483 std::string current_path =
m_PATH;
496 const char *method_name =
"CrestClient::findTagMeta";
498 std::string current_path =
m_PATH;
501 current_path +=
name;
517 const char *method_name =
"CrestClient::getSize";
519 std::string current_path =
m_PATH;
522 current_path +=
"?tagname=";
531 auto res = respond.find(
"resources");
534 if (
res != respond.end())
536 r = respond[
"resources"][0];
540 if (
r.find(
"niovs") !=
r.end())
546 throw CrestException(
"ERROR in CrestClient::getSize CREST Server JSON response has no \"size\" key.");
556 const char *method_name =
"CrestClient::createGlobalTagMap";
558 std::string current_path =
m_PATH;
567 const char *method_name =
"CrestClient::findGlobalTagMap";
569 std::string current_path =
m_PATH;
572 current_path +=
name;
573 std::string headers_params =
"";
575 if (xCrestMapMode !=
"")
577 headers_params +=
"X-Crest-MapMode: ";
578 headers_params += xCrestMapMode;
582 headers_params +=
"X-Crest-MapMode: ";
583 headers_params +=
"Trace";
596 const char *method_name =
"CrestClient::removeGlobalTagMap";
598 std::string current_path =
m_PATH;
601 current_path +=
name;
605 current_path +=
"tagname=";
611 current_path +=
"record=";
612 current_path += record;
617 current_path +=
"label=";
618 current_path +=
label;
631 const char *method_name =
"CrestClient::selectIovs";
633 std::string current_path =
m_PATH;
636 current_path +=
"?method=";
638 current_path +=
"&tagname=";
640 current_path +=
name;
641 current_path +=
"&since=";
643 current_path +=
"&until=";
646 current_path +=
"INF";
652 current_path +=
"&snapshot=";
655 current_path +=
"&size=";
657 current_path +=
"&page=";
659 current_path +=
"&sort=";
660 current_path += sort;
676 const char *method_name =
"CrestClient::selectGroups";
678 std::string current_path =
m_PATH;
681 current_path +=
"?method=";
683 current_path +=
"&tagname=";
685 current_path +=
name;
686 current_path +=
"&snapshot=";
690 current_path +=
"&size=";
692 current_path +=
"&page=";
694 current_path +=
"&sort=";
695 current_path += sort;
713 const std::string &payloadFormat,
715 const std::string &compressionType,
720 std::string current_path =
m_PATH;
722 std::vector<std::string>
files;
725 if (payloadFormat ==
"JSON")
734 auto subjectIdIter1 = js.find(
"resources");
735 if (subjectIdIter1 != js.end())
737 resources = js[
"resources"];
739 int partN = resources.size();
740 for (
int i = 0;
i < partN;
i++)
743 std::string file_param;
745 auto subjectIdIter1 = element.find(
"data");
746 if (subjectIdIter1 != element.end())
748 file_param = element[
"data"];
751 int found_dots = file_param.find_first_of(
':');
752 int word_size = file_param.size();
753 std::string data_file = file_param.substr(found_dots + 3, word_size);
754 files.push_back(data_file);
762 const char *method_name =
"CrestClient::getPayload";
764 std::string current_path =
m_PATH;
766 current_path +=
"/data?format=BLOB&hash=";
767 current_path +=
hash;
777 const char *method_name =
"CrestClient::getPayloadMeta";
779 std::string current_path =
m_PATH;
782 current_path +=
hash;
783 current_path +=
"?format=META";
798 if (
hash != calculatedHash) {
799 throw CrestException(
"ERROR in " + (std::string)method_name +
": payload is corrupted.");
static GlobalTagMapSetDto from_json(const json &j)
static const std::string s_TAG_PATH
GlobalTagMapSetDto findGlobalTagMap(const std::string &name, const std::string &xCrestMapMode) override
This method searches for tag mappings using the global tag name or tag name on the CREST server.
std::string replace(std::string s, const std::string &s2, const std::string &s3)
nlohmann::json getJson(const std::string &str, const char *method) const
Auxiliary method to convert string in to JSON object.
void removeGlobalTag(const std::string &name) override
This method removes a global tag on the CREST server.
static const std::string s_MGMT_INFO_PATH
int getSize(const std::string &tagname) override
This method gets the number of IOVs for the given tag.
static const std::string s_ADMIN_PATH
std::string makeUrl(const std::string &address) const
std::vector< PayloadDto > resources
TagSetDto listTags(const std::string &name, int size, int page, const std::string &sort) override
This method returns the tag list as TagSetDto from the CREST server.
void removeTag(const std::string &name) override
This method removes a tag from the CREST server.
static const std::string s_IOV_PATH
static const std::string s_METHOD_IOVS
std::string performRequest(const std::string ¤t_path, Action action, nlohmann::json &js, const std::string &header_params="")
General auxiliary method to make request to the CREST Server.
static const std::string s_GLOBALTAG_MAP_PATH
std::string uploadPayload(const std::string ¤t_path, const std::string &tag, uint64_t endtime, const nlohmann::json &js, const std::string &objectType, const std::string &compressionType, const std::string &version, const std::vector< std::string > &files)
void setPrefix(const std::string &prefix)
GlobalTagDto findGlobalTag(const std::string &name) override
This method finds a global tag by name on the CREST server.
~CrestClient()
CrestClient destructor.
std::string getHash(std::string_view str)
This method method calculates the hash for string.
Header file for CREST C++ Client Library.
TagDto findTag(const std::string &name) override
This method finds a tag by the name on the CREST server.
void setHost(const std::string &host)
void createTagMeta(TagMetaDto &tag) override
This method creates a tag meta info on the CREST server.
static const std::string s_GLOBALTAG_PATH
static const std::string s_META_PATH
void updateTagMeta(TagMetaDto &tag) override
This method updates a tag meta info on the CREST server.
IovSetDto selectIovs(const std::string &name, uint64_t since, uint64_t until, long snapshot, int size, int page, const std::string &sort) override
This method selects IOVs for a given tagname on the CREST server.
static const std::string s_METHOD_GROUPS
static const std::string s_MGMT_PATH
std::string getCrestVersion() override
This method returns the full CREST Server version.
The TagDto class It contains all fields of the TagDto class from the CREST API.
void createTag(TagDto &tag) override
This method creates a tag on the CREST server.
std::pair< std::vector< unsigned int >, bool > res
static PayloadSetDto from_json(const json &j)
PayloadDto getPayloadMeta(const std::string &hash) override
This method finds a payload meta info for the hash on the CREST server.
CrestClient(const std::string &host, const std::string &port, bool checkVersion=false)
CrestClient constructor.
TagMetaDto findTagMeta(const std::string &name) override
This method reads a tag meta info by the tag name from the CREST server.
void storeData(const std::string &tag, const StoreSetDto &storeSetJson, const std::string &payloadFormat="JSON", const std::string &objectType="none", const std::string &compressionType="none", const std::string &version="1.0", uint64_t endTime=-1) override
This method stores several payloads in batch mode on the CREST server.
void createGlobalTagMap(GlobalTagMapDto &globalTagMap) override
This method creates a global tag map on the CREST server.
static const std::string s_PAYLOAD_PATH
std::string to_string(const DetectorType &type)
void checkCrestVersion()
This method is a CREST version test.
nlohmann::json getMgmtInfo()
This is an auxiliary method to read the CREST Server properties.
static IovSetDto from_json(const json &j)
std::string getPayload(const std::string &hash) override
This method finds a payload resource associated to the hash on the CREST server.
GlobalTagSetDto listGlobalTags(const std::string &name, int size, int page, const std::string &sort) override
This method finds the global tags on the CREST server.
void removeGlobalTagMap(const std::string &name, const std::string &record, const std::string &label, const std::string &tagname) override
This method removes a global tag map on the CREST server.
Crest::CrestRequest m_request
std::string parseXMLOutput(const std::string_view xmlBuffer) const
This method removes all XML/HTML tags from a string.
void createGlobalTag(GlobalTagDto &globalTag) override
This method creates a global tag on CREST server.
const std::string & getClientVersion()
This method returns the full CrestApi version.
int getMajorVersion(std::string &str)
This is an auxiliary method to extract a major version number from full version string.
void checkHash(const std::string &hash, const std::string &str, const char *method_name)
This checks the hash of payload from IOV (hash) with the hash calculated for the payload in the std::...
std::string removeCR(const std::string &str) const
This method removes all end of line and carriage return symbols from a string.
IovSetDto selectGroups(const std::string &name, long snapshot, int size, int page, const std::string &sort) override
This method returns IOV groups for a given tagname on CREST server.
void setPort(const std::string &port)
static const std::string s_IOV_SIZE_PATH