mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 09:17:29 +02:00
Merge pull request #15353 from roxanneskelly/Case819
Case 819 - Add min-listen-port command line parameter to assignment monitor
This commit is contained in:
commit
5856ab3d3a
4 changed files with 53 additions and 12 deletions
|
@ -64,6 +64,10 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) :
|
||||||
"UDP port for this assignment client (or monitor)", "port");
|
"UDP port for this assignment client (or monitor)", "port");
|
||||||
parser.addOption(portOption);
|
parser.addOption(portOption);
|
||||||
|
|
||||||
|
const QCommandLineOption minChildListenPort(ASSIGNMENT_MONITOR_MIN_CHILDREN_LISTEN_PORT_OPTION,
|
||||||
|
"Minimum UDP listen port", "port");
|
||||||
|
parser.addOption(minChildListenPort);
|
||||||
|
|
||||||
const QCommandLineOption walletDestinationOption(ASSIGNMENT_WALLET_DESTINATION_ID_OPTION,
|
const QCommandLineOption walletDestinationOption(ASSIGNMENT_WALLET_DESTINATION_ID_OPTION,
|
||||||
"set wallet destination", "wallet-uuid");
|
"set wallet destination", "wallet-uuid");
|
||||||
parser.addOption(walletDestinationOption);
|
parser.addOption(walletDestinationOption);
|
||||||
|
@ -195,6 +199,11 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) :
|
||||||
assignmentServerPort = parser.value(assignmentServerPortOption).toInt();
|
assignmentServerPort = parser.value(assignmentServerPortOption).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quint16 childMinListenPort = 0;
|
||||||
|
if (argumentVariantMap.contains(ASSIGNMENT_MONITOR_MIN_CHILDREN_LISTEN_PORT_OPTION)) {
|
||||||
|
childMinListenPort = argumentVariantMap.value(ASSIGNMENT_MONITOR_MIN_CHILDREN_LISTEN_PORT_OPTION).toUInt();
|
||||||
|
}
|
||||||
|
|
||||||
// check for an overidden listen port
|
// check for an overidden listen port
|
||||||
quint16 listenPort = 0;
|
quint16 listenPort = 0;
|
||||||
if (argumentVariantMap.contains(ASSIGNMENT_CLIENT_LISTEN_PORT_OPTION)) {
|
if (argumentVariantMap.contains(ASSIGNMENT_CLIENT_LISTEN_PORT_OPTION)) {
|
||||||
|
@ -234,8 +243,8 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) :
|
||||||
|
|
||||||
if (numForks || minForks || maxForks) {
|
if (numForks || minForks || maxForks) {
|
||||||
AssignmentClientMonitor* monitor = new AssignmentClientMonitor(numForks, minForks, maxForks,
|
AssignmentClientMonitor* monitor = new AssignmentClientMonitor(numForks, minForks, maxForks,
|
||||||
requestAssignmentType, assignmentPool,
|
requestAssignmentType, assignmentPool, listenPort,
|
||||||
listenPort, walletUUID, assignmentServerHostname,
|
childMinListenPort, walletUUID, assignmentServerHostname,
|
||||||
assignmentServerPort, httpStatusPort, logDirectory);
|
assignmentServerPort, httpStatusPort, logDirectory);
|
||||||
monitor->setParent(this);
|
monitor->setParent(this);
|
||||||
connect(this, &QCoreApplication::aboutToQuit, monitor, &AssignmentClientMonitor::aboutToQuit);
|
connect(this, &QCoreApplication::aboutToQuit, monitor, &AssignmentClientMonitor::aboutToQuit);
|
||||||
|
|
|
@ -20,6 +20,7 @@ const QString ASSIGNMENT_POOL_OPTION = "pool";
|
||||||
const QString ASSIGNMENT_CLIENT_LISTEN_PORT_OPTION = "p";
|
const QString ASSIGNMENT_CLIENT_LISTEN_PORT_OPTION = "p";
|
||||||
const QString ASSIGNMENT_WALLET_DESTINATION_ID_OPTION = "wallet";
|
const QString ASSIGNMENT_WALLET_DESTINATION_ID_OPTION = "wallet";
|
||||||
const QString CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION = "a";
|
const QString CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION = "a";
|
||||||
|
const QString ASSIGNMENT_MONITOR_MIN_CHILDREN_LISTEN_PORT_OPTION = "min-listen-port";
|
||||||
const QString CUSTOM_ASSIGNMENT_SERVER_PORT_OPTION = "server-port";
|
const QString CUSTOM_ASSIGNMENT_SERVER_PORT_OPTION = "server-port";
|
||||||
const QString ASSIGNMENT_NUM_FORKS_OPTION = "n";
|
const QString ASSIGNMENT_NUM_FORKS_OPTION = "n";
|
||||||
const QString ASSIGNMENT_MIN_FORKS_OPTION = "min";
|
const QString ASSIGNMENT_MIN_FORKS_OPTION = "min";
|
||||||
|
|
|
@ -40,7 +40,7 @@ AssignmentClientMonitor::AssignmentClientMonitor(const unsigned int numAssignmen
|
||||||
const unsigned int minAssignmentClientForks,
|
const unsigned int minAssignmentClientForks,
|
||||||
const unsigned int maxAssignmentClientForks,
|
const unsigned int maxAssignmentClientForks,
|
||||||
Assignment::Type requestAssignmentType, QString assignmentPool,
|
Assignment::Type requestAssignmentType, QString assignmentPool,
|
||||||
quint16 listenPort, QUuid walletUUID, QString assignmentServerHostname,
|
quint16 listenPort, quint16 childMinListenPort, QUuid walletUUID, QString assignmentServerHostname,
|
||||||
quint16 assignmentServerPort, quint16 httpStatusServerPort, QString logDirectory) :
|
quint16 assignmentServerPort, quint16 httpStatusServerPort, QString logDirectory) :
|
||||||
_httpManager(QHostAddress::LocalHost, httpStatusServerPort, "", this),
|
_httpManager(QHostAddress::LocalHost, httpStatusServerPort, "", this),
|
||||||
_numAssignmentClientForks(numAssignmentClientForks),
|
_numAssignmentClientForks(numAssignmentClientForks),
|
||||||
|
@ -50,8 +50,8 @@ AssignmentClientMonitor::AssignmentClientMonitor(const unsigned int numAssignmen
|
||||||
_assignmentPool(assignmentPool),
|
_assignmentPool(assignmentPool),
|
||||||
_walletUUID(walletUUID),
|
_walletUUID(walletUUID),
|
||||||
_assignmentServerHostname(assignmentServerHostname),
|
_assignmentServerHostname(assignmentServerHostname),
|
||||||
_assignmentServerPort(assignmentServerPort)
|
_assignmentServerPort(assignmentServerPort),
|
||||||
|
_childMinListenPort(childMinListenPort)
|
||||||
{
|
{
|
||||||
qDebug() << "_requestAssignmentType =" << _requestAssignmentType;
|
qDebug() << "_requestAssignmentType =" << _requestAssignmentType;
|
||||||
|
|
||||||
|
@ -100,8 +100,13 @@ void AssignmentClientMonitor::simultaneousWaitOnChildren(int waitMsecs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssignmentClientMonitor::childProcessFinished(qint64 pid, int exitCode, QProcess::ExitStatus exitStatus) {
|
void AssignmentClientMonitor::childProcessFinished(qint64 pid, quint16 listenPort, int exitCode, QProcess::ExitStatus exitStatus) {
|
||||||
auto message = "Child process " + QString::number(pid) + " has %1 with exit code " + QString::number(exitCode) + ".";
|
auto message = "Child process " + QString::number(pid) + " on port " + QString::number(listenPort) +
|
||||||
|
"has %1 with exit code " + QString::number(exitCode) + ".";
|
||||||
|
|
||||||
|
if (listenPort) {
|
||||||
|
_childListenPorts.remove(listenPort);
|
||||||
|
}
|
||||||
|
|
||||||
if (_childProcesses.remove(pid)) {
|
if (_childProcesses.remove(pid)) {
|
||||||
message.append(" Removed from internal map.");
|
message.append(" Removed from internal map.");
|
||||||
|
@ -153,6 +158,23 @@ void AssignmentClientMonitor::aboutToQuit() {
|
||||||
void AssignmentClientMonitor::spawnChildClient() {
|
void AssignmentClientMonitor::spawnChildClient() {
|
||||||
QProcess* assignmentClient = new QProcess(this);
|
QProcess* assignmentClient = new QProcess(this);
|
||||||
|
|
||||||
|
quint16 listenPort = 0;
|
||||||
|
// allocate a port
|
||||||
|
|
||||||
|
if (_childMinListenPort) {
|
||||||
|
for (listenPort = _childMinListenPort; _childListenPorts.contains(listenPort); listenPort++) {
|
||||||
|
if (_maxAssignmentClientForks &&
|
||||||
|
(listenPort >= _maxAssignmentClientForks + _childMinListenPort)) {
|
||||||
|
listenPort = 0;
|
||||||
|
qDebug() << "Insufficient listen ports";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (listenPort) {
|
||||||
|
_childListenPorts.insert(listenPort);
|
||||||
|
}
|
||||||
|
|
||||||
// unparse the parts of the command-line that the child cares about
|
// unparse the parts of the command-line that the child cares about
|
||||||
QStringList _childArguments;
|
QStringList _childArguments;
|
||||||
if (_assignmentPool != "") {
|
if (_assignmentPool != "") {
|
||||||
|
@ -176,6 +198,11 @@ void AssignmentClientMonitor::spawnChildClient() {
|
||||||
_childArguments.append(QString::number(_requestAssignmentType));
|
_childArguments.append(QString::number(_requestAssignmentType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (listenPort) {
|
||||||
|
_childArguments.append("-" + ASSIGNMENT_CLIENT_LISTEN_PORT_OPTION);
|
||||||
|
_childArguments.append(QString::number(listenPort));
|
||||||
|
}
|
||||||
|
|
||||||
// tell children which assignment monitor port to use
|
// tell children which assignment monitor port to use
|
||||||
// for now they simply talk to us on localhost
|
// for now they simply talk to us on localhost
|
||||||
_childArguments.append("--" + ASSIGNMENT_CLIENT_MONITOR_PORT_OPTION);
|
_childArguments.append("--" + ASSIGNMENT_CLIENT_MONITOR_PORT_OPTION);
|
||||||
|
@ -247,8 +274,8 @@ void AssignmentClientMonitor::spawnChildClient() {
|
||||||
auto pid = assignmentClient->processId();
|
auto pid = assignmentClient->processId();
|
||||||
// make sure we hear that this process has finished when it does
|
// make sure we hear that this process has finished when it does
|
||||||
connect(assignmentClient, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
|
connect(assignmentClient, static_cast<void(QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
|
||||||
this, [this, pid](int exitCode, QProcess::ExitStatus exitStatus) {
|
this, [this, listenPort, pid](int exitCode, QProcess::ExitStatus exitStatus) {
|
||||||
childProcessFinished(pid, exitCode, exitStatus);
|
childProcessFinished(pid, listenPort, exitCode, exitStatus);
|
||||||
});
|
});
|
||||||
|
|
||||||
qDebug() << "Spawned a child client with PID" << assignmentClient->processId();
|
qDebug() << "Spawned a child client with PID" << assignmentClient->processId();
|
||||||
|
|
|
@ -37,14 +37,15 @@ class AssignmentClientMonitor : public QObject, public HTTPRequestHandler {
|
||||||
public:
|
public:
|
||||||
AssignmentClientMonitor(const unsigned int numAssignmentClientForks, const unsigned int minAssignmentClientForks,
|
AssignmentClientMonitor(const unsigned int numAssignmentClientForks, const unsigned int minAssignmentClientForks,
|
||||||
const unsigned int maxAssignmentClientForks, Assignment::Type requestAssignmentType,
|
const unsigned int maxAssignmentClientForks, Assignment::Type requestAssignmentType,
|
||||||
QString assignmentPool, quint16 listenPort, QUuid walletUUID, QString assignmentServerHostname,
|
QString assignmentPool, quint16 listenPort, quint16 childMinListenPort, QUuid walletUUID,
|
||||||
quint16 assignmentServerPort, quint16 httpStatusServerPort, QString logDirectory);
|
QString assignmentServerHostname, quint16 assignmentServerPort, quint16 httpStatusServerPort,
|
||||||
|
QString logDirectory);
|
||||||
~AssignmentClientMonitor();
|
~AssignmentClientMonitor();
|
||||||
|
|
||||||
void stopChildProcesses();
|
void stopChildProcesses();
|
||||||
private slots:
|
private slots:
|
||||||
void checkSpares();
|
void checkSpares();
|
||||||
void childProcessFinished(qint64 pid, int exitCode, QProcess::ExitStatus exitStatus);
|
void childProcessFinished(qint64 pid, quint16 port, int exitCode, QProcess::ExitStatus exitStatus);
|
||||||
void handleChildStatusPacket(QSharedPointer<ReceivedMessage> message);
|
void handleChildStatusPacket(QSharedPointer<ReceivedMessage> message);
|
||||||
|
|
||||||
bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false) override;
|
bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false) override;
|
||||||
|
@ -75,6 +76,9 @@ private:
|
||||||
|
|
||||||
QMap<qint64, ACProcess> _childProcesses;
|
QMap<qint64, ACProcess> _childProcesses;
|
||||||
|
|
||||||
|
quint16 _childMinListenPort;
|
||||||
|
QSet<quint16> _childListenPorts;
|
||||||
|
|
||||||
bool _wantsChildFileLogging { false };
|
bool _wantsChildFileLogging { false };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue