diff --git a/common/cpp/src/system_io/system_io_windows.cpp b/common/cpp/src/system_io/system_io_windows.cpp index 81272027b807eaa7d4ca82828cdcfdf1457d43ce..a8b90ee39ba2ef84c9587946abdcdf180e96f288 100644 --- a/common/cpp/src/system_io/system_io_windows.cpp +++ b/common/cpp/src/system_io/system_io_windows.cpp @@ -49,6 +49,8 @@ Error IOErrorFromGetLastError() { return IOErrorTemplates::kPermissionDenied.Generate(); case ERROR_CONNECTION_REFUSED: return IOErrorTemplates::kConnectionRefused.Generate(); + case WSAEADDRNOTAVAIL: + return IOErrorTemplates::kUnreachableNetwork.Generate(); case WSAEFAULT: return IOErrorTemplates::kInvalidMemoryAddress.Generate(); case WSAECONNRESET: diff --git a/deploy/docker/cluster/scripts/receiver.json.tpl b/deploy/docker/cluster/scripts/receiver.json.tpl index b1948f8b1e9d216887c26447220816a062a567da..6a9236bcf11d331d0ecb14b0595772a7ee3e39cb 100644 --- a/deploy/docker/cluster/scripts/receiver.json.tpl +++ b/deploy/docker/cluster/scripts/receiver.json.tpl @@ -1,4 +1,5 @@ { + "AdvertiseIP": "{{ env "NOMAD_IP_recv" }}", "PerformanceDbServer":"localhost:8400/influxdb", "PerformanceDbName": "asapo_receivers", "DatabaseServer":"auto", diff --git a/deploy/nomad_jobs/receiver.json.tpl b/deploy/nomad_jobs/receiver.json.tpl index 648f8b59fae7f8b41176b64b48023d0cbfe4a266..8db2c97b3a93093f52e6132e2da859bf9c79aaa9 100644 --- a/deploy/nomad_jobs/receiver.json.tpl +++ b/deploy/nomad_jobs/receiver.json.tpl @@ -1,4 +1,5 @@ { + "AdvertiseIP": "127.0.0.1", "PerformanceDbServer":"localhost:8400/influxdb", "PerformanceDbName": "asapo_receivers", "DatabaseServer":"auto", diff --git a/receiver/src/receiver_config.cpp b/receiver/src/receiver_config.cpp index ae55ea992df809839004dbc981d001d8a81c2681..8401555dfe9d798b6f8eb1611875a0a249553aa0 100644 --- a/receiver/src/receiver_config.cpp +++ b/receiver/src/receiver_config.cpp @@ -34,6 +34,7 @@ Error ReceiverConfigFactory::SetConfig(std::string file_name) { (err = parser.GetUInt64("AuthorizationInterval", &config.authorization_interval_ms)) || (err = parser.GetString("RootFolder", &config.root_folder)) || (err = parser.GetString("PerformanceDbName", &config.performance_db_name)) || + (err = parser.GetString("AdvertiseIP", &config.advertise_ip)) || (err = parser.GetString("LogLevel", &log_level)); if (err) { @@ -42,11 +43,6 @@ Error ReceiverConfigFactory::SetConfig(std::string file_name) { config.dataserver.tag = config.tag + "_ds"; - config.source_host = io__->GetHostName(&err); - if (err) { - return err; - } - config.log_level = StringToLogLevel(log_level, &err); return err; diff --git a/receiver/src/receiver_config.h b/receiver/src/receiver_config.h index 7052ac71e260a8f553366b6f4a22a3daab5c7539..831e7223262eb6bce5ac86329c0127bd3f98f6a4 100644 --- a/receiver/src/receiver_config.h +++ b/receiver/src/receiver_config.h @@ -23,7 +23,7 @@ struct ReceiverConfig { uint64_t datacache_reserved_share = 0; LogLevel log_level = LogLevel::Info; std::string tag; - std::string source_host; + std::string advertise_ip; ReceiverDataCenterConfig dataserver; std::string discovery_server; }; diff --git a/receiver/src/request_handler_db_write.cpp b/receiver/src/request_handler_db_write.cpp index 19670a85b3b8f48dc0451e92f9e8301c2f910e3a..91580bfae63e1f59d0cc9635b560da855351ee7b 100644 --- a/receiver/src/request_handler_db_write.cpp +++ b/receiver/src/request_handler_db_write.cpp @@ -56,7 +56,7 @@ FileInfo RequestHandlerDbWrite::PrepareFileInfo(const Request* request) const { file_info.size = request->GetDataSize(); file_info.id = request->GetDataID(); file_info.buf_id = request->GetSlotId(); - file_info.source = GetReceiverConfig()->source_host + ":" + string_format("%ld", + file_info.source = GetReceiverConfig()->advertise_ip + ":" + string_format("%ld", GetReceiverConfig()->dataserver.listen_port); file_info.metadata = request->GetMetaData(); return file_info; diff --git a/receiver/unittests/mock_receiver_config.cpp b/receiver/unittests/mock_receiver_config.cpp index 29805ebde5ef0de2d1d1aada86537fcbacb82a6d..1ddc3ed4c83dc520f874c93ea1d759a067556f85 100644 --- a/receiver/unittests/mock_receiver_config.cpp +++ b/receiver/unittests/mock_receiver_config.cpp @@ -61,6 +61,7 @@ Error SetReceiverConfig (const ReceiverConfig& config, std::string error_field) config_string += "," + Key("WriteToDisk", error_field) + (config.write_to_disk ? "true" : "false"); config_string += "," + Key("WriteToDb", error_field) + (config.write_to_db ? "true" : "false"); config_string += "," + Key("LogLevel", error_field) + "\"" + log_level + "\""; + config_string += "," + Key("AdvertiseIP", error_field) + "\"" + config.advertise_ip + "\""; config_string += "," + Key("Tag", error_field) + "\"" + config.tag + "\""; config_string += "," + Key("RootFolder", error_field) + "\"" + config.root_folder + "\""; config_string += "}"; @@ -70,20 +71,7 @@ Error SetReceiverConfig (const ReceiverConfig& config, std::string error_field) testing::Return(config_string) ); - if (error_field == "SourceHost") { - EXPECT_CALL(mock_io, GetHostName_t(_)). - WillOnce( - DoAll(SetArgPointee<0>(asapo::IOErrorTemplates::kUnknownIOError.Generate().release()), - Return("") - )); - } else if (error_field == "none") { - EXPECT_CALL(mock_io, GetHostName_t(_)). - WillOnce( - DoAll(SetArgPointee<0>(nullptr), - Return(config.source_host) - )); - } - + printf("%s\n", config_string.c_str()); auto err = config_factory.SetConfig("fname"); config_factory.io__.release(); diff --git a/receiver/unittests/test_config.cpp b/receiver/unittests/test_config.cpp index 6231fed9089ba3bfbe11804e1d3543aa6b7450a1..aca938cff1aae4909ce0dc7e873677d5c856db05 100644 --- a/receiver/unittests/test_config.cpp +++ b/receiver/unittests/test_config.cpp @@ -59,9 +59,10 @@ class ConfigTests : public Test { test_config.use_datacache = false; test_config.datacache_reserved_share = 10; test_config.datacache_size_gb = 2; - test_config.source_host = "host"; + test_config.advertise_ip = "host"; test_config.dataserver.nthreads = 5; test_config.discovery_server = "discovery"; + test_config.advertise_ip = "0.0.0.1"; } }; @@ -90,10 +91,11 @@ TEST_F(ConfigTests, ReadSettings) { ASSERT_THAT(config->use_datacache, Eq(false)); ASSERT_THAT(config->datacache_reserved_share, Eq(10)); ASSERT_THAT(config->datacache_size_gb, Eq(2)); - ASSERT_THAT(config->source_host, Eq("host")); ASSERT_THAT(config->dataserver.nthreads, Eq(5)); ASSERT_THAT(config->dataserver.tag, Eq("receiver1_ds")); ASSERT_THAT(config->discovery_server, Eq("discovery")); + ASSERT_THAT(config->advertise_ip, Eq("0.0.0.1")); + } @@ -103,7 +105,7 @@ TEST_F(ConfigTests, ErrorReadSettings) { std::vector<std::string>fields {"PerformanceDbServer", "ListenPort", "DataServer", "ListenPort", "WriteToDisk", "WriteToDb", "DataCache", "Use", "SizeGB", "ReservedShare", "DatabaseServer", "Tag", "AuthorizationServer", "AuthorizationInterval", "RootFolder", "PerformanceDbName", "LogLevel", - "SourceHost", "NThreads", "DiscoveryServer"}; + "NThreads", "DiscoveryServer", "AdvertiseIP"}; for (const auto& field : fields) { auto err = asapo::SetReceiverConfig(test_config, field); ASSERT_THAT(err, Ne(nullptr)); diff --git a/receiver/unittests/test_request_handler_db_writer.cpp b/receiver/unittests/test_request_handler_db_writer.cpp index 11047e9e98c819aee04be24e531d259fbb343f00..19c1ec322e678642ece25429416c87db5cb77dde 100644 --- a/receiver/unittests/test_request_handler_db_writer.cpp +++ b/receiver/unittests/test_request_handler_db_writer.cpp @@ -71,7 +71,7 @@ class DbWriterHandlerTests : public Test { std::string expected_beamtime_id = "beamtime_id"; std::string expected_default_stream = "detector"; std::string expected_stream = "stream"; - std::string expected_hostname = "host"; + std::string expected_host_ip = "127.0.0.1"; uint64_t expected_port = 1234; uint64_t expected_buf_id = 18446744073709551615ull; std::string expected_file_name = "2"; @@ -89,7 +89,7 @@ class DbWriterHandlerTests : public Test { handler.log__ = &mock_logger; mock_request.reset(new NiceMock<MockRequest> {request_header, 1, ""}); config.database_uri = "127.0.0.1:27017"; - config.source_host = expected_hostname; + config.advertise_ip = expected_host_ip; config.dataserver.listen_port = expected_port; SetReceiverConfig(config, "none"); @@ -173,7 +173,7 @@ FileInfo DbWriterHandlerTests::PrepareFileInfo() { file_info.name = expected_file_name; file_info.id = expected_id; file_info.buf_id = expected_buf_id; - file_info.source = expected_hostname + ":" + std::to_string(expected_port); + file_info.source = expected_host_ip + ":" + std::to_string(expected_port); file_info.metadata = expected_metadata; return file_info; } diff --git a/tests/automatic/settings/receiver.json.tpl.lin.in b/tests/automatic/settings/receiver.json.tpl.lin.in index 2f27019b74b1e721ecc52ea1a4b28c1c5e46e6a3..86fa61c0dbb173a77071e26568cb9913d5f8a4e1 100644 --- a/tests/automatic/settings/receiver.json.tpl.lin.in +++ b/tests/automatic/settings/receiver.json.tpl.lin.in @@ -1,4 +1,5 @@ { + "AdvertiseIP": "127.0.0.1", "PerformanceDbServer":"localhost:8086", "PerformanceDbName": "db_test", "DatabaseServer":"auto", diff --git a/tests/automatic/settings/receiver.json.tpl.win.in b/tests/automatic/settings/receiver.json.tpl.win.in index 7fcedb822a21daa57a82a0d3526bda85cbd26ca2..4cc81d11dafa9d9522dd01da192a3efa850a49c0 100644 --- a/tests/automatic/settings/receiver.json.tpl.win.in +++ b/tests/automatic/settings/receiver.json.tpl.win.in @@ -1,4 +1,5 @@ { + "AdvertiseIP": "127.0.0.1", "PerformanceDbServer":"localhost:8086", "PerformanceDbName": "db_test", "DatabaseServer":"auto", diff --git a/tests/manual/python_tests/producer/receiver.json.tpl b/tests/manual/python_tests/producer/receiver.json.tpl index 88be63ae321b4974c7c440f7f479dc7682acb806..0eaaa9848c36a37e666c5abadf9b856701581820 100644 --- a/tests/manual/python_tests/producer/receiver.json.tpl +++ b/tests/manual/python_tests/producer/receiver.json.tpl @@ -1,4 +1,5 @@ { + "AdvertiseIP": "127.0.0.1", "PerformanceDbServer":"localhost:8086", "PerformanceDbName": "db_test", "DatabaseServer":"localhost:27017",