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