Update how controller handles circuit tests -- save results to filesystem.

This commit is contained in:
Adam Ierymenko 2017-03-01 16:33:34 -08:00
parent 136fddc7f1
commit a577b8d381
7 changed files with 100 additions and 102 deletions

View file

@ -22,6 +22,22 @@ namespace ZeroTier {
static const nlohmann::json _EMPTY_JSON(nlohmann::json::object());
bool JSONDB::writeRaw(const std::string &n,const std::string &obj)
{
if (!_isValidObjectName(n))
return false;
const std::string path(_genPath(n,true));
if (!path.length())
return false;
const std::string buf(obj);
if (!OSUtils::writeFile(path.c_str(),buf))
return false;
return true;
}
bool JSONDB::put(const std::string &n,const nlohmann::json &obj)
{
if (!_isValidObjectName(n))
@ -35,9 +51,6 @@ bool JSONDB::put(const std::string &n,const nlohmann::json &obj)
if (!OSUtils::writeFile(path.c_str(),buf))
return false;
if (_feed)
fwrite(buf.c_str(),buf.length()+1,1,_feed);
_E &e = _db[n];
e.obj = obj;
e.lastModifiedOnDisk = OSUtils::getLastModified(path.c_str());
@ -72,9 +85,6 @@ const nlohmann::json &JSONDB::get(const std::string &n,unsigned long maxSinceChe
e->second.obj = OSUtils::jsonParse(buf);
e->second.lastModifiedOnDisk = lm; // don't update these if there is a parse error -- try again and again ASAP
e->second.lastCheck = now;
if (_feed)
fwrite(buf.c_str(),buf.length()+1,1,_feed); // it changed, so send to feed (also sends all objects on startup, which we want for Central)
} catch ( ... ) {} // parse errors result in "holding pattern" behavior
}
}
@ -99,9 +109,6 @@ const nlohmann::json &JSONDB::get(const std::string &n,unsigned long maxSinceChe
e2.lastModifiedOnDisk = lm;
e2.lastCheck = now;
if (_feed)
fwrite(buf.c_str(),buf.length()+1,1,_feed);
return e2.obj;
}
}