Skip to content

Commit

Permalink
Updated Json2configurationprovider.cpp to avoid automatic merges
Browse files Browse the repository at this point in the history
Signed-off-by: parth-gr <[email protected]>
  • Loading branch information
parth-gr committed Sep 2, 2020
1 parent b840a8e commit 4268730
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Source/moja.flint.configuration/src/json2configurationprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "moja/flint/configuration/localdomain.h"
#include "moja/flint/configuration/spinup.h"

#include <moja/instrumentor.h>
#include <moja/logging.h>
#include <moja/pocojsonutils.h>

Expand All @@ -33,6 +34,7 @@ namespace flint {
namespace configuration {

JSON2ConfigurationProvider::JSON2ConfigurationProvider(const std::vector<std::string>& configFilePath) {
MOJA_PROFILE_FUNCTION();
for (const std::string configFie : configFilePath) {
Poco::File file(configFie);
if (!file.exists()) {
Expand All @@ -46,6 +48,7 @@ JSON2ConfigurationProvider::JSON2ConfigurationProvider(const std::vector<std::st

JSON2ConfigurationProvider::JSON2ConfigurationProvider(const std::vector<std::string>& configFilePath,
const std::vector<std::string>& configProviderFilePath) {
MOJA_PROFILE_FUNCTION();
for (const auto& configFie : configFilePath) {
Poco::File file(configFie);
if (!file.exists()) {
Expand All @@ -70,6 +73,7 @@ JSON2ConfigurationProvider::JSON2ConfigurationProvider(const std::vector<std::st
}

std::shared_ptr<Configuration> JSON2ConfigurationProvider::createConfiguration() {
MOJA_PROFILE_FUNCTION();
// parse the first run configuration file
auto fileName = _configFilePath[0];
std::ifstream file(fileName);
Expand Down Expand Up @@ -125,6 +129,7 @@ Parse and merge run configuration files.
It only merges up to 2nd level configuration.
*/
void JSON2ConfigurationProvider::mergeJsonConfigFile(std::string fileName, Poco::Dynamic::Var parsedResult) {
MOJA_PROFILE_FUNCTION();
auto jsonStructFinal = parsedResult.extract<Object::Ptr>();
std::ifstream file(fileName);

Expand Down Expand Up @@ -176,6 +181,7 @@ Parse and merge data provider configuration files
it merges only raster-tiled layers configuration. It assumes that other configurations are identical.
*/
void JSON2ConfigurationProvider::mergeJsonProviderConfigFile(std::string fileName, Poco::Dynamic::Var parsedResult) {
MOJA_PROFILE_FUNCTION();
auto jsonStructFinal = parsedResult.extract<Object::Ptr>();
auto providerFinal = jsonStructFinal->getObject("Providers");
std::ifstream file(fileName);
Expand Down Expand Up @@ -240,6 +246,7 @@ void JSON2ConfigurationProvider::mergeJsonProviderConfigFile(std::string fileNam
}

void JSON2ConfigurationProvider::createLocalDomain(Poco::Dynamic::Var& parsedJSON, Configuration& config) const {
MOJA_PROFILE_FUNCTION();
Poco::DynamicStruct jsonStruct = *parsedJSON.extract<Poco::JSON::Object::Ptr>();
auto localDomainStruct = jsonStruct["LocalDomain"].extract<Poco::DynamicStruct>();
const auto localDomainType = parseLocalDomainType(localDomainStruct["type"]);
Expand Down Expand Up @@ -298,7 +305,7 @@ void JSON2ConfigurationProvider::createLocalDomain(Poco::Dynamic::Var& parsedJSO
config.setLocalDomain(localDomainType, iterationType, doLogging, numThreads, sequencerLibrary, sequencer,
simulateLandUnit, landUnitBuildSuccess, settings, stepping);

config.localDomain()->setLandscapeObject(landscape["provider"].extract<std::string>(), iterationType);
config.localDomain()->setLandscapeObject(landscape["provider"].extract<std::string>(), iterationType);

auto landscapeObject = config.localDomain()->landscapeObject();
switch (iterationType) {
Expand Down Expand Up @@ -392,6 +399,7 @@ void JSON2ConfigurationProvider::createLocalDomain(Poco::Dynamic::Var& parsedJSO
}

void JSON2ConfigurationProvider::createSpinup(Poco::Dynamic::Var& parsedJSON, Configuration& config) const {
MOJA_PROFILE_FUNCTION();
Poco::DynamicStruct jsonStruct = *parsedJSON.extract<Poco::JSON::Object::Ptr>();
if (!jsonStruct.contains("Spinup")) {
DynamicObject settings;
Expand Down Expand Up @@ -426,6 +434,7 @@ void JSON2ConfigurationProvider::createSpinup(Poco::Dynamic::Var& parsedJSON, Co
}

void JSON2ConfigurationProvider::createLibraries(Poco::Dynamic::Var& parsedJSON, Configuration& config) const {
MOJA_PROFILE_FUNCTION();
Poco::DynamicStruct jsonStruct = *parsedJSON.extract<Poco::JSON::Object::Ptr>();
auto librariesStruct = jsonStruct["Libraries"].extract<Poco::DynamicStruct>();
for (auto item : librariesStruct) {
Expand All @@ -445,11 +454,13 @@ void JSON2ConfigurationProvider::createLibraries(Poco::Dynamic::Var& parsedJSON,
}

bool JSON2ConfigurationProvider::fileExists(const std::string& path) {
MOJA_PROFILE_FUNCTION();
Poco::File pf(path);
return pf.exists();
}

void JSON2ConfigurationProvider::createProviders(Poco::Dynamic::Var& parsedJSON, Configuration& config) const {
MOJA_PROFILE_FUNCTION();
auto jsonStruct2 = *parsedJSON.extract<Poco::JSON::Object::Ptr>();
auto provider = jsonStruct2.getObject("Providers");
auto& data = *(provider.get());
Expand Down Expand Up @@ -531,6 +542,7 @@ void JSON2ConfigurationProvider::createPools(Poco::Dynamic::Var& parsedJSON, Con

bool JSON2ConfigurationProvider::createSpecialPools(const std::string& poolName, const DynamicStruct& poolSettings,
Configuration& config) const {
MOJA_PROFILE_FUNCTION();
if (!poolSettings.contains("transform")) {
return false;
}
Expand All @@ -552,6 +564,8 @@ bool JSON2ConfigurationProvider::createSpecialPools(const std::string& poolName,

bool JSON2ConfigurationProvider::createSpecialVariables(
const std::pair<const std::string, Poco::Dynamic::Var>& keyValPair, Configuration& config, bool isSpinup) const {

MOJA_PROFILE_FUNCTION();
auto spinup = config.spinup();
auto varName = keyValPair.first;
if (keyValPair.second.isStruct()) {
Expand Down Expand Up @@ -585,6 +599,7 @@ bool JSON2ConfigurationProvider::createSpecialVariables(

void JSON2ConfigurationProvider::createVariables(Poco::Dynamic::Var& parsedJSON, Configuration& config,
bool isSpinup) const {
MOJA_PROFILE_FUNCTION();
auto spinup = config.spinup();
const std::string configSection = isSpinup ? "SpinupVariables" : "Variables";

Expand Down Expand Up @@ -630,6 +645,7 @@ void JSON2ConfigurationProvider::createVariables(Poco::Dynamic::Var& parsedJSON,
}

void JSON2ConfigurationProvider::createModules(Poco::Dynamic::Var& parsedJSON, Configuration& config) const {
MOJA_PROFILE_FUNCTION();
Poco::DynamicStruct jsonStruct = *parsedJSON.extract<Poco::JSON::Object::Ptr>();
auto modulesStruct = jsonStruct["Modules"].extract<Poco::DynamicStruct>();
for (auto item : modulesStruct) {
Expand All @@ -653,13 +669,14 @@ void JSON2ConfigurationProvider::createModules(Poco::Dynamic::Var& parsedJSON, C
isProxy = moduleStruct["is_proxy"].extract<bool>();
}

const auto settings = parsePocoVarToDynamic(moduleStruct["settings"]);
const auto settings = parsePocoVarToDynamic(moduleStruct["settings"]);
config.addModule(moduleLibraryName, item.first, moduleOrder, isProxy,
settings.isEmpty() ? DynamicObject() : settings.extract<const DynamicObject>());
}
}

void JSON2ConfigurationProvider::createSpinupModules(Poco::Dynamic::Var& parsedJSON, Configuration& config) const {
MOJA_PROFILE_FUNCTION();
Poco::DynamicStruct jsonStruct = *parsedJSON.extract<Poco::JSON::Object::Ptr>();
auto modulesStruct = jsonStruct["SpinupModules"].extract<Poco::DynamicStruct>();
for (auto item : modulesStruct) {
Expand Down

0 comments on commit 4268730

Please sign in to comment.