details.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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.MainHostDetailsController = Em.Controller.extend({
  20. name: 'mainHostDetailsController',
  21. content: null,
  22. isFromHosts: false,
  23. backgroundOperations: [],
  24. isStarting: true,
  25. isStopping: function(){
  26. return !this.get('isStarting');
  27. }.property('isStarting'),
  28. setBack: function(isFromHosts){
  29. this.set('isFromHosts', isFromHosts);
  30. },
  31. hostOperations: function(){
  32. var hostName = this.get('content.hostName');
  33. return this.get('backgroundOperations').filterProperty('hostName', hostName);
  34. }.property('backgroundOperations.length', 'content'),
  35. hostOperationsCount: function() {
  36. return this.get('hostOperations.length');
  37. }.property('backgroundOperations.length', 'content'),
  38. showBackgroundOperationsPopup: function(){
  39. App.ModalPopup.show({
  40. headerClass: Ember.View.extend({
  41. controllerBinding: 'App.router.mainHostDetailsController',
  42. template:Ember.Handlebars.compile('{{hostOperationsCount}} Background Operations Running')
  43. }),
  44. bodyClass: Ember.View.extend({
  45. controllerBinding: 'App.router.mainHostDetailsController',
  46. templateName: require('templates/main/host/background_operations_popup')
  47. }),
  48. onPrimary: function() {
  49. this.hide();
  50. }
  51. });
  52. },
  53. startComponent: function(event){
  54. var self = this;
  55. App.ModalPopup.show({
  56. header: Em.I18n.t('hosts.host.start.popup.header'),
  57. body: Em.I18n.t('hosts.host.start.popup.body'),
  58. primary: 'Yes',
  59. secondary: 'No',
  60. onPrimary: function() {
  61. var component = event.context;
  62. component.set('workStatus', true);
  63. var backgroundOperations = self.get('backgroundOperations');
  64. backgroundOperations.pushObject({
  65. "hostName": self.get('content.hostName'),
  66. "role":component.get('componentName'),
  67. "command": "START",
  68. "details": [
  69. {"startTime":"4 min ago", "name":"Some intermediate operation"},
  70. {"startTime":"5 min ago", "name":"Component started"}
  71. ],
  72. "logs":{"exitcode":"404", "stdout":27, "stderror":501}
  73. });
  74. var stopped = self.get('content.components').filterProperty('workStatus', false);
  75. if (stopped.length == 0)
  76. self.set('isStarting', true);
  77. this.hide();
  78. },
  79. onSecondary: function() {
  80. this.hide();
  81. }
  82. });
  83. },
  84. stopComponent: function(event){
  85. var self = this;
  86. App.ModalPopup.show({
  87. header: Em.I18n.t('hosts.host.start.popup.header'),
  88. body: Em.I18n.t('hosts.host.start.popup.body'),
  89. primary: 'Yes',
  90. secondary: 'No',
  91. onPrimary: function() {
  92. var component = event.context;
  93. component.set('workStatus', false);
  94. var backgroundOperations = self.get('backgroundOperations');
  95. backgroundOperations.pushObject({
  96. "hostName": self.get('content.hostName'),
  97. "role": component.get('componentName'),
  98. "command": "STOP",
  99. "details": [
  100. {"startTime":"4 min ago", "name":"Some intermediate operation"},
  101. {"startTime":"5 min ago", "name":"Component stopped"}
  102. ],
  103. "logs":{"exitcode":"404", "stdout":15, "stderror":501}
  104. });
  105. var started = self.get('content.components').filterProperty('workStatus', true);
  106. if (started.length == 0)
  107. self.set('isStarting', false);
  108. this.hide();
  109. },
  110. onSecondary: function() {
  111. this.hide();
  112. }
  113. });
  114. },
  115. decommission: function(event){
  116. App.ModalPopup.show({
  117. header: Em.I18n.t('hosts.host.start.popup.header'),
  118. body: Em.I18n.t('hosts.host.start.popup.body'),
  119. primary: 'Yes',
  120. secondary: 'No',
  121. onPrimary: function() {
  122. this.hide();
  123. },
  124. onSecondary: function() {
  125. this.hide();
  126. }
  127. });
  128. },
  129. recommission: function(event){
  130. App.ModalPopup.show({
  131. header: Em.I18n.t('hosts.host.start.popup.header'),
  132. body: Em.I18n.t('hosts.host.start.popup.body'),
  133. primary: 'Yes',
  134. secondary: 'No',
  135. onPrimary: function() {
  136. this.hide();
  137. },
  138. onSecondary: function() {
  139. this.hide();
  140. }
  141. });
  142. },
  143. startConfirmPopup: function (event) {
  144. var self = this;
  145. App.ModalPopup.show({
  146. header: Em.I18n.t('hosts.host.start.popup.header'),
  147. body: Em.I18n.t('hosts.host.start.popup.body'),
  148. primary: 'Yes',
  149. secondary: 'No',
  150. onPrimary: function() {
  151. self.get('content.components').setEach('workStatus', true);
  152. self.set('isStarting', !self.get('isStarting'));
  153. this.hide();
  154. },
  155. onSecondary: function() {
  156. this.hide();
  157. }
  158. });
  159. },
  160. stopConfirmPopup: function (event) {
  161. var self = this;
  162. App.ModalPopup.show({
  163. header: Em.I18n.t('hosts.host.stop.popup.header'),
  164. body: Em.I18n.t('hosts.host.stop.popup.body'),
  165. primary: 'Yes',
  166. secondary: 'No',
  167. onPrimary: function() {
  168. self.get('content.components').setEach('workStatus', false);
  169. self.set('isStarting', !self.get('isStarting'));
  170. this.hide();
  171. },
  172. onSecondary: function() {
  173. this.hide();
  174. }
  175. });
  176. },
  177. validateDeletion: function() {
  178. var slaveComponents = ['DataNode', 'TaskTracker', 'RegionServer'];
  179. var masterComponents = [];
  180. var workingComponents = [];
  181. var components = this.get('content.components');
  182. components.forEach(function(cInstance){
  183. var cName = cInstance.get('componentName');
  184. if(slaveComponents.contains(cName)) {
  185. if(cInstance.get('workStatus')){
  186. workingComponents.push(cName);
  187. }
  188. } else {
  189. masterComponents.push(cName);
  190. }
  191. });
  192. //debugger;
  193. if(workingComponents.length || masterComponents.length) {
  194. this.raiseWarning(workingComponents, masterComponents);
  195. } else {
  196. this.deleteButtonPopup();
  197. }
  198. },
  199. raiseWarning: function (workingComponents, masterComponents) {
  200. var self = this;
  201. var masterString = '';
  202. var workingString = '';
  203. if(masterComponents && masterComponents.length) {
  204. var masterList = masterComponents.join(', ');
  205. var ml_text = Em.I18n.t('hosts.cant.do.popup.masterList.body');
  206. masterString = ml_text.format(masterList);
  207. }
  208. if(workingComponents && workingComponents.length) {
  209. var workingList = workingComponents.join(', ');
  210. var wl_text = Em.I18n.t('hosts.cant.do.popup.workingList.body');
  211. workingString = wl_text.format(workingList);
  212. }
  213. App.ModalPopup.show({
  214. header: Em.I18n.t('hosts.cant.do.popup.header'),
  215. html: true,
  216. body: masterString + workingString,
  217. primary: "OK",
  218. secondary: null,
  219. onPrimary: function() {
  220. this.hide();
  221. }
  222. })
  223. },
  224. deleteButtonPopup: function() {
  225. var self = this;
  226. App.ModalPopup.show({
  227. header: Em.I18n.t('hosts.delete.popup.header'),
  228. body: Em.I18n.t('hosts.delete.popup.body'),
  229. primary: 'Yes',
  230. secondary: 'No',
  231. onPrimary: function() {
  232. self.removeHost();
  233. this.hide();
  234. },
  235. onSecondary: function() {
  236. this.hide();
  237. }
  238. });
  239. },
  240. removeHost: function () {
  241. App.router.get('mainHostController').checkRemoved(this.get('content.id'));
  242. App.router.transitionTo('hosts');
  243. }
  244. })