step5_controller.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  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. App.WizardStep5Controller = Em.Controller.extend({
  20. name:"wizardStep5Controller",
  21. title: function () {
  22. if (this.get('content.controllerName') == 'reassignMasterController') {
  23. return Em.I18n.t('installer.step5.reassign.header');
  24. }
  25. return Em.I18n.t('installer.step5.header');
  26. }.property('content.controllerName'),
  27. isReassignWizard: function () {
  28. return this.get('content.controllerName') == 'reassignMasterController';
  29. }.property(),
  30. isReassignHive: function () {
  31. return this.get('servicesMasters').objectAt(0) && this.get('servicesMasters').objectAt(0).component_name == 'HIVE_SERVER' && this.get('isReassignWizard');
  32. }.property('isReassignWizard', 'servicesMasters'),
  33. hosts:[],
  34. servicesMasters:[],
  35. selectedServicesMasters:[],
  36. components:require('data/service_components'),
  37. clearStep:function () {
  38. this.set('hosts', []);
  39. this.set('selectedServicesMasters', []);
  40. this.set('servicesMasters', []);
  41. },
  42. loadStep:function () {
  43. console.log("WizardStep5Controller: Loading step5: Assign Masters");
  44. this.clearStep();
  45. this.renderHostInfo();
  46. this.renderComponents(this.loadComponents());
  47. this.updateComponent('ZOOKEEPER_SERVER');
  48. this.updateComponent('HBASE_MASTER');
  49. if (!this.get("selectedServicesMasters").filterProperty('isInstalled', false).length) {
  50. console.log('no master components to add');
  51. App.router.send('next');
  52. }
  53. },
  54. /**
  55. * Used to set showAddControl flag for ZOOKEEPER_SERVER and HBASE_SERVER
  56. */
  57. updateComponent: function(componentName){
  58. var component = this.last(componentName);
  59. var services = this.get('content.services').filterProperty('isInstalled', true).mapProperty('serviceName');
  60. var currentService = componentName.split('_')[0];
  61. var showControl = !services.contains(currentService);
  62. if (component) {
  63. if(showControl){
  64. if (this.get("selectedServicesMasters").filterProperty("component_name", componentName).length < this.get("hosts.length") && !this.get('isReassignWizard')) {
  65. component.set('showAddControl', true);
  66. } else {
  67. component.set('showRemoveControl', false);
  68. }
  69. }
  70. this.rebalanceComponentHosts(componentName);
  71. }
  72. },
  73. /**
  74. * Load active host list to <code>hosts</code> variable
  75. */
  76. renderHostInfo:function () {
  77. var hostInfo = this.get('content.hosts');
  78. var result = [];
  79. for (var index in hostInfo) {
  80. var _host = hostInfo[index];
  81. if (_host.bootStatus === 'REGISTERED') {
  82. result.push(Ember.Object.create({
  83. host_name:_host.name,
  84. cpu:_host.cpu,
  85. memory:_host.memory,
  86. disk_info:_host.disk_info,
  87. host_info: Em.I18n.t('installer.step5.hostInfo').fmt(_host.name, (_host.memory * 1024).bytesToSize(1, 'parseFloat'), _host.cpu)
  88. }));
  89. }
  90. }
  91. this.set("hosts", result);
  92. },
  93. /**
  94. * Load services info to appropriate variable and return masterComponentHosts
  95. * @return Array
  96. */
  97. loadComponents:function () {
  98. var services = this.get('content.services')
  99. .filterProperty('isSelected', true).mapProperty('serviceName'); //list of shown services
  100. var masterComponents = this.get('components').filterProperty('isMaster', true); //get full list from mock data
  101. var masterHosts = this.get('content.masterComponentHosts'); //saved to local storage info
  102. var resultComponents = [];
  103. var servicesLength = services.length;
  104. for (var index = 0; index < servicesLength; index++) {
  105. var componentInfo = masterComponents.filterProperty('service_name', services[index]);
  106. componentInfo.forEach(function (_componentInfo) {
  107. if (_componentInfo.component_name == 'ZOOKEEPER_SERVER' || _componentInfo.component_name == 'HBASE_MASTER') {
  108. var savedComponents = masterHosts.filterProperty('component', _componentInfo.component_name);
  109. if (savedComponents.length) {
  110. savedComponents.forEach(function (item) {
  111. var zooKeeperHost = {};
  112. zooKeeperHost.display_name = _componentInfo.display_name;
  113. zooKeeperHost.component_name = _componentInfo.component_name;
  114. zooKeeperHost.selectedHost = item.hostName;
  115. zooKeeperHost.availableHosts = [];
  116. zooKeeperHost.serviceId = services[index];
  117. zooKeeperHost.isInstalled = item.isInstalled;
  118. zooKeeperHost.isHiveCoHost = false;
  119. resultComponents.push(zooKeeperHost);
  120. })
  121. } else {
  122. var zooHosts = this.selectHost(_componentInfo.component_name);
  123. zooHosts.forEach(function (_host) {
  124. var zooKeeperHost = {};
  125. zooKeeperHost.display_name = _componentInfo.display_name;
  126. zooKeeperHost.component_name = _componentInfo.component_name;
  127. zooKeeperHost.selectedHost = _host;
  128. zooKeeperHost.availableHosts = [];
  129. zooKeeperHost.serviceId = services[index];
  130. zooKeeperHost.isInstalled = false;
  131. zooKeeperHost.isHiveCoHost = false;
  132. resultComponents.push(zooKeeperHost);
  133. });
  134. }
  135. } else {
  136. var savedComponent = masterHosts.findProperty('component', _componentInfo.component_name);
  137. var componentObj = {};
  138. componentObj.component_name = _componentInfo.component_name;
  139. componentObj.display_name = _componentInfo.display_name;
  140. componentObj.selectedHost = savedComponent ? savedComponent.hostName : this.selectHost(_componentInfo.component_name); // call the method that plays selectNode algorithm or fetches from server
  141. componentObj.isInstalled = savedComponent ? savedComponent.isInstalled : App.HostComponent.find().someProperty('componentName', _componentInfo.component_name);
  142. componentObj.serviceId = services[index];
  143. componentObj.availableHosts = [];
  144. componentObj.isHiveCoHost = ['HIVE_METASTORE', 'WEBHCAT_SERVER'].contains(_componentInfo.component_name) && !this.get('isReassignWizard');
  145. resultComponents.push(componentObj);
  146. }
  147. }, this);
  148. }
  149. return resultComponents;
  150. },
  151. /**
  152. * Put master components to <code>selectedServicesMasters</code>, which will be automatically rendered in template
  153. * @param masterComponents
  154. */
  155. renderComponents:function (masterComponents) {
  156. var services = this.get('content.services')
  157. .filterProperty('isInstalled', true).mapProperty('serviceName'); //list of shown services
  158. var showRemoveControlZk = !services.contains('ZOOKEEPER') && masterComponents.filterProperty('display_name', 'ZooKeeper').length > 1;
  159. var showRemoveControlHb = !services.contains('HBASE') && masterComponents.filterProperty('component_name', 'HBASE_MASTER').length > 1;
  160. var zid = 1;
  161. var hid = 1;
  162. var result = [];
  163. masterComponents.forEach(function (item) {
  164. var componentObj = Ember.Object.create(item);
  165. console.log("TRACE: render master component name is: " + item.component_name);
  166. if (item.display_name === "ZooKeeper") {
  167. componentObj.set('zId', zid++);
  168. componentObj.set("showRemoveControl", showRemoveControlZk);
  169. } else if(item.component_name === "HBASE_MASTER"){
  170. componentObj.set('zId', hid++);
  171. componentObj.set("showRemoveControl", showRemoveControlHb);
  172. }
  173. componentObj.set("availableHosts", this.get("hosts"));
  174. result.push(componentObj);
  175. }, this);
  176. this.set("selectedServicesMasters", result);
  177. if (this.get('isReassignWizard')) {
  178. var components = result.filterProperty('component_name', this.get('content.reassign.component_name'));
  179. components.setEach('isInstalled', false);
  180. this.set('servicesMasters', components);
  181. } else {
  182. this.set('servicesMasters', result);
  183. }
  184. },
  185. hasHiveServer: function () {
  186. return !!this.get('selectedServicesMasters').findProperty('component_name', 'HIVE_SERVER') && !this.get('isReassignWizard');
  187. }.property('selectedServicesMasters'),
  188. updateHiveCoHosts: function () {
  189. var hiveServer = this.get('selectedServicesMasters').findProperty('component_name', 'HIVE_SERVER');
  190. var hiveMetastore = this.get('selectedServicesMasters').findProperty('component_name', 'HIVE_METASTORE');
  191. var webHCatServer = this.get('selectedServicesMasters').findProperty('component_name', 'WEBHCAT_SERVER');
  192. if (hiveServer && hiveMetastore && webHCatServer) {
  193. if (!this.get('isReassignHive') && this.get('servicesMasters').objectAt(0) && !this.get('servicesMasters').objectAt(0).component_name == 'HIVE_METASTORE') {
  194. this.get('selectedServicesMasters').findProperty('component_name', 'HIVE_METASTORE').set('selectedHost', hiveServer.get('selectedHost'))
  195. }
  196. this.get('selectedServicesMasters').findProperty('component_name', 'WEBHCAT_SERVER').set('selectedHost', hiveServer.get('selectedHost'));
  197. }
  198. }.observes('selectedServicesMasters.@each.selectedHost'),
  199. getKerberosServer:function (noOfHosts) {
  200. var hosts = this.get('hosts');
  201. if (noOfHosts === 1) {
  202. return hosts[0];
  203. } else if (noOfHosts < 3) {
  204. return hosts[1];
  205. } else if (noOfHosts <= 5) {
  206. return hosts[1];
  207. } else if (noOfHosts <= 30) {
  208. return hosts[3];
  209. } else {
  210. return hosts[5];
  211. }
  212. },
  213. getNameNode:function (noOfHosts) {
  214. var hosts = this.get('hosts');
  215. return hosts[0];
  216. },
  217. getSNameNode:function (noOfHosts) {
  218. var hosts = this.get('hosts');
  219. if (noOfHosts === 1) {
  220. return hosts[0];
  221. } else {
  222. return hosts[1];
  223. }
  224. },
  225. getJobTracker:function (noOfHosts) {
  226. var hosts = this.get('hosts');
  227. if (noOfHosts === 1) {
  228. return hosts[0];
  229. } else if (noOfHosts < 3) {
  230. return hosts[1];
  231. } else if (noOfHosts <= 5) {
  232. return hosts[1];
  233. } else if (noOfHosts <= 30) {
  234. return hosts[1];
  235. } else {
  236. return hosts[2];
  237. }
  238. },
  239. getHBaseMaster:function (noOfHosts) {
  240. var hosts = this.get('hosts');
  241. if (noOfHosts === 1) {
  242. return hosts[0];
  243. } else if (noOfHosts < 3) {
  244. return hosts[0];
  245. } else if (noOfHosts <= 5) {
  246. return hosts[0];
  247. } else if (noOfHosts <= 30) {
  248. return hosts[2];
  249. } else {
  250. return hosts[3];
  251. }
  252. },
  253. getOozieServer:function (noOfHosts) {
  254. var hosts = this.get('hosts');
  255. if (noOfHosts === 1) {
  256. return hosts[0];
  257. } else if (noOfHosts < 3) {
  258. return hosts[1];
  259. } else if (noOfHosts <= 5) {
  260. return hosts[1];
  261. } else if (noOfHosts <= 30) {
  262. return hosts[2];
  263. } else {
  264. return hosts[3];
  265. }
  266. },
  267. getHiveServer:function (noOfHosts) {
  268. var hosts = this.get('hosts');
  269. if (noOfHosts === 1) {
  270. return hosts[0];
  271. } else if (noOfHosts < 3) {
  272. return hosts[1];
  273. } else if (noOfHosts <= 5) {
  274. return hosts[1];
  275. } else if (noOfHosts <= 30) {
  276. return hosts[2];
  277. } else {
  278. return hosts[4];
  279. }
  280. },
  281. getHueServer:function (noOfHosts) {
  282. var hosts = this.get('hosts');
  283. var hostnames = [];
  284. var inc = 0;
  285. hosts.forEach(function (_hostname) {
  286. hostnames[inc] = _hostname.host_name;
  287. inc++;
  288. });
  289. var hostExcAmbari = hostnames.without(location.hostname);
  290. if (noOfHosts > 1) {
  291. return hostExcAmbari[0];
  292. } else {
  293. return hostnames[0];
  294. }
  295. },
  296. getHiveMetastore:function (noOfHosts) {
  297. return this.getHiveServer(noOfHosts);
  298. },
  299. getWebHCatServer:function (noOfHosts) {
  300. return this.getHiveServer(noOfHosts);
  301. },
  302. getZooKeeperServer:function (noOfHosts) {
  303. var hosts = this.get('hosts');
  304. if (noOfHosts < 3) {
  305. return [hosts[0].host_name];
  306. } else {
  307. return [hosts[0].host_name, hosts[1].host_name, hosts[2].host_name];
  308. }
  309. },
  310. getGangliaServer:function (noOfHosts) {
  311. var hosts = this.get('hosts');
  312. var hostnames = [];
  313. var inc = 0;
  314. hosts.forEach(function (_hostname) {
  315. hostnames[inc] = _hostname.host_name;
  316. inc++;
  317. });
  318. var hostExcAmbari = hostnames.without(location.hostname);
  319. if (noOfHosts > 1) {
  320. return hostExcAmbari[0];
  321. } else {
  322. return hostnames[0];
  323. }
  324. },
  325. getNagiosServer:function (noOfHosts) {
  326. var hosts = this.get('hosts');
  327. var hostnames = [];
  328. var inc = 0;
  329. hosts.forEach(function (_hostname) {
  330. hostnames[inc] = _hostname.host_name;
  331. inc++;
  332. });
  333. var hostExcAmbari = hostnames.without(location.hostname);
  334. if (noOfHosts > 1) {
  335. return hostExcAmbari[0];
  336. } else {
  337. return hostnames[0];
  338. }
  339. },
  340. /**
  341. * Return hostName of masterNode for specified service
  342. * @param componentName
  343. * @return {*}
  344. */
  345. selectHost:function (componentName) {
  346. var noOfHosts = this.get('hosts').length;
  347. switch (componentName) {
  348. case 'KERBEROS_SERVER':
  349. return this.getKerberosServer(noOfHosts).host_name;
  350. case 'NAMENODE':
  351. return this.getNameNode(noOfHosts).host_name;
  352. case 'SECONDARY_NAMENODE':
  353. return this.getSNameNode(noOfHosts).host_name;
  354. case 'JOBTRACKER':
  355. return this.getJobTracker(noOfHosts).host_name;
  356. case 'HBASE_MASTER':
  357. return [this.getHBaseMaster(noOfHosts).host_name];
  358. case 'OOZIE_SERVER':
  359. return this.getOozieServer(noOfHosts).host_name;
  360. case 'HIVE_SERVER':
  361. return this.getHiveServer(noOfHosts).host_name;
  362. case 'HIVE_METASTORE':
  363. return this.getHiveMetastore(noOfHosts).host_name;
  364. case 'WEBHCAT_SERVER':
  365. return this.getWebHCatServer(noOfHosts).host_name;
  366. case 'ZOOKEEPER_SERVER':
  367. return this.getZooKeeperServer(noOfHosts);
  368. case 'GANGLIA_SERVER':
  369. return this.getGangliaServer(noOfHosts);
  370. case 'NAGIOS_SERVER':
  371. return this.getNagiosServer(noOfHosts);
  372. case 'HUE_SERVER':
  373. return this.getHueServer(noOfHosts);
  374. }
  375. },
  376. masterHostMapping:function () {
  377. var mapping = [], mappingObject, self = this, mappedHosts, hostObj, hostInfo;
  378. //get the unique assigned hosts and find the master services assigned to them
  379. mappedHosts = this.get("selectedServicesMasters").mapProperty("selectedHost").uniq();
  380. mappedHosts.forEach(function (item) {
  381. hostObj = self.get("hosts").findProperty("host_name", item);
  382. console.log("Name of the host is: " + hostObj.host_name);
  383. mappingObject = Ember.Object.create({
  384. host_name:item,
  385. hostInfo:hostObj.host_info,
  386. masterServices:self.get("selectedServicesMasters").filterProperty("selectedHost", item)
  387. });
  388. mapping.pushObject(mappingObject);
  389. }, this);
  390. mapping.sort(this.sortHostsByName);
  391. return mapping;
  392. }.property("selectedServicesMasters.@each.selectedHost"),
  393. remainingHosts:function () {
  394. return (this.get("hosts.length") - this.get("masterHostMapping.length"));
  395. }.property("selectedServicesMasters.@each.selectedHost"),
  396. //methods
  397. getAvailableHosts:function (componentName) {
  398. var selectedHosts = this.get("selectedServicesMasters").filterProperty("component_name", componentName).mapProperty("selectedHost").uniq();
  399. return this.get('hosts').filter(function(item){
  400. return !selectedHosts.contains(item.get("host_name"));
  401. });
  402. },
  403. /**
  404. * On change callback for selects
  405. * @param componentName
  406. * @param selectedHost
  407. * @param zId
  408. */
  409. assignHostToMaster:function (componentName, selectedHost, zId) {
  410. if (selectedHost && componentName) {
  411. if (zId) {
  412. this.get('selectedServicesMasters').filterProperty('component_name', componentName).findProperty("zId", zId).set("selectedHost", selectedHost);
  413. this.rebalanceComponentHosts(componentName);
  414. } else {
  415. this.get('selectedServicesMasters').findProperty("component_name", componentName).set("selectedHost", selectedHost);
  416. }
  417. }
  418. },
  419. /**
  420. * Returns last component of selected type
  421. * @param componentName
  422. * @return {*}
  423. */
  424. last: function(componentName){
  425. return this.get("selectedServicesMasters").filterProperty("component_name", componentName).get("lastObject");
  426. },
  427. /**
  428. * Add new component to ZooKeeper Server and Hbase master
  429. * @param componentName
  430. * @return {Boolean}
  431. */
  432. addComponent:function (componentName) {
  433. /*
  434. *Logic: If ZooKeeper service is selected then there can be
  435. * minimum 1 ZooKeeper master in total, and
  436. * maximum 1 ZooKeeper on every host
  437. */
  438. var maxNumZooKeepers = this.get("hosts.length"),
  439. currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  440. newZookeeper = null,
  441. zookeeperHosts = null,
  442. suggestedHost = null,
  443. i = 0,
  444. lastZoo = null;
  445. if (!currentZooKeepers.length) {
  446. console.log('ALERT: Zookeeper service was not selected');
  447. return false;
  448. }
  449. if (currentZooKeepers.get("length") < maxNumZooKeepers) {
  450. currentZooKeepers.set("lastObject.showAddControl", false);
  451. currentZooKeepers.set("lastObject.showRemoveControl", true);
  452. //create a new zookeeper based on an existing one
  453. newZookeeper = Ember.Object.create({});
  454. lastZoo = currentZooKeepers.get("lastObject");
  455. newZookeeper.set("display_name", lastZoo.get("display_name"));
  456. newZookeeper.set("component_name", lastZoo.get("component_name"));
  457. newZookeeper.set("selectedHost", lastZoo.get("selectedHost"));
  458. newZookeeper.set("availableHosts", this.getAvailableHosts(componentName));
  459. if (currentZooKeepers.get("length") === (maxNumZooKeepers - 1)) {
  460. newZookeeper.set("showAddControl", false);
  461. } else {
  462. newZookeeper.set("showAddControl", true);
  463. }
  464. newZookeeper.set("showRemoveControl", true);
  465. //get recommended host for the new Zookeeper server
  466. zookeeperHosts = currentZooKeepers.mapProperty("selectedHost").uniq();
  467. for (i = 0; i < this.get("hosts.length"); i++) {
  468. if (!(zookeeperHosts.contains(this.get("hosts")[i].get("host_name")))) {
  469. suggestedHost = this.get("hosts")[i].get("host_name");
  470. break;
  471. }
  472. }
  473. newZookeeper.set("selectedHost", suggestedHost);
  474. newZookeeper.set("zId", (currentZooKeepers.get("lastObject.zId") + 1));
  475. this.get("selectedServicesMasters").insertAt(this.get("selectedServicesMasters").indexOf(lastZoo) + 1, newZookeeper);
  476. if(componentName == 'ZOOKEEPER_SERVER' || componentName == 'HBASE_MASTER'){
  477. this.rebalanceComponentHosts(componentName);
  478. }
  479. return true;
  480. }
  481. return false;//if no more zookeepers can be added
  482. },
  483. /**
  484. * Remove component from ZooKeeper server or Hbase Master
  485. * @param componentName
  486. * @param zId
  487. * @return {Boolean}
  488. */
  489. removeComponent:function (componentName, zId) {
  490. var currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", componentName)
  491. //work only if the Zookeeper service is selected in previous step
  492. if (!currentZooKeepers.length) {
  493. return false;
  494. }
  495. if (currentZooKeepers.get("length") > 1) {
  496. this.get("selectedServicesMasters").removeAt(this.get("selectedServicesMasters").indexOf(currentZooKeepers.findProperty("zId", zId)));
  497. currentZooKeepers = this.get("selectedServicesMasters").filterProperty("component_name", componentName);
  498. if (currentZooKeepers.get("length") < this.get("hosts.length")) {
  499. currentZooKeepers.set("lastObject.showAddControl", true);
  500. }
  501. if (currentZooKeepers.get("length") === 1) {
  502. currentZooKeepers.set("lastObject.showRemoveControl", false);
  503. }
  504. if(componentName == 'ZOOKEEPER_SERVER' || componentName == 'HBASE_MASTER'){
  505. this.rebalanceComponentHosts(componentName);
  506. }
  507. return true;
  508. }
  509. return false;
  510. },
  511. rebalanceComponentHosts:function (componentName) {
  512. //for a zookeeper and hbase update the available hosts for the other zookeepers and hbases
  513. var currentComponents = this.get("selectedServicesMasters").filterProperty("component_name", componentName),
  514. componentHosts = currentComponents.mapProperty("selectedHost"),
  515. availableComponentHosts = [],
  516. preparedAvailableHosts = null;
  517. //get all hosts available for zookeepers
  518. this.get("hosts").forEach(function (item) {
  519. if (!componentHosts.contains(item.get("host_name"))) {
  520. availableComponentHosts.pushObject(item);
  521. }
  522. }, this);
  523. currentComponents.forEach(function (item) {
  524. preparedAvailableHosts = availableComponentHosts.slice(0);
  525. preparedAvailableHosts.pushObject(this.get("hosts").findProperty("host_name", item.get("selectedHost")))
  526. preparedAvailableHosts.sort(this.sortHostsByConfig, this);
  527. item.set("availableHosts", preparedAvailableHosts);
  528. }, this);
  529. },
  530. sortHostsByConfig:function (a, b) {
  531. //currently handling only total memory on the host
  532. if (a.memory < b.memory) {
  533. return 1;
  534. }
  535. else {
  536. return -1;
  537. }
  538. },
  539. sortHostsByName:function (a, b) {
  540. if (a.host_name > b.host_name) {
  541. return 1;
  542. }
  543. else {
  544. return -1;
  545. }
  546. }
  547. });