details.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. /**
  24. * open dashboard page
  25. */
  26. routeHome: function () {
  27. App.router.transitionTo('main.dashboard');
  28. },
  29. /**
  30. * open summary page of the selected service
  31. * @param event
  32. */
  33. routeToService: function(event){
  34. var service = event.context;
  35. App.router.transitionTo('main.services.service.summary',service);
  36. },
  37. /**
  38. * set new value to isFromHosts property
  39. * @param isFromHosts new value
  40. */
  41. setBack: function(isFromHosts){
  42. this.set('isFromHosts', isFromHosts);
  43. },
  44. /**
  45. * Send specific command to server
  46. * @param url
  47. * @param data Object to send
  48. */
  49. sendCommandToServer : function(url, postData, callback){
  50. var url = (App.testMode) ?
  51. '/data/wizard/deploy/poll_1.json' : //content is the same as ours
  52. App.apiPrefix + '/clusters/' + App.router.getClusterName() + url;
  53. var method = App.testMode ? 'GET' : 'PUT';
  54. $.ajax({
  55. type: method,
  56. url: url,
  57. data: JSON.stringify(postData),
  58. dataType: 'json',
  59. timeout: App.timeout,
  60. success: function(data){
  61. if(data && data.Requests){
  62. callback(data.Requests.id);
  63. } else{
  64. callback(null);
  65. console.log('cannot get request id from ', data);
  66. }
  67. },
  68. error: function (request, ajaxOptions, error) {
  69. //do something
  70. callback(null);
  71. console.log('error on change component host status')
  72. },
  73. statusCode: require('data/statusCodes')
  74. });
  75. },
  76. /**
  77. * send command to server to start selected host component
  78. * @param event
  79. */
  80. startComponent: function (event) {
  81. var self = this;
  82. App.showConfirmationPopup(function() {
  83. var component = event.context;
  84. self.sendCommandToServer('/hosts/' + self.get('content.hostName') + '/host_components/' + component.get('componentName').toUpperCase(),{
  85. HostRoles:{
  86. state: 'STARTED'
  87. }
  88. }, function(requestId){
  89. if(!requestId){
  90. return;
  91. }
  92. console.log('Send request for STARTING successfully');
  93. if (App.testMode) {
  94. component.set('workStatus', App.HostComponentStatus.starting);
  95. setTimeout(function(){
  96. component.set('workStatus', App.HostComponentStatus.started);
  97. },App.testModeDelayForActions);
  98. } else {
  99. App.router.get('clusterController').loadUpdatedStatusDelayed(500);
  100. App.router.get('backgroundOperationsController.eventsArray').push({
  101. "when" : function(controller){
  102. var result = (controller.getOperationsForRequestId(requestId).length == 0);
  103. console.log('startComponent.when = ', result)
  104. return result;
  105. },
  106. "do" : function(){
  107. App.router.get('clusterController').loadUpdatedStatus();
  108. }
  109. });
  110. }
  111. App.router.get('backgroundOperationsController').showPopup();
  112. });
  113. });
  114. },
  115. /**
  116. * send command to server to stop selected host component
  117. * @param event
  118. */
  119. stopComponent: function (event) {
  120. var self = this;
  121. App.showConfirmationPopup(function() {
  122. var component = event.context;
  123. self.sendCommandToServer('/hosts/' + self.get('content.hostName') + '/host_components/' + component.get('componentName').toUpperCase(),{
  124. HostRoles:{
  125. state: 'INSTALLED'
  126. }
  127. }, function(requestId){
  128. if(!requestId){
  129. return
  130. }
  131. console.log('Send request for STOPPING successfully');
  132. if (App.testMode) {
  133. component.set('workStatus', App.HostComponentStatus.stopping);
  134. setTimeout(function(){
  135. component.set('workStatus', App.HostComponentStatus.stopped);
  136. },App.testModeDelayForActions);
  137. } else {
  138. App.router.get('clusterController').loadUpdatedStatus();
  139. App.router.get('backgroundOperationsController.eventsArray').push({
  140. "when" : function(controller){
  141. var result = (controller.getOperationsForRequestId(requestId).length == 0);
  142. console.log('stopComponent.when = ', result)
  143. return result;
  144. },
  145. "do" : function(){
  146. App.router.get('clusterController').loadUpdatedStatus();
  147. }
  148. });
  149. }
  150. App.router.get('backgroundOperationsController').showPopup();
  151. });
  152. });
  153. },
  154. /**
  155. * send command to server to run decommission on DATANODE
  156. * @param event
  157. */
  158. decommission: function(event){
  159. var self = this;
  160. var decommissionHostNames = this.get('view.decommissionDataNodeHostNames');
  161. if (decommissionHostNames == null) {
  162. decommissionHostNames = [];
  163. }
  164. App.showConfirmationPopup(function(){
  165. var component = event.context;
  166. // Only HDFS service as of now
  167. var svcName = component.get('service.serviceName');
  168. if (svcName === "HDFS") {
  169. var hostName = self.get('content.hostName');
  170. var index = decommissionHostNames.indexOf(hostName);
  171. if (index < 0) {
  172. decommissionHostNames.push(hostName);
  173. }
  174. self.doDatanodeDecommission(decommissionHostNames);
  175. }
  176. App.router.get('backgroundOperationsController').showPopup();
  177. });
  178. },
  179. /**
  180. * Performs either Decommission or Recommision by updating the hosts list on
  181. * server.
  182. */
  183. doDatanodeDecommission: function(decommissionHostNames){
  184. var self = this;
  185. if (decommissionHostNames == null) {
  186. decommissionHostNames = [];
  187. }
  188. var invocationTag = String(new Date().getTime());
  189. var clusterName = App.router.get('clusterController.clusterName');
  190. var clusterUrl = App.apiPrefix + '/clusters/' + clusterName;
  191. var configsUrl = clusterUrl + '/configurations';
  192. var configsData = {
  193. type: "hdfs-exclude-file",
  194. tag: invocationTag,
  195. properties: {
  196. datanodes: decommissionHostNames.join(',')
  197. }
  198. };
  199. var configsAjax = {
  200. type: 'POST',
  201. url: configsUrl,
  202. dataType: 'json',
  203. data: JSON.stringify(configsData),
  204. timeout: App.timeout,
  205. success: function(){
  206. var actionsUrl = clusterUrl + '/services/HDFS/actions/DECOMMISSION_DATANODE';
  207. var actionsData = {
  208. parameters: {
  209. excludeFileTag: invocationTag
  210. }
  211. }
  212. var actionsAjax = {
  213. type: 'POST',
  214. url: actionsUrl,
  215. dataType: 'json',
  216. data: JSON.stringify(actionsData),
  217. timeout: App.timeout,
  218. success: function(){
  219. var persistUrl = App.apiPrefix + '/persist';
  220. var persistData = {
  221. "decommissionDataNodesTag": invocationTag
  222. };
  223. var persistPutAjax = {
  224. type: 'POST',
  225. url: persistUrl,
  226. dataType: 'json',
  227. data: JSON.stringify(persistData),
  228. timeout: App.timeout,
  229. success: function(){
  230. var view = self.get('view');
  231. view.loadDecommissionNodesList();
  232. }
  233. };
  234. jQuery.ajax(persistPutAjax);
  235. },
  236. error: function(xhr, textStatus, errorThrown){
  237. console.log(textStatus);
  238. console.log(errorThrown);
  239. }
  240. };
  241. jQuery.ajax(actionsAjax);
  242. },
  243. error: function(xhr, textStatus, errorThrown){
  244. console.log(textStatus);
  245. console.log(errorThrown);
  246. }
  247. }
  248. jQuery.ajax(configsAjax);
  249. },
  250. /**
  251. * send command to server to run recommission on DATANODE
  252. * @param event
  253. */
  254. recommission: function(event){
  255. var self = this;
  256. var decommissionHostNames = this.get('view.decommissionDataNodeHostNames');
  257. if (decommissionHostNames == null) {
  258. decommissionHostNames = [];
  259. }
  260. App.showConfirmationPopup(function(){
  261. var component = event.context;
  262. // Only HDFS service as of now
  263. var svcName = component.get('service.serviceName');
  264. if (svcName === "HDFS") {
  265. var hostName = self.get('content.hostName');
  266. var index = decommissionHostNames.indexOf(hostName);
  267. decommissionHostNames.splice(index, 1);
  268. self.doDatanodeDecommission(decommissionHostNames);
  269. }
  270. App.router.get('backgroundOperationsController').showPopup();
  271. });
  272. },
  273. /**
  274. * Deletion of hosts not supported for this version
  275. *
  276. * validateDeletion: function () { var slaveComponents = [ 'DataNode',
  277. * 'TaskTracker', 'RegionServer' ]; var masterComponents = []; var
  278. * workingComponents = [];
  279. *
  280. * var components = this.get('content.components');
  281. * components.forEach(function (cInstance) { var cName =
  282. * cInstance.get('componentName'); if (slaveComponents.contains(cName)) { if
  283. * (cInstance.get('workStatus') === App.HostComponentStatus.stopped &&
  284. * !cInstance.get('decommissioned')) { workingComponents.push(cName); } } else {
  285. * masterComponents.push(cName); } }); // debugger; if
  286. * (workingComponents.length || masterComponents.length) {
  287. * this.raiseWarning(workingComponents, masterComponents); } else {
  288. * this.deleteButtonPopup(); } },
  289. */
  290. raiseWarning: function (workingComponents, masterComponents) {
  291. var self = this;
  292. var masterString = '';
  293. var workingString = '';
  294. if(masterComponents && masterComponents.length) {
  295. var masterList = masterComponents.join(', ');
  296. var ml_text = Em.I18n.t('hosts.cant.do.popup.masterList.body');
  297. masterString = ml_text.format(masterList);
  298. }
  299. if(workingComponents && workingComponents.length) {
  300. var workingList = workingComponents.join(', ');
  301. var wl_text = Em.I18n.t('hosts.cant.do.popup.workingList.body');
  302. workingString = wl_text.format(workingList);
  303. }
  304. App.ModalPopup.show({
  305. header: Em.I18n.t('hosts.cant.do.popup.header'),
  306. html: true,
  307. body: masterString + workingString,
  308. primary: Em.I18n.t('ok'),
  309. secondary: null,
  310. onPrimary: function() {
  311. this.hide();
  312. }
  313. })
  314. },
  315. /**
  316. * show confirmation popup to delete host
  317. */
  318. deleteButtonPopup: function() {
  319. var self = this;
  320. App.showConfirmationPopup(function(){
  321. self.removeHost();
  322. });
  323. },
  324. /**
  325. * remove host and open hosts page
  326. */
  327. removeHost: function () {
  328. App.router.get('mainHostController').checkRemoved(this.get('content.id'));
  329. App.router.transitionTo('hosts');
  330. }
  331. })