mirror of
https://github.com/arcan1s/queued.git
synced 2025-08-28 03:09:55 +00:00
use 100 symbols (2)
This commit is contained in:
@ -23,8 +23,7 @@
|
||||
#include "QueuedctlUser.h"
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlAuth::auth(const QString &_user,
|
||||
const QString &_cache)
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlAuth::auth(const QString &_user, const QString &_cache)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Auth as user" << _user;
|
||||
|
||||
@ -47,8 +46,7 @@ QueuedctlCommon::QueuedctlResult QueuedctlAuth::auth(const QString &_user,
|
||||
|
||||
QString QueuedctlAuth::getToken(const QString &_cache, const QString &_user)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Get token using cache" << _cache << "and user"
|
||||
<< _user;
|
||||
qCDebug(LOG_APP) << "Get token using cache" << _cache << "and user" << _user;
|
||||
|
||||
QString tokenId = token(_user, _cache);
|
||||
if (tryAuth(tokenId)) {
|
||||
@ -63,8 +61,7 @@ QString QueuedctlAuth::getToken(const QString &_cache, const QString &_user)
|
||||
void QueuedctlAuth::parser(QCommandLineParser &_parser) {}
|
||||
|
||||
|
||||
void QueuedctlAuth::setToken(const QString &_token, const QString &_user,
|
||||
const QString &_cache)
|
||||
void QueuedctlAuth::setToken(const QString &_token, const QString &_user, const QString &_cache)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Save token to" << _cache << "from user" << _user;
|
||||
|
||||
|
@ -24,12 +24,10 @@
|
||||
|
||||
namespace QueuedctlAuth
|
||||
{
|
||||
QueuedctlCommon::QueuedctlResult auth(const QString &_user,
|
||||
const QString &_cache);
|
||||
QueuedctlCommon::QueuedctlResult auth(const QString &_user, const QString &_cache);
|
||||
QString getToken(const QString &_cache, const QString &_user);
|
||||
void parser(QCommandLineParser &_parser);
|
||||
void setToken(const QString &_token, const QString &_user,
|
||||
const QString &_cache);
|
||||
void setToken(const QString &_token, const QString &_user, const QString &_cache);
|
||||
QString token(const QString &_user, const QString &_cache);
|
||||
bool tryAuth(const QString &_token);
|
||||
};
|
||||
|
@ -48,15 +48,13 @@ QString QueuedctlCommon::commandsHelp()
|
||||
commands.sort();
|
||||
for (auto &cmd : commands)
|
||||
// align like default help message
|
||||
cmdList += QString(" %1%2").arg(cmd, -21).arg(
|
||||
QueuedctlArguments[cmd].description);
|
||||
cmdList += QString(" %1%2").arg(cmd, -21).arg(QueuedctlArguments[cmd].description);
|
||||
|
||||
return cmdList.join('\n');
|
||||
}
|
||||
|
||||
|
||||
QString QueuedctlCommon::hashHashToString(
|
||||
const QHash<QString, QHash<QString, QString>> &_hash)
|
||||
QString QueuedctlCommon::hashHashToString(const QHash<QString, QHash<QString, QString>> &_hash)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Convert hash to string" << _hash;
|
||||
|
||||
@ -84,8 +82,7 @@ QString QueuedctlCommon::hashToString(const QVariantHash &_hash)
|
||||
QStringList keys = _hash.keys();
|
||||
keys.sort();
|
||||
for (auto &key : keys)
|
||||
output += QString("%1: %2").arg(key).arg(
|
||||
_hash[key].toString().replace('\n', ' '));
|
||||
output += QString("%1: %2").arg(key).arg(_hash[key].toString().replace('\n', ' '));
|
||||
|
||||
return output.join('\n');
|
||||
}
|
||||
@ -106,10 +103,9 @@ QString QueuedctlCommon::hashListToString(const QList<QVariantHash> &_list)
|
||||
// append rows
|
||||
for (auto &hash : _list) {
|
||||
QStringList row;
|
||||
std::for_each(header.cbegin(), header.cend(),
|
||||
[&hash, &row](const QString &column) {
|
||||
row += hash[column].toString().replace('\n', ' ');
|
||||
});
|
||||
std::for_each(header.cbegin(), header.cend(), [&hash, &row](const QString &column) {
|
||||
row += hash[column].toString().replace('\n', ' ');
|
||||
});
|
||||
output += row.join(',');
|
||||
}
|
||||
|
||||
@ -117,18 +113,15 @@ QString QueuedctlCommon::hashListToString(const QList<QVariantHash> &_list)
|
||||
}
|
||||
|
||||
|
||||
void QueuedctlCommon::preprocess(const QStringList &_args,
|
||||
QCommandLineParser &_parser)
|
||||
void QueuedctlCommon::preprocess(const QStringList &_args, QCommandLineParser &_parser)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Preprocess command" << _args;
|
||||
|
||||
QString command = _args.isEmpty() ? "" : _args.first();
|
||||
// HACK: workaround to show valid help message
|
||||
auto id = QueuedctlArguments.contains(command)
|
||||
? QueuedctlArguments[command].id
|
||||
: QueuedctlArgument::Invalid;
|
||||
_parser.addPositionalArgument(id == QueuedctlArgument::Invalid ? "command"
|
||||
: command,
|
||||
auto id = QueuedctlArguments.contains(command) ? QueuedctlArguments[command].id
|
||||
: QueuedctlArgument::Invalid;
|
||||
_parser.addPositionalArgument(id == QueuedctlArgument::Invalid ? "command" : command,
|
||||
"Command to execute.");
|
||||
|
||||
if (command.isEmpty())
|
||||
@ -206,8 +199,7 @@ void QueuedctlCommon::print(const QueuedctlResult &_result)
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
const QString &_user)
|
||||
QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache, const QString &_user)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Process command with args"
|
||||
<< "using auth" << _cache << _user;
|
||||
@ -216,14 +208,11 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
QStringList args = _parser.positionalArguments();
|
||||
QString command = args.isEmpty() ? "" : args.first();
|
||||
|
||||
auto id = QueuedctlArguments.contains(command)
|
||||
? QueuedctlArguments[command].id
|
||||
: QueuedctlArgument::Invalid;
|
||||
auto id = QueuedctlArguments.contains(command) ? QueuedctlArguments[command].id
|
||||
: QueuedctlArgument::Invalid;
|
||||
checkArgs(args, QueuedctlArguments[command].positionalArgsCount, _parser);
|
||||
|
||||
QString token = (id == QueuedctlArgument::Auth)
|
||||
? ""
|
||||
: QueuedctlAuth::getToken(_cache, _user);
|
||||
QString token = (id == QueuedctlArgument::Auth) ? "" : QueuedctlAuth::getToken(_cache, _user);
|
||||
|
||||
switch (id) {
|
||||
case QueuedctlArgument::Auth: {
|
||||
@ -241,10 +230,9 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
case QueuedctlArgument::PermissionAdd: {
|
||||
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1), token);
|
||||
long long userId = -1;
|
||||
userIdRes.match([&userId](const long long val) { userId = val; },
|
||||
[&result](const QueuedError &err) {
|
||||
result.output = err.message().c_str();
|
||||
});
|
||||
userIdRes.match(
|
||||
[&userId](const long long val) { userId = val; },
|
||||
[&result](const QueuedError &err) { result.output = err.message().c_str(); });
|
||||
if (userId == -1)
|
||||
break;
|
||||
result = QueuedctlPermissions::addPermission(userId, args.at(2), token);
|
||||
@ -253,14 +241,12 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
case QueuedctlArgument::PermissionRemove: {
|
||||
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1), token);
|
||||
long long userId = -1;
|
||||
userIdRes.match([&userId](const long long val) { userId = val; },
|
||||
[&result](const QueuedError &err) {
|
||||
result.output = err.message().c_str();
|
||||
});
|
||||
userIdRes.match(
|
||||
[&userId](const long long val) { userId = val; },
|
||||
[&result](const QueuedError &err) { result.output = err.message().c_str(); });
|
||||
if (userId == -1)
|
||||
break;
|
||||
result
|
||||
= QueuedctlPermissions::removePermission(userId, args.at(2), token);
|
||||
result = QueuedctlPermissions::removePermission(userId, args.at(2), token);
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::PluginAdd: {
|
||||
@ -294,9 +280,7 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
result.status = true;
|
||||
result.output = hashHashToString(val);
|
||||
},
|
||||
[&result](const QueuedError &err) {
|
||||
result.output = err.message().c_str();
|
||||
});
|
||||
[&result](const QueuedError &err) { result.output = err.message().c_str(); });
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::TaskAdd: {
|
||||
@ -305,8 +289,7 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::TaskGet: {
|
||||
result = QueuedctlTask::getTask(args.at(1).toLongLong(), args.at(2),
|
||||
token);
|
||||
result = QueuedctlTask::getTask(args.at(1).toLongLong(), args.at(2), token);
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::TaskList: {
|
||||
@ -315,8 +298,7 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
}
|
||||
case QueuedctlArgument::TaskSet: {
|
||||
auto definitions = QueuedctlTask::getDefinitions(_parser, true, token);
|
||||
result = QueuedctlTask::setTask(args.at(1).toLongLong(), definitions,
|
||||
token);
|
||||
result = QueuedctlTask::setTask(args.at(1).toLongLong(), definitions, token);
|
||||
break;
|
||||
}
|
||||
case QueuedctlArgument::TaskStart: {
|
||||
@ -335,10 +317,9 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
case QueuedctlArgument::UserGet: {
|
||||
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1), token);
|
||||
long long userId = -1;
|
||||
userIdRes.match([&userId](const long long val) { userId = val; },
|
||||
[&result](const QueuedError &err) {
|
||||
result.output = err.message().c_str();
|
||||
});
|
||||
userIdRes.match(
|
||||
[&userId](const long long val) { userId = val; },
|
||||
[&result](const QueuedError &err) { result.output = err.message().c_str(); });
|
||||
if (userId == -1)
|
||||
break;
|
||||
result = QueuedctlUser::getUser(userId, args.at(2), token);
|
||||
@ -351,10 +332,9 @@ QueuedctlCommon::process(QCommandLineParser &_parser, const QString &_cache,
|
||||
case QueuedctlArgument::UserSet: {
|
||||
auto userIdRes = QueuedCoreAdaptor::getUserId(args.at(1), token);
|
||||
long long userId = -1;
|
||||
userIdRes.match([&userId](const long long val) { userId = val; },
|
||||
[&result](const QueuedError &err) {
|
||||
result.output = err.message().c_str();
|
||||
});
|
||||
userIdRes.match(
|
||||
[&userId](const long long val) { userId = val; },
|
||||
[&result](const QueuedError &err) { result.output = err.message().c_str(); });
|
||||
if (userId == -1)
|
||||
break;
|
||||
auto definitions = QueuedctlUser::getDefinitions(_parser, true);
|
||||
|
@ -57,46 +57,38 @@ typedef struct {
|
||||
QString description;
|
||||
int positionalArgsCount;
|
||||
} QueuedctlArgumentInfo;
|
||||
const QHash<QString, QueuedctlArgumentInfo> QueuedctlArguments = {
|
||||
{"auth", {QueuedctlArgument::Auth, "Gets new auth token.", 1}},
|
||||
{"option-get", {QueuedctlArgument::OptionGet, "Gets option value.", 2}},
|
||||
{"option-set", {QueuedctlArgument::OptionSet, "Sets option value.", 3}},
|
||||
{"perm-add",
|
||||
{QueuedctlArgument::PermissionAdd, "Sets user permission.", 3}},
|
||||
{"perm-remove",
|
||||
{QueuedctlArgument::PermissionRemove, "Removes user permission.", 3}},
|
||||
{"plugin",
|
||||
{QueuedctlArgument::PluginSpecification, "Get plugin description.", 2}},
|
||||
{"plugin-add", {QueuedctlArgument::PluginAdd, "Adds plugin to load.", 2}},
|
||||
{"plugin-list",
|
||||
{QueuedctlArgument::PluginList, "Shows enabled plugins.", 1}},
|
||||
{"plugin-options",
|
||||
{QueuedctlArgument::PluginOptions, "Get plugin options.", 2}},
|
||||
{"plugin-remove",
|
||||
{QueuedctlArgument::PluginRemove, "Removes plugin to load.", 2}},
|
||||
{"report", {QueuedctlArgument::Report, "Shows usage report.", 1}},
|
||||
{"status", {QueuedctlArgument::Status, "Server status.", 1}},
|
||||
{"task-add", {QueuedctlArgument::TaskAdd, "Adds new task.", 2}},
|
||||
{"task-get", {QueuedctlArgument::TaskGet, "Gets task properties.", 3}},
|
||||
{"task-list", {QueuedctlArgument::TaskList, "Gets tasks list.", 1}},
|
||||
{"task-set", {QueuedctlArgument::TaskSet, "Sets task properties.", 2}},
|
||||
{"task-start", {QueuedctlArgument::TaskStart, "Starts task.", 2}},
|
||||
{"task-stop", {QueuedctlArgument::TaskStop, "Stops task.", 2}},
|
||||
{"user-add", {QueuedctlArgument::UserAdd, "Adds new user.", 2}},
|
||||
{"user-get", {QueuedctlArgument::UserGet, "Gets user properties.", 3}},
|
||||
{"user-list", {QueuedctlArgument::UserList, "Gets users list.", 1}},
|
||||
{"user-set", {QueuedctlArgument::UserSet, "Sets user properties.", 2}}};
|
||||
const QHash<QString, QueuedctlArgumentInfo> QueuedctlArguments
|
||||
= {{"auth", {QueuedctlArgument::Auth, "Gets new auth token.", 1}},
|
||||
{"option-get", {QueuedctlArgument::OptionGet, "Gets option value.", 2}},
|
||||
{"option-set", {QueuedctlArgument::OptionSet, "Sets option value.", 3}},
|
||||
{"perm-add", {QueuedctlArgument::PermissionAdd, "Sets user permission.", 3}},
|
||||
{"perm-remove", {QueuedctlArgument::PermissionRemove, "Removes user permission.", 3}},
|
||||
{"plugin", {QueuedctlArgument::PluginSpecification, "Get plugin description.", 2}},
|
||||
{"plugin-add", {QueuedctlArgument::PluginAdd, "Adds plugin to load.", 2}},
|
||||
{"plugin-list", {QueuedctlArgument::PluginList, "Shows enabled plugins.", 1}},
|
||||
{"plugin-options", {QueuedctlArgument::PluginOptions, "Get plugin options.", 2}},
|
||||
{"plugin-remove", {QueuedctlArgument::PluginRemove, "Removes plugin to load.", 2}},
|
||||
{"report", {QueuedctlArgument::Report, "Shows usage report.", 1}},
|
||||
{"status", {QueuedctlArgument::Status, "Server status.", 1}},
|
||||
{"task-add", {QueuedctlArgument::TaskAdd, "Adds new task.", 2}},
|
||||
{"task-get", {QueuedctlArgument::TaskGet, "Gets task properties.", 3}},
|
||||
{"task-list", {QueuedctlArgument::TaskList, "Gets tasks list.", 1}},
|
||||
{"task-set", {QueuedctlArgument::TaskSet, "Sets task properties.", 2}},
|
||||
{"task-start", {QueuedctlArgument::TaskStart, "Starts task.", 2}},
|
||||
{"task-stop", {QueuedctlArgument::TaskStop, "Stops task.", 2}},
|
||||
{"user-add", {QueuedctlArgument::UserAdd, "Adds new user.", 2}},
|
||||
{"user-get", {QueuedctlArgument::UserGet, "Gets user properties.", 3}},
|
||||
{"user-list", {QueuedctlArgument::UserList, "Gets users list.", 1}},
|
||||
{"user-set", {QueuedctlArgument::UserSet, "Sets user properties.", 2}}};
|
||||
// methods
|
||||
void checkArgs(const QStringList &_args, const int _count,
|
||||
QCommandLineParser &_parser);
|
||||
void checkArgs(const QStringList &_args, const int _count, QCommandLineParser &_parser);
|
||||
QString commandsHelp();
|
||||
QString hashHashToString(const QHash<QString, QHash<QString, QString>> &_hash);
|
||||
QString hashToString(const QVariantHash &_hash);
|
||||
QString hashListToString(const QList<QVariantHash> &_list);
|
||||
void preprocess(const QStringList &_args, QCommandLineParser &_parser);
|
||||
void print(const QueuedctlResult &_result);
|
||||
QueuedctlResult process(QCommandLineParser &_parser, const QString &_cache,
|
||||
const QString &_user);
|
||||
QueuedctlResult process(QCommandLineParser &_parser, const QString &_cache, const QString &_user);
|
||||
};
|
||||
|
||||
|
||||
|
@ -21,24 +21,21 @@
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlOption::editOption(const QString &_option, const QVariant &_value,
|
||||
const QString &_token)
|
||||
QueuedctlOption::editOption(const QString &_option, const QVariant &_value, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Edit option" << _option << "to" << _value;
|
||||
|
||||
QueuedctlCommon::QueuedctlResult output;
|
||||
auto res = QueuedCoreAdaptor::sendOptionEdit(_option, _value, _token);
|
||||
res.match([&output](const bool val) { output.status = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlOption::getOption(const QString &_option, const QString &_token)
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlOption::getOption(const QString &_option,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Get option" << _option;
|
||||
|
||||
@ -49,9 +46,7 @@ QueuedctlOption::getOption(const QString &_option, const QString &_token)
|
||||
output.status = val.isValid();
|
||||
output.output = QString("%1: %2").arg(_option, val.toString());
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@ -24,11 +24,9 @@
|
||||
|
||||
namespace QueuedctlOption
|
||||
{
|
||||
QueuedctlCommon::QueuedctlResult editOption(const QString &_option,
|
||||
const QVariant &_value,
|
||||
QueuedctlCommon::QueuedctlResult editOption(const QString &_option, const QVariant &_value,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getOption(const QString &_option,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getOption(const QString &_option, const QString &_token);
|
||||
void parserGet(QCommandLineParser &_parser);
|
||||
void parserSet(QCommandLineParser &_parser);
|
||||
};
|
||||
|
@ -20,8 +20,9 @@
|
||||
#include <queued/Queued.h>
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlPermissions::addPermission(
|
||||
const long long _id, const QString &_permission, const QString &_token)
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlPermissions::addPermission(const long long _id,
|
||||
const QString &_permission,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Add permission" << _permission << "to" << _id;
|
||||
|
||||
@ -31,20 +32,18 @@ QueuedctlCommon::QueuedctlResult QueuedctlPermissions::addPermission(
|
||||
if (permission == QueuedEnums::Permission::Invalid) {
|
||||
output.output = "Invalid permission";
|
||||
} else {
|
||||
auto res
|
||||
= QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission, _token);
|
||||
auto res = QueuedCoreAdaptor::sendUserPermissionAdd(_id, permission, _token);
|
||||
res.match([&output](const bool val) { output.status = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlPermissions::removePermission(
|
||||
const long long _id, const QString &_permission, const QString &_token)
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlPermissions::removePermission(const long long _id,
|
||||
const QString &_permission,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Remove permission" << _permission << "to" << _id;
|
||||
|
||||
@ -54,12 +53,9 @@ QueuedctlCommon::QueuedctlResult QueuedctlPermissions::removePermission(
|
||||
if (permission == QueuedEnums::Permission::Invalid) {
|
||||
output.output = "Invalid permission";
|
||||
} else {
|
||||
auto res = QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission,
|
||||
_token);
|
||||
auto res = QueuedCoreAdaptor::sendUserPermissionRemove(_id, permission, _token);
|
||||
res.match([&output](const bool val) { output.status = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
}
|
||||
|
||||
return output;
|
||||
@ -69,6 +65,5 @@ QueuedctlCommon::QueuedctlResult QueuedctlPermissions::removePermission(
|
||||
void QueuedctlPermissions::parser(QCommandLineParser &_parser)
|
||||
{
|
||||
_parser.addPositionalArgument("user", "User ID.", "<user>");
|
||||
_parser.addPositionalArgument("permission", "Permission name.",
|
||||
"<permission>");
|
||||
_parser.addPositionalArgument("permission", "Permission name.", "<permission>");
|
||||
}
|
||||
|
@ -24,11 +24,9 @@
|
||||
|
||||
namespace QueuedctlPermissions
|
||||
{
|
||||
QueuedctlCommon::QueuedctlResult addPermission(const long long _id,
|
||||
const QString &_permission,
|
||||
QueuedctlCommon::QueuedctlResult addPermission(const long long _id, const QString &_permission,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult removePermission(const long long _id,
|
||||
const QString &_permission,
|
||||
QueuedctlCommon::QueuedctlResult removePermission(const long long _id, const QString &_permission,
|
||||
const QString &_token);
|
||||
void parser(QCommandLineParser &_parser);
|
||||
};
|
||||
|
@ -20,8 +20,8 @@
|
||||
#include <queued/Queued.h>
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlPlugins::addPlugin(const QString &_plugin, const QString &_token)
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::addPlugin(const QString &_plugin,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Add plugin" << _plugin;
|
||||
|
||||
@ -29,16 +29,14 @@ QueuedctlPlugins::addPlugin(const QString &_plugin, const QString &_token)
|
||||
|
||||
QueuedctlCommon::QueuedctlResult output;
|
||||
res.match([&output](const bool val) { output.status = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlPlugins::getPlugin(const QString &_plugin, const QString &_token)
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::getPlugin(const QString &_plugin,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Get plugin" << _plugin;
|
||||
|
||||
@ -57,24 +55,20 @@ QueuedctlPlugins::getPlugin(const QString &_plugin, const QString &_token)
|
||||
text += QString(" %1").arg(opt.name);
|
||||
text += QString(" description: %1").arg(opt.description);
|
||||
text += QString(" type: %1").arg(opt.type);
|
||||
text += QString(" default: %1")
|
||||
.arg(opt.defaultValue.toString());
|
||||
text += QString(" default: %1").arg(opt.defaultValue.toString());
|
||||
}
|
||||
|
||||
output.status = true;
|
||||
output.output = text.join('\n');
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlPlugins::getPluginOptions(const QString &_plugin,
|
||||
const QString &_token)
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::getPluginOptions(const QString &_plugin,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Get plugin options" << _plugin;
|
||||
|
||||
@ -86,9 +80,7 @@ QueuedctlPlugins::getPluginOptions(const QString &_plugin,
|
||||
output.status = true;
|
||||
output.output = QueuedctlCommon::hashToString(val);
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
@ -96,8 +88,7 @@ QueuedctlPlugins::getPluginOptions(const QString &_plugin,
|
||||
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::listPlugins()
|
||||
{
|
||||
auto res = QueuedCoreAdaptor::getOption(
|
||||
QueuedConfig::QueuedSettings::Plugins, "");
|
||||
auto res = QueuedCoreAdaptor::getOption(QueuedConfig::QueuedSettings::Plugins, "");
|
||||
|
||||
QueuedctlCommon::QueuedctlResult output;
|
||||
res.match(
|
||||
@ -105,16 +96,14 @@ QueuedctlCommon::QueuedctlResult QueuedctlPlugins::listPlugins()
|
||||
output.status = val.isValid();
|
||||
output.output = val.toString();
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlPlugins::removePlugin(const QString &_plugin, const QString &_token)
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlPlugins::removePlugin(const QString &_plugin,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Remove plugin" << _plugin;
|
||||
|
||||
@ -122,9 +111,7 @@ QueuedctlPlugins::removePlugin(const QString &_plugin, const QString &_token)
|
||||
|
||||
QueuedctlCommon::QueuedctlResult output;
|
||||
res.match([&output](const bool val) { output.status = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@ -24,15 +24,11 @@
|
||||
|
||||
namespace QueuedctlPlugins
|
||||
{
|
||||
QueuedctlCommon::QueuedctlResult addPlugin(const QString &_plugin,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getPlugin(const QString &_plugin,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getPluginOptions(const QString &_plugin,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult addPlugin(const QString &_plugin, const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getPlugin(const QString &_plugin, const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getPluginOptions(const QString &_plugin, const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult listPlugins();
|
||||
QueuedctlCommon::QueuedctlResult removePlugin(const QString &_plugin,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult removePlugin(const QString &_plugin, const QString &_token);
|
||||
void parser(QCommandLineParser &_parser);
|
||||
};
|
||||
|
||||
|
@ -26,9 +26,9 @@ extern "C" {
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlTask::addTask(
|
||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||
const QString &_token)
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlTask::addTask(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Add task" << _definitions.command;
|
||||
|
||||
@ -40,25 +40,21 @@ QueuedctlCommon::QueuedctlResult QueuedctlTask::addTask(
|
||||
output.status = (val > 0);
|
||||
output.output = QString::number(val);
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QueuedProcess::QueuedProcessDefinitions
|
||||
QueuedctlTask::getDefinitions(const QCommandLineParser &_parser,
|
||||
const bool _expandAll, const QString &_token)
|
||||
QueuedctlTask::getDefinitions(const QCommandLineParser &_parser, const bool _expandAll,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Parse task definitions from parser, expand all"
|
||||
<< _expandAll;
|
||||
qCDebug(LOG_APP) << "Parse task definitions from parser, expand all" << _expandAll;
|
||||
|
||||
QueuedProcess::QueuedProcessDefinitions definitions;
|
||||
|
||||
std::for_each(_parser.values("argument").cbegin(),
|
||||
_parser.values("argument").cend(),
|
||||
std::for_each(_parser.values("argument").cbegin(), _parser.values("argument").cend(),
|
||||
[&definitions](const QString &arg) {
|
||||
if (!arg.isEmpty())
|
||||
definitions.arguments += arg;
|
||||
@ -68,37 +64,29 @@ QueuedctlTask::getDefinitions(const QCommandLineParser &_parser,
|
||||
if (_parser.value("task-user").isEmpty()) {
|
||||
definitions.user = 0;
|
||||
} else {
|
||||
auto res
|
||||
= QueuedCoreAdaptor::getUserId(_parser.value("task-user"), _token);
|
||||
res.match(
|
||||
[&definitions](const long long val) { definitions.user = val; },
|
||||
[&definitions](const QueuedError &) { definitions.user = 0; });
|
||||
auto res = QueuedCoreAdaptor::getUserId(_parser.value("task-user"), _token);
|
||||
res.match([&definitions](const long long val) { definitions.user = val; },
|
||||
[&definitions](const QueuedError &) { definitions.user = 0; });
|
||||
}
|
||||
definitions.workingDirectory
|
||||
= QFileInfo(_parser.value("directory")).absoluteFilePath();
|
||||
definitions.workingDirectory = QFileInfo(_parser.value("directory")).absoluteFilePath();
|
||||
// limits now
|
||||
QueuedLimits::Limits limits(
|
||||
_parser.value("limit-cpu").toLongLong(),
|
||||
_parser.value("limit-gpu").toLongLong(),
|
||||
QueuedLimits::convertMemory(_parser.value("limit-memory")),
|
||||
QueuedLimits::convertMemory(_parser.value("limit-gpumemory")),
|
||||
QueuedLimits::convertMemory(_parser.value("limit-storage")));
|
||||
QueuedLimits::Limits limits(_parser.value("limit-cpu").toLongLong(),
|
||||
_parser.value("limit-gpu").toLongLong(),
|
||||
QueuedLimits::convertMemory(_parser.value("limit-memory")),
|
||||
QueuedLimits::convertMemory(_parser.value("limit-gpumemory")),
|
||||
QueuedLimits::convertMemory(_parser.value("limit-storage")));
|
||||
definitions.limits = limits.toString();
|
||||
|
||||
// all options
|
||||
if (_expandAll) {
|
||||
definitions.command
|
||||
= QFileInfo(_parser.value("program")).absoluteFilePath();
|
||||
definitions.endTime
|
||||
= QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
||||
definitions.command = QFileInfo(_parser.value("program")).absoluteFilePath();
|
||||
definitions.endTime = QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
||||
definitions.gid = _parser.value("gid").toUInt();
|
||||
definitions.startTime
|
||||
= QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
||||
definitions.startTime = QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
||||
definitions.uid = _parser.value("uid").toUInt();
|
||||
} else {
|
||||
// queuedctl -- task-add /path/to/application
|
||||
definitions.command
|
||||
= QFileInfo(_parser.positionalArguments().at(1)).absoluteFilePath();
|
||||
definitions.command = QFileInfo(_parser.positionalArguments().at(1)).absoluteFilePath();
|
||||
}
|
||||
|
||||
return definitions;
|
||||
@ -106,8 +94,7 @@ QueuedctlTask::getDefinitions(const QCommandLineParser &_parser,
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlTask::getTask(const long long _id, const QString &_property,
|
||||
const QString &_token)
|
||||
QueuedctlTask::getTask(const long long _id, const QString &_property, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Get property" << _property << "from task" << _id;
|
||||
|
||||
@ -120,9 +107,7 @@ QueuedctlTask::getTask(const long long _id, const QString &_property,
|
||||
output.status = true;
|
||||
output.output = QueuedctlCommon::hashToString(val);
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
} else {
|
||||
auto res = QueuedCoreAdaptor::getTask(_id, _property);
|
||||
res.match(
|
||||
@ -130,30 +115,24 @@ QueuedctlTask::getTask(const long long _id, const QString &_property,
|
||||
output.status = val.isValid();
|
||||
output.output = val.toString();
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlTask::getTasks(const QCommandLineParser &_parser,
|
||||
const QString &_token)
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlTask::getTasks(const QCommandLineParser &_parser,
|
||||
const QString &_token)
|
||||
{
|
||||
long long userId = -1;
|
||||
if (!_parser.value("task-user").isEmpty()) {
|
||||
auto res
|
||||
= QueuedCoreAdaptor::getUserId(_parser.value("task-user"), _token);
|
||||
auto res = QueuedCoreAdaptor::getUserId(_parser.value("task-user"), _token);
|
||||
res.match([&userId](const long long val) { userId = val; },
|
||||
[&userId](const QueuedError &) {});
|
||||
}
|
||||
QDateTime stop
|
||||
= QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
||||
QDateTime start
|
||||
= QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
||||
QDateTime stop = QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
||||
QDateTime start = QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
||||
|
||||
QueuedctlCommon::QueuedctlResult output;
|
||||
|
||||
@ -163,9 +142,7 @@ QueuedctlTask::getTasks(const QCommandLineParser &_parser,
|
||||
output.status = true;
|
||||
output.output = QueuedctlCommon::hashListToString(val);
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
@ -176,40 +153,33 @@ void QueuedctlTask::parserAdd(QCommandLineParser &_parser)
|
||||
_parser.addPositionalArgument("program", "Command line.", "<program>");
|
||||
|
||||
// command line arguments
|
||||
QCommandLineOption argumentOption({"a", "argument"},
|
||||
"Command line argument.", "argument", "");
|
||||
QCommandLineOption argumentOption({"a", "argument"}, "Command line argument.", "argument", "");
|
||||
_parser.addOption(argumentOption);
|
||||
// working directory
|
||||
QCommandLineOption directoryOption("directory",
|
||||
"Command working directory.",
|
||||
"directory", QDir::currentPath());
|
||||
QCommandLineOption directoryOption("directory", "Command working directory.", "directory",
|
||||
QDir::currentPath());
|
||||
_parser.addOption(directoryOption);
|
||||
// user
|
||||
QCommandLineOption userOption("task-user", "Task user.", "task-user",
|
||||
::getlogin());
|
||||
QCommandLineOption userOption("task-user", "Task user.", "task-user", ::getlogin());
|
||||
_parser.addOption(userOption);
|
||||
// nice
|
||||
QCommandLineOption niceOption("nice", "Task nice level.", "nice", "0");
|
||||
_parser.addOption(niceOption);
|
||||
// cpu limit
|
||||
QCommandLineOption cpuOption("limit-cpu", "Task CPU limit.", "limit-cpu",
|
||||
"0");
|
||||
QCommandLineOption cpuOption("limit-cpu", "Task CPU limit.", "limit-cpu", "0");
|
||||
_parser.addOption(cpuOption);
|
||||
// gpu limit
|
||||
QCommandLineOption gpuOption("limit-gpu", "Task GPU limit.", "limit-gpu",
|
||||
"0");
|
||||
QCommandLineOption gpuOption("limit-gpu", "Task GPU limit.", "limit-gpu", "0");
|
||||
_parser.addOption(gpuOption);
|
||||
// memory limit
|
||||
QCommandLineOption memoryOption("limit-memory", "Task memory limit.",
|
||||
"limit-memory", "0");
|
||||
QCommandLineOption memoryOption("limit-memory", "Task memory limit.", "limit-memory", "0");
|
||||
_parser.addOption(memoryOption);
|
||||
// gpu memory limit
|
||||
QCommandLineOption gpumemoryOption(
|
||||
"limit-gpumemory", "Task GPU memory limit.", "limit-gpumemory", "0");
|
||||
QCommandLineOption gpumemoryOption("limit-gpumemory", "Task GPU memory limit.",
|
||||
"limit-gpumemory", "0");
|
||||
_parser.addOption(gpumemoryOption);
|
||||
// storage limit
|
||||
QCommandLineOption storageOption("limit-storage", "Task storage limit.",
|
||||
"limit-storage", "0");
|
||||
QCommandLineOption storageOption("limit-storage", "Task storage limit.", "limit-storage", "0");
|
||||
_parser.addOption(storageOption);
|
||||
}
|
||||
|
||||
@ -217,8 +187,7 @@ void QueuedctlTask::parserAdd(QCommandLineParser &_parser)
|
||||
void QueuedctlTask::parserGet(QCommandLineParser &_parser)
|
||||
{
|
||||
_parser.addPositionalArgument("id", "Task ID.", "<id>");
|
||||
_parser.addPositionalArgument("property", "Task property name.",
|
||||
"<property>");
|
||||
_parser.addPositionalArgument("property", "Task property name.", "<property>");
|
||||
}
|
||||
|
||||
|
||||
@ -241,16 +210,13 @@ void QueuedctlTask::parserSet(QCommandLineParser &_parser)
|
||||
_parser.addPositionalArgument("id", "Task ID.", "<id>");
|
||||
|
||||
// command line
|
||||
QCommandLineOption commandOption({"p", "program"}, "Command line.",
|
||||
"program", "");
|
||||
QCommandLineOption commandOption({"p", "program"}, "Command line.", "program", "");
|
||||
_parser.addOption(commandOption);
|
||||
// command line arguments
|
||||
QCommandLineOption argumentOption({"a", "argument"},
|
||||
"Command line argument.", "argument", "");
|
||||
QCommandLineOption argumentOption({"a", "argument"}, "Command line argument.", "argument", "");
|
||||
_parser.addOption(argumentOption);
|
||||
// working directory
|
||||
QCommandLineOption directoryOption(
|
||||
"directory", "Command working directory.", "directory", "");
|
||||
QCommandLineOption directoryOption("directory", "Command working directory.", "directory", "");
|
||||
_parser.addOption(directoryOption);
|
||||
// user
|
||||
QCommandLineOption userOption("task-user", "Task user.", "task-user", "");
|
||||
@ -271,24 +237,20 @@ void QueuedctlTask::parserSet(QCommandLineParser &_parser)
|
||||
QCommandLineOption stopOption("stop", "Task stop time.", "stop", "");
|
||||
_parser.addOption(stopOption);
|
||||
// cpu limit
|
||||
QCommandLineOption cpuOption("limit-cpu", "Task CPU limit.", "limit-cpu",
|
||||
"-1");
|
||||
QCommandLineOption cpuOption("limit-cpu", "Task CPU limit.", "limit-cpu", "-1");
|
||||
_parser.addOption(cpuOption);
|
||||
// gpu limit
|
||||
QCommandLineOption gpuOption("limit-gpu", "Task GPU limit.", "limit-gpu",
|
||||
"-1");
|
||||
QCommandLineOption gpuOption("limit-gpu", "Task GPU limit.", "limit-gpu", "-1");
|
||||
_parser.addOption(gpuOption);
|
||||
// memory limit
|
||||
QCommandLineOption memoryOption("limit-memory", "Task memory limit.",
|
||||
"limit-memory", "-1");
|
||||
QCommandLineOption memoryOption("limit-memory", "Task memory limit.", "limit-memory", "-1");
|
||||
_parser.addOption(memoryOption);
|
||||
// gpu memory limit
|
||||
QCommandLineOption gpumemoryOption(
|
||||
"limit-gpumemory", "Task GPU memory limit.", "limit-gpumemory", "-1");
|
||||
QCommandLineOption gpumemoryOption("limit-gpumemory", "Task GPU memory limit.",
|
||||
"limit-gpumemory", "-1");
|
||||
_parser.addOption(gpumemoryOption);
|
||||
// storage limit
|
||||
QCommandLineOption storageOption("limit-storage", "Task storage limit.",
|
||||
"limit-storage", "-1");
|
||||
QCommandLineOption storageOption("limit-storage", "Task storage limit.", "limit-storage", "-1");
|
||||
_parser.addOption(storageOption);
|
||||
}
|
||||
|
||||
@ -299,10 +261,10 @@ void QueuedctlTask::parserStart(QCommandLineParser &_parser)
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlTask::setTask(
|
||||
const long long _id,
|
||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||
const QString &_token)
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlTask::setTask(const long long _id,
|
||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Edit task" << _id;
|
||||
|
||||
@ -310,9 +272,7 @@ QueuedctlCommon::QueuedctlResult QueuedctlTask::setTask(
|
||||
|
||||
QueuedctlCommon::QueuedctlResult output;
|
||||
res.match([&output](const bool val) { output.status = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
@ -327,16 +287,13 @@ QueuedctlCommon::QueuedctlResult QueuedctlTask::startTask(const long long _id,
|
||||
|
||||
QueuedctlCommon::QueuedctlResult output;
|
||||
res.match([&output](const bool val) { output.status = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlTask::stopTask(const long long _id,
|
||||
const QString &_token)
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlTask::stopTask(const long long _id, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Stop task" << _id;
|
||||
|
||||
@ -344,9 +301,7 @@ QueuedctlCommon::QueuedctlResult QueuedctlTask::stopTask(const long long _id,
|
||||
|
||||
QueuedctlCommon::QueuedctlResult output;
|
||||
res.match([&output](const bool val) { output.status = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@ -27,28 +27,22 @@
|
||||
namespace QueuedctlTask
|
||||
{
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
addTask(const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||
const QString &_token);
|
||||
addTask(const QueuedProcess::QueuedProcessDefinitions &_definitions, const QString &_token);
|
||||
QueuedProcess::QueuedProcessDefinitions
|
||||
getDefinitions(const QCommandLineParser &_parser, const bool _expandAll,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
getTask(const long long _id, const QString &_property, const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getTasks(const QCommandLineParser &_parser,
|
||||
const QString &_token);
|
||||
getDefinitions(const QCommandLineParser &_parser, const bool _expandAll, const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getTask(const long long _id, const QString &_property,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getTasks(const QCommandLineParser &_parser, const QString &_token);
|
||||
void parserAdd(QCommandLineParser &_parser);
|
||||
void parserGet(QCommandLineParser &_parser);
|
||||
void parserList(QCommandLineParser &_parser);
|
||||
void parserSet(QCommandLineParser &_parser);
|
||||
void parserStart(QCommandLineParser &_parser);
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
setTask(const long long _id,
|
||||
const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||
setTask(const long long _id, const QueuedProcess::QueuedProcessDefinitions &_definitions,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult startTask(const long long _id,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult stopTask(const long long _id,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult startTask(const long long _id, const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult stopTask(const long long _id, const QString &_token);
|
||||
};
|
||||
|
||||
|
||||
|
@ -29,8 +29,7 @@ extern "C" {
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlUser::addUser(const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||
const QString &_token)
|
||||
QueuedctlUser::addUser(const QueuedUser::QueuedUserDefinitions &_definitions, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Add user" << _definitions.name;
|
||||
|
||||
@ -42,24 +41,19 @@ QueuedctlUser::addUser(const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||
output.status = (val > 0);
|
||||
output.output = QString::number(val);
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlUser::getReport(const QCommandLineParser &_parser,
|
||||
const QString &_token)
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlUser::getReport(const QCommandLineParser &_parser,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Get usage report";
|
||||
|
||||
QDateTime stop
|
||||
= QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
||||
QDateTime start
|
||||
= QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
||||
QDateTime stop = QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
||||
QDateTime start = QDateTime::fromString(_parser.value("start"), Qt::ISODateWithMs);
|
||||
|
||||
auto res = QueuedCoreAdaptor::getPerformance(start, stop, _token);
|
||||
|
||||
@ -69,41 +63,34 @@ QueuedctlUser::getReport(const QCommandLineParser &_parser,
|
||||
output.status = true;
|
||||
output.output = QueuedctlCommon::hashListToString(val);
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QueuedUser::QueuedUserDefinitions
|
||||
QueuedctlUser::getDefinitions(const QCommandLineParser &_parser,
|
||||
const bool _expandAll)
|
||||
QueuedUser::QueuedUserDefinitions QueuedctlUser::getDefinitions(const QCommandLineParser &_parser,
|
||||
const bool _expandAll)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Parse user definitions from parser, expand all"
|
||||
<< _expandAll;
|
||||
qCDebug(LOG_APP) << "Parse user definitions from parser, expand all" << _expandAll;
|
||||
|
||||
QueuedUser::QueuedUserDefinitions definitions;
|
||||
|
||||
// define password first
|
||||
definitions.password = _parser.isSet("stdin-password")
|
||||
? getPassword()
|
||||
: _parser.value("password");
|
||||
definitions.password
|
||||
= _parser.isSet("stdin-password") ? getPassword() : _parser.value("password");
|
||||
auto res = QueuedCoreAdaptor::sendPasswordHash(definitions.password);
|
||||
res.match(
|
||||
[&definitions](const QString &val) { definitions.password = val; },
|
||||
[&definitions](const QueuedError &) { definitions.password = ""; });
|
||||
res.match([&definitions](const QString &val) { definitions.password = val; },
|
||||
[&definitions](const QueuedError &) { definitions.password = ""; });
|
||||
|
||||
definitions.email = _parser.value("email");
|
||||
definitions.priority = _parser.value("priority").toUInt();
|
||||
// limits now
|
||||
QueuedLimits::Limits limits(
|
||||
_parser.value("limit-cpu").toLongLong(),
|
||||
_parser.value("limit-gpu").toLongLong(),
|
||||
QueuedLimits::convertMemory(_parser.value("limit-memory")),
|
||||
QueuedLimits::convertMemory(_parser.value("limit-gpumemory")),
|
||||
QueuedLimits::convertMemory(_parser.value("limit-storage")));
|
||||
QueuedLimits::Limits limits(_parser.value("limit-cpu").toLongLong(),
|
||||
_parser.value("limit-gpu").toLongLong(),
|
||||
QueuedLimits::convertMemory(_parser.value("limit-memory")),
|
||||
QueuedLimits::convertMemory(_parser.value("limit-gpumemory")),
|
||||
QueuedLimits::convertMemory(_parser.value("limit-storage")));
|
||||
definitions.limits = limits.toString();
|
||||
|
||||
// all options
|
||||
@ -137,8 +124,7 @@ QString QueuedctlUser::getPassword()
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlUser::getUser(const long long _id, const QString &_property,
|
||||
const QString &_token)
|
||||
QueuedctlUser::getUser(const long long _id, const QString &_property, const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Get property" << _property << "from user" << _id;
|
||||
|
||||
@ -151,9 +137,7 @@ QueuedctlUser::getUser(const long long _id, const QString &_property,
|
||||
output.status = true;
|
||||
output.output = QueuedctlCommon::hashToString(val);
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
} else {
|
||||
auto res = QueuedCoreAdaptor::getUser(_id, _property);
|
||||
res.match(
|
||||
@ -161,25 +145,20 @@ QueuedctlUser::getUser(const long long _id, const QString &_property,
|
||||
output.status = val.isValid();
|
||||
output.output = val.toString();
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlUser::getUsers(const QCommandLineParser &_parser,
|
||||
const QString &_token)
|
||||
QueuedctlCommon::QueuedctlResult QueuedctlUser::getUsers(const QCommandLineParser &_parser,
|
||||
const QString &_token)
|
||||
{
|
||||
QDateTime lastLogin = QDateTime::fromString(_parser.value("last-logged"),
|
||||
Qt::ISODateWithMs);
|
||||
auto permission
|
||||
= _parser.value("access").isEmpty()
|
||||
? QueuedEnums::Permission::Invalid
|
||||
: QueuedEnums::Permission(_parser.value("access").toInt());
|
||||
QDateTime lastLogin = QDateTime::fromString(_parser.value("last-logged"), Qt::ISODateWithMs);
|
||||
auto permission = _parser.value("access").isEmpty()
|
||||
? QueuedEnums::Permission::Invalid
|
||||
: QueuedEnums::Permission(_parser.value("access").toInt());
|
||||
|
||||
auto res = QueuedCoreAdaptor::getUsers(lastLogin, permission, _token);
|
||||
|
||||
@ -189,9 +168,7 @@ QueuedctlUser::getUsers(const QCommandLineParser &_parser,
|
||||
output.status = true;
|
||||
output.output = QueuedctlCommon::hashListToString(val);
|
||||
},
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
@ -202,43 +179,35 @@ void QueuedctlUser::parserAdd(QCommandLineParser &_parser)
|
||||
_parser.addPositionalArgument("name", "User name.", "<name>");
|
||||
|
||||
// permissions
|
||||
QCommandLineOption accessOption({"a", "access"}, "User permission.",
|
||||
"access", "0");
|
||||
QCommandLineOption accessOption({"a", "access"}, "User permission.", "access", "0");
|
||||
_parser.addOption(accessOption);
|
||||
// email
|
||||
QCommandLineOption emailOption({"e", "email"}, "User email.", "email", "");
|
||||
_parser.addOption(emailOption);
|
||||
// priority
|
||||
QCommandLineOption priorityOption({"p", "priority"}, "User priority.",
|
||||
"priority", "0");
|
||||
QCommandLineOption priorityOption({"p", "priority"}, "User priority.", "priority", "0");
|
||||
_parser.addOption(priorityOption);
|
||||
// password
|
||||
QCommandLineOption passwordOption("password", "User password.", "password",
|
||||
"");
|
||||
QCommandLineOption passwordOption("password", "User password.", "password", "");
|
||||
_parser.addOption(passwordOption);
|
||||
// password
|
||||
QCommandLineOption stdinPasswordOption("stdin-password",
|
||||
"User password from stdin.");
|
||||
QCommandLineOption stdinPasswordOption("stdin-password", "User password from stdin.");
|
||||
_parser.addOption(stdinPasswordOption);
|
||||
// cpu limit
|
||||
QCommandLineOption cpuOption("limit-cpu", "User CPU limit.", "limit-cpu",
|
||||
"0");
|
||||
QCommandLineOption cpuOption("limit-cpu", "User CPU limit.", "limit-cpu", "0");
|
||||
_parser.addOption(cpuOption);
|
||||
// gpu limit
|
||||
QCommandLineOption gpuOption("limit-gpu", "User GPU limit.", "limit-gpu",
|
||||
"0");
|
||||
QCommandLineOption gpuOption("limit-gpu", "User GPU limit.", "limit-gpu", "0");
|
||||
_parser.addOption(gpuOption);
|
||||
// memory limit
|
||||
QCommandLineOption memoryOption("limit-memory", "User memory limit.",
|
||||
"limit-memory", "0");
|
||||
QCommandLineOption memoryOption("limit-memory", "User memory limit.", "limit-memory", "0");
|
||||
_parser.addOption(memoryOption);
|
||||
// gpu memory limit
|
||||
QCommandLineOption gpumemoryOption(
|
||||
"limit-gpumemory", "User GPU memory limit.", "limit-gpumemory", "0");
|
||||
QCommandLineOption gpumemoryOption("limit-gpumemory", "User GPU memory limit.",
|
||||
"limit-gpumemory", "0");
|
||||
_parser.addOption(gpumemoryOption);
|
||||
// storage limit
|
||||
QCommandLineOption storageOption("limit-storage", "User storage limit.",
|
||||
"limit-storage", "0");
|
||||
QCommandLineOption storageOption("limit-storage", "User storage limit.", "limit-storage", "0");
|
||||
_parser.addOption(storageOption);
|
||||
}
|
||||
|
||||
@ -246,16 +215,14 @@ void QueuedctlUser::parserAdd(QCommandLineParser &_parser)
|
||||
void QueuedctlUser::parserGet(QCommandLineParser &_parser)
|
||||
{
|
||||
_parser.addPositionalArgument("id", "User ID.", "<id>");
|
||||
_parser.addPositionalArgument("property", "User property name.",
|
||||
"<property>");
|
||||
_parser.addPositionalArgument("property", "User property name.", "<property>");
|
||||
}
|
||||
|
||||
|
||||
void QueuedctlUser::parserList(QCommandLineParser &_parser)
|
||||
{
|
||||
// last logged in
|
||||
QCommandLineOption loggedOption("last-logged", "User last logged time.",
|
||||
"last-logged", "");
|
||||
QCommandLineOption loggedOption("last-logged", "User last logged time.", "last-logged", "");
|
||||
_parser.addOption(loggedOption);
|
||||
// permissions
|
||||
QCommandLineOption accessOption("access", "User permission.", "access", "");
|
||||
@ -285,43 +252,35 @@ void QueuedctlUser::parserSet(QCommandLineParser &_parser)
|
||||
QCommandLineOption nameOption({"n", "name"}, "User name.", "name", "");
|
||||
_parser.addOption(nameOption);
|
||||
// priority
|
||||
QCommandLineOption priorityOption({"p", "priority"}, "User priority.",
|
||||
"priority", "0");
|
||||
QCommandLineOption priorityOption({"p", "priority"}, "User priority.", "priority", "0");
|
||||
_parser.addOption(priorityOption);
|
||||
// password
|
||||
QCommandLineOption passwordOption("password", "User password.", "password",
|
||||
"");
|
||||
QCommandLineOption passwordOption("password", "User password.", "password", "");
|
||||
_parser.addOption(passwordOption);
|
||||
// password
|
||||
QCommandLineOption stdinPasswordOption("stdin-password",
|
||||
"User password from stdin.");
|
||||
QCommandLineOption stdinPasswordOption("stdin-password", "User password from stdin.");
|
||||
_parser.addOption(stdinPasswordOption);
|
||||
// cpu limit
|
||||
QCommandLineOption cpuOption("limit-cpu", "User CPU limit.", "limit-cpu",
|
||||
"0");
|
||||
QCommandLineOption cpuOption("limit-cpu", "User CPU limit.", "limit-cpu", "0");
|
||||
_parser.addOption(cpuOption);
|
||||
// gpu limit
|
||||
QCommandLineOption gpuOption("limit-gpu", "User GPU limit.", "limit-gpu",
|
||||
"0");
|
||||
QCommandLineOption gpuOption("limit-gpu", "User GPU limit.", "limit-gpu", "0");
|
||||
_parser.addOption(gpuOption);
|
||||
// memory limit
|
||||
QCommandLineOption memoryOption("limit-memory", "User memory limit.",
|
||||
"limit-memory", "0");
|
||||
QCommandLineOption memoryOption("limit-memory", "User memory limit.", "limit-memory", "0");
|
||||
_parser.addOption(memoryOption);
|
||||
// gpu memory limit
|
||||
QCommandLineOption gpumemoryOption(
|
||||
"limit-gpumemory", "User GPU memory limit.", "limit-gpumemory", "0");
|
||||
QCommandLineOption gpumemoryOption("limit-gpumemory", "User GPU memory limit.",
|
||||
"limit-gpumemory", "0");
|
||||
_parser.addOption(gpumemoryOption);
|
||||
// storage limit
|
||||
QCommandLineOption storageOption("limit-storage", "User storage limit.",
|
||||
"limit-storage", "0");
|
||||
QCommandLineOption storageOption("limit-storage", "User storage limit.", "limit-storage", "0");
|
||||
_parser.addOption(storageOption);
|
||||
}
|
||||
|
||||
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
QueuedctlUser::setUser(const long long _id,
|
||||
const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||
QueuedctlUser::setUser(const long long _id, const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||
const QString &_token)
|
||||
{
|
||||
qCDebug(LOG_APP) << "Edit user" << _id;
|
||||
@ -330,9 +289,7 @@ QueuedctlUser::setUser(const long long _id,
|
||||
|
||||
QueuedctlCommon::QueuedctlResult output;
|
||||
res.match([&output](const bool val) { output.status = val; },
|
||||
[&output](const QueuedError &err) {
|
||||
output.output = err.message().c_str();
|
||||
});
|
||||
[&output](const QueuedError &err) { output.output = err.message().c_str(); });
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@ -26,27 +26,24 @@
|
||||
|
||||
namespace QueuedctlUser
|
||||
{
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
addUser(const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult addUser(const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getReport(const QCommandLineParser &_parser,
|
||||
const QString &_token);
|
||||
QueuedUser::QueuedUserDefinitions
|
||||
getDefinitions(const QCommandLineParser &_parser, const bool _expandAll);
|
||||
QueuedUser::QueuedUserDefinitions getDefinitions(const QCommandLineParser &_parser,
|
||||
const bool _expandAll);
|
||||
QString getPassword();
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
getUser(const long long _id, const QString &_property, const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getUsers(const QCommandLineParser &_parser,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getUser(const long long _id, const QString &_property,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult getUsers(const QCommandLineParser &_parser, const QString &_token);
|
||||
void parserAdd(QCommandLineParser &_parser);
|
||||
void parserGet(QCommandLineParser &_parser);
|
||||
void parserList(QCommandLineParser &_parser);
|
||||
void parserReport(QCommandLineParser &_parser);
|
||||
void parserSet(QCommandLineParser &_parser);
|
||||
QueuedctlCommon::QueuedctlResult
|
||||
setUser(const long long _id,
|
||||
const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||
const QString &_token);
|
||||
QueuedctlCommon::QueuedctlResult setUser(const long long _id,
|
||||
const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||
const QString &_token);
|
||||
};
|
||||
|
||||
|
||||
|
@ -38,8 +38,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
// parser
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(
|
||||
"Daemon for starting jobs to queue of calculations");
|
||||
parser.setApplicationDescription("Daemon for starting jobs to queue of calculations");
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
// info
|
||||
@ -51,12 +50,11 @@ int main(int argc, char *argv[])
|
||||
parser.addOption(debugOption);
|
||||
|
||||
// configuration option
|
||||
QCommandLineOption tokenOption({"t", "token"}, "Path to cached token.",
|
||||
"token", QueuedSettings::defaultTokenPath());
|
||||
QCommandLineOption tokenOption({"t", "token"}, "Path to cached token.", "token",
|
||||
QueuedSettings::defaultTokenPath());
|
||||
parser.addOption(tokenOption);
|
||||
QCommandLineOption userOption({"u", "user"},
|
||||
"User to login instead of current one.",
|
||||
"user", ::getlogin());
|
||||
QCommandLineOption userOption({"u", "user"}, "User to login instead of current one.", "user",
|
||||
::getlogin());
|
||||
parser.addOption(userOption);
|
||||
|
||||
// additional help option
|
||||
@ -91,8 +89,8 @@ int main(int argc, char *argv[])
|
||||
QueuedDebug::enableDebug();
|
||||
|
||||
// process
|
||||
auto result = QueuedctlCommon::process(parser, parser.value(tokenOption),
|
||||
parser.value(userOption));
|
||||
auto result
|
||||
= QueuedctlCommon::process(parser, parser.value(tokenOption), parser.value(userOption));
|
||||
QueuedctlCommon::print(result);
|
||||
|
||||
return result.status ? 0 : 1;
|
||||
|
Reference in New Issue
Block a user