quick_view_link_view.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var stringUtils = require('utils/string_utils');
  20. App.QuickViewLinks = Em.View.extend({
  21. isLoaded: false,
  22. showQuickLinks: false,
  23. quickLinksErrorMessage: '',
  24. /**
  25. * Updated quick links. Here we put correct hostname to url
  26. * @type {Array}
  27. */
  28. quickLinks: [],
  29. actualTags: [],
  30. configProperties: [],
  31. /**
  32. * list of files that contains properties for enabling/disabling ssl
  33. */
  34. requiredSiteNames: [],
  35. /**
  36. * @type {object}
  37. */
  38. ambariProperties: function () {
  39. return App.router.get('clusterController.ambariProperties');
  40. }.property().volatile(),
  41. didInsertElement: function () {
  42. this.loadQuickLinksConfigurations();
  43. },
  44. willDestroyElement: function () {
  45. this.get('configProperties').clear();
  46. this.get('actualTags').clear();
  47. this.get('quickLinks').clear();
  48. this.get('requiredSiteNames').clear();
  49. },
  50. /**
  51. * The flags responsible for data to build quick links:
  52. * - App.router.clusterController.isServiceMetricsLoaded
  53. *
  54. * The flags responsible for correct, up-to-date state of quick links:
  55. * - App.currentStackVersionNumber
  56. * - App.singleNodeInstall
  57. * - App.router.clusterController.isHostComponentMetricsLoaded
  58. */
  59. setQuickLinks: function () {
  60. if (App.get('router.clusterController.isServiceMetricsLoaded')) {
  61. this.loadTags();
  62. }
  63. }.observes(
  64. 'App.currentStackVersionNumber',
  65. 'App.singleNodeInstall',
  66. 'App.router.clusterController.isServiceMetricsLoaded',
  67. 'App.router.clusterController.isHostComponentMetricsLoaded'
  68. ),
  69. /**
  70. * call for configuration tags
  71. * @returns {$.ajax}
  72. */
  73. loadTags: function () {
  74. return App.ajax.send({
  75. name: 'config.tags',
  76. sender: this,
  77. success: 'loadTagsSuccess',
  78. error: 'loadTagsError'
  79. });
  80. },
  81. loadTagsSuccess: function (data) {
  82. this.get('actualTags').clear();
  83. var tags = [];
  84. var self = this;
  85. for (var prop in data.Clusters.desired_configs) {
  86. tags.push(Em.Object.create({
  87. siteName: prop,
  88. tagName: data.Clusters.desired_configs[prop]['tag']
  89. }));
  90. }
  91. this.get('actualTags').pushObjects(tags);
  92. this.setConfigProperties().done(function (data) {
  93. self.get('configProperties').pushObjects(data);
  94. self.getQuickLinksHosts();
  95. });
  96. },
  97. loadTagsError: function () {
  98. this.getQuickLinksHosts();
  99. },
  100. loadQuickLinksConfigurations: function(){
  101. var serviceName = this.get('content.serviceName');
  102. console.info("Loading quicklinks configurations for " + serviceName);
  103. return App.ajax.send({
  104. name: 'configs.quicklinksconfig',
  105. sender: this,
  106. data: {
  107. serviceName: serviceName,
  108. stackVersionUrl: App.get('stackVersionURL')
  109. },
  110. success: 'loadQuickLinksConfigSuccessCallback'
  111. });
  112. },
  113. loadQuickLinksConfigSuccessCallback: function(data){
  114. App.quicklinksMapper.map(data);
  115. var quickLinksConfig = this.getQuickLinksConfiguration();
  116. if(quickLinksConfig != null){
  117. var protocolConfig = Em.get(quickLinksConfig, 'protocol');
  118. var checks = Em.get(protocolConfig, 'checks');
  119. var sites = ['core-site', 'hdfs-site'];
  120. if(checks){
  121. checks.forEach(function(check){
  122. var protocolConfigSiteProp = Em.get(check, 'site');
  123. if (sites.indexOf(protocolConfigSiteProp) < 0){
  124. sites.push(protocolConfigSiteProp);
  125. }
  126. }, this);
  127. }
  128. var links = Em.get(quickLinksConfig, 'links');
  129. if(links && links.length > 0){
  130. links.forEach(function(link){
  131. if(!link.remove){
  132. var portConfig = Em.get(link, 'port');
  133. var portConfigSiteProp = Em.get(portConfig, 'site');
  134. if(sites.indexOf(portConfigSiteProp) < 0){
  135. sites.push(portConfigSiteProp);
  136. }
  137. }
  138. }, this);
  139. this.set('requiredSiteNames', this.get('requiredSiteNames').pushObjects(sites).uniq());
  140. this.setQuickLinks();
  141. }
  142. }
  143. },
  144. /**
  145. * call for public host names
  146. * @returns {$.ajax}
  147. */
  148. getQuickLinksHosts: function () {
  149. var masterHosts = App.HostComponent.find().filterProperty('isMaster').mapProperty('hostName').uniq();
  150. return App.ajax.send({
  151. name: 'hosts.for_quick_links',
  152. sender: this,
  153. data: {
  154. clusterName: App.get('clusterName'),
  155. masterHosts: masterHosts.join(','),
  156. urlParams: (this.get('content.serviceName') === 'HBASE') ? ',host_components/metrics/hbase/master/IsActiveMaster' : ''
  157. },
  158. success: 'setQuickLinksSuccessCallback'
  159. });
  160. },
  161. setQuickLinksSuccessCallback: function (response) {
  162. var serviceName = this.get('content.serviceName');
  163. var hosts = this.getHosts(response, serviceName);
  164. var hasQuickLinks = this.hasQuickLinksConfig(serviceName, hosts);
  165. var componentName = App.QuickLinksConfig.ServiceComponentMap[serviceName];
  166. var masterComponent = App.MasterComponent.find().findProperty('componentName', componentName);
  167. var hasHosts = false;
  168. if (masterComponent) {
  169. hasHosts = !!masterComponent.get('totalCount');
  170. }
  171. // no need to set quicklinks if
  172. // 1)current service does not have quick links configured
  173. // 2)No host component present for the configured quicklink
  174. this.set('showQuickLinks', hasQuickLinks && hasHosts);
  175. if (hosts.length === 0){
  176. this.setEmptyLinks();
  177. } else if (hosts.length === 1) {
  178. this.setSingleHostLinks(hosts, response);
  179. } else {
  180. this.setMultipleHostLinks(hosts);
  181. }
  182. },
  183. /**
  184. * Get public host name by its host name.
  185. *
  186. * @method getPublicHostName
  187. * @param {Object[]} hosts - list of hosts from response
  188. * @param {string} hostName
  189. * @return {string|null}
  190. **/
  191. getPublicHostName: function (hosts, hostName) {
  192. var host = hosts.findProperty('Hosts.host_name', hostName);
  193. if (host) {
  194. return Em.get(host, 'Hosts.public_host_name');
  195. }
  196. return null;
  197. },
  198. setConfigProperties: function () {
  199. this.get('configProperties').clear();
  200. var requiredSiteNames = this.get('requiredSiteNames');
  201. var tags = this.get('actualTags').filter(function (tag) {
  202. return requiredSiteNames.contains(tag.siteName);
  203. });
  204. return App.router.get('configurationController').getConfigsByTags(tags);
  205. },
  206. getQuickLinksConfiguration: function(){
  207. var serviceName = this.get('content.serviceName');
  208. var self = this;
  209. if (self.hasQuickLinksConfig(serviceName)) {
  210. return App.QuickLinksConfig.find().findProperty("id", serviceName);
  211. }
  212. return null;
  213. },
  214. hasQuickLinksConfig: function(serviceName) {
  215. var result = App.QuickLinksConfig.find().findProperty('id', serviceName);
  216. if(!result)
  217. return false;
  218. var links = result.get("links");
  219. if(links && links.length > 0){
  220. var toBeRemoved = 0;
  221. links.forEach(function(link){
  222. if(link.remove)
  223. toBeRemoved++;
  224. });
  225. return !(links.length === toBeRemoved);
  226. } else {
  227. return false;
  228. }
  229. },
  230. toAddLink: function(link){
  231. var linkRemoved = Em.get(link, 'removed');
  232. var url = Em.get(link, 'url');
  233. return (url && !linkRemoved);
  234. },
  235. getHostLink: function(link, host, protocol, configProperties, response){
  236. var serviceName = this.get('content.serviceName');
  237. if (serviceName === 'MAPREDUCE2' && response) {
  238. var portConfig = Em.get(link, 'port');
  239. var siteName = Em.get(portConfig, 'site');
  240. var siteConfigs = this.get('configProperties').findProperty('type', siteName).properties;
  241. var hostPortConfigValue = siteConfigs[Em.get(portConfig, protocol + '_config')];
  242. if (hostPortConfigValue != null) {
  243. var hostPortValue = hostPortConfigValue.match(new RegExp("([\\w\\d.-]*):(\\d+)"));
  244. var hostObj = response.items.findProperty('Hosts.host_name', hostPortValue[1]);
  245. if (hostObj != null) {
  246. host = hostObj.Hosts.public_host_name;
  247. }
  248. }
  249. }
  250. var linkPort = this.setPort(Em.get(link, 'port'), protocol, configProperties);
  251. if (this.toAddLink(link)) {
  252. var newItem = {};
  253. var requiresUserName = Em.get(link, 'requires_user_name');
  254. var template = Em.get(link, 'url');
  255. if('true' === requiresUserName){
  256. newItem.url = template.fmt(protocol, host, linkPort, App.router.get('loginName'));
  257. } else {
  258. newItem.url = template.fmt(protocol, host, linkPort);
  259. }
  260. newItem.label = link.label;
  261. return newItem;
  262. } else {
  263. return null;
  264. }
  265. },
  266. /**
  267. * set empty links
  268. */
  269. setEmptyLinks: function () {
  270. //display an error message
  271. var quickLinks = [{
  272. label: this.get('quickLinksErrorMessage')
  273. }];
  274. this.set('quickLinks', quickLinks);
  275. this.set('isLoaded', true);
  276. },
  277. /**
  278. * set links that contain only one host
  279. * @param {Array} hosts
  280. */
  281. setSingleHostLinks: function (hosts, response) {
  282. var quickLinksConfig = this.getQuickLinksConfiguration();
  283. if(quickLinksConfig != null){
  284. var quickLinks = [];
  285. var configProperties = this.get('configProperties');
  286. var protocol = this.setProtocol(configProperties, quickLinksConfig);
  287. var publicHostName = hosts[0].publicHostName;
  288. var links = Em.get(quickLinksConfig, 'links');
  289. links.forEach(function(link){
  290. var newItem = this.getHostLink(link, publicHostName, protocol, configProperties, response); //quicklink generated for the hbs template
  291. if(newItem != null){
  292. quickLinks.push(newItem);
  293. }
  294. }, this);
  295. this.set('quickLinks', quickLinks);
  296. this.set('isLoaded', true);
  297. } else {
  298. this.set('quickLinks', []);
  299. this.set('isLoaded', false);
  300. }
  301. },
  302. /**
  303. * set links that contain multiple hosts
  304. * @param {Array} hosts
  305. */
  306. setMultipleHostLinks: function (hosts) {
  307. var quickLinksConfig = this.getQuickLinksConfiguration();
  308. if(quickLinksConfig == null){
  309. this.set('quickLinksArray', []);
  310. this.set('isLoaded', false);
  311. return;
  312. }
  313. var quickLinksArray = [];
  314. hosts.forEach(function (host) {
  315. var publicHostName = host.publicHostName;
  316. var quickLinks = [];
  317. var configProperties = this.get('configProperties');
  318. var protocol = this.setProtocol(configProperties, quickLinksConfig);
  319. var serviceName = Em.get(quickLinksConfig, 'serviceName');
  320. var links = Em.get(quickLinksConfig, 'links');
  321. links.forEach(function(link){
  322. var linkRemoved = Em.get(link, 'removed');
  323. var url = Em.get(link, 'url');
  324. if (url && !linkRemoved) {
  325. var port;
  326. var hostNameRegExp = new RegExp('([\\w\\W]*):\\d+');
  327. if (serviceName === 'HDFS') {
  328. var config;
  329. var configPropertiesObject = configProperties.findProperty('type', 'hdfs-site');
  330. if (configPropertiesObject && configPropertiesObject.properties) {
  331. var properties = configPropertiesObject.properties;
  332. var nameServiceId = properties['dfs.nameservices'];
  333. var nnProperties = ['dfs.namenode.{0}-address.{1}.nn1', 'dfs.namenode.{0}-address.{1}.nn2'].map(function (c) {
  334. return c.format(protocol, nameServiceId);
  335. });
  336. var nnPropertiesLength = nnProperties.length;
  337. for (var i = nnPropertiesLength; i--;) {
  338. var propertyName = nnProperties[i];
  339. var hostNameMatch = properties[propertyName] && properties[propertyName].match(hostNameRegExp);
  340. if (hostNameMatch && hostNameMatch[1] === host.publicHostName) {
  341. config = propertyName;
  342. break;
  343. }
  344. }
  345. }
  346. var portConfig = Em.get(link, 'port');
  347. Em.set(portConfig, protocol +'_property', config);
  348. Em.set(link, 'port', portConfig)
  349. }
  350. var newItem = this.getHostLink(link, publicHostName, protocol, configProperties); //quicklink generated for the hbs template
  351. if(newItem != null){
  352. quickLinks.push(newItem);
  353. }
  354. }
  355. }, this);
  356. if (host.status) {
  357. quickLinks.set('publicHostNameLabel', Em.I18n.t('quick.links.publicHostName').format(host.publicHostName, host.status));
  358. } else {
  359. quickLinks.set('publicHostNameLabel', host.publicHostName);
  360. }
  361. quickLinksArray.push(quickLinks);
  362. }, this);
  363. this.set('quickLinksArray', quickLinksArray);
  364. this.set('isLoaded', true);
  365. },
  366. /**
  367. * set status to hosts with OOZIE_SERVER
  368. * @param {Array} hosts
  369. * @returns {Array}
  370. */
  371. processOozieHosts: function (hosts) {
  372. var activeOozieServers = this.get('content.hostComponents')
  373. .filterProperty('componentName', 'OOZIE_SERVER')
  374. .filterProperty('workStatus', 'STARTED')
  375. .mapProperty('hostName');
  376. var oozieHostsArray = hosts.filter(function (host) {
  377. host.status = Em.I18n.t('quick.links.label.active');
  378. return activeOozieServers.contains(host.hostName);
  379. }, this);
  380. if (oozieHostsArray.length == 0)
  381. this.set('quickLinksErrorMessage', Em.I18n.t('quick.links.error.oozie.label'));
  382. return oozieHostsArray;
  383. },
  384. /**
  385. * set status to hosts with NAMENODE
  386. * @param {Array} hosts
  387. * @returns {Array}
  388. */
  389. processHdfsHosts: function (hosts) {
  390. return hosts.map(function (host) {
  391. if (host.hostName === Em.get(this, 'content.activeNameNode.hostName')) {
  392. host.status = Em.I18n.t('quick.links.label.active');
  393. } else if (host.hostName === Em.get(this, 'content.standbyNameNode.hostName')) {
  394. host.status = Em.I18n.t('quick.links.label.standby');
  395. } else if (host.hostName === Em.get(this, 'content.standbyNameNode2.hostName')) {
  396. host.status = Em.I18n.t('quick.links.label.standby');
  397. }
  398. return host;
  399. }, this);
  400. },
  401. /**
  402. * set status to hosts with HBASE_MASTER
  403. * @param {Array} hosts
  404. * @param {object} response
  405. * @returns {Array}
  406. */
  407. processHbaseHosts: function (hosts, response) {
  408. return hosts.map(function (host) {
  409. var isActiveMaster;
  410. response.items.filterProperty('Hosts.host_name', host.hostName).filter(function (item) {
  411. var hbaseMaster = item.host_components.findProperty('HostRoles.component_name', 'HBASE_MASTER');
  412. isActiveMaster = hbaseMaster && Em.get(hbaseMaster, 'metrics.hbase.master.IsActiveMaster');
  413. });
  414. if (isActiveMaster === 'true') {
  415. host.status = Em.I18n.t('quick.links.label.active');
  416. } else if (isActiveMaster === 'false') {
  417. host.status = Em.I18n.t('quick.links.label.standby');
  418. }
  419. return host;
  420. }, this);
  421. },
  422. /**
  423. * set status to hosts with RESOURCEMANAGER
  424. * @param {Array} hosts
  425. * @returns {Array}
  426. */
  427. processYarnHosts: function (hosts) {
  428. return hosts.map(function (host) {
  429. var resourceManager = this.get('content.hostComponents')
  430. .filterProperty('componentName', 'RESOURCEMANAGER')
  431. .findProperty('hostName', host.hostName);
  432. var haStatus = resourceManager && resourceManager.get('haStatus');
  433. if (haStatus === 'ACTIVE') {
  434. host.status = Em.I18n.t('quick.links.label.active');
  435. } else if (haStatus === 'STANDBY') {
  436. host.status = Em.I18n.t('quick.links.label.standby');
  437. }
  438. return host;
  439. }, this);
  440. },
  441. /**
  442. * sets public host names for required masters of current service
  443. * @param {string} serviceName - selected serviceName
  444. * @param {JSON} response
  445. * @returns {Array} containing hostName(s)
  446. * @method getHosts
  447. */
  448. getHosts: function (response, serviceName) {
  449. //The default error message when we cannot obtain the host information for the given service
  450. this.set('quickLinksErrorMessage', Em.I18n.t('quick.links.error.nohosts.label').format(serviceName));
  451. if (App.get('singleNodeInstall')) {
  452. return [{
  453. hostName: App.get('singleNodeAlias'),
  454. publicHostName: App.get('singleNodeAlias')
  455. }];
  456. }
  457. if (Em.isNone(this.get('content.hostComponents'))) {
  458. return [];
  459. }
  460. var hosts = [];
  461. switch (serviceName) {
  462. case 'OOZIE':
  463. hosts = this.processOozieHosts(this.findHosts('OOZIE_SERVER', response));
  464. break;
  465. case "HDFS":
  466. hosts = this.processHdfsHosts(this.findHosts('NAMENODE', response));
  467. break;
  468. case "HBASE":
  469. hosts = this.processHbaseHosts(this.findHosts('HBASE_MASTER', response), response);
  470. break;
  471. case "YARN":
  472. hosts = this.processYarnHosts(this.findHosts('RESOURCEMANAGER', response));
  473. break;
  474. default:
  475. var componentName = App.QuickLinksConfig.ServiceComponentMap[serviceName];
  476. if (componentName) {
  477. hosts = this.findHosts(componentName, response);
  478. } else if (this.getWithDefault('content.hostComponents', []).someProperty('isMaster')) {
  479. hosts = this.findHosts(this.get('content.hostComponents').findProperty('isMaster').get('componentName'), response);
  480. }
  481. break;
  482. }
  483. return hosts;
  484. },
  485. /**
  486. * find host public names
  487. * @param {string} componentName
  488. * @param {object} response
  489. * @returns {Array}
  490. */
  491. findHosts: function (componentName, response) {
  492. var hosts = [];
  493. this.get('content.hostComponents')
  494. .filterProperty('componentName', componentName)
  495. .forEach(function (component) {
  496. var host = this.getPublicHostName(response.items, component.get('hostName'));
  497. if (host) {
  498. hosts.push({
  499. hostName: component.get('hostName'),
  500. publicHostName: host
  501. });
  502. }
  503. }, this);
  504. return hosts;
  505. },
  506. /**
  507. * services that supports security. this array is used to find out protocol.
  508. * besides GANGLIA, YARN, MAPREDUCE2, ACCUMULO. These services use
  509. * their properties to know protocol
  510. */
  511. servicesSupportsHttps: ["HDFS", "HBASE"],
  512. reverseType: function(type){
  513. if("https" === type)
  514. return "http";
  515. else if("http" === type)
  516. return "https"
  517. },
  518. meetDesired: function(configProperties, configType, property, desiredState){
  519. var currentConfig = configProperties.findProperty('type', configType);
  520. var currentPropertyValue = currentConfig.properties[property];
  521. if("NOT_EXIST" === desiredState){
  522. if(currentPropertyValue == null)
  523. return true;
  524. else
  525. return false
  526. } else if("EXIST" === desiredState){
  527. if(currentPropertyValue == null)
  528. return false;
  529. else
  530. return true;
  531. } else {
  532. return (desiredState === currentPropertyValue)
  533. }
  534. },
  535. /**
  536. * setProtocol - if cluster is secure for some services (GANGLIA, MAPREDUCE2, YARN and servicesSupportsHttps)
  537. * protocol becomes "https" otherwise "http" (by default)
  538. * @param {String} serviceName - service name
  539. * @param {Object} configProperties
  540. * @param {Object} ambariProperties
  541. * @returns {string} "https" or "http" only!
  542. * @method setProtocol
  543. * @param item
  544. */
  545. setProtocol: function (configProperties, item) {
  546. var hadoopSslEnabled = false;
  547. if (configProperties && configProperties.length > 0) {
  548. var hdfsSite = configProperties.findProperty('type', 'hdfs-site');
  549. hadoopSslEnabled = (hdfsSite && Em.get(hdfsSite, 'properties') && hdfsSite.properties['dfs.http.policy'] === 'HTTPS_ONLY');
  550. }
  551. var protocolConfig = Em.get(item, 'protocol');
  552. if(!protocolConfig){
  553. if(hadoopSslEnabled)
  554. return "https";
  555. else
  556. return "http";
  557. }
  558. var protocolType = Em.get(protocolConfig, 'type');
  559. if ("HTTPS_ONLY" === protocolType)
  560. return "https";
  561. else if ("HTTP_ONLY" === protocolType)
  562. return "http";
  563. else {
  564. var count = 0;
  565. var checks = Em.get(protocolConfig, 'checks');
  566. if(!checks){
  567. if(hadoopSslEnabled)
  568. return 'https';
  569. else
  570. return 'http';
  571. }
  572. checks.forEach(function(check){
  573. var configType = Em.get(check, 'site');
  574. var property = Em.get(check, 'property');
  575. var desiredState = Em.get(check, 'desired');
  576. var checkMeet = this.meetDesired(configProperties, configType, property, desiredState)
  577. if(!checkMeet){
  578. count++;
  579. }
  580. }, this);
  581. if(count > 0)
  582. return this.reverseType(protocolType);
  583. else
  584. return protocolType;
  585. }
  586. },
  587. /**
  588. * sets the port of quick link
  589. * @param item
  590. * @param protocol
  591. * @param config
  592. * @returns {string}
  593. * @method setPort
  594. */
  595. setPort: function (portConfigs, protocol, configProperties, configPropertyKey) {
  596. var defaultPort = Em.get(portConfigs, protocol+'_default_port');
  597. var portProperty = Em.get(portConfigs, protocol+'_property');
  598. var site = configProperties.findProperty('type', Em.get(portConfigs, 'site'));
  599. var propertyValue = site && site.properties && site.properties[portProperty];
  600. if (!propertyValue)
  601. return defaultPort;
  602. var regexValue = Em.get(portConfigs, 'regex');
  603. regexValue = regexValue.trim();
  604. if(regexValue){
  605. var re = new RegExp(regexValue);
  606. var portValue = propertyValue.match(re);
  607. try {
  608. return portValue[1];
  609. }catch(err) {
  610. return defaultPort;
  611. }
  612. } else {
  613. return propertyValue;
  614. }
  615. }
  616. });