step3_controller.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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.WizardStep3Controller = Em.ArrayController.extend({
  20. name: 'wizardStep3Controller',
  21. content: [],
  22. bootHosts: [],
  23. isSubmitDisabled: false,
  24. categories: ['Hosts', 'Succeeded', 'Failed'],
  25. category: 'Hosts',
  26. allChecked: true,
  27. onAllChecked: function () {
  28. var hosts = this.visibleHosts();
  29. if (this.get('allChecked') === true) {
  30. hosts.setEach('isChecked', true);
  31. } else {
  32. hosts.setEach('isChecked', false);
  33. }
  34. }.observes('allChecked'),
  35. mockData: require('data/mock/step3_hosts'),
  36. mockRetryData: require('data/mock/step3_pollData'),
  37. /**
  38. * Provide some initialisation work. Start bootstrap if needed
  39. */
  40. navigateStep: function () {
  41. if (App.db.getBootStatus() === false) {
  42. this.startBootstrap();
  43. }
  44. },
  45. /**
  46. * Onclick handler for <code>Retry</code> button.
  47. */
  48. retry: function () {
  49. if (this.get('isSubmitDisabled')) {
  50. return;
  51. }
  52. var hosts = this.visibleHosts();
  53. var selectedHosts = hosts.filterProperty('isChecked', true);
  54. selectedHosts.forEach(function (_host) {
  55. console.log('Retrying: ' + _host.name);
  56. });
  57. //TODO: uncomment below code to hookup with @GET bootstrap API
  58. /*
  59. this.set('bootHosts',selectedHosts);
  60. this.doBootstrap();
  61. */
  62. },
  63. /**
  64. * Below function returns the current set of visible hosts on view (All, succeded, failed)
  65. */
  66. visibleHosts: function () {
  67. if (this.get('category') === 'Succeeded') {
  68. return (this.filterProperty('bootStatus', 'success'));
  69. } else if (this.get('category') === 'Failed') {
  70. return (this.filterProperty('bootStatus', 'error'));
  71. } else if (this.get('category') === 'Hosts') {
  72. return this.content;
  73. }
  74. },
  75. /**
  76. * Onclick handler for <code>Remove</code> button
  77. */
  78. removeBtn: function () {
  79. if (this.get('isSubmitDisabled')) {
  80. return;
  81. }
  82. var hostResult = this.visibleHosts();
  83. var selectedHosts = hostResult.filterProperty('isChecked', true);
  84. selectedHosts.forEach(function (_hostInfo) {
  85. console.log('Removing: ' + _hostInfo.name);
  86. });
  87. this.removeHosts(selectedHosts);
  88. },
  89. /**
  90. * Do remove hosts logic: remove host info from UI and save it to model
  91. * @param hosts
  92. */
  93. removeHosts: function (hosts) {
  94. this.removeObjects(hosts);
  95. App.router.send('removeHosts', hosts);
  96. },
  97. startBootstrap: function () {
  98. this.set('isSubmitDisabled', true);
  99. this.set('bootHosts', this.get('content'));
  100. this.doBootstrap();
  101. },
  102. /**
  103. * Below function parses and updates the content, and governs
  104. * the possibility of the next doBootstrap (polling) call
  105. *
  106. * @param hostsFrmServer
  107. * @param hostsFrmContent
  108. * @return {Boolean}
  109. */
  110. parseHostInfo: function (hostsFrmServer, hostsFrmContent) {
  111. var result = true; // default value as true implies if the data rendered by REST API has no hosts, polling will stop
  112. hostsFrmServer.forEach(function (_hostFrmServer) {
  113. var host = hostsFrmContent.findProperty('name', _hostFrmServer.name);
  114. if (host !== null && host !== undefined) { // check if hostname extracted from REST API data matches any hostname in content
  115. host.set('bootStatus', _hostFrmServer.status);
  116. host.set('cpu', _hostFrmServer.cpu);
  117. host.set('memory', _hostFrmServer.memory);
  118. }
  119. });
  120. result = !this.content.someProperty('bootStatus', 'pending');
  121. return result;
  122. },
  123. doBootstrap: function () {
  124. var self = this;
  125. $.ajax({
  126. type: 'GET',
  127. url: '/ambari_server/api/bootstrap',
  128. async: false,
  129. timeout: 5000,
  130. success: function (data) {
  131. console.log("TRACE: In success function for the GET bootstrap call");
  132. var result = self.parseHostInfo(data, this.get('bootHosts'));
  133. if (result !== true && App.router.getInstallerCurrentStep() === '3') {
  134. window.setTimeout(self.doBootstrap, 3000);
  135. } else {
  136. self.stopBootstrap();
  137. }
  138. },
  139. error: function () {
  140. console.log("ERROR");
  141. self.stopBootstrap();
  142. },
  143. statusCode: {
  144. 404: function () {
  145. console.log("URI not found.");
  146. }
  147. },
  148. dataType: 'application/json'
  149. });
  150. },
  151. stopBootstrap: function () {
  152. //TODO: uncomment following line after the hook up with the API call
  153. // this.set('isSubmitDisabled',false);
  154. },
  155. hostLogPopup: function (event) {
  156. App.ModalPopup.show({
  157. header: Em.I18n.t('installer.step3.hostLog.popup.header'),
  158. onPrimary: function () {
  159. this.hide();
  160. },
  161. bodyClass: Ember.View.extend({
  162. templateName: require('templates/installer/step3HostLogPopup')
  163. })
  164. });
  165. },
  166. // TODO: dummy button. Remove this after the hook up with actual REST API.
  167. mockBtn: function () {
  168. this.set('isSubmitDisabled', false);
  169. this.clear();
  170. var hostInfo = this.mockData;
  171. this.renderHosts(hostInfo);
  172. },
  173. renderHosts: function (hostsInfo) {
  174. var self = this;
  175. hostsInfo.forEach(function (_hostInfo) {
  176. var hostInfo = App.HostInfo.create({
  177. name: _hostInfo.name,
  178. bootStatus: _hostInfo.bootStatus
  179. });
  180. console.log('pushing ' + hostInfo.name);
  181. self.content.pushObject(hostInfo);
  182. });
  183. },
  184. pollBtn: function () {
  185. if (this.get('isSubmitDisabled')) {
  186. return;
  187. }
  188. var hosts = this.visibleHosts();
  189. var selectedHosts = hosts.filterProperty('isChecked', true);
  190. var mockHosts = this.mockRetryData;
  191. if (this.parseHostInfo(mockHosts, selectedHosts)) {
  192. // this.saveHostInfoToDb();
  193. }
  194. }
  195. });