Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
nni
Commits
26c195e9
Unverified
Commit
26c195e9
authored
Apr 19, 2019
by
SparkSnail
Committed by
GitHub
Apr 19, 2019
Browse files
Show error message when start experiment failed (#996)
Fix issue #890
parent
a2f91703
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
10 deletions
+19
-10
tools/nni_cmd/launcher.py
tools/nni_cmd/launcher.py
+2
-2
tools/nni_cmd/rest_utils.py
tools/nni_cmd/rest_utils.py
+17
-8
No files found.
tools/nni_cmd/launcher.py
View file @
26c195e9
...
@@ -325,12 +325,12 @@ def set_experiment(experiment_config, mode, port, config_file_name):
...
@@ -325,12 +325,12 @@ def set_experiment(experiment_config, mode, port, config_file_name):
request_data
[
'clusterMetaData'
].
append
(
request_data
[
'clusterMetaData'
].
append
(
{
'key'
:
'trial_config'
,
'value'
:
experiment_config
[
'trial'
]})
{
'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
):
if
check_response
(
response
):
return
response
return
response
else
:
else
:
_
,
stderr_full_path
=
get_log_path
(
config_file_name
)
_
,
stderr_full_path
=
get_log_path
(
config_file_name
)
if
response
:
if
response
is
not
None
:
with
open
(
stderr_full_path
,
'a+'
)
as
fout
:
with
open
(
stderr_full_path
,
'a+'
)
as
fout
:
fout
.
write
(
json
.
dumps
(
json
.
loads
(
response
.
text
),
indent
=
4
,
sort_keys
=
True
,
separators
=
(
','
,
':'
)))
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
))
print_error
(
'Setting experiment error, error message is {}'
.
format
(
response
.
text
))
...
...
tools/nni_cmd/rest_utils.py
View file @
26c195e9
...
@@ -23,39 +23,48 @@ import time
...
@@ -23,39 +23,48 @@ import time
import
requests
import
requests
from
.url_utils
import
check_status_url
from
.url_utils
import
check_status_url
from
.constants
import
REST_TIME_OUT
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'''
'''Call rest put method'''
try
:
try
:
response
=
requests
.
put
(
url
,
headers
=
{
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
},
\
response
=
requests
.
put
(
url
,
headers
=
{
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
},
\
data
=
data
,
timeout
=
timeout
)
data
=
data
,
timeout
=
timeout
)
return
response
return
response
except
Exception
:
except
Exception
as
exception
:
if
show_error
:
print_error
(
exception
)
return
None
return
None
def
rest_post
(
url
,
data
,
timeout
):
def
rest_post
(
url
,
data
,
timeout
,
show_error
=
False
):
'''Call rest post method'''
'''Call rest post method'''
try
:
try
:
response
=
requests
.
post
(
url
,
headers
=
{
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
},
\
response
=
requests
.
post
(
url
,
headers
=
{
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
},
\
data
=
data
,
timeout
=
timeout
)
data
=
data
,
timeout
=
timeout
)
return
response
return
response
except
Exception
:
except
Exception
as
exception
:
if
show_error
:
print_error
(
exception
)
return
None
return
None
def
rest_get
(
url
,
timeout
):
def
rest_get
(
url
,
timeout
,
show_error
=
False
):
'''Call rest get method'''
'''Call rest get method'''
try
:
try
:
response
=
requests
.
get
(
url
,
timeout
=
timeout
)
response
=
requests
.
get
(
url
,
timeout
=
timeout
)
return
response
return
response
except
Exception
:
except
Exception
as
exception
:
if
show_error
:
print_error
(
exception
)
return
None
return
None
def
rest_delete
(
url
,
timeout
):
def
rest_delete
(
url
,
timeout
,
show_error
=
False
):
'''Call rest delete method'''
'''Call rest delete method'''
try
:
try
:
response
=
requests
.
delete
(
url
,
timeout
=
timeout
)
response
=
requests
.
delete
(
url
,
timeout
=
timeout
)
return
response
return
response
except
Exception
:
except
Exception
as
exception
:
if
show_error
:
print_error
(
exception
)
return
None
return
None
def
check_rest_server
(
rest_port
):
def
check_rest_server
(
rest_port
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment