[ONOS-3203] End-to-end demo of Fault Management via SNMP.

This adds SNMP device-discovery, and a Fault Management app which makes alarms available to users via REST/GUI/CLI interfaces.
There is still code cleanup that could be done, but aim of this commit is an end-to-end proof of concept.

To demonstrate :

1) /opt/onos/bin/onos-service
onos> app activate org.onosproject.snmp
onos> app activate org.onosproject.faultmanagement

2) SNMP devices are seeded via config file. The default seed file contains connection details for devices (SNMP agents) available via internet  e.g. demo.snmplabs.com
cp /opt/onos/apache-karaf-3.0.3/etc/samples/org.onosproject.provider.snmp.device.impl.SnmpDeviceProvider.cfg   /opt/onos/apache-karaf-3.0.3/etc/

3) ONOS will poll these SNMP devices and store their alarms.

4) You can now manipulate the alarms via REST  e.g. http://<onos>:8181/onos/v1/fm/alarms , via CLI  via various "alarm-*” commands or in UI with an Alarms Overlay.

More info at https://wiki.onosproject.org/display/ONOS/Fault+Management

15/Dec/15: Updated regarding review comments from Thomas Vachuska.
17/Dec/15: Updated coreService.registerApplication(name) as per https://gerrit.onosproject.org/#/c/6878/

Change-Id: I886f8511f178dc4600ab96e5ff10cc90329cabec
diff --git a/apps/faultmanagement/fmgui/src/main/resources/alarmTable/css.html b/apps/faultmanagement/fmgui/src/main/resources/alarmTable/css.html
new file mode 100644
index 0000000..436ca0e
--- /dev/null
+++ b/apps/faultmanagement/fmgui/src/main/resources/alarmTable/css.html
@@ -0,0 +1 @@
+<link rel="stylesheet" href="app/view/alarmTable/alarmTable.css">
\ No newline at end of file
diff --git a/apps/faultmanagement/fmgui/src/main/resources/alarmTable/js.html b/apps/faultmanagement/fmgui/src/main/resources/alarmTable/js.html
new file mode 100644
index 0000000..b7bdb61
--- /dev/null
+++ b/apps/faultmanagement/fmgui/src/main/resources/alarmTable/js.html
@@ -0,0 +1 @@
+<script src="app/view/alarmTable/alarmTable.js"></script>
\ No newline at end of file
diff --git a/apps/faultmanagement/fmgui/src/main/resources/alarmTopov/css.html b/apps/faultmanagement/fmgui/src/main/resources/alarmTopov/css.html
new file mode 100644
index 0000000..3294fbd
--- /dev/null
+++ b/apps/faultmanagement/fmgui/src/main/resources/alarmTopov/css.html
@@ -0,0 +1 @@
+<link rel="stylesheet" href="app/view/alarmTopov/alarmTopov.css">
diff --git a/apps/faultmanagement/fmgui/src/main/resources/alarmTopov/js.html b/apps/faultmanagement/fmgui/src/main/resources/alarmTopov/js.html
new file mode 100644
index 0000000..5ca23c2
--- /dev/null
+++ b/apps/faultmanagement/fmgui/src/main/resources/alarmTopov/js.html
@@ -0,0 +1,2 @@
+<script src="app/view/alarmTopov/alarmTopovDemo.js"></script>
+<script src="app/view/alarmTopov/alarmTopovOverlay.js"></script>
diff --git a/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTable/alarmTable.css b/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTable/alarmTable.css
new file mode 100644
index 0000000..47dfee4
--- /dev/null
+++ b/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTable/alarmTable.css
@@ -0,0 +1,35 @@
+/* css for alarm table view */
+
+#ov-alarm-table h2 {
+    display: inline-block;
+}
+
+/* Panel Styling */
+#ov-alarm-table-item-details-panel.floatpanel {
+    position: absolute;
+    top: 115px;
+}
+
+.light #ov-alarm-table-item-details-panel.floatpanel {
+    background-color: rgb(229, 234, 237);
+}
+.dark #ov-alarm-table-item-details-panel.floatpanel {
+    background-color: #3A4042;
+}
+
+#ov-alarm-table-item-details-panel h3 {
+    margin: 0;
+    font-size: large;
+}
+
+#ov-alarm-table-item-details-panel h4 {
+    margin: 0;
+}
+
+#ov-alarm-table-item-details-panel td {
+    padding: 5px;
+}
+#ov-alarm-table-item-details-panel td.label {
+    font-style: italic;
+    opacity: 0.8;
+}
diff --git a/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTable/alarmTable.html b/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTable/alarmTable.html
new file mode 100644
index 0000000..b9eacc3
--- /dev/null
+++ b/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTable/alarmTable.html
@@ -0,0 +1,54 @@
+<!-- partial HTML -->
+<div id="ov-alarm-table">
+    <div class="tabular-header">
+        <h2>Alarms  for {{devId || "all devices."}} ({{tableData.length}} total)</h2>
+        <div class="ctrl-btns">
+            <div class="refresh" ng-class="{active: autoRefresh}"
+                 icon icon-id="refresh" icon-size="36"
+                 tooltip tt-msg="autoRefreshTip"
+                 ng-click="toggleRefresh()"></div>
+        </div>
+    </div>
+
+    <div class="summary-list" onos-table-resize>
+
+        <div class="table-header" onos-sortable-header>
+            <table>
+                <tr>
+
+                    <td colId="id" sortable>Id </td>
+                    <td colId="alarmDeviceId" sortable>Device </td>
+                    <td colId="alarmDesc" sortable>Description </td>
+                    <td colId="alarmSource" sortable>Source </td>
+                    <td colId="alarmTimeRaised" sortable>Time Raised </td>
+                    <td colId="alarmSeverity" sortable>Severity </td>
+
+                </tr>
+            </table>
+        </div>
+
+        <div class="table-body">
+            <table>
+                <tr ng-if="!tableData.length" class="no-data">
+                    <td colspan="3">
+                        No Alarms found
+                    </td>
+                </tr>
+
+                <tr ng-repeat="item in tableData track by $index"
+                    ng-click="selectCallback($event, item)"
+                    ng-class="{selected: item.id === selId}">
+                    <td>{{item.id}}</td>
+                    <td>{{item.alarmDeviceId}}</td>
+                    <td>{{item.alarmDesc}}</td>
+                    <td>{{item.alarmSource}}</td>
+                    <td>{{item.alarmTimeRaised}}</td>
+                    <td>{{item.alarmSeverity}}</td>
+                </tr>
+            </table>
+        </div>
+
+    </div>
+
+    <ov-alarm-table-item-details-panel></ov-alarm-table-item-details-panel>
+</div>
diff --git a/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTable/alarmTable.js b/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTable/alarmTable.js
new file mode 100644
index 0000000..82ceeda
--- /dev/null
+++ b/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTable/alarmTable.js
@@ -0,0 +1,157 @@
+// js for alarm app table view
+(function () {
+    'use strict';
+
+    // injected refs
+    var $log, $scope, $loc, devId, fs, wss;
+
+    // constants
+    var detailsReq = 'alarmTableDetailsRequest',
+            detailsResp = 'alarmTableDetailsResponse',
+            pName = 'ov-alarm-table-item-details-panel',
+            propOrder = ['id', 'alarmDeviceId', 'alarmDesc', 'alarmSource', 'alarmTimeRaised', 'alarmTimeUpdated', 'alarmTimeCleared', 'alarmSeverity'],
+            friendlyProps = ['Alarm Id', 'Device Id', 'Description', 'Source', 'Time Raised', 'Time Updated', 'Time Cleared', 'Severity'];
+
+
+    function addProp(tbody, index, value) {
+        var tr = tbody.append('tr');
+
+        function addCell(cls, txt) {
+            tr.append('td').attr('class', cls).html(txt);
+        }
+        addCell('label', friendlyProps[index] + ' :');
+        addCell('value', value);
+    }
+
+    function populatePanel(panel) {
+        var title = panel.append('h3'),
+                tbody = panel.append('table').append('tbody');
+
+        title.text('Alarm Details');
+
+        propOrder.forEach(function (prop, i) {
+            addProp(tbody, i, $scope.panelDetails[prop]);
+        });
+
+        panel.append('hr');
+        panel.append('h4').text('Comments');
+        panel.append('p').text($scope.panelDetails.comment);
+    }
+
+    function respDetailsCb(data) {
+        $scope.panelDetails = data.details;
+        $scope.$apply();
+    }
+
+    angular.module('ovAlarmTable', [])
+            .controller('OvAlarmTableCtrl',
+                    ['$log', '$scope', '$location', 'TableBuilderService',
+                        'FnService', 'WebSocketService',
+                        function (_$log_, _$scope_, _$location_, tbs, _fs_, _wss_) {
+                            var params;
+
+                            $log = _$log_;
+                            $scope = _$scope_;
+                            $loc = _$location_;
+
+                            fs = _fs_;
+                            wss = _wss_;
+
+
+                            params = $loc.search();
+                            if (params.hasOwnProperty('devId')) {
+                                $scope.devId = params['devId'];
+                            }
+
+                            var handlers = {};
+                            $scope.panelDetails = {};
+
+                            // details response handler
+                            handlers[detailsResp] = respDetailsCb;
+                            wss.bindHandlers(handlers);
+
+                            // custom selection callback
+                            function selCb($event, row) {
+                                $log.debug("selCb row=" + JSON.stringify(row, null, 4) +
+                                        ", $event=" + JSON.stringify($event, null, 4));
+                                $log.debug('$scope.selId=', $scope.selId);
+                                if ($scope.selId) {
+                                    $log.debug('send');
+                                    wss.sendEvent(detailsReq, {id: row.id});
+                                } else {
+                                    $log.debug('hidePanel');
+                                    $scope.hidePanel();
+                                }
+                                $log.debug('Got a click on:', row);
+                            }
+
+                            // TableBuilderService creating a table for us
+                            tbs.buildTable({
+                                scope: $scope,
+                                tag: 'alarmTable',
+                                selCb: selCb,
+                                query: params
+                            });
+
+                            // cleanup
+                            $scope.$on('$destroy', function () {
+                                wss.unbindHandlers(handlers);
+                                $log.log('OvAlarmTableCtrl has been destroyed');
+                            });
+
+                            $log.log('OvAlarmTableCtrl has been created');
+                        }])
+
+            .directive('ovAlarmTableItemDetailsPanel', ['PanelService', 'KeyService',
+                function (ps, ks) {
+                    return {
+                        restrict: 'E',
+                        link: function (scope, element, attrs) {
+                            // insert details panel with PanelService
+                            // create the panel
+                            var panel = ps.createPanel(pName, {
+                                width: 400,
+                                margin: 20,
+                                hideMargin: 0
+                            });
+                            panel.hide();
+                            scope.hidePanel = function () {
+                                panel.hide();
+                            };
+
+                            function closePanel() {
+                                if (panel.isVisible()) {
+                                    $scope.selId = null;
+                                    panel.hide();
+                                    return true;
+                                }
+                                return false;
+                            }
+
+                            // create key bindings to handle panel
+                            ks.keyBindings({
+                                esc: [closePanel, 'Close the details panel'],
+                                _helpFormat: ['esc']
+                            });
+                            ks.gestureNotes([
+                                ['click', 'Select a row to show item details']
+                            ]);
+
+                            // update the panel's contents when the data is changed
+                            scope.$watch('panelDetails', function () {
+                                if (!fs.isEmptyObject(scope.panelDetails)) {
+                                    panel.empty();
+                                    populatePanel(panel);
+                                    panel.show();
+                                }
+                            });
+
+                            // cleanup on destroyed scope
+                            scope.$on('$destroy', function () {
+                                ks.unbindKeys();
+                                ps.destroyPanel(pName);
+                            });
+                        }
+                    };
+                }]);
+}());
diff --git a/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTopov/alarmTopov.css b/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTopov/alarmTopov.css
new file mode 100644
index 0000000..e657900
--- /dev/null
+++ b/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTopov/alarmTopov.css
@@ -0,0 +1,2 @@
+/* css for alarm app topology overlay  */
+
diff --git a/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTopov/alarmTopovDemo.js b/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTopov/alarmTopovDemo.js
new file mode 100644
index 0000000..8c4846e
--- /dev/null
+++ b/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTopov/alarmTopovDemo.js
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed 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.
+ */
+
+/*
+ Alarm Demo module. This contains the "business logic" for the topology
+ overlay that we are implementing.
+ */
+
+(function () {
+    'use strict';
+
+    // injected refs
+    var $log, fs, flash, wss;
+
+    // constants
+    var displayStart = 'alarmTopovDisplayStart',
+        displayUpdate = 'alarmTopovDisplayUpdate',
+        displayStop = 'alarmTopovDisplayStop';
+
+    // internal state
+    var currentMode = null;
+
+
+    // === ---------------------------
+    // === Helper functions
+
+    function sendDisplayStart(mode) {
+        wss.sendEvent(displayStart, {
+            mode: mode
+        });
+    }
+
+    function sendDisplayUpdate(what) {
+        wss.sendEvent(displayUpdate, {
+            id: what ? what.id : ''
+        });
+    }
+
+    function sendDisplayStop() {
+        wss.sendEvent(displayStop);
+    }
+
+    // === ---------------------------
+    // === Main API functions
+
+    function startDisplay(mode) {
+        if (currentMode === mode) {
+            $log.debug('(in mode', mode, 'already)');
+        } else {
+            currentMode = mode;
+            sendDisplayStart(mode);
+            flash.flash('Starting display mode: ' + mode);
+        }
+    }
+
+    function updateDisplay(m) {
+        if (currentMode) {
+            sendDisplayUpdate(m);
+        }
+    }
+
+    function stopDisplay() {
+        if (currentMode) {
+            currentMode = null;
+            sendDisplayStop();
+            flash.flash('Canceling display mode');
+            return true;
+        }
+        return false;
+    }
+
+    // === ---------------------------
+    // === Module Factory Definition
+
+    angular.module('ovAlarmTopov', [])
+        .factory('AlarmTopovDemoService',
+        ['$log', 'FnService', 'FlashService', 'WebSocketService',
+
+        function (_$log_, _fs_, _flash_, _wss_) {
+            $log = _$log_;
+            fs = _fs_;
+            flash = _flash_;
+            wss = _wss_;
+
+            return {
+                startDisplay: startDisplay,
+                updateDisplay: updateDisplay,
+                stopDisplay: stopDisplay
+            };
+        }]);
+}());
diff --git a/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTopov/alarmTopovOverlay.js b/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTopov/alarmTopovOverlay.js
new file mode 100644
index 0000000..37ebda3
--- /dev/null
+++ b/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTopov/alarmTopovOverlay.js
@@ -0,0 +1,136 @@
+// alarm topology overlay - client side
+//
+// This is the glue that binds our business logic (in alarmTopovDemo.js)
+// to the overlay framework.
+
+(function () {
+    'use strict';
+
+    // injected refs
+    var $log, tov, stds, ns;
+
+    // internal state should be kept in the service module (not here)
+
+    // our overlay definition
+    var overlay = {
+        // NOTE: this must match the ID defined in AppUiTopovOverlay
+        overlayId: 'alarmsTopo-overlay',
+        glyphId: '*star4',
+        tooltip: 'Alarms Overlay',
+        // These glyphs get installed using the overlayId as a prefix.
+        // e.g. 'star4' is installed as 'alarmsTopo-overlay-star4'
+        // They can be referenced (from this overlay) as '*star4'
+        // That is, the '*' prefix stands in for 'alarmsTopo-overlay-'
+        glyphs: {
+            star4: {
+                vb: '0 0 8 8',
+                // TODO new icon needed
+                d: 'M1,4l2,-1l1,-2l1,2l2,1l-2,1l-1,2l-1,-2z'
+            },
+            banner: {
+                vb: '0 0 6 6',
+                // TODO new icon needed
+                d: 'M1,1v4l2,-2l2,2v-4z'
+            }
+        },
+        activate: function () {
+            $log.debug("Alarm topology overlay ACTIVATED");
+        },
+        deactivate: function () {
+            stds.stopDisplay();
+            $log.debug("Alarm topology overlay DEACTIVATED");
+        },
+        // detail panel button definitions
+        buttons: {
+            alarm1button: {
+                gid: 'chain',
+                tt: 'Show alarms for this device',
+                cb: function (data) {
+                    $log.debug('Show alarms for selected device. data:', data);
+                    ns.navTo("alarmTable", {devId: data.id});
+
+                }
+            },
+            alarm2button: {
+                gid: '*banner',
+                tt: 'Show alarms for all devices',
+                cb: function (data) {
+                    $log.debug('Show alarms for all devices. data:', data);
+                    ns.navTo("alarmTable");
+
+                }
+            }
+        },
+        // Key bindings for traffic overlay buttons
+        // NOTE: fully qual. button ID is derived from overlay-id and key-name
+        keyBindings: {
+            0: {
+                cb: function () {
+                    stds.stopDisplay();
+                },
+                tt: 'Cancel Alarm Count on Device',
+                gid: 'xMark'
+            },
+            V: {
+                cb: function () {
+                    stds.startDisplay('mouse');
+                },
+                tt: 'Start Alarm Count on Device',
+                gid: '*banner'
+            },
+            _keyOrder: [
+                '0', 'V'
+            ]
+        },
+        hooks: {
+            // hook for handling escape key
+            // Must return true to consume ESC, false otherwise.
+            escape: function () {
+                // Must return true to consume ESC, false otherwise.
+                return stds.stopDisplay();
+            },
+            // hooks for when the selection changes...
+            empty: function () {
+                selectionCallback('empty');
+            },
+            single: function (data) {
+                selectionCallback('single', data);
+            },
+            multi: function (selectOrder) {
+                selectionCallback('multi', selectOrder);
+                tov.addDetailButton('alarm1button');
+                tov.addDetailButton('alarm2button');
+            },
+            mouseover: function (m) {
+                // m has id, class, and type properties
+                $log.debug('mouseover:', m);
+                stds.updateDisplay(m);
+            },
+            mouseout: function () {
+                $log.debug('mouseout');
+                stds.updateDisplay();
+            }
+        }
+    };
+
+
+    function buttonCallback(x) {
+        $log.debug('Toolbar-button callback', x);
+    }
+
+    function selectionCallback(x, d) {
+        $log.debug('Selection callback', x, d);
+    }
+
+    // invoke code to register with the overlay service
+    angular.module('ovAlarmTopov')
+            .run(['$log', 'TopoOverlayService', 'AlarmTopovDemoService', 'NavService',
+                function (_$log_, _tov_, _stds_, _ns_) {
+                    $log = _$log_;
+                    tov = _tov_;
+                    stds = _stds_;
+                    ns = _ns_;
+                    tov.register(overlay);
+                }]);
+
+}());
diff --git a/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTopov/sampleTopov.html b/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTopov/sampleTopov.html
new file mode 100644
index 0000000..e51c1e0
--- /dev/null
+++ b/apps/faultmanagement/fmgui/src/main/resources/app/view/alarmTopov/sampleTopov.html
@@ -0,0 +1,4 @@
+<!-- partial HTML -->
+<div id="ov-alarm-topov">
+    <p>This is a hidden view .. just a placeholder to house the javascript</p>
+</div>
diff --git a/apps/faultmanagement/fmgui/src/main/resources/css.html b/apps/faultmanagement/fmgui/src/main/resources/css.html
new file mode 100644
index 0000000..860f655
--- /dev/null
+++ b/apps/faultmanagement/fmgui/src/main/resources/css.html
@@ -0,0 +1 @@
+<link rel="stylesheet" href="app/view/alarmCustom/alarmCustom.css">
\ No newline at end of file
diff --git a/apps/faultmanagement/fmgui/src/main/resources/js.html b/apps/faultmanagement/fmgui/src/main/resources/js.html
new file mode 100644
index 0000000..d07cd63
--- /dev/null
+++ b/apps/faultmanagement/fmgui/src/main/resources/js.html
@@ -0,0 +1 @@
+<script src="app/view/alarmCustom/alarmCustom.js"></script>
\ No newline at end of file