details.js 8.7 KB

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