refs #497, changed and improved handling of bootstrap files

* changed global setup (port, root directory)
* version for bootstrap files
This commit is contained in:
Klaus Basan
2015-10-28 17:04:49 +01:00
committed by Mathew Sutcliffe
parent 23856bbc57
commit 03f4aa6889
10 changed files with 150 additions and 80 deletions

View File

@@ -5,15 +5,14 @@
"url": "https://vatsim-germany.org:50443/mapping/public/bootstrap" "url": "https://vatsim-germany.org:50443/mapping/public/bootstrap"
}, },
{ {
"url": "http://ubuntu12/public/bootstrap" "url": "http://ubuntu12/swiftdatastore/public/bootstrap"
} }
] ]
}, },
"dbIcaoReader": { "dbHttpPort": 80,
"url": "http://ubuntu12/vatrep/public" "dbHttpsPort": 443,
}, "dbRootDirectory": {
"dbModelReader": { "url": "http://ubuntu12/swiftdatastore/public"
"url": "http://ubuntu12/vatrep/public"
}, },
"fsdTestServers": { "fsdTestServers": {
"containerbase": [ "containerbase": [
@@ -45,7 +44,7 @@
"containerbase": [ "containerbase": [
] ]
}, },
"timestampMSecsSinceEpoch": 0, "timestampMSecsSinceEpoch": 1445201830000,
"vatsimBookings": { "vatsimBookings": {
"url": "http://vatbook.euroutepro.com/xml2.php" "url": "http://vatbook.euroutepro.com/xml2.php"
}, },

View File

@@ -5,14 +5,13 @@
"url": "https://vatsim-germany.org:50443/mapping/public/bootstrap" "url": "https://vatsim-germany.org:50443/mapping/public/bootstrap"
}, },
{ {
"url": "http://ubuntu12/public/bootstrap" "url": "http://ubuntu12/swiftdatastore/public/bootstrap"
} }
] ]
}, },
"dbIcaoReader": { "dbHttpPort": 5080,
"url": "https://vatsim-germany.org:50443/mapping/public" "dbHttpsPort": 50443,
}, "dbRootDirectory": {
"dbModelReader": {
"url": "https://vatsim-germany.org:50443/mapping/public" "url": "https://vatsim-germany.org:50443/mapping/public"
}, },
"fsdTestServers": { "fsdTestServers": {
@@ -45,7 +44,7 @@
"containerbase": [ "containerbase": [
] ]
}, },
"timestampMSecsSinceEpoch": 0, "timestampMSecsSinceEpoch": 1445201830000,
"vatsimBookings": { "vatsimBookings": {
"url": "http://vatbook.euroutepro.com/xml2.php" "url": "http://vatbook.euroutepro.com/xml2.php"
}, },

View File

@@ -5,15 +5,14 @@
"url": "https://vatsim-germany.org:50443/mapping/public/bootstrap" "url": "https://vatsim-germany.org:50443/mapping/public/bootstrap"
}, },
{ {
"url": "http://ubuntu12/public/bootstrap" "url": "http://ubuntu12/swiftdatastore/public/bootstrap"
} }
] ]
}, },
"dbIcaoReader": { "dbHttpPort": 5080,
"url": "http://ubuntu12/vatrep/public" "dbHttpsPort": 50443,
}, "dbRootDirectory": {
"dbModelReader": { "url": "https://vatsim-germany.org:50443/mapping/public"
"url": "http://ubuntu12/vatrep/public"
}, },
"fsdTestServers": { "fsdTestServers": {
"containerbase": [ "containerbase": [
@@ -45,7 +44,7 @@
"containerbase": [ "containerbase": [
] ]
}, },
"timestampMSecsSinceEpoch": 0, "timestampMSecsSinceEpoch": 1445201830000,
"vatsimBookings": { "vatsimBookings": {
"url": "http://vatbook.euroutepro.com/xml2.php" "url": "http://vatbook.euroutepro.com/xml2.php"
}, },

View File

@@ -7,17 +7,19 @@ CONFIG -= qt
OTHER_FILES += data/images/flags/*.png OTHER_FILES += data/images/flags/*.png
OTHER_FILES += data/images/airlines/*.png OTHER_FILES += data/images/airlines/*.png
OTHER_FILES += swiftDB/*.* OTHER_FILES += swiftDB/*.*
OTHER_FILES += bootstrap/productive/*.* OTHER_FILES += bootstrap/0.6/productive/*.*
OTHER_FILES += bootstrap/development/*.* OTHER_FILES += bootstrap/0.6/development/*.*
OTHER_FILES += local.env.template/*.* OTHER_FILES += local.env.template/*.*
OTHER_FILES += local.env.template/bootstrap/*.* OTHER_FILES += local.env.template/bootstrap/*.*
OTHER_FILES += local.env.template/bootstrap/0.6/*.*
COPY_FILES += $$PWD/data/images/flags/*.png COPY_FILES += $$PWD/data/images/flags/*.png
COPY_FILES += $$PWD/data/images/airlines/*.png COPY_FILES += $$PWD/data/images/airlines/*.png
COPY_FILES += $$PWD/swiftDB/*.* COPY_FILES += $$PWD/swiftDB/*.*
COPY_FILES += $$PWD/bootstrap/productive/*.* COPY_FILES += $$PWD/bootstrap/0.6/productive/*.*
COPY_FILES += $$PWD/bootstrap/development/*.* COPY_FILES += $$PWD/bootstrap/0.6/development/*.*
COPY_FILES += $$PWD/local.env.template/*.* COPY_FILES += $$PWD/local.env.template/*.*
COPY_FILES += $$PWD/local.env.template/bootstrap/*.* COPY_FILES += $$PWD/local.env.template/bootstrap/*.*
COPY_FILES += $$PWD/local.env.template/bootstrap/0.6/*.*
load(common_post) load(common_post)

View File

@@ -9,6 +9,7 @@
#include "globalsetup.h" #include "globalsetup.h"
#include "blackmisc/math/mathutils.h" #include "blackmisc/math/mathutils.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include <QStringList> #include <QStringList>
using namespace BlackMisc; using namespace BlackMisc;
@@ -21,29 +22,55 @@ namespace BlackCore
{ {
CGlobalSetup::CGlobalSetup() : CGlobalSetup::CGlobalSetup() :
ITimestampBased(0), ITimestampBased(0),
m_dbIcaoReader("http://ubuntu12/vatrep/public"), m_dbRootDirectory("http://ubuntu12/swiftdatastore/public"),
m_dbModelReader("http://ubuntu12/vatrep/public"), m_dbHttpPort(80),
m_dbHttpsPort(443),
m_vatsimBookings("http://vatbook.euroutepro.com/xml2.php"), m_vatsimBookings("http://vatbook.euroutepro.com/xml2.php"),
m_vatsimMetars("http://metar.vatsim.net/metar.php"), m_vatsimMetars("http://metar.vatsim.net/metar.php"),
m_vatsimDataFile(QStringList({ "http://info.vroute.net/vatsim-data.txt" })), m_vatsimDataFile(QStringList({ "http://info.vroute.net/vatsim-data.txt" })),
m_bootstrap(QStringList({ "https://vatsim-germany.org:50443/mapping/public/bootstrap", "http://ubuntu12/public/bootstrap"})), m_bootstrap(QStringList({ "https://vatsim-germany.org:50443/mapping/public/bootstrap", "http://ubuntu12/public/bootstrap"})),
m_swiftDbDataFiles(QStringList({ })), m_swiftDbDataFiles(QStringList({})),
m_fsdTestServers({ CServer("swift", "swift Testserver", "vatsim-germany.org", 6809, CUser("1234567", "swift Test User", "", "123456"), true) }) m_fsdTestServers({ CServer("swift", "swift Testserver", "vatsim-germany.org", 6809, CUser("1234567", "swift Test User", "", "123456"), true) })
{ } { }
CUrl CGlobalSetup::dbIcaoReader() const
{
return dbRootDirectory();
}
CUrl CGlobalSetup::dbModelReader() const
{
return dbRootDirectory();
}
CUrl CGlobalSetup::dbHomePage() const CUrl CGlobalSetup::dbHomePage() const
{ {
return dbModelReader().withAppendedPath("/page/index.php"); return dbRootDirectory().withAppendedPath("/page/index.php");
} }
CUrl CGlobalSetup::dbLoginService() const CUrl CGlobalSetup::dbLoginService() const
{ {
return dbModelReader().withAppendedPath("/service/index.php"); return dbRootDirectory().
withAppendedPath("/service/jsonauthenticate.php").
withSwitchedScheme("https", m_dbHttpsPort);
} }
bool CGlobalSetup::hasSameType(const QString &type) const bool CGlobalSetup::dbDebugFlag() const
{ {
return getType() == type.trimmed().toUpper(); if (!m_dbDebugFlag) { return false; }
// further checks could go here
return isDevelopment();
}
void CGlobalSetup::setServerDebugFlag(bool debug)
{
m_dbDebugFlag = debug;
}
bool CGlobalSetup::hasSameType(CGlobalSetup &otherSetup) const
{
return this->isDevelopment() == otherSetup.isDevelopment();
} }
CUrl CGlobalSetup::vatsimMetars() const CUrl CGlobalSetup::vatsimMetars() const
@@ -61,12 +88,19 @@ namespace BlackCore
QString s("timestamp: "); QString s("timestamp: ");
s.append(this->getFormattedUtcTimestampYmdhms()); s.append(this->getFormattedUtcTimestampYmdhms());
s.append(separator); s.append(separator);
s.append("For development: ");
s.append(boolToYesNo(isDevelopment()));
s.append(separator);
s.append("DB root directory: ");
s.append(dbRootDirectory().convertToQString(i18n));
s.append(separator);
s.append("ICAO DB reader: "); s.append("ICAO DB reader: ");
s.append(dbIcaoReader().convertToQString(i18n)); s.append(dbIcaoReader().convertToQString(i18n));
s.append(separator); s.append(separator);
s.append("Model DB reader: "); s.append("Model DB reader: ");
s.append(dbModelReader().convertToQString(i18n)); s.append(dbModelReader().convertToQString(i18n));
s.append(separator); s.append(separator);
s.append("DB home page: "); s.append("DB home page: ");
s.append(dbHomePage().convertToQString(i18n)); s.append(dbHomePage().convertToQString(i18n));
s.append(separator); s.append(separator);
@@ -101,12 +135,12 @@ namespace BlackCore
ColumnIndex i = index.frontCasted<ColumnIndex>(); ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexDbIcaoReader: case IndexDbRootDirectory:
return CVariant::fromValue(this->m_dbIcaoReader); return CVariant::fromValue(this->m_dbRootDirectory);
case IndexDbModelReader: case IndexDbHttpPort:
return CVariant::fromValue(this->m_dbModelReader); return CVariant::fromValue(this->m_dbHttpPort);
case IndexDbHomePage: case IndexDbHttpsPort:
return CVariant::fromValue(this->dbHomePage()); return CVariant::fromValue(this->m_dbHttpsPort);
case IndexDbLoginService: case IndexDbLoginService:
return CVariant::fromValue(this->dbLoginService()); return CVariant::fromValue(this->dbLoginService());
case IndexVatsimData: case IndexVatsimData:
@@ -136,13 +170,15 @@ namespace BlackCore
ColumnIndex i = index.frontCasted<ColumnIndex>(); ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexDbIcaoReader: case IndexDbRootDirectory:
this->m_dbIcaoReader.setPropertyByIndex(variant, index.copyFrontRemoved()); this->m_dbRootDirectory.setPropertyByIndex(variant, index.copyFrontRemoved());
break; break;
case IndexDbModelReader: case IndexDbHttpPort:
this->m_dbModelReader.setPropertyByIndex(variant, index.copyFrontRemoved()); this->m_dbHttpPort = variant.toInt();
break;
case IndexDbHttpsPort:
this->m_dbHttpsPort = variant.toInt();
break; break;
case IndexDbHomePage:
case IndexDbLoginService: case IndexDbLoginService:
break; break;
case IndexVatsimData: case IndexVatsimData:
@@ -165,5 +201,11 @@ namespace BlackCore
break; break;
} }
} }
const QString &CGlobalSetup::versionString()
{
static const QString v("0.6");
return v;
}
} // ns } // ns
} // ns } // ns

View File

@@ -33,9 +33,9 @@ namespace BlackCore
//! Properties by index //! Properties by index
enum ColumnIndex enum ColumnIndex
{ {
IndexDbIcaoReader = BlackMisc::CPropertyIndex::GlobalIndexCGlobalSetup, IndexDbRootDirectory = BlackMisc::CPropertyIndex::GlobalIndexCGlobalSetup,
IndexDbModelReader, IndexDbHttpPort,
IndexDbHomePage, IndexDbHttpsPort,
IndexDbLoginService, IndexDbLoginService,
IndexVatsimBookings, IndexVatsimBookings,
IndexVatsimMetars, IndexVatsimMetars,
@@ -50,11 +50,20 @@ namespace BlackCore
//! Destructor. //! Destructor.
~CGlobalSetup() {} ~CGlobalSetup() {}
//! Root directory of DB
const BlackMisc::Network::CUrl &dbRootDirectory() const { return m_dbRootDirectory; }
//! ICAO Reader location //! ICAO Reader location
const BlackMisc::Network::CUrl &dbIcaoReader() const { return m_dbIcaoReader; } BlackMisc::Network::CUrl dbIcaoReader() const;
//! Model Reader protocol //! Model Reader protocol
const BlackMisc::Network::CUrl &dbModelReader() const { return m_dbModelReader; } BlackMisc::Network::CUrl dbModelReader() const;
//! Http port
int dbHttpPort() const { return m_dbHttpPort; }
//! Https port
int dbHttpsPort() const { return m_dbHttpsPort; }
//! Home page url //! Home page url
BlackMisc::Network::CUrl dbHomePage() const; BlackMisc::Network::CUrl dbHomePage() const;
@@ -62,17 +71,17 @@ namespace BlackCore
//! Login service //! Login service
BlackMisc::Network::CUrl dbLoginService() const; BlackMisc::Network::CUrl dbLoginService() const;
//! Debug flag
bool dbDebugFlag() const;
//! Set debug flag
void setServerDebugFlag(bool debug);
//! URL to read VATSIM bookings //! URL to read VATSIM bookings
const BlackMisc::Network::CUrl &vatsimBookings() const { return m_vatsimBookings; } const BlackMisc::Network::CUrl &vatsimBookings() const { return m_vatsimBookings; }
//! Type (development, productive)?
const QString &getType() const { return m_type; }
//! Set type
void setType(const QString &type) { m_type = type.trimmed().toUpper(); }
//! Same type? //! Same type?
bool hasSameType(const QString &type) const; bool hasSameType(CGlobalSetup &otherSetup) const;
//! VATSIM METAR URL //! VATSIM METAR URL
BlackMisc::Network::CUrl vatsimMetars() const; BlackMisc::Network::CUrl vatsimMetars() const;
@@ -89,6 +98,12 @@ namespace BlackCore
//! FSD test servers //! FSD test servers
const BlackMisc::Network::CServerList &fsdTestServers() const { return m_fsdTestServers; } const BlackMisc::Network::CServerList &fsdTestServers() const { return m_fsdTestServers; }
//! Productive settings?
bool isDevelopment() const { return m_development; }
//! Productive settings?
void setDevelopment(bool development) { m_development = development; }
//! \copydoc CValueObject::convertToQString //! \copydoc CValueObject::convertToQString
QString convertToQString(bool i18n = false) const; QString convertToQString(bool i18n = false) const;
@@ -101,18 +116,25 @@ namespace BlackCore
//! \copydoc CValueObject::setPropertyByIndex //! \copydoc CValueObject::setPropertyByIndex
void setPropertyByIndex(const BlackMisc::CVariant &variant, const BlackMisc::CPropertyIndex &index); void setPropertyByIndex(const BlackMisc::CVariant &variant, const BlackMisc::CPropertyIndex &index);
//! Schema version
static const QString &versionString();
private: private:
BLACK_ENABLE_TUPLE_CONVERSION(BlackCore::Data::CGlobalSetup) BLACK_ENABLE_TUPLE_CONVERSION(BlackCore::Data::CGlobalSetup)
QString m_type; //!< dev./productive? BlackMisc::Network::CUrl m_dbRootDirectory; //!< Root directory
BlackMisc::Network::CUrl m_dbIcaoReader; //!< direct DB ICAO reader int m_dbHttpPort = 80; //!< port
BlackMisc::Network::CUrl m_dbModelReader; //!< direct DB model reader int m_dbHttpsPort = 443; //!< SSL port
BlackMisc::Network::CUrl m_vatsimBookings; //!< ATC bookings BlackMisc::Network::CUrl m_vatsimBookings; //!< ATC bookings
BlackMisc::Network::CUrl m_vatsimMetars; //!< METAR data BlackMisc::Network::CUrl m_vatsimMetars; //!< METAR data
BlackMisc::Network::CUrlList m_vatsimDataFile; //!< Overall VATSIM data file BlackMisc::Network::CUrlList m_vatsimDataFile; //!< Overall VATSIM data file
BlackMisc::Network::CUrlList m_bootstrap; //!< where we can obtain downloads of these data BlackMisc::Network::CUrlList m_bootstrap; //!< where we can obtain downloads of these data
BlackMisc::Network::CUrlList m_swiftDbDataFiles; //!< alternative locations of the DB files, if DB is not available BlackMisc::Network::CUrlList m_swiftDbDataFiles; //!< alternative locations of the DB files, if DB is not available
BlackMisc::Network::CServerList m_fsdTestServers; //!< FSD test servers BlackMisc::Network::CServerList m_fsdTestServers; //!< FSD test servers
bool m_development = false; //!< dev. version?
// transient members, to be switched on/off via GUI or set from reader
bool m_dbDebugFlag = false; //!< can trigger DEBUG on the server, so you need to know hat you are doing
}; };
//! Trait for for global setup data //! Trait for for global setup data
@@ -135,15 +157,16 @@ namespace BlackCore
Q_DECLARE_METATYPE(BlackCore::Data::CGlobalSetup) Q_DECLARE_METATYPE(BlackCore::Data::CGlobalSetup)
BLACK_DECLARE_TUPLE_CONVERSION(BlackCore::Data::CGlobalSetup, ( BLACK_DECLARE_TUPLE_CONVERSION(BlackCore::Data::CGlobalSetup, (
attr(o.m_timestampMSecsSinceEpoch), attr(o.m_timestampMSecsSinceEpoch),
attr(o.m_type), attr(o.m_dbRootDirectory),
attr(o.m_dbIcaoReader), attr(o.m_dbHttpPort),
attr(o.m_dbModelReader), attr(o.m_dbHttpsPort),
attr(o.m_vatsimBookings), attr(o.m_vatsimBookings),
attr(o.m_vatsimMetars), attr(o.m_vatsimMetars),
attr(o.m_vatsimDataFile), attr(o.m_vatsimDataFile),
attr(o.m_bootstrap), attr(o.m_bootstrap),
attr(o.m_swiftDbDataFiles), attr(o.m_swiftDbDataFiles),
attr(o.m_fsdTestServers) attr(o.m_fsdTestServers),
attr(o.m_development),
attr(o.m_dbDebugFlag, flags < DisabledForJson > ())
)) ))
#endif // guard #endif // guard

View File

@@ -164,7 +164,6 @@ namespace BlackCore
CUrl CIcaoDataReader::getBaseUrl() const CUrl CIcaoDataReader::getBaseUrl() const
{ {
CUrl baseUrl(this->m_setup.get().dbIcaoReader()); CUrl baseUrl(this->m_setup.get().dbIcaoReader());
Q_ASSERT_X(!baseUrl.isEmpty(), Q_FUNC_INFO, "No URL");
return baseUrl; return baseUrl;
} }

View File

@@ -329,7 +329,6 @@ namespace BlackCore
CUrl CModelDataReader::getBaseUrl() const CUrl CModelDataReader::getBaseUrl() const
{ {
CUrl baseUrl(m_setup.get().dbModelReader()); CUrl baseUrl(m_setup.get().dbModelReader());
Q_ASSERT_X(!baseUrl.isEmpty(), Q_FUNC_INFO, "No URL");
return baseUrl; return baseUrl;
} }

View File

@@ -85,15 +85,21 @@ namespace BlackCore
QString dir(CProject::getSwiftPrivateResourceDir()); QString dir(CProject::getSwiftPrivateResourceDir());
if (dir.isEmpty()) { return false; } if (dir.isEmpty()) { return false; }
fileName = CFileUtils::appendFilePaths(dir, "bootstrap/setup.json"); fileName = CFileUtils::appendFilePaths(dir, "bootstrap/" + CGlobalSetup::versionString() + "/bootstrap.json");
QString content(CFileUtils::readFileToString(fileName)); QString content(CFileUtils::readFileToString(fileName));
if (content.isEmpty()) { return false; } if (content.isEmpty()) { return false; }
CGlobalSetup s; CGlobalSetup s;
s.convertFromJson(content); s.convertFromJson(content);
s.setDevelopment(true);
m_setup.set(s); m_setup.set(s);
return true; return true;
} }
bool CSetupReader::isForDevelopment()
{
return CProject::useDevelopmentSetup();
}
CUrlList CSetupReader::getRemainingUrls() const CUrlList CSetupReader::getRemainingUrls() const
{ {
CUrlList urls(m_setup.get().bootstrapUrls().appendPath(appendPathAndFile())); CUrlList urls(m_setup.get().bootstrapUrls().appendPath(appendPathAndFile()));
@@ -103,9 +109,9 @@ namespace BlackCore
QString CSetupReader::appendPathAndFile() QString CSetupReader::appendPathAndFile()
{ {
return CProject::useDevelopmentSetup() ? return isForDevelopment() ?
"development/bootstrap.json" : CGlobalSetup::versionString() + "/development/bootstrap.json" :
"productive/bootstrap.json"; CGlobalSetup::versionString() + "/productive/bootstrap.json";
} }
void CSetupReader::ps_parseSetupFile(QNetworkReply *nwReplyPtr) void CSetupReader::ps_parseSetupFile(QNetworkReply *nwReplyPtr)
@@ -145,13 +151,12 @@ namespace BlackCore
} }
else else
{ {
QString type(urlString.toLower().contains("develop") ? "DEV" : "PRODUCTIVE"); CGlobalSetup currentSetup(m_setup.get()); // from cache
CGlobalSetup currentSetup(m_setup.get());
CGlobalSetup loadedSetup; CGlobalSetup loadedSetup;
loadedSetup.convertFromJson(Json::jsonObjectFromString(setupJson)); loadedSetup.convertFromJson(Json::jsonObjectFromString(setupJson));
loadedSetup.setType(type); loadedSetup.setDevelopment(isForDevelopment()); // always update, regardless what persistent setting says
if (loadedSetup.getMSecsSinceEpoch() == 0 && lastModified > 0) { loadedSetup.setMSecsSinceEpoch(lastModified); } if (loadedSetup.getMSecsSinceEpoch() == 0 && lastModified > 0) { loadedSetup.setMSecsSinceEpoch(lastModified); }
bool sameType = loadedSetup.hasSameType(currentSetup.getType()); bool sameType = loadedSetup.hasSameType(currentSetup);
qint64 currentVersionTimestamp = currentSetup.getMSecsSinceEpoch(); qint64 currentVersionTimestamp = currentSetup.getMSecsSinceEpoch();
qint64 newVersionTimestamp = loadedSetup.getMSecsSinceEpoch(); qint64 newVersionTimestamp = loadedSetup.getMSecsSinceEpoch();
bool sameVersionLoaded = sameType && (newVersionTimestamp == currentVersionTimestamp); bool sameVersionLoaded = sameType && (newVersionTimestamp == currentVersionTimestamp);

View File

@@ -54,6 +54,9 @@ namespace BlackCore
//! Remaining URLs failed one excluded //! Remaining URLs failed one excluded
BlackMisc::Network::CUrlList getRemainingUrls() const; BlackMisc::Network::CUrlList getRemainingUrls() const;
//! Read for development environment?
static bool isForDevelopment();
//! Bootstrap URL //! Bootstrap URL
static QString appendPathAndFile(); static QString appendPathAndFile();
}; };