add_controller.js 17 KB

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