step5_controller.js 22 KB

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