installer.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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.InstallerController = Em.Controller.extend({
  20. name: 'installerController',
  21. clusterName: '',
  22. validClusterName: true,
  23. hostNames: '',
  24. hostNameArr: [],
  25. errorMsg_clusterName: '',
  26. hostNameEmptyError: false,
  27. hostNameErr: false,
  28. manualInstall: false,
  29. hostNameNotRequireErr: false,
  30. InstallType: 'ambariDriven',
  31. sshKey: '',
  32. passphrase: '',
  33. confirmPassphrase: '',
  34. sshKeyNullErr: false,
  35. passphraseNullErr: false,
  36. passphraseMatchErr: false,
  37. localRepo: false,
  38. softRepo: 'remote',
  39. localRepoPath: '',
  40. softRepoLocalPathNullErr: false,
  41. hideRepoErrMsg: function () {
  42. if (this.get('localRepo') === false) {
  43. this.set('softRepoLocalPathNullErr', false);
  44. }
  45. }.observes('localRepo'),
  46. hostManageErr: function () {
  47. if (this.get('hostNameEmptyError') || this.get('hostNameNotRequireErr') || this.get('hostNameErr') || this.get('sshKeyNullErr') || this.get('passphraseMatchErr')) {
  48. return true;
  49. } else {
  50. return false
  51. }
  52. }.property('hostNameEmptyError', 'hostNameNotRequireErr', 'hostNameErr', 'sshKeyNullErr', 'passphraseMatchErr'),
  53. advOptErr: function () {
  54. if (this.get('softRepoLocalPathNullErr')) {
  55. return true;
  56. } else {
  57. return false
  58. }
  59. }.property('softRepoLocalPathNullErr'),
  60. evaluateStep1: function () {
  61. //TODO: Done
  62. //task1 = checks on valid cluster name
  63. //task2 (prereq(task1 says it's a valid cluster name)) = storing cluster name in localstorage
  64. var result;
  65. console.log('TRACE: Entering controller:Installer:evaluateStep1 function');
  66. if (this.get('clusterName') == '') {
  67. this.set('errorMsg_clusterName', App.messages.step1_clusterName_error_null);
  68. this.set('validClusterName', false);
  69. result = false;
  70. } else if (/\s/.test(this.get('clusterName'))) {
  71. console.log('White spaces not allowed for cluster name');
  72. this.set('errorMsg_clusterName', App.messages.step1_clusterName_error_Whitespaces);
  73. this.set('validClusterName', false);
  74. result = false;
  75. } else if (/[^\w\s]/gi.test(this.get('clusterName'))) {
  76. console.log('Special characters are not allowed for the cluster name');
  77. this.set('errorMsg_clusterName', App.messages.step1_clusterName_error_specialChar);
  78. this.set('validClusterName', false);
  79. result = false;
  80. } else {
  81. console.log('value of clusterNmae is: ' + this.get('clusterName'));
  82. this.set('validClusterName', true);
  83. result = true;
  84. }
  85. if (result === true) {
  86. App.db.setClusterName(this.get('clusterName'));
  87. }
  88. console.log('Exiting the evaluatestep1 function');
  89. return result;
  90. },
  91. evaluateStep2: function () {
  92. // TODO: evaluation/manipulation at the end of step2
  93. //task1 = do primary validations on whole step before executing any further steps
  94. //task2 = parsing hostnames string to hostnames json array
  95. //task3 = check validation for every hostname and store it in localstorage
  96. //task4 = Storing ambari agent Install type in localStorage (InstallType maps at host level and so every host will have this as an property)
  97. //task5 = Storing path of software repository(remote/local repo) to localStorage
  98. //task6 = call to rest API: @Post http://ambari_server/api/bootstrap
  99. //task7 = On faliure of the previous call, show 'error injecting host information in server db'
  100. //task8 = On success of the previous call, go to step 3(awesome....)
  101. console.log('TRACE: Entering controller:Installer:evaluateStep2 function');
  102. /** task1 **/
  103. console.log('value of manual install is: ' + this.get('manualInstall'));
  104. if (this.get('hostNames') === '' && this.get('manualInstall') === false) {
  105. this.set('hostNameEmptyError', true);
  106. this.set('hostNameNotRequireErr', false);
  107. return false;
  108. } else if (this.get('hostNames') !== '' && this.get('manualInstall') === true) {
  109. this.set('hostNameNotRequireErr', true);
  110. this.set('hostNameEmptyError', false);
  111. return false;
  112. } else {
  113. this.set('hostNameEmptyError', false);
  114. this.set('hostNameNotRequireErr', false);
  115. }
  116. if (this.get('manualInstall') === false) {
  117. if (this.get('sshKey') === '') {
  118. this.set('sshKeyNullErr', true);
  119. return false;
  120. }
  121. else {
  122. this.set('sshKeyNullErr', false);
  123. }
  124. if (this.get('passphrase') !== this.get('confirmPassphrase')) {
  125. this.set('passphraseMatchErr', true);
  126. return false;
  127. } else {
  128. this.set('passphraseMatchErr', false);
  129. }
  130. }
  131. if (this.get('localRepo') === true) {
  132. if (this.get('localRepoPath') === '') {
  133. this.set('softRepoLocalPathNullErr', true);
  134. return false;
  135. } else {
  136. this.set('softRepoLocalPathNullErr', false);
  137. }
  138. } else {
  139. this.set('softRepoLocalPathNullErr', false);
  140. }
  141. /** task2 task3 task4 **/
  142. this.hostNameArr = this.get('hostNames').split('\s');
  143. for (var i = 0; i < this.hostNameArr.length; i++) {
  144. //TODO: other validation for hostnames will be covered over here
  145. // For now hostname that are starting or ending with '-' are not allowed
  146. if (/^\-/.test(this.hostNameArr[i]) || /\-$/.test(this.hostNameArr[i])) {
  147. console.log('Invalide host name' + this.hostNameArr[i]);
  148. alert('Invalide host name: ' + this.hostNameArr[i]);
  149. this.set('hostNameErr', true);
  150. return false;
  151. } else {
  152. this.set('hostNameErr', false);
  153. }
  154. }
  155. var hostInfo = {};
  156. for (var i = 0; i < this.hostNameArr.length; i++) {
  157. hostInfo[this.hostNameArr[i]] = {'name': this.hostNameArr[i]};
  158. // hostInfo[this.hostNameArr[i]].name = this.hostNameArr[i];
  159. hostInfo[this.hostNameArr[i]].installType = this.get('InstallType');
  160. }
  161. App.db.setHosts(hostInfo);
  162. /** task4 **/
  163. var softRepoInfo = {'type': this.get('softRepo'), 'path': ''};
  164. if ('success' == 'success') {
  165. return true;
  166. } else {
  167. return false;
  168. }
  169. },
  170. evaluateStep3: function () {
  171. // TODO: evaluation at the end of step3
  172. /* Not sure if below tasks are to be covered over here
  173. * as these functions are meant to be called at the end of a step
  174. * and the following tasks are interactive to the page and not on clicking next button.
  175. *
  176. * task1 will be a function called on entering step3 from step3 connectoutlet or init function in InstallerStep3 View.
  177. * task2 will be a parsing function that on reaching a particular condition(all hosts are in success or faliue status) will stop task1
  178. * task3 will be a function binded to remove button
  179. * task4 will be a function binded to retry button
  180. *
  181. *
  182. * keeping it over here for now
  183. */
  184. //task1 = start polling with rest API @Get http://ambari_server/api/bootstrap.
  185. //task2 = stop polling when all the hosts have either success or failure status.
  186. //task3(prerequisite = remove) = Remove set of selected hosts from the localStorage
  187. //task4(prerequisite = retry) = temporarily store list of checked host and call to rest API: @Post http://ambari_server/api/bootstrap
  188. },
  189. evaluateStep4: function () {
  190. // TODO: evaluation at the end of step4
  191. },
  192. evaluateStep5: function () {
  193. // TODO: evaluation at the end of step5
  194. },
  195. evaluateStep6: function () {
  196. // TODO: evaluation at the end of step6
  197. },
  198. evaluateStep7: function () {
  199. // TODO: evaluation at the end of step7
  200. },
  201. evaluateStep8: function () {
  202. // TODO: evaluation at the end of step8
  203. },
  204. prevInstallStatus: function () {
  205. console.log('Inside the prevInstallStep function: The name is ' + App.router.get('loginController.loginName'));
  206. var result = App.db.isCompleted()
  207. if (result == '1') {
  208. return true;
  209. }
  210. }.property('App.router.loginController.loginName'),
  211. currentStep: function () {
  212. return App.get('router').getInstallerCurrentStep();
  213. }.property(),
  214. clusters: null,
  215. init: function () {
  216. this.clusters = App.Cluster.find();
  217. },
  218. isStep1: function () {
  219. return this.get('currentStep') == '1';
  220. }.property('currentStep'),
  221. isStep2: function () {
  222. return this.get('currentStep') == '2';
  223. }.property('currentStep'),
  224. isStep3: function () {
  225. return this.get('currentStep') == '3';
  226. }.property('currentStep'),
  227. isStep4: function () {
  228. return this.get('currentStep') == '4';
  229. }.property('currentStep'),
  230. isStep5: function () {
  231. return this.get('currentStep') == '5';
  232. }.property('currentStep'),
  233. isStep6: function () {
  234. return this.get('currentStep') == '6';
  235. }.property('currentStep'),
  236. isStep7: function () {
  237. return this.get('currentStep') == '7';
  238. }.property('currentStep'),
  239. isStep8: function () {
  240. return this.get('currentStep') == '8';
  241. }.property('currentStep'),
  242. /**
  243. *
  244. * @param cluster ClusterModel
  245. */
  246. createCluster: function (cluster) {
  247. alert('created cluster ' + cluster.name);
  248. }
  249. });