step2_controller.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. installType: function () {
  39. if (this.get('manualInstall') === true) {
  40. return 'manualDriven';
  41. } else {
  42. return 'ambariDriven';
  43. }
  44. }.observes('manualInstall'),
  45. hideRepoErrMsg: function () {
  46. if (this.get('localRepo') === false) {
  47. this.set('softRepoLocalPathNullErr', false);
  48. }
  49. }.observes('localRepo'),
  50. validateHostNames: function () {
  51. this.hostNameArr = this.get('hostNames').split(new RegExp("\\s"));
  52. for (var i = 0; i < this.hostNameArr.length; i++) {
  53. //TODO: other validation for hostnames will be covered over here
  54. // For now hostnames that start or end with '-' are not allowed
  55. if (/^\-/.test(this.hostNameArr[i]) || /\-$/.test(this.hostNameArr[i])) {
  56. console.log('Invalid host name: ' + this.hostNameArr[i]);
  57. this.set('hostNameErrMsg', Em.I18n.t('installer.step2.hostName.error.invalid'));
  58. this.set('hostNameErr', true);
  59. this.set('hostNameEmptyError', false);
  60. this.set('hostNameNotRequiredErr', false);
  61. return false;
  62. }
  63. }
  64. return true;
  65. },
  66. validateHosts: function () {
  67. if (this.get('hostNames') === '' && this.get('manualInstall') === false) {
  68. this.set('hostNameEmptyError', true);
  69. this.set('hostNameNotRequiredErr', false);
  70. this.set('hostNameErr', false);
  71. this.set('hostNameErrMsg', Em.I18n.t('installer.step2.hostName.error.required'));
  72. } else if (this.get('hostNames') !== '' && this.get('manualInstall') === true) {
  73. this.set('hostNameNotRequiredErr', true);
  74. this.set('hostNameEmptyError', false);
  75. this.set('hostNameErr', false);
  76. this.set('hostNameErrMsg', Em.I18n.t('installer.step2.hostName.error.notRequired'));
  77. } else {
  78. this.set('hostNameErr', false);
  79. this.set('hostNameEmptyError', false);
  80. this.set('hostNameNotRequiredErr', false);
  81. this.set('hostNameErrMsg', '');
  82. }
  83. }.observes('hostNames', 'manualInstall'),
  84. validateSSHKey: function () {
  85. if (this.get('manualInstall') === false) {
  86. if (this.get('sshKey') === '') {
  87. this.set('sshKeyNullErr', true);
  88. }
  89. else {
  90. this.set('sshKeyNullErr', false);
  91. }
  92. }
  93. }.observes('manualInstall', 'sshKey'),
  94. validatePassphrase: function () {
  95. if (this.get('manualInstall') === false) {
  96. if (this.get('passphrase') !== this.get('confirmPassphrase')) {
  97. this.set('passphraseMatchErr', true);
  98. } else {
  99. this.set('passphraseMatchErr', false);
  100. }
  101. }
  102. }.observes('manualInstall', 'passphrase', 'confirmPassphrase'),
  103. validateLocalRepo: function () {
  104. if (this.get('localRepo') === true) {
  105. if (this.get('localRepoPath') === '') {
  106. this.set('softRepoLocalPathNullErr', true);
  107. } else {
  108. this.set('softRepoLocalPathNullErr', false);
  109. }
  110. } else {
  111. this.set('softRepoLocalPathNullErr', false);
  112. }
  113. }.observes('localRepoPath'),
  114. validateStep2: function () {
  115. this.validateHosts();
  116. this.validateSSHKey();
  117. this.validatePassphrase();
  118. this.validateLocalRepo();
  119. return this.validateHostNames();
  120. },
  121. hostManageErr: function () {
  122. return (this.get('hostNameEmptyError') || this.get('hostNameNotRequiredErr') ||
  123. this.get('hostNameErr') || this.get('sshKeyNullErr') || this.get('passphraseMatchErr'));
  124. }.property('hostNameErrMsg', 'sshKeyNullErr', 'passphraseMatchErr'),
  125. sshLessInstall: function () {
  126. if (this.get('manualInstall') === true) {
  127. this.set('hostManageErr', false);
  128. this.set('hostNameEmptyError', false);
  129. this.set('sshKeyNullErr', false);
  130. this.set('passphraseMatchErr', false);
  131. }
  132. }.observes('manualInstall'),
  133. advOptErr: function () {
  134. return this.get('softRepoLocalPathNullErr');
  135. }.property('softRepoLocalPathNullErr'),
  136. step2Err: function () {
  137. if (this.get('hostManageErr') === true || this.get('advOptErr') === true) {
  138. this.set('isSubmitDisabled', true);
  139. } else {
  140. this.set('isSubmitDisabled', false);
  141. }
  142. }.observes('hostManageErr', 'advOptErr'),
  143. softRepo: function () {
  144. if (this.get('localRepo') === false) {
  145. this.set('localRepoPath', '');
  146. }
  147. }.observes('localRepo'),
  148. evaluateStep2: function () {
  149. //task1 = do primary validations on whole step before executing any further steps
  150. //task2 = parsing hostnames string to hostnames json array
  151. //task3 = check validation for every hostname and store it in localstorage
  152. //task4 = Storing ambari agent Install type in localStorage (installType maps at host level and so every host will have this as an property)
  153. //task5 = Storing path of software repository(remote/local repo) to localStorage
  154. //task6 = call to rest API: @Post http://ambari_server/api/bootstrap
  155. //task7 = On Manual Install, next button click pops up a warning with "proceed" and "close" buttons
  156. //task8 = On faliure of the previous call, show 'error injecting host information in server db'
  157. //task9 = On success of the previous call, go to step 3
  158. console.log('TRACE: Entering controller:InstallerStep2:evaluateStep2 function');
  159. console.log('value of manual install is: ' + this.get('manualInstall'));
  160. var validateResult = this.validateStep2();
  161. if (this.get('isSubmitDisabled') === true || validateResult === false) {
  162. console.log("ERROR: error in validation");
  163. return false;
  164. } else {
  165. if (this.get('manualInstall') === true) {
  166. this.manualInstallPopup();
  167. return true;
  168. }
  169. }
  170. var hostInfo = {};
  171. for (var i = 0; i < this.hostNameArr.length; i++) {
  172. hostInfo[this.hostNameArr[i]] = {
  173. name: this.hostNameArr[i],
  174. installType: this.get('installType')
  175. };
  176. }
  177. App.db.setHosts(hostInfo);
  178. if (this.get('localRepo') === false) {
  179. App.db.setSoftRepo({ 'repoType': 'remote', 'repoPath': null});
  180. } else {
  181. App.db.setSoftRepo({ 'repoType': 'local', 'repoPath': this.get('localRepoPath') });
  182. }
  183. // Just an additional check. If manualInstall is true, program should have not reached over here
  184. if (this.get('manualInstall') === false) {
  185. // For now using mock jquery call
  186. //TODO: hook up with bootstrap call
  187. var bootStrapData = {'sshKey': this.get('sshKey'), 'sshKeyPassphrase': this.get('passphrase'), hosts: this.get('hostNameArr')}.stringify;
  188. $.ajax({
  189. type: 'POST',
  190. url: '/ambari_server/api/bootstrap',
  191. data: bootStrapData,
  192. async: false,
  193. timeout: 2000,
  194. success: function () {
  195. console.log("TRACE: In success function for the post bootstrap function");
  196. App.transitionTo('step3');
  197. },
  198. error: function () {
  199. console.log("ERROR: bootstrap post call failed");
  200. return false;
  201. },
  202. statusCode: {
  203. 404: function () {
  204. console.log("URI not found.");
  205. alert("URI not found,. This needs to be hooked up with a @POST bootstrap call");
  206. //After the bootstrap call hook up change the below return statement to "return false"
  207. console.log("TRACE: In faliure function for the post bootstrap function");
  208. //Remove below line, once bootstrap has been implemented
  209. App.router.transitionTo('step3');
  210. return true;
  211. }
  212. },
  213. dataType: 'application/json'
  214. });
  215. } else {
  216. console.log("ERROR: ASSERTION FAILED -> program should have never reached over here");
  217. }
  218. },
  219. manualInstallPopup: function (event) {
  220. App.ModalPopup.show({
  221. header: Em.I18n.t('installer.step2.manualInstall.popup.header'),
  222. onPrimary: function () {
  223. this.hide();
  224. App.router.transitionTo('step3');
  225. },
  226. bodyClass: Ember.View.extend({
  227. templateName: require('templates/installer/step2ManualInstallPopup')
  228. })
  229. });
  230. }
  231. });