mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 19:04:27 +02:00
Merge pull request #2686 from birarda/ds-script-preload
allow passing of preload scripts to DS on launch
This commit is contained in:
commit
4fe2ec3950
3 changed files with 62 additions and 11 deletions
|
@ -148,14 +148,19 @@ void Agent::run() {
|
||||||
<< NodeType::ParticleServer);
|
<< NodeType::ParticleServer);
|
||||||
|
|
||||||
// figure out the URL for the script for this agent assignment
|
// figure out the URL for the script for this agent assignment
|
||||||
QString scriptURLString("http://%1:8080/assignment/%2");
|
QUrl scriptURL;
|
||||||
scriptURLString = scriptURLString.arg(NodeList::getInstance()->getDomainHandler().getIP().toString(),
|
if (_payload.isEmpty()) {
|
||||||
uuidStringWithoutCurlyBraces(_uuid));
|
scriptURL = QUrl(QString("http://%1:8080/assignment/%2")
|
||||||
|
.arg(NodeList::getInstance()->getDomainHandler().getIP().toString(),
|
||||||
|
uuidStringWithoutCurlyBraces(_uuid)));
|
||||||
|
} else {
|
||||||
|
scriptURL = QUrl(_payload);
|
||||||
|
}
|
||||||
|
|
||||||
QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
|
QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
|
||||||
QNetworkReply *reply = networkManager->get(QNetworkRequest(QUrl(scriptURLString)));
|
QNetworkReply *reply = networkManager->get(QNetworkRequest(scriptURL));
|
||||||
|
|
||||||
qDebug() << "Downloading script at" << scriptURLString;
|
qDebug() << "Downloading script at" << scriptURL.toString();
|
||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||||
|
|
|
@ -187,7 +187,7 @@ void DomainServer::setupNodeListAndAssignments(const QUuid& sessionUUID) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSet<Assignment::Type> parsedTypes(QSet<Assignment::Type>() << Assignment::AgentType);
|
QSet<Assignment::Type> parsedTypes;
|
||||||
parseAssignmentConfigs(parsedTypes);
|
parseAssignmentConfigs(parsedTypes);
|
||||||
|
|
||||||
populateDefaultStaticAssignmentsExcludingTypes(parsedTypes);
|
populateDefaultStaticAssignmentsExcludingTypes(parsedTypes);
|
||||||
|
@ -222,12 +222,19 @@ void DomainServer::parseAssignmentConfigs(QSet<Assignment::Type>& excludedTypes)
|
||||||
|
|
||||||
if (assignmentType < Assignment::AllTypes && !excludedTypes.contains(assignmentType)) {
|
if (assignmentType < Assignment::AllTypes && !excludedTypes.contains(assignmentType)) {
|
||||||
QVariant mapValue = _argumentVariantMap[variantMapKeys[configIndex]];
|
QVariant mapValue = _argumentVariantMap[variantMapKeys[configIndex]];
|
||||||
|
QJsonArray assignmentArray;
|
||||||
|
|
||||||
if (mapValue.type() == QVariant::String) {
|
if (mapValue.type() == QVariant::String) {
|
||||||
QJsonDocument deserializedDocument = QJsonDocument::fromJson(mapValue.toString().toUtf8());
|
QJsonDocument deserializedDocument = QJsonDocument::fromJson(mapValue.toString().toUtf8());
|
||||||
createStaticAssignmentsForType(assignmentType, deserializedDocument.array());
|
assignmentArray = deserializedDocument.array();
|
||||||
} else {
|
} else {
|
||||||
createStaticAssignmentsForType(assignmentType, mapValue.toJsonValue().toArray());
|
assignmentArray = mapValue.toJsonValue().toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (assignmentType != Assignment::AgentType) {
|
||||||
|
createStaticAssignmentsForType(assignmentType, assignmentArray);
|
||||||
|
} else {
|
||||||
|
createScriptedAssignmentsFromArray(assignmentArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
excludedTypes.insert(assignmentType);
|
excludedTypes.insert(assignmentType);
|
||||||
|
@ -242,6 +249,42 @@ void DomainServer::addStaticAssignmentToAssignmentHash(Assignment* newAssignment
|
||||||
_staticAssignmentHash.insert(newAssignment->getUUID(), SharedAssignmentPointer(newAssignment));
|
_staticAssignmentHash.insert(newAssignment->getUUID(), SharedAssignmentPointer(newAssignment));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DomainServer::createScriptedAssignmentsFromArray(const QJsonArray &configArray) {
|
||||||
|
foreach(const QJsonValue& jsonValue, configArray) {
|
||||||
|
if (jsonValue.isObject()) {
|
||||||
|
QJsonObject jsonObject = jsonValue.toObject();
|
||||||
|
|
||||||
|
// make sure we were passed a URL, otherwise this is an invalid scripted assignment
|
||||||
|
const QString ASSIGNMENT_URL_KEY = "url";
|
||||||
|
QString assignmentURL = jsonObject[ASSIGNMENT_URL_KEY].toString();
|
||||||
|
|
||||||
|
if (!assignmentURL.isEmpty()) {
|
||||||
|
// check the json for a pool
|
||||||
|
const QString ASSIGNMENT_POOL_KEY = "pool";
|
||||||
|
QString assignmentPool = jsonObject[ASSIGNMENT_POOL_KEY].toString();
|
||||||
|
|
||||||
|
// check for a number of instances, if not passed then default is 1
|
||||||
|
const QString ASSIGNMENT_INSTANCES_KEY = "instances";
|
||||||
|
int numInstances = jsonObject[ASSIGNMENT_INSTANCES_KEY].toInt();
|
||||||
|
numInstances = (numInstances == 0 ? 1 : numInstances);
|
||||||
|
|
||||||
|
for (int i = 0; i < numInstances; i++) {
|
||||||
|
// add a scripted assignment to the queue for this instance
|
||||||
|
Assignment* scriptAssignment = new Assignment(Assignment::CreateCommand,
|
||||||
|
Assignment::AgentType,
|
||||||
|
assignmentPool);
|
||||||
|
scriptAssignment->setPayload(assignmentURL.toUtf8());
|
||||||
|
|
||||||
|
qDebug() << "Adding scripted assignment to queue -" << *scriptAssignment;
|
||||||
|
qDebug() << "URL for script is" << assignmentURL;
|
||||||
|
|
||||||
|
_assignmentQueue.enqueue(SharedAssignmentPointer(scriptAssignment));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DomainServer::createStaticAssignmentsForType(Assignment::Type type, const QJsonArray& configArray) {
|
void DomainServer::createStaticAssignmentsForType(Assignment::Type type, const QJsonArray& configArray) {
|
||||||
// we have a string for config for this type
|
// we have a string for config for this type
|
||||||
qDebug() << "Parsing config for assignment type" << type;
|
qDebug() << "Parsing config for assignment type" << type;
|
||||||
|
@ -284,8 +327,10 @@ void DomainServer::createStaticAssignmentsForType(Assignment::Type type, const Q
|
||||||
|
|
||||||
void DomainServer::populateDefaultStaticAssignmentsExcludingTypes(const QSet<Assignment::Type>& excludedTypes) {
|
void DomainServer::populateDefaultStaticAssignmentsExcludingTypes(const QSet<Assignment::Type>& excludedTypes) {
|
||||||
// enumerate over all assignment types and see if we've already excluded it
|
// enumerate over all assignment types and see if we've already excluded it
|
||||||
for (int defaultedType = Assignment::AudioMixerType; defaultedType != Assignment::AllTypes; defaultedType++) {
|
for (Assignment::Type defaultedType = Assignment::AudioMixerType;
|
||||||
if (!excludedTypes.contains((Assignment::Type) defaultedType)) {
|
defaultedType != Assignment::AllTypes;
|
||||||
|
defaultedType = static_cast<Assignment::Type>(static_cast<int>(defaultedType) + 1)) {
|
||||||
|
if (!excludedTypes.contains(defaultedType) && defaultedType != Assignment::AgentType) {
|
||||||
// type has not been set from a command line or config file config, use the default
|
// type has not been set from a command line or config file config, use the default
|
||||||
// by clearing whatever exists and writing a single default assignment with no payload
|
// by clearing whatever exists and writing a single default assignment with no payload
|
||||||
Assignment* newAssignment = new Assignment(Assignment::CreateCommand, (Assignment::Type) defaultedType);
|
Assignment* newAssignment = new Assignment(Assignment::CreateCommand, (Assignment::Type) defaultedType);
|
||||||
|
|
|
@ -66,6 +66,7 @@ private:
|
||||||
|
|
||||||
void parseAssignmentConfigs(QSet<Assignment::Type>& excludedTypes);
|
void parseAssignmentConfigs(QSet<Assignment::Type>& excludedTypes);
|
||||||
void addStaticAssignmentToAssignmentHash(Assignment* newAssignment);
|
void addStaticAssignmentToAssignmentHash(Assignment* newAssignment);
|
||||||
|
void createScriptedAssignmentsFromArray(const QJsonArray& configArray);
|
||||||
void createStaticAssignmentsForType(Assignment::Type type, const QJsonArray& configArray);
|
void createStaticAssignmentsForType(Assignment::Type type, const QJsonArray& configArray);
|
||||||
void populateDefaultStaticAssignmentsExcludingTypes(const QSet<Assignment::Type>& excludedTypes);
|
void populateDefaultStaticAssignmentsExcludingTypes(const QSet<Assignment::Type>& excludedTypes);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue