kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.faultmanagement.alarms.gui; |
| 17 | |
| 18 | import java.util.Map; |
| 19 | import org.onosproject.incubator.net.faultmanagement.alarm.Alarm; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | import org.onosproject.ui.UiTopoOverlay; |
| 22 | import org.onosproject.ui.topo.ButtonId; |
| 23 | import org.onosproject.ui.topo.PropertyPanel; |
| 24 | import org.onosproject.ui.topo.TopoConstants.CoreButtons; |
| 25 | import static org.onosproject.ui.topo.TopoConstants.Properties.*; |
| 26 | |
| 27 | /** |
| 28 | * Our topology overlay. |
| 29 | */ |
| 30 | public class AlarmTopovOverlay extends UiTopoOverlay { |
| 31 | |
| 32 | // NOTE: this must match the ID defined in alarmTopov.js |
| 33 | private static final String OVERLAY_ID = "alarmsTopo-overlay"; |
| 34 | |
| 35 | private static final ButtonId ALARM1_BUTTON = new ButtonId("alarm1button"); |
| 36 | private static final ButtonId ALARM2_BUTTON = new ButtonId("alarm2button"); |
| 37 | |
| 38 | public AlarmTopovOverlay() { |
| 39 | super(OVERLAY_ID); |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public void modifySummary(PropertyPanel pp) { |
| 44 | pp.title("Alarms Overview"); |
| 45 | // We could just remove some properties here but lets keep it uncluttered, unless |
| 46 | // there is feedback other properties are essential. |
| 47 | pp.removeAllProps(); |
| 48 | Map<Alarm.SeverityLevel, Long> countsForAll = AlarmServiceUtil.lookUpAlarmCounts(); |
| 49 | addAlarmCountsProperties(pp, countsForAll); |
| 50 | |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public void modifyDeviceDetails(PropertyPanel pp, DeviceId deviceId) { |
| 55 | pp.title("Alarm Details"); |
| 56 | pp.removeProps(LATITUDE, LONGITUDE, PORTS, FLOWS, TUNNELS, SERIAL_NUMBER, PROTOCOL); |
| 57 | |
| 58 | Map<Alarm.SeverityLevel, Long> countsForDevice = AlarmServiceUtil.lookUpAlarmCounts(deviceId); |
| 59 | addAlarmCountsProperties(pp, countsForDevice); |
| 60 | |
| 61 | pp.addButton(ALARM1_BUTTON) |
| 62 | .addButton(ALARM2_BUTTON); |
| 63 | |
| 64 | pp.removeButtons(CoreButtons.SHOW_PORT_VIEW) |
Jian Li | 79f6732 | 2016-01-06 18:22:37 -0800 | [diff] [blame] | 65 | .removeButtons(CoreButtons.SHOW_GROUP_VIEW) |
| 66 | .removeButtons(CoreButtons.SHOW_METER_VIEW); |
kmcpeake | b172d5f | 2015-12-10 11:30:43 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | private void addAlarmCountsProperties(PropertyPanel pp, Map<Alarm.SeverityLevel, Long> countsForDevice) { |
| 70 | |
| 71 | // TODO we could show these as color-coded squares with a count inside, to save space on the screen. |
| 72 | |
| 73 | long cr = countsForDevice.getOrDefault(Alarm.SeverityLevel.CRITICAL, 0L); |
| 74 | long ma = countsForDevice.getOrDefault(Alarm.SeverityLevel.MAJOR, 0L); |
| 75 | long mi = countsForDevice.getOrDefault(Alarm.SeverityLevel.MINOR, 0L); |
| 76 | long wa = countsForDevice.getOrDefault(Alarm.SeverityLevel.WARNING, 0L); |
| 77 | long in = countsForDevice.getOrDefault(Alarm.SeverityLevel.INDETERMINATE, 0L); |
| 78 | long cl = countsForDevice.getOrDefault(Alarm.SeverityLevel.CLEARED, 0L); |
| 79 | |
| 80 | // Unfortunately the PropertyPanel does not righ justify numbers even when using longs, |
| 81 | // but that not in scope of fault management work |
| 82 | pp.addProp("Critical", cr); |
| 83 | pp.addProp("Major", ma); |
| 84 | pp.addProp("Minor", mi); |
| 85 | pp.addProp("Warning", wa); |
| 86 | pp.addProp("Indeter.", in); |
| 87 | pp.addProp("Cleared", cl); |
| 88 | pp.addSeparator(); |
| 89 | pp.addProp("Total", cr + ma + mi + wa + in + cl); |
| 90 | |
| 91 | } |
| 92 | |
| 93 | } |