##// END OF EJS Templates
channelstream: nicer handle of connection errors for debug.
marcink -
r3169:c15445d5 default
parent child Browse files
Show More
@@ -26,7 +26,7 b' from pyramid.httpexceptions import HTTPB'
26
26
27 from rhodecode.apps._base import BaseAppView
27 from rhodecode.apps._base import BaseAppView
28 from rhodecode.lib.channelstream import (
28 from rhodecode.lib.channelstream import (
29 channelstream_request,
29 channelstream_request, get_channelstream_server_url,
30 ChannelstreamConnectionException,
30 ChannelstreamConnectionException,
31 ChannelstreamPermissionException,
31 ChannelstreamPermissionException,
32 check_channel_permissions,
32 check_channel_permissions,
@@ -56,8 +56,9 b' class ChannelstreamView(BaseAppView):'
56 @NotAnonymous()
56 @NotAnonymous()
57 @view_config(route_name='channelstream_connect', renderer='json_ext')
57 @view_config(route_name='channelstream_connect', renderer='json_ext')
58 def connect(self):
58 def connect(self):
59 """ handle authorization of users trying to connect """
60
59 self.load_default_context()
61 self.load_default_context()
60 """ handle authorization of users trying to connect """
61 try:
62 try:
62 json_body = self.request.json_body
63 json_body = self.request.json_body
63 except Exception:
64 except Exception:
@@ -107,11 +108,14 b' class ChannelstreamView(BaseAppView):'
107 'broadcast_presence_with_user_lists': True
108 'broadcast_presence_with_user_lists': True
108 }
109 }
109 # connect user to server
110 # connect user to server
111 channelstream_url = get_channelstream_server_url(
112 self.channelstream_config, '/connect')
110 try:
113 try:
111 connect_result = channelstream_request(self.channelstream_config,
114 connect_result = channelstream_request(
112 payload, '/connect')
115 self.channelstream_config, payload, '/connect')
113 except ChannelstreamConnectionException:
116 except ChannelstreamConnectionException:
114 log.exception('Channelstream service is down')
117 log.exception(
118 'Channelstream service at {} is down'.format(channelstream_url))
115 return HTTPBadGateway()
119 return HTTPBadGateway()
116
120
117 connect_result['channels'] = channels
121 connect_result['channels'] = channels
@@ -153,17 +157,21 b' class ChannelstreamView(BaseAppView):'
153 'store_history': True,
157 'store_history': True,
154 'broadcast_presence_with_user_lists': True
158 'broadcast_presence_with_user_lists': True
155 }
159 }
160
161 channelstream_url = get_channelstream_server_url(
162 self.channelstream_config, '/subscribe')
156 try:
163 try:
157 connect_result = channelstream_request(
164 connect_result = channelstream_request(
158 self.channelstream_config, payload, '/subscribe')
165 self.channelstream_config, payload, '/subscribe')
159 except ChannelstreamConnectionException:
166 except ChannelstreamConnectionException:
160 log.exception('Channelstream service is down')
167 log.exception(
168 'Channelstream service at {} is down'.format(channelstream_url))
161 return HTTPBadGateway()
169 return HTTPBadGateway()
162 # include_channel_info will limit history only to new channel
170 # include_channel_info will limit history only to new channel
163 # to not overwrite histories on other channels in client
171 # to not overwrite histories on other channels in client
164 connect_result['channels_info'] = parse_channels_info(
172 connect_result['channels_info'] = parse_channels_info(
165 connect_result['channels_info'],
173 connect_result['channels_info'],
166 include_channel_info=filtered_channels)
174 include_channel_info=filtered_channels)
167 update_history_from_logs(self.channelstream_config,
175 update_history_from_logs(
168 filtered_channels, connect_result)
176 self.channelstream_config, filtered_channels, connect_result)
169 return connect_result
177 return connect_result
@@ -53,23 +53,27 b' class ChannelstreamPermissionException(C'
53 pass
53 pass
54
54
55
55
56 def get_channelstream_server_url(config, endpoint):
57 return 'http://{}{}'.format(config['server'], endpoint)
58
59
56 def channelstream_request(config, payload, endpoint, raise_exc=True):
60 def channelstream_request(config, payload, endpoint, raise_exc=True):
57 signer = itsdangerous.TimestampSigner(config['secret'])
61 signer = itsdangerous.TimestampSigner(config['secret'])
58 sig_for_server = signer.sign(endpoint)
62 sig_for_server = signer.sign(endpoint)
59 secret_headers = {'x-channelstream-secret': sig_for_server,
63 secret_headers = {'x-channelstream-secret': sig_for_server,
60 'x-channelstream-endpoint': endpoint,
64 'x-channelstream-endpoint': endpoint,
61 'Content-Type': 'application/json'}
65 'Content-Type': 'application/json'}
62 req_url = 'http://{}{}'.format(config['server'], endpoint)
66 req_url = get_channelstream_server_url(config, endpoint)
63 response = None
67 response = None
64 try:
68 try:
65 response = requests.post(req_url, data=json.dumps(payload),
69 response = requests.post(req_url, data=json.dumps(payload),
66 headers=secret_headers).json()
70 headers=secret_headers).json()
67 except requests.ConnectionError:
71 except requests.ConnectionError:
68 log.exception('ConnectionError happened')
72 log.exception('ConnectionError occurred for endpoint %s', req_url)
69 if raise_exc:
73 if raise_exc:
70 raise ChannelstreamConnectionException()
74 raise ChannelstreamConnectionException(req_url)
71 except Exception:
75 except Exception:
72 log.exception('Exception related to channelstream happened')
76 log.exception('Exception related to Channelstream happened')
73 if raise_exc:
77 if raise_exc:
74 raise ChannelstreamConnectionException()
78 raise ChannelstreamConnectionException()
75 return response
79 return response
General Comments 0
You need to be logged in to leave comments. Login now