Repository: ambari Updated Branches: refs/heads/trunk bc5d7e07c -> fb016d5cc
AMBARI-8051 - Alerts: Convert HDP 1.x Nagios Alerts (jonathanhurley) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/fb016d5c Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/fb016d5c Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/fb016d5c Branch: refs/heads/trunk Commit: fb016d5cce61e1b06b9c467bc28f4c0a98b1481c Parents: bc5d7e0 Author: Jonathan Hurley <[email protected]> Authored: Thu Oct 30 16:41:23 2014 -0400 Committer: Jonathan Hurley <[email protected]> Committed: Fri Oct 31 08:22:47 2014 -0400 ---------------------------------------------------------------------- .../internal/AlertGroupResourceProvider.java | 13 +- .../internal/AlertTargetResourceProvider.java | 3 +- .../resources/host_scripts/alert_disk_space.py | 4 +- .../HDP/1.3.2/services/GANGLIA/alerts.json | 107 +++++ .../stacks/HDP/1.3.2/services/HBASE/alerts.json | 109 +++++ .../stacks/HDP/1.3.2/services/HDFS/alerts.json | 435 +++++++++++++++++++ .../stacks/HDP/1.3.2/services/HIVE/alerts.json | 52 +++ .../package/files/alert_hive_thrift_port.py | 89 ++++ .../HIVE/package/files/alert_webhcat_server.py | 111 +++++ .../HDP/1.3.2/services/MAPREDUCE/alerts.json | 201 +++++++++ .../files/alert_mapreduce_directory_space.py | 95 ++++ .../stacks/HDP/1.3.2/services/OOZIE/alerts.json | 40 ++ .../package/files/alert_check_oozie_server.py | 74 ++++ .../HDP/1.3.2/services/ZOOKEEPER/alerts.json | 51 +++ .../AlertTargetResourceProviderTest.java | 38 +- 15 files changed, 1403 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProvider.java index e3c93e0..50820a7 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertGroupResourceProvider.java @@ -335,15 +335,16 @@ public class AlertGroupResourceProvider extends Collection<Long> definitionIds = (Collection<Long>) requestMap.get(ALERT_GROUP_DEFINITIONS); // if targets were supplied, replace existing - Set<AlertTargetEntity> targets = new HashSet<AlertTargetEntity>(); - if (null != targetIds && targetIds.size() > 0) { + if (null != targetIds) { + Set<AlertTargetEntity> targets = new HashSet<AlertTargetEntity>(); + List<Long> ids = new ArrayList<Long>(targetIds.size()); ids.addAll(targetIds); - targets.addAll(s_dao.findTargetsById(ids)); - entity.setAlertTargets(targets); - } else if (targetIds.size() == 0) { - // empty array supplied, clear out existing targets + if (ids.size() > 0) { + targets.addAll(s_dao.findTargetsById(ids)); + } + entity.setAlertTargets(targets); } http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java index 5173c1b..1caaa22 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java @@ -343,7 +343,8 @@ public class AlertTargetResourceProvider extends resource.setProperty(ALERT_TARGET_NOTIFICATION_TYPE, entity.getNotificationType()); - if (!isCollection) { + // these are expensive to deserialize; only do it if asked for + if (requestedIds.contains(ALERT_TARGET_PROPERTIES)) { String properties = entity.getProperties(); Map<String, String> map = s_gson.<Map<String, String>> fromJson( properties, http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/main/resources/host_scripts/alert_disk_space.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/host_scripts/alert_disk_space.py b/ambari-server/src/main/resources/host_scripts/alert_disk_space.py index 6666cdc..e68e583 100644 --- a/ambari-server/src/main/resources/host_scripts/alert_disk_space.py +++ b/ambari-server/src/main/resources/host_scripts/alert_disk_space.py @@ -44,9 +44,7 @@ def execute(parameters=None, host_name=None): disk_usage = _get_disk_usage() except NotImplementedError, platform_error: return (('CRITICAL', [str(platform_error)])) - pass - - disk_usage = _get_disk_usage() + if disk_usage is None or disk_usage.total == 0: return (('CRITICAL', ['Unable to determine the disk usage'])) http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/GANGLIA/alerts.json ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/GANGLIA/alerts.json b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/GANGLIA/alerts.json new file mode 100644 index 0000000..4639337 --- /dev/null +++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/GANGLIA/alerts.json @@ -0,0 +1,107 @@ +{ + "GANGLIA": { + "service": [], + "GANGLIA_SERVER": [ + { + "name": "ganglia_server_process", + "label": "Ganglia Server Process", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "PORT", + "uri": "8651", + "default_port": 8651, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + }, + { + "name": "ganglia_monitor_hdfs_namenode", + "label": "Ganglia NameNode Process Monitor", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "PORT", + "uri": "8661", + "default_port": 8661, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + }, + { + "name": "ganglia_monitor_hbase_master", + "label": "Ganglia HBase Master Process Monitor", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "PORT", + "uri": "8663", + "default_port": 8663, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + }, + { + "name": "ganglia_monitor_mapreduce_jobtracker", + "label": "Ganglia JobTracker Process Monitor", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "PORT", + "uri": "8662", + "default_port": 8662, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + }, + { + "name": "ganglia_monitor_mapreduce_history_server", + "label": "Ganglia History Server Process Monitor", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "PORT", + "uri": "8666", + "default_port": 8666, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + } + ] + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HBASE/alerts.json ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HBASE/alerts.json b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HBASE/alerts.json new file mode 100644 index 0000000..3cf10d5 --- /dev/null +++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HBASE/alerts.json @@ -0,0 +1,109 @@ +{ + "HBASE": { + "service": [ + { + "name": "hbase_regionserver_process_percent", + "label": "Percent RegionServers Available", + "interval": 1, + "scope": "SERVICE", + "enabled": true, + "source": { + "type": "AGGREGATE", + "alert_name": "hbase_regionserver_process", + "reporting": { + "ok": { + "text": "affected: [{1}], total: [{0}]" + }, + "warning": { + "text": "affected: [{1}], total: [{0}]", + "value": 0.1 + }, + "critical": { + "text": "affected: [{1}], total: [{0}]", + "value": 0.3 + } + } + } + } + ], + "HBASE_MASTER": [ + { + "name": "hbase_master_process", + "label": "HBase Master Process", + "interval": 1, + "scope": "ANY", + "source": { + "type": "PORT", + "uri": "{{hbase-site/hbase.master.port}}", + "default_port": 60000, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + }, + { + "name": "hbase_master_cpu", + "label": "HBase Maser CPU Utilization", + "interval": 5, + "scope": "ANY", + "enabled": true, + "source": { + "type": "METRIC", + "uri": { + "http": "{{hbase-site/hbase.master.info.port}}", + "https": "{{hbase-site/hbase.master.info.port}}", + "https_property": "{{cluster-env/security_enabled}}", + "https_property_value": "true", + "default_port": 60010 + }, + "reporting": { + "ok": { + "text": "{1} CPU, load {0:.1%}" + }, + "warning": { + "text": "{1} CPU, load {0:.1%}", + "value": 200 + }, + "critical": { + "text": "{1} CPU, load {0:.1%}", + "value": 250 + } + }, + "jmx": { + "property_list": [ + "java.lang:type=OperatingSystem/SystemCpuLoad", + "java.lang:type=OperatingSystem/AvailableProcessors" + ], + "value": "{0} * 100" + } + } + } + ], + "HBASE_REGIONSERVER": [ + { + "name": "hbase_regionserver_process", + "label": "HBase RegionServer Process", + "interval": 1, + "scope": "HOST", + "source": { + "type": "PORT", + "uri": "{{hbase-site/hbase.regionserver.info.port}}", + "default_port": 60030, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + } + ] + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HDFS/alerts.json ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HDFS/alerts.json b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HDFS/alerts.json new file mode 100644 index 0000000..11836b3 --- /dev/null +++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HDFS/alerts.json @@ -0,0 +1,435 @@ +{ + "HDFS":{ + "service": [ + { + "name": "datanode_process_percent", + "label": "Percent DataNodes Available", + "interval": 1, + "scope": "SERVICE", + "enabled": true, + "source": { + "type": "AGGREGATE", + "alert_name": "datanode_process", + "reporting": { + "ok": { + "text": "affected: [{1}], total: [{0}]" + }, + "warning": { + "text": "affected: [{1}], total: [{0}]", + "value": 0.1 + }, + "critical": { + "text": "affected: [{1}], total: [{0}]", + "value": 0.3 + } + } + } + }, + { + "name": "datanode_storage_percent", + "label": "Percent DataNodes With Available Space", + "interval": 1, + "scope": "SERVICE", + "enabled": true, + "source": { + "type": "AGGREGATE", + "alert_name": "datanode_storage", + "reporting": { + "ok": { + "text": "affected: [{1}], total: [{0}]" + }, + "warning": { + "text": "affected: [{1}], total: [{0}]", + "value": 0.1 + }, + "critical": { + "text": "affected: [{1}], total: [{0}]", + "value": 0.3 + } + } + } + }, + { + "name": "journalnode_process_percent", + "label": "Percent JournalNodes Available", + "interval": 1, + "scope": "SERVICE", + "enabled": true, + "source": { + "type": "AGGREGATE", + "alert_name": "journalnode_process", + "reporting": { + "ok": { + "text": "affected: [{1}], total: [{0}]" + }, + "warning": { + "text": "affected: [{1}], total: [{0}]", + "value": 0.33 + }, + "critical": { + "text": "affected: [{1}], total: [{0}]", + "value": 0.50 + } + } + } + } + ], + "NAMENODE": [ + { + "name": "namenode_webui", + "label": "NameNode Web UI", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "WEB", + "uri": { + "http": "{{hdfs-site/dfs.http.address}}", + "https": "{{hdfs-site/dfs.https.port}}", + "https_property": "{{hdfs-site/dfs.https.enable}}", + "https_property_value": "true" + }, + "reporting": { + "ok": { + "text": "HTTP {0} response in {2:.4f} seconds" + }, + "warning":{ + "text": "HTTP {0} response in {2:.4f} seconds" + }, + "critical": { + "text": "Connection failed to {1}" + } + } + } + }, + { + "name": "namenode_cpu", + "label": "NameNode Host CPU Utilization", + "interval": 5, + "scope": "ANY", + "enabled": true, + "source": { + "type": "METRIC", + "uri": { + "http": "{{hdfs-site/dfs.http.address}}", + "https": "{{hdfs-site/dfs.https.port}}", + "https_property": "{{hdfs-site/dfs.https.enable}}", + "https_property_value": "true" + }, + "reporting": { + "ok": { + "text": "{1} CPU, load {0:.1%}" + }, + "warning": { + "text": "{1} CPU, load {0:.1%}", + "value": 200 + }, + "critical": { + "text": "{1} CPU, load {0:.1%}", + "value": 250 + } + }, + "jmx": { + "property_list": [ + "java.lang:type=OperatingSystem/SystemCpuLoad", + "java.lang:type=OperatingSystem/AvailableProcessors" + ], + "value": "{0} * 100" + } + } + }, + { + "name": "namenode_hdfs_blocks_health", + "label": "NameNode Blocks Health", + "interval": 2, + "scope": "ANY", + "enabled": true, + "source": { + "type": "METRIC", + "uri": { + "http": "{{hdfs-site/dfs.http.address}}", + "https": "{{hdfs-site/dfs.https.port}}", + "https_property": "{{hdfs-site/dfs.https.enable}}", + "https_property_value": "true" + }, + "reporting": { + "ok": { + "text": "Total Blocks:[{1}], Missing Blocks:[{0}]" + }, + "warning": { + "text": "Total Blocks:[{1}], Missing Blocks:[{0}]", + "value": 1 + }, + "critical": { + "text": "Total Blocks:[{1}], Missing Blocks:[{0}]", + "value": 1 + } + }, + "jmx": { + "property_list": [ + "Hadoop:service=NameNode,name=FSNamesystemMetrics/MissingBlocks", + "Hadoop:service=NameNode,name=FSNamesystemMetrics/BlocksTotal" + ], + "value": "{0}" + } + } + }, + { + "name": "namenode_hdfs_capacity_utilization", + "label": "HDFS Capacity Utilization", + "interval": 2, + "scope": "ANY", + "enabled": true, + "source": { + "type": "METRIC", + "uri": { + "http": "{{hdfs-site/dfs.http.address}}", + "https": "{{hdfs-site/dfs.https.port}}", + "https_property": "{{hdfs-site/dfs.https.enable}}", + "https_property_value": "true" + }, + "reporting": { + "ok": { + "text": "Capacity Used:[{2:d}%, {0}], Capacity Remaining:[{1}]" + }, + "warning": { + "text": "Capacity Used:[{2:d}%, {0}], Capacity Remaining:[{1}]", + "value": 80 + }, + "critical": { + "text": "Capacity Used:[{2:d}%, {0}], Capacity Remaining:[{1}]", + "value": 90 + } + }, + "jmx": { + "property_list": [ + "Hadoop:service=NameNode,name=FSNamesystemState/CapacityUsed", + "Hadoop:service=NameNode,name=FSNamesystemState/CapacityRemaining" + ], + "value": "{0}/({0} + {1}) * 100" + } + } + }, + { + "name": "namenode_rpc_latency", + "label": "NameNode RPC Latency", + "interval": 2, + "scope": "ANY", + "enabled": true, + "source": { + "type": "METRIC", + "uri": { + "http": "{{hdfs-site/dfs.http.address}}", + "https": "{{hdfs-site/dfs.https.port}}", + "https_property": "{{hdfs-site/dfs.https.enable}}", + "https_property_value": "true" + }, + "reporting": { + "ok": { + "text": "Average Queue Time:[{0}], Average Processing Time:[{1}]" + }, + "warning": { + "text": "Average Queue Time:[{0}], Average Processing Time:[{1}]", + "value": 3000 + }, + "critical": { + "text": "Average Queue Time:[{0}], Average Processing Time:[{1}]", + "value": 5000 + } + }, + "jmx": { + "property_list": [ + "Hadoop:service=NameNode,name=RpcActivityForPort*/RpcQueueTime_avg_time", + "Hadoop:service=NameNode,name=RpcActivityForPort*/RpcProcessingTime_avg_time" + ], + "value": "{0}" + } + } + }, + { + "name": "namenode_directory_status", + "label": "NameNode Directory Status", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "METRIC", + "uri": { + "http": "{{hdfs-site/dfs.http.address}}", + "https": "{{hdfs-site/dfs.https.port}}", + "https_property": "{{hdfs-site/dfs.https.enable}}", + "https_property_value": "true" + }, + "reporting": { + "ok": { + "text": "Directories are healthy" + }, + "warning": { + "text": "Failed directory count: {1}", + "value": 1 + }, + "critical": { + "text": "Failed directory count: {1}", + "value": 1 + } + }, + "jmx": { + "property_list": [ + "Hadoop:service=NameNode,name=NameNodeInfo/NameDirStatuses" + ], + "value": "calculate(args)\ndef calculate(args):\n import json\n json_statuses = json.loads({0})\n return len(json_statuses['failed']) if 'failed' in json_statuses else 0" + } + } + }, + { + "name": "namenode_process", + "label": "NameNode Process", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "PORT", + "uri": "{{hdfs-site/dfs.namenode.http-address}}", + "default_port": 50070, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + } + ], + "SECONDARY_NAMENODE": [ + { + "name": "secondary_namenode_process", + "label": "Secondary NameNode Process", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "PORT", + "uri": "{{hdfs-site/dfs.secondary.http.address}}", + "default_port": 50090, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + } + ], + "JOURNALNODE": [ + { + "name": "journalnode_process", + "label": "JournalNode Process", + "interval": 1, + "scope": "HOST", + "enabled": true, + "source": { + "type": "PORT", + "uri": "{{hdfs-site/dfs.journalnode.http-address}}", + "default_port": 8480, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + } + ], + "DATANODE": [ + { + "name": "datanode_process", + "label": "DateNode Process", + "interval": 1, + "scope": "HOST", + "enabled": true, + "source": { + "type": "PORT", + "uri": "{{hdfs-site/dfs.datanode.address}}", + "default_port": 50010, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + }, + { + "name": "datanode_webui", + "label": "DataNode Web UI", + "interval": 1, + "scope": "HOST", + "enabled": true, + "source": { + "type": "WEB", + "uri": { + "http": "{{hdfs-site/dfs.datanode.http.address}}", + "https": "{{hdfs-site/dfs.datanode.https.address}}", + "https_property": "{{hdfs-site/dfs.https.enable}}", + "https_property_value": "true" + }, + "reporting": { + "ok": { + "text": "HTTP {0} response in {2:.4f} seconds" + }, + "warning":{ + "text": "HTTP {0} response in {2:.4f} seconds" + }, + "critical": { + "text": "Connection failed to {1}" + } + } + } + }, + { + "name": "datanode_storage", + "label": "DataNode Storage", + "interval": 2, + "scope": "HOST", + "enabled": true, + "source": { + "type": "METRIC", + "uri": { + "http": "{{hdfs-site/dfs.datanode.http.address}}", + "https": "{{hdfs-site/dfs.datanode.https.address}}", + "https_property": "{{hdfs-site/dfs.https.enable}}", + "https_property_value": "true" + }, + "reporting": { + "ok": { + "text": "Remaining Capacity:[{0}], Total Capacity:[{2:d}% Used, {1}]" + }, + "warning": { + "text": "Remaining Capacity:[{0}], Total Capacity:[{2:d}% Used, {1}]", + "value": 80 + }, + "critical": { + "text": "Remaining Capacity:[{0}], Total Capacity:[{2:d}% Used, {1}]", + "value": 90 + } + }, + "jmx": { + "property_list": [ + "Hadoop:service=DataNode,name=FSDatasetState-*/Remaining", + "Hadoop:service=DataNode,name=FSDatasetState-*/Capacity" + ], + "value": "({1} - {0})/{1} * 100" + } + } + } + ] + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/alerts.json ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/alerts.json b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/alerts.json new file mode 100644 index 0000000..f55e692 --- /dev/null +++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/alerts.json @@ -0,0 +1,52 @@ +{ + "HIVE": { + "service": [], + "HIVE_METASTORE": [ + { + "name": "hive_metastore_process", + "label": "Hive Metastore Process", + "interval": 1, + "scope": "ANY", + "source": { + "type": "PORT", + "uri": "{{hive-site/hive.metastore.uris}}", + "default_port": 9083, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + } + ], + "HIVE_SERVER": [ + { + "name": "hive_server_process", + "label": "HiveServer2 Process", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "SCRIPT", + "path": "HDP/1.3.2/services/HIVE/package/files/alert_hive_thrift_port.py" + } + } + ], + "WEBHCAT_SERVER": [ + { + "name": "hive_webhcat_server_status", + "label": "WebHCat Server Status", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "SCRIPT", + "path": "HDP/1.3.2/services/HIVE/package/files/alert_webhcat_server.py" + } + } + ] + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/package/files/alert_hive_thrift_port.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/package/files/alert_hive_thrift_port.py b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/package/files/alert_hive_thrift_port.py new file mode 100644 index 0000000..bd3f276 --- /dev/null +++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/package/files/alert_hive_thrift_port.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python + +""" +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import json +import socket +import time +import traceback +import urllib2 +from resource_management.libraries.functions import hive_check + +OK_MESSAGE = "TCP OK - %.4f response on port %s" +CRITICAL_MESSAGE = "Connection failed on host {0}:{1}" + +HIVE_SERVER_THRIFT_PORT_KEY = '{{hive-site/hive.server2.thrift.port}}' +SECURITY_ENABLED_KEY = '{{cluster-env/security_enabled}}' + +PERCENT_WARNING = 200 +PERCENT_CRITICAL = 200 + +THRIFT_PORT_DEFAULT = 10000 + +def get_tokens(): + """ + Returns a tuple of tokens in the format {{site/property}} that will be used + to build the dictionary passed into execute + """ + return (HIVE_SERVER_THRIFT_PORT_KEY,SECURITY_ENABLED_KEY) + + +def execute(parameters=None, host_name=None): + """ + Returns a tuple containing the result code and a pre-formatted result label + + Keyword arguments: + parameters (dictionary): a mapping of parameter key to value + host_name (string): the name of this host where the alert is running + """ + + if parameters is None: + return (('UNKNOWN', ['There were no parameters supplied to the script.'])) + + thrift_port = THRIFT_PORT_DEFAULT + if HIVE_SERVER_THRIFT_PORT_KEY in parameters: + thrift_port = int(parameters[HIVE_SERVER_THRIFT_PORT_KEY]) + + security_enabled = False + if SECURITY_ENABLED_KEY in parameters: + security_enabled = bool(parameters[SECURITY_ENABLED_KEY]) + + result_code = None + + try: + if host_name is None: + host_name = socket.getfqdn() + + start_time = time.time() + is_thrift_port_ok = hive_check.check_thrift_port_sasl(host_name, + thrift_port, security_enabled=security_enabled) + + if is_thrift_port_ok == True: + result_code = 'OK' + total_time = time.time() - start_time + label = OK_MESSAGE % (total_time, thrift_port) + else: + result_code = 'CRITICAL' + label = CRITICAL_MESSAGE.format(host_name,thrift_port) + + except Exception, e: + label = str(e) + result_code = 'UNKNOWN' + + return ((result_code, [label])) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/package/files/alert_webhcat_server.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/package/files/alert_webhcat_server.py b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/package/files/alert_webhcat_server.py new file mode 100644 index 0000000..44840de --- /dev/null +++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/package/files/alert_webhcat_server.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python + +""" +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import json +import socket +import time +import urllib2 + +RESULT_CODE_OK = 'OK' +RESULT_CODE_CRITICAL = 'CRITICAL' +RESULT_CODE_UNKNOWN = 'UNKNOWN' + +OK_MESSAGE = 'TCP OK - {0:.4f} response on port {1}' +CRITICAL_CONNECTION_MESSAGE = 'Connection failed on host {0}:{1}' +CRITICAL_TEMPLETON_STATUS_MESSAGE = 'WebHCat returned an unexpected status of "{0}"' +CRITICAL_TEMPLETON_UNKNOWN_JSON_MESSAGE = 'Unable to determine WebHCat health from unexpected JSON response' + +TEMPLETON_PORT_KEY = '{{webhcat-site/templeton.port}}' +SECURITY_ENABLED_KEY = '{{cluster-env/security_enabled}}' + +TEMPLETON_OK_RESPONSE = 'ok' +TEMPLETON_PORT_DEFAULT = 50111 + +def get_tokens(): + """ + Returns a tuple of tokens in the format {{site/property}} that will be used + to build the dictionary passed into execute + """ + return (TEMPLETON_PORT_KEY,SECURITY_ENABLED_KEY) + + +def execute(parameters=None, host_name=None): + """ + Returns a tuple containing the result code and a pre-formatted result label + + Keyword arguments: + parameters (dictionary): a mapping of parameter key to value + host_name (string): the name of this host where the alert is running + """ + + result_code = RESULT_CODE_UNKNOWN + + if parameters is None: + return (result_code, ['There were no parameters supplied to the script.']) + + templeton_port = TEMPLETON_PORT_DEFAULT + if TEMPLETON_PORT_KEY in parameters: + templeton_port = int(parameters[TEMPLETON_PORT_KEY]) + + security_enabled = False + if SECURITY_ENABLED_KEY in parameters: + security_enabled = parameters[SECURITY_ENABLED_KEY].lower() == 'true' + + scheme = 'http' + if security_enabled is True: + scheme = 'https' + + label = '' + url_response = None + templeton_status = '' + total_time = 0 + + try: + # the alert will always run on the webhcat host + if host_name is None: + host_name = socket.getfqdn() + + query = "{0}://{1}:{2}/templeton/v1/status".format(scheme, host_name, + templeton_port) + + # execute the query for the JSON that includes templeton status + start_time = time.time() + url_response = urllib2.urlopen(query) + total_time = time.time() - start_time + except: + label = CRITICAL_CONNECTION_MESSAGE.format(host_name,templeton_port) + return (RESULT_CODE_CRITICAL, [label]) + + # URL response received, parse it + try: + json_response = json.loads(url_response.read()) + templeton_status = json_response['status'] + except: + return (RESULT_CODE_CRITICAL, [CRITICAL_TEMPLETON_UNKNOWN_JSON_MESSAGE]) + + # proper JSON received, compare against known value + if templeton_status.lower() == TEMPLETON_OK_RESPONSE: + result_code = RESULT_CODE_OK + label = OK_MESSAGE.format(total_time, templeton_port) + else: + result_code = RESULT_CODE_CRITICAL + label = CRITICAL_TEMPLETON_STATUS_MESSAGE.format(templeton_status) + + return (result_code, [label]) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/MAPREDUCE/alerts.json ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/MAPREDUCE/alerts.json b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/MAPREDUCE/alerts.json new file mode 100644 index 0000000..698560d --- /dev/null +++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/MAPREDUCE/alerts.json @@ -0,0 +1,201 @@ +{ + "MAPREDUCE":{ + "service": [ + { + "name": "mapreduce_tasktracker_process_percent", + "label": "Percent TaskTrackers Available", + "interval": 1, + "scope": "SERVICE", + "enabled": true, + "source": { + "type": "AGGREGATE", + "alert_name": "mapreduce_tasktracker_process", + "reporting": { + "ok": { + "text": "affected: [{1}], total: [{0}]" + }, + "warning": { + "text": "affected: [{1}], total: [{0}]", + "value": 0.1 + }, + "critical": { + "text": "affected: [{1}], total: [{0}]", + "value": 0.3 + } + } + } + } + ], + "JOBTRACKER": [ + { + "name": "mapreduce_jobtracker_webui", + "label": "JobTracker Web UI", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "WEB", + "uri": { + "http": "{{mapred-site/mapred.job.tracker.http.address}}" + }, + "reporting": { + "ok": { + "text": "HTTP {0} response in {2:.4f} seconds" + }, + "warning":{ + "text": "HTTP {0} response in {2:.4f} seconds" + }, + "critical": { + "text": "Connection failed to {1}" + } + } + } + }, + { + "name": "mapreduce_jobtracker_cpu", + "label": "JobTracker Host CPU Utilization", + "interval": 5, + "scope": "ANY", + "enabled": true, + "source": { + "type": "METRIC", + "uri": { + "http": "{{mapred-site/mapred.job.tracker.http.address}}" + }, + "reporting": { + "ok": { + "text": "{1} CPU, load {0:.1%}" + }, + "warning": { + "text": "{1} CPU, load {0:.1%}", + "value": 200 + }, + "critical": { + "text": "{1} CPU, load {0:.1%}", + "value": 250 + } + }, + "jmx": { + "property_list": [ + "java.lang:type=OperatingSystem/SystemCpuLoad", + "java.lang:type=OperatingSystem/AvailableProcessors" + ], + "value": "{0} * 100" + } + } + }, + { + "name": "mapreduce_jobtracker_rpc_latency", + "label": "JobTracker RPC Latency", + "interval": 2, + "scope": "ANY", + "enabled": true, + "source": { + "type": "METRIC", + "uri": { + "http": "{{mapred-site/mapred.job.tracker.http.address}}" + }, + "reporting": { + "ok": { + "text": "Average Queue Time:[{0}], Average Processing Time:[{1}]" + }, + "warning": { + "text": "Average Queue Time:[{0}], Average Processing Time:[{1}]", + "value": 3000 + }, + "critical": { + "text": "Average Queue Time:[{0}], Average Processing Time:[{1}]", + "value": 5000 + } + }, + "jmx": { + "property_list": [ + "Hadoop:service=JobTracker,name=RpcActivityForPort*/RpcQueueTime_avg_time", + "Hadoop:service=JobTracker,name=RpcActivityForPort*/RpcProcessingTime_avg_time" + ], + "value": "{0}" + } + } + }, + { + "name": "mapreduce_jobtracker_process", + "label": "JobTracker Process", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "PORT", + "uri": "{{mapred-site/mapred.job.tracker.http.address}}", + "default_port": 50030, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + } + ], + "TASKTRACKER": [ + { + "name": "mapreduce_tasktracker_process", + "label": "TaskTracker Process", + "interval": 1, + "scope": "HOST", + "enabled": true, + "source": { + "type": "PORT", + "uri": "50060", + "default_port": 50060, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + }, + { + "name": "mapreduce_local_directory_space", + "label": "MapReduce Local Directory Space", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "SCRIPT", + "path": "HDP/1.3.2/services/MAPREDUCE/package/files/alert_mapreduce_directory_space.py" + } + } + ], + "HISTORYSERVER": [ + { + "name": "mapreduce_historyserver_webui", + "label": "History Server Web UI", + "interval": 1, + "scope": "ANY", + "enabled": true, + "source": { + "type": "WEB", + "uri": { + "http": "{{mapred-site/mapreduce.history.server.http.address}}" + }, + "reporting": { + "ok": { + "text": "HTTP {0} response in {2:.4f} seconds" + }, + "warning":{ + "text": "HTTP {0} response in {2:.4f} seconds" + }, + "critical": { + "text": "Connection failed to {1}" + } + } + } + } + ] + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/MAPREDUCE/package/files/alert_mapreduce_directory_space.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/MAPREDUCE/package/files/alert_mapreduce_directory_space.py b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/MAPREDUCE/package/files/alert_mapreduce_directory_space.py new file mode 100644 index 0000000..2124ad1 --- /dev/null +++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/MAPREDUCE/package/files/alert_mapreduce_directory_space.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python + +""" +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import collections +import os +import platform + +RESULT_CODE_OK = 'OK' +RESULT_CODE_CRITICAL = 'CRITICAL' +RESULT_CODE_UNKNOWN = 'UNKNOWN' + +MAPREDUCE_LOCAL_DIR_KEY = '{{mapred-site/mapred.local.dir}}' + +def get_tokens(): + """ + Returns a tuple of tokens in the format {{site/property}} that will be used + to build the dictionary passed into execute + """ + return (MAPREDUCE_LOCAL_DIR_KEY,) + + +def execute(parameters=None, host_name=None): + """ + Returns a tuple containing the result code and a pre-formatted result label + + Keyword arguments: + parameters (dictionary): a mapping of parameter key to value + host_name (string): the name of this host where the alert is running + """ + if parameters is None: + return (('UNKNOWN', ['There were no parameters supplied to the script.'])) + + mapreduce_local_directories = None + if MAPREDUCE_LOCAL_DIR_KEY in parameters: + mapreduce_local_directories = parameters[MAPREDUCE_LOCAL_DIR_KEY] + + if MAPREDUCE_LOCAL_DIR_KEY is None: + return (('UNKNOWN', ['The MapReduce Local Directory is required.'])) + + directory_list = mapreduce_local_directories.split(",") + for directory in directory_list: + disk_usage = None + try: + disk_usage = _get_disk_usage(directory) + except NotImplementedError, platform_error: + return (RESULT_CODE_UNKNOWN, [str(platform_error)]) + + if disk_usage is None or disk_usage.total == 0: + return (RESULT_CODE_UNKNOWN, ['Unable to determine the disk usage.']) + + percent = disk_usage.used / float(disk_usage.total) * 100 + + if percent > 85: + message = 'The disk usage of {0} is {1:d}%'.format(directory,percent) + return (RESULT_CODE_CRITICAL, [message]) + + return (RESULT_CODE_OK, ["All MapReduce local directories have sufficient space."]) + + +def _get_disk_usage(path): + """ + returns a named tuple that contains the total, used, and free disk space + in bytes + """ + used = 0 + total = 0 + free = 0 + + if 'statvfs' in dir(os): + disk_stats = os.statvfs(path) + free = disk_stats.f_bavail * disk_stats.f_frsize + total = disk_stats.f_blocks * disk_stats.f_frsize + used = (disk_stats.f_blocks - disk_stats.f_bfree) * disk_stats.f_frsize + else: + raise NotImplementedError("{0} is not a supported platform for this alert".format(platform.platform())) + + DiskInfo = collections.namedtuple('DiskInfo', 'total used free') + return DiskInfo(total=total, used=used, free=free) http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/OOZIE/alerts.json ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/OOZIE/alerts.json b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/OOZIE/alerts.json new file mode 100644 index 0000000..a8e63e8 --- /dev/null +++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/OOZIE/alerts.json @@ -0,0 +1,40 @@ +{ + "OOZIE": { + "service": [], + "OOZIE_SERVER": [ + { + "name": "oozie_server_webui", + "label": "Oozie Server Web UI", + "interval": 1, + "scope": "ANY", + "source": { + "type": "WEB", + "uri": { + "http": "{{oozie-site/oozie.base.url}}/oozie" + }, + "reporting": { + "ok": { + "text": "HTTP {0} response in {2:.4f} seconds" + }, + "warning":{ + "text": "HTTP {0} response in {2:.4f} seconds" + }, + "critical": { + "text": "Connection failed to {1}" + } + } + } + }, + { + "name": "oozie_server_status", + "label": "Oozie Server Status", + "interval": 1, + "scope": "ANY", + "source": { + "type": "SCRIPT", + "path": "HDP/1.3.2/services/OOZIE/package/files/alert_check_oozie_server.py" + } + } + ] + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/OOZIE/package/files/alert_check_oozie_server.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/OOZIE/package/files/alert_check_oozie_server.py b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/OOZIE/package/files/alert_check_oozie_server.py new file mode 100644 index 0000000..7bf1255 --- /dev/null +++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/OOZIE/package/files/alert_check_oozie_server.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +""" +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import subprocess +from subprocess import CalledProcessError + +RESULT_CODE_OK = 'OK' +RESULT_CODE_CRITICAL = 'CRITICAL' +RESULT_CODE_UNKNOWN = 'UNKNOWN' + +OOZIE_URL_KEY = '{{oozie-site/oozie.base.url}}' + +def get_tokens(): + """ + Returns a tuple of tokens in the format {{site/property}} that will be used + to build the dictionary passed into execute + """ + return (OOZIE_URL_KEY) + + +def execute(parameters=None, host_name=None): + """ + Returns a tuple containing the result code and a pre-formatted result label + + Keyword arguments: + parameters (dictionary): a mapping of parameter key to value + host_name (string): the name of this host where the alert is running + """ + + if parameters is None: + return (RESULT_CODE_UNKNOWN, ['There were no parameters supplied to the script.']) + + oozie_url = None + if OOZIE_URL_KEY in parameters: + oozie_url = parameters[OOZIE_URL_KEY] + + if oozie_url is None: + return (RESULT_CODE_UNKNOWN, ['The Oozie URL is a required parameter.']) + + try: + # oozie admin -oozie http://server:11000/oozie -status + oozie_process = subprocess.Popen(['oozie', 'admin', '-oozie', + oozie_url, '-status'], stderr=subprocess.PIPE, stdout=subprocess.PIPE) + + oozie_output, oozie_error = oozie_process.communicate() + oozie_return_code = oozie_process.returncode + + if oozie_return_code == 0: + # strip trailing newlines + oozie_output = str(oozie_output).strip('\n') + return (RESULT_CODE_OK, [oozie_output]) + else: + oozie_error = str(oozie_error).strip('\n') + return (RESULT_CODE_CRITICAL, [oozie_error]) + + except CalledProcessError, cpe: + return (RESULT_CODE_CRITICAL, [str(cpe)]) http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/ZOOKEEPER/alerts.json ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/ZOOKEEPER/alerts.json b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/ZOOKEEPER/alerts.json new file mode 100644 index 0000000..be210ea --- /dev/null +++ b/ambari-server/src/main/resources/stacks/HDP/1.3.2/services/ZOOKEEPER/alerts.json @@ -0,0 +1,51 @@ +{ + "ZOOKEEPER": { + "service": [ + { + "name": "zookeeper_server_process_percent", + "label": "Percent ZooKeeper Servers Available", + "interval": 1, + "scope": "SERVICE", + "enabled": true, + "source": { + "type": "AGGREGATE", + "alert_name": "zookeeper_server_process", + "reporting": { + "ok": { + "text": "affected: [{1}], total: [{0}]" + }, + "warning": { + "text": "affected: [{1}], total: [{0}]", + "value": 0.35 + }, + "critical": { + "text": "affected: [{1}], total: [{0}]", + "value": 0.70 + } + } + } + } + ], + "ZOOKEEPER_SERVER": [ + { + "name": "zookeeper_server_process", + "label": "ZooKeeper Server Process", + "interval": 1, + "scope": "ANY", + "source": { + "type": "PORT", + "uri": "{{zookeeper-env/clientPort}}", + "default_port": 2181, + "reporting": { + "ok": { + "text": "TCP OK - {0:.4f} response on port {1}" + }, + "critical": { + "text": "Connection failed: {0} to {1}:{2}" + } + } + } + } + ] + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/fb016d5c/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java index 282dfcc..ce623ed 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java @@ -106,9 +106,15 @@ public class AlertTargetResourceProviderTest { assertEquals(1, results.size()); - Resource r = results.iterator().next(); + Resource resource = results.iterator().next(); Assert.assertEquals(ALERT_TARGET_NAME, - r.getPropertyValue(AlertTargetResourceProvider.ALERT_TARGET_NAME)); + resource.getPropertyValue(AlertTargetResourceProvider.ALERT_TARGET_NAME)); + + // ensure that properties is null if not requested + Map<String, String> properties = (Map<String, String>) resource.getPropertyValue( + AlertTargetResourceProvider.ALERT_TARGET_PROPERTIES); + + Assert.assertNull(properties); verify(m_dao); } @@ -130,24 +136,38 @@ public class AlertTargetResourceProviderTest { ALERT_TARGET_ID.toString()).toPredicate(); expect(m_dao.findTargetById(ALERT_TARGET_ID.longValue())).andReturn( - getMockEntities().get(0)); + getMockEntities().get(0)).atLeastOnce(); replay(m_amc, m_dao); AlertTargetResourceProvider provider = createProvider(m_amc); Set<Resource> results = provider.getResources(request, predicate); - assertEquals(1, results.size()); + Resource resource = results.iterator().next(); - Resource r = results.iterator().next(); Assert.assertEquals(ALERT_TARGET_ID, - r.getPropertyValue(AlertTargetResourceProvider.ALERT_TARGET_ID)); + resource.getPropertyValue(AlertTargetResourceProvider.ALERT_TARGET_ID)); Assert.assertEquals(ALERT_TARGET_NAME, - r.getPropertyValue(AlertTargetResourceProvider.ALERT_TARGET_NAME)); + resource.getPropertyValue(AlertTargetResourceProvider.ALERT_TARGET_NAME)); + + // properties were not requested, they should not be included + Map<String, String> properties = (Map<String, String>) resource.getPropertyValue( + AlertTargetResourceProvider.ALERT_TARGET_PROPERTIES); + + Assert.assertNull(properties); + + // ask for all fields + request = PropertyHelper.getReadRequest(); + results = provider.getResources(request, predicate); + assertEquals(1, results.size()); + resource = results.iterator().next(); + + // ensure properties is included + properties = (Map<String, String>) resource.getPropertyValue( + AlertTargetResourceProvider.ALERT_TARGET_PROPERTIES); - Map<String, String> properties = (Map<String, String>) r.getPropertyValue(AlertTargetResourceProvider.ALERT_TARGET_PROPERTIES); - assertEquals( "bar", properties.get("foo") ); + assertEquals("bar", properties.get("foo")); assertEquals( "baz", properties.get("foobar") ); verify(m_amc, m_dao);
