2 * Copyright 2016 ZTE, Inc. and others.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 routeUtil.growl=function(title,message,type){
20 icon: "fa fa-envelope-o fa-lg",
21 title: " "+$.i18n.prop('org_onap_msb_route_property_ttl')+title,
22 message: message+" "
29 routeUtil.showApiGateWayAddress=function(){
33 if($("input[name='chkVisualRange']:checked").length==0) return false;
35 if(vm.msbRouteInfo.protocol=='REST' || vm.msbRouteInfo.protocol=='HTTP' || vm.msbRouteInfo.protocol=='UI' || vm.msbRouteInfo.protocol=='PORTAL') return true;
37 if(vm.msbRouteInfo.protocol=='UDP' || vm.msbRouteInfo.protocol=='TCP') {
38 if(vm.if_publish_port.length==1) return true;
48 routeUtil.showHealthStatus=function(nodes){
50 for(var i=0;i<nodes.length;i++){
52 if(nodes[i].status!="passing"){
53 return " <span class='label label-warning'>"+$.i18n.prop('org_onap_msb_discover_property_abnormal')+"</span>";
57 return " <span class='label label-success'>"+$.i18n.prop('org_onap_msb_discover_property_normal')+"</span>";
62 routeUtil.showVisualRange=function(visualRange){
64 var rangArray=visualRange.split("|");
66 var visualRangeText="";
68 if(rangArray.length>1) rangArray.sort(function(a,b){return a>b?1:-1});
70 for(var i=0;i<rangArray.length;i++){
71 if(rangArray[i] === '0'){
72 visualRangeText+= "<span class='label-visualRange label-sysOut'>"+$.i18n.prop('org_onap_msb_route_form_intersystem')+"</span>";
74 else if(rangArray[i] === '1'){
75 visualRangeText+= "<span class='label-visualRange label-sysIn'>"+$.i18n.prop('org_onap_msb_route_form_insystem')+"</span>";
80 return visualRangeText;
85 routeUtil.showCheckInterval=function(node){
86 if(node.checkType=="TTL"){
87 return node.ttl==0?"":node.ttl;
89 else if(node.checkType=="TCP" || node.checkType=="HTTP"){
90 return node.checkInterval==0?"":node.checkInterval;
100 routeUtil.ifAPIUrl=function(url){
101 if(url=="" || url ==null) return false;
103 var reg_api_match=/^(\/api\/.*?)$/;
104 return reg_api_match.test(url);
109 routeUtil.checkLables=function(apiGateway_labels_array,service_labels){
110 if(apiGateway_labels_array==null || apiGateway_labels_array.length==0) return true;
111 if(service_labels=="") return false;
112 var service_labels_array=service_labels.split(",");
113 for(var i=0;i<service_labels_array.length;i++){
114 for(var j=0;j<apiGateway_labels_array.length;j++){
115 if(service_labels_array[i].trim()==apiGateway_labels_array[j].trim()){
123 routeUtil.checkNetwork_plane_type=function(apiGateway_networkPlaneType,service_networkPlaneType){
124 if(apiGateway_networkPlaneType==null || apiGateway_networkPlaneType=="") return true;
125 var apiGateway_networkPlaneType_array=apiGateway_networkPlaneType.split("|");
126 var service_networkPlaneType_array=service_networkPlaneType.split("|")
128 for(var i=0;i<service_networkPlaneType_array.length;i++){
129 for(var j=0;j<apiGateway_networkPlaneType_array.length;j++){
130 if(service_networkPlaneType_array[i].trim()==apiGateway_networkPlaneType_array[j].trim()){
140 routeUtil.checkTargetServiceUrl=function(service){
142 if(service==null) return false;
144 return routeUtil.checkNetwork_plane_type(service.network_plane_type,$("input[name='networkPlaneType']").val()) &&
145 routeUtil.checkLables(service.labels,$("#labels").val());
150 Array.prototype.unique = function(){
153 for(var i = 0; i < this.length; i++){
163 routeUtil.buildTargetServiceUrl=function(service,namespace){
165 namespace=namespace==""?"default":namespace;
166 var serviceName=vm.msbRouteInfo.serviceName==""?"serviceName":vm.msbRouteInfo.serviceName;
167 var targetServiceUrlArray=[];
169 var routeWay="ip",routeSubdomain="openpalette.zte.com.cn";
170 var metadataArray=service.metadata;
171 if(metadataArray!=null){
172 for(var i=0;i<metadataArray.length;i++){
173 if(metadataArray[i].key=="routeWay"){
174 routeWay=metadataArray[i].value;
176 if(metadataArray[i].key=="routeSubdomain"){
177 routeSubdomain=metadataArray[i].value;
185 var protocol=$("select[name='protocol']").find("option:selected").text();
186 if(vm.msbRouteInfo.path.trim()!="" && vm.msbRouteInfo.path.trim()!="/"){
187 path=vm.msbRouteInfo.path;
190 var version=vm.msbRouteInfo.version==""?"":"/"+vm.msbRouteInfo.version
193 path="/iui/"+serviceName;
196 else if(protocol=='REST'){
198 path="/api/"+serviceName+version;
202 else if(protocol=='HTTP' || (protocol=="" && vm.msbRouteInfo.protocol=="PORTAL")){
203 var reg_customName_match=/^(\/.*?)$/;
204 if(!reg_customName_match.test(serviceName)) {
206 path="/"+serviceName+version;
209 path=serviceName+version;
220 if(vm.msbRouteInfo.host!=""){
221 host=vm.msbRouteInfo.host;
224 if(vm.msbRouteInfo.namespace!="" && vm.msbRouteInfo.namespace!="default") host=serviceName+"-"+vm.msbRouteInfo.namespace;
225 else host=serviceName;
229 var publish_port,publish_protocol;
235 var routeWays=routeWay.split("|");
236 for(var i=0;i<routeWays.length;i++){
237 if(routeWays[i]=="ip"){
239 if(service.visualRange=="1"){
242 if(protocol=='TCP'||protocol=='UDP'){
243 publish_protocol=protocol.toLowerCase();
244 publish_port=vm.msbRouteInfo.publish_port;
247 publish_protocol="http";
248 publish_port=10080; // service.nodes[0].port;
251 targetServiceUrlArray.push("<span> ns:"+namespace+" </span> "+publish_protocol+"://"+service.nodes[0].ip+":"+publish_port+path);
254 var publishPorts=vm.msbRouteInfo.publish_port.split("|");
255 if(publishPorts.length==2){
256 // multiPublishPort: https|http
258 targetServiceUrlArray.push("<span> ns:"+namespace+" </span> "+"https://"+service.nodes[0].ip+":"+publishPorts[0]+path);
259 targetServiceUrlArray.push("<span> ns:"+namespace+" </span> "+"http://"+service.nodes[0].ip+":"+publishPorts[1]+path);
266 if(protocol=='TCP'||protocol=='UDP'){
267 publish_protocol=protocol.toLowerCase();
268 publish_port=vm.msbRouteInfo.publish_port;
271 if(vm.msbRouteInfo.publish_port!=""){
272 publish_port=vm.msbRouteInfo.publish_port;
273 publish_protocol="https";
276 publish_port=80; //service.nodes[0].port;
277 publish_protocol="http";
280 var https_default_publish_port=443;
281 targetServiceUrlArray.push("<span> ns:"+namespace+" </span> https://"+service.nodes[0].ip+path);
286 var portInfo= publish_port==80?"":":"+ publish_port;
287 targetServiceUrlArray.push("<span> ns:"+namespace+" </span> "+publish_protocol+"://"+service.nodes[0].ip+portInfo+path);
294 else if(routeWays[i]=="domain"){
295 var domain=host+"."+routeSubdomain;
298 if(vm.msbRouteInfo.path.trim()!="" && vm.msbRouteInfo.path.trim()!="/" ){
299 publish_url=vm.msbRouteInfo.path;
302 if(vm.msbRouteInfo.url.trim()==path || vm.msbRouteInfo.url.trim()=="/"){
311 if(protocol=='TCP'||protocol=='UDP'){
313 publish_port=vm.msbRouteInfo.publish_port;
314 publish_protocol=protocol.toLowerCase();
319 publish_protocol="http";
320 publish_port=80;//service.nodes[0].port;
321 targetServiceUrlArray.push("<span> ns:"+namespace+" </span> https://"+domain+publish_url);
327 var portInfo= publish_port==80?"":":"+ publish_port ;
328 targetServiceUrlArray.push("<span> ns:"+namespace+" </span> "+publish_protocol+"://"+domain+portInfo+publish_url);
334 return targetServiceUrlArray;
339 routeUtil.changeTargetServiceUrl=function(){
341 vm.targetServiceUrl4SysOut="";
342 vm.targetServiceUrl4SysIn="";
343 vm.publishUrl.ifShowPublishUrl4SysOut=false;
344 vm.publishUrl.ifShowPublishUrl4SysIn=false;
345 if(routeUtil.showApiGateWayAddress()==false) return;
350 $("input[name='chkVisualRange']:checked").each(function(){
355 // targetAllServiceUrlArray.push("["+$.i18n.prop('org_onap_msb_route_form_intersystem')+"]");
356 var targetAllServiceUrlArray=[];
357 vm.publishUrl.ifShowPublishUrl4SysOut=true;
359 for(var i=0;i<vm.routeService.length;i++){
360 if(routeUtil.checkTargetServiceUrl(vm.routeService[i])){
361 var targetServiceUrlArray = routeUtil.buildTargetServiceUrl(vm.routeService[i],vm.msbRouteInfo.namespace);
363 if(targetServiceUrlArray.length>0){
364 routeUtil.concatArray(targetAllServiceUrlArray,targetServiceUrlArray);
370 //vm.targetServiceUrl+="(ns:"+vm.msbRouteInfo.namespace+") 未匹配到对应apigateway<br>";
373 for(var i=0;i<vm.routeService_all.length;i++){
374 if(routeUtil.checkTargetServiceUrl(vm.routeService_all[i])){
375 var targetServiceUrlArray = routeUtil.buildTargetServiceUrl(vm.routeService_all[i],"all");
377 if(targetServiceUrlArray.length>0){
378 routeUtil.concatArray(targetAllServiceUrlArray,targetServiceUrlArray);
383 vm.publishUrl.publishUrl4SysOut=targetAllServiceUrlArray.unique().join("<br>");
387 else if($(this).val()==1){
388 var targetAllServiceUrlArray=[];
389 vm.publishUrl.ifShowPublishUrl4SysIn=true;
390 //targetAllServiceUrlArray.push("["+$.i18n.prop('org_onap_msb_route_form_insystem')+"]");
392 for(var i=0;i<vm.apiGatewayService.length;i++){
393 if(routeUtil.checkTargetServiceUrl(vm.apiGatewayService[i])){
394 var targetServiceUrlArray = routeUtil.buildTargetServiceUrl(vm.apiGatewayService[i],vm.msbRouteInfo.namespace);
395 if(targetServiceUrlArray.length>0){
396 routeUtil.concatArray(targetAllServiceUrlArray,targetServiceUrlArray);
402 for(var i=0;i<vm.apiGatewayService_all.length;i++){
403 if(routeUtil.checkTargetServiceUrl(vm.apiGatewayService_all[i])){
404 var targetServiceUrlArray =routeUtil.buildTargetServiceUrl(vm.apiGatewayService_all[i],"all");
405 if(targetServiceUrlArray.length>0){
406 routeUtil.concatArray(targetAllServiceUrlArray,targetServiceUrlArray);
411 vm.publishUrl.publishUrl4SysIn=targetAllServiceUrlArray.unique().join("<br>");
425 routeUtil.getQueryString=function(url,name){
426 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
427 var r = url.match(reg);
428 if (r != null) return unescape(r[2]);
434 routeUtil.concatArray=function(parentArray,childArray){
436 for (var i=0; i < childArray.length; i++) {
437 parentArray.push(childArray[i]);