diff options
author | Arne H Juul <arnej27959@users.noreply.github.com> | 2016-08-26 11:19:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-26 11:19:58 +0200 |
commit | a063b43a39a6d7129a46c5ae138e22877a7e2b86 (patch) | |
tree | 1de769db1aba2bd47114d203b6378e817bf1dd16 /config | |
parent | db33333e69efdba1d90e6e3e3585a16db76341f2 (diff) | |
parent | cb47dcb04043330a577f88e112dcc2f2040316c8 (diff) |
Merge pull request #450 from yahoo/havardpe/cpp-file-acquirer
Havardpe/cpp file acquirer
Diffstat (limited to 'config')
-rw-r--r-- | config/CMakeLists.txt | 2 | ||||
-rw-r--r-- | config/src/tests/file_acquirer/.gitignore | 1 | ||||
-rw-r--r-- | config/src/tests/file_acquirer/CMakeLists.txt | 8 | ||||
-rw-r--r-- | config/src/tests/file_acquirer/file_acquirer_test.cpp | 44 | ||||
-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 |
8 files changed, 137 insertions, 0 deletions
diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index b6e0f7de178..49756f049ba 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 @@ -34,6 +35,7 @@ vespa_define_module( src/tests/configholder src/tests/unittest src/tests/frtconnectionpool + src/tests/file_acquirer src/tests/file_subscription src/tests/legacysubscriber src/tests/subscriber diff --git a/config/src/tests/file_acquirer/.gitignore b/config/src/tests/file_acquirer/.gitignore new file mode 100644 index 00000000000..45df7a8e0ab --- /dev/null +++ b/config/src/tests/file_acquirer/.gitignore @@ -0,0 +1 @@ +/config_file_acquirer_test_app diff --git a/config/src/tests/file_acquirer/CMakeLists.txt b/config/src/tests/file_acquirer/CMakeLists.txt new file mode 100644 index 00000000000..1b68d767df7 --- /dev/null +++ b/config/src/tests/file_acquirer/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(config_file_acquirer_test_app TEST + SOURCES + file_acquirer_test.cpp + DEPENDS + config_cloudconfig +) +vespa_add_test(NAME config_file_acquirer_test_app COMMAND config_file_acquirer_test_app) diff --git a/config/src/tests/file_acquirer/file_acquirer_test.cpp b/config/src/tests/file_acquirer/file_acquirer_test.cpp new file mode 100644 index 00000000000..028890a5f44 --- /dev/null +++ b/config/src/tests/file_acquirer/file_acquirer_test.cpp @@ -0,0 +1,44 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/vespalib/testkit/test_kit.h> +#include <vespa/config/file_acquirer/file_acquirer.h> +#include <vespa/fnet/frt/frt.h> +#include <vespa/vespalib/util/stringfmt.h> + +using namespace config; + +struct ServerFixture : FRT_Invokable { + FRT_Supervisor orb; + vespalib::string spec; + void init_rpc() { + FRT_ReflectionBuilder rb(&orb); + rb.DefineMethod("waitFor", "s", "s", true, FRT_METHOD(ServerFixture::RPC_waitFor), this); + rb.MethodDesc("wait for and resolve file reference"); + rb.ParamDesc("file_ref", "file reference to wait for and resolve"); + rb.ReturnDesc("file_path", "actual path to the requested file"); + } + ServerFixture() : orb() { + init_rpc(); + orb.Listen(0); + spec = vespalib::make_string("tcp/localhost:%d", orb.GetListenPort()); + orb.Start(); + } + void RPC_waitFor(FRT_RPCRequest *req) { + FRT_Values ¶ms = *req->GetParams(); + FRT_Values &ret = *req->GetReturn(); + if (strcmp(params[0]._string._str, "my_ref") == 0) { + ret.AddString("my_path"); + } else { + req->SetError(FRTE_RPC_METHOD_FAILED, "invalid file reference"); + } + } + ~ServerFixture() { + orb.ShutDown(true); + } +}; + +TEST_FF("require that files can be acquired over rpc", ServerFixture(), RpcFileAcquirer(f1.spec)) { + EXPECT_EQUAL("my_path", f2.wait_for("my_ref", 60.0)); + EXPECT_EQUAL("", f2.wait_for("bogus_ref", 60.0)); +} + +TEST_MAIN() { TEST_RUN_ALL(); } 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 |