From 9bc3a2028fa85b995e69a0c9ea1630f3bf272f07 Mon Sep 17 00:00:00 2001 From: ddubuc Date: Thu, 7 Sep 2023 17:29:00 +0200 Subject: [PATCH 1/8] Fix: Need to manage download with powershell to avoid proxy issues with fetchcontent_declare --- .../cpp/ArmoniK.Api.Common/CMakeLists.txt | 27 ++++++++++++- packages/cpp/CMakeLists.txt | 9 ++++- packages/cpp/cmake/downloader.cmake | 38 +++++++++++++++++++ packages/cpp/cmake/downloader.ps1 | 13 +++++++ 4 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 packages/cpp/cmake/downloader.cmake create mode 100644 packages/cpp/cmake/downloader.ps1 diff --git a/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt index d6f0b8d04..ddbbc03c2 100644 --- a/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt +++ b/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt @@ -34,10 +34,26 @@ find_package(gRPC CONFIG REQUIRED) find_package(Threads) include(FetchContent) +include(downloader) + +SET(SRC_FMT "https://github.com/fmtlib/fmt/archive/refs/tags/10.1.0.tar.gz") +SET(SRC_SIMDJSON "https://github.com/simdjson/simdjson/archive/refs/tags/v3.2.2.tar.gz") + +#To fix proxy issue with FETCHCONTENT, we need to trust to a powershell script to downlad file with webbrowser credentials +if (WIN32) +file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/_deps/") + + download_windows_file_https("${SRC_FMT}" "${CMAKE_BINARY_DIR}/_deps/10.1.0.tar.gz" TRUE) + + SET(SRC_FMT "${CMAKE_BINARY_DIR}/_deps/10.1.0.tar.gz") + +endif() + FETCHCONTENT_DECLARE( fmt - URL https://github.com/fmtlib/fmt/archive/refs/tags/10.1.0.tar.gz + URL ${SRC_FMT} + TIMEOUT 180 ) FetchContent_GetProperties(fmt) @@ -45,9 +61,16 @@ if(NOT fmt_POPULATED) FetchContent_Populate(fmt) endif() +if (WIN32) + download_windows_file_https(${SRC_SIMDJSON} "${CMAKE_BINARY_DIR}/_deps/v3.2.2.tar.gz" TRUE) + + SET(SRC_SIMDJSON "${CMAKE_BINARY_DIR}/_deps/v3.2.2.tar.gz") +endif() + FETCHCONTENT_DECLARE( simdjson - URL https://github.com/simdjson/simdjson/archive/refs/tags/v3.2.2.tar.gz + URL "${SRC_SIMDJSON}" + TIMEOUT 180 ) FetchContent_GetProperties(simdjson) diff --git a/packages/cpp/CMakeLists.txt b/packages/cpp/CMakeLists.txt index 9c7437ec0..5aefe758e 100644 --- a/packages/cpp/CMakeLists.txt +++ b/packages/cpp/CMakeLists.txt @@ -23,6 +23,8 @@ if (WIN32) set(Protobuf_USE_STATIC_LIBS ON) endif () +LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") + option(BUILD_TEST "Build tests" OFF) option(BUILD_CLIENT "Build client" ON) option(BUILD_WORKER "Build worker" ON) @@ -36,12 +38,15 @@ set(CMAKE_CXX_STANDARD 17) function(setup_options project_name_param) -file(READ /etc/issue ${PROJECT_NAME}_ETCISSUE_CONTENT) -string(FIND "${${project_name_param}_ETCISSUE_CONTENT}" "Alpine" IS_ALPINE) + if(MSVC) target_compile_options(${project_name_param} PRIVATE /W4) else() + + file(READ /etc/issue ${PROJECT_NAME}_ETCISSUE_CONTENT) + string(FIND "${${project_name_param}_ETCISSUE_CONTENT}" "Alpine" IS_ALPINE) + if(CMAKE_BUILD_TYPE MATCHES DEBUG AND IS_ALPINE EQUAL -1) target_compile_options(${project_name_param} PRIVATE -Wall -Wextra -Wpedantic -fsanitize=undefined,address) else () diff --git a/packages/cpp/cmake/downloader.cmake b/packages/cpp/cmake/downloader.cmake new file mode 100644 index 000000000..8a01f18af --- /dev/null +++ b/packages/cpp/cmake/downloader.cmake @@ -0,0 +1,38 @@ +# Downloads a file from a URL. The URL may be https, and things will still work. +# URL - the URL to dowload the file from +# DESTFILE - the location to save the download to. The file there will be overwritten if it exists. +# FAIL_ON_ERROR - whether or not to print a FATAL_ERROR if the download fails. +function(download_windows_file_https URL DESTFILE FAIL_ON_ERROR) + + #Fixe issue with PROXY on windows to avoid env variable HTTP_PROXY with pwd + find_program(POWERSHELL NAMES powershell DOC "Path to the Windows Powershell executable. Used to download files") + set(HAVE_DOWNLOADER_PROGRAM TRUE) + + set(DOWNLOADER_PROGRAM ${POWERSHELL}) + + # from http://superuser.com/questions/25538/how-to-download-files-from-command-line-in-windows-like-wget-is-doing + + set(DOWNLOAD_COMMAND "") + if(NOT HAVE_DOWNLOADER_PROGRAM) + message(FATAL_ERROR "A downloader program, either curl, wget, or powershell, is required to download files. Please set CURL, WGET, or POWERSHELL to the location of the respective program.") + endif() + + SET(SCRIPT_DOWNLOAD "${CMAKE_SOURCE_DIR}/cmake/downloader.ps1") + + cmake_path(NATIVE_PATH SCRIPT_DOWNLOAD script_download) + cmake_path(NATIVE_PATH DESTFILE dest_win_file) + #${URL} ${dest_win_file} + SET(CONFIGURED_DOWNLOAD_COMMAND "${script_download}") + + #message("Executing command: ${DOWNLOADER_PROGRAM} ${CONFIGURED_DOWNLOAD_COMMAND}") + + execute_process(COMMAND "${DOWNLOADER_PROGRAM}" -ExecutionPolicy Bypass -File "${CONFIGURED_DOWNLOAD_COMMAND}" ${URL} ${dest_win_file} RESULT_VARIABLE DOWNLOAD_RESULT OUTPUT_VARIABLE out_var ERROR_VARIABLE err_var) + + + if((NOT ${DOWNLOAD_RESULT} EQUAL 0 OR NOT "${err_var}" STREQUAL "") AND FAIL_ON_ERROR) + message(STATUS "Unable to download file ${URL} msg ${DOWNLOAD_RESULT} : ${out_var} error : ${err_var}") + message(FATAL_ERROR "${DOWNLOADER_PROGRAM} ${CONFIGURED_DOWNLOAD_COMMAND}") + else() + message(STATUS "Info sucess to download file ${URL} msg ${DOWNLOAD_RESULT} : [${out_var}] error : [${err_var}]") + endif() +endfunction(download_windows_file_https URL DESTFILE FAIL_ON_ERROR) diff --git a/packages/cpp/cmake/downloader.ps1 b/packages/cpp/cmake/downloader.ps1 new file mode 100644 index 000000000..f64b6447b --- /dev/null +++ b/packages/cpp/cmake/downloader.ps1 @@ -0,0 +1,13 @@ +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + +$browser = New-Object System.Net.WebClient + +$browser.Proxy.Credentials =[System.Net.CredentialCache]::DefaultNetworkCredentials; + +$url=$args[0] + +$dest=$args[1] + +write-output "Download file [$url] to [$dest]" + +Invoke-WebRequest $url -OutFile $dest From 46d20b20ee913309ab779e6cb001c434492e94a0 Mon Sep 17 00:00:00 2001 From: Dylan Brasseur Date: Wed, 13 Sep 2023 16:10:53 +0200 Subject: [PATCH 2/8] Fixed missing namespace in raw headers. Moved src links to some variables --- .../cpp/ArmoniK.Api.Client/CMakeLists.txt | 15 ++-- .../header/submitter/ResultsClient.h | 4 +- .../header/submitter/SubmitterClient.h | 5 +- .../source/submitter/ResultsClient.cpp | 20 ++--- .../source/submitter/SubmitterClient.cpp | 34 ++++----- .../cpp/ArmoniK.Api.Common/CMakeLists.txt | 33 ++------- .../cpp/ArmoniK.Api.Common/Config.cmake.in | 6 +- .../header/exceptions/ArmoniKApiException.h | 4 +- .../header/exceptions/ArmoniKTaskError.h | 4 +- .../ArmoniKTaskNotCompletedException.h | 4 +- .../ArmoniK.Api.Common/header/logger/base.h | 4 +- .../header/logger/context.h | 4 +- .../header/logger/formatter.h | 4 +- .../ArmoniK.Api.Common/header/logger/fwd.h | 4 +- .../ArmoniK.Api.Common/header/logger/level.h | 4 +- .../header/logger/local_logger.h | 4 +- .../ArmoniK.Api.Common/header/logger/logger.h | 4 +- .../ArmoniK.Api.Common/header/logger/writer.h | 4 +- .../header/options/ComputePlane.h | 4 +- .../header/options/ControlPlane.h | 4 +- .../header/options/GrpcSocketType.h | 6 +- .../header/utils/Configuration.h | 8 +- .../header/utils/EnvConfiguration.h | 4 +- .../ArmoniK.Api.Common/header/utils/GuuId.h | 6 +- .../header/utils/JsonConfiguration.h | 4 +- .../source/logger/formatter.cpp | 4 +- .../source/logger/local_logger.cpp | 4 +- .../source/logger/logger.cpp | 4 +- .../source/logger/writer.cpp | 4 +- .../source/utils/Configuration.cpp | 4 +- .../source/utils/JsonConfiguration.cpp | 6 +- packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt | 3 - .../source/SubmitterClientTest.cpp | 30 ++++---- .../ArmoniK.Api.Worker.Tests/CMakeLists.txt | 5 -- .../ArmoniK.Api.Worker.Tests/source/main.cpp | 19 ++--- .../cpp/ArmoniK.Api.Worker/CMakeLists.txt | 10 +-- .../header/Worker/ArmoniKWorker.h | 18 +++-- .../header/Worker/ProcessStatus.h | 4 +- .../header/Worker/TaskHandler.h | 9 +-- .../header/utils/WorkerServer.h | 14 ++-- .../source/Worker/ArmoniKWorker.cpp | 26 ++++--- .../source/Worker/ProcessStatus.cpp | 4 +- .../source/Worker/TaskHandler.cpp | 73 ++++++++++--------- packages/cpp/CMakeLists.txt | 8 +- packages/cpp/Dependencies.cmake | 9 +++ 45 files changed, 218 insertions(+), 237 deletions(-) create mode 100644 packages/cpp/Dependencies.cmake diff --git a/packages/cpp/ArmoniK.Api.Client/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Client/CMakeLists.txt index 109efdbd7..f9960cac7 100644 --- a/packages/cpp/ArmoniK.Api.Client/CMakeLists.txt +++ b/packages/cpp/ArmoniK.Api.Client/CMakeLists.txt @@ -1,5 +1,4 @@ set(PROJECT_NAME ArmoniK.Api.Client) -set(NAMESPACE ArmoniK::Api::Client) set(ARMONIK_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/armonik/client) set(PROJECT_BUILD_DIR ${BUILD_DIR}/${PROJECT_NAME}) @@ -28,16 +27,20 @@ set(PROTO_MESSAGES list(TRANSFORM PROTO_FILES PREPEND "${PROTO_FILES_DIR}/") list(TRANSFORM PROTO_MESSAGES PREPEND "${PROTO_FILES_DIR}/") -find_package(Protobuf REQUIRED) -find_package(gRPC CONFIG REQUIRED) -find_package(Threads) - SET(SOURCES_FILES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/source") SET(HEADER_FILES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/header") FILE(GLOB_RECURSE SRC_CLIENT_FILES ${SOURCES_FILES_DIR}/*.cpp) FILE(GLOB_RECURSE HEADER_CLIENT_FILES ${HEADER_FILES_DIR}/*.h) +# Trouver les packages requis +if (UNIX) + find_package(Protobuf REQUIRED) +else() + find_package(Protobuf CONFIG REQUIRED) +endif() +find_package(gRPC CONFIG REQUIRED) +find_package(Threads) file(MAKE_DIRECTORY ${PROJECT_BUILD_DIR}) @@ -76,8 +79,6 @@ target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf gRPC::grpc++_ setup_options(${PROJECT_NAME}) -target_compile_definitions(${PROJECT_NAME} PUBLIC API_CLIENT_NAMESPACE=${NAMESPACE}) - target_include_directories(${PROJECT_NAME} PUBLIC "$" diff --git a/packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h b/packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h index 5b8df675b..c3b3bceed 100644 --- a/packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h +++ b/packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h @@ -3,7 +3,7 @@ #include -namespace API_CLIENT_NAMESPACE { +namespace armonik::api::client { class ResultsClient { public: explicit ResultsClient(std::unique_ptr stub) @@ -15,6 +15,6 @@ class ResultsClient { private: std::unique_ptr stub; }; -} // namespace API_CLIENT_NAMESPACE +} // namespace armonik::api::client #endif // ARMONIK_API_RESULTSCLIENT_H diff --git a/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h b/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h index adc98c484..2d50abf81 100644 --- a/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h +++ b/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h @@ -10,7 +10,7 @@ #include "submitter_common.pb.h" #include "submitter_service.grpc.pb.h" -namespace API_CLIENT_NAMESPACE { +namespace armonik::api::client { /** * @brief Data structure for task payload @@ -30,7 +30,6 @@ struct payload_data { */ class SubmitterClient { private: - grpc::ClientContext context_; std::unique_ptr stub_; public: @@ -105,4 +104,4 @@ class SubmitterClient { get_result_status(const std::string &session_id, const std::vector &result_ids); }; -} // namespace API_CLIENT_NAMESPACE \ No newline at end of file +} // namespace armonik::api::client \ No newline at end of file diff --git a/packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp b/packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp index 6efe6847e..9bc73e5fd 100644 --- a/packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp +++ b/packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp @@ -2,12 +2,12 @@ #include "exceptions/ArmoniKApiException.h" #include -namespace API_CLIENT_NAMESPACE { +namespace armonik::api::client { std::map ResultsClient::create_results(std::string_view session_id, const std::vector &names) { std::map mapping; - grpc::ClientContext context; + ::grpc::ClientContext context; armonik::api::grpc::v1::results::CreateResultsMetaDataRequest results_request; armonik::api::grpc::v1::results::CreateResultsMetaDataResponse results_response; @@ -32,7 +32,7 @@ std::map ResultsClient::create_results(std::string_vie << ". details : " << status.error_details() << std::endl; auto str = message.str(); std::cerr << "Could not create results for submit: " << str << std::endl; - throw ArmoniK::Api::Common::exceptions::ArmoniKApiException(str); + throw armonik::api::common::exceptions::ArmoniKApiException(str); } for (auto &&res : results_response.results()) { @@ -42,11 +42,11 @@ std::map ResultsClient::create_results(std::string_vie } void ResultsClient::upload_result_data(const std::string &session_id, const std::string &result_id, std::string_view payload) { - grpc::ClientContext context; + ::grpc::ClientContext context; armonik::api::grpc::v1::results::ResultsServiceConfigurationResponse configuration; auto status = stub->GetServiceConfiguration(&context, armonik::api::grpc::v1::Empty(), &configuration); if (!status.ok()) { - throw ArmoniK::Api::Common::exceptions::ArmoniKApiException("Unable to get result configuration : " + + throw armonik::api::common::exceptions::ArmoniKApiException("Unable to get result configuration : " + status.error_message()); } @@ -54,7 +54,7 @@ void ResultsClient::upload_result_data(const std::string &session_id, const std: armonik::api::grpc::v1::results::UploadResultDataResponse response; // response.set_allocated_result(new armonik::api::grpc::v1::results::ResultRaw()); - grpc::ClientContext streamContext; + ::grpc::ClientContext streamContext; auto stream = stub->UploadResultData(&streamContext, &response); armonik::api::grpc::v1::results::UploadResultDataRequest request; request.mutable_id()->set_session_id(session_id); @@ -67,18 +67,18 @@ void ResultsClient::upload_result_data(const std::string &session_id, const std: *request.mutable_data_chunk() = payload.substr(offset, chunkSize); if (!stream->Write(request)) { - throw ArmoniK::Api::Common::exceptions::ArmoniKApiException("Unable to continue upload result"); + throw armonik::api::common::exceptions::ArmoniKApiException("Unable to continue upload result"); } offset += chunkSize; } if (!stream->WritesDone()) { - throw ArmoniK::Api::Common::exceptions::ArmoniKApiException("Unable to upload result"); + throw armonik::api::common::exceptions::ArmoniKApiException("Unable to upload result"); } status = stream->Finish(); if (!status.ok()) { - throw ArmoniK::Api::Common::exceptions::ArmoniKApiException("Unable to finish upload result " + + throw armonik::api::common::exceptions::ArmoniKApiException("Unable to finish upload result " + status.error_message()); } } -} // namespace API_CLIENT_NAMESPACE \ No newline at end of file +} // namespace armonik::api::client \ No newline at end of file diff --git a/packages/cpp/ArmoniK.Api.Client/source/submitter/SubmitterClient.cpp b/packages/cpp/ArmoniK.Api.Client/source/submitter/SubmitterClient.cpp index e0b21230f..10541b9df 100644 --- a/packages/cpp/ArmoniK.Api.Client/source/submitter/SubmitterClient.cpp +++ b/packages/cpp/ArmoniK.Api.Client/source/submitter/SubmitterClient.cpp @@ -31,7 +31,7 @@ using namespace armonik::api::grpc::v1::submitter; * * @param stub the gRPC client stub */ -API_CLIENT_NAMESPACE::SubmitterClient::SubmitterClient(std::unique_ptr stub) { +armonik::api::client::SubmitterClient::SubmitterClient(std::unique_ptr stub) { stub_ = std::move(stub); } @@ -40,7 +40,7 @@ API_CLIENT_NAMESPACE::SubmitterClient::SubmitterClient(std::unique_ptr &partition_ids = {}) { CreateSessionRequest request; *request.mutable_default_task_option() = std::move(default_task_options); @@ -48,8 +48,8 @@ std::string API_CLIENT_NAMESPACE::SubmitterClient::create_session(TaskOptions de request.add_partition_ids(partition_id); } CreateSessionReply reply; - - Status status = stub_->CreateSession(&context_, request, &reply); + ::grpc::ClientContext context; + Status status = stub_->CreateSession(&context, request, &reply); if (!status.ok()) { std::stringstream message; message << "Error: " << status.error_code() << ": " << status.error_message() @@ -70,7 +70,7 @@ std::string API_CLIENT_NAMESPACE::SubmitterClient::create_session(TaskOptions de * @return A vector of futures containing CreateLargeTaskRequest objects. */ std::vector>> -API_CLIENT_NAMESPACE::SubmitterClient::to_request_stream(const std::vector &task_requests, +armonik::api::client::SubmitterClient::to_request_stream(const std::vector &task_requests, std::string session_id, TaskOptions task_options, const size_t chunk_max_size) { std::vector>> async_chunk_payload_tasks; @@ -104,7 +104,7 @@ API_CLIENT_NAMESPACE::SubmitterClient::to_request_stream(const std::vector> -API_CLIENT_NAMESPACE::SubmitterClient::task_chunk_stream(const TaskRequest &task_request, bool is_last, +armonik::api::client::SubmitterClient::task_chunk_stream(const TaskRequest &task_request, bool is_last, size_t chunk_max_size) { return std::async(std::launch::async, [&task_request, chunk_max_size, is_last]() { std::vector requests; @@ -180,7 +180,7 @@ API_CLIENT_NAMESPACE::SubmitterClient::task_chunk_stream(const TaskRequest &task * @return A future containing a CreateTaskReply object. */ std::future -API_CLIENT_NAMESPACE::SubmitterClient::create_tasks_async(std::string session_id, TaskOptions task_options, +armonik::api::client::SubmitterClient::create_tasks_async(std::string session_id, TaskOptions task_options, const std::vector &task_requests) { return std::async(std::launch::async, [this, task_requests, session_id = std::move(session_id), task_options = std::move(task_options)]() mutable { @@ -238,7 +238,7 @@ API_CLIENT_NAMESPACE::SubmitterClient::create_tasks_async(std::string session_id * @return A vector of task IDs. */ std::tuple, std::vector> -API_CLIENT_NAMESPACE::SubmitterClient::submit_tasks_with_dependencies( +armonik::api::client::SubmitterClient::submit_tasks_with_dependencies( std::string session_id, TaskOptions task_options, const std::vector &payloads_with_dependencies, int max_retries = 5) { std::vector task_ids; @@ -290,7 +290,7 @@ API_CLIENT_NAMESPACE::SubmitterClient::submit_tasks_with_dependencies( * @param result_request A vector of ResultRequest objects. * @return A future containing data result. */ -std::future API_CLIENT_NAMESPACE::SubmitterClient::get_result_async(const ResultRequest &result_request) { +std::future armonik::api::client::SubmitterClient::get_result_async(const ResultRequest &result_request) { return std::async(std::launch::async, [this, &result_request]() { ResultReply reply; ClientContext context_result; @@ -313,30 +313,30 @@ std::future API_CLIENT_NAMESPACE::SubmitterClient::get_result_async dataComplete = true; break; case armonik::api::grpc::v1::DataChunk::TYPE_NOT_SET: - throw ArmoniK::Api::Common::exceptions::ArmoniKApiException("Issue with server, invalid data chunk"); + throw armonik::api::common::exceptions::ArmoniKApiException("Issue with server, invalid data chunk"); } break; case ResultReply::kError: - throw ArmoniK::Api::Common::exceptions::ArmoniKTaskError("Can't get result because it's in error", + throw armonik::api::common::exceptions::ArmoniKTaskError("Can't get result because it's in error", reply.error()); case ResultReply::kNotCompletedTask: - throw ArmoniK::Api::Common::exceptions::ArmoniKTaskNotCompletedException(reply.not_completed_task()); + throw armonik::api::common::exceptions::ArmoniKTaskNotCompletedException(reply.not_completed_task()); case ResultReply::TYPE_NOT_SET: - throw ArmoniK::Api::Common::exceptions::ArmoniKApiException("Issue with server, invalid reply"); + throw armonik::api::common::exceptions::ArmoniKApiException("Issue with server, invalid reply"); } } if (!dataComplete) { - throw ArmoniK::Api::Common::exceptions::ArmoniKApiException("Retrieved data is incomplete"); + throw armonik::api::common::exceptions::ArmoniKApiException("Retrieved data is incomplete"); } return result_data; }); } std::map -ArmoniK::Api::Client::SubmitterClient::get_result_status(const std::string &session_id, +armonik::api::client::SubmitterClient::get_result_status(const std::string &session_id, const std::vector &result_ids) { - grpc::ClientContext context; + ::grpc::ClientContext context; armonik::api::grpc::v1::submitter::GetResultStatusRequest request; armonik::api::grpc::v1::submitter::GetResultStatusReply reply; @@ -345,7 +345,7 @@ ArmoniK::Api::Client::SubmitterClient::get_result_status(const std::string &sess auto status = stub_->GetResultStatus(&context, request, &reply); if (!status.ok()) { - throw ArmoniK::Api::Common::exceptions::ArmoniKApiException("Couldn't get result status : " + + throw armonik::api::common::exceptions::ArmoniKApiException("Couldn't get result status : " + status.error_message()); } diff --git a/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt index ddbbc03c2..7df317bc9 100644 --- a/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt +++ b/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt @@ -3,7 +3,6 @@ include(GNUInstallDirs) include(CMakePackageConfigHelpers) set(PROJECT_NAME ArmoniK.Api.Common) -set(NAMESPACE ArmoniK::Api::Common) set(ARMONIK_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/armonik/common) set(PROJECT_BUILD_DIR ${BUILD_DIR}/${PROJECT_NAME}) @@ -27,28 +26,16 @@ set(PROTO_FILES list(TRANSFORM PROTO_FILES PREPEND "${PROTO_FILES_DIR}/") -set(CMAKE_FIND_DEBUG_MODE FALSE) # Trouver les packages requis -find_package(Protobuf REQUIRED) +if (UNIX) + find_package(Protobuf REQUIRED) +else() + find_package(Protobuf CONFIG REQUIRED) +endif() find_package(gRPC CONFIG REQUIRED) find_package(Threads) include(FetchContent) -include(downloader) - -SET(SRC_FMT "https://github.com/fmtlib/fmt/archive/refs/tags/10.1.0.tar.gz") -SET(SRC_SIMDJSON "https://github.com/simdjson/simdjson/archive/refs/tags/v3.2.2.tar.gz") - -#To fix proxy issue with FETCHCONTENT, we need to trust to a powershell script to downlad file with webbrowser credentials -if (WIN32) -file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/_deps/") - - download_windows_file_https("${SRC_FMT}" "${CMAKE_BINARY_DIR}/_deps/10.1.0.tar.gz" TRUE) - - SET(SRC_FMT "${CMAKE_BINARY_DIR}/_deps/10.1.0.tar.gz") - -endif() - FETCHCONTENT_DECLARE( fmt @@ -61,12 +48,6 @@ if(NOT fmt_POPULATED) FetchContent_Populate(fmt) endif() -if (WIN32) - download_windows_file_https(${SRC_SIMDJSON} "${CMAKE_BINARY_DIR}/_deps/v3.2.2.tar.gz" TRUE) - - SET(SRC_SIMDJSON "${CMAKE_BINARY_DIR}/_deps/v3.2.2.tar.gz") -endif() - FETCHCONTENT_DECLARE( simdjson URL "${SRC_SIMDJSON}" @@ -78,8 +59,6 @@ if(NOT simdjson_POPULATED) FetchContent_Populate(simdjson) endif() -set(CMAKE_FIND_DEBUG_MODE FALSE) - SET(SOURCES_FILES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/source") SET(HEADER_FILES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/header") @@ -91,7 +70,7 @@ file(MAKE_DIRECTORY ${PROJECT_BUILD_DIR}) add_library(${PROJECT_NAME} ${PROTO_GENERATED_FILES} ${SRC_CLIENT_FILES} ${HEADER_CLIENT_FILES} ${simdjson_SOURCE_DIR}/singleheader/simdjson.cpp ${simdjson_SOURCE_DIR}/singleheader/simdjson.h) target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf gRPC::grpc++_unsecure) -target_compile_definitions(${PROJECT_NAME} PUBLIC API_COMMON_NAMESPACE=${NAMESPACE} FMT_HEADER_ONLY=1) +target_compile_definitions(${PROJECT_NAME} PUBLIC FMT_HEADER_ONLY=1) setup_options(${PROJECT_NAME}) diff --git a/packages/cpp/ArmoniK.Api.Common/Config.cmake.in b/packages/cpp/ArmoniK.Api.Common/Config.cmake.in index 5b2d09d17..442f21fb4 100644 --- a/packages/cpp/ArmoniK.Api.Common/Config.cmake.in +++ b/packages/cpp/ArmoniK.Api.Common/Config.cmake.in @@ -4,7 +4,11 @@ set_and_check(ARMONIK_API_COMMON_PREFIX "@PACKAGE_CMAKE_INSTALL_PREFIX@") set_and_check(ARMONIK_API_COMMON_LIBPATH "@PACKAGE_CMAKE_INSTALL_LIBDIR@") include(CMakeFindDependencyMacro) -find_dependency(Protobuf REQUIRED) +if (UNIX) + find_dependency(Protobuf REQUIRED) +else() + find_dependency(Protobuf CONFIG REQUIRED) +endif() find_dependency(gRPC CONFIG REQUIRED) find_dependency(Threads) diff --git a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKApiException.h b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKApiException.h index e9fcd49a3..661f78c54 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKApiException.h +++ b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKApiException.h @@ -2,12 +2,12 @@ #define ARMONIK_API_ARMONIKAPIEXCEPTION_H #include -namespace API_COMMON_NAMESPACE::exceptions { +namespace armonik::api::common::exceptions { class ArmoniKApiException : public std::runtime_error { public: explicit ArmoniKApiException(const std::string &message) : runtime_error(message) {} }; -} // namespace API_COMMON_NAMESPACE::exceptions +} // namespace armonik::api::common::exceptions #endif // ARMONIK_API_ARMONIKAPIEXCEPTION_H diff --git a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskError.h b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskError.h index b22b80b92..f0f47440b 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskError.h +++ b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskError.h @@ -5,7 +5,7 @@ #include #include #include -namespace API_COMMON_NAMESPACE::exceptions { +namespace armonik::api::common::exceptions { class ArmoniKTaskError : public ArmoniKApiException { public: @@ -31,6 +31,6 @@ class ArmoniKTaskError : public ArmoniKApiException { std::vector> status_details; }; -} // namespace API_COMMON_NAMESPACE::exceptions +} // namespace armonik::api::common::exceptions #endif // ARMONIK_API_ARMONIKTASKERROR_H diff --git a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskNotCompletedException.h b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskNotCompletedException.h index 67bf2927e..43437c2d3 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskNotCompletedException.h +++ b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskNotCompletedException.h @@ -2,7 +2,7 @@ #define ARMONIK_API_ARMONIKTASKNOTCOMPLETEDEXCEPTION_H #include "ArmoniKApiException.h" -namespace API_COMMON_NAMESPACE::exceptions { +namespace armonik::api::common::exceptions { class ArmoniKTaskNotCompletedException : public ArmoniKApiException { public: @@ -10,6 +10,6 @@ class ArmoniKTaskNotCompletedException : public ArmoniKApiException { : ArmoniKApiException("Task " + taskId + " not completed. " + message), taskId(taskId) {} const std::string taskId; }; -} // namespace API_COMMON_NAMESPACE::exceptions +} // namespace armonik::api::common::exceptions #endif // ARMONIK_API_ARMONIKTASKNOTCOMPLETEDEXCEPTION_H diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/base.h b/packages/cpp/ArmoniK.Api.Common/header/logger/base.h index 0694e7f09..09521c480 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/base.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/base.h @@ -9,7 +9,7 @@ #include "context.h" #include "level.h" -namespace API_COMMON_NAMESPACE::logger { +namespace armonik::api::common::logger { /** * @interface ILogger * @brief Logger interface. @@ -107,4 +107,4 @@ class ILogger { log(Level::Fatal, message, message_context); } }; -} // namespace API_COMMON_NAMESPACE::logger +} // namespace armonik::api::common::logger diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/context.h b/packages/cpp/ArmoniK.Api.Common/header/logger/context.h index da0dddf7e..07cc9278d 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/context.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/context.h @@ -7,7 +7,7 @@ #include #include -namespace API_COMMON_NAMESPACE::logger { +namespace armonik::api::common::logger { /** * @class Context * @brief Logger context. @@ -17,4 +17,4 @@ class Context : public std::map { using std::map::map; using std::map::operator=; }; -} // namespace API_COMMON_NAMESPACE::logger +} // namespace armonik::api::common::logger diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/formatter.h b/packages/cpp/ArmoniK.Api.Common/header/logger/formatter.h index 7d5e04a0e..daeb69e43 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/formatter.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/formatter.h @@ -10,7 +10,7 @@ #include "fwd.h" #include "level.h" -namespace API_COMMON_NAMESPACE::logger { +namespace armonik::api::common::logger { /** * @interface IFormatter * @brief Formatter interface to use by a logger. @@ -46,4 +46,4 @@ std::unique_ptr formatter_clef(); * @return Pointer to the formatter. */ std::unique_ptr formatter_plain(bool styling = false); -} // namespace API_COMMON_NAMESPACE::logger +} // namespace armonik::api::common::logger diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/fwd.h b/packages/cpp/ArmoniK.Api.Common/header/logger/fwd.h index 4ee0de957..cb6ce7ee3 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/fwd.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/fwd.h @@ -4,7 +4,7 @@ * @brief Forward declarations for logger classes. */ -namespace API_COMMON_NAMESPACE::logger { +namespace armonik::api::common::logger { class ILogger; class IFormatter; class IWriter; @@ -14,4 +14,4 @@ class Logger; class LocalLogger; enum class Level; -} // namespace API_COMMON_NAMESPACE::logger +} // namespace armonik::api::common::logger diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/level.h b/packages/cpp/ArmoniK.Api.Common/header/logger/level.h index f060d83f0..d087d5073 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/level.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/level.h @@ -6,7 +6,7 @@ #include -namespace API_COMMON_NAMESPACE::logger { +namespace armonik::api::common::logger { /** * @enum Level * @brief Logging Level datatype. @@ -43,4 +43,4 @@ constexpr std::string_view level_name(Level level) { return "Unknown"; } } -} // namespace API_COMMON_NAMESPACE::logger +} // namespace armonik::api::common::logger diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/local_logger.h b/packages/cpp/ArmoniK.Api.Common/header/logger/local_logger.h index d4243fed7..9f6612fad 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/local_logger.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/local_logger.h @@ -11,7 +11,7 @@ #include "fwd.h" #include "level.h" -namespace API_COMMON_NAMESPACE::logger { +namespace armonik::api::common::logger { /** * @class LocalLogger @@ -74,4 +74,4 @@ class LocalLogger : ILogger { */ void log(Level level, std::string_view message, const Context &message_context = {}) override; }; -} // namespace API_COMMON_NAMESPACE::logger +} // namespace armonik::api::common::logger diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/logger.h b/packages/cpp/ArmoniK.Api.Common/header/logger/logger.h index 572037e34..f81d19561 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/logger.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/logger.h @@ -13,7 +13,7 @@ #include "level.h" #include "local_logger.h" -namespace API_COMMON_NAMESPACE::logger { +namespace armonik::api::common::logger { /** * @brief Default Logger. */ @@ -108,4 +108,4 @@ class Logger : public ILogger { */ void log(Level level, std::string_view message, const Context &message_context = {}) override; }; -} // namespace API_COMMON_NAMESPACE::logger +} // namespace armonik::api::common::logger diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/writer.h b/packages/cpp/ArmoniK.Api.Common/header/logger/writer.h index 8666c9d92..7ffded2e5 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/writer.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/writer.h @@ -10,7 +10,7 @@ #include "level.h" -namespace API_COMMON_NAMESPACE::logger { +namespace armonik::api::common::logger { /** * @interface IWriter * @brief Writer interface to use by a logger. @@ -41,4 +41,4 @@ std::unique_ptr writer_console(); * @return Pointer to the writer. */ std::unique_ptr writer_file(std::ostream &out); -} // namespace API_COMMON_NAMESPACE::logger +} // namespace armonik::api::common::logger diff --git a/packages/cpp/ArmoniK.Api.Common/header/options/ComputePlane.h b/packages/cpp/ArmoniK.Api.Common/header/options/ComputePlane.h index 90eb2a512..f1f513d03 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/options/ComputePlane.h +++ b/packages/cpp/ArmoniK.Api.Common/header/options/ComputePlane.h @@ -5,7 +5,7 @@ /** * @brief The armonik namespace contains classes and functions related to the ArmoniK API. */ -namespace API_COMMON_NAMESPACE::options { +namespace armonik::api::common::options { /** * @brief The ComputePlane class manages the communication addresses for workers and agents. */ @@ -58,4 +58,4 @@ class ComputePlane { std::string worker_address_; ///< The worker address string. std::string agent_address_; ///< The agent address string. }; -} // namespace API_COMMON_NAMESPACE::options +} // namespace armonik::api::common::options diff --git a/packages/cpp/ArmoniK.Api.Common/header/options/ControlPlane.h b/packages/cpp/ArmoniK.Api.Common/header/options/ControlPlane.h index 2bf455949..32f1e0af9 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/options/ControlPlane.h +++ b/packages/cpp/ArmoniK.Api.Common/header/options/ControlPlane.h @@ -3,7 +3,7 @@ #include "utils/Configuration.h" -namespace API_COMMON_NAMESPACE::options { +namespace armonik::api::common::options { class ControlPlane { public: ControlPlane(const utils::Configuration &config) { @@ -37,6 +37,6 @@ class ControlPlane { std::string ca_cert_pem_path_; bool sslValidation_; }; -} // namespace API_COMMON_NAMESPACE::options +} // namespace armonik::api::common::options #endif // ARMONIK_API_CONTROLPLANE_H diff --git a/packages/cpp/ArmoniK.Api.Common/header/options/GrpcSocketType.h b/packages/cpp/ArmoniK.Api.Common/header/options/GrpcSocketType.h index c833ee8e7..73c7d2c30 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/options/GrpcSocketType.h +++ b/packages/cpp/ArmoniK.Api.Common/header/options/GrpcSocketType.h @@ -1,10 +1,10 @@ #pragma once /** - * @namespace API_COMMON_NAMESPACE::options + * @namespace armonik::api::common::options * @brief This namespace contains common options for the armonik API. */ -namespace API_COMMON_NAMESPACE::options { +namespace armonik::api::common::options { /** * @enum grpc_socket_type * @brief Enumerates the types of gRPC sockets supported by armonik API. @@ -13,4 +13,4 @@ enum grpc_socket_type { tcp = 1, /**< @brief TCP/IP socket type */ UnixDomainSocket = 2 /**< @brief Unix domain socket type */ }; -} // namespace API_COMMON_NAMESPACE::options +} // namespace armonik::api::common::options diff --git a/packages/cpp/ArmoniK.Api.Common/header/utils/Configuration.h b/packages/cpp/ArmoniK.Api.Common/header/utils/Configuration.h index efb60b715..a5825ecd7 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/utils/Configuration.h +++ b/packages/cpp/ArmoniK.Api.Common/header/utils/Configuration.h @@ -11,12 +11,12 @@ #include #include -namespace API_COMMON_NAMESPACE::options { +namespace armonik::api::common::options { class ComputePlane; class ControlPlane; -} // namespace API_COMMON_NAMESPACE::options +} // namespace armonik::api::common::options -namespace API_COMMON_NAMESPACE::utils { +namespace armonik::api::common::utils { /** * @class Configuration * @brief Interface for a configuration class that stores and manages key-value pairs. @@ -89,4 +89,4 @@ class Configuration { std::set above_env_keys_; bool use_environment_ = false; }; -} // namespace API_COMMON_NAMESPACE::utils +} // namespace armonik::api::common::utils diff --git a/packages/cpp/ArmoniK.Api.Common/header/utils/EnvConfiguration.h b/packages/cpp/ArmoniK.Api.Common/header/utils/EnvConfiguration.h index 496bfe853..67974f15b 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/utils/EnvConfiguration.h +++ b/packages/cpp/ArmoniK.Api.Common/header/utils/EnvConfiguration.h @@ -7,11 +7,11 @@ #include "utils/Configuration.h" -namespace API_COMMON_NAMESPACE::utils::EnvConfiguration { +namespace armonik::api::common::utils::EnvConfiguration { inline void fromEnv(Configuration &config) { config.add_env_configuration(); } inline Configuration fromEnv() { Configuration config; config.add_env_configuration(); return config; } -} // namespace API_COMMON_NAMESPACE::utils::EnvConfiguration +} // namespace armonik::api::common::utils::EnvConfiguration diff --git a/packages/cpp/ArmoniK.Api.Common/header/utils/GuuId.h b/packages/cpp/ArmoniK.Api.Common/header/utils/GuuId.h index d8c8bac30..ada30259d 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/utils/GuuId.h +++ b/packages/cpp/ArmoniK.Api.Common/header/utils/GuuId.h @@ -10,9 +10,9 @@ #include /** - * @brief The API_COMMON_NAMESPACE::utils namespace provides utility classes and functions for the ArmoniK API. + * @brief The armonik::api::common::utils namespace provides utility classes and functions for the ArmoniK API. */ -namespace API_COMMON_NAMESPACE::utils { +namespace armonik::api::common::utils { /** * @class GuuId * @brief The GuuId class provides a static method for generating UUIDs. @@ -44,4 +44,4 @@ class GuuId { return uuid; } }; -} // namespace API_COMMON_NAMESPACE::utils +} // namespace armonik::api::common::utils diff --git a/packages/cpp/ArmoniK.Api.Common/header/utils/JsonConfiguration.h b/packages/cpp/ArmoniK.Api.Common/header/utils/JsonConfiguration.h index 2a4c8b238..b5adcd498 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/utils/JsonConfiguration.h +++ b/packages/cpp/ArmoniK.Api.Common/header/utils/JsonConfiguration.h @@ -5,7 +5,7 @@ */ #include "utils/Configuration.h" -namespace API_COMMON_NAMESPACE::utils::JsonConfiguration { +namespace armonik::api::common::utils::JsonConfiguration { void fromPath(Configuration &config, std::string_view filepath); void fromString(Configuration &config, std::string_view json_string); inline Configuration fromPath(std::string_view filepath) { @@ -18,4 +18,4 @@ inline Configuration fromString(std::string_view json_string) { fromString(config, json_string); return config; } -} // namespace API_COMMON_NAMESPACE::utils::JsonConfiguration +} // namespace armonik::api::common::utils::JsonConfiguration diff --git a/packages/cpp/ArmoniK.Api.Common/source/logger/formatter.cpp b/packages/cpp/ArmoniK.Api.Common/source/logger/formatter.cpp index 7af918d73..16dcc4c79 100644 --- a/packages/cpp/ArmoniK.Api.Common/source/logger/formatter.cpp +++ b/packages/cpp/ArmoniK.Api.Common/source/logger/formatter.cpp @@ -10,7 +10,7 @@ #include "logger/formatter.h" -namespace API_COMMON_NAMESPACE::logger { +namespace armonik::api::common::logger { /** * @brief Formatter for CLEF (Compact Log Event Format) */ @@ -98,4 +98,4 @@ std::unique_ptr formatter_plain(bool styling) { return std::make_uni // Interface destructor IFormatter::~IFormatter() = default; -} // namespace API_COMMON_NAMESPACE::logger +} // namespace armonik::api::common::logger diff --git a/packages/cpp/ArmoniK.Api.Common/source/logger/local_logger.cpp b/packages/cpp/ArmoniK.Api.Common/source/logger/local_logger.cpp index 316405217..ac4b4acfc 100644 --- a/packages/cpp/ArmoniK.Api.Common/source/logger/local_logger.cpp +++ b/packages/cpp/ArmoniK.Api.Common/source/logger/local_logger.cpp @@ -6,7 +6,7 @@ #include "logger/local_logger.h" -namespace API_COMMON_NAMESPACE::logger { +namespace armonik::api::common::logger { namespace { // Empty string to return when key is not found @@ -51,4 +51,4 @@ void LocalLogger::log(Level level, std::string_view message, const Context &mess auto formatted = formatter_->format(level_, message, *global_context_, local_context_, message_context); writer_->write(level_, formatted); } -} // namespace API_COMMON_NAMESPACE::logger +} // namespace armonik::api::common::logger diff --git a/packages/cpp/ArmoniK.Api.Common/source/logger/logger.cpp b/packages/cpp/ArmoniK.Api.Common/source/logger/logger.cpp index 090ce7ace..4895de7cf 100644 --- a/packages/cpp/ArmoniK.Api.Common/source/logger/logger.cpp +++ b/packages/cpp/ArmoniK.Api.Common/source/logger/logger.cpp @@ -6,7 +6,7 @@ #include "logger/logger.h" -namespace API_COMMON_NAMESPACE::logger { +namespace armonik::api::common::logger { namespace { // Empty string to return when key is not found @@ -78,4 +78,4 @@ void Logger::log(Level level, std::string_view message, const Context &message_c // Interface destructor ILogger::~ILogger() = default; -} // namespace API_COMMON_NAMESPACE::logger +} // namespace armonik::api::common::logger diff --git a/packages/cpp/ArmoniK.Api.Common/source/logger/writer.cpp b/packages/cpp/ArmoniK.Api.Common/source/logger/writer.cpp index 9236c9183..81d8b095c 100644 --- a/packages/cpp/ArmoniK.Api.Common/source/logger/writer.cpp +++ b/packages/cpp/ArmoniK.Api.Common/source/logger/writer.cpp @@ -3,7 +3,7 @@ #include "logger/writer.h" -namespace API_COMMON_NAMESPACE::logger { +namespace armonik::api::common::logger { /** * @brief std::ostream -baked Writer @@ -56,4 +56,4 @@ std::unique_ptr writer_file(std::ostream &out) { return std::make_uniqu // Interface destructor IWriter::~IWriter() = default; -} // namespace API_COMMON_NAMESPACE::logger +} // namespace armonik::api::common::logger diff --git a/packages/cpp/ArmoniK.Api.Common/source/utils/Configuration.cpp b/packages/cpp/ArmoniK.Api.Common/source/utils/Configuration.cpp index 5ac8cdbfd..1a449d781 100644 --- a/packages/cpp/ArmoniK.Api.Common/source/utils/Configuration.cpp +++ b/packages/cpp/ArmoniK.Api.Common/source/utils/Configuration.cpp @@ -4,7 +4,7 @@ #include "options/ControlPlane.h" #include "utils/JsonConfiguration.h" -namespace API_COMMON_NAMESPACE::utils { +namespace armonik::api::common::utils { Configuration &Configuration::add_json_configuration(std::string_view file_path) { JsonConfiguration::fromPath(*this, file_path); return *this; @@ -44,4 +44,4 @@ std::string Configuration::get(const std::string &string) const { const std::map &Configuration::list() const { return options_; } options::ControlPlane Configuration::get_control_plane() const { return *this; } -} // namespace API_COMMON_NAMESPACE::utils +} // namespace armonik::api::common::utils diff --git a/packages/cpp/ArmoniK.Api.Common/source/utils/JsonConfiguration.cpp b/packages/cpp/ArmoniK.Api.Common/source/utils/JsonConfiguration.cpp index a639be866..61aa7149d 100644 --- a/packages/cpp/ArmoniK.Api.Common/source/utils/JsonConfiguration.cpp +++ b/packages/cpp/ArmoniK.Api.Common/source/utils/JsonConfiguration.cpp @@ -11,7 +11,7 @@ using namespace simdjson; * @param prefix Prefix for the key * @param element json element */ -void populate(API_COMMON_NAMESPACE::utils::Configuration &config, const std::string &prefix, +void populate(armonik::api::common::utils::Configuration &config, const std::string &prefix, const dom::element &element) { switch (element.type()) { case dom::element_type::ARRAY: { @@ -33,7 +33,7 @@ void populate(API_COMMON_NAMESPACE::utils::Configuration &config, const std::str } } -void API_COMMON_NAMESPACE::utils::JsonConfiguration::fromPath(API_COMMON_NAMESPACE::utils::Configuration &config, +void armonik::api::common::utils::JsonConfiguration::fromPath(armonik::api::common::utils::Configuration &config, std::string_view filepath) { dom::parser parser; dom::element elem; @@ -44,7 +44,7 @@ void API_COMMON_NAMESPACE::utils::JsonConfiguration::fromPath(API_COMMON_NAMESPA std::cerr << "Unable to load json file " << filepath << " : " << e.what(); } } -void API_COMMON_NAMESPACE::utils::JsonConfiguration::fromString(API_COMMON_NAMESPACE::utils::Configuration &config, +void armonik::api::common::utils::JsonConfiguration::fromString(armonik::api::common::utils::Configuration &config, std::string_view json_string) { dom::parser parser; populate(config, "", parser.parse(padded_string(json_string))); diff --git a/packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt index bdf0fa933..ef6ad2dc3 100644 --- a/packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt +++ b/packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt @@ -1,5 +1,4 @@ set(PROJECT_NAME ArmoniK.Api.Tests) -set(NAMESPACE ArmoniK::Api::Tests) # Trouver les packages requis find_package(Protobuf REQUIRED) @@ -29,8 +28,6 @@ endif() set(PROTO_BINARY_DIR "${BUILD_DIR}/${PROJECT_NAME}/") set(PROTO_IMPORT_DIRS "${PROTO_FILES_DIR}") -target_compile_definitions(${PROJECT_NAME} PUBLIC API_TEST_NAMESPACE=${NAMESPACE}) - target_include_directories(${PROJECT_NAME} PUBLIC "$" diff --git a/packages/cpp/ArmoniK.Api.Tests/source/SubmitterClientTest.cpp b/packages/cpp/ArmoniK.Api.Tests/source/SubmitterClientTest.cpp index e0ea56ff6..857277dc2 100644 --- a/packages/cpp/ArmoniK.Api.Tests/source/SubmitterClientTest.cpp +++ b/packages/cpp/ArmoniK.Api.Tests/source/SubmitterClientTest.cpp @@ -24,7 +24,7 @@ #include "results_service.grpc.pb.h" #include "submitter/ResultsClient.h" -using ArmoniK::Api::Common::utils::Configuration; +using armonik::api::common::utils::Configuration; using armonik::api::grpc::v1::TaskOptions; using armonik::api::grpc::v1::submitter::CreateSessionReply; using armonik::api::grpc::v1::submitter::CreateSessionRequest; @@ -32,12 +32,12 @@ using armonik::api::grpc::v1::submitter::Submitter; using grpc::Channel; using grpc::ClientContext; using grpc::Status; -using namespace ArmoniK::Api::Common::utils; +using namespace armonik::api::common::utils; using ::testing::_; using ::testing::AtLeast; -namespace logger = ArmoniK::Api::Common::logger; +namespace logger = armonik::api::common::logger; /** * @brief Initializes task options creates channel with server address @@ -91,7 +91,7 @@ TEST(testMock, createSession) { std::unique_ptr stub = Submitter::NewStub(channel); // EXPECT_CALL(*stub, CreateSession(_, _, _)).Times(AtLeast(1)); - ArmoniK::Api::Client::SubmitterClient submitter(std::move(stub)); + armonik::api::client::SubmitterClient submitter(std::move(stub)); std::string session_id = submitter.create_session(task_options, partition_ids); std::cout << "create_session response: " << session_id << std::endl; @@ -141,17 +141,17 @@ TEST(testMock, submitTask) { CreateSessionReply reply; grpc::ClientContext context; - ArmoniK::Api::Client::SubmitterClient submitter(std::move(stub)); + armonik::api::client::SubmitterClient submitter(std::move(stub)); const std::vector &partition_ids = {""}; std::string session_id = submitter.create_session(task_options, partition_ids); ASSERT_FALSE(session_id.empty()); - ArmoniK::Api::Client::ResultsClient results(armonik::api::grpc::v1::results::Results::NewStub(channel)); + armonik::api::client::ResultsClient results(armonik::api::grpc::v1::results::Results::NewStub(channel)); std::vector names; names.reserve(10); for (int i = 0; i < 10; i++) { - names.push_back(ArmoniK::Api::Common::utils::GuuId::generate_uuid()); + names.push_back(armonik::api::common::utils::GuuId::generate_uuid()); } auto result_mapping = results.create_results(session_id, names); int j = 0; @@ -160,10 +160,10 @@ TEST(testMock, submitTask) { } try { - std::vector payloads; + std::vector payloads; for (int i = 0; i < 10; i++) { - ArmoniK::Api::Client::payload_data data; + armonik::api::client::payload_data data; data.keys = names[i]; data.payload = {'a', 'r', 'm', 'o', 'n', 'i', 'k'}; data.dependencies = {}; @@ -207,19 +207,19 @@ TEST(testMock, testWorker) { grpc::ClientContext context; std::unique_ptr stub_client = Submitter::NewStub(channel); - ArmoniK::Api::Client::SubmitterClient submitter(std::move(stub_client)); + armonik::api::client::SubmitterClient submitter(std::move(stub_client)); std::string session_id = submitter.create_session(task_options, partition_ids); auto name = "test"; armonik::api::grpc::v1::results::CreateResultsMetaDataRequest request_create; request_create.set_session_id(session_id); - ArmoniK::Api::Client::ResultsClient results(armonik::api::grpc::v1::results::Results::NewStub(channel)); + armonik::api::client::ResultsClient results(armonik::api::grpc::v1::results::Results::NewStub(channel)); auto mapping = results.create_results(session_id, {name}); ASSERT_TRUE(mapping.size() == 1); - std::vector payloads; - ArmoniK::Api::Client::payload_data data; + std::vector payloads; + armonik::api::client::payload_data data; data.keys = mapping[name]; data.payload = "armonik"; data.dependencies = {}; @@ -261,14 +261,14 @@ TEST(testMock, getResult) { grpc::ClientContext context; std::unique_ptr stub_client = Submitter::NewStub(channel); - ArmoniK::Api::Client::SubmitterClient submitter(std::move(stub_client)); + armonik::api::client::SubmitterClient submitter(std::move(stub_client)); std::string session_id = submitter.create_session(task_options, partition_ids); auto name = "test"; armonik::api::grpc::v1::results::CreateResultsMetaDataRequest request_create; request_create.set_session_id(session_id); - ArmoniK::Api::Client::ResultsClient results(armonik::api::grpc::v1::results::Results::NewStub(channel)); + armonik::api::client::ResultsClient results(armonik::api::grpc::v1::results::Results::NewStub(channel)); auto mapping = results.create_results(session_id, {name}); ASSERT_TRUE(mapping.size() == 1); diff --git a/packages/cpp/ArmoniK.Api.Worker.Tests/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Worker.Tests/CMakeLists.txt index 9b6221cc7..7eeae3f99 100644 --- a/packages/cpp/ArmoniK.Api.Worker.Tests/CMakeLists.txt +++ b/packages/cpp/ArmoniK.Api.Worker.Tests/CMakeLists.txt @@ -1,5 +1,4 @@ set(PROJECT_NAME ArmoniK.Api.Worker.Tests) -set(NAMESPACE ArmoniK::Api::Worker::Tests) # Trouver les packages requis find_package(Protobuf REQUIRED) @@ -13,8 +12,6 @@ SET(HEADER_FILES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/header") FILE(GLOB_RECURSE SRC_CLIENT_FILES ${SOURCES_FILES_DIR}/*.cpp) FILE(GLOB_RECURSE HEADER_CLIENT_FILES ${HEADER_FILES_DIR}/*.h) -#file(MAKE_DIRECTORY ${BUILD_DIR}/${PROJECT_NAME}) - add_executable(${PROJECT_NAME} ${SRC_CLIENT_FILES} ${HEADER_CLIENT_FILES}) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17) @@ -23,8 +20,6 @@ target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf gRPC::grpc++_ set(PROTO_BINARY_DIR "${BUILD_DIR}/${PROJECT_NAME}/") set(PROTO_IMPORT_DIRS "${PROTO_FILES_DIR}") -target_compile_definitions(${PROJECT_NAME} PUBLIC API_WORKER_TEST_NAMESPACE=${NAMESPACE}) - target_include_directories(${PROJECT_NAME} PUBLIC "$" diff --git a/packages/cpp/ArmoniK.Api.Worker.Tests/source/main.cpp b/packages/cpp/ArmoniK.Api.Worker.Tests/source/main.cpp index d69e888ba..39558d0e7 100644 --- a/packages/cpp/ArmoniK.Api.Worker.Tests/source/main.cpp +++ b/packages/cpp/ArmoniK.Api.Worker.Tests/source/main.cpp @@ -1,6 +1,5 @@ #include #include -#include #include @@ -8,8 +7,6 @@ #include "objects.pb.h" #include "utils/WorkerServer.h" -#include "worker_common.pb.h" -#include "worker_service.grpc.pb.h" #include "Worker/ArmoniKWorker.h" #include "Worker/ProcessStatus.h" @@ -20,18 +17,18 @@ using grpc::Channel; using grpc::ClientContext; using grpc::Status; -using ArmoniK::Api::Common::utils::Configuration; +using armonik::api::common::utils::Configuration; using armonik::api::grpc::v1::TaskOptions; using namespace armonik::api::grpc::v1::worker; -using namespace ArmoniK::Api::Common::utils; +using namespace armonik::api::common::utils; -class TestWorker : public ArmoniK::Api::Worker::ArmoniKWorker { +class TestWorker : public armonik::api::worker::ArmoniKWorker { public: explicit TestWorker(std::unique_ptr agent) : ArmoniKWorker(std::move(agent)) {} - ArmoniK::Api::Worker::ProcessStatus Execute(ArmoniK::Api::Worker::TaskHandler &taskHandler) override { + armonik::api::worker::ProcessStatus Execute(armonik::api::worker::TaskHandler &taskHandler) override { std::cout << "Call computer" << std::endl; std::cout << "SizePayload : " << taskHandler.getPayload().size() << "\nSize DD : " << taskHandler.getDataDependencies().size() @@ -41,16 +38,16 @@ class TestWorker : public ArmoniK::Api::Worker::ArmoniKWorker { if (!taskHandler.getExpectedResults().empty()) { auto res = taskHandler.send_result(taskHandler.getExpectedResults()[0], taskHandler.getPayload()).get(); if (res.has_error()) { - throw ArmoniK::Api::Common::exceptions::ArmoniKApiException(res.error()); + throw armonik::api::common::exceptions::ArmoniKApiException(res.error()); } } } catch (const std::exception &e) { std::cout << "Error sending result " << e.what() << std::endl; - return ArmoniK::Api::Worker::ProcessStatus(e.what()); + return armonik::api::worker::ProcessStatus(e.what()); } - return ArmoniK::Api::Worker::ProcessStatus::Ok; + return armonik::api::worker::ProcessStatus::Ok; } }; @@ -64,7 +61,7 @@ int main(int argc, char **argv) { config.set("ComputePlane__AgentChannel__Address", "/cache/armonik_agent.sock"); try { - ArmoniK::Api::Worker::WorkerServer::create(config)->run(); + armonik::api::worker::WorkerServer::create(config)->run(); } catch (const std::exception &e) { std::cout << "Error in worker" << e.what() << std::endl; } diff --git a/packages/cpp/ArmoniK.Api.Worker/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Worker/CMakeLists.txt index 9d45cd04d..a9438e86f 100644 --- a/packages/cpp/ArmoniK.Api.Worker/CMakeLists.txt +++ b/packages/cpp/ArmoniK.Api.Worker/CMakeLists.txt @@ -1,5 +1,4 @@ set(PROJECT_NAME ArmoniK.Api.Worker) -set(NAMESPACE ArmoniK::Api::Worker) set(ARMONIK_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}/armonik/worker) set(PROJECT_BUILD_DIR ${BUILD_DIR}/${PROJECT_NAME}) @@ -14,9 +13,12 @@ set(PROTO_MESSAGES list(TRANSFORM PROTO_FILES PREPEND ${PROTO_FILES_DIR}/) list(TRANSFORM PROTO_MESSAGES PREPEND ${PROTO_FILES_DIR}/) -set(CMAKE_FIND_DEBUG_MODE FALSE) # Trouver les packages requis -find_package(Protobuf REQUIRED) +if (UNIX) + find_package(Protobuf REQUIRED) +else() + find_package(Protobuf CONFIG REQUIRED) +endif() find_package(gRPC CONFIG REQUIRED) find_package(Threads) @@ -32,8 +34,6 @@ add_library(${PROJECT_NAME} ${PROTO_GENERATED_FILES} ${SRC_CLIENT_FILES} ${HEADE target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf gRPC::grpc++_unsecure ArmoniK.Api.Common ${PROTO_TARGET}) -target_compile_definitions(${PROJECT_NAME} PUBLIC API_WORKER_NAMESPACE=${NAMESPACE}) - target_include_directories(${PROJECT_NAME} PUBLIC "$" diff --git a/packages/cpp/ArmoniK.Api.Worker/header/Worker/ArmoniKWorker.h b/packages/cpp/ArmoniK.Api.Worker/header/Worker/ArmoniKWorker.h index 98fdde775..c395443a6 100644 --- a/packages/cpp/ArmoniK.Api.Worker/header/Worker/ArmoniKWorker.h +++ b/packages/cpp/ArmoniK.Api.Worker/header/Worker/ArmoniKWorker.h @@ -16,11 +16,11 @@ #include "ProcessStatus.h" #include "Worker/TaskHandler.h" -namespace API_WORKER_NAMESPACE { +namespace armonik::api::worker { class ArmoniKWorker : public armonik::api::grpc::v1::worker::Worker::Service { private: - ArmoniK::Api::Common::logger::Logger logger_; + armonik::api::common::logger::Logger logger_; std::unique_ptr agent_; public: @@ -38,9 +38,10 @@ class ArmoniKWorker : public armonik::api::grpc::v1::worker::Worker::Service { * * @return The status of the method. */ - grpc::Status Process(::grpc::ServerContext *context, - ::grpc::ServerReader<::armonik::api::grpc::v1::worker::ProcessRequest> *reader, - ::armonik::api::grpc::v1::worker::ProcessReply *response) override; + [[maybe_unused]] ::grpc::Status + Process(::grpc::ServerContext *context, + ::grpc::ServerReader<::armonik::api::grpc::v1::worker::ProcessRequest> *reader, + ::armonik::api::grpc::v1::worker::ProcessReply *response) override; /** * @brief Function which does the actual work @@ -58,8 +59,9 @@ class ArmoniKWorker : public armonik::api::grpc::v1::worker::Worker::Service { * * @return The status of the method. */ - grpc::Status HealthCheck(::grpc::ServerContext *context, const ::armonik::api::grpc::v1::Empty *request, - ::armonik::api::grpc::v1::worker::HealthCheckReply *response) override; + [[maybe_unused]] ::grpc::Status HealthCheck(::grpc::ServerContext *context, + const ::armonik::api::grpc::v1::Empty *request, + ::armonik::api::grpc::v1::worker::HealthCheckReply *response) override; }; -} // namespace API_WORKER_NAMESPACE +} // namespace armonik::api::worker diff --git a/packages/cpp/ArmoniK.Api.Worker/header/Worker/ProcessStatus.h b/packages/cpp/ArmoniK.Api.Worker/header/Worker/ProcessStatus.h index 4b2536499..2c40fd8b7 100644 --- a/packages/cpp/ArmoniK.Api.Worker/header/Worker/ProcessStatus.h +++ b/packages/cpp/ArmoniK.Api.Worker/header/Worker/ProcessStatus.h @@ -4,7 +4,7 @@ #include #include -namespace API_WORKER_NAMESPACE { +namespace armonik::api::worker { class ProcessStatus { public: ProcessStatus() : ProcessStatus(true, "") {} @@ -34,6 +34,6 @@ class ProcessStatus { bool ok_ = true; std::string details_; }; -} // namespace API_WORKER_NAMESPACE +} // namespace armonik::api::worker #endif // ARMONIK_API_PROCESSSTATUS_H diff --git a/packages/cpp/ArmoniK.Api.Worker/header/Worker/TaskHandler.h b/packages/cpp/ArmoniK.Api.Worker/header/Worker/TaskHandler.h index 1f799286a..2732ee254 100644 --- a/packages/cpp/ArmoniK.Api.Worker/header/Worker/TaskHandler.h +++ b/packages/cpp/ArmoniK.Api.Worker/header/Worker/TaskHandler.h @@ -8,7 +8,7 @@ #include "worker_common.pb.h" #include "worker_service.grpc.pb.h" -namespace API_WORKER_NAMESPACE { +namespace armonik::api::worker { // #include "SessionContext.h" @@ -19,9 +19,8 @@ namespace API_WORKER_NAMESPACE { class TaskHandler { private: - grpc::ClientContext context_; armonik::api::grpc::v1::agent::Agent::Stub &stub_; - grpc::ServerReader &request_iterator_; + ::grpc::ServerReader &request_iterator_; std::string session_id_; std::string task_id_; armonik::api::grpc::v1::TaskOptions task_options_; @@ -39,7 +38,7 @@ class TaskHandler { * @param request_iterator The request iterator */ TaskHandler(armonik::api::grpc::v1::agent::Agent::Stub &client, - grpc::ServerReader &request_iterator); + ::grpc::ServerReader &request_iterator); /** * @brief Initialise the task handler @@ -147,4 +146,4 @@ class TaskHandler { const armonik::api::grpc::v1::Configuration &getConfiguration() const; }; -} // namespace API_WORKER_NAMESPACE +} // namespace armonik::api::worker diff --git a/packages/cpp/ArmoniK.Api.Worker/header/utils/WorkerServer.h b/packages/cpp/ArmoniK.Api.Worker/header/utils/WorkerServer.h index fce57027a..baf04120f 100644 --- a/packages/cpp/ArmoniK.Api.Worker/header/utils/WorkerServer.h +++ b/packages/cpp/ArmoniK.Api.Worker/header/utils/WorkerServer.h @@ -25,14 +25,14 @@ using namespace armonik::api::grpc::v1::agent; -namespace API_WORKER_NAMESPACE { +namespace armonik::api::worker { /** * @class WorkerServer * @brief Represents the worker server for ArmoniK API. */ class WorkerServer { public: - Common::logger::Logger logger; + common::logger::Logger logger; private: ::grpc::ServerBuilder builder_; @@ -44,8 +44,8 @@ class WorkerServer { * @brief Constructor for the WorkerServer class. * @param configuration A shared pointer to the Configuration object. */ - explicit WorkerServer(const Common::utils::Configuration &configuration) - : logger(Common::logger::writer_console(), Common::logger::formatter_clef()) { + explicit WorkerServer(const common::utils::Configuration &configuration) + : logger(common::logger::writer_console(), common::logger::formatter_clef()) { logger.local_context_generator_add("threadId", []() { std::stringstream ss; ss << std::this_thread::get_id(); @@ -53,7 +53,7 @@ class WorkerServer { }); logger.global_context_add("container", "ArmoniK.Worker"); logger.info("Creating worker"); - Common::options::ComputePlane compute_plane(configuration); + common::options::ComputePlane compute_plane(configuration); builder_.AddListeningPort(compute_plane.get_server_address(), ::grpc::InsecureServerCredentials()); builder_.SetMaxReceiveMessageSize(-1); @@ -73,7 +73,7 @@ class WorkerServer { * @return A shared pointer to the created WorkerServer instance */ template - static std::shared_ptr create(Common::utils::Configuration configuration, Args &&...args) { + static std::shared_ptr create(common::utils::Configuration configuration, Args &&...args) { auto worker_server = std::make_shared(std::move(configuration)); worker_server->builder_.RegisterService( new Worker(Agent::NewStub(worker_server->channel), static_cast(args)...)); @@ -87,4 +87,4 @@ class WorkerServer { instance_server->Wait(); } }; -} // namespace API_WORKER_NAMESPACE +} // namespace armonik::api::worker diff --git a/packages/cpp/ArmoniK.Api.Worker/source/Worker/ArmoniKWorker.cpp b/packages/cpp/ArmoniK.Api.Worker/source/Worker/ArmoniKWorker.cpp index 37911f5a0..082a03873 100644 --- a/packages/cpp/ArmoniK.Api.Worker/source/Worker/ArmoniKWorker.cpp +++ b/packages/cpp/ArmoniK.Api.Worker/source/Worker/ArmoniKWorker.cpp @@ -20,17 +20,17 @@ using grpc::Channel; using grpc::ClientContext; using grpc::Status; -using ArmoniK::Api::Common::utils::Configuration; +using armonik::api::common::utils::Configuration; using armonik::api::grpc::v1::TaskOptions; using namespace armonik::api::grpc::v1::worker; -using namespace ArmoniK::Api::Common::utils; +using namespace armonik::api::common::utils; /** * @brief Constructs a ArmoniKWorker object. */ -API_WORKER_NAMESPACE::ArmoniKWorker::ArmoniKWorker(std::unique_ptr agent) - : logger_(ArmoniK::Api::Common::logger::writer_console(), ArmoniK::Api::Common::logger::formatter_clef()) { +armonik::api::worker::ArmoniKWorker::ArmoniKWorker(std::unique_ptr agent) + : logger_(armonik::api::common::logger::writer_console(), armonik::api::common::logger::formatter_clef()) { logger_.info("Build Service ArmoniKWorker"); logger_.global_context_add("class", "ArmoniKWorker"); logger_.global_context_add("Worker", "ArmoniK.Api.Cpp"); @@ -46,9 +46,10 @@ API_WORKER_NAMESPACE::ArmoniKWorker::ArmoniKWorker(std::unique_ptr *reader, - ::armonik::api::grpc::v1::worker::ProcessReply *response) { +[[maybe_unused]] Status +armonik::api::worker::ArmoniKWorker::Process([[maybe_unused]] ::grpc::ServerContext *context, + ::grpc::ServerReader *reader, + ::armonik::api::grpc::v1::worker::ProcessReply *response) { logger_.debug("Receive new request From C++ Worker"); @@ -68,10 +69,10 @@ Status API_WORKER_NAMESPACE::ArmoniKWorker::Process([[maybe_unused]] ::grpc::Ser } *response->mutable_output() = std::move(output); } catch (const std::exception &e) { - return {grpc::StatusCode::UNAVAILABLE, "Error processing task", e.what()}; + return {::grpc::StatusCode::UNAVAILABLE, "Error processing task", e.what()}; } - return grpc::Status::OK; + return ::grpc::Status::OK; } /** @@ -83,9 +84,10 @@ Status API_WORKER_NAMESPACE::ArmoniKWorker::Process([[maybe_unused]] ::grpc::Ser * * @return The status of the method. */ -Status API_WORKER_NAMESPACE::ArmoniKWorker::HealthCheck([[maybe_unused]] ::grpc::ServerContext *context, - [[maybe_unused]] const ::armonik::api::grpc::v1::Empty *request, - ::armonik::api::grpc::v1::worker::HealthCheckReply *response) { +[[maybe_unused]] Status +armonik::api::worker::ArmoniKWorker::HealthCheck([[maybe_unused]] ::grpc::ServerContext *context, + [[maybe_unused]] const ::armonik::api::grpc::v1::Empty *request, + ::armonik::api::grpc::v1::worker::HealthCheckReply *response) { // Implementation of the HealthCheck method logger_.debug("HealthCheck request OK"); diff --git a/packages/cpp/ArmoniK.Api.Worker/source/Worker/ProcessStatus.cpp b/packages/cpp/ArmoniK.Api.Worker/source/Worker/ProcessStatus.cpp index 7c9a685d1..48bc205b9 100644 --- a/packages/cpp/ArmoniK.Api.Worker/source/Worker/ProcessStatus.cpp +++ b/packages/cpp/ArmoniK.Api.Worker/source/Worker/ProcessStatus.cpp @@ -1,4 +1,4 @@ #include "Worker/ProcessStatus.h" -const API_WORKER_NAMESPACE::ProcessStatus API_WORKER_NAMESPACE::ProcessStatus::Ok; -const API_WORKER_NAMESPACE::ProcessStatus API_WORKER_NAMESPACE::ProcessStatus::Error(false); +const armonik::api::worker::ProcessStatus armonik::api::worker::ProcessStatus::Ok; +const armonik::api::worker::ProcessStatus armonik::api::worker::ProcessStatus::Error(false); diff --git a/packages/cpp/ArmoniK.Api.Worker/source/Worker/TaskHandler.cpp b/packages/cpp/ArmoniK.Api.Worker/source/Worker/TaskHandler.cpp index 5f524e049..2d1d75454 100644 --- a/packages/cpp/ArmoniK.Api.Worker/source/Worker/TaskHandler.cpp +++ b/packages/cpp/ArmoniK.Api.Worker/source/Worker/TaskHandler.cpp @@ -17,11 +17,10 @@ using armonik::api::grpc::v1::agent::Agent; using armonik::api::grpc::v1::agent::CreateTaskReply; using armonik::api::grpc::v1::agent::CreateTaskRequest; using armonik::api::grpc::v1::worker::ProcessRequest; -using grpc::Channel; -using grpc::ChannelInterface; -using grpc::ClientContext; -using grpc::Status; -using namespace armonik::api::grpc::v1::agent; +using ::grpc::Channel; +using ::grpc::ChannelInterface; +using ::grpc::ClientContext; +using ::grpc::Status; /** * @brief Construct a new Task Handler object @@ -29,15 +28,15 @@ using namespace armonik::api::grpc::v1::agent; * @param client the agent client * @param request_iterator The request iterator */ -API_WORKER_NAMESPACE::TaskHandler::TaskHandler(Agent::Stub &client, - grpc::ServerReader &request_iterator) +armonik::api::worker::TaskHandler::TaskHandler(Agent::Stub &client, + ::grpc::ServerReader &request_iterator) : stub_(client), request_iterator_(request_iterator) {} /** * @brief Initialise the task handler * */ -void API_WORKER_NAMESPACE::TaskHandler::init() { +void armonik::api::worker::TaskHandler::init() { ProcessRequest Request; if (!request_iterator_.Read(&Request)) { throw std::runtime_error("Request stream ended unexpectedly."); @@ -55,8 +54,6 @@ void API_WORKER_NAMESPACE::TaskHandler::init() { token_ = Request.communication_token(); config_ = std::move(*init_request->mutable_configuration()); - std::vector chunks; - auto *datachunk = &init_request->payload(); payload_.resize(datachunk->data().size()); std::memcpy(payload_.data(), datachunk->data().data(), datachunk->data().size()); @@ -129,7 +126,7 @@ void API_WORKER_NAMESPACE::TaskHandler::init() { * @return std::future> */ std::future> -API_WORKER_NAMESPACE::TaskHandler::task_chunk_stream(TaskRequest task_request, bool is_last, const std::string &token, +armonik::api::worker::TaskHandler::task_chunk_stream(TaskRequest task_request, bool is_last, const std::string &token, size_t chunk_max_size) { return std::async(std::launch::async, [task_request = std::move(task_request), chunk_max_size, is_last, token]() { std::vector requests; @@ -209,13 +206,13 @@ API_WORKER_NAMESPACE::TaskHandler::task_chunk_stream(TaskRequest task_request, b * @return std::vector>> */ std::vector>> -API_WORKER_NAMESPACE::TaskHandler::to_request_stream(const std::vector &task_requests, +armonik::api::worker::TaskHandler::to_request_stream(const std::vector &task_requests, TaskOptions task_options, const std::string &token, const size_t chunk_max_size) { std::vector>> async_chunk_payload_tasks; async_chunk_payload_tasks.push_back(std::async([task_options = std::move(task_options), token]() mutable { - CreateTaskRequest_InitRequest create_task_request_init; + grpc::v1::agent::CreateTaskRequest_InitRequest create_task_request_init; *create_task_request_init.mutable_task_options() = std::move(task_options); CreateTaskRequest create_task_request; @@ -241,7 +238,7 @@ API_WORKER_NAMESPACE::TaskHandler::to_request_stream(const std::vector -API_WORKER_NAMESPACE::TaskHandler::create_tasks_async(TaskOptions task_options, +armonik::api::worker::TaskHandler::create_tasks_async(TaskOptions task_options, const std::vector &task_requests) { return std::async(std::launch::async, [this, &task_requests, &task_options]() mutable { size_t chunk = config_.data_chunk_max_size(); @@ -249,7 +246,7 @@ API_WORKER_NAMESPACE::TaskHandler::create_tasks_async(TaskOptions task_options, CreateTaskReply reply{}; reply.set_allocated_creation_status_list(new armonik::api::grpc::v1::agent::CreateTaskReply_CreationStatusList()); - grpc::ClientContext context_client_writer; + ::grpc::ClientContext context_client_writer; auto stream(stub_.CreateTask(&context_client_writer, &reply)); auto create_task_request_async = to_request_stream(task_requests, std::move(task_options), token_, chunk); @@ -261,7 +258,7 @@ API_WORKER_NAMESPACE::TaskHandler::create_tasks_async(TaskOptions task_options, } stream->WritesDone(); - grpc::Status status = stream->Finish(); + ::grpc::Status status = stream->Finish(); if (!status.ok()) { std::stringstream message; message << "Error: " << status.error_code() << ": " << status.error_message() @@ -280,11 +277,12 @@ API_WORKER_NAMESPACE::TaskHandler::create_tasks_async(TaskOptions task_options, * @param data The result data * @return A future containing a vector of ResultReply */ -std::future API_WORKER_NAMESPACE::TaskHandler::send_result(std::string key, std::string_view data) { +std::future +armonik::api::worker::TaskHandler::send_result(std::string key, std::string_view data) { return std::async(std::launch::async, [this, key = std::move(key), data]() mutable { - grpc::ClientContext context_client_writer; + ::grpc::ClientContext context_client_writer; - ResultReply reply; + armonik::api::grpc::v1::agent::ResultReply reply; size_t max_chunk = config_.data_chunk_max_size(); const size_t data_size = data.size(); @@ -292,7 +290,7 @@ std::future API_WORKER_NAMESPACE::TaskHandler::send_result(std::str auto stream = stub_.SendResult(&context_client_writer, &reply); - Result init_msg; + armonik::api::grpc::v1::agent::Result init_msg; init_msg.mutable_init()->set_key(std::move(key)); init_msg.set_communication_token(token_); @@ -301,7 +299,7 @@ std::future API_WORKER_NAMESPACE::TaskHandler::send_result(std::str while (start < data_size) { size_t chunkSize = std::min(max_chunk, data_size - start); - Result msg; + armonik::api::grpc::v1::agent::Result msg; msg.set_communication_token(token_); auto chunk = msg.mutable_data(); chunk->mutable_data()->resize(chunkSize); @@ -312,19 +310,19 @@ std::future API_WORKER_NAMESPACE::TaskHandler::send_result(std::str start += chunkSize; } - Result end_msg; + armonik::api::grpc::v1::agent::Result end_msg; end_msg.set_communication_token(token_); end_msg.mutable_data()->set_data_complete(true); stream->Write(end_msg); stream->WritesDone(); - grpc::Status status = stream->Finish(); + ::grpc::Status status = stream->Finish(); if (!status.ok()) { std::stringstream message; message << "Error: " << status.error_code() << ": " << status.error_message() << ". details: " << status.error_details() << std::endl; - throw ArmoniK::Api::Common::exceptions::ArmoniKApiException(message.str()); + throw armonik::api::common::exceptions::ArmoniKApiException(message.str()); } return reply; }); @@ -336,18 +334,21 @@ std::future API_WORKER_NAMESPACE::TaskHandler::send_result(std::str * @param results The results data * @return std::vector list of result ids */ -std::vector -API_WORKER_NAMESPACE::TaskHandler::get_result_ids(std::vector results) { +std::vector armonik::api::worker::TaskHandler::get_result_ids( + std::vector results) { std::vector result_ids; - grpc::ClientContext context_client_writer; - CreateResultsMetaDataRequest request; - CreateResultsMetaDataResponse reply; + ::grpc::ClientContext context_client_writer; + armonik::api::grpc::v1::agent::CreateResultsMetaDataRequest request; + armonik::api::grpc::v1::agent::CreateResultsMetaDataResponse reply; *request.mutable_results() = {results.begin(), results.end()}; request.set_session_id(session_id_); Status status = stub_.CreateResultsMetaData(&context_client_writer, request, &reply); + if (!status.ok()) { + throw armonik::api::common::exceptions::ArmoniKApiException(status.error_message()); + } auto results_reply = reply.results(); @@ -363,28 +364,28 @@ API_WORKER_NAMESPACE::TaskHandler::get_result_ids(std::vector */ -const std::string &API_WORKER_NAMESPACE::TaskHandler::getPayload() const { return payload_; } +const std::string &armonik::api::worker::TaskHandler::getPayload() const { return payload_; } /** * @brief Get the Data Dependencies object * * @return std::vector */ -const std::map &API_WORKER_NAMESPACE::TaskHandler::getDataDependencies() const { +const std::map &armonik::api::worker::TaskHandler::getDataDependencies() const { return data_dependencies_; } @@ -393,7 +394,7 @@ const std::map &API_WORKER_NAMESPACE::TaskHandler::get * * @return armonik::api::grpc::v1::TaskOptions */ -const armonik::api::grpc::v1::TaskOptions &API_WORKER_NAMESPACE::TaskHandler::getTaskOptions() const { +const armonik::api::grpc::v1::TaskOptions &armonik::api::worker::TaskHandler::getTaskOptions() const { return task_options_; } @@ -402,7 +403,7 @@ const armonik::api::grpc::v1::TaskOptions &API_WORKER_NAMESPACE::TaskHandler::ge * * @return google::protobuf::RepeatedPtrField */ -const std::vector &API_WORKER_NAMESPACE::TaskHandler::getExpectedResults() const { +const std::vector &armonik::api::worker::TaskHandler::getExpectedResults() const { return expected_result_; } @@ -411,6 +412,6 @@ const std::vector &API_WORKER_NAMESPACE::TaskHandler::getExpectedRe * * @return armonik::api::grpc::v1::Configuration */ -const armonik::api::grpc::v1::Configuration &API_WORKER_NAMESPACE::TaskHandler::getConfiguration() const { +const armonik::api::grpc::v1::Configuration &armonik::api::worker::TaskHandler::getConfiguration() const { return config_; } diff --git a/packages/cpp/CMakeLists.txt b/packages/cpp/CMakeLists.txt index 5aefe758e..74f4ea033 100644 --- a/packages/cpp/CMakeLists.txt +++ b/packages/cpp/CMakeLists.txt @@ -7,7 +7,7 @@ string(REGEX MATCHALL "[0-9]+" version_list ${version}) list(GET version_list 0 version_major) list(GET version_list 1 version_minor) list(GET version_list 2 version_patch) -message(STATUS "Version ${version}") +message(STATUS "ArmoniK Version ${version}") set(SOLUTION_NAME ArmoniK.Api) project(${SOLUTION_NAME} C CXX) @@ -23,8 +23,6 @@ if (WIN32) set(Protobuf_USE_STATIC_LIBS ON) endif () -LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") - option(BUILD_TEST "Build tests" OFF) option(BUILD_CLIENT "Build client" ON) option(BUILD_WORKER "Build worker" ON) @@ -33,13 +31,11 @@ option(BUILD_SHARED_LIBS "Build using shared libraries" OFF) # make cache variables for install destinations include(GNUInstallDirs) include(CMakePackageConfigHelpers) - -set(CMAKE_CXX_STANDARD 17) +include(Dependencies.cmake) function(setup_options project_name_param) - if(MSVC) target_compile_options(${project_name_param} PRIVATE /W4) else() diff --git a/packages/cpp/Dependencies.cmake b/packages/cpp/Dependencies.cmake new file mode 100644 index 000000000..459e07763 --- /dev/null +++ b/packages/cpp/Dependencies.cmake @@ -0,0 +1,9 @@ +if(NOT DEFINED SRC_FMT) + set(SRC_FMT "https://github.com/fmtlib/fmt/archive/refs/tags/10.1.0.tar.gz") +endif() +if(NOT DEFINED SRC_SIMDJSON) + set(SRC_SIMDJSON "https://github.com/simdjson/simdjson/archive/refs/tags/v3.2.2.tar.gz") +endif() +if(NOT DEFINED SRC_GTEST) + set(SRC_GTEST "https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip") +endif() \ No newline at end of file From 8a3b3adb753abb49d746e43868c2059ae84493f2 Mon Sep 17 00:00:00 2001 From: Dylan Brasseur Date: Wed, 13 Sep 2023 16:40:04 +0200 Subject: [PATCH 3/8] Better build/dependencies documentation --- .../cpp/ArmoniK.Api.Common/CMakeLists.txt | 2 +- packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt | 2 +- packages/cpp/README.md | 17 +++++++++ packages/cpp/cmake/downloader.cmake | 38 ------------------- packages/cpp/cmake/downloader.ps1 | 13 ------- 5 files changed, 19 insertions(+), 53 deletions(-) create mode 100644 packages/cpp/README.md delete mode 100644 packages/cpp/cmake/downloader.cmake delete mode 100644 packages/cpp/cmake/downloader.ps1 diff --git a/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt index 7df317bc9..d639e543b 100644 --- a/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt +++ b/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt @@ -39,7 +39,7 @@ include(FetchContent) FETCHCONTENT_DECLARE( fmt - URL ${SRC_FMT} + URL "${SRC_FMT}" TIMEOUT 180 ) diff --git a/packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt index ef6ad2dc3..9fa363c76 100644 --- a/packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt +++ b/packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt @@ -45,7 +45,7 @@ set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY include(FetchContent) FetchContent_Declare( googletest - URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip + URL "${SRC_GTEST}" ) # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) diff --git a/packages/cpp/README.md b/packages/cpp/README.md new file mode 100644 index 000000000..ac34e1f34 --- /dev/null +++ b/packages/cpp/README.md @@ -0,0 +1,17 @@ +# ArmoniK Api Cpp + +## Build requirements +- cmake 3.22+ +- C++ compiler with C++17 support +- grpc 1.54 - 1.56.2 +- protobuf +- fmt 10.1.0 (https://github.com/fmtlib/fmt/archive/refs/tags/10.1.0.tar.gz) +- simdjson 3.2.2 (https://github.com/simdjson/simdjson/archive/refs/tags/v3.2.2.tar.gz) +- gtest (https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip) (if BUILD_TEST=ON) + +## How to build +```shell +cmake -S . -B out +cmake --build out +cmake --install out +``` diff --git a/packages/cpp/cmake/downloader.cmake b/packages/cpp/cmake/downloader.cmake deleted file mode 100644 index 8a01f18af..000000000 --- a/packages/cpp/cmake/downloader.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# Downloads a file from a URL. The URL may be https, and things will still work. -# URL - the URL to dowload the file from -# DESTFILE - the location to save the download to. The file there will be overwritten if it exists. -# FAIL_ON_ERROR - whether or not to print a FATAL_ERROR if the download fails. -function(download_windows_file_https URL DESTFILE FAIL_ON_ERROR) - - #Fixe issue with PROXY on windows to avoid env variable HTTP_PROXY with pwd - find_program(POWERSHELL NAMES powershell DOC "Path to the Windows Powershell executable. Used to download files") - set(HAVE_DOWNLOADER_PROGRAM TRUE) - - set(DOWNLOADER_PROGRAM ${POWERSHELL}) - - # from http://superuser.com/questions/25538/how-to-download-files-from-command-line-in-windows-like-wget-is-doing - - set(DOWNLOAD_COMMAND "") - if(NOT HAVE_DOWNLOADER_PROGRAM) - message(FATAL_ERROR "A downloader program, either curl, wget, or powershell, is required to download files. Please set CURL, WGET, or POWERSHELL to the location of the respective program.") - endif() - - SET(SCRIPT_DOWNLOAD "${CMAKE_SOURCE_DIR}/cmake/downloader.ps1") - - cmake_path(NATIVE_PATH SCRIPT_DOWNLOAD script_download) - cmake_path(NATIVE_PATH DESTFILE dest_win_file) - #${URL} ${dest_win_file} - SET(CONFIGURED_DOWNLOAD_COMMAND "${script_download}") - - #message("Executing command: ${DOWNLOADER_PROGRAM} ${CONFIGURED_DOWNLOAD_COMMAND}") - - execute_process(COMMAND "${DOWNLOADER_PROGRAM}" -ExecutionPolicy Bypass -File "${CONFIGURED_DOWNLOAD_COMMAND}" ${URL} ${dest_win_file} RESULT_VARIABLE DOWNLOAD_RESULT OUTPUT_VARIABLE out_var ERROR_VARIABLE err_var) - - - if((NOT ${DOWNLOAD_RESULT} EQUAL 0 OR NOT "${err_var}" STREQUAL "") AND FAIL_ON_ERROR) - message(STATUS "Unable to download file ${URL} msg ${DOWNLOAD_RESULT} : ${out_var} error : ${err_var}") - message(FATAL_ERROR "${DOWNLOADER_PROGRAM} ${CONFIGURED_DOWNLOAD_COMMAND}") - else() - message(STATUS "Info sucess to download file ${URL} msg ${DOWNLOAD_RESULT} : [${out_var}] error : [${err_var}]") - endif() -endfunction(download_windows_file_https URL DESTFILE FAIL_ON_ERROR) diff --git a/packages/cpp/cmake/downloader.ps1 b/packages/cpp/cmake/downloader.ps1 deleted file mode 100644 index f64b6447b..000000000 --- a/packages/cpp/cmake/downloader.ps1 +++ /dev/null @@ -1,13 +0,0 @@ -[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 - -$browser = New-Object System.Net.WebClient - -$browser.Proxy.Credentials =[System.Net.CredentialCache]::DefaultNetworkCredentials; - -$url=$args[0] - -$dest=$args[1] - -write-output "Download file [$url] to [$dest]" - -Invoke-WebRequest $url -OutFile $dest From e06c5e2cfa487092e2d38653a41a29fcdf6bef56 Mon Sep 17 00:00:00 2001 From: Dylan Brasseur Date: Wed, 13 Sep 2023 16:56:17 +0200 Subject: [PATCH 4/8] Fixed missing checks --- packages/cpp/ArmoniK.Api.Worker/CMakeLists.txt | 17 +++++++++-------- packages/cpp/Dependencies.cmake | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/cpp/ArmoniK.Api.Worker/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Worker/CMakeLists.txt index a9438e86f..1f14608ea 100644 --- a/packages/cpp/ArmoniK.Api.Worker/CMakeLists.txt +++ b/packages/cpp/ArmoniK.Api.Worker/CMakeLists.txt @@ -13,14 +13,6 @@ set(PROTO_MESSAGES list(TRANSFORM PROTO_FILES PREPEND ${PROTO_FILES_DIR}/) list(TRANSFORM PROTO_MESSAGES PREPEND ${PROTO_FILES_DIR}/) -# Trouver les packages requis -if (UNIX) - find_package(Protobuf REQUIRED) -else() - find_package(Protobuf CONFIG REQUIRED) -endif() -find_package(gRPC CONFIG REQUIRED) -find_package(Threads) SET(SOURCES_FILES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/source") SET(HEADER_FILES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/header") @@ -32,6 +24,15 @@ file(MAKE_DIRECTORY ${PROJECT_BUILD_DIR}/proto) add_library(${PROJECT_NAME} ${PROTO_GENERATED_FILES} ${SRC_CLIENT_FILES} ${HEADER_CLIENT_FILES}) +# Trouver les packages requis +if (UNIX) + find_package(Protobuf REQUIRED) +else() + find_package(Protobuf CONFIG REQUIRED) +endif() +find_package(gRPC CONFIG REQUIRED) +find_package(Threads) + target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf gRPC::grpc++_unsecure ArmoniK.Api.Common ${PROTO_TARGET}) target_include_directories(${PROJECT_NAME} diff --git a/packages/cpp/Dependencies.cmake b/packages/cpp/Dependencies.cmake index 459e07763..36e8eabed 100644 --- a/packages/cpp/Dependencies.cmake +++ b/packages/cpp/Dependencies.cmake @@ -6,4 +6,4 @@ if(NOT DEFINED SRC_SIMDJSON) endif() if(NOT DEFINED SRC_GTEST) set(SRC_GTEST "https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip") -endif() \ No newline at end of file +endif() From bf5677714569dbe126fb201a1e937f1b41372245 Mon Sep 17 00:00:00 2001 From: Dylan Brasseur Date: Wed, 13 Sep 2023 16:59:35 +0200 Subject: [PATCH 5/8] Fixed missing file in docker --- packages/cpp/tools/Dockerfile.worker | 1 + packages/cpp/tools/packaging/deb.Dockerfile | 1 + packages/cpp/tools/packaging/ubi7.Dockerfile | 2 ++ 3 files changed, 4 insertions(+) diff --git a/packages/cpp/tools/Dockerfile.worker b/packages/cpp/tools/Dockerfile.worker index 287dae88b..66b02ce54 100644 --- a/packages/cpp/tools/Dockerfile.worker +++ b/packages/cpp/tools/Dockerfile.worker @@ -38,6 +38,7 @@ COPY ./packages/cpp/ArmoniK.Api.Common ./ArmoniK.Api.Common COPY ./packages/cpp/ArmoniK.Api.Worker ./ArmoniK.Api.Worker COPY ./packages/cpp/ArmoniK.Api.Worker.Tests ./ArmoniK.Api.Worker.Tests COPY ./packages/cpp/CMakeLists.txt ./ +COPY ./packages/cpp/Dependencies.cmake ./ # Copy the Protocol Buffer definition files into the image WORKDIR /app/proto diff --git a/packages/cpp/tools/packaging/deb.Dockerfile b/packages/cpp/tools/packaging/deb.Dockerfile index 51b27b5c3..d18b14d03 100644 --- a/packages/cpp/tools/packaging/deb.Dockerfile +++ b/packages/cpp/tools/packaging/deb.Dockerfile @@ -17,6 +17,7 @@ COPY packages/cpp/ArmoniK.Api.Client/. ./ArmoniK.Api.Client/ COPY packages/cpp/ArmoniK.Api.Worker/. ./ArmoniK.Api.Worker/ COPY packages/cpp/CMakeLists.txt . COPY packages/cpp/Packaging.cmake . +COPY packages/cpp/Dependencies.cmake . WORKDIR /app/libarmonik/build RUN cmake -DBUILD_SHARED_LIBS=ON -DBUILD_CLIENT:BOOL=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_WORKER:BOOL=ON -DPROTO_FILES_DIR=/app/libarmonik/Protos -DCPACK_GENERATOR=DEB .. && make package -j && make clean diff --git a/packages/cpp/tools/packaging/ubi7.Dockerfile b/packages/cpp/tools/packaging/ubi7.Dockerfile index 58df393e3..a185637cd 100644 --- a/packages/cpp/tools/packaging/ubi7.Dockerfile +++ b/packages/cpp/tools/packaging/ubi7.Dockerfile @@ -28,6 +28,8 @@ COPY packages/cpp/ArmoniK.Api.Client/. ./ArmoniK.Api.Client/. COPY packages/cpp/ArmoniK.Api.Worker/. ./ArmoniK.Api.Worker/. COPY packages/cpp/CMakeLists.txt . COPY packages/cpp/Packaging.cmake . +COPY packages/cpp/Dependencies.cmake . + WORKDIR /rpm/build RUN cmake -DBUILD_SHARED_LIBS=ON -DBUILD_CLIENT:BOOL=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_WORKER:BOOL=ON -DPROTO_FILES_DIR=/rpm/Protos -DCPACK_GENERATOR=RPM -DCMAKE_PREFIX_PATH=/usr/local/grpc .. && make package -j ENTRYPOINT ["bash"] From 45d16bc657e743a9ae9701b40c2c3f03c51d42fc Mon Sep 17 00:00:00 2001 From: Dylan Brasseur Date: Thu, 14 Sep 2023 10:41:00 +0200 Subject: [PATCH 6/8] C++14 support --- .../cpp/ArmoniK.Api.Client/CMakeLists.txt | 1 + .../header/submitter/ResultsClient.h | 13 ++++--- .../header/submitter/SubmitterClient.h | 10 ++++-- .../source/submitter/ResultsClient.cpp | 18 ++++++---- .../source/submitter/SubmitterClient.cpp | 12 +++---- .../cpp/ArmoniK.Api.Common/CMakeLists.txt | 1 + .../header/exceptions/ArmoniKApiException.h | 10 ++++-- .../header/exceptions/ArmoniKTaskError.h | 10 ++++-- .../ArmoniKTaskNotCompletedException.h | 10 ++++-- .../ArmoniK.Api.Common/header/logger/base.h | 26 ++++++++------ .../header/logger/context.h | 10 ++++-- .../header/logger/formatter.h | 13 ++++--- .../ArmoniK.Api.Common/header/logger/fwd.h | 10 ++++-- .../ArmoniK.Api.Common/header/logger/level.h | 16 ++++++--- .../header/logger/local_logger.h | 14 +++++--- .../ArmoniK.Api.Common/header/logger/logger.h | 13 ++++--- .../ArmoniK.Api.Common/header/logger/util.h | 6 ++++ .../ArmoniK.Api.Common/header/logger/writer.h | 13 ++++--- .../header/options/ComputePlane.h | 10 ++++-- .../header/options/ControlPlane.h | 20 +++++++---- .../header/utils/Configuration.h | 17 ++++++--- .../header/utils/JsonConfiguration.h | 20 +++++++---- .../source/logger/formatter.cpp | 35 +++++++++++-------- .../source/logger/local_logger.cpp | 12 +++++-- .../source/logger/logger.cpp | 20 +++++++---- .../source/logger/writer.cpp | 14 +++++--- .../source/utils/Configuration.cpp | 24 ++++++++++--- .../source/utils/JsonConfiguration.cpp | 6 ++-- packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt | 2 +- .../source/SubmitterClientTest.cpp | 13 ++++--- .../ArmoniK.Api.Worker.Tests/CMakeLists.txt | 2 +- .../cpp/ArmoniK.Api.Worker/CMakeLists.txt | 1 + .../header/Worker/ArmoniKWorker.h | 8 +++-- .../header/Worker/ProcessStatus.h | 8 +++-- .../header/Worker/TaskHandler.h | 10 ++++-- .../header/utils/WorkerServer.h | 8 +++-- .../source/Worker/TaskHandler.cpp | 20 ++++------- packages/cpp/README.md | 2 +- 38 files changed, 306 insertions(+), 152 deletions(-) create mode 100644 packages/cpp/ArmoniK.Api.Common/header/logger/util.h diff --git a/packages/cpp/ArmoniK.Api.Client/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Client/CMakeLists.txt index f9960cac7..cc602013b 100644 --- a/packages/cpp/ArmoniK.Api.Client/CMakeLists.txt +++ b/packages/cpp/ArmoniK.Api.Client/CMakeLists.txt @@ -76,6 +76,7 @@ set_source_files_properties(${PROTO_GENERATED_FILES} PROPERTIES SKIP_UNITY_BUILD list(APPEND PROTO_GENERATED_FILES ${PROTO_GENERATED_MESSAGES}) target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf gRPC::grpc++_unsecure ArmoniK.Api.Common) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14) setup_options(${PROJECT_NAME}) diff --git a/packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h b/packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h index c3b3bceed..fe4a8e943 100644 --- a/packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h +++ b/packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h @@ -3,18 +3,23 @@ #include -namespace armonik::api::client { +namespace armonik { +namespace api { +namespace client { class ResultsClient { public: explicit ResultsClient(std::unique_ptr stub) : stub(std::move(stub)) {} - std::map create_results(std::string_view session_id, const std::vector &names); - void upload_result_data(const std::string &session_id, const std::string &result_id, std::string_view payload); + std::map create_results(absl::string_view session_id, + const std::vector &names); + void upload_result_data(const std::string &session_id, const std::string &result_id, absl::string_view payload); private: std::unique_ptr stub; }; -} // namespace armonik::api::client +} // namespace client +} // namespace api +} // namespace armonik #endif // ARMONIK_API_RESULTSCLIENT_H diff --git a/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h b/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h index 2d50abf81..fadff0205 100644 --- a/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h +++ b/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h @@ -10,7 +10,9 @@ #include "submitter_common.pb.h" #include "submitter_service.grpc.pb.h" -namespace armonik::api::client { +namespace armonik { +namespace api { +namespace client { /** * @brief Data structure for task payload @@ -88,7 +90,7 @@ class SubmitterClient { * @param max_retries The maximum number of retries for submitting tasks. * @return A vector of submitted task IDs. */ - std::tuple, std::vector> + std::pair, std::vector> submit_tasks_with_dependencies(std::string session_id, armonik::api::grpc::v1::TaskOptions task_options, const std::vector &payloads_with_dependencies, [[maybe_unused]] int max_retries); @@ -104,4 +106,6 @@ class SubmitterClient { get_result_status(const std::string &session_id, const std::vector &result_ids); }; -} // namespace armonik::api::client \ No newline at end of file +} // namespace client +} // namespace api +} // namespace armonik \ No newline at end of file diff --git a/packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp b/packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp index 9bc73e5fd..b8c3ae3c1 100644 --- a/packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp +++ b/packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp @@ -2,9 +2,11 @@ #include "exceptions/ArmoniKApiException.h" #include -namespace armonik::api::client { +namespace armonik { +namespace api { +namespace client { -std::map ResultsClient::create_results(std::string_view session_id, +std::map ResultsClient::create_results(absl::string_view session_id, const std::vector &names) { std::map mapping; ::grpc::ClientContext context; @@ -21,7 +23,7 @@ std::map ResultsClient::create_results(std::string_vie } results_request.mutable_results()->Add(results_create.begin(), results_create.end()); - *results_request.mutable_session_id() = session_id; + results_request.mutable_session_id()->assign(session_id.data(), session_id.size()); // Creates the results auto status = stub->CreateResultsMetaData(&context, results_request, &results_response); @@ -41,7 +43,7 @@ std::map ResultsClient::create_results(std::string_vie return mapping; } void ResultsClient::upload_result_data(const std::string &session_id, const std::string &result_id, - std::string_view payload) { + absl::string_view payload) { ::grpc::ClientContext context; armonik::api::grpc::v1::results::ResultsServiceConfigurationResponse configuration; auto status = stub->GetServiceConfiguration(&context, armonik::api::grpc::v1::Empty(), &configuration); @@ -64,8 +66,8 @@ void ResultsClient::upload_result_data(const std::string &session_id, const std: while (offset < payload.size()) { size_t chunkSize = std::min(maxChunkSize, payload.size() - offset); - - *request.mutable_data_chunk() = payload.substr(offset, chunkSize); + auto chunk = payload.substr(offset, chunkSize); + request.mutable_data_chunk()->assign(chunk.data(), chunk.size()); if (!stream->Write(request)) { throw armonik::api::common::exceptions::ArmoniKApiException("Unable to continue upload result"); } @@ -81,4 +83,6 @@ void ResultsClient::upload_result_data(const std::string &session_id, const std: status.error_message()); } } -} // namespace armonik::api::client \ No newline at end of file +} // namespace client +} // namespace api +} // namespace armonik \ No newline at end of file diff --git a/packages/cpp/ArmoniK.Api.Client/source/submitter/SubmitterClient.cpp b/packages/cpp/ArmoniK.Api.Client/source/submitter/SubmitterClient.cpp index 10541b9df..f88900b06 100644 --- a/packages/cpp/ArmoniK.Api.Client/source/submitter/SubmitterClient.cpp +++ b/packages/cpp/ArmoniK.Api.Client/source/submitter/SubmitterClient.cpp @@ -83,7 +83,7 @@ armonik::api::client::SubmitterClient::to_request_stream(const std::vector{std::move(create_large_task_request)}; })); for (auto task_request = task_requests.begin(); task_request != task_requests.end(); ++task_request) { @@ -200,7 +200,7 @@ armonik::api::client::SubmitterClient::create_tasks_async(std::string session_id reply.set_allocated_creation_status_list(new CreateTaskReply_CreationStatusList()); ClientContext context_client_writer; - std::unique_ptr stream(stub_->CreateLargeTasks(&context_client_writer, &reply)); + auto stream(stub_->CreateLargeTasks(&context_client_writer, &reply)); // task_chunk_stream(task_requests, ) std::vector> async_task_requests; @@ -237,7 +237,7 @@ armonik::api::client::SubmitterClient::create_tasks_async(std::string session_id * @param max_retries Maximum number of retries. * @return A vector of task IDs. */ -std::tuple, std::vector> +std::pair, std::vector> armonik::api::client::SubmitterClient::submit_tasks_with_dependencies( std::string session_id, TaskOptions task_options, const std::vector &payloads_with_dependencies, int max_retries = 5) { @@ -281,7 +281,7 @@ armonik::api::client::SubmitterClient::submit_tasks_with_dependencies( message << "Error while creating tasks ! : Error Message : " << createTaskReply.error() << std::endl; throw std::runtime_error(message.str().c_str()); } - return std::make_tuple(std::move(task_ids), std::move(failed_task_ids)); + return std::make_pair(std::move(task_ids), std::move(failed_task_ids)); } /** @@ -300,13 +300,11 @@ std::future armonik::api::client::SubmitterClient::get_result_async std::string result_data; bool dataComplete = false; while (streamingCall->Read(&reply)) { - size_t offset = result_data.size(); switch (reply.type_case()) { case ResultReply::kResult: switch (reply.result().type_case()) { case armonik::api::grpc::v1::DataChunk::kData: - result_data.resize(offset + reply.result().data().size()); - std::memcpy(result_data.data() + offset, reply.result().data().data(), reply.result().data().size()); + result_data.append(reply.result().data()); dataComplete = false; // Setting to false in case we receive stuff out of order break; case armonik::api::grpc::v1::DataChunk::kDataComplete: diff --git a/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt index d639e543b..b57c565c0 100644 --- a/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt +++ b/packages/cpp/ArmoniK.Api.Common/CMakeLists.txt @@ -71,6 +71,7 @@ add_library(${PROJECT_NAME} ${PROTO_GENERATED_FILES} ${SRC_CLIENT_FILES} ${HEADE target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf gRPC::grpc++_unsecure) target_compile_definitions(${PROJECT_NAME} PUBLIC FMT_HEADER_ONLY=1) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14) setup_options(${PROJECT_NAME}) diff --git a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKApiException.h b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKApiException.h index 661f78c54..a8fe30996 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKApiException.h +++ b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKApiException.h @@ -2,12 +2,18 @@ #define ARMONIK_API_ARMONIKAPIEXCEPTION_H #include -namespace armonik::api::common::exceptions { +namespace armonik { +namespace api { +namespace common { +namespace exceptions { class ArmoniKApiException : public std::runtime_error { public: explicit ArmoniKApiException(const std::string &message) : runtime_error(message) {} }; -} // namespace armonik::api::common::exceptions +} // namespace exceptions +} // namespace common +} // namespace api +} // namespace armonik #endif // ARMONIK_API_ARMONIKAPIEXCEPTION_H diff --git a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskError.h b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskError.h index f0f47440b..a968074f7 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskError.h +++ b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskError.h @@ -5,7 +5,10 @@ #include #include #include -namespace armonik::api::common::exceptions { +namespace armonik { +namespace api { +namespace common { +namespace exceptions { class ArmoniKTaskError : public ArmoniKApiException { public: @@ -31,6 +34,9 @@ class ArmoniKTaskError : public ArmoniKApiException { std::vector> status_details; }; -} // namespace armonik::api::common::exceptions +} // namespace exceptions +} // namespace common +} // namespace api +} // namespace armonik #endif // ARMONIK_API_ARMONIKTASKERROR_H diff --git a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskNotCompletedException.h b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskNotCompletedException.h index 43437c2d3..9b33e129b 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskNotCompletedException.h +++ b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskNotCompletedException.h @@ -2,7 +2,10 @@ #define ARMONIK_API_ARMONIKTASKNOTCOMPLETEDEXCEPTION_H #include "ArmoniKApiException.h" -namespace armonik::api::common::exceptions { +namespace armonik { +namespace api { +namespace common { +namespace exceptions { class ArmoniKTaskNotCompletedException : public ArmoniKApiException { public: @@ -10,6 +13,9 @@ class ArmoniKTaskNotCompletedException : public ArmoniKApiException { : ArmoniKApiException("Task " + taskId + " not completed. " + message), taskId(taskId) {} const std::string taskId; }; -} // namespace armonik::api::common::exceptions +} // namespace exceptions +} // namespace common +} // namespace api +} // namespace armonik #endif // ARMONIK_API_ARMONIKTASKNOTCOMPLETEDEXCEPTION_H diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/base.h b/packages/cpp/ArmoniK.Api.Common/header/logger/base.h index 09521c480..c099bdaa8 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/base.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/base.h @@ -4,12 +4,13 @@ * @brief Logger interface */ -#include - #include "context.h" #include "level.h" -namespace armonik::api::common::logger { +namespace armonik { +namespace api { +namespace common { +namespace logger { /** * @interface ILogger * @brief Logger interface. @@ -41,7 +42,7 @@ class ILogger { * @param message Message to log. * @param message_context Context specific for this message. */ - virtual void log(Level level, std::string_view message, const Context &message_context = {}) = 0; + virtual void log(Level level, absl::string_view message, const Context &message_context = {}) = 0; public: /** @@ -63,7 +64,7 @@ class ILogger { * @param message Message to log. * @param message_context Context specific for this message. */ - void verbose(std::string_view message, const Context &message_context = {}) { + void verbose(absl::string_view message, const Context &message_context = {}) { log(Level::Verbose, message, message_context); } /** @@ -71,7 +72,7 @@ class ILogger { * @param message Message to log. * @param message_context Context specific for this message. */ - void debug(std::string_view message, const Context &message_context = {}) { + void debug(absl::string_view message, const Context &message_context = {}) { log(Level::Debug, message, message_context); } /** @@ -79,7 +80,7 @@ class ILogger { * @param message Message to log. * @param message_context Context specific for this message. */ - void info(std::string_view message, const Context &message_context = {}) { + void info(absl::string_view message, const Context &message_context = {}) { log(Level::Info, message, message_context); } /** @@ -87,7 +88,7 @@ class ILogger { * @param message Message to log. * @param message_context Context specific for this message. */ - void warning(std::string_view message, const Context &message_context = {}) { + void warning(absl::string_view message, const Context &message_context = {}) { log(Level::Warning, message, message_context); } /** @@ -95,7 +96,7 @@ class ILogger { * @param message Message to log. * @param message_context Context specific for this message. */ - void error(std::string_view message, const Context &message_context = {}) { + void error(absl::string_view message, const Context &message_context = {}) { log(Level::Error, message, message_context); } /** @@ -103,8 +104,11 @@ class ILogger { * @param message Message to log. * @param message_context Context specific for this message. */ - void fatal(std::string_view message, const Context &message_context = {}) { + void fatal(absl::string_view message, const Context &message_context = {}) { log(Level::Fatal, message, message_context); } }; -} // namespace armonik::api::common::logger +} // namespace logger +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/context.h b/packages/cpp/ArmoniK.Api.Common/header/logger/context.h index 07cc9278d..fbce586bf 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/context.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/context.h @@ -7,7 +7,10 @@ #include #include -namespace armonik::api::common::logger { +namespace armonik { +namespace api { +namespace common { +namespace logger { /** * @class Context * @brief Logger context. @@ -17,4 +20,7 @@ class Context : public std::map { using std::map::map; using std::map::operator=; }; -} // namespace armonik::api::common::logger +} // namespace logger +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/formatter.h b/packages/cpp/ArmoniK.Api.Common/header/logger/formatter.h index daeb69e43..03a902d2a 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/formatter.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/formatter.h @@ -5,12 +5,14 @@ */ #include -#include #include "fwd.h" #include "level.h" -namespace armonik::api::common::logger { +namespace armonik { +namespace api { +namespace common { +namespace logger { /** * @interface IFormatter * @brief Formatter interface to use by a logger. @@ -31,7 +33,7 @@ class IFormatter { * @param message_context Context specific to this very message. * @return The formatted message. */ - virtual std::string format(Level level, std::string_view message, const Context &global_context, + virtual std::string format(Level level, absl::string_view message, const Context &global_context, const Context &local_context, const Context &message_context) = 0; }; @@ -46,4 +48,7 @@ std::unique_ptr formatter_clef(); * @return Pointer to the formatter. */ std::unique_ptr formatter_plain(bool styling = false); -} // namespace armonik::api::common::logger +} // namespace logger +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/fwd.h b/packages/cpp/ArmoniK.Api.Common/header/logger/fwd.h index cb6ce7ee3..3332c3a1a 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/fwd.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/fwd.h @@ -4,7 +4,10 @@ * @brief Forward declarations for logger classes. */ -namespace armonik::api::common::logger { +namespace armonik { +namespace api { +namespace common { +namespace logger { class ILogger; class IFormatter; class IWriter; @@ -14,4 +17,7 @@ class Logger; class LocalLogger; enum class Level; -} // namespace armonik::api::common::logger +} // namespace logger +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/level.h b/packages/cpp/ArmoniK.Api.Common/header/logger/level.h index d087d5073..18ede9b0a 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/level.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/level.h @@ -1,12 +1,15 @@ #pragma once + +#include /** * @file level.h * @brief Logging levels. */ -#include - -namespace armonik::api::common::logger { +namespace armonik { +namespace api { +namespace common { +namespace logger { /** * @enum Level * @brief Logging Level datatype. @@ -25,7 +28,7 @@ enum class Level { * @param level Log level to convert. * @return String view representing the log level. */ -constexpr std::string_view level_name(Level level) { +constexpr absl::string_view level_name(Level level) { switch (level) { case Level::Verbose: return "Verbose"; @@ -43,4 +46,7 @@ constexpr std::string_view level_name(Level level) { return "Unknown"; } } -} // namespace armonik::api::common::logger +} // namespace logger +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/local_logger.h b/packages/cpp/ArmoniK.Api.Common/header/logger/local_logger.h index 9f6612fad..a21e651eb 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/local_logger.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/local_logger.h @@ -4,14 +4,15 @@ * @brief Logger with a local context. */ -#include - #include "base.h" #include "context.h" #include "fwd.h" #include "level.h" -namespace armonik::api::common::logger { +namespace armonik { +namespace api { +namespace common { +namespace logger { /** * @class LocalLogger @@ -72,6 +73,9 @@ class LocalLogger : ILogger { /** * @copydoc ILogger::log() */ - void log(Level level, std::string_view message, const Context &message_context = {}) override; + void log(Level level, absl::string_view message, const Context &message_context = {}) override; }; -} // namespace armonik::api::common::logger +} // namespace logger +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/logger.h b/packages/cpp/ArmoniK.Api.Common/header/logger/logger.h index f81d19561..f58b5af4e 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/logger.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/logger.h @@ -5,7 +5,6 @@ #include #include -#include #include "base.h" #include "context.h" @@ -13,7 +12,10 @@ #include "level.h" #include "local_logger.h" -namespace armonik::api::common::logger { +namespace armonik { +namespace api { +namespace common { +namespace logger { /** * @brief Default Logger. */ @@ -106,6 +108,9 @@ class Logger : public ILogger { * @copydoc ILogger::log() * @details Thread-safe. */ - void log(Level level, std::string_view message, const Context &message_context = {}) override; + void log(Level level, absl::string_view message, const Context &message_context = {}) override; }; -} // namespace armonik::api::common::logger +} // namespace logger +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/util.h b/packages/cpp/ArmoniK.Api.Common/header/logger/util.h new file mode 100644 index 000000000..3256601be --- /dev/null +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/util.h @@ -0,0 +1,6 @@ +#pragma once + +#include +#include + +const fmt::string_view to_fmt(const absl::string_view sv) { return fmt::string_view(sv.data(), sv.size()); } \ No newline at end of file diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/writer.h b/packages/cpp/ArmoniK.Api.Common/header/logger/writer.h index 7ffded2e5..79a15583f 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/writer.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/writer.h @@ -6,11 +6,13 @@ #include #include -#include #include "level.h" -namespace armonik::api::common::logger { +namespace armonik { +namespace api { +namespace common { +namespace logger { /** * @interface IWriter * @brief Writer interface to use by a logger. @@ -27,7 +29,7 @@ class IWriter { * @param level Log level to use for this message. * @param formatted formatted message to write. */ - virtual void write(Level level, std::string_view formatted) = 0; + virtual void write(Level level, absl::string_view formatted) = 0; }; /** @@ -41,4 +43,7 @@ std::unique_ptr writer_console(); * @return Pointer to the writer. */ std::unique_ptr writer_file(std::ostream &out); -} // namespace armonik::api::common::logger +} // namespace logger +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/header/options/ComputePlane.h b/packages/cpp/ArmoniK.Api.Common/header/options/ComputePlane.h index f1f513d03..8466f692a 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/options/ComputePlane.h +++ b/packages/cpp/ArmoniK.Api.Common/header/options/ComputePlane.h @@ -5,7 +5,10 @@ /** * @brief The armonik namespace contains classes and functions related to the ArmoniK API. */ -namespace armonik::api::common::options { +namespace armonik { +namespace api { +namespace common { +namespace options { /** * @brief The ComputePlane class manages the communication addresses for workers and agents. */ @@ -58,4 +61,7 @@ class ComputePlane { std::string worker_address_; ///< The worker address string. std::string agent_address_; ///< The agent address string. }; -} // namespace armonik::api::common::options +} // namespace options +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/header/options/ControlPlane.h b/packages/cpp/ArmoniK.Api.Common/header/options/ControlPlane.h index 32f1e0af9..7a977aadc 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/options/ControlPlane.h +++ b/packages/cpp/ArmoniK.Api.Common/header/options/ControlPlane.h @@ -3,7 +3,10 @@ #include "utils/Configuration.h" -namespace armonik::api::common::options { +namespace armonik { +namespace api { +namespace common { +namespace options { class ControlPlane { public: ControlPlane(const utils::Configuration &config) { @@ -15,11 +18,11 @@ class ControlPlane { sslValidation_ = config.get(SSLValidationKey) != "disable"; } - [[nodiscard]] std::string_view getEndpoint() const { return endpoint_; } - [[nodiscard]] std::string_view getUserCertPemPath() const { return user_cert_pem_path_; } - [[nodiscard]] std::string_view getUserKeyPemPath() const { return user_key_pem_path_; } - [[nodiscard]] std::string_view getUserP12Path() const { return user_p12_path_; } - [[nodiscard]] std::string_view getCaCertPemPath() const { return ca_cert_pem_path_; } + [[nodiscard]] absl::string_view getEndpoint() const { return endpoint_; } + [[nodiscard]] absl::string_view getUserCertPemPath() const { return user_cert_pem_path_; } + [[nodiscard]] absl::string_view getUserKeyPemPath() const { return user_key_pem_path_; } + [[nodiscard]] absl::string_view getUserP12Path() const { return user_p12_path_; } + [[nodiscard]] absl::string_view getCaCertPemPath() const { return ca_cert_pem_path_; } [[nodiscard]] bool isSslValidation() const { return sslValidation_; } static constexpr char EndpointKey[] = "Grpc__EndPoint"; @@ -37,6 +40,9 @@ class ControlPlane { std::string ca_cert_pem_path_; bool sslValidation_; }; -} // namespace armonik::api::common::options +} // namespace options +} // namespace common +} // namespace api +} // namespace armonik #endif // ARMONIK_API_CONTROLPLANE_H diff --git a/packages/cpp/ArmoniK.Api.Common/header/utils/Configuration.h b/packages/cpp/ArmoniK.Api.Common/header/utils/Configuration.h index a5825ecd7..d5140a8cc 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/utils/Configuration.h +++ b/packages/cpp/ArmoniK.Api.Common/header/utils/Configuration.h @@ -5,18 +5,22 @@ #pragma once +#include #include #include #include #include #include -namespace armonik::api::common::options { +namespace armonik { +namespace api { +namespace common { +namespace options { class ComputePlane; class ControlPlane; -} // namespace armonik::api::common::options +} // namespace options -namespace armonik::api::common::utils { +namespace utils { /** * @class Configuration * @brief Interface for a configuration class that stores and manages key-value pairs. @@ -61,7 +65,7 @@ class Configuration { * @param file_path Path to the JSON file. * @return Reference to the current Configuration object. */ - Configuration &add_json_configuration(std::string_view file_path); + Configuration &add_json_configuration(absl::string_view file_path); /** * @brief Add environment variable configuration. @@ -89,4 +93,7 @@ class Configuration { std::set above_env_keys_; bool use_environment_ = false; }; -} // namespace armonik::api::common::utils +} // namespace utils +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/header/utils/JsonConfiguration.h b/packages/cpp/ArmoniK.Api.Common/header/utils/JsonConfiguration.h index b5adcd498..67b5c9440 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/utils/JsonConfiguration.h +++ b/packages/cpp/ArmoniK.Api.Common/header/utils/JsonConfiguration.h @@ -5,17 +5,25 @@ */ #include "utils/Configuration.h" -namespace armonik::api::common::utils::JsonConfiguration { -void fromPath(Configuration &config, std::string_view filepath); -void fromString(Configuration &config, std::string_view json_string); -inline Configuration fromPath(std::string_view filepath) { +namespace armonik { +namespace api { +namespace common { +namespace utils { +namespace JsonConfiguration { +void fromPath(Configuration &config, absl::string_view filepath); +void fromString(Configuration &config, absl::string_view json_string); +inline Configuration fromPath(absl::string_view filepath) { Configuration config; fromPath(config, filepath); return config; } -inline Configuration fromString(std::string_view json_string) { +inline Configuration fromString(absl::string_view json_string) { Configuration config; fromString(config, json_string); return config; } -} // namespace armonik::api::common::utils::JsonConfiguration +} // namespace JsonConfiguration +} // namespace utils +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/source/logger/formatter.cpp b/packages/cpp/ArmoniK.Api.Common/source/logger/formatter.cpp index 16dcc4c79..eb2901f0a 100644 --- a/packages/cpp/ArmoniK.Api.Common/source/logger/formatter.cpp +++ b/packages/cpp/ArmoniK.Api.Common/source/logger/formatter.cpp @@ -9,8 +9,12 @@ #include "logger/level.h" #include "logger/formatter.h" +#include "logger/util.h" -namespace armonik::api::common::logger { +namespace armonik { +namespace api { +namespace common { +namespace logger { /** * @brief Formatter for CLEF (Compact Log Event Format) */ @@ -19,8 +23,8 @@ class ClefFormatter : public IFormatter { /** * @copydoc IFormatter::format() */ - std::string format(Level level, std::string_view message, const Context &global_context, const Context &local_context, - const Context &message_context) override { + std::string format(Level level, absl::string_view message, const Context &global_context, + const Context &local_context, const Context &message_context) override { // Buffer to store the formatted string std::string buf; auto out = std::back_inserter(buf); @@ -30,13 +34,13 @@ class ClefFormatter : public IFormatter { auto ns = std::chrono::duration_cast(time.time_since_epoch()).count() % 1'000'000'000; // Format message with timestamp and level - fmt::format_to(out, R"({{"@t": "{:%FT%T}.{:09}Z", "@mt": {:?}, "@l": {:?})", fmt::gmtime(time), ns, message, - level_name(level)); + fmt::format_to(out, R"({{"@t": "{:%FT%T}.{:09}Z", "@mt": {:?}, "@l": {:?})", fmt::gmtime(time), ns, to_fmt(message), + to_fmt(level_name(level))); // Add contexts to the formatted message for (auto context : {&global_context, &local_context, &message_context}) { - for (auto &[key, val] : *context) { - fmt::format_to(out, ", {:?}: {:?}", key, val); + for (auto &kv : *context) { + fmt::format_to(out, ", {:?}: {:?}", kv.first, kv.second); } } @@ -65,8 +69,8 @@ class PlainFormatter : public IFormatter { /** * @copydoc IFormatter::format() */ - std::string format(Level level, std::string_view message, const Context &global_context, const Context &local_context, - const Context &message_context) override { + std::string format(Level level, absl::string_view message, const Context &global_context, + const Context &local_context, const Context &message_context) override { // Buffer to store the formatted string std::string buf; auto out = std::back_inserter(buf); @@ -79,13 +83,13 @@ class PlainFormatter : public IFormatter { auto message_style = styling_ ? fmt::emphasis::bold : fmt::text_style{}; // Format message with timestamp and level - fmt::format_to(out, "{:%FT%T}.{:09}z\t[{}]\t{}", fmt::gmtime(time), ns, level_name(level), - fmt::styled(message, message_style)); + fmt::format_to(out, "{:%FT%T}.{:09}z\t[{}]\t{}", fmt::gmtime(time), ns, to_fmt(level_name(level)), + fmt::styled(to_fmt(message), message_style)); // Add contexts to the formatted message for (auto context : {&global_context, &local_context, &message_context}) { - for (auto &[key, val] : *context) { - fmt::format_to(out, "\t{}={}", key, val); + for (auto &kv : *context) { + fmt::format_to(out, "\t{}={}", kv.first, kv.second); } } @@ -98,4 +102,7 @@ std::unique_ptr formatter_plain(bool styling) { return std::make_uni // Interface destructor IFormatter::~IFormatter() = default; -} // namespace armonik::api::common::logger +} // namespace logger +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/source/logger/local_logger.cpp b/packages/cpp/ArmoniK.Api.Common/source/logger/local_logger.cpp index ac4b4acfc..c766cd139 100644 --- a/packages/cpp/ArmoniK.Api.Common/source/logger/local_logger.cpp +++ b/packages/cpp/ArmoniK.Api.Common/source/logger/local_logger.cpp @@ -6,7 +6,10 @@ #include "logger/local_logger.h" -namespace armonik::api::common::logger { +namespace armonik { +namespace api { +namespace common { +namespace logger { namespace { // Empty string to return when key is not found @@ -43,7 +46,7 @@ const std::string &LocalLogger::context_get(const std::string &key) const { void LocalLogger::context_remove(const std::string &key) { local_context_.erase(key); } // Write a new message to the log -void LocalLogger::log(Level level, std::string_view message, const Context &message_context) { +void LocalLogger::log(Level level, absl::string_view message, const Context &message_context) { if (level < level_) { return; } @@ -51,4 +54,7 @@ void LocalLogger::log(Level level, std::string_view message, const Context &mess auto formatted = formatter_->format(level_, message, *global_context_, local_context_, message_context); writer_->write(level_, formatted); } -} // namespace armonik::api::common::logger +} // namespace logger +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/source/logger/logger.cpp b/packages/cpp/ArmoniK.Api.Common/source/logger/logger.cpp index 4895de7cf..36cc8f242 100644 --- a/packages/cpp/ArmoniK.Api.Common/source/logger/logger.cpp +++ b/packages/cpp/ArmoniK.Api.Common/source/logger/logger.cpp @@ -6,13 +6,16 @@ #include "logger/logger.h" -namespace armonik::api::common::logger { +namespace armonik { +namespace api { +namespace common { +namespace logger { namespace { // Empty string to return when key is not found -static const std::string empty_string{}; +const std::string empty_string; // Empty string generator when key is not found -static const std::function empty_func = []() { return std::string(); }; +const std::function empty_func = []() { return std::string(); }; } // namespace // Construct a Logger @@ -61,15 +64,15 @@ void Logger::local_context_generator_remove(const std::string &key) { local_cont // Create a logger with a local context that references this logger LocalLogger Logger::local(Context local_context) const { // Populate local context from generator - for (auto &&[key, generator] : local_context_generator_) { - local_context[key] = generator(); + for (auto &&kg : local_context_generator_) { + local_context[kg.first] = kg.second(); } return LocalLogger(writer_.get(), formatter_.get(), &global_context_, std::move(local_context), level_); } // ILogger::log() -void Logger::log(Level level, std::string_view message, const Context &message_context) { +void Logger::log(Level level, absl::string_view message, const Context &message_context) { if (level < level_) { return; } @@ -78,4 +81,7 @@ void Logger::log(Level level, std::string_view message, const Context &message_c // Interface destructor ILogger::~ILogger() = default; -} // namespace armonik::api::common::logger +} // namespace logger +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/source/logger/writer.cpp b/packages/cpp/ArmoniK.Api.Common/source/logger/writer.cpp index 81d8b095c..70d98ade2 100644 --- a/packages/cpp/ArmoniK.Api.Common/source/logger/writer.cpp +++ b/packages/cpp/ArmoniK.Api.Common/source/logger/writer.cpp @@ -3,7 +3,10 @@ #include "logger/writer.h" -namespace armonik::api::common::logger { +namespace armonik { +namespace api { +namespace common { +namespace logger { /** * @brief std::ostream -baked Writer @@ -25,7 +28,7 @@ class FileWriter : public IWriter { * @copydoc IWriter::write() * @details Thread-safe. */ - void write(Level, std::string_view message) override { + void write(Level, absl::string_view message) override { // Lock the writer to ensure the message is written all-at-once std::lock_guard lock_guard{mutex_}; out_ << message << std::endl; @@ -44,7 +47,7 @@ class ConsoleWriter : public IWriter { * @copydoc IWriter::write() * @details Thread-safe. */ - void write(Level level, std::string_view message) override { + void write(Level level, absl::string_view message) override { // Lock the writer to ensure the message is written all-at-once std::lock_guard lock_guard{mutex_}; (level < Level::Warning ? std::cout : std::cerr) << message << std::endl; @@ -56,4 +59,7 @@ std::unique_ptr writer_file(std::ostream &out) { return std::make_uniqu // Interface destructor IWriter::~IWriter() = default; -} // namespace armonik::api::common::logger +} // namespace logger +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/source/utils/Configuration.cpp b/packages/cpp/ArmoniK.Api.Common/source/utils/Configuration.cpp index 1a449d781..97451187f 100644 --- a/packages/cpp/ArmoniK.Api.Common/source/utils/Configuration.cpp +++ b/packages/cpp/ArmoniK.Api.Common/source/utils/Configuration.cpp @@ -4,8 +4,19 @@ #include "options/ControlPlane.h" #include "utils/JsonConfiguration.h" -namespace armonik::api::common::utils { -Configuration &Configuration::add_json_configuration(std::string_view file_path) { +constexpr char armonik::api::common::options::ControlPlane::CaCertKey[]; +constexpr char armonik::api::common::options::ControlPlane::EndpointKey[]; +constexpr char armonik::api::common::options::ControlPlane::SSLValidationKey[]; +constexpr char armonik::api::common::options::ControlPlane::UserCertKey[]; +constexpr char armonik::api::common::options::ControlPlane::UserKeyKey[]; +constexpr char armonik::api::common::options::ControlPlane::UserP12Key[]; + +namespace armonik { +namespace api { +namespace common { +namespace utils { + +Configuration &Configuration::add_json_configuration(absl::string_view file_path) { JsonConfiguration::fromPath(*this, file_path); return *this; } @@ -19,8 +30,8 @@ Configuration &Configuration::add_env_configuration() { options::ComputePlane Configuration::get_compute_plane() const { return *this; } void Configuration::set(const Configuration &other) { - for (auto &&[key, value] : other.list()) { - set(key, value); + for (auto &&kv : other.list()) { + set(kv.first, kv.second); } } void Configuration::set(const std::string &key, const std::string &value) { @@ -44,4 +55,7 @@ std::string Configuration::get(const std::string &string) const { const std::map &Configuration::list() const { return options_; } options::ControlPlane Configuration::get_control_plane() const { return *this; } -} // namespace armonik::api::common::utils +} // namespace utils +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/source/utils/JsonConfiguration.cpp b/packages/cpp/ArmoniK.Api.Common/source/utils/JsonConfiguration.cpp index 61aa7149d..1ae866931 100644 --- a/packages/cpp/ArmoniK.Api.Common/source/utils/JsonConfiguration.cpp +++ b/packages/cpp/ArmoniK.Api.Common/source/utils/JsonConfiguration.cpp @@ -34,7 +34,7 @@ void populate(armonik::api::common::utils::Configuration &config, const std::str } void armonik::api::common::utils::JsonConfiguration::fromPath(armonik::api::common::utils::Configuration &config, - std::string_view filepath) { + absl::string_view filepath) { dom::parser parser; dom::element elem; try { @@ -45,7 +45,7 @@ void armonik::api::common::utils::JsonConfiguration::fromPath(armonik::api::comm } } void armonik::api::common::utils::JsonConfiguration::fromString(armonik::api::common::utils::Configuration &config, - std::string_view json_string) { + absl::string_view json_string) { dom::parser parser; - populate(config, "", parser.parse(padded_string(json_string))); + populate(config, "", parser.parse(padded_string(json_string.data(), json_string.size()))); } diff --git a/packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt index 9fa363c76..931ea3406 100644 --- a/packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt +++ b/packages/cpp/ArmoniK.Api.Tests/CMakeLists.txt @@ -15,7 +15,7 @@ FILE(GLOB_RECURSE HEADER_CLIENT_FILES ${HEADER_FILES_DIR}/*.h) add_executable(${PROJECT_NAME} ${SRC_CLIENT_FILES} ${HEADER_CLIENT_FILES}) -set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14) target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf gRPC::grpc++_unsecure ArmoniK.Api.Client ArmoniK.Api.Common GTest::gtest_main GTest::gmock_main) diff --git a/packages/cpp/ArmoniK.Api.Tests/source/SubmitterClientTest.cpp b/packages/cpp/ArmoniK.Api.Tests/source/SubmitterClientTest.cpp index 857277dc2..4391d1575 100644 --- a/packages/cpp/ArmoniK.Api.Tests/source/SubmitterClientTest.cpp +++ b/packages/cpp/ArmoniK.Api.Tests/source/SubmitterClientTest.cpp @@ -155,8 +155,8 @@ TEST(testMock, submitTask) { } auto result_mapping = results.create_results(session_id, names); int j = 0; - for (auto &&[k, v] : result_mapping) { - names[j++] = v; + for (auto &&kv : result_mapping) { + names[j++] = kv.second; } try { @@ -169,15 +169,14 @@ TEST(testMock, submitTask) { data.dependencies = {}; payloads.push_back(data); } - const auto [task_ids, failed_task_ids] = - submitter.submit_tasks_with_dependencies(session_id, task_options, payloads, 5); - for (const auto &task_id : task_ids) { + const auto taskId_failedTaskId = submitter.submit_tasks_with_dependencies(session_id, task_options, payloads, 5); + for (const auto &task_id : taskId_failedTaskId.first) { std::stringstream out; out << "Generate task_ids : " << task_id; log.info(out.str()); } - for (const auto &failed_task_id : failed_task_ids) { + for (const auto &failed_task_id : taskId_failedTaskId.second) { std::stringstream out; out << "Failed task_ids : " << failed_task_id; log.info(out.str()); @@ -224,7 +223,7 @@ TEST(testMock, testWorker) { data.payload = "armonik"; data.dependencies = {}; payloads.push_back(data); - const auto [task_ids, failed] = submitter.submit_tasks_with_dependencies(session_id, task_options, payloads, 5); + const auto task_id_failed = submitter.submit_tasks_with_dependencies(session_id, task_options, payloads, 5); while (true) { auto status = submitter.get_result_status(session_id, {mapping[name]})[mapping[name]]; diff --git a/packages/cpp/ArmoniK.Api.Worker.Tests/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Worker.Tests/CMakeLists.txt index 7eeae3f99..af46aa18a 100644 --- a/packages/cpp/ArmoniK.Api.Worker.Tests/CMakeLists.txt +++ b/packages/cpp/ArmoniK.Api.Worker.Tests/CMakeLists.txt @@ -14,7 +14,7 @@ FILE(GLOB_RECURSE HEADER_CLIENT_FILES ${HEADER_FILES_DIR}/*.h) add_executable(${PROJECT_NAME} ${SRC_CLIENT_FILES} ${HEADER_CLIENT_FILES}) -set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14) target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf gRPC::grpc++_unsecure ArmoniK.Api.Worker ArmoniK.Api.Common) set(PROTO_BINARY_DIR "${BUILD_DIR}/${PROJECT_NAME}/") diff --git a/packages/cpp/ArmoniK.Api.Worker/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Worker/CMakeLists.txt index 1f14608ea..9f0821f53 100644 --- a/packages/cpp/ArmoniK.Api.Worker/CMakeLists.txt +++ b/packages/cpp/ArmoniK.Api.Worker/CMakeLists.txt @@ -87,6 +87,7 @@ set_property(TARGET ${PROJECT_NAME} PROPERTY set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY COMPATIBLE_INTERFACE_STRING ${PROJECT_NAME}_MAJOR_VERSION ) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14) # generate the version file for the config file write_basic_package_version_file( diff --git a/packages/cpp/ArmoniK.Api.Worker/header/Worker/ArmoniKWorker.h b/packages/cpp/ArmoniK.Api.Worker/header/Worker/ArmoniKWorker.h index c395443a6..ff06921bd 100644 --- a/packages/cpp/ArmoniK.Api.Worker/header/Worker/ArmoniKWorker.h +++ b/packages/cpp/ArmoniK.Api.Worker/header/Worker/ArmoniKWorker.h @@ -16,7 +16,9 @@ #include "ProcessStatus.h" #include "Worker/TaskHandler.h" -namespace armonik::api::worker { +namespace armonik { +namespace api { +namespace worker { class ArmoniKWorker : public armonik::api::grpc::v1::worker::Worker::Service { private: @@ -64,4 +66,6 @@ class ArmoniKWorker : public armonik::api::grpc::v1::worker::Worker::Service { ::armonik::api::grpc::v1::worker::HealthCheckReply *response) override; }; -} // namespace armonik::api::worker +} // namespace worker +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Worker/header/Worker/ProcessStatus.h b/packages/cpp/ArmoniK.Api.Worker/header/Worker/ProcessStatus.h index 2c40fd8b7..76056e8c4 100644 --- a/packages/cpp/ArmoniK.Api.Worker/header/Worker/ProcessStatus.h +++ b/packages/cpp/ArmoniK.Api.Worker/header/Worker/ProcessStatus.h @@ -4,7 +4,9 @@ #include #include -namespace armonik::api::worker { +namespace armonik { +namespace api { +namespace worker { class ProcessStatus { public: ProcessStatus() : ProcessStatus(true, "") {} @@ -34,6 +36,8 @@ class ProcessStatus { bool ok_ = true; std::string details_; }; -} // namespace armonik::api::worker +} // namespace worker +} // namespace api +} // namespace armonik #endif // ARMONIK_API_PROCESSSTATUS_H diff --git a/packages/cpp/ArmoniK.Api.Worker/header/Worker/TaskHandler.h b/packages/cpp/ArmoniK.Api.Worker/header/Worker/TaskHandler.h index 2732ee254..e50d753ae 100644 --- a/packages/cpp/ArmoniK.Api.Worker/header/Worker/TaskHandler.h +++ b/packages/cpp/ArmoniK.Api.Worker/header/Worker/TaskHandler.h @@ -8,7 +8,9 @@ #include "worker_common.pb.h" #include "worker_service.grpc.pb.h" -namespace armonik::api::worker { +namespace armonik { +namespace api { +namespace worker { // #include "SessionContext.h" @@ -87,7 +89,7 @@ class TaskHandler { * @param data The result data * @return A future containing a vector of ResultReply */ - std::future send_result(std::string key, std::string_view data); + std::future send_result(std::string key, absl::string_view data); /** * @brief Get the result ids object @@ -146,4 +148,6 @@ class TaskHandler { const armonik::api::grpc::v1::Configuration &getConfiguration() const; }; -} // namespace armonik::api::worker +} // namespace worker +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Worker/header/utils/WorkerServer.h b/packages/cpp/ArmoniK.Api.Worker/header/utils/WorkerServer.h index baf04120f..3ca818957 100644 --- a/packages/cpp/ArmoniK.Api.Worker/header/utils/WorkerServer.h +++ b/packages/cpp/ArmoniK.Api.Worker/header/utils/WorkerServer.h @@ -25,7 +25,9 @@ using namespace armonik::api::grpc::v1::agent; -namespace armonik::api::worker { +namespace armonik { +namespace api { +namespace worker { /** * @class WorkerServer * @brief Represents the worker server for ArmoniK API. @@ -87,4 +89,6 @@ class WorkerServer { instance_server->Wait(); } }; -} // namespace armonik::api::worker +} // namespace worker +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Worker/source/Worker/TaskHandler.cpp b/packages/cpp/ArmoniK.Api.Worker/source/Worker/TaskHandler.cpp index 2d1d75454..aa888b3c6 100644 --- a/packages/cpp/ArmoniK.Api.Worker/source/Worker/TaskHandler.cpp +++ b/packages/cpp/ArmoniK.Api.Worker/source/Worker/TaskHandler.cpp @@ -55,8 +55,8 @@ void armonik::api::worker::TaskHandler::init() { config_ = std::move(*init_request->mutable_configuration()); auto *datachunk = &init_request->payload(); - payload_.resize(datachunk->data().size()); - std::memcpy(payload_.data(), datachunk->data().data(), datachunk->data().size()); + payload_.clear(); + payload_.append(datachunk->data()); while (!datachunk->data_complete()) { if (!request_iterator_.Read(&Request)) { @@ -68,9 +68,7 @@ void armonik::api::worker::TaskHandler::init() { datachunk = &Request.compute().payload(); if (datachunk->type_case() == armonik::api::grpc::v1::DataChunk::kData) { - size_t prev_size = payload_.size(); - payload_.resize(payload_.size() + datachunk->data().size()); - std::memcpy(payload_.data() + prev_size, datachunk->data().data(), datachunk->data().size()); + payload_.append(datachunk->data()); } else if (datachunk->type_case() == armonik::api::grpc::v1::DataChunk::TYPE_NOT_SET) { throw std::runtime_error("Expected a Compute request type with a DataChunk Payload to continue the stream."); } else if (datachunk->type_case() == armonik::api::grpc::v1::DataChunk::kDataComplete) { @@ -103,9 +101,7 @@ void armonik::api::worker::TaskHandler::init() { auto chunk = dep_request.compute().data(); if (chunk.type_case() == armonik::api::grpc::v1::DataChunk::kData) { - size_t prevSize = data_dep.size(); - data_dep.resize(prevSize + chunk.data().size()); - std::memcpy(data_dep.data() + prevSize, chunk.data().data(), chunk.data().size()); + data_dep.append(chunk.data()); } else if (datachunk->type_case() == armonik::api::grpc::v1::DataChunk::TYPE_NOT_SET) { throw std::runtime_error("Expected a Compute request type with a DataChunk Payload to continue the stream."); } else if (datachunk->type_case() == armonik::api::grpc::v1::DataChunk::kDataComplete) { @@ -219,7 +215,7 @@ armonik::api::worker::TaskHandler::to_request_stream(const std::vector{std::move(create_task_request)}; })); for (auto task_request = task_requests.begin(); task_request != task_requests.end(); ++task_request) { @@ -278,7 +274,7 @@ armonik::api::worker::TaskHandler::create_tasks_async(TaskOptions task_options, * @return A future containing a vector of ResultReply */ std::future -armonik::api::worker::TaskHandler::send_result(std::string key, std::string_view data) { +armonik::api::worker::TaskHandler::send_result(std::string key, absl::string_view data) { return std::async(std::launch::async, [this, key = std::move(key), data]() mutable { ::grpc::ClientContext context_client_writer; @@ -301,9 +297,7 @@ armonik::api::worker::TaskHandler::send_result(std::string key, std::string_view armonik::api::grpc::v1::agent::Result msg; msg.set_communication_token(token_); - auto chunk = msg.mutable_data(); - chunk->mutable_data()->resize(chunkSize); - std::memcpy(chunk->mutable_data()->data(), data.data() + start, chunkSize); + msg.mutable_data()->mutable_data()->assign(data.data() + start, chunkSize); stream->Write(msg); diff --git a/packages/cpp/README.md b/packages/cpp/README.md index ac34e1f34..333572380 100644 --- a/packages/cpp/README.md +++ b/packages/cpp/README.md @@ -2,7 +2,7 @@ ## Build requirements - cmake 3.22+ -- C++ compiler with C++17 support +- C++ compiler with C++14 support - grpc 1.54 - 1.56.2 - protobuf - fmt 10.1.0 (https://github.com/fmtlib/fmt/archive/refs/tags/10.1.0.tar.gz) From b05644c4fdc436c7d1ecda6dcb773ac696354bfa Mon Sep 17 00:00:00 2001 From: Dylan Brasseur Date: Fri, 15 Sep 2023 12:52:05 +0200 Subject: [PATCH 7/8] Fixed some namespaces and warnings --- .../header/submitter/SubmitterClient.h | 3 +-- packages/cpp/ArmoniK.Api.Common/header/logger/util.h | 2 +- .../header/options/GrpcSocketType.h | 10 ++++++++-- .../header/utils/EnvConfiguration.h | 12 ++++++++++-- packages/cpp/ArmoniK.Api.Common/header/utils/GuuId.h | 10 ++++++++-- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h b/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h index fadff0205..5f4e7e735 100644 --- a/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h +++ b/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h @@ -92,8 +92,7 @@ class SubmitterClient { */ std::pair, std::vector> submit_tasks_with_dependencies(std::string session_id, armonik::api::grpc::v1::TaskOptions task_options, - const std::vector &payloads_with_dependencies, - [[maybe_unused]] int max_retries); + const std::vector &payloads_with_dependencies, int max_retries); /** * @brief Get result without streaming. diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/util.h b/packages/cpp/ArmoniK.Api.Common/header/logger/util.h index 3256601be..a2c706991 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/logger/util.h +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/util.h @@ -3,4 +3,4 @@ #include #include -const fmt::string_view to_fmt(const absl::string_view sv) { return fmt::string_view(sv.data(), sv.size()); } \ No newline at end of file +fmt::string_view to_fmt(const absl::string_view sv) { return {sv.data(), sv.size()}; } diff --git a/packages/cpp/ArmoniK.Api.Common/header/options/GrpcSocketType.h b/packages/cpp/ArmoniK.Api.Common/header/options/GrpcSocketType.h index 73c7d2c30..0e5bb04eb 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/options/GrpcSocketType.h +++ b/packages/cpp/ArmoniK.Api.Common/header/options/GrpcSocketType.h @@ -4,7 +4,10 @@ * @namespace armonik::api::common::options * @brief This namespace contains common options for the armonik API. */ -namespace armonik::api::common::options { +namespace armonik { +namespace api { +namespace common { +namespace options { /** * @enum grpc_socket_type * @brief Enumerates the types of gRPC sockets supported by armonik API. @@ -13,4 +16,7 @@ enum grpc_socket_type { tcp = 1, /**< @brief TCP/IP socket type */ UnixDomainSocket = 2 /**< @brief Unix domain socket type */ }; -} // namespace armonik::api::common::options +} // namespace options +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/header/utils/EnvConfiguration.h b/packages/cpp/ArmoniK.Api.Common/header/utils/EnvConfiguration.h index 67974f15b..f7c4b6898 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/utils/EnvConfiguration.h +++ b/packages/cpp/ArmoniK.Api.Common/header/utils/EnvConfiguration.h @@ -7,11 +7,19 @@ #include "utils/Configuration.h" -namespace armonik::api::common::utils::EnvConfiguration { +namespace armonik { +namespace api { +namespace common { +namespace utils { +namespace EnvConfiguration { inline void fromEnv(Configuration &config) { config.add_env_configuration(); } inline Configuration fromEnv() { Configuration config; config.add_env_configuration(); return config; } -} // namespace armonik::api::common::utils::EnvConfiguration +} // namespace EnvConfiguration +} // namespace utils +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/header/utils/GuuId.h b/packages/cpp/ArmoniK.Api.Common/header/utils/GuuId.h index ada30259d..f4abb4ee4 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/utils/GuuId.h +++ b/packages/cpp/ArmoniK.Api.Common/header/utils/GuuId.h @@ -12,7 +12,10 @@ /** * @brief The armonik::api::common::utils namespace provides utility classes and functions for the ArmoniK API. */ -namespace armonik::api::common::utils { +namespace armonik { +namespace api { +namespace common { +namespace utils { /** * @class GuuId * @brief The GuuId class provides a static method for generating UUIDs. @@ -44,4 +47,7 @@ class GuuId { return uuid; } }; -} // namespace armonik::api::common::utils +} // namespace utils +} // namespace common +} // namespace api +} // namespace armonik From de4eafaf2b75f84b3e557ce634b8f5c1b03ddebb Mon Sep 17 00:00:00 2001 From: Dylan Brasseur Date: Fri, 15 Sep 2023 13:13:26 +0200 Subject: [PATCH 8/8] Added PR suggestions --- .../header/submitter/ResultsClient.h | 50 ++--- .../header/submitter/SubmitterClient.h | 2 +- .../source/submitter/ResultsClient.cpp | 174 +++++++++--------- .../header/exceptions/ArmoniKApiException.h | 38 ++-- .../header/exceptions/ArmoniKTaskError.h | 84 ++++----- .../ArmoniKTaskNotCompletedException.h | 42 ++--- .../source/Worker/TaskHandler.cpp | 2 +- 7 files changed, 195 insertions(+), 197 deletions(-) diff --git a/packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h b/packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h index fe4a8e943..93b07631d 100644 --- a/packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h +++ b/packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h @@ -1,25 +1,25 @@ -#ifndef ARMONIK_API_RESULTSCLIENT_H -#define ARMONIK_API_RESULTSCLIENT_H - -#include - -namespace armonik { -namespace api { -namespace client { -class ResultsClient { -public: - explicit ResultsClient(std::unique_ptr stub) - : stub(std::move(stub)) {} - - std::map create_results(absl::string_view session_id, - const std::vector &names); - void upload_result_data(const std::string &session_id, const std::string &result_id, absl::string_view payload); - -private: - std::unique_ptr stub; -}; -} // namespace client -} // namespace api -} // namespace armonik - -#endif // ARMONIK_API_RESULTSCLIENT_H +#ifndef ARMONIK_API_RESULTSCLIENT_H +#define ARMONIK_API_RESULTSCLIENT_H + +#include + +namespace armonik { +namespace api { +namespace client { +class ResultsClient { +public: + explicit ResultsClient(std::unique_ptr stub) + : stub(std::move(stub)) {} + + std::map create_results(absl::string_view session_id, + const std::vector &names); + void upload_result_data(const std::string &session_id, const std::string &result_id, absl::string_view payload); + +private: + std::unique_ptr stub; +}; +} // namespace client +} // namespace api +} // namespace armonik + +#endif // ARMONIK_API_RESULTSCLIENT_H diff --git a/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h b/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h index 5f4e7e735..9eefa6857 100644 --- a/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h +++ b/packages/cpp/ArmoniK.Api.Client/header/submitter/SubmitterClient.h @@ -107,4 +107,4 @@ class SubmitterClient { } // namespace client } // namespace api -} // namespace armonik \ No newline at end of file +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp b/packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp index b8c3ae3c1..ad354fdd2 100644 --- a/packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp +++ b/packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp @@ -1,88 +1,86 @@ -#include "submitter/ResultsClient.h" -#include "exceptions/ArmoniKApiException.h" -#include - -namespace armonik { -namespace api { -namespace client { - -std::map ResultsClient::create_results(absl::string_view session_id, - const std::vector &names) { - std::map mapping; - ::grpc::ClientContext context; - armonik::api::grpc::v1::results::CreateResultsMetaDataRequest results_request; - armonik::api::grpc::v1::results::CreateResultsMetaDataResponse results_response; - - // Creates the result creation requests - std::vector results_create; - results_create.reserve(names.size()); - for (auto &&name : names) { - armonik::api::grpc::v1::results::CreateResultsMetaDataRequest_ResultCreate result_create; - result_create.set_name(name); - results_create.push_back(result_create); - } - - results_request.mutable_results()->Add(results_create.begin(), results_create.end()); - results_request.mutable_session_id()->assign(session_id.data(), session_id.size()); - - // Creates the results - auto status = stub->CreateResultsMetaData(&context, results_request, &results_response); - - if (!status.ok()) { - std::stringstream message; - message << "Error: " << status.error_code() << ": " << status.error_message() - << ". details : " << status.error_details() << std::endl; - auto str = message.str(); - std::cerr << "Could not create results for submit: " << str << std::endl; - throw armonik::api::common::exceptions::ArmoniKApiException(str); - } - - for (auto &&res : results_response.results()) { - mapping.insert({res.name(), res.result_id()}); - } - return mapping; -} -void ResultsClient::upload_result_data(const std::string &session_id, const std::string &result_id, - absl::string_view payload) { - ::grpc::ClientContext context; - armonik::api::grpc::v1::results::ResultsServiceConfigurationResponse configuration; - auto status = stub->GetServiceConfiguration(&context, armonik::api::grpc::v1::Empty(), &configuration); - if (!status.ok()) { - throw armonik::api::common::exceptions::ArmoniKApiException("Unable to get result configuration : " + - status.error_message()); - } - - size_t maxChunkSize = configuration.data_chunk_max_size(); - - armonik::api::grpc::v1::results::UploadResultDataResponse response; - // response.set_allocated_result(new armonik::api::grpc::v1::results::ResultRaw()); - ::grpc::ClientContext streamContext; - auto stream = stub->UploadResultData(&streamContext, &response); - armonik::api::grpc::v1::results::UploadResultDataRequest request; - request.mutable_id()->set_session_id(session_id); - request.mutable_id()->set_result_id(result_id); - stream->Write(request); - size_t offset = 0; - - while (offset < payload.size()) { - size_t chunkSize = std::min(maxChunkSize, payload.size() - offset); - auto chunk = payload.substr(offset, chunkSize); - request.mutable_data_chunk()->assign(chunk.data(), chunk.size()); - if (!stream->Write(request)) { - throw armonik::api::common::exceptions::ArmoniKApiException("Unable to continue upload result"); - } - offset += chunkSize; - } - - if (!stream->WritesDone()) { - throw armonik::api::common::exceptions::ArmoniKApiException("Unable to upload result"); - } - status = stream->Finish(); - if (!status.ok()) { - throw armonik::api::common::exceptions::ArmoniKApiException("Unable to finish upload result " + - status.error_message()); - } -} -} // namespace client -} // namespace api -} // namespace armonik \ No newline at end of file +#include "submitter/ResultsClient.h" +#include "exceptions/ArmoniKApiException.h" +#include + +namespace armonik { +namespace api { +namespace client { + +std::map ResultsClient::create_results(absl::string_view session_id, + const std::vector &names) { + std::map mapping; + ::grpc::ClientContext context; + armonik::api::grpc::v1::results::CreateResultsMetaDataRequest results_request; + armonik::api::grpc::v1::results::CreateResultsMetaDataResponse results_response; + + // Creates the result creation requests + std::vector results_create; + results_create.reserve(names.size()); + for (auto &&name : names) { + armonik::api::grpc::v1::results::CreateResultsMetaDataRequest_ResultCreate result_create; + result_create.set_name(name); + results_create.push_back(result_create); + } + + results_request.mutable_results()->Add(results_create.begin(), results_create.end()); + results_request.mutable_session_id()->assign(session_id.data(), session_id.size()); + + // Creates the results + auto status = stub->CreateResultsMetaData(&context, results_request, &results_response); + + if (!status.ok()) { + std::stringstream message; + message << "Error: " << status.error_code() << ": " << status.error_message() + << ". details : " << status.error_details() << std::endl; + auto str = message.str(); + std::cerr << "Could not create results for submit: " << str << std::endl; + throw armonik::api::common::exceptions::ArmoniKApiException(str); + } + + for (auto &&res : results_response.results()) { + mapping.insert({res.name(), res.result_id()}); + } + return mapping; +} +void ResultsClient::upload_result_data(const std::string &session_id, const std::string &result_id, + absl::string_view payload) { + ::grpc::ClientContext context; + armonik::api::grpc::v1::results::ResultsServiceConfigurationResponse configuration; + auto status = stub->GetServiceConfiguration(&context, armonik::api::grpc::v1::Empty(), &configuration); + if (!status.ok()) { + throw armonik::api::common::exceptions::ArmoniKApiException("Unable to get result configuration : " + + status.error_message()); + } + + size_t maxChunkSize = configuration.data_chunk_max_size(); + + armonik::api::grpc::v1::results::UploadResultDataResponse response; + // response.set_allocated_result(new armonik::api::grpc::v1::results::ResultRaw()); + ::grpc::ClientContext streamContext; + auto stream = stub->UploadResultData(&streamContext, &response); + armonik::api::grpc::v1::results::UploadResultDataRequest request; + request.mutable_id()->set_session_id(session_id); + request.mutable_id()->set_result_id(result_id); + stream->Write(request); + + while (!payload.empty()) { + auto chunk = payload.substr(0, maxChunkSize); + request.mutable_data_chunk()->assign(chunk.data(), chunk.size()); + if (!stream->Write(request)) { + throw armonik::api::common::exceptions::ArmoniKApiException("Unable to continue upload result"); + } + payload = payload.substr(maxChunkSize); + } + + if (!stream->WritesDone()) { + throw armonik::api::common::exceptions::ArmoniKApiException("Unable to upload result"); + } + status = stream->Finish(); + if (!status.ok()) { + throw armonik::api::common::exceptions::ArmoniKApiException("Unable to finish upload result " + + status.error_message()); + } +} +} // namespace client +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKApiException.h b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKApiException.h index a8fe30996..d26fe9a3d 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKApiException.h +++ b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKApiException.h @@ -1,19 +1,19 @@ -#ifndef ARMONIK_API_ARMONIKAPIEXCEPTION_H -#define ARMONIK_API_ARMONIKAPIEXCEPTION_H - -#include -namespace armonik { -namespace api { -namespace common { -namespace exceptions { - -class ArmoniKApiException : public std::runtime_error { -public: - explicit ArmoniKApiException(const std::string &message) : runtime_error(message) {} -}; -} // namespace exceptions -} // namespace common -} // namespace api -} // namespace armonik - -#endif // ARMONIK_API_ARMONIKAPIEXCEPTION_H +#ifndef ARMONIK_API_ARMONIKAPIEXCEPTION_H +#define ARMONIK_API_ARMONIKAPIEXCEPTION_H + +#include +namespace armonik { +namespace api { +namespace common { +namespace exceptions { + +class ArmoniKApiException : public std::runtime_error { +public: + explicit ArmoniKApiException(const std::string &message) : runtime_error(message) {} +}; +} // namespace exceptions +} // namespace common +} // namespace api +} // namespace armonik + +#endif // ARMONIK_API_ARMONIKAPIEXCEPTION_H diff --git a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskError.h b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskError.h index a968074f7..5118cf15f 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskError.h +++ b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskError.h @@ -1,42 +1,42 @@ -#ifndef ARMONIK_API_ARMONIKTASKERROR_H -#define ARMONIK_API_ARMONIKTASKERROR_H - -#include "ArmoniKApiException.h" -#include -#include -#include -namespace armonik { -namespace api { -namespace common { -namespace exceptions { - -class ArmoniKTaskError : public ArmoniKApiException { -public: - explicit ArmoniKTaskError(const std::string &message, const armonik::api::grpc::v1::TaskError &task_error) - : ArmoniKApiException(message) { - std::stringstream ss; - ss << "TaskId : " << task_error.task_id() << " Errors : "; - for (auto &&e : task_error.errors()) { - std::string status = armonik::api::grpc::v1::task_status::TaskStatus_Name(e.task_status()); - status_details.emplace_back(status, e.detail()); - ss << '\n' << status << " : " << e.detail(); - } - details = std::string(ArmoniKApiException::what()) + " : " + ss.str(); - taskId_ = task_error.task_id(); - } - [[nodiscard]] const char *what() const noexcept override { return details.c_str(); } - const std::string &taskId() { return taskId_; } - const std::vector> &error_details() { return status_details; } - -private: - std::string details; - std::string taskId_; - std::vector> status_details; -}; - -} // namespace exceptions -} // namespace common -} // namespace api -} // namespace armonik - -#endif // ARMONIK_API_ARMONIKTASKERROR_H +#ifndef ARMONIK_API_ARMONIKTASKERROR_H +#define ARMONIK_API_ARMONIKTASKERROR_H + +#include "ArmoniKApiException.h" +#include +#include +#include +namespace armonik { +namespace api { +namespace common { +namespace exceptions { + +class ArmoniKTaskError : public ArmoniKApiException { +public: + explicit ArmoniKTaskError(const std::string &message, const armonik::api::grpc::v1::TaskError &task_error) + : ArmoniKApiException(message) { + std::stringstream ss; + ss << "TaskId : " << task_error.task_id() << " Errors : "; + for (auto &&e : task_error.errors()) { + std::string status = armonik::api::grpc::v1::task_status::TaskStatus_Name(e.task_status()); + status_details.emplace_back(status, e.detail()); + ss << '\n' << status << " : " << e.detail(); + } + details = std::string(ArmoniKApiException::what()) + " : " + ss.str(); + taskId_ = task_error.task_id(); + } + [[nodiscard]] const char *what() const noexcept override { return details.c_str(); } + const std::string &taskId() { return taskId_; } + const std::vector> &error_details() { return status_details; } + +private: + std::string details; + std::string taskId_; + std::vector> status_details; +}; + +} // namespace exceptions +} // namespace common +} // namespace api +} // namespace armonik + +#endif // ARMONIK_API_ARMONIKTASKERROR_H diff --git a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskNotCompletedException.h b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskNotCompletedException.h index 9b33e129b..800a6ceeb 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskNotCompletedException.h +++ b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskNotCompletedException.h @@ -1,21 +1,21 @@ -#ifndef ARMONIK_API_ARMONIKTASKNOTCOMPLETEDEXCEPTION_H -#define ARMONIK_API_ARMONIKTASKNOTCOMPLETEDEXCEPTION_H - -#include "ArmoniKApiException.h" -namespace armonik { -namespace api { -namespace common { -namespace exceptions { - -class ArmoniKTaskNotCompletedException : public ArmoniKApiException { -public: - explicit ArmoniKTaskNotCompletedException(const std::string &taskId, const std::string &message = "") - : ArmoniKApiException("Task " + taskId + " not completed. " + message), taskId(taskId) {} - const std::string taskId; -}; -} // namespace exceptions -} // namespace common -} // namespace api -} // namespace armonik - -#endif // ARMONIK_API_ARMONIKTASKNOTCOMPLETEDEXCEPTION_H +#ifndef ARMONIK_API_ARMONIKTASKNOTCOMPLETEDEXCEPTION_H +#define ARMONIK_API_ARMONIKTASKNOTCOMPLETEDEXCEPTION_H + +#include "ArmoniKApiException.h" +namespace armonik { +namespace api { +namespace common { +namespace exceptions { + +class ArmoniKTaskNotCompletedException : public ArmoniKApiException { +public: + explicit ArmoniKTaskNotCompletedException(const std::string &taskId, const std::string &message = "") + : ArmoniKApiException("Task " + taskId + " not completed. " + message), taskId(taskId) {} + const std::string taskId; +}; +} // namespace exceptions +} // namespace common +} // namespace api +} // namespace armonik + +#endif // ARMONIK_API_ARMONIKTASKNOTCOMPLETEDEXCEPTION_H diff --git a/packages/cpp/ArmoniK.Api.Worker/source/Worker/TaskHandler.cpp b/packages/cpp/ArmoniK.Api.Worker/source/Worker/TaskHandler.cpp index aa888b3c6..8b2820d92 100644 --- a/packages/cpp/ArmoniK.Api.Worker/source/Worker/TaskHandler.cpp +++ b/packages/cpp/ArmoniK.Api.Worker/source/Worker/TaskHandler.cpp @@ -55,7 +55,7 @@ void armonik::api::worker::TaskHandler::init() { config_ = std::move(*init_request->mutable_configuration()); auto *datachunk = &init_request->payload(); - payload_.clear(); + assert(payload_.empty()); payload_.append(datachunk->data()); while (!datachunk->data_complete()) {