Commit 61ed0fc7 authored by fred's avatar fred
Browse files

check optional services on startup, fixed base directory with xmpp and tracker services

parent dc49d4c6
......@@ -54,7 +54,7 @@ Http_api::Http_api(QString basedirectory, QxtAbstractWebSessionManager * sm, QOb
z_push_api->setsockopt (ZMQ_SNDHWM, &hwm, sizeof (hwm));
z_push_api->setsockopt (ZMQ_RCVHWM, &hwm, sizeof (hwm));
QString directory = "ipc://" + basedirectory + "/http";
QString directory = "ipc://" + m_basedirectory + "/http";
z_push_api->bind(directory.toLatin1());
}
......
......@@ -75,20 +75,15 @@ Dispatcher::Dispatcher(params ncs_params)
connect(snTerm, SIGNAL(activated(int)), this, SLOT(handleSigTerm()));
mongodb_ = new Mongodb(ncs_params.mongodb_ip, ncs_params.mongodb_base);
//mongodb_back = new Nosql("back", ncs_params.mongodb_ip, ncs_params.mongodb_base);
//mongodb_tracker = new Nosql("tracker", ncs_params.mongodb_ip, ncs_params.mongodb_base);
zeromq = new Zeromq();
zeromq = new Zeromq(ncs_params.base_directory);
service = new Service(ncs_params);
service->Http_api_init();
service->Http_admin_init();
//service->Nodetrack_init();
service->Nodeftp_init();
//service->Xmpp_init(ncs_params.domain_name, ncs_params.xmpp_client_port, ncs_params.xmpp_server_port);
if (ncs_params.api_port != 0) service->Http_api_init();
if (ncs_params.tracker_port != 0) service->Nodetrack_init();
if (ncs_params.ftp_server_port != 0) service->Nodeftp_init();
if (ncs_params.xmpp_client_port != 0 && ncs_params.xmpp_server_port != 0 ) service->Xmpp_init();
service->Worker_init();
service->link();
......@@ -179,9 +174,9 @@ int main(int argc, char *argv[])
options.alias("mongodb-base", "mdp");
options.add("domain-name", "set the domain name", QxtCommandOptions::Required);
options.alias("domain-name", "dn");
options.add("xmpp-client-port", "set the xmpp client port", QxtCommandOptions::Required);
options.add("xmpp-client-port", "set the xmpp client port", QxtCommandOptions::Optional);
options.alias("xmpp-client-port", "xcp");
options.add("xmpp-server-port", "set the xmpp server port", QxtCommandOptions::Required);
options.add("xmpp-server-port", "set the xmpp server port", QxtCommandOptions::Optional);
options.alias("xmpp-server-port", "xsp");
options.add("ncs-base-directory", "set the ncs base directory", QxtCommandOptions::Required);
......@@ -195,10 +190,13 @@ int main(int argc, char *argv[])
options.alias("ncs-api-port", "apip");
options.add("ftp-server-port", "set the ftp server port", QxtCommandOptions::Required);
options.add("ftp-server-port", "set the ftp server port", QxtCommandOptions::Optional);
options.alias("ftp-server-port", "fsp");
options.add("tracker-server-port", "set the bittorrent tracker port", QxtCommandOptions::Optional);
options.alias("tracker-server-port", "tsp");
options.add("smtp-hostname", "set the smtp hostname", QxtCommandOptions::Required);
options.alias("smtp-hostname", "sph");
......@@ -299,11 +297,8 @@ int main(int argc, char *argv[])
{
ncs_params.xmpp_client_port = settings.value("xmpp-client-port").toInt();
}
else {
std::cout << "ncs: --xmpp-client-port requires a parameter" << std::endl;
options.showUsage();
return -1;
}
else ncs_params.xmpp_client_port = 0;
if(options.count("xmpp-server-port")) {
ncs_params.xmpp_server_port = options.value("xmpp-server-port").toInt();
......@@ -313,11 +308,8 @@ int main(int argc, char *argv[])
{
ncs_params.xmpp_server_port = settings.value("xmpp-server-port").toInt();
}
else {
std::cout << "ncs: --xmpp-server-port requires a parameter" << std::endl;
options.showUsage();
return -1;
}
else ncs_params.xmpp_server_port = 0;
......@@ -351,11 +343,21 @@ int main(int argc, char *argv[])
{
ncs_params.ftp_server_port = settings.value("ftp-server-port").toInt();
}
else {
std::cout << "ncs: --ftp-server-port requires a parameter" << std::endl;
options.showUsage();
return -1;
else ncs_params.ftp_server_port = 0;
if(options.count("tracker-server-port")) {
ncs_params.tracker_port = options.value("tracker-server-port").toInt();
settings.setValue("tracker-server-port", ncs_params.tracker_port);
}
else if(settings.contains("tracker-server-port"))
{
ncs_params.tracker_port = settings.value("tracker-server-port").toInt();
}
else ncs_params.tracker_port = 0;
......
......@@ -42,6 +42,7 @@ struct params {
int ftp_server_port;
int admin_port;
int api_port;
int tracker_port;
email alert_email;
};
......
......@@ -58,7 +58,8 @@ Nodetrack::Nodetrack(QString basedirectory, QxtAbstractWebSessionManager * sm, Q
z_push_api->setsockopt(ZMQ_SNDHWM, &hwm, sizeof (hwm));
z_push_api->setsockopt(ZMQ_RCVHWM, &hwm, sizeof (hwm));
z_push_api->bind("ipc:///tmp/nodecast/nodetrack");
QString directory = "ipc://" + m_basedirectory + "/nodetrack";
z_push_api->bind(directory.toLatin1());
}
......
......@@ -24,6 +24,7 @@ Service::Service(params a_ncs_params, QObject *parent) : m_ncs_params(a_ncs_para
{
m_nodetrack = NULL;
m_nodeftp = NULL;
m_http_api = NULL;
m_xmpp_server = NULL;
m_xmpp_client = NULL;
}
......@@ -31,7 +32,7 @@ Service::Service(params a_ncs_params, QObject *parent) : m_ncs_params(a_ncs_para
Service::~Service()
{
qDebug() << "delete http api server";
delete(m_http_api);
if (m_http_api) delete(m_http_api);
qDebug() << "delete http admin server";
delete(m_http_admin);
......@@ -90,7 +91,10 @@ void Service::Http_admin_init()
void Service::Nodetrack_init()
{
m_nodetrack_session.setPort(6969);
int port;
m_ncs_params.tracker_port == 0 ? port = 6969 : port = m_ncs_params.tracker_port;
m_nodetrack_session.setPort(port);
m_nodetrack_session.setConnector(&m_nodetrack_connector);
m_nodetrack = new Nodetrack(m_ncs_params.base_directory, &m_nodetrack_session);
......@@ -131,7 +135,7 @@ void Service::Xmpp_init()
qRegisterMetaType<QXmppLogger::MessageType>("QXmppLogger::MessageType");
m_xmpp_server = new Xmpp_server(m_ncs_params.domain_name, m_ncs_params.xmpp_client_port, m_ncs_params.xmpp_server_port);
m_xmpp_client = new Xmpp_client(m_ncs_params.domain_name, m_ncs_params.xmpp_client_port);
m_xmpp_client = new Xmpp_client(m_ncs_params.base_directory, m_ncs_params.domain_name, m_ncs_params.xmpp_client_port);
}
......
......@@ -21,7 +21,7 @@
#include "xmpp_client.h"
Xmpp_client::Xmpp_client(QString a_domain, int a_xmpp_client_port, QObject *parent) : QXmppClient(parent), m_domain(a_domain), m_xmpp_client_port(a_xmpp_client_port)
Xmpp_client::Xmpp_client(QString basedirectory, QString a_domain, int a_xmpp_client_port, QObject *parent) : m_basedirectory(basedirectory), QXmppClient(parent), m_domain(a_domain), m_xmpp_client_port(a_xmpp_client_port)
{
qDebug() << "Xmpp_client::Xmpp_client !!!";
......@@ -49,7 +49,9 @@ Xmpp_client::Xmpp_client(QString a_domain, int a_xmpp_client_port, QObject *pare
z_push_api->setsockopt(ZMQ_RCVHWM, &hwm, sizeof (hwm));
//z_push_api->bind("inproc://xmpp");
z_push_api->bind("ipc:///tmp/nodecast/xmpp");
QString directory = "ipc://" + m_basedirectory + "/xmpp";
z_push_api->bind(directory.toLatin1());
......
......@@ -43,7 +43,7 @@ class Xmpp_client : public QXmppClient
Q_OBJECT
public:
Xmpp_client(QString a_domain, int a_xmpp_client_port, QObject *parent = 0);
Xmpp_client(QString basedirectory, QString a_domain, int a_xmpp_client_port, QObject *parent = 0);
~Xmpp_client();
private:
......@@ -52,6 +52,8 @@ private:
QXmppLogger m_logger;
QXmppPresence subscribe;
QBuffer *m_buffer;
QString m_basedirectory;
//QXmppTransferJob *m_job;
//zmq::context_t *m_context;
......
......@@ -113,7 +113,6 @@ public:
private:
//Nosql &mongodb_;
QString m_domain;
int m_xmpp_client_port;
int m_xmpp_server_port;
......
......@@ -393,9 +393,10 @@ void Ztracker::destructor()
Zpull::Zpull(zmq::context_t *a_context) : m_context(a_context)
Zpull::Zpull(QString base_directory, zmq::context_t *a_context) : m_context(a_context)
{
std::cout << "Zpull::Zpull constructeur" << std::endl;
QString directory;
m_mutex_zeromq = new QMutex();
m_mutex_http = new QMutex();
......@@ -406,18 +407,24 @@ Zpull::Zpull(zmq::context_t *a_context) : m_context(a_context)
int hwm = 50000;
m_socket_http->setsockopt(ZMQ_SNDHWM, &hwm, sizeof (hwm));
m_socket_http->setsockopt(ZMQ_RCVHWM, &hwm, sizeof (hwm));
m_socket_http->connect("ipc:///tmp/nodecast/http");
directory = "ipc://" + base_directory + "/http";
m_socket_http->connect(directory.toLatin1());
m_socket_workers = new zmq::socket_t (*m_context, ZMQ_PULL);
m_socket_workers->setsockopt(ZMQ_SNDHWM, &hwm, sizeof (hwm));
m_socket_workers->setsockopt(ZMQ_RCVHWM, &hwm, sizeof (hwm));
m_socket_workers->connect("ipc:///tmp/nodecast/workers");
directory = "ipc://" + base_directory + "/workers";
m_socket_workers->connect(directory.toLatin1());
m_socket_zeromq = new zmq::socket_t (*m_context, ZMQ_PULL);
m_socket_zeromq->setsockopt(ZMQ_SNDHWM, &hwm, sizeof (hwm));
m_socket_zeromq->setsockopt(ZMQ_RCVHWM, &hwm, sizeof (hwm));
m_socket_zeromq->connect("ipc:///tmp/nodecast/zeromq");
directory = "ipc://" + base_directory + "/zeromq";
m_socket_zeromq->connect(directory.toLatin1());
......@@ -1709,7 +1716,7 @@ void Zstream_push::stream_payload()
Zeromq *Zeromq::_singleton = NULL;
Zeromq::Zeromq()
Zeromq::Zeromq(QString base_directory) : m_base_directory(base_directory)
{
qDebug() << "Zeromq::construct";
......@@ -1784,7 +1791,7 @@ Zeromq::~Zeromq()
Zeromq* Zeromq::getInstance() {
if (NULL == _singleton)
/* if (NULL == _singleton)
{
qDebug() << "creating singleton.";
_singleton = new Zeromq();
......@@ -1792,7 +1799,7 @@ Zeromq* Zeromq::getInstance() {
else
{
qDebug() << "singleton already created!";
}
}*/
return _singleton;
}
......@@ -1828,7 +1835,7 @@ void Zeromq::init()
thread_pull = new QThread;
pull = new Zpull(m_context);
pull = new Zpull(m_base_directory, m_context);
pull->moveToThread(thread_pull);
thread_pull->start();
connect(this, SIGNAL(shutdown()), pull, SLOT(destructor()), Qt::BlockingQueuedConnection);
......
......@@ -137,7 +137,7 @@ class Zpull : public QThread
{
Q_OBJECT
public:
Zpull(zmq::context_t *a_context);
Zpull(QString base_directory, zmq::context_t *a_context);
~Zpull();
private:
......@@ -210,7 +210,7 @@ class Zeromq : public QObject
Q_OBJECT
public:
static Zeromq *getInstance();
Zeromq();
Zeromq(QString base_directory);
~Zeromq();
void init();
......@@ -228,6 +228,7 @@ public:
private:
QString m_base_directory;
QThread *thread_dispatch;
QThread *thread_tracker;
QThread *thread_pull;
......
Supports Markdown
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