step2_controller.js 8.9 KB

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