File indexing completed on 2025-01-18 10:02:33
0001 #pragma once
0002
0003 #include <iostream>
0004 #include <limits>
0005 #include <nlohmann/json.hpp>
0006
0007 #include <nopayloadclient/resthandler.hpp>
0008 #include <nopayloadclient/payload.hpp>
0009 #include <nopayloadclient/iov.hpp>
0010
0011 #include <nopayloadclient/plhandler.hpp>
0012 #include <nopayloadclient/config.hpp>
0013 #include <nopayloadclient/exception.hpp>
0014 #include <syslog.h>
0015 #include <nopayloadclient/logger.hpp>
0016
0017 #define NOPAYLOADCLIENT_TRY(...) { \
0018 try { \
0019 __VA_ARGS__ \
0020 } \
0021 catch (BaseException &e) { \
0022 return e.jsonify(); \
0023 } \
0024 } \
0025
0026 namespace nopayloadclient {
0027
0028 using nlohmann::json;
0029 using std::string;
0030 using ll = long long;
0031
0032 class NoPayloadClient {
0033 public:
0034 NoPayloadClient();
0035 NoPayloadClient(const string& gt_name);
0036
0037 virtual json add(int a, int b) {
0038 std::cout << "NoPayloadClient::add(a=" << a << ", b=" << b << ")" << std::endl;
0039 return json {a+b};
0040 }
0041
0042
0043 virtual json setGlobalTag(const string& name);
0044 virtual json getGlobalTag();
0045 virtual json override(const string& pl_type, const string& file_url);
0046
0047
0048 virtual json getUrlDict(ll major_iov, ll minor_iov);
0049
0050 virtual json getPayloadIOVs(ll major_iov, ll minor_iov);
0051
0052
0053 virtual json createPayloadType(const string& pl_type);
0054 virtual json deletePayloadType(const string& pl_type);
0055 virtual json createGlobalTag(const string& name);
0056 virtual json createGlobalTag();
0057 virtual json deleteGlobalTag(const string& name);
0058 virtual json deleteGlobalTag();
0059 virtual json lockGlobalTag(const string& name);
0060 virtual json lockGlobalTag();
0061 virtual json unlockGlobalTag(const string& name);
0062 virtual json unlockGlobalTag();
0063 virtual json cloneGlobalTag(const string& source, const string& target);
0064 virtual json cloneGlobalTag(const string& target);
0065 virtual json insertPayload(const string& pl_type, const string& file_url,
0066 ll major_iov_start, ll minor_iov_start);
0067 virtual json insertPayload(const string& pl_type, const string& file_url,
0068 ll major_iov_start, ll minor_iov_start,
0069 ll major_iov_end, ll minor_iov_end);
0070 virtual json deletePayloadIOV(const string& pl_type, ll major_iov_start, ll minor_iov_start);
0071 virtual json deletePayloadIOV(const string& pl_type, ll major_iov_start, ll minor_iov_start,
0072 ll major_iov_end, ll minor_iov_end);
0073
0074
0075 virtual json getSize();
0076 virtual json getPayloadTypes();
0077 virtual json getGlobalTags();
0078 virtual json checkConnection();
0079 virtual json getConfDict();
0080 virtual json clearCache();
0081 friend std::ostream& operator<<(std::ostream& os, const NoPayloadClient& c);
0082 template<typename T>
0083 json makeResp(T msg);
0084 static bool objWithNameExists(const json& j, const string& name);
0085
0086 private:
0087 json config_;
0088 json override_dict_;
0089 string global_tag_;
0090 RESTHandler rest_handler_;
0091 PLHandler pl_handler_;
0092
0093
0094 void prepareInsertIov(Payload &pl);
0095 void insertIov(Payload& pl, IOV& iov);
0096 void insertPayload(Payload &pl, IOV &iov);
0097 void createNewPll(const string& pl_type);
0098
0099
0100 bool gtExists(const string& name);
0101 bool gtStatusExists(const string& name);
0102 bool plTypeExists(const string& pl_type);
0103 bool gtHasPlType(const string& pl_type);
0104 void checkGtExists(const string& name);
0105 void checkGtDoesNotExist(const string& name);
0106 void checkGtStatusExists(const string& name);
0107 void checkPlTypeExists(const string& name);
0108 void applyOverriding(json& payload_iovs);
0109
0110 json getUrlDict(const json& payload_iovs);
0111 };
0112
0113
0114 bool objWithNameExists(const json& j, const string& name);
0115
0116
0117 }