step2_controller.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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.InstallerStep2Controller = Em.Controller.extend({
  20. name: 'installerStep2Controller',
  21. content: [],
  22. hostNames: '',
  23. hostNameArr: [],
  24. hostNameEmptyError: false,
  25. hostNameErr: false,
  26. manualInstall: false,
  27. hostNameNotRequiredErr: false,
  28. hostNameErrMsg: '',
  29. sshKey: '',
  30. passphrase: '',
  31. confirmPassphrase: '',
  32. sshKeyNullErr: false,
  33. passphraseMatchErr: false,
  34. localRepo: false,
  35. localRepoPath: '',
  36. softRepoLocalPathNullErr: false,
  37. isSubmitDisabled: false,
  38. clearStep: function () {
  39. this.set('hostNames', '');
  40. this.set('sshKey', '');
  41. this.set('passphrase', '');
  42. this.set('confirmPassphrase', '');
  43. this.set('localRepoPath', '');
  44. },
  45. navigateStep: function () {
  46. if (App.router.get('isFwdNavigation') === true) {
  47. this.loadStep();
  48. }
  49. },
  50. loadStep: function () {
  51. console.log("TRACE: Loading step2: Install Options");
  52. var hostNames = App.db.getAllHostNames();
  53. var softrepo = App.db.getSoftRepo();
  54. var installType = App.db.getInstallType();
  55. if (hostNames !== undefined) {
  56. this.set('hostNames', hostNames);
  57. } else {
  58. this.set('hostNames', '');
  59. }
  60. if (installType !== undefined && installType.installType === 'manual') {
  61. this.set('manualInstall', true);
  62. } else {
  63. this.set('manualInstall', false);
  64. }
  65. if (softrepo !== undefined && softrepo.repoType === 'local') {
  66. this.set('localRepo', true);
  67. this.set('localRepoPath', softrepo.repoPath);
  68. } else {
  69. this.set('localRepo', false);
  70. this.set('localRepoPath', '');
  71. }
  72. },
  73. installType: function () {
  74. if (this.get('manualInstall') === true) {
  75. return 'manualDriven';
  76. } else {
  77. return 'ambariDriven';
  78. }
  79. }.observes('manualInstall'),
  80. hideRepoErrMsg: function () {
  81. if (this.get('localRepo') === false) {
  82. this.set('softRepoLocalPathNullErr', false);
  83. }
  84. }.observes('localRepo'),
  85. validateHostNames: function () {
  86. this.hostNameArr = this.get('hostNames').trim().split(new RegExp("\\s+", "g"));
  87. for (var index in this.hostNameArr) {
  88. console.log("host name is: " + this.hostNameArr[index]);
  89. //TODO: other validation for hostnames will be covered over here
  90. // For now hostnames that start or end with '-' are not allowed
  91. if (/^\-/.test(this.hostNameArr[index]) || /\-$/.test(this.hostNameArr[index])) {
  92. console.log('Invalid host name: ' + this.hostNameArr[index]);
  93. this.set('hostNameErr', true);
  94. this.set('hostNameErrMsg', Em.I18n.t('installer.step2.hostName.error.invalid'));
  95. this.set('hostNameEmptyError', false);
  96. this.set('hostNameNotRequiredErr', false);
  97. return false;
  98. }
  99. }
  100. return true;
  101. },
  102. validateHosts: function () {
  103. if (this.get('hostNames') === '' && this.get('manualInstall') === false) {
  104. this.set('hostNameEmptyError', true);
  105. this.set('hostNameNotRequiredErr', false);
  106. this.set('hostNameErr', false);
  107. this.set('hostNameErrMsg', Em.I18n.t('installer.step2.hostName.error.required'));
  108. } else if (this.get('hostNames') !== '' && this.get('manualInstall') === true) {
  109. this.set('hostNameNotRequiredErr', true);
  110. this.set('hostNameEmptyError', false);
  111. this.set('hostNameErr', false);
  112. this.set('hostNameErrMsg', Em.I18n.t('installer.step2.hostName.error.notRequired'));
  113. } else {
  114. this.set('hostNameErr', false);
  115. this.set('hostNameEmptyError', false);
  116. this.set('hostNameNotRequiredErr', false);
  117. this.set('hostNameErrMsg', '');
  118. }
  119. }.observes('hostNames', 'manualInstall'),
  120. validateSSHKey: function () {
  121. if (this.get('manualInstall') === false) {
  122. if (this.get('sshKey') === '') {
  123. this.set('sshKeyNullErr', true);
  124. }
  125. else {
  126. this.set('sshKeyNullErr', false);
  127. }
  128. }
  129. }.observes('manualInstall', 'sshKey'),
  130. validatePassphrase: function () {
  131. if (this.get('manualInstall') === false) {
  132. if (this.get('passphrase') !== this.get('confirmPassphrase')) {
  133. this.set('passphraseMatchErr', true);
  134. } else {
  135. this.set('passphraseMatchErr', false);
  136. }
  137. }
  138. }.observes('manualInstall', 'passphrase', 'confirmPassphrase'),
  139. validateLocalRepo: function () {
  140. if (this.get('localRepo') === true) {
  141. if (this.get('localRepoPath') === '') {
  142. this.set('softRepoLocalPathNullErr', true);
  143. } else {
  144. this.set('softRepoLocalPathNullErr', false);
  145. }
  146. } else {
  147. this.set('softRepoLocalPathNullErr', false);
  148. }
  149. }.observes('localRepoPath'),
  150. validateStep2: function () {
  151. this.validateHosts();
  152. this.validateSSHKey();
  153. this.validatePassphrase();
  154. this.validateLocalRepo();
  155. return this.validateHostNames();
  156. },
  157. hostManageErr: function () {
  158. return (this.get('hostNameEmptyError') || this.get('hostNameNotRequiredErr') ||
  159. this.get('hostNameErr') || this.get('sshKeyNullErr') || this.get('passphraseMatchErr'));
  160. }.property('hostNameErrMsg', 'sshKeyNullErr', 'passphraseMatchErr'),
  161. sshLessInstall: function () {
  162. if (this.get('manualInstall') === true) {
  163. this.set('hostManageErr', false);
  164. this.set('hostNameEmptyError', false);
  165. this.set('sshKeyNullErr', false);
  166. this.set('passphraseMatchErr', false);
  167. }
  168. }.observes('manualInstall'),
  169. advOptErr: function () {
  170. return this.get('softRepoLocalPathNullErr');
  171. }.property('softRepoLocalPathNullErr'),
  172. step2Err: function () {
  173. if (this.get('hostManageErr') === true || this.get('advOptErr') === true) {
  174. this.set('isSubmitDisabled', true);
  175. } else {
  176. this.set('isSubmitDisabled', false);
  177. }
  178. }.observes('hostManageErr', 'advOptErr'),
  179. softRepo: function () {
  180. if (this.get('localRepo') === false) {
  181. this.set('localRepoPath', '');
  182. }
  183. }.observes('localRepo'),
  184. evaluateStep2: function () {
  185. console.log('TRACE: Entering controller:InstallerStep2:evaluateStep2 function');
  186. console.log('value of manual install is: ' + this.get('manualInstall'));
  187. if (this.get('isSubmitDisabled') === true) {
  188. console.log("ERROR: error in validation");
  189. return false;
  190. }
  191. var validateResult = !this.validateStep2();
  192. var hostInfo = {};
  193. for (var i = 0; i < this.hostNameArr.length; i++) {
  194. hostInfo[this.hostNameArr[i]] = {
  195. name: this.hostNameArr[i],
  196. installType: this.get('installType'),
  197. bootStatus: 'pending'
  198. };
  199. }
  200. App.db.setAllHostNames(this.get('hostNames'));
  201. App.db.setHosts(hostInfo);
  202. if (this.get('manualInstall') === false) {
  203. App.db.setInstallType({installType: 'ambari' });
  204. } else {
  205. App.db.setInstallType({installType: 'manual' });
  206. }
  207. if (this.get('localRepo') === false) {
  208. App.db.setSoftRepo({ 'repoType': 'remote', 'repoPath': null});
  209. } else {
  210. App.db.setSoftRepo({ 'repoType': 'local', 'repoPath': this.get('localRepoPath') });
  211. }
  212. if (this.get('manualInstall') === true) {
  213. this.manualInstallPopup();
  214. return true;
  215. }
  216. if (this.get('manualInstall') === false) {
  217. // For now using mock jquery call
  218. //TODO: hook up with bootstrap call
  219. var bootStrapData = {'sshKey': this.get('sshKey'), 'sshKeyPassphrase': this.get('passphrase'), hosts: this.get('hostNameArr')}.stringify;
  220. $.ajax({
  221. type: 'POST',
  222. url: '/ambari_server/api/bootstrap',
  223. data: bootStrapData,
  224. async: false,
  225. timeout: 2000,
  226. success: function () {
  227. console.log("TRACE: In success function for the post bootstrap function");
  228. App.router.transitionTo('step3');
  229. },
  230. error: function () {
  231. console.log("ERROR: bootstrap post call failed");
  232. return false;
  233. },
  234. statusCode: {
  235. 404: function () {
  236. console.log("URI not found.");
  237. alert("URI not found,. This needs to be hooked up with a @POST bootstrap call");
  238. //After the bootstrap call hook up change the below return statement to "return false"
  239. console.log("TRACE: In faliure function for the post bootstrap function");
  240. //Remove below line, once bootstrap has been implemented
  241. App.router.send('next');
  242. return true;
  243. }
  244. },
  245. dataType: 'application/json'
  246. });
  247. } else {
  248. console.log("ERROR: ASSERTION FAILED -> program should have never reached over here");
  249. }
  250. },
  251. manualInstallPopup: function (event) {
  252. App.ModalPopup.show({
  253. header: Em.I18n.t('installer.step2.manualInstall.popup.header'),
  254. onPrimary: function () {
  255. this.hide();
  256. App.router.send('next');
  257. //App.router.transitionTo('step3');
  258. },
  259. bodyClass: Ember.View.extend({
  260. templateName: require('templates/installer/step2ManualInstallPopup')
  261. })
  262. });
  263. }
  264. });