diff options
Diffstat (limited to 'configd/src/apps/sentinel/rpchooks.cpp')
-rw-r--r-- | configd/src/apps/sentinel/rpchooks.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/configd/src/apps/sentinel/rpchooks.cpp b/configd/src/apps/sentinel/rpchooks.cpp new file mode 100644 index 00000000000..6e271db3977 --- /dev/null +++ b/configd/src/apps/sentinel/rpchooks.cpp @@ -0,0 +1,64 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "rpchooks.h" +#include "cmdq.h" +#include <vespa/fnet/frt/frt.h> + +#include <vespa/log/log.h> +LOG_SETUP(".rpchooks"); + +namespace config::sentinel { + +RPCHooks::~RPCHooks() = default; + + +void +RPCHooks::initRPC(FRT_Supervisor *supervisor) +{ + FRT_ReflectionBuilder rb(supervisor); + + //------------------------------------------------------------------------- + rb.DefineMethod("sentinel.ls", "", "s", + FRT_METHOD(RPCHooks::rpc_listServices), this); + rb.MethodDesc("list services"); + rb.ReturnDesc("status", "Status for services"); + //------------------------------------------------------------------------- + rb.DefineMethod("sentinel.service.stop", "s", "", + FRT_METHOD(RPCHooks::rpc_stopService), this); + rb.MethodDesc("stop a service"); + //------------------------------------------------------------------------- + rb.DefineMethod("sentinel.service.start", "s", "", + FRT_METHOD(RPCHooks::rpc_startService), this); + rb.MethodDesc("stop a service"); + //------------------------------------------------------------------------- +} + +void +RPCHooks::rpc_listServices(FRT_RPCRequest *req) +{ + LOG(debug, "got listservices"); + req->Detach(); + _commands.enqueue(std::make_unique<Cmd>(req, Cmd::LIST)); +} + +void +RPCHooks::rpc_stopService(FRT_RPCRequest *req) +{ + FRT_Values &args = *req->GetParams(); + const char *srvNM = args[0]._string._str; + LOG(debug, "got stopservice '%s'", srvNM); + req->Detach(); + _commands.enqueue(std::make_unique<Cmd>(req, Cmd::STOP, srvNM)); +} + +void +RPCHooks::rpc_startService(FRT_RPCRequest *req) +{ + FRT_Values &args = *req->GetParams(); + const char *srvNM = args[0]._string._str; + LOG(debug, "got startservice '%s'", srvNM); + req->Detach(); + _commands.enqueue(std::make_unique<Cmd>(req, Cmd::START, srvNM)); +} + +} // namespace slobrok |