installer.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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: null,
  169. hosts: null,
  170. services: null,
  171. hostsInfo: null,
  172. slaveComponentHosts: null,
  173. hostSlaveComponents: null,
  174. masterComponentHosts: null,
  175. hostToMasterComponent : null,
  176. serviceConfigProperties: null
  177. }),
  178. /**
  179. * Load clusterInfo(step1) to model
  180. */
  181. loadClusterInfo: function () {
  182. var cStatus = App.db.getClusterStatus() || {status: "", isCompleted: false};
  183. var cluster = {
  184. name: App.db.getClusterName() || "",
  185. status: cStatus.status,
  186. isCompleted: cStatus.isCompleted
  187. };
  188. this.set('content.cluster', cluster);
  189. console.log("InstallerController:loadClusterInfo: loaded data ", cluster);
  190. },
  191. /**
  192. * Save all info about claster to model
  193. * @param stepController Step1WizardController
  194. */
  195. saveClusterInfo: function (stepController) {
  196. var cluster = stepController.get('content.cluster');
  197. var clusterStatus = {
  198. status: cluster.status,
  199. isCompleted: cluster.isCompleted
  200. }
  201. App.db.setClusterName(cluster.name);
  202. App.db.setClusterStatus(clusterStatus);
  203. console.log("InstallerController:saveClusterInfo: saved data ", cluster);
  204. //probably next line is extra work - need to check it
  205. this.set('content.cluster', cluster);
  206. },
  207. /**
  208. * Temporary function for wizardStep9, before back-end integration
  209. */
  210. setInfoForStep9: function () {
  211. App.db.setClusterStatus({status: 'pending', isCompleted: false});
  212. var hostInfo = App.db.getHosts();
  213. for (var index in hostInfo) {
  214. hostInfo[index].status = "pending";
  215. hostInfo[index].message = 'Information';
  216. hostInfo[index].progress = '0';
  217. }
  218. App.db.setHosts(hostInfo);
  219. },
  220. /**
  221. * Load all data for <code>Specify Host(install step2)</code> step
  222. * Data Example:
  223. * {
  224. * hostNames: '',
  225. * manualInstall: false,
  226. * sshKey: '',
  227. * passphrase: '',
  228. * confirmPassphrase: '',
  229. * localRepo: false,
  230. * localRepoPath: ''
  231. * }
  232. */
  233. loadInstallOptions: function () {
  234. if (!this.content.hosts) {
  235. this.content.hosts = Em.Object.create();
  236. }
  237. //TODO : rewire it as model. or not :)
  238. var hostsInfo = Em.Object.create();
  239. hostsInfo.hostNames = App.db.getAllHostNames() || ''; //empty string if undefined
  240. //TODO : should we check installType for add host wizard????
  241. var installType = App.db.getInstallType();
  242. //false if installType not equals 'manual'
  243. hostsInfo.manualInstall = installType && installType.installType === 'manual' || false;
  244. var softRepo = App.db.getSoftRepo();
  245. if (softRepo && softRepo.repoType === 'local') {
  246. hostsInfo.localRepo = true;
  247. hostsInfo.localRepopath = softRepo.repoPath;
  248. } else {
  249. hostsInfo.localRepo = false;
  250. hostsInfo.localRepoPath = '';
  251. }
  252. hostsInfo.sshKey = 'random';
  253. hostsInfo.passphrase = '';
  254. hostsInfo.confirmPassphrase = '';
  255. this.set('content.hosts', hostsInfo);
  256. console.log("InstallerController:loadHosts: loaded data ", hostsInfo);
  257. },
  258. /**
  259. * Save data, which user filled, to main controller
  260. * @param stepController App.WizardStep2Controller
  261. */
  262. saveHosts: function (stepController) {
  263. //TODO: put data to content.hosts and only then save it)
  264. //App.db.setBootStatus(false);
  265. App.db.setAllHostNames(stepController.get('hostNames'));
  266. App.db.setHosts(stepController.getHostInfo());
  267. if (stepController.get('manualInstall') === false) {
  268. App.db.setInstallType({installType: 'ambari' });
  269. } else {
  270. App.db.setInstallType({installType: 'manual' });
  271. }
  272. if (stepController.get('localRepo') === false) {
  273. App.db.setSoftRepo({ 'repoType': 'remote', 'repoPath': null});
  274. } else {
  275. App.db.setSoftRepo({ 'repoType': 'local', 'repoPath': stepController.get('localRepoPath') });
  276. }
  277. },
  278. /**
  279. * Return hosts, which were add at <code>Specify Host(step2)</code> step
  280. * @paramm isNew whether return all hosts or only new ones
  281. */
  282. getHostList: function (isNew) {
  283. var hosts = [];
  284. var hostArray = App.db.getHosts()
  285. console.log('in instsllerController.getHostList: host names is ', hostArray);
  286. for (var i in hostArray) {
  287. var hostInfo = App.HostInfo.create({
  288. name: hostArray[i].name,
  289. bootStatus: hostArray[i].bootStatus
  290. });
  291. hosts.pushObject(hostInfo);
  292. }
  293. console.log('TRACE: pushing ' + hosts);
  294. return hosts;
  295. },
  296. /**
  297. * Remove host from model. Used at <code>Confirm hosts(step2)</code> step
  298. * @param hosts Array of hosts, which we want to delete
  299. */
  300. removeHosts: function (hosts) {
  301. //todo Replace this code with real logic
  302. App.db.removeHosts(hosts);
  303. },
  304. /**
  305. * Save data, which user filled, to main controller
  306. * @param stepController App.WizardStep3Controller
  307. */
  308. saveConfirmedHosts: function (stepController) {
  309. var hostInfo = {};
  310. stepController.get('content').forEach(function (_host) {
  311. hostInfo[_host.name] = {
  312. name: _host.name,
  313. cpu: _host.cpu,
  314. memory: _host.memory,
  315. bootStatus: _host.bootStatus
  316. };
  317. });
  318. console.log('installerController:saveConfirmedHosts: save hosts ', hostInfo);
  319. App.db.setHosts(hostInfo);
  320. this.set('content.hostsInfo', hostInfo);
  321. },
  322. /**
  323. * Load confirmed hosts.
  324. * Will be used at <code>Assign Masters(step5)</code> step
  325. */
  326. loadConfirmedHosts: function () {
  327. this.set('content.hostsInfo', App.db.getHosts());
  328. },
  329. /**
  330. * Save data after installation to main controller
  331. * @param stepController App.WizardStep9Controller
  332. */
  333. saveInstalledHosts: function (stepController) {
  334. var hosts = stepController.get('hosts');
  335. var hostInfo = App.db.getHosts();
  336. for (var index in hostInfo) {
  337. hostInfo[index].status = "pending";
  338. var host = hosts.findProperty('name', hostInfo[index].name);
  339. if (host) {
  340. hostInfo[index].status = host.status;
  341. hostInfo[index].message = host.message;
  342. hostInfo[index].progress = host.progress;
  343. }
  344. }
  345. App.db.setHosts(hostInfo);
  346. console.log('installerController:saveInstalledHosts: save hosts ', hostInfo);
  347. },
  348. /**
  349. * Remove all data for hosts
  350. */
  351. clearHosts: function () {
  352. var hosts = this.get('content').get('hosts');
  353. if (hosts) {
  354. hosts.hostNames = '';
  355. hosts.manualInstall = false;
  356. hosts.localRepo = '';
  357. hosts.localRepopath = '';
  358. hosts.sshKey = '';
  359. hosts.passphrase = '';
  360. hosts.confirmPassphrase = '';
  361. }
  362. },
  363. /**
  364. * Load services data. Will be used at <code>Select services(step4)</code> step
  365. */
  366. loadServices: function () {
  367. var servicesInfo = App.db.getService();
  368. servicesInfo.forEach(function (item, index) {
  369. servicesInfo[index] = Em.Object.create(item);
  370. });
  371. this.set('content.services', servicesInfo);
  372. console.log('installerController.loadServices: loaded data ', servicesInfo);
  373. console.log('selected services ', servicesInfo.filterProperty('isSelected', true).mapProperty('serviceName'));
  374. },
  375. /**
  376. * Save data to model
  377. * @param stepController App.WizardStep4Controller
  378. */
  379. saveServices: function (stepController) {
  380. var serviceNames = [];
  381. // we can also do it without stepController since all data,
  382. // changed at page, automatically changes in model(this.content.services)
  383. App.db.setService(stepController.get('content'));
  384. stepController.filterProperty('isSelected', true).forEach(function (item) {
  385. serviceNames.push(item.serviceName);
  386. });
  387. App.db.setSelectedServiceNames(serviceNames);
  388. console.log('installerController.saveServices: saved data ', serviceNames);
  389. },
  390. /**
  391. * Save Master Component Hosts data to Main Controller
  392. * @param stepController App.WizardStep5Controller
  393. */
  394. saveMasterComponentHosts: function (stepController) {
  395. var obj = stepController.get('selectedServicesMasters');
  396. var masterComponentHosts = [];
  397. obj.forEach(function (_component) {
  398. masterComponentHosts.push({
  399. component: _component.component_name,
  400. hostName: _component.selectedHost
  401. });
  402. });
  403. console.log("installerController.saveComponentHosts: saved hosts ", masterComponentHosts);
  404. App.db.setMasterComponentHosts(masterComponentHosts);
  405. this.set('content.masterComponentHosts', masterComponentHosts);
  406. var hosts = masterComponentHosts.mapProperty('hostName').uniq();
  407. var hostsMasterServicesMapping = [];
  408. hosts.forEach(function (_host) {
  409. var componentsOnHost = masterComponentHosts.filterProperty('hostName', _host).mapProperty('component');
  410. hostsMasterServicesMapping.push({
  411. hostname: _host,
  412. components: componentsOnHost
  413. });
  414. }, this);
  415. console.log("installerController.setHostToMasterComponent: saved hosts ", hostsMasterServicesMapping);
  416. App.db.setHostToMasterComponent(hostsMasterServicesMapping);
  417. this.set('content.hostToMasterComponent', hostsMasterServicesMapping);
  418. },
  419. /**
  420. * Load master component hosts data for using in required step controllers
  421. */
  422. loadMasterComponentHosts: function () {
  423. var masterComponentHosts = App.db.getMasterComponentHosts();
  424. this.set("content.masterComponentHosts", masterComponentHosts);
  425. console.log("InstallerController.loadMasterComponentHosts: loaded hosts ", masterComponentHosts);
  426. var hostsMasterServicesMapping = App.db.getHostToMasterComponent();
  427. this.set("content.hostToMasterComponent", hostsMasterServicesMapping);
  428. console.log("InstallerController.loadHostToMasterComponent: loaded hosts ", hostsMasterServicesMapping);
  429. },
  430. /**
  431. * Save slaveHostComponents to main controller
  432. * @param stepController
  433. */
  434. saveSlaveComponentHosts: function (stepController) {
  435. var hosts = stepController.get('hosts');
  436. var isMrSelected = stepController.get('isMrSelected');
  437. var isHbSelected = stepController.get('isHbSelected');
  438. App.db.setHostSlaveComponents(hosts);
  439. this.set('content.hostSlaveComponents', hosts);
  440. var dataNodeHosts = [];
  441. var taskTrackerHosts = [];
  442. var regionServerHosts = [];
  443. var clientHosts = [];
  444. hosts.forEach(function (host) {
  445. if (host.get('isDataNode')) {
  446. dataNodeHosts.push({
  447. hostname: host.hostname,
  448. group: 'Default'
  449. });
  450. }
  451. if (isMrSelected && host.get('isTaskTracker')) {
  452. taskTrackerHosts.push({
  453. hostname: host.hostname,
  454. group: 'Default'
  455. });
  456. }
  457. if (isHbSelected && host.get('isRegionServer')) {
  458. regionServerHosts.push({
  459. hostname: host.hostname,
  460. group: 'Default'
  461. });
  462. }
  463. if (host.get('isClient')) {
  464. clientHosts.pushObject({
  465. hostname: host.hostname,
  466. group: 'Default'
  467. });
  468. }
  469. }, this);
  470. var slaveComponentHosts = [];
  471. slaveComponentHosts.push({
  472. componentName: 'DATANODE',
  473. displayName: 'DataNode',
  474. hosts: dataNodeHosts
  475. });
  476. if (isMrSelected) {
  477. slaveComponentHosts.push({
  478. componentName: 'TASKTRACKER',
  479. displayName: 'TaskTracker',
  480. hosts: taskTrackerHosts
  481. });
  482. }
  483. if (isHbSelected) {
  484. slaveComponentHosts.push({
  485. componentName: 'HBASE_REGIONSERVER',
  486. displayName: 'RegionServer',
  487. hosts: regionServerHosts
  488. });
  489. }
  490. slaveComponentHosts.pushObject({
  491. componentName: 'CLIENT',
  492. displayName: 'client',
  493. hosts: clientHosts
  494. });
  495. App.db.setSlaveComponentHosts(slaveComponentHosts);
  496. this.set('content.slaveComponentHosts', slaveComponentHosts);
  497. },
  498. /**
  499. * Load master component hosts data for using in required step controllers
  500. */
  501. loadSlaveComponentHosts: function () {
  502. var slaveComponentHosts = App.db.getSlaveComponentHosts();
  503. this.set("content.slaveComponentHosts", slaveComponentHosts);
  504. console.log("InstallerController.loadSlaveComponentHosts: loaded hosts ", slaveComponentHosts);
  505. var hostSlaveComponents = App.db.getHostSlaveComponents();
  506. this.set('content.hostSlaveComponents', hostSlaveComponents);
  507. console.log("InstallerController.loadSlaveComponentHosts: loaded hosts ", hostSlaveComponents);
  508. },
  509. /**
  510. * Save config properties
  511. * @param stepController Step7WizardController
  512. */
  513. saveServiceConfigProperties: function (stepController) {
  514. var serviceConfigProperties = [];
  515. stepController.get('stepConfigs').forEach(function (_content) {
  516. _content.get('configs').forEach(function (_configProperties) {
  517. var configProperty = {
  518. name: _configProperties.get('name'),
  519. value: _configProperties.get('value')
  520. };
  521. serviceConfigProperties.push(configProperty);
  522. }, this);
  523. }, this);
  524. App.db.setServiceConfigProperties(serviceConfigProperties);
  525. this.set('content.serviceConfigProperties', serviceConfigProperties);
  526. },
  527. /**
  528. * Load serviceConfigProperties to model
  529. */
  530. loadServiceConfigProperties: function () {
  531. var serviceConfigProperties = App.db.getServiceConfigProperties();
  532. this.set('content.serviceConfigProperties', serviceConfigProperties);
  533. console.log("InstallerController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  534. },
  535. /**
  536. * Load information about hosts with clients components
  537. */
  538. loadClients: function(){
  539. var clients = App.db.getClientsForSelectedServices();
  540. this.set('content.clients', clients);
  541. console.log("InstallerController.loadClients: loaded list ", clients);
  542. },
  543. /**
  544. * Generate clients list for selected services and save it to model
  545. * @param stepController step4WizardController
  546. */
  547. saveClients: function(stepController){
  548. var clients = [];
  549. var serviceComponents = require('data/service_components');
  550. stepController.get('content').filterProperty('isSelected',true).forEach(function (_service) {
  551. var client = serviceComponents.filterProperty('service_name', _service.serviceName).findProperty('isClient', true);
  552. if (client) {
  553. clients.pushObject({
  554. component_name: client.component_name,
  555. display_name: client.display_name
  556. });
  557. }
  558. }, this);
  559. App.db.setClientsForSelectedServices(clients);
  560. this.set('content.clients', clients);
  561. console.log("InstallerController.saveClients: saved list ", clients);
  562. },
  563. /**
  564. * Load HostToMasterComponent array
  565. */
  566. loadHostToMasterComponent: function(){
  567. var list = App.db.getHostToMasterComponent();
  568. this.set('content.hostToMasterComponent', list);
  569. console.log("AddHostController.loadHostToMasterComponent: loaded list ", list);
  570. },
  571. /**
  572. * List of statuses, what data is currently loaded
  573. */
  574. isStepLoaded: {},
  575. /**
  576. * Call specified function only once
  577. */
  578. callLoadFuncOnce: function (name) {
  579. if (!this.isStepLoaded[name]) {
  580. this[name]();
  581. this.isStepLoaded[name] = true;
  582. }
  583. },
  584. /**
  585. * Load data for all steps until <code>current step</code>
  586. */
  587. loadAllPriorSteps: function () {
  588. var step = this.get('currentStep');
  589. switch (step) {
  590. case '9':
  591. //need to call it every time since we preload data in setInfoForStep9
  592. this.loadClusterInfo();
  593. case '8':
  594. this.loadClusterInfo();
  595. case '7':
  596. this.callLoadFuncOnce('loadServiceConfigProperties');
  597. case '6':
  598. this.callLoadFuncOnce('loadMasterComponentHosts');
  599. this.callLoadFuncOnce('loadSlaveComponentHosts');
  600. this.callLoadFuncOnce('loadClients');
  601. this.callLoadFuncOnce('loadHostToMasterComponent');
  602. case '5':
  603. this.callLoadFuncOnce('loadConfirmedHosts');
  604. case '4':
  605. this.callLoadFuncOnce('loadServices');
  606. case '3':
  607. case '2':
  608. this.callLoadFuncOnce('loadInstallOptions');
  609. case '1':
  610. this.callLoadFuncOnce('loadClusterInfo');
  611. }
  612. }
  613. });