/* * Copyright 2016 ZTE, Inc. and others. * * 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 routeUtil = {}; routeUtil.growl=function(title,message,type){ $.growl({ icon: "fa fa-envelope-o fa-lg", title: "  "+$.i18n.prop('org_onap_msb_route_property_ttl')+title, message: message+"        " },{ type: type }); } routeUtil.showApiGateWayAddress=function(){ if($("input[name='chkVisualRange']:checked").length==0) return false; if(vm.msbRouteInfo.protocol=='REST' || vm.msbRouteInfo.protocol=='HTTP' || vm.msbRouteInfo.protocol=='UI' || vm.msbRouteInfo.protocol=='PORTAL') return true; if(vm.msbRouteInfo.protocol=='UDP' || vm.msbRouteInfo.protocol=='TCP') { if(vm.if_publish_port.length==1) return true; } return false; } routeUtil.showHealthStatus=function(nodes){ for(var i=0;i"+$.i18n.prop('org_onap_msb_discover_property_abnormal')+""; } } return " "+$.i18n.prop('org_onap_msb_discover_property_normal')+""; } routeUtil.showVisualRange=function(visualRange){ var rangArray=visualRange.split("|"); var visualRangeText=""; if(rangArray.length>1) rangArray.sort(function(a,b){return a>b?1:-1}); for(var i=0;i"; } else if(rangArray[i] === '1'){ visualRangeText+= ""+$.i18n.prop('org_onap_msb_route_form_insystem')+""; } } return visualRangeText; } routeUtil.showCheckInterval=function(node){ if(node.checkType=="TTL"){ return node.ttl==0?"":node.ttl; } else if(node.checkType=="TCP" || node.checkType=="HTTP"){ return node.checkInterval==0?"":node.checkInterval; } else{ return ""; } } routeUtil.ifAPIUrl=function(url){ if(url=="" || url ==null) return false; var reg_api_match=/^(\/api\/.*?)$/; return reg_api_match.test(url); } routeUtil.checkLables=function(apiGateway_labels_array,service_labels){ if(apiGateway_labels_array==null || apiGateway_labels_array.length==0) return true; if(service_labels=="") return false; var service_labels_array=service_labels.split(","); for(var i=0;i ns:"+namespace+" "+publish_protocol+"://"+service.nodes[0].ip+":"+publish_port+path); } else{ var publishPorts=vm.msbRouteInfo.publish_port.split("|"); if(publishPorts.length==2){ // multiPublishPort: https|http targetServiceUrlArray.push(" ns:"+namespace+" "+"https://"+service.nodes[0].ip+":"+publishPorts[0]+path); targetServiceUrlArray.push(" ns:"+namespace+" "+"http://"+service.nodes[0].ip+":"+publishPorts[1]+path); } else{ // single Port if(protocol=='TCP'||protocol=='UDP'){ publish_protocol=protocol.toLowerCase(); publish_port=vm.msbRouteInfo.publish_port; } else{ if(vm.msbRouteInfo.publish_port!=""){ publish_port=vm.msbRouteInfo.publish_port; publish_protocol="https"; } else{ publish_port=80; //service.nodes[0].port; publish_protocol="http"; //https default:443 var https_default_publish_port=443; targetServiceUrlArray.push(" ns:"+namespace+" https://"+service.nodes[0].ip+path); } } var portInfo= publish_port==80?"":":"+ publish_port; targetServiceUrlArray.push(" ns:"+namespace+" "+publish_protocol+"://"+service.nodes[0].ip+portInfo+path); } } } else if(routeWays[i]=="domain"){ var domain=host+"."+routeSubdomain; var publish_url; if(vm.msbRouteInfo.path.trim()!="" && vm.msbRouteInfo.path.trim()!="/" ){ publish_url=vm.msbRouteInfo.path; } else{ if(vm.msbRouteInfo.url.trim()==path || vm.msbRouteInfo.url.trim()=="/"){ publish_url="/"; } else{ publish_url=path; } } if(protocol=='TCP'||protocol=='UDP'){ publish_port=vm.msbRouteInfo.publish_port; publish_protocol=protocol.toLowerCase(); } else { publish_protocol="http"; publish_port=80;//service.nodes[0].port; targetServiceUrlArray.push(" ns:"+namespace+" https://"+domain+publish_url); } var portInfo= publish_port==80?"":":"+ publish_port ; targetServiceUrlArray.push(" ns:"+namespace+" "+publish_protocol+"://"+domain+portInfo+publish_url); } } return targetServiceUrlArray; } routeUtil.changeTargetServiceUrl=function(){ vm.targetServiceUrl4SysOut=""; vm.targetServiceUrl4SysIn=""; vm.publishUrl.ifShowPublishUrl4SysOut=false; vm.publishUrl.ifShowPublishUrl4SysIn=false; if(routeUtil.showApiGateWayAddress()==false) return; $("input[name='chkVisualRange']:checked").each(function(){ if($(this).val()==0) { // targetAllServiceUrlArray.push("["+$.i18n.prop('org_onap_msb_route_form_intersystem')+"]"); var targetAllServiceUrlArray=[]; vm.publishUrl.ifShowPublishUrl4SysOut=true; for(var i=0;i0){ routeUtil.concatArray(targetAllServiceUrlArray,targetServiceUrlArray); } } } //vm.targetServiceUrl+="(ns:"+vm.msbRouteInfo.namespace+") 未匹配到对应apigateway
"; for(var i=0;i0){ routeUtil.concatArray(targetAllServiceUrlArray,targetServiceUrlArray); } } } vm.publishUrl.publishUrl4SysOut=targetAllServiceUrlArray.unique().join("
"); } else if($(this).val()==1){ var targetAllServiceUrlArray=[]; vm.publishUrl.ifShowPublishUrl4SysIn=true; //targetAllServiceUrlArray.push("["+$.i18n.prop('org_onap_msb_route_form_insystem')+"]"); for(var i=0;i0){ routeUtil.concatArray(targetAllServiceUrlArray,targetServiceUrlArray); } } } for(var i=0;i0){ routeUtil.concatArray(targetAllServiceUrlArray,targetServiceUrlArray); } } } vm.publishUrl.publishUrl4SysIn=targetAllServiceUrlArray.unique().join("
"); } }); } routeUtil.getQueryString=function(url,name){ var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = url.match(reg); if (r != null) return unescape(r[2]); return null; } routeUtil.concatArray=function(parentArray,childArray){ for (var i=0; i < childArray.length; i++) { parentArray.push(childArray[i]); } }