Skip to content

Commit b8ed999

Browse files
committed
Merge branch 'tickets/DM-55404'
2 parents 22894c2 + 0f1991d commit b8ed999

32 files changed

Lines changed: 1735 additions & 137 deletions

python/lsst/qserv/admin/replication_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
chunk_info_file = "chunk_info.json"
4545

46-
repl_api_version = 56
46+
repl_api_version = 57
4747

4848
_log = logging.getLogger(__name__)
4949

src/cconfig/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ add_library(cconfig SHARED)
22

33
target_sources(cconfig PRIVATE
44
CzarConfig.cc
5+
DataManagementEvent.cc
6+
EventService.cc
57
)
68

79
target_include_directories(cconfig PRIVATE
@@ -11,8 +13,27 @@ target_include_directories(cconfig PRIVATE
1113
target_link_libraries(cconfig PUBLIC
1214
log
1315
XrdSsiLib
16+
boost_system
17+
util
1418
)
1519

1620
install(
1721
TARGETS cconfig
1822
)
23+
24+
FUNCTION(cconfig_tests)
25+
FOREACH(TEST IN ITEMS ${ARGV})
26+
add_executable(${TEST} ${TEST}.cc)
27+
target_link_libraries(${TEST} PUBLIC
28+
cconfig
29+
Boost::unit_test_framework
30+
Threads::Threads
31+
mysql
32+
)
33+
add_test(NAME ${TEST} COMMAND ${TEST})
34+
ENDFOREACH()
35+
ENDFUNCTION()
36+
37+
cconfig_tests(
38+
testEventService
39+
)

src/cconfig/CzarConfig.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ CzarConfig::CzarConfig(util::ConfigStore const& configStore, std::string const&
111111
throw util::ConfigException(ERR_LOC, " CzarConfig::" + std::string(__func__) +
112112
": 'replication.num_http_threads' can't be 0.");
113113
}
114+
if (_replicationNumEventThreads->getVal() == 0) {
115+
throw util::ConfigException(ERR_LOC, " CzarConfig::" + std::string(__func__) +
116+
": 'replication.num_event_threads' can't be 0.");
117+
}
114118

115119
// Cache the cached version of the configuration in the JSON format. The JSON object
116120
// contains two collections of parameters: the "input" ones that were passed into

src/cconfig/CzarConfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ class CzarConfig {
206206
}
207207
uint16_t replicationHttpPort() const { return _replicationHttpPort->getVal(); }
208208
size_t replicationNumHttpThreads() const { return _replicationNumHttpThreads->getVal(); }
209+
size_t replicationNumEventThreads() const { return _replicationNumEventThreads->getVal(); }
209210
std::string const& httpUser() const { return _httpUser->getVal(); }
210211
void setHttpUser(std::string const& user);
211212
std::string const& httpPassword() const { return _httpPassword->getVal(); }
@@ -386,6 +387,8 @@ class CzarConfig {
386387
util::ConfigValTInt::create(_configValMap, "replication", "http_port", notReq, 0);
387388
CVTUIntPtr _replicationNumHttpThreads =
388389
util::ConfigValTUInt::create(_configValMap, "replication", "num_http_threads", notReq, 2);
390+
CVTUIntPtr _replicationNumEventThreads =
391+
util::ConfigValTUInt::create(_configValMap, "replication", "num_event_threads", notReq, 2);
389392

390393
// User and password for the HTTP frontend
391394
CVTStrPtr _httpUser = util::ConfigValTStr::create(_configValMap, "http", "user", notReq, "");

src/cconfig/DataManagementEvent.cc

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* LSST Data Management System
3+
*
4+
* This product includes software developed by the
5+
* LSST Project (http://www.lsst.org/).
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the LSST License Statement and
18+
* the GNU General Public License along with this program. If not,
19+
* see <http://www.lsstcorp.org/LegalNotices/>.
20+
*/
21+
22+
#include "cconfig/DataManagementEvent.h"
23+
24+
// System headers
25+
#include <stdexcept>
26+
27+
using namespace std;
28+
using json = nlohmann::json;
29+
30+
namespace {
31+
32+
string parseDatabase(json const& jsonObj, string const& context) {
33+
if (!jsonObj.contains("database")) {
34+
throw invalid_argument(context + ": Missing required field 'database'");
35+
}
36+
return jsonObj.at("database").get<string>();
37+
}
38+
39+
string parseTable(json const& jsonObj, string const& context) {
40+
if (!jsonObj.contains("table")) {
41+
throw invalid_argument(context + ": Missing required field 'table'");
42+
}
43+
return jsonObj.at("table").get<string>();
44+
}
45+
46+
} // namespace
47+
48+
namespace lsst::qserv::cconfig {
49+
50+
string DataManagementEvent::type2str(Type type) {
51+
switch (type) {
52+
case Type::NONE:
53+
return "NONE";
54+
case Type::CHUNK_MAP_REBUILT:
55+
return "CHUNK_MAP_REBUILT";
56+
case Type::DATABASE_PUBLISHED:
57+
return "DATABASE_PUBLISHED";
58+
case Type::DATABASE_DELETED:
59+
return "DATABASE_DELETED";
60+
case Type::TABLE_DELETED:
61+
return "TABLE_DELETED";
62+
}
63+
throw invalid_argument("Unknown DataManagementEvent::Type: " + std::to_string(static_cast<int>(type)));
64+
}
65+
66+
DataManagementEvent::Type DataManagementEvent::str2type(string const& str) {
67+
string const context = "DataManagementEvent::" + string(__func__);
68+
if (str == "NONE") return Type::NONE;
69+
if (str == "CHUNK_MAP_REBUILT") return Type::CHUNK_MAP_REBUILT;
70+
if (str == "DATABASE_PUBLISHED") return Type::DATABASE_PUBLISHED;
71+
if (str == "DATABASE_DELETED") return Type::DATABASE_DELETED;
72+
if (str == "TABLE_DELETED") return Type::TABLE_DELETED;
73+
throw invalid_argument(context + ": unknown DataManagementEvent::Type: '" + str + "'");
74+
}
75+
76+
DataManagementEvent DataManagementEvent::fromJson(json const& jsonObj) {
77+
string const context = "DataManagementEvent::" + string(__func__);
78+
DataManagementEvent event;
79+
if (!jsonObj.is_object()) throw invalid_argument(context + ": JSON object expected");
80+
if (!jsonObj.contains("timestamp"))
81+
throw invalid_argument(context + ": Missing required field 'timestamp'");
82+
event.timestamp =
83+
chrono::system_clock::time_point(chrono::milliseconds(jsonObj.at("timestamp").get<long long>()));
84+
if (!jsonObj.contains("type")) throw invalid_argument(context + ": Missing required field 'type'");
85+
event.type = DataManagementEvent::str2type(jsonObj.at("type").get<string>());
86+
switch (event.type) {
87+
case Type::NONE:
88+
break;
89+
case Type::CHUNK_MAP_REBUILT:
90+
break;
91+
case Type::DATABASE_PUBLISHED:
92+
event.database = ::parseDatabase(jsonObj, context);
93+
break;
94+
case Type::DATABASE_DELETED:
95+
event.database = ::parseDatabase(jsonObj, context);
96+
break;
97+
case Type::TABLE_DELETED:
98+
event.database = ::parseDatabase(jsonObj, context);
99+
event.table = ::parseTable(jsonObj, context);
100+
break;
101+
default:
102+
throw invalid_argument(context + ": Unknown DataManagementEvent::Type");
103+
}
104+
return event;
105+
}
106+
107+
json DataManagementEvent::toJson() const {
108+
return {{"timestamp", chrono::duration_cast<chrono::milliseconds>(timestamp.time_since_epoch()).count()},
109+
{"type", DataManagementEvent::type2str(type)},
110+
{"database", database},
111+
{"table", table}};
112+
}
113+
114+
} // namespace lsst::qserv::cconfig

src/cconfig/DataManagementEvent.h

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* LSST Data Management System
3+
*
4+
* This product includes software developed by the
5+
* LSST Project (http://www.lsst.org/).
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the LSST License Statement and
18+
* the GNU General Public License along with this program. If not,
19+
* see <http://www.lsstcorp.org/LegalNotices/>.
20+
*/
21+
#ifndef LSST_QSERV_CCONFIG_DATAMANAGEMENTEVENT_H
22+
#define LSST_QSERV_CCONFIG_DATAMANAGEMENTEVENT_H
23+
24+
// System headers
25+
#include <chrono>
26+
#include <string>
27+
28+
// Third party headers
29+
#include "nlohmann/json.hpp"
30+
31+
// This header declarations
32+
namespace lsst::qserv::cconfig {
33+
34+
/**
35+
* Class DataManagementEvent is an abstraction for the events posted by the Replication system.
36+
* It contains information about the event type and any associated data.
37+
*/
38+
class DataManagementEvent {
39+
public:
40+
enum class Type : int {
41+
NONE = 0,
42+
CHUNK_MAP_REBUILT,
43+
DATABASE_PUBLISHED,
44+
DATABASE_DELETED,
45+
TABLE_DELETED
46+
};
47+
48+
static std::string type2str(Type type);
49+
static Type str2type(std::string const& str);
50+
51+
/**
52+
* Construct a DataManagementEvent object from a JSON representation.
53+
*
54+
* @param jsonObj The JSON object containing the event data.
55+
* @return A DataManagementEvent object.
56+
* @throws std::invalid_argument if the JSON object is missing required fields or contains invalid data.
57+
*/
58+
static DataManagementEvent fromJson(nlohmann::json const& jsonObj);
59+
60+
nlohmann::json toJson() const;
61+
62+
// Timestamp of the event.
63+
std::chrono::system_clock::time_point timestamp = std::chrono::system_clock::now();
64+
65+
// Mandatory attribute
66+
Type type = Type::NONE;
67+
68+
// Optional attributes which depend on the event type.
69+
std::string database;
70+
std::string table;
71+
};
72+
73+
} // namespace lsst::qserv::cconfig
74+
75+
#endif // LSST_QSERV_CCONFIG_DATAMANAGEMENTEVENT_H

0 commit comments

Comments
 (0)