|
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"];
242 int n =
str.find(
'.');
246 throw CrestException(
"ERROR in CrestClient::getMajorVersion: string \"" +
str +
"\" does not contain major version.");
249 std::string vers =
str.substr(0,
n);
257 throw CrestException(
"ERROR in CrestClient::getMajorVersion: string \"" +
str +
"\" does not contain major version.");
271 if (clientVersion != serverVersion)
273 throw CrestException(
"ERROR in CrestClient::checkCrestVersion: CrestApi version \"" +
client +
"\" does not correspond to the server version \"" +
server +
"\".");
290 const char *method_name =
"CrestClient::createGlobalTag";
292 std::string current_path =
m_PATH;
301 const char *method_name =
"CrestClient::findGlobalTag";
303 std::string current_path =
m_PATH;
306 current_path +=
name;
321 const char *method_name =
"CrestClient::listGlobalTags";
323 std::string current_path =
m_PATH;
328 current_path +=
"name=";
329 current_path +=
name;
334 current_path +=
"size=";
340 current_path +=
"page=";
346 current_path +=
"sort=";
347 current_path += sort;
364 const char *method_name =
"CrestClient::removeGlobalTag";
366 std::string current_path =
m_PATH;
370 current_path +=
name;
380 const char *method_name =
"CrestClient::createTag";
382 std::string current_path =
m_PATH;
392 const char *method_name =
"CrestClient::findTag";
394 std::string current_path =
m_PATH;
397 current_path +=
name;
411 const char *method_name =
"CrestClient::listTags";
413 std::string current_path =
m_PATH;
418 current_path +=
"name=";
419 current_path +=
name;
424 current_path +=
"size=";
430 current_path +=
"page=";
436 current_path +=
"sort=";
437 current_path += sort;
454 const char *method_name =
"CrestClient::removeTag";
456 std::string current_path =
m_PATH;
460 current_path +=
name;
470 const char *method_name =
"CrestClient::createTagMeta";
472 std::string current_path =
m_PATH;
485 const char *method_name =
"CrestClient::updateTagMeta";
487 std::string current_path =
m_PATH;
500 const char *method_name =
"CrestClient::findTagMeta";
502 std::string current_path =
m_PATH;
505 current_path +=
name;
521 const char *method_name =
"CrestClient::getSize";
523 std::string current_path =
m_PATH;
526 current_path +=
"?tagname=";
535 auto res = respond.find(
"resources");
538 if (
res != respond.end())
540 r = respond[
"resources"][0];
544 if (
r.find(
"niovs") !=
r.end())
550 throw CrestException(
"ERROR in CrestClient::getSize CREST Server JSON response has no \"size\" key.");
560 const char *method_name =
"CrestClient::createGlobalTagMap";
562 std::string current_path =
m_PATH;
571 const char *method_name =
"CrestClient::findGlobalTagMap";
573 std::string current_path =
m_PATH;
576 current_path +=
name;
577 std::string headers_params =
"";
579 if (xCrestMapMode !=
"")
581 headers_params +=
"X-Crest-MapMode: ";
582 headers_params += xCrestMapMode;
586 headers_params +=
"X-Crest-MapMode: ";
587 headers_params +=
"Trace";
600 const char *method_name =
"CrestClient::removeGlobalTagMap";
602 std::string current_path =
m_PATH;
605 current_path +=
name;
609 current_path +=
"tagname=";
615 current_path +=
"record=";
616 current_path += record;
621 current_path +=
"label=";
622 current_path +=
label;
635 const char *method_name =
"CrestClient::selectIovs";
637 std::string current_path =
m_PATH;
640 current_path +=
"?method=";
642 current_path +=
"&tagname=";
644 current_path +=
name;
645 current_path +=
"&since=";
647 current_path +=
"&until=";
650 current_path +=
"INF";
656 current_path +=
"&snapshot=";
659 current_path +=
"&size=";
661 current_path +=
"&page=";
663 current_path +=
"&sort=";
664 current_path += sort;
680 const char *method_name =
"CrestClient::selectGroups";
682 std::string current_path =
m_PATH;
685 current_path +=
"?method=";
687 current_path +=
"&tagname=";
689 current_path +=
name;
690 current_path +=
"&snapshot=";
694 current_path +=
"&size=";
696 current_path +=
"&page=";
698 current_path +=
"&sort=";
699 current_path += sort;
717 const std::string &payloadFormat,
719 const std::string &compressionType,
724 std::string current_path =
m_PATH;
726 std::vector<std::string>
files;
729 if (payloadFormat ==
"JSON")
738 auto subjectIdIter1 = js.find(
"resources");
739 if (subjectIdIter1 != js.end())
741 resources = js[
"resources"];
743 int partN = resources.size();
744 for (
int i = 0;
i < partN;
i++)
747 std::string file_param;
749 auto subjectIdIter1 = element.find(
"data");
750 if (subjectIdIter1 != element.end())
752 file_param = element[
"data"];
755 int found_dots = file_param.find_first_of(
':');
756 int word_size = file_param.size();
757 std::string data_file = file_param.substr(found_dots + 3, word_size);
758 files.push_back(data_file);
766 const char *method_name =
"CrestClient::getPayload";
768 std::string current_path =
m_PATH;
770 current_path +=
"/data?format=BLOB&hash=";
771 current_path +=
hash;
780 const char *method_name =
"CrestClient::getPayloadMeta";
782 std::string current_path =
m_PATH;
785 current_path +=
hash;
786 current_path +=
"?format=META";
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.
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
std::string getCrestVersion()
This method returns the full CREST Server version.
static const std::string s_MGMT_PATH
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.
static const std::string s_CREST_CLIENT_VERSION
void createGlobalTagMap(GlobalTagMapDto &globalTagMap) override
This method creates a global tag map on the CREST server.
std::string getClientVersion()
This method returns the full CrestApi version.
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.
int getMajorVersion(std::string &str)
This is an auxiliary method to extract a major version number from full version string.
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