diff --git a/CMakeLists.txt b/CMakeLists.txt index d4e6c35a31a5615fd037d2fa899c98fdbf564709..e50c24502162da1734ccc05caa5da3eae86716a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,11 @@ set (HIDRA2_CXX_COMMON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/common/cpp/includ find_package (Threads) +set (CMAKE_PREFIX_PATH "${LIBCURL_DIR}") +find_package (CURL REQUIRED) +message (STATUS "Found cURL libraries: ${CURL_LIBRARIES}") +message (STATUS "cURL include: ${CURL_INCLUDE_DIRS}") + # format sources include(astyle) diff --git a/common/cpp/CMakeLists.txt b/common/cpp/CMakeLists.txt index 2e79b345e35a1a91c74e90320c463f8f66b3800d..981bb1f4484a0033056be6f49ccdde39cf9796e1 100644 --- a/common/cpp/CMakeLists.txt +++ b/common/cpp/CMakeLists.txt @@ -6,6 +6,8 @@ add_subdirectory(src/json_parser) add_subdirectory(src/data_structs) +add_subdirectory(src/http_client) + if(BUILD_MONGODB_CLIENTLIB) add_subdirectory(src/database) endif() diff --git a/worker/api/cpp/src/curl_http_client.h b/common/cpp/include/http_client/curl_http_client.h similarity index 100% rename from worker/api/cpp/src/curl_http_client.h rename to common/cpp/include/http_client/curl_http_client.h diff --git a/worker/api/cpp/src/http_client.h b/common/cpp/include/http_client/http_client.h similarity index 96% rename from worker/api/cpp/src/http_client.h rename to common/cpp/include/http_client/http_client.h index 31b838a62924f70fe83aecd5e70b4654421671aa..ff4c1395b3db5c5b9edc070a0edf8c5e4b9c47f2 100644 --- a/worker/api/cpp/src/http_client.h +++ b/common/cpp/include/http_client/http_client.h @@ -1,7 +1,7 @@ #ifndef HIDRA2_HTTP_CLIENT_H #define HIDRA2_HTTP_CLIENT_H -#include <hidra2_worker.h> +#include "common/error.h" namespace hidra2 { @@ -14,8 +14,6 @@ class HttpClient { }; -Error HttpCodeToWorkerError(const HttpCode& code); - enum class HttpCode : int { Continue = 100, SwitchingProtocols = 101, diff --git a/worker/api/cpp/src/http_error.h b/common/cpp/include/http_client/http_error.h similarity index 100% rename from worker/api/cpp/src/http_error.h rename to common/cpp/include/http_client/http_error.h diff --git a/common/cpp/src/http_client/CMakeLists.txt b/common/cpp/src/http_client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b274c9319e20e484c12d9f22f8668fda3f6a39f9 --- /dev/null +++ b/common/cpp/src/http_client/CMakeLists.txt @@ -0,0 +1,16 @@ +set(TARGET_NAME curl_http_client) +set(SOURCE_FILES + curl_http_client.cpp + ) + + +################################ +# Library +################################ +add_library(${TARGET_NAME} OBJECT ${SOURCE_FILES}) +IF(WIN32) + target_compile_definitions(${TARGET_NAME} PUBLIC -DCURL_STATICLIB) +ENDIF() +target_include_directories(${TARGET_NAME} PUBLIC ${HIDRA2_CXX_COMMON_INCLUDE_DIR} ${CURL_INCLUDE_DIRS}) + + diff --git a/worker/api/cpp/src/curl_http_client.cpp b/common/cpp/src/http_client/curl_http_client.cpp similarity index 94% rename from worker/api/cpp/src/curl_http_client.cpp rename to common/cpp/src/http_client/curl_http_client.cpp index 364b87cd1975a90de5ec53cc3eefaeb8e126265c..fc9904e491b61b4c9f6a36e1ebb197fcf7db7f78 100644 --- a/worker/api/cpp/src/curl_http_client.cpp +++ b/common/cpp/src/http_client/curl_http_client.cpp @@ -1,4 +1,4 @@ -#include "curl_http_client.h" +#include "http_client/curl_http_client.h" #include <cstring> @@ -56,7 +56,7 @@ Error ProcessCurlResponse(CURL* curl, CURLcode res, const char* errbuf, return nullptr; } else { *buffer = GetCurlError(curl, res, errbuf); - return TextError(std::string(WorkerErrorMessage::kErrorReadingSource) + ": " + *buffer); + return TextError("Curl client error: " + *buffer); } } diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index 66e3f287721a6746fd92b16e408cc8070c89b8c2..371b917b0d85e82476392a4ca6ebfc4c79c4a131 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -13,19 +13,18 @@ set(SOURCE_FILES ################################ # Library ################################ -add_library(${TARGET_NAME} STATIC ${SOURCE_FILES} $<TARGET_OBJECTS:system_io>) + + +add_library(${TARGET_NAME} STATIC ${SOURCE_FILES} $<TARGET_OBJECTS:system_io> $<TARGET_OBJECTS:curl_http_client>) set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) -target_include_directories(${TARGET_NAME} PUBLIC ${HIDRA2_CXX_COMMON_INCLUDE_DIR}) +target_include_directories(${TARGET_NAME} PUBLIC ${HIDRA2_CXX_COMMON_INCLUDE_DIR} ${CURL_INCLUDE_DIRS}) +target_link_libraries(${TARGET_NAME} ${CURL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) + add_executable(${TARGET_NAME}-bin src/main.cpp) set_target_properties(${TARGET_NAME}-bin PROPERTIES OUTPUT_NAME ${TARGET_NAME}) target_link_libraries(${TARGET_NAME}-bin ${TARGET_NAME}) -#Add all necessary common libraries -GET_PROPERTY(HIDRA2_COMMON_IO_LIBRARIES GLOBAL PROPERTY HIDRA2_COMMON_IO_LIBRARIES) -target_link_libraries(${TARGET_NAME}-bin ${HIDRA2_COMMON_IO_LIBRARIES}) -set_target_properties(${TARGET_NAME}-bin PROPERTIES LINKER_LANGUAGE CXX) - ################################ # Testing ################################ @@ -38,6 +37,7 @@ set(TEST_SOURCE_FILES unittests/test_statistics.cpp unittests/test_request.cpp unittests/test_request_handler_file_write.cpp + unittests/test_statistics_sender_influx_db.cpp ) # set(TEST_LIBRARIES "${TARGET_NAME};system_io") diff --git a/receiver/src/statistics.cpp b/receiver/src/statistics.cpp index 5d1443963e88aecf6db9d8c66b6ef8658ecdd09c..ddb8c6b4e6fc6b6a2ddf97987577d10d4b79e228 100644 --- a/receiver/src/statistics.cpp +++ b/receiver/src/statistics.cpp @@ -18,15 +18,15 @@ StatisticsToSend Statistics::PrepareStatisticsToSend() const noexcept { stat.n_requests = nrequests_; stat.data_volume = volume_counter_; stat.elapsed_ms = GetTotalElapsedMs(); - for (auto i=0;i<kNStatisticEntities;i++){ - stat.entity_shares[i] = double(GetElapsedMs(StatisticEntity(i)))/stat.elapsed_ms; + for (auto i = 0; i < kNStatisticEntities; i++) { + stat.entity_shares[i] = double(GetElapsedMs(StatisticEntity(i))) / stat.elapsed_ms; } return stat; } uint64_t Statistics::GetTotalElapsedMs() const noexcept { return std::chrono::duration_cast<std::chrono::milliseconds> - ( high_resolution_clock::now() - last_timepoint_).count(); + ( high_resolution_clock::now() - last_timepoint_).count(); } uint64_t Statistics::GetElapsedMs(StatisticEntity entity) const noexcept { @@ -50,7 +50,8 @@ void Statistics::IncreaseRequestCounter() noexcept { nrequests_++; } -Statistics::Statistics(unsigned int write_frequency) : statistics_sender__{new StatisticsSenderInfluxDb},write_interval_{write_frequency}{ +Statistics::Statistics(unsigned int write_frequency) : statistics_sender__{new StatisticsSenderInfluxDb}, +write_interval_{write_frequency} { ResetStatistics(); } diff --git a/receiver/src/statistics.h b/receiver/src/statistics.h index 78efec123f5e4ceeac553d20f9b9f1bb1967797a..cd3cb2986a134df08460f7b9e3860356c664b125 100644 --- a/receiver/src/statistics.h +++ b/receiver/src/statistics.h @@ -16,10 +16,10 @@ enum StatisticEntity : int { }; struct StatisticsToSend { - double entity_shares[kNStatisticEntities]; - uint64_t elapsed_ms; - uint64_t data_volume; - uint64_t n_requests; + double entity_shares[kNStatisticEntities]; + uint64_t elapsed_ms; + uint64_t data_volume; + uint64_t n_requests; }; class Statistics { diff --git a/receiver/src/statistics_sender.h b/receiver/src/statistics_sender.h index a079f4f5b703fc3b3eb7b0df4e9aa7398525866d..2cf12b272a7b70bcfbaebadb493db5a47972cb29 100644 --- a/receiver/src/statistics_sender.h +++ b/receiver/src/statistics_sender.h @@ -8,7 +8,7 @@ namespace hidra2 { struct StatisticsToSend; class StatisticsSender { - public: + public: virtual void SendStatistics(const StatisticsToSend& statistic) const noexcept = 0; virtual ~StatisticsSender() = default; }; diff --git a/receiver/src/statistics_sender_influx_db.cpp b/receiver/src/statistics_sender_influx_db.cpp index bcdafda4f3fd5f964e40dcddafff8a54018377db..0ac7e8b41d7d4bfdfd9dbe4d628cf323d2010c66 100644 --- a/receiver/src/statistics_sender_influx_db.cpp +++ b/receiver/src/statistics_sender_influx_db.cpp @@ -1,5 +1,6 @@ #include "statistics_sender_influx_db.h" #include "statistics.h" +#include "http_client/curl_http_client.h" namespace hidra2 { @@ -7,5 +8,9 @@ void StatisticsSenderInfluxDb::SendStatistics(const StatisticsToSend& statistic) } +StatisticsSenderInfluxDb::StatisticsSenderInfluxDb(): httpclient__{new CurlHttpClient} { + +}; + } diff --git a/receiver/src/statistics_sender_influx_db.h b/receiver/src/statistics_sender_influx_db.h index 908bfeafcce40589bd67fd17569c36ed86c51ebf..e59954f463829f263c171b8664ed72763c911bdb 100644 --- a/receiver/src/statistics_sender_influx_db.h +++ b/receiver/src/statistics_sender_influx_db.h @@ -1,12 +1,17 @@ #ifndef HIDRA2_STATISTICS_SENDER_INFLUX_DB_H #define HIDRA2_STATISTICS_SENDER_INFLUX_DB_H +#include "http_client/http_client.h" #include "statistics_sender.h" + namespace hidra2 { -class StatisticsSenderInfluxDb : public StatisticsSender{ - virtual void SendStatistics(const StatisticsToSend& statistic) const noexcept override; +class StatisticsSenderInfluxDb : public StatisticsSender { + public: + StatisticsSenderInfluxDb(); + virtual void SendStatistics(const StatisticsToSend& statistic) const noexcept override; + std::unique_ptr<HttpClient> httpclient__; }; } diff --git a/receiver/unittests/mock_statistics.h b/receiver/unittests/mock_statistics.h index 1d7077fadb8a930b33e4808216cf1c5978278a6d..6c34db0e55a48e331b99ddd635a6cfd291b14c1f 100644 --- a/receiver/unittests/mock_statistics.h +++ b/receiver/unittests/mock_statistics.h @@ -9,30 +9,30 @@ namespace hidra2 { class MockStatistics : public hidra2::Statistics { - public: - void SendIfNeeded() noexcept override { - SendIfNeeded_t(); - } - void IncreaseRequestCounter() noexcept override { - IncreaseRequestCounter_t(); - } - void StartTimer(const hidra2::StatisticEntity &entity) noexcept override { - StartTimer_t(entity); - } - void IncreaseRequestDataVolume(uint64_t transferred_data_volume) noexcept override { - IncreaseRequestDataVolume_t(transferred_data_volume); - } - void StopTimer() noexcept override { - StopTimer_t(); - } - - MOCK_METHOD0(SendIfNeeded_t, void()); - MOCK_METHOD0(IncreaseRequestCounter_t, void()); - MOCK_METHOD0(StopTimer_t, void()); - MOCK_METHOD1(IncreaseRequestDataVolume_t, void (uint64_t - transferred_data_volume)); - MOCK_METHOD1(StartTimer_t, void( - const hidra2::StatisticEntity &entity)); + public: + void SendIfNeeded() noexcept override { + SendIfNeeded_t(); + } + void IncreaseRequestCounter() noexcept override { + IncreaseRequestCounter_t(); + } + void StartTimer(const hidra2::StatisticEntity& entity) noexcept override { + StartTimer_t(entity); + } + void IncreaseRequestDataVolume(uint64_t transferred_data_volume) noexcept override { + IncreaseRequestDataVolume_t(transferred_data_volume); + } + void StopTimer() noexcept override { + StopTimer_t(); + } + + MOCK_METHOD0(SendIfNeeded_t, void()); + MOCK_METHOD0(IncreaseRequestCounter_t, void()); + MOCK_METHOD0(StopTimer_t, void()); + MOCK_METHOD1(IncreaseRequestDataVolume_t, void (uint64_t + transferred_data_volume)); + MOCK_METHOD1(StartTimer_t, void( + const hidra2::StatisticEntity& entity)); }; diff --git a/receiver/unittests/test_request.cpp b/receiver/unittests/test_request.cpp index 278e149a553fea6191d408142f9af95bd23ec2b3..085e246023e2c4f0768777c8b3ec8dbcfe5b3864 100644 --- a/receiver/unittests/test_request.cpp +++ b/receiver/unittests/test_request.cpp @@ -45,7 +45,7 @@ class MockReqestHandler : public hidra2::RequestHandler { } StatisticEntity GetStatisticEntity() const { - return StatisticEntity::kDisk; + return StatisticEntity::kDisk; } MOCK_CONST_METHOD1(ProcessRequest_t, ErrorInterface * (const Request& request)); @@ -135,7 +135,7 @@ TEST_F(RequestTests, HandleProcessesRequests) { MockReqestHandler mock_request_handler; MockStatistics mock_statistics; - auto stat = std::unique_ptr<hidra2::Statistics>{&mock_statistics}; + auto stat = std::unique_ptr<hidra2::Statistics> {&mock_statistics}; EXPECT_CALL(mock_request_handler, ProcessRequest_t(_)).WillOnce( Return(nullptr) diff --git a/receiver/unittests/test_statistics.cpp b/receiver/unittests/test_statistics.cpp index c85f2eaf45e402dcccd3133191d3d6b9bb251fc7..5302896967a5574b4e4d02fbf129e44569603935 100644 --- a/receiver/unittests/test_statistics.cpp +++ b/receiver/unittests/test_statistics.cpp @@ -32,25 +32,25 @@ TEST(StatisticTestsConstructor, Constructor) { class MockStatisticsSender: public StatisticsSender { - public: - void SendStatistics(const StatisticsToSend& statistics) const noexcept override { - SendStatistics_t(statistics); - } - MOCK_CONST_METHOD1(SendStatistics_t, void (const StatisticsToSend&)); + public: + void SendStatistics(const StatisticsToSend& statistics) const noexcept override { + SendStatistics_t(statistics); + } + MOCK_CONST_METHOD1(SendStatistics_t, void (const StatisticsToSend&)); }; class StatisticTests : public Test { - public: - Statistics statistics{0}; - void TestTimer(const StatisticEntity& entity); - MockStatisticsSender mock_statistics_sender; - void SetUp() override { - statistics.statistics_sender__.reset(&mock_statistics_sender); - } - void TearDown() override { - statistics.statistics_sender__.release(); - } - StatisticsToSend ExtractStat(); + public: + Statistics statistics{0}; + void TestTimer(const StatisticEntity& entity); + MockStatisticsSender mock_statistics_sender; + void SetUp() override { + statistics.statistics_sender__.reset(&mock_statistics_sender); + } + void TearDown() override { + statistics.statistics_sender__.release(); + } + StatisticsToSend ExtractStat(); }; @@ -59,7 +59,7 @@ ACTION_P(SaveArg1ToSendStat, value) { value->n_requests = resp.n_requests; value->data_volume = resp.data_volume; value->elapsed_ms = resp.elapsed_ms; - for (int i=0;i<hidra2::kNStatisticEntities;i++){ + for (int i = 0; i < hidra2::kNStatisticEntities; i++) { value->entity_shares[i] = resp.entity_shares[i]; } @@ -72,12 +72,12 @@ StatisticsToSend StatisticTests::ExtractStat() { stat.elapsed_ms = 0; stat.n_requests = 0; stat.data_volume = 0; - for (int i=0;i<hidra2::kNStatisticEntities;i++){ + for (int i = 0; i < hidra2::kNStatisticEntities; i++) { stat.entity_shares[i] = 0.0; } - EXPECT_CALL(mock_statistics_sender,SendStatistics_t(_)). - WillOnce(SaveArg1ToSendStat(&stat)); + EXPECT_CALL(mock_statistics_sender, SendStatistics_t(_)). + WillOnce(SaveArg1ToSendStat(&stat)); statistics.SendIfNeeded(); return stat; @@ -130,7 +130,7 @@ TEST_F(StatisticTests, DataVolumeZeroAtInit) { ASSERT_THAT(stat.data_volume, Eq(0)); } -void StatisticTests::TestTimer(const StatisticEntity& entity){ +void StatisticTests::TestTimer(const StatisticEntity& entity) { statistics.StartTimer(entity); std::this_thread::sleep_for(std::chrono::milliseconds(10)); @@ -158,7 +158,7 @@ TEST_F(StatisticTests, TimerForDisk) { TEST_F(StatisticTests, SendStaticsDoesCallsSender) { statistics.SetWriteInterval(1000); - EXPECT_CALL(mock_statistics_sender,SendStatistics_t(_)).Times(0); + EXPECT_CALL(mock_statistics_sender, SendStatistics_t(_)).Times(0); statistics.SendIfNeeded(); } diff --git a/receiver/unittests/test_statistics_sender_influx_db.cpp b/receiver/unittests/test_statistics_sender_influx_db.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6690e981e8be35939e59667dce076f731c7761b0 --- /dev/null +++ b/receiver/unittests/test_statistics_sender_influx_db.cpp @@ -0,0 +1,36 @@ +#include <gtest/gtest.h> +#include <gmock/gmock.h> +#include <unittests/MockIO.h> + +#include "../src/statistics_sender_influx_db.h" +#include "../src/statistics_sender.h" +#include "http_client/curl_http_client.h" + +using ::testing::Test; +using ::testing::Return; +using ::testing::_; +using ::testing::DoAll; +using ::testing::SetArgReferee; +using ::testing::Gt; +using ::testing::Eq; +using ::testing::Ne; +using ::testing::Mock; +using ::testing::NiceMock; +using ::testing::SaveArg; +using ::testing::SaveArgPointee; +using ::testing::InSequence; +using ::testing::SetArgPointee; + +using hidra2::StatisticsSenderInfluxDb; + + +namespace { + +TEST(SenderInfluxDb, Constructor) { + StatisticsSenderInfluxDb sender; + ASSERT_THAT(dynamic_cast<hidra2::CurlHttpClient*>(sender.httpclient__.get()), Ne(nullptr)); +} + + + +} diff --git a/tests/automatic/CMakeLists.txt b/tests/automatic/CMakeLists.txt index 1c613b8555c478cc08aacf1db994443192bbe1b5..b0a661944ef8fd479b8d5aa8d4b4c69139995420 100644 --- a/tests/automatic/CMakeLists.txt +++ b/tests/automatic/CMakeLists.txt @@ -18,5 +18,6 @@ endif() add_subdirectory(worker) +add_subdirectory(curl_http_client) add_subdirectory(producer_receiver) \ No newline at end of file diff --git a/tests/automatic/curl_http_client/CMakeLists.txt b/tests/automatic/curl_http_client/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c375a144de531be429b0e85e3e3689115a826c33 --- /dev/null +++ b/tests/automatic/curl_http_client/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(curl_http_client_get) diff --git a/tests/automatic/worker/curl_http_client_get/CMakeLists.txt b/tests/automatic/curl_http_client/curl_http_client_get/CMakeLists.txt similarity index 100% rename from tests/automatic/worker/curl_http_client_get/CMakeLists.txt rename to tests/automatic/curl_http_client/curl_http_client_get/CMakeLists.txt diff --git a/tests/automatic/worker/curl_http_client_get/curl_httpclient_get.cpp b/tests/automatic/curl_http_client/curl_http_client_get/curl_httpclient_get.cpp similarity index 100% rename from tests/automatic/worker/curl_http_client_get/curl_httpclient_get.cpp rename to tests/automatic/curl_http_client/curl_http_client_get/curl_httpclient_get.cpp diff --git a/tests/automatic/worker/CMakeLists.txt b/tests/automatic/worker/CMakeLists.txt index e5145961a17f9444a92f8f471c1cc5380c7f6363..f8a2dd31597411f2a2297fc6436cce592cfbd8e9 100644 --- a/tests/automatic/worker/CMakeLists.txt +++ b/tests/automatic/worker/CMakeLists.txt @@ -4,8 +4,6 @@ add_subdirectory(next_multithread_folder) add_subdirectory(next_multithread_broker) add_subdirectory(connect_multithread) -add_subdirectory(curl_http_client_get) - if(BUILD_WORKER_TOOLS) add_subdirectory(folder_to_db) endif() diff --git a/tests/automatic/worker/connect_multithread/CMakeLists.txt b/tests/automatic/worker/connect_multithread/CMakeLists.txt index abe83367dc6b2796d7ca4d734b6ed4d37b8ed167..64224018bc011daf620bca4a96fcc5730004d9b4 100644 --- a/tests/automatic/worker/connect_multithread/CMakeLists.txt +++ b/tests/automatic/worker/connect_multithread/CMakeLists.txt @@ -7,7 +7,6 @@ set(SOURCE_FILES content_multithread.cpp) ################################ add_executable(${TARGET_NAME} ${SOURCE_FILES}) target_link_libraries(${TARGET_NAME} test_common hidra2-worker ${HIDRA2_COMMON_IO_LIBRARIES}) -set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) if (CMAKE_COMPILER_IS_GNUCXX) set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS_DEBUG "--coverage") endif() diff --git a/tests/automatic/worker/next_multithread_broker/CMakeLists.txt b/tests/automatic/worker/next_multithread_broker/CMakeLists.txt index 15b5b8ebbb6d39d62eaa820e6e84b031a95a6f81..9c22693a5cbb40f0778ce0ff145ef428fc3e1d8f 100644 --- a/tests/automatic/worker/next_multithread_broker/CMakeLists.txt +++ b/tests/automatic/worker/next_multithread_broker/CMakeLists.txt @@ -6,7 +6,7 @@ set(SOURCE_FILES next_multithread_broker.cpp) # Executable and link ################################ add_executable(${TARGET_NAME} ${SOURCE_FILES}) -target_link_libraries(${TARGET_NAME} test_common hidra2-worker ${CMAKE_THREAD_LIBS_INIT}) +target_link_libraries(${TARGET_NAME} test_common hidra2-worker) ################################ # Testing diff --git a/tests/automatic/worker/next_multithread_folder/CMakeLists.txt b/tests/automatic/worker/next_multithread_folder/CMakeLists.txt index eed3cc9b92840d9f2fe0aebda644df863acb553a..b0920c971f868faacd93ed7fbd60e630651f87c4 100644 --- a/tests/automatic/worker/next_multithread_folder/CMakeLists.txt +++ b/tests/automatic/worker/next_multithread_folder/CMakeLists.txt @@ -12,7 +12,6 @@ GET_PROPERTY(HIDRA2_COMMON_IO_LIBRARIES GLOBAL PROPERTY HIDRA2_COMMON_IO_LIBRARI target_link_libraries(${TARGET_NAME} ${HIDRA2_COMMON_IO_LIBRARIES}) target_link_libraries(${TARGET_NAME} test_common hidra2-worker) -set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE CXX) if (CMAKE_COMPILER_IS_GNUCXX) set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS_DEBUG "--coverage") endif() diff --git a/worker/api/cpp/CMakeLists.txt b/worker/api/cpp/CMakeLists.txt index 914d87840dff2058631c83a683401fb10bf9f959..f60a3268647407b76e3c858f0baaa73ec59df718 100644 --- a/worker/api/cpp/CMakeLists.txt +++ b/worker/api/cpp/CMakeLists.txt @@ -2,33 +2,23 @@ set(TARGET_NAME hidra2-worker) set(SOURCE_FILES src/data_broker.cpp - src/http_client.cpp src/folder_data_broker.cpp src/server_data_broker.cpp - src/curl_http_client.cpp - src/http_error.cpp) +) ################################ # Library ################################ add_library(${TARGET_NAME} STATIC ${SOURCE_FILES} $<TARGET_OBJECTS:system_io> - $<TARGET_OBJECTS:json_parser> $<TARGET_OBJECTS:data_structs> ) - -set (CMAKE_PREFIX_PATH "${LIBCURL_DIR}") -find_package (CURL REQUIRED) -message (STATUS "Found cURL libraries: ${CURL_LIBRARIES}") -message (STATUS "cURL include: ${CURL_INCLUDE_DIRS}") - + $<TARGET_OBJECTS:json_parser> $<TARGET_OBJECTS:data_structs> $<TARGET_OBJECTS:curl_http_client> ) target_include_directories(${TARGET_NAME} PUBLIC include ${HIDRA2_CXX_COMMON_INCLUDE_DIR} ${CURL_INCLUDE_DIRS}) -IF(WIN32) - target_compile_definitions(${TARGET_NAME} PUBLIC -DCURL_STATICLIB) -ELSEIF(CMAKE_C_COMPILER_ID STREQUAL "GNU") +IF(CMAKE_C_COMPILER_ID STREQUAL "GNU") SET( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") -ENDIF(WIN32) +ENDIF() target_link_libraries(${TARGET_NAME} ${CURL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) diff --git a/worker/api/cpp/src/http_client.cpp b/worker/api/cpp/src/http_client.cpp deleted file mode 100644 index d5c86c6c07343e163714d36a2b22053138bec407..0000000000000000000000000000000000000000 --- a/worker/api/cpp/src/http_client.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "http_client.h" -#include "http_error.h" -namespace hidra2 { - -Error HttpCodeToWorkerError(const HttpCode& code) { - const char* message; - switch (code) { - case HttpCode::OK: - return nullptr; - case HttpCode::BadRequest: - message = WorkerErrorMessage::kWrongInput; - break; - case HttpCode::InternalServerError: - message = WorkerErrorMessage::kErrorReadingSource; - break; - case HttpCode::NoContent: - message = WorkerErrorMessage::kNoData; - return TextErrorWithType(message, ErrorType::kEndOfFile); - case HttpCode::NotFound: - message = WorkerErrorMessage::kSourceNotFound; - break; - default: - message = WorkerErrorMessage::kErrorReadingSource; - break; - } - return Error{new HttpError(message, code)}; -} - -} diff --git a/worker/api/cpp/src/http_error.cpp b/worker/api/cpp/src/http_error.cpp deleted file mode 100644 index 72189fc37a93b34175987bac04642cc283b570c3..0000000000000000000000000000000000000000 --- a/worker/api/cpp/src/http_error.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "http_error.h" - -namespace hidra2 { - - - -} \ No newline at end of file diff --git a/worker/api/cpp/src/server_data_broker.cpp b/worker/api/cpp/src/server_data_broker.cpp index 0298c82db4d538a0c0202ff7efb82fa10b16752a..0b739e6e7d720e713c91a8623ea9153d08f4678a 100644 --- a/worker/api/cpp/src/server_data_broker.cpp +++ b/worker/api/cpp/src/server_data_broker.cpp @@ -1,9 +1,37 @@ #include "server_data_broker.h" #include "io/io_factory.h" -#include "curl_http_client.h" +#include "http_client/curl_http_client.h" +#include "http_client/http_error.h" + namespace hidra2 { +Error HttpCodeToWorkerError(const HttpCode& code) { + const char* message; + switch (code) { + case HttpCode::OK: + return nullptr; + case HttpCode::BadRequest: + message = WorkerErrorMessage::kWrongInput; + break; + case HttpCode::InternalServerError: + message = WorkerErrorMessage::kErrorReadingSource; + break; + case HttpCode::NoContent: + message = WorkerErrorMessage::kNoData; + return TextErrorWithType(message, ErrorType::kEndOfFile); + case HttpCode::NotFound: + message = WorkerErrorMessage::kSourceNotFound; + break; + default: + message = WorkerErrorMessage::kErrorReadingSource; + break; + } + return Error{new HttpError(message, code)}; +} + + + ServerDataBroker::ServerDataBroker(const std::string& server_uri, const std::string& source_name): io__{GenerateDefaultIO()}, httpclient__{new CurlHttpClient}, diff --git a/worker/api/cpp/src/server_data_broker.h b/worker/api/cpp/src/server_data_broker.h index 2081261b832c9884e8c762983f58c43adf91579e..5be1b4236e818fa303cde1829811219bc7e099d9 100644 --- a/worker/api/cpp/src/server_data_broker.h +++ b/worker/api/cpp/src/server_data_broker.h @@ -3,18 +3,20 @@ #include "worker/data_broker.h" #include "io/io.h" -#include "http_client.h" +#include "http_client/http_client.h" namespace hidra2 { +Error HttpCodeToWorkerError(const HttpCode& code); + class ServerDataBroker final : public hidra2::DataBroker { public: explicit ServerDataBroker(const std::string& server_uri, const std::string& source_name); Error Connect() override; Error GetNext(FileInfo* info, FileData* data) override; - std::unique_ptr<hidra2::IO> io__; // modified in testings to mock system calls,otherwise do not touch - std::unique_ptr<hidra2::HttpClient> httpclient__; + std::unique_ptr<IO> io__; // modified in testings to mock system calls,otherwise do not touch + std::unique_ptr<HttpClient> httpclient__; private: Error GetFileInfoFromServer(FileInfo* info, const std::string& operation); std::string server_uri_; diff --git a/worker/api/cpp/unittests/MockHttpClient.h b/worker/api/cpp/unittests/MockHttpClient.h index a386321db331ea9549646faff4fa4302c17e5434..ba445416229fcbc863dbb3f3041043926dbf7808 100644 --- a/worker/api/cpp/unittests/MockHttpClient.h +++ b/worker/api/cpp/unittests/MockHttpClient.h @@ -4,7 +4,7 @@ #include <gtest/gtest.h> #include <gmock/gmock.h> -#include "../src/http_client.h" +#include "http_client/http_client.h" #include "worker/data_broker.h" diff --git a/worker/api/cpp/unittests/test_server_broker.cpp b/worker/api/cpp/unittests/test_server_broker.cpp index 48296c46fdb53baa0cdca421aa692b6e22c34de8..d20858b5ea9de38112afd4ba7ae5794500b07d32 100644 --- a/worker/api/cpp/unittests/test_server_broker.cpp +++ b/worker/api/cpp/unittests/test_server_broker.cpp @@ -5,10 +5,10 @@ #include "io/io.h" #include "../../../../common/cpp/src/system_io/system_io.h" #include "../src/server_data_broker.h" -#include "../src/curl_http_client.h" +#include "http_client/curl_http_client.h" #include "unittests/MockIO.h" #include "MockHttpClient.h" -#include "../src/http_error.h" +#include "http_client/http_error.h" using hidra2::DataBrokerFactory; using hidra2::DataBroker;