add_controller.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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.AddHostController = Em.Controller.extend({
  20. name: 'addHostController',
  21. /**
  22. * All wizards data will be stored in this variable
  23. */
  24. content: Em.Object.create(),
  25. /**
  26. * Used for hiding back button in wizard
  27. */
  28. hideBackButton: true,
  29. isStepDisabled: [],
  30. totalSteps: 9,
  31. init: function () {
  32. this.isStepDisabled.pushObject(Ember.Object.create({
  33. step: 1,
  34. value: false
  35. }));
  36. for (var i = 2; i <= this.totalSteps; i++) {
  37. this.isStepDisabled.pushObject(Ember.Object.create({
  38. step: i,
  39. value: true
  40. }));
  41. }
  42. },
  43. setStepsEnable: function () {
  44. for (var i = 2; i <= this.totalSteps; i++) {
  45. var step = this.get('isStepDisabled').findProperty('step', i);
  46. if (i <= this.get('currentStep')) {
  47. step.set('value', false);
  48. } else {
  49. step.set('value', true);
  50. }
  51. }
  52. }.observes('currentStep'),
  53. /**
  54. * Return current step of Add Host Wizard
  55. */
  56. currentStep: function () {
  57. return App.get('router').getWizardCurrentStep('addHost');
  58. }.property(),
  59. /**
  60. * Set current step to new value.
  61. * Method moved from App.router.setInstallerCurrentStep
  62. * @param currentStep
  63. * @param completed
  64. */
  65. setCurrentStep: function (currentStep, completed) {
  66. App.db.setWizardCurrentStep('addHost', currentStep, completed);
  67. this.set('currentStep', currentStep);
  68. },
  69. isStep1: function () {
  70. return this.get('currentStep') == 1;
  71. }.property('currentStep'),
  72. isStep2: function () {
  73. return this.get('currentStep') == 2;
  74. }.property('currentStep'),
  75. isStep3: function () {
  76. return this.get('currentStep') == 3;
  77. }.property('currentStep'),
  78. isStep4: function () {
  79. return this.get('currentStep') == 4;
  80. }.property('currentStep'),
  81. isStep5: function () {
  82. return this.get('currentStep') == 5;
  83. }.property('currentStep'),
  84. isStep6: function () {
  85. return this.get('currentStep') == 6;
  86. }.property('currentStep'),
  87. isStep7: function () {
  88. return this.get('currentStep') == 7;
  89. }.property('currentStep'),
  90. isStep8: function () {
  91. return this.get('currentStep') == 8;
  92. }.property('currentStep'),
  93. isStep9: function () {
  94. return this.get('currentStep') == 9;
  95. }.property('currentStep'),
  96. isStep10: function () {
  97. return this.get('currentStep') == 10;
  98. }.property('currentStep'),
  99. gotoStep: function (step) {
  100. if (this.get('isStepDisabled').findProperty('step', step).get('value') === false) {
  101. App.router.send('gotoStep' + step);
  102. }
  103. },
  104. gotoStep1: function () {
  105. this.gotoStep(1);
  106. },
  107. gotoStep2: function () {
  108. this.gotoStep(2);
  109. },
  110. gotoStep3: function () {
  111. this.gotoStep(3);
  112. },
  113. gotoStep4: function () {
  114. this.gotoStep(4);
  115. },
  116. gotoStep5: function () {
  117. this.gotoStep(5);
  118. },
  119. gotoStep6: function () {
  120. this.gotoStep(6);
  121. },
  122. gotoStep7: function () {
  123. this.gotoStep(7);
  124. },
  125. gotoStep8: function () {
  126. this.gotoStep(8);
  127. },
  128. gotoStep9: function () {
  129. this.gotoStep(9);
  130. },
  131. gotoStep10: function () {
  132. this.gotoStep(10);
  133. },
  134. /**
  135. * Load all data for <code>Specify Host(install step2)</code> step
  136. * Data Example:
  137. * {
  138. * hostNames: '',
  139. * manualInstall: false,
  140. * sshKey: '',
  141. * passphrase: '',
  142. * confirmPassphrase: '',
  143. * localRepo: false,
  144. * localRepoPath: ''
  145. * }
  146. */
  147. loadHosts: function () {
  148. if (!this.content.hosts) {
  149. this.content.hosts = Em.Object.create();
  150. }
  151. //TODO : rewire it as model. or not :)
  152. var hostsInfo = Em.Object.create();
  153. hostsInfo.hostNames = App.db.getAllHostNames() || ''; //empty string if undefined
  154. //TODO : should we check installType for add host wizard????
  155. var installType = App.db.getInstallType();
  156. //false if installType not equals 'manual'
  157. hostsInfo.manualInstall = installType && installType.installType === 'manual' || false;
  158. var softRepo = App.db.getSoftRepo();
  159. if (softRepo && softRepo.repoType === 'local') {
  160. hostsInfo.localRepo = true;
  161. hostsInfo.localRepopath = softRepo.repoPath;
  162. } else {
  163. hostsInfo.localRepo = false;
  164. hostsInfo.localRepoPath = '';
  165. }
  166. hostsInfo.sshKey = 'random';
  167. hostsInfo.passphrase = '';
  168. hostsInfo.confirmPassphrase = '';
  169. this.set('content.hosts', hostsInfo);
  170. console.log("AddHostController:loadHosts: loaded data ", hostsInfo);
  171. },
  172. /**
  173. * Save data, which user filled, to main controller
  174. * @param stepController App.WizardStep2Controller
  175. */
  176. saveHosts: function (stepController) {
  177. //TODO: put data to content.hosts and only then save it)
  178. //App.db.setBootStatus(false);
  179. App.db.setAllHostNames(stepController.get('hostNames'));
  180. App.db.setHosts(stepController.getHostInfo());
  181. if (stepController.get('manualInstall') === false) {
  182. App.db.setInstallType({installType: 'ambari' });
  183. } else {
  184. App.db.setInstallType({installType: 'manual' });
  185. }
  186. if (stepController.get('localRepo') === false) {
  187. App.db.setSoftRepo({ 'repoType': 'remote', 'repoPath': null});
  188. } else {
  189. App.db.setSoftRepo({ 'repoType': 'local', 'repoPath': stepController.get('localRepoPath') });
  190. }
  191. },
  192. /**
  193. * Return hosts, which were add at <code>Specify Host(step2)</code> step
  194. * @paramm isNew whether return all hosts or only new ones
  195. */
  196. getHostList: function (isNew) {
  197. var hosts = [];
  198. var hostArray = App.db.getHosts()
  199. console.log('in addHostController.getHostList: host names is ', hostArray);
  200. for (var i in hostArray) {
  201. var hostInfo = App.HostInfo.create({
  202. name: hostArray[i].name,
  203. bootStatus: hostArray[i].bootStatus
  204. });
  205. hosts.pushObject(hostInfo);
  206. }
  207. ;
  208. console.log('TRACE: pushing ' + hosts);
  209. return hosts;
  210. },
  211. /**
  212. * Remove host from model. Used at <code>Confirm hosts(step2)</code> step
  213. * @param hosts Array of hosts, which we want to delete
  214. */
  215. removeHosts: function (hosts) {
  216. //todo Replace this code with real logic
  217. App.db.removeHosts(hosts);
  218. },
  219. /**
  220. * Save data, which user filled, to main controller
  221. * @param stepController App.WizardStep3Controller
  222. */
  223. saveConfirmedHosts: function (stepController) {
  224. var hostInfo = {};
  225. stepController.get('content').forEach(function (_host) {
  226. hostInfo[_host.name] = {
  227. name: _host.name,
  228. cpu: _host.cpu,
  229. memory: _host.memory,
  230. bootStatus: _host.bootStatus
  231. };
  232. });
  233. console.log('addHostController:saveConfirmedHosts: save hosts ', hostInfo);
  234. App.db.setHosts(hostInfo);
  235. },
  236. /**
  237. * Remove all data for hosts
  238. */
  239. clearHosts: function () {
  240. var hosts = this.get('content').get('hosts');
  241. if (hosts) {
  242. hosts.hostNames = '';
  243. hosts.manualInstall = false;
  244. hosts.localRepo = '';
  245. hosts.localRepopath = '';
  246. hosts.sshKey = '';
  247. hosts.passphrase = '';
  248. hosts.confirmPassphrase = '';
  249. }
  250. },
  251. /**
  252. * Load services data. Will be used at <code>Select services(step4)</code> step
  253. */
  254. loadServices: function () {
  255. var servicesInfo = App.db.getService();
  256. servicesInfo.forEach(function (item, index) {
  257. servicesInfo[index] = Em.Object.create(item);
  258. });
  259. this.set('content.services', servicesInfo);
  260. console.log('addHostController.loadServices: loaded data ', servicesInfo);
  261. },
  262. /**
  263. * Save data to model
  264. * @param stepController App.WizardStep4Controller
  265. */
  266. saveServices: function (stepController) {
  267. var serviceNames = [];
  268. App.db.setService(stepController.get('content'));
  269. stepController.filterProperty('isSelected', true).forEach(function (item) {
  270. serviceNames.push(item.serviceName);
  271. });
  272. App.db.setSelectedServiceNames(serviceNames);
  273. console.log('addHostController.saveServices: saved data ', serviceNames);
  274. },
  275. /**
  276. * Load data for all steps until <code>current step</code>
  277. */
  278. loadAllPriorSteps: function () {
  279. var step = this.get('currentStep');
  280. switch (step) {
  281. /*case '10':
  282. this.get('installerStep9Controller').loadStep();
  283. case '9':
  284. this.get('installerStep8Controller').loadStep();
  285. case '8':
  286. this.get('installerStep7Controller').loadStep();
  287. case '7':
  288. this.get('installerStep6Controller').loadStep();
  289. case '6':
  290. this.get('installerStep5Controller').loadStep();
  291. case '5':
  292. this.get('installerStep4Controller').loadStep();*/
  293. case '4':
  294. //this.get('installerStep3Controller').loadStep();
  295. case '3':
  296. this.loadServices();
  297. case '2':
  298. case '1':
  299. this.loadHosts();
  300. }
  301. },
  302. /**
  303. * Remove all loaded data.
  304. * Created as copy for App.router.clearAllSteps
  305. */
  306. clearAllSteps: function () {
  307. this.clearHosts();
  308. }
  309. });