add_controller.js 20 KB

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