mirror of
https://github.com/arcan1s/queued.git
synced 2025-04-24 15:37:19 +00:00
replace unsigned int to uint, add coreinterface class
This commit is contained in:
parent
de3d7c10c3
commit
6646400027
@ -27,6 +27,8 @@
|
||||
#include "QueuedAdvancedSettings.h"
|
||||
#include "QueuedConfiguration.h"
|
||||
#include "QueuedCore.h"
|
||||
#include "QueuedCoreAdaptor.h"
|
||||
#include "QueuedCoreInterface.h"
|
||||
#include "QueuedDatabase.h"
|
||||
#include "QueuedDebug.h"
|
||||
#include "QueuedEnums.h"
|
||||
|
@ -74,7 +74,7 @@ public:
|
||||
* @return true on successfully addition
|
||||
*/
|
||||
bool addTask(const QString &_command, const QStringList &_arguments,
|
||||
const QString &_workingDirectory, const unsigned int _nice,
|
||||
const QString &_workingDirectory, const uint _nice,
|
||||
const long long _userId, const QueuedLimits::Limits &_limits,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth);
|
||||
/**
|
||||
@ -94,7 +94,7 @@ public:
|
||||
* @return true on successfully addition
|
||||
*/
|
||||
bool addUser(const QString &_name, const QString &_email,
|
||||
const QString &_password, const unsigned int _permissions,
|
||||
const QString &_password, const uint _permissions,
|
||||
const QueuedLimits::Limits &_limits,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth);
|
||||
/**
|
||||
@ -194,7 +194,8 @@ public:
|
||||
* @brief init subclasses
|
||||
* @param _configuration
|
||||
* path to configuration file
|
||||
* @throws QueuedDatabaseException
|
||||
* @throw QueuedDatabaseException
|
||||
* @throw QueuedDBusException
|
||||
*/
|
||||
void init(const QString &_configuration);
|
||||
|
||||
@ -267,6 +268,11 @@ private:
|
||||
*/
|
||||
QVariantHash dropAdminFields(const QString &_table,
|
||||
const QVariantHash &_payload);
|
||||
/**
|
||||
* @brief init DBus interface
|
||||
* @throw QueuedDBusException
|
||||
*/
|
||||
void initDBus();
|
||||
/**
|
||||
* @brief init processes
|
||||
*/
|
||||
@ -275,6 +281,7 @@ private:
|
||||
* @brief init settings and database
|
||||
* @param _configuration
|
||||
* path to configuration file
|
||||
* @throw QueuedDatabaseException
|
||||
*/
|
||||
void initSettings(const QString &_configuration);
|
||||
/**
|
||||
|
53
sources/queued/include/queued/QueuedCoreAdaptor.h
Normal file
53
sources/queued/include/queued/QueuedCoreAdaptor.h
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Evgeniy Alekseev
|
||||
*
|
||||
* 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 QueuedCoreAdaptor.h
|
||||
* Header of Queued library
|
||||
* @author Evgeniy Alekseev
|
||||
* @copyright MIT
|
||||
* @bug https://github.com/arcan1s/queued/issues
|
||||
*/
|
||||
|
||||
|
||||
#ifndef QUEUEDCOREADAPTOR_H
|
||||
#define QUEUEDCOREADAPTOR_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
/**
|
||||
* @brief DBus adaptor for core interface
|
||||
*/
|
||||
class QueuedCoreAdaptor : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief QueuedCoreAdaptor class constructor
|
||||
* @param parent
|
||||
* pointer to parent item
|
||||
*/
|
||||
explicit QueuedCoreAdaptor(QObject *parent);
|
||||
/**
|
||||
* @brief QueuedCoreAdaptor class destructor
|
||||
*/
|
||||
virtual ~QueuedCoreAdaptor();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif /* QUEUEDCOREADAPTOR_H */
|
234
sources/queued/include/queued/QueuedCoreInterface.h
Normal file
234
sources/queued/include/queued/QueuedCoreInterface.h
Normal file
@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Evgeniy Alekseev
|
||||
*
|
||||
* 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 QueuedCoreInterface.h
|
||||
* Header of Queued library
|
||||
* @author Evgeniy Alekseev
|
||||
* @copyright MIT
|
||||
* @bug https://github.com/arcan1s/queued/issues
|
||||
*/
|
||||
|
||||
|
||||
#ifndef QUEUEDCOREINTERFACE_H
|
||||
#define QUEUEDCOREINTERFACE_H
|
||||
|
||||
#include <QDBusAbstractAdaptor>
|
||||
#include <QDBusVariant>
|
||||
|
||||
#include "QueuedConfig.h"
|
||||
|
||||
|
||||
class QueuedCore;
|
||||
|
||||
/**
|
||||
* @brief DBus interface for QueuedCore class
|
||||
*/
|
||||
class QueuedCoreInterface : public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", DBUS_SERVICE_NAME)
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief QueuedCoreInterface class constructor
|
||||
* @param parent
|
||||
* pointer to QueuedCore object
|
||||
*/
|
||||
explicit QueuedCoreInterface(QueuedCore *parent);
|
||||
/**
|
||||
* @brief QueuedCoreInterface class destructor
|
||||
*/
|
||||
virtual ~QueuedCoreInterface();
|
||||
|
||||
public slots:
|
||||
/**
|
||||
* @brief auth user by password
|
||||
* @param name
|
||||
* user name
|
||||
* @param password
|
||||
* user password
|
||||
* @return generated token ID or empty string in case of invalid password
|
||||
*/
|
||||
QString Auth(const QString &name, const QString &password);
|
||||
/**
|
||||
* @brief edit option
|
||||
* @param key
|
||||
* option key to edit
|
||||
* @param value
|
||||
* option value to edit
|
||||
* @param whoAmI
|
||||
* auth user name
|
||||
* @param token
|
||||
* auth user token
|
||||
* @return true on successful option edition
|
||||
*/
|
||||
bool OptionEdit(const QString &key, const QDBusVariant &value,
|
||||
const QString &whoAmI, const QString &token);
|
||||
/**
|
||||
* @brief add new task
|
||||
* @param command
|
||||
* command line
|
||||
* @param arguments
|
||||
* command line arguments
|
||||
* @param workingDirectory
|
||||
* working directory
|
||||
* @param nice
|
||||
* nice level
|
||||
* @param user
|
||||
* user ID
|
||||
* @param cpu
|
||||
* limit by CPU cores
|
||||
* @param gpu
|
||||
* limit by GPU cores
|
||||
* @param memory
|
||||
* limit by memory
|
||||
* @param gpumemory
|
||||
* limit by GPU memory
|
||||
* @param storage
|
||||
* limit by storage
|
||||
* @param whoAmI
|
||||
* auth user name
|
||||
* @param token
|
||||
* auth user token
|
||||
* @return true on successful task addition
|
||||
*/
|
||||
bool TaskAdd(const QString &command, const QStringList &arguments,
|
||||
const QString &workingDirectory, const uint nice,
|
||||
const long long user, const long long cpu, const long long gpu,
|
||||
const QString &memory, const QString &gpumemory,
|
||||
const QString &storage, const QString &whoAmI,
|
||||
const QString &token);
|
||||
/**
|
||||
* @brief edit task
|
||||
* @param id
|
||||
* task ID
|
||||
* @param data
|
||||
* new task data
|
||||
* @param whoAmI
|
||||
* auth user name
|
||||
* @param token
|
||||
* auth user token
|
||||
* @return true on successful task edition
|
||||
*/
|
||||
bool TaskEdit(const qlonglong id, const QDBusVariant &data,
|
||||
const QString &whoAmI, const QString &token);
|
||||
/**
|
||||
* @brief force start task
|
||||
* @param id
|
||||
* task ID
|
||||
* @param whoAmI
|
||||
* auth user name
|
||||
* @param token
|
||||
* auth user token
|
||||
* @return true on successful task start
|
||||
*/
|
||||
bool TaskStart(const qlonglong id, const QString &whoAmI,
|
||||
const QString &token);
|
||||
/**
|
||||
* @brief force stop task
|
||||
* @param id
|
||||
* task ID
|
||||
* @param whoAmI
|
||||
* auth user name
|
||||
* @param token
|
||||
* auth user token
|
||||
* @return true on successful task stop
|
||||
*/
|
||||
bool TaskStop(const qlonglong id, const QString &whoAmI,
|
||||
const QString &token);
|
||||
/**
|
||||
* @brief add new user
|
||||
* @param name
|
||||
* user name
|
||||
* @param email
|
||||
* user email
|
||||
* @param password
|
||||
* user password
|
||||
* @param permissions
|
||||
* user permissions
|
||||
* @param cpu
|
||||
* limit by CPU cores
|
||||
* @param gpu
|
||||
* limit by GPU cores
|
||||
* @param memory
|
||||
* limit by memory
|
||||
* @param gpumemory
|
||||
* limit by GPU memory
|
||||
* @param storage
|
||||
* limit by storage
|
||||
* @param whoAmI
|
||||
* auth user name
|
||||
* @param token
|
||||
* auth user token
|
||||
* @return true on successful task addition
|
||||
*/
|
||||
bool UserAdd(const QString &name, const QString &email,
|
||||
const QString &password, const uint permissions,
|
||||
const long long cpu, const long long gpu,
|
||||
const QString &memory, const QString &gpumemory,
|
||||
const QString &storage, const QString &whoAmI,
|
||||
const QString &token);
|
||||
/**
|
||||
* @brief edit user
|
||||
* @param id
|
||||
* user ID
|
||||
* @param data
|
||||
* new user data
|
||||
* @param whoAmI
|
||||
* auth user name
|
||||
* @param token
|
||||
* auth user token
|
||||
* @return true on successful user edition
|
||||
*/
|
||||
bool UserEdit(const qlonglong id, const QDBusVariant &data,
|
||||
const QString &whoAmI, const QString &token);
|
||||
/**
|
||||
* @brief add permission to user
|
||||
* @param id
|
||||
* user ID
|
||||
* @param permission
|
||||
* permission to add
|
||||
* @param whoAmI
|
||||
* auth user name
|
||||
* @param token
|
||||
* auth user token
|
||||
* @return true on successful permission addition
|
||||
*/
|
||||
bool UserPermissionAdd(const qlonglong id, const uint permission,
|
||||
const QString &whoAmI, const QString &token);
|
||||
/**
|
||||
* @brief remove permission from user
|
||||
* @param id
|
||||
* user ID
|
||||
* @param permission
|
||||
* permission to remove
|
||||
* @param whoAmI
|
||||
* auth user name
|
||||
* @param token
|
||||
* auth user token
|
||||
* @return true on successful permission removal
|
||||
*/
|
||||
bool UserPermissionRemove(const qlonglong id, const uint permission,
|
||||
const QString &whoAmI, const QString &token);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief pointer to database object
|
||||
*/
|
||||
QueuedCore *m_core = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif /* QUEUEDCOREINTERFACE_H */
|
@ -65,4 +65,42 @@ private:
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief DBus operation exception
|
||||
*/
|
||||
class QueuedDBusException : public QException
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief QueuedDBusException class constructor
|
||||
* @param message
|
||||
* exception message
|
||||
*/
|
||||
QueuedDBusException(const QString &message)
|
||||
: m_message(message){};
|
||||
/**
|
||||
* @brief clone QueuedDBusException
|
||||
*/
|
||||
QueuedDBusException *clone() const
|
||||
{
|
||||
return new QueuedDBusException(*this);
|
||||
};
|
||||
/**
|
||||
* @brief message of this exception
|
||||
* @return message for logging, etc
|
||||
*/
|
||||
QString message() const { return m_message; };
|
||||
/**
|
||||
* @brief raise QueuedDBusException
|
||||
*/
|
||||
void raise() const { throw * this; }
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief exception message
|
||||
*/
|
||||
QString m_message;
|
||||
};
|
||||
|
||||
|
||||
#endif /* QUEUEDEXCEPTIONS_H */
|
||||
|
@ -44,12 +44,12 @@ class QueuedProcess : public QProcess
|
||||
Q_PROPERTY(QStringList commandArguments READ commandArguments WRITE
|
||||
setCommandArguments)
|
||||
Q_PROPERTY(QDateTime endTime READ endTime WRITE setEndTime)
|
||||
Q_PROPERTY(unsigned int gid READ uid WRITE setGid)
|
||||
Q_PROPERTY(uint gid READ uid WRITE setGid)
|
||||
Q_PROPERTY(QueuedLimits::Limits limits READ limits WRITE setLimits)
|
||||
Q_PROPERTY(unsigned int nice READ nice WRITE setNice)
|
||||
Q_PROPERTY(uint nice READ nice WRITE setNice)
|
||||
Q_PROPERTY(QueuedEnums::ProcessState pstate READ pstate WRITE setPState)
|
||||
Q_PROPERTY(QDateTime startTime READ startTime WRITE setStartTime)
|
||||
Q_PROPERTY(unsigned int uid READ uid WRITE setUid)
|
||||
Q_PROPERTY(uint uid READ uid WRITE setUid)
|
||||
Q_PROPERTY(long long user READ user WRITE setUser)
|
||||
Q_PROPERTY(QString workDirectory READ workDirectory WRITE setWorkDirectory)
|
||||
|
||||
@ -84,9 +84,9 @@ public:
|
||||
QString command;
|
||||
QStringList arguments;
|
||||
QString workingDirectory;
|
||||
unsigned int uid;
|
||||
unsigned int gid;
|
||||
unsigned int nice;
|
||||
uint uid;
|
||||
uint gid;
|
||||
uint nice;
|
||||
QDateTime startTime;
|
||||
QDateTime endTime;
|
||||
long long user;
|
||||
@ -140,7 +140,7 @@ public:
|
||||
* @brief process GID
|
||||
* @return process GID
|
||||
*/
|
||||
unsigned int gid() const;
|
||||
uint gid() const;
|
||||
/**
|
||||
* @brief process limits
|
||||
* @return process defined limits
|
||||
@ -150,7 +150,7 @@ public:
|
||||
* @brief process nice
|
||||
* @return process nice
|
||||
*/
|
||||
unsigned int nice() const;
|
||||
uint nice() const;
|
||||
/**
|
||||
* @brief process state
|
||||
* @return process defined state
|
||||
@ -165,7 +165,7 @@ public:
|
||||
* @brief process UID
|
||||
* @return process UID
|
||||
*/
|
||||
unsigned int uid() const;
|
||||
uint uid() const;
|
||||
/**
|
||||
* @brief user
|
||||
* @return process owner ID
|
||||
@ -198,7 +198,7 @@ public:
|
||||
* @param _gid
|
||||
* new process GID
|
||||
*/
|
||||
void setGid(const unsigned int _gid);
|
||||
void setGid(const uint _gid);
|
||||
/**
|
||||
* @brief set process limits
|
||||
* @param _limits
|
||||
@ -210,7 +210,7 @@ public:
|
||||
* @param _nice
|
||||
* new process nice
|
||||
*/
|
||||
void setNice(const unsigned int _nice);
|
||||
void setNice(const uint _nice);
|
||||
/**
|
||||
* @brief set process state
|
||||
* @param _limits
|
||||
@ -228,7 +228,7 @@ public:
|
||||
* @param _uid
|
||||
* new process UID
|
||||
*/
|
||||
void setUid(const unsigned int _uid);
|
||||
void setUid(const uint _uid);
|
||||
/**
|
||||
* @brief set user ID
|
||||
* @param _user
|
||||
|
@ -42,7 +42,7 @@ class QueuedUser : public QObject
|
||||
Q_PROPERTY(QString email READ email WRITE setEmail)
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(QString password READ password WRITE setPassword)
|
||||
Q_PROPERTY(unsigned int permissions READ permissions WRITE setPermissions)
|
||||
Q_PROPERTY(uint permissions READ permissions WRITE setPermissions)
|
||||
// limits
|
||||
Q_PROPERTY(QueuedLimits::Limits limits READ limits WRITE setLimits)
|
||||
|
||||
@ -65,7 +65,7 @@ public:
|
||||
QString name;
|
||||
QString email;
|
||||
QString password;
|
||||
unsigned int permissions;
|
||||
uint permissions;
|
||||
QueuedLimits::Limits limits;
|
||||
} QueuedUserDefinitions;
|
||||
|
||||
@ -112,7 +112,7 @@ public:
|
||||
* @brief get UID and GID from user ID
|
||||
* @return pair of {uid, gid}
|
||||
*/
|
||||
QPair<unsigned int, unsigned int> ids();
|
||||
QPair<uint, uint> ids();
|
||||
/**
|
||||
* @brief check if password is valid
|
||||
* @param _password
|
||||
@ -153,7 +153,7 @@ public:
|
||||
* @brief user permissions
|
||||
* @return sum of user permissions from QueuedUser::Permissions
|
||||
*/
|
||||
unsigned int permissions() const;
|
||||
uint permissions() const;
|
||||
// permissions
|
||||
/**
|
||||
* @brief user limits
|
||||
@ -184,7 +184,7 @@ public:
|
||||
* @param _permissions
|
||||
* new user permissions
|
||||
*/
|
||||
void setPermissions(const unsigned int _permissions);
|
||||
void setPermissions(const uint _permissions);
|
||||
// permissions
|
||||
/**
|
||||
* @brief set limits
|
||||
|
@ -130,7 +130,7 @@ public:
|
||||
* user id
|
||||
* @return pair of {uid, gid}
|
||||
*/
|
||||
QPair<unsigned int, unsigned int> ids(const long long _id);
|
||||
QPair<uint, uint> ids(const long long _id);
|
||||
/**
|
||||
* @brief load tokens
|
||||
* @param _tokens
|
||||
|
@ -22,8 +22,9 @@
|
||||
|
||||
|
||||
#include "queued/Queued.h"
|
||||
#include <queued/Queued.h>
|
||||
#include <queued/QueuedDatabaseSchema.h>
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
|
||||
#include "queued/QueuedDatabaseSchema.h"
|
||||
|
||||
@ -57,8 +58,8 @@ QueuedCore::~QueuedCore()
|
||||
*/
|
||||
bool QueuedCore::addTask(
|
||||
const QString &_command, const QStringList &_arguments,
|
||||
const QString &_workingDirectory, const unsigned int _nice,
|
||||
const long long _userId, const QueuedLimits::Limits &_limits,
|
||||
const QString &_workingDirectory, const uint _nice, const long long _userId,
|
||||
const QueuedLimits::Limits &_limits,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Add task" << _command << "with arguments" << _arguments
|
||||
@ -117,7 +118,7 @@ bool QueuedCore::addTask(
|
||||
*/
|
||||
bool QueuedCore::addUser(
|
||||
const QString &_name, const QString &_email, const QString &_password,
|
||||
const unsigned int _permissions, const QueuedLimits::Limits &_limits,
|
||||
const uint _permissions, const QueuedLimits::Limits &_limits,
|
||||
const QueuedUserManager::QueuedUserAuthorization &_auth)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Add user" << _name << "with email" << _email
|
||||
@ -353,7 +354,7 @@ bool QueuedCore::editUserPermission(
|
||||
user->addPermissions(_permission);
|
||||
else
|
||||
user->removePermissions(_permission);
|
||||
unsigned int permissions = user->permissions();
|
||||
uint permissions = user->permissions();
|
||||
qCInfo(LOG_LIB) << "New user permissions";
|
||||
|
||||
// modify in database now
|
||||
@ -451,6 +452,11 @@ void QueuedCore::deinit()
|
||||
disconnect(connection);
|
||||
m_connections.clear();
|
||||
|
||||
// dbus cleanup
|
||||
QDBusConnection::sessionBus().unregisterObject(
|
||||
QueuedConfig::DBUS_OBJECT_PATH);
|
||||
QDBusConnection::sessionBus().unregisterService(QueuedConfig::DBUS_SERVICE);
|
||||
|
||||
// delete objects now
|
||||
if (m_reports)
|
||||
delete m_reports;
|
||||
@ -487,6 +493,9 @@ void QueuedCore::init(const QString &_configuration)
|
||||
m_advancedSettings,
|
||||
SIGNAL(valueUpdated(const QString &, const QVariant &)), this,
|
||||
SLOT(updateSettings(const QString &, const QVariant &)));
|
||||
|
||||
// dbus session
|
||||
initDBus();
|
||||
}
|
||||
|
||||
|
||||
@ -569,6 +578,31 @@ QVariantHash QueuedCore::dropAdminFields(const QString &_table,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn initDBus
|
||||
*/
|
||||
void QueuedCore::initDBus()
|
||||
{
|
||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||
|
||||
if (!bus.registerService(QueuedConfig::DBUS_SERVICE)) {
|
||||
QString message = QString("Could not register service %1")
|
||||
.arg(bus.lastError().message());
|
||||
qCCritical(LOG_DBUS) << message;
|
||||
throw QueuedDBusException(message);
|
||||
}
|
||||
|
||||
if (!bus.registerObject(QueuedConfig::DBUS_OBJECT_PATH,
|
||||
new QueuedCoreInterface(this),
|
||||
QDBusConnection::ExportAllContents)) {
|
||||
QString message = QString("Could not register core object %1")
|
||||
.arg(bus.lastError().message());
|
||||
qCCritical(LOG_DBUS) << message;
|
||||
throw QueuedDBusException(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn initProcesses
|
||||
*/
|
||||
@ -610,8 +644,11 @@ void QueuedCore::initSettings(const QString &_configuration)
|
||||
m_database = new QueuedDatabase(this, dbSetup.path, dbSetup.driver);
|
||||
bool status = m_database->open(dbSetup.hostname, dbSetup.port,
|
||||
dbSetup.username, dbSetup.password);
|
||||
if (!status)
|
||||
throw QueuedDatabaseException("Could not open database");
|
||||
if (!status) {
|
||||
QString message = QString("Could not open database");
|
||||
qCCritical(LOG_LIB) << message;
|
||||
throw QueuedDatabaseException(message);
|
||||
}
|
||||
|
||||
// create administrator if required
|
||||
auto dbAdmin = m_settings->admin();
|
||||
|
46
sources/queued/src/QueuedCoreAdaptor.cpp
Normal file
46
sources/queued/src/QueuedCoreAdaptor.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Evgeniy Alekseev
|
||||
*
|
||||
* 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 QueuedCoreAdaptor.cpp
|
||||
* Source code of queued library
|
||||
* @author Evgeniy Alekseev
|
||||
* @copyright GPLv3
|
||||
* @bug https://github.com/arcan1s/queued/issues
|
||||
*/
|
||||
|
||||
|
||||
#include "queued/Queued.h"
|
||||
|
||||
|
||||
/**
|
||||
* @class QueuedCoreAdaptor
|
||||
*/
|
||||
/**
|
||||
* @fn QueuedCoreAdaptor
|
||||
*/
|
||||
QueuedCoreAdaptor::QueuedCoreAdaptor(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn ~QueuedCoreAdaptor
|
||||
*/
|
||||
QueuedCoreAdaptor::~QueuedCoreAdaptor()
|
||||
{
|
||||
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||
}
|
206
sources/queued/src/QueuedCoreInterface.cpp
Normal file
206
sources/queued/src/QueuedCoreInterface.cpp
Normal file
@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Evgeniy Alekseev
|
||||
*
|
||||
* 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 QueuedCoreInterface.cpp
|
||||
* Source code of queued library
|
||||
* @author Evgeniy Alekseev
|
||||
* @copyright GPLv3
|
||||
* @bug https://github.com/arcan1s/queued/issues
|
||||
*/
|
||||
|
||||
|
||||
#include "queued/Queued.h"
|
||||
|
||||
|
||||
/**
|
||||
* @class QueuedCoreInterface
|
||||
*/
|
||||
/**
|
||||
* @fn QueuedCoreInterface
|
||||
*/
|
||||
QueuedCoreInterface::QueuedCoreInterface(QueuedCore *parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
, m_core(parent)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn ~QueuedCoreInterface
|
||||
*/
|
||||
QueuedCoreInterface::~QueuedCoreInterface()
|
||||
{
|
||||
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn Auth
|
||||
*/
|
||||
QString QueuedCoreInterface::Auth(const QString &name, const QString &password)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Authorize user" << name;
|
||||
|
||||
return m_core->authorization(name, password).token;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn OptionEdit
|
||||
*/
|
||||
bool QueuedCoreInterface::OptionEdit(const QString &key,
|
||||
const QDBusVariant &value,
|
||||
const QString &whoAmI,
|
||||
const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Edit option" << key << value.variant() << "auth by"
|
||||
<< whoAmI;
|
||||
|
||||
return m_core->editOption(key, value.variant(),
|
||||
QueuedUserManager::auth(whoAmI, token));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn TaskAdd
|
||||
*/
|
||||
bool QueuedCoreInterface::TaskAdd(
|
||||
const QString &command, const QStringList &arguments,
|
||||
const QString &workingDirectory, const uint nice, const long long user,
|
||||
const long long cpu, const long long gpu, const QString &memory,
|
||||
const QString &gpumemory, const QString &storage, const QString &whoAmI,
|
||||
const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Add new task with parameters" << command << arguments
|
||||
<< workingDirectory << nice << "from user" << user
|
||||
<< "auth by" << whoAmI;
|
||||
|
||||
return m_core->addTask(
|
||||
command, arguments, workingDirectory, nice, user,
|
||||
QueuedLimits::Limits(cpu, gpu, QueuedLimits::convertMemory(memory),
|
||||
QueuedLimits::convertMemory(gpumemory),
|
||||
QueuedLimits::convertMemory(storage)),
|
||||
QueuedUserManager::auth(whoAmI, token));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn TaskEdit
|
||||
*/
|
||||
bool QueuedCoreInterface::TaskEdit(const qlonglong id, const QDBusVariant &data,
|
||||
const QString &whoAmI, const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Edit task" << id << data.variant() << "auth by"
|
||||
<< whoAmI;
|
||||
|
||||
return m_core->editTask(id, data.variant().toHash(),
|
||||
QueuedUserManager::auth(whoAmI, token));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn TaskStart
|
||||
*/
|
||||
bool QueuedCoreInterface::TaskStart(const qlonglong id, const QString &whoAmI,
|
||||
const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Force start task" << id << "auth by" << whoAmI;
|
||||
|
||||
return m_core->startTask(id, QueuedUserManager::auth(whoAmI, token));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn TaskStop
|
||||
*/
|
||||
bool QueuedCoreInterface::TaskStop(const qlonglong id, const QString &whoAmI,
|
||||
const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Force stop task" << id << "auth by" << whoAmI;
|
||||
|
||||
return m_core->stopTask(id, QueuedUserManager::auth(whoAmI, token));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn UserAdd
|
||||
*/
|
||||
bool QueuedCoreInterface::UserAdd(const QString &name, const QString &email,
|
||||
const QString &password,
|
||||
const uint permissions, const long long cpu,
|
||||
const long long gpu, const QString &memory,
|
||||
const QString &gpumemory,
|
||||
const QString &storage, const QString &whoAmI,
|
||||
const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Add new user with paramaters" << name << email
|
||||
<< permissions << "auth by" << whoAmI;
|
||||
|
||||
return m_core->addUser(
|
||||
name, email, password, permissions,
|
||||
QueuedLimits::Limits(cpu, gpu, QueuedLimits::convertMemory(memory),
|
||||
QueuedLimits::convertMemory(gpumemory),
|
||||
QueuedLimits::convertMemory(storage)),
|
||||
QueuedUserManager::auth(whoAmI, token));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn UserEdit
|
||||
*/
|
||||
bool QueuedCoreInterface::UserEdit(const qlonglong id, const QDBusVariant &data,
|
||||
const QString &whoAmI, const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Edit user" << id << data.variant() << "auth by"
|
||||
<< whoAmI;
|
||||
|
||||
return m_core->editUser(id, data.variant().toHash(),
|
||||
QueuedUserManager::auth(whoAmI, token));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn UserPermissionAdd
|
||||
*/
|
||||
bool QueuedCoreInterface::UserPermissionAdd(const qlonglong id,
|
||||
const uint permission,
|
||||
const QString &whoAmI,
|
||||
const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Add permission" << permission << "to user" << id
|
||||
<< "auth by" << whoAmI;
|
||||
|
||||
return m_core->editUserPermission(
|
||||
id, static_cast<QueuedEnums::Permission>(permission), true,
|
||||
QueuedUserManager::auth(whoAmI, token));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn UserPermissionRemove
|
||||
*/
|
||||
bool QueuedCoreInterface::UserPermissionRemove(const qlonglong id,
|
||||
const uint permission,
|
||||
const QString &whoAmI,
|
||||
const QString &token)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << "Remove permission" << permission << "from user" << id
|
||||
<< "auth by" << whoAmI;
|
||||
|
||||
return m_core->editUserPermission(
|
||||
id, static_cast<QueuedEnums::Permission>(permission), false,
|
||||
QueuedUserManager::auth(whoAmI, token));
|
||||
}
|
@ -109,7 +109,7 @@ QDateTime QueuedProcess::endTime() const
|
||||
/**
|
||||
* @fn gid
|
||||
*/
|
||||
unsigned int QueuedProcess::gid() const
|
||||
uint QueuedProcess::gid() const
|
||||
{
|
||||
return m_definitions.gid;
|
||||
}
|
||||
@ -127,7 +127,7 @@ QueuedLimits::Limits QueuedProcess::limits() const
|
||||
/**
|
||||
* @fn nice
|
||||
*/
|
||||
unsigned int QueuedProcess::nice() const
|
||||
uint QueuedProcess::nice() const
|
||||
{
|
||||
return m_definitions.nice;
|
||||
}
|
||||
@ -154,7 +154,7 @@ QDateTime QueuedProcess::startTime() const
|
||||
/**
|
||||
* @fn uid
|
||||
*/
|
||||
unsigned int QueuedProcess::uid() const
|
||||
uint QueuedProcess::uid() const
|
||||
{
|
||||
return m_definitions.uid;
|
||||
}
|
||||
@ -216,7 +216,7 @@ void QueuedProcess::setEndTime(const QDateTime &_time)
|
||||
/**
|
||||
* @fn setGid
|
||||
*/
|
||||
void QueuedProcess::setGid(const unsigned int _gid)
|
||||
void QueuedProcess::setGid(const uint _gid)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set process GID to" << _gid;
|
||||
|
||||
@ -238,7 +238,7 @@ void QueuedProcess::setLimits(const QueuedLimits::Limits &_limits)
|
||||
/**
|
||||
* @fn setNice
|
||||
*/
|
||||
void QueuedProcess::setNice(const unsigned int _nice)
|
||||
void QueuedProcess::setNice(const uint _nice)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set nice level to" << _nice;
|
||||
|
||||
@ -271,7 +271,7 @@ void QueuedProcess::setStartTime(const QDateTime &_time)
|
||||
/**
|
||||
* @fn setUid
|
||||
*/
|
||||
void QueuedProcess::setUid(const unsigned int _uid)
|
||||
void QueuedProcess::setUid(const uint _uid)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Set process UID to" << _uid;
|
||||
|
||||
|
@ -102,9 +102,9 @@ bool QueuedUser::hasPermission(const QueuedEnums::Permission _permission)
|
||||
/**
|
||||
* @fn ids
|
||||
*/
|
||||
QPair<unsigned int, unsigned int> QueuedUser::ids()
|
||||
QPair<uint, uint> QueuedUser::ids()
|
||||
{
|
||||
QPair<unsigned int, unsigned int> system = {1, 1};
|
||||
QPair<uint, uint> system = {1, 1};
|
||||
|
||||
auto pwd = getpwnam(name().toLocal8Bit().constData());
|
||||
if (!pwd) {
|
||||
@ -180,7 +180,7 @@ QString QueuedUser::password() const
|
||||
/**
|
||||
* @fn permissions
|
||||
*/
|
||||
unsigned int QueuedUser::permissions() const
|
||||
uint QueuedUser::permissions() const
|
||||
{
|
||||
return m_definitions.permissions;
|
||||
}
|
||||
@ -231,7 +231,7 @@ void QueuedUser::setPassword(const QString _password)
|
||||
/**
|
||||
* @fn setPermissions
|
||||
*/
|
||||
void QueuedUser::setPermissions(const unsigned int _permissions)
|
||||
void QueuedUser::setPermissions(const uint _permissions)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "New user permissions" << _permissions;
|
||||
|
||||
|
@ -178,7 +178,7 @@ QDateTime QueuedUserManager::checkToken(const QString &_token,
|
||||
/**
|
||||
* @fn ids
|
||||
*/
|
||||
QPair<unsigned int, unsigned int> QueuedUserManager::ids(const long long _id)
|
||||
QPair<uint, uint> QueuedUserManager::ids(const long long _id)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Get ids for user" << _id;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user