From aaf8e60de315ac10d31fa0ef5d0b3b36b8b715b1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Feb 2016 15:11:21 -0800 Subject: [PATCH 1/8] delay critical quit messages until just prior to quit --- domain-server/src/DomainServer.cpp | 36 ++++++++++++------- domain-server/src/DomainServer.h | 3 +- .../src/DomainServerSettingsManager.cpp | 11 ++++-- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index d1cb9d4e4a..e30e009520 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -120,6 +120,14 @@ DomainServer::~DomainServer() { DependencyManager::destroy(); } +void DomainServer::queuedQuit(QString quitMessage, int exitCode) { + if (!quitMessage.isEmpty()) { + qCritical() << qPrintable(quitMessage); + } + + QCoreApplication::exit(exitCode); +} + void DomainServer::aboutToQuit() { // clear the log handler so that Qt doesn't call the destructor on LogHandler @@ -164,8 +172,11 @@ bool DomainServer::optionallyReadX509KeyAndCertificate() { qDebug() << "TCP server listening for HTTPS connections on" << DOMAIN_SERVER_HTTPS_PORT; } else if (!certPath.isEmpty() || !keyPath.isEmpty()) { - qDebug() << "Missing certificate or private key. domain-server will now quit."; - QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection); + static const QString MISSING_CERT_ERROR_MSG = "Missing certificate or private key. domain-server will now quit."; + static const int MISSING_CERT_ERROR_CODE = 3; + + QMetaObject::invokeMethod(this, "queuedQuit", Qt::QueuedConnection, + Q_ARG(QString, MISSING_CERT_ERROR_MSG), Q_ARG(int, MISSING_CERT_ERROR_CODE)); return false; } @@ -199,8 +210,10 @@ bool DomainServer::optionallySetupOAuth() { || _hostname.isEmpty() || _oauthClientID.isEmpty() || _oauthClientSecret.isEmpty()) { - qDebug() << "Missing OAuth provider URL, hostname, client ID, or client secret. domain-server will now quit."; - QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection); + static const QString MISSING_OAUTH_INFO_MSG = "Missing OAuth provider URL, hostname, client ID, or client secret. domain-server will now quit."; + static const int MISSING_OAUTH_INFO_ERROR_CODE = 1542; + QMetaObject::invokeMethod(this, "queuedQuit", Qt::QueuedConnection, + Q_ARG(QString, MISSING_OAUTH_INFO_MSG), Q_ARG(int, MISSING_OAUTH_INFO_ERROR_CODE)); return false; } else { qDebug() << "OAuth will be used to identify clients using provider at" << _oauthProviderURL.toString(); @@ -404,9 +417,13 @@ bool DomainServer::resetAccountManagerAccessToken() { return true; } else { - qDebug() << "Missing OAuth provider URL, but a domain-server feature was required that requires authentication." << - "domain-server will now quit."; - QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection); + static const QString MISSING_OAUTH_PROVIDER_MSG = + QString("Missing OAuth provider URL, but a domain-server feature was required that requires authentication.") + + QString("domain-server will now quit."); + static const int MISSING_OAUTH_PROVIDER_ERROR_CODE = 5323; + QMetaObject::invokeMethod(this, "queuedQuit", Qt::QueuedConnection, + Q_ARG(QString, MISSING_OAUTH_PROVIDER_MSG), + Q_ARG(int, MISSING_OAUTH_PROVIDER_ERROR_CODE)); return false; } @@ -517,11 +534,6 @@ void DomainServer::setupICEHeartbeatForFullNetworking() { } } -void DomainServer::loginFailed() { - qDebug() << "Login to data server has failed. domain-server will now quit"; - QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection); -} - void DomainServer::parseAssignmentConfigs(QSet& excludedTypes) { // check for configs from the command line, these take precedence const QString ASSIGNMENT_CONFIG_REGEX_STRING = "config-([\\d]+)"; diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index afdd7bd26e..326ca3e1a8 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -65,7 +65,6 @@ public slots: private slots: void aboutToQuit(); - void loginFailed(); void setupPendingAssignmentCredits(); void sendPendingTransactionsToServer(); @@ -77,6 +76,8 @@ private slots: void handleTempDomainSuccess(QNetworkReply& requestReply); void handleTempDomainError(QNetworkReply& requestReply); + + void queuedQuit(QString quitMessage, int exitCode); private: void setupNodeListAndAssignments(const QUuid& sessionUUID = QUuid::createUuid()); diff --git a/domain-server/src/DomainServerSettingsManager.cpp b/domain-server/src/DomainServerSettingsManager.cpp index 98bb63241e..2cf62bd00a 100644 --- a/domain-server/src/DomainServerSettingsManager.cpp +++ b/domain-server/src/DomainServerSettingsManager.cpp @@ -62,9 +62,14 @@ DomainServerSettingsManager::DomainServerSettingsManager() : } } - qCritical() << "Did not find settings decription in JSON at" << SETTINGS_DESCRIPTION_RELATIVE_PATH - << "- Unable to continue. domain-server will quit."; - QMetaObject::invokeMethod(QCoreApplication::instance(), "quit", Qt::QueuedConnection); + static const QString MISSING_SETTINGS_DESC_MSG = + QString("Did not find settings decription in JSON at %1 - Unable to continue. domain-server will quit.") + .arg(SETTINGS_DESCRIPTION_RELATIVE_PATH); + static const int MISSING_SETTINGS_DESC_ERROR_CODE = 8912; + + QMetaObject::invokeMethod(QCoreApplication::instance(), "queuedQuit", Qt::QueuedConnection, + Q_ARG(QString, MISSING_SETTINGS_DESC_MSG), + Q_ARG(int, MISSING_SETTINGS_DESC_ERROR_CODE)); } void DomainServerSettingsManager::processSettingsRequestPacket(QSharedPointer message) { From 0f4467c5829a8f3389766dc235c0950f68ab80e3 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Feb 2016 15:17:34 -0800 Subject: [PATCH 2/8] cleanup exit codes for queued DS exit --- domain-server/src/DomainServer.cpp | 4 ++-- domain-server/src/DomainServerSettingsManager.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index e30e009520..d68a2cfc8e 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -211,7 +211,7 @@ bool DomainServer::optionallySetupOAuth() { || _oauthClientID.isEmpty() || _oauthClientSecret.isEmpty()) { static const QString MISSING_OAUTH_INFO_MSG = "Missing OAuth provider URL, hostname, client ID, or client secret. domain-server will now quit."; - static const int MISSING_OAUTH_INFO_ERROR_CODE = 1542; + static const int MISSING_OAUTH_INFO_ERROR_CODE = 4; QMetaObject::invokeMethod(this, "queuedQuit", Qt::QueuedConnection, Q_ARG(QString, MISSING_OAUTH_INFO_MSG), Q_ARG(int, MISSING_OAUTH_INFO_ERROR_CODE)); return false; @@ -420,7 +420,7 @@ bool DomainServer::resetAccountManagerAccessToken() { static const QString MISSING_OAUTH_PROVIDER_MSG = QString("Missing OAuth provider URL, but a domain-server feature was required that requires authentication.") + QString("domain-server will now quit."); - static const int MISSING_OAUTH_PROVIDER_ERROR_CODE = 5323; + static const int MISSING_OAUTH_PROVIDER_ERROR_CODE = 5; QMetaObject::invokeMethod(this, "queuedQuit", Qt::QueuedConnection, Q_ARG(QString, MISSING_OAUTH_PROVIDER_MSG), Q_ARG(int, MISSING_OAUTH_PROVIDER_ERROR_CODE)); diff --git a/domain-server/src/DomainServerSettingsManager.cpp b/domain-server/src/DomainServerSettingsManager.cpp index 2cf62bd00a..49ae03ccd4 100644 --- a/domain-server/src/DomainServerSettingsManager.cpp +++ b/domain-server/src/DomainServerSettingsManager.cpp @@ -65,7 +65,7 @@ DomainServerSettingsManager::DomainServerSettingsManager() : static const QString MISSING_SETTINGS_DESC_MSG = QString("Did not find settings decription in JSON at %1 - Unable to continue. domain-server will quit.") .arg(SETTINGS_DESCRIPTION_RELATIVE_PATH); - static const int MISSING_SETTINGS_DESC_ERROR_CODE = 8912; + static const int MISSING_SETTINGS_DESC_ERROR_CODE = 6; QMetaObject::invokeMethod(QCoreApplication::instance(), "queuedQuit", Qt::QueuedConnection, Q_ARG(QString, MISSING_SETTINGS_DESC_MSG), From f455e404e3d81dd038b573be99b8a85520850f27 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Feb 2016 15:19:57 -0800 Subject: [PATCH 3/8] add an option for assets path --- domain-server/resources/describe-settings.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/domain-server/resources/describe-settings.json b/domain-server/resources/describe-settings.json index 891c586a6a..1a6ca980fe 100644 --- a/domain-server/resources/describe-settings.json +++ b/domain-server/resources/describe-settings.json @@ -168,7 +168,7 @@ }, { "name": "asset_server", - "label": "Asset Server", + "label": "Asset Server (ATP)", "assignment-types": [3], "settings": [ { @@ -178,6 +178,15 @@ "help": "Assigns an asset-server in your domain to serve files to clients via the ATP protocol (over UDP)", "default": true, "advanced": true + }, + { + "name": "assets_path", + "type": "string", + "label": "Assets Path", + "help": "The path to the directory assets are stored in.
If this path is relative, it will be relative to the application data directory. If you change this path you will need to manually copy any existing assets from the previous directory.", + "placeholder": "assets", + "default": "assets", + "advanced": true } ] }, From 7c0b3953e4d47db6de434aaf3f423183148f68b5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Feb 2016 15:34:43 -0800 Subject: [PATCH 4/8] handle custom path in asset-server for assets --- assignment-client/src/assets/AssetServer.cpp | 50 +++++++++++++++++--- assignment-client/src/assets/AssetServer.h | 2 + 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index 8ab53d3b87..443fbff3b1 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -45,25 +45,61 @@ AssetServer::AssetServer(ReceivedMessage& message) : } void AssetServer::run() { + + qDebug() << "Waiting for connection to domain to request settings from domain-server."; + + // wait until we have the domain-server settings, otherwise we bail + DomainHandler& domainHandler = DependencyManager::get()->getDomainHandler(); + connect(&domainHandler, &DomainHandler::settingsReceived, this, &AssetServer::completeSetup); + connect(&domainHandler, &DomainHandler::settingsReceiveFail, this, &AssetServer::domainSettingsRequestFailed); + ThreadedAssignment::commonInit(ASSET_SERVER_LOGGING_TARGET_NAME, NodeType::AssetServer); +} +void AssetServer::completeSetup() { auto nodeList = DependencyManager::get(); - nodeList->addNodeTypeToInterestSet(NodeType::Agent); - const QString RESOURCES_PATH = "assets"; + auto& domainHandler = nodeList->getDomainHandler(); + const QJsonObject& settingsObject = domainHandler.getSettingsObject(); - _resourcesDirectory = QDir(ServerPathUtils::getDataDirectory()).filePath(RESOURCES_PATH); + static const QString ASSET_SERVER_SETTINGS_KEY = "asset_server"; + auto assetServerObject = settingsObject[ASSET_SERVER_SETTINGS_KEY]; + + // get the path to the asset folder from the domain server settings + static const QString ASSETS_PATH_OPTION = "assets_path"; + auto assetsJSONValue = assetServerObject.toObject()[ASSETS_PATH_OPTION]; + + if (assetsJSONValue.type() != QJsonValue::String) { + qCritical() << "Received an assets path from the domain-server that could not be parsed. Stopping assignment."; + setFinished(true); + return; + } + + auto assetsPathString = assetsJSONValue.toString(); + QDir assetsPath { assetsPathString }; + QString absoluteFilePath = assetsPath.absolutePath(); + + if (assetsPath.isRelative()) { + // if the domain settings passed us a relative path, make an absolute path that is relative to the + // default data directory + absoluteFilePath = ServerPathUtils::getDataFilePath(assetsPathString); + } + + _resourcesDirectory = QDir(absoluteFilePath); qDebug() << "Creating resources directory"; _resourcesDirectory.mkpath("."); bool noExistingAssets = !_resourcesDirectory.exists() \ - || _resourcesDirectory.entryList(QDir::Files).size() == 0; + || _resourcesDirectory.entryList(QDir::Files).size() == 0; if (noExistingAssets) { qDebug() << "Asset resources directory not found, searching for existing asset resources"; QString oldDataDirectory = QCoreApplication::applicationDirPath(); - auto oldResourcesDirectory = QDir(oldDataDirectory).filePath("resources/" + RESOURCES_PATH); + + const QString OLD_RESOURCES_PATH = "assets"; + + auto oldResourcesDirectory = QDir(oldDataDirectory).filePath("resources/" + OLD_RESOURCES_PATH); if (QDir(oldResourcesDirectory).exists()) { @@ -111,10 +147,12 @@ void AssetServer::run() { auto hexHash = hash.toHex(); qDebug() << "\tMoving " << filename << " to " << hexHash; - + file.rename(_resourcesDirectory.absoluteFilePath(hexHash) + "." + fileInfo.suffix()); } } + + nodeList->addNodeTypeToInterestSet(NodeType::Agent); } void AssetServer::handleAssetGetInfo(QSharedPointer message, SharedNodePointer senderNode) { diff --git a/assignment-client/src/assets/AssetServer.h b/assignment-client/src/assets/AssetServer.h index fe83ce92a6..7d6e26af08 100644 --- a/assignment-client/src/assets/AssetServer.h +++ b/assignment-client/src/assets/AssetServer.h @@ -29,6 +29,8 @@ public slots: void run(); private slots: + void completeSetup(); + void handleAssetGetInfo(QSharedPointer packet, SharedNodePointer senderNode); void handleAssetGet(QSharedPointer packet, SharedNodePointer senderNode); void handleAssetUpload(QSharedPointer packetList, SharedNodePointer senderNode); From f117bd586724df4f7bc61bd2d2aebcadd3ee535f Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Feb 2016 15:38:50 -0800 Subject: [PATCH 5/8] fix check for string assets path --- assignment-client/src/assets/AssetServer.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index 443fbff3b1..556813d335 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -63,13 +63,20 @@ void AssetServer::completeSetup() { const QJsonObject& settingsObject = domainHandler.getSettingsObject(); static const QString ASSET_SERVER_SETTINGS_KEY = "asset_server"; - auto assetServerObject = settingsObject[ASSET_SERVER_SETTINGS_KEY]; + + if (!settingsObject.contains(ASSET_SERVER_SETTINGS_KEY)) { + qCritical() << "Received settings from the domain-server with no asset-server section. Stopping assignment."; + setFinished(true); + return; + } + + auto assetServerObject = settingsObject[ASSET_SERVER_SETTINGS_KEY].toObject(); // get the path to the asset folder from the domain server settings static const QString ASSETS_PATH_OPTION = "assets_path"; - auto assetsJSONValue = assetServerObject.toObject()[ASSETS_PATH_OPTION]; + auto assetsJSONValue = assetServerObject[ASSETS_PATH_OPTION]; - if (assetsJSONValue.type() != QJsonValue::String) { + if (!assetsJSONValue.isString()) { qCritical() << "Received an assets path from the domain-server that could not be parsed. Stopping assignment."; setFinished(true); return; From 8eaea8a7ffff645e7531c970ae84986309674694 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Feb 2016 15:42:35 -0800 Subject: [PATCH 6/8] clarify asset-server migration message --- assignment-client/src/assets/AssetServer.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index 556813d335..34cd97eca6 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -97,11 +97,10 @@ void AssetServer::completeSetup() { qDebug() << "Creating resources directory"; _resourcesDirectory.mkpath("."); - bool noExistingAssets = !_resourcesDirectory.exists() \ - || _resourcesDirectory.entryList(QDir::Files).size() == 0; + bool noExistingAssets = !_resourcesDirectory.exists() || _resourcesDirectory.entryList(QDir::Files).size() == 0; if (noExistingAssets) { - qDebug() << "Asset resources directory not found, searching for existing asset resources"; + qDebug() << "Asset resources directory empty, searching for existing asset resources to migrate"; QString oldDataDirectory = QCoreApplication::applicationDirPath(); const QString OLD_RESOURCES_PATH = "assets"; From 8c2d69f865f05b519d61fdb7cf0ed04260aa8a85 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Feb 2016 15:45:35 -0800 Subject: [PATCH 7/8] use breaks in help messages for file paths --- domain-server/resources/describe-settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/domain-server/resources/describe-settings.json b/domain-server/resources/describe-settings.json index 1a6ca980fe..760b0f7c40 100644 --- a/domain-server/resources/describe-settings.json +++ b/domain-server/resources/describe-settings.json @@ -183,7 +183,7 @@ "name": "assets_path", "type": "string", "label": "Assets Path", - "help": "The path to the directory assets are stored in.
If this path is relative, it will be relative to the application data directory. If you change this path you will need to manually copy any existing assets from the previous directory.", + "help": "The path to the directory assets are stored in.
If this path is relative, it will be relative to the application data directory.
If you change this path you will need to manually copy any existing assets from the previous directory.", "placeholder": "assets", "default": "assets", "advanced": true @@ -386,7 +386,7 @@ { "name": "persistFilePath", "label": "Entities File Path", - "help": "The path to the file entities are stored in. If this path is relative it will be relative to the application data directory. The filename must end in .json.gz.", + "help": "The path to the file entities are stored in.
If this path is relative it will be relative to the application data directory.
The filename must end in .json.gz.", "placeholder": "models.json.gz", "default": "models.json.gz", "advanced": true From 27d338e81c2c689c958cc554820023324fd71070 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 11 Feb 2016 15:49:13 -0800 Subject: [PATCH 8/8] make any asset path relative to assets dir --- assignment-client/src/assets/AssetServer.cpp | 2 +- domain-server/resources/describe-settings.json | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index 34cd97eca6..4ca2439996 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -89,7 +89,7 @@ void AssetServer::completeSetup() { if (assetsPath.isRelative()) { // if the domain settings passed us a relative path, make an absolute path that is relative to the // default data directory - absoluteFilePath = ServerPathUtils::getDataFilePath(assetsPathString); + absoluteFilePath = ServerPathUtils::getDataFilePath("assets/" + assetsPathString); } _resourcesDirectory = QDir(absoluteFilePath); diff --git a/domain-server/resources/describe-settings.json b/domain-server/resources/describe-settings.json index 760b0f7c40..014d9f3767 100644 --- a/domain-server/resources/describe-settings.json +++ b/domain-server/resources/describe-settings.json @@ -184,8 +184,7 @@ "type": "string", "label": "Assets Path", "help": "The path to the directory assets are stored in.
If this path is relative, it will be relative to the application data directory.
If you change this path you will need to manually copy any existing assets from the previous directory.", - "placeholder": "assets", - "default": "assets", + "default": "", "advanced": true } ]