installer.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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.InstallerController = Em.Controller.extend({
  20. name: 'installerController',
  21. isStepDisabled: [],
  22. totalSteps: 10,
  23. init: function () {
  24. this.clusters = App.Cluster.find();
  25. this.isStepDisabled.pushObject(Ember.Object.create({
  26. step: 1,
  27. value: false
  28. }));
  29. for (var i = 2; i <= this.totalSteps; i++) {
  30. this.isStepDisabled.pushObject(Ember.Object.create({
  31. step: i,
  32. value: true
  33. }));
  34. }
  35. // window.onbeforeunload = function () {
  36. // return "You have not saved your document yet. If you continue, your work will not be saved."
  37. //}
  38. },
  39. setStepsEnable: function () {
  40. for (var i = 2; i <= this.totalSteps; i++) {
  41. var step = this.get('isStepDisabled').findProperty('step', i);
  42. if (i <= this.get('currentStep')) {
  43. step.set('value', false);
  44. } else {
  45. step.set('value', true);
  46. }
  47. }
  48. }.observes('currentStep'),
  49. prevInstallStatus: function () {
  50. console.log('Inside the prevInstallStep function: The name is ' + App.router.get('loginController.loginName'));
  51. var result = App.db.isCompleted()
  52. if (result == '1') {
  53. return true;
  54. }
  55. }.property('App.router.loginController.loginName'),
  56. currentStep: function () {
  57. return App.get('router').getInstallerCurrentStep();
  58. }.property(),
  59. clusters: null,
  60. isStep1: function () {
  61. return this.get('currentStep') == 1;
  62. }.property('currentStep'),
  63. isStep2: function () {
  64. return this.get('currentStep') == 2;
  65. }.property('currentStep'),
  66. isStep3: function () {
  67. return this.get('currentStep') == 3;
  68. }.property('currentStep'),
  69. isStep4: function () {
  70. return this.get('currentStep') == 4;
  71. }.property('currentStep'),
  72. isStep5: function () {
  73. return this.get('currentStep') == 5;
  74. }.property('currentStep'),
  75. isStep6: function () {
  76. return this.get('currentStep') == 6;
  77. }.property('currentStep'),
  78. isStep7: function () {
  79. return this.get('currentStep') == 7;
  80. }.property('currentStep'),
  81. isStep8: function () {
  82. return this.get('currentStep') == 8;
  83. }.property('currentStep'),
  84. isStep9: function () {
  85. return this.get('currentStep') == 9;
  86. }.property('currentStep'),
  87. isStep10: function () {
  88. return this.get('currentStep') == 10;
  89. }.property('currentStep'),
  90. gotoStep1: function () {
  91. if (this.get('isStepDisabled').findProperty('step', 1).get('value') === true) {
  92. return;
  93. } else {
  94. App.router.send('gotoStep1');
  95. }
  96. },
  97. gotoStep2: function () {
  98. if (this.get('isStepDisabled').findProperty('step', 2).get('value') === true) {
  99. return;
  100. } else {
  101. App.router.send('gotoStep2');
  102. }
  103. },
  104. gotoStep3: function () {
  105. if (this.get('isStepDisabled').findProperty('step', 3).get('value') === true) {
  106. return;
  107. } else {
  108. App.router.send('gotoStep3');
  109. }
  110. },
  111. gotoStep4: function () {
  112. if (this.get('isStepDisabled').findProperty('step', 4).get('value') === true) {
  113. return;
  114. } else {
  115. App.router.send('gotoStep4');
  116. }
  117. },
  118. gotoStep5: function () {
  119. if (this.get('isStepDisabled').findProperty('step', 5).get('value') === true) {
  120. return;
  121. } else {
  122. App.router.send('gotoStep5');
  123. }
  124. },
  125. gotoStep6: function () {
  126. if (this.get('isStepDisabled').findProperty('step', 6).get('value') === true) {
  127. return;
  128. } else {
  129. App.router.send('gotoStep6');
  130. }
  131. },
  132. gotoStep7: function () {
  133. if (this.get('isStepDisabled').findProperty('step', 7).get('value') === true) {
  134. return;
  135. } else {
  136. App.router.send('gotoStep7');
  137. }
  138. },
  139. gotoStep8: function () {
  140. if (this.get('isStepDisabled').findProperty('step', 8).get('value') === true) {
  141. return;
  142. } else {
  143. App.router.send('gotoStep8');
  144. }
  145. },
  146. gotoStep9: function () {
  147. if (this.get('isStepDisabled').findProperty('step', 9).get('value') === true) {
  148. return;
  149. } else {
  150. App.router.send('gotoStep9');
  151. }
  152. },
  153. gotoStep10: function () {
  154. if (this.get('isStepDisabled').findProperty('step', 10).get('value') === true) {
  155. return;
  156. } else {
  157. App.router.send('gotoStep10');
  158. }
  159. },
  160. /**
  161. *
  162. * @param cluster ClusterModel
  163. */
  164. createCluster: function (cluster) {
  165. alert('created cluster ' + cluster.name);
  166. },
  167. content: Em.Object.create({
  168. cluster: {},
  169. hosts: {},
  170. services: {},
  171. hostsInfo: {},
  172. slaveComponentHosts: {},
  173. hostSlaveComponents: {},
  174. masterComponentHosts: {},
  175. serviceConfigProperties: {}
  176. }),
  177. /**
  178. * Load clusterInfo(step1) to model
  179. */
  180. loadClusterInfo: function () {
  181. var cluster = {
  182. name: App.db.getClusterName(),
  183. status: App.db.getClusterStatus().status,
  184. isCompleted: App.db.getClusterStatus().isCompleted
  185. };
  186. this.set('content.cluster', cluster);
  187. console.log("InstallerController:loadClusterInfo: loaded data ", cluster);
  188. },
  189. /**
  190. * Save all info about claster to model
  191. * @param stepController Step1WizardController
  192. */
  193. saveClusterInfo: function (stepController) {
  194. var cluster = stepController.get('content.cluster');
  195. var clusterStatus = {
  196. status: cluster.status,
  197. isCompleted: cluster.isCompleted
  198. }
  199. App.db.setClusterName(cluster.name);
  200. App.db.setClusterStatus(clusterStatus);
  201. console.log("InstallerController:saveClusterInfo: saved data ", cluster);
  202. //probably next line is extra work - need to check it
  203. this.set('content.cluster', cluster);
  204. },
  205. /**
  206. * Temporary function for wizardStep9, before back-end integration
  207. */
  208. setInfoForStep9: function () {
  209. App.db.setClusterStatus({status: 'pending', isCompleted: false});
  210. var hostInfo = App.db.getHosts();
  211. for (var index in hostInfo) {
  212. hostInfo[index].status = "pending";
  213. hostInfo[index].message = 'Information';
  214. hostInfo[index].progress = '0';
  215. }
  216. App.db.setHosts(hostInfo);
  217. },
  218. /**
  219. * Load all data for <code>Specify Host(install step2)</code> step
  220. * Data Example:
  221. * {
  222. * hostNames: '',
  223. * manualInstall: false,
  224. * sshKey: '',
  225. * passphrase: '',
  226. * confirmPassphrase: '',
  227. * localRepo: false,
  228. * localRepoPath: ''
  229. * }
  230. */
  231. loadInstallOptions: function () {
  232. if (!this.content.hosts) {
  233. this.content.hosts = Em.Object.create();
  234. }
  235. //TODO : rewire it as model. or not :)
  236. var hostsInfo = Em.Object.create();
  237. hostsInfo.hostNames = App.db.getAllHostNames() || ''; //empty string if undefined
  238. //TODO : should we check installType for add host wizard????
  239. var installType = App.db.getInstallType();
  240. //false if installType not equals 'manual'
  241. hostsInfo.manualInstall = installType && installType.installType === 'manual' || false;
  242. var softRepo = App.db.getSoftRepo();
  243. if (softRepo && softRepo.repoType === 'local') {
  244. hostsInfo.localRepo = true;
  245. hostsInfo.localRepopath = softRepo.repoPath;
  246. } else {
  247. hostsInfo.localRepo = false;
  248. hostsInfo.localRepoPath = '';
  249. }
  250. hostsInfo.sshKey = 'random';
  251. hostsInfo.passphrase = '';
  252. hostsInfo.confirmPassphrase = '';
  253. this.set('content.hosts', hostsInfo);
  254. console.log("InstallerController:loadHosts: loaded data ", hostsInfo);
  255. },
  256. /**
  257. * Save data, which user filled, to main controller
  258. * @param stepController App.WizardStep2Controller
  259. */
  260. saveHosts: function (stepController) {
  261. //TODO: put data to content.hosts and only then save it)
  262. //App.db.setBootStatus(false);
  263. App.db.setAllHostNames(stepController.get('hostNames'));
  264. App.db.setHosts(stepController.getHostInfo());
  265. if (stepController.get('manualInstall') === false) {
  266. App.db.setInstallType({installType: 'ambari' });
  267. } else {
  268. App.db.setInstallType({installType: 'manual' });
  269. }
  270. if (stepController.get('localRepo') === false) {
  271. App.db.setSoftRepo({ 'repoType': 'remote', 'repoPath': null});
  272. } else {
  273. App.db.setSoftRepo({ 'repoType': 'local', 'repoPath': stepController.get('localRepoPath') });
  274. }
  275. },
  276. /**
  277. * Return hosts, which were add at <code>Specify Host(step2)</code> step
  278. * @paramm isNew whether return all hosts or only new ones
  279. */
  280. getHostList: function (isNew) {
  281. var hosts = [];
  282. var hostArray = App.db.getHosts()
  283. console.log('in instsllerController.getHostList: host names is ', hostArray);
  284. for (var i in hostArray) {
  285. var hostInfo = App.HostInfo.create({
  286. name: hostArray[i].name,
  287. bootStatus: hostArray[i].bootStatus
  288. });
  289. hosts.pushObject(hostInfo);
  290. }
  291. console.log('TRACE: pushing ' + hosts);
  292. return hosts;
  293. },
  294. /**
  295. * Remove host from model. Used at <code>Confirm hosts(step2)</code> step
  296. * @param hosts Array of hosts, which we want to delete
  297. */
  298. removeHosts: function (hosts) {
  299. //todo Replace this code with real logic
  300. App.db.removeHosts(hosts);
  301. },
  302. /**
  303. * Save data, which user filled, to main controller
  304. * @param stepController App.WizardStep3Controller
  305. */
  306. saveConfirmedHosts: function (stepController) {
  307. var hostInfo = {};
  308. stepController.get('content').forEach(function (_host) {
  309. hostInfo[_host.name] = {
  310. name: _host.name,
  311. cpu: _host.cpu,
  312. memory: _host.memory,
  313. bootStatus: _host.bootStatus
  314. };
  315. });
  316. console.log('installerController:saveConfirmedHosts: save hosts ', hostInfo);
  317. App.db.setHosts(hostInfo);
  318. this.set('content.hostsInfo', hostInfo);
  319. },
  320. /**
  321. * Load confirmed hosts.
  322. * Will be used at <code>Assign Masters(step5)</code> step
  323. */
  324. loadConfirmedHosts: function () {
  325. this.set('content.hostsInfo', App.db.getHosts());
  326. },
  327. /**
  328. * Save data after installation to main controller
  329. * @param stepController App.WizardStep9Controller
  330. */
  331. saveInstalledHosts: function (stepController) {
  332. var hosts = stepController.get('hosts');
  333. var hostInfo = App.db.getHosts();
  334. for (var index in hostInfo) {
  335. hostInfo[index].status = "pending";
  336. var host = hosts.findProperty('name', hostInfo[index].name);
  337. if (host) {
  338. hostInfo[index].status = host.status;
  339. hostInfo[index].message = host.message;
  340. hostInfo[index].progress = host.progress;
  341. }
  342. }
  343. App.db.setHosts(hostInfo);
  344. console.log('installerController:saveInstalledHosts: save hosts ', hostInfo);
  345. },
  346. /**
  347. * Remove all data for hosts
  348. */
  349. clearHosts: function () {
  350. var hosts = this.get('content').get('hosts');
  351. if (hosts) {
  352. hosts.hostNames = '';
  353. hosts.manualInstall = false;
  354. hosts.localRepo = '';
  355. hosts.localRepopath = '';
  356. hosts.sshKey = '';
  357. hosts.passphrase = '';
  358. hosts.confirmPassphrase = '';
  359. }
  360. },
  361. /**
  362. * Load services data. Will be used at <code>Select services(step4)</code> step
  363. */
  364. loadServices: function () {
  365. var servicesInfo = App.db.getService();
  366. servicesInfo.forEach(function (item, index) {
  367. servicesInfo[index] = Em.Object.create(item);
  368. });
  369. this.set('content.services', servicesInfo);
  370. console.log('installerController.loadServices: loaded data ', servicesInfo);
  371. console.log('selected services ', servicesInfo.filterProperty('isSelected', true).mapProperty('serviceName'));
  372. },
  373. /**
  374. * Save data to model
  375. * @param stepController App.WizardStep4Controller
  376. */
  377. saveServices: function (stepController) {
  378. var serviceNames = [];
  379. // we can also do it without stepController since all data,
  380. // changed at page, automatically changes in model(this.content.services)
  381. App.db.setService(stepController.get('content'));
  382. stepController.filterProperty('isSelected', true).forEach(function (item) {
  383. serviceNames.push(item.serviceName);
  384. });
  385. App.db.setSelectedServiceNames(serviceNames);
  386. console.log('installerController.saveServices: saved data ', serviceNames);
  387. },
  388. /**
  389. * Save Master Component Hosts data to Main Controller
  390. * @param stepController App.WizardStep5Controller
  391. */
  392. saveMasterComponentHosts: function (stepController) {
  393. var obj = stepController.get('selectedServicesMasters');
  394. var masterComponentHosts = [];
  395. obj.forEach(function (_component) {
  396. masterComponentHosts.push({
  397. component: _component.component_name,
  398. hostName: _component.selectedHost
  399. });
  400. });
  401. console.log("installerController.saveComponentHosts: saved hosts ", masterComponentHosts);
  402. App.db.setMasterComponentHosts(masterComponentHosts);
  403. this.set('content.masterComponentHosts', masterComponentHosts);
  404. },
  405. /**
  406. * Load master component hosts data for using in required step controllers
  407. */
  408. loadMasterComponentHosts: function () {
  409. var masterComponentHosts = App.db.getMasterComponentHosts();
  410. this.set("content.masterComponentHosts", masterComponentHosts);
  411. console.log("InstallerController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  412. },
  413. /**
  414. * Save slaveHostComponents to main controller
  415. * @param stepController
  416. */
  417. saveSlaveComponentHosts: function (stepController) {
  418. var hosts = stepController.get('hosts');
  419. var isMrSelected = stepController.get('isMrSelected');
  420. var isHbSelected = stepController.get('isHbSelected');
  421. App.db.setHostSlaveComponents(hosts);
  422. this.set('content.hostSlaveComponents', hosts);
  423. var dataNodeHosts = [];
  424. var taskTrackerHosts = [];
  425. var regionServerHosts = [];
  426. hosts.forEach(function (host) {
  427. if (host.get('isDataNode')) {
  428. dataNodeHosts.push({
  429. hostname: host.hostname,
  430. group: 'Default'
  431. });
  432. }
  433. if (isMrSelected && host.get('isTaskTracker')) {
  434. taskTrackerHosts.push({
  435. hostname: host.hostname,
  436. group: 'Default'
  437. });
  438. }
  439. if (isHbSelected && host.get('isRegionServer')) {
  440. regionServerHosts.push({
  441. hostname: host.hostname,
  442. group: 'Default'
  443. });
  444. }
  445. }, this);
  446. var slaveComponentHosts = [];
  447. slaveComponentHosts.push({
  448. componentName: 'DATANODE',
  449. displayName: 'DataNode',
  450. hosts: dataNodeHosts
  451. });
  452. if (isMrSelected) {
  453. slaveComponentHosts.push({
  454. componentName: 'TASKTRACKER',
  455. displayName: 'TaskTracker',
  456. hosts: taskTrackerHosts
  457. });
  458. }
  459. if (isHbSelected) {
  460. slaveComponentHosts.push({
  461. componentName: 'HBASE_REGIONSERVER',
  462. displayName: 'RegionServer',
  463. hosts: regionServerHosts
  464. });
  465. }
  466. App.db.setSlaveComponentHosts(slaveComponentHosts);
  467. this.set('content.slaveComponentHosts', slaveComponentHosts);
  468. },
  469. /**
  470. * Load master component hosts data for using in required step controllers
  471. */
  472. loadSlaveComponentHosts: function () {
  473. var slaveComponentHosts = App.db.getSlaveComponentHosts();
  474. this.set("content.slaveComponentHosts", slaveComponentHosts);
  475. console.log("InstallerController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  476. var hostSlaveComponents = App.db.getHostSlaveComponents();
  477. this.set('content.hostSlaveComponents', hostSlaveComponents);
  478. console.log("InstallerController.loadSlaveComponentHosts: loaded hosts ", hostSlaveComponents);
  479. },
  480. /**
  481. * TODO:
  482. * @param stepController Step7WizardController
  483. */
  484. saveServiceConfigProperties: function (stepController) {
  485. var serviceConfigProperties = [];
  486. stepController.get('stepConfigs').forEach(function (_content) {
  487. _content.get('configs').forEach(function (_configProperties) {
  488. var configProperty = {
  489. name: _configProperties.get('name'),
  490. value: _configProperties.get('value')
  491. };
  492. serviceConfigProperties.push(configProperty);
  493. }, this);
  494. }, this);
  495. App.db.setServiceConfigProperties(serviceConfigProperties);
  496. this.set('content.serviceConfigProperties', serviceConfigProperties);
  497. },
  498. /**
  499. * Load serviceConfigProperties to model
  500. */
  501. loadServiceConfigProperties: function () {
  502. var serviceConfigProperties = App.db.getServiceConfigProperties();
  503. this.set('content.serviceConfigProperties', serviceConfigProperties);
  504. console.log("InstallerController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  505. },
  506. /**
  507. * List of statuses, what data is currently loaded
  508. */
  509. isStepLoaded: {},
  510. /**
  511. * Call specified function only once
  512. */
  513. callLoadFuncOnce: function (name) {
  514. if (!this.isStepLoaded[name]) {
  515. this[name]();
  516. this.isStepLoaded[name] = true;
  517. }
  518. },
  519. /**
  520. * Load data for all steps until <code>current step</code>
  521. */
  522. loadAllPriorSteps: function () {
  523. var step = this.get('currentStep');
  524. switch (step) {
  525. case '9':
  526. //need to call it every time since we preload data in setInfoForStep9
  527. this.loadClusterInfo();
  528. case '8':
  529. this.callLoadFuncOnce('loadClusterInfo');
  530. case '7':
  531. this.callLoadFuncOnce('loadServiceConfigProperties');
  532. case '6':
  533. this.callLoadFuncOnce('loadMasterComponentHosts');
  534. this.callLoadFuncOnce('loadSlaveComponentHosts');
  535. case '5':
  536. this.callLoadFuncOnce('loadConfirmedHosts');
  537. case '4':
  538. this.callLoadFuncOnce('loadServices');
  539. case '3':
  540. case '2':
  541. this.callLoadFuncOnce('loadInstallOptions');
  542. case '1':
  543. this.callLoadFuncOnce('loadClusterInfo');
  544. }
  545. }
  546. });