details.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. routeHome:function () {
  24. App.router.transitionTo('main.dashboard');
  25. },
  26. setBack: function(isFromHosts){
  27. this.set('isFromHosts', isFromHosts);
  28. },
  29. /**
  30. * Send specific command to server
  31. * @param url
  32. * @param data Object to send
  33. */
  34. sendCommandToServer : function(url, postData, callback){
  35. var url = (App.testMode) ?
  36. '/data/wizard/deploy/poll_1.json' : //content is the same as ours
  37. '/api/clusters/' + App.router.getClusterName() + url;
  38. var method = App.testMode ? 'GET' : 'PUT';
  39. $.ajax({
  40. type: method,
  41. url: url,
  42. data: JSON.stringify(postData),
  43. dataType: 'json',
  44. timeout: 5000,
  45. success: function(data){
  46. if(data && data.Requests){
  47. callback(data.Requests.id);
  48. } else{
  49. callback(null);
  50. console.log('cannot get request id from ', data);
  51. }
  52. },
  53. error: function (request, ajaxOptions, error) {
  54. //do something
  55. callback(null);
  56. console.log('error on change component host status')
  57. },
  58. statusCode: require('data/statusCodes')
  59. });
  60. },
  61. startComponent: function(event){
  62. var self = this;
  63. App.ModalPopup.show({
  64. header: Em.I18n.t('hosts.host.start.popup.header'),
  65. body: Em.I18n.t('hosts.host.start.popup.body'),
  66. primary: 'Yes',
  67. secondary: 'No',
  68. onPrimary: function() {
  69. var component = event.context;
  70. self.sendCommandToServer('/hosts/' + self.get('content.hostName') + '/host_components/' + component.get('componentName').toUpperCase(),{
  71. HostRoles:{
  72. state: 'STARTED'
  73. }
  74. }, function(requestId){
  75. if(!requestId){
  76. return;
  77. }
  78. console.log('Send request for STARTING successfully');
  79. component.set('workStatus', App.Component.Status.starting);
  80. if(App.testMode){
  81. setTimeout(function(){
  82. component.set('workStatus', App.Component.Status.started);
  83. },10000);
  84. } else{
  85. App.router.get('backgroundOperationsController.eventsArray').push({
  86. "when" : function(controller){
  87. var result = (controller.getOperationsForRequestId(requestId).length == 0);
  88. console.log('startComponent.when = ', result)
  89. return result;
  90. },
  91. "do" : function(){
  92. component.set('workStatus', App.Component.Status.started);
  93. }
  94. });
  95. }
  96. App.router.get('backgroundOperationsController').showPopup();
  97. });
  98. this.hide();
  99. },
  100. onSecondary: function() {
  101. this.hide();
  102. }
  103. });
  104. },
  105. stopComponent: function(event){
  106. var self = this;
  107. App.ModalPopup.show({
  108. header: Em.I18n.t('hosts.host.start.popup.header'),
  109. body: Em.I18n.t('hosts.host.start.popup.body'),
  110. primary: 'Yes',
  111. secondary: 'No',
  112. onPrimary: function() {
  113. var component = event.context;
  114. self.sendCommandToServer('/hosts/' + self.get('content.hostName') + '/host_components/' + component.get('componentName').toUpperCase(),{
  115. HostRoles:{
  116. state: 'INSTALLED'
  117. }
  118. }, function(requestId){
  119. if(!requestId){
  120. return
  121. }
  122. console.log('Send request for STOPPING successfully');
  123. component.set('workStatus', App.Component.Status.stopping);
  124. if(App.testMode){
  125. setTimeout(function(){
  126. component.set('workStatus', App.Component.Status.stopped);
  127. },10000);
  128. } else{
  129. App.router.get('backgroundOperationsController.eventsArray').push({
  130. "when" : function(controller){
  131. var result = (controller.getOperationsForRequestId(requestId).length == 0);
  132. console.log('stopComponent.when = ', result)
  133. return result;
  134. },
  135. "do" : function(){
  136. component.set('workStatus', App.Component.Status.stopped);
  137. }
  138. });
  139. }
  140. App.router.get('backgroundOperationsController').showPopup();
  141. });
  142. this.hide();
  143. },
  144. onSecondary: function() {
  145. this.hide();
  146. }
  147. });
  148. },
  149. decommission: function(event){
  150. var self = this;
  151. App.ModalPopup.show({
  152. header: Em.I18n.t('hosts.host.start.popup.header'),
  153. body: Em.I18n.t('hosts.host.start.popup.body'),
  154. primary: 'Yes',
  155. secondary: 'No',
  156. onPrimary: function() {
  157. var component = event.context;
  158. component.set('decommissioned', true);
  159. //todo:call to server
  160. App.router.get('backgroundOperationsController').showPopup();
  161. this.hide();
  162. },
  163. onSecondary: function() {
  164. this.hide();
  165. }
  166. });
  167. },
  168. recommission: function(event){
  169. var self = this;
  170. App.ModalPopup.show({
  171. header: Em.I18n.t('hosts.host.start.popup.header'),
  172. body: Em.I18n.t('hosts.host.start.popup.body'),
  173. primary: 'Yes',
  174. secondary: 'No',
  175. onPrimary: function() {
  176. var component = event.context;
  177. component.set('decommissioned', false);
  178. //todo: call to server
  179. App.router.get('backgroundOperationsController').showPopup();
  180. this.hide();
  181. },
  182. onSecondary: function() {
  183. this.hide();
  184. }
  185. });
  186. },
  187. validateDeletion: function() {
  188. var slaveComponents = ['DataNode', 'TaskTracker', 'RegionServer'];
  189. var masterComponents = [];
  190. var workingComponents = [];
  191. var components = this.get('content.components');
  192. components.forEach(function(cInstance){
  193. var cName = cInstance.get('componentName');
  194. if(slaveComponents.contains(cName)) {
  195. if(cInstance.get('workStatus')===App.Component.Status.stopped &&
  196. !cInstance.get('decommissioned')){
  197. workingComponents.push(cName);
  198. }
  199. } else {
  200. masterComponents.push(cName);
  201. }
  202. });
  203. //debugger;
  204. if(workingComponents.length || masterComponents.length) {
  205. this.raiseWarning(workingComponents, masterComponents);
  206. } else {
  207. this.deleteButtonPopup();
  208. }
  209. },
  210. raiseWarning: function (workingComponents, masterComponents) {
  211. var self = this;
  212. var masterString = '';
  213. var workingString = '';
  214. if(masterComponents && masterComponents.length) {
  215. var masterList = masterComponents.join(', ');
  216. var ml_text = Em.I18n.t('hosts.cant.do.popup.masterList.body');
  217. masterString = ml_text.format(masterList);
  218. }
  219. if(workingComponents && workingComponents.length) {
  220. var workingList = workingComponents.join(', ');
  221. var wl_text = Em.I18n.t('hosts.cant.do.popup.workingList.body');
  222. workingString = wl_text.format(workingList);
  223. }
  224. App.ModalPopup.show({
  225. header: Em.I18n.t('hosts.cant.do.popup.header'),
  226. html: true,
  227. body: masterString + workingString,
  228. primary: "OK",
  229. secondary: null,
  230. onPrimary: function() {
  231. this.hide();
  232. }
  233. })
  234. },
  235. deleteButtonPopup: function() {
  236. var self = this;
  237. App.ModalPopup.show({
  238. header: Em.I18n.t('hosts.delete.popup.header'),
  239. body: Em.I18n.t('hosts.delete.popup.body'),
  240. primary: 'Yes',
  241. secondary: 'No',
  242. onPrimary: function() {
  243. self.removeHost();
  244. this.hide();
  245. },
  246. onSecondary: function() {
  247. this.hide();
  248. }
  249. });
  250. },
  251. removeHost: function () {
  252. App.router.get('mainHostController').checkRemoved(this.get('content.id'));
  253. App.router.transitionTo('hosts');
  254. }
  255. })