rebuild GUI structure(only changed modules' name)
[vnfsdk/refrepo.git] / extsys / src / main / webapp / extsys / vim / js / client-cometd.js
1 /*
2  * Copyright 2016-2017 ZTE Corporation.
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 /**
17  * Created by 10184303 on 15-11-17.
18  */
19
20 $(function () {
21     var registerCometdMessage = function (url, callback) {
22         var cometd = new $.Cometd();
23         var cometdURL = location.protocol + "//" + location.host + "/api/nsocnotification/v1";
24         cometd.configure({
25             url: cometdURL,
26             logLevel: "debug"
27         });
28
29         cometd.addListener("/meta/handshake", function (handshake) {
30             if (handshake.successful === true) {
31                 cometd.batch(function () {
32                     cometd.subscribe(url, function (message) {
33                         callback.call(this, message.data);
34                     });
35                 });
36             }
37         });
38         cometd.handshake();
39     }
40     registerCometdMessage("/VIMstatus", function (data) {
41         var alarmArray = JSON.parse(data.greeting);
42         console.log(data.greeting);
43         for (var i = 0; i < alarmArray.length; i++) {
44             vm.vimStatusTime = alarmArray[i].checkTime;
45             for (var n = 0; n < vm.vimInfo.length; n++) {
46                 if (alarmArray[i].id == vm.vimInfo[n].oid && alarmArray[i].hostStorageInfo == "") {
47                     vm.vimInfo[n].status = alarmArray[i].status;
48                     vm.vimInfo[n].errorInfo = alarmArray[i].alarmContent;
49                     break;
50                 }
51                 if (alarmArray[i].id == vm.vimInfo[n].oid && alarmArray[i].hostStorageInfo.length != "") {
52                     vm.vimInfo[n].status = "inactive";
53                     vm.vimInfo[n].errorInfo = alarmArray[i].hostStorageInfo;
54                     break;
55                 }
56
57             }
58         }
59
60         setTimeout('resUtil.tooltipVimStatus()', 5000);
61     });
62 });
63