CLIENT GUI Framework
[vnfsdk/refrepo.git] / openo-portal / portal-extsys / src / main / webapp / extsys / vim / js / client-cometd.js
1 /*\r
2  * Copyright 2016-2017 ZTE Corporation.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 /**\r
17  * Created by 10184303 on 15-11-17.\r
18  */\r
19 \r
20 $(function () {\r
21     var registerCometdMessage = function (url, callback) {\r
22         var cometd = new $.Cometd();\r
23         var cometdURL = location.protocol + "//" + location.host + "/api/nsocnotification/v1";\r
24         cometd.configure({\r
25             url: cometdURL,\r
26             logLevel: "debug"\r
27         });\r
28 \r
29         cometd.addListener("/meta/handshake", function (handshake) {\r
30             if (handshake.successful === true) {\r
31                 cometd.batch(function () {\r
32                     cometd.subscribe(url, function (message) {\r
33                         callback.call(this, message.data);\r
34                     });\r
35                 });\r
36             }\r
37         });\r
38         cometd.handshake();\r
39     }\r
40     registerCometdMessage("/VIMstatus", function (data) {\r
41         var alarmArray = JSON.parse(data.greeting);\r
42         console.log(data.greeting);\r
43         for (var i = 0; i < alarmArray.length; i++) {\r
44             vm.vimStatusTime = alarmArray[i].checkTime;\r
45             for (var n = 0; n < vm.vimInfo.length; n++) {\r
46                 if (alarmArray[i].id == vm.vimInfo[n].oid && alarmArray[i].hostStorageInfo == "") {\r
47                     vm.vimInfo[n].status = alarmArray[i].status;\r
48                     vm.vimInfo[n].errorInfo = alarmArray[i].alarmContent;\r
49                     break;\r
50                 }\r
51                 if (alarmArray[i].id == vm.vimInfo[n].oid && alarmArray[i].hostStorageInfo.length != "") {\r
52                     vm.vimInfo[n].status = "inactive";\r
53                     vm.vimInfo[n].errorInfo = alarmArray[i].hostStorageInfo;\r
54                     break;\r
55                 }\r
56 \r
57             }\r
58         }\r
59 \r
60         setTimeout('resUtil.tooltipVimStatus()', 5000);\r
61     });\r
62 });\r
63 \r