Commit 874f06ce authored by Michael Ott's avatar Michael Ott
Browse files

Disable REST API in collectagent and dcdbpusher if there are no restAPI configuration blocks

parent 9a2bfd2f
......@@ -526,16 +526,14 @@ int main(int argc, char* const argv[]) {
LOG(info) << " Username and password not printed.";
#endif
LOG(info) << "RestAPI Settings:";
LOG(info) << " REST Server: " << restAPISettings.host << ":" << restAPISettings.port;
#ifdef SimpleMQTTVerbose
LOG(info) << " Certificate: " << restAPISettings.certificate;
if (restAPISettings.enabled) {
LOG(info) << "RestAPI Settings:";
LOG(info) << " REST Server: " << restAPISettings.host << ":" << restAPISettings.port;
LOG(info) << " Certificate: " << restAPISettings.certificate;
LOG(info) << " Private key file: " << restAPISettings.privateKey;
LOG(info) << " DH params from: " << restAPISettings.dhFile;
#else
LOG(info) << " Certificate, private key and DH-param file not printed.";
#endif
}
LOG_VAR(vLogLevel) << "----- Analytics Configuration -----";
for(auto& p : analyticsController->getManager()->getPlugins()) {
LOG_VAR(vLogLevel) << "Operator Plugin \"" << p.id << "\"";
......@@ -561,11 +559,13 @@ int main(int argc, char* const argv[]) {
/*
* Start the HTTP Server for the REST API
*/
CARestAPI httpsServer(restAPISettings, &mySensorCache, analyticsController);
config.readRestAPIUsers(&httpsServer);
httpsServer.start();
LOG(info) << "HTTP Server running...";
CARestAPI* httpsServer;
if (restAPISettings.enabled) {
httpsServer = new CARestAPI(restAPISettings, &mySensorCache, analyticsController);
config.readRestAPIUsers(httpsServer);
httpsServer->start();
LOG(info) << "HTTP Server running...";
}
/*
* Run (hopefully) forever...
......@@ -609,8 +609,11 @@ int main(int argc, char* const argv[]) {
analyticsController->stop();
ms.stop();
LOG(info) << "MQTT Server stopped...";
httpsServer.stop();
LOG(info) << "HTTP Server stopped...";
if (restAPISettings.enabled) {
httpsServer->stop();
delete httpsServer;
LOG(info) << "HTTP Server stopped...";
}
delete mySensorDataStore;
delete myJobDataStore;
delete mySensorConfig;
......
......@@ -67,6 +67,7 @@ public:
class serverSettings_t {
public:
serverSettings_t() {}
bool enabled = false;
std::string host = "";/**< Host name/IP address to listen on */
std::string port = "8000";/**< Port to listen on */
std::string certificate = "";/**< Certificate chain file in PEM format */
......
......@@ -93,6 +93,7 @@ bool GlobalConfiguration::readConfig() {
// ----- READING REST API SETTINGS -----
if(cfg.find("restAPI") != cfg.not_found()) {
restAPISettings.enabled = true;
BOOST_FOREACH(boost::property_tree::iptree::value_type & global, cfg.get_child("restAPI")) {
if (boost::iequals(global.first, "address")) {
restAPISettings.host = global.second.data();
......
......@@ -344,16 +344,13 @@ int main(int argc, char** argv) {
LOG(info) << "Analytics Settings:";
LOG(info) << " Hierarchy: " << (analyticsSettings.hierarchy!="" ? analyticsSettings.hierarchy : "none");
LOG(info) << " Filter: " << (analyticsSettings.filter!="" ? analyticsSettings.filter : "none");
LOG(info) << "RestAPI Settings:";
LOG(info) << " REST Server: " << restAPISettings.host << ":" << restAPISettings.port;
#ifdef DEBUG
LOG(info) << " Certificate: " << restAPISettings.certificate;
LOG(info) << " Private key file: " << restAPISettings.privateKey;
LOG(info) << " DH params from: " << restAPISettings.dhFile;
#else
LOG(info) << " Certificate, private key and DH-param file not printed.";
#endif
if (restAPISettings.enabled) {
LOG(info) << "RestAPI Settings:";
LOG(info) << " REST Server: " << restAPISettings.host << ":" << restAPISettings.port;
LOG(info) << " Certificate: " << restAPISettings.certificate;
LOG(info) << " Private key file: " << restAPISettings.privateKey;
LOG(info) << " DH params from: " << restAPISettings.dhFile;
}
LOG_VAR(vLogLevel) << "----- Sampling Configuration -----";
for(auto& p : _pluginManager->getPlugins()) {
LOG_VAR(vLogLevel) << "Sampling Plugin \"" << p.id << "\"";
......@@ -371,9 +368,10 @@ int main(int argc, char** argv) {
//MQTTPusher and Https server get their own threads
_mqttPusher = new MQTTPusher(globalSettings.brokerPort, globalSettings.brokerHost, pluginSettings.autoPublish, globalSettings.qosLevel,
_pluginManager->getPlugins(), _operatorManager->getPlugins(), globalSettings.maxMsgNum, globalSettings.maxInflightMsgNum, globalSettings.maxQueuedMsgNum);
_httpsServer = new RestAPI(restAPISettings, _pluginManager, _mqttPusher, _operatorManager, io);
_configuration->readRestAPIUsers(_httpsServer);
if (restAPISettings.enabled) {
_httpsServer = new RestAPI(restAPISettings, _pluginManager, _mqttPusher, _operatorManager, io);
_configuration->readRestAPIUsers(_httpsServer);
}
if (globalSettings.validateConfig) {
return 0;
}
......@@ -426,8 +424,10 @@ int main(int argc, char** argv) {
LOG(info) << "Threads created!";
LOG(info) << "Starting RestAPI Https Server...";
_httpsServer->start();
if (restAPISettings.enabled) {
LOG(info) << "Starting RestAPI Https Server...";
_httpsServer->start();
}
LOG(info) << "Registering signal handlers...";
signal(SIGINT, sigHandler); //Handle Strg+C
......@@ -452,7 +452,10 @@ int main(int argc, char** argv) {
LOG(info) << "Tearing down objects...";
_queryEngine.setNavigator(nullptr);
_queryEngine.setSensorMap(nullptr);
delete _httpsServer;
if (restAPISettings.enabled) {
_httpsServer->stop();
delete _httpsServer;
}
delete _mqttPusher;
delete _operatorManager;
delete _pluginManager;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment