mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-02 09:00:14 -06:00
Loads OpenTelemetry configuration from file
Adds support for loading OpenTelemetry configuration from a JSON file. Generalizes configuration file loading to handle OSDU, SUMO and OpenTelemetry configurations using a common function. Improves JSON value parsing to support strings, doubles, and booleans.
This commit is contained in:
1 parent
6c11e53f21
commit
a754b44e64
1 file changed
+54
-29
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "RiaLogging.h"
|
#include "RiaLogging.h"
|
||||||
#include "RiaPreferences.h"
|
#include "RiaPreferences.h"
|
||||||
|
#include "RiaPreferencesOpenTelemetry.h"
|
||||||
#include "RiaPreferencesOsdu.h"
|
#include "RiaPreferencesOsdu.h"
|
||||||
#include "RiaPreferencesSumo.h"
|
#include "RiaPreferencesSumo.h"
|
||||||
|
|
||||||
@@ -123,7 +124,23 @@ std::map<QString, QString> RiaConnectorTools::readKeyValuePairs( const QString&
|
|||||||
std::map<QString, QString> keyValuePairs;
|
std::map<QString, QString> keyValuePairs;
|
||||||
for ( auto it = obj.begin(); it != obj.end(); ++it )
|
for ( auto it = obj.begin(); it != obj.end(); ++it )
|
||||||
{
|
{
|
||||||
keyValuePairs[it.key()] = it.value().toString();
|
QJsonValue value = it.value();
|
||||||
|
QString valueStr;
|
||||||
|
|
||||||
|
if ( value.isString() )
|
||||||
|
{
|
||||||
|
valueStr = value.toString();
|
||||||
|
}
|
||||||
|
else if ( value.isDouble() )
|
||||||
|
{
|
||||||
|
valueStr = QString::number( value.toDouble() );
|
||||||
|
}
|
||||||
|
else if ( value.isBool() )
|
||||||
|
{
|
||||||
|
valueStr = value.toBool() ? "true" : "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
keyValuePairs[it.key()] = valueStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return keyValuePairs;
|
return keyValuePairs;
|
||||||
@@ -145,43 +162,51 @@ void RiaConnectorTools::readCloudConfigFiles( RiaPreferences* preferences )
|
|||||||
// location_of_resinsight_executable/../../share/cloud_services/*_config.json
|
// location_of_resinsight_executable/../../share/cloud_services/*_config.json
|
||||||
//
|
//
|
||||||
|
|
||||||
|
auto buildConfigFilePathCandidates = []( const QString& fileName ) -> QStringList
|
||||||
{
|
{
|
||||||
QStringList osduFilePathCandidates;
|
QStringList candidates;
|
||||||
osduFilePathCandidates << QDir::homePath() + "/.resinsight/osdu_config.json";
|
candidates << QDir::homePath() + "/.resinsight/" + fileName;
|
||||||
osduFilePathCandidates << QCoreApplication::applicationDirPath() + "/../share/cloud_services/osdu_config.json";
|
candidates << QCoreApplication::applicationDirPath() + "/../share/cloud_services/" + fileName;
|
||||||
osduFilePathCandidates << QCoreApplication::applicationDirPath() + "/../../share/cloud_services/osdu_config.json";
|
candidates << QCoreApplication::applicationDirPath() + "/../../share/cloud_services/" + fileName;
|
||||||
|
return candidates;
|
||||||
|
};
|
||||||
|
|
||||||
for ( const auto& osduFileCandidate : osduFilePathCandidates )
|
// Load OSDU configuration
|
||||||
|
for ( const auto& filePath : buildConfigFilePathCandidates( "osdu_config.json" ) )
|
||||||
|
{
|
||||||
|
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( filePath );
|
||||||
|
if ( !keyValuePairs.empty() )
|
||||||
{
|
{
|
||||||
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( osduFileCandidate );
|
RiaLogging::info( QString( "Imported OSDU configuration from : '%1'" ).arg( filePath ) );
|
||||||
if ( !keyValuePairs.empty() )
|
preferences->osduPreferences()->setData( keyValuePairs );
|
||||||
{
|
preferences->osduPreferences()->setFieldsReadOnly();
|
||||||
RiaLogging::info( QString( "Imported OSDU configuration from : '%1'" ).arg( osduFileCandidate ) );
|
break;
|
||||||
|
|
||||||
preferences->osduPreferences()->setData( keyValuePairs );
|
|
||||||
preferences->osduPreferences()->setFieldsReadOnly();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load SUMO configuration
|
||||||
|
for ( const auto& filePath : buildConfigFilePathCandidates( "sumo_config.json" ) )
|
||||||
{
|
{
|
||||||
QStringList sumoFilePathCandidates;
|
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( filePath );
|
||||||
sumoFilePathCandidates << QDir::homePath() + "/.resinsight/sumo_config.json";
|
if ( !keyValuePairs.empty() )
|
||||||
sumoFilePathCandidates << QCoreApplication::applicationDirPath() + "/../share/cloud_services/sumo_config.json";
|
|
||||||
sumoFilePathCandidates << QCoreApplication::applicationDirPath() + "/../../share/cloud_services/sumo_config.json";
|
|
||||||
|
|
||||||
for ( const auto& sumoFileCandidate : sumoFilePathCandidates )
|
|
||||||
{
|
{
|
||||||
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( sumoFileCandidate );
|
RiaLogging::info( QString( "Imported SUMO configuration from : '%1'" ).arg( filePath ) );
|
||||||
if ( !keyValuePairs.empty() )
|
preferences->sumoPreferences()->setData( keyValuePairs );
|
||||||
{
|
preferences->sumoPreferences()->setFieldsReadOnly();
|
||||||
RiaLogging::info( QString( "Imported SUMO configuration from : '%1'" ).arg( sumoFileCandidate ) );
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
preferences->sumoPreferences()->setData( keyValuePairs );
|
// Load OpenTelemetry configuration
|
||||||
preferences->sumoPreferences()->setFieldsReadOnly();
|
for ( const auto& filePath : buildConfigFilePathCandidates( "opentelemetry_config.json" ) )
|
||||||
break;
|
{
|
||||||
}
|
auto keyValuePairs = RiaConnectorTools::readKeyValuePairs( filePath );
|
||||||
|
if ( !keyValuePairs.empty() )
|
||||||
|
{
|
||||||
|
RiaLogging::info( QString( "Imported OpenTelemetry configuration from : '%1'" ).arg( filePath ) );
|
||||||
|
RiaPreferencesOpenTelemetry::current()->setData( keyValuePairs );
|
||||||
|
RiaPreferencesOpenTelemetry::current()->setFieldsReadOnly();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user