aboutsummaryrefslogtreecommitdiffstats
path: root/configd
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2021-05-27 13:52:08 +0000
committerArne Juul <arnej@verizonmedia.com>2021-05-27 13:52:08 +0000
commit95e353b52f1c8e34727d7bb385fcc5baf89f481f (patch)
treeaef97bc38a15eddaef04b4612e10c0aaeeea6755 /configd
parente6832404fb93af477d8f3829d7258827d6280a8a (diff)
use environment and bootstrap it before creating manager
Diffstat (limited to 'configd')
-rw-r--r--configd/src/apps/sentinel/manager.cpp66
-rw-r--r--configd/src/apps/sentinel/manager.h29
-rw-r--r--configd/src/apps/sentinel/sentinel.cpp13
3 files changed, 30 insertions, 78 deletions
diff --git a/configd/src/apps/sentinel/manager.cpp b/configd/src/apps/sentinel/manager.cpp
index bfd9a5e2bef..d1d06c6039a 100644
--- a/configd/src/apps/sentinel/manager.cpp
+++ b/configd/src/apps/sentinel/manager.cpp
@@ -15,36 +15,11 @@ LOG_SETUP(".manager");
namespace config::sentinel {
-void
-Manager::configure_port(int port)
-{
- if (port == 0) {
- port = 19098;
- const char *portString = getenv("VESPA_SENTINEL_PORT");
- if (portString) {
- port = strtoul(portString, nullptr, 10);
- }
- }
- if (port <= 0 || port > 65535) {
- throw vespalib::FatalException("Bad port " + std::to_string(port) + ", expected range [1, 65535]", VESPA_STRLOC);
- }
- if (port != _boundPort) {
- LOG(debug, "Config-sentinel accepts connections on port %d", port);
- _stateServer = std::make_unique<vespalib::StateServer>(
- port, _stateApi.myHealth, _startMetrics.producer, _stateApi.myComponents);
- _boundPort = port;
- }
-}
-
-Manager::Manager()
- : _subscriber(),
- _services(),
- _outputConnections(),
- _boundPort(0),
- _startMetrics(),
- _stateApi()
+Manager::Manager(Env &env)
+ : _env(env),
+ _services(),
+ _outputConnections()
{
- _startMetrics.startedTime = vespalib::steady_clock::now();
}
Manager::~Manager()
@@ -98,24 +73,13 @@ Manager::terminate()
}
void
-Manager::subscribe(const std::string & configId, std::chrono::milliseconds timeout)
-{
- _sentinelHandle = _subscriber.subscribe<SentinelConfig>(configId, timeout);
-}
-
-void
Manager::doConfigure()
{
- std::unique_ptr<SentinelConfig> cfg(_sentinelHandle->getConfig());
- const SentinelConfig& config(*cfg);
+ LOG_ASSERT(_env.configOwner().hasConfig());
+ const SentinelConfig& config(_env.configOwner().getConfig());
- if (config.port.telnet != _boundPort) {
- configure_port(config.port.telnet);
- }
-
- if (!_rpcServer || config.port.rpc != _rpcServer->getPort()) {
- _rpcServer = std::make_unique<RpcServer>(config.port.rpc, _cmdQ);
- }
+ _env.rpcPort(config.port.rpc);
+ _env.statePort(config.port.telnet);
LOG(debug, "Manager::configure() %d config elements, tenant(%s), application(%s), instance(%s)",
(int)config.service.size(), config.application.tenant.c_str(), config.application.name.c_str(),
@@ -126,7 +90,7 @@ Manager::doConfigure()
const vespalib::string name(serviceConfig.name);
auto found(_services.find(name));
if (found == _services.end()) {
- services[name] = std::make_unique<Service>(serviceConfig, config.application, _outputConnections, _startMetrics);
+ services[name] = std::make_unique<Service>(serviceConfig, config.application, _outputConnections, _env.metrics());
} else {
found->second->reconfigure(serviceConfig);
services[name] = std::move(found->second);
@@ -140,8 +104,7 @@ Manager::doConfigure()
_orphans[entry.first] = std::move(svc);
}
}
- vespalib::ComponentConfigProducer::Config current("sentinel", _subscriber.getGeneration(), "ok");
- _stateApi.myComponents.addConfig(current);
+ _env.notifyConfigUpdated();
}
@@ -149,15 +112,14 @@ int
Manager::doWork()
{
// Return true if there are any running services, false if not.
-
- if (_subscriber.nextGenerationNow()) {
+ if (_env.configOwner().checkForConfigUpdate()) {
doConfigure();
}
handleRestarts();
handleCommands();
handleOutputs();
handleChildDeaths();
- _startMetrics.maybeLog();
+ _env.metrics().maybeLog();
// Check for active services.
for (const auto & service : _services) {
@@ -244,7 +206,7 @@ void
Manager::handleCommands()
{
// handle RPC commands
- std::vector<Cmd::UP> got = _cmdQ.drain();
+ std::vector<Cmd::UP> got = _env.commandQueue().drain();
for (const Cmd::UP & cmd : got) {
handleCmd(*cmd);
}
@@ -355,7 +317,7 @@ Manager::handleCmd(const Cmd& cmd)
void
Manager::updateMetrics()
{
- _startMetrics.maybeLog();
+ _env.metrics().maybeLog();
}
}
diff --git a/configd/src/apps/sentinel/manager.h b/configd/src/apps/sentinel/manager.h
index e157d5e003d..dabe1590d20 100644
--- a/configd/src/apps/sentinel/manager.h
+++ b/configd/src/apps/sentinel/manager.h
@@ -1,11 +1,12 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
-#include "service.h"
-#include "metrics.h"
-#include "state-api.h"
#include "cmdq.h"
+#include "env.h"
+#include "metrics.h"
#include "rpcserver.h"
+#include "service.h"
+#include "state-api.h"
#include <vespa/config-sentinel.h>
#include <vespa/config/config.h>
#include <vespa/vespalib/net/state_server.h>
@@ -31,20 +32,13 @@ class Manager {
private:
typedef std::map<vespalib::string, Service::UP> ServiceMap;
- ConfigSubscriber _subscriber;
- ConfigHandle<SentinelConfig>::UP _sentinelHandle;
+ Env &_env;
ServiceMap _services;
ServiceMap _orphans;
std::list<OutputConnection *> _outputConnections;
- CommandQueue _cmdQ;
- std::unique_ptr<RpcServer> _rpcServer;
- int _boundPort;
- StartMetrics _startMetrics;
- StateApi _stateApi;
- std::unique_ptr<vespalib::StateServer> _stateServer;
- Manager(const Manager&);
- Manager& operator =(const Manager&);
+ Manager(const Manager&) = delete;
+ Manager& operator =(const Manager&) = delete;
Service *serviceByPid(pid_t pid);
Service *serviceByName(const vespalib::string & name);
@@ -54,19 +48,14 @@ private:
void handleChildDeaths();
void handleRestarts();
- static int listen(int port);
- void configure_port(int port);
-
void updateMetrics();
void terminateServices(bool catchable, bool printDebug = false);
- void doConfigure();
-
public:
- Manager();
+ Manager(Env &env);
virtual ~Manager();
- void subscribe(const std::string & configId, std::chrono::milliseconds timeout);
+ void doConfigure();
bool terminate();
int doWork();
void updateActiveFdset(fd_set *fds, int *maxNum);
diff --git a/configd/src/apps/sentinel/sentinel.cpp b/configd/src/apps/sentinel/sentinel.cpp
index 9d5a18d249f..53c9ae7fbc2 100644
--- a/configd/src/apps/sentinel/sentinel.cpp
+++ b/configd/src/apps/sentinel/sentinel.cpp
@@ -61,11 +61,10 @@ main(int argc, char **argv)
}
setlocale(LC_ALL, "C");
- sentinel::Manager handler;
-
+ sentinel::Env environment;
LOG(debug, "Reading configuration");
try {
- handler.subscribe(configId, CONFIG_TIMEOUT_MS);
+ environment.boot(configId);
} catch (ConfigTimeoutException & ex) {
LOG(warning, "Timeout getting config, please check your setup. Will exit and restart: %s", ex.getMessage().c_str());
EV_STOPPING("config-sentinel", ex.what());
@@ -80,11 +79,13 @@ main(int argc, char **argv)
return EXIT_FAILURE;
}
+ sentinel::Manager manager(environment);
+ manager.doConfigure();
vespalib::steady_time lastTime = vespalib::steady_clock::now();
while (!stop()) {
try {
vespalib::SignalHandler::CHLD.clear();
- handler.doWork(); // Check for child procs & commands
+ manager.doWork(); // Check for child procs & commands
} catch (InvalidConfigException& ex) {
LOG(warning, "Configuration problem: (ignoring): %s", ex.what());
} catch (vespalib::PortListenException& ex) {
@@ -102,7 +103,7 @@ main(int argc, char **argv)
int maxNum = 0;
fd_set fds;
FD_ZERO(&fds);
- handler.updateActiveFdset(&fds, &maxNum);
+ manager.updateActiveFdset(&fds, &maxNum);
struct timeval tv;
tv.tv_sec = 0;
@@ -118,6 +119,6 @@ main(int argc, char **argv)
}
EV_STOPPING("config-sentinel", "normal exit");
- int rv = handler.terminate();
+ int rv = manager.terminate();
return rv;
}