only one evaluation per alias allowed (#56)

This commit is contained in:
Rok Garbas 2020-06-04 00:08:43 +02:00 committed by GitHub
parent ae670990dd
commit 8896ea9e1c
Failed to generate hash of commit

View file

@ -76,11 +76,7 @@ MAPPING = {
"package_attr_name": { "package_attr_name": {
"type": "text", "type": "text",
"analyzer": "nixAttrName", "analyzer": "nixAttrName",
"fields": { "fields": {"raw": {"type": "keyword"}},
"raw": {
"type": "keyword"
},
},
}, },
"package_attr_set": {"type": "keyword"}, "package_attr_set": {"type": "keyword"},
"package_pname": {"type": "keyword"}, "package_pname": {"type": "keyword"},
@ -89,10 +85,7 @@ MAPPING = {
"package_longDescription": {"type": "text"}, "package_longDescription": {"type": "text"},
"package_license": { "package_license": {
"type": "nested", "type": "nested",
"properties": { "properties": {"fullName": {"type": "text"}, "url": {"type": "text"}},
"fullName": {"type": "text"},
"url": {"type": "text"},
},
}, },
"package_maintainers": { "package_maintainers": {
"type": "nested", "type": "nested",
@ -291,7 +284,7 @@ def ensure_index(es, index, mapping):
}, },
) )
logger.debug(f"ensure_index: index '{index}' was created") logger.debug(f"ensure_index: index '{index}' was created")
return True return True
@ -303,8 +296,23 @@ def create_index_name(channel, evaluation):
def update_alias(es, name, index): def update_alias(es, name, index):
es.indices.put_alias(index=index, name=name) indexes = set(es.indices.get_alias(name=name).keys())
logger.debug(f"'{name}' alias now points to '{index}' index")
# indexes to remove from alias
actions = [
{"remove": {"index": item, "alias": name}}
for item in indexes.difference(set([index]))
]
# add index if does not exists in alias
if index not in indexes:
actions.append({"add": {"index": index, "alias": name}})
if actions:
es.indices.update_aliases({"actions": actions})
indexes = ", ".join(es.indices.get_alias(name=name).keys())
logger.debug(f"'{name}' alias now points to '{indexes}' index")
def write(unit, es, index_name, number_of_items, item_generator): def write(unit, es, index_name, number_of_items, item_generator):
@ -346,7 +354,8 @@ def main(es_url, channel, verbose):
if index_created: if index_created:
write("packages", es, index_name, *get_packages(evaluation)) write("packages", es, index_name, *get_packages(evaluation))
write("options", es, index_name, *get_options(evaluation)) write("options", es, index_name, *get_options(evaluation))
update_alias(es, alias_name, index_name)
update_alias(es, alias_name, index_name)
if __name__ == "__main__": if __name__ == "__main__":