Skip to content

Commit 114da01

Browse files
committed
Change Error classes to just HawkularError, not HawkularMetricsError anymore. Also remove duplicate code and unused code
1 parent 2a69ddf commit 114da01

3 files changed

Lines changed: 17 additions & 32 deletions

File tree

hawkular/alerts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright 2015-2016 Red Hat, Inc. and/or its affiliates
2+
Copyright 2015-2017 Red Hat, Inc. and/or its affiliates
33
and other contributors.
44
55
Licensed under the Apache License, Version 2.0 (the "License");

hawkular/client.py

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright 2015-2016 Red Hat, Inc. and/or its affiliates
2+
Copyright 2015-2017 Red Hat, Inc. and/or its affiliates
33
and other contributors.
44
55
Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,10 +17,7 @@
1717
from __future__ import unicode_literals
1818

1919
import codecs
20-
import time
21-
import collections
2220
import base64
23-
import ssl
2421

2522
try:
2623
import simplejson as json
@@ -46,15 +43,15 @@ def default(self, obj):
4643
return json.JSONEncoder.default(self, obj)
4744

4845

49-
class HawkularMetricsError(HTTPError):
46+
class HawkularError(HTTPError):
5047
pass
5148

5249

53-
class HawkularMetricsConnectionError(URLError):
50+
class HawkularConnectionError(URLError):
5451
pass
5552

5653

57-
class HawkularMetricsStatusError(ValueError):
54+
class HawkularStatusError(ValueError):
5855
pass
5956

6057

@@ -71,7 +68,9 @@ def http_response(self, request, response):
7168
https_response = http_response
7269

7370

74-
class ApiObject:
71+
class ApiObject(object):
72+
73+
__slots__ = []
7574

7675
defaults = dict()
7776

@@ -114,21 +113,7 @@ def list_to_object_list(cls, o):
114113
return [cls(ob) for ob in o]
115114
return []
116115

117-
118-
class HawkularHTTPErrorProcessor(HTTPErrorProcessor):
119-
"""
120-
Hawkular-Metrics uses http codes 201, 204
121-
"""
122-
123-
def http_response(self, request, response):
124-
if response.code in [200, 201, 204]:
125-
return response
126-
return HTTPErrorProcessor.http_response(self, request, response)
127-
128-
https_response = http_response
129-
130-
131-
class HawkularBaseClient:
116+
class HawkularBaseClient(object):
132117
"""
133118
Creates new client for Hawkular-Metrics. As tenant_id, give intended tenant_id, even if it's not
134119
created yet. To change the instance's tenant_id, use tenant(tenant_id) method
@@ -284,7 +269,7 @@ def _serialize_object(o):
284269
def _handle_error(self, e):
285270
if isinstance(e, HTTPError):
286271
# Cast to HawkularMetricsError
287-
ee = HawkularMetricsError(e.url, e.code, e.msg, e.hdrs, e.fp)
272+
ee = HawkularError(e.url, e.code, e.msg, e.hdrs, e.fp)
288273
err_json = e.read()
289274

290275
try:
@@ -297,17 +282,17 @@ def _handle_error(self, e):
297282

298283
elif isinstance(e, URLError):
299284
# Cast to HawkularMetricsConnectionError
300-
ee = HawkularMetricsConnectionError(e)
285+
ee = HawkularConnectionError(e)
301286
ee.msg = "Error, could not send event(s) to the Hawkular Metrics: " + str(e.reason)
302287
raise ee
303288
elif isinstance(e, KeyError):
304289
# Cast to HawkularMetricsStatusError
305-
ee = HawkularMetricsStatusError(e)
290+
ee = HawkularStatusError(e)
306291
ee.msg = "Error, unable to get implementation version for metrics: " + str(e.reason)
307292
raise ee
308293
elif isinstance(e, ValueError):
309294
# Cast to HawkularMetricsStatusError
310-
ee = HawkularMetricsStatusError(e)
295+
ee = HawkularStatusError(e)
311296
ee.msg = "Error, unable to determine implementation version for metrics: " + str(e.reason)
312297
raise ee
313298
else:

hawkular/metrics.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
except ImportError:
2929
import json
3030

31-
from hawkular.client import ApiObject, HawkularBaseClient, HawkularMetricsError
32-
from hawkular.client import HawkularMetricsConnectionError, HawkularMetricsStatusError
31+
from hawkular.client import ApiObject, HawkularBaseClient, HawkularError
32+
from hawkular.client import HawkularConnectionError, HawkularStatusError
3333

3434
class MetricType:
3535
Gauge = 'gauges'
@@ -125,7 +125,7 @@ def put(self, data):
125125
for d in data:
126126
metric_type = d.pop('type', None)
127127
if metric_type is None:
128-
raise HawkularMetricsError('Undefined MetricType')
128+
raise HawkularError('Undefined MetricType')
129129
r[metric_type].append(d)
130130

131131
# This isn't transactional, but .. ouh well. One can always repost everything.
@@ -274,7 +274,7 @@ def create_metric_definition(self, metric_type, metric_id, **tags):
274274
json_data = json.dumps(item, indent=2)
275275
try:
276276
self._post(self._get_url(metric_type), json_data)
277-
except HawkularMetricsError as e:
277+
except HawkularError as e:
278278
if e.code == 409:
279279
return False
280280
raise e

0 commit comments

Comments
 (0)