RedisWriter: checksum package, source_location and templates separately in metadata_checksum

This commit is contained in:
Alexander A. Klimov 2018-06-07 12:49:38 +02:00 committed by Michael Friedrich
parent e980485e23
commit 3ea3b2ba27
3 changed files with 28 additions and 5 deletions

View File

@ -152,7 +152,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
String objectKey = CalculateCheckSumString(object->GetName());
//String objectKey = object->GetName();
std::set<String> propertiesBlacklist ({"name"});
std::set<String> propertiesBlacklist ({"name", "__name", "package", "source_location", "templates"});
Dictionary::Ptr checkSums = new Dictionary();
checkSums->Set("name_checksum", CalculateCheckSumString(object->GetName()));
@ -200,6 +200,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool useTran
checkSums->Set("vars_checksum", CalculateCheckSumVars(customVarObject));
}
checkSums->Set("metadata_checksum", CalculateCheckSumMetadata(object));
checkSums->Set("properties_checksum", CalculateCheckSumProperties(object, propertiesBlacklist));
String checkSumsBody = JsonEncode(checkSums);

View File

@ -58,6 +58,13 @@ String RedisWriter::CalculateCheckSumProperties(const ConfigObject::Ptr& object,
return HashValue(object, propertiesBlacklist);
}
static const std::set<String> metadataWhitelist ({"package", "source_location", "templates"});
String RedisWriter::CalculateCheckSumMetadata(const ConfigObject::Ptr& object)
{
return HashValue(object, metadataWhitelist, true);
}
String RedisWriter::CalculateCheckSumVars(const CustomVarObject::Ptr& object)
{
Dictionary::Ptr vars = object->GetVars();
@ -75,7 +82,7 @@ String RedisWriter::HashValue(const Value& value)
return HashValue(value, propertiesBlacklistEmpty);
}
String RedisWriter::HashValue(const Value& value, const std::set<String>& propertiesBlacklist)
String RedisWriter::HashValue(const Value& value, const std::set<String>& propertiesBlacklist, bool propertiesWhitelist)
{
Value temp;
bool mutabl;
@ -98,8 +105,22 @@ String RedisWriter::HashValue(const Value& value, const std::set<String>& proper
dict = dict->ShallowClone();
ObjectLock olock(dict);
if (propertiesWhitelist) {
auto current = dict->Begin();
auto propertiesBlacklistEnd = propertiesBlacklist.end();
while (current != dict->End()) {
if (propertiesBlacklist.find(current->first) == propertiesBlacklistEnd) {
dict->Remove(current++);
} else {
++current;
}
}
} else {
for (auto& property : propertiesBlacklist)
dict->Remove(property);
}
if (!mutabl)
temp = dict;

View File

@ -77,10 +77,11 @@ private:
static String CalculateCheckSumString(const String& str);
static String CalculateCheckSumGroups(const Array::Ptr& groups);
static String CalculateCheckSumProperties(const ConfigObject::Ptr& object, const std::set<String>& propertiesBlacklist);
static String CalculateCheckSumMetadata(const ConfigObject::Ptr& object);
static String CalculateCheckSumVars(const CustomVarObject::Ptr& object);
static String HashValue(const Value& value);
static String HashValue(const Value& value, const std::set<String>& propertiesBlacklist);
static String HashValue(const Value& value, const std::set<String>& propertiesBlacklist, bool propertiesWhitelist = false);
static void StateChangedHandler(const ConfigObject::Ptr& object);
static void VersionChangedHandler(const ConfigObject::Ptr& object);