Assign image keyname and pubkey at vnf level
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / ux / mwtnEvents / mwtnEvents-module / src / main / resources / mwtnEvents / mwtnEvents.controller.js
1 /*
2  * Copyright (c) 2016 Tech Mahindra Ltd. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 define(
10     [ 'app/mwtnEvents/mwtnEvents.module', 'app/mwtnEvents/mwtnEvents.services', 'app/mwtnCommons/mwtnCommons.services'],
11     function(mwtnEventsApp) {
12
13       mwtnEventsApp.register
14           .controller(
15               'mwtnEventsCtrl',
16               [
17                   '$scope',
18                   '$rootScope',
19                   '$mwtnEvents',
20                   'uiGridConstants',
21                   function($scope, $rootScope, $mwtnEvents, uiGridConstants) {
22
23                     $rootScope.section_logo = 'src/app/mwtnEvents/images/mwtnEvents.png';
24
25                     $scope.status = {alarms:true};
26                     $scope.oneATime = true;
27                     
28                     $scope.gridOptionsAlarms = JSON.parse(JSON.stringify($mwtnEvents.gridOptions));
29                     $scope.gridOptionsAlarms.columnDefs = [
30                       // { field: 'id', type: 'number', displayName: 'No.',  headerCellClass: $scope.highlightFilteredHeader, width : 50, cellClass: 'number', pinnedLeft : true },
31                       // { field: 'icon',  type: 'string', displayName: '',  headerCellClass: $scope.highlightFilteredHeader, width: 25, enableSorting: false, enableFiltering:false, cellTemplate: iconCell },
32                       { field: 'timeStamp',  type: 'string', displayName: 'Timestamp',  headerCellClass: $scope.highlightFilteredHeader, width : 200,sort: {
33                         direction: uiGridConstants.DESC,
34                         priority: 1
35                       } },
36                       { field: 'counter',  type: 'number', displayName: 'Counter',  headerCellClass: $scope.highlightFilteredHeader, width: 90 },
37                       { field: 'nodeName',  type: 'string', displayName: 'NetworkElement',  headerCellClass: $scope.highlightFilteredHeader, width: 170 },
38                       { field: 'objectId',  type: 'string', displayName: 'Object',  headerCellClass: $scope.highlightFilteredHeader, width: 400 },
39
40                       { field: 'problem',  type: 'string', displayName: 'Alarm',  headerCellClass: $scope.highlightFilteredHeader, width : 140 },
41                       { field: 'severity',  type: 'string', displayName: 'Severity',  headerCellClass: $scope.highlightFilteredHeader, width : 100 }
42                     ];
43
44                     $scope.gridOptionsAVC = JSON.parse(JSON.stringify($mwtnEvents.gridOptions));
45                     $scope.gridOptionsAVC.columnDefs = [
46                       // { field: 'id', type: 'number', displayName: 'No.',  headerCellClass: $scope.highlightFilteredHeader, width : 50, cellClass: 'number', pinnedLeft : true },
47                       // { field: 'icon',  type: 'string', displayName: '',  headerCellClass: $scope.highlightFilteredHeader, width: 25, enableSorting: false, enableFiltering:false, cellTemplate: iconCell },
48                       { field: 'timeStamp',  type: 'string', displayName: 'Timestamp',  headerCellClass: $scope.highlightFilteredHeader, width : 200,sort: {
49                         direction: uiGridConstants.DESC,
50                         priority: 1
51                       } },
52                       { field: 'counter',  type: 'number', displayName: 'Counter',  headerCellClass: $scope.highlightFilteredHeader, width: 90 },
53                       { field: 'nodeName',  type: 'string', displayName: 'NetworkElement',  headerCellClass: $scope.highlightFilteredHeader, width: 170 },
54                       { field: 'objectId',  type: 'string', displayName: 'Object',  headerCellClass: $scope.highlightFilteredHeader, width: 400 },
55                       { field: 'attributeName',  type: 'string', displayName: 'Attribute',  headerCellClass: $scope.highlightFilteredHeader, width : 140 },
56                       { field: 'newValue',  type: 'string', displayName: 'New value',  headerCellClass: $scope.highlightFilteredHeader, width : 140 }
57                     ];
58
59                     $scope.gridOptionsObject = JSON.parse(JSON.stringify($mwtnEvents.gridOptions));
60                     $scope.gridOptionsObject.columnDefs = [
61                       // { field: 'id', type: 'number', displayName: 'No.',  headerCellClass: $scope.highlightFilteredHeader, width : 50, cellClass: 'number', pinnedLeft : true },
62                       // { field: 'icon',  type: 'string', displayName: '',  headerCellClass: $scope.highlightFilteredHeader, width: 25, enableSorting: false, enableFiltering:false, cellTemplate: iconCell },
63                       { field: 'timeStamp',  type: 'string', displayName: 'Timestamp',  headerCellClass: $scope.highlightFilteredHeader, width : 200,sort: {
64                         direction: uiGridConstants.DESC,
65                         priority: 1
66                       } },
67                       { field: 'counter',  type: 'number', displayName: 'Counter',  headerCellClass: $scope.highlightFilteredHeader, width: 90 },
68                       { field: 'nodeName',  type: 'string', displayName: 'NetworkElement',  headerCellClass: $scope.highlightFilteredHeader, width: 170 },
69                       { field: 'objectId',  type: 'string', displayName: 'Object',  headerCellClass: $scope.highlightFilteredHeader, width: 400 },
70                       { field: 'objectType',  type: 'string', displayName: 'Type',  headerCellClass: $scope.highlightFilteredHeader, width: 400 },
71                       { field: 'action',  type: 'string', displayName: 'Action',  headerCellClass: $scope.highlightFilteredHeader, width: 100 }
72                       
73                     ];
74
75                     var listenToNotifications = function() {
76                       $mwtnEvents.getMwtnWebSocketUrl().then(function(success){
77                         
78                         try {
79                           var notificationSocket = new WebSocket(success);
80
81                           notificationSocket.onmessage = function(event) {
82                             // we process our received event here
83                             if (typeof event.data === 'string') {
84                               // console.log("Client Received:\n" + event.data);
85                               // console.log("---------------------------");
86                               $mwtnEvents.formatData(event).then(function(formated) {
87                                 switch (formated.notifType) {
88                                 case 'ProblemNotification':
89                                   $scope.gridOptionsAlarms.data.push(formated);
90                                   break;
91                                 case 'AttributeValueChangedNotification':
92                                   $scope.gridOptionsAVC.data.push(formated);
93                                   break;                                
94                                 case 'ObjectCreationNotification':
95                                   formated.action = 'created';
96                                   if (formated.nodeName.contains('SDN-Controller')) {
97                                     formated.objectType = 'NETCONF session';
98                                   }
99                                   $scope.gridOptionsObject.data.push(formated);
100                                   break;
101                                 case 'ObjectDeletionNotification':
102                                   formated.action = 'deleted';
103                                   if (formated.nodeName.contains('SDN-Controller')) {
104                                     formated.objectType = 'NETCONF session';
105                                   }
106                                   $scope.gridOptionsObject.data.push(formated);
107                                   break;
108                                 default:
109                                   console.error('Missing implementation for', formated.notifType);
110                                 }
111                               }, function(error) {
112                                 // do nothing
113                               });
114                             }
115                           };
116
117                           notificationSocket.onerror = function(error) {
118                             console.log("Socket error: " + error);
119                           };
120
121                           notificationSocket.onopen = function(event) {
122                             console.log("Socket connection opened.");
123                             console.log("---------------------------");
124
125                             function subscribe() {
126                               if (notificationSocket.readyState === notificationSocket.OPEN) {
127                                 var data = {
128                                   'data' : 'scopes',
129                                   'scopes' : [ "ObjectCreationNotification",
130                                       "ObjectDeletionNotification",
131                                       "AttributeValueChangedNotification",
132                                       "ProblemNotification" ]
133                                 };
134                                 notificationSocket.send(JSON.stringify(data));
135                               }
136                             }
137                             subscribe();
138                           };
139
140                           notificationSocket.onclose = function(event) {
141                             console.log("Socket connection closed.");
142                           };
143                         } catch (e) {
144                           console.error("Error when creating WebSocket.\n" + e);
145                         }
146                       }, function(error){
147                         console.error("Error when creating WebSocket.\n" + error);
148                       });
149                     };
150                     listenToNotifications();
151                   } ]);
152
153     });