step2_controller.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. manualInstall: false,
  25. sshKey: '',
  26. passphrase: '',
  27. confirmPassphrase: '',
  28. localRepo: false,
  29. localRepoPath: '',
  30. hasSubmitted: false,
  31. clearStep: function () {
  32. this.set('hostNames', '');
  33. this.set('sshKey', '');
  34. this.set('passphrase', '');
  35. this.set('confirmPassphrase', '');
  36. this.set('localRepoPath', '');
  37. },
  38. navigateStep: function () {
  39. if (App.router.get('isFwdNavigation') === true) {
  40. this.loadStep();
  41. }
  42. },
  43. loadStep: function () {
  44. console.log("TRACE: Loading step2: Install Options");
  45. var hostNames = App.db.getAllHostNames();
  46. var softRepo = App.db.getSoftRepo();
  47. var installType = App.db.getInstallType();
  48. if (hostNames !== undefined) {
  49. this.set('hostNames', hostNames);
  50. } else {
  51. this.set('hostNames', '');
  52. }
  53. if (installType !== undefined && installType.installType === 'manual') {
  54. this.set('manualInstall', true);
  55. } else {
  56. this.set('manualInstall', false);
  57. }
  58. if (softRepo !== undefined && softRepo.repoType === 'local') {
  59. this.set('localRepo', true);
  60. this.set('localRepoPath', softRepo.repoPath);
  61. } else {
  62. this.set('localRepo', false);
  63. this.set('localRepoPath', '');
  64. }
  65. },
  66. installType: function () {
  67. if (this.get('manualInstall') === true) {
  68. return 'manualDriven';
  69. } else {
  70. return 'ambariDriven';
  71. }
  72. }.property('manualInstall'),
  73. isHostNameValid: function (hostname) {
  74. // For now hostnames that start or end with '-' are not allowed
  75. return !(/^\-/.test(hostname) || /\-$/.test(hostname));
  76. },
  77. isAllHostNamesValid: function () {
  78. this.hostNameArr = this.get('hostNames').trim().split(new RegExp("\\s+", "g"));
  79. for (var index in this.hostNameArr) {
  80. if (!this.isHostNameValid(this.hostNameArr[index])) {
  81. return false;
  82. }
  83. }
  84. return true;
  85. },
  86. hostsError: function () {
  87. if (this.get('hasSubmitted') && this.get('hostNames').trim() === '') {
  88. return Em.I18n.t('installer.step2.hostName.error.required');
  89. } else if (this.isAllHostNamesValid() === false) {
  90. return Em.I18n.t('installer.step2.hostName.error.invalid');
  91. }
  92. return null;
  93. }.property('hostNames', 'manualInstall', 'hasSubmitted'),
  94. sshKeyError: function () {
  95. if (this.get('hasSubmitted') && this.get('manualInstall') === false && this.get('sshKey').trim() === '') {
  96. return Em.I18n.t('installer.step2.sshKey.error.required');
  97. }
  98. return null;
  99. }.property('sshKey', 'manualInstall', 'hasSubmitted'),
  100. localRepoError: function () {
  101. if (this.get('hasSubmitted') && this.get('localRepo') && this.get('localRepoPath').trim() === '') {
  102. return Em.I18n.t('installer.step2.localRepo.error.required');
  103. }
  104. return null;
  105. }.property('localRepo', 'localRepoPath', 'hasSubmitted'),
  106. evaluateStep2: function () {
  107. console.log('TRACE: Entering controller:InstallerStep2:evaluateStep2 function');
  108. this.set('hasSubmitted', true);
  109. if (this.get('hostsError') || this.get('sshKeyError') || this.get('localRepoError')) {
  110. return false;
  111. }
  112. if (this.get('isSubmitDisabled') === true) {
  113. return false;
  114. }
  115. var hostInfo = {};
  116. this.hostNameArr.forEach(function (hostName) {
  117. hostInfo[hostName] = {
  118. name: hostName,
  119. installType: this.get('installType'),
  120. bootStatus: 'pending'
  121. };
  122. }, this);
  123. App.db.setAllHostNames(this.get('hostNames'));
  124. App.db.setHosts(hostInfo);
  125. if (this.get('manualInstall') === false) {
  126. App.db.setInstallType({installType: 'ambari' });
  127. } else {
  128. App.db.setInstallType({installType: 'manual' });
  129. }
  130. if (this.get('localRepo') === false) {
  131. App.db.setSoftRepo({ 'repoType': 'remote', 'repoPath': null});
  132. } else {
  133. App.db.setSoftRepo({ 'repoType': 'local', 'repoPath': this.get('localRepoPath') });
  134. }
  135. if (this.get('manualInstall') === true) {
  136. this.manualInstallPopup();
  137. return false;
  138. }
  139. // For now using mock jquery call
  140. //TODO: hook up with bootstrap call
  141. var bootStrapData = {'sshKey': this.get('sshKey'), hosts: this.get('hostNameArr')}.stringify;
  142. $.ajax({
  143. type: 'POST',
  144. url: '/api/bootstrap',
  145. data: bootStrapData,
  146. timeout: 2000,
  147. success: function () {
  148. console.log("TRACE: In success function for the post bootstrap function");
  149. App.router.transitionTo('step3');
  150. },
  151. error: function () {
  152. console.log("ERROR: bootstrap post call failed");
  153. return false;
  154. },
  155. complete: function() {
  156. // TODO: remove this function. this is just to force navigating to the next step before bootstrap integration
  157. App.router.send('next');
  158. },
  159. statusCode: {
  160. 404: function () {
  161. console.log("URI not found.");
  162. //After the bootstrap call hook up change the below return statement to "return false"
  163. console.log("TRACE: In faliure function for the post bootstrap function");
  164. return false;
  165. }
  166. },
  167. dataType: 'application/json'
  168. });
  169. },
  170. manualInstallPopup: function (event) {
  171. App.ModalPopup.show({
  172. header: Em.I18n.t('installer.step2.manualInstall.popup.header'),
  173. onPrimary: function () {
  174. this.hide();
  175. App.router.send('next');
  176. // App.router.transitionTo('step3');
  177. },
  178. bodyClass: Ember.View.extend({
  179. templateName: require('templates/installer/step2ManualInstallPopup')
  180. })
  181. });
  182. },
  183. isSubmitDisabled: function() {
  184. return (this.get('hostNameError') || this.get('sshKeyError') || this.get('localRepoError'));
  185. }.property('hostNameError', 'sshKeyError', 'localRepoError')
  186. });