wizard.js 16 KB

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