mirror of
https://github.com/arcan1s/queued.git
synced 2025-04-24 15:37:19 +00:00
add cgadaptor template
This commit is contained in:
parent
49299af761
commit
0d5e9a328e
@ -100,7 +100,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// check if exists
|
||||
if (existingSessionOperation(QString("Active"))) {
|
||||
if (existingSessionOperation("Active")) {
|
||||
qCWarning(LOG_APP) << "Another session is active";
|
||||
return 1;
|
||||
}
|
||||
|
@ -52,9 +52,8 @@ QVariantHash QueuedTcpServerResponseHelperPermissions::removePermission(
|
||||
if (permission == QueuedEnums::Permission::Invalid)
|
||||
return {{"code", 400}, {"message", "Invalid permission"}};
|
||||
|
||||
return {
|
||||
{"code",
|
||||
QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission, _token)
|
||||
? 200
|
||||
: 400}};
|
||||
return {{"code", QueuedCoreAdaptor::sendUserPermissionRemove(
|
||||
_id, permission, _token)
|
||||
? 200
|
||||
: 400}};
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ namespace QueuedConfig
|
||||
*/
|
||||
const char DBUS_SERVICE[] = DBUS_SERVICE_NAME;
|
||||
/**
|
||||
* @brief DBus object path for applicaiton
|
||||
* @brief DBus object path for application
|
||||
*/
|
||||
const char DBUS_APPLICATION_PATH[] = "/application";
|
||||
/**
|
||||
@ -103,6 +103,12 @@ const char WEBAPI_TOKEN_HEADER[] = "x-queued-token";
|
||||
*/
|
||||
const int WEBAPI_VERSIONS[] = {1};
|
||||
|
||||
// cgroups configuration
|
||||
/**
|
||||
* @brief path to root directory of cgroups
|
||||
*/
|
||||
const char CG_FS_PATH[] = "/sys/fs/cgroup";
|
||||
|
||||
// plugin interfaces
|
||||
/**
|
||||
* @brief plugin interface name
|
||||
|
@ -25,6 +25,7 @@
|
||||
#define QUEUED_H
|
||||
|
||||
#include "QueuedAdvancedSettings.h"
|
||||
#include "QueuedControlGroupsAdaptor.h"
|
||||
#include "QueuedCore.h"
|
||||
#include "QueuedCoreAdaptor.h"
|
||||
#include "QueuedCoreInterface.h"
|
||||
|
142
sources/queued/include/queued/QueuedControlGroupsAdaptor.h
Normal file
142
sources/queued/include/queued/QueuedControlGroupsAdaptor.h
Normal file
@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (c) 2017 Queued team
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
*
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
/**
|
||||
* @file QueuedControlGroupsAdaptor.h
|
||||
* Header of Queued library
|
||||
* @author Queued team
|
||||
* @copyright MIT
|
||||
* @bug https://github.com/arcan1s/queued/issues
|
||||
*/
|
||||
|
||||
|
||||
#ifndef QUEUEDCONTROLGROUPSADAPTOR_H
|
||||
#define QUEUEDCONTROLGROUPSADAPTOR_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
/**
|
||||
* @brief adaptor to control processes by using control groups
|
||||
*/
|
||||
class QueuedControlGroupsAdaptor : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
// static
|
||||
Q_PROPERTY(QStringList controlPaths READ controlPaths)
|
||||
Q_PROPERTY(QString cpuPath READ cpuPath)
|
||||
Q_PROPERTY(QString memoryPath READ memoryPath)
|
||||
// dynamic
|
||||
Q_PROPERTY(QString name READ name)
|
||||
Q_PROPERTY(long long cpuLimit READ cpuLimit WRITE setCpuLimit)
|
||||
Q_PROPERTY(long long memoryLimit READ memoryLimit WRITE setMemoryLimit)
|
||||
|
||||
public:
|
||||
// constants
|
||||
/**
|
||||
* @brief name of file contains processes list
|
||||
*/
|
||||
const char *CG_PROC_FILE = "cgroup.procs";
|
||||
|
||||
/**
|
||||
* @brief QueuedControlGroupsAdaptor class constructor
|
||||
* @param _parent
|
||||
* pointer to parent object
|
||||
* @param _name
|
||||
* control group name
|
||||
*/
|
||||
explicit QueuedControlGroupsAdaptor(QObject *_parent, QString &_name);
|
||||
/**
|
||||
* @brief QueuedControlGroupsAdaptor class destructor
|
||||
*/
|
||||
virtual ~QueuedControlGroupsAdaptor();
|
||||
// static properties
|
||||
/**
|
||||
* @brief paths to all control directories
|
||||
* @return full paths to all known control directories
|
||||
*/
|
||||
static QStringList controlPaths();
|
||||
/**
|
||||
* @brief path to CPU control
|
||||
* @return full path to CPU control directory
|
||||
*/
|
||||
static QString cpuPath();
|
||||
/**
|
||||
* @brief path to memory control
|
||||
* @return full path to memory control directory
|
||||
*/
|
||||
static QString memoryPath();
|
||||
// instance depended properties
|
||||
/**
|
||||
* @brief CPU limit
|
||||
* @return current CPU limit level
|
||||
*/
|
||||
long long cpuLimit() const;
|
||||
/**
|
||||
* @brief memory limit
|
||||
* @return current memory limit level
|
||||
*/
|
||||
long long memoryLimit() const;
|
||||
/**
|
||||
* @brief control group name
|
||||
* @return control group name
|
||||
*/
|
||||
QString name() const;
|
||||
/**
|
||||
* @brief set CPU limit
|
||||
* @param _value
|
||||
* new CPU limit level
|
||||
*/
|
||||
void setCpuLimit(const long long _value);
|
||||
/**
|
||||
* @brief set memory limit
|
||||
* @param _value
|
||||
* new memory limit level
|
||||
*/
|
||||
void setMemoryLimit(const long long _value);
|
||||
// methods
|
||||
/**
|
||||
* @brief assign control group to process
|
||||
* @param _pid
|
||||
* process ID
|
||||
* @param _name
|
||||
* control group name
|
||||
* @return process assignment status
|
||||
*/
|
||||
bool addProcess(const uint _pid);
|
||||
/**
|
||||
* @brief create empty group
|
||||
* @param _name
|
||||
* control group name
|
||||
* @return group creation status
|
||||
*/
|
||||
bool createGroup();
|
||||
/**
|
||||
* @brief remove control group
|
||||
* @param _name
|
||||
* control group name
|
||||
* @return group removal status
|
||||
*/
|
||||
bool removeGroup();
|
||||
|
||||
private:
|
||||
// properties
|
||||
/**
|
||||
* @brief control group name
|
||||
*/
|
||||
QString m_name;
|
||||
};
|
||||
|
||||
|
||||
#endif /* QUEUEDCONTROLGROUPSADAPTOR_H */
|
@ -74,7 +74,7 @@ public:
|
||||
* @return list of records from table
|
||||
*/
|
||||
QList<QVariantHash> get(const QString &_table,
|
||||
const QString &_condition = QString());
|
||||
const QString &_condition = "");
|
||||
/**
|
||||
* @brief get record from table with given id
|
||||
* @param _table
|
||||
|
@ -39,29 +39,29 @@ namespace QueuedDB
|
||||
*/
|
||||
const char SETTINGS_TABLE[] = "settings";
|
||||
/**
|
||||
* @brief tasks table name
|
||||
*/
|
||||
* @brief tasks table name
|
||||
*/
|
||||
const char TASKS_TABLE[] = "tasks";
|
||||
/**
|
||||
* @brief tokens table name
|
||||
*/
|
||||
* @brief tokens table name
|
||||
*/
|
||||
const char TOKENS_TABLE[] = "tokens";
|
||||
/**
|
||||
* @brief users table name
|
||||
*/
|
||||
* @brief users table name
|
||||
*/
|
||||
const char USERS_TABLE[] = "users";
|
||||
/**
|
||||
* @struct QueuedDBField
|
||||
* @brief describes database column
|
||||
* @var QueuedDBField::name
|
||||
* column name
|
||||
* @var QueuedDBField::sqlDescription
|
||||
* description to create column
|
||||
* @var QueuedDBField::type
|
||||
* Qt type of column for cast
|
||||
* @var QueuedDBField::adminField
|
||||
* is admin permissions required to edit or not
|
||||
*/
|
||||
* @struct QueuedDBField
|
||||
* @brief describes database column
|
||||
* @var QueuedDBField::name
|
||||
* column name
|
||||
* @var QueuedDBField::sqlDescription
|
||||
* description to create column
|
||||
* @var QueuedDBField::type
|
||||
* Qt type of column for cast
|
||||
* @var QueuedDBField::adminField
|
||||
* is admin permissions required to edit or not
|
||||
*/
|
||||
typedef struct {
|
||||
QString name;
|
||||
QString sqlDescription;
|
||||
|
@ -58,7 +58,7 @@ public:
|
||||
/**
|
||||
* @brief raise QueuedException
|
||||
*/
|
||||
void raise() const override { throw * this; }
|
||||
void raise() const override { throw *this; }
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -87,9 +87,9 @@ struct Limits {
|
||||
explicit Limits(const QString &_stringLimits)
|
||||
: Limits()
|
||||
{
|
||||
QStringList limits = _stringLimits.split(QChar('\n'));
|
||||
QStringList limits = _stringLimits.split('\n');
|
||||
while (limits.count() < 5)
|
||||
limits.append(QString("0"));
|
||||
limits.append("0");
|
||||
|
||||
cpu = limits.at(0).toLongLong();
|
||||
gpu = limits.at(1).toLongLong();
|
||||
|
@ -117,7 +117,7 @@ QString QueuedAdvancedSettings::internalId(const QString &_key)
|
||||
return internal;
|
||||
}
|
||||
|
||||
return QString();
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@ -135,7 +135,7 @@ QueuedAdvancedSettings::internalId(const QueuedConfig::QueuedSettings _key)
|
||||
return internal;
|
||||
}
|
||||
|
||||
return QString();
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@ -160,8 +160,8 @@ void QueuedAdvancedSettings::set(const QList<QVariantHash> &_values)
|
||||
qCDebug(LOG_LIB) << "Set values from" << _values;
|
||||
|
||||
for (auto &pair : _values) {
|
||||
QString key = pair[QString("key")].toString().toLower();
|
||||
m_ids[key] = pair[QString("_id")].toLongLong();
|
||||
set(key, pair[QString("value")]);
|
||||
QString key = pair["key"].toString().toLower();
|
||||
m_ids[key] = pair["_id"].toLongLong();
|
||||
set(key, pair["value"]);
|
||||
}
|
||||
}
|
||||
|
232
sources/queued/src/QueuedControlGroupsAdaptor.cpp
Normal file
232
sources/queued/src/QueuedControlGroupsAdaptor.cpp
Normal file
@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright (c) 2017 Queued team
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
*
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
/**
|
||||
* @file QueuedControlGroupsAdaptor.cpp
|
||||
* Source code of queued library
|
||||
* @author Queued team
|
||||
* @copyright GPLv3
|
||||
* @bug https://github.com/arcan1s/queued/issues
|
||||
*/
|
||||
|
||||
|
||||
#include <queued/Queued.h>
|
||||
|
||||
#include <QDir>
|
||||
|
||||
|
||||
/**
|
||||
* @class QueuedControlGroupsAdaptor
|
||||
*/
|
||||
/**
|
||||
* @fn QueuedControlGroupsAdaptor
|
||||
*/
|
||||
QueuedControlGroupsAdaptor::QueuedControlGroupsAdaptor(QObject *_parent,
|
||||
QString &_name)
|
||||
: QObject(_parent)
|
||||
, m_name(_name)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
createGroup();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn ~QueuedControlGroupsAdaptor
|
||||
*/
|
||||
QueuedControlGroupsAdaptor::~QueuedControlGroupsAdaptor()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
|
||||
removeGroup();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn controlPaths
|
||||
*/
|
||||
QStringList QueuedControlGroupsAdaptor::controlPaths()
|
||||
{
|
||||
return {cpuPath(), memoryPath()};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn cpuPath
|
||||
*/
|
||||
QString QueuedControlGroupsAdaptor::cpuPath()
|
||||
{
|
||||
return QDir(QueuedConfig::CG_FS_PATH).filePath("cpu");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn memoryPath
|
||||
*/
|
||||
QString QueuedControlGroupsAdaptor::memoryPath()
|
||||
{
|
||||
return QDir(QueuedConfig::CG_FS_PATH).filePath("memory");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn cpuLimit
|
||||
*/
|
||||
long long QueuedControlGroupsAdaptor::cpuLimit() const
|
||||
{
|
||||
QFile file(QDir(cpuPath()).filePath("cpu.cfs_quota_us"));
|
||||
|
||||
long long limit = 0;
|
||||
if (file.open(QIODevice::ReadOnly | QFile::Text)) {
|
||||
QTextStream stream(&file);
|
||||
limit = stream.readAll().toLongLong();
|
||||
} else {
|
||||
qCCritical(LOG_LIB) << "Could not get CPU limit" << name();
|
||||
return 0;
|
||||
}
|
||||
file.close();
|
||||
|
||||
return limit * QueuedSystemInfo::cpuCount() / 1000;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn memoryLimit
|
||||
*/
|
||||
long long QueuedControlGroupsAdaptor::memoryLimit() const
|
||||
{
|
||||
QFile file(QDir(memoryPath()).filePath("memory.limit_in_bytes"));
|
||||
|
||||
long long limit = 0;
|
||||
if (file.open(QIODevice::ReadOnly | QFile::Text)) {
|
||||
QTextStream stream(&file);
|
||||
limit = stream.readAll().toLongLong();
|
||||
} else {
|
||||
qCCritical(LOG_LIB) << "Could not get memory limit" << name();
|
||||
return 0;
|
||||
}
|
||||
file.close();
|
||||
|
||||
return limit;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn name
|
||||
*/
|
||||
QString QueuedControlGroupsAdaptor::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn setCpuLimit
|
||||
*/
|
||||
void QueuedControlGroupsAdaptor::setCpuLimit(const long long _value)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set new CPU limit to" << _value;
|
||||
|
||||
QFile file(QDir(cpuPath()).filePath("cpu.cfs_quota_us"));
|
||||
|
||||
if (file.open(QIODevice::ReadWrite)) {
|
||||
QTextStream stream(&file);
|
||||
stream << _value;
|
||||
} else {
|
||||
qCCritical(LOG_LIB)
|
||||
<< "Could not set CPU limit" << name() << "to" << _value;
|
||||
return;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn setMemoryLimit
|
||||
*/
|
||||
void QueuedControlGroupsAdaptor::setMemoryLimit(const long long _value)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set new memory limit to" << _value;
|
||||
|
||||
QFile file(QDir(cpuPath()).filePath("memory.limit_in_bytes"));
|
||||
|
||||
if (file.open(QIODevice::ReadWrite)) {
|
||||
QTextStream stream(&file);
|
||||
stream << _value;
|
||||
} else {
|
||||
qCCritical(LOG_LIB)
|
||||
<< "Could not set memory limit" << name() << "to" << _value;
|
||||
return;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn assignGroup
|
||||
*/
|
||||
bool QueuedControlGroupsAdaptor::addProcess(const uint _pid)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Assign add process" << _pid;
|
||||
|
||||
for (auto &path : controlPaths()) {
|
||||
auto proc = QDir(QDir(path).filePath(name())).filePath(CG_PROC_FILE);
|
||||
QFile file(proc);
|
||||
|
||||
if (file.open(QIODevice::ReadWrite)) {
|
||||
QTextStream stream(&file);
|
||||
stream << _pid;
|
||||
} else {
|
||||
qCCritical(LOG_LIB)
|
||||
<< "Cound not assign pid" << _pid << "to" << proc;
|
||||
return false;
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn createGroup
|
||||
*/
|
||||
bool QueuedControlGroupsAdaptor::createGroup()
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Create empty group";
|
||||
|
||||
auto paths = controlPaths();
|
||||
|
||||
return std::all_of(
|
||||
paths.cbegin(), paths.cend(),
|
||||
[this](const QString &path) { return QDir(path).mkpath(name()); });
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn removeGroup
|
||||
*/
|
||||
bool QueuedControlGroupsAdaptor::removeGroup()
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Remove group";
|
||||
|
||||
auto paths = controlPaths();
|
||||
|
||||
return std::all_of(
|
||||
paths.cbegin(), paths.cend(), [this](const QString &path) {
|
||||
return QDir(QDir(path).filePath(name())).removeRecursively();
|
||||
});
|
||||
}
|
@ -602,12 +602,13 @@ void QueuedCore::init(const QString &_configuration)
|
||||
initProcesses();
|
||||
|
||||
// settings update notifier
|
||||
m_connections += connect(
|
||||
m_advancedSettings,
|
||||
SIGNAL(valueUpdated(const QueuedConfig::QueuedSettings, const QString &,
|
||||
const QVariant &)),
|
||||
this, SLOT(updateSettings(const QueuedConfig::QueuedSettings,
|
||||
const QString &, const QVariant &)));
|
||||
m_connections
|
||||
+= connect(m_advancedSettings,
|
||||
SIGNAL(valueUpdated(const QueuedConfig::QueuedSettings,
|
||||
const QString &, const QVariant &)),
|
||||
this,
|
||||
SLOT(updateSettings(const QueuedConfig::QueuedSettings,
|
||||
const QString &, const QVariant &)));
|
||||
|
||||
// dbus session
|
||||
initDBus();
|
||||
@ -671,7 +672,7 @@ void QueuedCore::updateSettings(const QueuedConfig::QueuedSettings _id,
|
||||
|
||||
|
||||
/**
|
||||
* @fn updateTaskTime
|
||||
* @fn updateTaskTime
|
||||
*/
|
||||
void QueuedCore::updateTaskTime(const long long _id,
|
||||
const QDateTime &_startTime,
|
||||
@ -682,12 +683,12 @@ void QueuedCore::updateTaskTime(const long long _id,
|
||||
|
||||
QVariantHash record;
|
||||
if (_startTime.isValid()) {
|
||||
record[QString("startTime")] = _startTime.toString(Qt::ISODateWithMs);
|
||||
record["startTime"] = _startTime.toString(Qt::ISODateWithMs);
|
||||
if (m_plugins)
|
||||
emit(m_plugins->interface()->onStartTask(_id));
|
||||
}
|
||||
if (_endTime.isValid()) {
|
||||
record[QString("endTime")] = _endTime.toString(Qt::ISODateWithMs);
|
||||
record["endTime"] = _endTime.toString(Qt::ISODateWithMs);
|
||||
if (m_plugins)
|
||||
emit(m_plugins->interface()->onStopTask(_id));
|
||||
}
|
||||
@ -807,8 +808,8 @@ void QueuedCore::initProcesses()
|
||||
.toString();
|
||||
|
||||
m_processes = new QueuedProcessManager(this, processLine, onExitAction);
|
||||
auto dbProcesses = m_database->get(QueuedDB::TASKS_TABLE,
|
||||
QString("WHERE endTime IS NULL"));
|
||||
auto dbProcesses
|
||||
= m_database->get(QueuedDB::TASKS_TABLE, "WHERE endTime IS NULL");
|
||||
m_processes->loadProcesses(dbProcesses);
|
||||
|
||||
m_connections
|
||||
@ -837,7 +838,7 @@ void QueuedCore::initSettings(const QString &_configuration)
|
||||
bool status = m_database->open(dbSetup.hostname, dbSetup.port,
|
||||
dbSetup.username, dbSetup.password);
|
||||
if (!status) {
|
||||
QString message = QString("Could not open database");
|
||||
QString message = "Could not open database";
|
||||
qCCritical(LOG_LIB) << message;
|
||||
throw QueuedDatabaseException(message);
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ bool QueuedCoreAdaptor::sendUserEdit(
|
||||
|
||||
|
||||
/**
|
||||
* sendUserPermissionAdd
|
||||
* @fn sendUserPermissionAdd
|
||||
*/
|
||||
bool QueuedCoreAdaptor::sendUserPermissionAdd(
|
||||
const long long _id, const QueuedEnums::Permission _permission,
|
||||
@ -280,7 +280,7 @@ bool QueuedCoreAdaptor::sendUserPermissionAdd(
|
||||
|
||||
|
||||
/**
|
||||
* sendUserPermissionRemove
|
||||
* @fn sendUserPermissionRemove
|
||||
*/
|
||||
bool QueuedCoreAdaptor::sendUserPermissionRemove(
|
||||
const long long _id, const QueuedEnums::Permission _permission,
|
||||
|
@ -135,19 +135,19 @@ bool QueuedCoreInterface::TaskEdit(
|
||||
// build payload
|
||||
QVariantHash data;
|
||||
if (!command.isEmpty())
|
||||
data[QString("command")] = command;
|
||||
data["command"] = command;
|
||||
if (!arguments.isEmpty())
|
||||
data[QString("arguments")] = arguments;
|
||||
data["arguments"] = arguments;
|
||||
if (!directory.isEmpty())
|
||||
data[QString("directory")] = directory;
|
||||
data["directory"] = directory;
|
||||
if (nice > 0)
|
||||
data[QString("nice")] = nice;
|
||||
data["nice"] = nice;
|
||||
if (uid > 0)
|
||||
data[QString("uid")] = uid;
|
||||
data["uid"] = uid;
|
||||
if (gid > 0)
|
||||
data[QString("gid")] = gid;
|
||||
data["gid"] = gid;
|
||||
if (user > 0)
|
||||
data[QString("user")] = user;
|
||||
data["user"] = user;
|
||||
// append limits now
|
||||
auto limits = task->nativeLimits();
|
||||
if (cpu > -1)
|
||||
@ -160,7 +160,7 @@ bool QueuedCoreInterface::TaskEdit(
|
||||
limits.gpumemory = gpumemory;
|
||||
if (storage > -1)
|
||||
limits.storage = storage;
|
||||
data[QString("limits")] = limits.toString();
|
||||
data["limits"] = limits.toString();
|
||||
|
||||
return m_core->editTask(id, data, token);
|
||||
}
|
||||
@ -240,11 +240,11 @@ bool QueuedCoreInterface::UserEdit(const qlonglong id, const QString &name,
|
||||
// build payload
|
||||
QVariantHash data;
|
||||
if (!name.isEmpty())
|
||||
data[QString("name")] = name;
|
||||
data["name"] = name;
|
||||
if (!password.isEmpty())
|
||||
data[QString("password")] = password;
|
||||
data["password"] = password;
|
||||
if (!email.isEmpty())
|
||||
data[QString("email")] = email;
|
||||
data["email"] = email;
|
||||
// append limits now
|
||||
auto limits = user->nativeLimits();
|
||||
if (cpu > -1)
|
||||
@ -257,7 +257,7 @@ bool QueuedCoreInterface::UserEdit(const qlonglong id, const QString &name,
|
||||
limits.gpumemory = gpumemory;
|
||||
if (storage > -1)
|
||||
limits.storage = storage;
|
||||
data[QString("limits")] = limits.toString();
|
||||
data["limits"] = limits.toString();
|
||||
|
||||
return m_core->editUser(id, data, token);
|
||||
}
|
||||
|
@ -201,11 +201,10 @@ long long QueuedDatabase::add(const QString &_table, const QVariantHash &_value)
|
||||
|
||||
auto payload = getQueryPayload(_table, _value);
|
||||
// build query
|
||||
QSqlQuery query
|
||||
= m_database.exec(QString("INSERT INTO %1 (%2) VALUES (%3)")
|
||||
.arg(_table)
|
||||
.arg(payload.first.join(QChar(',')))
|
||||
.arg(payload.second.join(QChar(','))));
|
||||
QSqlQuery query = m_database.exec(QString("INSERT INTO %1 (%2) VALUES (%3)")
|
||||
.arg(_table)
|
||||
.arg(payload.first.join(','))
|
||||
.arg(payload.second.join(',')));
|
||||
QSqlError error = query.lastError();
|
||||
if (error.isValid()) {
|
||||
qCCritical(LOG_LIB) << "Could not add record" << _value << "to table"
|
||||
@ -235,7 +234,7 @@ bool QueuedDatabase::modify(const QString &_table, const long long _id,
|
||||
// build query
|
||||
QSqlQuery query = m_database.exec(QString("UPDATE %1 SET %2 WHERE _id=%3")
|
||||
.arg(_table)
|
||||
.arg(stringPayload.join(QChar(',')))
|
||||
.arg(stringPayload.join(','))
|
||||
.arg(_id));
|
||||
QSqlError error = query.lastError();
|
||||
if (error.isValid()) {
|
||||
@ -434,7 +433,7 @@ QueuedDatabase::getQueryPayload(const QString &_table,
|
||||
<< "No key" << key << "found in schema of" << _table;
|
||||
continue;
|
||||
}
|
||||
if (key == QString("_id")) {
|
||||
if (key == "_id") {
|
||||
qCWarning(LOG_LIB) << "Modifying record ID is not allowed";
|
||||
continue;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ void QueuedDebug::applyLogFormat()
|
||||
*/
|
||||
void QueuedDebug::enableDebug()
|
||||
{
|
||||
QLoggingCategory::setFilterRules(QString("org.queued.*=true"));
|
||||
QLoggingCategory::setFilterRules("org.queued.*=true");
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,14 +30,12 @@
|
||||
long long QueuedLimits::convertMemory(QString _value, bool *_status)
|
||||
{
|
||||
long long intValue;
|
||||
if (_value.endsWith(QString("K")))
|
||||
intValue = _value.remove(QString("K")).toLongLong(_status) * 1024;
|
||||
else if (_value.endsWith(QString("M")))
|
||||
intValue
|
||||
= _value.remove(QString("M")).toLongLong(_status) * 1024 * 1024;
|
||||
else if (_value.endsWith(QString("G")))
|
||||
intValue = _value.remove(QString("G")).toLongLong(_status) * 1024 * 1024
|
||||
* 1024;
|
||||
if (_value.endsWith("K"))
|
||||
intValue = _value.remove("K").toLongLong(_status) * 1024;
|
||||
else if (_value.endsWith("M"))
|
||||
intValue = _value.remove("M").toLongLong(_status) * 1024 * 1024;
|
||||
else if (_value.endsWith("G"))
|
||||
intValue = _value.remove("G").toLongLong(_status) * 1024 * 1024 * 1024;
|
||||
else
|
||||
intValue = _value.toInt(_status);
|
||||
|
||||
|
@ -80,10 +80,9 @@ void QueuedProcess::updateArguments()
|
||||
|
||||
// replace limits now
|
||||
application.replace(
|
||||
"{cpu}",
|
||||
QString("%1").arg(QueuedSystemInfo::cpuWeight(nativeLimits().cpu)
|
||||
* 100.0,
|
||||
0, 'f', 0));
|
||||
"{cpu}", QString("%1").arg(
|
||||
QueuedSystemInfo::cpuWeight(nativeLimits().cpu) * 100.0, 0,
|
||||
'f', 0));
|
||||
application.replace(
|
||||
"{memory}",
|
||||
QString("%1").arg(QueuedSystemInfo::memoryWeight(nativeLimits().memory)
|
||||
|
@ -69,21 +69,20 @@ QueuedProcess *QueuedProcessManager::add(const QVariantHash &_properties,
|
||||
|
||||
QueuedProcess::QueuedProcessDefinitions defs;
|
||||
// parameters
|
||||
defs.command = _properties[QString("command")].toString();
|
||||
defs.arguments = _properties[QString("commandArguments")].toString().split(
|
||||
QChar('\n'));
|
||||
defs.workingDirectory = _properties[QString("workDirectory")].toString();
|
||||
defs.nice = _properties[QString("nice")].toUInt();
|
||||
defs.limits = _properties[QString("limits")].toString();
|
||||
defs.command = _properties["command"].toString();
|
||||
defs.arguments = _properties["commandArguments"].toString().split('\n');
|
||||
defs.workingDirectory = _properties["workDirectory"].toString();
|
||||
defs.nice = _properties["nice"].toUInt();
|
||||
defs.limits = _properties["limits"].toString();
|
||||
// user data
|
||||
defs.uid = _properties[QString("uid")].toUInt();
|
||||
defs.gid = _properties[QString("gid")].toUInt();
|
||||
defs.user = _properties[QString("user")].toLongLong();
|
||||
defs.uid = _properties["uid"].toUInt();
|
||||
defs.gid = _properties["gid"].toUInt();
|
||||
defs.user = _properties["user"].toLongLong();
|
||||
// metadata
|
||||
defs.startTime = QDateTime::fromString(
|
||||
_properties[QString("startTime")].toString(), Qt::ISODateWithMs);
|
||||
defs.endTime = QDateTime::fromString(
|
||||
_properties[QString("endTime")].toString(), Qt::ISODateWithMs);
|
||||
defs.startTime = QDateTime::fromString(_properties["startTime"].toString(),
|
||||
Qt::ISODateWithMs);
|
||||
defs.endTime = QDateTime::fromString(_properties["endTime"].toString(),
|
||||
Qt::ISODateWithMs);
|
||||
|
||||
return add(defs, _index);
|
||||
}
|
||||
@ -107,8 +106,9 @@ QueuedProcess *QueuedProcessManager::add(
|
||||
m_processes[_index] = process;
|
||||
// connect to signal
|
||||
m_connections[_index] = connect(
|
||||
process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(
|
||||
&QProcess::finished),
|
||||
process,
|
||||
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(
|
||||
&QProcess::finished),
|
||||
[=](const int exitCode, const QProcess::ExitStatus exitStatus) {
|
||||
return taskFinished(exitCode, exitStatus, _index);
|
||||
});
|
||||
@ -127,7 +127,7 @@ void QueuedProcessManager::loadProcesses(const QList<QVariantHash> &_processes)
|
||||
qCDebug(LOG_LIB) << "Add tasks from" << _processes;
|
||||
|
||||
for (auto &processData : _processes)
|
||||
add(processData, processData[QString("_id")].toLongLong());
|
||||
add(processData, processData["_id"].toLongLong());
|
||||
}
|
||||
|
||||
|
||||
@ -235,6 +235,7 @@ void QueuedProcessManager::start(const long long _index)
|
||||
|
||||
QDateTime start = QDateTime::currentDateTimeUtc();
|
||||
pr->start();
|
||||
// emit start time
|
||||
pr->setStartTime(start);
|
||||
emit(taskStartTimeReceived(_index, start));
|
||||
}
|
||||
|
@ -80,8 +80,8 @@ QueuedConfig::QueuedDBSetup QueuedSettings::db() const
|
||||
*/
|
||||
QString QueuedSettings::defaultPath()
|
||||
{
|
||||
QString fileName = QStandardPaths::locate(QStandardPaths::ConfigLocation,
|
||||
QString("queued.ini"));
|
||||
QString fileName
|
||||
= QStandardPaths::locate(QStandardPaths::ConfigLocation, "queued.ini");
|
||||
qCInfo(LOG_LIB) << "Found configuration file" << fileName;
|
||||
|
||||
return fileName;
|
||||
|
@ -59,7 +59,7 @@ QString QueuedTokenManager::isTokenValid(const QString &_token) const
|
||||
&& (tokenExpiration(_token) > QDateTime::currentDateTimeUtc()))
|
||||
return m_tokens[_token].user;
|
||||
else
|
||||
return QString();
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@ -95,9 +95,9 @@ void QueuedTokenManager::loadTokens(const QList<QVariantHash> &_values)
|
||||
|
||||
for (auto &token : _values) {
|
||||
QDateTime validUntil = QDateTime::fromString(
|
||||
token[QString("validUntil")].toString(), Qt::ISODateWithMs);
|
||||
loadToken({token[QString("token")].toString(),
|
||||
token[QString("user")].toString(), validUntil});
|
||||
token["validUntil"].toString(), Qt::ISODateWithMs);
|
||||
loadToken(
|
||||
{token["token"].toString(), token["user"].toString(), validUntil});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,11 +60,11 @@ QueuedUser *QueuedUserManager::add(const QVariantHash &_properties,
|
||||
qCDebug(LOG_LIB) << "Add user" << _properties << "with ID" << _id;
|
||||
|
||||
QueuedUser::QueuedUserDefinitions defs;
|
||||
defs.name = _properties[QString("name")].toString();
|
||||
defs.email = _properties[QString("email")].toString();
|
||||
defs.password = _properties[QString("password")].toString();
|
||||
defs.permissions = _properties[QString("permissions")].toUInt();
|
||||
defs.limits = _properties[QString("limits")].toString();
|
||||
defs.name = _properties["name"].toString();
|
||||
defs.email = _properties["email"].toString();
|
||||
defs.password = _properties["password"].toString();
|
||||
defs.permissions = _properties["permissions"].toUInt();
|
||||
defs.limits = _properties["limits"].toString();
|
||||
|
||||
return add(defs, _id);
|
||||
}
|
||||
@ -116,13 +116,13 @@ QString QueuedUserManager::authorize(const QString &_user,
|
||||
auto userObj = user(_user, false);
|
||||
if (!userObj) {
|
||||
qCInfo(LOG_LIB) << "No user found" << _user;
|
||||
return QString();
|
||||
return "";
|
||||
}
|
||||
|
||||
bool status = userObj->isPasswordValid(_password);
|
||||
if (!status) {
|
||||
qCInfo(LOG_LIB) << "User password invalid for" << _user;
|
||||
return QString();
|
||||
return "";
|
||||
}
|
||||
|
||||
auto time = QDateTime::currentDateTimeUtc();
|
||||
@ -208,7 +208,7 @@ void QueuedUserManager::loadUsers(const QList<QVariantHash> &_users)
|
||||
|
||||
// load now
|
||||
for (auto &userData : _users)
|
||||
add(userData, userData[QString("_id")].toLongLong());
|
||||
add(userData, userData["_id"].toLongLong());
|
||||
}
|
||||
|
||||
|
||||
|
@ -47,9 +47,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,
|
||||
|
@ -122,7 +122,7 @@ void QueuedctlCommon::preprocess(const QStringList &_args,
|
||||
{
|
||||
qCDebug(LOG_APP) << "Preprocess command" << _args;
|
||||
|
||||
QString command = _args.isEmpty() ? QString() : _args.first();
|
||||
QString command = _args.isEmpty() ? "" : _args.first();
|
||||
// HACK: workaround to show valid help message
|
||||
auto id = QueuedctlArguments.contains(command)
|
||||
? QueuedctlArguments[command].id
|
||||
@ -212,7 +212,7 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
|
||||
auto result = QueuedctlResult();
|
||||
QStringList args = _parser.positionalArguments();
|
||||
QString command = args.isEmpty() ? QString() : args.first();
|
||||
QString command = args.isEmpty() ? "" : args.first();
|
||||
|
||||
auto id = QueuedctlArguments.contains(command)
|
||||
? QueuedctlArguments[command].id
|
||||
@ -321,7 +321,7 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
if (result.status)
|
||||
result.output = QString("Task %1 added").arg(taskId);
|
||||
else
|
||||
result.output = QString("Could not add task");
|
||||
result.output = "Could not add task";
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::TaskGet: {
|
||||
@ -365,7 +365,7 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
if (result.status)
|
||||
result.output = QString("User %1 added").arg(userId);
|
||||
else
|
||||
result.output = QString("Could not add user");
|
||||
result.output = "Could not add user";
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::UserGet: {
|
||||
|
Loading…
Reference in New Issue
Block a user