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 import requests
from pathlib import Path from pathlib import Path
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
HERE = Path(__file__).parent HERE = Path(__file__).parent
@ -16,9 +19,16 @@ def apply_mappings_to_host(host: str):
data = json.load(json_data) data = json.load(json_data)
es_server = host es_server = host
url = f"{es_server}/_template/{f.stem}" url = f"{es_server}/_template/{f.stem}"
requests.delete(url)
r = requests.post( session = requests.Session()
url, headers={"Content-Type": "application/json"}, data=json.dumps(data) 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} return {"mapping": f.stem, "result": r.text}