mirror of
https://github.com/arcan1s/queued.git
synced 2025-07-07 10:55:50 +00:00
use 100 symbols (2)
This commit is contained in:
@ -21,7 +21,7 @@ BreakBeforeBinaryOperators: All
|
|||||||
BreakBeforeBraces: Linux
|
BreakBeforeBraces: Linux
|
||||||
BreakBeforeTernaryOperators: true
|
BreakBeforeTernaryOperators: true
|
||||||
BreakConstructorInitializersBeforeComma: true
|
BreakConstructorInitializersBeforeComma: true
|
||||||
ColumnLimit: 80
|
ColumnLimit: 100
|
||||||
CommentPragmas: '^ IWYU pragma:'
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
ConstructorInitializerIndentWidth: 4
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
@ -29,8 +29,7 @@ void QueuedEmailNotify::init(const QVariantHash &_settings)
|
|||||||
m_helper->setInsecureCurl(_settings.value("InsecureCurl", false).toBool());
|
m_helper->setInsecureCurl(_settings.value("InsecureCurl", false).toBool());
|
||||||
m_helper->setPassword(_settings.value("Password", "").toString());
|
m_helper->setPassword(_settings.value("Password", "").toString());
|
||||||
m_helper->setPort(_settings.value("Port", 465).toInt());
|
m_helper->setPort(_settings.value("Port", 465).toInt());
|
||||||
m_helper->setServer(
|
m_helper->setServer(_settings.value("Server", "smtp://smtp.example.com").toString());
|
||||||
_settings.value("Server", "smtp://smtp.example.com").toString());
|
|
||||||
m_helper->setSslEnabled(_settings.value("UseSSL", false).toBool());
|
m_helper->setSslEnabled(_settings.value("UseSSL", false).toBool());
|
||||||
m_helper->setUsername(_settings.value("Username", "").toString());
|
m_helper->setUsername(_settings.value("Username", "").toString());
|
||||||
}
|
}
|
||||||
@ -50,14 +49,12 @@ void QueuedEmailNotify::setup(const QueuedPluginManagerInterface *_manager)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void QueuedEmailNotify::updateSettings(const QString &_key,
|
void QueuedEmailNotify::updateSettings(const QString &_key, const QVariant &_value)
|
||||||
const QVariant &_value)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_PL) << "Update settings for" << _key;
|
qCDebug(LOG_PL) << "Update settings for" << _key;
|
||||||
|
|
||||||
if (!m_helper) {
|
if (!m_helper) {
|
||||||
qCWarning(LOG_PL)
|
qCWarning(LOG_PL) << "Helper is not initialized. Did you forget to call ::init()?";
|
||||||
<< "Helper is not initialized. Did you forget to call ::init()?";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@ char *QueuedEmailNotifyHelper::curlString(const QString &_source)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t QueuedEmailNotifyHelper::curlReadCallback(char *buffer, size_t size,
|
size_t QueuedEmailNotifyHelper::curlReadCallback(char *buffer, size_t size, size_t nitems,
|
||||||
size_t nitems, void *instream)
|
void *instream)
|
||||||
{
|
{
|
||||||
// FIXME not really best choice to use here
|
// FIXME not really best choice to use here
|
||||||
auto text = reinterpret_cast<MailBody *>(instream);
|
auto text = reinterpret_cast<MailBody *>(instream);
|
||||||
@ -206,16 +206,14 @@ void QueuedEmailNotifyHelper::sendEmail(const long long _id)
|
|||||||
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
|
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
|
||||||
|
|
||||||
// mail body
|
// mail body
|
||||||
curl_easy_setopt(curl, CURLOPT_READFUNCTION,
|
curl_easy_setopt(curl, CURLOPT_READFUNCTION, &QueuedEmailNotifyHelper::curlReadCallback);
|
||||||
&QueuedEmailNotifyHelper::curlReadCallback);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_READDATA, &text);
|
curl_easy_setopt(curl, CURLOPT_READDATA, &text);
|
||||||
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
||||||
|
|
||||||
// send
|
// send
|
||||||
auto res = curl_easy_perform(curl);
|
auto res = curl_easy_perform(curl);
|
||||||
if (res != CURLE_OK)
|
if (res != CURLE_OK)
|
||||||
qCWarning(LOG_PL) << "Could not perform curl action"
|
qCWarning(LOG_PL) << "Could not perform curl action" << curl_easy_strerror(res);
|
||||||
<< curl_easy_strerror(res);
|
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
curl_slist_free_all(recipients);
|
curl_slist_free_all(recipients);
|
||||||
@ -244,16 +242,13 @@ QString QueuedEmailNotifyHelper::getEmail(const long long _id) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList QueuedEmailNotifyHelper::getEmailText(const long long _id,
|
QStringList QueuedEmailNotifyHelper::getEmailText(const long long _id, const QString &_to) const
|
||||||
const QString &_to) const
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_PL) << "Get email text for user" << _to << "for task" << _id;
|
qCDebug(LOG_PL) << "Get email text for user" << _to << "for task" << _id;
|
||||||
|
|
||||||
auto now
|
auto now = QDateTime::currentDateTimeUtc().toString(Qt::DateFormat::RFC2822Date);
|
||||||
= QDateTime::currentDateTimeUtc().toString(Qt::DateFormat::RFC2822Date);
|
|
||||||
|
|
||||||
return {QString("Date: %1\r\n").arg(now),
|
return {QString("Date: %1\r\n").arg(now), QString("To: %1\r\n").arg(curlEmail(_to)),
|
||||||
QString("To: %1\r\n").arg(curlEmail(_to)),
|
|
||||||
QString("From: %1\r\n").arg(curlEmail(from())),
|
QString("From: %1\r\n").arg(curlEmail(from())),
|
||||||
// message-id?
|
// message-id?
|
||||||
QString("Subject: %1\r\n").arg("Job %1 done").arg(_id), "\r\n",
|
QString("Subject: %1\r\n").arg("Job %1 done").arg(_id), "\r\n",
|
||||||
|
@ -42,8 +42,7 @@ public:
|
|||||||
virtual ~QueuedEmailNotifyHelper() = default;
|
virtual ~QueuedEmailNotifyHelper() = default;
|
||||||
static QString curlEmail(const QString &_from);
|
static QString curlEmail(const QString &_from);
|
||||||
static char *curlString(const QString &_source);
|
static char *curlString(const QString &_source);
|
||||||
static size_t curlReadCallback(char *buffer, size_t size, size_t nitems,
|
static size_t curlReadCallback(char *buffer, size_t size, size_t nitems, void *instream);
|
||||||
void *instream);
|
|
||||||
// properties
|
// properties
|
||||||
QString from() const;
|
QString from() const;
|
||||||
bool isInsecureCurl() const;
|
bool isInsecureCurl() const;
|
||||||
|
@ -41,8 +41,7 @@ QueuedApplication::~QueuedApplication()
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_APP) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
QDBusConnection::sessionBus().unregisterObject(
|
QDBusConnection::sessionBus().unregisterObject(QueuedConfig::DBUS_APPLICATION_PATH);
|
||||||
QueuedConfig::DBUS_APPLICATION_PATH);
|
|
||||||
m_core->deleteLater();
|
m_core->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,8 +60,8 @@ void QueuedApplication::initDBus()
|
|||||||
if (!bus.registerObject(QueuedConfig::DBUS_APPLICATION_PATH,
|
if (!bus.registerObject(QueuedConfig::DBUS_APPLICATION_PATH,
|
||||||
new QueuedApplicationInterface(this),
|
new QueuedApplicationInterface(this),
|
||||||
QDBusConnection::ExportAllContents)) {
|
QDBusConnection::ExportAllContents)) {
|
||||||
QString message = QString("Could not register application object %1")
|
QString message
|
||||||
.arg(bus.lastError().message());
|
= QString("Could not register application object %1").arg(bus.lastError().message());
|
||||||
qCCritical(LOG_DBUS) << message;
|
qCCritical(LOG_DBUS) << message;
|
||||||
throw QueuedDBusException(message);
|
throw QueuedDBusException(message);
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,7 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedApplicationInterface::QueuedApplicationInterface(
|
QueuedApplicationInterface::QueuedApplicationInterface(QueuedApplication *parent)
|
||||||
QueuedApplication *parent)
|
|
||||||
: QDBusAbstractAdaptor(parent)
|
: QDBusAbstractAdaptor(parent)
|
||||||
, m_application(parent)
|
, m_application(parent)
|
||||||
{
|
{
|
||||||
|
@ -36,8 +36,8 @@ QueuedApplication *instance = nullptr;
|
|||||||
bool existingSessionOperation(const QString &operation)
|
bool existingSessionOperation(const QString &operation)
|
||||||
{
|
{
|
||||||
auto res = QueuedCoreAdaptor::sendRequest<bool>(
|
auto res = QueuedCoreAdaptor::sendRequest<bool>(
|
||||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_APPLICATION_PATH,
|
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_APPLICATION_PATH, QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_SERVICE, operation, QVariantList());
|
operation, QVariantList());
|
||||||
|
|
||||||
return ((res.type() == Result::Content::Value) && res.get());
|
return ((res.type() == Result::Content::Value) && res.get());
|
||||||
}
|
}
|
||||||
@ -60,8 +60,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// parser
|
// parser
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription(
|
parser.setApplicationDescription("Daemon for starting jobs to queue of calculations");
|
||||||
"Daemon for starting jobs to queue of calculations");
|
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
parser.addVersionOption();
|
parser.addVersionOption();
|
||||||
// info
|
// info
|
||||||
@ -69,8 +68,7 @@ int main(int argc, char *argv[])
|
|||||||
parser.addOption(infoOption);
|
parser.addOption(infoOption);
|
||||||
|
|
||||||
// configuration option
|
// configuration option
|
||||||
QCommandLineOption configOption({"c", "config"},
|
QCommandLineOption configOption({"c", "config"}, "Read initial configuration from file.",
|
||||||
"Read initial configuration from file.",
|
|
||||||
"config", QueuedSettings::defaultPath());
|
"config", QueuedSettings::defaultPath());
|
||||||
parser.addOption(configOption);
|
parser.addOption(configOption);
|
||||||
|
|
||||||
|
@ -46,33 +46,26 @@ QueuedServer::~QueuedServer()
|
|||||||
void QueuedServer::init()
|
void QueuedServer::init()
|
||||||
{
|
{
|
||||||
while (QueuedCoreAdaptor::getStatus().type() != Result::Content::Value) {
|
while (QueuedCoreAdaptor::getStatus().type() != Result::Content::Value) {
|
||||||
qCWarning(LOG_SERV)
|
qCWarning(LOG_SERV) << "Daemon seems to be unavailable wait" << WAIT_FOR_DAEMON;
|
||||||
<< "Daemon seems to be unavailable wait" << WAIT_FOR_DAEMON;
|
|
||||||
|
|
||||||
QTime timer = QTime::currentTime().addMSecs(WAIT_FOR_DAEMON);
|
QTime timer = QTime::currentTime().addMSecs(WAIT_FOR_DAEMON);
|
||||||
while (QTime::currentTime() < timer)
|
while (QTime::currentTime() < timer)
|
||||||
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
|
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_server->init(QueuedCoreAdaptor::getOption(
|
m_server->init(QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::ServerTimeout, "")
|
||||||
QueuedConfig::QueuedSettings::ServerTimeout, "")
|
|
||||||
.get()
|
.get()
|
||||||
.toInt());
|
.toInt());
|
||||||
QString address = QueuedCoreAdaptor::getOption(
|
QString address = QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::ServerAddress, "")
|
||||||
QueuedConfig::QueuedSettings::ServerAddress, "")
|
|
||||||
.get()
|
.get()
|
||||||
.toString();
|
.toString();
|
||||||
ushort port = QueuedCoreAdaptor::getOption(
|
ushort port
|
||||||
QueuedConfig::QueuedSettings::ServerPort, "")
|
= QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::ServerPort, "").get().toUInt();
|
||||||
.get()
|
|
||||||
.toUInt();
|
|
||||||
m_server->listen(QHostAddress(address), port);
|
m_server->listen(QHostAddress(address), port);
|
||||||
m_server->setMaxPendingConnections(
|
m_server->setMaxPendingConnections(
|
||||||
QueuedCoreAdaptor::getOption(
|
QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::ServerMaxConnections, "")
|
||||||
QueuedConfig::QueuedSettings::ServerMaxConnections, "")
|
|
||||||
.get()
|
.get()
|
||||||
.toInt());
|
.toInt());
|
||||||
|
|
||||||
qCInfo(LOG_SERV) << "Server listen on" << m_server->serverAddress()
|
qCInfo(LOG_SERV) << "Server listen on" << m_server->serverAddress() << m_server->serverPort();
|
||||||
<< m_server->serverPort();
|
|
||||||
}
|
}
|
||||||
|
@ -27,14 +27,13 @@ QVariantHash QueuedTcpServerResponseHelper::getData(const Request &_request,
|
|||||||
const QVariantHash &_data,
|
const QVariantHash &_data,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Get data for request"
|
qCDebug(LOG_SERV) << "Get data for request" << static_cast<int>(_request.path)
|
||||||
<< static_cast<int>(_request.path) << _request.apiVersion
|
<< _request.apiVersion << _request.arg << "with data" << _data;
|
||||||
<< _request.arg << "with data" << _data;
|
|
||||||
|
|
||||||
QVariantHash output;
|
QVariantHash output;
|
||||||
if (_request.apiVersion == 1)
|
if (_request.apiVersion == 1)
|
||||||
output = QueuedTcpServerResponseHelperApi1::getData(
|
output = QueuedTcpServerResponseHelperApi1::getData(_request.path, _request.arg,
|
||||||
_request.path, _request.arg, _request.type, _data, _token);
|
_request.type, _data, _token);
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -64,8 +63,7 @@ QueuedTcpServerResponseHelper::parsePath(const QString &_path)
|
|||||||
// check if request is valid
|
// check if request is valid
|
||||||
request.valid = (request.path != RequestPath::Unknown)
|
request.valid = (request.path != RequestPath::Unknown)
|
||||||
&& (std::find(std::begin(QueuedConfig::WEBAPI_VERSIONS),
|
&& (std::find(std::begin(QueuedConfig::WEBAPI_VERSIONS),
|
||||||
std::end(QueuedConfig::WEBAPI_VERSIONS),
|
std::end(QueuedConfig::WEBAPI_VERSIONS), request.apiVersion)
|
||||||
request.apiVersion)
|
|
||||||
!= std::end(QueuedConfig::WEBAPI_VERSIONS));
|
!= std::end(QueuedConfig::WEBAPI_VERSIONS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,49 +43,47 @@ typedef struct {
|
|||||||
QString type;
|
QString type;
|
||||||
bool valid;
|
bool valid;
|
||||||
} Request;
|
} Request;
|
||||||
static const QHash<int, QByteArray> HTTPCodeMap
|
static const QHash<int, QByteArray> HTTPCodeMap = {{100, "Continue"},
|
||||||
= {{100, "Continue"},
|
{101, "Switching Protocols"},
|
||||||
{101, "Switching Protocols"},
|
{200, "OK"},
|
||||||
{200, "OK"},
|
{201, "Created"},
|
||||||
{201, "Created"},
|
{202, "Accepted"},
|
||||||
{202, "Accepted"},
|
{203, "Non-Authoritative Information"},
|
||||||
{203, "Non-Authoritative Information"},
|
{204, "No Content"},
|
||||||
{204, "No Content"},
|
{205, "Reset Content"},
|
||||||
{205, "Reset Content"},
|
{206, "Partial Content"},
|
||||||
{206, "Partial Content"},
|
{300, "Multiple Choices"},
|
||||||
{300, "Multiple Choices"},
|
{301, "Moved Permanently"},
|
||||||
{301, "Moved Permanently"},
|
{302, "Found"},
|
||||||
{302, "Found"},
|
{303, "See Other"},
|
||||||
{303, "See Other"},
|
{304, "Not Modified"},
|
||||||
{304, "Not Modified"},
|
{305, "Use Proxy"},
|
||||||
{305, "Use Proxy"},
|
{307, "Temporary Redirect"},
|
||||||
{307, "Temporary Redirect"},
|
{400, "Bad Request"},
|
||||||
{400, "Bad Request"},
|
{401, "Unauthorized"},
|
||||||
{401, "Unauthorized"},
|
{402, "Payment Required"},
|
||||||
{402, "Payment Required"},
|
{403, "Forbidden"},
|
||||||
{403, "Forbidden"},
|
{404, "Not Found"},
|
||||||
{404, "Not Found"},
|
{405, "Method Not Allowed"},
|
||||||
{405, "Method Not Allowed"},
|
{406, "Not Acceptable"},
|
||||||
{406, "Not Acceptable"},
|
{407, "Proxy Authentication Required"},
|
||||||
{407, "Proxy Authentication Required"},
|
{408, "Request Time-out"},
|
||||||
{408, "Request Time-out"},
|
{409, "Conflict"},
|
||||||
{409, "Conflict"},
|
{410, "Gone"},
|
||||||
{410, "Gone"},
|
{411, "Length Required"},
|
||||||
{411, "Length Required"},
|
{412, "Precondition Failed"},
|
||||||
{412, "Precondition Failed"},
|
{413, "Request Entity Too Large"},
|
||||||
{413, "Request Entity Too Large"},
|
{414, "Request-URI Too Large"},
|
||||||
{414, "Request-URI Too Large"},
|
{415, "Unsupported Media Type"},
|
||||||
{415, "Unsupported Media Type"},
|
{416, "Requested range not satisfiable"},
|
||||||
{416, "Requested range not satisfiable"},
|
{417, "Expectation Failed"},
|
||||||
{417, "Expectation Failed"},
|
{500, "Internal Server Error"},
|
||||||
{500, "Internal Server Error"},
|
{501, "Not Implemented"},
|
||||||
{501, "Not Implemented"},
|
{502, "Bad Gateway"},
|
||||||
{502, "Bad Gateway"},
|
{503, "Service Unavailable"},
|
||||||
{503, "Service Unavailable"},
|
{504, "Gateway Time-out"},
|
||||||
{504, "Gateway Time-out"},
|
{505, "HTTP Version not supported"}};
|
||||||
{505, "HTTP Version not supported"}};
|
QVariantHash getData(const Request &_request, const QVariantHash &_data, const QString &_token);
|
||||||
QVariantHash getData(const Request &_request, const QVariantHash &_data,
|
|
||||||
const QString &_token);
|
|
||||||
Request parsePath(const QString &_path);
|
Request parsePath(const QString &_path);
|
||||||
RequestPath pathToEnum(const QString &_path);
|
RequestPath pathToEnum(const QString &_path);
|
||||||
};
|
};
|
||||||
|
@ -27,12 +27,11 @@
|
|||||||
|
|
||||||
|
|
||||||
QVariantHash QueuedTcpServerResponseHelperApi1::getData(
|
QVariantHash QueuedTcpServerResponseHelperApi1::getData(
|
||||||
const QueuedTcpServerResponseHelper::RequestPath _request,
|
const QueuedTcpServerResponseHelper::RequestPath _request, const QString &_arg,
|
||||||
const QString &_arg, const QString &_type, const QVariantHash &_data,
|
const QString &_type, const QVariantHash &_data, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Get data for" << static_cast<int>(_request)
|
qCDebug(LOG_SERV) << "Get data for" << static_cast<int>(_request) << "with arg" << _arg
|
||||||
<< "with arg" << _arg << "with data" << _data;
|
<< "with data" << _data;
|
||||||
|
|
||||||
QVariantHash output;
|
QVariantHash output;
|
||||||
if ((_request != QueuedTcpServerResponseHelper::RequestPath::Auth)
|
if ((_request != QueuedTcpServerResponseHelper::RequestPath::Auth)
|
||||||
@ -50,47 +49,41 @@ QVariantHash QueuedTcpServerResponseHelperApi1::getData(
|
|||||||
break;
|
break;
|
||||||
case QueuedTcpServerResponseHelper::RequestPath::Option:
|
case QueuedTcpServerResponseHelper::RequestPath::Option:
|
||||||
if (_type == "GET")
|
if (_type == "GET")
|
||||||
output
|
output = QueuedTcpServerResponseHelperOption::getOption(_arg, _token);
|
||||||
= QueuedTcpServerResponseHelperOption::getOption(_arg, _token);
|
|
||||||
else if (_type == "POST")
|
else if (_type == "POST")
|
||||||
output = QueuedTcpServerResponseHelperOption::setOption(_arg, _data,
|
output = QueuedTcpServerResponseHelperOption::setOption(_arg, _data, _token);
|
||||||
_token);
|
|
||||||
else
|
else
|
||||||
output = {{"code", 405}};
|
output = {{"code", 405}};
|
||||||
break;
|
break;
|
||||||
case QueuedTcpServerResponseHelper::RequestPath::Permissions:
|
case QueuedTcpServerResponseHelper::RequestPath::Permissions:
|
||||||
if (_type == "DELETE")
|
if (_type == "DELETE")
|
||||||
output = QueuedTcpServerResponseHelperPermissions::removePermission(
|
output = QueuedTcpServerResponseHelperPermissions::removePermission(_arg.toLongLong(),
|
||||||
_arg.toLongLong(), _data, _token);
|
_data, _token);
|
||||||
else if (_type == "POST")
|
else if (_type == "POST")
|
||||||
output = QueuedTcpServerResponseHelperPermissions::addPermission(
|
output = QueuedTcpServerResponseHelperPermissions::addPermission(_arg.toLongLong(),
|
||||||
_arg.toLongLong(), _data, _token);
|
_data, _token);
|
||||||
else
|
else
|
||||||
output = {{"code", 405}};
|
output = {{"code", 405}};
|
||||||
break;
|
break;
|
||||||
case QueuedTcpServerResponseHelper::RequestPath::Plugin:
|
case QueuedTcpServerResponseHelper::RequestPath::Plugin:
|
||||||
if (_type == "GET")
|
if (_type == "GET")
|
||||||
output
|
output = QueuedTcpServerResponseHelperPlugins::getPlugin(_arg, _token);
|
||||||
= QueuedTcpServerResponseHelperPlugins::getPlugin(_arg, _token);
|
|
||||||
else
|
else
|
||||||
output = {{"code", 405}};
|
output = {{"code", 405}};
|
||||||
break;
|
break;
|
||||||
case QueuedTcpServerResponseHelper::RequestPath::Plugins:
|
case QueuedTcpServerResponseHelper::RequestPath::Plugins:
|
||||||
if (_type == "DELETE")
|
if (_type == "DELETE")
|
||||||
output = QueuedTcpServerResponseHelperPlugins::removePlugin(_arg,
|
output = QueuedTcpServerResponseHelperPlugins::removePlugin(_arg, _token);
|
||||||
_token);
|
|
||||||
else if (_type == "GET")
|
else if (_type == "GET")
|
||||||
output = QueuedTcpServerResponseHelperPlugins::listPlugins();
|
output = QueuedTcpServerResponseHelperPlugins::listPlugins();
|
||||||
else if (_type == "POST")
|
else if (_type == "POST")
|
||||||
output
|
output = QueuedTcpServerResponseHelperPlugins::addPlugin(_arg, _token);
|
||||||
= QueuedTcpServerResponseHelperPlugins::addPlugin(_arg, _token);
|
|
||||||
else
|
else
|
||||||
output = {{"code", 405}};
|
output = {{"code", 405}};
|
||||||
break;
|
break;
|
||||||
case QueuedTcpServerResponseHelper::RequestPath::Reports:
|
case QueuedTcpServerResponseHelper::RequestPath::Reports:
|
||||||
if (_type == "GET")
|
if (_type == "GET")
|
||||||
output
|
output = QueuedTcpServerResponseHelperUser::getReport(_data, _token);
|
||||||
= QueuedTcpServerResponseHelperUser::getReport(_data, _token);
|
|
||||||
else
|
else
|
||||||
output = {{"code", 405}};
|
output = {{"code", 405}};
|
||||||
break;
|
break;
|
||||||
@ -102,14 +95,12 @@ QVariantHash QueuedTcpServerResponseHelperApi1::getData(
|
|||||||
break;
|
break;
|
||||||
case QueuedTcpServerResponseHelper::RequestPath::Task:
|
case QueuedTcpServerResponseHelper::RequestPath::Task:
|
||||||
if (_type == "GET")
|
if (_type == "GET")
|
||||||
output = QueuedTcpServerResponseHelperTask::getTask(
|
output = QueuedTcpServerResponseHelperTask::getTask(_arg.toLongLong(), _data, _token);
|
||||||
_arg.toLongLong(), _data, _token);
|
|
||||||
else if (_type == "POST")
|
else if (_type == "POST")
|
||||||
output = QueuedTcpServerResponseHelperTask::addOrEditTask(
|
output = QueuedTcpServerResponseHelperTask::addOrEditTask(_arg.toLongLong(), _data,
|
||||||
_arg.toLongLong(), _data, _token);
|
_token);
|
||||||
else if (_type == "PUT")
|
else if (_type == "PUT")
|
||||||
output = QueuedTcpServerResponseHelperTask::startOrStopTask(
|
output = QueuedTcpServerResponseHelperTask::startOrStopTask(_arg.toLongLong(), _token);
|
||||||
_arg.toLongLong(), _token);
|
|
||||||
else
|
else
|
||||||
output = {{"code", 405}};
|
output = {{"code", 405}};
|
||||||
break;
|
break;
|
||||||
@ -121,11 +112,9 @@ QVariantHash QueuedTcpServerResponseHelperApi1::getData(
|
|||||||
break;
|
break;
|
||||||
case QueuedTcpServerResponseHelper::RequestPath::User:
|
case QueuedTcpServerResponseHelper::RequestPath::User:
|
||||||
if (_type == "GET")
|
if (_type == "GET")
|
||||||
output = QueuedTcpServerResponseHelperUser::getUser(_arg, _data,
|
output = QueuedTcpServerResponseHelperUser::getUser(_arg, _data, _token);
|
||||||
_token);
|
|
||||||
else if (_type == "POST")
|
else if (_type == "POST")
|
||||||
output = QueuedTcpServerResponseHelperUser::addOrEditUser(
|
output = QueuedTcpServerResponseHelperUser::addOrEditUser(_arg, _data, _token);
|
||||||
_arg, _data, _token);
|
|
||||||
else
|
else
|
||||||
output = {{"code", 405}};
|
output = {{"code", 405}};
|
||||||
break;
|
break;
|
||||||
|
@ -24,9 +24,8 @@
|
|||||||
|
|
||||||
namespace QueuedTcpServerResponseHelperApi1
|
namespace QueuedTcpServerResponseHelperApi1
|
||||||
{
|
{
|
||||||
QVariantHash getData(const QueuedTcpServerResponseHelper::RequestPath _request,
|
QVariantHash getData(const QueuedTcpServerResponseHelper::RequestPath _request, const QString &_arg,
|
||||||
const QString &_arg, const QString &_type,
|
const QString &_type, const QVariantHash &_data, const QString &_token);
|
||||||
const QVariantHash &_data, const QString &_token);
|
|
||||||
QVariantHash getStatus();
|
QVariantHash getStatus();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,8 +25,7 @@ QVariantHash QueuedTcpServerResponseHelperAuth::auth(const QVariantHash &_data)
|
|||||||
|
|
||||||
QVariantHash output;
|
QVariantHash output;
|
||||||
if (_data.contains("user") && _data.contains("password")) {
|
if (_data.contains("user") && _data.contains("password")) {
|
||||||
auto res = QueuedCoreAdaptor::auth(_data["user"].toString(),
|
auto res = QueuedCoreAdaptor::auth(_data["user"].toString(), _data["password"].toString());
|
||||||
_data["password"].toString());
|
|
||||||
|
|
||||||
res.match(
|
res.match(
|
||||||
[&output](const QString &val) {
|
[&output](const QString &val) {
|
||||||
|
@ -19,9 +19,8 @@
|
|||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
|
||||||
|
|
||||||
QVariantHash
|
QVariantHash QueuedTcpServerResponseHelperOption::getOption(const QString &_option,
|
||||||
QueuedTcpServerResponseHelperOption::getOption(const QString &_option,
|
const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Get option" << _option;
|
qCDebug(LOG_SERV) << "Get option" << _option;
|
||||||
|
|
||||||
@ -41,16 +40,16 @@ QueuedTcpServerResponseHelperOption::getOption(const QString &_option,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash QueuedTcpServerResponseHelperOption::setOption(
|
QVariantHash QueuedTcpServerResponseHelperOption::setOption(const QString &_option,
|
||||||
const QString &_option, const QVariantHash &_value, const QString &_token)
|
const QVariantHash &_value,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Set option" << _option << "to" << _value;
|
qCDebug(LOG_SERV) << "Set option" << _option << "to" << _value;
|
||||||
|
|
||||||
if (!_value.contains("value"))
|
if (!_value.contains("value"))
|
||||||
return {{"code", 400}, {"message", "No required fields found"}};
|
return {{"code", 400}, {"message", "No required fields found"}};
|
||||||
|
|
||||||
auto res
|
auto res = QueuedCoreAdaptor::sendOptionEdit(_option, _value["value"], _token);
|
||||||
= QueuedCoreAdaptor::sendOptionEdit(_option, _value["value"], _token);
|
|
||||||
|
|
||||||
QVariantHash output;
|
QVariantHash output;
|
||||||
res.match(
|
res.match(
|
||||||
|
@ -23,8 +23,7 @@
|
|||||||
namespace QueuedTcpServerResponseHelperOption
|
namespace QueuedTcpServerResponseHelperOption
|
||||||
{
|
{
|
||||||
QVariantHash getOption(const QString &_option, const QString &_token);
|
QVariantHash getOption(const QString &_option, const QString &_token);
|
||||||
QVariantHash setOption(const QString &_option, const QVariantHash &_value,
|
QVariantHash setOption(const QString &_option, const QVariantHash &_value, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,21 +19,20 @@
|
|||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
|
||||||
|
|
||||||
QVariantHash QueuedTcpServerResponseHelperPermissions::addPermission(
|
QVariantHash QueuedTcpServerResponseHelperPermissions::addPermission(const long long _id,
|
||||||
const long long _id, const QVariantHash &_value, const QString &_token)
|
const QVariantHash &_value,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Add permission for" << _id << _value;
|
qCDebug(LOG_SERV) << "Add permission for" << _id << _value;
|
||||||
|
|
||||||
if (!_value.contains("permission"))
|
if (!_value.contains("permission"))
|
||||||
return {{"code", 400}, {"message", "No required fields found"}};
|
return {{"code", 400}, {"message", "No required fields found"}};
|
||||||
|
|
||||||
auto permission
|
auto permission = QueuedEnums::stringToPermission(_value["permission"].toString());
|
||||||
= QueuedEnums::stringToPermission(_value["permission"].toString());
|
|
||||||
if (permission == QueuedEnums::Permission::Invalid)
|
if (permission == QueuedEnums::Permission::Invalid)
|
||||||
return {{"code", 400}, {"message", "Invalid permission"}};
|
return {{"code", 400}, {"message", "Invalid permission"}};
|
||||||
|
|
||||||
auto res
|
auto res = QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission, _token);
|
||||||
= QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission, _token);
|
|
||||||
|
|
||||||
QVariantHash output;
|
QVariantHash output;
|
||||||
res.match(
|
res.match(
|
||||||
@ -48,21 +47,20 @@ QVariantHash QueuedTcpServerResponseHelperPermissions::addPermission(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash QueuedTcpServerResponseHelperPermissions::removePermission(
|
QVariantHash QueuedTcpServerResponseHelperPermissions::removePermission(const long long _id,
|
||||||
const long long _id, const QVariantHash &_value, const QString &_token)
|
const QVariantHash &_value,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Remove permission for" << _id << _value;
|
qCDebug(LOG_SERV) << "Remove permission for" << _id << _value;
|
||||||
|
|
||||||
if (!_value.contains("permission"))
|
if (!_value.contains("permission"))
|
||||||
return {{"code", 400}, {"message", "No required fields found"}};
|
return {{"code", 400}, {"message", "No required fields found"}};
|
||||||
|
|
||||||
auto permission
|
auto permission = QueuedEnums::stringToPermission(_value["permission"].toString());
|
||||||
= QueuedEnums::stringToPermission(_value["permission"].toString());
|
|
||||||
if (permission == QueuedEnums::Permission::Invalid)
|
if (permission == QueuedEnums::Permission::Invalid)
|
||||||
return {{"code", 400}, {"message", "Invalid permission"}};
|
return {{"code", 400}, {"message", "Invalid permission"}};
|
||||||
|
|
||||||
auto res
|
auto res = QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission, _token);
|
||||||
= QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission, _token);
|
|
||||||
|
|
||||||
QVariantHash output;
|
QVariantHash output;
|
||||||
res.match(
|
res.match(
|
||||||
|
@ -22,8 +22,7 @@
|
|||||||
|
|
||||||
namespace QueuedTcpServerResponseHelperPermissions
|
namespace QueuedTcpServerResponseHelperPermissions
|
||||||
{
|
{
|
||||||
QVariantHash addPermission(const long long _id, const QVariantHash &_value,
|
QVariantHash addPermission(const long long _id, const QVariantHash &_value, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
QVariantHash removePermission(const long long _id, const QVariantHash &_value,
|
QVariantHash removePermission(const long long _id, const QVariantHash &_value,
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
};
|
};
|
||||||
|
@ -19,9 +19,8 @@
|
|||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
|
||||||
|
|
||||||
QVariantHash
|
QVariantHash QueuedTcpServerResponseHelperPlugins::addPlugin(const QString &_name,
|
||||||
QueuedTcpServerResponseHelperPlugins::addPlugin(const QString &_name,
|
const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Add plugin" << _name;
|
qCDebug(LOG_SERV) << "Add plugin" << _name;
|
||||||
|
|
||||||
@ -40,9 +39,8 @@ QueuedTcpServerResponseHelperPlugins::addPlugin(const QString &_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash
|
QVariantHash QueuedTcpServerResponseHelperPlugins::getPlugin(const QString &_name,
|
||||||
QueuedTcpServerResponseHelperPlugins::getPlugin(const QString &_name,
|
const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Get plugin" << _name;
|
qCDebug(LOG_SERV) << "Get plugin" << _name;
|
||||||
|
|
||||||
@ -65,8 +63,7 @@ QueuedTcpServerResponseHelperPlugins::getPlugin(const QString &_name,
|
|||||||
|
|
||||||
QVariantHash QueuedTcpServerResponseHelperPlugins::listPlugins()
|
QVariantHash QueuedTcpServerResponseHelperPlugins::listPlugins()
|
||||||
{
|
{
|
||||||
auto res = QueuedCoreAdaptor::getOption(
|
auto res = QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::Plugins, "");
|
||||||
QueuedConfig::QueuedSettings::Plugins, "");
|
|
||||||
|
|
||||||
QVariantHash output;
|
QVariantHash output;
|
||||||
res.match(
|
res.match(
|
||||||
@ -81,9 +78,8 @@ QVariantHash QueuedTcpServerResponseHelperPlugins::listPlugins()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash
|
QVariantHash QueuedTcpServerResponseHelperPlugins::removePlugin(const QString &_name,
|
||||||
QueuedTcpServerResponseHelperPlugins::removePlugin(const QString &_name,
|
const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Remove plugin" << _name;
|
qCDebug(LOG_SERV) << "Remove plugin" << _name;
|
||||||
|
|
||||||
|
@ -19,8 +19,9 @@
|
|||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
|
||||||
|
|
||||||
QVariantHash QueuedTcpServerResponseHelperTask::addOrEditTask(
|
QVariantHash QueuedTcpServerResponseHelperTask::addOrEditTask(const long long _id,
|
||||||
const long long _id, const QVariantHash &_data, const QString &_token)
|
const QVariantHash &_data,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Add or edit task" << _id << "with data" << _data;
|
qCDebug(LOG_SERV) << "Add or edit task" << _id << "with data" << _data;
|
||||||
|
|
||||||
@ -63,12 +64,10 @@ QueuedTcpServerResponseHelperTask::getDefinitions(const QVariantHash &_data)
|
|||||||
for (auto &arg : args)
|
for (auto &arg : args)
|
||||||
defs.arguments.append(arg.toString());
|
defs.arguments.append(arg.toString());
|
||||||
defs.command = _data["command"].toString();
|
defs.command = _data["command"].toString();
|
||||||
defs.endTime
|
defs.endTime = QDateTime::fromString(_data["end"].toString(), Qt::ISODateWithMs);
|
||||||
= QDateTime::fromString(_data["end"].toString(), Qt::ISODateWithMs);
|
|
||||||
defs.gid = _data["gid"].toUInt();
|
defs.gid = _data["gid"].toUInt();
|
||||||
defs.nice = _data["nice"].toUInt();
|
defs.nice = _data["nice"].toUInt();
|
||||||
defs.startTime
|
defs.startTime = QDateTime::fromString(_data["start"].toString(), Qt::ISODateWithMs);
|
||||||
= QDateTime::fromString(_data["start"].toString(), Qt::ISODateWithMs);
|
|
||||||
defs.uid = _data["uid"].toUInt();
|
defs.uid = _data["uid"].toUInt();
|
||||||
defs.user = _data["user"].toLongLong();
|
defs.user = _data["user"].toLongLong();
|
||||||
defs.workingDirectory = _data["workingDirectory"].toString();
|
defs.workingDirectory = _data["workingDirectory"].toString();
|
||||||
@ -85,8 +84,9 @@ QueuedTcpServerResponseHelperTask::getDefinitions(const QVariantHash &_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash QueuedTcpServerResponseHelperTask::getTask(
|
QVariantHash QueuedTcpServerResponseHelperTask::getTask(const long long _id,
|
||||||
const long long _id, const QVariantHash &_data, const QString &_token)
|
const QVariantHash &_data,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Get task" << _id << _data;
|
qCDebug(LOG_SERV) << "Get task" << _id << _data;
|
||||||
|
|
||||||
@ -95,11 +95,10 @@ QVariantHash QueuedTcpServerResponseHelperTask::getTask(
|
|||||||
QVariantHash output = {{"code", 200}};
|
QVariantHash output = {{"code", 200}};
|
||||||
if (property.isEmpty()) {
|
if (property.isEmpty()) {
|
||||||
auto res = QueuedCoreAdaptor::getTask(_id, _token);
|
auto res = QueuedCoreAdaptor::getTask(_id, _token);
|
||||||
res.match(
|
res.match([&output](const QVariantHash &val) { output["properties"] = val; },
|
||||||
[&output](const QVariantHash &val) { output["properties"] = val; },
|
[&output](const QueuedError &err) {
|
||||||
[&output](const QueuedError &err) {
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
output = {{"code", 500}, {"message", err.message().c_str()}};
|
});
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
auto res = QueuedCoreAdaptor::getTask(_id, property);
|
auto res = QueuedCoreAdaptor::getTask(_id, property);
|
||||||
res.match(
|
res.match(
|
||||||
@ -115,17 +114,14 @@ QVariantHash QueuedTcpServerResponseHelperTask::getTask(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash
|
QVariantHash QueuedTcpServerResponseHelperTask::getTasks(const QVariantHash &_data,
|
||||||
QueuedTcpServerResponseHelperTask::getTasks(const QVariantHash &_data,
|
const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Get tasks" << _data;
|
qCDebug(LOG_SERV) << "Get tasks" << _data;
|
||||||
|
|
||||||
long long userId = _data.value("userId").toLongLong();
|
long long userId = _data.value("userId").toLongLong();
|
||||||
QDateTime start
|
QDateTime start = QDateTime::fromString(_data["start"].toString(), Qt::ISODateWithMs);
|
||||||
= QDateTime::fromString(_data["start"].toString(), Qt::ISODateWithMs);
|
QDateTime stop = QDateTime::fromString(_data["stop"].toString(), Qt::ISODateWithMs);
|
||||||
QDateTime stop
|
|
||||||
= QDateTime::fromString(_data["stop"].toString(), Qt::ISODateWithMs);
|
|
||||||
|
|
||||||
QVariantHash output;
|
QVariantHash output;
|
||||||
// some conversion magic
|
// some conversion magic
|
||||||
@ -145,9 +141,8 @@ QueuedTcpServerResponseHelperTask::getTasks(const QVariantHash &_data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash
|
QVariantHash QueuedTcpServerResponseHelperTask::startOrStopTask(const long long _id,
|
||||||
QueuedTcpServerResponseHelperTask::startOrStopTask(const long long _id,
|
const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Change task state" << _id;
|
qCDebug(LOG_SERV) << "Change task state" << _id;
|
||||||
|
|
||||||
@ -156,8 +151,7 @@ QueuedTcpServerResponseHelperTask::startOrStopTask(const long long _id,
|
|||||||
QVariantHash output;
|
QVariantHash output;
|
||||||
res.match(
|
res.match(
|
||||||
[&output, &_id, &_token](const QVariantHash &val) {
|
[&output, &_id, &_token](const QVariantHash &val) {
|
||||||
if (val["startTime"].toString().isEmpty()
|
if (val["startTime"].toString().isEmpty() || !val["endTime"].toString().isEmpty())
|
||||||
|| !val["endTime"].toString().isEmpty())
|
|
||||||
output = startTask(_id, _token);
|
output = startTask(_id, _token);
|
||||||
else
|
else
|
||||||
output = stopTask(_id, _token);
|
output = stopTask(_id, _token);
|
||||||
@ -190,8 +184,7 @@ QVariantHash QueuedTcpServerResponseHelperTask::startTask(const long long _id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash QueuedTcpServerResponseHelperTask::stopTask(const long long _id,
|
QVariantHash QueuedTcpServerResponseHelperTask::stopTask(const long long _id, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Stop task" << _id;
|
qCDebug(LOG_SERV) << "Stop task" << _id;
|
||||||
|
|
||||||
|
@ -24,12 +24,9 @@
|
|||||||
|
|
||||||
namespace QueuedTcpServerResponseHelperTask
|
namespace QueuedTcpServerResponseHelperTask
|
||||||
{
|
{
|
||||||
QVariantHash addOrEditTask(const long long _id, const QVariantHash &_data,
|
QVariantHash addOrEditTask(const long long _id, const QVariantHash &_data, const QString &_token);
|
||||||
const QString &_token);
|
QueuedProcess::QueuedProcessDefinitions getDefinitions(const QVariantHash &_data);
|
||||||
QueuedProcess::QueuedProcessDefinitions
|
QVariantHash getTask(const long long _id, const QVariantHash &_data, const QString &_token);
|
||||||
getDefinitions(const QVariantHash &_data);
|
|
||||||
QVariantHash getTask(const long long _id, const QVariantHash &_data,
|
|
||||||
const QString &_token);
|
|
||||||
QVariantHash getTasks(const QVariantHash &_data, const QString &_token);
|
QVariantHash getTasks(const QVariantHash &_data, const QString &_token);
|
||||||
QVariantHash startOrStopTask(const long long _id, const QString &_token);
|
QVariantHash startOrStopTask(const long long _id, const QString &_token);
|
||||||
QVariantHash startTask(const long long _id, const QString &_token);
|
QVariantHash startTask(const long long _id, const QString &_token);
|
||||||
|
@ -20,8 +20,9 @@
|
|||||||
#include <queued/QueuedUser.h>
|
#include <queued/QueuedUser.h>
|
||||||
|
|
||||||
|
|
||||||
QVariantHash QueuedTcpServerResponseHelperUser::addOrEditUser(
|
QVariantHash QueuedTcpServerResponseHelperUser::addOrEditUser(const QString &_user,
|
||||||
const QString &_user, const QVariantHash &_data, const QString &_token)
|
const QVariantHash &_data,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Add user" << _user << "with data" << _data;
|
qCDebug(LOG_SERV) << "Add user" << _user << "with data" << _data;
|
||||||
|
|
||||||
@ -68,10 +69,8 @@ QueuedTcpServerResponseHelperUser::getDefinitions(const QVariantHash &_data)
|
|||||||
|
|
||||||
QueuedUser::QueuedUserDefinitions defs;
|
QueuedUser::QueuedUserDefinitions defs;
|
||||||
defs.email = _data["email"].toString();
|
defs.email = _data["email"].toString();
|
||||||
auto res
|
auto res = QueuedCoreAdaptor::sendPasswordHash(_data["password"].toString());
|
||||||
= QueuedCoreAdaptor::sendPasswordHash(_data["password"].toString());
|
res.match([&defs](const QString &val) { defs.password = val; }, [](const QueuedError &) {});
|
||||||
res.match([&defs](const QString &val) { defs.password = val; },
|
|
||||||
[](const QueuedError &) {});
|
|
||||||
defs.permissions = _data["permissions"].toUInt();
|
defs.permissions = _data["permissions"].toUInt();
|
||||||
defs.priority = _data["priority"].toUInt();
|
defs.priority = _data["priority"].toUInt();
|
||||||
// limits
|
// limits
|
||||||
@ -87,16 +86,13 @@ QueuedTcpServerResponseHelperUser::getDefinitions(const QVariantHash &_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash
|
QVariantHash QueuedTcpServerResponseHelperUser::getReport(const QVariantHash &_data,
|
||||||
QueuedTcpServerResponseHelperUser::getReport(const QVariantHash &_data,
|
const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Get report using payload" << _data;
|
qCDebug(LOG_SERV) << "Get report using payload" << _data;
|
||||||
|
|
||||||
QDateTime stop
|
QDateTime stop = QDateTime::fromString(_data["stop"].toString(), Qt::ISODateWithMs);
|
||||||
= QDateTime::fromString(_data["stop"].toString(), Qt::ISODateWithMs);
|
QDateTime start = QDateTime::fromString(_data["start"].toString(), Qt::ISODateWithMs);
|
||||||
QDateTime start
|
|
||||||
= QDateTime::fromString(_data["start"].toString(), Qt::ISODateWithMs);
|
|
||||||
|
|
||||||
QVariantHash output = {{"code", 200}};
|
QVariantHash output = {{"code", 200}};
|
||||||
// some conversion magic
|
// some conversion magic
|
||||||
@ -116,15 +112,15 @@ QueuedTcpServerResponseHelperUser::getReport(const QVariantHash &_data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash QueuedTcpServerResponseHelperUser::getUser(
|
QVariantHash QueuedTcpServerResponseHelperUser::getUser(const QString &_user,
|
||||||
const QString &_user, const QVariantHash &_data, const QString &_token)
|
const QVariantHash &_data,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Get user data for" << _user << _data;
|
qCDebug(LOG_SERV) << "Get user data for" << _user << _data;
|
||||||
|
|
||||||
auto userIdRes = QueuedCoreAdaptor::getUserId(_user, _token);
|
auto userIdRes = QueuedCoreAdaptor::getUserId(_user, _token);
|
||||||
long long userId = -1;
|
long long userId = -1;
|
||||||
userIdRes.match([&userId](const long long val) { userId = val; },
|
userIdRes.match([&userId](const long long val) { userId = val; }, [](const QueuedError &) {});
|
||||||
[](const QueuedError &) {});
|
|
||||||
if (userId == -1)
|
if (userId == -1)
|
||||||
return {{"code", 500}};
|
return {{"code", 500}};
|
||||||
|
|
||||||
@ -133,11 +129,10 @@ QVariantHash QueuedTcpServerResponseHelperUser::getUser(
|
|||||||
QVariantHash output = {{"code", 200}};
|
QVariantHash output = {{"code", 200}};
|
||||||
if (property.isEmpty()) {
|
if (property.isEmpty()) {
|
||||||
auto res = QueuedCoreAdaptor::getUser(userId, _token);
|
auto res = QueuedCoreAdaptor::getUser(userId, _token);
|
||||||
res.match(
|
res.match([&output](const QVariantHash &val) { output["properties"] = val; },
|
||||||
[&output](const QVariantHash &val) { output["properties"] = val; },
|
[&output](const QueuedError &err) {
|
||||||
[&output](const QueuedError &err) {
|
output = {{"code", 500}, {"message", err.message().c_str()}};
|
||||||
output = {{"code", 500}, {"message", err.message().c_str()}};
|
});
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
auto res = QueuedCoreAdaptor::getUser(userId, property);
|
auto res = QueuedCoreAdaptor::getUser(userId, property);
|
||||||
res.match(
|
res.match(
|
||||||
@ -153,16 +148,13 @@ QVariantHash QueuedTcpServerResponseHelperUser::getUser(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantHash
|
QVariantHash QueuedTcpServerResponseHelperUser::getUsers(const QVariantHash &_data,
|
||||||
QueuedTcpServerResponseHelperUser::getUsers(const QVariantHash &_data,
|
const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Get users" << _data;
|
qCDebug(LOG_SERV) << "Get users" << _data;
|
||||||
|
|
||||||
QDateTime lastLogin = QDateTime::fromString(_data["lastLogged"].toString(),
|
QDateTime lastLogin = QDateTime::fromString(_data["lastLogged"].toString(), Qt::ISODateWithMs);
|
||||||
Qt::ISODateWithMs);
|
auto permission = QueuedEnums::stringToPermission(_data["permission"].toString());
|
||||||
auto permission
|
|
||||||
= QueuedEnums::stringToPermission(_data["permission"].toString());
|
|
||||||
|
|
||||||
QVariantHash output = {{"code", 200}};
|
QVariantHash output = {{"code", 200}};
|
||||||
// some conversion magic
|
// some conversion magic
|
||||||
|
@ -24,12 +24,10 @@
|
|||||||
|
|
||||||
namespace QueuedTcpServerResponseHelperUser
|
namespace QueuedTcpServerResponseHelperUser
|
||||||
{
|
{
|
||||||
QVariantHash addOrEditUser(const QString &_user, const QVariantHash &_data,
|
QVariantHash addOrEditUser(const QString &_user, const QVariantHash &_data, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
QueuedUser::QueuedUserDefinitions getDefinitions(const QVariantHash &_data);
|
QueuedUser::QueuedUserDefinitions getDefinitions(const QVariantHash &_data);
|
||||||
QVariantHash getReport(const QVariantHash &_data, const QString &_token);
|
QVariantHash getReport(const QVariantHash &_data, const QString &_token);
|
||||||
QVariantHash getUser(const QString &_user, const QVariantHash &_data,
|
QVariantHash getUser(const QString &_user, const QVariantHash &_data, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
QVariantHash getUsers(const QVariantHash &_data, const QString &_token);
|
QVariantHash getUsers(const QVariantHash &_data, const QString &_token);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@
|
|||||||
#include "QueuedTcpServerResponseHelper.h"
|
#include "QueuedTcpServerResponseHelper.h"
|
||||||
|
|
||||||
|
|
||||||
QueuedTcpServerThread::QueuedTcpServerThread(int socketDescriptor,
|
QueuedTcpServerThread::QueuedTcpServerThread(int socketDescriptor, const int timeout,
|
||||||
const int timeout, QObject *parent)
|
QObject *parent)
|
||||||
: QThread(parent)
|
: QThread(parent)
|
||||||
, m_socketDescriptor(socketDescriptor)
|
, m_socketDescriptor(socketDescriptor)
|
||||||
, m_timeout(timeout)
|
, m_timeout(timeout)
|
||||||
@ -46,11 +46,9 @@ QueuedTcpServerThread::~QueuedTcpServerThread()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QByteArrayList QueuedTcpServerThread::defaultResponse(const int code,
|
QByteArrayList QueuedTcpServerThread::defaultResponse(const int code, const QVariantHash &json)
|
||||||
const QVariantHash &json)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Build server response with code" << code
|
qCDebug(LOG_SERV) << "Build server response with code" << code << "and json";
|
||||||
<< "and json";
|
|
||||||
|
|
||||||
QList<QByteArray> output;
|
QList<QByteArray> output;
|
||||||
output += "HTTP/1.1 " + QByteArray::number(code) + " "
|
output += "HTTP/1.1 " + QByteArray::number(code) + " "
|
||||||
@ -58,8 +56,7 @@ QByteArrayList QueuedTcpServerThread::defaultResponse(const int code,
|
|||||||
output += "Server: QueuedServer/Qt" + QByteArray(qVersion()) + "\r\n";
|
output += "Server: QueuedServer/Qt" + QByteArray(qVersion()) + "\r\n";
|
||||||
output += "Date: "
|
output += "Date: "
|
||||||
+ QLocale::c()
|
+ QLocale::c()
|
||||||
.toString(QDateTime::currentDateTimeUtc(),
|
.toString(QDateTime::currentDateTimeUtc(), "ddd, d MMM yyyy HH:mm:dd t")
|
||||||
"ddd, d MMM yyyy HH:mm:dd t")
|
|
||||||
.toUtf8()
|
.toUtf8()
|
||||||
+ "\r\n";
|
+ "\r\n";
|
||||||
output += "Content-Type: application/json\r\n";
|
output += "Content-Type: application/json\r\n";
|
||||||
@ -68,8 +65,7 @@ QByteArrayList QueuedTcpServerThread::defaultResponse(const int code,
|
|||||||
// json response
|
// json response
|
||||||
if (!json.isEmpty()) {
|
if (!json.isEmpty()) {
|
||||||
auto jsonObj = QJsonObject::fromVariantHash(json);
|
auto jsonObj = QJsonObject::fromVariantHash(json);
|
||||||
auto jsonByte
|
auto jsonByte = QJsonDocument(jsonObj).toJson(QJsonDocument::JsonFormat::Compact);
|
||||||
= QJsonDocument(jsonObj).toJson(QJsonDocument::JsonFormat::Compact);
|
|
||||||
output += jsonByte;
|
output += jsonByte;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,17 +93,16 @@ QueuedTcpServerThread::getHeaders(const QStringList &headers)
|
|||||||
if (parsed.count() < 2)
|
if (parsed.count() < 2)
|
||||||
continue;
|
continue;
|
||||||
headersObj.headers += QPair<QByteArray, QByteArray>(
|
headersObj.headers += QPair<QByteArray, QByteArray>(
|
||||||
{parsed.first().toUtf8().toLower(),
|
{parsed.first().toUtf8().toLower(), parsed.mid(1).join(": ").toUtf8()});
|
||||||
parsed.mid(1).join(": ").toUtf8()});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return headersObj;
|
return headersObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedTcpServerThread::QueuedTcpServerRequest QueuedTcpServerThread::getRequest(
|
QueuedTcpServerThread::QueuedTcpServerRequest
|
||||||
const QByteArray &body,
|
QueuedTcpServerThread::getRequest(const QByteArray &body,
|
||||||
const QueuedTcpServerThread::QueuedTcpServerHeaders &headers)
|
const QueuedTcpServerThread::QueuedTcpServerHeaders &headers)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_SERV) << "Get request object from body" << body;
|
qCDebug(LOG_SERV) << "Get request object from body" << body;
|
||||||
|
|
||||||
@ -159,8 +154,7 @@ QueuedTcpServerThread::response(const QueuedTcpServerRequest &request) const
|
|||||||
netRequest.setRawHeader(headers.first, headers.second);
|
netRequest.setRawHeader(headers.first, headers.second);
|
||||||
|
|
||||||
// prepend code
|
// prepend code
|
||||||
if (netRequest.header(QNetworkRequest::KnownHeaders::ContentTypeHeader)
|
if (netRequest.header(QNetworkRequest::KnownHeaders::ContentTypeHeader).toString()
|
||||||
.toString()
|
|
||||||
!= "application/json")
|
!= "application/json")
|
||||||
response.code = 415;
|
response.code = 415;
|
||||||
else
|
else
|
||||||
@ -169,12 +163,10 @@ QueuedTcpServerThread::response(const QueuedTcpServerRequest &request) const
|
|||||||
|
|
||||||
// json data
|
// json data
|
||||||
if (response.code == 200) {
|
if (response.code == 200) {
|
||||||
auto req = QueuedTcpServerResponseHelper::parsePath(
|
auto req = QueuedTcpServerResponseHelper::parsePath(request.headers.query.path());
|
||||||
request.headers.query.path());
|
|
||||||
req.type = request.headers.request;
|
req.type = request.headers.request;
|
||||||
if (req.valid) {
|
if (req.valid) {
|
||||||
response.data = QueuedTcpServerResponseHelper::getData(
|
response.data = QueuedTcpServerResponseHelper::getData(req, request.data, token);
|
||||||
req, request.data, token);
|
|
||||||
response.code = response.data["code"].toInt();
|
response.code = response.data["code"].toInt();
|
||||||
} else {
|
} else {
|
||||||
response.code = 404;
|
response.code = 404;
|
||||||
@ -193,8 +185,7 @@ void QueuedTcpServerThread::run()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(m_socket, SIGNAL(readyRead()), this, SLOT(readyRead()),
|
connect(m_socket, SIGNAL(readyRead()), this, SLOT(readyRead()), Qt::DirectConnection);
|
||||||
Qt::DirectConnection);
|
|
||||||
|
|
||||||
exec();
|
exec();
|
||||||
}
|
}
|
||||||
|
@ -44,16 +44,13 @@ public:
|
|||||||
QVariantHash data;
|
QVariantHash data;
|
||||||
} QueuedTcpServerResponse;
|
} QueuedTcpServerResponse;
|
||||||
|
|
||||||
explicit QueuedTcpServerThread(int socketDescriptor, const int timeout,
|
explicit QueuedTcpServerThread(int socketDescriptor, const int timeout, QObject *parent);
|
||||||
QObject *parent);
|
|
||||||
virtual ~QueuedTcpServerThread();
|
virtual ~QueuedTcpServerThread();
|
||||||
static QByteArrayList defaultResponse(const int code,
|
static QByteArrayList defaultResponse(const int code, const QVariantHash &json);
|
||||||
const QVariantHash &json);
|
|
||||||
static QueuedTcpServerHeaders getHeaders(const QStringList &headers);
|
static QueuedTcpServerHeaders getHeaders(const QStringList &headers);
|
||||||
static QueuedTcpServerRequest
|
static QueuedTcpServerRequest getRequest(const QByteArray &body,
|
||||||
getRequest(const QByteArray &body, const QueuedTcpServerHeaders &headers);
|
const QueuedTcpServerHeaders &headers);
|
||||||
QueuedTcpServerResponse
|
QueuedTcpServerResponse response(const QueuedTcpServerRequest &request) const;
|
||||||
response(const QueuedTcpServerRequest &request) const;
|
|
||||||
void run() override;
|
void run() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -50,8 +50,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// parser
|
// parser
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription(
|
parser.setApplicationDescription("Daemon for starting jobs to queue of calculations");
|
||||||
"Daemon for starting jobs to queue of calculations");
|
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
parser.addVersionOption();
|
parser.addVersionOption();
|
||||||
// info
|
// info
|
||||||
|
@ -114,8 +114,7 @@ static const char CG_FS_PATH[] = "/sys/fs/cgroup";
|
|||||||
* @brief plugin interface name
|
* @brief plugin interface name
|
||||||
* @remark required by Qt macro
|
* @remark required by Qt macro
|
||||||
*/
|
*/
|
||||||
#define PLUGIN_INTERFACE_NAME \
|
#define PLUGIN_INTERFACE_NAME "org.queued.plugin/@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@"
|
||||||
"org.queued.plugin/@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@"
|
|
||||||
/**
|
/**
|
||||||
* @brief plugin interface name
|
* @brief plugin interface name
|
||||||
*/
|
*/
|
||||||
|
@ -130,8 +130,8 @@ signals:
|
|||||||
* @param _value
|
* @param _value
|
||||||
* changed value
|
* changed value
|
||||||
*/
|
*/
|
||||||
void valueUpdated(const QueuedConfig::QueuedSettings _id,
|
void valueUpdated(const QueuedConfig::QueuedSettings _id, const QString &_key,
|
||||||
const QString &_key, const QVariant &_value);
|
const QVariant &_value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
|
@ -90,11 +90,9 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return task ID or -1 if no task added
|
* @return task ID or -1 if no task added
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long> addTask(const QString &_command,
|
QueuedResult<long long> addTask(const QString &_command, const QStringList &_arguments,
|
||||||
const QStringList &_arguments,
|
const QString &_workingDirectory, const long long _userId,
|
||||||
const QString &_workingDirectory,
|
const uint _nice, const QueuedLimits::Limits &_limits,
|
||||||
const long long _userId, const uint _nice,
|
|
||||||
const QueuedLimits::Limits &_limits,
|
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief add new user
|
* @brief add new user
|
||||||
@ -115,10 +113,8 @@ public:
|
|||||||
* @return user ID or -1 if no user created
|
* @return user ID or -1 if no user created
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long> addUser(const QString &_name, const QString &_email,
|
QueuedResult<long long> addUser(const QString &_name, const QString &_email,
|
||||||
const QString &_password,
|
const QString &_password, const uint _permissions,
|
||||||
const uint _permissions,
|
const uint _priority, const QueuedLimits::Limits &_limits,
|
||||||
const uint _priority,
|
|
||||||
const QueuedLimits::Limits &_limits,
|
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief try to authorize by given token
|
* @brief try to authorize by given token
|
||||||
@ -135,8 +131,7 @@ public:
|
|||||||
* user password
|
* user password
|
||||||
* @return token. It will be empty if authorization error occurs
|
* @return token. It will be empty if authorization error occurs
|
||||||
*/
|
*/
|
||||||
QueuedResult<QString> authorization(const QString &_name,
|
QueuedResult<QString> authorization(const QString &_name, const QString &_password);
|
||||||
const QString &_password);
|
|
||||||
/**
|
/**
|
||||||
* @brief edit advanced settings
|
* @brief edit advanced settings
|
||||||
* @param _key
|
* @param _key
|
||||||
@ -161,8 +156,7 @@ public:
|
|||||||
* fields will be ignored. No need to pass all properties here
|
* fields will be ignored. No need to pass all properties here
|
||||||
* @return true on successful task edition
|
* @return true on successful task edition
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> editTask(const long long _id,
|
QueuedResult<bool> editTask(const long long _id, const QVariantHash &_taskData,
|
||||||
const QVariantHash &_taskData,
|
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief edit user
|
* @brief edit user
|
||||||
@ -176,8 +170,7 @@ public:
|
|||||||
* fields will be ignored. No need to pass all properties here
|
* fields will be ignored. No need to pass all properties here
|
||||||
* @return true on successful user edition
|
* @return true on successful user edition
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> editUser(const long long _id,
|
QueuedResult<bool> editUser(const long long _id, const QVariantHash &_userData,
|
||||||
const QVariantHash &_userData,
|
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief edit user permissions
|
* @brief edit user permissions
|
||||||
@ -191,10 +184,9 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return true on successful user permission edition
|
* @return true on successful user permission edition
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool>
|
QueuedResult<bool> editUserPermission(const long long _id,
|
||||||
editUserPermission(const long long _id,
|
const QueuedEnums::Permission &_permission,
|
||||||
const QueuedEnums::Permission &_permission,
|
const bool _add, const QString &_token);
|
||||||
const bool _add, const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief hash password
|
* @brief hash password
|
||||||
* @param _password
|
* @param _password
|
||||||
@ -222,8 +214,7 @@ public:
|
|||||||
* @return performance table
|
* @return performance table
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>>
|
QueuedResult<QList<QVariantHash>>
|
||||||
performanceReport(const QDateTime &_from, const QDateTime &_to,
|
performanceReport(const QDateTime &_from, const QDateTime &_to, const QString &_token) const;
|
||||||
const QString &_token) const;
|
|
||||||
/**
|
/**
|
||||||
* @brief get plugin description
|
* @brief get plugin description
|
||||||
* @param _plugin
|
* @param _plugin
|
||||||
@ -232,8 +223,8 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return dictionary of PluginSpecification representation
|
* @return dictionary of PluginSpecification representation
|
||||||
*/
|
*/
|
||||||
QueuedResult<QueuedPluginSpecification::Plugin>
|
QueuedResult<QueuedPluginSpecification::Plugin> plugin(const QString &_plugin,
|
||||||
plugin(const QString &_plugin, const QString &_token);
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief get plugin settings
|
* @brief get plugin settings
|
||||||
* @param _plugin
|
* @param _plugin
|
||||||
@ -242,8 +233,7 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return hash of plugin settings
|
* @return hash of plugin settings
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariantHash> pluginSettings(const QString &_plugin,
|
QueuedResult<QVariantHash> pluginSettings(const QString &_plugin, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief remove plugin from autoload and unload it now
|
* @brief remove plugin from autoload and unload it now
|
||||||
* @param _plugin
|
* @param _plugin
|
||||||
@ -252,8 +242,7 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return true on successful plugin removal
|
* @return true on successful plugin removal
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> removePlugin(const QString &_plugin,
|
QueuedResult<bool> removePlugin(const QString &_plugin, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief force start task
|
* @brief force start task
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -293,10 +282,8 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return list of tasks in database format
|
* @return list of tasks in database format
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>> taskReport(const long long _user,
|
QueuedResult<QList<QVariantHash>> taskReport(const long long _user, const QDateTime &_from,
|
||||||
const QDateTime &_from,
|
const QDateTime &_to, const QString &_token) const;
|
||||||
const QDateTime &_to,
|
|
||||||
const QString &_token) const;
|
|
||||||
/**
|
/**
|
||||||
* @brief get user by ID
|
* @brief get user by ID
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -325,10 +312,9 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return list of users in database format
|
* @return list of users in database format
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>>
|
QueuedResult<QList<QVariantHash>> userReport(const QDateTime &_lastLogged,
|
||||||
userReport(const QDateTime &_lastLogged,
|
const QueuedEnums::Permission _permission,
|
||||||
const QueuedEnums::Permission _permission,
|
const QString &_token) const;
|
||||||
const QString &_token) const;
|
|
||||||
// control methods
|
// control methods
|
||||||
/**
|
/**
|
||||||
* @brief deinit subclasses
|
* @brief deinit subclasses
|
||||||
|
@ -95,8 +95,7 @@ QueuedResult<bool> sendPluginAdd(const QString &_plugin, const QString &_token);
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful plugin removal
|
* @return true on successful plugin removal
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> sendPluginRemove(const QString &_plugin,
|
QueuedResult<bool> sendPluginRemove(const QString &_plugin, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief send TaskAdd
|
* @brief send TaskAdd
|
||||||
* @param _definitions
|
* @param _definitions
|
||||||
@ -105,9 +104,8 @@ QueuedResult<bool> sendPluginRemove(const QString &_plugin,
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return task ID or {0, -1} if no task added
|
* @return task ID or {0, -1} if no task added
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long>
|
QueuedResult<long long> sendTaskAdd(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
sendTaskAdd(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief send TaskEdit
|
* @brief send TaskEdit
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -118,10 +116,9 @@ sendTaskAdd(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful task edition
|
* @return true on successful task edition
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool>
|
QueuedResult<bool> sendTaskEdit(const long long _id,
|
||||||
sendTaskEdit(const long long _id,
|
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief send TaskStart
|
* @brief send TaskStart
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -148,9 +145,8 @@ QueuedResult<bool> sendTaskStop(const long long _id, const QString &_token);
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return user ID or -1 if no user added
|
* @return user ID or -1 if no user added
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long>
|
QueuedResult<long long> sendUserAdd(const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
sendUserAdd(const QueuedUser::QueuedUserDefinitions &_definitions,
|
const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief send UserEdit
|
* @brief send UserEdit
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -161,10 +157,9 @@ sendUserAdd(const QueuedUser::QueuedUserDefinitions &_definitions,
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful user edition
|
* @return true on successful user edition
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool>
|
QueuedResult<bool> sendUserEdit(const long long _id,
|
||||||
sendUserEdit(const long long _id,
|
const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
const QueuedUser::QueuedUserDefinitions &_definitions,
|
const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief send UserPermissionsAdd
|
* @brief send UserPermissionsAdd
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -175,10 +170,9 @@ sendUserEdit(const long long _id,
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful permission addition
|
* @return true on successful permission addition
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool>
|
QueuedResult<bool> sendUserPermissionAdd(const long long _id,
|
||||||
sendUserPermissionAdd(const long long _id,
|
const QueuedEnums::Permission _permission,
|
||||||
const QueuedEnums::Permission _permission,
|
const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief send sendUserPermissionRemove
|
* @brief send sendUserPermissionRemove
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -189,10 +183,9 @@ sendUserPermissionAdd(const long long _id,
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful permission removal
|
* @return true on successful permission removal
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool>
|
QueuedResult<bool> sendUserPermissionRemove(const long long _id,
|
||||||
sendUserPermissionRemove(const long long _id,
|
const QueuedEnums::Permission _permission,
|
||||||
const QueuedEnums::Permission _permission,
|
const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
// specific methods for properties
|
// specific methods for properties
|
||||||
/**
|
/**
|
||||||
* @brief get plugin
|
* @brief get plugin
|
||||||
@ -202,8 +195,8 @@ sendUserPermissionRemove(const long long _id,
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return plugin specification body
|
* @return plugin specification body
|
||||||
*/
|
*/
|
||||||
QueuedResult<QueuedPluginSpecification::Plugin>
|
QueuedResult<QueuedPluginSpecification::Plugin> getPlugin(const QString &_plugin,
|
||||||
getPlugin(const QString &_plugin, const QString &_token);
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief get plugin options
|
* @brief get plugin options
|
||||||
* @param _plugin
|
* @param _plugin
|
||||||
@ -212,8 +205,7 @@ getPlugin(const QString &_plugin, const QString &_token);
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return plugin options dictionary
|
* @return plugin options dictionary
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariantHash> getPluginOptions(const QString &_plugin,
|
QueuedResult<QVariantHash> getPluginOptions(const QString &_plugin, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief get option
|
* @brief get option
|
||||||
* @param _property
|
* @param _property
|
||||||
@ -222,8 +214,7 @@ QueuedResult<QVariantHash> getPluginOptions(const QString &_plugin,
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return option value
|
* @return option value
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant> getOption(const QString &_property,
|
QueuedResult<QVariant> getOption(const QString &_property, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief get option
|
* @brief get option
|
||||||
* @param _property
|
* @param _property
|
||||||
@ -244,8 +235,7 @@ QueuedResult<QVariant> getOption(const QueuedConfig::QueuedSettings _property,
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return list of user with used resources
|
* @return list of user with used resources
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>> getPerformance(const QDateTime &_from,
|
QueuedResult<QList<QVariantHash>> getPerformance(const QDateTime &_from, const QDateTime &_to,
|
||||||
const QDateTime &_to,
|
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief server status
|
* @brief server status
|
||||||
@ -285,10 +275,8 @@ QueuedResult<QVariant> getTask(const long long _id, const QString &_property,
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return list of task in database representation
|
* @return list of task in database representation
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>> getTasks(const long long _user,
|
QueuedResult<QList<QVariantHash>> getTasks(const long long _user, const QDateTime &_from,
|
||||||
const QDateTime &_from,
|
const QDateTime &_to, const QString &_token);
|
||||||
const QDateTime &_to,
|
|
||||||
const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief get user properties
|
* @brief get user properties
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -330,9 +318,9 @@ QueuedResult<long long> getUserId(const QString &_name, const QString &_token);
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return list of users in database representation
|
* @return list of users in database representation
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>>
|
QueuedResult<QList<QVariantHash>> getUsers(const QDateTime &_lastLogged,
|
||||||
getUsers(const QDateTime &_lastLogged,
|
const QueuedEnums::Permission _permission,
|
||||||
const QueuedEnums::Permission _permission, const QString &_token);
|
const QString &_token);
|
||||||
// common methods
|
// common methods
|
||||||
/**
|
/**
|
||||||
* @brief additional method to avoid conversion from QueuedResult to
|
* @brief additional method to avoid conversion from QueuedResult to
|
||||||
@ -380,13 +368,11 @@ QueuedResult<T> sendRequest(const QString &_service, const QString &_path,
|
|||||||
const QVariantList &_args)
|
const QVariantList &_args)
|
||||||
{
|
{
|
||||||
QDBusConnection bus = QDBusConnection::systemBus();
|
QDBusConnection bus = QDBusConnection::systemBus();
|
||||||
QDBusMessage request
|
QDBusMessage request = QDBusMessage::createMethodCall(_service, _path, _interface, _cmd);
|
||||||
= QDBusMessage::createMethodCall(_service, _path, _interface, _cmd);
|
|
||||||
if (!_args.isEmpty())
|
if (!_args.isEmpty())
|
||||||
request.setArguments(_args);
|
request.setArguments(_args);
|
||||||
|
|
||||||
QDBusReply<QDBusVariant> dbusResponse
|
QDBusReply<QDBusVariant> dbusResponse = bus.call(request, QDBus::BlockWithGui);
|
||||||
= bus.call(request, QDBus::BlockWithGui);
|
|
||||||
|
|
||||||
if (dbusResponse.isValid()) {
|
if (dbusResponse.isValid()) {
|
||||||
auto response = dbusResponse.value();
|
auto response = dbusResponse.value();
|
||||||
|
@ -72,8 +72,7 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful option edition
|
* @return true on successful option edition
|
||||||
*/
|
*/
|
||||||
QDBusVariant OptionEdit(const QString &key, const QDBusVariant &value,
|
QDBusVariant OptionEdit(const QString &key, const QDBusVariant &value, const QString &token);
|
||||||
const QString &token);
|
|
||||||
/**
|
/**
|
||||||
* @brief get password hash
|
* @brief get password hash
|
||||||
* @param password
|
* @param password
|
||||||
@ -126,11 +125,9 @@ public slots:
|
|||||||
* @return task ID or -1 if no task added
|
* @return task ID or -1 if no task added
|
||||||
*/
|
*/
|
||||||
QDBusVariant TaskAdd(const QString &command, const QStringList &arguments,
|
QDBusVariant TaskAdd(const QString &command, const QStringList &arguments,
|
||||||
const QString &workingDirectory, const qlonglong user,
|
const QString &workingDirectory, const qlonglong user, const uint nice,
|
||||||
const uint nice, const qlonglong cpu,
|
const qlonglong cpu, const qlonglong gpu, const qlonglong memory,
|
||||||
const qlonglong gpu, const qlonglong memory,
|
const qlonglong gpumemory, const qlonglong storage, const QString &token);
|
||||||
const qlonglong gpumemory, const qlonglong storage,
|
|
||||||
const QString &token);
|
|
||||||
/**
|
/**
|
||||||
* @brief edit task
|
* @brief edit task
|
||||||
* @param id
|
* @param id
|
||||||
@ -163,11 +160,9 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful task edition
|
* @return true on successful task edition
|
||||||
*/
|
*/
|
||||||
QDBusVariant TaskEdit(const qlonglong id, const QString &command,
|
QDBusVariant TaskEdit(const qlonglong id, const QString &command, const QStringList &arguments,
|
||||||
const QStringList &arguments,
|
const QString &directory, const uint nice, const uint uid, const uint gid,
|
||||||
const QString &directory, const uint nice,
|
const qlonglong user, const qlonglong cpu, const qlonglong gpu,
|
||||||
const uint uid, const uint gid, const qlonglong user,
|
|
||||||
const qlonglong cpu, const qlonglong gpu,
|
|
||||||
const qlonglong memory, const qlonglong gpumemory,
|
const qlonglong memory, const qlonglong gpumemory,
|
||||||
const qlonglong storage, const QString &token);
|
const qlonglong storage, const QString &token);
|
||||||
/**
|
/**
|
||||||
@ -221,12 +216,10 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return user ID or -1 if no user found
|
* @return user ID or -1 if no user found
|
||||||
*/
|
*/
|
||||||
QDBusVariant UserAdd(const QString &name, const QString &email,
|
QDBusVariant UserAdd(const QString &name, const QString &email, const QString &password,
|
||||||
const QString &password, const uint permissions,
|
const uint permissions, const uint priority, const qlonglong cpu,
|
||||||
const uint priority, const qlonglong cpu,
|
const qlonglong gpu, const qlonglong memory, const qlonglong gpumemory,
|
||||||
const qlonglong gpu, const qlonglong memory,
|
const qlonglong storage, const QString &token);
|
||||||
const qlonglong gpumemory, const qlonglong storage,
|
|
||||||
const QString &token);
|
|
||||||
/**
|
/**
|
||||||
* @brief edit user
|
* @brief edit user
|
||||||
* @param id
|
* @param id
|
||||||
@ -251,9 +244,8 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful user edition
|
* @return true on successful user edition
|
||||||
*/
|
*/
|
||||||
QDBusVariant UserEdit(const qlonglong id, const QString &name,
|
QDBusVariant UserEdit(const qlonglong id, const QString &name, const QString &password,
|
||||||
const QString &password, const QString &email,
|
const QString &email, const qlonglong cpu, const qlonglong gpu,
|
||||||
const qlonglong cpu, const qlonglong gpu,
|
|
||||||
const qlonglong memory, const qlonglong gpumemory,
|
const qlonglong memory, const qlonglong gpumemory,
|
||||||
const qlonglong storage, const QString &token);
|
const qlonglong storage, const QString &token);
|
||||||
/**
|
/**
|
||||||
@ -266,8 +258,7 @@ public slots:
|
|||||||
* auth user token
|
* auth user token
|
||||||
* @return true on successful permission addition
|
* @return true on successful permission addition
|
||||||
*/
|
*/
|
||||||
QDBusVariant UserPermissionAdd(const qlonglong id, const uint permission,
|
QDBusVariant UserPermissionAdd(const qlonglong id, const uint permission, const QString &token);
|
||||||
const QString &token);
|
|
||||||
/**
|
/**
|
||||||
* @brief remove permission from user
|
* @brief remove permission from user
|
||||||
* @param id
|
* @param id
|
||||||
|
@ -47,8 +47,7 @@ public:
|
|||||||
* @param driver
|
* @param driver
|
||||||
* database driver
|
* database driver
|
||||||
*/
|
*/
|
||||||
explicit QueuedDatabase(QObject *parent, const QString path,
|
explicit QueuedDatabase(QObject *parent, const QString path, const QString driver);
|
||||||
const QString driver);
|
|
||||||
/**
|
/**
|
||||||
* @brief QueuedDatabase class destructor
|
* @brief QueuedDatabase class destructor
|
||||||
*/
|
*/
|
||||||
@ -89,8 +88,7 @@ public:
|
|||||||
* optional condition string
|
* optional condition string
|
||||||
* @return list of records from table
|
* @return list of records from table
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> get(const QString &_table,
|
QList<QVariantHash> get(const QString &_table, const QString &_condition = "");
|
||||||
const QString &_condition = "");
|
|
||||||
/**
|
/**
|
||||||
* @brief get record from table with given id
|
* @brief get record from table with given id
|
||||||
* @param _table
|
* @param _table
|
||||||
@ -112,8 +110,8 @@ public:
|
|||||||
* password to connect, will be ignored if _username is empty
|
* password to connect, will be ignored if _username is empty
|
||||||
* @return true on successful opening
|
* @return true on successful opening
|
||||||
*/
|
*/
|
||||||
bool open(const QString &_hostname, const int _port,
|
bool open(const QString &_hostname, const int _port, const QString &_username,
|
||||||
const QString &_username, const QString &_password);
|
const QString &_password);
|
||||||
/**
|
/**
|
||||||
* @brief path to database
|
* @brief path to database
|
||||||
* @return path to used database
|
* @return path to used database
|
||||||
@ -140,8 +138,7 @@ public slots:
|
|||||||
* value to update
|
* value to update
|
||||||
* @return true on successfully modification
|
* @return true on successfully modification
|
||||||
*/
|
*/
|
||||||
bool modify(const QString &_table, const long long _id,
|
bool modify(const QString &_table, const long long _id, const QVariantHash &_value);
|
||||||
const QVariantHash &_value);
|
|
||||||
/**
|
/**
|
||||||
* @brief remove record in table by ID
|
* @brief remove record in table by ID
|
||||||
* @param _table
|
* @param _table
|
||||||
|
@ -76,47 +76,37 @@ typedef QHash<QString, QHash<QString, QueuedDBField>> QueuedDBSchema;
|
|||||||
/**
|
/**
|
||||||
* @brief database schema
|
* @brief database schema
|
||||||
*/
|
*/
|
||||||
static const QueuedDBSchema DBSchema = {
|
static const QueuedDBSchema DBSchema
|
||||||
{SETTINGS_TABLE,
|
= {{SETTINGS_TABLE,
|
||||||
{{"_id",
|
{{"_id", {"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong, true}},
|
||||||
{"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong,
|
{"key", {"key", "TEXT NOT NULL DEFAULT '0'", QVariant::String, true}},
|
||||||
true}},
|
{"value", {"value", "TEXT", QVariant::String, true}}}},
|
||||||
{"key", {"key", "TEXT NOT NULL DEFAULT '0'", QVariant::String, true}},
|
{TASKS_TABLE,
|
||||||
{"value", {"value", "TEXT", QVariant::String, true}}}},
|
{{"_id", {"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong, true}},
|
||||||
{TASKS_TABLE,
|
{"user", {"user", "INT NOT NULL DEFAULT 0", QVariant::LongLong, true}},
|
||||||
{{"_id",
|
{"command", {"command", "TEXT", QVariant::String, false}},
|
||||||
{"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong,
|
{"commandArguments", {"commandArguments", "TEXT", QVariant::String, false}},
|
||||||
true}},
|
{"workDirectory", {"workDirectory", "TEXT", QVariant::String, false}},
|
||||||
{"user", {"user", "INT NOT NULL DEFAULT 0", QVariant::LongLong, true}},
|
{"nice", {"nice", "INT NOT NULL DEFAULT 0", QVariant::UInt, true}},
|
||||||
{"command", {"command", "TEXT", QVariant::String, false}},
|
{"uid", {"uid", "INT", QVariant::UInt, true}},
|
||||||
{"commandArguments",
|
{"gid", {"gid", "INT", QVariant::UInt, true}},
|
||||||
{"commandArguments", "TEXT", QVariant::String, false}},
|
{"limits", {"limits", "TEXT", QVariant::String, false}},
|
||||||
{"workDirectory", {"workDirectory", "TEXT", QVariant::String, false}},
|
{"startTime", {"startTime", "INT", QVariant::LongLong, true}},
|
||||||
{"nice", {"nice", "INT NOT NULL DEFAULT 0", QVariant::UInt, true}},
|
{"endTime", {"endTime", "INT", QVariant::LongLong, true}}}},
|
||||||
{"uid", {"uid", "INT", QVariant::UInt, true}},
|
{TOKENS_TABLE,
|
||||||
{"gid", {"gid", "INT", QVariant::UInt, true}},
|
{{"_id", {"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong, true}},
|
||||||
{"limits", {"limits", "TEXT", QVariant::String, false}},
|
{"token", {"token", "TEXT NOT NULL DEFAULT '0'", QVariant::String, true}},
|
||||||
{"startTime", {"startTime", "INT", QVariant::LongLong, true}},
|
{"user", {"user", "TEXT NOT NULL DEFAULT '0'", QVariant::String, true}},
|
||||||
{"endTime", {"endTime", "INT", QVariant::LongLong, true}}}},
|
{"validUntil", {"validUntil", "TEXT NOT NULL DEFAULT '0'", QVariant::String, true}}}},
|
||||||
{TOKENS_TABLE,
|
{USERS_TABLE,
|
||||||
{{"_id",
|
{{"_id", {"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong, true}},
|
||||||
{"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong,
|
{"name", {"name", "TEXT NOT NULL DEFAULT '0'", QVariant::String, true}},
|
||||||
true}},
|
{"password", {"password", "TEXT", QVariant::String, false}},
|
||||||
{"token", {"token", "TEXT NOT NULL DEFAULT '0'", QVariant::String, true}},
|
{"email", {"email", "TEXT", QVariant::String, false}},
|
||||||
{"user", {"user", "TEXT NOT NULL DEFAULT '0'", QVariant::String, true}},
|
{"lastLogin", {"lastLogin", "TEXT", QVariant::String, true}},
|
||||||
{"validUntil",
|
{"limits", {"limits", "TEXT", QVariant::String, true}},
|
||||||
{"validUntil", "TEXT NOT NULL DEFAULT '0'", QVariant::String, true}}}},
|
{"permissions", {"permissions", "INT", QVariant::UInt, true}},
|
||||||
{USERS_TABLE,
|
{"priotiry", {"priority", "INT", QVariant::UInt, true}}}}};
|
||||||
{{"_id",
|
|
||||||
{"_id", "INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE", QVariant::LongLong,
|
|
||||||
true}},
|
|
||||||
{"name", {"name", "TEXT NOT NULL DEFAULT '0'", QVariant::String, true}},
|
|
||||||
{"password", {"password", "TEXT", QVariant::String, false}},
|
|
||||||
{"email", {"email", "TEXT", QVariant::String, false}},
|
|
||||||
{"lastLogin", {"lastLogin", "TEXT", QVariant::String, true}},
|
|
||||||
{"limits", {"limits", "TEXT", QVariant::String, true}},
|
|
||||||
{"permissions", {"permissions", "INT", QVariant::UInt, true}},
|
|
||||||
{"priotiry", {"priority", "INT", QVariant::UInt, true}}}}};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* QUEUEDDATABASESCHEMA_H */
|
#endif /* QUEUEDDATABASESCHEMA_H */
|
||||||
|
@ -62,12 +62,11 @@ namespace QueuedDebug
|
|||||||
/**
|
/**
|
||||||
* @brief default log format
|
* @brief default log format
|
||||||
*/
|
*/
|
||||||
static const char LOG_FORMAT[]
|
static const char LOG_FORMAT[] = "[%{time "
|
||||||
= "[%{time "
|
"process}][%{if-debug}DD%{endif}%{if-info}II%{endif}%"
|
||||||
"process}][%{if-debug}DD%{endif}%{if-info}II%{endif}%"
|
"{if-warning}WW%{endif}%{if-critical}CC%{endif}%{if-"
|
||||||
"{if-warning}WW%{endif}%{if-critical}CC%{endif}%{if-"
|
"fatal}FF%{endif}][%{category}][%{function}] "
|
||||||
"fatal}FF%{endif}][%{category}][%{function}] "
|
"%{message}";
|
||||||
"%{message}";
|
|
||||||
/**
|
/**
|
||||||
* @brief method to apply log format
|
* @brief method to apply log format
|
||||||
*/
|
*/
|
||||||
|
@ -46,10 +46,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief clone QueuedException
|
* @brief clone QueuedException
|
||||||
*/
|
*/
|
||||||
QueuedException *clone() const override
|
QueuedException *clone() const override { return new QueuedException(*this); };
|
||||||
{
|
|
||||||
return new QueuedException(*this);
|
|
||||||
};
|
|
||||||
/**
|
/**
|
||||||
* @brief message of this exception
|
* @brief message of this exception
|
||||||
* @return message for logging, etc
|
* @return message for logging, etc
|
||||||
|
@ -163,8 +163,7 @@ bool limitCompare(const long long _first, const long long _second);
|
|||||||
* default limits if anu
|
* default limits if anu
|
||||||
* @return minimal limits from given
|
* @return minimal limits from given
|
||||||
*/
|
*/
|
||||||
Limits minimalLimits(const Limits &_task, const Limits &_user,
|
Limits minimalLimits(const Limits &_task, const Limits &_user, const Limits &_default);
|
||||||
const Limits &_default);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,8 +69,7 @@ public:
|
|||||||
* @param _value
|
* @param _value
|
||||||
* option value
|
* option value
|
||||||
*/
|
*/
|
||||||
virtual void updateSettings(const QString &_key, const QVariant &_value)
|
virtual void updateSettings(const QString &_key, const QVariant &_value) = 0;
|
||||||
= 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_INTERFACE(QueuedPluginInterface, PLUGIN_INTERFACE_NAME)
|
Q_DECLARE_INTERFACE(QueuedPluginInterface, PLUGIN_INTERFACE_NAME)
|
||||||
|
@ -60,12 +60,10 @@ struct PluginOption {
|
|||||||
* input variant object
|
* input variant object
|
||||||
* @return appended argument body
|
* @return appended argument body
|
||||||
*/
|
*/
|
||||||
inline QDBusArgument &operator<<(QDBusArgument &_argument,
|
inline QDBusArgument &operator<<(QDBusArgument &_argument, const PluginOption &_arg)
|
||||||
const PluginOption &_arg)
|
|
||||||
{
|
{
|
||||||
_argument.beginStructure();
|
_argument.beginStructure();
|
||||||
_argument << QDBusVariant(_arg.defaultValue.isValid() ? _arg.defaultValue
|
_argument << QDBusVariant(_arg.defaultValue.isValid() ? _arg.defaultValue : "");
|
||||||
: "");
|
|
||||||
_argument << _arg.description;
|
_argument << _arg.description;
|
||||||
_argument << _arg.name;
|
_argument << _arg.name;
|
||||||
_argument << _arg.type;
|
_argument << _arg.type;
|
||||||
@ -81,8 +79,7 @@ inline QDBusArgument &operator<<(QDBusArgument &_argument,
|
|||||||
* output variant object
|
* output variant object
|
||||||
* @return source DBus argument
|
* @return source DBus argument
|
||||||
*/
|
*/
|
||||||
inline const QDBusArgument &operator>>(const QDBusArgument &_argument,
|
inline const QDBusArgument &operator>>(const QDBusArgument &_argument, PluginOption &_arg)
|
||||||
PluginOption &_arg)
|
|
||||||
{
|
{
|
||||||
QDBusVariant variant;
|
QDBusVariant variant;
|
||||||
|
|
||||||
@ -145,8 +142,7 @@ inline QDBusArgument &operator<<(QDBusArgument &_argument, const Plugin &_arg)
|
|||||||
* output variant object
|
* output variant object
|
||||||
* @return source DBus argument
|
* @return source DBus argument
|
||||||
*/
|
*/
|
||||||
inline const QDBusArgument &operator>>(const QDBusArgument &_argument,
|
inline const QDBusArgument &operator>>(const QDBusArgument &_argument, Plugin &_arg)
|
||||||
Plugin &_arg)
|
|
||||||
{
|
{
|
||||||
_argument.beginStructure();
|
_argument.beginStructure();
|
||||||
_argument >> _arg.author;
|
_argument >> _arg.author;
|
||||||
|
@ -102,8 +102,7 @@ public:
|
|||||||
* @param index
|
* @param index
|
||||||
* index of process
|
* index of process
|
||||||
*/
|
*/
|
||||||
explicit QueuedProcess(QObject *_parent,
|
explicit QueuedProcess(QObject *_parent, const QueuedProcessDefinitions &definitions,
|
||||||
const QueuedProcessDefinitions &definitions,
|
|
||||||
const long long index);
|
const long long index);
|
||||||
/**
|
/**
|
||||||
* @brief QueuedProcess class destructor
|
* @brief QueuedProcess class destructor
|
||||||
|
@ -55,8 +55,7 @@ public:
|
|||||||
* @typedef QueuedProcessConnectionMap
|
* @typedef QueuedProcessConnectionMap
|
||||||
* map of indices to related QMetaObject::Connection
|
* map of indices to related QMetaObject::Connection
|
||||||
*/
|
*/
|
||||||
typedef QHash<long long, QMetaObject::Connection>
|
typedef QHash<long long, QMetaObject::Connection> QueuedProcessConnectionMap;
|
||||||
QueuedProcessConnectionMap;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief QueuedProcessManager class constructor
|
* @brief QueuedProcessManager class constructor
|
||||||
@ -93,9 +92,8 @@ public:
|
|||||||
* task index
|
* task index
|
||||||
* @return pointer to created task
|
* @return pointer to created task
|
||||||
*/
|
*/
|
||||||
QueuedProcess *
|
QueuedProcess *add(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
add(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
const long long _index);
|
||||||
const long long _index);
|
|
||||||
/**
|
/**
|
||||||
* @brief add tasks from database
|
* @brief add tasks from database
|
||||||
* @param _processes
|
* @param _processes
|
||||||
@ -182,8 +180,7 @@ private slots:
|
|||||||
* @param _index
|
* @param _index
|
||||||
* index of finished task
|
* index of finished task
|
||||||
*/
|
*/
|
||||||
void taskFinished(const int _exitCode,
|
void taskFinished(const int _exitCode, const QProcess::ExitStatus _exitStatus,
|
||||||
const QProcess::ExitStatus _exitStatus,
|
|
||||||
const long long _index);
|
const long long _index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -91,8 +91,7 @@ public slots:
|
|||||||
* @remark if property is empty it return map of all properties
|
* @remark if property is empty it return map of all properties
|
||||||
* @return property value or empty if task or property not found
|
* @return property value or empty if task or property not found
|
||||||
*/
|
*/
|
||||||
QDBusVariant Task(const long long id, const QString &property,
|
QDBusVariant Task(const long long id, const QString &property, const QString &token);
|
||||||
const QString &token);
|
|
||||||
/**
|
/**
|
||||||
* @brief get user property
|
* @brief get user property
|
||||||
* @param id
|
* @param id
|
||||||
@ -104,8 +103,7 @@ public slots:
|
|||||||
* @remark if property is empty it return map of all properties
|
* @remark if property is empty it return map of all properties
|
||||||
* @return property value or empty if user or property not found
|
* @return property value or empty if user or property not found
|
||||||
*/
|
*/
|
||||||
QDBusVariant User(const long long id, const QString &property,
|
QDBusVariant User(const long long id, const QString &property, const QString &token);
|
||||||
const QString &token);
|
|
||||||
/**
|
/**
|
||||||
* @brief get user ID by name
|
* @brief get user ID by name
|
||||||
* @param name
|
* @param name
|
||||||
|
@ -63,8 +63,7 @@ public slots:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
QDBusVariant Performance(const QString &from, const QString &to,
|
QDBusVariant Performance(const QString &from, const QString &to, const QString &token);
|
||||||
const QString &token);
|
|
||||||
/**
|
/**
|
||||||
* @brief server status
|
* @brief server status
|
||||||
* @return server status
|
* @return server status
|
||||||
@ -82,8 +81,8 @@ public slots:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return list of tasks match to query
|
* @return list of tasks match to query
|
||||||
*/
|
*/
|
||||||
QDBusVariant Tasks(const qlonglong user, const QString &from,
|
QDBusVariant Tasks(const qlonglong user, const QString &from, const QString &to,
|
||||||
const QString &to, const QString &token);
|
const QString &token);
|
||||||
/**
|
/**
|
||||||
* @brief users list
|
* @brief users list
|
||||||
* @param lastLogged
|
* @param lastLogged
|
||||||
@ -94,8 +93,7 @@ public slots:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return list of users match to query
|
* @return list of users match to query
|
||||||
*/
|
*/
|
||||||
QDBusVariant Users(const QString &lastLogged, const uint permission,
|
QDBusVariant Users(const QString &lastLogged, const uint permission, const QString &token);
|
||||||
const QString &token);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
|
@ -66,8 +66,7 @@ public:
|
|||||||
* pointer to core object
|
* pointer to core object
|
||||||
* @return performance table
|
* @return performance table
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> performance(const QueuedCore *_core,
|
QList<QVariantHash> performance(const QueuedCore *_core, const QDateTime &_from = QDateTime(),
|
||||||
const QDateTime &_from = QDateTime(),
|
|
||||||
const QDateTime &_to = QDateTime()) const;
|
const QDateTime &_to = QDateTime()) const;
|
||||||
/**
|
/**
|
||||||
* list of tasks which match criteria
|
* list of tasks which match criteria
|
||||||
@ -79,8 +78,7 @@ public:
|
|||||||
* maximal end time
|
* maximal end time
|
||||||
* @return list of tasks in database format
|
* @return list of tasks in database format
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> tasks(const long long _user = -1,
|
QList<QVariantHash> tasks(const long long _user = -1, const QDateTime &_from = QDateTime(),
|
||||||
const QDateTime &_from = QDateTime(),
|
|
||||||
const QDateTime &_to = QDateTime()) const;
|
const QDateTime &_to = QDateTime()) const;
|
||||||
/**
|
/**
|
||||||
* list of users which match criteria
|
* list of users which match criteria
|
||||||
|
@ -50,8 +50,7 @@ typedef Result::Error<QueuedEnums::ReturnStatus> QueuedError;
|
|||||||
* input error class
|
* input error class
|
||||||
* @return appended argument body
|
* @return appended argument body
|
||||||
*/
|
*/
|
||||||
inline QDBusArgument &operator<<(QDBusArgument &_argument,
|
inline QDBusArgument &operator<<(QDBusArgument &_argument, const QueuedError &_arg)
|
||||||
const QueuedError &_arg)
|
|
||||||
{
|
{
|
||||||
_argument.beginStructure();
|
_argument.beginStructure();
|
||||||
_argument << QString(_arg.message().c_str());
|
_argument << QString(_arg.message().c_str());
|
||||||
@ -68,8 +67,7 @@ inline QDBusArgument &operator<<(QDBusArgument &_argument,
|
|||||||
* output object
|
* output object
|
||||||
* @return source DBus argument
|
* @return source DBus argument
|
||||||
*/
|
*/
|
||||||
inline const QDBusArgument &operator>>(const QDBusArgument &_argument,
|
inline const QDBusArgument &operator>>(const QDBusArgument &_argument, QueuedError &_arg)
|
||||||
QueuedError &_arg)
|
|
||||||
{
|
{
|
||||||
QString message;
|
QString message;
|
||||||
long long code;
|
long long code;
|
||||||
@ -79,8 +77,7 @@ inline const QDBusArgument &operator>>(const QDBusArgument &_argument,
|
|||||||
_argument >> code;
|
_argument >> code;
|
||||||
_argument.endStructure();
|
_argument.endStructure();
|
||||||
|
|
||||||
_arg = QueuedError(message.toStdString(),
|
_arg = QueuedError(message.toStdString(), static_cast<QueuedEnums::ReturnStatus>(code));
|
||||||
static_cast<QueuedEnums::ReturnStatus>(code));
|
|
||||||
return _argument;
|
return _argument;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@ -94,8 +91,7 @@ typedef QHash<QString, QHash<QString, QString>> QueuedStatusMap;
|
|||||||
* result value payload class
|
* result value payload class
|
||||||
* custom Result<T, E> implementation
|
* custom Result<T, E> implementation
|
||||||
*/
|
*/
|
||||||
template <class T>
|
template <class T> using QueuedResult = Result::Result<T, QueuedEnums::ReturnStatus>;
|
||||||
using QueuedResult = Result::Result<T, QueuedEnums::ReturnStatus>;
|
|
||||||
Q_DECLARE_METATYPE(QueuedResult<bool>)
|
Q_DECLARE_METATYPE(QueuedResult<bool>)
|
||||||
Q_DECLARE_METATYPE(QueuedResult<long long>)
|
Q_DECLARE_METATYPE(QueuedResult<long long>)
|
||||||
Q_DECLARE_METATYPE(QueuedResult<QString>)
|
Q_DECLARE_METATYPE(QueuedResult<QString>)
|
||||||
@ -128,8 +124,7 @@ inline QDBusArgument &operator<<(QDBusArgument &_argument, const QVariant &_arg)
|
|||||||
* output variant object
|
* output variant object
|
||||||
* @return source DBus argument
|
* @return source DBus argument
|
||||||
*/
|
*/
|
||||||
inline const QDBusArgument &operator>>(const QDBusArgument &_argument,
|
inline const QDBusArgument &operator>>(const QDBusArgument &_argument, QVariant &_arg)
|
||||||
QVariant &_arg)
|
|
||||||
{
|
{
|
||||||
QDBusVariant variant;
|
QDBusVariant variant;
|
||||||
|
|
||||||
@ -149,8 +144,7 @@ inline const QDBusArgument &operator>>(const QDBusArgument &_argument,
|
|||||||
* @return appended argument body
|
* @return appended argument body
|
||||||
*/
|
*/
|
||||||
template <class T>
|
template <class T>
|
||||||
inline QDBusArgument &operator<<(QDBusArgument &_argument,
|
inline QDBusArgument &operator<<(QDBusArgument &_argument, const QueuedResult<T> &_arg)
|
||||||
const QueuedResult<T> &_arg)
|
|
||||||
{
|
{
|
||||||
// HACK we are using explicit cast to QString here to make sure of valid
|
// HACK we are using explicit cast to QString here to make sure of valid
|
||||||
// marshalling
|
// marshalling
|
||||||
@ -187,8 +181,7 @@ inline QDBusArgument &operator<<(QDBusArgument &_argument,
|
|||||||
* @return source DBus argument
|
* @return source DBus argument
|
||||||
*/
|
*/
|
||||||
template <class T>
|
template <class T>
|
||||||
inline const QDBusArgument &operator>>(const QDBusArgument &_argument,
|
inline const QDBusArgument &operator>>(const QDBusArgument &_argument, QueuedResult<T> &_arg)
|
||||||
QueuedResult<T> &_arg)
|
|
||||||
{
|
{
|
||||||
QString type;
|
QString type;
|
||||||
T value;
|
T value;
|
||||||
|
@ -145,8 +145,7 @@ typedef QHash<QString, QueuedSettingsField> QueuedSettingsDefaultMap;
|
|||||||
static const QueuedSettingsDefaultMap QueuedSettingsDefaults = {
|
static const QueuedSettingsDefaultMap QueuedSettingsDefaults = {
|
||||||
{"", {QueuedSettings::Invalid, QVariant(), false}},
|
{"", {QueuedSettings::Invalid, QVariant(), false}},
|
||||||
{"DatabaseInterval", {QueuedSettings::DatabaseInterval, 86400000, true}},
|
{"DatabaseInterval", {QueuedSettings::DatabaseInterval, 86400000, true}},
|
||||||
{"DatabaseVersion",
|
{"DatabaseVersion", {QueuedSettings::DatabaseVersion, QueuedConfig::DATABASE_VERSION, true}},
|
||||||
{QueuedSettings::DatabaseVersion, QueuedConfig::DATABASE_VERSION, true}},
|
|
||||||
{"DefaultLimits", {QueuedSettings::DefaultLimits, "0\n0\n0\n0\n0", false}},
|
{"DefaultLimits", {QueuedSettings::DefaultLimits, "0\n0\n0\n0\n0", false}},
|
||||||
{"KeepTasks", {QueuedSettings::KeepTasks, 0, false}},
|
{"KeepTasks", {QueuedSettings::KeepTasks, 0, false}},
|
||||||
{"KeepUsers", {QueuedSettings::KeepUsers, 0, false}},
|
{"KeepUsers", {QueuedSettings::KeepUsers, 0, false}},
|
||||||
|
@ -74,8 +74,7 @@ public:
|
|||||||
* @param _definitions
|
* @param _definitions
|
||||||
* token definitions
|
* token definitions
|
||||||
*/
|
*/
|
||||||
void
|
void loadToken(const QueuedTokenManager::QueuedTokenDefinitions &_definitions);
|
||||||
loadToken(const QueuedTokenManager::QueuedTokenDefinitions &_definitions);
|
|
||||||
/**
|
/**
|
||||||
* @brief upload tokens from database
|
* @brief upload tokens from database
|
||||||
* @param _values
|
* @param _values
|
||||||
|
@ -84,8 +84,7 @@ public:
|
|||||||
* @param index
|
* @param index
|
||||||
* index of process
|
* index of process
|
||||||
*/
|
*/
|
||||||
explicit QueuedUser(QObject *_parent,
|
explicit QueuedUser(QObject *_parent, const QueuedUserDefinitions &definitions,
|
||||||
const QueuedUserDefinitions &definitions,
|
|
||||||
const long long index);
|
const long long index);
|
||||||
/**
|
/**
|
||||||
* @brief QueuedUser class destructor
|
* @brief QueuedUser class destructor
|
||||||
@ -98,8 +97,7 @@ public:
|
|||||||
* new user permission
|
* new user permission
|
||||||
* @return current user permissions
|
* @return current user permissions
|
||||||
*/
|
*/
|
||||||
QueuedEnums::Permissions
|
QueuedEnums::Permissions addPermission(const QueuedEnums::Permission _permission);
|
||||||
addPermission(const QueuedEnums::Permission _permission);
|
|
||||||
/**
|
/**
|
||||||
* @brief generates SHA512 hash from given password
|
* @brief generates SHA512 hash from given password
|
||||||
* @param _password
|
* @param _password
|
||||||
@ -108,8 +106,7 @@ public:
|
|||||||
* password salt if any
|
* password salt if any
|
||||||
* @return SHA512 of password
|
* @return SHA512 of password
|
||||||
*/
|
*/
|
||||||
static QString hashFromPassword(const QString &_password,
|
static QString hashFromPassword(const QString &_password, const QString &_salt);
|
||||||
const QString &_salt);
|
|
||||||
/**
|
/**
|
||||||
* @brief test user permissions
|
* @brief test user permissions
|
||||||
* @param _permission
|
* @param _permission
|
||||||
@ -137,8 +134,7 @@ public:
|
|||||||
* permission to remove
|
* permission to remove
|
||||||
* @return current user permissions
|
* @return current user permissions
|
||||||
*/
|
*/
|
||||||
QueuedEnums::Permissions
|
QueuedEnums::Permissions removePermission(const QueuedEnums::Permission _permission);
|
||||||
removePermission(const QueuedEnums::Permission _permission);
|
|
||||||
// main properties
|
// main properties
|
||||||
/**
|
/**
|
||||||
* @brief user email
|
* @brief user email
|
||||||
|
@ -39,8 +39,7 @@ class QueuedUserManager : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString salt READ salt WRITE setSalt)
|
Q_PROPERTY(QString salt READ salt WRITE setSalt)
|
||||||
Q_PROPERTY(
|
Q_PROPERTY(long long tokenExpiration READ tokenExpiration WRITE setTokenExpiration)
|
||||||
long long tokenExpiration READ tokenExpiration WRITE setTokenExpiration)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -53,6 +52,13 @@ public:
|
|||||||
* @brief QueuedUserManager class destructor
|
* @brief QueuedUserManager class destructor
|
||||||
*/
|
*/
|
||||||
virtual ~QueuedUserManager();
|
virtual ~QueuedUserManager();
|
||||||
|
/**
|
||||||
|
* @brief parse user definitions from table data
|
||||||
|
* @param _properties
|
||||||
|
* map of usr properties
|
||||||
|
* @return data mapped to internal format
|
||||||
|
*/
|
||||||
|
static QueuedUser::QueuedUserDefinitions parseDefinitions(const QVariantHash &_properties);
|
||||||
/**
|
/**
|
||||||
* @brief add user
|
* @brief add user
|
||||||
* @param _properties
|
* @param _properties
|
||||||
@ -70,8 +76,7 @@ public:
|
|||||||
* user ID
|
* user ID
|
||||||
* @return pointer to created user
|
* @return pointer to created user
|
||||||
*/
|
*/
|
||||||
QueuedUser *add(const QueuedUser::QueuedUserDefinitions &_definitions,
|
QueuedUser *add(const QueuedUser::QueuedUserDefinitions &_definitions, const long long _id);
|
||||||
const long long _id);
|
|
||||||
/**
|
/**
|
||||||
* @brief authorize user manually
|
* @brief authorize user manually
|
||||||
* @remark it ignores password input and creates unlimited token
|
* @remark it ignores password input and creates unlimited token
|
||||||
@ -97,8 +102,7 @@ public:
|
|||||||
* service to authorize
|
* service to authorize
|
||||||
* @return true if user allowed to do it otherwise return false
|
* @return true if user allowed to do it otherwise return false
|
||||||
*/
|
*/
|
||||||
bool authorize(const QString &_token,
|
bool authorize(const QString &_token, const QueuedEnums::Permission _service);
|
||||||
const QueuedEnums::Permission _service);
|
|
||||||
/**
|
/**
|
||||||
* @brief check token expiration
|
* @brief check token expiration
|
||||||
* @param _token
|
* @param _token
|
||||||
|
@ -89,11 +89,9 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return task ID or -1 if no task added
|
* @return task ID or -1 if no task added
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long> addTask(const QString &_command,
|
QueuedResult<long long> addTask(const QString &_command, const QStringList &_arguments,
|
||||||
const QStringList &_arguments,
|
const QString &_workingDirectory, const long long _userId,
|
||||||
const QString &_workingDirectory,
|
const uint _nice, const QueuedLimits::Limits &_limits,
|
||||||
const long long _userId, const uint _nice,
|
|
||||||
const QueuedLimits::Limits &_limits,
|
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief add new user
|
* @brief add new user
|
||||||
@ -114,10 +112,8 @@ public:
|
|||||||
* @return user ID or -1 if no user created
|
* @return user ID or -1 if no user created
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long> addUser(const QString &_name, const QString &_email,
|
QueuedResult<long long> addUser(const QString &_name, const QString &_email,
|
||||||
const QString &_password,
|
const QString &_password, const uint _permissions,
|
||||||
const uint _permissions,
|
const uint _priority, const QueuedLimits::Limits &_limits,
|
||||||
const uint _priority,
|
|
||||||
const QueuedLimits::Limits &_limits,
|
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief try to authorize by given token
|
* @brief try to authorize by given token
|
||||||
@ -134,8 +130,7 @@ public:
|
|||||||
* user password
|
* user password
|
||||||
* @return token. It will be empty if authorization error occurs
|
* @return token. It will be empty if authorization error occurs
|
||||||
*/
|
*/
|
||||||
QueuedResult<QString> authorization(const QString &_name,
|
QueuedResult<QString> authorization(const QString &_name, const QString &_password);
|
||||||
const QString &_password);
|
|
||||||
/**
|
/**
|
||||||
* @brief edit advanced settings
|
* @brief edit advanced settings
|
||||||
* @param _key
|
* @param _key
|
||||||
@ -160,8 +155,7 @@ public:
|
|||||||
* fields will be ignored. No need to pass all properties here
|
* fields will be ignored. No need to pass all properties here
|
||||||
* @return true on successful task edition
|
* @return true on successful task edition
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> editTask(const long long _id,
|
QueuedResult<bool> editTask(const long long _id, const QVariantHash &_taskData,
|
||||||
const QVariantHash &_taskData,
|
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief edit user
|
* @brief edit user
|
||||||
@ -175,8 +169,7 @@ public:
|
|||||||
* fields will be ignored. No need to pass all properties here
|
* fields will be ignored. No need to pass all properties here
|
||||||
* @return true on successful user edition
|
* @return true on successful user edition
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> editUser(const long long _id,
|
QueuedResult<bool> editUser(const long long _id, const QVariantHash &_userData,
|
||||||
const QVariantHash &_userData,
|
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief edit user permissions
|
* @brief edit user permissions
|
||||||
@ -190,10 +183,9 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return true on successful user permission edition
|
* @return true on successful user permission edition
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool>
|
QueuedResult<bool> editUserPermission(const long long _id,
|
||||||
editUserPermission(const long long _id,
|
const QueuedEnums::Permission &_permission,
|
||||||
const QueuedEnums::Permission &_permission,
|
const bool _add, const QString &_token);
|
||||||
const bool _add, const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief hash password
|
* @brief hash password
|
||||||
* @param _password
|
* @param _password
|
||||||
@ -221,8 +213,7 @@ public:
|
|||||||
* @return performance table
|
* @return performance table
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>>
|
QueuedResult<QList<QVariantHash>>
|
||||||
performanceReport(const QDateTime &_from, const QDateTime &_to,
|
performanceReport(const QDateTime &_from, const QDateTime &_to, const QString &_token) const;
|
||||||
const QString &_token) const;
|
|
||||||
/**
|
/**
|
||||||
* @brief get plugin description
|
* @brief get plugin description
|
||||||
* @param _plugin
|
* @param _plugin
|
||||||
@ -231,8 +222,8 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return dictionary of PluginSpecification representation
|
* @return dictionary of PluginSpecification representation
|
||||||
*/
|
*/
|
||||||
QueuedResult<QueuedPluginSpecification::Plugin>
|
QueuedResult<QueuedPluginSpecification::Plugin> plugin(const QString &_plugin,
|
||||||
plugin(const QString &_plugin, const QString &_token);
|
const QString &_token);
|
||||||
/**
|
/**
|
||||||
* @brief get plugin settings
|
* @brief get plugin settings
|
||||||
* @param _plugin
|
* @param _plugin
|
||||||
@ -241,8 +232,7 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return hash of plugin settings
|
* @return hash of plugin settings
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariantHash> pluginSettings(const QString &_plugin,
|
QueuedResult<QVariantHash> pluginSettings(const QString &_plugin, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief remove plugin from autoload and unload it now
|
* @brief remove plugin from autoload and unload it now
|
||||||
* @param _plugin
|
* @param _plugin
|
||||||
@ -251,8 +241,7 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return true on successful plugin removal
|
* @return true on successful plugin removal
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> removePlugin(const QString &_plugin,
|
QueuedResult<bool> removePlugin(const QString &_plugin, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
/**
|
/**
|
||||||
* @brief force start task
|
* @brief force start task
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -292,10 +281,8 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return list of tasks in database format
|
* @return list of tasks in database format
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>> taskReport(const long long _user,
|
QueuedResult<QList<QVariantHash>> taskReport(const long long _user, const QDateTime &_from,
|
||||||
const QDateTime &_from,
|
const QDateTime &_to, const QString &_token) const;
|
||||||
const QDateTime &_to,
|
|
||||||
const QString &_token) const;
|
|
||||||
/**
|
/**
|
||||||
* @brief get user by ID
|
* @brief get user by ID
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -324,10 +311,9 @@ public:
|
|||||||
* user auth token
|
* user auth token
|
||||||
* @return list of users in database format
|
* @return list of users in database format
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>>
|
QueuedResult<QList<QVariantHash>> userReport(const QDateTime &_lastLogged,
|
||||||
userReport(const QDateTime &_lastLogged,
|
const QueuedEnums::Permission _permission,
|
||||||
const QueuedEnums::Permission _permission,
|
const QString &_token) const;
|
||||||
const QString &_token) const;
|
|
||||||
// control methods
|
// control methods
|
||||||
/**
|
/**
|
||||||
* @brief deinit subclasses
|
* @brief deinit subclasses
|
||||||
@ -352,8 +338,8 @@ private slots:
|
|||||||
* @param _value
|
* @param _value
|
||||||
* new value
|
* new value
|
||||||
*/
|
*/
|
||||||
void updateSettings(const QueuedConfig::QueuedSettings _id,
|
void updateSettings(const QueuedConfig::QueuedSettings _id, const QString &_key,
|
||||||
const QString &_key, const QVariant &_value);
|
const QVariant &_value);
|
||||||
/**
|
/**
|
||||||
* @brief update process time
|
* @brief update process time
|
||||||
* @param _id
|
* @param _id
|
||||||
|
@ -37,6 +37,7 @@ class QueuedDatabase;
|
|||||||
class QueuedPluginManager;
|
class QueuedPluginManager;
|
||||||
class QueuedProcess;
|
class QueuedProcess;
|
||||||
class QueuedProcessManager;
|
class QueuedProcessManager;
|
||||||
|
class QueuedUser;
|
||||||
class QueuedUserManager;
|
class QueuedUserManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,8 +97,7 @@ private:
|
|||||||
* initial database payload
|
* initial database payload
|
||||||
* @return payload with dropped keys
|
* @return payload with dropped keys
|
||||||
*/
|
*/
|
||||||
QVariantHash dropAdminFields(const QString &_table,
|
QVariantHash dropAdminFields(const QString &_table, const QVariantHash &_payload);
|
||||||
const QVariantHash &_payload);
|
|
||||||
/**
|
/**
|
||||||
* @brief method allows to init class if it was not created
|
* @brief method allows to init class if it was not created
|
||||||
* @tparam T
|
* @tparam T
|
||||||
@ -132,10 +132,10 @@ private:
|
|||||||
* task defined limits
|
* task defined limits
|
||||||
* @return task ID or -1 if no task added
|
* @return task ID or -1 if no task added
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long>
|
QueuedResult<long long> addTaskPrivate(const QString &_command, const QStringList &_arguments,
|
||||||
addTaskPrivate(const QString &_command, const QStringList &_arguments,
|
const QString &_workingDirectory,
|
||||||
const QString &_workingDirectory, const long long _userId,
|
const long long _userId, const uint _nice,
|
||||||
const uint _nice, const QueuedLimits::Limits &_limits);
|
const QueuedLimits::Limits &_limits);
|
||||||
/**
|
/**
|
||||||
* @brief add new user
|
* @brief add new user
|
||||||
* @param _name
|
* @param _name
|
||||||
@ -152,10 +152,10 @@ private:
|
|||||||
* user limits
|
* user limits
|
||||||
* @return user ID or -1 if no user found
|
* @return user ID or -1 if no user found
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long>
|
QueuedResult<long long> addUserPrivate(const QString &_name, const QString &_email,
|
||||||
addUserPrivate(const QString &_name, const QString &_email,
|
const QString &_password, const uint _permissions,
|
||||||
const QString &_password, const uint _permissions,
|
const uint _priority,
|
||||||
const uint _priority, const QueuedLimits::Limits &_limits);
|
const QueuedLimits::Limits &_limits);
|
||||||
/**
|
/**
|
||||||
* @brief edit advanced settings
|
* @brief edit advanced settings
|
||||||
* @param _key
|
* @param _key
|
||||||
@ -164,8 +164,7 @@ private:
|
|||||||
* advanced settings value
|
* advanced settings value
|
||||||
* @return true on successful option edition
|
* @return true on successful option edition
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> editOptionPrivate(const QString &_key,
|
QueuedResult<bool> editOptionPrivate(const QString &_key, const QVariant &_value);
|
||||||
const QVariant &_value);
|
|
||||||
/**
|
/**
|
||||||
* @brief edit plugin list
|
* @brief edit plugin list
|
||||||
* @param _plugin
|
* @param _plugin
|
||||||
@ -174,8 +173,7 @@ private:
|
|||||||
* true if it requires add plugin
|
* true if it requires add plugin
|
||||||
* @return true on successful action
|
* @return true on successful action
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> editPluginPrivate(const QString &_plugin,
|
QueuedResult<bool> editPluginPrivate(const QString &_plugin, const bool _add);
|
||||||
const bool _add);
|
|
||||||
/**
|
/**
|
||||||
* @brief edit task
|
* @brief edit task
|
||||||
* @param _process
|
* @param _process
|
||||||
@ -186,8 +184,7 @@ private:
|
|||||||
* fields will be ignored. No need to pass all properties here
|
* fields will be ignored. No need to pass all properties here
|
||||||
* @return true on successful task edition
|
* @return true on successful task edition
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> editTaskPrivate(QueuedProcess *_process,
|
QueuedResult<bool> editTaskPrivate(QueuedProcess *_process, const QVariantHash &_taskData);
|
||||||
const QVariantHash &_taskData);
|
|
||||||
/**
|
/**
|
||||||
* @brief edit user
|
* @brief edit user
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -198,8 +195,7 @@ private:
|
|||||||
* fields will be ignored. No need to pass all properties here
|
* fields will be ignored. No need to pass all properties here
|
||||||
* @return true on successful user edition
|
* @return true on successful user edition
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> editUserPrivate(const long long _id,
|
QueuedResult<bool> editUserPrivate(QueuedUser *_user, const QVariantHash &_userData);
|
||||||
const QVariantHash &_userData);
|
|
||||||
/**
|
/**
|
||||||
* @brief edit user permissions
|
* @brief edit user permissions
|
||||||
* @param _id
|
* @param _id
|
||||||
@ -210,10 +206,23 @@ private:
|
|||||||
* indicates whether it should be added or removed
|
* indicates whether it should be added or removed
|
||||||
* @return true on successful user permission edition
|
* @return true on successful user permission edition
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool>
|
QueuedResult<bool> editUserPermissionPrivate(const long long _id,
|
||||||
editUserPermissionPrivate(const long long _id,
|
const QueuedEnums::Permission &_permission,
|
||||||
const QueuedEnums::Permission &_permission,
|
const bool _add);
|
||||||
const bool _add);
|
/**
|
||||||
|
* @brief try get task from storages
|
||||||
|
* @param _id
|
||||||
|
* task ID to search
|
||||||
|
* @return pointer to found task if any
|
||||||
|
*/
|
||||||
|
QueuedProcess *tryGetTask(const long long _id);
|
||||||
|
/**
|
||||||
|
* @brief try get user from storages
|
||||||
|
* @param _id
|
||||||
|
* user ID to search
|
||||||
|
* @return pointer to found user if any
|
||||||
|
*/
|
||||||
|
QueuedUser *tryGetUser(const long long _id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,8 +54,7 @@ bool QueuedAdvancedSettings::checkDatabaseVersion() const
|
|||||||
{
|
{
|
||||||
QString key = internalId(QueuedConfig::QueuedSettings::DatabaseVersion);
|
QString key = internalId(QueuedConfig::QueuedSettings::DatabaseVersion);
|
||||||
|
|
||||||
return m_values.contains(key.toLower())
|
return m_values.contains(key.toLower()) && (get(key).toInt() == QueuedConfig::DATABASE_VERSION);
|
||||||
&& (get(key).toInt() == QueuedConfig::DATABASE_VERSION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -70,16 +69,14 @@ QVariant QueuedAdvancedSettings::get(const QString &_key) const
|
|||||||
if (m_values.contains(key))
|
if (m_values.contains(key))
|
||||||
return m_values.value(key);
|
return m_values.value(key);
|
||||||
else
|
else
|
||||||
return QueuedConfig::QueuedSettingsDefaults[internalId(_key)]
|
return QueuedConfig::QueuedSettingsDefaults[internalId(_key)].defaultValue;
|
||||||
.defaultValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn get
|
* @fn get
|
||||||
*/
|
*/
|
||||||
QVariant
|
QVariant QueuedAdvancedSettings::get(const QueuedConfig::QueuedSettings _key) const
|
||||||
QueuedAdvancedSettings::get(const QueuedConfig::QueuedSettings _key) const
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Looking for key" << static_cast<int>(_key);
|
qCDebug(LOG_LIB) << "Looking for key" << static_cast<int>(_key);
|
||||||
|
|
||||||
@ -125,8 +122,7 @@ QString QueuedAdvancedSettings::internalId(const QString &_key)
|
|||||||
/**
|
/**
|
||||||
* @fn internalId
|
* @fn internalId
|
||||||
*/
|
*/
|
||||||
QString
|
QString QueuedAdvancedSettings::internalId(const QueuedConfig::QueuedSettings _key)
|
||||||
QueuedAdvancedSettings::internalId(const QueuedConfig::QueuedSettings _key)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Looking for key" << static_cast<int>(_key);
|
qCDebug(LOG_LIB) << "Looking for key" << static_cast<int>(_key);
|
||||||
|
|
||||||
@ -157,8 +153,7 @@ bool QueuedAdvancedSettings::isAdmin(const QString &_key) const
|
|||||||
/**
|
/**
|
||||||
* @fn isAdmin
|
* @fn isAdmin
|
||||||
*/
|
*/
|
||||||
bool QueuedAdvancedSettings::isAdmin(
|
bool QueuedAdvancedSettings::isAdmin(const QueuedConfig::QueuedSettings &_key) const
|
||||||
const QueuedConfig::QueuedSettings &_key) const
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Check if admin option" << static_cast<int>(_key);
|
qCDebug(LOG_LIB) << "Check if admin option" << static_cast<int>(_key);
|
||||||
|
|
||||||
|
@ -32,8 +32,7 @@
|
|||||||
/**
|
/**
|
||||||
* @fn QueuedControlGroupsAdaptor
|
* @fn QueuedControlGroupsAdaptor
|
||||||
*/
|
*/
|
||||||
QueuedControlGroupsAdaptor::QueuedControlGroupsAdaptor(QObject *_parent,
|
QueuedControlGroupsAdaptor::QueuedControlGroupsAdaptor(QObject *_parent, QString _name)
|
||||||
QString _name)
|
|
||||||
: QObject(_parent)
|
: QObject(_parent)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
@ -157,8 +156,7 @@ void QueuedControlGroupsAdaptor::setCpuLimit(const long long _value)
|
|||||||
stream << _value;
|
stream << _value;
|
||||||
stream.flush();
|
stream.flush();
|
||||||
} else {
|
} else {
|
||||||
qCCritical(LOG_LIB)
|
qCCritical(LOG_LIB) << "Could not set CPU limit" << name() << "to" << _value;
|
||||||
<< "Could not set CPU limit" << name() << "to" << _value;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
@ -179,8 +177,7 @@ void QueuedControlGroupsAdaptor::setMemoryLimit(const long long _value)
|
|||||||
stream << _value;
|
stream << _value;
|
||||||
stream.flush();
|
stream.flush();
|
||||||
} else {
|
} else {
|
||||||
qCCritical(LOG_LIB)
|
qCCritical(LOG_LIB) << "Could not set memory limit" << name() << "to" << _value;
|
||||||
<< "Could not set memory limit" << name() << "to" << _value;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
@ -204,8 +201,7 @@ bool QueuedControlGroupsAdaptor::addProcess(const uint _pid)
|
|||||||
QTextStream stream(&file);
|
QTextStream stream(&file);
|
||||||
stream << _pid;
|
stream << _pid;
|
||||||
} else {
|
} else {
|
||||||
qCCritical(LOG_LIB)
|
qCCritical(LOG_LIB) << "Cound not assign pid" << _pid << "to" << proc;
|
||||||
<< "Cound not assign pid" << _pid << "to" << proc;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,40 +222,33 @@ bool QueuedControlGroupsAdaptor::createGroup()
|
|||||||
auto paths = controlPaths();
|
auto paths = controlPaths();
|
||||||
|
|
||||||
// create cgroups
|
// create cgroups
|
||||||
bool status = std::all_of(
|
bool status = std::all_of(paths.cbegin(), paths.cend(),
|
||||||
paths.cbegin(), paths.cend(),
|
[this](const QString &path) { return QDir(path).mkpath(name()); });
|
||||||
[this](const QString &path) { return QDir(path).mkpath(name()); });
|
|
||||||
// apply settings
|
// apply settings
|
||||||
status &= std::all_of(
|
status &= std::all_of(paths.cbegin(), paths.cend(), [this](const QString &path) {
|
||||||
paths.cbegin(), paths.cend(), [this](const QString &path) {
|
auto notify = QDir(groupPath(path)).filePath(CG_NOTIFY_ON_RELEASE_FILE);
|
||||||
auto notify
|
QFile file(notify);
|
||||||
= QDir(groupPath(path)).filePath(CG_NOTIFY_ON_RELEASE_FILE);
|
if (file.open(QIODevice::WriteOnly)) {
|
||||||
QFile file(notify);
|
QTextStream stream(&file);
|
||||||
if (file.open(QIODevice::WriteOnly)) {
|
stream << 1;
|
||||||
QTextStream stream(&file);
|
} else {
|
||||||
stream << 1;
|
qCCritical(LOG_LIB) << "Could not apply rules to" << CG_NOTIFY_ON_RELEASE_FILE;
|
||||||
} else {
|
return false;
|
||||||
qCCritical(LOG_LIB)
|
}
|
||||||
<< "Could not apply rules to" << CG_NOTIFY_ON_RELEASE_FILE;
|
return true;
|
||||||
return false;
|
});
|
||||||
}
|
status &= std::all_of(paths.cbegin(), paths.cend(), [this](const QString &path) {
|
||||||
return true;
|
auto agent = QDir(groupPath(path)).filePath(CG_RELEASE_FILE);
|
||||||
});
|
QFile file(agent);
|
||||||
status &= std::all_of(
|
if (file.open(QIODevice::WriteOnly)) {
|
||||||
paths.cbegin(), paths.cend(), [this](const QString &path) {
|
QTextStream stream(&file);
|
||||||
auto agent = QDir(groupPath(path)).filePath(CG_RELEASE_FILE);
|
stream << QString("rmdir \"%1\"").arg(QDir(path).filePath(name()));
|
||||||
QFile file(agent);
|
} else {
|
||||||
if (file.open(QIODevice::WriteOnly)) {
|
qCCritical(LOG_LIB) << "Could not apply rules to" << CG_RELEASE_FILE;
|
||||||
QTextStream stream(&file);
|
return false;
|
||||||
stream
|
}
|
||||||
<< QString("rmdir \"%1\"").arg(QDir(path).filePath(name()));
|
return true;
|
||||||
} else {
|
});
|
||||||
qCCritical(LOG_LIB)
|
|
||||||
<< "Could not apply rules to" << CG_RELEASE_FILE;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
@ -275,7 +264,6 @@ bool QueuedControlGroupsAdaptor::removeGroup()
|
|||||||
|
|
||||||
auto paths = controlPaths();
|
auto paths = controlPaths();
|
||||||
|
|
||||||
return std::all_of(
|
return std::all_of(paths.cbegin(), paths.cend(),
|
||||||
paths.cbegin(), paths.cend(),
|
[this](const QString &path) { return QDir(path).rmdir(name()); });
|
||||||
[this](const QString &path) { return QDir(path).rmdir(name()); });
|
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,7 @@ QueuedCore::~QueuedCore()
|
|||||||
/**
|
/**
|
||||||
* @fn addPlugin
|
* @fn addPlugin
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCore::addPlugin(const QString &_plugin,
|
QueuedResult<bool> QueuedCore::addPlugin(const QString &_plugin, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add plugin" << _plugin;
|
qCDebug(LOG_LIB) << "Add plugin" << _plugin;
|
||||||
|
|
||||||
@ -68,34 +67,33 @@ QueuedResult<bool> QueuedCore::addPlugin(const QString &_plugin,
|
|||||||
/**
|
/**
|
||||||
* @addTask
|
* @addTask
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long>
|
QueuedResult<long long> QueuedCore::addTask(const QString &_command, const QStringList &_arguments,
|
||||||
QueuedCore::addTask(const QString &_command, const QStringList &_arguments,
|
const QString &_workingDirectory,
|
||||||
const QString &_workingDirectory, const long long _userId,
|
const long long _userId, const uint _nice,
|
||||||
const uint _nice, const QueuedLimits::Limits &_limits,
|
const QueuedLimits::Limits &_limits,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add task" << _command << "with arguments" << _arguments
|
qCDebug(LOG_LIB) << "Add task" << _command << "with arguments" << _arguments << "from user"
|
||||||
<< "from user" << _userId;
|
<< _userId;
|
||||||
|
|
||||||
return m_impl->addTask(_command, _arguments, _workingDirectory, _userId,
|
return m_impl->addTask(_command, _arguments, _workingDirectory, _userId, _nice, _limits,
|
||||||
_nice, _limits, _token);
|
_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn addUser
|
* @fn addUser
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long>
|
QueuedResult<long long> QueuedCore::addUser(const QString &_name, const QString &_email,
|
||||||
QueuedCore::addUser(const QString &_name, const QString &_email,
|
const QString &_password, const uint _permissions,
|
||||||
const QString &_password, const uint _permissions,
|
const uint _priority,
|
||||||
const uint _priority, const QueuedLimits::Limits &_limits,
|
const QueuedLimits::Limits &_limits,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add user" << _name << "with email" << _email
|
qCDebug(LOG_LIB) << "Add user" << _name << "with email" << _email << "and permissions"
|
||||||
<< "and permissions" << _permissions;
|
<< _permissions;
|
||||||
|
|
||||||
return m_impl->addUser(_name, _email, _password, _permissions, _priority,
|
return m_impl->addUser(_name, _email, _password, _permissions, _priority, _limits, _token);
|
||||||
_limits, _token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -111,8 +109,7 @@ QueuedResult<bool> QueuedCore::authorization(const QString &_token)
|
|||||||
/**
|
/**
|
||||||
* @fn authorization
|
* @fn authorization
|
||||||
*/
|
*/
|
||||||
QueuedResult<QString> QueuedCore::authorization(const QString &_name,
|
QueuedResult<QString> QueuedCore::authorization(const QString &_name, const QString &_password)
|
||||||
const QString &_password)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Authorize user" << _name;
|
qCDebug(LOG_LIB) << "Authorize user" << _name;
|
||||||
|
|
||||||
@ -123,8 +120,7 @@ QueuedResult<QString> QueuedCore::authorization(const QString &_name,
|
|||||||
/**
|
/**
|
||||||
* @fn editOption
|
* @fn editOption
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCore::editOption(const QString &_key,
|
QueuedResult<bool> QueuedCore::editOption(const QString &_key, const QVariant &_value,
|
||||||
const QVariant &_value,
|
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Set key" << _key << "to" << _value;
|
qCDebug(LOG_LIB) << "Set key" << _key << "to" << _value;
|
||||||
@ -136,8 +132,7 @@ QueuedResult<bool> QueuedCore::editOption(const QString &_key,
|
|||||||
/**
|
/**
|
||||||
* @fn editTask
|
* @fn editTask
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCore::editTask(const long long _id,
|
QueuedResult<bool> QueuedCore::editTask(const long long _id, const QVariantHash &_taskData,
|
||||||
const QVariantHash &_taskData,
|
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit task with ID" << _id;
|
qCDebug(LOG_LIB) << "Edit task with ID" << _id;
|
||||||
@ -149,8 +144,7 @@ QueuedResult<bool> QueuedCore::editTask(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn editUser
|
* @fn editUser
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCore::editUser(const long long _id,
|
QueuedResult<bool> QueuedCore::editUser(const long long _id, const QVariantHash &_userData,
|
||||||
const QVariantHash &_userData,
|
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit user with ID" << _id;
|
qCDebug(LOG_LIB) << "Edit user with ID" << _id;
|
||||||
@ -162,13 +156,12 @@ QueuedResult<bool> QueuedCore::editUser(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn editUserPermission
|
* @fn editUserPermission
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool>
|
QueuedResult<bool> QueuedCore::editUserPermission(const long long _id,
|
||||||
QueuedCore::editUserPermission(const long long _id,
|
const QueuedEnums::Permission &_permission,
|
||||||
const QueuedEnums::Permission &_permission,
|
const bool _add, const QString &_token)
|
||||||
const bool _add, const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit permissions" << static_cast<int>(_permission)
|
qCDebug(LOG_LIB) << "Edit permissions" << static_cast<int>(_permission) << "for user" << _id
|
||||||
<< "for user" << _id << "add" << _add;
|
<< "add" << _add;
|
||||||
|
|
||||||
return m_impl->editUserPermission(_id, _permission, _add, _token);
|
return m_impl->editUserPermission(_id, _permission, _add, _token);
|
||||||
}
|
}
|
||||||
@ -186,8 +179,7 @@ QueuedResult<QString> QueuedCore::hashFromPassword(const QString &_password)
|
|||||||
/**
|
/**
|
||||||
* @fn option
|
* @fn option
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant> QueuedCore::option(const QString &_key,
|
QueuedResult<QVariant> QueuedCore::option(const QString &_key, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Look for option" << _key;
|
qCDebug(LOG_LIB) << "Look for option" << _key;
|
||||||
|
|
||||||
@ -198,9 +190,9 @@ QueuedResult<QVariant> QueuedCore::option(const QString &_key,
|
|||||||
/**
|
/**
|
||||||
* @fn performanceReport
|
* @fn performanceReport
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>>
|
QueuedResult<QList<QVariantHash>> QueuedCore::performanceReport(const QDateTime &_from,
|
||||||
QueuedCore::performanceReport(const QDateTime &_from, const QDateTime &_to,
|
const QDateTime &_to,
|
||||||
const QString &_token) const
|
const QString &_token) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get performance report for" << _from << _to;
|
qCDebug(LOG_LIB) << "Get performance report for" << _from << _to;
|
||||||
|
|
||||||
@ -211,8 +203,8 @@ QueuedCore::performanceReport(const QDateTime &_from, const QDateTime &_to,
|
|||||||
/**
|
/**
|
||||||
* @fn plugin
|
* @fn plugin
|
||||||
*/
|
*/
|
||||||
QueuedResult<QueuedPluginSpecification::Plugin>
|
QueuedResult<QueuedPluginSpecification::Plugin> QueuedCore::plugin(const QString &_plugin,
|
||||||
QueuedCore::plugin(const QString &_plugin, const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get data for plugin" << _plugin;
|
qCDebug(LOG_LIB) << "Get data for plugin" << _plugin;
|
||||||
|
|
||||||
@ -223,8 +215,7 @@ QueuedCore::plugin(const QString &_plugin, const QString &_token)
|
|||||||
/**
|
/**
|
||||||
* @fn pluginSettings
|
* @fn pluginSettings
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariantHash> QueuedCore::pluginSettings(const QString &_plugin,
|
QueuedResult<QVariantHash> QueuedCore::pluginSettings(const QString &_plugin, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get plugin settings for" << _plugin;
|
qCDebug(LOG_LIB) << "Get plugin settings for" << _plugin;
|
||||||
|
|
||||||
@ -235,8 +226,7 @@ QueuedResult<QVariantHash> QueuedCore::pluginSettings(const QString &_plugin,
|
|||||||
/**
|
/**
|
||||||
* @fn removePlugin
|
* @fn removePlugin
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCore::removePlugin(const QString &_plugin,
|
QueuedResult<bool> QueuedCore::removePlugin(const QString &_plugin, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Remove plugin" << _plugin;
|
qCDebug(LOG_LIB) << "Remove plugin" << _plugin;
|
||||||
|
|
||||||
@ -247,8 +237,7 @@ QueuedResult<bool> QueuedCore::removePlugin(const QString &_plugin,
|
|||||||
/**
|
/**
|
||||||
* @fn startTask
|
* @fn startTask
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCore::startTask(const long long _id,
|
QueuedResult<bool> QueuedCore::startTask(const long long _id, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Force start task with ID" << _id;
|
qCDebug(LOG_LIB) << "Force start task with ID" << _id;
|
||||||
|
|
||||||
@ -259,8 +248,7 @@ QueuedResult<bool> QueuedCore::startTask(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn stopTask
|
* @fn stopTask
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCore::stopTask(const long long _id,
|
QueuedResult<bool> QueuedCore::stopTask(const long long _id, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Force stop task with ID" << _id;
|
qCDebug(LOG_LIB) << "Force stop task with ID" << _id;
|
||||||
|
|
||||||
@ -271,8 +259,7 @@ QueuedResult<bool> QueuedCore::stopTask(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn task
|
* @fn task
|
||||||
*/
|
*/
|
||||||
const QueuedProcess *QueuedCore::task(const long long _id,
|
const QueuedProcess *QueuedCore::task(const long long _id, const QString &_token) const
|
||||||
const QString &_token) const
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get task by ID" << _id;
|
qCDebug(LOG_LIB) << "Get task by ID" << _id;
|
||||||
|
|
||||||
@ -283,9 +270,10 @@ const QueuedProcess *QueuedCore::task(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn taskReport
|
* @fn taskReport
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>>
|
QueuedResult<QList<QVariantHash>> QueuedCore::taskReport(const long long _user,
|
||||||
QueuedCore::taskReport(const long long _user, const QDateTime &_from,
|
const QDateTime &_from,
|
||||||
const QDateTime &_to, const QString &_token) const
|
const QDateTime &_to,
|
||||||
|
const QString &_token) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get tasks table by" << _user << _from << _to;
|
qCDebug(LOG_LIB) << "Get tasks table by" << _user << _from << _to;
|
||||||
|
|
||||||
@ -296,8 +284,7 @@ QueuedCore::taskReport(const long long _user, const QDateTime &_from,
|
|||||||
/**
|
/**
|
||||||
* @fn user
|
* @fn user
|
||||||
*/
|
*/
|
||||||
const QueuedUser *QueuedCore::user(const long long _id,
|
const QueuedUser *QueuedCore::user(const long long _id, const QString &_token) const
|
||||||
const QString &_token) const
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get user by ID" << _id;
|
qCDebug(LOG_LIB) << "Get user by ID" << _id;
|
||||||
|
|
||||||
@ -308,8 +295,7 @@ const QueuedUser *QueuedCore::user(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn user
|
* @fn user
|
||||||
*/
|
*/
|
||||||
const QueuedUser *QueuedCore::user(const QString &_name,
|
const QueuedUser *QueuedCore::user(const QString &_name, const QString &_token) const
|
||||||
const QString &_token) const
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get user by name" << _name;
|
qCDebug(LOG_LIB) << "Get user by name" << _name;
|
||||||
|
|
||||||
@ -320,13 +306,11 @@ const QueuedUser *QueuedCore::user(const QString &_name,
|
|||||||
/**
|
/**
|
||||||
* @fn userReport
|
* @fn userReport
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>>
|
QueuedResult<QList<QVariantHash>> QueuedCore::userReport(const QDateTime &_lastLogged,
|
||||||
QueuedCore::userReport(const QDateTime &_lastLogged,
|
const QueuedEnums::Permission _permission,
|
||||||
const QueuedEnums::Permission _permission,
|
const QString &_token) const
|
||||||
const QString &_token) const
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get users table by" << _lastLogged
|
qCDebug(LOG_LIB) << "Get users table by" << _lastLogged << static_cast<int>(_permission);
|
||||||
<< static_cast<int>(_permission);
|
|
||||||
|
|
||||||
return m_impl->userReport(_lastLogged, _permission, _token);
|
return m_impl->userReport(_lastLogged, _permission, _token);
|
||||||
}
|
}
|
||||||
@ -340,12 +324,9 @@ void QueuedCore::deinit()
|
|||||||
m_impl->deinit();
|
m_impl->deinit();
|
||||||
|
|
||||||
// dbus cleanup
|
// dbus cleanup
|
||||||
QDBusConnection::systemBus().unregisterObject(
|
QDBusConnection::systemBus().unregisterObject(QueuedConfig::DBUS_OBJECT_PATH);
|
||||||
QueuedConfig::DBUS_OBJECT_PATH);
|
QDBusConnection::systemBus().unregisterObject(QueuedConfig::DBUS_PROPERTY_PATH);
|
||||||
QDBusConnection::systemBus().unregisterObject(
|
QDBusConnection::systemBus().unregisterObject(QueuedConfig::DBUS_REPORTS_PATH);
|
||||||
QueuedConfig::DBUS_PROPERTY_PATH);
|
|
||||||
QDBusConnection::systemBus().unregisterObject(
|
|
||||||
QueuedConfig::DBUS_REPORTS_PATH);
|
|
||||||
QDBusConnection::systemBus().unregisterService(QueuedConfig::DBUS_SERVICE);
|
QDBusConnection::systemBus().unregisterService(QueuedConfig::DBUS_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,33 +353,29 @@ void QueuedCore::initDBus()
|
|||||||
QDBusConnection bus = QDBusConnection::systemBus();
|
QDBusConnection bus = QDBusConnection::systemBus();
|
||||||
|
|
||||||
if (!bus.registerService(QueuedConfig::DBUS_SERVICE)) {
|
if (!bus.registerService(QueuedConfig::DBUS_SERVICE)) {
|
||||||
QString message = QString("Could not register service %1")
|
QString message = QString("Could not register service %1").arg(bus.lastError().message());
|
||||||
.arg(bus.lastError().message());
|
|
||||||
qCCritical(LOG_DBUS) << message;
|
qCCritical(LOG_DBUS) << message;
|
||||||
throw QueuedDBusException(message);
|
throw QueuedDBusException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bus.registerObject(QueuedConfig::DBUS_OBJECT_PATH,
|
if (!bus.registerObject(QueuedConfig::DBUS_OBJECT_PATH, new QueuedCoreInterface(this),
|
||||||
new QueuedCoreInterface(this),
|
|
||||||
QDBusConnection::ExportAllContents)) {
|
QDBusConnection::ExportAllContents)) {
|
||||||
QString message = QString("Could not register core object %1")
|
QString message
|
||||||
.arg(bus.lastError().message());
|
= QString("Could not register core object %1").arg(bus.lastError().message());
|
||||||
qCCritical(LOG_DBUS) << message;
|
qCCritical(LOG_DBUS) << message;
|
||||||
throw QueuedDBusException(message);
|
throw QueuedDBusException(message);
|
||||||
}
|
}
|
||||||
if (!bus.registerObject(QueuedConfig::DBUS_PROPERTY_PATH,
|
if (!bus.registerObject(QueuedConfig::DBUS_PROPERTY_PATH, new QueuedPropertyInterface(this),
|
||||||
new QueuedPropertyInterface(this),
|
|
||||||
QDBusConnection::ExportAllContents)) {
|
QDBusConnection::ExportAllContents)) {
|
||||||
QString message = QString("Could not register properties object %1")
|
QString message
|
||||||
.arg(bus.lastError().message());
|
= QString("Could not register properties object %1").arg(bus.lastError().message());
|
||||||
qCCritical(LOG_DBUS) << message;
|
qCCritical(LOG_DBUS) << message;
|
||||||
throw QueuedDBusException(message);
|
throw QueuedDBusException(message);
|
||||||
}
|
}
|
||||||
if (!bus.registerObject(QueuedConfig::DBUS_REPORTS_PATH,
|
if (!bus.registerObject(QueuedConfig::DBUS_REPORTS_PATH, new QueuedReportInterface(this),
|
||||||
new QueuedReportInterface(this),
|
|
||||||
QDBusConnection::ExportAllContents)) {
|
QDBusConnection::ExportAllContents)) {
|
||||||
QString message = QString("Could not register reports object %1")
|
QString message
|
||||||
.arg(bus.lastError().message());
|
= QString("Could not register reports object %1").arg(bus.lastError().message());
|
||||||
qCCritical(LOG_DBUS) << message;
|
qCCritical(LOG_DBUS) << message;
|
||||||
throw QueuedDBusException(message);
|
throw QueuedDBusException(message);
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,7 @@
|
|||||||
QueuedResult<bool> QueuedCoreAdaptor::auth(const QString &_token)
|
QueuedResult<bool> QueuedCoreAdaptor::auth(const QString &_token)
|
||||||
{
|
{
|
||||||
QVariantList args = {_token};
|
QVariantList args = {_token};
|
||||||
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
|
||||||
QueuedConfig::DBUS_SERVICE, "TryAuth", args);
|
QueuedConfig::DBUS_SERVICE, "TryAuth", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,14 +39,12 @@ QueuedResult<bool> QueuedCoreAdaptor::auth(const QString &_token)
|
|||||||
/**
|
/**
|
||||||
* @fn auth
|
* @fn auth
|
||||||
*/
|
*/
|
||||||
QueuedResult<QString> QueuedCoreAdaptor::auth(const QString &_name,
|
QueuedResult<QString> QueuedCoreAdaptor::auth(const QString &_name, const QString &_password)
|
||||||
const QString &_password)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Auth user" << _name;
|
qCDebug(LOG_DBUS) << "Auth user" << _name;
|
||||||
|
|
||||||
QVariantList args = {_name, _password};
|
QVariantList args = {_name, _password};
|
||||||
return sendRequest<QString>(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<QString>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
|
||||||
QueuedConfig::DBUS_SERVICE, "Auth", args);
|
QueuedConfig::DBUS_SERVICE, "Auth", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,16 +52,13 @@ QueuedResult<QString> QueuedCoreAdaptor::auth(const QString &_name,
|
|||||||
/**
|
/**
|
||||||
* @fn sendOptionEdit
|
* @fn sendOptionEdit
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCoreAdaptor::sendOptionEdit(const QString &_key,
|
QueuedResult<bool> QueuedCoreAdaptor::sendOptionEdit(const QString &_key, const QVariant &_value,
|
||||||
const QVariant &_value,
|
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Edit option" << _key << "to" << _value;
|
qCDebug(LOG_DBUS) << "Edit option" << _key << "to" << _value;
|
||||||
|
|
||||||
QVariantList args
|
QVariantList args = {_key, QVariant::fromValue(QDBusVariant(_value)), _token};
|
||||||
= {_key, QVariant::fromValue(QDBusVariant(_value)), _token};
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
|
||||||
QueuedConfig::DBUS_SERVICE, "OptionEdit", args);
|
QueuedConfig::DBUS_SERVICE, "OptionEdit", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,27 +66,23 @@ QueuedResult<bool> QueuedCoreAdaptor::sendOptionEdit(const QString &_key,
|
|||||||
/**
|
/**
|
||||||
* @fn sendPasswordHash
|
* @fn sendPasswordHash
|
||||||
*/
|
*/
|
||||||
QueuedResult<QString>
|
QueuedResult<QString> QueuedCoreAdaptor::sendPasswordHash(const QString &_password)
|
||||||
QueuedCoreAdaptor::sendPasswordHash(const QString &_password)
|
|
||||||
{
|
{
|
||||||
QVariantList args = {_password};
|
QVariantList args = {_password};
|
||||||
return sendRequest<QString>(
|
return sendRequest<QString>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_SERVICE, "PasswordHash", args);
|
||||||
QueuedConfig::DBUS_SERVICE, "PasswordHash", args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn sendPluginAdd
|
* @fn sendPluginAdd
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCoreAdaptor::sendPluginAdd(const QString &_plugin,
|
QueuedResult<bool> QueuedCoreAdaptor::sendPluginAdd(const QString &_plugin, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Add plugin" << _plugin;
|
qCDebug(LOG_DBUS) << "Add plugin" << _plugin;
|
||||||
|
|
||||||
QVariantList args = {_plugin, _token};
|
QVariantList args = {_plugin, _token};
|
||||||
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
|
||||||
QueuedConfig::DBUS_SERVICE, "PluginAdd", args);
|
QueuedConfig::DBUS_SERVICE, "PluginAdd", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,8 +96,7 @@ QueuedResult<bool> QueuedCoreAdaptor::sendPluginRemove(const QString &_plugin,
|
|||||||
qCDebug(LOG_DBUS) << "Remove plugin" << _plugin;
|
qCDebug(LOG_DBUS) << "Remove plugin" << _plugin;
|
||||||
|
|
||||||
QVariantList args = {_plugin, _token};
|
QVariantList args = {_plugin, _token};
|
||||||
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
|
||||||
QueuedConfig::DBUS_SERVICE, "PluginRemove", args);
|
QueuedConfig::DBUS_SERVICE, "PluginRemove", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,9 +104,9 @@ QueuedResult<bool> QueuedCoreAdaptor::sendPluginRemove(const QString &_plugin,
|
|||||||
/**
|
/**
|
||||||
* @fn sendTaskAdd
|
* @fn sendTaskAdd
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long> QueuedCoreAdaptor::sendTaskAdd(
|
QueuedResult<long long>
|
||||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
QueuedCoreAdaptor::sendTaskAdd(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Add task" << _definitions.command;
|
qCDebug(LOG_DBUS) << "Add task" << _definitions.command;
|
||||||
|
|
||||||
@ -133,8 +122,7 @@ QueuedResult<long long> QueuedCoreAdaptor::sendTaskAdd(
|
|||||||
limits.gpumemory,
|
limits.gpumemory,
|
||||||
limits.storage,
|
limits.storage,
|
||||||
_token};
|
_token};
|
||||||
return sendRequest<long long>(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<long long>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
|
||||||
QueuedConfig::DBUS_SERVICE, "TaskAdd", args);
|
QueuedConfig::DBUS_SERVICE, "TaskAdd", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,10 +130,10 @@ QueuedResult<long long> QueuedCoreAdaptor::sendTaskAdd(
|
|||||||
/**
|
/**
|
||||||
* @fn sendTaskEdit
|
* @fn sendTaskEdit
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCoreAdaptor::sendTaskEdit(
|
QueuedResult<bool>
|
||||||
const long long _id,
|
QueuedCoreAdaptor::sendTaskEdit(const long long _id,
|
||||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Edit task" << _id;
|
qCDebug(LOG_DBUS) << "Edit task" << _id;
|
||||||
|
|
||||||
@ -164,8 +152,7 @@ QueuedResult<bool> QueuedCoreAdaptor::sendTaskEdit(
|
|||||||
limits.gpumemory,
|
limits.gpumemory,
|
||||||
limits.storage,
|
limits.storage,
|
||||||
_token};
|
_token};
|
||||||
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
|
||||||
QueuedConfig::DBUS_SERVICE, "TaskEdit", args);
|
QueuedConfig::DBUS_SERVICE, "TaskEdit", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,14 +160,12 @@ QueuedResult<bool> QueuedCoreAdaptor::sendTaskEdit(
|
|||||||
/**
|
/**
|
||||||
* @fn sendTaskStart
|
* @fn sendTaskStart
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCoreAdaptor::sendTaskStart(const long long _id,
|
QueuedResult<bool> QueuedCoreAdaptor::sendTaskStart(const long long _id, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Start task" << _id;
|
qCDebug(LOG_DBUS) << "Start task" << _id;
|
||||||
|
|
||||||
QVariantList args = {_id, _token};
|
QVariantList args = {_id, _token};
|
||||||
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
|
||||||
QueuedConfig::DBUS_SERVICE, "TaskStart", args);
|
QueuedConfig::DBUS_SERVICE, "TaskStart", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,14 +173,12 @@ QueuedResult<bool> QueuedCoreAdaptor::sendTaskStart(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn sendTaskStop
|
* @fn sendTaskStop
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCoreAdaptor::sendTaskStop(const long long _id,
|
QueuedResult<bool> QueuedCoreAdaptor::sendTaskStop(const long long _id, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Stop task" << _id;
|
qCDebug(LOG_DBUS) << "Stop task" << _id;
|
||||||
|
|
||||||
QVariantList args = {_id, _token};
|
QVariantList args = {_id, _token};
|
||||||
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
|
||||||
QueuedConfig::DBUS_SERVICE, "TaskStop", args);
|
QueuedConfig::DBUS_SERVICE, "TaskStop", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,9 +186,9 @@ QueuedResult<bool> QueuedCoreAdaptor::sendTaskStop(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn sendUserAdd
|
* @fn sendUserAdd
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long> QueuedCoreAdaptor::sendUserAdd(
|
QueuedResult<long long>
|
||||||
const QueuedUser::QueuedUserDefinitions &_definitions,
|
QueuedCoreAdaptor::sendUserAdd(const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Add user" << _definitions.name;
|
qCDebug(LOG_DBUS) << "Add user" << _definitions.name;
|
||||||
|
|
||||||
@ -221,8 +204,7 @@ QueuedResult<long long> QueuedCoreAdaptor::sendUserAdd(
|
|||||||
limits.gpumemory,
|
limits.gpumemory,
|
||||||
limits.storage,
|
limits.storage,
|
||||||
_token};
|
_token};
|
||||||
return sendRequest<long long>(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<long long>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
|
||||||
QueuedConfig::DBUS_SERVICE, "UserAdd", args);
|
QueuedConfig::DBUS_SERVICE, "UserAdd", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,25 +212,18 @@ QueuedResult<long long> QueuedCoreAdaptor::sendUserAdd(
|
|||||||
/**
|
/**
|
||||||
* @fn sendUserEdit
|
* @fn sendUserEdit
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCoreAdaptor::sendUserEdit(
|
QueuedResult<bool>
|
||||||
const long long _id, const QueuedUser::QueuedUserDefinitions &_definitions,
|
QueuedCoreAdaptor::sendUserEdit(const long long _id,
|
||||||
const QString &_token)
|
const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Edit user" << _id;
|
qCDebug(LOG_DBUS) << "Edit user" << _id;
|
||||||
|
|
||||||
auto limits = QueuedLimits::Limits(_definitions.limits);
|
auto limits = QueuedLimits::Limits(_definitions.limits);
|
||||||
QVariantList args = {_id,
|
QVariantList args
|
||||||
_definitions.name,
|
= {_id, _definitions.name, _definitions.password, _definitions.email, limits.cpu,
|
||||||
_definitions.password,
|
limits.gpu, limits.memory, limits.gpumemory, limits.storage, _token};
|
||||||
_definitions.email,
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
limits.cpu,
|
|
||||||
limits.gpu,
|
|
||||||
limits.memory,
|
|
||||||
limits.gpumemory,
|
|
||||||
limits.storage,
|
|
||||||
_token};
|
|
||||||
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE,
|
|
||||||
QueuedConfig::DBUS_OBJECT_PATH,
|
|
||||||
QueuedConfig::DBUS_SERVICE, "UserEdit", args);
|
QueuedConfig::DBUS_SERVICE, "UserEdit", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,16 +232,13 @@ QueuedResult<bool> QueuedCoreAdaptor::sendUserEdit(
|
|||||||
* @fn sendUserPermissionAdd
|
* @fn sendUserPermissionAdd
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCoreAdaptor::sendUserPermissionAdd(
|
QueuedResult<bool> QueuedCoreAdaptor::sendUserPermissionAdd(
|
||||||
const long long _id, const QueuedEnums::Permission _permission,
|
const long long _id, const QueuedEnums::Permission _permission, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Add permission" << static_cast<int>(_permission)
|
qCDebug(LOG_DBUS) << "Add permission" << static_cast<int>(_permission) << "to" << _id;
|
||||||
<< "to" << _id;
|
|
||||||
|
|
||||||
QVariantList args = {_id, static_cast<uint>(_permission), _token};
|
QVariantList args = {_id, static_cast<uint>(_permission), _token};
|
||||||
return sendRequest<bool>(
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_SERVICE, "UserPermissionAdd", args);
|
||||||
QueuedConfig::DBUS_SERVICE, "UserPermissionAdd", args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -274,63 +246,56 @@ QueuedResult<bool> QueuedCoreAdaptor::sendUserPermissionAdd(
|
|||||||
* @fn sendUserPermissionRemove
|
* @fn sendUserPermissionRemove
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCoreAdaptor::sendUserPermissionRemove(
|
QueuedResult<bool> QueuedCoreAdaptor::sendUserPermissionRemove(
|
||||||
const long long _id, const QueuedEnums::Permission _permission,
|
const long long _id, const QueuedEnums::Permission _permission, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Remove permission" << static_cast<int>(_permission)
|
qCDebug(LOG_DBUS) << "Remove permission" << static_cast<int>(_permission) << "from" << _id;
|
||||||
<< "from" << _id;
|
|
||||||
|
|
||||||
QVariantList args = {_id, static_cast<uint>(_permission), _token};
|
QVariantList args = {_id, static_cast<uint>(_permission), _token};
|
||||||
return sendRequest<bool>(
|
return sendRequest<bool>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_OBJECT_PATH,
|
QueuedConfig::DBUS_SERVICE, "UserPermissionRemove", args);
|
||||||
QueuedConfig::DBUS_SERVICE, "UserPermissionRemove", args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getPlugin
|
* @fn getPlugin
|
||||||
*/
|
*/
|
||||||
QueuedResult<QueuedPluginSpecification::Plugin>
|
QueuedResult<QueuedPluginSpecification::Plugin> QueuedCoreAdaptor::getPlugin(const QString &_plugin,
|
||||||
QueuedCoreAdaptor::getPlugin(const QString &_plugin, const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get information for plugin" << _plugin;
|
qCDebug(LOG_DBUS) << "Get information for plugin" << _plugin;
|
||||||
|
|
||||||
QVariantList args = {_plugin, _token};
|
QVariantList args = {_plugin, _token};
|
||||||
|
|
||||||
return sendRequest<QueuedPluginSpecification::Plugin>(
|
return sendRequest<QueuedPluginSpecification::Plugin>(
|
||||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_PROPERTY_PATH,
|
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_PROPERTY_PATH, QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_SERVICE, "Plugin", args);
|
"Plugin", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getPluginOptions
|
* @fn getPluginOptions
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariantHash>
|
QueuedResult<QVariantHash> QueuedCoreAdaptor::getPluginOptions(const QString &_plugin,
|
||||||
QueuedCoreAdaptor::getPluginOptions(const QString &_plugin,
|
const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get options for plugin" << _plugin;
|
qCDebug(LOG_DBUS) << "Get options for plugin" << _plugin;
|
||||||
|
|
||||||
QVariantList args = {_plugin, _token};
|
QVariantList args = {_plugin, _token};
|
||||||
|
|
||||||
return sendRequest<QVariantHash>(
|
return sendRequest<QVariantHash>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_PROPERTY_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_PROPERTY_PATH,
|
QueuedConfig::DBUS_SERVICE, "PluginOptions", args);
|
||||||
QueuedConfig::DBUS_SERVICE, "PluginOptions", args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getOption
|
* @fn getOption
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant> QueuedCoreAdaptor::getOption(const QString &_property,
|
QueuedResult<QVariant> QueuedCoreAdaptor::getOption(const QString &_property, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get option" << _property;
|
qCDebug(LOG_DBUS) << "Get option" << _property;
|
||||||
|
|
||||||
QVariantList args = {_property, _token};
|
QVariantList args = {_property, _token};
|
||||||
return sendRequest<QVariant>(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<QVariant>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_PROPERTY_PATH,
|
||||||
QueuedConfig::DBUS_PROPERTY_PATH,
|
|
||||||
QueuedConfig::DBUS_SERVICE, "Option", args);
|
QueuedConfig::DBUS_SERVICE, "Option", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,9 +303,8 @@ QueuedResult<QVariant> QueuedCoreAdaptor::getOption(const QString &_property,
|
|||||||
/**
|
/**
|
||||||
* @fn getOption
|
* @fn getOption
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant>
|
QueuedResult<QVariant> QueuedCoreAdaptor::getOption(const QueuedConfig::QueuedSettings _property,
|
||||||
QueuedCoreAdaptor::getOption(const QueuedConfig::QueuedSettings _property,
|
const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get option" << static_cast<int>(_property);
|
qCDebug(LOG_DBUS) << "Get option" << static_cast<int>(_property);
|
||||||
|
|
||||||
@ -351,17 +315,17 @@ QueuedCoreAdaptor::getOption(const QueuedConfig::QueuedSettings _property,
|
|||||||
/**
|
/**
|
||||||
* @fn getPerformance
|
* @fn getPerformance
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>>
|
QueuedResult<QList<QVariantHash>> QueuedCoreAdaptor::getPerformance(const QDateTime &_from,
|
||||||
QueuedCoreAdaptor::getPerformance(const QDateTime &_from, const QDateTime &_to,
|
const QDateTime &_to,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get performance report for" << _from << _to;
|
qCDebug(LOG_DBUS) << "Get performance report for" << _from << _to;
|
||||||
|
|
||||||
QVariantList args = {_from.toString(Qt::ISODateWithMs),
|
QVariantList args
|
||||||
_to.toString(Qt::ISODateWithMs), _token};
|
= {_from.toString(Qt::ISODateWithMs), _to.toString(Qt::ISODateWithMs), _token};
|
||||||
return sendRequest<QList<QVariantHash>>(
|
return sendRequest<QList<QVariantHash>>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_REPORTS_PATH,
|
QueuedConfig::DBUS_REPORTS_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "Performance", args);
|
QueuedConfig::DBUS_SERVICE, "Performance", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -370,28 +334,23 @@ QueuedCoreAdaptor::getPerformance(const QDateTime &_from, const QDateTime &_to,
|
|||||||
*/
|
*/
|
||||||
QueuedResult<QueuedStatusMap> QueuedCoreAdaptor::getStatus()
|
QueuedResult<QueuedStatusMap> QueuedCoreAdaptor::getStatus()
|
||||||
{
|
{
|
||||||
return sendRequest<QueuedStatusMap>(
|
return sendRequest<QueuedStatusMap>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_REPORTS_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_REPORTS_PATH,
|
QueuedConfig::DBUS_SERVICE, "Status", {});
|
||||||
QueuedConfig::DBUS_SERVICE, "Status", {});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getTask
|
* @fn getTask
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariantHash> QueuedCoreAdaptor::getTask(const long long _id,
|
QueuedResult<QVariantHash> QueuedCoreAdaptor::getTask(const long long _id, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get task properties" << _id;
|
qCDebug(LOG_DBUS) << "Get task properties" << _id;
|
||||||
|
|
||||||
auto res = getTask(_id, "", _token);
|
auto res = getTask(_id, "", _token);
|
||||||
|
|
||||||
QueuedResult<QVariantHash> output;
|
QueuedResult<QVariantHash> output;
|
||||||
res.match(
|
res.match([&output](const QVariant &val) { output = toResult<QVariantHash>(val); },
|
||||||
[&output](const QVariant &val) {
|
[&output](const QueuedError &err) { output = err; });
|
||||||
output = toResult<QVariantHash>(val);
|
|
||||||
},
|
|
||||||
[&output](const QueuedError &err) { output = err; });
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -400,15 +359,13 @@ QueuedResult<QVariantHash> QueuedCoreAdaptor::getTask(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn getTask
|
* @fn getTask
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant> QueuedCoreAdaptor::getTask(const long long _id,
|
QueuedResult<QVariant> QueuedCoreAdaptor::getTask(const long long _id, const QString &_property,
|
||||||
const QString &_property,
|
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get task property" << _id << _property;
|
qCDebug(LOG_DBUS) << "Get task property" << _id << _property;
|
||||||
|
|
||||||
QVariantList args = {_id, _property, _token};
|
QVariantList args = {_id, _property, _token};
|
||||||
return sendRequest<QVariant>(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<QVariant>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_PROPERTY_PATH,
|
||||||
QueuedConfig::DBUS_PROPERTY_PATH,
|
|
||||||
QueuedConfig::DBUS_SERVICE, "Task", args);
|
QueuedConfig::DBUS_SERVICE, "Task", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,36 +373,33 @@ QueuedResult<QVariant> QueuedCoreAdaptor::getTask(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn getTasks
|
* @fn getTasks
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>>
|
QueuedResult<QList<QVariantHash>> QueuedCoreAdaptor::getTasks(const long long _user,
|
||||||
QueuedCoreAdaptor::getTasks(const long long _user, const QDateTime &_from,
|
const QDateTime &_from,
|
||||||
const QDateTime &_to, const QString &_token)
|
const QDateTime &_to,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get tasks list for" << _user << _from << _to;
|
qCDebug(LOG_DBUS) << "Get tasks list for" << _user << _from << _to;
|
||||||
|
|
||||||
QVariantList args = {_user, _from.toString(Qt::ISODateWithMs),
|
QVariantList args
|
||||||
_to.toString(Qt::ISODateWithMs), _token};
|
= {_user, _from.toString(Qt::ISODateWithMs), _to.toString(Qt::ISODateWithMs), _token};
|
||||||
return sendRequest<QList<QVariantHash>>(
|
return sendRequest<QList<QVariantHash>>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_REPORTS_PATH,
|
QueuedConfig::DBUS_REPORTS_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "Tasks", args);
|
QueuedConfig::DBUS_SERVICE, "Tasks", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn getUser
|
* @fn getUser
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariantHash> QueuedCoreAdaptor::getUser(const long long _id,
|
QueuedResult<QVariantHash> QueuedCoreAdaptor::getUser(const long long _id, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get user property" << _id;
|
qCDebug(LOG_DBUS) << "Get user property" << _id;
|
||||||
|
|
||||||
auto res = getUser(_id, "", _token);
|
auto res = getUser(_id, "", _token);
|
||||||
|
|
||||||
QueuedResult<QVariantHash> output;
|
QueuedResult<QVariantHash> output;
|
||||||
res.match(
|
res.match([&output](const QVariant &val) { output = toResult<QVariantHash>(val); },
|
||||||
[&output](const QVariant &val) {
|
[&output](const QueuedError &err) { output = err; });
|
||||||
output = toResult<QVariantHash>(val);
|
|
||||||
},
|
|
||||||
[&output](const QueuedError &err) { output = err; });
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -454,15 +408,13 @@ QueuedResult<QVariantHash> QueuedCoreAdaptor::getUser(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn getUser
|
* @fn getUser
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant> QueuedCoreAdaptor::getUser(const long long _id,
|
QueuedResult<QVariant> QueuedCoreAdaptor::getUser(const long long _id, const QString &_property,
|
||||||
const QString &_property,
|
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get user property" << _id << _property;
|
qCDebug(LOG_DBUS) << "Get user property" << _id << _property;
|
||||||
|
|
||||||
QVariantList args = {_id, _property, _token};
|
QVariantList args = {_id, _property, _token};
|
||||||
return sendRequest<QVariant>(QueuedConfig::DBUS_SERVICE,
|
return sendRequest<QVariant>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_PROPERTY_PATH,
|
||||||
QueuedConfig::DBUS_PROPERTY_PATH,
|
|
||||||
QueuedConfig::DBUS_SERVICE, "User", args);
|
QueuedConfig::DBUS_SERVICE, "User", args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -470,8 +422,7 @@ QueuedResult<QVariant> QueuedCoreAdaptor::getUser(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn getUserId
|
* @fn getUserId
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long> QueuedCoreAdaptor::getUserId(const QString &_name,
|
QueuedResult<long long> QueuedCoreAdaptor::getUserId(const QString &_name, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get user ID for" << _name;
|
qCDebug(LOG_DBUS) << "Get user ID for" << _name;
|
||||||
|
|
||||||
@ -481,9 +432,8 @@ QueuedResult<long long> QueuedCoreAdaptor::getUserId(const QString &_name,
|
|||||||
return stringToLong;
|
return stringToLong;
|
||||||
|
|
||||||
QVariantList args = {_name, _token};
|
QVariantList args = {_name, _token};
|
||||||
return sendRequest<long long>(
|
return sendRequest<long long>(QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_PROPERTY_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_PROPERTY_PATH,
|
QueuedConfig::DBUS_SERVICE, "UserIdByName", args);
|
||||||
QueuedConfig::DBUS_SERVICE, "UserIdByName", args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -491,16 +441,14 @@ QueuedResult<long long> QueuedCoreAdaptor::getUserId(const QString &_name,
|
|||||||
* @fn getUsers
|
* @fn getUsers
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>>
|
QueuedResult<QList<QVariantHash>>
|
||||||
QueuedCoreAdaptor::getUsers(const QDateTime &_lastLogged,
|
QueuedCoreAdaptor::getUsers(const QDateTime &_lastLogged, const QueuedEnums::Permission _permission,
|
||||||
const QueuedEnums::Permission _permission,
|
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get users list for" << _lastLogged
|
qCDebug(LOG_DBUS) << "Get users list for" << _lastLogged << static_cast<int>(_permission);
|
||||||
<< static_cast<int>(_permission);
|
|
||||||
|
|
||||||
QVariantList args = {_lastLogged.toString(Qt::ISODateWithMs),
|
QVariantList args
|
||||||
static_cast<uint>(_permission), _token};
|
= {_lastLogged.toString(Qt::ISODateWithMs), static_cast<uint>(_permission), _token};
|
||||||
return sendRequest<QList<QVariantHash>>(
|
return sendRequest<QList<QVariantHash>>(QueuedConfig::DBUS_SERVICE,
|
||||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_REPORTS_PATH,
|
QueuedConfig::DBUS_REPORTS_PATH,
|
||||||
QueuedConfig::DBUS_SERVICE, "Users", args);
|
QueuedConfig::DBUS_SERVICE, "Users", args);
|
||||||
}
|
}
|
||||||
|
@ -61,27 +61,23 @@ QueuedCoreInterface::~QueuedCoreInterface()
|
|||||||
/**
|
/**
|
||||||
* @fn Auth
|
* @fn Auth
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedCoreInterface::Auth(const QString &name,
|
QDBusVariant QueuedCoreInterface::Auth(const QString &name, const QString &password)
|
||||||
const QString &password)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Authorize user" << name;
|
qCDebug(LOG_DBUS) << "Authorize user" << name;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::toDBusVariant(
|
return QueuedCoreAdaptor::toDBusVariant(m_core->authorization(name, password));
|
||||||
m_core->authorization(name, password));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn OptionEdit
|
* @fn OptionEdit
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedCoreInterface::OptionEdit(const QString &key,
|
QDBusVariant QueuedCoreInterface::OptionEdit(const QString &key, const QDBusVariant &value,
|
||||||
const QDBusVariant &value,
|
|
||||||
const QString &token)
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Edit option" << key << value.variant();
|
qCDebug(LOG_DBUS) << "Edit option" << key << value.variant();
|
||||||
|
|
||||||
return QueuedCoreAdaptor::toDBusVariant(
|
return QueuedCoreAdaptor::toDBusVariant(m_core->editOption(key, value.variant(), token));
|
||||||
m_core->editOption(key, value.variant(), token));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -97,8 +93,7 @@ QDBusVariant QueuedCoreInterface::PasswordHash(const QString &password)
|
|||||||
/**
|
/**
|
||||||
* @fn PluginAdd
|
* @fn PluginAdd
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedCoreInterface::PluginAdd(const QString &plugin,
|
QDBusVariant QueuedCoreInterface::PluginAdd(const QString &plugin, const QString &token)
|
||||||
const QString &token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Add plugin" << plugin;
|
qCDebug(LOG_DBUS) << "Add plugin" << plugin;
|
||||||
|
|
||||||
@ -109,54 +104,51 @@ QDBusVariant QueuedCoreInterface::PluginAdd(const QString &plugin,
|
|||||||
/**
|
/**
|
||||||
* @fn PluginRemove
|
* @fn PluginRemove
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedCoreInterface::PluginRemove(const QString &plugin,
|
QDBusVariant QueuedCoreInterface::PluginRemove(const QString &plugin, const QString &token)
|
||||||
const QString &token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Remove plugin" << plugin;
|
qCDebug(LOG_DBUS) << "Remove plugin" << plugin;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::toDBusVariant(
|
return QueuedCoreAdaptor::toDBusVariant(m_core->removePlugin(plugin, token));
|
||||||
m_core->removePlugin(plugin, token));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn TaskAdd
|
* @fn TaskAdd
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedCoreInterface::TaskAdd(
|
QDBusVariant QueuedCoreInterface::TaskAdd(const QString &command, const QStringList &arguments,
|
||||||
const QString &command, const QStringList &arguments,
|
const QString &workingDirectory, const qlonglong user,
|
||||||
const QString &workingDirectory, const qlonglong user, const uint nice,
|
const uint nice, const qlonglong cpu, const qlonglong gpu,
|
||||||
const qlonglong cpu, const qlonglong gpu, const qlonglong memory,
|
const qlonglong memory, const qlonglong gpumemory,
|
||||||
const qlonglong gpumemory, const qlonglong storage, const QString &token)
|
const qlonglong storage, const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Add new task with parameters" << command << arguments
|
qCDebug(LOG_DBUS) << "Add new task with parameters" << command << arguments << workingDirectory
|
||||||
<< workingDirectory << "from user" << user;
|
<< "from user" << user;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::toDBusVariant(m_core->addTask(
|
return QueuedCoreAdaptor::toDBusVariant(
|
||||||
command, arguments, workingDirectory, user, nice,
|
m_core->addTask(command, arguments, workingDirectory, user, nice,
|
||||||
QueuedLimits::Limits(cpu, gpu, memory, gpumemory, storage), token));
|
QueuedLimits::Limits(cpu, gpu, memory, gpumemory, storage), token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn TaskEdit
|
* @fn TaskEdit
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedCoreInterface::TaskEdit(
|
QDBusVariant QueuedCoreInterface::TaskEdit(const qlonglong id, const QString &command,
|
||||||
const qlonglong id, const QString &command, const QStringList &arguments,
|
const QStringList &arguments, const QString &directory,
|
||||||
const QString &directory, const uint nice, const uint uid, const uint gid,
|
const uint nice, const uint uid, const uint gid,
|
||||||
const qlonglong user, const qlonglong cpu, const qlonglong gpu,
|
const qlonglong user, const qlonglong cpu,
|
||||||
const qlonglong memory, const qlonglong gpumemory, const qlonglong storage,
|
const qlonglong gpu, const qlonglong memory,
|
||||||
const QString &token)
|
const qlonglong gpumemory, const qlonglong storage,
|
||||||
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Edit task" << id << command << arguments << directory
|
qCDebug(LOG_DBUS) << "Edit task" << id << command << arguments << directory << nice << uid
|
||||||
<< nice << uid << gid << cpu << gpu << memory << gpumemory
|
<< gid << cpu << gpu << memory << gpumemory << storage;
|
||||||
<< storage;
|
|
||||||
|
|
||||||
auto task = m_core->task(id, token);
|
auto task = m_core->task(id, token);
|
||||||
if (!task) {
|
if (!task) {
|
||||||
qCWarning(LOG_DBUS) << "Could not find task" << id;
|
qCWarning(LOG_DBUS) << "Could not find task" << id;
|
||||||
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<bool>(
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<bool>(
|
||||||
QueuedError("Task does not exist",
|
QueuedError("Task does not exist", QueuedEnums::ReturnStatus::InvalidArgument)));
|
||||||
QueuedEnums::ReturnStatus::InvalidArgument)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// build payload
|
// build payload
|
||||||
@ -196,8 +188,7 @@ QDBusVariant QueuedCoreInterface::TaskEdit(
|
|||||||
/**
|
/**
|
||||||
* @fn TaskStart
|
* @fn TaskStart
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedCoreInterface::TaskStart(const qlonglong id,
|
QDBusVariant QueuedCoreInterface::TaskStart(const qlonglong id, const QString &token)
|
||||||
const QString &token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Force start task" << id;
|
qCDebug(LOG_DBUS) << "Force start task" << id;
|
||||||
|
|
||||||
@ -208,8 +199,7 @@ QDBusVariant QueuedCoreInterface::TaskStart(const qlonglong id,
|
|||||||
/**
|
/**
|
||||||
* @fn TaskStop
|
* @fn TaskStop
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedCoreInterface::TaskStop(const qlonglong id,
|
QDBusVariant QueuedCoreInterface::TaskStop(const qlonglong id, const QString &token)
|
||||||
const QString &token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Force stop task" << id;
|
qCDebug(LOG_DBUS) << "Force stop task" << id;
|
||||||
|
|
||||||
@ -229,41 +219,39 @@ QDBusVariant QueuedCoreInterface::TryAuth(const QString &token)
|
|||||||
/**
|
/**
|
||||||
* @fn UserAdd
|
* @fn UserAdd
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedCoreInterface::UserAdd(
|
QDBusVariant QueuedCoreInterface::UserAdd(const QString &name, const QString &email,
|
||||||
const QString &name, const QString &email, const QString &password,
|
const QString &password, const uint permissions,
|
||||||
const uint permissions, const uint priority, const qlonglong cpu,
|
const uint priority, const qlonglong cpu,
|
||||||
const qlonglong gpu, const qlonglong memory, const qlonglong gpumemory,
|
const qlonglong gpu, const qlonglong memory,
|
||||||
const qlonglong storage, const QString &token)
|
const qlonglong gpumemory, const qlonglong storage,
|
||||||
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Add new user with paramaters" << name << email
|
qCDebug(LOG_DBUS) << "Add new user with paramaters" << name << email << permissions;
|
||||||
<< permissions;
|
|
||||||
|
|
||||||
return QueuedCoreAdaptor::toDBusVariant(m_core->addUser(
|
return QueuedCoreAdaptor::toDBusVariant(
|
||||||
name, email, password, permissions, priority,
|
m_core->addUser(name, email, password, permissions, priority,
|
||||||
QueuedLimits::Limits(cpu, gpu, memory, gpumemory, storage), token));
|
QueuedLimits::Limits(cpu, gpu, memory, gpumemory, storage), token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn UserEdit
|
* @fn UserEdit
|
||||||
*/
|
*/
|
||||||
QDBusVariant
|
QDBusVariant QueuedCoreInterface::UserEdit(const qlonglong id, const QString &name,
|
||||||
QueuedCoreInterface::UserEdit(const qlonglong id, const QString &name,
|
const QString &password, const QString &email,
|
||||||
const QString &password, const QString &email,
|
const qlonglong cpu, const qlonglong gpu,
|
||||||
const qlonglong cpu, const qlonglong gpu,
|
const qlonglong memory, const qlonglong gpumemory,
|
||||||
const qlonglong memory, const qlonglong gpumemory,
|
const qlonglong storage, const QString &token)
|
||||||
const qlonglong storage, const QString &token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Edit user" << id << name << email << cpu << gpu
|
qCDebug(LOG_DBUS) << "Edit user" << id << name << email << cpu << gpu << memory << gpumemory
|
||||||
<< memory << gpumemory << storage;
|
<< storage;
|
||||||
|
|
||||||
// get user object first to match limits
|
// get user object first to match limits
|
||||||
auto user = m_core->user(id, token);
|
auto user = m_core->user(id, token);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
qCWarning(LOG_DBUS) << "Could not find user" << id;
|
qCWarning(LOG_DBUS) << "Could not find user" << id;
|
||||||
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<bool>(
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<bool>(
|
||||||
QueuedError("User does not exist",
|
QueuedError("User does not exist", QueuedEnums::ReturnStatus::InvalidArgument)));
|
||||||
QueuedEnums::ReturnStatus::InvalidArgument)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// build payload
|
// build payload
|
||||||
@ -295,8 +283,7 @@ QueuedCoreInterface::UserEdit(const qlonglong id, const QString &name,
|
|||||||
/**
|
/**
|
||||||
* @fn UserPermissionAdd
|
* @fn UserPermissionAdd
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedCoreInterface::UserPermissionAdd(const qlonglong id,
|
QDBusVariant QueuedCoreInterface::UserPermissionAdd(const qlonglong id, const uint permission,
|
||||||
const uint permission,
|
|
||||||
const QString &token)
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Add permission" << permission << "to user" << id;
|
qCDebug(LOG_DBUS) << "Add permission" << permission << "to user" << id;
|
||||||
@ -309,8 +296,7 @@ QDBusVariant QueuedCoreInterface::UserPermissionAdd(const qlonglong id,
|
|||||||
/**
|
/**
|
||||||
* @fn UserPermissionRemove
|
* @fn UserPermissionRemove
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedCoreInterface::UserPermissionRemove(const qlonglong id,
|
QDBusVariant QueuedCoreInterface::UserPermissionRemove(const qlonglong id, const uint permission,
|
||||||
const uint permission,
|
|
||||||
const QString &token)
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Remove permission" << permission << "from user" << id;
|
qCDebug(LOG_DBUS) << "Remove permission" << permission << "from user" << id;
|
||||||
|
@ -35,16 +35,14 @@
|
|||||||
/**
|
/**
|
||||||
* @fn addPlugin
|
* @fn addPlugin
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCorePrivate::addPlugin(const QString &_plugin,
|
QueuedResult<bool> QueuedCorePrivate::addPlugin(const QString &_plugin, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add plugin" << _plugin;
|
qCDebug(LOG_LIB) << "Add plugin" << _plugin;
|
||||||
|
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add plugin";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add plugin";
|
||||||
return QueuedError("Not allowed",
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_helper->editPluginPrivate(_plugin, true);
|
return m_helper->editPluginPrivate(_plugin, true);
|
||||||
@ -54,19 +52,20 @@ QueuedResult<bool> QueuedCorePrivate::addPlugin(const QString &_plugin,
|
|||||||
/**
|
/**
|
||||||
* @addTask
|
* @addTask
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long> QueuedCorePrivate::addTask(
|
QueuedResult<long long> QueuedCorePrivate::addTask(const QString &_command,
|
||||||
const QString &_command, const QStringList &_arguments,
|
const QStringList &_arguments,
|
||||||
const QString &_workingDirectory, const long long _userId, const uint _nice,
|
const QString &_workingDirectory,
|
||||||
const QueuedLimits::Limits &_limits, const QString &_token)
|
const long long _userId, const uint _nice,
|
||||||
|
const QueuedLimits::Limits &_limits,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add task" << _command << "with arguments" << _arguments
|
qCDebug(LOG_LIB) << "Add task" << _command << "with arguments" << _arguments << "from user"
|
||||||
<< "from user" << _userId;
|
<< _userId;
|
||||||
|
|
||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
if (!authUser) {
|
if (!authUser) {
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||||
return QueuedError("Invalid token",
|
return QueuedError("Invalid token", QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
QueuedEnums::ReturnStatus::InvalidToken);
|
|
||||||
}
|
}
|
||||||
long long userAuthId = authUser->index();
|
long long userAuthId = authUser->index();
|
||||||
long long actualUserId = (_userId == -1) ? userAuthId : _userId;
|
long long actualUserId = (_userId == -1) ? userAuthId : _userId;
|
||||||
@ -78,54 +77,48 @@ QueuedResult<long long> QueuedCorePrivate::addTask(
|
|||||||
// it means that user places task as own one
|
// it means that user places task as own one
|
||||||
if (!isUser) {
|
if (!isUser) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add task";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add task";
|
||||||
return QueuedError(
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
"Not allowed",
|
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// user tries to place task as another one
|
// user tries to place task as another one
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add task";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add task";
|
||||||
return QueuedError(
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
"Not allowed",
|
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_helper->addTaskPrivate(_command, _arguments, _workingDirectory,
|
return m_helper->addTaskPrivate(_command, _arguments, _workingDirectory, _userId, _nice,
|
||||||
_userId, _nice, _limits);
|
_limits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn addUser
|
* @fn addUser
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long> QueuedCorePrivate::addUser(
|
QueuedResult<long long> QueuedCorePrivate::addUser(const QString &_name, const QString &_email,
|
||||||
const QString &_name, const QString &_email, const QString &_password,
|
const QString &_password,
|
||||||
const uint _permissions, const uint _priority,
|
const uint _permissions, const uint _priority,
|
||||||
const QueuedLimits::Limits &_limits, const QString &_token)
|
const QueuedLimits::Limits &_limits,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add user" << _name << "with email" << _email
|
qCDebug(LOG_LIB) << "Add user" << _name << "with email" << _email << "and permissions"
|
||||||
<< "and permissions" << _permissions;
|
<< _permissions;
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add user";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to add user";
|
||||||
return QueuedError("Not allowed",
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if already exists
|
// check if already exists
|
||||||
auto userObj = user(_name, _token);
|
auto userObj = user(_name, _token);
|
||||||
if (userObj) {
|
if (userObj) {
|
||||||
qCWarning(LOG_LIB) << "User" << _name << "already exists";
|
qCWarning(LOG_LIB) << "User" << _name << "already exists";
|
||||||
return QueuedError("User already exists",
|
return QueuedError("User already exists", QueuedEnums::ReturnStatus::InvalidArgument);
|
||||||
QueuedEnums::ReturnStatus::InvalidArgument);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_helper->addUserPrivate(_name, _email, _password, _permissions,
|
return m_helper->addUserPrivate(_name, _email, _password, _permissions, _priority, _limits);
|
||||||
_priority, _limits);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -157,8 +150,7 @@ QueuedResult<QString> QueuedCorePrivate::authorization(const QString &_name,
|
|||||||
QVariantHash payload
|
QVariantHash payload
|
||||||
= {{"token", token},
|
= {{"token", token},
|
||||||
{"user", _name},
|
{"user", _name},
|
||||||
{"validUntil",
|
{"validUntil", m_users->checkToken(token).toString(Qt::ISODateWithMs)}};
|
||||||
m_users->checkToken(token).toString(Qt::ISODateWithMs)}};
|
|
||||||
m_database->add(QueuedDB::TOKENS_TABLE, payload);
|
m_database->add(QueuedDB::TOKENS_TABLE, payload);
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
@ -168,8 +160,7 @@ QueuedResult<QString> QueuedCorePrivate::authorization(const QString &_name,
|
|||||||
/**
|
/**
|
||||||
* @fn editOption
|
* @fn editOption
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCorePrivate::editOption(const QString &_key,
|
QueuedResult<bool> QueuedCorePrivate::editOption(const QString &_key, const QVariant &_value,
|
||||||
const QVariant &_value,
|
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Set key" << _key << "to" << _value;
|
qCDebug(LOG_LIB) << "Set key" << _key << "to" << _value;
|
||||||
@ -178,8 +169,7 @@ QueuedResult<bool> QueuedCorePrivate::editOption(const QString &_key,
|
|||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit options";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit options";
|
||||||
return QueuedError("Not allowed",
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_helper->editOptionPrivate(_key, _value);
|
return m_helper->editOptionPrivate(_key, _value);
|
||||||
@ -189,33 +179,20 @@ QueuedResult<bool> QueuedCorePrivate::editOption(const QString &_key,
|
|||||||
/**
|
/**
|
||||||
* @fn editTask
|
* @fn editTask
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCorePrivate::editTask(const long long _id,
|
QueuedResult<bool> QueuedCorePrivate::editTask(const long long _id, const QVariantHash &_taskData,
|
||||||
const QVariantHash &_taskData,
|
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit task with ID" << _id;
|
qCDebug(LOG_LIB) << "Edit task with ID" << _id;
|
||||||
|
|
||||||
auto task = m_processes->process(_id);
|
auto task = m_helper->tryGetTask(_id);
|
||||||
if (!task) {
|
if (!task)
|
||||||
qCInfo(LOG_LIB) << "Try to get information about task" << _id
|
return QueuedError("Task does not exist", QueuedEnums::ReturnStatus::InvalidArgument);
|
||||||
<< "from database";
|
|
||||||
auto data = m_database->get(QueuedDB::TASKS_TABLE, _id);
|
|
||||||
if (data.isEmpty()) {
|
|
||||||
qCWarning(LOG_LIB) << "Could not find task with ID" << _id;
|
|
||||||
return QueuedError("Task does not exist",
|
|
||||||
QueuedEnums::ReturnStatus::InvalidArgument);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto defs = QueuedProcessManager::parseDefinitions(data);
|
|
||||||
task = new QueuedProcess(this, defs, _id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
if (!authUser) {
|
if (!authUser) {
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||||
return QueuedError("Invalid token",
|
return QueuedError("Invalid token", QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
QueuedEnums::ReturnStatus::InvalidToken);
|
|
||||||
}
|
}
|
||||||
long long userAuthId = authUser->index();
|
long long userAuthId = authUser->index();
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
@ -224,37 +201,28 @@ QueuedResult<bool> QueuedCorePrivate::editTask(const long long _id,
|
|||||||
// it means that user edits own task
|
// it means that user edits own task
|
||||||
if (!isUser) {
|
if (!isUser) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit task";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit task";
|
||||||
return QueuedError(
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
"Not allowed",
|
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// user tries to edit random task
|
// user tries to edit random task
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit task";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit task";
|
||||||
return QueuedError(
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
"Not allowed",
|
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// only admin can edit run/stopped task
|
// only admin can edit run/stopped task
|
||||||
if (!task->startTime().isNull()) {
|
if (!task->startTime().isNull()) {
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB)
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit run/exited task";
|
||||||
<< "User" << _token << "not allowed to edit run/exited task";
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
return QueuedError(
|
|
||||||
"Not allowed",
|
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// drop admin fields
|
// drop admin fields
|
||||||
QVariantHash payload
|
QVariantHash payload
|
||||||
= isAdmin ? _taskData
|
= isAdmin ? _taskData : m_helper->dropAdminFields(QueuedDB::TASKS_TABLE, _taskData);
|
||||||
: m_helper->dropAdminFields(QueuedDB::TASKS_TABLE, _taskData);
|
|
||||||
if (payload.contains("nice"))
|
if (payload.contains("nice"))
|
||||||
payload["nice"]
|
payload["nice"] = std::min(payload["nice"].toUInt(), authUser->priority());
|
||||||
= std::min(payload["nice"].toUInt(), authUser->priority());
|
|
||||||
|
|
||||||
return m_helper->editTaskPrivate(task, payload);
|
return m_helper->editTaskPrivate(task, payload);
|
||||||
}
|
}
|
||||||
@ -263,63 +231,53 @@ QueuedResult<bool> QueuedCorePrivate::editTask(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn editUser
|
* @fn editUser
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCorePrivate::editUser(const long long _id,
|
QueuedResult<bool> QueuedCorePrivate::editUser(const long long _id, const QVariantHash &_userData,
|
||||||
const QVariantHash &_userData,
|
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit user with ID" << _id;
|
qCDebug(LOG_LIB) << "Edit user with ID" << _id;
|
||||||
|
|
||||||
auto userObj = user(_id, _token);
|
auto userObj = m_helper->tryGetUser(_id);
|
||||||
if (!userObj) {
|
if (!userObj)
|
||||||
qCWarning(LOG_LIB) << "Could not find user with ID" << _id;
|
return QueuedError("User does not exist", QueuedEnums::ReturnStatus::InvalidArgument);
|
||||||
return QueuedError("User does not exist",
|
|
||||||
QueuedEnums::ReturnStatus::InvalidArgument);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
if (!authUser) {
|
if (!authUser) {
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||||
return QueuedError("Invalid token",
|
return QueuedError("Invalid token", QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
QueuedEnums::ReturnStatus::InvalidToken);
|
|
||||||
}
|
}
|
||||||
long long userAuthId = authUser->index();
|
long long userAuthId = authUser->index();
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (userAuthId != _id) {
|
if (userAuthId != _id) {
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit user";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit user";
|
||||||
return QueuedError(
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
"Not allowed",
|
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// drop admin fields
|
// drop admin fields
|
||||||
QVariantHash payload
|
QVariantHash payload
|
||||||
= isAdmin ? _userData
|
= isAdmin ? _userData : m_helper->dropAdminFields(QueuedDB::USERS_TABLE, _userData);
|
||||||
: m_helper->dropAdminFields(QueuedDB::USERS_TABLE, _userData);
|
|
||||||
|
|
||||||
return m_helper->editUserPrivate(_id, payload);
|
return m_helper->editUserPrivate(userObj, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn editUserPermission
|
* @fn editUserPermission
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCorePrivate::editUserPermission(
|
QueuedResult<bool> QueuedCorePrivate::editUserPermission(const long long _id,
|
||||||
const long long _id, const QueuedEnums::Permission &_permission,
|
const QueuedEnums::Permission &_permission,
|
||||||
const bool _add, const QString &_token)
|
const bool _add, const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit permissions" << static_cast<int>(_permission)
|
qCDebug(LOG_LIB) << "Edit permissions" << static_cast<int>(_permission) << "for user" << _id
|
||||||
<< "for user" << _id << "add" << _add;
|
<< "add" << _add;
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to edit permissions";
|
||||||
<< "not allowed to edit permissions";
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
return QueuedError("Not allowed",
|
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_helper->editUserPermissionPrivate(_id, _permission, _add);
|
return m_helper->editUserPermissionPrivate(_id, _permission, _add);
|
||||||
@ -329,20 +287,17 @@ QueuedResult<bool> QueuedCorePrivate::editUserPermission(
|
|||||||
/**
|
/**
|
||||||
* @fn hashFromPassword
|
* @fn hashFromPassword
|
||||||
*/
|
*/
|
||||||
QueuedResult<QString>
|
QueuedResult<QString> QueuedCorePrivate::hashFromPassword(const QString &_password)
|
||||||
QueuedCorePrivate::hashFromPassword(const QString &_password)
|
|
||||||
{
|
{
|
||||||
return _password.isEmpty() ? ""
|
return _password.isEmpty() ? ""
|
||||||
: QueuedUser::hashFromPassword(
|
: QueuedUser::hashFromPassword(_password, m_settings->admin().salt);
|
||||||
_password, m_settings->admin().salt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn option
|
* @fn option
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariant> QueuedCorePrivate::option(const QString &_key,
|
QueuedResult<QVariant> QueuedCorePrivate::option(const QString &_key, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Look for option" << _key;
|
qCDebug(LOG_LIB) << "Look for option" << _key;
|
||||||
|
|
||||||
@ -351,16 +306,16 @@ QueuedResult<QVariant> QueuedCorePrivate::option(const QString &_key,
|
|||||||
if ((isAdmin) || (!m_advancedSettings->isAdmin(_key)))
|
if ((isAdmin) || (!m_advancedSettings->isAdmin(_key)))
|
||||||
return m_advancedSettings->get(_key);
|
return m_advancedSettings->get(_key);
|
||||||
else
|
else
|
||||||
return QueuedError("Not allowed",
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn performanceReport
|
* @fn performanceReport
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>> QueuedCorePrivate::performanceReport(
|
QueuedResult<QList<QVariantHash>> QueuedCorePrivate::performanceReport(const QDateTime &_from,
|
||||||
const QDateTime &_from, const QDateTime &_to, const QString &_token) const
|
const QDateTime &_to,
|
||||||
|
const QString &_token) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get performance report for" << _from << _to;
|
qCDebug(LOG_LIB) << "Get performance report for" << _from << _to;
|
||||||
|
|
||||||
@ -368,18 +323,15 @@ QueuedResult<QList<QVariantHash>> QueuedCorePrivate::performanceReport(
|
|||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
if (!authUser) {
|
if (!authUser) {
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||||
return QueuedError("Invalid token",
|
return QueuedError("Invalid token", QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
QueuedEnums::ReturnStatus::InvalidToken);
|
|
||||||
}
|
}
|
||||||
long long userAuthId = authUser->index();
|
long long userAuthId = authUser->index();
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Reports);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Reports);
|
||||||
|
|
||||||
if (isAdmin) {
|
if (isAdmin) {
|
||||||
return m_reports->performance(static_cast<QueuedCore *>(parent()),
|
return m_reports->performance(static_cast<QueuedCore *>(parent()), _from, _to);
|
||||||
_from, _to);
|
|
||||||
} else {
|
} else {
|
||||||
auto data = m_reports->performance(static_cast<QueuedCore *>(parent()),
|
auto data = m_reports->performance(static_cast<QueuedCore *>(parent()), _from, _to);
|
||||||
_from, _to);
|
|
||||||
QList<QVariantHash> output;
|
QList<QVariantHash> output;
|
||||||
for (auto &userData : data) {
|
for (auto &userData : data) {
|
||||||
if (userData["_id"].toLongLong() != userAuthId)
|
if (userData["_id"].toLongLong() != userAuthId)
|
||||||
@ -394,13 +346,12 @@ QueuedResult<QList<QVariantHash>> QueuedCorePrivate::performanceReport(
|
|||||||
/**
|
/**
|
||||||
* @fn plugin
|
* @fn plugin
|
||||||
*/
|
*/
|
||||||
QueuedResult<QueuedPluginSpecification::Plugin>
|
QueuedResult<QueuedPluginSpecification::Plugin> QueuedCorePrivate::plugin(const QString &_plugin,
|
||||||
QueuedCorePrivate::plugin(const QString &_plugin, const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (!isAdmin)
|
if (!isAdmin)
|
||||||
return QueuedError("Not allowed",
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
|
|
||||||
return m_plugins->loadSpecification(_plugin);
|
return m_plugins->loadSpecification(_plugin);
|
||||||
}
|
}
|
||||||
@ -409,19 +360,17 @@ QueuedCorePrivate::plugin(const QString &_plugin, const QString &_token)
|
|||||||
/**
|
/**
|
||||||
* @fn pluginSettings
|
* @fn pluginSettings
|
||||||
*/
|
*/
|
||||||
QueuedResult<QVariantHash>
|
QueuedResult<QVariantHash> QueuedCorePrivate::pluginSettings(const QString &_plugin,
|
||||||
QueuedCorePrivate::pluginSettings(const QString &_plugin, const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get plugin settings for" << _plugin;
|
qCDebug(LOG_LIB) << "Get plugin settings for" << _plugin;
|
||||||
|
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (!isAdmin)
|
if (!isAdmin)
|
||||||
return QueuedError("Not allowed",
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
|
|
||||||
auto dbSettings
|
auto dbSettings = m_database->get(QueuedDB::SETTINGS_TABLE,
|
||||||
= m_database->get(QueuedDB::SETTINGS_TABLE,
|
QString("WHERE key LIKE 'Plugin.%1.%'").arg(_plugin));
|
||||||
QString("WHERE key LIKE 'Plugin.%1.%'").arg(_plugin));
|
|
||||||
QVariantHash settings;
|
QVariantHash settings;
|
||||||
std::for_each(dbSettings.cbegin(), dbSettings.cend(),
|
std::for_each(dbSettings.cbegin(), dbSettings.cend(),
|
||||||
[&settings, &_plugin](const QVariantHash &value) {
|
[&settings, &_plugin](const QVariantHash &value) {
|
||||||
@ -446,16 +395,14 @@ QueuedCorePrivate::pluginSettings(const QString &_plugin, const QString &_token)
|
|||||||
/**
|
/**
|
||||||
* @fn removePlugin
|
* @fn removePlugin
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCorePrivate::removePlugin(const QString &_plugin,
|
QueuedResult<bool> QueuedCorePrivate::removePlugin(const QString &_plugin, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Remove plugin" << _plugin;
|
qCDebug(LOG_LIB) << "Remove plugin" << _plugin;
|
||||||
|
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to remove plugin";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to remove plugin";
|
||||||
return QueuedError("Not allowed",
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_helper->editPluginPrivate(_plugin, false);
|
return m_helper->editPluginPrivate(_plugin, false);
|
||||||
@ -465,8 +412,7 @@ QueuedResult<bool> QueuedCorePrivate::removePlugin(const QString &_plugin,
|
|||||||
/**
|
/**
|
||||||
* @fn startTask
|
* @fn startTask
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCorePrivate::startTask(const long long _id,
|
QueuedResult<bool> QueuedCorePrivate::startTask(const long long _id, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Force start task with ID" << _id;
|
qCDebug(LOG_LIB) << "Force start task with ID" << _id;
|
||||||
|
|
||||||
@ -474,17 +420,14 @@ QueuedResult<bool> QueuedCorePrivate::startTask(const long long _id,
|
|||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
if (!authUser) {
|
if (!authUser) {
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||||
return QueuedError("Invalid token",
|
return QueuedError("Invalid token", QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
QueuedEnums::ReturnStatus::InvalidToken);
|
|
||||||
}
|
}
|
||||||
long long userAuthId = authUser->index();
|
long long userAuthId = authUser->index();
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
if (userAuthId != _id) {
|
if (userAuthId != _id) {
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to start tasks";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to start tasks";
|
||||||
return QueuedError(
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
"Not allowed",
|
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,24 +440,21 @@ QueuedResult<bool> QueuedCorePrivate::startTask(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn stopTask
|
* @fn stopTask
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCorePrivate::stopTask(const long long _id,
|
QueuedResult<bool> QueuedCorePrivate::stopTask(const long long _id, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Force stop task with ID" << _id;
|
qCDebug(LOG_LIB) << "Force stop task with ID" << _id;
|
||||||
|
|
||||||
auto task = m_processes->process(_id);
|
auto task = m_processes->process(_id);
|
||||||
if (!task) {
|
if (!task) {
|
||||||
qCWarning(LOG_LIB) << "Could not find task with ID" << _id;
|
qCWarning(LOG_LIB) << "Could not find task with ID" << _id;
|
||||||
return QueuedError("Task does not exist",
|
return QueuedError("Task does not exist", QueuedEnums::ReturnStatus::InvalidArgument);
|
||||||
QueuedEnums::ReturnStatus::InvalidArgument);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
if (!authUser) {
|
if (!authUser) {
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||||
return QueuedError("Invalid token",
|
return QueuedError("Invalid token", QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
QueuedEnums::ReturnStatus::InvalidToken);
|
|
||||||
}
|
}
|
||||||
long long userAuthId = authUser->index();
|
long long userAuthId = authUser->index();
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Admin);
|
||||||
@ -523,17 +463,13 @@ QueuedResult<bool> QueuedCorePrivate::stopTask(const long long _id,
|
|||||||
// it means that user edits own task
|
// it means that user edits own task
|
||||||
if (!isUser) {
|
if (!isUser) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to stop task";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to stop task";
|
||||||
return QueuedError(
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
"Not allowed",
|
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// user tries to edit random task
|
// user tries to edit random task
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to stop task";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to stop task";
|
||||||
return QueuedError(
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
"Not allowed",
|
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -546,16 +482,13 @@ QueuedResult<bool> QueuedCorePrivate::stopTask(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn task
|
* @fn task
|
||||||
*/
|
*/
|
||||||
const QueuedProcess *QueuedCorePrivate::task(const long long _id,
|
const QueuedProcess *QueuedCorePrivate::task(const long long _id, const QString &_token) const
|
||||||
const QString &_token) const
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get task by ID" << _id;
|
qCDebug(LOG_LIB) << "Get task by ID" << _id;
|
||||||
|
|
||||||
auto task = m_processes->process(_id);
|
auto task = m_helper->tryGetTask(_id);
|
||||||
if (!task) {
|
if (!task)
|
||||||
qCWarning(LOG_LIB) << "Could not find task with ID" << _id;
|
return nullptr;
|
||||||
return task;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
@ -580,9 +513,10 @@ const QueuedProcess *QueuedCorePrivate::task(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn taskReport
|
* @fn taskReport
|
||||||
*/
|
*/
|
||||||
QueuedResult<QList<QVariantHash>>
|
QueuedResult<QList<QVariantHash>> QueuedCorePrivate::taskReport(const long long _user,
|
||||||
QueuedCorePrivate::taskReport(const long long _user, const QDateTime &_from,
|
const QDateTime &_from,
|
||||||
const QDateTime &_to, const QString &_token) const
|
const QDateTime &_to,
|
||||||
|
const QString &_token) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get tasks table by" << _user << _from << _to;
|
qCDebug(LOG_LIB) << "Get tasks table by" << _user << _from << _to;
|
||||||
|
|
||||||
@ -590,8 +524,7 @@ QueuedCorePrivate::taskReport(const long long _user, const QDateTime &_from,
|
|||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
if (!authUser) {
|
if (!authUser) {
|
||||||
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
qCWarning(LOG_LIB) << "Could not find auth user" << _token;
|
||||||
return QueuedError("Invalid token",
|
return QueuedError("Invalid token", QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
QueuedEnums::ReturnStatus::InvalidToken);
|
|
||||||
}
|
}
|
||||||
long long userAuthId = authUser->index();
|
long long userAuthId = authUser->index();
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Reports);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Reports);
|
||||||
@ -600,11 +533,8 @@ QueuedCorePrivate::taskReport(const long long _user, const QDateTime &_from,
|
|||||||
effectiveUserId = userAuthId;
|
effectiveUserId = userAuthId;
|
||||||
} else if (userAuthId != _user) {
|
} else if (userAuthId != _user) {
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB)
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to get task report";
|
||||||
<< "User" << _token << "not allowed to get task report";
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
return QueuedError(
|
|
||||||
"Not allowed",
|
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -615,16 +545,13 @@ QueuedCorePrivate::taskReport(const long long _user, const QDateTime &_from,
|
|||||||
/**
|
/**
|
||||||
* @fn user
|
* @fn user
|
||||||
*/
|
*/
|
||||||
const QueuedUser *QueuedCorePrivate::user(const long long _id,
|
const QueuedUser *QueuedCorePrivate::user(const long long _id, const QString &_token) const
|
||||||
const QString &_token) const
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get user by ID" << _id;
|
qCDebug(LOG_LIB) << "Get user by ID" << _id;
|
||||||
|
|
||||||
auto user = m_users->user(_id);
|
auto user = m_helper->tryGetUser(_id);
|
||||||
if (!user) {
|
if (!user)
|
||||||
qCWarning(LOG_LIB) << "Could not find user with ID" << _id;
|
return nullptr;
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
auto authUser = m_users->user(_token, true);
|
auto authUser = m_users->user(_token, true);
|
||||||
@ -649,8 +576,7 @@ const QueuedUser *QueuedCorePrivate::user(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn user
|
* @fn user
|
||||||
*/
|
*/
|
||||||
const QueuedUser *QueuedCorePrivate::user(const QString &_name,
|
const QueuedUser *QueuedCorePrivate::user(const QString &_name, const QString &_token) const
|
||||||
const QString &_token) const
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get user by name" << _name;
|
qCDebug(LOG_LIB) << "Get user by name" << _name;
|
||||||
|
|
||||||
@ -668,15 +594,13 @@ QueuedCorePrivate::userReport(const QDateTime &_lastLogged,
|
|||||||
const QueuedEnums::Permission _permission,
|
const QueuedEnums::Permission _permission,
|
||||||
const QString &_token) const
|
const QString &_token) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get users table by" << _lastLogged
|
qCDebug(LOG_LIB) << "Get users table by" << _lastLogged << static_cast<int>(_permission);
|
||||||
<< static_cast<int>(_permission);
|
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Reports);
|
bool isAdmin = m_users->authorize(_token, QueuedEnums::Permission::Reports);
|
||||||
if (!isAdmin) {
|
if (!isAdmin) {
|
||||||
qCInfo(LOG_LIB) << "User" << _token << "not allowed to get user report";
|
qCInfo(LOG_LIB) << "User" << _token << "not allowed to get user report";
|
||||||
return QueuedError("Not allowed",
|
return QueuedError("Not allowed", QueuedEnums::ReturnStatus::InsufficientPermissions);
|
||||||
QueuedEnums::ReturnStatus::InsufficientPermissions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_reports->users(_lastLogged, _permission);
|
return m_reports->users(_lastLogged, _permission);
|
||||||
|
@ -102,12 +102,10 @@ QueuedUserManager *QueuedCorePrivateHelper::users()
|
|||||||
/**
|
/**
|
||||||
* @fn dropAdminFields
|
* @fn dropAdminFields
|
||||||
*/
|
*/
|
||||||
QVariantHash
|
QVariantHash QueuedCorePrivateHelper::dropAdminFields(const QString &_table,
|
||||||
QueuedCorePrivateHelper::dropAdminFields(const QString &_table,
|
const QVariantHash &_payload)
|
||||||
const QVariantHash &_payload)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Drop admin fields from" << _payload << "in table"
|
qCDebug(LOG_LIB) << "Drop admin fields from" << _payload << "in table" << _table;
|
||||||
<< _table;
|
|
||||||
|
|
||||||
QVariantHash payload;
|
QVariantHash payload;
|
||||||
for (auto &key : _payload.keys()) {
|
for (auto &key : _payload.keys()) {
|
||||||
@ -123,28 +121,25 @@ QueuedCorePrivateHelper::dropAdminFields(const QString &_table,
|
|||||||
/**
|
/**
|
||||||
* @addTaskPrivate
|
* @addTaskPrivate
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long> QueuedCorePrivateHelper::addTaskPrivate(
|
QueuedResult<long long>
|
||||||
const QString &_command, const QStringList &_arguments,
|
QueuedCorePrivateHelper::addTaskPrivate(const QString &_command, const QStringList &_arguments,
|
||||||
const QString &_workingDirectory, const long long _userId, const uint _nice,
|
const QString &_workingDirectory, const long long _userId,
|
||||||
const QueuedLimits::Limits &_limits)
|
const uint _nice, const QueuedLimits::Limits &_limits)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add task" << _command << "with arguments" << _arguments
|
qCDebug(LOG_LIB) << "Add task" << _command << "with arguments" << _arguments << "from user"
|
||||||
<< "from user" << _userId;
|
<< _userId;
|
||||||
|
|
||||||
// add to database
|
// add to database
|
||||||
auto ids = users()->ids(_userId);
|
auto ids = users()->ids(_userId);
|
||||||
auto userObj = m_core->user(_userId, m_core->m_adminToken);
|
auto userObj = m_core->user(_userId, m_core->m_adminToken);
|
||||||
if (!userObj) {
|
if (!userObj) {
|
||||||
qCWarning(LOG_LIB) << "Could not find task user" << _userId;
|
qCWarning(LOG_LIB) << "Could not find task user" << _userId;
|
||||||
return QueuedError("Invalid token",
|
return QueuedError("Invalid token", QueuedEnums::ReturnStatus::InvalidToken);
|
||||||
QueuedEnums::ReturnStatus::InvalidToken);
|
|
||||||
}
|
}
|
||||||
auto taskLimits = QueuedLimits::minimalLimits(
|
auto taskLimits = QueuedLimits::minimalLimits(
|
||||||
_limits, userObj->nativeLimits(),
|
_limits, userObj->nativeLimits(),
|
||||||
QueuedLimits::Limits(
|
QueuedLimits::Limits(
|
||||||
advancedSettings()
|
advancedSettings()->get(QueuedConfig::QueuedSettings::DefaultLimits).toString()));
|
||||||
->get(QueuedConfig::QueuedSettings::DefaultLimits)
|
|
||||||
.toString()));
|
|
||||||
QVariantHash properties = {{"user", _userId},
|
QVariantHash properties = {{"user", _userId},
|
||||||
{"command", _command},
|
{"command", _command},
|
||||||
{"commandArguments", _arguments},
|
{"commandArguments", _arguments},
|
||||||
@ -172,18 +167,17 @@ QueuedResult<long long> QueuedCorePrivateHelper::addTaskPrivate(
|
|||||||
/**
|
/**
|
||||||
* @fn addUserPrivate
|
* @fn addUserPrivate
|
||||||
*/
|
*/
|
||||||
QueuedResult<long long> QueuedCorePrivateHelper::addUserPrivate(
|
QueuedResult<long long>
|
||||||
const QString &_name, const QString &_email, const QString &_password,
|
QueuedCorePrivateHelper::addUserPrivate(const QString &_name, const QString &_email,
|
||||||
const uint _permissions, const uint _priority,
|
const QString &_password, const uint _permissions,
|
||||||
const QueuedLimits::Limits &_limits)
|
const uint _priority, const QueuedLimits::Limits &_limits)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add user" << _name << "with email" << _email
|
qCDebug(LOG_LIB) << "Add user" << _name << "with email" << _email << "and permissions"
|
||||||
<< "and permissions" << _permissions;
|
<< _permissions;
|
||||||
// add to database
|
// add to database
|
||||||
QVariantHash properties
|
QVariantHash properties = {{"name", _name}, {"password", _password},
|
||||||
= {{"name", _name}, {"password", _password},
|
{"email", _email}, {"permissions", _permissions},
|
||||||
{"email", _email}, {"permissions", _permissions},
|
{"priority", _priority}, {"limits", _limits.toString()}};
|
||||||
{"priority", _priority}, {"limits", _limits.toString()}};
|
|
||||||
auto id = database()->add(QueuedDB::USERS_TABLE, properties);
|
auto id = database()->add(QueuedDB::USERS_TABLE, properties);
|
||||||
if (id == -1) {
|
if (id == -1) {
|
||||||
qCWarning(LOG_LIB) << "Could not add user" << _name;
|
qCWarning(LOG_LIB) << "Could not add user" << _name;
|
||||||
@ -203,9 +197,8 @@ QueuedResult<long long> QueuedCorePrivateHelper::addUserPrivate(
|
|||||||
/**
|
/**
|
||||||
* @fn editOptionPrivate
|
* @fn editOptionPrivate
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool>
|
QueuedResult<bool> QueuedCorePrivateHelper::editOptionPrivate(const QString &_key,
|
||||||
QueuedCorePrivateHelper::editOptionPrivate(const QString &_key,
|
const QVariant &_value)
|
||||||
const QVariant &_value)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Set key" << _key << "to" << _value;
|
qCDebug(LOG_LIB) << "Set key" << _key << "to" << _value;
|
||||||
|
|
||||||
@ -220,8 +213,7 @@ QueuedCorePrivateHelper::editOptionPrivate(const QString &_key,
|
|||||||
status = (id != -1);
|
status = (id != -1);
|
||||||
} else {
|
} else {
|
||||||
status = database()->modify(QueuedDB::SETTINGS_TABLE, id, payload);
|
status = database()->modify(QueuedDB::SETTINGS_TABLE, id, payload);
|
||||||
qCInfo(LOG_LIB) << "Value for" << _key
|
qCInfo(LOG_LIB) << "Value for" << _key << "has been modified with status" << status;
|
||||||
<< "has been modified with status" << status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add to child object
|
// add to child object
|
||||||
@ -230,8 +222,7 @@ QueuedCorePrivateHelper::editOptionPrivate(const QString &_key,
|
|||||||
// notify plugins if required
|
// notify plugins if required
|
||||||
if (plugins()) {
|
if (plugins()) {
|
||||||
auto tryPluginOption = plugins()->convertOptionName(_key);
|
auto tryPluginOption = plugins()->convertOptionName(_key);
|
||||||
if ((!tryPluginOption.first.isEmpty())
|
if ((!tryPluginOption.first.isEmpty()) && (!tryPluginOption.second.isEmpty()))
|
||||||
&& (!tryPluginOption.second.isEmpty()))
|
|
||||||
plugins()->optionChanged(_key, _value);
|
plugins()->optionChanged(_key, _value);
|
||||||
// notify plugins
|
// notify plugins
|
||||||
emit(plugins()->interface()->onEditOption(_key, _value));
|
emit(plugins()->interface()->onEditOption(_key, _value));
|
||||||
@ -245,16 +236,13 @@ QueuedCorePrivateHelper::editOptionPrivate(const QString &_key,
|
|||||||
/**
|
/**
|
||||||
* @fn editPluginPrivate
|
* @fn editPluginPrivate
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool>
|
QueuedResult<bool> QueuedCorePrivateHelper::editPluginPrivate(const QString &_plugin,
|
||||||
QueuedCorePrivateHelper::editPluginPrivate(const QString &_plugin,
|
const bool _add)
|
||||||
const bool _add)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit plugin" << _plugin << "add" << _add;
|
qCDebug(LOG_LIB) << "Edit plugin" << _plugin << "add" << _add;
|
||||||
|
|
||||||
QStringList pluginList = advancedSettings()
|
QStringList pluginList
|
||||||
->get(QueuedConfig::QueuedSettings::Plugins)
|
= advancedSettings()->get(QueuedConfig::QueuedSettings::Plugins).toString().split('\n');
|
||||||
.toString()
|
|
||||||
.split('\n');
|
|
||||||
|
|
||||||
QueuedResult<bool> r;
|
QueuedResult<bool> r;
|
||||||
if (_add && !pluginList.contains(_plugin)) {
|
if (_add && !pluginList.contains(_plugin)) {
|
||||||
@ -270,15 +258,12 @@ QueuedCorePrivateHelper::editPluginPrivate(const QString &_plugin,
|
|||||||
r = true;
|
r = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCDebug(LOG_LIB) << "Plugin" << _plugin
|
qCDebug(LOG_LIB) << "Plugin" << _plugin << "not loaded or already loaded";
|
||||||
<< "not loaded or already loaded";
|
r = QueuedError("Plugin is not loaded or already loaded", QueuedEnums::ReturnStatus::Error);
|
||||||
r = QueuedError("Plugin is not loaded or already loaded",
|
|
||||||
QueuedEnums::ReturnStatus::Error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r.type() == Result::Content::Value) {
|
if (r.type() == Result::Content::Value) {
|
||||||
editOptionPrivate(advancedSettings()->internalId(
|
editOptionPrivate(advancedSettings()->internalId(QueuedConfig::QueuedSettings::Plugins),
|
||||||
QueuedConfig::QueuedSettings::Plugins),
|
|
||||||
pluginList.join('\n'));
|
pluginList.join('\n'));
|
||||||
// notify plugins
|
// notify plugins
|
||||||
if (plugins()) {
|
if (plugins()) {
|
||||||
@ -296,9 +281,8 @@ QueuedCorePrivateHelper::editPluginPrivate(const QString &_plugin,
|
|||||||
/**
|
/**
|
||||||
* @fn editTaskPrivate
|
* @fn editTaskPrivate
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool>
|
QueuedResult<bool> QueuedCorePrivateHelper::editTaskPrivate(QueuedProcess *_process,
|
||||||
QueuedCorePrivateHelper::editTaskPrivate(QueuedProcess *_process,
|
const QVariantHash &_taskData)
|
||||||
const QVariantHash &_taskData)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit task with ID" << _process->index();
|
qCDebug(LOG_LIB) << "Edit task with ID" << _process->index();
|
||||||
|
|
||||||
@ -324,33 +308,25 @@ QueuedCorePrivateHelper::editTaskPrivate(QueuedProcess *_process,
|
|||||||
/**
|
/**
|
||||||
* @fn editUserPrivate
|
* @fn editUserPrivate
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool>
|
QueuedResult<bool> QueuedCorePrivateHelper::editUserPrivate(QueuedUser *_user,
|
||||||
QueuedCorePrivateHelper::editUserPrivate(const long long _id,
|
const QVariantHash &_userData)
|
||||||
const QVariantHash &_userData)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit user with ID" << _id;
|
qCDebug(LOG_LIB) << "Edit user with ID" << _user->index();
|
||||||
|
|
||||||
auto userObj = users()->user(_id);
|
|
||||||
if (!userObj) {
|
|
||||||
qCWarning(LOG_LIB) << "Could not find user with ID" << _id;
|
|
||||||
return QueuedError("User does not exist",
|
|
||||||
QueuedEnums::ReturnStatus::InvalidArgument);
|
|
||||||
};
|
|
||||||
|
|
||||||
// modify record in database first
|
// modify record in database first
|
||||||
bool status = database()->modify(QueuedDB::USERS_TABLE, _id, _userData);
|
bool status = database()->modify(QueuedDB::USERS_TABLE, _user->index(), _userData);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
qCWarning(LOG_LIB) << "Could not modify user record" << _id
|
qCWarning(LOG_LIB) << "Could not modify user record" << _user->index()
|
||||||
<< "in database, do not edit it in memory";
|
<< "in database, do not edit it in memory";
|
||||||
return QueuedError("", QueuedEnums::ReturnStatus::Error);
|
return QueuedError("", QueuedEnums::ReturnStatus::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// modify values stored in memory
|
// modify values stored in memory
|
||||||
for (auto &property : _userData.keys())
|
for (auto &property : _userData.keys())
|
||||||
userObj->setProperty(qPrintable(property), _userData[property]);
|
_user->setProperty(qPrintable(property), _userData[property]);
|
||||||
// notify plugins
|
// notify plugins
|
||||||
if (plugins())
|
if (plugins())
|
||||||
emit(plugins()->interface()->onEditUser(_id, _userData));
|
emit(plugins()->interface()->onEditUser(_user->index(), _userData));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -360,22 +336,20 @@ QueuedCorePrivateHelper::editUserPrivate(const long long _id,
|
|||||||
* @fn editUserPermissionPrivate
|
* @fn editUserPermissionPrivate
|
||||||
*/
|
*/
|
||||||
QueuedResult<bool> QueuedCorePrivateHelper::editUserPermissionPrivate(
|
QueuedResult<bool> QueuedCorePrivateHelper::editUserPermissionPrivate(
|
||||||
const long long _id, const QueuedEnums::Permission &_permission,
|
const long long _id, const QueuedEnums::Permission &_permission, const bool _add)
|
||||||
const bool _add)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Edit permissions" << static_cast<int>(_permission)
|
qCDebug(LOG_LIB) << "Edit permissions" << static_cast<int>(_permission) << "for user" << _id
|
||||||
<< "for user" << _id << "add" << _add;
|
<< "add" << _add;
|
||||||
|
|
||||||
auto userObj = users()->user(_id);
|
auto userObj = users()->user(_id);
|
||||||
if (!userObj) {
|
if (!userObj) {
|
||||||
qCWarning(LOG_LIB) << "Could not find user with ID" << _id;
|
qCWarning(LOG_LIB) << "Could not find user with ID" << _id;
|
||||||
return QueuedError("User does not exist",
|
return QueuedError("User does not exist", QueuedEnums::ReturnStatus::InvalidArgument);
|
||||||
QueuedEnums::ReturnStatus::InvalidArgument);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// edit runtime permissions to get value
|
// edit runtime permissions to get value
|
||||||
auto perms = _add ? userObj->addPermission(_permission)
|
auto perms
|
||||||
: userObj->removePermission(_permission);
|
= _add ? userObj->addPermission(_permission) : userObj->removePermission(_permission);
|
||||||
auto permissions = static_cast<uint>(perms);
|
auto permissions = static_cast<uint>(perms);
|
||||||
qCInfo(LOG_LIB) << "New user permissions" << perms;
|
qCInfo(LOG_LIB) << "New user permissions" << perms;
|
||||||
|
|
||||||
@ -395,3 +369,49 @@ QueuedResult<bool> QueuedCorePrivateHelper::editUserPermissionPrivate(
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn tryGetTask
|
||||||
|
*/
|
||||||
|
QueuedProcess *QueuedCorePrivateHelper::tryGetTask(const long long _id)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Search for task" << _id;
|
||||||
|
|
||||||
|
auto task = processes()->process(_id);
|
||||||
|
if (!task) {
|
||||||
|
qCInfo(LOG_LIB) << "Try to get information about task" << _id << "from database";
|
||||||
|
auto data = database()->get(QueuedDB::TASKS_TABLE, _id);
|
||||||
|
if (data.isEmpty()) {
|
||||||
|
qCWarning(LOG_LIB) << "Could not find task with ID" << _id;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto defs = QueuedProcessManager::parseDefinitions(data);
|
||||||
|
task = new QueuedProcess(this, defs, _id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn tryGetUser
|
||||||
|
*/
|
||||||
|
QueuedUser *QueuedCorePrivateHelper::tryGetUser(const long long _id)
|
||||||
|
{
|
||||||
|
auto user = users()->user(_id);
|
||||||
|
if (!user) {
|
||||||
|
qCInfo(LOG_LIB) << "Try to get information about user" << _id << "from database";
|
||||||
|
auto data = database()->get(QueuedDB::USERS_TABLE, _id);
|
||||||
|
if (data.isEmpty()) {
|
||||||
|
qCWarning(LOG_LIB) << "Could not find user with ID" << _id;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto defs = QueuedUserManager::parseDefinitions(data);
|
||||||
|
user = new QueuedUser(this, defs, _id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
@ -88,13 +88,12 @@ void QueuedCorePrivate::init(const QString &_configuration)
|
|||||||
initReports();
|
initReports();
|
||||||
|
|
||||||
// settings update notifier
|
// settings update notifier
|
||||||
m_connections
|
m_connections += connect(
|
||||||
+= connect(m_advancedSettings,
|
m_advancedSettings,
|
||||||
SIGNAL(valueUpdated(const QueuedConfig::QueuedSettings,
|
SIGNAL(valueUpdated(const QueuedConfig::QueuedSettings, const QString &, const QVariant &)),
|
||||||
const QString &, const QVariant &)),
|
this,
|
||||||
this,
|
SLOT(
|
||||||
SLOT(updateSettings(const QueuedConfig::QueuedSettings,
|
updateSettings(const QueuedConfig::QueuedSettings, const QString &, const QVariant &)));
|
||||||
const QString &, const QVariant &)));
|
|
||||||
|
|
||||||
// run!
|
// run!
|
||||||
m_processes->start();
|
m_processes->start();
|
||||||
@ -107,17 +106,13 @@ void QueuedCorePrivate::init(const QString &_configuration)
|
|||||||
void QueuedCorePrivate::initPlugins()
|
void QueuedCorePrivate::initPlugins()
|
||||||
{
|
{
|
||||||
QStringList pluginList
|
QStringList pluginList
|
||||||
= m_advancedSettings->get(QueuedConfig::QueuedSettings::Plugins)
|
= m_advancedSettings->get(QueuedConfig::QueuedSettings::Plugins).toString().split('\n');
|
||||||
.toString()
|
|
||||||
.split('\n');
|
|
||||||
|
|
||||||
m_plugins = m_helper->initObject(m_plugins, m_adminToken);
|
m_plugins = m_helper->initObject(m_plugins, m_adminToken);
|
||||||
for (auto &plugin : pluginList) {
|
for (auto &plugin : pluginList) {
|
||||||
auto settings = pluginSettings(plugin, m_adminToken);
|
auto settings = pluginSettings(plugin, m_adminToken);
|
||||||
settings.match(
|
settings.match(
|
||||||
[this, &plugin](const QVariantHash &opts) {
|
[this, &plugin](const QVariantHash &opts) { m_plugins->loadPlugin(plugin, opts); },
|
||||||
m_plugins->loadPlugin(plugin, opts);
|
|
||||||
},
|
|
||||||
[&plugin](const QueuedError &) {
|
[&plugin](const QueuedError &) {
|
||||||
qCWarning(LOG_LIB) << "Could not load settings for" << plugin;
|
qCWarning(LOG_LIB) << "Could not load settings for" << plugin;
|
||||||
});
|
});
|
||||||
@ -132,25 +127,21 @@ void QueuedCorePrivate::initProcesses()
|
|||||||
{
|
{
|
||||||
// init processes
|
// init processes
|
||||||
auto onExitAction = static_cast<QueuedEnums::ExitAction>(
|
auto onExitAction = static_cast<QueuedEnums::ExitAction>(
|
||||||
m_advancedSettings->get(QueuedConfig::QueuedSettings::OnExitAction)
|
m_advancedSettings->get(QueuedConfig::QueuedSettings::OnExitAction).toInt());
|
||||||
.toInt());
|
|
||||||
|
|
||||||
m_processes = m_helper->initObject(m_processes);
|
m_processes = m_helper->initObject(m_processes);
|
||||||
m_processes->setExitAction(onExitAction);
|
m_processes->setExitAction(onExitAction);
|
||||||
auto dbProcesses
|
auto dbProcesses = m_database->get(QueuedDB::TASKS_TABLE, "WHERE endTime IS NULL");
|
||||||
= m_database->get(QueuedDB::TASKS_TABLE, "WHERE endTime IS NULL");
|
|
||||||
m_processes->loadProcesses(dbProcesses);
|
m_processes->loadProcesses(dbProcesses);
|
||||||
|
|
||||||
m_connections
|
m_connections += connect(m_processes, &QueuedProcessManager::taskStartTimeReceived,
|
||||||
+= connect(m_processes, &QueuedProcessManager::taskStartTimeReceived,
|
[this](const long long _index, const QDateTime &_time) {
|
||||||
[this](const long long _index, const QDateTime &_time) {
|
return updateTaskTime(_index, _time, QDateTime());
|
||||||
return updateTaskTime(_index, _time, QDateTime());
|
});
|
||||||
});
|
m_connections += connect(m_processes, &QueuedProcessManager::taskStopTimeReceived,
|
||||||
m_connections
|
[this](const long long _index, const QDateTime &_time) {
|
||||||
+= connect(m_processes, &QueuedProcessManager::taskStopTimeReceived,
|
return updateTaskTime(_index, QDateTime(), _time);
|
||||||
[this](const long long _index, const QDateTime &_time) {
|
});
|
||||||
return updateTaskTime(_index, QDateTime(), _time);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -176,8 +167,8 @@ void QueuedCorePrivate::initSettings(const QString &_configuration)
|
|||||||
auto dbSetup = m_settings->db();
|
auto dbSetup = m_settings->db();
|
||||||
m_database = m_helper->initObject(m_database, dbSetup.path, dbSetup.driver);
|
m_database = m_helper->initObject(m_database, dbSetup.path, dbSetup.driver);
|
||||||
m_database->close();
|
m_database->close();
|
||||||
bool status = m_database->open(dbSetup.hostname, dbSetup.port,
|
bool status
|
||||||
dbSetup.username, dbSetup.password);
|
= m_database->open(dbSetup.hostname, dbSetup.port, dbSetup.username, dbSetup.password);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
QString message = "Could not open database";
|
QString message = "Could not open database";
|
||||||
qCCritical(LOG_LIB) << message;
|
qCCritical(LOG_LIB) << message;
|
||||||
@ -192,11 +183,9 @@ void QueuedCorePrivate::initSettings(const QString &_configuration)
|
|||||||
m_advancedSettings = m_helper->initObject(m_advancedSettings);
|
m_advancedSettings = m_helper->initObject(m_advancedSettings);
|
||||||
m_advancedSettings->set(m_database->get(QueuedDB::SETTINGS_TABLE));
|
m_advancedSettings->set(m_database->get(QueuedDB::SETTINGS_TABLE));
|
||||||
if (!m_advancedSettings->checkDatabaseVersion()) {
|
if (!m_advancedSettings->checkDatabaseVersion()) {
|
||||||
qCInfo(LOG_LIB) << "Bump database version to"
|
qCInfo(LOG_LIB) << "Bump database version to" << QueuedConfig::DATABASE_VERSION;
|
||||||
<< QueuedConfig::DATABASE_VERSION;
|
|
||||||
m_helper->editOptionPrivate(
|
m_helper->editOptionPrivate(
|
||||||
m_advancedSettings->internalId(
|
m_advancedSettings->internalId(QueuedConfig::QueuedSettings::DatabaseVersion),
|
||||||
QueuedConfig::QueuedSettings::DatabaseVersion),
|
|
||||||
QueuedConfig::DATABASE_VERSION);
|
QueuedConfig::DATABASE_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,21 +201,18 @@ void QueuedCorePrivate::initUsers()
|
|||||||
{
|
{
|
||||||
// load users and tokens
|
// load users and tokens
|
||||||
auto expiry
|
auto expiry
|
||||||
= m_advancedSettings->get(QueuedConfig::QueuedSettings::TokenExpiration)
|
= m_advancedSettings->get(QueuedConfig::QueuedSettings::TokenExpiration).toLongLong();
|
||||||
.toLongLong();
|
|
||||||
|
|
||||||
m_users = m_helper->initObject(m_users);
|
m_users = m_helper->initObject(m_users);
|
||||||
m_users->setSalt(m_settings->admin().salt);
|
m_users->setSalt(m_settings->admin().salt);
|
||||||
m_users->setTokenExpiration(expiry);
|
m_users->setTokenExpiration(expiry);
|
||||||
QString now = QDateTime::currentDateTimeUtc().toString(Qt::ISODateWithMs);
|
QString now = QDateTime::currentDateTimeUtc().toString(Qt::ISODateWithMs);
|
||||||
auto dbTokens = m_database->get(
|
auto dbTokens = m_database->get(
|
||||||
QueuedDB::TOKENS_TABLE,
|
QueuedDB::TOKENS_TABLE, QString("WHERE datetime(validUntil) > datetime('%1')").arg(now));
|
||||||
QString("WHERE datetime(validUntil) > datetime('%1')").arg(now));
|
|
||||||
m_users->loadTokens(dbTokens);
|
m_users->loadTokens(dbTokens);
|
||||||
auto dbUsers = m_database->get(QueuedDB::USERS_TABLE);
|
auto dbUsers = m_database->get(QueuedDB::USERS_TABLE);
|
||||||
m_users->loadUsers(dbUsers);
|
m_users->loadUsers(dbUsers);
|
||||||
|
|
||||||
m_connections += connect(
|
m_connections += connect(m_users, SIGNAL(userLoggedIn(const long long, const QDateTime &)),
|
||||||
m_users, SIGNAL(userLoggedIn(const long long, const QDateTime &)), this,
|
this, SLOT(updateUserLoginTime(const long long, const QDateTime &)));
|
||||||
SLOT(updateUserLoginTime(const long long, const QDateTime &)));
|
|
||||||
}
|
}
|
||||||
|
@ -35,12 +35,11 @@
|
|||||||
/**
|
/**
|
||||||
* @fn updateSettings
|
* @fn updateSettings
|
||||||
*/
|
*/
|
||||||
void QueuedCorePrivate::updateSettings(const QueuedConfig::QueuedSettings _id,
|
void QueuedCorePrivate::updateSettings(const QueuedConfig::QueuedSettings _id, const QString &_key,
|
||||||
const QString &_key,
|
|
||||||
const QVariant &_value)
|
const QVariant &_value)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Received update for" << static_cast<int>(_id) << _key
|
qCDebug(LOG_LIB) << "Received update for" << static_cast<int>(_id) << _key << "with value"
|
||||||
<< "with value" << _value;
|
<< _value;
|
||||||
|
|
||||||
// FIXME probably there is a better way to change settings
|
// FIXME probably there is a better way to change settings
|
||||||
switch (_id) {
|
switch (_id) {
|
||||||
@ -64,8 +63,7 @@ void QueuedCorePrivate::updateSettings(const QueuedConfig::QueuedSettings _id,
|
|||||||
m_databaseManager->setKeepUsers(_value.toLongLong());
|
m_databaseManager->setKeepUsers(_value.toLongLong());
|
||||||
break;
|
break;
|
||||||
case QueuedConfig::QueuedSettings::OnExitAction:
|
case QueuedConfig::QueuedSettings::OnExitAction:
|
||||||
m_processes->setExitAction(
|
m_processes->setExitAction(static_cast<QueuedEnums::ExitAction>(_value.toInt()));
|
||||||
static_cast<QueuedEnums::ExitAction>(_value.toInt()));
|
|
||||||
break;
|
break;
|
||||||
case QueuedConfig::QueuedSettings::Plugins:
|
case QueuedConfig::QueuedSettings::Plugins:
|
||||||
// do nothing here
|
// do nothing here
|
||||||
@ -86,12 +84,10 @@ void QueuedCorePrivate::updateSettings(const QueuedConfig::QueuedSettings _id,
|
|||||||
/**
|
/**
|
||||||
* @fn updateTaskTime
|
* @fn updateTaskTime
|
||||||
*/
|
*/
|
||||||
void QueuedCorePrivate::updateTaskTime(const long long _id,
|
void QueuedCorePrivate::updateTaskTime(const long long _id, const QDateTime &_startTime,
|
||||||
const QDateTime &_startTime,
|
|
||||||
const QDateTime &_endTime)
|
const QDateTime &_endTime)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Update task" << _id << "time to" << _startTime
|
qCDebug(LOG_LIB) << "Update task" << _id << "time to" << _startTime << _endTime;
|
||||||
<< _endTime;
|
|
||||||
|
|
||||||
QVariantHash record;
|
QVariantHash record;
|
||||||
if (_startTime.isValid()) {
|
if (_startTime.isValid()) {
|
||||||
@ -114,8 +110,7 @@ void QueuedCorePrivate::updateTaskTime(const long long _id,
|
|||||||
/**
|
/**
|
||||||
* @fn updateUserLoginTime
|
* @fn updateUserLoginTime
|
||||||
*/
|
*/
|
||||||
void QueuedCorePrivate::updateUserLoginTime(const long long _id,
|
void QueuedCorePrivate::updateUserLoginTime(const long long _id, const QDateTime &_time)
|
||||||
const QDateTime &_time)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Update user" << _id << "with login time" << _time;
|
qCDebug(LOG_LIB) << "Update user" << _id << "with login time" << _time;
|
||||||
|
|
||||||
|
@ -33,8 +33,7 @@
|
|||||||
/**
|
/**
|
||||||
* @fn QueuedDatabase
|
* @fn QueuedDatabase
|
||||||
*/
|
*/
|
||||||
QueuedDatabase::QueuedDatabase(QObject *parent, const QString path,
|
QueuedDatabase::QueuedDatabase(QObject *parent, const QString path, const QString driver)
|
||||||
const QString driver)
|
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_path(path)
|
, m_path(path)
|
||||||
{
|
{
|
||||||
@ -85,28 +84,23 @@ void QueuedDatabase::close()
|
|||||||
/**
|
/**
|
||||||
* @fn createAdministrator
|
* @fn createAdministrator
|
||||||
*/
|
*/
|
||||||
void QueuedDatabase::createAdministrator(const QString &_user,
|
void QueuedDatabase::createAdministrator(const QString &_user, const QString &_password)
|
||||||
const QString &_password)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Check for user" << _user;
|
qCDebug(LOG_LIB) << "Check for user" << _user;
|
||||||
|
|
||||||
QSqlQuery query
|
QSqlQuery query = m_database.exec(
|
||||||
= m_database.exec(QString("SELECT * FROM '%1' WHERE name='%2'")
|
QString("SELECT * FROM '%1' WHERE name='%2'").arg(QueuedDB::USERS_TABLE).arg(_user));
|
||||||
.arg(QueuedDB::USERS_TABLE)
|
|
||||||
.arg(_user));
|
|
||||||
QSqlError error = query.lastError();
|
QSqlError error = query.lastError();
|
||||||
if (error.isValid())
|
if (error.isValid())
|
||||||
qCWarning(LOG_LIB) << "Could not get record" << _user << "from"
|
qCWarning(LOG_LIB) << "Could not get record" << _user << "from" << QueuedDB::USERS_TABLE
|
||||||
<< QueuedDB::USERS_TABLE << "message"
|
<< "message" << error.text();
|
||||||
<< error.text();
|
|
||||||
else if (query.next())
|
else if (query.next())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qCInfo(LOG_LIB) << "Create administrator user" << _user;
|
qCInfo(LOG_LIB) << "Create administrator user" << _user;
|
||||||
QVariantHash payload = {
|
QVariantHash payload = {{"name", _user},
|
||||||
{"name", _user},
|
{"password", _password},
|
||||||
{"password", _password},
|
{"permissions", static_cast<int>(QueuedEnums::Permission::SuperAdmin)}};
|
||||||
{"permissions", static_cast<int>(QueuedEnums::Permission::SuperAdmin)}};
|
|
||||||
|
|
||||||
if (!add(QueuedDB::USERS_TABLE, payload))
|
if (!add(QueuedDB::USERS_TABLE, payload))
|
||||||
qCCritical(LOG_LIB) << "Could not create administrator";
|
qCCritical(LOG_LIB) << "Could not create administrator";
|
||||||
@ -132,16 +126,14 @@ void QueuedDatabase::createSchema(const QString &_table)
|
|||||||
if (columns.contains(column))
|
if (columns.contains(column))
|
||||||
continue;
|
continue;
|
||||||
QueuedDB::QueuedDBField field = QueuedDB::DBSchema[_table][column];
|
QueuedDB::QueuedDBField field = QueuedDB::DBSchema[_table][column];
|
||||||
QSqlQuery query
|
QSqlQuery query = m_database.exec(QString("ALTER TABLE '%1' ADD `%2` %3")
|
||||||
= m_database.exec(QString("ALTER TABLE '%1' ADD `%2` %3")
|
.arg(_table)
|
||||||
.arg(_table)
|
.arg(column)
|
||||||
.arg(column)
|
.arg(field.sqlDescription));
|
||||||
.arg(field.sqlDescription));
|
|
||||||
QSqlError error = query.lastError();
|
QSqlError error = query.lastError();
|
||||||
if (error.isValid())
|
if (error.isValid())
|
||||||
qCCritical(LOG_LIB)
|
qCCritical(LOG_LIB) << "Could not insert column" << column << "to table" << _table
|
||||||
<< "Could not insert column" << column << "to table" << _table
|
<< "error:" << error.text();
|
||||||
<< "error:" << error.text();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,34 +146,27 @@ void QueuedDatabase::createTable(const QString &_table)
|
|||||||
qCDebug(LOG_LIB) << "Create table" << _table;
|
qCDebug(LOG_LIB) << "Create table" << _table;
|
||||||
|
|
||||||
QSqlQuery query = m_database.exec(
|
QSqlQuery query = m_database.exec(
|
||||||
QString("CREATE TABLE '%1' (`_id` INTEGER PRIMARY KEY AUTOINCREMENT)")
|
QString("CREATE TABLE '%1' (`_id` INTEGER PRIMARY KEY AUTOINCREMENT)").arg(_table));
|
||||||
.arg(_table));
|
|
||||||
QSqlError error = query.lastError();
|
QSqlError error = query.lastError();
|
||||||
if (error.isValid())
|
if (error.isValid())
|
||||||
qCCritical(LOG_LIB)
|
qCCritical(LOG_LIB) << "Could not create table" << _table << "error:" << error.text();
|
||||||
<< "Could not create table" << _table << "error:" << error.text();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn get
|
* @fn get
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> QueuedDatabase::get(const QString &_table,
|
QList<QVariantHash> QueuedDatabase::get(const QString &_table, const QString &_condition)
|
||||||
const QString &_condition)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get records in table" << _table << "with condition"
|
qCDebug(LOG_LIB) << "Get records in table" << _table << "with condition" << _condition;
|
||||||
<< _condition;
|
|
||||||
|
|
||||||
QList<QVariantHash> output;
|
QList<QVariantHash> output;
|
||||||
QSqlQuery query
|
QSqlQuery query = m_database.exec(
|
||||||
= m_database.exec(QString("SELECT * FROM '%1' %2 ORDER BY _id ASC")
|
QString("SELECT * FROM '%1' %2 ORDER BY _id ASC").arg(_table).arg(_condition));
|
||||||
.arg(_table)
|
|
||||||
.arg(_condition));
|
|
||||||
|
|
||||||
QSqlError error = query.lastError();
|
QSqlError error = query.lastError();
|
||||||
if (error.isValid()) {
|
if (error.isValid()) {
|
||||||
qCWarning(LOG_LIB) << "Could not get records from" << _table
|
qCWarning(LOG_LIB) << "Could not get records from" << _table << "message" << error.text();
|
||||||
<< "message" << error.text();
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
QSqlRecord record = query.record();
|
QSqlRecord record = query.record();
|
||||||
@ -221,18 +206,16 @@ QVariantHash QueuedDatabase::get(const QString &_table, const long long _id)
|
|||||||
/**
|
/**
|
||||||
* @fn open
|
* @fn open
|
||||||
*/
|
*/
|
||||||
bool QueuedDatabase::open(const QString &_hostname, const int _port,
|
bool QueuedDatabase::open(const QString &_hostname, const int _port, const QString &_username,
|
||||||
const QString &_username, const QString &_password)
|
const QString &_password)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Open database at" << _hostname << _port << "as user"
|
qCDebug(LOG_LIB) << "Open database at" << _hostname << _port << "as user" << _username;
|
||||||
<< _username;
|
|
||||||
|
|
||||||
if (!_hostname.isEmpty())
|
if (!_hostname.isEmpty())
|
||||||
m_database.setHostName(_hostname);
|
m_database.setHostName(_hostname);
|
||||||
if (_port > 0)
|
if (_port > 0)
|
||||||
m_database.setPort(_port);
|
m_database.setPort(_port);
|
||||||
bool status = _username.isEmpty() ? m_database.open()
|
bool status = _username.isEmpty() ? m_database.open() : m_database.open(_username, _password);
|
||||||
: m_database.open(_username, _password);
|
|
||||||
|
|
||||||
qCDebug(LOG_LIB) << "Open database status" << status;
|
qCDebug(LOG_LIB) << "Open database status" << status;
|
||||||
if (status)
|
if (status)
|
||||||
@ -265,8 +248,8 @@ long long QueuedDatabase::add(const QString &_table, const QVariantHash &_value)
|
|||||||
.arg(payload.values().join(',')));
|
.arg(payload.values().join(',')));
|
||||||
QSqlError error = query.lastError();
|
QSqlError error = query.lastError();
|
||||||
if (error.isValid()) {
|
if (error.isValid()) {
|
||||||
qCCritical(LOG_LIB) << "Could not add record" << _value << "to table"
|
qCCritical(LOG_LIB) << "Could not add record" << _value << "to table" << _table << "message"
|
||||||
<< _table << "message" << error.text();
|
<< error.text();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,25 +260,21 @@ long long QueuedDatabase::add(const QString &_table, const QVariantHash &_value)
|
|||||||
/**
|
/**
|
||||||
* @fn modify
|
* @fn modify
|
||||||
*/
|
*/
|
||||||
bool QueuedDatabase::modify(const QString &_table, const long long _id,
|
bool QueuedDatabase::modify(const QString &_table, const long long _id, const QVariantHash &_value)
|
||||||
const QVariantHash &_value)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Modify record" << _id << "in table" << _table
|
qCDebug(LOG_LIB) << "Modify record" << _id << "in table" << _table << "with value" << _value;
|
||||||
<< "with value" << _value;
|
|
||||||
|
|
||||||
auto payload = getQueryPayload(_table, _value);
|
auto payload = getQueryPayload(_table, _value);
|
||||||
QStringList stringPayload;
|
QStringList stringPayload;
|
||||||
for (auto &key : payload.keys())
|
for (auto &key : payload.keys())
|
||||||
stringPayload.append(QString("%1=%2").arg(key).arg(payload[key]));
|
stringPayload.append(QString("%1=%2").arg(key).arg(payload[key]));
|
||||||
// build query
|
// build query
|
||||||
QSqlQuery query = m_database.exec(QString("UPDATE %1 SET %2 WHERE _id=%3")
|
QSqlQuery query = m_database.exec(
|
||||||
.arg(_table)
|
QString("UPDATE %1 SET %2 WHERE _id=%3").arg(_table).arg(stringPayload.join(',')).arg(_id));
|
||||||
.arg(stringPayload.join(','))
|
|
||||||
.arg(_id));
|
|
||||||
QSqlError error = query.lastError();
|
QSqlError error = query.lastError();
|
||||||
if (error.isValid()) {
|
if (error.isValid()) {
|
||||||
qCCritical(LOG_LIB) << "Could not modify record" << _value << "in table"
|
qCCritical(LOG_LIB) << "Could not modify record" << _value << "in table" << _table
|
||||||
<< _table << "message" << error.text();
|
<< "message" << error.text();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,12 +289,11 @@ bool QueuedDatabase::remove(const QString &_table, const long long _id)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Remove row" << _id << "from" << _table;
|
qCDebug(LOG_LIB) << "Remove row" << _id << "from" << _table;
|
||||||
|
|
||||||
QSqlQuery query = m_database.exec(
|
QSqlQuery query = m_database.exec(QString("DELETE FROM %1 WHERE _id=%2").arg(_table).arg(_id));
|
||||||
QString("DELETE FROM %1 WHERE _id=%2").arg(_table).arg(_id));
|
|
||||||
QSqlError error = query.lastError();
|
QSqlError error = query.lastError();
|
||||||
if (error.isValid()) {
|
if (error.isValid()) {
|
||||||
qCCritical(LOG_LIB) << "Could not remove record" << _id << "in table"
|
qCCritical(LOG_LIB) << "Could not remove record" << _id << "in table" << _table << "message"
|
||||||
<< _table << "message" << error.text();
|
<< error.text();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,10 +308,10 @@ void QueuedDatabase::removeTasks(const QDateTime &_endTime)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Remove all tasks which are older than" << _endTime;
|
qCDebug(LOG_LIB) << "Remove all tasks which are older than" << _endTime;
|
||||||
|
|
||||||
QSqlQuery query = m_database.exec(
|
QSqlQuery query
|
||||||
QString("DELETE FROM %1 WHERE datetime(endTime) < datetime('%2')")
|
= m_database.exec(QString("DELETE FROM %1 WHERE datetime(endTime) < datetime('%2')")
|
||||||
.arg(QueuedDB::TASKS_TABLE)
|
.arg(QueuedDB::TASKS_TABLE)
|
||||||
.arg(_endTime.toString(Qt::ISODateWithMs)));
|
.arg(_endTime.toString(Qt::ISODateWithMs)));
|
||||||
|
|
||||||
QSqlError error = query.lastError();
|
QSqlError error = query.lastError();
|
||||||
if (error.isValid())
|
if (error.isValid())
|
||||||
@ -348,10 +326,10 @@ void QueuedDatabase::removeTasks(const QDateTime &_endTime)
|
|||||||
void QueuedDatabase::removeTokens()
|
void QueuedDatabase::removeTokens()
|
||||||
{
|
{
|
||||||
QString now = QDateTime::currentDateTimeUtc().toString(Qt::ISODateWithMs);
|
QString now = QDateTime::currentDateTimeUtc().toString(Qt::ISODateWithMs);
|
||||||
QSqlQuery query = m_database.exec(
|
QSqlQuery query
|
||||||
QString("DELETE FROM %1 WHERE datetime(validUntil) > datetime('%2')")
|
= m_database.exec(QString("DELETE FROM %1 WHERE datetime(validUntil) > datetime('%2')")
|
||||||
.arg(QueuedDB::TOKENS_TABLE)
|
.arg(QueuedDB::TOKENS_TABLE)
|
||||||
.arg(now));
|
.arg(now));
|
||||||
|
|
||||||
QSqlError error = query.lastError();
|
QSqlError error = query.lastError();
|
||||||
if (error.isValid())
|
if (error.isValid())
|
||||||
@ -365,13 +343,12 @@ void QueuedDatabase::removeTokens()
|
|||||||
*/
|
*/
|
||||||
void QueuedDatabase::removeUsers(const QDateTime &_lastLogin)
|
void QueuedDatabase::removeUsers(const QDateTime &_lastLogin)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Remove all users which logged older than"
|
qCDebug(LOG_LIB) << "Remove all users which logged older than" << _lastLogin;
|
||||||
<< _lastLogin;
|
|
||||||
|
|
||||||
QSqlQuery query = m_database.exec(
|
QSqlQuery query
|
||||||
QString("DELETE FROM %1 WHERE datetime(lastLogin) < datetime('%2')")
|
= m_database.exec(QString("DELETE FROM %1 WHERE datetime(lastLogin) < datetime('%2')")
|
||||||
.arg(QueuedDB::USERS_TABLE)
|
.arg(QueuedDB::USERS_TABLE)
|
||||||
.arg(_lastLogin.toString(Qt::ISODateWithMs)));
|
.arg(_lastLogin.toString(Qt::ISODateWithMs)));
|
||||||
|
|
||||||
QSqlError error = query.lastError();
|
QSqlError error = query.lastError();
|
||||||
if (error.isValid())
|
if (error.isValid())
|
||||||
@ -402,8 +379,7 @@ long long QueuedDatabase::lastInsertionId(const QString &_table) const
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Get last row ID from" << _table;
|
qCDebug(LOG_LIB) << "Get last row ID from" << _table;
|
||||||
|
|
||||||
QSqlQuery query
|
QSqlQuery query = m_database.exec(QString("SELECT max(_id) FROM '%1'").arg(_table));
|
||||||
= m_database.exec(QString("SELECT max(_id) FROM '%1'").arg(_table));
|
|
||||||
QSqlError error = query.lastError();
|
QSqlError error = query.lastError();
|
||||||
if (error.isValid()) {
|
if (error.isValid()) {
|
||||||
qCCritical(LOG_LIB) << "Could not get last insertion ID";
|
qCCritical(LOG_LIB) << "Could not get last insertion ID";
|
||||||
@ -421,9 +397,8 @@ long long QueuedDatabase::lastInsertionId(const QString &_table) const
|
|||||||
/**
|
/**
|
||||||
* @fn getQueryPayload
|
* @fn getQueryPayload
|
||||||
*/
|
*/
|
||||||
QHash<QString, QString>
|
QHash<QString, QString> QueuedDatabase::getQueryPayload(const QString &_table,
|
||||||
QueuedDatabase::getQueryPayload(const QString &_table,
|
const QVariantHash &_value) const
|
||||||
const QVariantHash &_value) const
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add record" << _value << "to table" << _table;
|
qCDebug(LOG_LIB) << "Add record" << _value << "to table" << _table;
|
||||||
|
|
||||||
@ -432,8 +407,7 @@ QueuedDatabase::getQueryPayload(const QString &_table,
|
|||||||
for (auto &key : _value.keys()) {
|
for (auto &key : _value.keys()) {
|
||||||
// we would check it only if there is data about this table
|
// we would check it only if there is data about this table
|
||||||
if (!schemaColumns.isEmpty() && !schemaColumns.contains(key)) {
|
if (!schemaColumns.isEmpty() && !schemaColumns.contains(key)) {
|
||||||
qCWarning(LOG_LIB)
|
qCWarning(LOG_LIB) << "No key" << key << "found in schema of" << _table;
|
||||||
<< "No key" << key << "found in schema of" << _table;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (key == "_id") {
|
if (key == "_id") {
|
||||||
|
@ -30,8 +30,7 @@
|
|||||||
/**
|
/**
|
||||||
* @fn QueuedDatabaseManager
|
* @fn QueuedDatabaseManager
|
||||||
*/
|
*/
|
||||||
QueuedDatabaseManager::QueuedDatabaseManager(QObject *_parent,
|
QueuedDatabaseManager::QueuedDatabaseManager(QObject *_parent, QueuedDatabase *_database)
|
||||||
QueuedDatabase *_database)
|
|
||||||
: QObject(_parent)
|
: QObject(_parent)
|
||||||
, m_database(_database)
|
, m_database(_database)
|
||||||
{
|
{
|
||||||
|
@ -90,18 +90,16 @@ QHash<QString, QHash<QString, QString>> QueuedDebug::getBuildMetaData()
|
|||||||
// api
|
// api
|
||||||
{"API",
|
{"API",
|
||||||
{
|
{
|
||||||
{"DATABASE_VERSION",
|
{"DATABASE_VERSION", QString::number(QueuedConfig::DATABASE_VERSION)},
|
||||||
QString::number(QueuedConfig::DATABASE_VERSION)},
|
|
||||||
{"PLUGIN_INTERFACE", QueuedConfig::PLUGIN_INTERFACE},
|
{"PLUGIN_INTERFACE", QueuedConfig::PLUGIN_INTERFACE},
|
||||||
{"WEBAPI_TOKEN_HEADER", QueuedConfig::WEBAPI_TOKEN_HEADER},
|
{"WEBAPI_TOKEN_HEADER", QueuedConfig::WEBAPI_TOKEN_HEADER},
|
||||||
{"WEBAPI_VERSIONS",
|
{"WEBAPI_VERSIONS",
|
||||||
std::accumulate(
|
std::accumulate(std::next(std::begin(QueuedConfig::WEBAPI_VERSIONS)),
|
||||||
std::next(std::begin(QueuedConfig::WEBAPI_VERSIONS)),
|
std::end(QueuedConfig::WEBAPI_VERSIONS),
|
||||||
std::end(QueuedConfig::WEBAPI_VERSIONS),
|
QString::number(QueuedConfig::WEBAPI_VERSIONS[0]),
|
||||||
QString::number(QueuedConfig::WEBAPI_VERSIONS[0]),
|
[](const QString str, const int version) {
|
||||||
[](const QString str, const int version) {
|
return QString("%1,%2").arg(str).arg(version);
|
||||||
return QString("%1,%2").arg(str).arg(version);
|
})},
|
||||||
})},
|
|
||||||
}},
|
}},
|
||||||
// paths
|
// paths
|
||||||
{"Paths",
|
{"Paths",
|
||||||
|
@ -58,20 +58,17 @@ bool QueuedLimits::limitCompare(const long long _first, const long long _second)
|
|||||||
/**
|
/**
|
||||||
* @fn minimalLimits
|
* @fn minimalLimits
|
||||||
*/
|
*/
|
||||||
QueuedLimits::Limits
|
QueuedLimits::Limits QueuedLimits::minimalLimits(const QueuedLimits::Limits &_task,
|
||||||
QueuedLimits::minimalLimits(const QueuedLimits::Limits &_task,
|
const QueuedLimits::Limits &_user,
|
||||||
const QueuedLimits::Limits &_user,
|
const QueuedLimits::Limits &_default)
|
||||||
const QueuedLimits::Limits &_default)
|
|
||||||
{
|
{
|
||||||
QueuedLimits::Limits limits;
|
QueuedLimits::Limits limits;
|
||||||
limits.cpu = std::min({_task.cpu, _user.cpu, _default.cpu}, &limitCompare);
|
limits.cpu = std::min({_task.cpu, _user.cpu, _default.cpu}, &limitCompare);
|
||||||
limits.gpu = std::min({_task.gpu, _user.gpu, _default.gpu}, &limitCompare);
|
limits.gpu = std::min({_task.gpu, _user.gpu, _default.gpu}, &limitCompare);
|
||||||
limits.memory = std::min({_task.memory, _user.memory, _default.memory},
|
limits.memory = std::min({_task.memory, _user.memory, _default.memory}, &limitCompare);
|
||||||
&limitCompare);
|
limits.gpumemory
|
||||||
limits.gpumemory = std::min(
|
= std::min({_task.gpumemory, _user.gpumemory, _default.gpumemory}, &limitCompare);
|
||||||
{_task.gpumemory, _user.gpumemory, _default.gpumemory}, &limitCompare);
|
limits.storage = std::min({_task.storage, _user.storage, _default.storage}, &limitCompare);
|
||||||
limits.storage = std::min({_task.storage, _user.storage, _default.storage},
|
|
||||||
&limitCompare);
|
|
||||||
|
|
||||||
return limits;
|
return limits;
|
||||||
}
|
}
|
||||||
|
@ -62,8 +62,7 @@ QueuedPluginManager::~QueuedPluginManager()
|
|||||||
/**
|
/**
|
||||||
* @fn convertOptionName
|
* @fn convertOptionName
|
||||||
*/
|
*/
|
||||||
QPair<QString, QString>
|
QPair<QString, QString> QueuedPluginManager::convertOptionName(const QString &_key)
|
||||||
QueuedPluginManager::convertOptionName(const QString &_key)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_PL) << "Convert option name" << _key;
|
qCDebug(LOG_PL) << "Convert option name" << _key;
|
||||||
|
|
||||||
@ -94,8 +93,7 @@ QueuedPluginManagerInterface *QueuedPluginManager::interface()
|
|||||||
/**
|
/**
|
||||||
* @fn loadPlugin
|
* @fn loadPlugin
|
||||||
*/
|
*/
|
||||||
bool QueuedPluginManager::loadPlugin(const QString &_name,
|
bool QueuedPluginManager::loadPlugin(const QString &_name, const QVariantHash &_settings)
|
||||||
const QVariantHash &_settings)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_PL) << "Load plugin" << _name << "with settings" << _settings;
|
qCDebug(LOG_PL) << "Load plugin" << _name << "with settings" << _settings;
|
||||||
|
|
||||||
@ -125,8 +123,8 @@ bool QueuedPluginManager::loadPlugin(const QString &_name,
|
|||||||
if (loader.isLoaded())
|
if (loader.isLoaded())
|
||||||
item = qobject_cast<QueuedPluginInterface *>(plugin);
|
item = qobject_cast<QueuedPluginInterface *>(plugin);
|
||||||
else
|
else
|
||||||
qCCritical(LOG_PL) << "Could not load the library for" << _name
|
qCCritical(LOG_PL) << "Could not load the library for" << _name << "error"
|
||||||
<< "error" << loader.errorString();
|
<< loader.errorString();
|
||||||
if (item) {
|
if (item) {
|
||||||
m_plugins[_name] = item;
|
m_plugins[_name] = item;
|
||||||
item->init(pluginSettings);
|
item->init(pluginSettings);
|
||||||
@ -143,8 +141,7 @@ bool QueuedPluginManager::loadPlugin(const QString &_name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedPluginSpecification::Plugin
|
QueuedPluginSpecification::Plugin QueuedPluginManager::loadSpecification(const QString &_name)
|
||||||
QueuedPluginManager::loadSpecification(const QString &_name)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_PL) << "Load specification for" << _name;
|
qCDebug(LOG_PL) << "Load specification for" << _name;
|
||||||
|
|
||||||
@ -171,8 +168,7 @@ QueuedPluginManager::loadSpecification(const QString &_name)
|
|||||||
*/
|
*/
|
||||||
QStringList QueuedPluginManager::pluginLocations()
|
QStringList QueuedPluginManager::pluginLocations()
|
||||||
{
|
{
|
||||||
QStringList locations = QStandardPaths::standardLocations(
|
QStringList locations = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
|
||||||
QStandardPaths::GenericDataLocation);
|
|
||||||
for (auto &loc : locations)
|
for (auto &loc : locations)
|
||||||
loc = QString("%1/%2/%3")
|
loc = QString("%1/%2/%3")
|
||||||
.arg(loc)
|
.arg(loc)
|
||||||
@ -205,15 +201,13 @@ bool QueuedPluginManager::unloadPlugin(const QString &_name)
|
|||||||
/**
|
/**
|
||||||
* @fn optionChanged
|
* @fn optionChanged
|
||||||
*/
|
*/
|
||||||
void QueuedPluginManager::optionChanged(const QString &_key,
|
void QueuedPluginManager::optionChanged(const QString &_key, const QVariant &_value)
|
||||||
const QVariant &_value)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_PL) << "Option" << _key << "changed to" << _value;
|
qCDebug(LOG_PL) << "Option" << _key << "changed to" << _value;
|
||||||
|
|
||||||
auto option = convertOptionName(_key);
|
auto option = convertOptionName(_key);
|
||||||
if (!m_plugins.contains(option.first)) {
|
if (!m_plugins.contains(option.first)) {
|
||||||
qCWarning(LOG_PL) << "Plugin" << option.first << "not found for"
|
qCWarning(LOG_PL) << "Plugin" << option.first << "not found for" << _key;
|
||||||
<< _key;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,9 +39,8 @@ QVariantHash QueuedPluginSpecification::dumpSpecification(const Plugin &_plugin)
|
|||||||
|
|
||||||
QVariantHash options;
|
QVariantHash options;
|
||||||
for (auto opt : _plugin.options)
|
for (auto opt : _plugin.options)
|
||||||
options[opt.name] = QVariantHash({{"default", opt.defaultValue},
|
options[opt.name] = QVariantHash(
|
||||||
{"description", opt.description},
|
{{"default", opt.defaultValue}, {"description", opt.description}, {"type", opt.type}});
|
||||||
{"type", opt.type}});
|
|
||||||
output["options"] = options;
|
output["options"] = options;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
@ -51,8 +50,7 @@ QVariantHash QueuedPluginSpecification::dumpSpecification(const Plugin &_plugin)
|
|||||||
/**
|
/**
|
||||||
* @fn readSpecification
|
* @fn readSpecification
|
||||||
*/
|
*/
|
||||||
QueuedPluginSpecification::Plugin
|
QueuedPluginSpecification::Plugin QueuedPluginSpecification::readSpecification(const QString &_path)
|
||||||
QueuedPluginSpecification::readSpecification(const QString &_path)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_PL) << "Read specification from" << _path;
|
qCDebug(LOG_PL) << "Read specification from" << _path;
|
||||||
|
|
||||||
|
@ -41,8 +41,7 @@ extern "C" {
|
|||||||
/**
|
/**
|
||||||
* @fn QueuedProcess
|
* @fn QueuedProcess
|
||||||
*/
|
*/
|
||||||
QueuedProcess::QueuedProcess(QObject *_parent,
|
QueuedProcess::QueuedProcess(QObject *_parent, const QueuedProcessDefinitions &definitions,
|
||||||
const QueuedProcessDefinitions &definitions,
|
|
||||||
const long long index)
|
const long long index)
|
||||||
: QProcess(_parent)
|
: QProcess(_parent)
|
||||||
, m_definitions(definitions)
|
, m_definitions(definitions)
|
||||||
@ -98,11 +97,9 @@ void QueuedProcess::updateLimits()
|
|||||||
{
|
{
|
||||||
auto nl = nativeLimits();
|
auto nl = nativeLimits();
|
||||||
|
|
||||||
m_cgroup->setCpuLimit(
|
m_cgroup->setCpuLimit(std::llround(QueuedSystemInfo::cpuWeight(nl.cpu) * 100.0));
|
||||||
std::llround(QueuedSystemInfo::cpuWeight(nl.cpu) * 100.0));
|
|
||||||
m_cgroup->setMemoryLimit(
|
m_cgroup->setMemoryLimit(
|
||||||
std::llround(QueuedSystemInfo::memoryWeight(nl.memory)
|
std::llround(QueuedSystemInfo::memoryWeight(nl.memory) * QueuedSystemInfo::memoryCount()));
|
||||||
* QueuedSystemInfo::memoryCount()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -111,27 +108,27 @@ void QueuedProcess::updateLimits()
|
|||||||
*/
|
*/
|
||||||
QList<Q_PID> QueuedProcess::childrenPids() const
|
QList<Q_PID> QueuedProcess::childrenPids() const
|
||||||
{
|
{
|
||||||
QStringList allDirectories = QDir("/proc").entryList(
|
QStringList allDirectories
|
||||||
QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
= QDir("/proc").entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
|
||||||
QStringList directories = allDirectories.filter(QRegExp("(\\d+)"));
|
QStringList directories = allDirectories.filter(QRegExp("(\\d+)"));
|
||||||
|
|
||||||
QList<Q_PID> pids = std::accumulate(
|
QList<Q_PID> pids
|
||||||
directories.cbegin(), directories.cend(), QList<Q_PID>(),
|
= std::accumulate(directories.cbegin(), directories.cend(), QList<Q_PID>(),
|
||||||
[this](QList<Q_PID> &list, const QString &dir) {
|
[this](QList<Q_PID> &list, const QString &dir) {
|
||||||
QFile statFile(QString("/proc/%1/stat").arg(dir));
|
QFile statFile(QString("/proc/%1/stat").arg(dir));
|
||||||
if (!statFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
if (!statFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||||
return list;
|
return list;
|
||||||
|
|
||||||
QString output = statFile.readAll();
|
QString output = statFile.readAll();
|
||||||
output.remove(QRegExp("\\d+ \\(.*\\) . "));
|
output.remove(QRegExp("\\d+ \\(.*\\) . "));
|
||||||
Q_PID ppid = output.split(' ').first().toLongLong();
|
Q_PID ppid = output.split(' ').first().toLongLong();
|
||||||
if (ppid == pid())
|
if (ppid == pid())
|
||||||
list.append(dir.toLongLong());
|
list.append(dir.toLongLong());
|
||||||
|
|
||||||
statFile.close();
|
statFile.close();
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
});
|
});
|
||||||
|
|
||||||
return pids;
|
return pids;
|
||||||
}
|
}
|
||||||
@ -359,8 +356,7 @@ void QueuedProcess::setWorkDirectory(const QString &_workDirectory)
|
|||||||
|
|
||||||
m_definitions.workingDirectory
|
m_definitions.workingDirectory
|
||||||
= _workDirectory.isEmpty()
|
= _workDirectory.isEmpty()
|
||||||
? QStandardPaths::writableLocation(
|
? QStandardPaths::writableLocation(QStandardPaths::StandardLocation::TempLocation)
|
||||||
QStandardPaths::StandardLocation::TempLocation)
|
|
||||||
: _workDirectory;
|
: _workDirectory;
|
||||||
setLogError("");
|
setLogError("");
|
||||||
setLogOutput("");
|
setLogOutput("");
|
||||||
|
@ -78,10 +78,8 @@ QueuedProcessManager::parseDefinitions(const QVariantHash &_properties)
|
|||||||
defs.gid = _properties["gid"].toUInt();
|
defs.gid = _properties["gid"].toUInt();
|
||||||
defs.user = _properties["user"].toLongLong();
|
defs.user = _properties["user"].toLongLong();
|
||||||
// metadata
|
// metadata
|
||||||
defs.startTime = QDateTime::fromString(_properties["startTime"].toString(),
|
defs.startTime = QDateTime::fromString(_properties["startTime"].toString(), Qt::ISODateWithMs);
|
||||||
Qt::ISODateWithMs);
|
defs.endTime = QDateTime::fromString(_properties["endTime"].toString(), Qt::ISODateWithMs);
|
||||||
defs.endTime = QDateTime::fromString(_properties["endTime"].toString(),
|
|
||||||
Qt::ISODateWithMs);
|
|
||||||
|
|
||||||
return defs;
|
return defs;
|
||||||
}
|
}
|
||||||
@ -90,11 +88,9 @@ QueuedProcessManager::parseDefinitions(const QVariantHash &_properties)
|
|||||||
/**
|
/**
|
||||||
* @fn add
|
* @fn add
|
||||||
*/
|
*/
|
||||||
QueuedProcess *QueuedProcessManager::add(const QVariantHash &_properties,
|
QueuedProcess *QueuedProcessManager::add(const QVariantHash &_properties, const long long _index)
|
||||||
const long long _index)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add new process" << _properties << "with index"
|
qCDebug(LOG_LIB) << "Add new process" << _properties << "with index" << _index;
|
||||||
<< _index;
|
|
||||||
|
|
||||||
return add(parseDefinitions(_properties), _index);
|
return add(parseDefinitions(_properties), _index);
|
||||||
}
|
}
|
||||||
@ -103,12 +99,11 @@ QueuedProcess *QueuedProcessManager::add(const QVariantHash &_properties,
|
|||||||
/**
|
/**
|
||||||
* @fn add
|
* @fn add
|
||||||
*/
|
*/
|
||||||
QueuedProcess *QueuedProcessManager::add(
|
QueuedProcess *
|
||||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
QueuedProcessManager::add(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
const long long _index)
|
const long long _index)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add new process" << _definitions.command
|
qCDebug(LOG_LIB) << "Add new process" << _definitions.command << "with index" << _index;
|
||||||
<< "with index" << _index;
|
|
||||||
|
|
||||||
if (processes().contains(_index))
|
if (processes().contains(_index))
|
||||||
return process(_index);
|
return process(_index);
|
||||||
@ -117,9 +112,7 @@ QueuedProcess *QueuedProcessManager::add(
|
|||||||
m_processes[_index] = process;
|
m_processes[_index] = process;
|
||||||
// connect to signal
|
// connect to signal
|
||||||
m_connections[_index] = connect(
|
m_connections[_index] = connect(
|
||||||
process,
|
process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
|
||||||
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(
|
|
||||||
&QProcess::finished),
|
|
||||||
[=](const int exitCode, const QProcess::ExitStatus exitStatus) {
|
[=](const int exitCode, const QProcess::ExitStatus exitStatus) {
|
||||||
return taskFinished(exitCode, exitStatus, _index);
|
return taskFinished(exitCode, exitStatus, _index);
|
||||||
});
|
});
|
||||||
@ -199,11 +192,9 @@ void QueuedProcessManager::start()
|
|||||||
long long index = -1;
|
long long index = -1;
|
||||||
// gather used resources
|
// gather used resources
|
||||||
QueuedLimits::Limits limits = usedLimits();
|
QueuedLimits::Limits limits = usedLimits();
|
||||||
double weightedCpu
|
double weightedCpu = limits.cpu == 0 ? 0.0 : QueuedSystemInfo::cpuWeight(limits.cpu);
|
||||||
= limits.cpu == 0 ? 0.0 : QueuedSystemInfo::cpuWeight(limits.cpu);
|
double weightedMemory
|
||||||
double weightedMemory = limits.memory == 0
|
= limits.memory == 0 ? 0.0 : QueuedSystemInfo::memoryWeight(limits.memory);
|
||||||
? 0.0
|
|
||||||
: QueuedSystemInfo::memoryWeight(limits.memory);
|
|
||||||
|
|
||||||
auto tasks = processes().values();
|
auto tasks = processes().values();
|
||||||
for (auto pr : tasks) {
|
for (auto pr : tasks) {
|
||||||
@ -211,10 +202,8 @@ void QueuedProcessManager::start()
|
|||||||
if (pr->state() != QProcess::ProcessState::NotRunning)
|
if (pr->state() != QProcess::ProcessState::NotRunning)
|
||||||
continue;
|
continue;
|
||||||
// check limits first
|
// check limits first
|
||||||
if (((1.0 - weightedCpu)
|
if (((1.0 - weightedCpu) < QueuedSystemInfo::cpuWeight(pr->nativeLimits().cpu))
|
||||||
< QueuedSystemInfo::cpuWeight(pr->nativeLimits().cpu))
|
&& ((1.0 - weightedMemory) < QueuedSystemInfo::memoryWeight(pr->nativeLimits().memory)))
|
||||||
&& ((1.0 - weightedMemory)
|
|
||||||
< QueuedSystemInfo::memoryWeight(pr->nativeLimits().memory)))
|
|
||||||
continue;
|
continue;
|
||||||
// now check nice level
|
// now check nice level
|
||||||
if ((index > -1) && (pr->nice() < process(index)->nice()))
|
if ((index > -1) && (pr->nice() < process(index)->nice()))
|
||||||
@ -314,28 +303,19 @@ QueuedLimits::Limits QueuedProcessManager::usedLimits()
|
|||||||
{
|
{
|
||||||
auto tasks = processes().values();
|
auto tasks = processes().values();
|
||||||
long long cpu = std::accumulate(
|
long long cpu = std::accumulate(
|
||||||
tasks.cbegin(), tasks.cend(), 0,
|
tasks.cbegin(), tasks.cend(), 0, [](long long value, QueuedProcess *process) {
|
||||||
[](long long value, QueuedProcess *process) {
|
auto limit = process->nativeLimits().cpu == 0 ? QueuedSystemInfo::cpuCount()
|
||||||
auto limit = process->nativeLimits().cpu == 0
|
: process->nativeLimits().cpu;
|
||||||
? QueuedSystemInfo::cpuCount()
|
return process->state() == QProcess::ProcessState::Running ? value + limit : value;
|
||||||
: process->nativeLimits().cpu;
|
|
||||||
return process->state() == QProcess::ProcessState::Running
|
|
||||||
? value + limit
|
|
||||||
: value;
|
|
||||||
});
|
});
|
||||||
long long memory = std::accumulate(
|
long long memory = std::accumulate(
|
||||||
tasks.cbegin(), tasks.cend(), 0,
|
tasks.cbegin(), tasks.cend(), 0, [](long long value, QueuedProcess *process) {
|
||||||
[](long long value, QueuedProcess *process) {
|
auto limit = process->nativeLimits().memory == 0 ? QueuedSystemInfo::memoryCount()
|
||||||
auto limit = process->nativeLimits().memory == 0
|
: process->nativeLimits().memory;
|
||||||
? QueuedSystemInfo::memoryCount()
|
return process->state() == QProcess::ProcessState::Running ? value + limit : value;
|
||||||
: process->nativeLimits().memory;
|
|
||||||
return process->state() == QProcess::ProcessState::Running
|
|
||||||
? value + limit
|
|
||||||
: value;
|
|
||||||
});
|
});
|
||||||
long long storage = std::accumulate(
|
long long storage = std::accumulate(
|
||||||
tasks.cbegin(), tasks.cend(), 0,
|
tasks.cbegin(), tasks.cend(), 0, [](long long value, QueuedProcess *process) {
|
||||||
[](long long value, QueuedProcess *process) {
|
|
||||||
return process->state() == QProcess::ProcessState::Running
|
return process->state() == QProcess::ProcessState::Running
|
||||||
? value + process->nativeLimits().storage
|
? value + process->nativeLimits().storage
|
||||||
: value;
|
: value;
|
||||||
@ -348,12 +328,11 @@ QueuedLimits::Limits QueuedProcessManager::usedLimits()
|
|||||||
/**
|
/**
|
||||||
* @fn taskFinished
|
* @fn taskFinished
|
||||||
*/
|
*/
|
||||||
void QueuedProcessManager::taskFinished(const int _exitCode,
|
void QueuedProcessManager::taskFinished(const int _exitCode, const QProcess::ExitStatus _exitStatus,
|
||||||
const QProcess::ExitStatus _exitStatus,
|
|
||||||
const long long _index)
|
const long long _index)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Process" << _index << "finished with code" << _exitCode
|
qCDebug(LOG_LIB) << "Process" << _index << "finished with code" << _exitCode << "and status"
|
||||||
<< "and status" << _exitStatus;
|
<< _exitStatus;
|
||||||
|
|
||||||
auto pr = process(_index);
|
auto pr = process(_index);
|
||||||
if (pr) {
|
if (pr) {
|
||||||
|
@ -39,6 +39,10 @@ QueuedPropertyInterface::QueuedPropertyInterface(QueuedCore *parent)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
|
|
||||||
|
qRegisterMetaType<QList<Q_PID>>("QList<Q_PID>");
|
||||||
|
qDBusRegisterMetaType<QList<Q_PID>>();
|
||||||
|
|
||||||
qRegisterMetaType<QueuedResult<QVariant>>("QueuedResult<QVariant>");
|
qRegisterMetaType<QueuedResult<QVariant>>("QueuedResult<QVariant>");
|
||||||
qDBusRegisterMetaType<QueuedResult<QVariant>>();
|
qDBusRegisterMetaType<QueuedResult<QVariant>>();
|
||||||
|
|
||||||
@ -49,8 +53,7 @@ QueuedPropertyInterface::QueuedPropertyInterface(QueuedCore *parent)
|
|||||||
"QueuedPluginSpecification::PluginOption");
|
"QueuedPluginSpecification::PluginOption");
|
||||||
qDBusRegisterMetaType<QueuedPluginSpecification::PluginOption>();
|
qDBusRegisterMetaType<QueuedPluginSpecification::PluginOption>();
|
||||||
|
|
||||||
qRegisterMetaType<QueuedPluginSpecification::Plugin>(
|
qRegisterMetaType<QueuedPluginSpecification::Plugin>("QueuedPluginSpecification::Plugin");
|
||||||
"QueuedPluginSpecification::Plugin");
|
|
||||||
qDBusRegisterMetaType<QueuedPluginSpecification::Plugin>();
|
qDBusRegisterMetaType<QueuedPluginSpecification::Plugin>();
|
||||||
|
|
||||||
qRegisterMetaType<QueuedResult<QueuedPluginSpecification::Plugin>>(
|
qRegisterMetaType<QueuedResult<QueuedPluginSpecification::Plugin>>(
|
||||||
@ -71,8 +74,7 @@ QueuedPropertyInterface::~QueuedPropertyInterface()
|
|||||||
/**
|
/**
|
||||||
* @fn Plugin
|
* @fn Plugin
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedPropertyInterface::Plugin(const QString &plugin,
|
QDBusVariant QueuedPropertyInterface::Plugin(const QString &plugin, const QString &token)
|
||||||
const QString &token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get plugin" << plugin;
|
qCDebug(LOG_DBUS) << "Get plugin" << plugin;
|
||||||
|
|
||||||
@ -83,21 +85,18 @@ QDBusVariant QueuedPropertyInterface::Plugin(const QString &plugin,
|
|||||||
/**
|
/**
|
||||||
* @fn PluginOptions
|
* @fn PluginOptions
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedPropertyInterface::PluginOptions(const QString &plugin,
|
QDBusVariant QueuedPropertyInterface::PluginOptions(const QString &plugin, const QString &token)
|
||||||
const QString &token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get plugin options" << plugin;
|
qCDebug(LOG_DBUS) << "Get plugin options" << plugin;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::toDBusVariant(
|
return QueuedCoreAdaptor::toDBusVariant(m_core->pluginSettings(plugin, token));
|
||||||
m_core->pluginSettings(plugin, token));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn Option
|
* @fn Option
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedPropertyInterface::Option(const QString &property,
|
QDBusVariant QueuedPropertyInterface::Option(const QString &property, const QString &token)
|
||||||
const QString &token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get property" << property;
|
qCDebug(LOG_DBUS) << "Get property" << property;
|
||||||
|
|
||||||
@ -108,8 +107,7 @@ QDBusVariant QueuedPropertyInterface::Option(const QString &property,
|
|||||||
/**
|
/**
|
||||||
* @fn Task
|
* @fn Task
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedPropertyInterface::Task(const long long id,
|
QDBusVariant QueuedPropertyInterface::Task(const long long id, const QString &property,
|
||||||
const QString &property,
|
|
||||||
const QString &token)
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get property" << property << "from task" << id;
|
qCDebug(LOG_DBUS) << "Get property" << property << "from task" << id;
|
||||||
@ -118,20 +116,17 @@ QDBusVariant QueuedPropertyInterface::Task(const long long id,
|
|||||||
if (!task) {
|
if (!task) {
|
||||||
qCWarning(LOG_DBUS) << "Could not find task" << id;
|
qCWarning(LOG_DBUS) << "Could not find task" << id;
|
||||||
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<QVariant>(
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<QVariant>(
|
||||||
QueuedError("Task does not exist",
|
QueuedError("Task does not exist", QueuedEnums::ReturnStatus::InvalidArgument)));
|
||||||
QueuedEnums::ReturnStatus::InvalidArgument)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property.isEmpty()) {
|
if (property.isEmpty()) {
|
||||||
auto response = QVariant::fromValue<QVariantHash>(getProperties(task));
|
auto response = QVariant::fromValue<QVariantHash>(getProperties(task));
|
||||||
return QueuedCoreAdaptor::toDBusVariant(
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<QVariant>(response));
|
||||||
QueuedResult<QVariant>(response));
|
|
||||||
} else {
|
} else {
|
||||||
auto response = task->property(qPrintable(property));
|
auto response = task->property(qPrintable(property));
|
||||||
if (response.type() == QVariant::DateTime)
|
if (response.type() == QVariant::DateTime)
|
||||||
response = response.toDateTime().toString(Qt::ISODateWithMs);
|
response = response.toDateTime().toString(Qt::ISODateWithMs);
|
||||||
return QueuedCoreAdaptor::toDBusVariant(
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<QVariant>(response));
|
||||||
QueuedResult<QVariant>(response));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,8 +134,7 @@ QDBusVariant QueuedPropertyInterface::Task(const long long id,
|
|||||||
/**
|
/**
|
||||||
* @fn User
|
* @fn User
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedPropertyInterface::User(const long long id,
|
QDBusVariant QueuedPropertyInterface::User(const long long id, const QString &property,
|
||||||
const QString &property,
|
|
||||||
const QString &token)
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Get property" << property << "from user" << id;
|
qCDebug(LOG_DBUS) << "Get property" << property << "from user" << id;
|
||||||
@ -149,20 +143,17 @@ QDBusVariant QueuedPropertyInterface::User(const long long id,
|
|||||||
if (!user) {
|
if (!user) {
|
||||||
qCWarning(LOG_DBUS) << "Could not find user" << id;
|
qCWarning(LOG_DBUS) << "Could not find user" << id;
|
||||||
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<QVariant>(
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<QVariant>(
|
||||||
QueuedError("User does not exist",
|
QueuedError("User does not exist", QueuedEnums::ReturnStatus::InvalidArgument)));
|
||||||
QueuedEnums::ReturnStatus::InvalidArgument)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property.isEmpty()) {
|
if (property.isEmpty()) {
|
||||||
auto response = QVariant::fromValue<QVariantHash>(getProperties(user));
|
auto response = QVariant::fromValue<QVariantHash>(getProperties(user));
|
||||||
return QueuedCoreAdaptor::toDBusVariant(
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<QVariant>(response));
|
||||||
QueuedResult<QVariant>(response));
|
|
||||||
} else {
|
} else {
|
||||||
auto response = user->property(qPrintable(property));
|
auto response = user->property(qPrintable(property));
|
||||||
if (response.type() == QVariant::DateTime)
|
if (response.type() == QVariant::DateTime)
|
||||||
response = response.toDateTime().toString(Qt::ISODateWithMs);
|
response = response.toDateTime().toString(Qt::ISODateWithMs);
|
||||||
return QueuedCoreAdaptor::toDBusVariant(
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<QVariant>(response));
|
||||||
QueuedResult<QVariant>(response));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,8 +161,7 @@ QDBusVariant QueuedPropertyInterface::User(const long long id,
|
|||||||
/**
|
/**
|
||||||
* @fn UserIdByName
|
* @fn UserIdByName
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedPropertyInterface::UserIdByName(const QString &name,
|
QDBusVariant QueuedPropertyInterface::UserIdByName(const QString &name, const QString &token)
|
||||||
const QString &token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Look for user ID" << name;
|
qCDebug(LOG_DBUS) << "Look for user ID" << name;
|
||||||
|
|
||||||
@ -179,12 +169,10 @@ QDBusVariant QueuedPropertyInterface::UserIdByName(const QString &name,
|
|||||||
if (!user) {
|
if (!user) {
|
||||||
qCWarning(LOG_DBUS) << "Could not find user" << name;
|
qCWarning(LOG_DBUS) << "Could not find user" << name;
|
||||||
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<long long>(
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<long long>(
|
||||||
QueuedError("User does not exist",
|
QueuedError("User does not exist", QueuedEnums::ReturnStatus::InvalidArgument)));
|
||||||
QueuedEnums::ReturnStatus::InvalidArgument)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return QueuedCoreAdaptor::toDBusVariant(
|
return QueuedCoreAdaptor::toDBusVariant(QueuedResult<long long>(user->index()));
|
||||||
QueuedResult<long long>(user->index()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -206,8 +194,7 @@ QVariantHash QueuedPropertyInterface::getProperties(const QObject *_object)
|
|||||||
continue;
|
continue;
|
||||||
result[name] = _object->property(name);
|
result[name] = _object->property(name);
|
||||||
if (result[name].type() == QVariant::DateTime)
|
if (result[name].type() == QVariant::DateTime)
|
||||||
result[name]
|
result[name] = result[name].toDateTime().toString(Qt::ISODateWithMs);
|
||||||
= result[name].toDateTime().toString(Qt::ISODateWithMs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -41,12 +41,10 @@ QueuedReportInterface::QueuedReportInterface(QueuedCore *parent)
|
|||||||
qRegisterMetaType<QHash<QString, QString>>("QHash<QString, QString>");
|
qRegisterMetaType<QHash<QString, QString>>("QHash<QString, QString>");
|
||||||
qDBusRegisterMetaType<QHash<QString, QString>>();
|
qDBusRegisterMetaType<QHash<QString, QString>>();
|
||||||
|
|
||||||
qRegisterMetaType<QueuedResult<QList<QVariantHash>>>(
|
qRegisterMetaType<QueuedResult<QList<QVariantHash>>>("QueuedResult<QList<QVariantHash>>");
|
||||||
"QueuedResult<QList<QVariantHash>>");
|
|
||||||
qDBusRegisterMetaType<QueuedResult<QList<QVariantHash>>>();
|
qDBusRegisterMetaType<QueuedResult<QList<QVariantHash>>>();
|
||||||
|
|
||||||
qRegisterMetaType<QueuedResult<QueuedStatusMap>>(
|
qRegisterMetaType<QueuedResult<QueuedStatusMap>>("QueuedResult<QueuedStatusMap>");
|
||||||
"QueuedResult<QueuedStatusMap>");
|
|
||||||
qDBusRegisterMetaType<QueuedResult<QueuedStatusMap>>();
|
qDBusRegisterMetaType<QueuedResult<QueuedStatusMap>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,15 +61,14 @@ QueuedReportInterface::~QueuedReportInterface()
|
|||||||
/**
|
/**
|
||||||
* @fn Performance
|
* @fn Performance
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedReportInterface::Performance(const QString &from,
|
QDBusVariant QueuedReportInterface::Performance(const QString &from, const QString &to,
|
||||||
const QString &to,
|
|
||||||
const QString &token)
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Performance report for" << from << to;
|
qCDebug(LOG_DBUS) << "Performance report for" << from << to;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::toDBusVariant(m_core->performanceReport(
|
return QueuedCoreAdaptor::toDBusVariant(
|
||||||
QDateTime::fromString(from, Qt::ISODateWithMs),
|
m_core->performanceReport(QDateTime::fromString(from, Qt::ISODateWithMs),
|
||||||
QDateTime::fromString(to, Qt::ISODateWithMs), token));
|
QDateTime::fromString(to, Qt::ISODateWithMs), token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -83,39 +80,34 @@ QDBusVariant QueuedReportInterface::Status()
|
|||||||
QueuedResult<QueuedStatusMap> metadata = QueuedDebug::getBuildMetaData();
|
QueuedResult<QueuedStatusMap> metadata = QueuedDebug::getBuildMetaData();
|
||||||
// append metadata here
|
// append metadata here
|
||||||
|
|
||||||
return QDBusVariant(
|
return QDBusVariant(QVariant::fromValue<QueuedResult<QueuedStatusMap>>(metadata));
|
||||||
QVariant::fromValue<QueuedResult<QueuedStatusMap>>(metadata));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn Tasks
|
* @fn Tasks
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedReportInterface::Tasks(const qlonglong user,
|
QDBusVariant QueuedReportInterface::Tasks(const qlonglong user, const QString &from,
|
||||||
const QString &from,
|
const QString &to, const QString &token)
|
||||||
const QString &to,
|
|
||||||
const QString &token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Search for tasks" << user << from << to;
|
qCDebug(LOG_DBUS) << "Search for tasks" << user << from << to;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::toDBusVariant(m_core->taskReport(
|
return QueuedCoreAdaptor::toDBusVariant(
|
||||||
user, QDateTime::fromString(from, Qt::ISODateWithMs),
|
m_core->taskReport(user, QDateTime::fromString(from, Qt::ISODateWithMs),
|
||||||
QDateTime::fromString(to, Qt::ISODateWithMs), token));
|
QDateTime::fromString(to, Qt::ISODateWithMs), token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn Users
|
* @fn Users
|
||||||
*/
|
*/
|
||||||
QDBusVariant QueuedReportInterface::Users(const QString &lastLogged,
|
QDBusVariant QueuedReportInterface::Users(const QString &lastLogged, const uint permission,
|
||||||
const uint permission,
|
|
||||||
const QString &token)
|
const QString &token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_DBUS) << "Search for users" << lastLogged << permission;
|
qCDebug(LOG_DBUS) << "Search for users" << lastLogged << permission;
|
||||||
|
|
||||||
return QueuedCoreAdaptor::toDBusVariant(
|
return QueuedCoreAdaptor::toDBusVariant(m_core->userReport(
|
||||||
m_core->userReport(QDateTime::fromString(lastLogged, Qt::ISODateWithMs),
|
QDateTime::fromString(lastLogged, Qt::ISODateWithMs),
|
||||||
permission < 1 ? QueuedEnums::Permission::Invalid
|
permission < 1 ? QueuedEnums::Permission::Invalid : QueuedEnums::Permission(permission),
|
||||||
: QueuedEnums::Permission(permission),
|
token));
|
||||||
token));
|
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,7 @@
|
|||||||
/**
|
/**
|
||||||
* @fn QueuedReportManager
|
* @fn QueuedReportManager
|
||||||
*/
|
*/
|
||||||
QueuedReportManager::QueuedReportManager(QObject *_parent,
|
QueuedReportManager::QueuedReportManager(QObject *_parent, QueuedDatabase *_database,
|
||||||
QueuedDatabase *_database,
|
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
: QObject(_parent)
|
: QObject(_parent)
|
||||||
, m_database(_database)
|
, m_database(_database)
|
||||||
@ -72,17 +71,14 @@ QList<QVariantHash> QueuedReportManager::performance(const QueuedCore *_core,
|
|||||||
.arg(_to.toString(Qt::ISODateWithMs));
|
.arg(_to.toString(Qt::ISODateWithMs));
|
||||||
|
|
||||||
QString condition
|
QString condition
|
||||||
= conditions.isEmpty()
|
= conditions.isEmpty() ? "" : QString("WHERE (%1)").arg(conditions.join(" AND "));
|
||||||
? ""
|
|
||||||
: QString("WHERE (%1)").arg(conditions.join(" AND "));
|
|
||||||
qCInfo(LOG_LIB) << "Task condition select" << condition;
|
qCInfo(LOG_LIB) << "Task condition select" << condition;
|
||||||
auto tasks = m_database->get(QueuedDB::TASKS_TABLE, condition);
|
auto tasks = m_database->get(QueuedDB::TASKS_TABLE, condition);
|
||||||
|
|
||||||
// build hash first
|
// build hash first
|
||||||
QHash<long long, QVariantHash> hashOutput;
|
QHash<long long, QVariantHash> hashOutput;
|
||||||
for (auto &task : tasks) {
|
for (auto &task : tasks) {
|
||||||
QueuedLimits::Limits limits
|
QueuedLimits::Limits limits = QueuedLimits::Limits(task["limits"].toString());
|
||||||
= QueuedLimits::Limits(task["limits"].toString());
|
|
||||||
// update values to system ones if empty
|
// update values to system ones if empty
|
||||||
if (limits.cpu == 0)
|
if (limits.cpu == 0)
|
||||||
limits.cpu = QueuedSystemInfo::cpuCount();
|
limits.cpu = QueuedSystemInfo::cpuCount();
|
||||||
@ -90,11 +86,9 @@ QList<QVariantHash> QueuedReportManager::performance(const QueuedCore *_core,
|
|||||||
limits.memory = QueuedSystemInfo::memoryCount();
|
limits.memory = QueuedSystemInfo::memoryCount();
|
||||||
// calculate usage stats
|
// calculate usage stats
|
||||||
long long taskTime
|
long long taskTime
|
||||||
= QDateTime::fromString(task["endTime"].toString(),
|
= QDateTime::fromString(task["endTime"].toString(), Qt::ISODateWithMs)
|
||||||
Qt::ISODateWithMs)
|
|
||||||
.toMSecsSinceEpoch()
|
.toMSecsSinceEpoch()
|
||||||
- QDateTime::fromString(task["startTime"].toString(),
|
- QDateTime::fromString(task["startTime"].toString(), Qt::ISODateWithMs)
|
||||||
Qt::ISODateWithMs)
|
|
||||||
.toMSecsSinceEpoch();
|
.toMSecsSinceEpoch();
|
||||||
limits *= taskTime / 1000;
|
limits *= taskTime / 1000;
|
||||||
|
|
||||||
@ -102,16 +96,12 @@ QList<QVariantHash> QueuedReportManager::performance(const QueuedCore *_core,
|
|||||||
long long userId = task.value("user").toLongLong();
|
long long userId = task.value("user").toLongLong();
|
||||||
auto userObj = _core->user(userId, m_token);
|
auto userObj = _core->user(userId, m_token);
|
||||||
QVariantHash currentData = hashOutput[userId];
|
QVariantHash currentData = hashOutput[userId];
|
||||||
currentData["cpu"]
|
currentData["cpu"] = currentData.value("cpu", 0).toLongLong() + limits.cpu;
|
||||||
= currentData.value("cpu", 0).toLongLong() + limits.cpu;
|
currentData["memory"] = currentData.value("memory", 0).toLongLong() + limits.memory;
|
||||||
currentData["memory"]
|
currentData["gpu"] = currentData.value("gpu", 0).toLongLong() + limits.gpu;
|
||||||
= currentData.value("memory", 0).toLongLong() + limits.memory;
|
|
||||||
currentData["gpu"]
|
|
||||||
= currentData.value("gpu", 0).toLongLong() + limits.gpu;
|
|
||||||
currentData["gpumemory"]
|
currentData["gpumemory"]
|
||||||
= currentData.value("gpumemory", 0).toLongLong() + limits.gpumemory;
|
= currentData.value("gpumemory", 0).toLongLong() + limits.gpumemory;
|
||||||
currentData["storage"]
|
currentData["storage"] = currentData.value("storage", 0).toLongLong() + limits.storage;
|
||||||
= currentData.value("storage", 0).toLongLong() + limits.storage;
|
|
||||||
currentData["count"] = currentData.value("count", 0).toLongLong() + 1;
|
currentData["count"] = currentData.value("count", 0).toLongLong() + 1;
|
||||||
// internal fields
|
// internal fields
|
||||||
currentData["user"] = userObj ? userObj->name() : "";
|
currentData["user"] = userObj ? userObj->name() : "";
|
||||||
@ -124,9 +114,7 @@ QList<QVariantHash> QueuedReportManager::performance(const QueuedCore *_core,
|
|||||||
// append output data
|
// append output data
|
||||||
auto userList = hashOutput.keys();
|
auto userList = hashOutput.keys();
|
||||||
std::sort(userList.begin(), userList.end(),
|
std::sort(userList.begin(), userList.end(),
|
||||||
[](const long long first, const long long second) {
|
[](const long long first, const long long second) { return first < second; });
|
||||||
return first < second;
|
|
||||||
});
|
|
||||||
QList<QVariantHash> output;
|
QList<QVariantHash> output;
|
||||||
for (auto userId : userList)
|
for (auto userId : userList)
|
||||||
output.append(hashOutput[userId]);
|
output.append(hashOutput[userId]);
|
||||||
@ -138,8 +126,7 @@ QList<QVariantHash> QueuedReportManager::performance(const QueuedCore *_core,
|
|||||||
/**
|
/**
|
||||||
* @fn tasks
|
* @fn tasks
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash> QueuedReportManager::tasks(const long long _user,
|
QList<QVariantHash> QueuedReportManager::tasks(const long long _user, const QDateTime &_from,
|
||||||
const QDateTime &_from,
|
|
||||||
const QDateTime &_to) const
|
const QDateTime &_to) const
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Search for tasks in" << _user << _from << _to;
|
qCDebug(LOG_LIB) << "Search for tasks in" << _user << _from << _to;
|
||||||
@ -157,9 +144,7 @@ QList<QVariantHash> QueuedReportManager::tasks(const long long _user,
|
|||||||
.arg(_to.toString(Qt::ISODateWithMs));
|
.arg(_to.toString(Qt::ISODateWithMs));
|
||||||
|
|
||||||
QString condition
|
QString condition
|
||||||
= conditions.isEmpty()
|
= conditions.isEmpty() ? "" : QString("WHERE (%1)").arg(conditions.join(" AND "));
|
||||||
? ""
|
|
||||||
: QString("WHERE (%1)").arg(conditions.join(" AND "));
|
|
||||||
qCInfo(LOG_LIB) << "Task condition select" << condition;
|
qCInfo(LOG_LIB) << "Task condition select" << condition;
|
||||||
|
|
||||||
return m_database->get(QueuedDB::TASKS_TABLE, condition);
|
return m_database->get(QueuedDB::TASKS_TABLE, condition);
|
||||||
@ -169,12 +154,10 @@ QList<QVariantHash> QueuedReportManager::tasks(const long long _user,
|
|||||||
/**
|
/**
|
||||||
* @fn users
|
* @fn users
|
||||||
*/
|
*/
|
||||||
QList<QVariantHash>
|
QList<QVariantHash> QueuedReportManager::users(const QDateTime &_lastLogged,
|
||||||
QueuedReportManager::users(const QDateTime &_lastLogged,
|
const QueuedEnums::Permission _permission) const
|
||||||
const QueuedEnums::Permission _permission) const
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Search for users in" << _lastLogged
|
qCDebug(LOG_LIB) << "Search for users in" << _lastLogged << static_cast<uint>(_permission);
|
||||||
<< static_cast<uint>(_permission);
|
|
||||||
|
|
||||||
QStringList conditions;
|
QStringList conditions;
|
||||||
if (_lastLogged.isValid())
|
if (_lastLogged.isValid())
|
||||||
@ -182,13 +165,11 @@ QueuedReportManager::users(const QDateTime &_lastLogged,
|
|||||||
"(lastLogin NOT NULL))")
|
"(lastLogin NOT NULL))")
|
||||||
.arg(_lastLogged.toString(Qt::ISODateWithMs));
|
.arg(_lastLogged.toString(Qt::ISODateWithMs));
|
||||||
if (_permission != QueuedEnums::Permission::Invalid)
|
if (_permission != QueuedEnums::Permission::Invalid)
|
||||||
conditions += QString("((permissions & ~%1) != permissions)")
|
conditions
|
||||||
.arg(static_cast<uint>(_permission));
|
+= QString("((permissions & ~%1) != permissions)").arg(static_cast<uint>(_permission));
|
||||||
|
|
||||||
QString condition
|
QString condition
|
||||||
= conditions.isEmpty()
|
= conditions.isEmpty() ? "" : QString("WHERE (%1)").arg(conditions.join(" AND "));
|
||||||
? ""
|
|
||||||
: QString("WHERE (%1)").arg(conditions.join(" AND "));
|
|
||||||
qCInfo(LOG_LIB) << "User condition select" << condition;
|
qCInfo(LOG_LIB) << "User condition select" << condition;
|
||||||
|
|
||||||
return m_database->get(QueuedDB::USERS_TABLE, condition);
|
return m_database->get(QueuedDB::USERS_TABLE, condition);
|
||||||
|
@ -40,10 +40,8 @@ QueuedSettings::QueuedSettings(QObject *_parent, const QString _path)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
qRegisterMetaType<QueuedConfig::QueuedAdminSetup>(
|
qRegisterMetaType<QueuedConfig::QueuedAdminSetup>("QueuedConfig::QueuedAdminSetup");
|
||||||
"QueuedConfig::QueuedAdminSetup");
|
qRegisterMetaType<QueuedConfig::QueuedDBSetup>("QueuedConfig::QueuedDBSetup");
|
||||||
qRegisterMetaType<QueuedConfig::QueuedDBSetup>(
|
|
||||||
"QueuedConfig::QueuedDBSetup");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -79,8 +77,7 @@ QueuedConfig::QueuedDBSetup QueuedSettings::db() const
|
|||||||
*/
|
*/
|
||||||
QString QueuedSettings::defaultPath()
|
QString QueuedSettings::defaultPath()
|
||||||
{
|
{
|
||||||
QString fileName
|
QString fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation, "queued.ini");
|
||||||
= QStandardPaths::locate(QStandardPaths::ConfigLocation, "queued.ini");
|
|
||||||
qCInfo(LOG_LIB) << "Found configuration file" << fileName;
|
qCInfo(LOG_LIB) << "Found configuration file" << fileName;
|
||||||
|
|
||||||
return fileName;
|
return fileName;
|
||||||
@ -92,9 +89,9 @@ QString QueuedSettings::defaultPath()
|
|||||||
*/
|
*/
|
||||||
QString QueuedSettings::defaultTokenPath()
|
QString QueuedSettings::defaultTokenPath()
|
||||||
{
|
{
|
||||||
QString fileName = QString("%1/queued")
|
QString fileName
|
||||||
.arg(QStandardPaths::writableLocation(
|
= QString("%1/queued")
|
||||||
QStandardPaths::GenericCacheLocation));
|
.arg(QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation));
|
||||||
qCInfo(LOG_LIB) << "Cache file location" << fileName;
|
qCInfo(LOG_LIB) << "Cache file location" << fileName;
|
||||||
|
|
||||||
return fileName;
|
return fileName;
|
||||||
@ -132,8 +129,7 @@ void QueuedSettings::readConfiguration()
|
|||||||
m_cfgDB.password = settings.value("Password").toString();
|
m_cfgDB.password = settings.value("Password").toString();
|
||||||
// get standard path for temporary files
|
// get standard path for temporary files
|
||||||
QString defaultDB = QString("%1/queued.db")
|
QString defaultDB = QString("%1/queued.db")
|
||||||
.arg(QStandardPaths::writableLocation(
|
.arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
|
||||||
QStandardPaths::TempLocation));
|
|
||||||
m_cfgDB.path = settings.value("Path", defaultDB).toString();
|
m_cfgDB.path = settings.value("Path", defaultDB).toString();
|
||||||
m_cfgDB.port = settings.value("Port").toInt();
|
m_cfgDB.port = settings.value("Port").toInt();
|
||||||
m_cfgDB.username = settings.value("Username").toString();
|
m_cfgDB.username = settings.value("Username").toString();
|
||||||
|
@ -74,8 +74,7 @@ double QueuedSystemInfo::memoryWeight(const long long _memory)
|
|||||||
qCDebug(LOG_LIB) << "Get memory weight for" << _memory;
|
qCDebug(LOG_LIB) << "Get memory weight for" << _memory;
|
||||||
|
|
||||||
if ((_memory > 0) && (_memory < memoryCount()))
|
if ((_memory > 0) && (_memory < memoryCount()))
|
||||||
return static_cast<double>(_memory)
|
return static_cast<double>(_memory) / static_cast<double>(memoryCount());
|
||||||
/ static_cast<double>(memoryCount());
|
|
||||||
else
|
else
|
||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
|
@ -55,8 +55,7 @@ QString QueuedTokenManager::isTokenValid(const QString &_token) const
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Check token on validity" << _token;
|
qCDebug(LOG_LIB) << "Check token on validity" << _token;
|
||||||
|
|
||||||
if (m_tokens.contains(_token)
|
if (m_tokens.contains(_token) && (tokenExpiration(_token) > QDateTime::currentDateTimeUtc()))
|
||||||
&& (tokenExpiration(_token) > QDateTime::currentDateTimeUtc()))
|
|
||||||
return m_tokens[_token].user;
|
return m_tokens[_token].user;
|
||||||
else
|
else
|
||||||
return "";
|
return "";
|
||||||
@ -66,18 +65,16 @@ QString QueuedTokenManager::isTokenValid(const QString &_token) const
|
|||||||
/**
|
/**
|
||||||
* @brief loadToken
|
* @brief loadToken
|
||||||
*/
|
*/
|
||||||
void QueuedTokenManager::loadToken(
|
void QueuedTokenManager::loadToken(const QueuedTokenManager::QueuedTokenDefinitions &_definitions)
|
||||||
const QueuedTokenManager::QueuedTokenDefinitions &_definitions)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add token for user" << _definitions.user
|
qCDebug(LOG_LIB) << "Add token for user" << _definitions.user << "valid until"
|
||||||
<< "valid until" << _definitions.validUntil;
|
<< _definitions.validUntil;
|
||||||
|
|
||||||
m_tokens[_definitions.token] = _definitions;
|
m_tokens[_definitions.token] = _definitions;
|
||||||
|
|
||||||
// register expiry timer
|
// register expiry timer
|
||||||
std::chrono::milliseconds duration(
|
std::chrono::milliseconds duration(_definitions.validUntil.toMSecsSinceEpoch()
|
||||||
_definitions.validUntil.toMSecsSinceEpoch()
|
- QDateTime::currentDateTimeUtc().toMSecsSinceEpoch());
|
||||||
- QDateTime::currentDateTimeUtc().toMSecsSinceEpoch());
|
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
timer.setSingleShot(true);
|
timer.setSingleShot(true);
|
||||||
timer.setInterval(duration);
|
timer.setInterval(duration);
|
||||||
@ -94,10 +91,9 @@ void QueuedTokenManager::loadTokens(const QList<QVariantHash> &_values)
|
|||||||
qCDebug(LOG_LIB) << "Set values from" << _values;
|
qCDebug(LOG_LIB) << "Set values from" << _values;
|
||||||
|
|
||||||
for (auto &token : _values) {
|
for (auto &token : _values) {
|
||||||
QDateTime validUntil = QDateTime::fromString(
|
QDateTime validUntil
|
||||||
token["validUntil"].toString(), Qt::ISODateWithMs);
|
= QDateTime::fromString(token["validUntil"].toString(), Qt::ISODateWithMs);
|
||||||
loadToken(
|
loadToken({token["token"].toString(), token["user"].toString(), validUntil});
|
||||||
{token["token"].toString(), token["user"].toString(), validUntil});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,13 +101,11 @@ void QueuedTokenManager::loadTokens(const QList<QVariantHash> &_values)
|
|||||||
/**
|
/**
|
||||||
* @fn registerToken
|
* @fn registerToken
|
||||||
*/
|
*/
|
||||||
QString QueuedTokenManager::registerToken(const QString &_user,
|
QString QueuedTokenManager::registerToken(const QString &_user, const QDateTime &_validUntil)
|
||||||
const QDateTime &_validUntil)
|
|
||||||
{
|
{
|
||||||
// generate from uuid
|
// generate from uuid
|
||||||
QString token = QUuid::createUuid().toString().remove('{').remove('}');
|
QString token = QUuid::createUuid().toString().remove('{').remove('}');
|
||||||
qCInfo(LOG_LIB) << "Registered token" << token << "valid until"
|
qCInfo(LOG_LIB) << "Registered token" << token << "valid until" << _validUntil;
|
||||||
<< _validUntil;
|
|
||||||
|
|
||||||
// append to internal storage
|
// append to internal storage
|
||||||
loadToken({token, _user, _validUntil});
|
loadToken({token, _user, _validUntil});
|
||||||
|
@ -36,8 +36,7 @@ extern "C" {
|
|||||||
/**
|
/**
|
||||||
* @fn QueuedUser
|
* @fn QueuedUser
|
||||||
*/
|
*/
|
||||||
QueuedUser::QueuedUser(QObject *_parent,
|
QueuedUser::QueuedUser(QObject *_parent, const QueuedUserDefinitions &definitions,
|
||||||
const QueuedUserDefinitions &definitions,
|
|
||||||
const long long index)
|
const long long index)
|
||||||
: QObject(_parent)
|
: QObject(_parent)
|
||||||
, m_definitions(definitions)
|
, m_definitions(definitions)
|
||||||
@ -61,14 +60,11 @@ QueuedUser::~QueuedUser()
|
|||||||
/**
|
/**
|
||||||
* @fn addPermissions
|
* @fn addPermissions
|
||||||
*/
|
*/
|
||||||
QueuedEnums::Permissions
|
QueuedEnums::Permissions QueuedUser::addPermission(const QueuedEnums::Permission _permission)
|
||||||
QueuedUser::addPermission(const QueuedEnums::Permission _permission)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add user permission" << static_cast<uint>(_permission);
|
qCDebug(LOG_LIB) << "Add user permission" << static_cast<uint>(_permission);
|
||||||
|
|
||||||
setPermissions(
|
setPermissions(static_cast<QueuedEnums::Permissions>(m_definitions.permissions) | _permission);
|
||||||
static_cast<QueuedEnums::Permissions>(m_definitions.permissions)
|
|
||||||
| _permission);
|
|
||||||
|
|
||||||
return static_cast<QueuedEnums::Permissions>(m_definitions.permissions);
|
return static_cast<QueuedEnums::Permissions>(m_definitions.permissions);
|
||||||
}
|
}
|
||||||
@ -77,11 +73,9 @@ QueuedUser::addPermission(const QueuedEnums::Permission _permission)
|
|||||||
/**
|
/**
|
||||||
* @fn hashFromPassword
|
* @fn hashFromPassword
|
||||||
*/
|
*/
|
||||||
QString QueuedUser::hashFromPassword(const QString &_password,
|
QString QueuedUser::hashFromPassword(const QString &_password, const QString &_salt)
|
||||||
const QString &_salt)
|
|
||||||
{
|
{
|
||||||
return QCryptographicHash::hash(_salt.toUtf8() + _password.toUtf8(),
|
return QCryptographicHash::hash(_salt.toUtf8() + _password.toUtf8(), QCryptographicHash::Sha512)
|
||||||
QCryptographicHash::Sha512)
|
|
||||||
.toHex();
|
.toHex();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,24 +115,19 @@ QPair<uint, uint> QueuedUser::ids()
|
|||||||
/**
|
/**
|
||||||
* @fn isPasswordValid
|
* @fn isPasswordValid
|
||||||
*/
|
*/
|
||||||
bool QueuedUser::isPasswordValid(const QString &_password,
|
bool QueuedUser::isPasswordValid(const QString &_password, const QString &_salt) const
|
||||||
const QString &_salt) const
|
|
||||||
{
|
{
|
||||||
return (m_definitions.password.toUtf8()
|
return (m_definitions.password.toUtf8() == hashFromPassword(_password, _salt));
|
||||||
== hashFromPassword(_password, _salt));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedEnums::Permissions
|
QueuedEnums::Permissions QueuedUser::removePermission(const QueuedEnums::Permission _permission)
|
||||||
QueuedUser::removePermission(const QueuedEnums::Permission _permission)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Remove user permission"
|
qCDebug(LOG_LIB) << "Remove user permission" << static_cast<uint>(_permission);
|
||||||
<< static_cast<uint>(_permission);
|
|
||||||
|
|
||||||
if (hasPermission(_permission))
|
if (hasPermission(_permission))
|
||||||
setPermissions(
|
setPermissions(static_cast<QueuedEnums::Permissions>(m_definitions.permissions)
|
||||||
static_cast<QueuedEnums::Permissions>(m_definitions.permissions)
|
^ _permission);
|
||||||
^ _permission);
|
|
||||||
|
|
||||||
return static_cast<QueuedEnums::Permissions>(m_definitions.permissions);
|
return static_cast<QueuedEnums::Permissions>(m_definitions.permissions);
|
||||||
}
|
}
|
||||||
|
@ -53,12 +53,12 @@ QueuedUserManager::~QueuedUserManager()
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn add
|
* @fn parseDefinitions
|
||||||
*/
|
*/
|
||||||
QueuedUser *QueuedUserManager::add(const QVariantHash &_properties,
|
QueuedUser::QueuedUserDefinitions
|
||||||
const long long _id)
|
QueuedUserManager::parseDefinitions(const QVariantHash &_properties)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add user" << _properties << "with ID" << _id;
|
qCDebug(LOG_LIB) << "Parse definitions from" << _properties;
|
||||||
|
|
||||||
QueuedUser::QueuedUserDefinitions defs;
|
QueuedUser::QueuedUserDefinitions defs;
|
||||||
defs.name = _properties["name"].toString();
|
defs.name = _properties["name"].toString();
|
||||||
@ -68,16 +68,26 @@ QueuedUser *QueuedUserManager::add(const QVariantHash &_properties,
|
|||||||
defs.priority = _properties["priority"].toUInt();
|
defs.priority = _properties["priority"].toUInt();
|
||||||
defs.limits = _properties["limits"].toString();
|
defs.limits = _properties["limits"].toString();
|
||||||
|
|
||||||
return add(defs, _id);
|
return defs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn add
|
* @fn add
|
||||||
*/
|
*/
|
||||||
QueuedUser *
|
QueuedUser *QueuedUserManager::add(const QVariantHash &_properties, const long long _id)
|
||||||
QueuedUserManager::add(const QueuedUser::QueuedUserDefinitions &_definitions,
|
{
|
||||||
const long long _id)
|
qCDebug(LOG_LIB) << "Add user" << _properties << "with ID" << _id;
|
||||||
|
|
||||||
|
return add(parseDefinitions(_properties), _id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn add
|
||||||
|
*/
|
||||||
|
QueuedUser *QueuedUserManager::add(const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
|
const long long _id)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Add user" << _definitions.name << "with ID" << _id;
|
qCDebug(LOG_LIB) << "Add user" << _definitions.name << "with ID" << _id;
|
||||||
|
|
||||||
@ -110,8 +120,7 @@ QString QueuedUserManager::authorize(const QString &_user)
|
|||||||
/**
|
/**
|
||||||
* @fn authorize
|
* @fn authorize
|
||||||
*/
|
*/
|
||||||
QString QueuedUserManager::authorize(const QString &_user,
|
QString QueuedUserManager::authorize(const QString &_user, const QString &_password)
|
||||||
const QString &_password)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Authorize user" << _user;
|
qCDebug(LOG_LIB) << "Authorize user" << _user;
|
||||||
|
|
||||||
@ -137,8 +146,7 @@ QString QueuedUserManager::authorize(const QString &_user,
|
|||||||
/**
|
/**
|
||||||
* @fn authorize
|
* @fn authorize
|
||||||
*/
|
*/
|
||||||
bool QueuedUserManager::authorize(const QString &_token,
|
bool QueuedUserManager::authorize(const QString &_token, const QueuedEnums::Permission _service)
|
||||||
const QueuedEnums::Permission _service)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Authorize user for" << static_cast<int>(_service);
|
qCDebug(LOG_LIB) << "Authorize user for" << static_cast<int>(_service);
|
||||||
|
|
||||||
@ -161,8 +169,7 @@ bool QueuedUserManager::authorize(const QString &_token,
|
|||||||
/**
|
/**
|
||||||
* @fn checkToken
|
* @fn checkToken
|
||||||
*/
|
*/
|
||||||
QDateTime QueuedUserManager::checkToken(const QString &_token,
|
QDateTime QueuedUserManager::checkToken(const QString &_token, bool *_valid) const
|
||||||
bool *_valid) const
|
|
||||||
{
|
{
|
||||||
if (_valid) {
|
if (_valid) {
|
||||||
QString user = m_tokens->isTokenValid(_token);
|
QString user = m_tokens->isTokenValid(_token);
|
||||||
|
@ -23,8 +23,7 @@
|
|||||||
#include "QueuedctlUser.h"
|
#include "QueuedctlUser.h"
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult QueuedctlAuth::auth(const QString &_user,
|
QueuedctlCommon::QueuedctlResult QueuedctlAuth::auth(const QString &_user, const QString &_cache)
|
||||||
const QString &_cache)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Auth as user" << _user;
|
qCDebug(LOG_APP) << "Auth as user" << _user;
|
||||||
|
|
||||||
@ -47,8 +46,7 @@ QueuedctlCommon::QueuedctlResult QueuedctlAuth::auth(const QString &_user,
|
|||||||
|
|
||||||
QString QueuedctlAuth::getToken(const QString &_cache, const QString &_user)
|
QString QueuedctlAuth::getToken(const QString &_cache, const QString &_user)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Get token using cache" << _cache << "and user"
|
qCDebug(LOG_APP) << "Get token using cache" << _cache << "and user" << _user;
|
||||||
<< _user;
|
|
||||||
|
|
||||||
QString tokenId = token(_user, _cache);
|
QString tokenId = token(_user, _cache);
|
||||||
if (tryAuth(tokenId)) {
|
if (tryAuth(tokenId)) {
|
||||||
@ -63,8 +61,7 @@ QString QueuedctlAuth::getToken(const QString &_cache, const QString &_user)
|
|||||||
void QueuedctlAuth::parser(QCommandLineParser &_parser) {}
|
void QueuedctlAuth::parser(QCommandLineParser &_parser) {}
|
||||||
|
|
||||||
|
|
||||||
void QueuedctlAuth::setToken(const QString &_token, const QString &_user,
|
void QueuedctlAuth::setToken(const QString &_token, const QString &_user, const QString &_cache)
|
||||||
const QString &_cache)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Save token to" << _cache << "from user" << _user;
|
qCDebug(LOG_APP) << "Save token to" << _cache << "from user" << _user;
|
||||||
|
|
||||||
|
@ -24,12 +24,10 @@
|
|||||||
|
|
||||||
namespace QueuedctlAuth
|
namespace QueuedctlAuth
|
||||||
{
|
{
|
||||||
QueuedctlCommon::QueuedctlResult auth(const QString &_user,
|
QueuedctlCommon::QueuedctlResult auth(const QString &_user, const QString &_cache);
|
||||||
const QString &_cache);
|
|
||||||
QString getToken(const QString &_cache, const QString &_user);
|
QString getToken(const QString &_cache, const QString &_user);
|
||||||
void parser(QCommandLineParser &_parser);
|
void parser(QCommandLineParser &_parser);
|
||||||
void setToken(const QString &_token, const QString &_user,
|
void setToken(const QString &_token, const QString &_user, const QString &_cache);
|
||||||
const QString &_cache);
|
|
||||||
QString token(const QString &_user, const QString &_cache);
|
QString token(const QString &_user, const QString &_cache);
|
||||||
bool tryAuth(const QString &_token);
|
bool tryAuth(const QString &_token);
|
||||||
};
|
};
|
||||||
|
@ -48,15 +48,13 @@ QString QueuedctlCommon::commandsHelp()
|
|||||||
commands.sort();
|
commands.sort();
|
||||||
for (auto &cmd : commands)
|
for (auto &cmd : commands)
|
||||||
// align like default help message
|
// align like default help message
|
||||||
cmdList += QString(" %1%2").arg(cmd, -21).arg(
|
cmdList += QString(" %1%2").arg(cmd, -21).arg(QueuedctlArguments[cmd].description);
|
||||||
QueuedctlArguments[cmd].description);
|
|
||||||
|
|
||||||
return cmdList.join('\n');
|
return cmdList.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString QueuedctlCommon::hashHashToString(
|
QString QueuedctlCommon::hashHashToString(const QHash<QString, QHash<QString, QString>> &_hash)
|
||||||
const QHash<QString, QHash<QString, QString>> &_hash)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Convert hash to string" << _hash;
|
qCDebug(LOG_APP) << "Convert hash to string" << _hash;
|
||||||
|
|
||||||
@ -84,8 +82,7 @@ QString QueuedctlCommon::hashToString(const QVariantHash &_hash)
|
|||||||
QStringList keys = _hash.keys();
|
QStringList keys = _hash.keys();
|
||||||
keys.sort();
|
keys.sort();
|
||||||
for (auto &key : keys)
|
for (auto &key : keys)
|
||||||
output += QString("%1: %2").arg(key).arg(
|
output += QString("%1: %2").arg(key).arg(_hash[key].toString().replace('\n', ' '));
|
||||||
_hash[key].toString().replace('\n', ' '));
|
|
||||||
|
|
||||||
return output.join('\n');
|
return output.join('\n');
|
||||||
}
|
}
|
||||||
@ -106,10 +103,9 @@ QString QueuedctlCommon::hashListToString(const QList<QVariantHash> &_list)
|
|||||||
// append rows
|
// append rows
|
||||||
for (auto &hash : _list) {
|
for (auto &hash : _list) {
|
||||||
QStringList row;
|
QStringList row;
|
||||||
std::for_each(header.cbegin(), header.cend(),
|
std::for_each(header.cbegin(), header.cend(), [&hash, &row](const QString &column) {
|
||||||
[&hash, &row](const QString &column) {
|
row += hash[column].toString().replace('\n', ' ');
|
||||||
row += hash[column].toString().replace('\n', ' ');
|
});
|
||||||
});
|
|
||||||
output += row.join(',');
|
output += row.join(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,18 +113,15 @@ QString QueuedctlCommon::hashListToString(const QList<QVariantHash> &_list)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void QueuedctlCommon::preprocess(const QStringList &_args,
|
void QueuedctlCommon::preprocess(const QStringList &_args, QCommandLineParser &_parser)
|
||||||
QCommandLineParser &_parser)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Preprocess command" << _args;
|
qCDebug(LOG_APP) << "Preprocess command" << _args;
|
||||||
|
|
||||||
QString command = _args.isEmpty() ? "" : _args.first();
|
QString command = _args.isEmpty() ? "" : _args.first();
|
||||||
// HACK: workaround to show valid help message
|
// HACK: workaround to show valid help message
|
||||||
auto id = QueuedctlArguments.contains(command)
|
auto id = QueuedctlArguments.contains(command) ? QueuedctlArguments[command].id
|
||||||
? QueuedctlArguments[command].id
|
: QueuedctlArgument::Invalid;
|
||||||
: QueuedctlArgument::Invalid;
|
_parser.addPositionalArgument(id == QueuedctlArgument::Invalid ? "command" : command,
|
||||||
_parser.addPositionalArgument(id == QueuedctlArgument::Invalid ? "command"
|
|
||||||
: command,
|
|
||||||
"Command to execute.");
|
"Command to execute.");
|
||||||
|
|
||||||
if (command.isEmpty())
|
if (command.isEmpty())
|
||||||
@ -206,8 +199,7 @@ void QueuedctlCommon::print(const QueuedctlResult &_result)
|
|||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult
|
||||||
QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache, const QString &_user)
|
||||||
const QString &_user)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Process command with args"
|
qCDebug(LOG_APP) << "Process command with args"
|
||||||
<< "using auth" << _cache << _user;
|
<< "using auth" << _cache << _user;
|
||||||
@ -216,14 +208,11 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
|||||||
QStringList args = _parser.positionalArguments();
|
QStringList args = _parser.positionalArguments();
|
||||||
QString command = args.isEmpty() ? "" : args.first();
|
QString command = args.isEmpty() ? "" : args.first();
|
||||||
|
|
||||||
auto id = QueuedctlArguments.contains(command)
|
auto id = QueuedctlArguments.contains(command) ? QueuedctlArguments[command].id
|
||||||
? QueuedctlArguments[command].id
|
: QueuedctlArgument::Invalid;
|
||||||
: QueuedctlArgument::Invalid;
|
|
||||||
checkArgs(args, QueuedctlArguments[command].positionalArgsCount, _parser);
|
checkArgs(args, QueuedctlArguments[command].positionalArgsCount, _parser);
|
||||||
|
|
||||||
QString token = (id == QueuedctlArgument::Auth)
|
QString token = (id == QueuedctlArgument::Auth) ? "" : QueuedctlAuth::getToken(_cache, _user);
|
||||||
? ""
|
|
||||||
: QueuedctlAuth::getToken(_cache, _user);
|
|
||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case QueuedctlArgument::Auth: {
|
case QueuedctlArgument::Auth: {
|
||||||
@ -241,10 +230,9 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
|||||||
case QueuedctlArgument::PermissionAdd: {
|
case QueuedctlArgument::PermissionAdd: {
|
||||||
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1), token);
|
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1), token);
|
||||||
long long userId = -1;
|
long long userId = -1;
|
||||||
userIdRes.match([&userId](const long long val) { userId = val; },
|
userIdRes.match(
|
||||||
[&result](const QueuedError &err) {
|
[&userId](const long long val) { userId = val; },
|
||||||
result.output = err.message().c_str();
|
[&result](const QueuedError &err) { result.output = err.message().c_str(); });
|
||||||
});
|
|
||||||
if (userId == -1)
|
if (userId == -1)
|
||||||
break;
|
break;
|
||||||
result = QueuedctlPermissions::addPermission(userId, args.at(2), token);
|
result = QueuedctlPermissions::addPermission(userId, args.at(2), token);
|
||||||
@ -253,14 +241,12 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
|||||||
case QueuedctlArgument::PermissionRemove: {
|
case QueuedctlArgument::PermissionRemove: {
|
||||||
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1), token);
|
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1), token);
|
||||||
long long userId = -1;
|
long long userId = -1;
|
||||||
userIdRes.match([&userId](const long long val) { userId = val; },
|
userIdRes.match(
|
||||||
[&result](const QueuedError &err) {
|
[&userId](const long long val) { userId = val; },
|
||||||
result.output = err.message().c_str();
|
[&result](const QueuedError &err) { result.output = err.message().c_str(); });
|
||||||
});
|
|
||||||
if (userId == -1)
|
if (userId == -1)
|
||||||
break;
|
break;
|
||||||
result
|
result = QueuedctlPermissions::removePermission(userId, args.at(2), token);
|
||||||
= QueuedctlPermissions::removePermission(userId, args.at(2), token);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::PluginAdd: {
|
case QueuedctlArgument::PluginAdd: {
|
||||||
@ -294,9 +280,7 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
|||||||
result.status = true;
|
result.status = true;
|
||||||
result.output = hashHashToString(val);
|
result.output = hashHashToString(val);
|
||||||
},
|
},
|
||||||
[&result](const QueuedError &err) {
|
[&result](const QueuedError &err) { result.output = err.message().c_str(); });
|
||||||
result.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::TaskAdd: {
|
case QueuedctlArgument::TaskAdd: {
|
||||||
@ -305,8 +289,7 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::TaskGet: {
|
case QueuedctlArgument::TaskGet: {
|
||||||
result = QueuedctlTask::getTask(args.at(1).toLongLong(), args.at(2),
|
result = QueuedctlTask::getTask(args.at(1).toLongLong(), args.at(2), token);
|
||||||
token);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::TaskList: {
|
case QueuedctlArgument::TaskList: {
|
||||||
@ -315,8 +298,7 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
|||||||
}
|
}
|
||||||
case QueuedctlArgument::TaskSet: {
|
case QueuedctlArgument::TaskSet: {
|
||||||
auto definitions = QueuedctlTask::getDefinitions(_parser, true, token);
|
auto definitions = QueuedctlTask::getDefinitions(_parser, true, token);
|
||||||
result = QueuedctlTask::setTask(args.at(1).toLongLong(), definitions,
|
result = QueuedctlTask::setTask(args.at(1).toLongLong(), definitions, token);
|
||||||
token);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QueuedctlArgument::TaskStart: {
|
case QueuedctlArgument::TaskStart: {
|
||||||
@ -335,10 +317,9 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
|||||||
case QueuedctlArgument::UserGet: {
|
case QueuedctlArgument::UserGet: {
|
||||||
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1), token);
|
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1), token);
|
||||||
long long userId = -1;
|
long long userId = -1;
|
||||||
userIdRes.match([&userId](const long long val) { userId = val; },
|
userIdRes.match(
|
||||||
[&result](const QueuedError &err) {
|
[&userId](const long long val) { userId = val; },
|
||||||
result.output = err.message().c_str();
|
[&result](const QueuedError &err) { result.output = err.message().c_str(); });
|
||||||
});
|
|
||||||
if (userId == -1)
|
if (userId == -1)
|
||||||
break;
|
break;
|
||||||
result = QueuedctlUser::getUser(userId, args.at(2), token);
|
result = QueuedctlUser::getUser(userId, args.at(2), token);
|
||||||
@ -351,10 +332,9 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
|||||||
case QueuedctlArgument::UserSet: {
|
case QueuedctlArgument::UserSet: {
|
||||||
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1), token);
|
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1), token);
|
||||||
long long userId = -1;
|
long long userId = -1;
|
||||||
userIdRes.match([&userId](const long long val) { userId = val; },
|
userIdRes.match(
|
||||||
[&result](const QueuedError &err) {
|
[&userId](const long long val) { userId = val; },
|
||||||
result.output = err.message().c_str();
|
[&result](const QueuedError &err) { result.output = err.message().c_str(); });
|
||||||
});
|
|
||||||
if (userId == -1)
|
if (userId == -1)
|
||||||
break;
|
break;
|
||||||
auto definitions = QueuedctlUser::getDefinitions(_parser, true);
|
auto definitions = QueuedctlUser::getDefinitions(_parser, true);
|
||||||
|
@ -57,46 +57,38 @@ typedef struct {
|
|||||||
QString description;
|
QString description;
|
||||||
int positionalArgsCount;
|
int positionalArgsCount;
|
||||||
} QueuedctlArgumentInfo;
|
} QueuedctlArgumentInfo;
|
||||||
const QHash<QString, QueuedctlArgumentInfo> QueuedctlArguments = {
|
const QHash<QString, QueuedctlArgumentInfo> QueuedctlArguments
|
||||||
{"auth", {QueuedctlArgument::Auth, "Gets new auth token.", 1}},
|
= {{"auth", {QueuedctlArgument::Auth, "Gets new auth token.", 1}},
|
||||||
{"option-get", {QueuedctlArgument::OptionGet, "Gets option value.", 2}},
|
{"option-get", {QueuedctlArgument::OptionGet, "Gets option value.", 2}},
|
||||||
{"option-set", {QueuedctlArgument::OptionSet, "Sets option value.", 3}},
|
{"option-set", {QueuedctlArgument::OptionSet, "Sets option value.", 3}},
|
||||||
{"perm-add",
|
{"perm-add", {QueuedctlArgument::PermissionAdd, "Sets user permission.", 3}},
|
||||||
{QueuedctlArgument::PermissionAdd, "Sets user permission.", 3}},
|
{"perm-remove", {QueuedctlArgument::PermissionRemove, "Removes user permission.", 3}},
|
||||||
{"perm-remove",
|
{"plugin", {QueuedctlArgument::PluginSpecification, "Get plugin description.", 2}},
|
||||||
{QueuedctlArgument::PermissionRemove, "Removes user permission.", 3}},
|
{"plugin-add", {QueuedctlArgument::PluginAdd, "Adds plugin to load.", 2}},
|
||||||
{"plugin",
|
{"plugin-list", {QueuedctlArgument::PluginList, "Shows enabled plugins.", 1}},
|
||||||
{QueuedctlArgument::PluginSpecification, "Get plugin description.", 2}},
|
{"plugin-options", {QueuedctlArgument::PluginOptions, "Get plugin options.", 2}},
|
||||||
{"plugin-add", {QueuedctlArgument::PluginAdd, "Adds plugin to load.", 2}},
|
{"plugin-remove", {QueuedctlArgument::PluginRemove, "Removes plugin to load.", 2}},
|
||||||
{"plugin-list",
|
{"report", {QueuedctlArgument::Report, "Shows usage report.", 1}},
|
||||||
{QueuedctlArgument::PluginList, "Shows enabled plugins.", 1}},
|
{"status", {QueuedctlArgument::Status, "Server status.", 1}},
|
||||||
{"plugin-options",
|
{"task-add", {QueuedctlArgument::TaskAdd, "Adds new task.", 2}},
|
||||||
{QueuedctlArgument::PluginOptions, "Get plugin options.", 2}},
|
{"task-get", {QueuedctlArgument::TaskGet, "Gets task properties.", 3}},
|
||||||
{"plugin-remove",
|
{"task-list", {QueuedctlArgument::TaskList, "Gets tasks list.", 1}},
|
||||||
{QueuedctlArgument::PluginRemove, "Removes plugin to load.", 2}},
|
{"task-set", {QueuedctlArgument::TaskSet, "Sets task properties.", 2}},
|
||||||
{"report", {QueuedctlArgument::Report, "Shows usage report.", 1}},
|
{"task-start", {QueuedctlArgument::TaskStart, "Starts task.", 2}},
|
||||||
{"status", {QueuedctlArgument::Status, "Server status.", 1}},
|
{"task-stop", {QueuedctlArgument::TaskStop, "Stops task.", 2}},
|
||||||
{"task-add", {QueuedctlArgument::TaskAdd, "Adds new task.", 2}},
|
{"user-add", {QueuedctlArgument::UserAdd, "Adds new user.", 2}},
|
||||||
{"task-get", {QueuedctlArgument::TaskGet, "Gets task properties.", 3}},
|
{"user-get", {QueuedctlArgument::UserGet, "Gets user properties.", 3}},
|
||||||
{"task-list", {QueuedctlArgument::TaskList, "Gets tasks list.", 1}},
|
{"user-list", {QueuedctlArgument::UserList, "Gets users list.", 1}},
|
||||||
{"task-set", {QueuedctlArgument::TaskSet, "Sets task properties.", 2}},
|
{"user-set", {QueuedctlArgument::UserSet, "Sets user properties.", 2}}};
|
||||||
{"task-start", {QueuedctlArgument::TaskStart, "Starts task.", 2}},
|
|
||||||
{"task-stop", {QueuedctlArgument::TaskStop, "Stops task.", 2}},
|
|
||||||
{"user-add", {QueuedctlArgument::UserAdd, "Adds new user.", 2}},
|
|
||||||
{"user-get", {QueuedctlArgument::UserGet, "Gets user properties.", 3}},
|
|
||||||
{"user-list", {QueuedctlArgument::UserList, "Gets users list.", 1}},
|
|
||||||
{"user-set", {QueuedctlArgument::UserSet, "Sets user properties.", 2}}};
|
|
||||||
// methods
|
// methods
|
||||||
void checkArgs(const QStringList &_args, const int _count,
|
void checkArgs(const QStringList &_args, const int _count, QCommandLineParser &_parser);
|
||||||
QCommandLineParser &_parser);
|
|
||||||
QString commandsHelp();
|
QString commandsHelp();
|
||||||
QString hashHashToString(const QHash<QString, QHash<QString, QString>> &_hash);
|
QString hashHashToString(const QHash<QString, QHash<QString, QString>> &_hash);
|
||||||
QString hashToString(const QVariantHash &_hash);
|
QString hashToString(const QVariantHash &_hash);
|
||||||
QString hashListToString(const QList<QVariantHash> &_list);
|
QString hashListToString(const QList<QVariantHash> &_list);
|
||||||
void preprocess(const QStringList &_args, QCommandLineParser &_parser);
|
void preprocess(const QStringList &_args, QCommandLineParser &_parser);
|
||||||
void print(const QueuedctlResult &_result);
|
void print(const QueuedctlResult &_result);
|
||||||
QueuedctlResult process(QCommandLineParser &_parser, const QString &_cache,
|
QueuedctlResult process(QCommandLineParser &_parser, const QString &_cache, const QString &_user);
|
||||||
const QString &_user);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,24 +21,21 @@
|
|||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult
|
||||||
QueuedctlOption::editOption(const QString &_option, const QVariant &_value,
|
QueuedctlOption::editOption(const QString &_option, const QVariant &_value, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Edit option" << _option << "to" << _value;
|
qCDebug(LOG_APP) << "Edit option" << _option << "to" << _value;
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult output;
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
auto res = QueuedCoreAdaptor::sendOptionEdit(_option, _value, _token);
|
auto res = QueuedCoreAdaptor::sendOptionEdit(_option, _value, _token);
|
||||||
res.match([&output](const bool val) { output.status = val; },
|
res.match([&output](const bool val) { output.status = val; },
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult QueuedctlOption::getOption(const QString &_option,
|
||||||
QueuedctlOption::getOption(const QString &_option, const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Get option" << _option;
|
qCDebug(LOG_APP) << "Get option" << _option;
|
||||||
|
|
||||||
@ -49,9 +46,7 @@ QueuedctlOption::getOption(const QString &_option, const QString &_token)
|
|||||||
output.status = val.isValid();
|
output.status = val.isValid();
|
||||||
output.output = QString("%1: %2").arg(_option, val.toString());
|
output.output = QString("%1: %2").arg(_option, val.toString());
|
||||||
},
|
},
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,9 @@
|
|||||||
|
|
||||||
namespace QueuedctlOption
|
namespace QueuedctlOption
|
||||||
{
|
{
|
||||||
QueuedctlCommon::QueuedctlResult editOption(const QString &_option,
|
QueuedctlCommon::QueuedctlResult editOption(const QString &_option, const QVariant &_value,
|
||||||
const QVariant &_value,
|
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
QueuedctlCommon::QueuedctlResult getOption(const QString &_option,
|
QueuedctlCommon::QueuedctlResult getOption(const QString &_option, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
void parserGet(QCommandLineParser &_parser);
|
void parserGet(QCommandLineParser &_parser);
|
||||||
void parserSet(QCommandLineParser &_parser);
|
void parserSet(QCommandLineParser &_parser);
|
||||||
};
|
};
|
||||||
|
@ -20,8 +20,9 @@
|
|||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult QueuedctlPermissions::addPermission(
|
QueuedctlCommon::QueuedctlResult QueuedctlPermissions::addPermission(const long long _id,
|
||||||
const long long _id, const QString &_permission, const QString &_token)
|
const QString &_permission,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Add permission" << _permission << "to" << _id;
|
qCDebug(LOG_APP) << "Add permission" << _permission << "to" << _id;
|
||||||
|
|
||||||
@ -31,20 +32,18 @@ QueuedctlCommon::QueuedctlResult QueuedctlPermissions::addPermission(
|
|||||||
if (permission == QueuedEnums::Permission::Invalid) {
|
if (permission == QueuedEnums::Permission::Invalid) {
|
||||||
output.output = "Invalid permission";
|
output.output = "Invalid permission";
|
||||||
} else {
|
} else {
|
||||||
auto res
|
auto res = QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission, _token);
|
||||||
= QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission, _token);
|
|
||||||
res.match([&output](const bool val) { output.status = val; },
|
res.match([&output](const bool val) { output.status = val; },
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult QueuedctlPermissions::removePermission(
|
QueuedctlCommon::QueuedctlResult QueuedctlPermissions::removePermission(const long long _id,
|
||||||
const long long _id, const QString &_permission, const QString &_token)
|
const QString &_permission,
|
||||||
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Remove permission" << _permission << "to" << _id;
|
qCDebug(LOG_APP) << "Remove permission" << _permission << "to" << _id;
|
||||||
|
|
||||||
@ -54,12 +53,9 @@ QueuedctlCommon::QueuedctlResult QueuedctlPermissions::removePermission(
|
|||||||
if (permission == QueuedEnums::Permission::Invalid) {
|
if (permission == QueuedEnums::Permission::Invalid) {
|
||||||
output.output = "Invalid permission";
|
output.output = "Invalid permission";
|
||||||
} else {
|
} else {
|
||||||
auto res = QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission,
|
auto res = QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission, _token);
|
||||||
_token);
|
|
||||||
res.match([&output](const bool val) { output.status = val; },
|
res.match([&output](const bool val) { output.status = val; },
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
@ -69,6 +65,5 @@ QueuedctlCommon::QueuedctlResult QueuedctlPermissions::removePermission(
|
|||||||
void QueuedctlPermissions::parser(QCommandLineParser &_parser)
|
void QueuedctlPermissions::parser(QCommandLineParser &_parser)
|
||||||
{
|
{
|
||||||
_parser.addPositionalArgument("user", "User ID.", "<user>");
|
_parser.addPositionalArgument("user", "User ID.", "<user>");
|
||||||
_parser.addPositionalArgument("permission", "Permission name.",
|
_parser.addPositionalArgument("permission", "Permission name.", "<permission>");
|
||||||
"<permission>");
|
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,9 @@
|
|||||||
|
|
||||||
namespace QueuedctlPermissions
|
namespace QueuedctlPermissions
|
||||||
{
|
{
|
||||||
QueuedctlCommon::QueuedctlResult addPermission(const long long _id,
|
QueuedctlCommon::QueuedctlResult addPermission(const long long _id, const QString &_permission,
|
||||||
const QString &_permission,
|
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
QueuedctlCommon::QueuedctlResult removePermission(const long long _id,
|
QueuedctlCommon::QueuedctlResult removePermission(const long long _id, const QString &_permission,
|
||||||
const QString &_permission,
|
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
void parser(QCommandLineParser &_parser);
|
void parser(QCommandLineParser &_parser);
|
||||||
};
|
};
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
#include <queued/Queued.h>
|
#include <queued/Queued.h>
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::addPlugin(const QString &_plugin,
|
||||||
QueuedctlPlugins::addPlugin(const QString &_plugin, const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Add plugin" << _plugin;
|
qCDebug(LOG_APP) << "Add plugin" << _plugin;
|
||||||
|
|
||||||
@ -29,16 +29,14 @@ QueuedctlPlugins::addPlugin(const QString &_plugin, const QString &_token)
|
|||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult output;
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
res.match([&output](const bool val) { output.status = val; },
|
res.match([&output](const bool val) { output.status = val; },
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::getPlugin(const QString &_plugin,
|
||||||
QueuedctlPlugins::getPlugin(const QString &_plugin, const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Get plugin" << _plugin;
|
qCDebug(LOG_APP) << "Get plugin" << _plugin;
|
||||||
|
|
||||||
@ -57,24 +55,20 @@ QueuedctlPlugins::getPlugin(const QString &_plugin, const QString &_token)
|
|||||||
text += QString(" %1").arg(opt.name);
|
text += QString(" %1").arg(opt.name);
|
||||||
text += QString(" description: %1").arg(opt.description);
|
text += QString(" description: %1").arg(opt.description);
|
||||||
text += QString(" type: %1").arg(opt.type);
|
text += QString(" type: %1").arg(opt.type);
|
||||||
text += QString(" default: %1")
|
text += QString(" default: %1").arg(opt.defaultValue.toString());
|
||||||
.arg(opt.defaultValue.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
output.status = true;
|
output.status = true;
|
||||||
output.output = text.join('\n');
|
output.output = text.join('\n');
|
||||||
},
|
},
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::getPluginOptions(const QString &_plugin,
|
||||||
QueuedctlPlugins::getPluginOptions(const QString &_plugin,
|
const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Get plugin options" << _plugin;
|
qCDebug(LOG_APP) << "Get plugin options" << _plugin;
|
||||||
|
|
||||||
@ -86,9 +80,7 @@ QueuedctlPlugins::getPluginOptions(const QString &_plugin,
|
|||||||
output.status = true;
|
output.status = true;
|
||||||
output.output = QueuedctlCommon::hashToString(val);
|
output.output = QueuedctlCommon::hashToString(val);
|
||||||
},
|
},
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -96,8 +88,7 @@ QueuedctlPlugins::getPluginOptions(const QString &_plugin,
|
|||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::listPlugins()
|
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::listPlugins()
|
||||||
{
|
{
|
||||||
auto res = QueuedCoreAdaptor::getOption(
|
auto res = QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::Plugins, "");
|
||||||
QueuedConfig::QueuedSettings::Plugins, "");
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult output;
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
res.match(
|
res.match(
|
||||||
@ -105,16 +96,14 @@ QueuedctlCommon::QueuedctlResult QueuedctlPlugins::listPlugins()
|
|||||||
output.status = val.isValid();
|
output.status = val.isValid();
|
||||||
output.output = val.toString();
|
output.output = val.toString();
|
||||||
},
|
},
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::removePlugin(const QString &_plugin,
|
||||||
QueuedctlPlugins::removePlugin(const QString &_plugin, const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Remove plugin" << _plugin;
|
qCDebug(LOG_APP) << "Remove plugin" << _plugin;
|
||||||
|
|
||||||
@ -122,9 +111,7 @@ QueuedctlPlugins::removePlugin(const QString &_plugin, const QString &_token)
|
|||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult output;
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
res.match([&output](const bool val) { output.status = val; },
|
res.match([&output](const bool val) { output.status = val; },
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -24,15 +24,11 @@
|
|||||||
|
|
||||||
namespace QueuedctlPlugins
|
namespace QueuedctlPlugins
|
||||||
{
|
{
|
||||||
QueuedctlCommon::QueuedctlResult addPlugin(const QString &_plugin,
|
QueuedctlCommon::QueuedctlResult addPlugin(const QString &_plugin, const QString &_token);
|
||||||
const QString &_token);
|
QueuedctlCommon::QueuedctlResult getPlugin(const QString &_plugin, const QString &_token);
|
||||||
QueuedctlCommon::QueuedctlResult getPlugin(const QString &_plugin,
|
QueuedctlCommon::QueuedctlResult getPluginOptions(const QString &_plugin, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
QueuedctlCommon::QueuedctlResult getPluginOptions(const QString &_plugin,
|
|
||||||
const QString &_token);
|
|
||||||
QueuedctlCommon::QueuedctlResult listPlugins();
|
QueuedctlCommon::QueuedctlResult listPlugins();
|
||||||
QueuedctlCommon::QueuedctlResult removePlugin(const QString &_plugin,
|
QueuedctlCommon::QueuedctlResult removePlugin(const QString &_plugin, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
void parser(QCommandLineParser &_parser);
|
void parser(QCommandLineParser &_parser);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,9 +26,9 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult QueuedctlTask::addTask(
|
QueuedctlCommon::QueuedctlResult
|
||||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
QueuedctlTask::addTask(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Add task" << _definitions.command;
|
qCDebug(LOG_APP) << "Add task" << _definitions.command;
|
||||||
|
|
||||||
@ -40,25 +40,21 @@ QueuedctlCommon::QueuedctlResult QueuedctlTask::addTask(
|
|||||||
output.status = (val > 0);
|
output.status = (val > 0);
|
||||||
output.output = QString::number(val);
|
output.output = QString::number(val);
|
||||||
},
|
},
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedProcess::QueuedProcessDefinitions
|
QueuedProcess::QueuedProcessDefinitions
|
||||||
QueuedctlTask::getDefinitions(const QCommandLineParser &_parser,
|
QueuedctlTask::getDefinitions(const QCommandLineParser &_parser, const bool _expandAll,
|
||||||
const bool _expandAll, const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Parse task definitions from parser, expand all"
|
qCDebug(LOG_APP) << "Parse task definitions from parser, expand all" << _expandAll;
|
||||||
<< _expandAll;
|
|
||||||
|
|
||||||
QueuedProcess::QueuedProcessDefinitions definitions;
|
QueuedProcess::QueuedProcessDefinitions definitions;
|
||||||
|
|
||||||
std::for_each(_parser.values("argument").cbegin(),
|
std::for_each(_parser.values("argument").cbegin(), _parser.values("argument").cend(),
|
||||||
_parser.values("argument").cend(),
|
|
||||||
[&definitions](const QString &arg) {
|
[&definitions](const QString &arg) {
|
||||||
if (!arg.isEmpty())
|
if (!arg.isEmpty())
|
||||||
definitions.arguments += arg;
|
definitions.arguments += arg;
|
||||||
@ -68,37 +64,29 @@ QueuedctlTask::getDefinitions(const QCommandLineParser &_parser,
|
|||||||
if (_parser.value("task-user").isEmpty()) {
|
if (_parser.value("task-user").isEmpty()) {
|
||||||
definitions.user = 0;
|
definitions.user = 0;
|
||||||
} else {
|
} else {
|
||||||
auto res
|
auto res = QueuedCoreAdaptor::getUserId(_parser.value("task-user"), _token);
|
||||||
= QueuedCoreAdaptor::getUserId(_parser.value("task-user"), _token);
|
res.match([&definitions](const long long val) { definitions.user = val; },
|
||||||
res.match(
|
[&definitions](const QueuedError &) { definitions.user = 0; });
|
||||||
[&definitions](const long long val) { definitions.user = val; },
|
|
||||||
[&definitions](const QueuedError &) { definitions.user = 0; });
|
|
||||||
}
|
}
|
||||||
definitions.workingDirectory
|
definitions.workingDirectory = QFileInfo(_parser.value("directory")).absoluteFilePath();
|
||||||
= QFileInfo(_parser.value("directory")).absoluteFilePath();
|
|
||||||
// limits now
|
// limits now
|
||||||
QueuedLimits::Limits limits(
|
QueuedLimits::Limits limits(_parser.value("limit-cpu").toLongLong(),
|
||||||
_parser.value("limit-cpu").toLongLong(),
|
_parser.value("limit-gpu").toLongLong(),
|
||||||
_parser.value("limit-gpu").toLongLong(),
|
QueuedLimits::convertMemory(_parser.value("limit-memory")),
|
||||||
QueuedLimits::convertMemory(_parser.value("limit-memory")),
|
QueuedLimits::convertMemory(_parser.value("limit-gpumemory")),
|
||||||
QueuedLimits::convertMemory(_parser.value("limit-gpumemory")),
|
QueuedLimits::convertMemory(_parser.value("limit-storage")));
|
||||||
QueuedLimits::convertMemory(_parser.value("limit-storage")));
|
|
||||||
definitions.limits = limits.toString();
|
definitions.limits = limits.toString();
|
||||||
|
|
||||||
// all options
|
// all options
|
||||||
if (_expandAll) {
|
if (_expandAll) {
|
||||||
definitions.command
|
definitions.command = QFileInfo(_parser.value("program")).absoluteFilePath();
|
||||||
= QFileInfo(_parser.value("program")).absoluteFilePath();
|
definitions.endTime = QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
||||||
definitions.endTime
|
|
||||||
= QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
|
||||||
definitions.gid = _parser.value("gid").toUInt();
|
definitions.gid = _parser.value("gid").toUInt();
|
||||||
definitions.startTime
|
definitions.startTime = QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
||||||
= QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
|
||||||
definitions.uid = _parser.value("uid").toUInt();
|
definitions.uid = _parser.value("uid").toUInt();
|
||||||
} else {
|
} else {
|
||||||
// queuedctl -- task-add /path/to/application
|
// queuedctl -- task-add /path/to/application
|
||||||
definitions.command
|
definitions.command = QFileInfo(_parser.positionalArguments().at(1)).absoluteFilePath();
|
||||||
= QFileInfo(_parser.positionalArguments().at(1)).absoluteFilePath();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return definitions;
|
return definitions;
|
||||||
@ -106,8 +94,7 @@ QueuedctlTask::getDefinitions(const QCommandLineParser &_parser,
|
|||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult
|
||||||
QueuedctlTask::getTask(const long long _id, const QString &_property,
|
QueuedctlTask::getTask(const long long _id, const QString &_property, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Get property" << _property << "from task" << _id;
|
qCDebug(LOG_APP) << "Get property" << _property << "from task" << _id;
|
||||||
|
|
||||||
@ -120,9 +107,7 @@ QueuedctlTask::getTask(const long long _id, const QString &_property,
|
|||||||
output.status = true;
|
output.status = true;
|
||||||
output.output = QueuedctlCommon::hashToString(val);
|
output.output = QueuedctlCommon::hashToString(val);
|
||||||
},
|
},
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
auto res = QueuedCoreAdaptor::getTask(_id, _property);
|
auto res = QueuedCoreAdaptor::getTask(_id, _property);
|
||||||
res.match(
|
res.match(
|
||||||
@ -130,30 +115,24 @@ QueuedctlTask::getTask(const long long _id, const QString &_property,
|
|||||||
output.status = val.isValid();
|
output.status = val.isValid();
|
||||||
output.output = val.toString();
|
output.output = val.toString();
|
||||||
},
|
},
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult QueuedctlTask::getTasks(const QCommandLineParser &_parser,
|
||||||
QueuedctlTask::getTasks(const QCommandLineParser &_parser,
|
const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
long long userId = -1;
|
long long userId = -1;
|
||||||
if (!_parser.value("task-user").isEmpty()) {
|
if (!_parser.value("task-user").isEmpty()) {
|
||||||
auto res
|
auto res = QueuedCoreAdaptor::getUserId(_parser.value("task-user"), _token);
|
||||||
= QueuedCoreAdaptor::getUserId(_parser.value("task-user"), _token);
|
|
||||||
res.match([&userId](const long long val) { userId = val; },
|
res.match([&userId](const long long val) { userId = val; },
|
||||||
[&userId](const QueuedError &) {});
|
[&userId](const QueuedError &) {});
|
||||||
}
|
}
|
||||||
QDateTime stop
|
QDateTime stop = QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
||||||
= QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
QDateTime start = QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
||||||
QDateTime start
|
|
||||||
= QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult output;
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
|
|
||||||
@ -163,9 +142,7 @@ QueuedctlTask::getTasks(const QCommandLineParser &_parser,
|
|||||||
output.status = true;
|
output.status = true;
|
||||||
output.output = QueuedctlCommon::hashListToString(val);
|
output.output = QueuedctlCommon::hashListToString(val);
|
||||||
},
|
},
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -176,40 +153,33 @@ void QueuedctlTask::parserAdd(QCommandLineParser &_parser)
|
|||||||
_parser.addPositionalArgument("program", "Command line.", "<program>");
|
_parser.addPositionalArgument("program", "Command line.", "<program>");
|
||||||
|
|
||||||
// command line arguments
|
// command line arguments
|
||||||
QCommandLineOption argumentOption({"a", "argument"},
|
QCommandLineOption argumentOption({"a", "argument"}, "Command line argument.", "argument", "");
|
||||||
"Command line argument.", "argument", "");
|
|
||||||
_parser.addOption(argumentOption);
|
_parser.addOption(argumentOption);
|
||||||
// working directory
|
// working directory
|
||||||
QCommandLineOption directoryOption("directory",
|
QCommandLineOption directoryOption("directory", "Command working directory.", "directory",
|
||||||
"Command working directory.",
|
QDir::currentPath());
|
||||||
"directory", QDir::currentPath());
|
|
||||||
_parser.addOption(directoryOption);
|
_parser.addOption(directoryOption);
|
||||||
// user
|
// user
|
||||||
QCommandLineOption userOption("task-user", "Task user.", "task-user",
|
QCommandLineOption userOption("task-user", "Task user.", "task-user", ::getlogin());
|
||||||
::getlogin());
|
|
||||||
_parser.addOption(userOption);
|
_parser.addOption(userOption);
|
||||||
// nice
|
// nice
|
||||||
QCommandLineOption niceOption("nice", "Task nice level.", "nice", "0");
|
QCommandLineOption niceOption("nice", "Task nice level.", "nice", "0");
|
||||||
_parser.addOption(niceOption);
|
_parser.addOption(niceOption);
|
||||||
// cpu limit
|
// cpu limit
|
||||||
QCommandLineOption cpuOption("limit-cpu", "Task CPU limit.", "limit-cpu",
|
QCommandLineOption cpuOption("limit-cpu", "Task CPU limit.", "limit-cpu", "0");
|
||||||
"0");
|
|
||||||
_parser.addOption(cpuOption);
|
_parser.addOption(cpuOption);
|
||||||
// gpu limit
|
// gpu limit
|
||||||
QCommandLineOption gpuOption("limit-gpu", "Task GPU limit.", "limit-gpu",
|
QCommandLineOption gpuOption("limit-gpu", "Task GPU limit.", "limit-gpu", "0");
|
||||||
"0");
|
|
||||||
_parser.addOption(gpuOption);
|
_parser.addOption(gpuOption);
|
||||||
// memory limit
|
// memory limit
|
||||||
QCommandLineOption memoryOption("limit-memory", "Task memory limit.",
|
QCommandLineOption memoryOption("limit-memory", "Task memory limit.", "limit-memory", "0");
|
||||||
"limit-memory", "0");
|
|
||||||
_parser.addOption(memoryOption);
|
_parser.addOption(memoryOption);
|
||||||
// gpu memory limit
|
// gpu memory limit
|
||||||
QCommandLineOption gpumemoryOption(
|
QCommandLineOption gpumemoryOption("limit-gpumemory", "Task GPU memory limit.",
|
||||||
"limit-gpumemory", "Task GPU memory limit.", "limit-gpumemory", "0");
|
"limit-gpumemory", "0");
|
||||||
_parser.addOption(gpumemoryOption);
|
_parser.addOption(gpumemoryOption);
|
||||||
// storage limit
|
// storage limit
|
||||||
QCommandLineOption storageOption("limit-storage", "Task storage limit.",
|
QCommandLineOption storageOption("limit-storage", "Task storage limit.", "limit-storage", "0");
|
||||||
"limit-storage", "0");
|
|
||||||
_parser.addOption(storageOption);
|
_parser.addOption(storageOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,8 +187,7 @@ void QueuedctlTask::parserAdd(QCommandLineParser &_parser)
|
|||||||
void QueuedctlTask::parserGet(QCommandLineParser &_parser)
|
void QueuedctlTask::parserGet(QCommandLineParser &_parser)
|
||||||
{
|
{
|
||||||
_parser.addPositionalArgument("id", "Task ID.", "<id>");
|
_parser.addPositionalArgument("id", "Task ID.", "<id>");
|
||||||
_parser.addPositionalArgument("property", "Task property name.",
|
_parser.addPositionalArgument("property", "Task property name.", "<property>");
|
||||||
"<property>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -241,16 +210,13 @@ void QueuedctlTask::parserSet(QCommandLineParser &_parser)
|
|||||||
_parser.addPositionalArgument("id", "Task ID.", "<id>");
|
_parser.addPositionalArgument("id", "Task ID.", "<id>");
|
||||||
|
|
||||||
// command line
|
// command line
|
||||||
QCommandLineOption commandOption({"p", "program"}, "Command line.",
|
QCommandLineOption commandOption({"p", "program"}, "Command line.", "program", "");
|
||||||
"program", "");
|
|
||||||
_parser.addOption(commandOption);
|
_parser.addOption(commandOption);
|
||||||
// command line arguments
|
// command line arguments
|
||||||
QCommandLineOption argumentOption({"a", "argument"},
|
QCommandLineOption argumentOption({"a", "argument"}, "Command line argument.", "argument", "");
|
||||||
"Command line argument.", "argument", "");
|
|
||||||
_parser.addOption(argumentOption);
|
_parser.addOption(argumentOption);
|
||||||
// working directory
|
// working directory
|
||||||
QCommandLineOption directoryOption(
|
QCommandLineOption directoryOption("directory", "Command working directory.", "directory", "");
|
||||||
"directory", "Command working directory.", "directory", "");
|
|
||||||
_parser.addOption(directoryOption);
|
_parser.addOption(directoryOption);
|
||||||
// user
|
// user
|
||||||
QCommandLineOption userOption("task-user", "Task user.", "task-user", "");
|
QCommandLineOption userOption("task-user", "Task user.", "task-user", "");
|
||||||
@ -271,24 +237,20 @@ void QueuedctlTask::parserSet(QCommandLineParser &_parser)
|
|||||||
QCommandLineOption stopOption("stop", "Task stop time.", "stop", "");
|
QCommandLineOption stopOption("stop", "Task stop time.", "stop", "");
|
||||||
_parser.addOption(stopOption);
|
_parser.addOption(stopOption);
|
||||||
// cpu limit
|
// cpu limit
|
||||||
QCommandLineOption cpuOption("limit-cpu", "Task CPU limit.", "limit-cpu",
|
QCommandLineOption cpuOption("limit-cpu", "Task CPU limit.", "limit-cpu", "-1");
|
||||||
"-1");
|
|
||||||
_parser.addOption(cpuOption);
|
_parser.addOption(cpuOption);
|
||||||
// gpu limit
|
// gpu limit
|
||||||
QCommandLineOption gpuOption("limit-gpu", "Task GPU limit.", "limit-gpu",
|
QCommandLineOption gpuOption("limit-gpu", "Task GPU limit.", "limit-gpu", "-1");
|
||||||
"-1");
|
|
||||||
_parser.addOption(gpuOption);
|
_parser.addOption(gpuOption);
|
||||||
// memory limit
|
// memory limit
|
||||||
QCommandLineOption memoryOption("limit-memory", "Task memory limit.",
|
QCommandLineOption memoryOption("limit-memory", "Task memory limit.", "limit-memory", "-1");
|
||||||
"limit-memory", "-1");
|
|
||||||
_parser.addOption(memoryOption);
|
_parser.addOption(memoryOption);
|
||||||
// gpu memory limit
|
// gpu memory limit
|
||||||
QCommandLineOption gpumemoryOption(
|
QCommandLineOption gpumemoryOption("limit-gpumemory", "Task GPU memory limit.",
|
||||||
"limit-gpumemory", "Task GPU memory limit.", "limit-gpumemory", "-1");
|
"limit-gpumemory", "-1");
|
||||||
_parser.addOption(gpumemoryOption);
|
_parser.addOption(gpumemoryOption);
|
||||||
// storage limit
|
// storage limit
|
||||||
QCommandLineOption storageOption("limit-storage", "Task storage limit.",
|
QCommandLineOption storageOption("limit-storage", "Task storage limit.", "limit-storage", "-1");
|
||||||
"limit-storage", "-1");
|
|
||||||
_parser.addOption(storageOption);
|
_parser.addOption(storageOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -299,10 +261,10 @@ void QueuedctlTask::parserStart(QCommandLineParser &_parser)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult QueuedctlTask::setTask(
|
QueuedctlCommon::QueuedctlResult
|
||||||
const long long _id,
|
QueuedctlTask::setTask(const long long _id,
|
||||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Edit task" << _id;
|
qCDebug(LOG_APP) << "Edit task" << _id;
|
||||||
|
|
||||||
@ -310,9 +272,7 @@ QueuedctlCommon::QueuedctlResult QueuedctlTask::setTask(
|
|||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult output;
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
res.match([&output](const bool val) { output.status = val; },
|
res.match([&output](const bool val) { output.status = val; },
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -327,16 +287,13 @@ QueuedctlCommon::QueuedctlResult QueuedctlTask::startTask(const long long _id,
|
|||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult output;
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
res.match([&output](const bool val) { output.status = val; },
|
res.match([&output](const bool val) { output.status = val; },
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult QueuedctlTask::stopTask(const long long _id,
|
QueuedctlCommon::QueuedctlResult QueuedctlTask::stopTask(const long long _id, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Stop task" << _id;
|
qCDebug(LOG_APP) << "Stop task" << _id;
|
||||||
|
|
||||||
@ -344,9 +301,7 @@ QueuedctlCommon::QueuedctlResult QueuedctlTask::stopTask(const long long _id,
|
|||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult output;
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
res.match([&output](const bool val) { output.status = val; },
|
res.match([&output](const bool val) { output.status = val; },
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -27,28 +27,22 @@
|
|||||||
namespace QueuedctlTask
|
namespace QueuedctlTask
|
||||||
{
|
{
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult
|
||||||
addTask(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
addTask(const QueuedProcess::QueuedProcessDefinitions &_definitions, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
QueuedProcess::QueuedProcessDefinitions
|
QueuedProcess::QueuedProcessDefinitions
|
||||||
getDefinitions(const QCommandLineParser &_parser, const bool _expandAll,
|
getDefinitions(const QCommandLineParser &_parser, const bool _expandAll, const QString &_token);
|
||||||
const QString &_token);
|
QueuedctlCommon::QueuedctlResult getTask(const long long _id, const QString &_property,
|
||||||
QueuedctlCommon::QueuedctlResult
|
const QString &_token);
|
||||||
getTask(const long long _id, const QString &_property, const QString &_token);
|
QueuedctlCommon::QueuedctlResult getTasks(const QCommandLineParser &_parser, const QString &_token);
|
||||||
QueuedctlCommon::QueuedctlResult getTasks(const QCommandLineParser &_parser,
|
|
||||||
const QString &_token);
|
|
||||||
void parserAdd(QCommandLineParser &_parser);
|
void parserAdd(QCommandLineParser &_parser);
|
||||||
void parserGet(QCommandLineParser &_parser);
|
void parserGet(QCommandLineParser &_parser);
|
||||||
void parserList(QCommandLineParser &_parser);
|
void parserList(QCommandLineParser &_parser);
|
||||||
void parserSet(QCommandLineParser &_parser);
|
void parserSet(QCommandLineParser &_parser);
|
||||||
void parserStart(QCommandLineParser &_parser);
|
void parserStart(QCommandLineParser &_parser);
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult
|
||||||
setTask(const long long _id,
|
setTask(const long long _id, const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
QueuedctlCommon::QueuedctlResult startTask(const long long _id,
|
QueuedctlCommon::QueuedctlResult startTask(const long long _id, const QString &_token);
|
||||||
const QString &_token);
|
QueuedctlCommon::QueuedctlResult stopTask(const long long _id, const QString &_token);
|
||||||
QueuedctlCommon::QueuedctlResult stopTask(const long long _id,
|
|
||||||
const QString &_token);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,8 +29,7 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult
|
||||||
QueuedctlUser::addUser(const QueuedUser::QueuedUserDefinitions &_definitions,
|
QueuedctlUser::addUser(const QueuedUser::QueuedUserDefinitions &_definitions, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Add user" << _definitions.name;
|
qCDebug(LOG_APP) << "Add user" << _definitions.name;
|
||||||
|
|
||||||
@ -42,24 +41,19 @@ QueuedctlUser::addUser(const QueuedUser::QueuedUserDefinitions &_definitions,
|
|||||||
output.status = (val > 0);
|
output.status = (val > 0);
|
||||||
output.output = QString::number(val);
|
output.output = QString::number(val);
|
||||||
},
|
},
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult QueuedctlUser::getReport(const QCommandLineParser &_parser,
|
||||||
QueuedctlUser::getReport(const QCommandLineParser &_parser,
|
const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Get usage report";
|
qCDebug(LOG_APP) << "Get usage report";
|
||||||
|
|
||||||
QDateTime stop
|
QDateTime stop = QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
||||||
= QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
QDateTime start = QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
||||||
QDateTime start
|
|
||||||
= QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
|
||||||
|
|
||||||
auto res = QueuedCoreAdaptor::getPerformance(start, stop, _token);
|
auto res = QueuedCoreAdaptor::getPerformance(start, stop, _token);
|
||||||
|
|
||||||
@ -69,41 +63,34 @@ QueuedctlUser::getReport(const QCommandLineParser &_parser,
|
|||||||
output.status = true;
|
output.status = true;
|
||||||
output.output = QueuedctlCommon::hashListToString(val);
|
output.output = QueuedctlCommon::hashListToString(val);
|
||||||
},
|
},
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedUser::QueuedUserDefinitions
|
QueuedUser::QueuedUserDefinitions QueuedctlUser::getDefinitions(const QCommandLineParser &_parser,
|
||||||
QueuedctlUser::getDefinitions(const QCommandLineParser &_parser,
|
const bool _expandAll)
|
||||||
const bool _expandAll)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Parse user definitions from parser, expand all"
|
qCDebug(LOG_APP) << "Parse user definitions from parser, expand all" << _expandAll;
|
||||||
<< _expandAll;
|
|
||||||
|
|
||||||
QueuedUser::QueuedUserDefinitions definitions;
|
QueuedUser::QueuedUserDefinitions definitions;
|
||||||
|
|
||||||
// define password first
|
// define password first
|
||||||
definitions.password = _parser.isSet("stdin-password")
|
definitions.password
|
||||||
? getPassword()
|
= _parser.isSet("stdin-password") ? getPassword() : _parser.value("password");
|
||||||
: _parser.value("password");
|
|
||||||
auto res = QueuedCoreAdaptor::sendPasswordHash(definitions.password);
|
auto res = QueuedCoreAdaptor::sendPasswordHash(definitions.password);
|
||||||
res.match(
|
res.match([&definitions](const QString &val) { definitions.password = val; },
|
||||||
[&definitions](const QString &val) { definitions.password = val; },
|
[&definitions](const QueuedError &) { definitions.password = ""; });
|
||||||
[&definitions](const QueuedError &) { definitions.password = ""; });
|
|
||||||
|
|
||||||
definitions.email = _parser.value("email");
|
definitions.email = _parser.value("email");
|
||||||
definitions.priority = _parser.value("priority").toUInt();
|
definitions.priority = _parser.value("priority").toUInt();
|
||||||
// limits now
|
// limits now
|
||||||
QueuedLimits::Limits limits(
|
QueuedLimits::Limits limits(_parser.value("limit-cpu").toLongLong(),
|
||||||
_parser.value("limit-cpu").toLongLong(),
|
_parser.value("limit-gpu").toLongLong(),
|
||||||
_parser.value("limit-gpu").toLongLong(),
|
QueuedLimits::convertMemory(_parser.value("limit-memory")),
|
||||||
QueuedLimits::convertMemory(_parser.value("limit-memory")),
|
QueuedLimits::convertMemory(_parser.value("limit-gpumemory")),
|
||||||
QueuedLimits::convertMemory(_parser.value("limit-gpumemory")),
|
QueuedLimits::convertMemory(_parser.value("limit-storage")));
|
||||||
QueuedLimits::convertMemory(_parser.value("limit-storage")));
|
|
||||||
definitions.limits = limits.toString();
|
definitions.limits = limits.toString();
|
||||||
|
|
||||||
// all options
|
// all options
|
||||||
@ -137,8 +124,7 @@ QString QueuedctlUser::getPassword()
|
|||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult
|
||||||
QueuedctlUser::getUser(const long long _id, const QString &_property,
|
QueuedctlUser::getUser(const long long _id, const QString &_property, const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Get property" << _property << "from user" << _id;
|
qCDebug(LOG_APP) << "Get property" << _property << "from user" << _id;
|
||||||
|
|
||||||
@ -151,9 +137,7 @@ QueuedctlUser::getUser(const long long _id, const QString &_property,
|
|||||||
output.status = true;
|
output.status = true;
|
||||||
output.output = QueuedctlCommon::hashToString(val);
|
output.output = QueuedctlCommon::hashToString(val);
|
||||||
},
|
},
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
auto res = QueuedCoreAdaptor::getUser(_id, _property);
|
auto res = QueuedCoreAdaptor::getUser(_id, _property);
|
||||||
res.match(
|
res.match(
|
||||||
@ -161,25 +145,20 @@ QueuedctlUser::getUser(const long long _id, const QString &_property,
|
|||||||
output.status = val.isValid();
|
output.status = val.isValid();
|
||||||
output.output = val.toString();
|
output.output = val.toString();
|
||||||
},
|
},
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult QueuedctlUser::getUsers(const QCommandLineParser &_parser,
|
||||||
QueuedctlUser::getUsers(const QCommandLineParser &_parser,
|
const QString &_token)
|
||||||
const QString &_token)
|
|
||||||
{
|
{
|
||||||
QDateTime lastLogin = QDateTime::fromString(_parser.value("last-logged"),
|
QDateTime lastLogin = QDateTime::fromString(_parser.value("last-logged"), Qt::ISODateWithMs);
|
||||||
Qt::ISODateWithMs);
|
auto permission = _parser.value("access").isEmpty()
|
||||||
auto permission
|
? QueuedEnums::Permission::Invalid
|
||||||
= _parser.value("access").isEmpty()
|
: QueuedEnums::Permission(_parser.value("access").toInt());
|
||||||
? QueuedEnums::Permission::Invalid
|
|
||||||
: QueuedEnums::Permission(_parser.value("access").toInt());
|
|
||||||
|
|
||||||
auto res = QueuedCoreAdaptor::getUsers(lastLogin, permission, _token);
|
auto res = QueuedCoreAdaptor::getUsers(lastLogin, permission, _token);
|
||||||
|
|
||||||
@ -189,9 +168,7 @@ QueuedctlUser::getUsers(const QCommandLineParser &_parser,
|
|||||||
output.status = true;
|
output.status = true;
|
||||||
output.output = QueuedctlCommon::hashListToString(val);
|
output.output = QueuedctlCommon::hashListToString(val);
|
||||||
},
|
},
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
@ -202,43 +179,35 @@ void QueuedctlUser::parserAdd(QCommandLineParser &_parser)
|
|||||||
_parser.addPositionalArgument("name", "User name.", "<name>");
|
_parser.addPositionalArgument("name", "User name.", "<name>");
|
||||||
|
|
||||||
// permissions
|
// permissions
|
||||||
QCommandLineOption accessOption({"a", "access"}, "User permission.",
|
QCommandLineOption accessOption({"a", "access"}, "User permission.", "access", "0");
|
||||||
"access", "0");
|
|
||||||
_parser.addOption(accessOption);
|
_parser.addOption(accessOption);
|
||||||
// email
|
// email
|
||||||
QCommandLineOption emailOption({"e", "email"}, "User email.", "email", "");
|
QCommandLineOption emailOption({"e", "email"}, "User email.", "email", "");
|
||||||
_parser.addOption(emailOption);
|
_parser.addOption(emailOption);
|
||||||
// priority
|
// priority
|
||||||
QCommandLineOption priorityOption({"p", "priority"}, "User priority.",
|
QCommandLineOption priorityOption({"p", "priority"}, "User priority.", "priority", "0");
|
||||||
"priority", "0");
|
|
||||||
_parser.addOption(priorityOption);
|
_parser.addOption(priorityOption);
|
||||||
// password
|
// password
|
||||||
QCommandLineOption passwordOption("password", "User password.", "password",
|
QCommandLineOption passwordOption("password", "User password.", "password", "");
|
||||||
"");
|
|
||||||
_parser.addOption(passwordOption);
|
_parser.addOption(passwordOption);
|
||||||
// password
|
// password
|
||||||
QCommandLineOption stdinPasswordOption("stdin-password",
|
QCommandLineOption stdinPasswordOption("stdin-password", "User password from stdin.");
|
||||||
"User password from stdin.");
|
|
||||||
_parser.addOption(stdinPasswordOption);
|
_parser.addOption(stdinPasswordOption);
|
||||||
// cpu limit
|
// cpu limit
|
||||||
QCommandLineOption cpuOption("limit-cpu", "User CPU limit.", "limit-cpu",
|
QCommandLineOption cpuOption("limit-cpu", "User CPU limit.", "limit-cpu", "0");
|
||||||
"0");
|
|
||||||
_parser.addOption(cpuOption);
|
_parser.addOption(cpuOption);
|
||||||
// gpu limit
|
// gpu limit
|
||||||
QCommandLineOption gpuOption("limit-gpu", "User GPU limit.", "limit-gpu",
|
QCommandLineOption gpuOption("limit-gpu", "User GPU limit.", "limit-gpu", "0");
|
||||||
"0");
|
|
||||||
_parser.addOption(gpuOption);
|
_parser.addOption(gpuOption);
|
||||||
// memory limit
|
// memory limit
|
||||||
QCommandLineOption memoryOption("limit-memory", "User memory limit.",
|
QCommandLineOption memoryOption("limit-memory", "User memory limit.", "limit-memory", "0");
|
||||||
"limit-memory", "0");
|
|
||||||
_parser.addOption(memoryOption);
|
_parser.addOption(memoryOption);
|
||||||
// gpu memory limit
|
// gpu memory limit
|
||||||
QCommandLineOption gpumemoryOption(
|
QCommandLineOption gpumemoryOption("limit-gpumemory", "User GPU memory limit.",
|
||||||
"limit-gpumemory", "User GPU memory limit.", "limit-gpumemory", "0");
|
"limit-gpumemory", "0");
|
||||||
_parser.addOption(gpumemoryOption);
|
_parser.addOption(gpumemoryOption);
|
||||||
// storage limit
|
// storage limit
|
||||||
QCommandLineOption storageOption("limit-storage", "User storage limit.",
|
QCommandLineOption storageOption("limit-storage", "User storage limit.", "limit-storage", "0");
|
||||||
"limit-storage", "0");
|
|
||||||
_parser.addOption(storageOption);
|
_parser.addOption(storageOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,16 +215,14 @@ void QueuedctlUser::parserAdd(QCommandLineParser &_parser)
|
|||||||
void QueuedctlUser::parserGet(QCommandLineParser &_parser)
|
void QueuedctlUser::parserGet(QCommandLineParser &_parser)
|
||||||
{
|
{
|
||||||
_parser.addPositionalArgument("id", "User ID.", "<id>");
|
_parser.addPositionalArgument("id", "User ID.", "<id>");
|
||||||
_parser.addPositionalArgument("property", "User property name.",
|
_parser.addPositionalArgument("property", "User property name.", "<property>");
|
||||||
"<property>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void QueuedctlUser::parserList(QCommandLineParser &_parser)
|
void QueuedctlUser::parserList(QCommandLineParser &_parser)
|
||||||
{
|
{
|
||||||
// last logged in
|
// last logged in
|
||||||
QCommandLineOption loggedOption("last-logged", "User last logged time.",
|
QCommandLineOption loggedOption("last-logged", "User last logged time.", "last-logged", "");
|
||||||
"last-logged", "");
|
|
||||||
_parser.addOption(loggedOption);
|
_parser.addOption(loggedOption);
|
||||||
// permissions
|
// permissions
|
||||||
QCommandLineOption accessOption("access", "User permission.", "access", "");
|
QCommandLineOption accessOption("access", "User permission.", "access", "");
|
||||||
@ -285,43 +252,35 @@ void QueuedctlUser::parserSet(QCommandLineParser &_parser)
|
|||||||
QCommandLineOption nameOption({"n", "name"}, "User name.", "name", "");
|
QCommandLineOption nameOption({"n", "name"}, "User name.", "name", "");
|
||||||
_parser.addOption(nameOption);
|
_parser.addOption(nameOption);
|
||||||
// priority
|
// priority
|
||||||
QCommandLineOption priorityOption({"p", "priority"}, "User priority.",
|
QCommandLineOption priorityOption({"p", "priority"}, "User priority.", "priority", "0");
|
||||||
"priority", "0");
|
|
||||||
_parser.addOption(priorityOption);
|
_parser.addOption(priorityOption);
|
||||||
// password
|
// password
|
||||||
QCommandLineOption passwordOption("password", "User password.", "password",
|
QCommandLineOption passwordOption("password", "User password.", "password", "");
|
||||||
"");
|
|
||||||
_parser.addOption(passwordOption);
|
_parser.addOption(passwordOption);
|
||||||
// password
|
// password
|
||||||
QCommandLineOption stdinPasswordOption("stdin-password",
|
QCommandLineOption stdinPasswordOption("stdin-password", "User password from stdin.");
|
||||||
"User password from stdin.");
|
|
||||||
_parser.addOption(stdinPasswordOption);
|
_parser.addOption(stdinPasswordOption);
|
||||||
// cpu limit
|
// cpu limit
|
||||||
QCommandLineOption cpuOption("limit-cpu", "User CPU limit.", "limit-cpu",
|
QCommandLineOption cpuOption("limit-cpu", "User CPU limit.", "limit-cpu", "0");
|
||||||
"0");
|
|
||||||
_parser.addOption(cpuOption);
|
_parser.addOption(cpuOption);
|
||||||
// gpu limit
|
// gpu limit
|
||||||
QCommandLineOption gpuOption("limit-gpu", "User GPU limit.", "limit-gpu",
|
QCommandLineOption gpuOption("limit-gpu", "User GPU limit.", "limit-gpu", "0");
|
||||||
"0");
|
|
||||||
_parser.addOption(gpuOption);
|
_parser.addOption(gpuOption);
|
||||||
// memory limit
|
// memory limit
|
||||||
QCommandLineOption memoryOption("limit-memory", "User memory limit.",
|
QCommandLineOption memoryOption("limit-memory", "User memory limit.", "limit-memory", "0");
|
||||||
"limit-memory", "0");
|
|
||||||
_parser.addOption(memoryOption);
|
_parser.addOption(memoryOption);
|
||||||
// gpu memory limit
|
// gpu memory limit
|
||||||
QCommandLineOption gpumemoryOption(
|
QCommandLineOption gpumemoryOption("limit-gpumemory", "User GPU memory limit.",
|
||||||
"limit-gpumemory", "User GPU memory limit.", "limit-gpumemory", "0");
|
"limit-gpumemory", "0");
|
||||||
_parser.addOption(gpumemoryOption);
|
_parser.addOption(gpumemoryOption);
|
||||||
// storage limit
|
// storage limit
|
||||||
QCommandLineOption storageOption("limit-storage", "User storage limit.",
|
QCommandLineOption storageOption("limit-storage", "User storage limit.", "limit-storage", "0");
|
||||||
"limit-storage", "0");
|
|
||||||
_parser.addOption(storageOption);
|
_parser.addOption(storageOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult
|
||||||
QueuedctlUser::setUser(const long long _id,
|
QueuedctlUser::setUser(const long long _id, const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
const QueuedUser::QueuedUserDefinitions &_definitions,
|
|
||||||
const QString &_token)
|
const QString &_token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_APP) << "Edit user" << _id;
|
qCDebug(LOG_APP) << "Edit user" << _id;
|
||||||
@ -330,9 +289,7 @@ QueuedctlUser::setUser(const long long _id,
|
|||||||
|
|
||||||
QueuedctlCommon::QueuedctlResult output;
|
QueuedctlCommon::QueuedctlResult output;
|
||||||
res.match([&output](const bool val) { output.status = val; },
|
res.match([&output](const bool val) { output.status = val; },
|
||||||
[&output](const QueuedError &err) {
|
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||||
output.output = err.message().c_str();
|
|
||||||
});
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -26,27 +26,24 @@
|
|||||||
|
|
||||||
namespace QueuedctlUser
|
namespace QueuedctlUser
|
||||||
{
|
{
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult addUser(const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
addUser(const QueuedUser::QueuedUserDefinitions &_definitions,
|
const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
QueuedctlCommon::QueuedctlResult getReport(const QCommandLineParser &_parser,
|
QueuedctlCommon::QueuedctlResult getReport(const QCommandLineParser &_parser,
|
||||||
const QString &_token);
|
const QString &_token);
|
||||||
QueuedUser::QueuedUserDefinitions
|
QueuedUser::QueuedUserDefinitions getDefinitions(const QCommandLineParser &_parser,
|
||||||
getDefinitions(const QCommandLineParser &_parser, const bool _expandAll);
|
const bool _expandAll);
|
||||||
QString getPassword();
|
QString getPassword();
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult getUser(const long long _id, const QString &_property,
|
||||||
getUser(const long long _id, const QString &_property, const QString &_token);
|
const QString &_token);
|
||||||
QueuedctlCommon::QueuedctlResult getUsers(const QCommandLineParser &_parser,
|
QueuedctlCommon::QueuedctlResult getUsers(const QCommandLineParser &_parser, const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
void parserAdd(QCommandLineParser &_parser);
|
void parserAdd(QCommandLineParser &_parser);
|
||||||
void parserGet(QCommandLineParser &_parser);
|
void parserGet(QCommandLineParser &_parser);
|
||||||
void parserList(QCommandLineParser &_parser);
|
void parserList(QCommandLineParser &_parser);
|
||||||
void parserReport(QCommandLineParser &_parser);
|
void parserReport(QCommandLineParser &_parser);
|
||||||
void parserSet(QCommandLineParser &_parser);
|
void parserSet(QCommandLineParser &_parser);
|
||||||
QueuedctlCommon::QueuedctlResult
|
QueuedctlCommon::QueuedctlResult setUser(const long long _id,
|
||||||
setUser(const long long _id,
|
const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
const QueuedUser::QueuedUserDefinitions &_definitions,
|
const QString &_token);
|
||||||
const QString &_token);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,8 +38,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// parser
|
// parser
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription(
|
parser.setApplicationDescription("Daemon for starting jobs to queue of calculations");
|
||||||
"Daemon for starting jobs to queue of calculations");
|
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
parser.addVersionOption();
|
parser.addVersionOption();
|
||||||
// info
|
// info
|
||||||
@ -51,12 +50,11 @@ int main(int argc, char *argv[])
|
|||||||
parser.addOption(debugOption);
|
parser.addOption(debugOption);
|
||||||
|
|
||||||
// configuration option
|
// configuration option
|
||||||
QCommandLineOption tokenOption({"t", "token"}, "Path to cached token.",
|
QCommandLineOption tokenOption({"t", "token"}, "Path to cached token.", "token",
|
||||||
"token", QueuedSettings::defaultTokenPath());
|
QueuedSettings::defaultTokenPath());
|
||||||
parser.addOption(tokenOption);
|
parser.addOption(tokenOption);
|
||||||
QCommandLineOption userOption({"u", "user"},
|
QCommandLineOption userOption({"u", "user"}, "User to login instead of current one.", "user",
|
||||||
"User to login instead of current one.",
|
::getlogin());
|
||||||
"user", ::getlogin());
|
|
||||||
parser.addOption(userOption);
|
parser.addOption(userOption);
|
||||||
|
|
||||||
// additional help option
|
// additional help option
|
||||||
@ -91,8 +89,8 @@ int main(int argc, char *argv[])
|
|||||||
QueuedDebug::enableDebug();
|
QueuedDebug::enableDebug();
|
||||||
|
|
||||||
// process
|
// process
|
||||||
auto result = QueuedctlCommon::process(parser, parser.value(tokenOption),
|
auto result
|
||||||
parser.value(userOption));
|
= QueuedctlCommon::process(parser, parser.value(tokenOption), parser.value(userOption));
|
||||||
QueuedctlCommon::print(result);
|
QueuedctlCommon::print(result);
|
||||||
|
|
||||||
return result.status ? 0 : 1;
|
return result.status ? 0 : 1;
|
||||||
|
@ -22,13 +22,10 @@ static const char SPECIAL_THANKS[] = "";
|
|||||||
// links
|
// links
|
||||||
static const char HOMEPAGE[] = "https://arcanis.me/projects/queued";
|
static const char HOMEPAGE[] = "https://arcanis.me/projects/queued";
|
||||||
static const char REPOSITORY[] = "https://github.com/arcan1s/queued";
|
static const char REPOSITORY[] = "https://github.com/arcan1s/queued";
|
||||||
static const char RELEASES[]
|
static const char RELEASES[] = "https://github.com/arcan1s/queued/releases/tag/V.";
|
||||||
= "https://github.com/arcan1s/queued/releases/tag/V.";
|
static const char VERSION_API[] = "https://api.github.com/repos/arcan1s/queued/releases";
|
||||||
static const char VERSION_API[]
|
|
||||||
= "https://api.github.com/repos/arcan1s/queued/releases";
|
|
||||||
static const char BUGTRACKER[] = "https://github.com/arcan1s/queued/issues";
|
static const char BUGTRACKER[] = "https://github.com/arcan1s/queued/issues";
|
||||||
static const char BUGTRACKER_API[]
|
static const char BUGTRACKER_API[] = "https://arcanis.me/repos/arcan1s/queued/issues";
|
||||||
= "https://arcanis.me/repos/arcan1s/queued/issues";
|
|
||||||
|
|
||||||
// build information
|
// build information
|
||||||
static const char BUILD_DATE[] = "@CURRENT_DATE@";
|
static const char BUILD_DATE[] = "@CURRENT_DATE@";
|
||||||
@ -39,8 +36,7 @@ static const char CMAKE_CXX_COMPILER[] = "@CMAKE_CXX_COMPILER@";
|
|||||||
static const char CMAKE_CXX_FLAGS[] = "@CMAKE_CXX_FLAGS@";
|
static const char CMAKE_CXX_FLAGS[] = "@CMAKE_CXX_FLAGS@";
|
||||||
static const char CMAKE_CXX_FLAGS_DEBUG[] = "@CMAKE_CXX_FLAGS_DEBUG@";
|
static const char CMAKE_CXX_FLAGS_DEBUG[] = "@CMAKE_CXX_FLAGS_DEBUG@";
|
||||||
static const char CMAKE_CXX_FLAGS_RELEASE[] = "@CMAKE_CXX_FLAGS_RELEASE@";
|
static const char CMAKE_CXX_FLAGS_RELEASE[] = "@CMAKE_CXX_FLAGS_RELEASE@";
|
||||||
static const char CMAKE_CXX_FLAGS_OPTIMIZATION[]
|
static const char CMAKE_CXX_FLAGS_OPTIMIZATION[] = "@CMAKE_CXX_FLAGS_OPTIMIZATION@";
|
||||||
= "@CMAKE_CXX_FLAGS_OPTIMIZATION@";
|
|
||||||
static const char CMAKE_DEFINITIONS[] = "@CMAKE_DEFINITIONS@";
|
static const char CMAKE_DEFINITIONS[] = "@CMAKE_DEFINITIONS@";
|
||||||
static const char CMAKE_INSTALL_PREFIX[] = "@CMAKE_INSTALL_PREFIX@";
|
static const char CMAKE_INSTALL_PREFIX[] = "@CMAKE_INSTALL_PREFIX@";
|
||||||
static const char CMAKE_MODULE_LINKER_FLAGS[] = "@CMAKE_MODULE_LINKER_FLAGS@";
|
static const char CMAKE_MODULE_LINKER_FLAGS[] = "@CMAKE_MODULE_LINKER_FLAGS@";
|
||||||
|
Reference in New Issue
Block a user