Skip to content

Commit c03924a

Browse files
authored
[DAPS-1837] - refactor common library to use proto3 (#1842)
* [DAPS-1837] - refactor: core server to support proto3 (#1844) * [DAPS-1845] - refactor repo server to use proto3 (#1846) * [DAPS-1847] - refactor: python package to be compatible with proto3 envelope (#1849) * [DAPS-1848] - refactor: update authz files to use proto3. (#1851) * [DAPS-1850] - refactor web server proto3 (#1852)
1 parent c86e353 commit c03924a

File tree

128 files changed

+2157
-3860
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+2157
-3860
lines changed

.github/workflows/javascript-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Install ESLint
2020
run: |
2121
npm init -y
22-
npm install eslint@latest @babel/eslint-parser@latest eslint-define-config globals eslint-plugin-jsdoc --save
22+
npm install eslint@^9 @babel/eslint-parser@latest eslint-define-config globals eslint-plugin-jsdoc --save
2323
npx eslint "**/*.js"
2424
2525
# Step 4: Report status

CMakeLists.txt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,19 @@ endif()
117117

118118

119119
if ( BUILD_REPO_SERVER OR BUILD_CORE_SERVER OR BUILD_AUTHZ OR BUILD_COMMON OR BUILD_PYTHON_CLIENT OR BUILD_WEB_SERVER)
120-
configure_file(
121-
"${CMAKE_CURRENT_SOURCE_DIR}/common/proto/common/Version.proto.in"
122-
"${CMAKE_CURRENT_SOURCE_DIR}/common/proto/common/Version.proto"
123-
@ONLY)
124120

121+
125122
# Create file glob here because need to be made visible here as well
126-
file( GLOB ProtoFiles "${PROJECT_SOURCE_DIR}/common/proto/common/*.proto" )
123+
file(GLOB_RECURSE ProtoFiles "${PROJECT_SOURCE_DIR}/common/proto3/common/*.proto")
127124
include(./cmake/Protobuf.cmake)
128125
endif()
129126

130127

131128
if( BUILD_WEB_SERVER )
132129
include(./cmake/Web.cmake)
133-
file(COPY ${ProtoFiles} DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/web/")
130+
131+
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/common/proto3/common/"
132+
DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/web/proto3/")
134133

135134
if( ENABLE_UNIT_TESTS )
136135
add_test(NAME unit_tests_web COMMAND "${DEPENDENCY_INSTALL_PATH}/nvm/versions/node/${LOCAL_NODE_VERSION}/bin/npm" "test")
@@ -200,7 +199,7 @@ endif()
200199

201200
if( BUILD_PYTHON_CLIENT )
202201
# make target = pydatafed
203-
file(COPY ${PROJECT_SOURCE_DIR}/external/DataFedDependencies/python/datafed_pkg/requirements.txt DESTINATION ${PROJECT_SOURCE_DIR}/python/datafed_pkg/requirements.txt)
202+
file(COPY ${PROJECT_SOURCE_DIR}/external/DataFedDependencies/python/datafed_pkg/requirements.txt DESTINATION ${PROJECT_SOURCE_DIR}/python/datafed_pkg)
204203
add_subdirectory( python EXCLUDE_FROM_ALL )
205204
endif()
206205

@@ -228,9 +227,9 @@ if( INSTALL_CORE_SERVER )
228227
endif()
229228

230229
if( INSTALL_WEB_SERVER )
231-
install( FILES ${ProtoFiles} DESTINATION ${DATAFED_INSTALL_PATH}/web )
232230
install( DIRECTORY ${PROJECT_SOURCE_DIR}/web/static DESTINATION ${DATAFED_INSTALL_PATH}/web )
233231
install( DIRECTORY ${PROJECT_SOURCE_DIR}/web/views DESTINATION ${DATAFED_INSTALL_PATH}/web )
232+
install( DIRECTORY ${PROJECT_SOURCE_DIR}/web/proto3 DESTINATION ${DATAFED_INSTALL_PATH}/web )
234233
install( FILES ${PROJECT_SOURCE_DIR}/web/version.js DESTINATION ${DATAFED_INSTALL_PATH}/web )
235234
endif()
236235

common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.17.0)
22

33
# The below command will by default generate the proto files in this folder
44
# we want to place them in the binary folder in /proto/common
5-
add_subdirectory(proto/common)
5+
add_subdirectory(proto3/common)
66

77
if( BUILD_COMMON )
88
configure_file(

common/include/common/IMessage.hpp

Lines changed: 177 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,45 @@ class Message;
1717

1818
namespace SDMS {
1919

20-
enum class MessageType { GOOGLE_PROTOCOL_BUFFER, STRING };
20+
/**
21+
* @enum MessageType
22+
* @brief Discriminator for the payload type carried by an IMessage.
23+
*/
24+
enum class MessageType {
25+
GOOGLE_PROTOCOL_BUFFER, ///< Payload is a google::protobuf::Message.
26+
STRING ///< Payload is a plain std::string.
27+
};
2128

2229
/**
23-
* The message is on its way to a server this it is a REQUEST
24-
* The message is on its way from a server then it is a RESPONSE
25-
**/
30+
* @enum MessageState
31+
* @brief Indicates the directional state of a message relative to a server.
32+
*
33+
* - @c REQUEST — the message is traveling *toward* a server.
34+
* - @c RESPONSE — the message is traveling *from* a server.
35+
*/
2636
enum class MessageState { REQUEST, RESPONSE };
2737

28-
enum class MessageAttribute { ID, KEY, STATE, CORRELATION_ID };
38+
/**
39+
* @enum MessageAttribute
40+
* @brief Named keys for the core metadata attributes stored on a message.
41+
*/
42+
enum class MessageAttribute {
43+
ID, ///< Unique message identifier.
44+
KEY, ///< Routing or lookup key.
45+
STATE, ///< Current MessageState (REQUEST or RESPONSE).
46+
CORRELATION_ID ///< Identifier used to correlate requests with responses.
47+
};
2948

49+
/**
50+
* @brief Convert a MessageAttribute to its human-readable string form.
51+
*
52+
* @param[in] attribute The attribute to stringify.
53+
* @return A string representation, or @c "unsupported_toString_print" if
54+
* the attribute does not have a defined conversion.
55+
*
56+
* @note Only ID and KEY are currently supported; all other values fall
57+
* through to the unsupported case.
58+
*/
3059
inline const std::string toString(const MessageAttribute attribute) {
3160
if (attribute == MessageAttribute::ID) {
3261
return std::string("ID");
@@ -37,67 +66,186 @@ inline const std::string toString(const MessageAttribute attribute) {
3766
}
3867
}
3968

69+
/// @brief Well-known string constants used throughout the messaging layer.
4070
namespace constants {
4171
namespace message {
4272
namespace google {
43-
/// Supported dynamic arguments
73+
/// @brief Key for the serialized frame size of a protobuf message.
4474
const std::string FRAME_SIZE = "frame_size";
45-
const std::string PROTO_ID = "proto_id";
46-
const std::string MSG_ID = "msg_id";
75+
/// @brief Key for the integral message-type identifier (e.g. envelope field number).
4776
const std::string MSG_TYPE = "msg_type";
77+
/// @brief Key for the security/session context attached to a message.
4878
const std::string CONTEXT = "context";
4979
} // namespace google
5080
} // namespace message
5181
} // namespace constants
5282

83+
/**
84+
* @class IMessage
85+
* @brief Abstract interface for all messages exchanged through the SDMS
86+
* messaging infrastructure.
87+
*
88+
* IMessage defines a uniform contract for:
89+
* - **Payload management** — carrying either a protobuf Message or a raw
90+
* string, with ownership semantics enforced by the implementation.
91+
* - **Routing** — an ordered list of route identifiers that determines
92+
* how a message is forwarded through the system.
93+
* - **Metadata** — core attributes (ID, KEY, STATE, CORRELATION_ID) plus
94+
* arbitrary named attributes with small-integer values.
95+
*
96+
* Implementations are expected to own the payload and manage its lifetime.
97+
* Callers retrieve payload data via non-owning raw pointers or copies.
98+
*/
5399
class IMessage {
54100
public:
55-
101+
/// @brief Virtual destructor.
56102
virtual ~IMessage() {};
57-
virtual bool exists(MessageAttribute) const = 0;
58-
virtual bool exists(const std::string &) const = 0;
59103

60104
/**
105+
* @brief Check whether a core metadata attribute has been set.
106+
*
107+
* @param[in] attribute The attribute to query.
108+
* @return @c true if the attribute is present on this message.
109+
*/
110+
virtual bool exists(MessageAttribute attribute) const = 0;
111+
112+
/**
113+
* @brief Check whether a named (dynamic) attribute has been set.
114+
*
115+
* @param[in] attribute_name The name of the dynamic attribute to query.
116+
* @return @c true if the named attribute is present on this message.
117+
*/
118+
virtual bool exists(const std::string &attribute_name) const = 0;
119+
120+
/*---------------------------------------------------------------------
61121
* Setters
62-
**/
122+
*-------------------------------------------------------------------*/
123+
124+
/**
125+
* @brief Set the message payload.
126+
*
127+
* The implementation must take ownership of the supplied payload. For
128+
* protobuf payloads the unique_ptr is moved in; for string payloads the
129+
* string is copied or moved. After this call the IMessage instance is
130+
* solely responsible for the lifetime of the payload data.
131+
*
132+
* @param[in] payload A variant holding either a protobuf message
133+
* (via @c std::unique_ptr) or a plain string.
134+
*/
135+
virtual void setPayload(
136+
std::variant<std::unique_ptr<::google::protobuf::Message>,
137+
std::string>
138+
payload) = 0;
63139

64140
/**
65-
* Adding a payload should make a copy and store internally. It should
66-
* Imply ownership of the payload and it's memory management.
67-
**/
68-
virtual void
69-
setPayload(std::variant<std::unique_ptr<::google::protobuf::Message>,
70-
std::string>) = 0;
141+
* @brief Append a single route to the end of the routing list.
142+
*
143+
* @param[in] route The route identifier to append.
144+
*/
71145
virtual void addRoute(const std::string &route) = 0;
72146

147+
/**
148+
* @brief Replace the entire routing list.
149+
*
150+
* @param[in] routes The new ordered list of route identifiers.
151+
*/
73152
virtual void setRoutes(const std::list<std::string> &routes) = 0;
74153

75-
virtual void set(MessageAttribute, const std::string &) = 0;
76-
virtual void set(MessageAttribute, MessageState) = 0;
154+
/**
155+
* @brief Set a core metadata attribute to a string value.
156+
*
157+
* Applicable to attributes such as @c ID, @c KEY, and
158+
* @c CORRELATION_ID.
159+
*
160+
* @param[in] attribute The attribute to set.
161+
* @param[in] value The string value to assign.
162+
*/
163+
virtual void set(MessageAttribute attribute, const std::string &value) = 0;
77164

78-
virtual void set(std::string attribute_name,
79-
std::variant<uint8_t, uint16_t, uint32_t>) = 0;
80165
/**
166+
* @brief Set a core metadata attribute to a MessageState value.
167+
*
168+
* Intended for the @c STATE attribute.
169+
*
170+
* @param[in] attribute The attribute to set (expected: @c STATE).
171+
* @param[in] state The MessageState value to assign.
172+
*/
173+
virtual void set(MessageAttribute attribute, MessageState state) = 0;
174+
175+
/**
176+
* @brief Set a named dynamic attribute to a small unsigned integer.
177+
*
178+
* Dynamic attributes are identified by string keys (e.g. the constants
179+
* in @c SDMS::constants::message::google).
180+
*
181+
* @param[in] attribute_name The name of the dynamic attribute.
182+
* @param[in] value The value, stored as one of uint8/16/32.
183+
*/
184+
virtual void set(std::string attribute_name,
185+
std::variant<uint8_t, uint16_t, uint32_t> value) = 0;
186+
187+
/*---------------------------------------------------------------------
81188
* Getters
82-
**/
189+
*-------------------------------------------------------------------*/
83190

84191
/**
85-
* The correlation ID is assigned to a message when it is created and is
86-
*extremely important for tracing a message in the logs.
87-
**/
192+
* @brief Retrieve a core metadata attribute.
193+
*
194+
* The returned variant holds a @c std::string for most attributes, or a
195+
* @c MessageState when querying @c STATE.
196+
*
197+
* @param[in] attribute The attribute to retrieve.
198+
* @return A variant containing either the string value or the
199+
* MessageState, depending on the attribute.
200+
*/
88201
virtual std::variant<std::string, MessageState>
89-
get(MessageAttribute) const = 0;
202+
get(MessageAttribute attribute) const = 0;
203+
204+
/**
205+
* @brief Get a const reference to the ordered routing list.
206+
*
207+
* @return Const reference to the internal route list.
208+
*/
90209
virtual const std::list<std::string> &getRoutes() const = 0;
210+
211+
/**
212+
* @brief Get a mutable reference to the ordered routing list.
213+
*
214+
* @return Mutable reference to the internal route list.
215+
*/
91216
virtual std::list<std::string> &getRoutes() = 0;
217+
218+
/**
219+
* @brief Return the payload type carried by this message.
220+
*
221+
* @return The MessageType discriminator.
222+
*/
92223
virtual MessageType type() const noexcept = 0;
224+
225+
/**
226+
* @brief Retrieve a named dynamic attribute.
227+
*
228+
* @param[in] attribute_name The name of the dynamic attribute.
229+
* @return The value stored as a @c uint8_t, @c uint16_t, or @c uint32_t
230+
* variant.
231+
*/
93232
virtual std::variant<uint8_t, uint16_t, uint32_t>
94233
get(const std::string &attribute_name) const = 0;
95234

96-
/// Note not returning a unique_ptr but a raw pointer because the message
97-
// should stil have ownership of the object.
235+
/**
236+
* @brief Retrieve a non-owning handle to the message payload.
237+
*
238+
* Ownership remains with the IMessage instance. For protobuf payloads
239+
* a raw pointer is returned (not a @c unique_ptr) to make this
240+
* explicit. For string payloads the string is returned by value (copy).
241+
*
242+
* @return A variant holding either a non-owning
243+
* @c google::protobuf::Message* or a @c std::string.
244+
*/
98245
virtual std::variant<google::protobuf::Message *, std::string>
99246
getPayload() = 0;
100247
};
101248

102249
} // namespace SDMS
250+
103251
#endif // MESSAGE_HPP

common/include/common/IMessageMapper.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ class IMessageMapper {
2222
};
2323

2424
public:
25-
virtual uint16_t getMessageType(uint8_t a_proto_id,
26-
const std::string &a_message_name) = 0;
27-
28-
virtual uint8_t getProtocolID(MessageProtocol) const = 0;
25+
virtual uint16_t getMessageType(const std::string& message_name) const = 0;
26+
virtual bool requiresAuth(const std::string& msg_type) const = 0;
2927
};
3028
} // namespace SDMS
3129

0 commit comments

Comments
 (0)