details.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583
  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. var batchUtils = require('utils/batch_scheduled_requests');
  20. App.MainHostDetailsController = Em.Controller.extend({
  21. name: 'mainHostDetailsController',
  22. /**
  23. * Viewed host
  24. * @type {App.Host|null}
  25. */
  26. content: null,
  27. /**
  28. * Does user come from hosts page
  29. * @type {bool}
  30. */
  31. isFromHosts: false,
  32. /**
  33. * path to page visited before
  34. * @type {string}
  35. */
  36. referer: '',
  37. /**
  38. * Open dashboard page
  39. * @method routeHome
  40. */
  41. routeHome: function () {
  42. App.router.transitionTo('main.dashboard.index');
  43. },
  44. /**
  45. * Open summary page of the selected service
  46. * @param {object} event
  47. * @method routeToService
  48. */
  49. routeToService: function (event) {
  50. var service = event.context;
  51. App.router.transitionTo('main.services.service.summary', service);
  52. },
  53. /**
  54. * List of active (not in passive state) host components
  55. * @type {Ember.Enumerable}
  56. */
  57. serviceActiveComponents: function () {
  58. return this.get('content.hostComponents').filterProperty('service.isInPassive', false);
  59. }.property('content.hostComponents'),
  60. /**
  61. * List of active host components which aren't clients
  62. * @type {Ember.Enumerable}
  63. */
  64. serviceNonClientActiveComponents: function () {
  65. return this.get('serviceActiveComponents').filterProperty('isClient', false);
  66. }.property('serviceActiveComponents'),
  67. /**
  68. * Default error-callback for ajax-requests in current page
  69. * @param {object} request
  70. * @param {object} ajaxOptions
  71. * @param {string} error
  72. * @param {object} opt
  73. * @param {object} params
  74. * @method ajaxErrorCallback
  75. */
  76. ajaxErrorCallback: function (request, ajaxOptions, error, opt, params) {
  77. console.log('error on change component host status');
  78. App.ajax.defaultErrorHandler(request, opt.url, opt.method);
  79. },
  80. /**
  81. * send command to server to start selected host component
  82. * @param {object} event
  83. * @method startComponent
  84. */
  85. startComponent: function (event) {
  86. var self = this;
  87. return App.showConfirmationPopup(function () {
  88. var component = event.context;
  89. var context = Em.I18n.t('requestInfo.startHostComponent') + " " + component.get('displayName');
  90. self.sendStartComponentCommand(component, context);
  91. });
  92. },
  93. /**
  94. * PUTs a command to server to start a component. If no
  95. * specific component is provided, all components are started.
  96. * @param {object} component When <code>null</code> all startable components are started.
  97. * @param {string} context Context under which this command is beign sent.
  98. * @method sendStartComponentCommand
  99. */
  100. sendStartComponentCommand: function (component, context) {
  101. var dataToSend = this.getDataToSend('STARTED', context, component);
  102. var data = {
  103. hostName: this.get('content.hostName'),
  104. component: component
  105. };
  106. this.setComponentToData(data, dataToSend, component);
  107. App.ajax.send({
  108. name: (Array.isArray(component)) ? 'host.host_components.stop' : 'host.host_component.stop',
  109. sender: this,
  110. data: data,
  111. success: 'startComponentSuccessCallback',
  112. error: 'ajaxErrorCallback'
  113. });
  114. },
  115. /**
  116. * construct meta data for query
  117. * @param {String} state
  118. * @param {String} context
  119. * @param {String|Array} component - componentName or Array of components
  120. * @return {Object} request info
  121. * @method getDataToSend creates request info to start/stop component(s)
  122. */
  123. getDataToSend: function (state, context, component) {
  124. var operationLevel = {
  125. "cluster_name": App.get('clusterName'),
  126. "host_name": this.get("content.hostName")
  127. };
  128. if (Array.isArray(component)) {
  129. operationLevel["level"] = "HOST";
  130. } else if(component){
  131. operationLevel["level"] = "HOST_COMPONENT",
  132. operationLevel["hostcomponent_name"] = component.get("componentName"),
  133. operationLevel["service_name"] = component.get("service.serviceName")
  134. }
  135. return {
  136. RequestInfo: {
  137. "context": context,
  138. "operation_level": operationLevel
  139. },
  140. Body: {
  141. HostRoles: {
  142. state: state
  143. }
  144. }
  145. }
  146. },
  147. /**
  148. * set additional data to query info depending on component
  149. * @param data
  150. * @param dataToSend
  151. * @param component
  152. * @return {Boolean}
  153. */
  154. setComponentToData: function (data, dataToSend, component) {
  155. if (!dataToSend || !component || !data) return false;
  156. if (Array.isArray(component)) {
  157. dataToSend.RequestInfo.query = "HostRoles/component_name.in(" + component.mapProperty('componentName').join(',') + ")";
  158. } else {
  159. data.componentName = component.get('componentName');
  160. }
  161. data.data = JSON.stringify(dataToSend);
  162. return true;
  163. },
  164. /**
  165. * Success callback for start component(s) request
  166. * @param {object} data
  167. * @param {object} opt
  168. * @param {object} params
  169. * @method startComponentSuccessCallback
  170. */
  171. startComponentSuccessCallback: function (data, opt, params) {
  172. console.log('Send request for STARTING successfully');
  173. if (App.testMode) {
  174. this.mimicWorkStatusChange(params.component, App.HostComponentStatus.starting, App.HostComponentStatus.started);
  175. }
  176. this.showBackgroundOperationsPopup();
  177. },
  178. /**
  179. * mimic status transition in test mode
  180. * @param entity
  181. * @param transitionalState
  182. * @param finalState
  183. */
  184. mimicWorkStatusChange: function(entity, transitionalState, finalState) {
  185. if (Em.isArray(entity)) {
  186. entity.forEach(function (item) {
  187. item.set('workStatus', transitionalState);
  188. setTimeout(function () {
  189. item.set('workStatus', finalState);
  190. }, App.testModeDelayForActions);
  191. });
  192. } else {
  193. entity.set('workStatus', transitionalState);
  194. setTimeout(function () {
  195. entity.set('workStatus', finalState);
  196. }, App.testModeDelayForActions);
  197. }
  198. },
  199. /**
  200. * load data (if we need to show this background operations popup) from persist
  201. * @param callback
  202. */
  203. showBackgroundOperationsPopup: function (callback) {
  204. App.router.get('applicationController').dataLoading().done(function (initValue) {
  205. if (initValue) {
  206. App.router.get('backgroundOperationsController').showPopup();
  207. }
  208. if (typeof callback === 'function') {
  209. callback();
  210. }
  211. });
  212. },
  213. /**
  214. * Send command to server to delete selected host component
  215. * @param {object} event
  216. * @method deleteComponent
  217. */
  218. deleteComponent: function (event) {
  219. var self = this;
  220. var component = event.context;
  221. var componentName = component.get('componentName');
  222. var displayName = component.get('displayName');
  223. var isLastComponent = (App.HostComponent.find().filterProperty('componentName', componentName).get('length') === 1);
  224. App.ModalPopup.show({
  225. header: Em.I18n.t('popup.confirmation.commonHeader'),
  226. primary: Em.I18n.t('hosts.host.deleteComponent.popup.confirm'),
  227. bodyClass: Em.View.extend({
  228. templateName: require('templates/main/host/details/deleteComponentPopup')
  229. }),
  230. isChecked: false,
  231. disablePrimary: function () {
  232. return !this.get('isChecked');
  233. }.property('isChecked'),
  234. lastComponent: function () {
  235. this.set('isChecked', !isLastComponent);
  236. return isLastComponent;
  237. }.property(),
  238. lastComponentError: Em.View.extend({
  239. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.deleteComponent.popup.warning').format(displayName))
  240. }),
  241. restartNagiosMsg: Em.View.extend({
  242. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.deleteComponent.popup.msg2').format(displayName))
  243. }),
  244. deleteComponentMsg: function () {
  245. return Em.I18n.t('hosts.host.deleteComponent.popup.msg1').format(displayName);
  246. }.property(),
  247. onPrimary: function () {
  248. self._doDeleteHostComponent(component);
  249. self.set('redrawComponents', true);
  250. this.hide();
  251. }
  252. });
  253. },
  254. /**
  255. * Trigger to reset list of master/slaves components on the view
  256. * @type {bool}
  257. */
  258. redrawComponents: false,
  259. /**
  260. * Deletes the given host component, or all host components.
  261. *
  262. * @param {object|null} component When <code>null</code> all host components are deleted.
  263. * @return <code>null</code> when components get deleted.
  264. * <code>{xhr: XhrObj, url: "http://", method: "DELETE"}</code>
  265. * when components failed to get deleted.
  266. * @method _doDeleteHostComponent
  267. */
  268. _doDeleteHostComponent: function (component) {
  269. App.ajax.send({
  270. name: (Em.isNone(component)) ? 'host.host_components.delete' : 'host.host_component.delete',
  271. sender: this,
  272. data: {
  273. componentName: (component) ? component.get('componentName') : '',
  274. hostName: this.get('content.hostName')
  275. },
  276. success: '_doDeleteHostComponentSuccessCallback',
  277. error: '_doDeleteHostComponentErrorCallback'
  278. });
  279. return this.get('_deletedHostComponentResult');
  280. },
  281. /**
  282. * Result of delete component(s) request
  283. * @type {object}
  284. */
  285. _deletedHostComponentResult: null,
  286. /**
  287. * Success callback for delete host component request
  288. * @method _doDeleteHostComponentSuccessCallback
  289. */
  290. _doDeleteHostComponentSuccessCallback: function () {
  291. this.set('_deletedHostComponentResult', null);
  292. },
  293. /**
  294. * Error-callback for delete host component request
  295. * @param {object} xhr
  296. * @param {string} textStatus
  297. * @param {object} errorThrown
  298. * @method _doDeleteHostComponentErrorCallback
  299. */
  300. _doDeleteHostComponentErrorCallback: function (xhr, textStatus, errorThrown) {
  301. console.log('Error deleting host component');
  302. console.log(textStatus);
  303. console.log(errorThrown);
  304. this.set('_deletedHostComponentResult', {xhr: xhr, url: url, method: 'DELETE'});
  305. },
  306. /**
  307. * Send command to server to upgrade selected host component
  308. * @param {object} event
  309. * @method upgradeComponent
  310. */
  311. upgradeComponent: function (event) {
  312. var self = this;
  313. var component = event.context;
  314. return App.showConfirmationPopup(function () {
  315. App.ajax.send({
  316. name: 'host.host_component.upgrade',
  317. sender: self,
  318. data: {
  319. component: component,
  320. hostName: self.get('content.hostName'),
  321. componentName: component.get('componentName'),
  322. data: JSON.stringify({
  323. RequestInfo: {
  324. "context": Em.I18n.t('requestInfo.upgradeHostComponent') + " " + component.get('displayName')
  325. },
  326. Body: {
  327. HostRoles: {
  328. stack_id: 'HDP-1.2.2',
  329. state: 'INSTALLED'
  330. }
  331. }
  332. })
  333. },
  334. success: 'upgradeComponentSuccessCallback',
  335. error: 'ajaxErrorCallback'
  336. });
  337. });
  338. },
  339. /**
  340. * Success callback for upgrade host component request
  341. * @param {object} data
  342. * @param {object} opt
  343. * @param {object} params
  344. * @method upgradeComponentSuccessCallback
  345. */
  346. upgradeComponentSuccessCallback: function (data, opt, params) {
  347. console.log('Send request for UPGRADE successfully');
  348. if (App.testMode) {
  349. this.mimicWorkStatusChange(params.component, App.HostComponentStatus.starting, App.HostComponentStatus.started);
  350. }
  351. this.showBackgroundOperationsPopup();
  352. },
  353. /**
  354. * Send command to server to stop selected host component
  355. * @param {object} event
  356. * @method stopComponent
  357. */
  358. stopComponent: function (event) {
  359. var self = this;
  360. return App.showConfirmationPopup(function () {
  361. var component = event.context;
  362. var context = Em.I18n.t('requestInfo.stopHostComponent') + " " + component.get('displayName');
  363. self.sendStopComponentCommand(component, context);
  364. });
  365. },
  366. /**
  367. * PUTs a command to server to stop a component. If no
  368. * specific component is provided, all components are stopped.
  369. * @param {object} component When <code>null</code> all components are stopped.
  370. * @param {object} context Context under which this command is beign sent.
  371. * @method sendStopComponentCommand
  372. */
  373. sendStopComponentCommand: function (component, context) {
  374. var dataToSend = this.getDataToSend('INSTALLED', context, component);
  375. var data = {
  376. hostName: this.get('content.hostName'),
  377. component: component
  378. };
  379. this.setComponentToData(data, dataToSend, component);
  380. App.ajax.send({
  381. name: (Array.isArray(component)) ? 'host.host_components.stop' : 'host.host_component.stop',
  382. sender: this,
  383. data: data,
  384. success: 'stopComponentSuccessCallback',
  385. error: 'ajaxErrorCallback'
  386. });
  387. },
  388. /**
  389. * Success callback for stop host component request
  390. * @param {object} data
  391. * @param {object} opt
  392. * @param {object} params
  393. * @method stopComponentSuccessCallback
  394. */
  395. stopComponentSuccessCallback: function (data, opt, params) {
  396. console.log('Send request for STOPPING successfully');
  397. if (App.testMode) {
  398. this.mimicWorkStatusChange(params.component, App.HostComponentStatus.stopping, App.HostComponentStatus.stopped);
  399. }
  400. this.showBackgroundOperationsPopup();
  401. },
  402. /**
  403. * Send command to server to restart selected components
  404. * @param {object} event
  405. * @method restartComponent
  406. */
  407. restartComponent: function (event) {
  408. var component = event.context;
  409. return App.showConfirmationPopup(function () {
  410. batchUtils.restartHostComponents([component], Em.I18n.t('rollingrestart.context.selectedComponentOnSelectedHost').format(component.get('displayName')), "HOST_COMPONENT");
  411. });
  412. },
  413. /**
  414. * get current status of security settings,
  415. * if true security is enabled otherwise disabled
  416. * @return {Boolean}
  417. */
  418. getSecurityStatus: function () {
  419. return App.router.get('mainAdminSecurityController').getUpdatedSecurityStatus();
  420. },
  421. /**
  422. * Send command to server to install selected host component
  423. * @param {object} event
  424. * @method addComponent
  425. */
  426. addComponent: function (event) {
  427. var self = this;
  428. var component = event.context;
  429. var componentName = component.get('componentName');
  430. var securityEnabled = this.getSecurityStatus();
  431. if (componentName === 'ZOOKEEPER_SERVER') {
  432. return App.showConfirmationPopup(function () {
  433. self.primary(component);
  434. }, Em.I18n.t('hosts.host.addComponent.addZooKeeper'));
  435. }
  436. else {
  437. if (securityEnabled && componentName !== 'CLIENTS') {
  438. return App.showConfirmationPopup(function () {
  439. self.primary(component);
  440. }, Em.I18n.t('hosts.host.addComponent.securityNote').format(componentName, self.get('content.hostName')));
  441. }
  442. else {
  443. return this.addClientComponent(component);
  444. }
  445. }
  446. },
  447. /**
  448. * Send command to server to install client on selected host
  449. * @param component
  450. */
  451. addClientComponent: function (component) {
  452. var self = this;
  453. var message = this.formatClientsMessage(component);
  454. return App.ModalPopup.show({
  455. primary: Em.I18n.t('hosts.host.addComponent.popup.confirm'),
  456. header: Em.I18n.t('popup.confirmation.commonHeader'),
  457. addComponentMsg: function () {
  458. return Em.I18n.t('hosts.host.addComponent.msg').format(message);
  459. }.property(),
  460. bodyClass: Em.View.extend({
  461. templateName: require('templates/main/host/details/addComponentPopup')
  462. }),
  463. restartNagiosMsg: Em.View.extend({
  464. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.addComponent.note').format(message))
  465. }),
  466. onPrimary: function () {
  467. this.hide();
  468. if (component.get('componentName') === 'CLIENTS') {
  469. // Clients component has many sub-components which
  470. // need to be installed.
  471. var scs = component.get('subComponentNames');
  472. scs.forEach(function (sc) {
  473. var c = Em.Object.create({
  474. displayName: App.format.role(sc),
  475. componentName: sc
  476. });
  477. self.primary(c);
  478. });
  479. } else {
  480. self.primary(component);
  481. }
  482. }
  483. });
  484. },
  485. /**
  486. * format message for operation of adding clients
  487. * @param client
  488. */
  489. formatClientsMessage: function (client) {
  490. var displayName = Em.isNone(client.get('displayName')) ? '' : client.get('displayName');
  491. var subComponentNames = client.get('subComponentNames');
  492. if (subComponentNames && subComponentNames.length > 0) {
  493. var dns = [];
  494. subComponentNames.forEach(function (scn) {
  495. dns.push(App.format.role(scn));
  496. });
  497. displayName += " (" + dns.join(", ") + ")";
  498. }
  499. return displayName;
  500. },
  501. /**
  502. * Send request to add host component
  503. * @param {App.HostComponent} component
  504. * @method primary
  505. */
  506. primary: function (component) {
  507. var self = this;
  508. var componentName = component.get('componentName');
  509. var displayName = component.get('displayName');
  510. App.ajax.send({
  511. name: 'host.host_component.add_new_component',
  512. sender: self,
  513. data: {
  514. hostName: self.get('content.hostName'),
  515. component: component,
  516. data: JSON.stringify({
  517. RequestInfo: {
  518. "context": Em.I18n.t('requestInfo.installHostComponent') + " " + displayName
  519. },
  520. Body: {
  521. host_components: [
  522. {
  523. HostRoles: {
  524. component_name: componentName
  525. }
  526. }
  527. ]
  528. }
  529. })
  530. },
  531. success: 'addNewComponentSuccessCallback',
  532. error: 'ajaxErrorCallback'
  533. });
  534. },
  535. /**
  536. * Success callback for add host component request
  537. * @param {object} data
  538. * @param {object} opt
  539. * @param {object} params
  540. * @method addNewComponentSuccessCallback
  541. */
  542. addNewComponentSuccessCallback: function (data, opt, params) {
  543. console.log('Send request for ADDING NEW COMPONENT successfully');
  544. App.ajax.send({
  545. name: 'host.host_component.install_new_component',
  546. sender: this,
  547. data: {
  548. hostName: this.get('content.hostName'),
  549. componentName: params.component.get('componentName'),
  550. component: params.component,
  551. data: JSON.stringify({
  552. RequestInfo: {
  553. "context": Em.I18n.t('requestInfo.installNewHostComponent') + " " + params.component.get('displayName')
  554. },
  555. Body: {
  556. HostRoles: {
  557. state: 'INSTALLED'
  558. }
  559. }
  560. })
  561. },
  562. success: 'installNewComponentSuccessCallback',
  563. error: 'ajaxErrorCallback'
  564. });
  565. },
  566. /**
  567. * Success callback for install host component request (sent in <code>addNewComponentSuccessCallback</code>)
  568. * @param {object} data
  569. * @param {object} opt
  570. * @param {object} params
  571. * @method installNewComponentSuccessCallback
  572. */
  573. installNewComponentSuccessCallback: function (data, opt, params) {
  574. if (!data.Requests || !data.Requests.id) {
  575. return false;
  576. }
  577. var self = this;
  578. console.log('Send request for INSTALLING NEW COMPONENT successfully');
  579. if (App.testMode) {
  580. this.mimicWorkStatusChange(params.component, App.HostComponentStatus.installing, App.HostComponentStatus.stopped);
  581. }
  582. this.showBackgroundOperationsPopup(function () {
  583. if (params.componentName === 'ZOOKEEPER_SERVER') {
  584. self.set('zkRequestId', data.Requests.id);
  585. self.addObserver('App.router.backgroundOperationsController.serviceTimestamp', self, self.checkZkConfigs);
  586. self.checkZkConfigs();
  587. }
  588. });
  589. return true;
  590. },
  591. /**
  592. * Send command to server to resfresh configs of selected component
  593. * @param {object} event
  594. * @method refreshComponentConfigs
  595. */
  596. refreshComponentConfigs: function (event) {
  597. var self = this;
  598. return App.showConfirmationPopup(function () {
  599. var component = event.context;
  600. var context = Em.I18n.t('requestInfo.refreshComponentConfigs').format(component.get('displayName'));
  601. self.sendRefreshComponentConfigsCommand(component, context);
  602. });
  603. },
  604. /**
  605. * PUTs a command to server to refresh configs of host component.
  606. * @param {object} component
  607. * @param {object} context Context under which this command is beign sent.
  608. * @method sendRefreshComponentConfigsCommand
  609. */
  610. sendRefreshComponentConfigsCommand: function (component, context) {
  611. var resource_filters = [
  612. {
  613. service_name: component.get('service.serviceName'),
  614. component_name: component.get('componentName'),
  615. hosts: component.get('host.hostName')
  616. }
  617. ];
  618. App.ajax.send({
  619. name: 'host.host_component.refresh_configs',
  620. sender: this,
  621. data: {
  622. resource_filters: resource_filters,
  623. context: context
  624. },
  625. success: 'refreshComponentConfigsSuccessCallback'
  626. });
  627. },
  628. /**
  629. * Success callback for refresh host component configs request
  630. * @method refreshComponentConfigsSuccessCallback
  631. */
  632. refreshComponentConfigsSuccessCallback: function () {
  633. console.log('Send request for refresh configs successfully');
  634. this.showBackgroundOperationsPopup();
  635. },
  636. /**
  637. * Load tags
  638. * @method checkZkConfigs
  639. */
  640. checkZkConfigs: function () {
  641. var bg = App.router.get('backgroundOperationsController.services').findProperty('id', this.get('zkRequestId'));
  642. if (bg && !bg.get('isRunning')) {
  643. this.loadConfigs();
  644. }
  645. },
  646. /**
  647. * Load configs
  648. * @method loadConfigs
  649. */
  650. loadConfigs: function () {
  651. this.removeObserver('App.router.backgroundOperationsController.serviceTimestamp', this, this.checkZkConfigs);
  652. App.ajax.send({
  653. name: 'config.tags',
  654. sender: this,
  655. success: 'loadConfigsSuccessCallback'
  656. });
  657. },
  658. /**
  659. * Success callback for load configs request
  660. * @param {object} data
  661. * @method adConfigsSuccessCallback
  662. */
  663. loadConfigsSuccessCallback: function (data) {
  664. var urlParams = this.constructConfigUrlParams(data);
  665. if (urlParams.length > 0) {
  666. App.ajax.send({
  667. name: 'reassign.load_configs',
  668. sender: this,
  669. data: {
  670. urlParams: urlParams.join('|')
  671. },
  672. success: 'saveZkConfigs'
  673. });
  674. return true;
  675. }
  676. return false;
  677. },
  678. /**
  679. * construct URL params for query, that load configs
  680. * @param data {Object}
  681. * @return {Array}
  682. */
  683. constructConfigUrlParams: function (data) {
  684. var urlParams = [];
  685. var services = App.Service.find();
  686. if (App.get('isHaEnabled')) {
  687. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  688. }
  689. if (services.someProperty('serviceName', 'HBASE')) {
  690. urlParams.push('(type=hbase-site&tag=' + data.Clusters.desired_configs['hbase-site'].tag + ')');
  691. }
  692. if (services.someProperty('serviceName', 'HIVE')) {
  693. urlParams.push('(type=webhcat-site&tag=' + data.Clusters.desired_configs['webhcat-site'].tag + ')');
  694. }
  695. if (services.someProperty('serviceName', 'STORM')) {
  696. urlParams.push('(type=storm-site&tag=' + data.Clusters.desired_configs['storm-site'].tag + ')');
  697. }
  698. return urlParams;
  699. },
  700. /**
  701. * save new ZooKeeper configs to server
  702. * @param {object} data
  703. * @method saveZkConfigs
  704. */
  705. saveZkConfigs: function (data) {
  706. var configs = {};
  707. data.items.forEach(function (item) {
  708. configs[item.type] = item.properties;
  709. }, this);
  710. var zks = this.getZkServerHosts();
  711. var zksWithPort = this.concatZkNames(zks);
  712. this.setZKConfigs(configs, zksWithPort, zks);
  713. for (var site in configs) {
  714. if (!configs.hasOwnProperty(site)) continue;
  715. App.ajax.send({
  716. name: 'reassign.save_configs',
  717. sender: this,
  718. data: {
  719. siteName: site,
  720. properties: configs[site]
  721. }
  722. });
  723. }
  724. },
  725. /**
  726. * Set new values for some configs (based on available ZooKeeper Servers)
  727. * @param configs {object}
  728. * @param zksWithPort {string}
  729. * @param zks {array}
  730. * @return {Boolean}
  731. */
  732. setZKConfigs: function (configs, zksWithPort, zks) {
  733. if(typeof configs !== 'object' || !Array.isArray(zks)) return false;
  734. if (App.get('isHaEnabled')) {
  735. configs['core-site']['ha.zookeeper.quorum'] = zksWithPort;
  736. }
  737. if (configs['hbase-site']) {
  738. configs['hbase-site']['hbase.zookeeper.quorum'] = zks.join(',');
  739. }
  740. if (configs['webhcat-site']) {
  741. configs['webhcat-site']['templeton.zookeeper.hosts'] = zksWithPort;
  742. }
  743. if (configs['storm-site']) {
  744. configs['storm-site']['storm.zookeeper.servers'] = JSON.stringify(zks).replace(/"/g, "'");
  745. }
  746. return true;
  747. },
  748. /**
  749. * concatenate URLs to ZOOKEEPER hosts with port "2181",
  750. * as value of config divided by comma
  751. * @param zks {array}
  752. */
  753. concatZkNames: function (zks) {
  754. var zks_with_port = '';
  755. zks.forEach(function (zk) {
  756. zks_with_port += zk + ':2181,';
  757. });
  758. return zks_with_port.slice(0, -1);
  759. },
  760. /**
  761. * Is deleteHost action id fired
  762. * @type {bool}
  763. */
  764. fromDeleteHost: false,
  765. /**
  766. * Get list of hostnames where ZK Server is installed
  767. * @returns {string[]}
  768. * @method getZkServerHosts
  769. */
  770. getZkServerHosts: function () {
  771. var zks = App.HostComponent.find().filterProperty('componentName', 'ZOOKEEPER_SERVER').mapProperty('host.hostName');
  772. if (this.get('fromDeleteHost')) {
  773. this.set('fromDeleteHost', false);
  774. return zks.without(this.get('content.hostName'));
  775. }
  776. return zks;
  777. },
  778. /**
  779. * Send command to server to install selected host component
  780. * @param {Object} event
  781. * @method installComponent
  782. */
  783. installComponent: function (event) {
  784. var self = this;
  785. var component = event.context;
  786. var componentName = component.get('componentName');
  787. var displayName = component.get('displayName');
  788. return App.ModalPopup.show({
  789. primary: Em.I18n.t('hosts.host.installComponent.popup.confirm'),
  790. header: Em.I18n.t('popup.confirmation.commonHeader'),
  791. installComponentMessage: function () {
  792. return Em.I18n.t('hosts.host.installComponent.msg').format(displayName);
  793. }.property(),
  794. restartNagiosMsg: Em.View.extend({
  795. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.addComponent.note').format(displayName))
  796. }),
  797. bodyClass: Em.View.extend({
  798. templateName: require('templates/main/host/details/installComponentPopup')
  799. }),
  800. onPrimary: function () {
  801. this.hide();
  802. App.ajax.send({
  803. name: 'host.host_component.install',
  804. sender: self,
  805. data: {
  806. hostName: self.get('content.hostName'),
  807. componentName: componentName,
  808. component: component,
  809. data: JSON.stringify({
  810. RequestInfo: {
  811. "context": Em.I18n.t('requestInfo.installHostComponent') + " " + displayName
  812. },
  813. Body: {
  814. HostRoles: {
  815. state: 'INSTALLED'
  816. }
  817. }
  818. })
  819. },
  820. success: 'installComponentSuccessCallback',
  821. error: 'ajaxErrorCallback'
  822. });
  823. }
  824. });
  825. },
  826. /**
  827. * Success callback for install component request
  828. * @param {object} data
  829. * @param {object} opt
  830. * @param {object} params
  831. * @method installComponentSuccessCallback
  832. */
  833. installComponentSuccessCallback: function (data, opt, params) {
  834. console.log('Send request for REINSTALL COMPONENT successfully');
  835. if (App.testMode) {
  836. this.mimicWorkStatusChange(params.component, App.HostComponentStatus.installing, App.HostComponentStatus.stopped);
  837. }
  838. this.showBackgroundOperationsPopup();
  839. },
  840. /**
  841. * Send command to server to run decommission on DATANODE, TASKTRACKER, NODEMANAGER, REGIONSERVER
  842. * @param {App.HostComponent} component
  843. * @method decommission
  844. */
  845. decommission: function (component) {
  846. var self = this;
  847. return App.showConfirmationPopup(function () {
  848. self.runDecommission.call(self, self.get('content.hostName'), component.get('service.serviceName'));
  849. });
  850. },
  851. /**
  852. * identify correct component to run decommission on them by service name,
  853. * in result run proper decommission method
  854. * @param hostName
  855. * @param svcName
  856. */
  857. runDecommission: function (hostName, svcName) {
  858. switch (svcName) {
  859. case 'HDFS':
  860. this.doDecommission(hostName, svcName, "NAMENODE", "DATANODE");
  861. break;
  862. case 'YARN':
  863. this.doDecommission(hostName, svcName, "RESOURCEMANAGER", "NODEMANAGER");
  864. break;
  865. case 'MAPREDUCE':
  866. this.doDecommission(hostName, svcName, "JOBTRACKER", "TASKTRACKER");
  867. break;
  868. case 'HBASE':
  869. this.doDecommissionRegionServer(hostName, svcName, "HBASE_MASTER", "HBASE_REGIONSERVER");
  870. }
  871. this.showBackgroundOperationsPopup();
  872. },
  873. /**
  874. * Send command to server to run recommission on DATANODE, TASKTRACKER, NODEMANAGER
  875. * @param {App.HostComponent} component
  876. * @method recommission
  877. */
  878. recommission: function (component) {
  879. var self = this;
  880. App.showConfirmationPopup(function () {
  881. self.runRecommission.call(self, self.get('content.hostName'), component.get('service.serviceName'));
  882. });
  883. },
  884. /**
  885. * identify correct component to run recommission on them by service name,
  886. * in result run proper recommission method
  887. * @param hostName
  888. * @param svcName
  889. */
  890. runRecommission: function (hostName, svcName) {
  891. switch (svcName) {
  892. case 'HDFS':
  893. this.doRecommissionAndStart(hostName, svcName, "NAMENODE", "DATANODE");
  894. break;
  895. case 'YARN':
  896. this.doRecommissionAndStart(hostName, svcName, "RESOURCEMANAGER", "NODEMANAGER");
  897. break;
  898. case 'MAPREDUCE':
  899. this.doRecommissionAndRestart(hostName, svcName, "JOBTRACKER", "TASKTRACKER");
  900. break;
  901. case 'HBASE':
  902. this.doRecommissionAndStart(hostName, svcName, "HBASE_MASTER", "HBASE_REGIONSERVER");
  903. }
  904. this.showBackgroundOperationsPopup();
  905. },
  906. /**
  907. * Performs Decommission (for DN, TT and NM)
  908. * @param {string} hostName
  909. * @param {string} serviceName
  910. * @param {string} componentName
  911. * @param {string} slaveType
  912. * @method doDecommission
  913. */
  914. doDecommission: function (hostName, serviceName, componentName, slaveType) {
  915. var contextNameString = 'hosts.host.' + slaveType.toLowerCase() + '.decommission';
  916. var context = Em.I18n.t(contextNameString);
  917. App.ajax.send({
  918. name: 'host.host_component.decommission_slave',
  919. sender: this,
  920. data: {
  921. context: context,
  922. command: 'DECOMMISSION',
  923. hostName: hostName,
  924. serviceName: serviceName,
  925. componentName: componentName,
  926. slaveType: slaveType
  927. },
  928. success: 'decommissionSuccessCallback',
  929. error: 'decommissionErrorCallback'
  930. });
  931. },
  932. /**
  933. * Performs Decommission (for RegionServer)
  934. * @method doDecommissionRegionServer
  935. * @param {string[]} hostNames - list of host when run from bulk operations or current host
  936. * @param {string} serviceName - serviceName
  937. * @param {string} componentName - master compoent name
  938. * @param {string} slaveType - slave component name
  939. */
  940. doDecommissionRegionServer: function (hostNames, serviceName, componentName, slaveType) {
  941. App.ajax.send({
  942. name: 'host.host_component.recommission_and_restart',
  943. sender: this,
  944. data: {
  945. intervalTimeSeconds: 1,
  946. tolerateSize: 0,
  947. batches: [
  948. {
  949. "order_id": 1,
  950. "type": "POST",
  951. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
  952. "RequestBodyInfo": {
  953. "RequestInfo": {
  954. "context": Em.I18n.t('hosts.host.regionserver.decommission.batch1'),
  955. "command": "DECOMMISSION",
  956. "parameters": {
  957. "slave_type": slaveType,
  958. "excluded_hosts": hostNames
  959. }
  960. },
  961. "Requests/resource_filters": [
  962. {"service_name": serviceName, "component_name": componentName}
  963. ]
  964. }
  965. },
  966. {
  967. "order_id": 2,
  968. "type": "PUT",
  969. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/host_components",
  970. "RequestBodyInfo": {
  971. "RequestInfo": {
  972. context: Em.I18n.t('hosts.host.regionserver.decommission.batch2'),
  973. query: 'HostRoles/component_name=' + slaveType + '&HostRoles/host_name.in(' + hostNames + ')&HostRoles/maintenance_state=OFF'
  974. },
  975. "Body": {
  976. HostRoles: {
  977. state: "INSTALLED"
  978. }
  979. }
  980. }
  981. },
  982. {
  983. "order_id": 3,
  984. "type": "POST",
  985. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
  986. "RequestBodyInfo": {
  987. "RequestInfo": {
  988. "context": Em.I18n.t('hosts.host.regionserver.decommission.batch3'),
  989. "command": "DECOMMISSION",
  990. "service_name": serviceName,
  991. "component_name": componentName,
  992. "parameters": {
  993. "slave_type": slaveType,
  994. "excluded_hosts": hostNames,
  995. "mark_draining_only": "true"
  996. }
  997. }
  998. }
  999. }
  1000. ]
  1001. },
  1002. success: 'decommissionSuccessCallback',
  1003. error: 'decommissionErrorCallback'
  1004. });
  1005. },
  1006. /**
  1007. * Error callback for decommission requests
  1008. * @param {object} request
  1009. * @param {object} ajaxOptions
  1010. * @param {string} error
  1011. * @method decommissionErrorCallback
  1012. */
  1013. decommissionErrorCallback: function (request, ajaxOptions, error) {
  1014. console.log('ERROR: ' + error);
  1015. },
  1016. /**
  1017. * Success ajax response for Recommission/Decommission slaves
  1018. * @param {object} data
  1019. * @method decommissionSuccessCallback
  1020. * @return {Boolean}
  1021. */
  1022. decommissionSuccessCallback: function (data) {
  1023. if (data && (data.Requests || data.resources[0].RequestSchedule)) {
  1024. this.showBackgroundOperationsPopup();
  1025. return true;
  1026. } else {
  1027. console.log('cannot get request id from ', data);
  1028. return false;
  1029. }
  1030. },
  1031. /**
  1032. * Performs Recommission and Start
  1033. * @param {string} hostNames
  1034. * @param {string} serviceName
  1035. * @param {string} componentName
  1036. * @param {string} slaveType
  1037. * @method doRecommissionAndStart
  1038. */
  1039. doRecommissionAndStart: function (hostNames, serviceName, componentName, slaveType) {
  1040. var contextNameString_1 = 'hosts.host.' + slaveType.toLowerCase() + '.recommission';
  1041. var context_1 = Em.I18n.t(contextNameString_1);
  1042. var contextNameString_2 = 'requestInfo.startHostComponent.' + slaveType.toLowerCase();
  1043. var startContext = Em.I18n.t(contextNameString_2);
  1044. App.ajax.send({
  1045. name: 'host.host_component.recommission_and_restart',
  1046. sender: this,
  1047. data: {
  1048. intervalTimeSeconds: 1,
  1049. tolerateSize: 1,
  1050. batches: [
  1051. {
  1052. "order_id": 1,
  1053. "type": "POST",
  1054. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
  1055. "RequestBodyInfo": {
  1056. "RequestInfo": {
  1057. "context": context_1,
  1058. "command": "DECOMMISSION",
  1059. "parameters": {
  1060. "slave_type": slaveType,
  1061. "included_hosts": hostNames
  1062. }
  1063. },
  1064. "Requests/resource_filters": [
  1065. {"service_name": serviceName, "component_name": componentName}
  1066. ]
  1067. }
  1068. },
  1069. {
  1070. "order_id": 2,
  1071. "type": "PUT",
  1072. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/host_components",
  1073. "RequestBodyInfo": {
  1074. "RequestInfo": {
  1075. context: startContext,
  1076. query: 'HostRoles/component_name=' + slaveType + '&HostRoles/host_name.in(' + hostNames + ')&HostRoles/maintenance_state=OFF'
  1077. },
  1078. "Body": {
  1079. HostRoles: {
  1080. state: "STARTED"
  1081. }
  1082. }
  1083. }
  1084. }
  1085. ]
  1086. },
  1087. success: 'decommissionSuccessCallback',
  1088. error: 'decommissionErrorCallback'
  1089. });
  1090. },
  1091. /**
  1092. * Performs Recommission and Restart
  1093. * @param {string} hostNames
  1094. * @param {string} serviceName
  1095. * @param {string} componentName
  1096. * @param {string} slaveType
  1097. * @method doRecommissionAndStart
  1098. */
  1099. doRecommissionAndRestart: function (hostNames, serviceName, componentName, slaveType) {
  1100. var contextNameString_1 = 'hosts.host.' + slaveType.toLowerCase() + '.recommission';
  1101. var context_1 = Em.I18n.t(contextNameString_1);
  1102. var contextNameString_2 = 'hosts.host.' + slaveType.toLowerCase() + '.restart';
  1103. var context_2 = Em.I18n.t(contextNameString_2);
  1104. App.ajax.send({
  1105. name: 'host.host_component.recommission_and_restart',
  1106. sender: this,
  1107. data: {
  1108. intervalTimeSeconds: 1,
  1109. tolerateSize: 1,
  1110. batches: [
  1111. {
  1112. "order_id": 1,
  1113. "type": "POST",
  1114. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
  1115. "RequestBodyInfo": {
  1116. "RequestInfo": {
  1117. "context": context_1,
  1118. "command": "DECOMMISSION",
  1119. "parameters": {
  1120. "slave_type": slaveType,
  1121. "included_hosts": hostNames
  1122. }
  1123. },
  1124. "Requests/resource_filters": [
  1125. {"service_name": serviceName, "component_name": componentName}
  1126. ]
  1127. }
  1128. },
  1129. {
  1130. "order_id": 2,
  1131. "type": "POST",
  1132. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
  1133. "RequestBodyInfo": {
  1134. "RequestInfo": {
  1135. "context": context_2,
  1136. "command": "RESTART",
  1137. "service_name": serviceName,
  1138. "component_name": slaveType,
  1139. "hosts": hostNames
  1140. }
  1141. }
  1142. }
  1143. ]
  1144. },
  1145. success: 'decommissionSuccessCallback',
  1146. error: 'decommissionErrorCallback'
  1147. });
  1148. },
  1149. /**
  1150. * Handler for host-menu items actions
  1151. * @param {object} option
  1152. * @method doAction
  1153. */
  1154. doAction: function (option) {
  1155. switch (option.context.action) {
  1156. case "deleteHost":
  1157. this.validateAndDeleteHost();
  1158. break;
  1159. case "startAllComponents":
  1160. if (!this.get('content.isNotHeartBeating')) this.doStartAllComponents();
  1161. break;
  1162. case "stopAllComponents":
  1163. if (!this.get('content.isNotHeartBeating')) this.doStopAllComponents();
  1164. break;
  1165. case "restartAllComponents":
  1166. if (!this.get('content.isNotHeartBeating')) this.doRestartAllComponents();
  1167. break;
  1168. case "onOffPassiveModeForHost":
  1169. this.onOffPassiveModeForHost(option.context);
  1170. break;
  1171. default:
  1172. break;
  1173. }
  1174. },
  1175. /**
  1176. * Turn On/Off Passive Mode for host
  1177. * @param {object} context
  1178. * @method onOffPassiveModeForHost
  1179. */
  1180. onOffPassiveModeForHost: function (context) {
  1181. var state = context.active ? 'ON' : 'OFF';
  1182. var self = this;
  1183. var message = Em.I18n.t('hosts.host.details.for.postfix').format(context.label);
  1184. return App.showConfirmationPopup(function () {
  1185. self.hostPassiveModeRequest(state, message);
  1186. },
  1187. Em.I18n.t('hosts.passiveMode.popup').format(context.active ? 'On' : 'Off', this.get('content.hostName'))
  1188. );
  1189. },
  1190. /**
  1191. * Send request to get passive state for host
  1192. * @param {string} state
  1193. * @param {string} message
  1194. * @method hostPassiveModeRequest
  1195. */
  1196. hostPassiveModeRequest: function (state, message) {
  1197. App.ajax.send({
  1198. name: 'bulk_request.hosts.passive_state',
  1199. sender: this,
  1200. data: {
  1201. hostNames: this.get('content.hostName'),
  1202. passive_state: state,
  1203. requestInfo: message
  1204. },
  1205. success: 'updateHost'
  1206. });
  1207. },
  1208. /**
  1209. * Success callback for receiving host passive state
  1210. * @param {object} data
  1211. * @param {object} opt
  1212. * @param {object} params
  1213. * @method updateHost
  1214. */
  1215. updateHost: function (data, opt, params) {
  1216. this.set('content.passiveState', params.passive_state);
  1217. App.router.get('clusterController').loadUpdatedStatus(function () {
  1218. batchUtils.infoPassiveState(params.passive_state);
  1219. });
  1220. },
  1221. /**
  1222. * Show confirmation popup for action "start all components"
  1223. * @method doStartAllComponents
  1224. */
  1225. doStartAllComponents: function () {
  1226. var self = this;
  1227. var components = this.get('serviceNonClientActiveComponents');
  1228. var componentsLength = Em.isNone(components) ? 0 : components.get('length');
  1229. if (componentsLength > 0) {
  1230. return App.showConfirmationPopup(function () {
  1231. self.sendStartComponentCommand(components, Em.I18n.t('hosts.host.maintainance.startAllComponents.context'));
  1232. });
  1233. }
  1234. },
  1235. /**
  1236. * Show confirmation popup for action "stop all components"
  1237. * @method doStopAllComponents
  1238. */
  1239. doStopAllComponents: function () {
  1240. var self = this;
  1241. var components = this.get('serviceNonClientActiveComponents');
  1242. var componentsLength = Em.isNone(components) ? 0 : components.get('length');
  1243. if (componentsLength > 0) {
  1244. return App.showConfirmationPopup(function () {
  1245. self.sendStopComponentCommand(components, Em.I18n.t('hosts.host.maintainance.stopAllComponents.context'));
  1246. });
  1247. }
  1248. },
  1249. /**
  1250. * Show confirmation popup for action "restart all components"
  1251. * @method doRestartAllComponents
  1252. */
  1253. doRestartAllComponents: function () {
  1254. var self = this;
  1255. var components = this.get('serviceActiveComponents');
  1256. var componentsLength = Em.isNone(components) ? 0 : components.get('length');
  1257. if (componentsLength > 0) {
  1258. App.showConfirmationPopup(function () {
  1259. batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allOnSelectedHost').format(self.get('content.hostName')), "HOST");
  1260. });
  1261. }
  1262. },
  1263. /**
  1264. * get info about host-components, exactly:
  1265. * - host-components grouped by status, features
  1266. * - flag, that indicate whether ZooKeeper Server is installed
  1267. * @return {Object}
  1268. */
  1269. getHostComponentsInfo: function () {
  1270. var componentsOnHost = this.get('content.hostComponents');
  1271. var allComponents = App.HostComponent.find();
  1272. var stoppedStates = [App.HostComponentStatus.stopped,
  1273. App.HostComponentStatus.install_failed,
  1274. App.HostComponentStatus.upgrade_failed,
  1275. App.HostComponentStatus.init,
  1276. App.HostComponentStatus.unknown];
  1277. var container = {
  1278. zkServerInstalled: false,
  1279. lastComponents: [],
  1280. masterComponents: [],
  1281. runningComponents: [],
  1282. nonDeletableComponents: [],
  1283. unknownComponents: []
  1284. };
  1285. if (componentsOnHost && componentsOnHost.get('length') > 0) {
  1286. componentsOnHost.forEach(function (cInstance) {
  1287. if (cInstance.get('componentName') === 'ZOOKEEPER_SERVER') {
  1288. container.zkServerInstalled = true;
  1289. }
  1290. if (allComponents.filterProperty('componentName', cInstance.get('componentName')).get('length') === 1) {
  1291. container.lastComponents.push(cInstance.get('displayName'));
  1292. }
  1293. var workStatus = cInstance.get('workStatus');
  1294. if (cInstance.get('isMaster') && !cInstance.get('isDeletable')) {
  1295. container.masterComponents.push(cInstance.get('displayName'));
  1296. }
  1297. if (stoppedStates.indexOf(workStatus) < 0) {
  1298. container.runningComponents.push(cInstance.get('displayName'));
  1299. }
  1300. if (!cInstance.get('isDeletable')) {
  1301. container.nonDeletableComponents.push(cInstance.get('displayName'));
  1302. }
  1303. if (workStatus === App.HostComponentStatus.unknown) {
  1304. container.unknownComponents.push(cInstance.get('displayName'));
  1305. }
  1306. });
  1307. }
  1308. return container;
  1309. },
  1310. /**
  1311. * Deletion of hosts not supported for this version
  1312. * @method validateAndDeleteHost
  1313. */
  1314. validateAndDeleteHost: function () {
  1315. if (!App.supports.deleteHost) {
  1316. return false;
  1317. }
  1318. var container = this.getHostComponentsInfo();
  1319. if (container.masterComponents.length > 0) {
  1320. this.raiseDeleteComponentsError(container.masterComponents, 'masterList');
  1321. return;
  1322. } else if (container.nonDeletableComponents.length > 0) {
  1323. this.raiseDeleteComponentsError(container.nonDeletableComponents, 'nonDeletableList');
  1324. return;
  1325. } else if (container.runningComponents.length > 0) {
  1326. this.raiseDeleteComponentsError(container.runningComponents, 'runningList');
  1327. return;
  1328. }
  1329. if (container.zkServerInstalled) {
  1330. var self = this;
  1331. return App.showConfirmationPopup(function () {
  1332. self._doDeleteHost(container.unknownComponents, container.lastComponents);
  1333. }, Em.I18n.t('hosts.host.addComponent.deleteHostWithZooKeeper'));
  1334. } else {
  1335. this._doDeleteHost(container.unknownComponents, container.lastComponents);
  1336. }
  1337. },
  1338. /**
  1339. * Show popup with info about reasons why host can't be deleted
  1340. * @param {string[]} components
  1341. * @param {string} type
  1342. * @method raiseDeleteComponentsError
  1343. */
  1344. raiseDeleteComponentsError: function (components, type) {
  1345. App.ModalPopup.show({
  1346. header: Em.I18n.t('hosts.cant.do.popup.title'),
  1347. type: type,
  1348. showBodyEnd: function () {
  1349. return this.get('type') === 'runningList' || this.get('type') === 'masterList';
  1350. }.property(),
  1351. components: components,
  1352. componentsStr: function () {
  1353. return this.get('components').join(", ");
  1354. }.property(),
  1355. componentsBody: function () {
  1356. return Em.I18n.t('hosts.cant.do.popup.' + type + '.body').format(this.get('components').length);
  1357. }.property(),
  1358. componentsBodyEnd: function () {
  1359. if (this.get('showBodyEnd')) {
  1360. return Em.I18n.t('hosts.cant.do.popup.' + type + '.body.end');
  1361. }
  1362. return '';
  1363. }.property(),
  1364. bodyClass: Em.View.extend({
  1365. templateName: require('templates/main/host/details/raiseDeleteComponentErrorPopup')
  1366. }),
  1367. secondary: null
  1368. })
  1369. },
  1370. /**
  1371. * Show confirmation popup to delete host
  1372. * @param {string[]} unknownComponents
  1373. * @param {string[]} lastComponents
  1374. * @method _doDeleteHost
  1375. */
  1376. _doDeleteHost: function (unknownComponents, lastComponents) {
  1377. var self = this;
  1378. App.ModalPopup.show({
  1379. header: Em.I18n.t('hosts.delete.popup.title'),
  1380. deletePopupBody: function () {
  1381. return Em.I18n.t('hosts.delete.popup.body').format(self.get('content.publicHostName'));
  1382. }.property(),
  1383. lastComponent: function () {
  1384. if (lastComponents && lastComponents.length) {
  1385. this.set('isChecked', false);
  1386. return true;
  1387. } else {
  1388. this.set('isChecked', true);
  1389. return false;
  1390. }
  1391. }.property(),
  1392. disablePrimary: function () {
  1393. return !this.get('isChecked');
  1394. }.property('isChecked'),
  1395. isChecked: false,
  1396. lastComponentError: Em.View.extend({
  1397. template: Em.Handlebars.compile(Em.I18n.t('hosts.delete.popup.body.msg4').format(lastComponents))
  1398. }),
  1399. unknownComponents: function () {
  1400. if (unknownComponents && unknownComponents.length) {
  1401. return unknownComponents.join(", ");
  1402. }
  1403. return '';
  1404. }.property(),
  1405. bodyClass: Em.View.extend({
  1406. templateName: require('templates/main/host/details/doDeleteHostPopup')
  1407. }),
  1408. onPrimary: function () {
  1409. self.set('fromDeleteHost', true);
  1410. var allComponents = self.get('content.hostComponents');
  1411. var deleteError = null;
  1412. allComponents.forEach(function (component) {
  1413. if (!deleteError) {
  1414. deleteError = self._doDeleteHostComponent(component);
  1415. }
  1416. });
  1417. if (!deleteError) {
  1418. App.ajax.send({
  1419. name: 'host.delete',
  1420. sender: this,
  1421. data: {
  1422. hostName: self.get('content.hostName')
  1423. },
  1424. success: 'deleteHostSuccessCallback',
  1425. error: 'deleteHostErrorCallback'
  1426. });
  1427. }
  1428. else {
  1429. this.hide();
  1430. deleteError.xhr.responseText = "{\"message\": \"" + deleteError.xhr.statusText + "\"}";
  1431. App.ajax.defaultErrorHandler(deleteError.xhr, deleteError.url, deleteError.method, deleteError.xhr.status);
  1432. }
  1433. },
  1434. deleteHostSuccessCallback: function (data) {
  1435. var dialogSelf = this;
  1436. App.router.get('updateController').updateHost(function () {
  1437. self.loadConfigs();
  1438. dialogSelf.hide();
  1439. App.router.transitionTo('hosts.index');
  1440. });
  1441. },
  1442. deleteHostErrorCallback: function (xhr, textStatus, errorThrown, opt) {
  1443. console.log('Error deleting host.');
  1444. console.log(textStatus);
  1445. console.log(errorThrown);
  1446. xhr.responseText = "{\"message\": \"" + xhr.statusText + "\"}";
  1447. self.loadConfigs();
  1448. this.hide();
  1449. App.ajax.defaultErrorHandler(xhr, opt.url, 'DELETE', xhr.status);
  1450. }
  1451. })
  1452. },
  1453. /**
  1454. * Send command to server to restart all host components with stale configs
  1455. * @method restartAllStaleConfigComponents
  1456. */
  1457. restartAllStaleConfigComponents: function () {
  1458. var self = this;
  1459. return App.showConfirmationPopup(function () {
  1460. var staleComponents = self.get('content.componentsWithStaleConfigs');
  1461. batchUtils.restartHostComponents(staleComponents, Em.I18n.t('rollingrestart.context.allWithStaleConfigsOnSelectedHost').format(self.get('content.hostName')), "HOST");
  1462. });
  1463. },
  1464. /**
  1465. * open Reassign Master Wizard with selected component
  1466. * @param {object} event
  1467. * @method moveComponent
  1468. */
  1469. moveComponent: function (event) {
  1470. App.showConfirmationPopup(function () {
  1471. var component = event.context;
  1472. var reassignMasterController = App.router.get('reassignMasterController');
  1473. reassignMasterController.saveComponentToReassign(component);
  1474. reassignMasterController.getSecurityStatus();
  1475. reassignMasterController.setCurrentStep('1');
  1476. App.router.transitionTo('reassign');
  1477. });
  1478. },
  1479. /**
  1480. * Restart clients host components to apply config changes
  1481. * @param {object} event
  1482. * @method refreshConfigs
  1483. */
  1484. refreshConfigs: function (event) {
  1485. var self = this;
  1486. var components = event.context.filter(function (component) {
  1487. return component.get('staleConfigs');
  1488. });
  1489. if (components.get('length') > 0) {
  1490. return App.showConfirmationPopup(function () {
  1491. batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allClientsOnSelectedHost').format(self.get('content.hostName')), "HOST");
  1492. });
  1493. }
  1494. }
  1495. });