/*
* Copyright (C) 2016 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 table;
var vm = avalon
.define({
$id : "routeController",
route:{
routeWay:"ip",
routeHost:"",
routeIP:"",
routePort:"",
routeSubDomain:"",
iuiRootPath:iuiRootPath,
apiRootPath:apiRootPath
},
apiIframeUrl:"",
iuiIframeUrl:"",
boxVisible:true,
routeTargetTitle:"",
server_rtn:{
info_block:false,
warning_block:false,
rtn_info:""
},
showAPIType:"0",
showAPITypeName:[$.i18n.prop("org_onap_msb_route_swagger_type_predefined"),$.i18n.prop("org_onap_msb_route_swagger_type_custominput")],
$msbProtocol :["REST","HTTP","UI","MQ","FTP","SNMP","TCP","UDP"],
$msbType:["UI","NAF","SAF"],
apiJson:{
local:"",
custom:""
},
setAPIType:function(type){
vm.apiRouteInfo.apiJsonType=type;
if(type==0){
vm.apiJson.local=vm.jsonApiSelectList.selectItems[0];
}
},
jsonApiSelectList: {
condName : "type",
component_type : 'select',
selectItems : []
},
dataTableLanguage: {
"sProcessing": " Loadding...",
"sLengthMenu": $.i18n.prop("org_onap_msb_route-table-sLengthMenu"),
"sZeroRecords": $.i18n.prop("org_onap_msb_route-table-sZeroRecords"),
"sInfo": " " + $.i18n.prop("org_onap_msb_route-table-sInfo"),
"sInfoEmpty": $.i18n.prop("org_onap_msb_route-table-sInfoEmpty"),
"sGroupActions": $.i18n.prop("org_onap_msb_route-table-sGroupActions"),
"sAjaxRequestGeneralError": $.i18n.prop("org_onap_msb_route-table-sAjaxRequestGeneralError"),
"sEmptyTable": $.i18n.prop("org_onap_msb_route-table-sEmptyTable"),
"oPaginate": {
"sPrevious": $.i18n.prop("org_onap_msb_route-table-sPrevious"),
"sNext": $.i18n.prop("org_onap_msb_route-table-sNext"),
"sPage": $.i18n.prop("org_onap_msb_route-table-sPage"),
"sPageOf": $.i18n.prop("org_onap_msb_route-table-sPageOf")
},
"sSearch": $.i18n.prop("org_onap_msb_route-table-search"),
"sInfoFiltered": $.i18n.prop("org_onap_msb_route-table-infofilter")
},
$apiRouteUrl :apiBasePath+'/apiRoute',
$apiRouteInstanceUrl :apiBasePath+'/apiRoute/{serviceName}/version/{version}',
$apiRouteStatusUrl :apiBasePath+'/apiRoute/{serviceName}/version/{version}/status/{status}',
$apiDocsUrl :apiBasePath+'/apiRoute/apiDocs',
$apiGatewayPortUrl :apiBasePath+'/apiRoute/apiGatewayPort',
$discoverInfoUrl :apiBasePath+'/apiRoute/discoverInfo',
$iuiRouteUrl :apiBasePath+'/iuiRoute',
$iuiRouteInstanceUrl :apiBasePath+'/iuiRoute/{serviceName}',
$iuiRouteStatusUrl :apiBasePath+'/iuiRoute/{serviceName}/status/{status}',
$customRouteUrl :apiBasePath+'/customRoute/all',
$customRouteInstanceUrl :apiBasePath+'/customRoute/instance',
$customRouteStatusUrl :apiBasePath+'/customRoute/status',
$msbRouteUrl:apiBasePath+'/services',
$msbRouteInstanceUrl :apiBasePath+'/services/{serviceName}/version/{version}',
routeLoading:false,
apiRouteArray : [],
apiGroupByPortArray : [],
apiRouteInfo : {
oldServiceName:"",
serviceName : "",
oldVersion:"",
version : "",
status:"",
url:"",
apiJson:"/swagger.json",
apiJsonType:"1",
control:"",
host:"",
publish_port:"",
publishProtocol:"",
server:"",
servers: []
},
iuiRouteArray : [],
iuiGroupByPortArray : [],
iuiRouteInfo : {
oldServiceName:"",
serviceName : "",
status:"",
url:"",
server:"",
control:"",
host:"",
publish_port:"",
publishProtocol:"",
servers: []
},
customRouteArray : [],
customGroupByPortArray : [],
customGroupRouteArray : [],
customRouteInfo : {
oldServiceName:"",
serviceName : "",
status:"",
url:"",
server:"",
control:"",
host:"",
publish_port:"",
publishProtocol:"",
servers: []
},
msbRouteArray : [],
msbRouteInfo : {
oldServiceName:"",
oldVersion:"",
serviceName : "",
version:"",
status:"0",
nodes:[],
newHost:"",
newttl:0,
url:"",
protocol:"",
visualRange:"",
visualRangeArray:[]
},
discoverInfo:{
ip:"",
port:"",
enabled:true,
deployMode:""
},
selectedRoute:"",
selectedRouteType:"",
routeDlgInfo:{
titleName:"",
saveType:""
},
$initRoute : function() {
vm.route.routeSubDomain=window.location.host.substring(3);
vm.route.routeWay="ip";
vm.route.routeHost=window.location.host.split(":")[0]; //Default show port:80
vm.route.routeIP=window.location.host.split(":")[0];
/*if(window.location.host.split(":")[1]==null){
vm.route.routePort="80";
}
else{
vm.route.routePort=window.location.host.split(":")[1];
}*/
vm.route.routePort="80";
var getDiscoverInfoReturn=true;
$.ajax({
"type": 'get',
"async": false,
"url": vm.$discoverInfoUrl,
"dataType": "json",
success: function (resp) {
vm.discoverInfo = (resp==null)?"":resp;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
getDiscoverInfoReturn=false;
bootbox.alert("get discoverInfo from server fails:"+XMLHttpRequest.statusText);
}
});
if(!getDiscoverInfoReturn) return;
vm.routeLoading=true;
$.ajax({
"type": 'get',
"url": vm.$apiRouteUrl+"?routeWay="+vm.route.routeWay,
"dataType": "json",
success: function (resp) {
//vm.apiRouteArray = (resp==null)?[]:resp;
//vm.apiRouteArray.sort(function(a,b){return a.serviceName>b.serviceName?1:-1});
if(resp!=null && resp.length>0){
vm.apiGroupByPortArray=routeUtil.groupRouteByPort(resp);
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
bootbox.alert("get API serviceInfos fails:"+XMLHttpRequest.responseText);
},
complete:function(){
vm.routeLoading=false;
routeUtil.refreshRoute();
}
});
$.ajax({
"type": 'get',
"url": vm.$iuiRouteUrl+"?routeWay="+vm.route.routeWay,
"dataType": "json",
success: function (resp) {
//vm.iuiRouteArray = (resp==null)?[]:resp;
//vm.iuiRouteArray.sort(function(a,b){return a.serviceName>b.serviceName?1:-1});
if(resp!=null && resp.length>0){
vm.iuiGroupByPortArray=routeUtil.groupRouteByPort(resp);
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.info("get iui services fails:"+XMLHttpRequest.responseText);
},
complete:function(){
routeUtil.refreshRoute();
}
});
$.ajax({
"type": 'get',
"url": vm.$customRouteUrl+"?routeWay="+vm.route.routeWay,
"dataType": "json",
success: function (resp) {
//vm.customRouteArray = (resp==null)?[]:resp;
if(resp!=null && resp.length>0)
{
//routeUtil.groupRoute(resp);
vm.customGroupByPortArray=routeUtil.groupRouteByPort(resp);
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.info("get custom services fails:"+XMLHttpRequest.responseText);
},
complete:function(){
routeUtil.refreshRoute();
}
});
$.ajax({
"type": 'get',
"url": vm.$apiDocsUrl,
"dataType": "json",
success: function (resp) {
vm.jsonApiSelectList.selectItems= (resp==null)?[]:resp;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.info("get local apiDocs fails:"+textStatus+":"+errorThrown);
}
});
vm.initIUIfori18n();
if(vm.discoverInfo.enabled==false){
vm.initMSBRoute();
}
},
initMSBRoute:function(){
vm.initIUIfori18n();
$.ajax({
"type": 'get',
"url": vm.$msbRouteUrl,
"dataType": "json",
success: function (resp) {
vm.msbRouteArray = (resp==null)?[]:resp;
vm.msbRouteArray.sort(function(a,b){return a.serviceName>b.serviceName?1:-1});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
bootbox.alert("get msb services fails:"+XMLHttpRequest.responseText);
return;
},
complete:function(){
table=$('#msbTable').DataTable({
"oLanguage": vm.dataTableLanguage,
columnDefs: [ {
targets: [ 0,8 ],
"searchable": false,
"bSortable": false
}],
"order": [[2, 'asc']]
});
}
});
},
clickDisplayGraphAlink: function () {
vm.boxVisible = !vm.boxVisible;
},
addmsbHost:function(){
if(vm.msbRouteInfo.newHost==""){
vm.server_rtn.warning_block=true;
vm.server_rtn.info_block=false;
vm.server_rtn.rtn_info= $.i18n.prop("org_onap_msb_route_err_host_empty");
return;
}
if(vm.msbRouteInfo.newttl==""){
vm.server_rtn.warning_block=true;
vm.server_rtn.info_block=false;
vm.server_rtn.rtn_info= $.i18n.prop("org_onap_msb_route_err_ttl_empty");
return;
}
var reg=/^(([1-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))\.)(([0-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))\.){2}([1-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5]))):(\d{1,5})$/
var ip,port;
if(!reg.test(vm.msbRouteInfo.newHost)){
vm.server_rtn.warning_block=true;
vm.server_rtn.info_block=false;
vm.server_rtn.rtn_info= $.i18n.prop("org_onap_msb_route_err_host_format");
return;
}
else{
var hosts=vm.msbRouteInfo.newHost.split(":");
ip=hosts[0];
port=hosts[1];
}
var reg_ttl=/^\d+$/
if(!reg_ttl.test(vm.msbRouteInfo.newttl)){
vm.server_rtn.warning_block=true;
vm.server_rtn.info_block=false;
vm.server_rtn.rtn_info= $.i18n.prop("org_onap_msb_route_err_ttl_format");
return;
}
// determine whether host repeated
for(var i=0;ib.serviceName?1:-1});
routeUtil.refreshRoute();
$('#iuirouteDlg').modal('hide');
routeUtil.growl($.i18n.prop('org_onap_msb_route_tab_iui'),$.i18n.prop('org_onap_msb_route_service_save'),"success");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
vm.server_rtn.warning_block=true;
vm.server_rtn.info_block=false;
vm.server_rtn.rtn_info= $.i18n.prop('org_onap_msb_route_err_service_save')+textStatus+":"+errorThrown;
}
});
}
else{ //update
var url= vm.$iuiRouteInstanceUrl;
url=url.replace("{serviceName}",vm.iuiRouteInfo.oldServiceName);
url=url+"?host="+vm.iuiRouteInfo.host+"&publish_port="+vm.iuiRouteInfo.publish_port+"&routeWay="+vm.route.routeWay;
//Determine whether to repeat
if(vm.iuiRouteInfo.serviceName!=vm.iuiRouteInfo.oldServiceName) //Has been modified service name
{
for(var i=0;ib.serviceName?1:-1});
routeUtil.refreshRoute();
$('#routeDlg').modal('hide');
routeUtil.growl($.i18n.prop('org_onap_msb_route_tab_api'),$.i18n.prop('org_onap_msb_route_service_save'),"success");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
vm.server_rtn.warning_block=true;
vm.server_rtn.info_block=false;
vm.server_rtn.rtn_info= $.i18n.prop('org_onap_msb_route_err_service_save')+textStatus+":"+errorThrown;
}
});
}
else{ //update
//Determine whether to repeat
if(vm.apiRouteInfo.serviceName!=vm.apiRouteInfo.oldServiceName ||
vm.apiRouteInfo.version!=vm.apiRouteInfo.oldVersion) //Has been modified service name
{
for(var i=0;i Loadding...",
"sLengthMenu": $.i18n.prop("org_onap_msb_route-table-sLengthMenu"),
"sZeroRecords": $.i18n.prop("org_onap_msb_route-table-sZeroRecords"),
"sInfo": " " + $.i18n.prop("org_onap_msb_route-table-sInfo"),
"sInfoEmpty": $.i18n.prop("org_onap_msb_route-table-sInfoEmpty"),
"sGroupActions": $.i18n.prop("org_onap_msb_route-table-sGroupActions"),
"sAjaxRequestGeneralError": $.i18n.prop("org_onap_msb_route-table-sAjaxRequestGeneralError"),
"sEmptyTable": $.i18n.prop("org_onap_msb_route-table-sEmptyTable"),
"oPaginate": {
"sPrevious": $.i18n.prop("org_onap_msb_route-table-sPrevious"),
"sNext": $.i18n.prop("org_onap_msb_route-table-sNext"),
"sPage": $.i18n.prop("org_onap_msb_route-table-sPage"),
"sPageOf": $.i18n.prop("org_onap_msb_route-table-sPageOf")
},
"sSearch": $.i18n.prop("org_onap_msb_route-table-search"),
"sInfoFiltered": $.i18n.prop("org_onap_msb_route-table-infofilter")
};
}
});