step2_controller.js 8.5 KB

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