mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 19:59:28 +02:00
Merge pull request #2703 from birarda/master
tweak so scripted assignments passed via config are static
This commit is contained in:
commit
2657400d6c
1 changed files with 29 additions and 18 deletions
|
@ -278,7 +278,8 @@ void DomainServer::createScriptedAssignmentsFromArray(const QJsonArray &configAr
|
||||||
qDebug() << "Adding scripted assignment to queue -" << *scriptAssignment;
|
qDebug() << "Adding scripted assignment to queue -" << *scriptAssignment;
|
||||||
qDebug() << "URL for script is" << assignmentURL;
|
qDebug() << "URL for script is" << assignmentURL;
|
||||||
|
|
||||||
_assignmentQueue.enqueue(SharedAssignmentPointer(scriptAssignment));
|
// scripts passed on CL or via JSON are static - so they are added back to the queue if the node dies
|
||||||
|
addStaticAssignmentToAssignmentHash(scriptAssignment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -740,6 +741,16 @@ QJsonObject DomainServer::jsonObjectForNode(const SharedNodePointer& node) {
|
||||||
return nodeJson;
|
return nodeJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char ASSIGNMENT_SCRIPT_HOST_LOCATION[] = "resources/web/assignment";
|
||||||
|
|
||||||
|
QString pathForAssignmentScript(const QUuid& assignmentUUID) {
|
||||||
|
QString newPath(ASSIGNMENT_SCRIPT_HOST_LOCATION);
|
||||||
|
newPath += "/";
|
||||||
|
// append the UUID for this script as the new filename, remove the curly braces
|
||||||
|
newPath += uuidStringWithoutCurlyBraces(assignmentUUID);
|
||||||
|
return newPath;
|
||||||
|
}
|
||||||
|
|
||||||
bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url) {
|
bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url) {
|
||||||
const QString JSON_MIME_TYPE = "application/json";
|
const QString JSON_MIME_TYPE = "application/json";
|
||||||
|
|
||||||
|
@ -870,17 +881,13 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
assignmentPool = QString(assignmentPoolValue);
|
assignmentPool = QString(assignmentPoolValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char ASSIGNMENT_SCRIPT_HOST_LOCATION[] = "resources/web/assignment";
|
|
||||||
|
|
||||||
for (int i = 0; i < numInstances; i++) {
|
for (int i = 0; i < numInstances; i++) {
|
||||||
|
|
||||||
// create an assignment for this saved script
|
// create an assignment for this saved script
|
||||||
Assignment* scriptAssignment = new Assignment(Assignment::CreateCommand, Assignment::AgentType, assignmentPool);
|
Assignment* scriptAssignment = new Assignment(Assignment::CreateCommand, Assignment::AgentType, assignmentPool);
|
||||||
|
|
||||||
QString newPath(ASSIGNMENT_SCRIPT_HOST_LOCATION);
|
QString newPath = pathForAssignmentScript(scriptAssignment->getUUID());
|
||||||
newPath += "/";
|
|
||||||
// append the UUID for this script as the new filename, remove the curly braces
|
|
||||||
newPath += uuidStringWithoutCurlyBraces(scriptAssignment->getUUID());
|
|
||||||
|
|
||||||
// create a file with the GUID of the assignment in the script host location
|
// create a file with the GUID of the assignment in the script host location
|
||||||
QFile scriptFile(newPath);
|
QFile scriptFile(newPath);
|
||||||
|
@ -945,6 +952,11 @@ void DomainServer::refreshStaticAssignmentAndAddToQueue(SharedAssignmentPointer&
|
||||||
qDebug() << "Reset UUID for assignment -" << *assignment.data() << "- and added to queue. Old UUID was"
|
qDebug() << "Reset UUID for assignment -" << *assignment.data() << "- and added to queue. Old UUID was"
|
||||||
<< uuidStringWithoutCurlyBraces(oldUUID);
|
<< uuidStringWithoutCurlyBraces(oldUUID);
|
||||||
|
|
||||||
|
if (assignment->getType() == Assignment::AgentType && assignment->getPayload().isEmpty()) {
|
||||||
|
// if this was an Agent without a script URL, we need to rename the old file so it can be retrieved at the new UUID
|
||||||
|
QFile::rename(pathForAssignmentScript(oldUUID), pathForAssignmentScript(assignment->getUUID()));
|
||||||
|
}
|
||||||
|
|
||||||
// add the static assignment back under the right UUID, and to the queue
|
// add the static assignment back under the right UUID, and to the queue
|
||||||
_staticAssignmentHash.insert(assignment->getUUID(), assignment);
|
_staticAssignmentHash.insert(assignment->getUUID(), assignment);
|
||||||
|
|
||||||
|
@ -1019,22 +1031,21 @@ SharedAssignmentPointer DomainServer::deployableAssignmentForRequest(const Assig
|
||||||
bool assignmentPoolsMatch = assignment->getPool() == requestAssignment.getPool();
|
bool assignmentPoolsMatch = assignment->getPool() == requestAssignment.getPool();
|
||||||
|
|
||||||
if ((requestIsAllTypes || assignmentTypesMatch) && (nietherHasPool || assignmentPoolsMatch)) {
|
if ((requestIsAllTypes || assignmentTypesMatch) && (nietherHasPool || assignmentPoolsMatch)) {
|
||||||
|
|
||||||
if (assignment->getType() == Assignment::AgentType) {
|
// remove the assignment from the queue
|
||||||
// if there is more than one instance to send out, simply decrease the number of instances
|
SharedAssignmentPointer deployableAssignment = _assignmentQueue.takeAt(sharedAssignment
|
||||||
return _assignmentQueue.takeAt(sharedAssignment - _assignmentQueue.begin());
|
- _assignmentQueue.begin());
|
||||||
} else {
|
|
||||||
// remove the assignment from the queue
|
if (deployableAssignment->getType() != Assignment::AgentType
|
||||||
SharedAssignmentPointer deployableAssignment = _assignmentQueue.takeAt(sharedAssignment
|
|| _staticAssignmentHash.contains(deployableAssignment->getUUID())) {
|
||||||
- _assignmentQueue.begin());
|
// this is a static assignment
|
||||||
|
|
||||||
// until we get a check-in from that GUID
|
// until we get a check-in from that GUID
|
||||||
// put assignment back in queue but stick it at the back so the others have a chance to go out
|
// put assignment back in queue but stick it at the back so the others have a chance to go out
|
||||||
_assignmentQueue.enqueue(deployableAssignment);
|
_assignmentQueue.enqueue(deployableAssignment);
|
||||||
|
|
||||||
// stop looping, we've handed out an assignment
|
|
||||||
return deployableAssignment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stop looping, we've handed out an assignment
|
||||||
|
return deployableAssignment;
|
||||||
} else {
|
} else {
|
||||||
// push forward the iterator to check the next assignment
|
// push forward the iterator to check the next assignment
|
||||||
++sharedAssignment;
|
++sharedAssignment;
|
||||||
|
|
Loading…
Reference in a new issue