Browse Source

AMBARI-8055. Alerts UI: Create model and mapper for Alert-Notifications.(xiwang)

Xi Wang 10 năm trước cách đây
mục cha
commit
84da60f37d

+ 47 - 0
ambari-web/app/assets/data/alerts/alertNotifications.json

@@ -0,0 +1,47 @@
+{
+  "href" : "http://c6407.ambari.apache.org:8080/api/v1/alert_targets?fields=*",
+  "items" : [
+    {
+      "href" : "http://c6407.ambari.apache.org:8080/api/v1/alert_targets/1",
+      "AlertTarget" : {
+        "description" : "The Admins",
+        "id" : 1,
+        "name" : "Administrators",
+        "notification_type" : "EMAIL",
+        "properties" : {
+          "mail.smtp.from" : "ambari@repo.ambari.apache.org",
+          "ambari.dispatch.credential.username" : "ambari",
+          "mail.smtp.host" : "repo.ambari.apache.org",
+          "mail.smtp.port" : "25",
+          "mail.smtp.auth" : "true",
+          "ambari.dispatch.credential.password" : "password",
+          "ambari.dispatch.recipients" : [
+            "ambari@repo.ambari.apache.org"
+          ],
+          "mail.smtp.tarttls.enable" : "false"
+        }
+      }
+    },
+    {
+      "href" : "http://c6407.ambari.apache.org:8080/api/v1/alert_targets/2",
+      "AlertTarget" : {
+        "description" : "another user",
+        "id" : 2,
+        "name" : "user1",
+        "notification_type" : "EMAIL",
+        "properties" : {
+          "mail.smtp.from" : "ambari@repo.ambari.apache.org",
+          "ambari.dispatch.credential.username" : "ambari",
+          "mail.smtp.host" : "repo.ambari.apache.org",
+          "mail.smtp.port" : "25",
+          "mail.smtp.auth" : "true",
+          "ambari.dispatch.credential.password" : "password",
+          "ambari.dispatch.recipients" : [
+            "ambari@repo.ambari.apache.org"
+          ],
+          "mail.smtp.tarttls.enable" : "false"
+        }
+      }
+    }
+  ]
+}

+ 29 - 0
ambari-web/app/mappers/alert_notification_mapper.js

@@ -0,0 +1,29 @@
+/**
+  * 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.alertNotificationMapper = App.QuickDataMapper.create({
+  model : App.AlertNotification,
+  config : {
+    id: 'AlertTarget.id',
+    name: 'AlertTarget.name',
+    type: 'AlertTarget.notification_type',
+    description: 'AlertTarget.description',
+    properties: 'AlertTarget.properties'
+  }
+});

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

@@ -42,6 +42,7 @@ require('models/service/flume');
 require('models/service/storm');
 require('models/alert');
 require('models/alert_instance');
+require('models/alert_notification');
 require('models/user');
 require('models/host');
 require('models/rack');

+ 12 - 6
ambari-web/app/models/alert_instance.js

@@ -31,7 +31,8 @@ App.AlertInstance = DS.Model.extend({
   maintenanceState: DS.attr('string'),
   instance: DS.attr('string'),
   state: DS.attr('string'),
-  text: DS.attr('string')
+  text: DS.attr('string'),
+  notification: DS.hasMany('App.AlertNotification')
 });
 
 App.AlertInstance.FIXTURES = [
@@ -50,7 +51,8 @@ App.AlertInstance.FIXTURES = [
     "service_name": "HDFS",
     "state": "CRITICAL",
     "text": "Connection failed: [Errno 111] Connection refused on host tr-2.c.pramod-thangali.internal:50090",
-    "alert_definition": 1
+    "alert_definition": 1,
+    "notification": 1
   },
   {
     "cluster_name" : "tdk",
@@ -67,7 +69,8 @@ App.AlertInstance.FIXTURES = [
     "service_name" : "HDFS",
     "state" : "CRITICAL",
     "text" : "Connection failed to 0.0.0.0:50075",
-    "alert_definition": 2
+    "alert_definition": 2,
+    "notification": 2
   },
   {
     "cluster_name": "tdk",
@@ -84,7 +87,8 @@ App.AlertInstance.FIXTURES = [
     "service_name": "ZOOKEEPER",
     "state": "CRITICAL",
     "text": "TCP OK - 0.0000 response on port 2181",
-    "alert_definition": 3
+    "alert_definition": 3,
+    "notification": 3
   },
   {
     "cluster_name": "tdk",
@@ -101,7 +105,8 @@ App.AlertInstance.FIXTURES = [
     "service_name": "ZOOKEEPER",
     "state": "OK",
     "text": "TCP OK - 0.0000 response on port 2181",
-    "alert_definition": 3
+    "alert_definition": 3,
+    "notification": 3
   },
   {
     "cluster_name": "tdk",
@@ -118,6 +123,7 @@ App.AlertInstance.FIXTURES = [
     "service_name": "ZOOKEEPER",
     "state": "OK",
     "text": "TCP OK - 0.0000 response on port 2181",
-    "alert_definition": 3
+    "alert_definition": 3,
+    "notification": 3
   }
 ];

+ 27 - 0
ambari-web/app/models/alert_notification.js

@@ -0,0 +1,27 @@
+/**
+ * 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.AlertNotification = DS.Model.extend({
+  id: DS.attr('number'),
+  name: DS.attr('string'),
+  type: DS.attr('string'),
+  description: DS.attr('string'),
+  properties: DS.attr('string')
+});

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

@@ -298,6 +298,10 @@ var urls = {
     'real': '/clusters/{clusterName}/hosts/{hostName}?fields=legacy_alerts',
     'mock': '/data/alerts/HDP2/host_alerts.json'
   },
+  'alerts.load_alert_notification': {
+    'real': '/alert_targets?fields=*',
+    'mock': 'data/alerts/alert_notifications.json'
+  },
   'background_operations.get_most_recent': {
     'real': '/clusters/{clusterName}/requests?to=end&page_size={operationsCount}&fields=Requests',
     'mock': '/data/background_operations/list_on_start.json',