details.js 58 KB

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