step2_controller.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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.WizardStep2Controller = Em.Controller.extend({
  20. name: 'wizardStep2Controller',
  21. hostNameArr: [],
  22. hasSubmitted: false,
  23. hostNames: function () {
  24. return this.get('content.hostNames');
  25. }.property('content.hostNames'),
  26. manualInstall: function () {
  27. return this.get('content.manualInstall');
  28. }.property('content.manualInstall'),
  29. localRepo: function () {
  30. return this.get('content.localRepo');
  31. }.property('content.localRepo'),
  32. localRepoPath: function () {
  33. return this.get('content.localRepoPath');
  34. }.property('content.localRepoPath'),
  35. sshKey: function () {
  36. return this.get('content.sshKey');
  37. }.property('content.sshKey'),
  38. passphrase: function () {
  39. return this.get('content.passphrase');
  40. }.property('content.passphrase'),
  41. confirmPassphrase: function () {
  42. return this.get('content.confirmPassphrase');
  43. }.property('content.confirmPassphrase'),
  44. installType: function () {
  45. if (this.get('manualInstall') === true) {
  46. return 'manualDriven';
  47. } else {
  48. return 'ambariDriven';
  49. }
  50. }.property('manualInstall'),
  51. isHostNameValid: function (hostname) {
  52. // For now hostnames that start or end with '-' are not allowed
  53. return !(/^\-/.test(hostname) || /\-$/.test(hostname));
  54. },
  55. isAllHostNamesValid: function () {
  56. this.hostNameArr = this.get('hostNames').trim().split(new RegExp("\\s+", "g"));
  57. for (var index in this.hostNameArr) {
  58. if (!this.isHostNameValid(this.hostNameArr[index])) {
  59. return false;
  60. }
  61. }
  62. return true;
  63. },
  64. hostsError: function () {
  65. if (this.get('hasSubmitted') && this.get('hostNames').trim() === '') {
  66. return Em.I18n.t('installer.step2.hostName.error.required');
  67. } else if (this.isAllHostNamesValid() === false) {
  68. return Em.I18n.t('installer.step2.hostName.error.invalid');
  69. }
  70. return null;
  71. }.property('hostNames', 'manualInstall', 'hasSubmitted'),
  72. sshKeyError: function () {
  73. if (this.get('hasSubmitted') && this.get('manualInstall') === false && this.get('sshKey').trim() === '') {
  74. return Em.I18n.t('installer.step2.sshKey.error.required');
  75. }
  76. return null;
  77. }.property('sshKey', 'manualInstall', 'hasSubmitted'),
  78. localRepoError: function () {
  79. if (this.get('hasSubmitted') && this.get('localRepo') && this.get('localRepoPath').trim() === '') {
  80. return Em.I18n.t('installer.step2.localRepo.error.required');
  81. }
  82. return null;
  83. }.property('localRepo', 'localRepoPath', 'hasSubmitted'),
  84. /**
  85. * Get host info, which will be saved in parent controller
  86. */
  87. getHostInfo: function () {
  88. var hostNameArr = this.get('hostNameArr');
  89. var hostInfo = {};
  90. for (var i = 0; i < hostNameArr.length; i++) {
  91. hostInfo[hostNameArr[i]] = {
  92. name: hostNameArr[i],
  93. installType: this.get('installType'),
  94. bootStatus: 'pending'
  95. };
  96. }
  97. return hostInfo;
  98. },
  99. /**
  100. * Onclick handler for <code>next button</code>. Do all UI work except data saving.
  101. * This work is doing by router.
  102. * @return {Boolean}
  103. */
  104. evaluateStep: function () {
  105. console.log('TRACE: Entering controller:WizardStep2:evaluateStep function');
  106. if (this.get('isSubmitDisabled')) {
  107. return false;
  108. }
  109. if (this.get('manualInstall') === true) {
  110. this.manualInstallPopup();
  111. return false;
  112. }
  113. // For now using mock jquery call
  114. //TODO: hook up with bootstrap call
  115. var bootStrapData = {'sshKey': this.get('sshKey'), hosts: this.get('hostNameArr')}.stringify;
  116. $.ajax({
  117. type: 'POST',
  118. url: '/api/bootstrap',
  119. data: bootStrapData,
  120. async: false,
  121. timeout: 2000,
  122. success: function () {
  123. console.log("TRACE: In success function for the post bootstrap function");
  124. App.router.send('next');
  125. },
  126. error: function () {
  127. console.log("ERROR: bootstrap post call failed");
  128. return false;
  129. },
  130. complete: function () {
  131. // TODO: remove this function. this is just to force navigating to the next step before bootstrap integration
  132. App.router.send('next');
  133. },
  134. statusCode: {
  135. 404: function () {
  136. console.log("URI not found.");
  137. //After the bootstrap call hook up change the below return statement to "return false"
  138. console.log("TRACE: In faliure function for the post bootstrap function");
  139. return false;
  140. }
  141. },
  142. dataType: 'application/json'
  143. });
  144. },
  145. manualInstallPopup: function (event) {
  146. App.ModalPopup.show({
  147. header: Em.I18n.t('installer.step2.manualInstall.popup.header'),
  148. onPrimary: function () {
  149. this.hide();
  150. App.router.send('next');
  151. },
  152. bodyClass: Ember.View.extend({
  153. templateName: require('templates/wizard/step2ManualInstallPopup')
  154. })
  155. });
  156. },
  157. isSubmitDisabled: function () {
  158. return (this.get('hostsError') || this.get('sshKeyError') || this.get('localRepoError'));
  159. }.property('hostsError', 'sshKeyError', 'localRepoError')
  160. });