1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
15 from yardstick.dispatcher.base import Base as DispatchBase
17 LOG = logging.getLogger(__name__)
20 class HttpDispatcher(DispatchBase):
21 """Dispatcher class for posting data into a http target.
24 __dispatcher_type__ = "Http"
26 # TODO: make parameters below configurable, currently just hard coded
27 # The target where the http request will be sent.
28 target = "http://127.0.0.1:8000/results"
29 # The max time in seconds to wait for a request to timeout.
32 def __init__(self, conf):
33 super(HttpDispatcher, self).__init__(conf)
34 self.headers = {'Content-type': 'application/json'}
35 self.timeout = self.timeout
36 self.target = self.target
38 def record_result_data(self, data):
40 # if the target was not set, do not do anything
41 LOG.error('Dispatcher target was not set, no data will'
45 # We may have receive only one counter on the wire
46 if not isinstance(data, list):
51 LOG.debug('Message : %s' % result)
52 res = requests.post(self.target,
53 data=json.dumps(result),
56 LOG.debug('Message posting finished with status code'
57 '%d.' % res.status_code)
58 except Exception as err:
59 LOG.exception('Failed to record result data: %s',