add_controller.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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.AddHostController = Em.Controller.extend({
  20. name: 'addHostController',
  21. /**
  22. * All wizards data will be stored in this variable
  23. */
  24. content: Em.Object.create(),
  25. /**
  26. * Used for hiding back button in wizard
  27. */
  28. hideBackButton: true,
  29. isStepDisabled: [],
  30. totalSteps: 9,
  31. init: function () {
  32. this.isStepDisabled.pushObject(Ember.Object.create({
  33. step: 1,
  34. value: false
  35. }));
  36. for (var i = 2; i <= this.totalSteps; i++) {
  37. this.isStepDisabled.pushObject(Ember.Object.create({
  38. step: i,
  39. value: true
  40. }));
  41. }
  42. },
  43. setStepsEnable: function () {
  44. for (var i = 2; i <= this.totalSteps; i++) {
  45. var step = this.get('isStepDisabled').findProperty('step', i);
  46. if (i <= this.get('currentStep')) {
  47. step.set('value', false);
  48. } else {
  49. step.set('value', true);
  50. }
  51. }
  52. }.observes('currentStep'),
  53. /**
  54. * Return current step of Add Host Wizard
  55. */
  56. currentStep: function () {
  57. return App.get('router').getWizardCurrentStep('addHost');
  58. }.property(),
  59. /**
  60. * Set current step to new value.
  61. * Method moved from App.router.setInstallerCurrentStep
  62. * @param currentStep
  63. * @param completed
  64. */
  65. setCurrentStep: function (currentStep, completed) {
  66. App.db.setWizardCurrentStep('addHost', currentStep, completed);
  67. this.set('currentStep', currentStep);
  68. },
  69. isStep1: function () {
  70. return this.get('currentStep') == 1;
  71. }.property('currentStep'),
  72. isStep2: function () {
  73. return this.get('currentStep') == 2;
  74. }.property('currentStep'),
  75. isStep3: function () {
  76. return this.get('currentStep') == 3;
  77. }.property('currentStep'),
  78. isStep4: function () {
  79. return this.get('currentStep') == 4;
  80. }.property('currentStep'),
  81. isStep5: function () {
  82. return this.get('currentStep') == 5;
  83. }.property('currentStep'),
  84. isStep6: function () {
  85. return this.get('currentStep') == 6;
  86. }.property('currentStep'),
  87. isStep7: function () {
  88. return this.get('currentStep') == 7;
  89. }.property('currentStep'),
  90. isStep8: function () {
  91. return this.get('currentStep') == 8;
  92. }.property('currentStep'),
  93. isStep9: function () {
  94. return this.get('currentStep') == 9;
  95. }.property('currentStep'),
  96. isStep10: function () {
  97. return this.get('currentStep') == 10;
  98. }.property('currentStep'),
  99. gotoStep: function (step) {
  100. if (this.get('isStepDisabled').findProperty('step', step).get('value') === false) {
  101. App.router.send('gotoStep' + step);
  102. }
  103. },
  104. gotoStep1: function () {
  105. this.gotoStep(1);
  106. },
  107. gotoStep2: function () {
  108. this.gotoStep(2);
  109. },
  110. gotoStep3: function () {
  111. this.gotoStep(3);
  112. },
  113. gotoStep4: function () {
  114. this.gotoStep(4);
  115. },
  116. gotoStep5: function () {
  117. this.gotoStep(5);
  118. },
  119. gotoStep6: function () {
  120. this.gotoStep(6);
  121. },
  122. gotoStep7: function () {
  123. this.gotoStep(7);
  124. },
  125. gotoStep8: function () {
  126. this.gotoStep(8);
  127. },
  128. gotoStep9: function () {
  129. this.gotoStep(9);
  130. },
  131. gotoStep10: function () {
  132. this.gotoStep(10);
  133. },
  134. /**
  135. * Load all data for <code>Specify Host(install step2)</code> step
  136. * Data Example:
  137. * {
  138. * hostNames: '',
  139. * manualInstall: false,
  140. * sshKey: '',
  141. * passphrase: '',
  142. * confirmPassphrase: '',
  143. * localRepo: false,
  144. * localRepoPath: ''
  145. * }
  146. */
  147. loadInstallOptions: function () {
  148. if (!this.content.hosts) {
  149. this.content.hosts = Em.Object.create();
  150. }
  151. //TODO : rewire it as model. or not :)
  152. var hostsInfo = Em.Object.create();
  153. hostsInfo.hostNames = App.db.getAllHostNames() || ''; //empty string if undefined
  154. //TODO : should we check installType for add host wizard????
  155. var installType = App.db.getInstallType();
  156. //false if installType not equals 'manual'
  157. hostsInfo.manualInstall = installType && installType.installType === 'manual' || false;
  158. var softRepo = App.db.getSoftRepo();
  159. if (softRepo && softRepo.repoType === 'local') {
  160. hostsInfo.localRepo = true;
  161. hostsInfo.localRepopath = softRepo.repoPath;
  162. } else {
  163. hostsInfo.localRepo = false;
  164. hostsInfo.localRepoPath = '';
  165. }
  166. hostsInfo.sshKey = 'random';
  167. hostsInfo.passphrase = '';
  168. hostsInfo.confirmPassphrase = '';
  169. this.set('content.hosts', hostsInfo);
  170. console.log("AddHostController:loadHosts: loaded data ", hostsInfo);
  171. },
  172. /**
  173. * Save data, which user filled, to main controller
  174. * @param stepController App.WizardStep2Controller
  175. */
  176. saveHosts: function (stepController) {
  177. //TODO: put data to content.hosts and only then save it)
  178. //App.db.setBootStatus(false);
  179. App.db.setAllHostNames(stepController.get('hostNames'));
  180. App.db.setHosts(stepController.getHostInfo());
  181. if (stepController.get('manualInstall') === false) {
  182. App.db.setInstallType({installType: 'ambari' });
  183. } else {
  184. App.db.setInstallType({installType: 'manual' });
  185. }
  186. if (stepController.get('localRepo') === false) {
  187. App.db.setSoftRepo({ 'repoType': 'remote', 'repoPath': null});
  188. } else {
  189. App.db.setSoftRepo({ 'repoType': 'local', 'repoPath': stepController.get('localRepoPath') });
  190. }
  191. },
  192. /**
  193. * Return hosts, which were add at <code>Specify Host(step2)</code> step
  194. * @paramm isNew whether return all hosts or only new ones
  195. */
  196. getHostList: function (isNew) {
  197. var hosts = [];
  198. var hostArray = App.db.getHosts()
  199. console.log('in addHostController.getHostList: host names is ', hostArray);
  200. for (var i in hostArray) {
  201. var hostInfo = App.HostInfo.create({
  202. name: hostArray[i].name,
  203. bootStatus: hostArray[i].bootStatus
  204. });
  205. hosts.pushObject(hostInfo);
  206. };
  207. console.log('TRACE: pushing ' + hosts);
  208. return hosts;
  209. },
  210. /**
  211. * Remove host from model. Used at <code>Confirm hosts(step2)</code> step
  212. * @param hosts Array of hosts, which we want to delete
  213. */
  214. removeHosts: function (hosts) {
  215. //todo Replace this code with real logic
  216. App.db.removeHosts(hosts);
  217. },
  218. /**
  219. * Save data, which user filled, to main controller
  220. * @param stepController App.WizardStep3Controller
  221. */
  222. saveConfirmedHosts: function (stepController) {
  223. var hostInfo = {};
  224. stepController.get('content').forEach(function (_host) {
  225. hostInfo[_host.name] = {
  226. name: _host.name,
  227. cpu: _host.cpu,
  228. memory: _host.memory,
  229. bootStatus: _host.bootStatus
  230. };
  231. });
  232. console.log('addHostController:saveConfirmedHosts: save hosts ', hostInfo);
  233. App.db.setHosts(hostInfo);
  234. this.set('content.hostsInfo', hostInfo);
  235. },
  236. /**
  237. * Load confirmed hosts.
  238. * Will be used at <code>Assign Masters(step5)</code> step
  239. */
  240. loadConfirmedHosts : function(){
  241. this.set('content.hostsInfo', App.db.getHosts());
  242. },
  243. /**
  244. * Remove all data for hosts
  245. */
  246. clearHosts: function () {
  247. var hosts = this.get('content').get('hosts');
  248. if (hosts) {
  249. hosts.hostNames = '';
  250. hosts.manualInstall = false;
  251. hosts.localRepo = '';
  252. hosts.localRepopath = '';
  253. hosts.sshKey = '';
  254. hosts.passphrase = '';
  255. hosts.confirmPassphrase = '';
  256. }
  257. },
  258. /**
  259. * Load services data. Will be used at <code>Select services(step4)</code> step
  260. */
  261. loadServices: function () {
  262. var servicesInfo = App.db.getService();
  263. servicesInfo.forEach(function (item, index) {
  264. servicesInfo[index] = Em.Object.create(item);
  265. });
  266. this.set('content.services', servicesInfo);
  267. console.log('addHostController.loadServices: loaded data ', servicesInfo);
  268. console.log('selected services ', servicesInfo.filterProperty('isSelected', true).mapProperty('serviceName'));
  269. },
  270. /**
  271. * Save data to model
  272. * @param stepController App.WizardStep4Controller
  273. */
  274. saveServices: function (stepController) {
  275. var serviceNames = [];
  276. // we can also do it without stepController since all data,
  277. // changed at page, automatically changes in model(this.content.services)
  278. App.db.setService(stepController.get('content'));
  279. stepController.filterProperty('isSelected', true).forEach(function (item) {
  280. serviceNames.push(item.serviceName);
  281. });
  282. App.db.setSelectedServiceNames(serviceNames);
  283. console.log('addHostController.saveServices: saved data ', serviceNames);
  284. },
  285. /**
  286. * Save Master Component Hosts data to Main Controller
  287. * @param stepController App.WizardStep5Controller
  288. */
  289. saveMasterComponentHosts: function (stepController) {
  290. var obj = stepController.get('selectedServicesMasters');
  291. var masterComponentHosts = [];
  292. obj.forEach(function (_component) {
  293. masterComponentHosts.push({
  294. component: _component.component_name,
  295. hostName: _component.selectedHost
  296. });
  297. });
  298. console.log("AddHostController.saveComponentHosts: saved hosts ", masterComponentHosts);
  299. App.db.setMasterComponentHosts(masterComponentHosts);
  300. this.set('content.masterComponentHosts', masterComponentHosts);
  301. },
  302. /**
  303. * Load master component hosts data for using in required step controllers
  304. */
  305. loadMasterComponentHosts: function () {
  306. var masterComponentHosts = App.db.getMasterComponentHosts();
  307. this.set("content.masterComponentHosts", masterComponentHosts);
  308. console.log("AddHostController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  309. },
  310. /**
  311. * Save slaveHostComponents to main controller
  312. * @param stepController
  313. */
  314. saveSlaveComponentHosts : function(stepController){
  315. var hosts = stepController.get('hosts');
  316. var isMrSelected = stepController.get('isMrSelected');
  317. var isHbSelected = stepController.get('isHbSelected');
  318. App.db.setHostSlaveComponents(hosts);
  319. this.set('content.hostSlaveComponents', hosts);
  320. var dataNodeHosts = [];
  321. var taskTrackerHosts = [];
  322. var regionServerHosts = [];
  323. hosts.forEach(function (host) {
  324. if (host.get('isDataNode')) {
  325. dataNodeHosts.push({
  326. hostname: host.hostname,
  327. group: 'Default'
  328. });
  329. }
  330. if (isMrSelected && host.get('isTaskTracker')) {
  331. taskTrackerHosts.push({
  332. hostname: host.hostname,
  333. group: 'Default'
  334. });
  335. }
  336. if (isHbSelected && host.get('isRegionServer')) {
  337. regionServerHosts.push({
  338. hostname: host.hostname,
  339. group: 'Default'
  340. });
  341. }
  342. }, this);
  343. var slaveComponentHosts = [];
  344. slaveComponentHosts.push({
  345. componentName: 'DATANODE',
  346. displayName: 'DataNode',
  347. hosts: dataNodeHosts
  348. });
  349. if (isMrSelected) {
  350. slaveComponentHosts.push({
  351. componentName: 'TASKTRACKER',
  352. displayName: 'TaskTracker',
  353. hosts: taskTrackerHosts
  354. });
  355. }
  356. if (isHbSelected) {
  357. slaveComponentHosts.push({
  358. componentName: 'HBASE_REGIONSERVER',
  359. displayName: 'RegionServer',
  360. hosts: regionServerHosts
  361. });
  362. }
  363. App.db.setSlaveComponentHosts(slaveComponentHosts);
  364. this.set('content.slaveComponentHosts', slaveComponentHosts);
  365. },
  366. /**
  367. * Load data for all steps until <code>current step</code>
  368. */
  369. loadAllPriorSteps: function () {
  370. var step = this.get('currentStep');
  371. switch (step) {
  372. case '7':
  373. //current
  374. case '6':
  375. //Sasha
  376. case '5':
  377. this.loadMasterComponentHosts();
  378. case '4':
  379. this.loadConfirmedHosts();
  380. case '3':
  381. this.loadServices();
  382. case '2':
  383. case '1':
  384. this.loadInstallOptions();
  385. }
  386. },
  387. /**
  388. * Remove all loaded data.
  389. * Created as copy for App.router.clearAllSteps
  390. */
  391. clearAllSteps: function () {
  392. this.clearHosts();
  393. }
  394. });