diff --git a/packages/cpp/ArmoniK.Api.Client/CMakeLists.txt b/packages/cpp/ArmoniK.Api.Client/CMakeLists.txt index 109efdbd7..cc602013b 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}) @@ -73,11 +76,10 @@ 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}) -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..93b07631d 100644 --- a/packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h +++ b/packages/cpp/ArmoniK.Api.Client/header/submitter/ResultsClient.h @@ -1,20 +1,25 @@ -#ifndef ARMONIK_API_RESULTSCLIENT_H -#define ARMONIK_API_RESULTSCLIENT_H - -#include - -namespace API_CLIENT_NAMESPACE { -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); - -private: - std::unique_ptr stub; -}; -} // namespace API_CLIENT_NAMESPACE - -#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 adc98c484..9eefa6857 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 API_CLIENT_NAMESPACE { +namespace armonik { +namespace api { +namespace client { /** * @brief Data structure for task payload @@ -30,7 +32,6 @@ struct payload_data { */ class SubmitterClient { private: - grpc::ClientContext context_; std::unique_ptr stub_; public: @@ -89,10 +90,9 @@ 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); + const std::vector &payloads_with_dependencies, int max_retries); /** * @brief Get result without streaming. @@ -105,4 +105,6 @@ 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 client +} // namespace api +} // 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 6efe6847e..ad354fdd2 100644 --- a/packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp +++ b/packages/cpp/ArmoniK.Api.Client/source/submitter/ResultsClient.cpp @@ -1,84 +1,86 @@ -#include "submitter/ResultsClient.h" -#include "exceptions/ArmoniKApiException.h" -#include - -namespace API_CLIENT_NAMESPACE { - -std::map ResultsClient::create_results(std::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() = session_id; - - // 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, - std::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); - - *request.mutable_data_chunk() = payload.substr(offset, chunkSize); - 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 API_CLIENT_NAMESPACE \ 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.Client/source/submitter/SubmitterClient.cpp b/packages/cpp/ArmoniK.Api.Client/source/submitter/SubmitterClient.cpp index e0b21230f..f88900b06 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; @@ -83,7 +83,7 @@ API_CLIENT_NAMESPACE::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) { @@ -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 { @@ -200,7 +200,7 @@ API_CLIENT_NAMESPACE::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,8 +237,8 @@ API_CLIENT_NAMESPACE::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> -API_CLIENT_NAMESPACE::SubmitterClient::submit_tasks_with_dependencies( +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) { std::vector task_ids; @@ -281,7 +281,7 @@ API_CLIENT_NAMESPACE::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)); } /** @@ -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; @@ -300,43 +300,41 @@ std::future API_CLIENT_NAMESPACE::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: 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 +343,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 d6f0b8d04..b57c565c0 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,9 +26,12 @@ 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) @@ -37,7 +39,8 @@ include(FetchContent) 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) @@ -47,7 +50,8 @@ 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) @@ -55,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") @@ -68,7 +70,8 @@ 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) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14) 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..d26fe9a3d 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKApiException.h +++ b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKApiException.h @@ -1,13 +1,19 @@ -#ifndef ARMONIK_API_ARMONIKAPIEXCEPTION_H -#define ARMONIK_API_ARMONIKAPIEXCEPTION_H - -#include -namespace API_COMMON_NAMESPACE::exceptions { - -class ArmoniKApiException : public std::runtime_error { -public: - explicit ArmoniKApiException(const std::string &message) : runtime_error(message) {} -}; -} // namespace API_COMMON_NAMESPACE::exceptions - -#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 b22b80b92..5118cf15f 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskError.h +++ b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskError.h @@ -1,36 +1,42 @@ -#ifndef ARMONIK_API_ARMONIKTASKERROR_H -#define ARMONIK_API_ARMONIKTASKERROR_H - -#include "ArmoniKApiException.h" -#include -#include -#include -namespace API_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 API_COMMON_NAMESPACE::exceptions - -#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 67bf2927e..800a6ceeb 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskNotCompletedException.h +++ b/packages/cpp/ArmoniK.Api.Common/header/exceptions/ArmoniKTaskNotCompletedException.h @@ -1,15 +1,21 @@ -#ifndef ARMONIK_API_ARMONIKTASKNOTCOMPLETEDEXCEPTION_H -#define ARMONIK_API_ARMONIKTASKNOTCOMPLETEDEXCEPTION_H - -#include "ArmoniKApiException.h" -namespace API_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 API_COMMON_NAMESPACE::exceptions - -#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.Common/header/logger/base.h b/packages/cpp/ArmoniK.Api.Common/header/logger/base.h index 0694e7f09..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 da0dddf7e..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 7d5e04a0e..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 4ee0de957..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 f060d83f0..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 d4243fed7..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 572037e34..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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..a2c706991 --- /dev/null +++ b/packages/cpp/ArmoniK.Api.Common/header/logger/util.h @@ -0,0 +1,6 @@ +#pragma once + +#include +#include + +fmt::string_view to_fmt(const absl::string_view sv) { return {sv.data(), sv.size()}; } diff --git a/packages/cpp/ArmoniK.Api.Common/header/logger/writer.h b/packages/cpp/ArmoniK.Api.Common/header/logger/writer.h index 8666c9d92..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 90eb2a512..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 2bf455949..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::options +} // namespace options +} // namespace common +} // namespace api +} // namespace armonik #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..0e5bb04eb 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/options/GrpcSocketType.h +++ b/packages/cpp/ArmoniK.Api.Common/header/options/GrpcSocketType.h @@ -1,10 +1,13 @@ #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 { +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 API_COMMON_NAMESPACE::options +} // namespace options +} // namespace common +} // namespace api +} // namespace armonik diff --git a/packages/cpp/ArmoniK.Api.Common/header/utils/Configuration.h b/packages/cpp/ArmoniK.Api.Common/header/utils/Configuration.h index efb60b715..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 API_COMMON_NAMESPACE::options { +namespace armonik { +namespace api { +namespace common { +namespace options { class ComputePlane; class ControlPlane; -} // namespace API_COMMON_NAMESPACE::options +} // namespace options -namespace API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::utils +} // namespace utils +} // 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 496bfe853..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 d8c8bac30..f4abb4ee4 100644 --- a/packages/cpp/ArmoniK.Api.Common/header/utils/GuuId.h +++ b/packages/cpp/ArmoniK.Api.Common/header/utils/GuuId.h @@ -10,9 +10,12 @@ #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 { +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 API_COMMON_NAMESPACE::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 2a4c8b238..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 7af918d73..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 316405217..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 090ce7ace..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 9236c9183..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 5ac8cdbfd..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 API_COMMON_NAMESPACE::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 API_COMMON_NAMESPACE::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 a639be866..1ae866931 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,8 +33,8 @@ void populate(API_COMMON_NAMESPACE::utils::Configuration &config, const std::str } } -void API_COMMON_NAMESPACE::utils::JsonConfiguration::fromPath(API_COMMON_NAMESPACE::utils::Configuration &config, - std::string_view filepath) { +void armonik::api::common::utils::JsonConfiguration::fromPath(armonik::api::common::utils::Configuration &config, + absl::string_view filepath) { dom::parser parser; dom::element elem; try { @@ -44,8 +44,8 @@ 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, - std::string_view json_string) { +void armonik::api::common::utils::JsonConfiguration::fromString(armonik::api::common::utils::Configuration &config, + 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 bdf0fa933..931ea3406 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) @@ -16,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) @@ -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 "$" @@ -48,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/ArmoniK.Api.Tests/source/SubmitterClientTest.cpp b/packages/cpp/ArmoniK.Api.Tests/source/SubmitterClientTest.cpp index e0ea56ff6..4391d1575 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,43 +141,42 @@ 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; - for (auto &&[k, v] : result_mapping) { - names[j++] = v; + for (auto &&kv : result_mapping) { + names[j++] = kv.second; } 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 = {}; 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()); @@ -207,24 +206,24 @@ 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 = {}; 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]]; @@ -261,14 +260,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..af46aa18a 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,18 +12,14 @@ 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) +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}/") 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..9f0821f53 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,11 +13,6 @@ 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) -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") @@ -30,9 +24,16 @@ file(MAKE_DIRECTORY ${PROJECT_BUILD_DIR}/proto) add_library(${PROJECT_NAME} ${PROTO_GENERATED_FILES} ${SRC_CLIENT_FILES} ${HEADER_CLIENT_FILES}) -target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf gRPC::grpc++_unsecure ArmoniK.Api.Common ${PROTO_TARGET}) +# 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_compile_definitions(${PROJECT_NAME} PUBLIC API_WORKER_NAMESPACE=${NAMESPACE}) +target_link_libraries(${PROJECT_NAME} PUBLIC protobuf::libprotobuf gRPC::grpc++_unsecure ArmoniK.Api.Common ${PROTO_TARGET}) target_include_directories(${PROJECT_NAME} PUBLIC @@ -86,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 98fdde775..ff06921bd 100644 --- a/packages/cpp/ArmoniK.Api.Worker/header/Worker/ArmoniKWorker.h +++ b/packages/cpp/ArmoniK.Api.Worker/header/Worker/ArmoniKWorker.h @@ -16,11 +16,13 @@ #include "ProcessStatus.h" #include "Worker/TaskHandler.h" -namespace API_WORKER_NAMESPACE { +namespace armonik { +namespace api { +namespace 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 +40,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 +61,11 @@ 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 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 4b2536499..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 API_WORKER_NAMESPACE { +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 API_WORKER_NAMESPACE +} // 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 1f799286a..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 API_WORKER_NAMESPACE { +namespace armonik { +namespace api { +namespace worker { // #include "SessionContext.h" @@ -19,9 +21,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 +40,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 @@ -88,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 @@ -147,4 +148,6 @@ class TaskHandler { const armonik::api::grpc::v1::Configuration &getConfiguration() const; }; -} // namespace API_WORKER_NAMESPACE +} // 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 fce57027a..3ca818957 100644 --- a/packages/cpp/ArmoniK.Api.Worker/header/utils/WorkerServer.h +++ b/packages/cpp/ArmoniK.Api.Worker/header/utils/WorkerServer.h @@ -25,14 +25,16 @@ using namespace armonik::api::grpc::v1::agent; -namespace API_WORKER_NAMESPACE { +namespace armonik { +namespace api { +namespace 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 +46,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 +55,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 +75,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 +89,6 @@ class WorkerServer { instance_server->Wait(); } }; -} // namespace API_WORKER_NAMESPACE +} // namespace worker +} // namespace api +} // namespace armonik 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..8b2820d92 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,11 +54,9 @@ 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()); + assert(payload_.empty()); + payload_.append(datachunk->data()); while (!datachunk->data_complete()) { if (!request_iterator_.Read(&Request)) { @@ -71,9 +68,7 @@ void API_WORKER_NAMESPACE::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) { @@ -106,9 +101,7 @@ void API_WORKER_NAMESPACE::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) { @@ -129,7 +122,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,20 +202,20 @@ 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; *create_task_request.mutable_init_request() = std::move(create_task_request_init); create_task_request.set_communication_token(token); - return std::vector{std::move(create_task_request)}; + return std::vector{std::move(create_task_request)}; })); for (auto task_request = task_requests.begin(); task_request != task_requests.end(); ++task_request) { @@ -241,7 +234,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 +242,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 +254,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 +273,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, absl::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 +286,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,30 +295,28 @@ 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); - std::memcpy(chunk->mutable_data()->data(), data.data() + start, chunkSize); + msg.mutable_data()->mutable_data()->assign(data.data() + start, chunkSize); stream->Write(msg); 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 +328,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 +358,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 +388,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 +397,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 +406,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 9c7437ec0..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) @@ -31,17 +31,18 @@ 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) -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/Dependencies.cmake b/packages/cpp/Dependencies.cmake new file mode 100644 index 000000000..36e8eabed --- /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() diff --git a/packages/cpp/README.md b/packages/cpp/README.md new file mode 100644 index 000000000..333572380 --- /dev/null +++ b/packages/cpp/README.md @@ -0,0 +1,17 @@ +# ArmoniK Api Cpp + +## Build requirements +- cmake 3.22+ +- 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) +- 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/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"]