wizard.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  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. require('models/host');
  20. App.WizardController = Em.Controller.extend(App.LocalStorage, {
  21. isStepDisabled: null,
  22. /**
  23. * map of actions which load data required by which step
  24. * used by <code>loadAllPriorSteps</code>
  25. */
  26. loadMap: {},
  27. /**
  28. * Wizard properties in local storage, which should be cleaned right after wizard has been finished
  29. */
  30. dbPropertiesToClean: [
  31. 'service',
  32. 'hosts',
  33. 'masterComponentHosts',
  34. 'slaveComponentHosts',
  35. 'cluster',
  36. 'allHostNames',
  37. 'installOptions',
  38. 'allHostNamesPattern',
  39. 'serviceComponents'
  40. ],
  41. init: function () {
  42. this.set('isStepDisabled', []);
  43. this.clusters = App.Cluster.find();
  44. this.get('isStepDisabled').pushObject(Ember.Object.create({
  45. step: 1,
  46. value: false
  47. }));
  48. for (var i = 2; i <= this.get('totalSteps'); i++) {
  49. this.get('isStepDisabled').pushObject(Ember.Object.create({
  50. step: i,
  51. value: true
  52. }));
  53. }
  54. },
  55. slaveComponents: function () {
  56. return App.StackServiceComponent.find().filterProperty('isSlave', true);
  57. }.property('App.router.clusterController.isLoaded'),
  58. allHosts: function () {
  59. var dbHosts = this.get('content.hosts');
  60. var hosts = [];
  61. var hostComponents = [];
  62. for (var hostName in dbHosts) {
  63. hostComponents = [];
  64. var disksOverallCapacity = 0;
  65. var diskFree = 0;
  66. dbHosts[hostName].hostComponents.forEach(function (componentName) {
  67. hostComponents.push(Em.Object.create({
  68. componentName: componentName,
  69. displayName: App.format.role(componentName)
  70. }));
  71. });
  72. dbHosts[hostName].disk_info.forEach(function (disk) {
  73. disksOverallCapacity += parseFloat(disk.size);
  74. diskFree += parseFloat(disk.available);
  75. });
  76. hosts.push(Em.Object.create({
  77. id: hostName,
  78. hostName: hostName,
  79. publicHostName: hostName,
  80. diskInfo: dbHosts[hostName].disk_info,
  81. diskTotal: disksOverallCapacity / (1024 * 1024),
  82. diskFree: diskFree / (1024 * 1024),
  83. disksMounted: dbHosts[hostName].disk_info.length,
  84. cpu: dbHosts[hostName].cpu,
  85. memory: dbHosts[hostName].memory,
  86. osType: dbHosts[hostName].osType ? dbHosts[hostName].osType: 0,
  87. osArch: dbHosts[hostName].osArch ? dbHosts[hostName].osArch : 0,
  88. ip: dbHosts[hostName].ip ? dbHosts[hostName].ip: 0,
  89. hostComponents: hostComponents
  90. }))
  91. }
  92. return hosts;
  93. }.property('content.hosts'),
  94. setStepsEnable: function () {
  95. for (var i = 1; i <= this.totalSteps; i++) {
  96. var step = this.get('isStepDisabled').findProperty('step', i);
  97. if (i <= this.get('currentStep')) {
  98. step.set('value', false);
  99. } else {
  100. step.set('value', true);
  101. }
  102. }
  103. }.observes('currentStep'),
  104. setLowerStepsDisable: function (stepNo) {
  105. for (var i = 1; i < stepNo; i++) {
  106. var step = this.get('isStepDisabled').findProperty('step', i);
  107. step.set('value', true);
  108. }
  109. },
  110. /**
  111. * Set current step to new value.
  112. * Method moved from App.router.setInstallerCurrentStep
  113. * @param currentStep
  114. * @param completed
  115. */
  116. currentStep: function () {
  117. return App.get('router').getWizardCurrentStep(this.get('name').substr(0, this.get('name').length - 10));
  118. }.property(),
  119. /**
  120. * Set current step to new value.
  121. * Method moved from App.router.setInstallerCurrentStep
  122. * @param currentStep
  123. * @param completed
  124. */
  125. setCurrentStep: function (currentStep, completed) {
  126. App.db.setWizardCurrentStep(this.get('name').substr(0, this.get('name').length - 10), currentStep, completed);
  127. this.set('currentStep', currentStep);
  128. },
  129. clusters: null,
  130. isStep0: function () {
  131. return this.get('currentStep') == 0;
  132. }.property('currentStep'),
  133. isStep1: function () {
  134. return this.get('currentStep') == 1;
  135. }.property('currentStep'),
  136. isStep2: function () {
  137. return this.get('currentStep') == 2;
  138. }.property('currentStep'),
  139. isStep3: function () {
  140. return this.get('currentStep') == 3;
  141. }.property('currentStep'),
  142. isStep4: function () {
  143. return this.get('currentStep') == 4;
  144. }.property('currentStep'),
  145. isStep5: function () {
  146. return this.get('currentStep') == 5;
  147. }.property('currentStep'),
  148. isStep6: function () {
  149. return this.get('currentStep') == 6;
  150. }.property('currentStep'),
  151. isStep7: function () {
  152. return this.get('currentStep') == 7;
  153. }.property('currentStep'),
  154. isStep8: function () {
  155. return this.get('currentStep') == 8;
  156. }.property('currentStep'),
  157. isStep9: function () {
  158. return this.get('currentStep') == 9;
  159. }.property('currentStep'),
  160. isStep10: function () {
  161. return this.get('currentStep') == 10;
  162. }.property('currentStep'),
  163. gotoStep: function (step, disableNaviWarning) {
  164. if (this.get('isStepDisabled').findProperty('step', step).get('value') !== false) {
  165. return false;
  166. }
  167. // if going back from Step 9 in Install Wizard, delete the checkpoint so that the user is not redirected
  168. // to Step 9
  169. if (this.get('content.controllerName') == 'installerController' && this.get('currentStep') === '9' && step < 9) {
  170. App.clusterStatus.setClusterStatus({
  171. clusterName: this.get('clusterName'),
  172. clusterState: 'CLUSTER_NOT_CREATED_1',
  173. wizardControllerName: 'installerController',
  174. localdb: App.db.data
  175. });
  176. }
  177. if ((this.get('currentStep') - step) > 1 && !disableNaviWarning) {
  178. App.ModalPopup.show({
  179. header: Em.I18n.t('installer.navigation.warning.header'),
  180. onPrimary: function () {
  181. App.router.send('gotoStep' + step);
  182. this.hide();
  183. },
  184. body: "If you proceed to go back to Step " + step + ", you will lose any changes you have made beyond this step"
  185. });
  186. } else {
  187. App.router.send('gotoStep' + step);
  188. }
  189. return true;
  190. },
  191. gotoStep0: function () {
  192. this.gotoStep(0);
  193. },
  194. gotoStep1: function () {
  195. this.gotoStep(1);
  196. },
  197. gotoStep2: function () {
  198. this.gotoStep(2);
  199. },
  200. gotoStep3: function () {
  201. this.gotoStep(3);
  202. },
  203. gotoStep4: function () {
  204. this.gotoStep(4);
  205. },
  206. gotoStep5: function () {
  207. this.gotoStep(5);
  208. },
  209. gotoStep6: function () {
  210. this.gotoStep(6);
  211. },
  212. gotoStep7: function () {
  213. this.gotoStep(7);
  214. },
  215. gotoStep8: function () {
  216. this.gotoStep(8);
  217. },
  218. gotoStep9: function () {
  219. this.gotoStep(9);
  220. },
  221. gotoStep10: function () {
  222. this.gotoStep(10);
  223. },
  224. /**
  225. * Initialize host status info for step9
  226. */
  227. setInfoForStep9: function () {
  228. var hostInfo = this.getDBProperty('hosts');
  229. for (var index in hostInfo) {
  230. hostInfo[index].status = "pending";
  231. hostInfo[index].message = 'Waiting';
  232. hostInfo[index].logTasks = [];
  233. hostInfo[index].tasks = [];
  234. hostInfo[index].progress = '0';
  235. }
  236. this.setDBProperty('hosts', hostInfo);
  237. },
  238. /**
  239. * Remove all data for installOptions step
  240. */
  241. clearInstallOptions: function () {
  242. var installOptions = this.get('getInstallOptions');
  243. this.set('content.installOptions', installOptions);
  244. this.setDBProperty('installOptions', installOptions);
  245. this.set('content.hosts', {});
  246. this.setDBProperty('hosts', {});
  247. },
  248. toObject: function (object) {
  249. var result = {};
  250. for (var i in object) {
  251. if (object.hasOwnProperty(i)) {
  252. result[i] = object[i];
  253. }
  254. }
  255. return result;
  256. },
  257. /**
  258. * save status of the cluster. This is called from step8 and step9 to persist install and start requestId
  259. * @param clusterStatus object with status, isCompleted, requestId, isInstallError and isStartError field.
  260. */
  261. saveClusterStatus: function (clusterStatus) {
  262. var oldStatus = this.toObject(this.get('content.cluster'));
  263. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  264. if (clusterStatus.requestId &&
  265. clusterStatus.oldRequestsId.indexOf(clusterStatus.requestId) === -1) {
  266. clusterStatus.oldRequestsId.push(clusterStatus.requestId);
  267. }
  268. this.set('content.cluster', clusterStatus);
  269. this.setDBProperty('cluster', clusterStatus);
  270. },
  271. /**
  272. * Invoke installation of selected services to the server and saves the request id returned by the server.
  273. * @param isRetry
  274. */
  275. installServices: function (isRetry, callback) {
  276. // clear requests since we are installing services
  277. // and we don't want to get tasks for previous install attempts
  278. this.set('content.cluster.oldRequestsId', []);
  279. var data;
  280. callback = callback || Em.K;
  281. if (isRetry) {
  282. data = {
  283. context: Em.I18n.t('requestInfo.installComponents'),
  284. HostRoles: {"state": "INSTALLED"},
  285. urlParams: "HostRoles/state=INSTALLED"
  286. }
  287. } else {
  288. data = {
  289. context: Em.I18n.t('requestInfo.installServices'),
  290. ServiceInfo: {"state": "INSTALLED"},
  291. urlParams: "ServiceInfo/state=INIT"
  292. }
  293. }
  294. App.ajax.send({
  295. name: isRetry ? 'common.host_components.update' : 'common.services.update',
  296. sender: this,
  297. data: data,
  298. success: 'installServicesSuccessCallback',
  299. error: 'installServicesErrorCallback'
  300. }).then(callback, callback);
  301. },
  302. installServicesSuccessCallback: function (jsonData) {
  303. var installStartTime = App.dateTime();
  304. console.log("TRACE: In success function for the installService call");
  305. if (jsonData) {
  306. var requestId = jsonData.Requests.id;
  307. console.log('requestId is: ' + requestId);
  308. var clusterStatus = {
  309. status: 'PENDING',
  310. requestId: requestId,
  311. isInstallError: false,
  312. isCompleted: false,
  313. installStartTime: installStartTime
  314. };
  315. this.saveClusterStatus(clusterStatus);
  316. } else {
  317. console.log('ERROR: Error occurred in parsing JSON data');
  318. }
  319. },
  320. installServicesErrorCallback: function (request, ajaxOptions, error) {
  321. console.log("TRACE: In error function for the installService call");
  322. console.log("TRACE: error code status is: " + request.status);
  323. console.log('Error message is: ' + request.responseText);
  324. var clusterStatus = {
  325. status: 'PENDING',
  326. requestId: this.get('content.cluster.requestId'),
  327. isInstallError: true,
  328. isCompleted: false
  329. };
  330. this.saveClusterStatus(clusterStatus);
  331. App.showAlertPopup(Em.I18n.t('common.errorPopup.header'), request.responseText);
  332. },
  333. /**
  334. * show popup, that display status of bootstrap launching
  335. * @param callback
  336. * @return {Object}
  337. */
  338. showLaunchBootstrapPopup: function (callback) {
  339. return App.ModalPopup.show({
  340. header: Em.I18n.t('installer.step2.bootStrap.header'),
  341. isError: false,
  342. serverError: null,
  343. bodyClass: Em.View.extend({
  344. templateName: require('templates/wizard/bootstrap_call_popup')
  345. }),
  346. showFooter: false,
  347. showCloseButton: false,
  348. secondary: null,
  349. /**
  350. * handle requestId when call is completed,
  351. * if it's correct call callback and hide popup
  352. * otherwise notify error and enable buttons to close popup
  353. * @param requestId
  354. * @param serverError
  355. */
  356. finishLoading: function (requestId, serverError) {
  357. if (Em.isNone(requestId)) {
  358. this.set('isError', true);
  359. this.set('showFooter', true);
  360. this.set('showCloseButton', true);
  361. this.set('serverError', serverError);
  362. } else {
  363. callback(requestId);
  364. this.hide();
  365. }
  366. }
  367. });
  368. },
  369. /**
  370. * Bootstrap selected hosts.
  371. * @param bootStrapData
  372. * @param callback
  373. * @return {Object}
  374. */
  375. launchBootstrap: function (bootStrapData, callback) {
  376. var popup = this.showLaunchBootstrapPopup(callback);
  377. App.ajax.send({
  378. name: 'wizard.launch_bootstrap',
  379. sender: this,
  380. data: {
  381. bootStrapData: bootStrapData,
  382. popup: popup
  383. },
  384. success: 'launchBootstrapSuccessCallback',
  385. error: 'launchBootstrapErrorCallback'
  386. });
  387. return popup;
  388. },
  389. launchBootstrapSuccessCallback: function (data, opt, params) {
  390. console.log("TRACE: POST bootstrap succeeded");
  391. params.popup.finishLoading(data.requestId, null);
  392. },
  393. launchBootstrapErrorCallback: function (request, ajaxOptions, error, opt, params) {
  394. console.log("ERROR: POST bootstrap failed");
  395. params.popup.finishLoading(null, error);
  396. },
  397. /**
  398. * Load <code>content.<name></code> variable from localStorage, if wasn't loaded before.
  399. * If you specify <code>reload</code> to true - it will reload it.
  400. * @param name
  401. * @param reload
  402. * @return {Boolean}
  403. */
  404. load: function (name, reload) {
  405. if (this.get('content.' + name) && !reload) {
  406. return false;
  407. }
  408. var result = this.getDBProperty(name);
  409. if (!result) {
  410. if (this['get' + name.capitalize()]) {
  411. result = this['get' + name.capitalize()]();
  412. this.setDBProperty(name, result);
  413. console.log(this.get('name') + ": created " + name, result);
  414. }
  415. else {
  416. console.debug('get' + name.capitalize(), ' not defined in the ' + this.get('name'));
  417. }
  418. }
  419. this.set('content.' + name, result);
  420. console.log(this.get('name') + ": loaded " + name, result);
  421. },
  422. save: function (name) {
  423. var value = this.toObject(this.get('content.' + name));
  424. this.setDBProperty(name, value);
  425. console.log(this.get('name') + ": saved " + name, value);
  426. },
  427. clear: function () {
  428. this.set('content', Ember.Object.create({
  429. 'controllerName': this.get('content.controllerName')
  430. }));
  431. this.set('currentStep', 0);
  432. this.clearStorageData();
  433. },
  434. clusterStatusTemplate: {
  435. name: "",
  436. status: "PENDING",
  437. isCompleted: false,
  438. requestId: null,
  439. installStartTime: null,
  440. installTime: null,
  441. isInstallError: false,
  442. isStartError: false,
  443. oldRequestsId: []
  444. },
  445. clearStorageData: function () {
  446. this.get('dbPropertiesToClean').forEach(function (key) {
  447. this.setDBProperty(key, undefined);
  448. }, this);
  449. },
  450. getInstallOptions: function() {
  451. return jQuery.extend({}, App.get('isHadoopWindowsStack')? this.get('installWindowsOptionsTemplate') : this.get('installOptionsTemplate'));
  452. }.property('App.isHadoopWindowsStack'),
  453. installOptionsTemplate: {
  454. hostNames: "", //string
  455. manualInstall: false, //true, false
  456. useSsh: true, //bool
  457. javaHome: App.defaultJavaHome, //string
  458. localRepo: false, //true, false
  459. sshKey: "", //string
  460. bootRequestId: null, //string
  461. sshUser: "root", //string
  462. agentUser: "root" //string
  463. },
  464. installWindowsOptionsTemplate: {
  465. hostNames: "", //string
  466. manualInstall: true, //true, false
  467. useSsh: false, //bool
  468. javaHome: App.defaultJavaHome, //string
  469. localRepo: false, //true, false
  470. sshKey: "", //string
  471. bootRequestId: null, //string
  472. sshUser: "", //string
  473. agentUser: "" //string
  474. },
  475. loadedServiceComponents: null,
  476. /**
  477. * Generate serviceComponents as pr the stack definition and save it to localdata
  478. * called form stepController step4WizardController
  479. */
  480. loadServiceComponents: function () {
  481. return App.ajax.send({
  482. name: 'wizard.service_components',
  483. sender: this,
  484. data: {
  485. stackUrl: App.get('stackVersionURL'),
  486. stackVersion: App.get('currentStackVersionNumber')
  487. },
  488. success: 'loadServiceComponentsSuccessCallback',
  489. error: 'loadServiceComponentsErrorCallback'
  490. });
  491. },
  492. loadServiceComponentsSuccessCallback: function (jsonData) {
  493. var savedSelectedServices = this.getDBProperty('selectedServiceNames');
  494. var savedInstalledServices = this.getDBProperty('installedServiceNames');
  495. this.set('content.selectedServiceNames', savedSelectedServices);
  496. this.set('content.installedServiceNames', savedInstalledServices);
  497. if (!savedSelectedServices) {
  498. jsonData.items.forEach(function (service) {
  499. service.StackServices.is_selected = true;
  500. }, this);
  501. } else {
  502. jsonData.items.forEach(function (service) {
  503. if (savedSelectedServices.contains(service.StackServices.service_name))
  504. service.StackServices.is_selected = true;
  505. else
  506. service.StackServices.is_selected = false;
  507. }, this);
  508. }
  509. if (!savedInstalledServices) {
  510. jsonData.items.forEach(function (service) {
  511. service.StackServices.is_installed = false;
  512. }, this);
  513. } else {
  514. jsonData.items.forEach(function (service) {
  515. if (savedInstalledServices.contains(service.StackServices.service_name))
  516. service.StackServices.is_installed = true;
  517. else
  518. service.StackServices.is_installed = false;
  519. }, this);
  520. }
  521. App.stackServiceMapper.mapStackServices(jsonData);
  522. },
  523. loadServiceComponentsErrorCallback: function (request, ajaxOptions, error) {
  524. console.log("TRACE: STep5 -> In error function for the getServiceComponents call");
  525. console.log("TRACE: STep5 -> error code status is: " + request.status);
  526. console.log('Step8: Error message is: ' + request.responseText);
  527. },
  528. /**
  529. * Load config groups from local DB
  530. */
  531. loadServiceConfigGroups: function () {
  532. var serviceConfigGroups = this.getDBProperty('serviceConfigGroups'),
  533. hosts = this.getDBProperty('hosts'),
  534. host_names = Em.keys(hosts);
  535. if (Em.isNone(serviceConfigGroups)) {
  536. serviceConfigGroups = [];
  537. }
  538. else {
  539. serviceConfigGroups.forEach(function(group) {
  540. var hostNames = group.hosts.map(function(host_id) {
  541. for (var i = 0; i < host_names.length; i++) {
  542. if (hosts[host_names[i]].id === host_id) {
  543. return host_names[i];
  544. }
  545. }
  546. Em.assert('host is missing!!!!', false);
  547. });
  548. Em.set(group, 'hosts', hostNames);
  549. });
  550. }
  551. this.set('content.configGroups', serviceConfigGroups);
  552. console.log("InstallerController.configGroups: loaded config ", serviceConfigGroups);
  553. },
  554. registerErrPopup: function (header, message) {
  555. App.ModalPopup.show({
  556. header: header,
  557. secondary: false,
  558. bodyClass: Ember.View.extend({
  559. template: Ember.Handlebars.compile('<p>{{view.message}}</p>'),
  560. message: message
  561. })
  562. });
  563. },
  564. /**
  565. * Save hosts that the user confirmed to proceed with from step 3
  566. * @param stepController App.WizardStep3Controller
  567. */
  568. saveConfirmedHosts: function (stepController) {
  569. var hosts = this.get('content.hosts'),
  570. indx = 1;
  571. //add previously installed hosts
  572. for (var hostName in hosts) {
  573. if (!hosts[hostName].isInstalled) {
  574. delete hosts[hostName];
  575. }
  576. }
  577. stepController.get('confirmedHosts').forEach(function (_host) {
  578. if (_host.bootStatus == 'REGISTERED') {
  579. hosts[_host.name] = {
  580. name: _host.name,
  581. cpu: _host.cpu,
  582. memory: _host.memory,
  583. disk_info: _host.disk_info,
  584. os_type: _host.os_type,
  585. os_arch: _host.os_arch,
  586. ip: _host.ip,
  587. bootStatus: _host.bootStatus,
  588. isInstalled: false,
  589. id: indx++
  590. };
  591. }
  592. });
  593. console.log('wizardController:saveConfirmedHosts: save hosts ', hosts);
  594. this.setDBProperty('hosts', hosts);
  595. this.set('content.hosts', hosts);
  596. },
  597. /**
  598. * Save data after installation to main controller
  599. * @param stepController App.WizardStep9Controller
  600. */
  601. saveInstalledHosts: function (stepController) {
  602. var hosts = stepController.get('hosts');
  603. var hostInfo = this.getDBProperty('hosts');
  604. for (var index in hostInfo) {
  605. hostInfo[index].status = "pending";
  606. var host = hosts.findProperty('name', hostInfo[index].name);
  607. if (host) {
  608. hostInfo[index].status = host.status;
  609. hostInfo[index].message = host.message;
  610. hostInfo[index].progress = host.progress;
  611. }
  612. }
  613. this.set('content.hosts', hostInfo);
  614. this.setDBProperty('hosts', hostInfo);
  615. console.log('wizardController:saveInstalledHosts: save hosts ', hostInfo);
  616. },
  617. /**
  618. * Save slaveHostComponents to main controller
  619. * @param stepController
  620. */
  621. saveSlaveComponentHosts: function (stepController) {
  622. var hosts = stepController.get('hosts'),
  623. dbHosts = this.getDBProperty('hosts'),
  624. headers = stepController.get('headers');
  625. var formattedHosts = Ember.Object.create();
  626. headers.forEach(function (header) {
  627. formattedHosts.set(header.get('name'), []);
  628. });
  629. hosts.forEach(function (host) {
  630. var checkboxes = host.get('checkboxes');
  631. headers.forEach(function (header) {
  632. var cb = checkboxes.findProperty('title', header.get('label'));
  633. if (cb.get('checked')) {
  634. formattedHosts.get(header.get('name')).push({
  635. group: 'Default',
  636. isInstalled: cb.get('isInstalled'),
  637. host_id: dbHosts[host.hostName].id
  638. });
  639. }
  640. });
  641. });
  642. var slaveComponentHosts = [];
  643. headers.forEach(function (header) {
  644. slaveComponentHosts.push({
  645. componentName: header.get('name'),
  646. displayName: header.get('label').replace(/\s/g, ''),
  647. hosts: formattedHosts.get(header.get('name'))
  648. });
  649. });
  650. this.setDBProperty('slaveComponentHosts', slaveComponentHosts);
  651. console.log('wizardController.slaveComponentHosts: saved hosts', slaveComponentHosts);
  652. this.set('content.slaveComponentHosts', slaveComponentHosts);
  653. },
  654. /**
  655. * Return true if cluster data is loaded and false otherwise.
  656. * This is used for all wizard controllers except for installer wizard.
  657. */
  658. dataLoading: function () {
  659. var dfd = $.Deferred();
  660. this.connectOutlet('loading');
  661. if (App.router.get('clusterController.isLoaded')) {
  662. dfd.resolve();
  663. } else {
  664. var interval = setInterval(function () {
  665. if (App.router.get('clusterController.isLoaded')) {
  666. dfd.resolve();
  667. clearInterval(interval);
  668. }
  669. }, 50);
  670. }
  671. return dfd.promise();
  672. },
  673. /**
  674. * Return true if user data is loaded via App.MainServiceInfoConfigsController
  675. * This function is used in reassign master wizard right now.
  676. */
  677. usersLoading: function () {
  678. var self = this;
  679. var dfd = $.Deferred();
  680. var miscController = App.MainAdminServiceAccountsController.create({content: self.get('content')});
  681. miscController.loadUsers();
  682. var interval = setInterval(function () {
  683. if (miscController.get('dataIsLoaded')) {
  684. if (self.get("content.hdfsUser")) {
  685. self.set('content.hdfsUser', miscController.get('content.hdfsUser'));
  686. }
  687. dfd.resolve();
  688. clearInterval(interval);
  689. }
  690. }, 10);
  691. return dfd.promise();
  692. },
  693. /**
  694. * Save cluster status before going to deploy step
  695. * @param name cluster state. Unique for every wizard
  696. */
  697. saveClusterState: function (name) {
  698. App.clusterStatus.setClusterStatus({
  699. clusterName: this.get('content.cluster.name'),
  700. clusterState: name,
  701. wizardControllerName: this.get('content.controllerName'),
  702. localdb: App.db.data
  703. });
  704. },
  705. /**
  706. * load advanced configs from server
  707. */
  708. loadAdvancedConfigs: function (dependentController) {
  709. var self = this;
  710. var loadServiceConfigsFn = function(clusterProperties) {
  711. var stackServices = self.get('content.services').filter(function (service) {
  712. return service.get('isInstalled') || service.get('isSelected');
  713. });
  714. var counter = stackServices.length;
  715. var loadAdvancedConfigResult = [];
  716. dependentController.set('isAdvancedConfigLoaded', false);
  717. stackServices.forEach(function (service) {
  718. var serviceName = service.get('serviceName');
  719. App.config.loadAdvancedConfig(serviceName, function (properties) {
  720. var supportsFinal = App.config.getConfigTypesInfoFromService(service).supportsFinal;
  721. function shouldSupportFinal(filename) {
  722. var matchingConfigType = supportsFinal.find(function (configType) {
  723. return filename.startsWith(configType);
  724. });
  725. return !!matchingConfigType;
  726. }
  727. properties.forEach(function (property) {
  728. property.supportsFinal = shouldSupportFinal(property.filename);
  729. });
  730. loadAdvancedConfigResult.pushObjects(properties);
  731. counter--;
  732. //pass configs to controller after last call is completed
  733. if (counter === 0) {
  734. loadAdvancedConfigResult.pushObjects(clusterProperties);
  735. self.set('content.advancedServiceConfig', loadAdvancedConfigResult);
  736. self.setDBProperty('advancedServiceConfig', loadAdvancedConfigResult);
  737. dependentController.set('isAdvancedConfigLoaded', true);
  738. }
  739. });
  740. }, this);
  741. };
  742. App.config.loadClusterConfig(loadServiceConfigsFn);
  743. },
  744. /**
  745. * Load serviceConfigProperties to model
  746. */
  747. loadServiceConfigProperties: function () {
  748. var serviceConfigProperties = this.getDBProperty('serviceConfigProperties');
  749. this.set('content.serviceConfigProperties', serviceConfigProperties);
  750. console.log("AddHostController.loadServiceConfigProperties: loaded config ", serviceConfigProperties);
  751. },
  752. /**
  753. * Save config properties
  754. * @param stepController Step7WizardController
  755. */
  756. saveServiceConfigProperties: function (stepController) {
  757. var serviceConfigProperties = [];
  758. var fileNamesToUpdate = [];
  759. stepController.get('stepConfigs').forEach(function (_content) {
  760. if (_content.serviceName === 'YARN') {
  761. _content.set('configs', App.config.textareaIntoFileConfigs(_content.get('configs'), 'capacity-scheduler.xml'));
  762. }
  763. _content.get('configs').forEach(function (_configProperties) {
  764. var configProperty = {
  765. id: _configProperties.get('id'),
  766. name: _configProperties.get('name'),
  767. value: _configProperties.get('value'),
  768. defaultValue: _configProperties.get('defaultValue'),
  769. description: _configProperties.get('description'),
  770. serviceName: _configProperties.get('serviceName'),
  771. domain: _configProperties.get('domain'),
  772. isVisible: _configProperties.get('isVisible'),
  773. isFinal: _configProperties.get('isFinal'),
  774. defaultIsFinal: _configProperties.get('isFinal'),
  775. supportsFinal: _configProperties.get('supportsFinal'),
  776. filename: _configProperties.get('filename'),
  777. displayType: _configProperties.get('displayType'),
  778. isRequiredByAgent: _configProperties.get('isRequiredByAgent'),
  779. hasInitialValue: !!_configProperties.get('hasInitialValue'),
  780. isRequired: _configProperties.get('isRequired'), // flag that allow saving property with empty value
  781. group: !!_configProperties.get('group') ? _configProperties.get('group.name') : null,
  782. showLabel: _configProperties.get('showLabel')
  783. };
  784. serviceConfigProperties.push(configProperty);
  785. }, this);
  786. // check for configs that need to update for installed services
  787. if (stepController.get('installedServiceNames') && stepController.get('installedServiceNames').contains(_content.get('serviceName'))) {
  788. // get only modified configs
  789. var configs = _content.get('configs').filter(function (config) {
  790. if (config.get('isNotDefaultValue') || (config.get('defaultValue') === null)) {
  791. var notAllowed = ['masterHost', 'masterHosts', 'slaveHosts', 'slaveHost'];
  792. return !notAllowed.contains(config.get('displayType')) && !!config.filename;
  793. }
  794. return false;
  795. });
  796. // if modified configs detected push all service's configs for update
  797. if (configs.length) {
  798. fileNamesToUpdate = fileNamesToUpdate.concat(configs.mapProperty('filename').uniq());
  799. }
  800. // watch for properties that are not modified but have to be updated
  801. if (_content.get('configs').someProperty('forceUpdate')) {
  802. // check for already added modified properties
  803. var forceUpdatedFileNames = _content.get('configs').filterProperty('forceUpdate', true).mapProperty('filename').uniq();
  804. fileNamesToUpdate = fileNamesToUpdate.concat(forceUpdatedFileNames).uniq();
  805. }
  806. }
  807. }, this);
  808. this.setDBProperty('serviceConfigProperties', serviceConfigProperties);
  809. this.set('content.serviceConfigProperties', serviceConfigProperties);
  810. this.setDBProperty('fileNamesToUpdate', fileNamesToUpdate);
  811. },
  812. /**
  813. * save Config groups
  814. * @param stepController
  815. * @param isAddService
  816. */
  817. saveServiceConfigGroups: function (stepController, isAddService) {
  818. var serviceConfigGroups = [],
  819. isForInstalledService = false,
  820. hosts = isAddService ? App.router.get('addServiceController').getDBProperty('hosts') : this.getDBProperty('hosts');
  821. stepController.get('stepConfigs').forEach(function (service) {
  822. // mark group of installed service
  823. if (service.get('selected') === false) isForInstalledService = true;
  824. service.get('configGroups').forEach(function (configGroup) {
  825. var properties = [];
  826. configGroup.get('properties').forEach(function (property) {
  827. properties.push({
  828. isRequiredByAgent: property.get('isRequiredByAgent'),
  829. name: property.get('name'),
  830. value: property.get('value'),
  831. isFinal: property.get('isFinal'),
  832. filename: property.get('filename')
  833. })
  834. });
  835. //configGroup copied into plain JS object to avoid Converting circular structure to JSON
  836. var hostNames = configGroup.get('hosts').map(function(host_name) {return hosts[host_name].id;});
  837. serviceConfigGroups.push({
  838. id: configGroup.get('id'),
  839. name: configGroup.get('name'),
  840. description: configGroup.get('description'),
  841. hosts: hostNames,
  842. publicHosts: configGroup.get('hosts').map(function(hostName) {return App.router.get('manageConfigGroupsController').hostsToPublic(hostName); }),
  843. properties: properties,
  844. isDefault: configGroup.get('isDefault'),
  845. isForInstalledService: isForInstalledService,
  846. isForUpdate: configGroup.isForUpdate || configGroup.get('hash') != this.getConfigGroupHash(configGroup, hostNames),
  847. service: {id: configGroup.get('service.id')}
  848. });
  849. }, this)
  850. }, this);
  851. this.setDBProperty('serviceConfigGroups', serviceConfigGroups);
  852. this.set('content.configGroups', serviceConfigGroups);
  853. },
  854. /**
  855. * generate string hash for config group
  856. * @param {Object} configGroup
  857. * @param {Array|undefined} hosts
  858. * @returns {String|null}
  859. * @method getConfigGroupHash
  860. */
  861. getConfigGroupHash: function(configGroup, hosts) {
  862. if (!Em.get(configGroup, 'properties.length') && !Em.get(configGroup, 'hosts.length') && !hosts) {
  863. return null;
  864. }
  865. var hash = {};
  866. Em.get(configGroup, 'properties').forEach(function (config) {
  867. hash[Em.get(config, 'name')] = {value: Em.get(config, 'value'), isFinal: Em.get(config, 'isFinal')};
  868. });
  869. hash['hosts'] = hosts || Em.get(configGroup, 'hosts');
  870. return JSON.stringify(hash);
  871. },
  872. /**
  873. * return slaveComponents bound to hosts
  874. * @return {Array}
  875. */
  876. getSlaveComponentHosts: function () {
  877. var components = this.get('slaveComponents');
  878. var result = [];
  879. var installedServices = App.Service.find().mapProperty('serviceName');
  880. var selectedServices = App.StackService.find().filterProperty('isSelected', true).mapProperty('serviceName');
  881. var installedComponentsMap = {};
  882. var uninstalledComponents = [];
  883. components.forEach(function (component) {
  884. if (installedServices.contains(component.get('serviceName'))) {
  885. installedComponentsMap[component.get('componentName')] = [];
  886. } else if (selectedServices.contains(component.get('serviceName'))) {
  887. uninstalledComponents.push(component);
  888. }
  889. }, this);
  890. installedComponentsMap['HDFS_CLIENT'] = [];
  891. App.HostComponent.find().forEach(function (hostComponent) {
  892. if (installedComponentsMap[hostComponent.get('componentName')]) {
  893. installedComponentsMap[hostComponent.get('componentName')].push(hostComponent.get('hostName'));
  894. }
  895. }, this);
  896. for (var componentName in installedComponentsMap) {
  897. var name = (componentName === 'HDFS_CLIENT') ? 'CLIENT' : componentName;
  898. var component = {
  899. componentName: name,
  900. displayName: App.format.role(name),
  901. hosts: [],
  902. isInstalled: true
  903. };
  904. installedComponentsMap[componentName].forEach(function (hostName) {
  905. component.hosts.push({
  906. group: "Default",
  907. hostName: hostName,
  908. isInstalled: true
  909. });
  910. }, this);
  911. result.push(component);
  912. }
  913. uninstalledComponents.forEach(function (component) {
  914. var hosts = jQuery.extend(true, [], result.findProperty('componentName', 'DATANODE').hosts);
  915. hosts.setEach('isInstalled', false);
  916. result.push({
  917. componentName: component.get('componentName'),
  918. displayName: App.format.role(component.get('componentName')),
  919. hosts: hosts,
  920. isInstalled: false
  921. })
  922. });
  923. return result;
  924. },
  925. /**
  926. * Load master component hosts data for using in required step controllers
  927. */
  928. loadMasterComponentHosts: function () {
  929. var masterComponentHosts = this.getDBProperty('masterComponentHosts');
  930. var stackMasterComponents = App.get('components.masters').uniq();
  931. if (!masterComponentHosts) {
  932. masterComponentHosts = [];
  933. App.HostComponent.find().filter(function(component) {
  934. return stackMasterComponents.contains(component.get('componentName'));
  935. }).forEach(function (item) {
  936. masterComponentHosts.push({
  937. component: item.get('componentName'),
  938. hostName: item.get('hostName'),
  939. isInstalled: true,
  940. serviceId: item.get('service.id'),
  941. display_name: item.get('displayName')
  942. })
  943. });
  944. this.setDBProperty('masterComponentHosts', masterComponentHosts);
  945. }
  946. this.set("content.masterComponentHosts", masterComponentHosts);
  947. },
  948. /**
  949. * Load information about hosts with clients components
  950. */
  951. loadClients: function () {
  952. var clients = this.getDBProperty('clientInfo');
  953. this.set('content.clients', clients);
  954. console.log(this.get('content.controllerName') + ".loadClients: loaded list ", clients);
  955. },
  956. /**
  957. * load methods assigned to each step
  958. * methods executed in exact order as they described in map
  959. * @return {object}
  960. */
  961. loadAllPriorSteps: function () {
  962. var currentStep = this.get('currentStep');
  963. var loadMap = this.get('loadMap');
  964. var operationStack = [];
  965. var dfd = $.Deferred();
  966. for (var s in loadMap) {
  967. if (parseInt(s) <= parseInt(currentStep)) {
  968. operationStack.pushObjects(loadMap[s]);
  969. }
  970. }
  971. var sequence = App.actionSequence.create({context: this});
  972. sequence.setSequence(operationStack).onFinish(function () {
  973. dfd.resolve();
  974. }).start();
  975. return dfd.promise();
  976. },
  977. /**
  978. * return new object extended from clusterStatusTemplate
  979. * @return Object
  980. */
  981. getCluster: function () {
  982. return jQuery.extend({}, this.get('clusterStatusTemplate'), {name: App.router.getClusterName()});
  983. },
  984. /**
  985. * Load services data from server.
  986. */
  987. loadServicesFromServer: function () {
  988. var services = this.getDBProperty('services');
  989. if (!services) {
  990. services = {
  991. selectedServices: [],
  992. installedServices: []
  993. };
  994. App.StackService.find().forEach(function(item){
  995. var isInstalled = App.Service.find().someProperty('id', item.get('serviceName'));
  996. item.set('isSelected', isInstalled);
  997. item.set('isInstalled', isInstalled);
  998. if (isInstalled) {
  999. services.selectedServices.push(item.get('serviceName'));
  1000. services.installedServices.push(item.get('serviceName'));
  1001. }
  1002. },this);
  1003. this.setDBProperty('services',services);
  1004. } else {
  1005. App.StackService.find().forEach(function(item) {
  1006. var isSelected = services.selectedServices.contains(item.get('serviceName'));
  1007. var isInstalled = services.installedServices.contains(item.get('serviceName'));
  1008. item.set('isSelected', isSelected);
  1009. item.set('isInstalled', isInstalled);
  1010. },this);
  1011. }
  1012. this.set('content.services', App.StackService.find());
  1013. },
  1014. /**
  1015. * Load confirmed hosts.
  1016. * Will be used at <code>Assign Masters(step5)</code> step
  1017. */
  1018. loadConfirmedHosts: function () {
  1019. var hosts = App.db.getHosts();
  1020. if (hosts) {
  1021. this.set('content.hosts', hosts);
  1022. }
  1023. }
  1024. });