diff --git a/src/util/common.cc b/src/util/common.cc index f129c0c7f..ef45a86f0 100644 --- a/src/util/common.cc +++ b/src/util/common.cc @@ -33,8 +33,15 @@ // Third-party headers #include "boost/asio.hpp" +// LSST headers +#include "lsst/log/Log.h" + using namespace std; +namespace { +LOG_LOGGER _log = LOG_GET("lsst.qserv.util.common"); +} + namespace lsst::qserv::util { string get_current_host_fqdn(bool all) { @@ -73,4 +80,19 @@ string get_current_host_fqdn(bool all) { return fqdn; } +std::string getCurrentHostFqdnBlocking() { + while (true) { + try { + string result = util::get_current_host_fqdn(); + if (!result.empty()) { + return result; + } + LOGS(_log, LOG_LVL_ERROR, __func__ << " Empty response for the worker hosts's FQDN."); + } catch (std::runtime_error const& ex) { + LOGS(_log, LOG_LVL_ERROR, __func__ << " Failed to obtain worker hosts's FQDN, ex: " << ex.what()); + } + sleep(1); + } +} + } // namespace lsst::qserv::util diff --git a/src/util/common.h b/src/util/common.h index faf7e837a..6f94678a8 100644 --- a/src/util/common.h +++ b/src/util/common.h @@ -55,6 +55,12 @@ namespace lsst::qserv::util { */ std::string get_current_host_fqdn(bool all = false); +/** Call get_current_host_fqdn(false) repeatedly until a name is gathered. + * Log messages will be printed. + * It will block until successful. + */ +std::string getCurrentHostFqdnBlocking(); + template typename Map::mapped_type const& getFromMap(Map const& m, typename Map::key_type const& key, typename Map::mapped_type const& defValue) {