Unverified Commit 26c195e9 authored by SparkSnail's avatar SparkSnail Committed by GitHub
Browse files

Show error message when start experiment failed (#996)

Fix issue #890
parent a2f91703
......@@ -325,12 +325,12 @@ def set_experiment(experiment_config, mode, port, config_file_name):
request_data['clusterMetaData'].append(
{'key': 'trial_config', 'value': experiment_config['trial']})
response = rest_post(experiment_url(port), json.dumps(request_data), REST_TIME_OUT)
response = rest_post(experiment_url(port), json.dumps(request_data), REST_TIME_OUT, show_error=True)
if check_response(response):
return response
else:
_, stderr_full_path = get_log_path(config_file_name)
if response:
if response is not None:
with open(stderr_full_path, 'a+') as fout:
fout.write(json.dumps(json.loads(response.text), indent=4, sort_keys=True, separators=(',', ':')))
print_error('Setting experiment error, error message is {}'.format(response.text))
......
......@@ -23,39 +23,48 @@ import time
import requests
from .url_utils import check_status_url
from .constants import REST_TIME_OUT
from .common_utils import print_error
def rest_put(url, data, timeout):
def rest_put(url, data, timeout, show_error=False):
'''Call rest put method'''
try:
response = requests.put(url, headers={'Accept': 'application/json', 'Content-Type': 'application/json'},\
data=data, timeout=timeout)
return response
except Exception:
except Exception as exception:
if show_error:
print_error(exception)
return None
def rest_post(url, data, timeout):
def rest_post(url, data, timeout, show_error=False):
'''Call rest post method'''
try:
response = requests.post(url, headers={'Accept': 'application/json', 'Content-Type': 'application/json'},\
data=data, timeout=timeout)
return response
except Exception:
except Exception as exception:
if show_error:
print_error(exception)
return None
def rest_get(url, timeout):
def rest_get(url, timeout, show_error=False):
'''Call rest get method'''
try:
response = requests.get(url, timeout=timeout)
return response
except Exception:
except Exception as exception:
if show_error:
print_error(exception)
return None
def rest_delete(url, timeout):
def rest_delete(url, timeout, show_error=False):
'''Call rest delete method'''
try:
response = requests.delete(url, timeout=timeout)
return response
except Exception:
except Exception as exception:
if show_error:
print_error(exception)
return None
def check_rest_server(rest_port):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment