mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
Ref T150, database reader using watchdog
* removed canConnect DB checks, using watchdog * changed signature to: int requestHeadersOfSharedFiles * rely on shared working URL from watchdog
This commit is contained in:
committed by
Mathew Sutcliffe
parent
fdfa2233fb
commit
46d2f2c048
@@ -10,6 +10,7 @@
|
|||||||
#include "blackcore/db/databasereader.h"
|
#include "blackcore/db/databasereader.h"
|
||||||
#include "blackcore/db/infodatareader.h"
|
#include "blackcore/db/infodatareader.h"
|
||||||
#include "blackcore/db/databaseutils.h"
|
#include "blackcore/db/databaseutils.h"
|
||||||
|
#include "blackcore/db/networkwatchdog.h"
|
||||||
#include "blackcore/webdataservices.h"
|
#include "blackcore/webdataservices.h"
|
||||||
#include "blackcore/application.h"
|
#include "blackcore/application.h"
|
||||||
#include "blackmisc/db/datastoreutility.h"
|
#include "blackmisc/db/datastoreutility.h"
|
||||||
@@ -39,13 +40,9 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
namespace Db
|
namespace Db
|
||||||
{
|
{
|
||||||
CUrl CDatabaseReader::s_workingSharedDbData;
|
|
||||||
|
|
||||||
CDatabaseReader::CDatabaseReader(QObject *owner, const CDatabaseReaderConfigList &config, const QString &name) :
|
CDatabaseReader::CDatabaseReader(QObject *owner, const CDatabaseReaderConfigList &config, const QString &name) :
|
||||||
BlackCore::CThreadedReader(owner, name), m_config(config)
|
BlackCore::CThreadedReader(owner, name), m_config(config)
|
||||||
{
|
{ }
|
||||||
CDatabaseReader::initWorkingUrls();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDatabaseReader::readInBackgroundThread(CEntityFlags::Entity entities, const QDateTime &newerThan)
|
void CDatabaseReader::readInBackgroundThread(CEntityFlags::Entity entities, const QDateTime &newerThan)
|
||||||
{
|
{
|
||||||
@@ -291,6 +288,14 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
this->receivedSharedFileHeaderNonClosing(nwReply);
|
this->receivedSharedFileHeaderNonClosing(nwReply);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (dsr.isLoadedFromDb())
|
||||||
|
{
|
||||||
|
const bool s = !dsr.hasErrorMessage();
|
||||||
|
emit this->swiftDbDataRead(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
return dsr;
|
return dsr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,20 +377,25 @@ namespace BlackCore
|
|||||||
return m_sharedFileResponses[entity].getLastModifiedTimestamp();
|
return m_sharedFileResponses[entity].getLastModifiedTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDatabaseReader::requestHeadersOfSharedFiles(CEntityFlags::Entity entities)
|
int CDatabaseReader::requestHeadersOfSharedFiles(CEntityFlags::Entity entities)
|
||||||
{
|
{
|
||||||
if (!this->isInternetAccessible(QString("No network/internet access, will not read shared file headers for %1").arg(CEntityFlags::flagToString(entities)))) { return false; }
|
if (!this->isInternetAccessible(QString("No network/internet access, will not read shared file headers for %1").arg(CEntityFlags::flagToString(entities)))) { return false; }
|
||||||
|
|
||||||
CEntityFlags::Entity allEntities(this->maskBySupportedEntities(entities));
|
CEntityFlags::Entity allEntities(this->maskBySupportedEntities(entities));
|
||||||
CEntityFlags::Entity currentEntity = CEntityFlags::iterateDbEntities(allEntities);
|
CEntityFlags::Entity currentEntity = CEntityFlags::iterateDbEntities(allEntities);
|
||||||
const CUrl urlSharedData = CGlobalSetup::buildDbDataDirectory(getWorkingDbDataFileLocationUrl());
|
const CUrl urlSharedDbdata = CDatabaseReader::getWorkingSharedDbdataDirectoryUrl();
|
||||||
|
if (urlSharedDbdata.isEmpty())
|
||||||
|
{
|
||||||
|
CLogMessage(this).warning("No working shared URL, cannot request headers");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int c = 0;
|
int c = 0;
|
||||||
while (currentEntity != CEntityFlags::NoEntity)
|
while (currentEntity != CEntityFlags::NoEntity)
|
||||||
{
|
{
|
||||||
const QString fileName = CDbInfo::entityToSharedName(currentEntity);
|
const QString fileName = CDbInfo::entityToSharedName(currentEntity);
|
||||||
Q_ASSERT_X(!fileName.isEmpty(), Q_FUNC_INFO, "No file name for entity");
|
Q_ASSERT_X(!fileName.isEmpty(), Q_FUNC_INFO, "No file name for entity");
|
||||||
CUrl url = urlSharedData;
|
CUrl url = urlSharedDbdata;
|
||||||
url.appendPath(fileName);
|
url.appendPath(fileName);
|
||||||
|
|
||||||
const QString entityString = CEntityFlags::flagToString(currentEntity);
|
const QString entityString = CEntityFlags::flagToString(currentEntity);
|
||||||
@@ -497,7 +507,7 @@ namespace BlackCore
|
|||||||
return this->getDbServiceBaseUrl().withAppendedPath("/service");
|
return this->getDbServiceBaseUrl().withAppendedPath("/service");
|
||||||
case CDbFlags::SharedInfoOnly:
|
case CDbFlags::SharedInfoOnly:
|
||||||
case CDbFlags::Shared:
|
case CDbFlags::Shared:
|
||||||
return CDatabaseReader::getWorkingDbDataFileLocationUrl();
|
return CDatabaseReader::getWorkingSharedDbdataDirectoryUrl();
|
||||||
default:
|
default:
|
||||||
qFatal("Wrong mode");
|
qFatal("Wrong mode");
|
||||||
break;
|
break;
|
||||||
@@ -525,12 +535,12 @@ namespace BlackCore
|
|||||||
nwReply->close();
|
nwReply->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDatabaseReader::receivedSharedFileHeaderNonClosing(QNetworkReply *nwReply)
|
void CDatabaseReader::receivedSharedFileHeaderNonClosing(QNetworkReply *nwReplyPtr)
|
||||||
{
|
{
|
||||||
if (this->isAbandoned()) { return; }
|
if (this->isAbandoned()) { return; }
|
||||||
|
|
||||||
const HeaderResponse headerResponse = this->transformReplyIntoHeaderResponse(nwReply);
|
const HeaderResponse headerResponse = this->transformReplyIntoHeaderResponse(nwReplyPtr);
|
||||||
const QString fileName = nwReply->url().fileName();
|
const QString fileName = nwReplyPtr->url().fileName();
|
||||||
const CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(fileName);
|
const CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(fileName);
|
||||||
this->m_sharedFileResponses[entity] = headerResponse;
|
this->m_sharedFileResponses[entity] = headerResponse;
|
||||||
|
|
||||||
@@ -650,9 +660,10 @@ namespace BlackCore
|
|||||||
return dbUrl;
|
return dbUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
CUrl CDatabaseReader::getWorkingDbDataFileLocationUrl()
|
CUrl CDatabaseReader::getWorkingSharedDbdataDirectoryUrl()
|
||||||
{
|
{
|
||||||
return CDatabaseReader::s_workingSharedDbData;
|
const CUrl sharedUrl(sApp->getWorkingSharedUrl());
|
||||||
|
return CGlobalSetup::buildDbDataDirectoryUrl(sharedUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDatabaseReader::cacheHasChanged(CEntityFlags::Entity entities)
|
void CDatabaseReader::cacheHasChanged(CEntityFlags::Entity entities)
|
||||||
@@ -660,24 +671,6 @@ namespace BlackCore
|
|||||||
this->emitReadSignalPerSingleCachedEntity(entities, false);
|
this->emitReadSignalPerSingleCachedEntity(entities, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CDatabaseReader::canPingSwiftServer()
|
|
||||||
{
|
|
||||||
const CUrl url(getDbUrl());
|
|
||||||
return CNetworkUtils::canConnect(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CDatabaseReader::initWorkingUrls(bool force)
|
|
||||||
{
|
|
||||||
if (!force && !CDatabaseReader::s_workingSharedDbData.isEmpty()) { return false; }
|
|
||||||
CDatabaseReader::s_workingSharedDbData = sApp->getGlobalSetup().getSwiftDbDataFileLocationUrls().getRandomWorkingUrl();
|
|
||||||
return !CDatabaseReader::s_workingSharedDbData.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
CUrl CDatabaseReader::getCurrentSharedDbDataUrl()
|
|
||||||
{
|
|
||||||
return CDatabaseReader::s_workingSharedDbData;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDatabaseReader::stringToDatastoreResponse(const QString &jsonContent, JsonDatastoreResponse &datastoreResponse)
|
void CDatabaseReader::stringToDatastoreResponse(const QString &jsonContent, JsonDatastoreResponse &datastoreResponse)
|
||||||
{
|
{
|
||||||
if (jsonContent.isEmpty())
|
if (jsonContent.isEmpty())
|
||||||
@@ -709,6 +702,11 @@ namespace BlackCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CDatabaseReader::JsonDatastoreResponse::isLoadedFromDb() const
|
||||||
|
{
|
||||||
|
return CNetworkWatchdog::isDbUrl(this->getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
void CDatabaseReader::JsonDatastoreResponse::setJsonArray(const QJsonArray &value)
|
void CDatabaseReader::JsonDatastoreResponse::setJsonArray(const QJsonArray &value)
|
||||||
{
|
{
|
||||||
m_jsonArray = value;
|
m_jsonArray = value;
|
||||||
|
|||||||
@@ -127,6 +127,9 @@ namespace BlackCore
|
|||||||
//! Incremental data, restricted by query?
|
//! Incremental data, restricted by query?
|
||||||
bool isRestricted() const { return m_restricted; }
|
bool isRestricted() const { return m_restricted; }
|
||||||
|
|
||||||
|
//! Is loaded from database
|
||||||
|
bool isLoadedFromDb() const;
|
||||||
|
|
||||||
//! Mark as restricted
|
//! Mark as restricted
|
||||||
void setRestricted(bool restricted) { m_restricted = restricted; }
|
void setRestricted(bool restricted) { m_restricted = restricted; }
|
||||||
|
|
||||||
@@ -229,8 +232,9 @@ namespace BlackCore
|
|||||||
//! Those entities where the timestamp of shared info obejct is newer than the cache timestamp
|
//! Those entities where the timestamp of shared info obejct is newer than the cache timestamp
|
||||||
BlackMisc::Network::CEntityFlags::Entity getEntitesWithNewerSharedInfoObject(BlackMisc::Network::CEntityFlags::Entity entities) const;
|
BlackMisc::Network::CEntityFlags::Entity getEntitesWithNewerSharedInfoObject(BlackMisc::Network::CEntityFlags::Entity entities) const;
|
||||||
|
|
||||||
//! Request header of shared file
|
//! Request headers of shared file
|
||||||
bool requestHeadersOfSharedFiles(BlackMisc::Network::CEntityFlags::Entity entities);
|
//! \return number of requested headers
|
||||||
|
int requestHeadersOfSharedFiles(BlackMisc::Network::CEntityFlags::Entity entities);
|
||||||
|
|
||||||
//! Status message (error message)
|
//! Status message (error message)
|
||||||
const QString &getStatusMessage() const;
|
const QString &getStatusMessage() const;
|
||||||
@@ -241,20 +245,14 @@ namespace BlackCore
|
|||||||
//! Log categories
|
//! Log categories
|
||||||
static const BlackMisc::CLogCategoryList &getLogCategories();
|
static const BlackMisc::CLogCategoryList &getLogCategories();
|
||||||
|
|
||||||
//! swift DB server reachable?
|
|
||||||
static bool canPingSwiftServer();
|
|
||||||
|
|
||||||
//! Init the working URLs
|
|
||||||
static bool initWorkingUrls(bool force = false);
|
|
||||||
|
|
||||||
//! Currently used URL for shared DB data
|
|
||||||
static BlackMisc::Network::CUrl getCurrentSharedDbDataUrl();
|
|
||||||
|
|
||||||
//! Transform JSON data to response struct data
|
//! Transform JSON data to response struct data
|
||||||
//! \private used also for samples, that`s why it is declared public
|
//! \private used also for samples, that`s why it is declared public
|
||||||
static void stringToDatastoreResponse(const QString &jsonContent, CDatabaseReader::JsonDatastoreResponse &datastoreResponse);
|
static void stringToDatastoreResponse(const QString &jsonContent, CDatabaseReader::JsonDatastoreResponse &datastoreResponse);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
//! DB have been read
|
||||||
|
void swiftDbDataRead(bool success);
|
||||||
|
|
||||||
//! Combined read signal
|
//! Combined read signal
|
||||||
void dataRead(BlackMisc::Network::CEntityFlags::Entity entities, BlackMisc::Network::CEntityFlags::ReadState state, int number);
|
void dataRead(BlackMisc::Network::CEntityFlags::Entity entities, BlackMisc::Network::CEntityFlags::ReadState state, int number);
|
||||||
|
|
||||||
@@ -299,15 +297,14 @@ namespace BlackCore
|
|||||||
//! Log if no working URL exists, using m_noWorkingUrlSeverity
|
//! Log if no working URL exists, using m_noWorkingUrlSeverity
|
||||||
void logNoWorkingUrl(BlackMisc::Network::CEntityFlags::Entity entity);
|
void logNoWorkingUrl(BlackMisc::Network::CEntityFlags::Entity entity);
|
||||||
|
|
||||||
//! Base URL
|
//! Base URL for mode (either a shared or DB URL)
|
||||||
BlackMisc::Network::CUrl getBaseUrl(BlackMisc::Db::CDbFlags::DataRetrievalModeFlag mode) const;
|
BlackMisc::Network::CUrl getBaseUrl(BlackMisc::Db::CDbFlags::DataRetrievalModeFlag mode) const;
|
||||||
|
|
||||||
//! DB base URL
|
//! DB base URL
|
||||||
static const BlackMisc::Network::CUrl &getDbUrl();
|
static const BlackMisc::Network::CUrl &getDbUrl();
|
||||||
|
|
||||||
//! Get the working shared URL, initialized by CDatabaseReader::initWorkingUrls
|
//! Working shared "dbdata" directory URL
|
||||||
//! \remark normally constant after startup phase
|
static BlackMisc::Network::CUrl getWorkingSharedDbdataDirectoryUrl();
|
||||||
static BlackMisc::Network::CUrl getWorkingDbDataFileLocationUrl();
|
|
||||||
|
|
||||||
//! File name for given mode, either php service or shared file name
|
//! File name for given mode, either php service or shared file name
|
||||||
static QString fileNameForMode(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Db::CDbFlags::DataRetrievalModeFlag mode);
|
static QString fileNameForMode(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Db::CDbFlags::DataRetrievalModeFlag mode);
|
||||||
@@ -349,9 +346,6 @@ namespace BlackCore
|
|||||||
static bool isChangedUrl(const BlackMisc::Network::CUrl &oldUrl, const BlackMisc::Network::CUrl ¤tUrl);
|
static bool isChangedUrl(const BlackMisc::Network::CUrl &oldUrl, const BlackMisc::Network::CUrl ¤tUrl);
|
||||||
//! @}
|
//! @}
|
||||||
|
|
||||||
private:
|
|
||||||
static BlackMisc::Network::CUrl s_workingSharedDbData; //!< one choosen URL for all DB reader objects
|
|
||||||
|
|
||||||
//! Start reading in own thread (without config/caching)
|
//! Start reading in own thread (without config/caching)
|
||||||
//! \remarks can handle DB or shared file reads
|
//! \remarks can handle DB or shared file reads
|
||||||
void startReadFromBackendInBackgroundThread(BlackMisc::Network::CEntityFlags::Entity entities, BlackMisc::Db::CDbFlags::DataRetrievalModeFlag mode, const QDateTime &newerThan = QDateTime());
|
void startReadFromBackendInBackgroundThread(BlackMisc::Network::CEntityFlags::Entity entities, BlackMisc::Db::CDbFlags::DataRetrievalModeFlag mode, const QDateTime &newerThan = QDateTime());
|
||||||
@@ -360,7 +354,7 @@ namespace BlackCore
|
|||||||
void receivedSharedFileHeader(QNetworkReply *nwReplyPtr);
|
void receivedSharedFileHeader(QNetworkReply *nwReplyPtr);
|
||||||
|
|
||||||
//! Received a reply of a header for a shared file
|
//! Received a reply of a header for a shared file
|
||||||
void receivedSharedFileHeaderNonClosing(QNetworkReply *nwReply);
|
void receivedSharedFileHeaderNonClosing(QNetworkReply *nwReplyPtr);
|
||||||
|
|
||||||
//! Check if terminated or error, otherwise split into array of objects
|
//! Check if terminated or error, otherwise split into array of objects
|
||||||
JsonDatastoreResponse transformReplyIntoDatastoreResponse(QNetworkReply *nwReply) const;
|
JsonDatastoreResponse transformReplyIntoDatastoreResponse(QNetworkReply *nwReply) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user