step2_controller.js 8.2 KB

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