Page MenuHomePhabricator
Paste P45937

(An Untitled Masterwork)
ActivePublic

Authored by Gehel on Mar 23 2023, 8:29 PM.
Tags
None
Referenced Files
F36924906: raw-paste-data.txt
Mar 23 2023, 8:29 PM
Subscribers
None
from typing import Iterable
def hostname_to_elasticsearch_instances(hosts: Iterable):
target_hosts = [host.split('.')[0] for host in hosts]
target_dc = [host.split('.')[1] for host in hosts]
main_hosts = [f'{host}-production-search-{dc}' for (host, dc) in zip(target_hosts, target_dc)]
psi_hosts = [f'{host}-production-search-psi-{dc}' for (host, dc) in zip(target_hosts, target_dc)]
omega_hosts = [f'{host}-production-search-omega-{dc}' for (host, dc) in zip(target_hosts, target_dc)]
return main_hosts
(instances_codfw, instance_eqiad) = hostname_to_elasticsearch_instances(
['elastic1055.eqiad.wmnet', 'elastic1056.eqiad.wmnet', 'elastic2057.codfw.wmnet', 'elastic2058.codfw.wmnet', ])
assert instances_codfw == [
'elastic1055-production-search-codfw',
]
def ban_nodes(self, nodes: Iterable[str]):
'''
:param nodes: [elastic1001, elastic1002, ...]
:return:
'''
health = self._elasticsearch.cluster.health()
cluster_name = health['cluster_name']
try:
settings = self._elasticsearch.cluster.get_settings()
banned_nodes = settings['']
# extract the currently banned hosts
# add new nodes to list
# set settings with new list
self._elasticsearch.cluster.put_settings({"persistent":{"cluster.routing.allocation.exclude":{"_host": nodes}}})
except (RequestError, TransportError, HTTPError) as e:
raise ElasticsearchClusterError("Could not read or write elasticsearch settings") from e