1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
|
/*
* Copyright (C) 2015 ZTE, Inc. and others. All rights reserved. (ZTE)
*
* 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.
*/
var vm = avalon.define({
$id: "mockdataController",
$addHOSTtitleName:"增加HOST",
$addVNFtitleName:"增加VNF实例",
$addVDUtitleName:"增加VDU实例",
$addVNFCtitleName:"增加VNFC实例",
$addNStitleName:"编排NS实例",
$mockAlarmTooltip:"点我就能模拟5条告警,告警码随机选取,祝你好运!",
$mockAlarmRemark:"关于模拟告警说明:<br/>1.创建资源后才能模拟告警; <br/>2.创建资源后要等会儿告警模块才能查询到资源信息,所以创建后等6秒再模拟告警吧!",
alarmbtnvalue:"模拟告警",
alarmbtndisabled:true,
server_rtn:{
info_block:false,
warning_block:false,
info_text:"",
warning_text:""
},
HOSTInfo : {
oid:"",
name:"wangyg test host001",
moc:"nfv.host.linux",
ipAddress:"10.74.151.88",
vendor:"",
version:"",
type:"",
user:"test",
password:"123456",
protocol:"ssh",
port:"21",
vimId:"-1",
customPara:"",
alarmbtndisabled:true,
alarmbtnvalue:"模拟告警"
},
VNFInfo : {
oid:"",
name:"wangyg test vnf001",
moc:"nfv.vnf.bn.vbras",
ipAddress:"",
vendor:"",
version:"",
type:"",
vnfd:"vnfd-1",
autoScalePolicy:"",
localization:"zh",
monitoringParameter:"",
status:"active",
createTime:commonUtil.parseDate(new Date(),"yyyy-MM-dd hh:mm:ss"),
customPara:"",
flavourId:"flavour-No-001",
vnfmid:"-1",
vimId:"-1",
alarmbtndisabled:true,
alarmbtnvalue:"模拟告警"
},
VDUInfo : {
oid:"",
name:"wangyg test vdu001",
moc:"nfv.vdu.linux",
ipAddress:"10.74.75.8",
vendor:"",
version:"",
type:"",
vduImage:"ubuntu12.0",
parentOid:"",
vnfId:"-1",
createTime:commonUtil.parseDate(new Date(),"yyyy-MM-dd hh:mm:ss"),
customPara:"",
flavourId:"flavour-No-001",
vimId:"-1",
hostId:"-1",
alarmbtndisabled:true,
alarmbtnvalue:"模拟告警"
},
VNFCInfo : {
oid:"",
name:"wangyg test VNFC",
moc:"nfv.vnfc.bn.vbras.protocol",
ipAddress:"",
vendor:"",
version:"",
type:"",
vnfId:"-1",
vduId:"-1",
createTime:commonUtil.parseDate(new Date(),"yyyy-MM-dd hh:mm:ss"),
alarmbtndisabled:true,
alarmbtnvalue:"模拟告警"
},
NSInfo : {
oid:"",
name:"wangyg编排服务测试1",
moc:"nfv.ns.raisecom.nanocellgw",
vendor:"zte",
version:"ns1.0",
type:"CN",
nsd:"nsd1",
autoScalePolicy:"",
monitoringParameter:"",
flavour:"e2d65cc9",
status:"active",
customPara:"",
vnfIds:[],
alarmbtndisabled:true,
alarmbtnvalue:"模拟告警"
},
$operationResult:{
success:"SUCCESS",
fail:"FAIL"
},
$queryVimInfoUrl : '/api/roc/v1/resource/vims',
$queryHostInfoUrl : '/api/roc/v1/resource/hosts',
$queryVnfInfoUrl : '/api/roc/v1/resource/vnfs',
$queryVduInfoUrl : '/api/roc/v1/resource/vdus',
$queryVnfmInfoUrl : '/api/roc/v1/resource/vnfms',
$addVduInfoUrl: '/api/roc/v1/resource/vdus',
$addVnfcInfoUrl: '/api/roc/v1/resource/vnfcs',
$addVnfInfoUrl: '/api/roc/v1/resource/vnfs',
$addHostInfoUrl: '/api/roc/v1/resource/hosts',
$addNSInfoUrl: '/api/roc/v1/resource/nsrs',
$raiseAlarmUrl:'/api/umc/v1/monitor/alarm',
vimList:[],
hostList:[],
vnfList:[],
vduList:[],
vnfmList:[],
$raiseAlarm : function(oid,name) {
if(oid=='' || oid==undefined || oid==null){
vm.server_rtn.info_block=false;
vm.server_rtn.warning_block=true;
vm.server_rtn.warning_text="oid为空,无法发送告警!请先创建资源吧~";
return;
}
vm.server_rtn.info_text="模拟了如下资源的告警 资源ID:"+oid+" 名称:"+name;
$.ajax({
type: "POST",
url: vm.$raiseAlarmUrl,
data: oid,
contentType:"text/plain; charset=utf-8", //发送信息至服务器时内容编码类型
success: function (data) {
vm.server_rtn.warning_block=false;
vm.server_rtn.info_block=true;
vm.server_rtn.info_text=vm.server_rtn.info_text+"<br/>服务器返回信息:"+data;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
vm.server_rtn.info_block=false;
vm.server_rtn.warning_block=true;
vm.server_rtn.warning_text=+"服务器返回错误:"+textStatus+":"+errorThrown;
}
});
},
$addNS : function() {
if (vm.NSInfo.vnfIds.length==0) {
alert("请选择包含的VNF");
return false;
}
$.ajax({
type: "POST",
url: vm.$addNSInfoUrl,
contentType:"application/json",
data: JSON.stringify({
name:vm.NSInfo.name,
moc:vm.NSInfo.moc,
vendor:vm.NSInfo.vendor,
version:vm.NSInfo.version,
type:vm.NSInfo.type,
customPara:vm.NSInfo.customPara,
nsd:vm.NSInfo.nsd,
autoScalePolicy:vm.NSInfo.autoScalePolicy,
monitoringParameter:vm.NSInfo.monitoringParameter,
flavour:vm.NSInfo.flavour,
status:vm.NSInfo.status,
vnfIds:vm.NSInfo.vnfIds
}),
dataType: "json",
success: function (data) {
if (data.operationResult == vm.$operationResult.success) {
vm.server_rtn.warning_block=false;
vm.server_rtn.info_block=true;
vm.server_rtn.info_text="保存成功!新建NS的id为:"+data.oid;
updateAlarmBtnState(vm.NSInfo);
vm.NSInfo.oid=data.oid;
}
else{
vm.server_rtn.info_block=false;
vm.server_rtn.warning_block=true;
vm.server_rtn.warning_text="保存NS失败!接口返回错误信息:"+data.exception;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
vm.server_rtn.info_block=false;
vm.server_rtn.warning_block=true;
vm.server_rtn.warning_text=textStatus+":"+errorThrown;
}
});
},
$addHost : function() {
if (vm.HOSTInfo.vimId=="-1") {
alert("请选择所属VIM");
return false;
}
$.ajax({
type: "POST",
url: vm.$addHostInfoUrl,
contentType:"application/json",
data: JSON.stringify({
name:vm.HOSTInfo.name,
moc:vm.HOSTInfo.moc,
ipAddress:vm.HOSTInfo.ipAddress,
vendor:vm.HOSTInfo.vendor,
version:vm.HOSTInfo.version,
type:vm.HOSTInfo.type,
customPara:vm.HOSTInfo.customPara,
user:vm.HOSTInfo.user,
password:vm.HOSTInfo.password,
port:vm.HOSTInfo.port,
protocol:vm.HOSTInfo.protocol,
vimId:vm.HOSTInfo.vimId
}),
dataType: "json",
success: function (data) {
if (data.operationResult == vm.$operationResult.success) {
vm.server_rtn.warning_block=false;
vm.server_rtn.info_block=true;
vm.server_rtn.info_text="保存成功!新建Host的id为:"+data.oid;
updateAlarmBtnState(vm.HOSTInfo);
vm.HOSTInfo.oid=data.oid;
}
else{
vm.server_rtn.info_block=false;
vm.server_rtn.warning_block=true;
vm.server_rtn.warning_text="保存Host失败!接口返回错误信息:"+data.exception;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
vm.server_rtn.info_block=false;
vm.server_rtn.warning_block=true;
vm.server_rtn.warning_text=textStatus+":"+errorThrown;
}
});
},
$addVNF : function() {
if (vm.VNFInfo.vnfmid == "-1"||vm.VNFInfo.vimId=="-1") {
alert("请选择所属的VNFM和VIM");
return false;
}
$.ajax({
type: "POST",
url: vm.$addVnfInfoUrl,
contentType:"application/json",
data: JSON.stringify({
name:vm.VNFInfo.name,
moc:vm.VNFInfo.moc,
ipAddress:vm.VNFInfo.ipAddress,
vendor:vm.VNFInfo.vendor,
version:vm.VNFInfo.version,
type:vm.VNFInfo.type,
vnfd:vm.VNFInfo.vnfd,
autoScalePolicy:vm.VNFInfo.autoScalePolicy,
localization:vm.VNFInfo.localization,
monitoringParameter:vm.VNFInfo.monitoringParameter,
status:vm.VNFInfo.status,
customPara:vm.VNFInfo.customPara,
flavourId:vm.VNFInfo.flavourId,
vnfmid:vm.VNFInfo.vnfmid,
vimId:vm.VNFInfo.vimId,
createTime:vm.VNFInfo.createTime
}),
dataType: "json",
success: function (data) {
if (data.operationResult == vm.$operationResult.success) {
vm.server_rtn.warning_block=false;
vm.server_rtn.info_block=true;
vm.server_rtn.info_text="保存成功!新建VNF的id为:"+data.oid;
updateAlarmBtnState(vm.VNFInfo);
vm.VNFInfo.oid=data.oid;
}
else{
vm.server_rtn.info_block=false;
vm.server_rtn.warning_block=true;
vm.server_rtn.warning_text="保存VNF失败!接口返回错误信息:"+data.exception;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
vm.server_rtn.info_block=false;
vm.server_rtn.warning_block=true;
vm.server_rtn.warning_text=textStatus+":"+errorThrown;
}
});
},
$addVNFC : function() {
if (vm.VNFCInfo.vnfId == "-1" ||vm.VNFCInfo.vduId =="-1") {
alert("请选择所属的VNF和部署到的VDU");
return false;
}
$.ajax({
type: "POST",
url: vm.$addVnfcInfoUrl,
contentType:"application/json",
data: JSON.stringify({
name:vm.VNFCInfo.name,
moc:vm.VNFCInfo.moc,
ipAddress:vm.VNFCInfo.ipAddress,
vendor:vm.VNFCInfo.vendor,
version:vm.VNFCInfo.version,
type:vm.VNFCInfo.type,
vnfId:vm.VNFCInfo.vnfId,
vduId:vm.VNFCInfo.vduId,
createTime:vm.VNFCInfo.createTime
}),
dataType: "json",
success: function (data) {
if (data.operationResult == vm.$operationResult.success) {
vm.server_rtn.warning_block=false;
vm.server_rtn.info_block=true;
vm.server_rtn.info_text="保存成功!新建VNFC的id为:"+data.oid;
updateAlarmBtnState(vm.VNFCInfo);
vm.VNFCInfo.oid=data.oid;
}
else{
vm.server_rtn.info_block=false;
vm.server_rtn.warning_block=true;
vm.server_rtn.warning_text="保存VNFC失败!接口返回错误信息:"+data.exception;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
vm.server_rtn.info_block=false;
vm.server_rtn.warning_block=true;
vm.server_rtn.warning_text=textStatus+":"+errorThrown;
}
});
},
$addVDU : function() {
if (vm.VDUInfo.vnfId=="-1"||vm.VDUInfo.vimId=="-1"||vm.VDUInfo.hostId=="-1") {
alert("请选择vim、host和vnf信息");
return false;
}
$.ajax({
type: "POST",
url: vm.$addVduInfoUrl,
//contentType:"application/json;charset=utf-8", //发送信息至服务器时内容编码类型。
contentType:"application/json",
data: JSON.stringify({
name:vm.VDUInfo.name,
moc:vm.VDUInfo.moc,
ipAddress:vm.VDUInfo.ipAddress,
vendor:vm.VDUInfo.vendor,
version:vm.VDUInfo.version,
type:vm.VDUInfo.type,
vduImage:vm.VDUInfo.vduImage,
parentOid:vm.VDUInfo.parentOid,
vnfId:vm.VDUInfo.vnfId,
createTime:vm.VDUInfo.createTime,
customPara:vm.VDUInfo.customPara,
flavourId:vm.VDUInfo.flavourId,
vimId:vm.VDUInfo.vimId,
hostId:vm.VDUInfo.hostId
}),
dataType: "json",
success: function (data) {
if (data.operationResult == vm.$operationResult.success) {
vm.server_rtn.warning_block=false;
vm.server_rtn.info_block=true;
vm.server_rtn.info_text="保存成功!新建VDU的id为:"+data.oid;
updateAlarmBtnState(vm.VDUInfo);
vm.VDUInfo.oid=data.oid;
}
else{
vm.server_rtn.info_block=false;
vm.server_rtn.warning_block=true;
vm.server_rtn.warning_text="保存VDU失败!接口返回错误信息:"+data.exception;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
vm.server_rtn.info_block=false;
vm.server_rtn.warning_block=true;
vm.server_rtn.warning_text=textStatus+":"+errorThrown;
}
});
}
});
avalon.scan();
//公共方法,在点击了保存并保存成功后将模拟告警按钮置灰6秒钟
var updateAlarmBtnState=function(node){
var waitsecs = 6;
var i=1;
node.alarmbtndisabled=true;
node.alarmbtnvalue="喝杯茶,稍等"+ waitsecs +"秒";
var id = setInterval(function(){
if(i<waitsecs){
printnr = waitsecs-i;
node.alarmbtnvalue="喝杯茶,稍等"+ printnr +"秒";
i++;
}else{
node.alarmbtnvalue="模拟告警";
node.alarmbtndisabled=false;
window.clearInterval(id);
}
},1000);
}
//以下函数为点击导航菜单时组合刷新对应的下拉菜单
var updateSelectForAddHOST=function(){
updateVimList();
vm.server_rtn.warning_block=false;
vm.server_rtn.info_block=false;
}
var updateSelectForAddVNF=function(){
updateVimList();
updateVnfmList();
vm.server_rtn.warning_block=false;
vm.server_rtn.info_block=false;
}
var updateSelectForAddVDU=function(){
updateVimList();
updateVnfList();
updateHostList();
vm.server_rtn.warning_block=false;
vm.server_rtn.info_block=false;
}
var updateSelectForAddVNFC=function(){
updateVnfList();
updateVduList();
vm.server_rtn.warning_block=false;
vm.server_rtn.info_block=false;
}
var updateSelectForAddNS=function(){
updateVnfList();
vm.server_rtn.warning_block=false;
vm.server_rtn.info_block=false;
}
//以下函数为刷新下拉菜单对应的实现类
var updateVnfList=function(){
//ajax查询vnf列表
$.ajax({
"type": 'get',
"url": vm.$queryVnfInfoUrl,
"dataType": "json",
"success": function (resp) {
if(resp.operationResult==vm.$operationResult.success)
{
vm.vnfList = (resp==null)?[]:resp.data;
}
else{
alert("查询vnf列表失败");
vm.vnfList=[];
return;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("查询vnf列表失败:"+textStatus+":"+errorThrown);
return;
}
});
}
var updateVimList=function(){
//ajax查询vim列表
$.ajax({
"type": 'get',
"url": vm.$queryVimInfoUrl,
"dataType": "json",
"success": function (resp) {
if(resp.operationResult==vm.$operationResult.success)
{
vm.vimList = (resp==null)?[]:resp.data;
}
else{
vm.vimList=[];
alert("查询vim列表失败");
return;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("查询vim列表失败:"+textStatus+":"+errorThrown);
return;
}
});
}
var updateHostList=function(){
//ajax查询host列表
$.ajax({
"type": 'get',
"url": vm.$queryHostInfoUrl,
"dataType": "json",
"success": function (resp) {
if(resp.operationResult==vm.$operationResult.success)
{
vm.hostList = (resp==null)?[]:resp.data;
}
else{
vm.hostList=[];
alert("查询host列表失败");
return;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("查询host列表失败:"+textStatus+":"+errorThrown);
return;
}
});
}
var updateVduList=function(){
//ajax查询vdu列表
$.ajax({
"type": 'get',
"url": vm.$queryVduInfoUrl,
"dataType": "json",
"success": function (resp) {
if(resp.operationResult==vm.$operationResult.success)
{
vm.vduList = (resp==null)?[]:resp.data;
}
else{
vm.vduList=[];
alert("查询vdu列表失败");
return;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("查询vdu列表失败:"+textStatus+":"+errorThrown);
return;
}
});
}
var updateVnfmList=function(){
//ajax查询vnfm列表
$.ajax({
"type": 'get',
"url": vm.$queryVnfmInfoUrl,
"dataType": "json",
"success": function (resp) {
if(resp.operationResult==vm.$operationResult.success)
{
vm.vnfmList = (resp==null)?[]:resp.data;
}
else{
vm.vnfmList=[];
alert("查询vnfm列表失败");
return;
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("查询vnfm列表失败:"+textStatus+":"+errorThrown);
return;
}
});
}
|