Add support for http serving

This commit is contained in:
allegroai 2019-06-11 18:51:59 +03:00
parent 636ad4431d
commit 06b64cd13f

View File

@ -7,6 +7,9 @@ import json
import requests
from pathlib import Path
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
HERE = Path(__file__).parent
@ -16,9 +19,16 @@ def apply_mappings_to_host(host: str):
data = json.load(json_data)
es_server = host
url = f"{es_server}/_template/{f.stem}"
requests.delete(url)
r = requests.post(
url, headers={"Content-Type": "application/json"}, data=json.dumps(data)
session = requests.Session()
adapter = HTTPAdapter(max_retries=Retry(5, backoff_factor=0.5))
session.mount('http://', adapter)
session.delete(url)
r = session.post(
url,
headers={"Content-Type": "application/json"},
data=json.dumps(data),
)
return {"mapping": f.stem, "result": r.text}