You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2016/03/23 18:47:06 UTC
ambari git commit: AMBARI-15533 - HDFS Alerts for AMS Throw 'invalid
literal for int() with base 10: '50.0'' (jonathanhurley)
Repository: ambari
Updated Branches:
refs/heads/trunk 13d487b77 -> f90d0beae
AMBARI-15533 - HDFS Alerts for AMS Throw 'invalid literal for int() with base 10: '50.0'' (jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f90d0bea
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f90d0bea
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f90d0bea
Branch: refs/heads/trunk
Commit: f90d0beaeb3e22da5245710b1cdfc49bf24f08c9
Parents: 13d487b
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Wed Mar 23 11:06:53 2016 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Wed Mar 23 13:44:35 2016 -0400
----------------------------------------------------------------------
.../package/alerts/alert_metrics_deviation.py | 28 +++++++++++++++++---
1 file changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/f90d0bea/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_metrics_deviation.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_metrics_deviation.py b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_metrics_deviation.py
index f62c4a3..2163898 100644
--- a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_metrics_deviation.py
+++ b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_metrics_deviation.py
@@ -64,10 +64,16 @@ METRIC_NAME_PARAM_KEY = 'metricName'
METRIC_NAME_PARAM_DEFAULT = ''
APP_ID_PARAM_KEY = 'appId'
APP_ID_PARAM_DEFAULT = 'NAMENODE'
+
+# the interval to check the metric (should be cast to int but could be a float)
INTERVAL_PARAM_KEY = 'interval'
INTERVAL_PARAM_DEFAULT = 60
+
+# the default threshold to trigger a CRITICAL (should be cast to int but could a float)
DEVIATION_CRITICAL_THRESHOLD_KEY = 'metric.deviation.critical.threshold'
DEVIATION_CRITICAL_THRESHOLD_DEFAULT = 10
+
+# the default threshold to trigger a WARNING (should be cast to int but could be a float)
DEVIATION_WARNING_THRESHOLD_KEY = 'metric.deviation.warning.threshold'
DEVIATION_WARNING_THRESHOLD_DEFAULT = 5
NAMENODE_SERVICE_RPC_PORT_KEY = ''
@@ -123,19 +129,19 @@ def execute(configurations={}, parameters={}, host_name=None):
interval = INTERVAL_PARAM_DEFAULT
if INTERVAL_PARAM_KEY in parameters:
- interval = int(parameters[INTERVAL_PARAM_KEY])
+ interval = _coerce_to_integer(parameters[INTERVAL_PARAM_KEY])
warning_threshold = DEVIATION_WARNING_THRESHOLD_DEFAULT
if DEVIATION_WARNING_THRESHOLD_KEY in parameters:
- warning_threshold = int(parameters[DEVIATION_WARNING_THRESHOLD_KEY])
+ warning_threshold = _coerce_to_integer(parameters[DEVIATION_WARNING_THRESHOLD_KEY])
critical_threshold = DEVIATION_CRITICAL_THRESHOLD_DEFAULT
if DEVIATION_CRITICAL_THRESHOLD_KEY in parameters:
- critical_threshold = int(parameters[DEVIATION_CRITICAL_THRESHOLD_KEY])
+ critical_threshold = _coerce_to_integer(parameters[DEVIATION_CRITICAL_THRESHOLD_KEY])
minimum_value_threshold = None
if MINIMUM_VALUE_THRESHOLD_KEY in parameters:
- minimum_value_threshold = int(parameters[MINIMUM_VALUE_THRESHOLD_KEY])
+ minimum_value_threshold = _coerce_to_integer(parameters[MINIMUM_VALUE_THRESHOLD_KEY])
#parse configuration
if configurations is None:
@@ -400,3 +406,17 @@ def _get_ha_state_from_json(string_json):
jmx_bean_name = jmx_bean["name"]
if jmx_bean_name == "Hadoop:service=NameNode,name=FSNamesystem":
return jmx_bean["tag.HAState"]
+
+
+def _coerce_to_integer(value):
+ """
+ Attempts to correctly coerce a value to an integer. For the case of an integer or a float,
+ this will essentially either NOOP or return a truncated value. If the parameter is a string,
+ then it will first attempt to be coerced from a integer, and failing that, a float.
+ :param value: the value to coerce
+ :return: the coerced value as an integer
+ """
+ try:
+ return int(value)
+ except ValueError:
+ return int(float(value))