wizard.js 17 KB

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