step2_controller.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. bootRequestId: null,
  23. hasSubmitted: false,
  24. hostNames: function () {
  25. return this.get('content.hostNames');
  26. }.property('content.hostNames'),
  27. manualInstall: function () {
  28. return this.get('content.manualInstall');
  29. }.property('content.manualInstall'),
  30. localRepo: function () {
  31. return this.get('content.localRepo');
  32. }.property('content.localRepo'),
  33. sshKey: function () {
  34. return this.get('content.sshKey');
  35. }.property('content.sshKey'),
  36. passphrase: function () {
  37. return this.get('content.passphrase');
  38. }.property('content.passphrase'),
  39. confirmPassphrase: function () {
  40. return this.get('content.confirmPassphrase');
  41. }.property('content.confirmPassphrase'),
  42. installType: function () {
  43. if (this.get('manualInstall') === true) {
  44. return 'manualDriven';
  45. } else {
  46. return 'ambariDriven';
  47. }
  48. }.property('manualInstall'),
  49. isHostNameValid: function (hostname) {
  50. // For now hostnames that start or end with '-' are not allowed
  51. return !(/^\-/.test(hostname) || /\-$/.test(hostname));
  52. },
  53. isAllHostNamesValid: function () {
  54. this.hostNameArr = this.get('hostNames').trim().split(new RegExp("\\s+", "g"));
  55. for (var index in this.hostNameArr) {
  56. if (!this.isHostNameValid(this.hostNameArr[index])) {
  57. return false;
  58. }
  59. }
  60. return true;
  61. },
  62. hostsError: function () {
  63. if (this.get('hasSubmitted') && this.get('hostNames').trim() === '') {
  64. return Em.I18n.t('installer.step2.hostName.error.required');
  65. } else if (this.isAllHostNamesValid() === false) {
  66. return Em.I18n.t('installer.step2.hostName.error.invalid');
  67. }
  68. return null;
  69. }.property('hostNames', 'manualInstall', 'hasSubmitted'),
  70. sshKeyError: function () {
  71. if (this.get('hasSubmitted') && this.get('manualInstall') === false && this.get('sshKey').trim() === '') {
  72. return Em.I18n.t('installer.step2.sshKey.error.required');
  73. }
  74. return null;
  75. }.property('sshKey', 'manualInstall', 'hasSubmitted'),
  76. /**
  77. * Get host info, which will be saved in parent controller
  78. */
  79. getHostInfo: function () {
  80. var hostNameArr = this.get('hostNameArr');
  81. var hostInfo = {};
  82. for (var i = 0; i < hostNameArr.length; i++) {
  83. hostInfo[hostNameArr[i]] = {
  84. name: hostNameArr[i],
  85. installType: this.get('installType'),
  86. bootStatus: 'pending'
  87. };
  88. }
  89. return hostInfo;
  90. },
  91. /**
  92. * Onclick handler for <code>next button</code>. Do all UI work except data saving.
  93. * This work is doing by router.
  94. * @return {Boolean}
  95. */
  96. evaluateStep: function () {
  97. console.log('TRACE: Entering controller:WizardStep2:evaluateStep function');
  98. if (this.get('isSubmitDisabled')) {
  99. return false;
  100. }
  101. if (this.get('manualInstall') === true) {
  102. this.manualInstallPopup();
  103. return false;
  104. }
  105. var bootStrapData = JSON.stringify({'verbose': true, 'sshKey': this.get('sshKey'), hosts: this.get('hostNameArr')});
  106. if (App.skipBootstrap) {
  107. App.router.send('next');
  108. return true;
  109. }
  110. var requestId = App.get('router.installerController').launchBootstrap(bootStrapData);
  111. if(requestId) {
  112. this.set('bootRequestId',requestId);
  113. App.router.send('next');
  114. }
  115. },
  116. manualInstallPopup: function (event) {
  117. App.ModalPopup.show({
  118. header: Em.I18n.t('installer.step2.manualInstall.popup.header'),
  119. onPrimary: function () {
  120. this.hide();
  121. App.router.send('next');
  122. },
  123. bodyClass: Ember.View.extend({
  124. templateName: require('templates/wizard/step2ManualInstallPopup')
  125. })
  126. });
  127. },
  128. isSubmitDisabled: function () {
  129. return (this.get('hostsError') || this.get('sshKeyError'));
  130. }.property('hostsError', 'sshKeyError')
  131. });