wizard.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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 = 2; 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. prevInstallStatus: function () {
  55. console.log('Inside the prevInstallStep function: The name is ' + App.router.get('loginController.loginName'));
  56. var result = App.db.isCompleted()
  57. if (result == '1') {
  58. return true;
  59. }
  60. }.property('App.router.loginController.loginName'),
  61. /**
  62. * Set current step to new value.
  63. * Method moved from App.router.setInstallerCurrentStep
  64. * @param currentStep
  65. * @param completed
  66. */
  67. currentStep: function () {
  68. return App.get('router').getWizardCurrentStep(this.get('name').substr(0, this.get('name').length - 10));
  69. }.property(),
  70. /**
  71. * Set current step to new value.
  72. * Method moved from App.router.setInstallerCurrentStep
  73. * @param currentStep
  74. * @param completed
  75. */
  76. setCurrentStep: function (currentStep, completed) {
  77. App.db.setWizardCurrentStep(this.get('name').substr(0, this.get('name').length - 10), currentStep, completed);
  78. this.set('currentStep', currentStep);
  79. },
  80. clusters: null,
  81. isStep1: function () {
  82. return this.get('currentStep') == 1;
  83. }.property('currentStep'),
  84. isStep2: function () {
  85. return this.get('currentStep') == 2;
  86. }.property('currentStep'),
  87. isStep3: function () {
  88. return this.get('currentStep') == 3;
  89. }.property('currentStep'),
  90. isStep4: function () {
  91. return this.get('currentStep') == 4;
  92. }.property('currentStep'),
  93. isStep5: function () {
  94. return this.get('currentStep') == 5;
  95. }.property('currentStep'),
  96. isStep6: function () {
  97. return this.get('currentStep') == 6;
  98. }.property('currentStep'),
  99. isStep7: function () {
  100. return this.get('currentStep') == 7;
  101. }.property('currentStep'),
  102. isStep8: function () {
  103. return this.get('currentStep') == 8;
  104. }.property('currentStep'),
  105. isStep9: function () {
  106. return this.get('currentStep') == 9;
  107. }.property('currentStep'),
  108. isStep10: function () {
  109. return this.get('currentStep') == 10;
  110. }.property('currentStep'),
  111. gotoStep: function (step) {
  112. if (this.get('isStepDisabled').findProperty('step', step).get('value') !== false) {
  113. return;
  114. }
  115. if ((this.get('currentStep') - step) > 1) {
  116. App.ModalPopup.show({
  117. header: Em.I18n.t('installer.navigation.warning.header'),
  118. onPrimary: function () {
  119. App.router.send('gotoStep' + step);
  120. this.hide();
  121. },
  122. body: "If you proceed to go back to Step " + step + ", you will lose any changes you have made beyond this step"
  123. });
  124. } else {
  125. App.router.send('gotoStep' + step);
  126. }
  127. },
  128. gotoStep1: function () {
  129. this.gotoStep(1);
  130. },
  131. gotoStep2: function () {
  132. this.gotoStep(2);
  133. },
  134. gotoStep3: function () {
  135. this.gotoStep(3);
  136. },
  137. gotoStep4: function () {
  138. this.gotoStep(4);
  139. },
  140. gotoStep5: function () {
  141. this.gotoStep(5);
  142. },
  143. gotoStep6: function () {
  144. this.gotoStep(6);
  145. },
  146. gotoStep7: function () {
  147. this.gotoStep(7);
  148. },
  149. gotoStep8: function () {
  150. this.gotoStep(8);
  151. },
  152. gotoStep9: function () {
  153. this.gotoStep(9);
  154. },
  155. gotoStep10: function () {
  156. this.gotoStep(10);
  157. },
  158. /**
  159. * Temporary function for wizardStep9, before back-end integration
  160. */
  161. setInfoForStep9: function () {
  162. var hostInfo = App.db.getHosts();
  163. for (var index in hostInfo) {
  164. hostInfo[index].status = "pending";
  165. hostInfo[index].message = 'Waiting';
  166. hostInfo[index].logTasks = [];
  167. hostInfo[index].tasks = [];
  168. hostInfo[index].progress = '0';
  169. }
  170. App.db.setHosts(hostInfo);
  171. },
  172. /**
  173. * Remove all data for installOptions step
  174. */
  175. clearInstallOptions: function () {
  176. var installOptions = jQuery.extend({}, this.get('installOptionsTemplate'));
  177. this.set('content.installOptions', installOptions);
  178. this.save('installOptions');
  179. this.set('content.hosts', []);
  180. this.save('hosts');
  181. },
  182. toObject: function(object){
  183. var result = {};
  184. for(var i in object){
  185. if(object.hasOwnProperty(i)){
  186. result[i] = object[i];
  187. }
  188. }
  189. return result;
  190. },
  191. /**
  192. * save status of the cluster. This is called from step8 and step9 to persist install and start requestId
  193. * @param clusterStatus object with status, isCompleted, requestId, isInstallError and isStartError field.
  194. */
  195. saveClusterStatus: function (clusterStatus) {
  196. var oldStatus = this.toObject(this.get('content.cluster'));
  197. clusterStatus = jQuery.extend(oldStatus, clusterStatus);
  198. if (clusterStatus.requestId &&
  199. clusterStatus.oldRequestsId.indexOf(clusterStatus.requestId) === -1){
  200. clusterStatus.oldRequestsId.push(clusterStatus.requestId);
  201. }
  202. this.set('content.cluster', clusterStatus);
  203. this.save('cluster');
  204. },
  205. /**
  206. * Invoke installation of selected services to the server and saves the request id returned by the server.
  207. * @param isRetry
  208. */
  209. installServices: function (isRetry) {
  210. // clear requests since we are installing services
  211. // and we don't want to get tasks for previous install attempts
  212. this.set('content.cluster.oldRequestsId', []);
  213. this.set('content.cluster.requestId', null);
  214. var self = this;
  215. var clusterName = this.get('content.cluster.name');
  216. var url;
  217. var method = (App.testMode) ? 'GET' : 'PUT';
  218. var data;
  219. switch (this.get('content.controllerName')) {
  220. case 'addHostController':
  221. if (isRetry) {
  222. url = App.apiPrefix + '/clusters/' + clusterName + '/host_components?HostRoles/state!=INSTALLED';
  223. data = '{"HostRoles": {"state": "INSTALLED"}}';
  224. } else {
  225. url = App.apiPrefix + '/clusters/' + clusterName + '/host_components?HostRoles/state=INIT';
  226. data = '{"HostRoles": {"state": "INSTALLED"}}';
  227. }
  228. break;
  229. case 'installerController':
  230. default:
  231. if (isRetry) {
  232. url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + clusterName + '/host_components?HostRoles/state!=INSTALLED';
  233. data = '{"HostRoles": {"state": "INSTALLED"}}';
  234. } else {
  235. url = (App.testMode) ? '/data/wizard/deploy/2_hosts/poll_1.json' : App.apiPrefix + '/clusters/' + clusterName + '/services?ServiceInfo/state=INIT';
  236. data = '{"ServiceInfo": {"state": "INSTALLED"}}';
  237. }
  238. break;
  239. }
  240. $.ajax({
  241. type: method,
  242. url: url,
  243. data: data,
  244. async: false,
  245. dataType: 'text',
  246. timeout: App.timeout,
  247. success: function (data) {
  248. var jsonData = jQuery.parseJSON(data);
  249. var installStartTime = new Date().getTime();
  250. console.log("TRACE: In success function for the installService call");
  251. console.log("TRACE: value of the url is: " + url);
  252. if (jsonData) {
  253. var requestId = jsonData.Requests.id;
  254. console.log('requestId is: ' + requestId);
  255. var clusterStatus = {
  256. status: 'PENDING',
  257. requestId: requestId,
  258. isInstallError: false,
  259. isCompleted: false,
  260. installStartTime: installStartTime
  261. };
  262. self.saveClusterStatus(clusterStatus);
  263. } else {
  264. console.log('ERROR: Error occurred in parsing JSON data');
  265. }
  266. },
  267. error: function (request, ajaxOptions, error) {
  268. console.log("TRACE: In error function for the installService call");
  269. console.log("TRACE: value of the url is: " + url);
  270. console.log("TRACE: error code status is: " + request.status);
  271. console.log('Error message is: ' + request.responseText);
  272. var clusterStatus = {
  273. status: 'PENDING',
  274. isInstallError: false,
  275. isCompleted: false
  276. };
  277. self.saveClusterStatus(clusterStatus);
  278. },
  279. statusCode: require('data/statusCodes')
  280. });
  281. },
  282. /*
  283. Bootstrap selected hosts.
  284. */
  285. launchBootstrap: function (bootStrapData) {
  286. var self = this;
  287. var requestId = null;
  288. var method = App.testMode ? 'GET' : 'POST';
  289. var url = App.testMode ? '/data/wizard/bootstrap/bootstrap.json' : App.apiPrefix + '/bootstrap';
  290. $.ajax({
  291. type: method,
  292. url: url,
  293. async: false,
  294. data: bootStrapData,
  295. timeout: App.timeout,
  296. contentType: 'application/json',
  297. success: function (data) {
  298. console.log("TRACE: POST bootstrap succeeded");
  299. requestId = data.requestId;
  300. },
  301. error: function () {
  302. console.log("ERROR: POST bootstrap failed");
  303. alert('Bootstrap call failed. Please try again.');
  304. },
  305. statusCode: require('data/statusCodes')
  306. });
  307. return requestId;
  308. },
  309. /**
  310. * Load <code>content.<name></code> variable from localStorage, if wasn't loaded before.
  311. * If you specify <code>reload</code> to true - it will reload it.
  312. * @param name
  313. * @param reload
  314. * @return {Boolean}
  315. */
  316. load: function (name, reload) {
  317. if (this.get('content.' + name) && !reload) {
  318. return false;
  319. }
  320. var result = App.db['get' + name.capitalize()]();
  321. if (!result){
  322. result = this['get' + name.capitalize()]();
  323. App.db['set' + name.capitalize()](result);
  324. console.log(this.get('name') + ": created " + name, result);
  325. }
  326. this.set('content.' + name, result);
  327. console.log(this.get('name') + ": loaded " + name, result);
  328. },
  329. save: function(name){
  330. var value = this.toObject(this.get('content.' + name));
  331. App.db['set' + name.capitalize()](value);
  332. console.log(this.get('name') + ": saved " + name, value);
  333. },
  334. clear: function () {
  335. this.set('content', Ember.Object.create({
  336. 'controllerName': this.get('content.controllerName'),
  337. 'isWizard': !(this.get('content.controllerName') === 'installerController')
  338. }));
  339. this.set('currentStep', 0);
  340. this.clearStorageData();
  341. },
  342. clusterStatusTemplate : {
  343. name: "",
  344. status: "PENDING",
  345. isCompleted: false,
  346. requestId: null,
  347. installStartTime: null,
  348. installTime: null,
  349. isInstallError: false,
  350. isStartError: false,
  351. oldRequestsId: []
  352. },
  353. clearStorageData: function(){
  354. App.db.setService(undefined); //not to use this data at AddService page
  355. App.db.setHosts(undefined);
  356. App.db.setMasterComponentHosts(undefined);
  357. App.db.setSlaveComponentHosts(undefined);
  358. App.db.setCluster(undefined);
  359. App.db.setAllHostNames(undefined);
  360. App.db.setSlaveProperties(undefined);
  361. App.db.setInstallOptions(undefined);
  362. App.db.setAllHostNamesPattern(undefined);
  363. },
  364. installOptionsTemplate: {
  365. hostNames: "", //string
  366. manualInstall: false, //true, false
  367. useSsh: true, //bool
  368. isJavaHome : false, //bool
  369. javaHome: App.defaultJavaHome, //string
  370. localRepo: false, //true, false
  371. sshKey: "", //string
  372. bootRequestId: null //string
  373. },
  374. /**
  375. * Generate serviceComponents as pr the stack definition and save it to localdata
  376. * called form stepController step4WizardController
  377. */
  378. loadServiceComponents: function (displayOrderConfig, apiUrl) {
  379. var result = null;
  380. var method = 'GET';
  381. var testUrl = '/data/wizard/stack/hdp/version/1.2.0.json';
  382. var url = (App.testMode) ? testUrl : App.apiPrefix + apiUrl;
  383. $.ajax({
  384. type: method,
  385. url: url,
  386. async: false,
  387. dataType: 'text',
  388. timeout: App.timeout,
  389. success: function (data) {
  390. var jsonData = jQuery.parseJSON(data);
  391. console.log("TRACE: getService ajax call -> In success function for the getServiceComponents call");
  392. console.log("TRACE: jsonData.services : " + jsonData.services);
  393. // Creating Model
  394. var Service = Ember.Object.extend({
  395. serviceName: null,
  396. displayName: null,
  397. isDisabled: true,
  398. isSelected: true,
  399. isInstalled: false,
  400. description: null,
  401. version: null
  402. });
  403. var data = [];
  404. // loop through all the service components
  405. for (var i = 0; i < displayOrderConfig.length; i++) {
  406. var entry = jsonData.services.findProperty("name", displayOrderConfig[i].serviceName);
  407. var myService = Service.create({
  408. serviceName: entry.name,
  409. displayName: displayOrderConfig[i].displayName,
  410. isDisabled: i === 0,
  411. isSelected: true,
  412. isInstalled: false,
  413. isHidden: displayOrderConfig[i].isHidden,
  414. description: entry.comment,
  415. version: entry.version
  416. });
  417. data.push(myService);
  418. }
  419. result = data;
  420. console.log('TRACE: service components: ' + JSON.stringify(data));
  421. },
  422. error: function (request, ajaxOptions, error) {
  423. console.log("TRACE: STep5 -> In error function for the getServiceComponents call");
  424. console.log("TRACE: STep5 -> value of the url is: " + url);
  425. console.log("TRACE: STep5 -> error code status is: " + request.status);
  426. console.log('Step8: Error message is: ' + request.responseText);
  427. },
  428. statusCode: require('data/statusCodes')
  429. });
  430. return result;
  431. },
  432. loadServicesFromServer: function() {
  433. var services = App.db.getService();
  434. if (services) {
  435. return;
  436. }
  437. var displayOrderConfig = require('data/services');
  438. var apiUrl = '/stacks/HDP/version/1.2.0';
  439. var apiService = this.loadServiceComponents(displayOrderConfig, apiUrl);
  440. this.set('content.services', apiService);
  441. App.db.setService(apiService);
  442. },
  443. /**
  444. * Load properties for group of slaves to model
  445. */
  446. loadSlaveGroupProperties: function () {
  447. var groupConfigProperties = App.db.getSlaveProperties() ? App.db.getSlaveProperties() : this.get('content.slaveComponentHosts');
  448. if (groupConfigProperties) {
  449. groupConfigProperties.forEach(function (_slaveComponentObj) {
  450. if (_slaveComponentObj.groups) {
  451. var groups = [];
  452. _slaveComponentObj.groups.forEach(function (_group) {
  453. var properties = [];
  454. _group.properties.forEach(function (_property) {
  455. var property = App.ServiceConfigProperty.create(_property);
  456. property.set('value', _property.storeValue);
  457. properties.pushObject(property);
  458. }, this);
  459. _group.properties = properties;
  460. groups.pushObject(App.Group.create(_group));
  461. }, this);
  462. _slaveComponentObj.groups = groups;
  463. }
  464. }, this);
  465. }
  466. this.set('content.slaveGroupProperties', groupConfigProperties);
  467. },
  468. registerErrPopup: function (header, message) {
  469. App.ModalPopup.show({
  470. header: header,
  471. secondary: false,
  472. onPrimary: function () {
  473. this.hide();
  474. },
  475. bodyClass: Ember.View.extend({
  476. template: Ember.Handlebars.compile(['<p>{{view.message}}</p>'].join('\n')),
  477. message: message
  478. })
  479. });
  480. }
  481. })