Commit 6efe8df3 authored by Frederic Logier's avatar Frederic Logier
Browse files

improved gridfs write with a qthreadpool

parent 7007e671
......@@ -5,6 +5,7 @@
<div class="secondary-navigation">
<ul class="wat-cf">
<li class="first"><a href="/admin/users">Users</a></li>
<li><a href="/admin/apps">Apps</a></li>
<li><a href="/admin/nodes">Nodes</a></li>
<li><a href="/admin/workflows">Workflows</a></li>
<li><a href="/admin/workers">Workers</a></li>
......
......@@ -5,6 +5,7 @@
<div class="secondary-navigation">
<ul class="wat-cf">
<li class="first"><a href="/admin/users">Users</a></li>
<li><a href="/admin/apps">Apps</a></li>
<li class="active"><a href="/admin/nodes">Nodes</a></li>
<li><a href="/admin/workflows">Workflows</a></li>
<li><a href="/admin/workers">Workers</a></li>
......
......@@ -5,6 +5,7 @@
<div class="secondary-navigation">
<ul class="wat-cf">
<li class="first"><a href="/admin/users">Users</a></li>
<li><a href="/admin/apps">Apps</a></li>
<li><a href="/admin/nodes">Nodes</a></li>
<li><a href="/admin/workflows">Workflows</a></li>
<li><a href="/admin/workers">Workers</a></li>
......
......@@ -5,6 +5,7 @@
<div class="secondary-navigation">
<ul class="wat-cf">
<li class="first"><a href="/admin/users">Users</a></li>
<li><a href="/admin/apps">Apps</a></li>
<li><a href="/admin/nodes">Nodes</a></li>
<li><a href="/admin/workflows">Workflows</a></li>
<li><a href="/admin/workers">Workers</a></li>
......
......@@ -5,6 +5,7 @@
<div class="secondary-navigation">
<ul class="wat-cf">
<li class="active first"><a href="/admin/users">Users</a></li>
<li><a href="/admin/apps">Apps</a></li>
<li><a href="/admin/nodes">Nodes</a></li>
<li><a href="/admin/workflows">Workflows</a></li>
<li><a href="/admin/workers">Workers</a></li>
......
......@@ -5,6 +5,7 @@
<div class="secondary-navigation">
<ul class="wat-cf">
<li class="first"><a href="/admin/users">Users</a></li>
<li><a href="/admin/apps">Apps</a></li>
<li><a href="/admin/nodes">Nodes</a></li>
<li><a href="/admin/workflows">Workflows</a></li>
<li class="active"><a href="/admin/workers">Workers</a></li>
......
......@@ -5,6 +5,7 @@
<div class="secondary-navigation">
<ul class="wat-cf">
<li class="first"><a href="/admin/users">Users</a></li>
<li><a href="/admin/apps">Apps</a></li>
<li><a href="/admin/nodes">Nodes</a></li>
<li class="active"><a href="/admin/workflows">Workflows</a></li>
<li><a href="/admin/workers">Workers</a></li>
......
......@@ -317,6 +317,16 @@ void Http_admin::admin(QxtWebRequestEvent* event, QString action)
admin_user_post(event);
}
else if (action == "apps")
{
admin_apps_get(event);
}
else if (action == "createapp")
{
admin_app_post(event);
}
else if (action == "nodes")
{
......@@ -387,6 +397,11 @@ void Http_admin::admin(QxtWebRequestEvent* event, QString action)
admin_user_post(event);
return;
}
else if (action == "createapp")
{
admin_app_post(event);
return;
}
else if (action == "createnode")
{
admin_node_post(event);
......@@ -404,8 +419,8 @@ void Http_admin::admin(QxtWebRequestEvent* event, QString action)
}
else if (action == "createworkflow")
{
admin_workflow_post(event);
admin_workflow_post(event);
return;
}
break;
......@@ -898,6 +913,283 @@ void Http_admin::admin_user_post(QxtWebRequestEvent* event)
}
/********** ADMIN PAGE ************/
void Http_admin::admin_apps_get(QxtWebRequestEvent* event)
{
/* QString bodyMessage;
bodyMessage = buildResponse("error", "ncs version 0.9.1");
qDebug() << bodyMessage;
{ "_id" : ObjectId("50f91cbda159811513a8b729"), "nodename" : "samsung@dev", "email" : "fredix@gmail.com", "user_id" : ObjectId("50f91c85a7a5dbe8e2f35b29"), "node_uuid" : "0d7f9bdc-37a2-4290-be41-62598bd7a525", "node_password" : "6786a141-6dff-4f91-891a-a9107915ad76" }
*/
QxtHtmlTemplate header;
QxtHtmlTemplate body;
QxtHtmlTemplate footer;
QxtWebPageEvent *page;
// if(!body.open("html_templates/admin_users_get.html"))
if(!body.open(m_basedirectory + "/html_templates/admin_apps_get.html"))
{
body["content"]="error 404";
page = new QxtWebPageEvent(event->sessionID,
event->requestID,
body.render().toUtf8());
page->status = 404;
qDebug() << "error 404";
}
else
{
header.open(m_basedirectory + "/html_templates/header.html");
footer.open(m_basedirectory + "/html_templates/footer.html");
header["connection"] = "<li><a href=\"/admin/logout\">Logout</a></li>";
qDebug() << "COOKIES : " << event->cookies.value("nodecast");
QString l_alert;
if (!check_user_login(event, l_alert)) return;
if (!l_alert.isEmpty()) header["alert"] = l_alert;
header["user_login"] = "connected as " + QString::fromStdString(user_bson[event->cookies.value("nodecast")].getField("login").toString(false));
BSONObj filter;
if (!user_bson[event->cookies.value("nodecast")].getBoolField("admin"))
{
filter = BSON("user_id" << user_bson[event->cookies.value("nodecast")].getField("_id"));
}
QList <BSONObj> apps = mongodb_->FindAll("apps", filter);
QString output;
int counter=0;
foreach (BSONObj app, apps)
{
BSONObj user_id = BSON("_id" << app.getField("user_id"));
BSONObj user = mongodb_->Find("users", user_id);
QString trclass = (counter %2 == 0) ? "odd" : "even";
output.append("<tr class=\"" + trclass + "\"><td><input type=\"checkbox\" class=\"checkbox\" name=\"id_" + QString::number(counter) + "\" value=\"" + QString::fromStdString(app.getField("_id").OID().str()) + "\"></td><td>" +
QString::fromStdString(app.getField("appname").str()) + "</td>" +
"<td>" + QString::fromStdString(app.getField("app_uuid").str()) + "</td>" +
"<td>" + QString::fromStdString(user.getField("email").str()) + "</td>" +
"<td class=\"last\"><a href=\"#\">show</a> | <a href=\"#\">edit</a> | <a href=\"#\">destroy</a></td></tr>");
counter++;
}
body["data"]=output;
body["data_count"]=QString::number(counter);
/*
page = new QxtWebPageEvent(event->sessionID,
event->requestID,
header.render().toUtf8() +
body.render().toUtf8() +
footer.render().toUtf8());
*/
page = new QxtWebPageEvent(event->sessionID,
event->requestID,
header.render().toUtf8() +
body.render().toUtf8() +
footer.render().toUtf8());
page->contentType="text/html";
}
postEvent(page);
/* postEvent(new QxtWebPageEvent(event->sessionID,
event->requestID,
index.render().toUtf8()));
*/
}
/********** ADMIN PAGE ************/
void Http_admin::admin_app_post(QxtWebRequestEvent* event)
{
/* QString bodyMessage;
bodyMessage = buildResponse("error", "ncs version 0.9.1");
qDebug() << bodyMessage;
*/
QxtHtmlTemplate header;
QxtHtmlTemplate body;
QxtHtmlTemplate footer;
QxtWebPageEvent *page;
QxtWebContent *form;
QxtWebRedirectEvent *redir=NULL;
// if(!body.open("html_templates/admin_users_get.html"))
switch (enumToHTTPmethod[event->method.toUpper()])
{
case GET:
if(!body.open(m_basedirectory + "/html_templates/admin_app_post.html"))
{
body["content"]="error 404";
page = new QxtWebPageEvent(event->sessionID,
event->requestID,
body.render().toUtf8());
page->status = 404;
qDebug() << "error 404";
}
else
{
header.open(m_basedirectory + "/html_templates/header.html");
footer.open(m_basedirectory + "/html_templates/footer.html");
qDebug() << "COOKIES : " << event->cookies.value("nodecast");
QString l_alert;
if (!check_user_login(event, l_alert)) return;
if (!l_alert.isEmpty()) header["alert"] = l_alert;
if (user_bson[event->cookies.value("nodecast")].getBoolField("admin"))
{
QString output="<label class=\"label\">Choose a owner</label>";
BSONObj empty;
QList <BSONObj> users = mongodb_->FindAll("users", empty);
output.append("<select name=\"user\">");
foreach (BSONObj user, users)
{
output.append("<option value=\"" + QString::fromStdString(user.getField("_id").OID().str()) + "\">" + QString::fromStdString(user.getField("login").str()) + "</option>");
}
output.append("</select>");
body["users"] = output;
}
/*
page = new QxtWebPageEvent(event->sessionID,
event->requestID,
header.render().toUtf8() +
body.render().toUtf8() +
footer.render().toUtf8());
*/
page = new QxtWebPageEvent(event->sessionID,
event->requestID,
header.render().toUtf8() +
body.render().toUtf8() +
footer.render().toUtf8());
page->contentType="text/html";
}
postEvent(page);
break;
case POST:
qDebug() << "COOKIES : " << event->cookies.value("nodecast");
QString l_alert;
if (!check_user_login(event, l_alert)) return;
form = event->content;
form->waitForAllContent();
QByteArray requestContent = form->readAll();
//RECEIVE : "firstname=fred&lastname=ix&email=fredix%40gmail.com"
qDebug() << "RECEIVE : " << requestContent;
//QxtWebStoreCookieEvent cookie_mail (event->sessionID, "email", hauth["email"], QDateTime::currentDateTime().addMonths(1));
//QxtWebStoreCookieEvent cookie_pass (event->sessionID, "password", hauth["password"], QDateTime::currentDateTime().addMonths(1));
//RECEIVE : "login=fredix&email=fredix%40gmail.com"
QHash <QString, QString> form_field;
QStringList list_field = QString::fromAscii(requestContent).split("&");
for (int i = 0; i < list_field.size(); ++i)
{
QStringList field = list_field.at(i).split("=");
if (field[1].isEmpty())
{
set_user_alert(event, errorMessage("field " + field[0] + " is empty", "error"));
redir = new QxtWebRedirectEvent( event->sessionID, event->requestID, "createnode", 302 );
postEvent(redir);
return;
}
form_field[field[0]] = field[1].replace(QString("%40"), QString("@"));
}
qDebug() << "form field : " << form_field;
QUuid app_uuid = QUuid::createUuid();
QString str_app_uuid = app_uuid.toString().mid(1,36);
qDebug() << "str_app_uuid : " << str_app_uuid;
BSONObj user_id;
if (!user_bson[event->cookies.value("nodecast")].getBoolField("admin"))
{
user_id = BSON("_id" << user_bson[event->cookies.value("nodecast")].getField("_id"));
}
else user_id = BSON("_id" << mongo::OID(form_field["user"].toStdString()));
BSONObj t_user = mongodb_->Find("users", user_id);
std::cout << "T USER : " << t_user.toString() << std::endl;
BSONObj t_app = BSON(GENOID <<
"appname" << form_field["appname"].toStdString() <<
"user_id" << t_user.getField("_id").OID() <<
"app_uuid" << str_app_uuid.toStdString());
mongodb_->Insert("apps", t_app);
be t_user_id = t_user.getField("_id");
bo app = BSON("apps" << t_app);
mongodb_->Addtoarray("users", t_user_id.wrap(), app);
//doc = { login : 'user', email : 'user@email.com', authentication_token : 'token'}
//db.users.insert(doc);
redir = new QxtWebRedirectEvent( event->sessionID, event->requestID, "apps", 302 );
postEvent(redir);
break;
}
}
/********** ADMIN PAGE ************/
void Http_admin::admin_nodes_get(QxtWebRequestEvent* event)
{
......@@ -1230,6 +1522,7 @@ void Http_admin::admin_node_post(QxtWebRequestEvent* event)
/********** ADMIN PAGE ************/
void Http_admin::admin_workflows_get(QxtWebRequestEvent* event)
{
......
......@@ -60,6 +60,8 @@ public slots:
private:
void admin_users_get(QxtWebRequestEvent* event);
void admin_user_post(QxtWebRequestEvent* event);
void admin_apps_get(QxtWebRequestEvent* event);
void admin_app_post(QxtWebRequestEvent* event);
void admin_nodes_get(QxtWebRequestEvent* event);
void admin_node_post(QxtWebRequestEvent* event);
void admin_node_or_workflow_delete(QxtWebRequestEvent* event, QString collection);
......
......@@ -269,6 +269,16 @@ Service::~Service()
api_user->deleteLater();
thread_api_user->wait();
qDebug() << "api_session->deleteLater();";
api_session->deleteLater();
thread_api_session->wait();
qDebug() << "api_app->deleteLater();";
api_app->deleteLater();
thread_api_app->wait();
/* delete(api_node);
delete(api_workflow);
delete(api_user);*/
......@@ -355,6 +365,27 @@ void Service::Http_api_init()
api_user->moveToThread(thread_api_user);
thread_api_user->start();
thread_api_session = new QThread(this);
api_session = new Api_session(m_ncs_params.base_directory, port + 103);
connect(thread_api_session, SIGNAL(started()), api_session, SLOT(init()));
connect(api_session, SIGNAL(destroyed()), thread_api_session, SLOT(quit()), Qt::DirectConnection);
api_session->moveToThread(thread_api_session);
thread_api_session->start();
thread_api_app = new QThread(this);
api_app = new Api_app(m_ncs_params.base_directory, port + 104);
connect(thread_api_app, SIGNAL(started()), api_app, SLOT(init()));
connect(api_app, SIGNAL(destroyed()), thread_api_app, SLOT(quit()), Qt::DirectConnection);
api_app->moveToThread(thread_api_app);
thread_api_app->start();
}
......
......@@ -95,6 +95,9 @@ public:
Api_node *api_node;
Api_workflow *api_workflow;
Api_user *api_user;
Api_session *api_session;
Api_app *api_app;
private:
QThread *thread_ZerogwProxy;
......@@ -103,6 +106,9 @@ private:
QThread *thread_api_node;
QThread *thread_api_workflow;
QThread *thread_api_user;
QThread *thread_api_session;
QThread *thread_api_app;
QThread *thread_xmpp_server;
QThread *thread_xmpp_client;
......
This diff is collapsed.
This diff is collapsed.
/**@file
* @brief CFtpServer - Custom compilation
*
* @author Mail :: thebrowser@gmail.com
*
* @copyright Copyright (C) 2007 Julien Poumailloux
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
* 4. If you like this software, a fee would be appreciated, particularly if
* you use this software in a commercial product, but is not required.
*/
// Compilation Options !:
/**
* @def CFTPSERVER_ENABLE_EXTRACMD
* Enable or disable extra commands support.
* Default: Disabled.
*/
//#define CFTPSERVER_ENABLE_EXTRACMD
/**
* @def CFTPSERVER_ENABLE_EVENTS
* Enable or disable events.
*/
//#define CFTPSERVER_ENABLE_EVENTS
/**
* @def CFTPSERVER_ENABLE_ZLIB
* Enable or disable data transfer compression support using the Zlib library.
*/
#define CFTPSERVER_ENABLE_ZLIB
/**
* @def CFTPSERVER_ENABLE_IPV6
* Enable or disable IPV6 support.
* @note Not yet implemented.
*/
//#define CFTPSERVER_ENABLE_IPV6 to be implemented.
/**
* @def __USE_FILE_OFFSET64
* Enable or disable large file support under Win32.
* @note Under Linux and other stuff, just add -D_FILE_OFFSET_BITS=64 to the compilation line.
*/
#ifdef WIN32
#define __USE_FILE_OFFSET64
#endif
/**@file
* @brief CFtpServer - Internal configuration
*
* @author Mail :: thebrowser@gmail.com
*
* @copyright Copyright (C) 2007 Julien Poumailloux
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
* 4. If you like this software, a fee would be appreciated, particularly if
* you use this software in a commercial product, but is not required.
*/
/*
* MODIFIED by frederic@logier.org for NCS
* REMOVED useless win32 directive
*/
#define SOCKET_ERROR -1
#define INVALID_SOCKET -1
#define MAX_PATH PATH_MAX
#ifndef O_BINARY
#define O_BINARY 0
#endif
#define CloseSocket(x) (shutdown((x), SHUT_RDWR), close(x))
#ifndef MSG_NOSIGNAL
#ifdef SO_NOSIGPIPE
#define MSG_NOSIGNAL SO_NOSIGPIPE
#else
#define MSG_NOSIGNAL 0
#endif
#endif
// Internal settings. Do not modify!
#define CFTPSERVER_REPLY_MAX_LEN (MAX_PATH + 64)
#define CFTPSERVER_LIST_MAX_LINE_LEN (MAX_PATH + 57)
/****************************************************************************
** ncs is the backend's server of nodecast
** Copyright (C) 2010-2013 Frédéric Logier <frederic@logier.org>
**
** https://github.com/nodecast/ncs
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "main.h"
#include <QCoreApplication>
int Service::sighupFd[2]={};
int Service::sigtermFd[2]={};
QSettings settings("nodecast", "nodeftp");
// http://doc.qt.nokia.com/4.7/unix-signals.html
static void setup_unix_signal_handlers()