Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Tidy up some loose ends in HA Agent

  • Loading branch information...
commit cd99fda9f1223db7446c0ddb6adb8c529cbf6772 1 parent f853398
Patrick Armstrong authored March 26, 2013
5  epu/exceptions.py
@@ -27,6 +27,11 @@ class ProgrammingError(Exception):
27 27
     """
28 28
 
29 29
 
  30
+class PolicyError(Exception):
  31
+    """Something went wrong with a policy somewhere
  32
+    """
  33
+
  34
+
30 35
 class GeneralIaaSException(Exception):
31 36
     """
32 37
     Unknown Exceptions that have come from the provisioner when communicating with IaaS
11  epu/highavailability/core.py
... ...
@@ -1,7 +1,7 @@
1 1
 
2 2
 import logging
3 3
 
4  
-from epu.exceptions import ProgrammingError
  4
+from epu.exceptions import ProgrammingError, PolicyError
5 5
 
6 6
 log = logging.getLogger(__name__)
7 7
 
@@ -68,9 +68,12 @@ def apply_policy(self):
68 68
         log.debug("%sapplying policy", self.logprefix)
69 69
 
70 70
         all_procs = self.control.get_all_processes()
71  
-        managed_upids = self.policy.apply_policy(all_procs, self.managed_upids)
72  
-        if managed_upids is not None:
73  
-            self.managed_upids = managed_upids
  71
+        try:
  72
+            managed_upids = self.policy.apply_policy(all_procs, self.managed_upids)
  73
+            if isinstance(managed_upids, (tuple, list)):
  74
+                self.managed_upids = managed_upids
  75
+        except PolicyError:
  76
+            log.exception("Couldn't apply policy because of an error")
74 77
 
75 78
     def set_managed_upids(self, upids):
76 79
         """Called to override the managed process set, for HAAgent restart
16  epu/highavailability/policy.py
... ...
@@ -1,9 +1,12 @@
1 1
 import logging
2 2
 import datetime
3 3
 
  4
+from urllib2 import HTTPError
  5
+
4 6
 from epu.sensors import Statistics
5 7
 from epu.sensors.trafficsentinel import TrafficSentinel
6 8
 from epu.states import ProcessState, HAState
  9
+from epu.exceptions import PolicyError
7 10
 
8 11
 log = logging.getLogger(__name__)
9 12
 
@@ -192,8 +195,7 @@ def apply_policy(self, all_procs, managed_upids):
192 195
         @param managed_upids: a list of upids that the HA Service is maintaining
193 196
         """
194 197
         if not self.parameters:
195  
-            log.debug("No policy parameters set. Not applying policy.")
196  
-            return []
  198
+            raise PolicyError("No policy parameters set. Not applying policy.")
197 199
 
198 200
         managed_upids = self._filter_invalid_processes(all_procs, managed_upids)
199 201
 
@@ -426,8 +428,7 @@ def status(self):
426 428
     def apply_policy(self, all_procs, managed_upids):
427 429
 
428 430
         if self._parameters is None:
429  
-            log.debug("No parameters set, unable to apply policy")
430  
-            return []
  431
+            raise PolicyError("No parameters set, unable to apply policy")
431 432
 
432 433
         time_since_last_scale = datetime.datetime.now() - self.last_scale_action
433 434
         if time_since_last_scale.seconds < self._parameters['cooldown_period']:
@@ -474,9 +475,10 @@ def apply_policy(self, all_procs, managed_upids):
474 475
         try:
475 476
             metric_per_host = self._sensor_aggregator.get_metric_statistics(
476 477
                 period, start_time, end_time, metric_name, statistics, dimensions)
477  
-        except Exception:
478  
-            log.exception("Problem getting metrics from sensor aggregator")
479  
-            return
  478
+        except HTTPError as h:
  479
+            msg = "Problem getting metrics from sensor aggregator with url: '%s'" % h.filename
  480
+            log.exception(msg)
  481
+            raise PolicyError(msg)
480 482
 
481 483
         values = []
482 484
         for host, metric_value in metric_per_host.iteritems():

0 notes on commit cd99fda

Please sign in to comment.
Something went wrong with that request. Please try again.