Browse Source

AMBARI-8286. Alert UI: Create mappers for Alert-Instances (onechiporenko)

Oleg Nechiporenko 10 years ago
parent
commit
3a4f020de5

+ 328 - 0
ambari-web/app/assets/data/alerts/alert_instances.json

@@ -0,0 +1,328 @@
+{
+  "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts?fields=*",
+  "items" : [
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/18",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : "AMBARI_AGENT",
+        "host_name" : "c6401.ambari.apache.org",
+        "id" : 18,
+        "instance" : null,
+        "label" : "Ambari Agent Disk Usage",
+        "latest_timestamp" : 1415224354954,
+        "maintenance_state" : "OFF",
+        "name" : "ambari_agent_disk_usage",
+        "original_timestamp" : 1414695835400,
+        "scope" : "HOST",
+        "service_name" : "AMBARI",
+        "state" : "OK",
+        "text" : "Capacity Used: [1.26%, 6.6 GB], Capacity Total: [525.3 GB]"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/7",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : null,
+        "host_name" : null,
+        "id" : 7,
+        "instance" : null,
+        "label" : "Percent DataNodes Available",
+        "latest_timestamp" : 1415224362617,
+        "maintenance_state" : "OFF",
+        "name" : "datanode_process_percent",
+        "original_timestamp" : 1414695787466,
+        "scope" : "SERVICE",
+        "service_name" : "HDFS",
+        "state" : "CRITICAL",
+        "text" : "affected: [1], total: [1]"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/16",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : null,
+        "host_name" : null,
+        "id" : 16,
+        "instance" : null,
+        "label" : "Percent DataNodes With Available Space",
+        "latest_timestamp" : 1415224362623,
+        "maintenance_state" : "OFF",
+        "name" : "datanode_storage_percent",
+        "original_timestamp" : 1414695797661,
+        "scope" : "SERVICE",
+        "service_name" : "HDFS",
+        "state" : "UNKNOWN",
+        "text" : "There are alerts with status UNKNOWN."
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/5",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : "NAMENODE",
+        "host_name" : "c6401.ambari.apache.org",
+        "id" : 5,
+        "instance" : null,
+        "label" : "NameNode Web UI",
+        "latest_timestamp" : 1415224354965,
+        "maintenance_state" : "OFF",
+        "name" : "namenode_webui",
+        "original_timestamp" : 1414695756761,
+        "scope" : "ANY",
+        "service_name" : "HDFS",
+        "state" : "CRITICAL",
+        "text" : "Connection failed to c6401.ambari.apache.org:50070"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/6",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : "DATANODE",
+        "host_name" : "c6401.ambari.apache.org",
+        "id" : 6,
+        "instance" : null,
+        "label" : "DateNode Process",
+        "latest_timestamp" : 1415224354964,
+        "maintenance_state" : "OFF",
+        "name" : "datanode_process",
+        "original_timestamp" : 1414695756761,
+        "scope" : "HOST",
+        "service_name" : "HDFS",
+        "state" : "CRITICAL",
+        "text" : "Connection failed: [Errno 111] Connection refused on host 0.0.0.0:50010"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/8",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : "SECONDARY_NAMENODE",
+        "host_name" : "c6401.ambari.apache.org",
+        "id" : 8,
+        "instance" : null,
+        "label" : "Secondary NameNode Process",
+        "latest_timestamp" : 1415224354958,
+        "maintenance_state" : "OFF",
+        "name" : "secondary_namenode_process",
+        "original_timestamp" : 1414695756751,
+        "scope" : "ANY",
+        "service_name" : "HDFS",
+        "state" : "CRITICAL",
+        "text" : "Connection failed: [Errno 111] Connection refused on host c6401.ambari.apache.org:50090"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/9",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : "NAMENODE",
+        "host_name" : "c6401.ambari.apache.org",
+        "id" : 9,
+        "instance" : null,
+        "label" : "NameNode Process",
+        "latest_timestamp" : 1415224354966,
+        "maintenance_state" : "OFF",
+        "name" : "namenode_process",
+        "original_timestamp" : 1414695756764,
+        "scope" : "ANY",
+        "service_name" : "HDFS",
+        "state" : "CRITICAL",
+        "text" : "Connection failed: [Errno 111] Connection refused on host c6401.ambari.apache.org:50070"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/10",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : "DATANODE",
+        "host_name" : "c6401.ambari.apache.org",
+        "id" : 10,
+        "instance" : null,
+        "label" : "DataNode Web UI",
+        "latest_timestamp" : 1415224354959,
+        "maintenance_state" : "OFF",
+        "name" : "datanode_webui",
+        "original_timestamp" : 1414695756747,
+        "scope" : "HOST",
+        "service_name" : "HDFS",
+        "state" : "CRITICAL",
+        "text" : "Connection failed to 0.0.0.0:50075"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/11",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : "NAMENODE",
+        "host_name" : "c6401.ambari.apache.org",
+        "id" : 11,
+        "instance" : null,
+        "label" : "NameNode Directory Status",
+        "latest_timestamp" : 1415224354970,
+        "maintenance_state" : "OFF",
+        "name" : "namenode_directory_status",
+        "original_timestamp" : 1414695756773,
+        "scope" : "ANY",
+        "service_name" : "HDFS",
+        "state" : "UNKNOWN",
+        "text" : "<urlopen error [Errno 111] Connection refused>"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/12",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : "NAMENODE",
+        "host_name" : "c6401.ambari.apache.org",
+        "id" : 12,
+        "instance" : null,
+        "label" : "NameNode Blocks Health",
+        "latest_timestamp" : 1415224294971,
+        "maintenance_state" : "OFF",
+        "name" : "namenode_hdfs_blocks_health",
+        "original_timestamp" : 1414695696729,
+        "scope" : "ANY",
+        "service_name" : "HDFS",
+        "state" : "UNKNOWN",
+        "text" : "<urlopen error [Errno 111] Connection refused>"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/13",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : "NAMENODE",
+        "host_name" : "c6401.ambari.apache.org",
+        "id" : 13,
+        "instance" : null,
+        "label" : "HDFS Capacity Utilization",
+        "latest_timestamp" : 1415224294976,
+        "maintenance_state" : "OFF",
+        "name" : "namenode_hdfs_capacity_utilization",
+        "original_timestamp" : 1414695696730,
+        "scope" : "ANY",
+        "service_name" : "HDFS",
+        "state" : "UNKNOWN",
+        "text" : "<urlopen error [Errno 111] Connection refused>"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/14",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : "DATANODE",
+        "host_name" : "c6401.ambari.apache.org",
+        "id" : 14,
+        "instance" : null,
+        "label" : "DataNode Storage",
+        "latest_timestamp" : 1415224294954,
+        "maintenance_state" : "OFF",
+        "name" : "datanode_storage",
+        "original_timestamp" : 1414695696721,
+        "scope" : "HOST",
+        "service_name" : "HDFS",
+        "state" : "UNKNOWN",
+        "text" : "<urlopen error [Errno 111] Connection refused>"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/15",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : "NAMENODE",
+        "host_name" : "c6401.ambari.apache.org",
+        "id" : 15,
+        "instance" : null,
+        "label" : "NameNode RPC Latency",
+        "latest_timestamp" : 1415224294962,
+        "maintenance_state" : "OFF",
+        "name" : "namenode_rpc_latency",
+        "original_timestamp" : 1414695696724,
+        "scope" : "ANY",
+        "service_name" : "HDFS",
+        "state" : "UNKNOWN",
+        "text" : "<urlopen error [Errno 111] Connection refused>"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/17",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : "NAMENODE",
+        "host_name" : "c6401.ambari.apache.org",
+        "id" : 17,
+        "instance" : null,
+        "label" : "NameNode Host CPU Utilization",
+        "latest_timestamp" : 1415224234971,
+        "maintenance_state" : "OFF",
+        "name" : "namenode_cpu",
+        "original_timestamp" : 1414696204578,
+        "scope" : "ANY",
+        "service_name" : "HDFS",
+        "state" : "UNKNOWN",
+        "text" : "<urlopen error [Errno 111] Connection refused>"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/19",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : "NAMENODE",
+        "host_name" : "c6401.ambari.apache.org",
+        "id" : 19,
+        "instance" : null,
+        "label" : "NameNode Last Checkpoint",
+        "latest_timestamp" : 1415224354957,
+        "maintenance_state" : "OFF",
+        "name" : "namenode_last_checkpoint",
+        "original_timestamp" : 1414695835395,
+        "scope" : "ANY",
+        "service_name" : "HDFS",
+        "state" : "UNKNOWN",
+        "text" : "<urlopen error [Errno 111] Connection refused>"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/4",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : null,
+        "host_name" : null,
+        "id" : 4,
+        "instance" : null,
+        "label" : "Percent ZooKeeper Servers Available",
+        "latest_timestamp" : 1415224362631,
+        "maintenance_state" : "OFF",
+        "name" : "zookeeper_server_process_percent",
+        "original_timestamp" : 1414695797691,
+        "scope" : "SERVICE",
+        "service_name" : "ZOOKEEPER",
+        "state" : "CRITICAL",
+        "text" : "affected: [1], total: [1]"
+      }
+    },
+    {
+      "href" : "http://c6401.ambari.apache.org:8080/api/v1/clusters/c/alerts/3",
+      "Alert" : {
+        "cluster_name" : "c",
+        "component_name" : "ZOOKEEPER_SERVER",
+        "host_name" : "c6401.ambari.apache.org",
+        "id" : 3,
+        "instance" : null,
+        "label" : "ZooKeeper Server Process",
+        "latest_timestamp" : 1415224354950,
+        "maintenance_state" : "OFF",
+        "name" : "zookeeper_server_process",
+        "original_timestamp" : 1414695756734,
+        "scope" : "ANY",
+        "service_name" : "ZOOKEEPER",
+        "state" : "CRITICAL",
+        "text" : "Connection failed: [Errno 111] Connection refused on host c6401.ambari.apache.org:2181"
+      }
+    }
+  ]
+}

+ 1 - 0
ambari-web/app/config.js

@@ -36,6 +36,7 @@ App.bgOperationsUpdateInterval = 6000;
 App.componentsUpdateInterval = 6000;
 App.componentsUpdateInterval = 6000;
 App.contentUpdateInterval = 15000;
 App.contentUpdateInterval = 15000;
 App.alertDefinitionsUpdateInterval = 10000;
 App.alertDefinitionsUpdateInterval = 10000;
+App.alertInstancesUpdateInterval = 10000;
 App.maxRunsForAppBrowser = 500;
 App.maxRunsForAppBrowser = 500;
 App.pageReloadTime=3600000;
 App.pageReloadTime=3600000;
 App.singleNodeInstall = false;
 App.singleNodeInstall = false;

+ 1 - 0
ambari-web/app/controllers.js

@@ -71,6 +71,7 @@ require('controllers/main/alerts_controller');
 require('controllers/main/alert_definitions_controller');
 require('controllers/main/alert_definitions_controller');
 require('controllers/main/alerts/alert_definitions_actions_controller');
 require('controllers/main/alerts/alert_definitions_actions_controller');
 require('controllers/main/alerts/definition_details_controller');
 require('controllers/main/alerts/definition_details_controller');
+require('controllers/main/alerts/alert_instances_controller');
 require('controllers/main/service');
 require('controllers/main/service');
 require('controllers/main/service/item');
 require('controllers/main/service/item');
 require('controllers/main/service/info/summary');
 require('controllers/main/service/info/summary');

+ 115 - 0
ambari-web/app/controllers/main/alerts/alert_instances_controller.js

@@ -0,0 +1,115 @@
+/**
+ * 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.
+ */
+
+var App = require('app');
+
+App.MainAlertInstancesController = Em.Controller.extend({
+  name: 'mainAlertInstancesController',
+  isLoaded: false,
+  /**
+   * Causes automatic updates of content if set to true
+   */
+  isUpdating: false,
+  updateTimer: null,
+  updateInterval: App.alertInstancesUpdateInterval,
+  /**
+   * "HOST" or "ALERT_DEFINITION"
+   */
+  sourceType: null,
+  sourceName: null,
+
+  fetchAlertInstances: function () {
+    this.set('isLoaded', false);
+    switch (this.get('sourceType')) {
+      case 'HOST':
+        App.ajax.send({
+          name: 'alerts.instances.by_host',
+          sender: this,
+          data: {
+            clusterName: App.router.get('clusterName'),
+            hostName: this.get('sourceName')
+          },
+          success: 'getAlertInstancesSuccessCallback',
+          error: 'getAlertInstancesErrorCallback'
+        });
+        break;
+      case 'ALERT_DEFINITION':
+        App.ajax.send({
+          name: 'alerts.instances.by_definition',
+          sender: this,
+          data: {
+            clusterName: App.router.get('clusterName'),
+            definitionName: this.get('sourceName')
+          },
+          success: 'getAlertInstancesSuccessCallback',
+          error: 'getAlertInstancesErrorCallback'
+        });
+        break;
+      default:
+        App.ajax.send({
+          name: 'alerts.instances',
+          sender: this,
+          data: {
+            clusterName: App.router.get('clusterName')
+          },
+          success: 'getAlertInstancesSuccessCallback',
+          error: 'getAlertInstancesErrorCallback'
+        });
+        break;
+    }
+  },
+
+  loadAlertInstances: function () {
+    this.set('sourceType', null);
+    this.set('sourceName', null);
+    this.fetchAlertInstances();
+  },
+
+  loadAlertInstancesByHost: function (hostName) {
+    this.set('sourceType', 'HOST');
+    this.set('sourceName', hostName);
+    this.fetchAlertInstances();
+  },
+
+  loadAlertInstancesByAlertDefinition: function (definitionName) {
+    this.set('sourceType', 'ALERT_DEFINITION');
+    this.set('sourceName', definitionName);
+    this.fetchAlertInstances();
+  },
+
+  scheduleUpdate: function () {
+    var self = this;
+    if (this.get('isUpdating')) {
+      this.set('updateTimer', setTimeout(function () {
+        self.fetchAlertInstances();
+        self.scheduleUpdate();
+      }, this.get('updateInterval')));
+    } else {
+      clearTimeout(this.get('updateTimer'));
+    }
+  }.observes('isUpdating'),
+
+  getAlertInstancesSuccessCallback: function (json) {
+    App.alertInstanceMapper.map(json);
+    this.set('isLoaded', true);
+  },
+
+  getAlertInstancesErrorCallback: function () {
+    this.set('isLoaded', true);
+  }
+});

+ 1 - 0
ambari-web/app/mappers.js

@@ -35,3 +35,4 @@ require('mappers/component_config_mapper');
 require('mappers/components_state_mapper');
 require('mappers/components_state_mapper');
 require('mappers/service_config_version_mapper');
 require('mappers/service_config_version_mapper');
 require('mappers/alert_definitions_mapper');
 require('mappers/alert_definitions_mapper');
+require('mappers/alert_instances_mapper');

+ 1 - 1
ambari-web/app/mappers/alert_definitions_mapper.js

@@ -27,7 +27,7 @@ App.alertDefinitionsMapper = App.QuickDataMapper.create({
   metricsUriModel: App.AlertMetricsUriDefinition,
   metricsUriModel: App.AlertMetricsUriDefinition,
 
 
   config: {
   config: {
-    id: 'AlertDefinition.id',
+    id: 'AlertDefinition.name',
     name: 'AlertDefinition.name',
     name: 'AlertDefinition.name',
     label: 'AlertDefinition.label',
     label: 'AlertDefinition.label',
     service_id: 'AlertDefinition.service_name',
     service_id: 'AlertDefinition.service_name',

+ 37 - 0
ambari-web/app/mappers/alert_instances_mapper.js

@@ -0,0 +1,37 @@
+/**
+ * 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.
+ */
+
+var App = require('app');
+
+App.alertInstanceMapper = App.QuickDataMapper.create({
+  model : App.AlertInstance,
+  config : {
+    id: 'Alert.id',
+    label: 'Alert.label',
+    alert_definition_name: 'Alert.name',
+    service_id: 'Alert.service_name',
+    component_name: 'Alert.component_name',
+    host_id: 'Alert.host_name',
+    scope: 'Alert.scope',
+    original_timestamp: 'Alert.original_timestamp',
+    latest_timestamp: 'Alert.latest_timestamp',
+    maintenance_state: 'Alert.maintenance_state',
+    instance: 'Alert.instance',
+    state: 'Alert.state',
+    text: 'Alert.text'
+  }
+});

+ 4 - 3
ambari-web/app/models/alert_instance.js

@@ -22,10 +22,10 @@ var dateUtils = require('utils/date');
 App.AlertInstance = DS.Model.extend({
 App.AlertInstance = DS.Model.extend({
   id: DS.attr('number'),
   id: DS.attr('number'),
   label: DS.attr('string'),
   label: DS.attr('string'),
-  alertDefinition: DS.belongsTo('App.AlertDefinition'),
-  serviceName: DS.attr('string'),
+  alertDefinitionName: DS.attr('string'),
+  service: DS.belongsTo('App.Service'),
   componentName: DS.attr('string'),
   componentName: DS.attr('string'),
-  hostName: DS.attr('string'),
+  host: DS.belongsTo('App.Host'),
   scope: DS.attr('string'),
   scope: DS.attr('string'),
   originalTimestamp: DS.attr('number'),
   originalTimestamp: DS.attr('number'),
   latestTimestamp: DS.attr('number'),
   latestTimestamp: DS.attr('number'),
@@ -136,3 +136,4 @@ App.AlertInstance.FIXTURES = [
     "notification": 3
     "notification": 3
   }
   }
 ];
 ];
+App.AlertInstance.FIXTURES = [];

+ 12 - 0
ambari-web/app/utils/ajax/ajax.js

@@ -302,6 +302,18 @@ var urls = {
     'real': '/alert_targets?fields=*',
     'real': '/alert_targets?fields=*',
     'mock': 'data/alerts/alert_notifications.json'
     'mock': 'data/alerts/alert_notifications.json'
   },
   },
+  'alerts.instances': {
+    'real': '/clusters/{clusterName}/alerts?fields=*',
+    'mock': '/data/alerts/alert_instances.json'
+  },
+  'alerts.instances.by_definition': {
+    'real': '/clusters/{clusterName}/alerts?fields=*&Alert/name={definitionName}',
+    'mock': '/data/alerts/alert_instances.json'
+  },
+  'alerts.instances.by_host': {
+    'real': '/clusters/{clusterName}/alerts?fields=*&Alert/host_name={hostName}',
+    'mock': '/data/alerts/alert_instances.json'
+  },
   'background_operations.get_most_recent': {
   'background_operations.get_most_recent': {
     'real': '/clusters/{clusterName}/requests?to=end&page_size={operationsCount}&fields=Requests',
     'real': '/clusters/{clusterName}/requests?to=end&page_size={operationsCount}&fields=Requests',
     'mock': '/data/background_operations/list_on_start.json',
     'mock': '/data/background_operations/list_on_start.json',