wizard.js 42 KB

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