Skip to content
Snippets Groups Projects
Commit 38f64d5b authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Fix for updating config properties

parent 30c0eb71
No related branches found
No related tags found
No related merge requests found
Pipeline #11180 passed
...@@ -37,7 +37,7 @@ bool update(const std::string &puri, const json_t &value); ...@@ -37,7 +37,7 @@ bool update(const std::string &puri, const json_t &value);
* Resolve a JSON schema reference, but do not wait for a remote reference * Resolve a JSON schema reference, but do not wait for a remote reference
* if it is not available. A null entity is returned if not resolved. * if it is not available. A null entity is returned if not resolved.
*/ */
json_t &resolve(const std::string &); json_t &resolve(const std::string &, bool eager=true);
/** /**
* Resolve a reference object, or if not a reference object it simply returns * Resolve a reference object, or if not a reference object it simply returns
...@@ -85,17 +85,17 @@ using config::configure; ...@@ -85,17 +85,17 @@ using config::configure;
template <typename T, typename... ARGS> template <typename T, typename... ARGS>
T *ftl::config::create(json_t &link, ARGS ...args) { T *ftl::config::create(json_t &link, ARGS ...args) {
auto &r = link; // = ftl::config::resolve(link); //auto &r = link; // = ftl::config::resolve(link);
if (!r["$id"].is_string()) { if (!link["$id"].is_string()) {
LOG(FATAL) << "Entity does not have $id or parent: " << r; LOG(FATAL) << "Entity does not have $id or parent: " << link;
return nullptr; return nullptr;
} }
ftl::Configurable *cfg = ftl::config::find(r["$id"].get<std::string>()); ftl::Configurable *cfg = ftl::config::find(link["$id"].get<std::string>());
if (!cfg) { if (!cfg) {
// try { // try {
cfg = new T(r, args...); cfg = new T(link, args...);
//} catch(...) { //} catch(...) {
// LOG(FATAL) << "Could not construct " << link; // LOG(FATAL) << "Could not construct " << link;
//} //}
......
...@@ -218,7 +218,8 @@ bool ftl::config::update(const std::string &puri, const json_t &value) { ...@@ -218,7 +218,8 @@ bool ftl::config::update(const std::string &puri, const json_t &value) {
cfg->set<json_t>(tail, value); cfg->set<json_t>(tail, value);
} else { } else {
DLOG(1) << "Updating: " << head << "[" << tail << "] = " << value; DLOG(1) << "Updating: " << head << "[" << tail << "] = " << value;
auto r = resolve(head); auto &r = resolve(head, false);
if (!r.is_structured()) { if (!r.is_structured()) {
LOG(ERROR) << "Cannot update property '" << tail << "' of '" << head << "'"; LOG(ERROR) << "Cannot update property '" << tail << "' of '" << head << "'";
return false; return false;
...@@ -229,7 +230,7 @@ bool ftl::config::update(const std::string &puri, const json_t &value) { ...@@ -229,7 +230,7 @@ bool ftl::config::update(const std::string &puri, const json_t &value) {
} }
} }
json_t &ftl::config::resolve(const std::string &puri) { json_t &ftl::config::resolve(const std::string &puri, bool eager) {
string uri_str = puri; string uri_str = puri;
// TODO(Nick) Must support alternative root (last $id) // TODO(Nick) Must support alternative root (last $id)
...@@ -252,11 +253,13 @@ json_t &ftl::config::resolve(const std::string &puri) { ...@@ -252,11 +253,13 @@ json_t &ftl::config::resolve(const std::string &puri) {
auto ptr = nlohmann::json::json_pointer("/"+uri.getFragment()); auto ptr = nlohmann::json::json_pointer("/"+uri.getFragment());
try { try {
return resolve((*ix).second->at(ptr)); return (eager) ? resolve((*ix).second->at(ptr)) : (*ix).second->at(ptr);
} catch(...) { } catch(...) {
LOG(WARNING) << "Resolve failed for " << puri;
return null_json; return null_json;
} }
} else { } else {
LOG(WARNING) << "Resolve failed for " << puri;
return null_json; return null_json;
} }
} }
...@@ -429,6 +432,10 @@ Configurable *ftl::config::configure(int argc, char **argv, const std::string &r ...@@ -429,6 +432,10 @@ Configurable *ftl::config::configure(int argc, char **argv, const std::string &r
rootCFG = rootcfg; rootCFG = rootcfg;
rootcfg->set("paths", paths); rootcfg->set("paths", paths);
process_options(rootcfg, options); process_options(rootcfg, options);
//LOG(INFO) << "CONFIG: " << config["vision_default"];
CHECK_EQ( &config, config_index["ftl://utu.fi"] );
return rootcfg; return rootcfg;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment