/* * 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 table; var vm = avalon .define({ $id : "serviceController", $apiGatewayServiceName:"apigateway", ifshowApiGatewayService:false, tcp_udp_port_range:["40001","40100"], apiGatewayService:[], apiGatewayService_all:[], routeService:[], routeService_all:[], server_rtn:{ info_block:false, warning_block:false, rtn_info:"" }, node_rtn:{ info_block:false, warning_block:false, rtn_info:"" }, if_publish_port:[], if_http_publish_port:[], $msbProtocol :["REST","HTTP","UI","MQ","FTP","SNMP","TCP","UDP"], $healthCheckType:["","TTL","HTTP","TCP"], $ha_role_Type:["","active","standby"], msbLbPolicyRange:[ { name:$.i18n.prop("org_onap_msb_discover_lbpolicy_round"), value:"round-robin" }, { name:"IPHash", value:"ip_hash" }, /*{ name:$.i18n.prop("org_onap_msb_discover_lbpolicy_leastconn"), value:"least_conn" },*/ { name:$.i18n.prop("org_onap_msb_discover_lbpolicy_clientcustom"), value:"client_custom" } ], $msbRouteUrl:apiBasePath+'/services?is_manual=true', $msbRouteInstanceUrl :apiBasePath+'/services/{serviceName}/version/{version}', $msbRouteNodesUrl :apiBasePath+'/services/{serviceName}/version/{version}/nodes', $apiGatewayInfoUrl :apiBasePath+'/services/apigatewayserviceinfo', $tcpudpportrangeUrl:apiBasePath+'/services/tcpudpportrange', publishUrl:{ publishUrl4SysOut:"", publishUrl4SysIn:"", ifShowPublishUrl4SysOut:false, ifShowPublishUrl4SysIn:false }, targetServiceHost:"", msbRouteArray : [], msbRouteInfo : { oldServiceName:"", oldVersion:"", oldPublic_port:"", serviceName : "", version:"", status:"0", nodes:[], url:"", protocol:"", visualRange:"", visualRangeArray:[], lb_policy:"", publish_port:"", namespace:"", network_plane_type:"", host:"", path:"" }, nodeInfo:{ ip:"", port:"", weight:"", max_fails:"", fail_timeout:"", checkType:"", checkUrl:"", checkInterval:"", checkTimeOut:"", ttl:"", ha_role:"" }, updateServiceInfo:{ serviceName : "", version:"", namespace:"", authtype:"" }, oldNodeInfo:{ ip:"", port:"" }, nodeDlgInfo:{ titleName:"", saveType:"" }, pageInfo:{ pageType:"add", pageTitle:"", }, initMSBRoute:function(){ vm.initIUIfori18n(); var url= window.location.search.substr(1); vm.pageInfo.pageType=routeUtil.getQueryString(url,"type"); if(vm.pageInfo.pageType=="add"){ vm.addMsbRoute(); vm.getApigatewayInfo("all"); vm.getApigatewayInfo(""); vm.pageInfo.pageTitle=$.i18n.prop("org_onap_msb_discover_form_title_add"); } else{ vm.updateServiceInfo.serviceName=routeUtil.getQueryString(url,"serviceName"); vm.updateServiceInfo.version=routeUtil.getQueryString(url,"version"); vm.updateServiceInfo.authtype=routeUtil.getQueryString(url,"authtype"); vm.updateServiceInfo.namespace=routeUtil.getQueryString(url,"namespace"); vm.initUpdateRoute(vm.updateServiceInfo.serviceName,vm.updateServiceInfo.version,vm.updateServiceInfo.namespace); vm.getApigatewayInfo("all"); vm.getApigatewayInfo(vm.updateServiceInfo.namespace); if(vm.pageInfo.pageType=="update"){ vm.pageInfo.pageTitle=$.i18n.prop("org_onap_msb_discover_form_title_update"); } else if(vm.pageInfo.pageType=="view"){ vm.pageInfo.pageTitle=$.i18n.prop("org_onap_msb_discover_form_title_view"); } } vm.getTcpUdpPortRangeUrl(); }, returnList:function(){ window.history.back(-1); }, closePage:function(){ window.close(); }, addMsbRoute:function(){ vm.msbRouteInfo.serviceName=""; vm.msbRouteInfo.version=""; vm.msbRouteInfo.url=""; vm.msbRouteInfo.protocol=""; vm.msbRouteInfo.publish_port=""; vm.msbRouteInfo.lb_policy=""; vm.msbRouteInfo.visualRange=""; vm.msbRouteInfo.visualRangeArray=[], vm.msbRouteInfo.nodes=[]; vm.msbRouteInfo.status="1"; vm.msbRouteInfo.namespace=""; vm.msbRouteInfo.network_plane_type=""; vm.msbRouteInfo.host=""; vm.msbRouteInfo.path=""; vm.server_rtn.warning_block=false; vm.server_rtn.info_block=false; $('#labels').val(""); $('#labels').on('tokenfield:createdtoken', function (e) { var re = /\S+:\S+/ var valid = re.test(e.attrs.value) if (!valid) { $(e.relatedTarget).addClass('invalid') } }).tokenfield(); $('#metadata').val(""); $('#metadata').on('tokenfield:createdtoken', function (e) { var re = /\S+:\S+/ var valid = re.test(e.attrs.value) if (!valid) { $(e.relatedTarget).addClass('invalid') } }).tokenfield(); $(".form-group").each(function () { $(this).removeClass('has-success'); $(this).removeClass('has-error'); $(this).find(".help-block[id]").remove(); $(this).find(".form-tip").removeClass('form-input-focus'); //$(this).find(".item-tip").removeClass('item-tip-focus'); }); }, initUpdateRoute:function(serviceName,version,namespace){ var url= vm.$msbRouteInstanceUrl; var version2=version==""?"null":version; var serviceName2= serviceName.replace(/\//g,"*"); url=url.replace("{serviceName}",serviceName2).replace("{version}",version2)+"?ifPassStatus=false&namespace="+namespace; $.ajax({ "type": 'get', "url": url, "dataType": "json", success: function (msbRouteInfo) { //vm.msbRouteInfo.serviceName=(msbRouteInfo.protocol=="UI"?msbRouteInfo.serviceName.replace("IUI_",""):msbRouteInfo.serviceName); vm.msbRouteInfo.serviceName=msbRouteInfo.serviceName; vm.msbRouteInfo.oldServiceName=msbRouteInfo.serviceName; vm.msbRouteInfo.version= msbRouteInfo.version; vm.msbRouteInfo.oldVersion= msbRouteInfo.version vm.msbRouteInfo.url=msbRouteInfo.url; vm.msbRouteInfo.protocol=msbRouteInfo.protocol; vm.msbRouteInfo.visualRange=msbRouteInfo.visualRange; vm.msbRouteInfo.visualRangeArray=msbRouteInfo.visualRange.split("|"); vm.msbRouteInfo.lb_policy=msbRouteInfo.lb_policy==""?"round-robin":msbRouteInfo.lb_policy; vm.msbRouteInfo.namespace=msbRouteInfo.namespace; vm.msbRouteInfo.network_plane_type=msbRouteInfo.network_plane_type; vm.msbRouteInfo.host=msbRouteInfo.host; vm.msbRouteInfo.path=msbRouteInfo.path; $("#labels").val(msbRouteInfo.labels); $('#labels').on('tokenfield:createdtoken', function (e) { var re = /\S+:\S+/ var valid = re.test(e.attrs.value) if (!valid) { $(e.relatedTarget).addClass('invalid') } }).tokenfield(); var metadataArray=msbRouteInfo.metadata; var metadatas=[]; for(var i=0;i