diff options
Diffstat (limited to 'config')
-rw-r--r-- | config/CMakeLists.txt | 1 | ||||
-rw-r--r-- | config/src/vespa/config/CMakeLists.txt | 1 | ||||
-rw-r--r-- | config/src/vespa/config/file_acquirer/CMakeLists.txt | 6 | ||||
-rw-r--r-- | config/src/vespa/config/file_acquirer/file_acquirer.cpp | 42 | ||||
-rw-r--r-- | config/src/vespa/config/file_acquirer/file_acquirer.h | 33 |
5 files changed, 83 insertions, 0 deletions
diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index b6e0f7de178..c5bcb2f5806 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -18,6 +18,7 @@ vespa_define_module( src/vespa/config/common src/vespa/config/configgen src/vespa/config/file + src/vespa/config/file_acquirer src/vespa/config/frt src/vespa/config/helper src/vespa/config/print diff --git a/config/src/vespa/config/CMakeLists.txt b/config/src/vespa/config/CMakeLists.txt index 6781d09aef1..c90ab86e387 100644 --- a/config/src/vespa/config/CMakeLists.txt +++ b/config/src/vespa/config/CMakeLists.txt @@ -6,6 +6,7 @@ vespa_add_library(config_cloudconfig $<TARGET_OBJECTS:config_configgen> $<TARGET_OBJECTS:config_raw> $<TARGET_OBJECTS:config_file> + $<TARGET_OBJECTS:config_file_acquirer> $<TARGET_OBJECTS:config_frt> $<TARGET_OBJECTS:config_helper> $<TARGET_OBJECTS:config_print> diff --git a/config/src/vespa/config/file_acquirer/CMakeLists.txt b/config/src/vespa/config/file_acquirer/CMakeLists.txt new file mode 100644 index 00000000000..a41895bae28 --- /dev/null +++ b/config/src/vespa/config/file_acquirer/CMakeLists.txt @@ -0,0 +1,6 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_library(config_file_acquirer OBJECT + SOURCES + file_acquirer.cpp + DEPENDS +) diff --git a/config/src/vespa/config/file_acquirer/file_acquirer.cpp b/config/src/vespa/config/file_acquirer/file_acquirer.cpp new file mode 100644 index 00000000000..c6bf4066eec --- /dev/null +++ b/config/src/vespa/config/file_acquirer/file_acquirer.cpp @@ -0,0 +1,42 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include <vespa/fastos/fastos.h> +#include <vespa/log/log.h> +LOG_SETUP(".config.file_acquirer"); +#include "file_acquirer.h" + +namespace config { + +RpcFileAcquirer::RpcFileAcquirer(const vespalib::string &spec) + : _orb(), + _spec(spec) +{ + _orb.Start(); +} + +vespalib::string +RpcFileAcquirer::wait_for(const vespalib::string &file_ref, double timeout_s) +{ + vespalib::string path; + FRT_Target *target = _orb.GetTarget(_spec.c_str()); + FRT_RPCRequest *req = _orb.AllocRPCRequest(); + req->SetMethodName("waitFor"); + req->GetParams()->AddString(file_ref.data(), file_ref.size()); + target->InvokeSync(req, timeout_s); + if(req->CheckReturnTypes("s")) { + path = req->GetReturn()->GetValue(0)._string._str; + } else { + LOG(warning, "could not acquire file '%s' (%d: %s)", + file_ref.c_str(), req->GetErrorCode(), req->GetErrorMessage()); + } + req->SubRef(); + target->SubRef(); + return path; +} + +RpcFileAcquirer::~RpcFileAcquirer() +{ + _orb.ShutDown(true); +} + +} // namespace config diff --git a/config/src/vespa/config/file_acquirer/file_acquirer.h b/config/src/vespa/config/file_acquirer/file_acquirer.h new file mode 100644 index 00000000000..ff090c9e7c0 --- /dev/null +++ b/config/src/vespa/config/file_acquirer/file_acquirer.h @@ -0,0 +1,33 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include <vespa/vespalib/stllike/string.h> +#include <vespa/fnet/frt/frt.h> + +namespace config { + +/** + * Interface used to wait for the availability of files and map file + * references to concrete paths. + **/ +struct FileAcquirer { + virtual vespalib::string wait_for(const vespalib::string &file_ref, double timeout_s) = 0; + virtual ~FileAcquirer() {} +}; + +/** + * File acquirer implementation using rpc to talk to an external rpc + * server to wait for files to be ready. + **/ +class RpcFileAcquirer : public FileAcquirer +{ +private: + FRT_Supervisor _orb; + vespalib::string _spec; +public: + RpcFileAcquirer(const vespalib::string &spec); + vespalib::string wait_for(const vespalib::string &file_ref, double timeout_s) override; + ~RpcFileAcquirer(); +}; + +} // namespace config |