Skip to content

refactor: Core server to support proto3#1844

Merged
JoshuaSBrown merged 8 commits into1837-DAPS-refactor-common-library-to-use-proto3from
1843-DAPS-refactor-core-server-to-use-proto3
Feb 7, 2026
Merged

refactor: Core server to support proto3#1844
JoshuaSBrown merged 8 commits into1837-DAPS-refactor-common-library-to-use-proto3from
1843-DAPS-refactor-core-server-to-use-proto3

Conversation

@JoshuaSBrown
Copy link
Collaborator

@JoshuaSBrown JoshuaSBrown commented Feb 5, 2026

Ticket

Description

How Has This Been Tested?

Artifacts (if appropriate):

Tasks

  • - A description of the PR has been provided, and a diagram included if it is a new feature.
  • - Formatter has been run
  • - CHANGELOG comment has been added
  • - Labels have been assigned to the pr
  • - A reviwer has been added
  • - A user has been assigned to work on the pr
  • - If new feature a unit test has been added

Summary by Sourcery

Update core server to use unified SDMS proto3 envelope and enums across database, client worker, task worker, and Globus integration, including error code refactoring and version constant updates.

Enhancements:

  • Switch all DatabaseAPI, ClientWorker, TaskWorker, and related components from legacy Auth/Anon protobuf messages to SDMS:: messages via the new envelope-based proto3 definitions.
  • Refactor message handler registration in ClientWorker to use envelope field-based message type resolution instead of protocol IDs for anonymous vs authorized channels.
  • Align error handling with new enum-based error codes (e.g., BAD_REQUEST, SERVICE_ERROR, INTERNAL_ERROR, AUTHN_REQUIRED, CLIENT_ERROR) and adjust search mode and token type enums usage.
  • Update version reporting to use new release and protocol version constants, and add a global protobuf shutdown fixture in DatabaseAPI unit tests to ensure clean teardown.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Feb 5, 2026

Reviewer's Guide

Refactors the core server to use the new unified proto3 Envelope/SDMS API and enum values, updates message routing to be field-name based instead of protocol-id based, aligns error codes, task enums, and version reporting with the new proto3 definitions, and adds proper protobuf shutdown in tests.

Sequence diagram for unified Envelope message handling in ClientWorker

sequenceDiagram
  actor Client
  participant ClientWorker
  participant ProtoBufMap
  participant MessageFactory
  participant DatabaseAPI
  participant RepoServer

  Client->>ClientWorker: send Envelope (Request)
  activate ClientWorker

  ClientWorker->>ProtoBufMap: getMessageType(message_field_name)
  ProtoBufMap-->>ClientWorker: msg_type

  ClientWorker->>ClientWorker: lookup m_msg_handlers[msg_type]
  alt no_handler
    ClientWorker->>MessageFactory: createResponseEnvelope(request)
    MessageFactory-->>ClientWorker: Envelope (Response)
    ClientWorker->>ClientWorker: create NackReply
    ClientWorker->>ClientWorker: set err_code BAD_REQUEST
    ClientWorker-->>Client: Envelope(NackReply)
  else handler_found
    ClientWorker->>ClientWorker: deserialize payload to Request message
    ClientWorker->>ClientWorker: invoke handler(uid, Request)

    alt dbPassThrough handler
      ClientWorker->>DatabaseAPI: func(Request, Reply, LogContext)
      activate DatabaseAPI
      DatabaseAPI->>RepoServer: dbGet/dbPost
      RepoServer-->>DatabaseAPI: JSON result
      DatabaseAPI-->>ClientWorker: filled Reply
      deactivate DatabaseAPI
    else local handler
      ClientWorker->>ClientWorker: perform local processing
    end

    ClientWorker->>MessageFactory: createResponseEnvelope(request)
    MessageFactory-->>ClientWorker: Envelope (Response)
    ClientWorker->>ClientWorker: attach Reply payload
    ClientWorker-->>Client: Envelope(Reply)
  end
  deactivate ClientWorker
Loading

Updated class diagram for ClientWorker, DatabaseAPI, and TaskWorker with proto3 Envelope

classDiagram

  class Envelope {
    +string toString()
    +void setPayload(google_protobuf_Message payload)
  }

  class ProtoBufMap {
    +uint16_t getMessageType(string message_name)
    +bool requiresAuth(string message_name)
    +string toString(uint16_t msg_type)
  }

  class MessageFactory {
    +Envelope createRequestEnvelope()
    +Envelope createResponseEnvelope(Envelope request)
  }

  class DatabaseAPI {
    +void clientAuthenticateByPassword(string password, SDMS_AuthStatusReply reply, LogContext log_context)
    +void clientAuthenticateByToken(string token, SDMS_AuthStatusReply reply, LogContext log_context)
    +void checkPerms(SDMS_CheckPermsRequest request, SDMS_CheckPermsReply reply, LogContext log_context)
    +void getPerms(SDMS_GetPermsRequest request, SDMS_GetPermsReply reply, LogContext log_context)
    +void userSetAccessToken(SDMS_UserSetAccessTokenRequest request, SDMS_AckReply reply, LogContext log_context)
    +void userCreate(SDMS_UserCreateRequest request, SDMS_UserDataReply reply, LogContext log_context)
    +void recordView(SDMS_RecordViewRequest request, SDMS_RecordDataReply reply, LogContext log_context)
    +void generalSearch(SDMS_SearchRequest request, SDMS_ListingReply reply, LogContext log_context)
    +void repoList(SDMS_RepoListRequest request, SDMS_RepoDataReply reply, LogContext log_context)
    +void schemaSearch(SDMS_SchemaSearchRequest request, SDMS_SchemaDataReply reply, LogContext log_context)
    +void dailyMessage(SDMS_DailyMessageRequest request, SDMS_DailyMessageReply reply, LogContext log_context)
    +uint32_t parseSearchRequest(SDMS_SearchRequest request, string qry_begin, string qry_end, string qry_filter, string params, LogContext log_context)
    -long dbGet(char url_path, vector~pair_string_string~ params, libjson_Value result, LogContext log_context)
    -long dbPost(char url_path, vector~pair_string_string~ params, string body, libjson_Value result, LogContext log_context)
  }

  class ClientWorker {
    -map~uint16_t,msg_fun_t~ m_msg_handlers
    -ProtoBufMap* m_msg_mapper
    -MessageFactory m_msg_factory
    -DatabaseAPI* m_db
    +void setupMsgHandlers()
    +void workerThread(LogContext log_context)
    +unique_ptr~IMessage~ procVersionRequest(string uid, VersionRequest request, LogContext log_context)
    +unique_ptr~IMessage~ procAuthenticateByPasswordRequest(string uid, AuthenticateByPasswordRequest request, LogContext log_context)
    +unique_ptr~IMessage~ procDataGetRequest(string uid, DataGetRequest request, LogContext log_context)
    +unique_ptr~IMessage~ procRecordCreateRequest(string uid, RecordCreateRequest request, LogContext log_context)
    +unique_ptr~IMessage~ procRepoAuthzRequest(string uid, RepoAuthzRequest request, LogContext log_context)
    +unique_ptr~IMessage~ procSchemaCreateRequest(string uid, SchemaCreateRequest request, LogContext log_context)
    +void recordCollectionDelete(vector~string~ ids, SDMS_TaskDataReply reply, LogContext log_context)
    +void handleTaskResponse(libjson_Value result, LogContext log_context)
    +template~Rq,Rp,func~ unique_ptr~IMessage~ dbPassThrough(string uid, Envelope msg_request, LogContext log_context)
  }

  class TaskWorker {
    -map~int,execute_fun_t~ m_execute
    -ITaskMgr& m_mgr
    +TaskWorker(ITaskMgr mgr, uint32_t worker_id, ICommunicator comm)
    +void workerThread(LogContext log_context)
    +static ICommunicator_Response cmdRawDataTransfer(TaskWorker me, libjson_Value params, LogContext log_context)
    +static ICommunicator_Response cmdRawDataDelete(TaskWorker me, libjson_Value params, LogContext log_context)
    +static ICommunicator_Response cmdRawDataUpdateSize(TaskWorker me, libjson_Value params, LogContext log_context)
    +static ICommunicator_Response cmdAllocCreate(TaskWorker me, libjson_Value params, LogContext log_context)
    +static ICommunicator_Response cmdAllocDelete(TaskWorker me, libjson_Value params, LogContext log_context)
    +ICommunicator_Response repoSendRecv(string repo_id, google_protobuf_Message request, LogContext log_context)
  }

  class SDMS_TaskCommand {
    <<enumeration>>
    +TC_RAW_DATA_TRANSFER
    +TC_RAW_DATA_DELETE
    +TC_RAW_DATA_UPDATE_SIZE
    +TC_ALLOC_CREATE
    +TC_ALLOC_DELETE
    +TC_STOP
  }

  class SDMS_ErrorCode {
    <<enumeration>>
    +BAD_REQUEST
    +INTERNAL_ERROR
    +SERVICE_ERROR
    +AUTHN_REQUIRED
    +CLIENT_ERROR
  }

  class VersionConstants {
    +int release_YEAR
    +int release_MONTH
    +int release_DAY
    +int release_HOUR
    +int release_MINUTE
    +int protocol_version_MAJOR
    +int protocol_version_MINOR
    +int protocol_version_PATCH
    +int core_version_MAJOR
    +int core_version_MINOR
    +int core_version_PATCH
  }

  Envelope --> ClientWorker : used by
  ClientWorker --> ProtoBufMap : uses
  ClientWorker --> MessageFactory : uses
  ClientWorker --> DatabaseAPI : uses
  TaskWorker --> DatabaseAPI : uses via repoSendRecv
  TaskWorker --> SDMS_TaskCommand : indexes m_execute
  ClientWorker --> SDMS_ErrorCode : sets error codes in NackReply
  VersionConstants <.. ClientWorker : reads version values
  VersionConstants <.. main : prints version info

  class main {
    +int main(int argc, char** argv)
  }
Loading

File-Level Changes

Change Details Files
Switch DatabaseAPI and related server components from legacy Auth/Anon protobuf APIs to unified proto3 SDMS/envelope definitions.
  • Replace SDMS_Anon/SDMS_Auth includes with common/envelope.pb.h and add specific enum proto includes where needed.
  • Update all DatabaseAPI method signatures to use SDMS::... request/reply types instead of Anon::... and Auth::... messages.
  • Adjust helper setters (setUserData, setProjectData, setRecordData, etc.) and parseSearchRequest to accept SDMS types and refer to fully-qualified enum values like SDMS::SM_DATA.
  • Update TaskWorker repo-side protobuf messages (RepoDataDeleteRequest, RepoDataGetSizeRequest, RepoPathCreate/DeleteRequest) to use SDMS types.
  • Update Config, TaskMgr, and GlobusAPI to include envelope.pb.h instead of the old SDMS headers.
core/server/DatabaseAPI.hpp
core/server/DatabaseAPI.cpp
core/server/TaskWorker.cpp
core/server/ClientWorker.hpp
core/server/Config.hpp
core/server/TaskMgr.cpp
core/server/TaskMgr.hpp
core/server/GlobusAPI.cpp
core/server/GlobusAPI.hpp
Align server error handling, enums, and auth behavior with new proto3 enum values and Nack semantics.
  • Replace legacy error codes like ID_INTERNAL_ERROR, ID_SERVICE_ERROR, ID_BAD_REQUEST, ID_CLIENT_ERROR, and ID_AUTHN_REQUIRED with enum values INTERNAL_ERROR, SERVICE_ERROR, BAD_REQUEST, CLIENT_ERROR, and AUTHN_REQUIRED.
  • Update access token type checks from ACCESS_SENTINEL to TOKEN_UNSPECIFIED and use SDMS enum namespaces where appropriate.
  • Ensure anonymous requests are blocked based on message metadata via ProtoBufMap::requiresAuth instead of numeric message-type thresholds.
  • Update TaskWorker command dispatch and STOP handling to use fully-qualified SDMS::TC_* enums.
  • Adjust GlobusAPI HTTP error wrappers to throw SERVICE_ERROR using new enums.
core/server/DatabaseAPI.cpp
core/server/ClientWorker.cpp
core/server/GlobusAPI.cpp
core/server/main.cpp
core/server/TaskWorker.cpp
Refactor ClientWorker message routing to use the new Envelope-based message mapping instead of protocol-id based mappings.
  • Remove explicit use of separate anonymous/auth protocol IDs and the SDMS::Anon/SDMS::Auth namespaces.
  • Redefine handler registration macros to be field-name based (SET_MSG_HANDLER(msg, ...), SET_MSG_HANDLER_DB(rq,rp,func)) and register all handlers using only message type names.
  • Update comments and logic to reflect that message types are identified by Envelope field numbers, not by protocol IDs.
  • Use ProtoBufMap::getMessageType("TaskListRequest") and requiresAuth() rather than numeric ranges to determine auth requirements and task-list message type.
  • Ensure NackReply uses new error enums when returning error responses from the worker thread.
core/server/ClientWorker.cpp
Update version reporting and tests to work with new non-proto Version.hpp and protobuf lifetime requirements.
  • Replace Version.pb.h usage in core server with a plain Version.hpp header and update version printing in main.cpp to use release:: and protocol::version:: namespaces.
  • Update ClientWorker::procVersionRequest to source release and API version values from the new Version constants instead of preprocessor macros.
  • Add a global Boost.Test fixture to call google::protobuf::ShutdownProtobufLibrary() at the end of the test run to cleanly shut down protobuf in DatabaseAPI unit tests.
core/server/main.cpp
core/server/ClientWorker.cpp
core/server/Version.hpp.in
core/server/tests/unit/test_DatabaseAPI.cpp

Possibly linked issues

  • #: The PR updates core server code to proto3/envelope usage, directly implementing the requested proto3 refactor.
  • #unknown: PR changes core server to consume new proto3 envelope/enums, directly implementing the protobuf refactor described in issue.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In DatabaseAPI.cpp you removed using namespace SDMS::Auth; but several function definitions still use unqualified proto types (e.g., UserUpdateRequest, UserListAllRequest, UserListCollabRequest, NoteCreateRequest, etc.); these should be fully qualified as SDMS::... (or an explicit using for the new namespace) to avoid compilation errors.
  • DatabaseAPI.cpp includes common/envelope.pb.h twice at the top; please drop the duplicate include to keep the includes clean.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In DatabaseAPI.cpp you removed `using namespace SDMS::Auth;` but several function definitions still use unqualified proto types (e.g., `UserUpdateRequest`, `UserListAllRequest`, `UserListCollabRequest`, `NoteCreateRequest`, etc.); these should be fully qualified as `SDMS::...` (or an explicit `using` for the new namespace) to avoid compilation errors.
- DatabaseAPI.cpp includes `common/envelope.pb.h` twice at the top; please drop the duplicate include to keep the includes clean.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

….com:ORNL/DataFed into 1843-DAPS-refactor-core-server-to-use-proto3
@JoshuaSBrown JoshuaSBrown changed the base branch from 1837-DAPS-refactor-common-library-to-use-proto3 to devel February 5, 2026 17:39
@JoshuaSBrown JoshuaSBrown changed the base branch from devel to 1837-DAPS-refactor-common-library-to-use-proto3 February 5, 2026 17:40
@JoshuaSBrown JoshuaSBrown self-assigned this Feb 5, 2026
@JoshuaSBrown JoshuaSBrown added Priority: Medium Above average priority Type: Refactor Imlplementation change, same functionality labels Feb 5, 2026
@JoshuaSBrown JoshuaSBrown linked an issue Feb 5, 2026 that may be closed by this pull request
@JoshuaSBrown JoshuaSBrown requested a review from nedvedba February 5, 2026 22:00
* [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)
@JoshuaSBrown JoshuaSBrown merged commit 96f2dd4 into 1837-DAPS-refactor-common-library-to-use-proto3 Feb 7, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: Medium Above average priority Type: Refactor Imlplementation change, same functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactor] - Refactor core server to use proto3

2 participants