step2_controller.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 (
  80. // (typeof this.get('localRepoPath') === 'undefined') ||
  81. !(/^([-a-z0-9._\/]|%[0-9a-f]{2})*$/i.test(this.get('localRepoPath')) ) ||
  82. (this.get('hasSubmitted') && this.get('localRepo') && this.get('localRepoPath').trim() === '' )
  83. )
  84. {
  85. return Em.I18n.t('installer.step2.localRepo.error.required');
  86. }
  87. return null;
  88. }.property('localRepo', 'localRepoPath', 'hasSubmitted'),
  89. /**
  90. * Get host info, which will be saved in parent controller
  91. */
  92. getHostInfo: function () {
  93. var hostNameArr = this.get('hostNameArr');
  94. var hostInfo = {};
  95. for (var i = 0; i < hostNameArr.length; i++) {
  96. hostInfo[hostNameArr[i]] = {
  97. name: hostNameArr[i],
  98. installType: this.get('installType'),
  99. bootStatus: 'pending'
  100. };
  101. }
  102. return hostInfo;
  103. },
  104. /**
  105. * Onclick handler for <code>next button</code>. Do all UI work except data saving.
  106. * This work is doing by router.
  107. * @return {Boolean}
  108. */
  109. evaluateStep: function () {
  110. console.log('TRACE: Entering controller:WizardStep2:evaluateStep function');
  111. if (this.get('isSubmitDisabled')) {
  112. return false;
  113. }
  114. if (this.get('manualInstall') === true) {
  115. this.manualInstallPopup();
  116. return false;
  117. }
  118. // For now using mock jquery call
  119. //TODO: hook up with bootstrap call
  120. var bootStrapData = {'sshKey': this.get('sshKey'), hosts: this.get('hostNameArr')}.stringify;
  121. $.ajax({
  122. type: 'POST',
  123. url: '/api/bootstrap',
  124. data: bootStrapData,
  125. async: false,
  126. timeout: 2000,
  127. success: function () {
  128. console.log("TRACE: In success function for the post bootstrap function");
  129. App.router.send('next');
  130. },
  131. error: function () {
  132. console.log("ERROR: bootstrap post call failed");
  133. return false;
  134. },
  135. complete: function () {
  136. // TODO: remove this function. this is just to force navigating to the next step before bootstrap integration
  137. App.router.send('next');
  138. },
  139. statusCode: {
  140. 404: function () {
  141. console.log("URI not found.");
  142. //After the bootstrap call hook up change the below return statement to "return false"
  143. console.log("TRACE: In faliure function for the post bootstrap function");
  144. return false;
  145. }
  146. },
  147. dataType: 'application/json'
  148. });
  149. },
  150. manualInstallPopup: function (event) {
  151. App.ModalPopup.show({
  152. header: Em.I18n.t('installer.step2.manualInstall.popup.header'),
  153. onPrimary: function () {
  154. this.hide();
  155. App.router.send('next');
  156. },
  157. bodyClass: Ember.View.extend({
  158. templateName: require('templates/wizard/step2ManualInstallPopup')
  159. })
  160. });
  161. },
  162. isSubmitDisabled: function () {
  163. return (this.get('hostsError') || this.get('sshKeyError') || this.get('localRepoError'));
  164. }.property('hostsError', 'sshKeyError', 'localRepoError')
  165. });