wizard.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  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.WizardController = Em.Controller.extend({
  20. isStepDisabled: null,
  21. init: function () {
  22. this.set('isStepDisabled', []);
  23. this.clusters = App.Cluster.find();
  24. this.isStepDisabled.pushObject(Ember.Object.create({
  25. step: 1,
  26. value: false
  27. }));
  28. for (var i = 2; i <= this.get('totalSteps'); i++) {
  29. this.isStepDisabled.pushObject(Ember.Object.create({
  30. step: i,
  31. value: true
  32. }));
  33. }
  34. // window.onbeforeunload = function () {
  35. // return "You have not saved your document yet. If you continue, your work will not be saved."
  36. //}
  37. },
  38. setStepsEnable: function () {
  39. for (var i = 1; i <= this.totalSteps; i++) {
  40. var step = this.get('isStepDisabled').findProperty('step', i);
  41. if (i <= this.get('currentStep')) {
  42. step.set('value', false);
  43. } else {
  44. step.set('value', true);
  45. }
  46. }
  47. }.observes('currentStep'),
  48. setLowerStepsDisable: function (stepNo) {
  49. for (var i = 1; i < stepNo; i++) {
  50. var step = this.get('isStepDisabled').findProperty('step', i);
  51. step.set('value', true);
  52. }
  53. },
  54. /**
  55. * Set current step to new value.
  56. * Method moved from App.router.setInstallerCurrentStep
  57. * @param currentStep
  58. * @param completed
  59. */
  60. currentStep: function () {
  61. return App.get('router').getWizardCurrentStep(this.get('name').substr(0, this.get('name').length - 10));
  62. }.property(),
  63. /**
  64. * Set current step to new value.
  65. * Method moved from App.router.setInstallerCurrentStep
  66. * @param currentStep
  67. * @param completed
  68. */
  69. setCurrentStep: function (currentStep, completed) {
  70. App.db.setWizardCurrentStep(this.get('name').substr(0, this.get('name').length - 10), currentStep, completed);
  71. this.set('currentStep', currentStep);
  72. },
  73. clusters: null,
  74. isStep1: function () {
  75. return this.get('currentStep') == 1;
  76. }.property('currentStep'),
  77. isStep2: function () {
  78. return this.get('currentStep') == 2;
  79. }.property('currentStep'),
  80. isStep3: function () {
  81. return this.get('currentStep') == 3;
  82. }.property('currentStep'),
  83. isStep4: function () {
  84. return this.get('currentStep') == 4;
  85. }.property('currentStep'),
  86. isStep5: function () {
  87. return this.get('currentStep') == 5;
  88. }.property('currentStep'),
  89. isStep6: function () {
  90. return this.get('currentStep') == 6;
  91. }.property('currentStep'),
  92. isStep7: function () {
  93. return this.get('currentStep') == 7;
  94. }.property('currentStep'),
  95. isStep8: function () {
  96. return this.get('currentStep') == 8;
  97. }.property('currentStep'),
  98. isStep9: function () {
  99. return this.get('currentStep') == 9;
  100. }.property('currentStep'),
  101. isStep10: function () {
  102. return this.get('currentStep') == 10;
  103. }.property('currentStep'),
  104. gotoStep: function (step) {
  105. if (this.get('isStepDisabled').findProperty('step', step).get('value') !== false) {
  106. return;
  107. }
  108. // if going back from Step 9 in Install Wizard, delete the checkpoint so that the user is not redirected
  109. // to Step 9
  110. if (this.get('content.controllerName') == 'installerController' && this.get('currentStep') === '9' && step < 9) {
  111. App.clusterStatus.setClusterStatus({
  112. clusterName: this.get('clusterName'),
  113. clusterState: 'CLUSTER_NOT_CREATED_1',
  114. wizardControllerName: 'installerController',
  115. localdb: App.db.data
  116. });
  117. }
  118. if ((this.get('currentStep') - step) > 1) {
  119. App.ModalPopup.show({
  120. header: Em.I18n.t('installer.navigation.warning.header'),
  121. onPrimary: function () {
  122. App.router.send('gotoStep' + step);
  123. this.hide();
  124. },
  125. body: "If you proceed to go back to Step " + step + ", you will lose any changes you have made beyond this step"
  126. });
  127. } else {
  128. App.router.send('gotoStep' + step);
  129. }
  130. },
  131. gotoStep1: function () {
  132. this.gotoStep(1);
  133. },
  134. gotoStep2: function () {
  135. this.gotoStep(2);
  136. },
  137. gotoStep3: function () {
  138. this.gotoStep(3);
  139. },
  140. gotoStep4: function () {
  141. this.gotoStep(4);
  142. },
  143. gotoStep5: function () {
  144. this.gotoStep(5);
  145. },
  146. gotoStep6: function () {
  147. this.gotoStep(6);
  148. },
  149. gotoStep7: function () {
  150. this.gotoStep(7);
  151. },
  152. gotoStep8: function () {
  153. this.gotoStep(8);
  154. },
  155. gotoStep9: function () {
  156. this.gotoStep(9);
  157. },
  158. gotoStep10: function () {
  159. this.gotoStep(10);
  160. },
  161. /**
  162. * Initialize host status info for step9
  163. */
  164. setInfoForStep9: function () {
  165. var hostInfo = App.db.getHosts();
  166. for (var index in hostInfo) {
  167. hostInfo[index].status = "pending";
  168. hostInfo[index].message = 'Waiting';
  169. hostInfo[index].logTasks = [];
  170. hostInfo[index].tasks = [];
  171. hostInfo[index].progress = '0';
  172. }
  173. App.db.setHosts(hostInfo);
  174. },
  175. /**
  176. * Remove all data for installOptions step
  177. */
  178. clearInstallOptions: function () {
  179. var installOptions = jQuery.extend({}, this.get('installOptionsTemplate'));
  180. this.set('content.installOptions', installOptions);
  181. this.save('installOptions');
  182. this.set('content.hosts', []);
  183. this.save('hosts');
  184. },
  185. toObject: function(object){
  186. var result = {};
  187. for(var i in object){
  188. if(object.hasOwnProperty(i)){
  189. result[i] = object[i];
  190. }
  191. }
  192. return result;
  193. },
  194. /**
  195. * save status of the cluster. This is called from step8 and step9 to persist install and start requestId
  196. * @param clusterStatus object with status, isCompleted, requestId, isInstallError and isStartError field.
  197. */
  198. saveClusterStatus: function (clusterStatus) {
  199. var oldStatus = this.toObject(this.get('content.cluster'));
  200. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  201. if (clusterStatus.requestId &&
  202. clusterStatus.oldRequestsId.indexOf(clusterStatus.requestId) === -1){
  203. clusterStatus.oldRequestsId.push(clusterStatus.requestId);
  204. }
  205. this.set('content.cluster', clusterStatus);
  206. this.save('cluster');
  207. },
  208. /**
  209. * Invoke installation of selected services to the server and saves the request id returned by the server.
  210. * @param isRetry
  211. */
  212. installServices: function (isRetry) {
  213. // clear requests since we are installing services
  214. // and we don't want to get tasks for previous install attempts
  215. this.set('content.cluster.oldRequestsId', []);
  216. this.set('content.cluster.requestId', null);
  217. var self = this;
  218. var clusterName = this.get('content.cluster.name');
  219. var url;
  220. var method = (App.testMode) ? 'GET' : 'PUT';
  221. var data;
  222. switch (this.get('content.controllerName')) {
  223. case 'addHostController':
  224. if (isRetry) {
  225. url = App.apiPrefix + '/clusters/' + clusterName + '/host_components?HostRoles/state!=INSTALLED';
  226. data = '{"HostRoles": {"state": "INSTALLED"}}';
  227. } else {
  228. url = App.apiPrefix + '/clusters/' + clusterName + '/host_components?HostRoles/state=INIT';
  229. data = '{"HostRoles": {"state": "INSTALLED"}}';
  230. }
  231. break;
  232. case 'installerController':
  233. default:
  234. if (isRetry) {
  235. url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + clusterName + '/host_components?HostRoles/state!=INSTALLED';
  236. data = '{"HostRoles": {"state": "INSTALLED"}}';
  237. } else {
  238. url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + clusterName + '/services?ServiceInfo/state=INIT';
  239. data = '{"ServiceInfo": {"state": "INSTALLED"}}';
  240. }
  241. break;
  242. }
  243. $.ajax({
  244. type: method,
  245. url: url,
  246. data: data,
  247. async: false,
  248. dataType: 'text',
  249. timeout: App.timeout,
  250. success: function (data) {
  251. var jsonData = jQuery.parseJSON(data);
  252. var installStartTime = new Date().getTime();
  253. console.log("TRACE: In success function for the installService call");
  254. console.log("TRACE: value of the url is: " + url);
  255. if (jsonData) {
  256. var requestId = jsonData.Requests.id;
  257. console.log('requestId is: ' + requestId);
  258. var clusterStatus = {
  259. status: 'PENDING',
  260. requestId: requestId,
  261. isInstallError: false,
  262. isCompleted: false,
  263. installStartTime: installStartTime
  264. };
  265. self.saveClusterStatus(clusterStatus);
  266. } else {
  267. console.log('ERROR: Error occurred in parsing JSON data');
  268. }
  269. },
  270. error: function (request, ajaxOptions, error) {
  271. console.log("TRACE: In error function for the installService call");
  272. console.log("TRACE: value of the url is: " + url);
  273. console.log("TRACE: error code status is: " + request.status);
  274. console.log('Error message is: ' + request.responseText);
  275. var clusterStatus = {
  276. status: 'PENDING',
  277. isInstallError: false,
  278. isCompleted: false
  279. };
  280. self.saveClusterStatus(clusterStatus);
  281. },
  282. statusCode: require('data/statusCodes')
  283. });
  284. },
  285. /*
  286. Bootstrap selected hosts.
  287. */
  288. launchBootstrap: function (bootStrapData) {
  289. var self = this;
  290. var requestId = null;
  291. var method = App.testMode ? 'GET' : 'POST';
  292. var url = App.testMode ? '/data/wizard/bootstrap/bootstrap.json' : App.apiPrefix + '/bootstrap';
  293. $.ajax({
  294. type: method,
  295. url: url,
  296. async: false,
  297. data: bootStrapData,
  298. timeout: App.timeout,
  299. contentType: 'application/json',
  300. success: function (data) {
  301. console.log("TRACE: POST bootstrap succeeded");
  302. requestId = data.requestId;
  303. },
  304. error: function () {
  305. console.log("ERROR: POST bootstrap failed");
  306. alert('Bootstrap call failed. Please try again.');
  307. },
  308. statusCode: require('data/statusCodes')
  309. });
  310. return requestId;
  311. },
  312. /**
  313. * Load <code>content.<name></code> variable from localStorage, if wasn't loaded before.
  314. * If you specify <code>reload</code> to true - it will reload it.
  315. * @param name
  316. * @param reload
  317. * @return {Boolean}
  318. */
  319. load: function (name, reload) {
  320. if (this.get('content.' + name) && !reload) {
  321. return false;
  322. }
  323. var result = App.db['get' + name.capitalize()]();
  324. if (!result){
  325. result = this['get' + name.capitalize()]();
  326. App.db['set' + name.capitalize()](result);
  327. console.log(this.get('name') + ": created " + name, result);
  328. }
  329. this.set('content.' + name, result);
  330. console.log(this.get('name') + ": loaded " + name, result);
  331. },
  332. save: function(name){
  333. var value = this.toObject(this.get('content.' + name));
  334. App.db['set' + name.capitalize()](value);
  335. console.log(this.get('name') + ": saved " + name, value);
  336. },
  337. clear: function () {
  338. this.set('content', Ember.Object.create({
  339. 'controllerName': this.get('content.controllerName')
  340. }));
  341. this.set('currentStep', 0);
  342. this.clearStorageData();
  343. },
  344. clusterStatusTemplate : {
  345. name: "",
  346. status: "PENDING",
  347. isCompleted: false,
  348. requestId: null,
  349. installStartTime: null,
  350. installTime: null,
  351. isInstallError: false,
  352. isStartError: false,
  353. oldRequestsId: []
  354. },
  355. clearStorageData: function(){
  356. App.db.setService(undefined); //not to use this data at AddService page
  357. App.db.setHosts(undefined);
  358. App.db.setMasterComponentHosts(undefined);
  359. App.db.setSlaveComponentHosts(undefined);
  360. App.db.setCluster(undefined);
  361. App.db.setAllHostNames(undefined);
  362. App.db.setSlaveProperties(undefined);
  363. App.db.setInstallOptions(undefined);
  364. App.db.setAllHostNamesPattern(undefined);
  365. },
  366. installOptionsTemplate: {
  367. hostNames: "", //string
  368. manualInstall: false, //true, false
  369. useSsh: true, //bool
  370. isJavaHome : false, //bool
  371. javaHome: App.defaultJavaHome, //string
  372. localRepo: false, //true, false
  373. sshKey: "", //string
  374. bootRequestId: null //string
  375. },
  376. /**
  377. * Generate serviceComponents as pr the stack definition and save it to localdata
  378. * called form stepController step4WizardController
  379. */
  380. loadServiceComponents: function (displayOrderConfig, apiUrl) {
  381. var result = null;
  382. var method = 'GET';
  383. var testUrl = '/data/wizard/stack/hdp/version/1.2.0.json';
  384. var url = (App.testMode) ? testUrl : App.apiPrefix + apiUrl;
  385. $.ajax({
  386. type: method,
  387. url: url,
  388. async: false,
  389. dataType: 'text',
  390. timeout: App.timeout,
  391. success: function (data) {
  392. var jsonData = jQuery.parseJSON(data);
  393. console.log("TRACE: getService ajax call -> In success function for the getServiceComponents call");
  394. console.log("TRACE: jsonData.services : " + jsonData.services);
  395. // Creating Model
  396. var Service = Ember.Object.extend({
  397. serviceName: null,
  398. displayName: null,
  399. isDisabled: true,
  400. isSelected: true,
  401. isInstalled: false,
  402. description: null,
  403. version: null
  404. });
  405. var data = [];
  406. // loop through all the service components
  407. for (var i = 0; i < displayOrderConfig.length; i++) {
  408. var entry = jsonData.services.findProperty("name", displayOrderConfig[i].serviceName);
  409. var myService = Service.create({
  410. serviceName: entry.name,
  411. displayName: displayOrderConfig[i].displayName,
  412. isDisabled: i === 0,
  413. isSelected: true,
  414. isInstalled: false,
  415. isHidden: displayOrderConfig[i].isHidden,
  416. description: entry.comment,
  417. version: entry.version
  418. });
  419. data.push(myService);
  420. }
  421. result = data;
  422. console.log('TRACE: service components: ' + JSON.stringify(data));
  423. },
  424. error: function (request, ajaxOptions, error) {
  425. console.log("TRACE: STep5 -> In error function for the getServiceComponents call");
  426. console.log("TRACE: STep5 -> value of the url is: " + url);
  427. console.log("TRACE: STep5 -> error code status is: " + request.status);
  428. console.log('Step8: Error message is: ' + request.responseText);
  429. },
  430. statusCode: require('data/statusCodes')
  431. });
  432. return result;
  433. },
  434. loadServicesFromServer: function() {
  435. var services = App.db.getService();
  436. if (services) {
  437. return;
  438. }
  439. var displayOrderConfig = require('data/services');
  440. var apiUrl = App.get('stackVersionURL');
  441. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  442. this.set('content.services', apiService);
  443. App.db.setService(apiService);
  444. },
  445. registerErrPopup: function (header, message) {
  446. App.ModalPopup.show({
  447. header: header,
  448. secondary: false,
  449. onPrimary: function () {
  450. this.hide();
  451. },
  452. bodyClass: Ember.View.extend({
  453. template: Ember.Handlebars.compile(['<p>{{view.message}}</p>'].join('\n')),
  454. message: message
  455. })
  456. });
  457. },
  458. /**
  459. * Save hosts that the user confirmed to proceed with from step 3
  460. * @param stepController App.WizardStep3Controller
  461. */
  462. saveConfirmedHosts: function (stepController) {
  463. var hostInfo = {};
  464. stepController.get('content.hosts').forEach(function (_host) {
  465. hostInfo[_host.name] = {
  466. name: _host.name,
  467. cpu: _host.cpu,
  468. memory: _host.memory,
  469. disk_info: _host.disk_info,
  470. bootStatus: _host.bootStatus,
  471. isInstalled: false
  472. };
  473. });
  474. console.log('wizardController:saveConfirmedHosts: save hosts ', hostInfo);
  475. App.db.setHosts(hostInfo);
  476. this.set('content.hosts', hostInfo);
  477. },
  478. /**
  479. * Save data after installation to main controller
  480. * @param stepController App.WizardStep9Controller
  481. */
  482. saveInstalledHosts: function (stepController) {
  483. var hosts = stepController.get('hosts');
  484. var hostInfo = App.db.getHosts();
  485. for (var index in hostInfo) {
  486. hostInfo[index].status = "pending";
  487. var host = hosts.findProperty('name', hostInfo[index].name);
  488. if (host) {
  489. hostInfo[index].status = host.status;
  490. hostInfo[index].message = host.message;
  491. hostInfo[index].progress = host.progress;
  492. }
  493. }
  494. this.set('content.hosts', hostInfo);
  495. this.save('hosts');
  496. console.log('wizardController:saveInstalledHosts: save hosts ', hostInfo);
  497. },
  498. /**
  499. * Save slaveHostComponents to main controller
  500. * @param stepController
  501. */
  502. saveSlaveComponentHosts: function (stepController) {
  503. var hosts = stepController.get('hosts');
  504. var headers = stepController.get('headers');
  505. var formattedHosts = Ember.Object.create();
  506. headers.forEach(function(header) {
  507. formattedHosts.set(header.get('name'), []);
  508. });
  509. hosts.forEach(function (host) {
  510. var checkboxes = host.get('checkboxes');
  511. headers.forEach(function(header) {
  512. var cb = checkboxes.findProperty('title', header.get('label'));
  513. if (cb.get('checked')) {
  514. formattedHosts.get(header.get('name')).push({
  515. hostName: host.hostName,
  516. group: 'Default',
  517. isInstalled: cb.get('installed')
  518. });
  519. }
  520. });
  521. });
  522. var slaveComponentHosts = [];
  523. headers.forEach(function(header) {
  524. slaveComponentHosts.push({
  525. componentName: header.get('name'),
  526. displayName: header.get('label').replace(/\s/g, ''),
  527. hosts: formattedHosts.get(header.get('name'))
  528. });
  529. });
  530. App.db.setSlaveComponentHosts(slaveComponentHosts);
  531. console.log('wizardController.slaveComponentHosts: saved hosts', slaveComponentHosts);
  532. this.set('content.slaveComponentHosts', slaveComponentHosts);
  533. },
  534. /**
  535. * Return true if cluster data is loaded and false otherwise.
  536. * This is used for all wizard controllers except for installer wizard.
  537. */
  538. dataLoading: function(){
  539. var dfd = $.Deferred();
  540. this.connectOutlet('loading');
  541. if (App.router.get('clusterController.isLoaded')){
  542. dfd.resolve();
  543. } else{
  544. var interval = setInterval(function(){
  545. if (App.router.get('clusterController.isLoaded')){
  546. dfd.resolve();
  547. clearInterval(interval);
  548. }
  549. },50);
  550. }
  551. return dfd.promise();
  552. }
  553. })