mirror of
https://github.com/arcan1s/queued.git
synced 2025-04-24 15:37:19 +00:00
implement priority supprt for users
This commit is contained in:
parent
881abd4c51
commit
bfea1635f9
@ -65,27 +65,21 @@ int main(int argc, char *argv[])
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
// info
|
||||
QCommandLineOption infoOption(QStringList() << "i"
|
||||
<< "info",
|
||||
"Show additional info.");
|
||||
QCommandLineOption infoOption({"i", "info"}, "Show additional info.");
|
||||
parser.addOption(infoOption);
|
||||
|
||||
// configuration option
|
||||
QCommandLineOption configOption(QStringList() << "c"
|
||||
<< "config",
|
||||
QCommandLineOption configOption({"c", "config"},
|
||||
"Read initial configuration from file.",
|
||||
"config", QueuedSettings::defaultPath());
|
||||
parser.addOption(configOption);
|
||||
|
||||
// debug mode
|
||||
QCommandLineOption debugOption(QStringList() << "d"
|
||||
<< "debug",
|
||||
"Print debug information.");
|
||||
QCommandLineOption debugOption({"d", "debug"}, "Print debug information.");
|
||||
parser.addOption(debugOption);
|
||||
|
||||
// daemon mode
|
||||
QCommandLineOption daemonOption(QStringList() << "daemon",
|
||||
"Start detached.");
|
||||
QCommandLineOption daemonOption("daemon", "Start detached.");
|
||||
parser.addOption(daemonOption);
|
||||
|
||||
parser.process(app);
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "QueuedTcpServerResponseHelperUser.h"
|
||||
|
||||
#include <queued/Queued.h>
|
||||
#include <queued/QueuedUser.h>
|
||||
|
||||
|
||||
QVariantHash QueuedTcpServerResponseHelperUser::addOrEditUser(
|
||||
@ -72,6 +73,7 @@ QueuedTcpServerResponseHelperUser::getDefinitions(const QVariantHash &_data)
|
||||
res.match([&defs](const QString &val) { defs.password = val; },
|
||||
[](const QueuedError &) {});
|
||||
defs.permissions = _data["permissions"].toUInt();
|
||||
defs.priority = _data["priority"].toUInt();
|
||||
// limits
|
||||
QueuedLimits::Limits limits;
|
||||
limits.cpu = _data["limitCpu"].toLongLong();
|
||||
|
@ -55,20 +55,15 @@ int main(int argc, char *argv[])
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
// info
|
||||
QCommandLineOption infoOption(QStringList() << "i"
|
||||
<< "info",
|
||||
"Show additional info.");
|
||||
QCommandLineOption infoOption({"i", "info"}, "Show additional info.");
|
||||
parser.addOption(infoOption);
|
||||
|
||||
// debug mode
|
||||
QCommandLineOption debugOption(QStringList() << "d"
|
||||
<< "debug",
|
||||
"Print debug information.");
|
||||
QCommandLineOption debugOption({"d", "debug"}, "Print debug information.");
|
||||
parser.addOption(debugOption);
|
||||
|
||||
// daemon mode
|
||||
QCommandLineOption daemonOption(QStringList() << "daemon",
|
||||
"Start detached.");
|
||||
QCommandLineOption daemonOption("daemon", "Start detached.");
|
||||
parser.addOption(daemonOption);
|
||||
|
||||
parser.process(app);
|
||||
|
@ -72,16 +72,20 @@ public:
|
||||
* working directory
|
||||
* @param _userId
|
||||
* task owner user ID
|
||||
* @param _nice
|
||||
* task nice level
|
||||
* @param _limits
|
||||
* task defined limits
|
||||
* @param _token
|
||||
* user auth token
|
||||
* @return task ID or -1 if no task added
|
||||
*/
|
||||
QueuedResult<long long>
|
||||
addTask(const QString &_command, const QStringList &_arguments,
|
||||
const QString &_workingDirectory, const long long _userId,
|
||||
const QueuedLimits::Limits &_limits, const QString &_token);
|
||||
QueuedResult<long long> addTask(const QString &_command,
|
||||
const QStringList &_arguments,
|
||||
const QString &_workingDirectory,
|
||||
const long long _userId, const uint _nice,
|
||||
const QueuedLimits::Limits &_limits,
|
||||
const QString &_token);
|
||||
/**
|
||||
* @brief add new user
|
||||
* @param _name
|
||||
@ -92,6 +96,8 @@ public:
|
||||
* user password
|
||||
* @param _permissions
|
||||
* user permissions
|
||||
* @param _priority
|
||||
* user priority
|
||||
* @param _limits
|
||||
* user limits
|
||||
* @param _token
|
||||
@ -101,6 +107,7 @@ public:
|
||||
QueuedResult<long long> addUser(const QString &_name, const QString &_email,
|
||||
const QString &_password,
|
||||
const uint _permissions,
|
||||
const uint _priority,
|
||||
const QueuedLimits::Limits &_limits,
|
||||
const QString &_token);
|
||||
/**
|
||||
|
@ -109,6 +109,8 @@ public slots:
|
||||
* working directory
|
||||
* @param user
|
||||
* user ID
|
||||
* @param nice
|
||||
* nice level
|
||||
* @param cpu
|
||||
* limit by CPU cores
|
||||
* @param gpu
|
||||
@ -125,9 +127,10 @@ public slots:
|
||||
*/
|
||||
QDBusVariant TaskAdd(const QString &command, const QStringList &arguments,
|
||||
const QString &workingDirectory, const qlonglong user,
|
||||
const qlonglong cpu, const qlonglong gpu,
|
||||
const qlonglong memory, const qlonglong gpumemory,
|
||||
const qlonglong storage, const QString &token);
|
||||
const uint nice, const qlonglong cpu,
|
||||
const qlonglong gpu, const qlonglong memory,
|
||||
const qlonglong gpumemory, const qlonglong storage,
|
||||
const QString &token);
|
||||
/**
|
||||
* @brief edit task
|
||||
* @param id
|
||||
@ -202,6 +205,8 @@ public slots:
|
||||
* user password
|
||||
* @param permissions
|
||||
* user permissions
|
||||
* @param priority
|
||||
* user permissions
|
||||
* @param cpu
|
||||
* limit by CPU cores
|
||||
* @param gpu
|
||||
@ -218,9 +223,10 @@ public slots:
|
||||
*/
|
||||
QDBusVariant UserAdd(const QString &name, const QString &email,
|
||||
const QString &password, const uint permissions,
|
||||
const qlonglong cpu, const qlonglong gpu,
|
||||
const qlonglong memory, const qlonglong gpumemory,
|
||||
const qlonglong storage, const QString &token);
|
||||
const uint priority, const qlonglong cpu,
|
||||
const qlonglong gpu, const qlonglong memory,
|
||||
const qlonglong gpumemory, const qlonglong storage,
|
||||
const QString &token);
|
||||
/**
|
||||
* @brief edit user
|
||||
* @param id
|
||||
|
@ -202,8 +202,8 @@ private:
|
||||
* value to build payload
|
||||
* @return list of keys and list of values
|
||||
*/
|
||||
QPair<QStringList, QStringList>
|
||||
getQueryPayload(const QString &_table, const QVariantHash &_value) const;
|
||||
QHash<QString, QString> getQueryPayload(const QString &_table,
|
||||
const QVariantHash &_value) const;
|
||||
};
|
||||
|
||||
|
||||
|
@ -115,7 +115,8 @@ static const QueuedDBSchema DBSchema = {
|
||||
{"email", {"email", "TEXT", QVariant::String, false}},
|
||||
{"lastLogin", {"lastLogin", "TEXT", QVariant::String, true}},
|
||||
{"limits", {"limits", "TEXT", QVariant::String, true}},
|
||||
{"permissions", {"permissions", "INT", QVariant::UInt, true}}}}};
|
||||
{"permissions", {"permissions", "INT", QVariant::UInt, true}},
|
||||
{"priotiry", {"priority", "INT", QVariant::UInt, true}}}}};
|
||||
};
|
||||
|
||||
#endif /* QUEUEDDATABASESCHEMA_H */
|
||||
|
@ -43,6 +43,7 @@ class QueuedUser : public QObject
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(QString password READ password WRITE setPassword)
|
||||
Q_PROPERTY(uint permissions READ permissions WRITE setPermissions)
|
||||
Q_PROPERTY(uint priority READ priority WRITE setPriority)
|
||||
// limits
|
||||
Q_PROPERTY(QString limits READ limits WRITE setLimits)
|
||||
|
||||
@ -66,6 +67,7 @@ public:
|
||||
QString email;
|
||||
QString password;
|
||||
uint permissions = 0;
|
||||
uint priority = 0;
|
||||
QString limits;
|
||||
} QueuedUserDefinitions;
|
||||
|
||||
@ -164,6 +166,11 @@ public:
|
||||
* @return sum of user permissions from QueuedUser::Permissions
|
||||
*/
|
||||
uint permissions() const;
|
||||
/**
|
||||
* @brief user max priority
|
||||
* @return user maximal priority value
|
||||
*/
|
||||
uint priority() const;
|
||||
// permissions
|
||||
/**
|
||||
* @brief user limits
|
||||
@ -195,6 +202,12 @@ public:
|
||||
* new user permissions
|
||||
*/
|
||||
void setPermissions(const uint _permissions);
|
||||
/**
|
||||
* @brief set user priority
|
||||
* @param _priority
|
||||
* new user priority value
|
||||
*/
|
||||
void setPriority(const uint _priority);
|
||||
// permissions
|
||||
/**
|
||||
* @brief set limits
|
||||
|
@ -81,16 +81,20 @@ public:
|
||||
* working directory
|
||||
* @param _userId
|
||||
* task owner user ID
|
||||
* @param _nice
|
||||
* task nice level
|
||||
* @param _limits
|
||||
* task defined limits
|
||||
* @param _token
|
||||
* user auth token
|
||||
* @return task ID or -1 if no task added
|
||||
*/
|
||||
QueuedResult<long long>
|
||||
addTask(const QString &_command, const QStringList &_arguments,
|
||||
const QString &_workingDirectory, const long long _userId,
|
||||
const QueuedLimits::Limits &_limits, const QString &_token);
|
||||
QueuedResult<long long> addTask(const QString &_command,
|
||||
const QStringList &_arguments,
|
||||
const QString &_workingDirectory,
|
||||
const long long _userId, const uint _nice,
|
||||
const QueuedLimits::Limits &_limits,
|
||||
const QString &_token);
|
||||
/**
|
||||
* @brief add new user
|
||||
* @param _name
|
||||
@ -101,6 +105,8 @@ public:
|
||||
* user password
|
||||
* @param _permissions
|
||||
* user permissions
|
||||
* @param _priority
|
||||
* user priority
|
||||
* @param _limits
|
||||
* user limits
|
||||
* @param _token
|
||||
@ -110,6 +116,7 @@ public:
|
||||
QueuedResult<long long> addUser(const QString &_name, const QString &_email,
|
||||
const QString &_password,
|
||||
const uint _permissions,
|
||||
const uint _priority,
|
||||
const QueuedLimits::Limits &_limits,
|
||||
const QString &_token);
|
||||
/**
|
||||
|
@ -125,15 +125,16 @@ private:
|
||||
* working directory
|
||||
* @param _userId
|
||||
* task owner user ID
|
||||
* @param _nice
|
||||
* task nice level
|
||||
* @param _limits
|
||||
* task defined limits
|
||||
* @return task ID or -1 if no task added
|
||||
*/
|
||||
QueuedResult<long long> addTaskPrivate(const QString &_command,
|
||||
const QStringList &_arguments,
|
||||
const QString &_workingDirectory,
|
||||
const long long _userId,
|
||||
const QueuedLimits::Limits &_limits);
|
||||
QueuedResult<long long>
|
||||
addTaskPrivate(const QString &_command, const QStringList &_arguments,
|
||||
const QString &_workingDirectory, const long long _userId,
|
||||
const uint _nice, const QueuedLimits::Limits &_limits);
|
||||
/**
|
||||
* @brief add new user
|
||||
* @param _name
|
||||
@ -144,15 +145,16 @@ private:
|
||||
* user password
|
||||
* @param _permissions
|
||||
* user permissions
|
||||
* @param _priority
|
||||
* user priority
|
||||
* @param _limits
|
||||
* user limits
|
||||
* @return user ID or -1 if no user found
|
||||
*/
|
||||
QueuedResult<long long> addUserPrivate(const QString &_name,
|
||||
const QString &_email,
|
||||
const QString &_password,
|
||||
const uint _permissions,
|
||||
const QueuedLimits::Limits &_limits);
|
||||
QueuedResult<long long>
|
||||
addUserPrivate(const QString &_name, const QString &_email,
|
||||
const QString &_password, const uint _permissions,
|
||||
const uint _priority, const QueuedLimits::Limits &_limits);
|
||||
/**
|
||||
* @brief edit advanced settings
|
||||
* @param _key
|
||||
|
@ -71,13 +71,14 @@ QueuedResult<bool> QueuedCore::addPlugin(const QString &_plugin,
|
||||
QueuedResult<long long>
|
||||
QueuedCore::addTask(const QString &_command, const QStringList &_arguments,
|
||||
const QString &_workingDirectory, const long long _userId,
|
||||
const QueuedLimits::Limits &_limits, const QString &_token)
|
||||
const uint _nice, const QueuedLimits::Limits &_limits,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Add task" << _command << "with arguments" << _arguments
|
||||
<< "from user" << _userId;
|
||||
|
||||
return m_impl->addTask(_command, _arguments, _workingDirectory, _userId,
|
||||
_limits, _token);
|
||||
_nice, _limits, _token);
|
||||
}
|
||||
|
||||
|
||||
@ -87,13 +88,14 @@ QueuedCore::addTask(const QString &_command, const QStringList &_arguments,
|
||||
QueuedResult<long long>
|
||||
QueuedCore::addUser(const QString &_name, const QString &_email,
|
||||
const QString &_password, const uint _permissions,
|
||||
const QueuedLimits::Limits &_limits, const QString &_token)
|
||||
const uint _priority, const QueuedLimits::Limits &_limits,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Add user" << _name << "with email" << _email
|
||||
<< "and permissions" << _permissions;
|
||||
|
||||
return m_impl->addUser(_name, _email, _password, _permissions, _limits,
|
||||
_token);
|
||||
return m_impl->addUser(_name, _email, _password, _permissions, _priority,
|
||||
_limits, _token);
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
|
||||
#include <queued/Queued.h>
|
||||
#include <queued/QueuedUser.h>
|
||||
|
||||
|
||||
/**
|
||||
@ -125,6 +126,7 @@ QueuedResult<long long> QueuedCoreAdaptor::sendTaskAdd(
|
||||
_definitions.arguments,
|
||||
_definitions.workingDirectory,
|
||||
_definitions.user,
|
||||
_definitions.nice,
|
||||
limits.cpu,
|
||||
limits.gpu,
|
||||
limits.memory,
|
||||
@ -212,6 +214,7 @@ QueuedResult<long long> QueuedCoreAdaptor::sendUserAdd(
|
||||
_definitions.email,
|
||||
_definitions.password,
|
||||
_definitions.permissions,
|
||||
_definitions.priority,
|
||||
limits.cpu,
|
||||
limits.gpu,
|
||||
limits.memory,
|
||||
|
@ -124,15 +124,15 @@ QDBusVariant QueuedCoreInterface::PluginRemove(const QString &plugin,
|
||||
*/
|
||||
QDBusVariant QueuedCoreInterface::TaskAdd(
|
||||
const QString &command, const QStringList &arguments,
|
||||
const QString &workingDirectory, const qlonglong user, const qlonglong cpu,
|
||||
const qlonglong gpu, const qlonglong memory, const qlonglong gpumemory,
|
||||
const qlonglong storage, const QString &token)
|
||||
const QString &workingDirectory, const qlonglong user, const uint nice,
|
||||
const qlonglong cpu, const qlonglong gpu, const qlonglong memory,
|
||||
const qlonglong gpumemory, const qlonglong storage, const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Add new task with parameters" << command << arguments
|
||||
<< workingDirectory << "from user" << user;
|
||||
|
||||
return QueuedCoreAdaptor::toDBusVariant(m_core->addTask(
|
||||
command, arguments, workingDirectory, user,
|
||||
command, arguments, workingDirectory, user, nice,
|
||||
QueuedLimits::Limits(cpu, gpu, memory, gpumemory, storage), token));
|
||||
}
|
||||
|
||||
@ -229,18 +229,17 @@ QDBusVariant QueuedCoreInterface::TryAuth(const QString &token)
|
||||
/**
|
||||
* @fn UserAdd
|
||||
*/
|
||||
QDBusVariant
|
||||
QueuedCoreInterface::UserAdd(const QString &name, const QString &email,
|
||||
const QString &password, const uint permissions,
|
||||
const qlonglong cpu, const qlonglong gpu,
|
||||
const qlonglong memory, const qlonglong gpumemory,
|
||||
const qlonglong storage, const QString &token)
|
||||
QDBusVariant QueuedCoreInterface::UserAdd(
|
||||
const QString &name, const QString &email, const QString &password,
|
||||
const uint permissions, const uint priority, const qlonglong cpu,
|
||||
const qlonglong gpu, const qlonglong memory, const qlonglong gpumemory,
|
||||
const qlonglong storage, const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Add new user with paramaters" << name << email
|
||||
<< permissions;
|
||||
|
||||
return QueuedCoreAdaptor::toDBusVariant(m_core->addUser(
|
||||
name, email, password, permissions,
|
||||
name, email, password, permissions, priority,
|
||||
QueuedLimits::Limits(cpu, gpu, memory, gpumemory, storage), token));
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ QueuedResult<bool> QueuedCorePrivate::addPlugin(const QString &_plugin,
|
||||
*/
|
||||
QueuedResult<long long> QueuedCorePrivate::addTask(
|
||||
const QString &_command, const QStringList &_arguments,
|
||||
const QString &_workingDirectory, const long long _userId,
|
||||
const QString &_workingDirectory, const long long _userId, const uint _nice,
|
||||
const QueuedLimits::Limits &_limits, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Add task" << _command << "with arguments" << _arguments
|
||||
@ -93,18 +93,17 @@ QueuedResult<long long> QueuedCorePrivate::addTask(
|
||||
}
|
||||
|
||||
return m_helper->addTaskPrivate(_command, _arguments, _workingDirectory,
|
||||
_userId, _limits);
|
||||
_userId, _nice, _limits);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn addUser
|
||||
*/
|
||||
QueuedResult<long long>
|
||||
QueuedCorePrivate::addUser(const QString &_name, const QString &_email,
|
||||
const QString &_password, const uint _permissions,
|
||||
const QueuedLimits::Limits &_limits,
|
||||
const QString &_token)
|
||||
QueuedResult<long long> QueuedCorePrivate::addUser(
|
||||
const QString &_name, const QString &_email, const QString &_password,
|
||||
const uint _permissions, const uint _priority,
|
||||
const QueuedLimits::Limits &_limits, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Add user" << _name << "with email" << _email
|
||||
<< "and permissions" << _permissions;
|
||||
@ -126,7 +125,7 @@ QueuedCorePrivate::addUser(const QString &_name, const QString &_email,
|
||||
}
|
||||
|
||||
return m_helper->addUserPrivate(_name, _email, _password, _permissions,
|
||||
_limits);
|
||||
_priority, _limits);
|
||||
}
|
||||
|
||||
|
||||
@ -245,6 +244,9 @@ QueuedResult<bool> QueuedCorePrivate::editTask(const long long _id,
|
||||
QVariantHash payload
|
||||
= isAdmin ? _taskData
|
||||
: m_helper->dropAdminFields(QueuedDB::TASKS_TABLE, _taskData);
|
||||
if (payload.contains("nice"))
|
||||
payload["nice"]
|
||||
= std::min(payload["nice"].toUInt(), authUser->priority());
|
||||
|
||||
return m_helper->editTaskPrivate(_id, payload);
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ QueuedCorePrivateHelper::dropAdminFields(const QString &_table,
|
||||
*/
|
||||
QueuedResult<long long> QueuedCorePrivateHelper::addTaskPrivate(
|
||||
const QString &_command, const QStringList &_arguments,
|
||||
const QString &_workingDirectory, const long long _userId,
|
||||
const QString &_workingDirectory, const long long _userId, const uint _nice,
|
||||
const QueuedLimits::Limits &_limits)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Add task" << _command << "with arguments" << _arguments
|
||||
@ -148,7 +148,7 @@ QueuedResult<long long> QueuedCorePrivateHelper::addTaskPrivate(
|
||||
{"command", _command},
|
||||
{"commandArguments", _arguments},
|
||||
{"workDirectory", _workingDirectory},
|
||||
{"nice", 0},
|
||||
{"nice", std::min(_nice, userObj->priority())},
|
||||
{"uid", ids.first},
|
||||
{"gid", ids.second},
|
||||
{"limits", taskLimits.toString()}};
|
||||
@ -173,16 +173,16 @@ QueuedResult<long long> QueuedCorePrivateHelper::addTaskPrivate(
|
||||
*/
|
||||
QueuedResult<long long> QueuedCorePrivateHelper::addUserPrivate(
|
||||
const QString &_name, const QString &_email, const QString &_password,
|
||||
const uint _permissions, const QueuedLimits::Limits &_limits)
|
||||
const uint _permissions, const uint _priority,
|
||||
const QueuedLimits::Limits &_limits)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Add user" << _name << "with email" << _email
|
||||
<< "and permissions" << _permissions;
|
||||
// add to database
|
||||
QVariantHash properties = {{"name", _name},
|
||||
{"password", _password},
|
||||
{"email", _email},
|
||||
{"permissions", _permissions},
|
||||
{"limits", _limits.toString()}};
|
||||
QVariantHash properties
|
||||
= {{"name", _name}, {"password", _password},
|
||||
{"email", _email}, {"permissions", _permissions},
|
||||
{"priority", _priority}, {"limits", _limits.toString()}};
|
||||
auto id = database()->add(QueuedDB::USERS_TABLE, properties);
|
||||
if (id == -1) {
|
||||
qCWarning(LOG_LIB) << "Could not add user" << _name;
|
||||
|
@ -212,8 +212,8 @@ long long QueuedDatabase::add(const QString &_table, const QVariantHash &_value)
|
||||
// build query
|
||||
QSqlQuery query = m_database.exec(QString("INSERT INTO %1 (%2) VALUES (%3)")
|
||||
.arg(_table)
|
||||
.arg(payload.first.join(','))
|
||||
.arg(payload.second.join(',')));
|
||||
.arg(payload.keys().join(','))
|
||||
.arg(payload.values().join(',')));
|
||||
QSqlError error = query.lastError();
|
||||
if (error.isValid()) {
|
||||
qCCritical(LOG_LIB) << "Could not add record" << _value << "to table"
|
||||
@ -236,10 +236,8 @@ bool QueuedDatabase::modify(const QString &_table, const long long _id,
|
||||
|
||||
auto payload = getQueryPayload(_table, _value);
|
||||
QStringList stringPayload;
|
||||
for (int i = 0; i < payload.first.count(); i++)
|
||||
stringPayload.append(QString("%1=%2")
|
||||
.arg(payload.first.at(i))
|
||||
.arg(payload.second.at(i)));
|
||||
for (auto &key : payload.keys())
|
||||
stringPayload.append(QString("%1=%2").arg(key).arg(payload[key]));
|
||||
// build query
|
||||
QSqlQuery query = m_database.exec(QString("UPDATE %1 SET %2 WHERE _id=%3")
|
||||
.arg(_table)
|
||||
@ -427,14 +425,13 @@ long long QueuedDatabase::lastInsertionId(const QString &_table) const
|
||||
/**
|
||||
* @fn getQueryPayload
|
||||
*/
|
||||
QPair<QStringList, QStringList>
|
||||
QHash<QString, QString>
|
||||
QueuedDatabase::getQueryPayload(const QString &_table,
|
||||
const QVariantHash &_value) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Add record" << _value << "to table" << _table;
|
||||
|
||||
QStringList keys;
|
||||
QStringList values;
|
||||
QHash<QString, QString> output;
|
||||
QStringList schemaColumns = QueuedDB::DBSchema[_table].keys();
|
||||
for (auto &key : _value.keys()) {
|
||||
if (!schemaColumns.contains(key)) {
|
||||
@ -446,9 +443,8 @@ QueuedDatabase::getQueryPayload(const QString &_table,
|
||||
qCWarning(LOG_LIB) << "Modifying record ID is not allowed";
|
||||
continue;
|
||||
}
|
||||
keys.append(key);
|
||||
values.append(QString("'%1'").arg(_value[key].toString()));
|
||||
output[key] = QString("'%1'").arg(_value[key].toString());
|
||||
}
|
||||
|
||||
return {keys, values};
|
||||
return output;
|
||||
}
|
||||
|
@ -198,6 +198,15 @@ uint QueuedUser::permissions() const
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn priority
|
||||
*/
|
||||
uint QueuedUser::priority() const
|
||||
{
|
||||
return m_definitions.priority;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn limits
|
||||
*/
|
||||
@ -251,6 +260,17 @@ void QueuedUser::setPermissions(const uint _permissions)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn setPriority
|
||||
*/
|
||||
void QueuedUser::setPriority(const uint _priority)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "New user priority" << _priority;
|
||||
|
||||
m_definitions.priority = _priority;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn setLimits
|
||||
*/
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
|
||||
#include <queued/Queued.h>
|
||||
#include <queued/QueuedUser.h>
|
||||
|
||||
|
||||
/**
|
||||
@ -64,6 +65,7 @@ QueuedUser *QueuedUserManager::add(const QVariantHash &_properties,
|
||||
defs.email = _properties["email"].toString();
|
||||
defs.password = _properties["password"].toString();
|
||||
defs.permissions = _properties["permissions"].toUInt();
|
||||
defs.priority = _properties["priority"].toUInt();
|
||||
defs.limits = _properties["limits"].toString();
|
||||
|
||||
return add(defs, _id);
|
||||
|
@ -173,8 +173,7 @@ void QueuedctlTask::parserAdd(QCommandLineParser &_parser)
|
||||
_parser.addPositionalArgument("program", "Command line.", "<program>");
|
||||
|
||||
// command line arguments
|
||||
QCommandLineOption argumentOption(QStringList() << "a"
|
||||
<< "argument",
|
||||
QCommandLineOption argumentOption({"a", "argument"},
|
||||
"Command line argument.", "argument", "");
|
||||
_parser.addOption(argumentOption);
|
||||
// working directory
|
||||
@ -239,13 +238,11 @@ void QueuedctlTask::parserSet(QCommandLineParser &_parser)
|
||||
_parser.addPositionalArgument("id", "Task ID.", "<id>");
|
||||
|
||||
// command line
|
||||
QCommandLineOption commandOption(QStringList() << "p"
|
||||
<< "program",
|
||||
"Command line.", "program", "");
|
||||
QCommandLineOption commandOption({"p", "program"}, "Command line.",
|
||||
"program", "");
|
||||
_parser.addOption(commandOption);
|
||||
// command line arguments
|
||||
QCommandLineOption argumentOption(QStringList() << "a"
|
||||
<< "argument",
|
||||
QCommandLineOption argumentOption({"a", "argument"},
|
||||
"Command line argument.", "argument", "");
|
||||
_parser.addOption(argumentOption);
|
||||
// working directory
|
||||
|
@ -96,6 +96,7 @@ QueuedctlUser::getDefinitions(const QCommandLineParser &_parser,
|
||||
[&definitions](const QueuedError &) { definitions.password = ""; });
|
||||
|
||||
definitions.email = _parser.value("email");
|
||||
definitions.priority = _parser.value("priority").toUInt();
|
||||
// limits now
|
||||
QueuedLimits::Limits limits(
|
||||
_parser.value("limit-cpu").toLongLong(),
|
||||
@ -200,15 +201,16 @@ void QueuedctlUser::parserAdd(QCommandLineParser &_parser)
|
||||
_parser.addPositionalArgument("name", "User name.", "<name>");
|
||||
|
||||
// permissions
|
||||
QCommandLineOption accessOption(QStringList() << "a"
|
||||
<< "access",
|
||||
"User permission.", "access", "0");
|
||||
QCommandLineOption accessOption({"a", "access"}, "User permission.",
|
||||
"access", "0");
|
||||
_parser.addOption(accessOption);
|
||||
// email
|
||||
QCommandLineOption emailOption(QStringList() << "e"
|
||||
<< "email",
|
||||
"User email.", "email", "");
|
||||
QCommandLineOption emailOption({"e", "email"}, "User email.", "email", "");
|
||||
_parser.addOption(emailOption);
|
||||
// priority
|
||||
QCommandLineOption priorityOption({"p", "priority"}, "User priority.",
|
||||
"priority", "0");
|
||||
_parser.addOption(priorityOption);
|
||||
// password
|
||||
QCommandLineOption passwordOption("password", "User password.", "password",
|
||||
"");
|
||||
@ -276,15 +278,15 @@ void QueuedctlUser::parserSet(QCommandLineParser &_parser)
|
||||
_parser.addPositionalArgument("id", "User ID.", "<id>");
|
||||
|
||||
// email
|
||||
QCommandLineOption emailOption(QStringList() << "e"
|
||||
<< "email",
|
||||
"User email.", "email", "");
|
||||
QCommandLineOption emailOption({"e", "email"}, "User email.", "email", "");
|
||||
_parser.addOption(emailOption);
|
||||
// name
|
||||
QCommandLineOption nameOption(QStringList() << "n"
|
||||
<< "name",
|
||||
"User name.", "name", "");
|
||||
QCommandLineOption nameOption({"n", "name"}, "User name.", "name", "");
|
||||
_parser.addOption(nameOption);
|
||||
// priority
|
||||
QCommandLineOption priorityOption({"p", "priority"}, "User priority.",
|
||||
"priority", "0");
|
||||
_parser.addOption(priorityOption);
|
||||
// password
|
||||
QCommandLineOption passwordOption("password", "User password.", "password",
|
||||
"");
|
||||
|
@ -43,25 +43,18 @@ int main(int argc, char *argv[])
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
// info
|
||||
QCommandLineOption infoOption(QStringList() << "i"
|
||||
<< "info",
|
||||
"Shows additional info.");
|
||||
QCommandLineOption infoOption({"i", "info"}, "Shows additional info.");
|
||||
parser.addOption(infoOption);
|
||||
|
||||
// debug mode
|
||||
QCommandLineOption debugOption(QStringList() << "d"
|
||||
<< "debug",
|
||||
"Prints debug information.");
|
||||
QCommandLineOption debugOption({"d", "debug"}, "Prints debug information.");
|
||||
parser.addOption(debugOption);
|
||||
|
||||
// configuration option
|
||||
QCommandLineOption tokenOption(QStringList() << "t"
|
||||
<< "token",
|
||||
"Path to cached token.", "token",
|
||||
QueuedSettings::defaultTokenPath());
|
||||
QCommandLineOption tokenOption({"t", "token"}, "Path to cached token.",
|
||||
"token", QueuedSettings::defaultTokenPath());
|
||||
parser.addOption(tokenOption);
|
||||
QCommandLineOption userOption(QStringList() << "u"
|
||||
<< "user",
|
||||
QCommandLineOption userOption({"u", "user"},
|
||||
"User to login instead of current one.",
|
||||
"user", ::getlogin());
|
||||
parser.addOption(userOption);
|
||||
|
Loading…
Reference in New Issue
Block a user