def __init__(self, token, case_name='Case Recording',
endpoint='http://www.openmdao.org/visualization', port='', case_id=None,
suppress_output=False):
"""
Initialize the OpenMDAOServerRecorder.
Parameters
----------
token: <string>
The token to be passed as a user's unique identifier. Register to get a token
at the given endpoint
case_name: <string>
The name this case should be stored under. Default: 'Case Recording'
endpoint: <string>
The URL (minus port, if not 80) where the server is hosted
port: <string>
The port which the server is listening on. Default to empty string (port 80)
suppress_output: <bool>
Indicates if all printing should be suppressed in this recorder
"""
super(WebRecorder, self).__init__()
self.model_viewer_data = None
self._headers = {'token': token, 'update': "False"}
if port != '':
self._endpoint = endpoint + ':' + port + '/case'
else:
self._endpoint = endpoint + '/case'
self._abs2prom = {'input': {}, 'output': {}}
self._prom2abs = {'input': {}, 'output': {}}
if case_id is None:
case_data_dict = {
'case_name': case_name,
'owner': 'temp_owner'
}
case_data = json.dumps(case_data_dict)
# Post case and get Case ID
case_request = requests.post(self._endpoint, data=case_data, headers=self._headers)
response = case_request.json()
if response['status'] != 'Failed':
self._case_id = str(response['case_id'])
else:
self._case_id = '-1'
if not suppress_output:
print("Failed to initialize case on server. No messages will be accepted \
from server for this case. Make sure you registered for a token at the \
given endpoint.")
if 'reasoning' in response:
if not suppress_output:
print("Failure reasoning: " + response['reasoning'])
else:
self._case_id = str(case_id)
self._headers['update'] = "True"
评论列表
文章目录