details.js 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257
  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 hostsManagement = require('utils/hosts');
  22. var stringUtils = require('utils/string_utils');
  23. App.MainHostDetailsController = Em.Controller.extend({
  24. name: 'mainHostDetailsController',
  25. /**
  26. * Viewed host
  27. * @type {App.Host|null}
  28. */
  29. content: null,
  30. /**
  31. * Does user come from hosts page
  32. * @type {bool}
  33. */
  34. isFromHosts: false,
  35. /**
  36. * path to page visited before
  37. * @type {string}
  38. */
  39. referer: '',
  40. /**
  41. * Host on which Hive Metastore will be added
  42. * @type {string}
  43. */
  44. hiveMetastoreHost: '',
  45. /**
  46. * Deferred object will be resolved when Oozie configs are downloaded
  47. * @type {object}
  48. */
  49. isOozieConfigLoaded: $.Deferred(),
  50. /**
  51. * @type {bool}
  52. */
  53. isOozieServerAddable: true,
  54. /**
  55. * Open dashboard page
  56. * @method routeHome
  57. */
  58. routeHome: function () {
  59. App.router.transitionTo('main.dashboard.index');
  60. },
  61. /**
  62. * List of active (not in passive state) host components
  63. * @type {Ember.Enumerable}
  64. */
  65. serviceActiveComponents: function () {
  66. return this.get('content.hostComponents').filterProperty('service.isInPassive', false);
  67. }.property('content.hostComponents'),
  68. /**
  69. * List of active host components which aren't clients
  70. * @type {Ember.Enumerable}
  71. */
  72. serviceNonClientActiveComponents: function () {
  73. return this.get('serviceActiveComponents').filterProperty('isClient', false);
  74. }.property('serviceActiveComponents'),
  75. /**
  76. * send command to server to start selected host component
  77. * @param {object} event
  78. * @method startComponent
  79. */
  80. startComponent: function (event) {
  81. var self = this;
  82. return App.showConfirmationPopup(function () {
  83. var component = event.context;
  84. var context = Em.I18n.t('requestInfo.startHostComponent') + " " + component.get('displayName');
  85. self.sendComponentCommand(component, context, App.HostComponentStatus.started);
  86. });
  87. },
  88. /**
  89. * send command to server to stop selected host component
  90. * @param {object} event
  91. * @method startComponent
  92. */
  93. stopComponent: function (event) {
  94. var self = this;
  95. return App.showConfirmationPopup(function () {
  96. var component = event.context;
  97. var context = Em.I18n.t('requestInfo.stopHostComponent') + " " + component.get('displayName');
  98. self.sendComponentCommand(component, context, App.HostComponentStatus.stopped);
  99. });
  100. },
  101. /**
  102. * PUTs a command to server to start/stop a component. If no
  103. * specific component is provided, all components are started.
  104. * @param {object} component When <code>null</code> all startable components are started.
  105. * @param {String} context Context under which this command is beign sent.
  106. * @param {String} state - desired state of component can be 'STARTED' or 'STOPPED'
  107. * @method sendComponentCommand
  108. */
  109. sendComponentCommand: function (component, context, state) {
  110. var data = {
  111. hostName: this.get('content.hostName'),
  112. context: context,
  113. component: component,
  114. HostRoles: {
  115. state: state
  116. }
  117. };
  118. if (Array.isArray(component)) {
  119. data.query = "HostRoles/component_name.in(" + component.mapProperty('componentName').join(',') + ")";
  120. } else {
  121. data.componentName = component.get('componentName');
  122. data.serviceName = component.get('service.serviceName');
  123. }
  124. App.ajax.send({
  125. name: (Array.isArray(component)) ? 'common.host.host_components.update' : 'common.host.host_component.update',
  126. sender: this,
  127. data: data,
  128. success: 'sendComponentCommandSuccessCallback',
  129. error: 'ajaxErrorCallback'
  130. });
  131. },
  132. /**
  133. * Success callback for stop/start host component request
  134. * @param {object} data
  135. * @param {object} opt
  136. * @param {object} params
  137. * @method stopComponentSuccessCallback
  138. */
  139. sendComponentCommandSuccessCallback: function (data, opt, params) {
  140. var running = (params.HostRoles.state === App.HostComponentStatus.stopped) ? App.HostComponentStatus.stopping : App.HostComponentStatus.starting;
  141. console.log('Send request for ' + running + ' successfully');
  142. params.component.set('workStatus', running);
  143. if (App.get('testMode')) {
  144. this.mimicWorkStatusChange(params.component, running, params.HostRoles.state);
  145. }
  146. this.showBackgroundOperationsPopup();
  147. },
  148. /**
  149. * Default error-callback for ajax-requests in current page
  150. * @param {object} request
  151. * @param {object} ajaxOptions
  152. * @param {string} error
  153. * @param {object} opt
  154. * @param {object} params
  155. * @method ajaxErrorCallback
  156. */
  157. ajaxErrorCallback: function (request, ajaxOptions, error, opt, params) {
  158. return componentsUtils.ajaxErrorCallback(request, ajaxOptions, error, opt, params);
  159. },
  160. /**
  161. * mimic status transition in test mode
  162. * @param entity
  163. * @param transitionalState
  164. * @param finalState
  165. */
  166. mimicWorkStatusChange: function (entity, transitionalState, finalState) {
  167. if (Em.isArray(entity)) {
  168. entity.forEach(function (item) {
  169. item.set('workStatus', transitionalState);
  170. setTimeout(function () {
  171. item.set('workStatus', finalState);
  172. }, App.testModeDelayForActions);
  173. });
  174. } else {
  175. entity.set('workStatus', transitionalState);
  176. setTimeout(function () {
  177. entity.set('workStatus', finalState);
  178. }, App.testModeDelayForActions);
  179. }
  180. },
  181. /**
  182. * load data (if we need to show this background operations popup) from persist
  183. * @param callback
  184. */
  185. showBackgroundOperationsPopup: function (callback) {
  186. App.router.get('applicationController').dataLoading().done(function (initValue) {
  187. if (initValue) {
  188. App.router.get('backgroundOperationsController').showPopup();
  189. }
  190. if (typeof callback === 'function') {
  191. callback();
  192. }
  193. });
  194. },
  195. /**
  196. * Send command to server to delete selected host component
  197. * @param {object} event
  198. * @method deleteComponent
  199. */
  200. deleteComponent: function (event) {
  201. var self = this;
  202. var component = event.context;
  203. var componentName = component.get('componentName');
  204. var displayName = component.get('displayName');
  205. var isLastComponent = (this.getTotalComponent(component) === 1);
  206. return App.ModalPopup.show({
  207. header: Em.I18n.t('popup.confirmation.commonHeader'),
  208. primary: Em.I18n.t('hosts.host.deleteComponent.popup.confirm'),
  209. bodyClass: Em.View.extend({
  210. templateName: require('templates/main/host/details/deleteComponentPopup')
  211. }),
  212. isHiveMetastore: function () {
  213. return componentName == 'HIVE_METASTORE';
  214. }.property(),
  215. deleteHiveMetastoreMsg: Em.View.extend({
  216. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.deleteComponent.popup.deleteHiveMetastore'))
  217. }),
  218. isNimbus: function () {
  219. return componentName == 'NIMBUS';
  220. }.property(),
  221. deleteNimbusMsg: Em.View.extend({
  222. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.deleteComponent.popup.deleteNimbus'))
  223. }),
  224. isRangerKMSServer: function () {
  225. return componentName == 'RANGER_KMS_SERVER';
  226. }.property(),
  227. deleteRangerKMSServereMsg: Em.View.extend({
  228. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.deleteComponent.popup.deleteRangerKMSServer'))
  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. isZkServer: function () {
  239. return componentName == 'ZOOKEEPER_SERVER';
  240. }.property(),
  241. lastComponentError: Em.View.extend({
  242. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.deleteComponent.popup.warning').format(displayName))
  243. }),
  244. deleteComponentMsg: function () {
  245. return Em.I18n.t('hosts.host.deleteComponent.popup.msg1').format(displayName);
  246. }.property(),
  247. deleteZkServerMsg: Em.View.extend({
  248. template: Em.Handlebars.compile(Em.I18n.t('hosts.host.deleteComponent.popup.deleteZooKeeperServer'))
  249. }),
  250. onPrimary: function () {
  251. var popup = this;
  252. self._doDeleteHostComponent(component, function () {
  253. self.set('redrawComponents', true);
  254. popup.hide();
  255. });
  256. }
  257. });
  258. },
  259. /**
  260. * get total count of host-components
  261. * @method getTotalComponent
  262. * @param component
  263. * @return {Number}
  264. */
  265. getTotalComponent: function (component) {
  266. var count;
  267. if (component.get('isSlave')) {
  268. count = App.SlaveComponent.find(component.get('componentName')).get('totalCount');
  269. } else if (component.get('isClient')) {
  270. count = App.ClientComponent.find(component.get('componentName')).get('totalCount');
  271. } else {
  272. count = App.HostComponent.find().filterProperty('componentName', component.get('componentName')).get('length');
  273. }
  274. return count || 0;
  275. },
  276. /**
  277. * Trigger to reset list of master/slaves components on the view
  278. * @type {bool}
  279. */
  280. redrawComponents: false,
  281. /**
  282. * Deletes the given host component, or all host components.
  283. *
  284. * @param {object|null} component When <code>null</code> all host components are deleted.
  285. * @return <code>null</code> when components get deleted.
  286. * <code>{xhr: XhrObj, url: "http://", method: "DELETE"}</code>
  287. * when components failed to get deleted.
  288. * @method _doDeleteHostComponent
  289. */
  290. _doDeleteHostComponent: function (component, callback) {
  291. callback = callback || Em.K;
  292. App.ajax.send({
  293. name: (Em.isNone(component)) ? 'common.delete.host' : 'common.delete.host_component',
  294. sender: this,
  295. data: {
  296. componentName: (component) ? component.get('componentName') : '',
  297. hostName: this.get('content.hostName')
  298. },
  299. success: '_doDeleteHostComponentSuccessCallback',
  300. error: '_doDeleteHostComponentErrorCallback'
  301. }).then(callback, callback);
  302. },
  303. /**
  304. * Result of delete component(s) request
  305. * @type {object}
  306. */
  307. _deletedHostComponentResult: null,
  308. /**
  309. * Success callback for delete host component request
  310. * @method _doDeleteHostComponentSuccessCallback
  311. */
  312. _doDeleteHostComponentSuccessCallback: function (response, request, data) {
  313. this.set('_deletedHostComponentResult', null);
  314. this.removeHostComponentModel(data.componentName, data.hostName);
  315. if (data.componentName == 'ZOOKEEPER_SERVER') {
  316. this.set('fromDeleteZkServer', true);
  317. this.loadConfigs();
  318. } else if (data.componentName == 'HIVE_METASTORE') {
  319. this.set('deleteHiveMetaStore', true);
  320. this.loadConfigs('loadHiveConfigs');
  321. } else if(data.componentName == 'NIMBUS') {
  322. this.set('deleteNimbusHost', true);
  323. this.loadConfigs('loadStormConfigs');
  324. } else if(data.componentName == 'RANGER_KMS_SERVER') {
  325. this.set('deleteRangerKMSServer', true);
  326. this.loadConfigs('loadRangerConfigs');
  327. }
  328. },
  329. /**
  330. * Error-callback for delete host component request
  331. * @param {object} xhr
  332. * @param {string} textStatus
  333. * @param {object} errorThrown
  334. * @method _doDeleteHostComponentErrorCallback
  335. */
  336. _doDeleteHostComponentErrorCallback: function (xhr, textStatus, errorThrown, data) {
  337. console.log('Error deleting host component');
  338. console.log(textStatus);
  339. console.log(errorThrown);
  340. this.set('_deletedHostComponentResult', {xhr: xhr, url: data.url, method: 'DELETE'});
  341. },
  342. /**
  343. * Remove host component data from App.HostComponent model.
  344. *
  345. * @param {String} componentName
  346. * @param {String} hostName
  347. */
  348. removeHostComponentModel: function(componentName, hostName) {
  349. var component = App.HostComponent.find().filterProperty('componentName', componentName).findProperty('hostName', hostName);
  350. App.serviceMapper.deleteRecord(component);
  351. },
  352. /**
  353. * Send command to server to upgrade selected host component
  354. * @param {object} event
  355. * @method upgradeComponent
  356. */
  357. upgradeComponent: function (event) {
  358. var self = this;
  359. var component = event.context;
  360. return App.showConfirmationPopup(function () {
  361. App.ajax.send({
  362. name: 'host.host_component.upgrade',
  363. sender: self,
  364. data: {
  365. component: component,
  366. hostName: self.get('content.hostName'),
  367. componentName: component.get('componentName'),
  368. data: JSON.stringify({
  369. RequestInfo: {
  370. "context": Em.I18n.t('requestInfo.upgradeHostComponent') + " " + component.get('displayName')
  371. },
  372. Body: {
  373. HostRoles: {
  374. stack_id: 'HDP-1.2.2',
  375. state: 'INSTALLED'
  376. }
  377. }
  378. })
  379. },
  380. success: 'upgradeComponentSuccessCallback',
  381. error: 'ajaxErrorCallback'
  382. });
  383. });
  384. },
  385. /**
  386. * Success callback for upgrade host component request
  387. * @param {object} data
  388. * @param {object} opt
  389. * @param {object} params
  390. * @method upgradeComponentSuccessCallback
  391. */
  392. upgradeComponentSuccessCallback: function (data, opt, params) {
  393. console.log('Send request for UPGRADE successfully');
  394. if (App.get('testMode')) {
  395. this.mimicWorkStatusChange(params.component, App.HostComponentStatus.starting, App.HostComponentStatus.started);
  396. }
  397. this.showBackgroundOperationsPopup();
  398. },
  399. /**
  400. * Send command to server to restart selected components
  401. * @param {object} event
  402. * @method restartComponent
  403. */
  404. restartComponent: function (event) {
  405. var component = event.context;
  406. return App.showConfirmationPopup(function () {
  407. batchUtils.restartHostComponents([component], Em.I18n.t('rollingrestart.context.selectedComponentOnSelectedHost').format(component.get('displayName')), "HOST_COMPONENT");
  408. });
  409. },
  410. /**
  411. * get current status of security settings,
  412. * if true security is enabled otherwise disabled
  413. * @return {Boolean}
  414. */
  415. securityEnabled: function () {
  416. return App.router.get('mainAdminSecurityController.securityEnabled');
  417. }.property('App.router.mainAdminSecurityController.securityEnabled'),
  418. /**
  419. * add component as <code>addComponent<code> method but perform
  420. * kdc sessionstate if cluster is secure;
  421. * @param event
  422. */
  423. addComponentWithCheck: function (event) {
  424. var componentName = event.context ? event.context.get('componentName') : "";
  425. event.hiveMetastoreHost = (componentName == "HIVE_METASTORE" && !!this.get('content.hostName')) ? this.get('content.hostName') : null;
  426. App.get('router.mainAdminKerberosController').getKDCSessionState(this.addComponent.bind(this, event));
  427. },
  428. /**
  429. * Send command to server to install selected host component
  430. * @param {object} event
  431. * @method addComponent
  432. */
  433. addComponent: function (event) {
  434. var
  435. returnFunc,
  436. self = this,
  437. component = event.context,
  438. hostName = event.selectedHost || this.get('content.hostName'),
  439. componentName = component.get('componentName'),
  440. missedComponents = event.selectedHost ? [] : componentsUtils.checkComponentDependencies(componentName, {
  441. scope: 'host',
  442. installedComponents: this.get('content.hostComponents').mapProperty('componentName')
  443. });
  444. if (!!missedComponents.length) {
  445. var popupMessage = Em.I18n.t('host.host.addComponent.popup.dependedComponents.body').format(component.get('displayName'),
  446. stringUtils.getFormattedStringFromArray(missedComponents.map(function(cName) {
  447. return App.StackServiceComponent.find(cName).get('displayName');
  448. })));
  449. return App.showAlertPopup(Em.I18n.t('host.host.addComponent.popup.dependedComponents.header'), popupMessage);
  450. }
  451. switch (componentName) {
  452. case 'ZOOKEEPER_SERVER':
  453. returnFunc = App.showConfirmationPopup(function () {
  454. self.primary(component);
  455. }, Em.I18n.t('hosts.host.addComponent.' + componentName ));
  456. break;
  457. case 'HIVE_METASTORE':
  458. returnFunc = App.showConfirmationPopup(function () {
  459. self.set('hiveMetastoreHost', hostName);
  460. self.loadConfigs("loadHiveConfigs");
  461. }, Em.I18n.t('hosts.host.addComponent.' + componentName ));
  462. break;
  463. case 'NIMBUS':
  464. returnFunc = App.showConfirmationPopup(function() {
  465. self.set('nimbusHost', hostName);
  466. self.loadConfigs("loadStormConfigs");
  467. }, Em.I18n.t('hosts.host.addComponent.' + componentName));
  468. break;
  469. case 'RANGER_KMS_SERVER':
  470. returnFunc = App.showConfirmationPopup(function() {
  471. self.set('rangerKMSServerHost', hostName);
  472. self.loadConfigs("loadRangerConfigs");
  473. }, Em.I18n.t('hosts.host.addComponent.' + componentName));
  474. break;
  475. default:
  476. returnFunc = this.addClientComponent(component);
  477. }
  478. return returnFunc;
  479. },
  480. /**
  481. * Send command to server to install client on selected host
  482. * @param component
  483. */
  484. addClientComponent: function (component) {
  485. var self = this;
  486. var message = this.formatClientsMessage(component);
  487. return this.showAddComponentPopup(message, function () {
  488. self.primary(component);
  489. });
  490. },
  491. showAddComponentPopup: function (message, primary) {
  492. return App.ModalPopup.show({
  493. primary: Em.I18n.t('hosts.host.addComponent.popup.confirm'),
  494. header: Em.I18n.t('popup.confirmation.commonHeader'),
  495. addComponentMsg: function () {
  496. return Em.I18n.t('hosts.host.addComponent.msg').format(message);
  497. }.property(),
  498. bodyClass: Em.View.extend({
  499. templateName: require('templates/main/host/details/addComponentPopup')
  500. }),
  501. onPrimary: function () {
  502. this.hide();
  503. primary();
  504. }
  505. });
  506. },
  507. /**
  508. * format message for operation of adding clients
  509. * @param client
  510. */
  511. formatClientsMessage: function (client) {
  512. var displayName = Em.isNone(client.get('displayName')) ? '' : client.get('displayName');
  513. var subComponentNames = client.get('subComponentNames');
  514. if (subComponentNames && subComponentNames.length > 0) {
  515. var dns = [];
  516. subComponentNames.forEach(function (scn) {
  517. dns.push(App.format.role(scn));
  518. });
  519. displayName += " (" + dns.join(", ") + ")";
  520. }
  521. return displayName;
  522. },
  523. /**
  524. * Send request to add host component
  525. * @param {App.HostComponent} component
  526. * @method primary
  527. */
  528. primary: function (component) {
  529. var self = this;
  530. componentsUtils.installHostComponent(self.get('content.hostName'), component);
  531. },
  532. /**
  533. * Success callback for install host component request (sent in <code>addNewComponentSuccessCallback</code>)
  534. * @param {object} data
  535. * @param {object} opt
  536. * @param {object} params
  537. * @method installNewComponentSuccessCallbƒack
  538. */
  539. installNewComponentSuccessCallback: function (data, opt, params) {
  540. if (!data || !data.Requests || !data.Requests.id) {
  541. return false;
  542. }
  543. var self = this;
  544. console.log('Send request for INSTALLING NEW COMPONENT successfully');
  545. if (App.get('testMode')) {
  546. this.mimicWorkStatusChange(params.component, App.HostComponentStatus.installing, App.HostComponentStatus.stopped);
  547. }
  548. this.showBackgroundOperationsPopup(function () {
  549. if (params.componentName === 'ZOOKEEPER_SERVER' || params.componentName === 'HIVE_SERVER') {
  550. self.set(params.componentName === 'ZOOKEEPER_SERVER' ? 'zkRequestId' : 'hiveRequestId', data.Requests.id);
  551. self.addObserver(
  552. 'App.router.backgroundOperationsController.serviceTimestamp',
  553. self,
  554. (params.componentName === 'ZOOKEEPER_SERVER' ? self.checkZkConfigs : self.checkHiveDone)
  555. );
  556. params.componentName === 'ZOOKEEPER_SERVER' ? self.checkZkConfigs() : self.checkHiveDone();
  557. }
  558. });
  559. return true;
  560. },
  561. /**
  562. * Call <code>setRackInfo</code> function to show Set Rack Id popup
  563. * @param data
  564. */
  565. setRackId: function (data) {
  566. var rack = data.context.get('rack');
  567. var hosts = [data.context];
  568. var operationData = {message: Em.I18n.t('hosts.host.details.setRackId')};
  569. hostsManagement.setRackInfo(operationData, hosts, rack);
  570. },
  571. /**
  572. * Call load tags
  573. * @method checkHiveDone
  574. */
  575. checkHiveDone: function () {
  576. var bg = App.router.get('backgroundOperationsController.services').findProperty('id', this.get('hiveRequestId'));
  577. if (bg && !bg.get('isRunning')) {
  578. var self = this;
  579. this.removeObserver('App.router.backgroundOperationsController.serviceTimestamp', this, this.checkHiveDone);
  580. setTimeout(function () {
  581. self.loadConfigs("loadHiveConfigs");
  582. }, App.get('componentsUpdateInterval'));
  583. }
  584. },
  585. /**
  586. * Success callback for load configs request
  587. * @param {object} data
  588. * @method loadOozieConfigs
  589. */
  590. loadOozieConfigs: function (data) {
  591. return App.ajax.send({
  592. name: 'admin.get.all_configurations',
  593. sender: this,
  594. data: {
  595. urlParams: '(type=oozie-env&tag=' + data.Clusters.desired_configs['oozie-env'].tag + ')'
  596. },
  597. success: 'onLoadOozieConfigs',
  598. error: 'onLoadConfigsErrorCallback'
  599. });
  600. },
  601. /**
  602. * get Oozie database config and set databaseType
  603. * @param {object} data
  604. * @method onLoadHiveConfigs
  605. */
  606. onLoadOozieConfigs: function (data) {
  607. var configs = {};
  608. data.items.forEach(function(item) {
  609. $.extend(configs, item.properties);
  610. });
  611. this.set('isOozieServerAddable', !(Em.isEmpty(configs["oozie_database"]) || configs["oozie_database"] === 'New Derby Database'));
  612. this.get('isOozieConfigLoaded').resolve();
  613. },
  614. /**
  615. * Success callback for Storm load configs request
  616. * @param {object} data
  617. * @method loadStormConfigs
  618. */
  619. loadStormConfigs: function (data) {
  620. App.ajax.send({
  621. name: 'admin.get.all_configurations',
  622. sender: this,
  623. data: {
  624. urlParams: '(type=storm-site&tag=' + data.Clusters.desired_configs['storm-env'].tag +')'
  625. },
  626. success: 'onLoadStormConfigs'
  627. });
  628. },
  629. /**
  630. * update and save Storm related configs to server
  631. * @param {object} data
  632. * @method onLoadStormConfigs
  633. */
  634. onLoadStormConfigs: function (data) {
  635. var
  636. nimbusHost = this.get('nimbusHost'),
  637. stormNimbusHosts = this.getStormNimbusHosts(),
  638. configs = {},
  639. attributes = {};
  640. data.items.forEach(function (item) {
  641. configs[item.type] = item.properties;
  642. attributes[item.type] = item.properties_attributes || {};
  643. }, this);
  644. configs['storm-site']['nimbus.seeds'] = stormNimbusHosts.join(',');
  645. var groups = [
  646. {
  647. properties: {
  648. 'storm-site': configs['storm-site'],
  649. 'storm-env': configs['storm-env']
  650. },
  651. properties_attributes: {
  652. 'storm-site': attributes['storm-site'],
  653. 'storm-env': attributes['storm-env']
  654. }
  655. },
  656. {
  657. properties: {
  658. 'core-site': configs['core-site']
  659. },
  660. properties_attributes: {
  661. 'core-site': attributes['core-site']
  662. }
  663. }
  664. ];
  665. this.saveConfigsBatch(groups, 'NIMBUS', nimbusHost);
  666. },
  667. /**
  668. * Success callback for load configs request
  669. * @param {object} data
  670. * @method loadHiveConfigs
  671. */
  672. loadHiveConfigs: function (data) {
  673. App.ajax.send({
  674. name: 'admin.get.all_configurations',
  675. sender: this,
  676. data: {
  677. urlParams: '(type=hive-site&tag=' + data.Clusters.desired_configs['hive-site'].tag + ')|(type=webhcat-site&tag=' +
  678. data.Clusters.desired_configs['webhcat-site'].tag + ')|(type=hive-env&tag=' + data.Clusters.desired_configs['hive-env'].tag +
  679. ')|(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')'
  680. },
  681. success: 'onLoadHiveConfigs'
  682. });
  683. },
  684. /**
  685. * update and save Hive related configs to server
  686. * @param {object} data
  687. * @method onLoadHiveConfigs
  688. */
  689. onLoadHiveConfigs: function (data) {
  690. var
  691. hiveMetastoreHost = this.get('hiveMetastoreHost'),
  692. hiveMSHosts = this.getHiveHosts(),
  693. hiveMasterHosts = hiveMSHosts.concat(App.HostComponent.find().filterProperty('componentName', 'HIVE_SERVER').mapProperty('hostName')).uniq().sort().join(','),
  694. configs = {},
  695. attributes = {},
  696. port = "",
  697. hiveUser = "",
  698. webhcatUser = "";
  699. data.items.forEach(function (item) {
  700. configs[item.type] = item.properties;
  701. attributes[item.type] = item.properties_attributes || {};
  702. }, this);
  703. port = configs['hive-site']['hive.metastore.uris'].match(/:[0-9]{2,4}/);
  704. port = port ? port[0].slice(1) : "9083";
  705. hiveUser = configs['hive-env']['hive_user'];
  706. webhcatUser = configs['hive-env']['webhcat_user'];
  707. for (var i = 0; i < hiveMSHosts.length; i++) {
  708. hiveMSHosts[i] = "thrift://" + hiveMSHosts[i] + ":" + port;
  709. }
  710. configs['hive-site']['hive.metastore.uris'] = hiveMSHosts.join(',');
  711. configs['webhcat-site']['templeton.hive.properties'] = configs['webhcat-site']['templeton.hive.properties'].replace(/thrift.+[0-9]{2,},/i, hiveMSHosts.join('\\,') + ",");
  712. configs['core-site']['hadoop.proxyuser.' + hiveUser + '.hosts'] = hiveMasterHosts;
  713. configs['core-site']['hadoop.proxyuser.' + webhcatUser + '.hosts'] = hiveMasterHosts;
  714. var groups = [
  715. {
  716. properties: {
  717. 'hive-site': configs['hive-site'],
  718. 'webhcat-site': configs['webhcat-site'],
  719. 'hive-env': configs['hive-env']
  720. },
  721. properties_attributes: {
  722. 'hive-site': attributes['hive-site'],
  723. 'webhcat-site': attributes['webhcat-site'],
  724. 'hive-env': attributes['hive-env']
  725. }
  726. },
  727. {
  728. properties: {
  729. 'core-site': configs['core-site']
  730. },
  731. properties_attributes: {
  732. 'core-site': attributes['core-site']
  733. }
  734. }
  735. ];
  736. this.saveConfigsBatch(groups, 'HIVE_METASTORE', hiveMetastoreHost);
  737. },
  738. /**
  739. * save configs' sites in batch
  740. * @param host
  741. * @param groups
  742. */
  743. saveConfigsBatch: function (groups, componentName, host) {
  744. groups.forEach(function (group) {
  745. var desiredConfigs = [],
  746. tag = 'version' + (new Date).getTime(),
  747. properties = group.properties;
  748. for (var site in properties) {
  749. if (!properties.hasOwnProperty(site) || Em.isNone(properties[site])) continue;
  750. desiredConfigs.push({
  751. "type": site,
  752. "tag": tag,
  753. "properties": properties[site],
  754. "properties_attributes": group.properties_attributes[site],
  755. "service_config_version_note": Em.I18n.t('hosts.host.configs.save.note').format(App.format.role(componentName))
  756. });
  757. }
  758. if (desiredConfigs.length > 0) {
  759. App.ajax.send({
  760. name: 'common.service.configurations',
  761. sender: this,
  762. data: {
  763. desired_config: desiredConfigs,
  764. componentName: componentName,
  765. host: host
  766. },
  767. success: 'installHostComponent'
  768. });
  769. }
  770. //clear hive metastore host not to send second request to install component
  771. host = null;
  772. }, this);
  773. },
  774. /**
  775. * success callback for saveConfigsBatch method
  776. * @param data
  777. * @param opt
  778. * @param params
  779. */
  780. installHostComponent: function(data, opt, params) {
  781. if (params.host) {
  782. componentsUtils.installHostComponent(params.host, App.StackServiceComponent.find(params.componentName));
  783. }
  784. },
  785. /**
  786. * Delete Hive Metastore is performed
  787. * @type {bool}
  788. */
  789. deleteHiveMetaStore: false,
  790. getHiveHosts: function () {
  791. var
  792. hiveHosts = App.HostComponent.find().filterProperty('componentName', 'HIVE_METASTORE').mapProperty('hostName'),
  793. hiveMetastoreHost = this.get('hiveMetastoreHost');
  794. if(!!hiveMetastoreHost){
  795. hiveHosts.push(hiveMetastoreHost);
  796. this.set('hiveMetastoreHost', '');
  797. }
  798. if (this.get('fromDeleteHost') || this.get('deleteHiveMetaStore')) {
  799. this.set('deleteHiveMetaStore', false);
  800. this.set('fromDeleteHost', false);
  801. return hiveHosts.without(this.get('content.hostName'));
  802. }
  803. return hiveHosts.sort();
  804. },
  805. /**
  806. * Success callback for load configs request
  807. * @param {object} data
  808. * @method loadHiveConfigs
  809. */
  810. loadRangerConfigs: function (data) {
  811. App.ajax.send({
  812. name: 'admin.get.all_configurations',
  813. sender: this,
  814. data: {
  815. urlParams: '(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')|(type=hdfs-site&tag=' + data.Clusters.desired_configs['hdfs-site'].tag + ')|(type=kms-env&tag=' + data.Clusters.desired_configs['kms-env'].tag + ')'
  816. },
  817. success: 'onLoadRangerConfigs'
  818. });
  819. },
  820. /**
  821. * update and save Hive hive.metastore.uris config to server
  822. * @param {object} data
  823. * @method onLoadHiveConfigs
  824. */
  825. onLoadRangerConfigs: function (data) {
  826. var hostToInstall = this.get('rangerKMSServerHost');
  827. var rkmsHosts = this.getRangerKMSServerHosts();
  828. var rkmsPort = data.items.findProperty('type', 'kms-env').properties['kms_port'];
  829. var coreSiteConfigs = data.items.findProperty('type', 'core-site');
  830. var hdfsSiteConfigs = data.items.findProperty('type', 'core-site');
  831. var groups = [
  832. {
  833. properties: {
  834. 'core-site': coreSiteConfigs.properties,
  835. 'hdfs-site': hdfsSiteConfigs.properties
  836. },
  837. properties_attributes: {
  838. 'core-site': coreSiteConfigs.properties_attributes,
  839. 'hdfs-site': hdfsSiteConfigs.properties_attributes
  840. }
  841. }
  842. ];
  843. for (var i = 0; i < rkmsHosts.length; i++) {
  844. rkmsHosts[i] = rkmsHosts[i] + ':' + rkmsPort;
  845. }
  846. coreSiteConfigs.properties['hadoop.security.key.provider.path'] = 'kms://http@' + rkmsHosts.join(',') + '/kms';
  847. hdfsSiteConfigs.properties['dfs.encryption.key.provider.uri'] = 'kms://http@' + rkmsHosts.join(',') + '/kms';
  848. this.saveConfigsBatch(groups, 'RANGER_KMS_SERVER', hostToInstall);
  849. },
  850. /**
  851. * Delete Hive Metastore is performed
  852. * @type {bool}
  853. */
  854. deleteRangerKMSServer: false,
  855. getRangerKMSServerHosts: function () {
  856. var rkmsHosts = App.HostComponent.find().filterProperty('componentName', 'RANGER_KMS_SERVER').mapProperty('hostName');
  857. var rangerKMSServerHost = this.get('rangerKMSServerHost');
  858. if(!!rangerKMSServerHost){
  859. rkmsHosts.push(rangerKMSServerHost);
  860. this.set('rangerKMSServerHost', '');
  861. }
  862. if (this.get('fromDeleteHost') || this.get('deleteRangerKMSServer')) {
  863. this.set('deleteRangerKMSServer', false);
  864. this.set('fromDeleteHost', false);
  865. return rkmsHosts.without(this.get('content.hostName'));
  866. }
  867. return rkmsHosts.sort();
  868. },
  869. /**
  870. * Delete Storm Nimbus is performed
  871. * @type {bool}
  872. */
  873. deleteNimbusHost: false,
  874. getStormNimbusHosts: function () {
  875. var
  876. stormNimbusHosts = App.HostComponent.find().filterProperty('componentName', 'NIMBUS').mapProperty('hostName'),
  877. nimbusHost = this.get('nimbusHost');
  878. if(!!nimbusHost){
  879. stormNimbusHosts.push(nimbusHost);
  880. this.set('nimbusHost', '');
  881. }
  882. if (this.get('fromDeleteHost') || this.get('deleteNimbusHost')) {
  883. this.set('deleteNimbusHost', false);
  884. this.set('fromDeleteHost', false);
  885. return stormNimbusHosts.without(this.get('content.hostName'));
  886. }
  887. return stormNimbusHosts.sort();
  888. },
  889. /**
  890. * Send command to server to resfresh configs of selected component
  891. * @param {object} event
  892. * @method refreshComponentConfigs
  893. */
  894. refreshComponentConfigs: function (event) {
  895. var self = this;
  896. return App.showConfirmationPopup(function () {
  897. var component = event.context;
  898. var context = Em.I18n.t('requestInfo.refreshComponentConfigs').format(component.get('displayName'));
  899. self.sendRefreshComponentConfigsCommand(component, context);
  900. });
  901. },
  902. /**
  903. * PUTs a command to server to refresh configs of host component.
  904. * @param {object} component
  905. * @param {object} context Context under which this command is beign sent.
  906. * @method sendRefreshComponentConfigsCommand
  907. */
  908. sendRefreshComponentConfigsCommand: function (component, context) {
  909. var resource_filters = [
  910. {
  911. service_name: component.get('service.serviceName'),
  912. component_name: component.get('componentName'),
  913. hosts: component.get('host.hostName')
  914. }
  915. ];
  916. App.ajax.send({
  917. name: 'host.host_component.refresh_configs',
  918. sender: this,
  919. data: {
  920. resource_filters: resource_filters,
  921. context: context
  922. },
  923. success: 'refreshComponentConfigsSuccessCallback'
  924. });
  925. },
  926. /**
  927. * Success callback for refresh host component configs request
  928. * @method refreshComponentConfigsSuccessCallback
  929. */
  930. refreshComponentConfigsSuccessCallback: function () {
  931. console.log('Send request for refresh configs successfully');
  932. this.showBackgroundOperationsPopup();
  933. },
  934. /**
  935. * Load tags
  936. * @method checkZkConfigs
  937. */
  938. checkZkConfigs: function () {
  939. var bg = App.router.get('backgroundOperationsController.services').findProperty('id', this.get('zkRequestId'));
  940. if (bg && !bg.get('isRunning')) {
  941. var self = this;
  942. this.removeObserver('App.router.backgroundOperationsController.serviceTimestamp', this, this.checkZkConfigs);
  943. setTimeout(function () {
  944. self.loadConfigs();
  945. }, App.get('componentsUpdateInterval'));
  946. }
  947. },
  948. /**
  949. * Load configs
  950. * @method loadConfigs
  951. */
  952. loadConfigs: function (callback) {
  953. App.ajax.send({
  954. name: 'config.tags',
  955. sender: this,
  956. success: callback ? callback : 'loadConfigsSuccessCallback',
  957. error: 'onLoadConfigsErrorCallback'
  958. });
  959. },
  960. /**
  961. * onLoadConfigsErrorCallback
  962. * @method onLoadConfigsErrorCallback
  963. */
  964. onLoadConfigsErrorCallback: function () {
  965. this.get('isOozieConfigLoaded').reject();
  966. },
  967. /**
  968. * Success callback for load configs request
  969. * @param {object} data
  970. * @method adConfigsSuccessCallback
  971. */
  972. loadConfigsSuccessCallback: function (data) {
  973. var urlParams = this.constructConfigUrlParams(data);
  974. if (urlParams.length > 0) {
  975. App.ajax.send({
  976. name: 'reassign.load_configs',
  977. sender: this,
  978. data: {
  979. urlParams: urlParams.join('|')
  980. },
  981. success: 'saveZkConfigs'
  982. });
  983. return true;
  984. }
  985. return false;
  986. },
  987. /**
  988. * construct URL params for query, that load configs
  989. * @param data {Object}
  990. * @return {Array}
  991. */
  992. constructConfigUrlParams: function (data) {
  993. var urlParams = [];
  994. var services = App.Service.find();
  995. if (App.get('isHaEnabled')) {
  996. urlParams.push('(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')');
  997. }
  998. if (services.someProperty('serviceName', 'HBASE')) {
  999. urlParams.push('(type=hbase-site&tag=' + data.Clusters.desired_configs['hbase-site'].tag + ')');
  1000. }
  1001. if (services.someProperty('serviceName', 'HIVE')) {
  1002. urlParams.push('(type=webhcat-site&tag=' + data.Clusters.desired_configs['webhcat-site'].tag + ')');
  1003. urlParams.push('(type=hive-site&tag=' + data.Clusters.desired_configs['hive-site'].tag + ')');
  1004. }
  1005. if (services.someProperty('serviceName', 'STORM')) {
  1006. urlParams.push('(type=storm-site&tag=' + data.Clusters.desired_configs['storm-site'].tag + ')');
  1007. }
  1008. if ((services.someProperty('serviceName', 'YARN') && App.get('isHadoop22Stack')) || App.get('isRMHaEnabled')) {
  1009. urlParams.push('(type=yarn-site&tag=' + data.Clusters.desired_configs['yarn-site'].tag + ')');
  1010. urlParams.push('(type=zoo.cfg&tag=' + data.Clusters.desired_configs['zoo.cfg'].tag + ')');
  1011. }
  1012. return urlParams;
  1013. },
  1014. /**
  1015. * save new ZooKeeper configs to server
  1016. * @param {object} data
  1017. * @method saveZkConfigs
  1018. */
  1019. saveZkConfigs: function (data) {
  1020. var configs = {};
  1021. var attributes = {};
  1022. data.items.forEach(function (item) {
  1023. configs[item.type] = item.properties;
  1024. attributes[item.type] = item.properties_attributes || {};
  1025. }, this);
  1026. var zks = this.getZkServerHosts();
  1027. var portValue = configs['zoo.cfg'] && Em.get(configs['zoo.cfg'], 'clientPort');
  1028. var zkPort = typeof portValue === 'udefined' ? '2181' : portValue;
  1029. var zksWithPort = this.concatZkNames(zks, zkPort);
  1030. this.setZKConfigs(configs, zksWithPort, zks);
  1031. var groups = [
  1032. {
  1033. properties: {
  1034. 'hive-site': configs['hive-site'],
  1035. 'webhcat-site': configs['webhcat-site']
  1036. },
  1037. properties_attributes: {
  1038. 'hive-site': attributes['hive-site'],
  1039. 'webhcat-site': attributes['webhcat-site']
  1040. }
  1041. }
  1042. ];
  1043. if ((App.Service.find().someProperty('serviceName', 'YARN') && App.get('isHadoop22Stack')) || App.get('isRMHaEnabled')) {
  1044. groups.push(
  1045. {
  1046. properties: {
  1047. 'yarn-site': configs['yarn-site']
  1048. },
  1049. properties_attributes: {
  1050. 'yarn-site': attributes['yarn-site']
  1051. }
  1052. }
  1053. );
  1054. }
  1055. this.saveConfigsBatch(groups, 'ZOOKEEPER_SERVER');
  1056. },
  1057. /**
  1058. *
  1059. * Set new values for some configs (based on available ZooKeeper Servers)
  1060. * @param configs {object}
  1061. * @param zksWithPort {string}
  1062. * @param zks {array}
  1063. * @return {Boolean}
  1064. */
  1065. setZKConfigs: function (configs, zksWithPort, zks) {
  1066. if (typeof configs !== 'object' || !Array.isArray(zks)) return false;
  1067. if (App.get('isHaEnabled')) {
  1068. configs['core-site']['ha.zookeeper.quorum'] = zksWithPort;
  1069. }
  1070. if (configs['hbase-site']) {
  1071. configs['hbase-site']['hbase.zookeeper.quorum'] = zks.join(',');
  1072. }
  1073. if (configs['accumulo-site']) {
  1074. configs['accumulo-site']['instance.zookeeper.host'] = zksWithPort;
  1075. }
  1076. if (configs['webhcat-site']) {
  1077. configs['webhcat-site']['templeton.zookeeper.hosts'] = zksWithPort;
  1078. }
  1079. if (configs['hive-site']) {
  1080. configs['hive-site']['hive.cluster.delegation.token.store.zookeeper.connectString'] = zksWithPort;
  1081. }
  1082. if (configs['storm-site']) {
  1083. configs['storm-site']['storm.zookeeper.servers'] = JSON.stringify(zks).replace(/"/g, "'");
  1084. }
  1085. if (App.get('isRMHaEnabled')) {
  1086. configs['yarn-site']['yarn.resourcemanager.zk-address'] = zksWithPort;
  1087. }
  1088. if (App.get('isHadoop22Stack')) {
  1089. if (configs['hive-site']) {
  1090. configs['hive-site']['hive.zookeeper.quorum'] = zksWithPort;
  1091. }
  1092. if (configs['yarn-site']) {
  1093. configs['yarn-site']['hadoop.registry.zk.quorum'] = zksWithPort;
  1094. }
  1095. }
  1096. return true;
  1097. },
  1098. /**
  1099. * concatenate URLs to ZOOKEEPER hosts with port "2181",
  1100. * as value of config divided by comma
  1101. * @param zks {array}
  1102. * @param port {string}
  1103. */
  1104. concatZkNames: function (zks, port) {
  1105. var zks_with_port = '';
  1106. zks.forEach(function (zk) {
  1107. zks_with_port += zk + ':' + port + ',';
  1108. });
  1109. return zks_with_port.slice(0, -1);
  1110. },
  1111. /**
  1112. * Is deleteHost action id fired
  1113. * @type {bool}
  1114. */
  1115. fromDeleteHost: false,
  1116. /**
  1117. * Is ZooKeeper Server being deleted from host
  1118. * @type {bool}
  1119. */
  1120. fromDeleteZkServer: false,
  1121. /**
  1122. * Get list of hostnames where ZK Server is installed
  1123. * @returns {string[]}
  1124. * @method getZkServerHosts
  1125. */
  1126. getZkServerHosts: function () {
  1127. var zks = App.HostComponent.find().filterProperty('componentName', 'ZOOKEEPER_SERVER').mapProperty('hostName');
  1128. if (this.get('fromDeleteHost') || this.get('fromDeleteZkServer')) {
  1129. this.set('fromDeleteHost', false);
  1130. this.set('fromDeleteZkServer', false);
  1131. return zks.without(this.get('content.hostName'));
  1132. }
  1133. return zks;
  1134. },
  1135. /**
  1136. * Send command to server to install selected host component
  1137. * @param {Object} event
  1138. * @method installComponent
  1139. */
  1140. installComponent: function (event) {
  1141. var self = this;
  1142. var component = event.context;
  1143. var componentName = component.get('componentName');
  1144. var displayName = component.get('displayName');
  1145. return App.ModalPopup.show({
  1146. primary: Em.I18n.t('hosts.host.installComponent.popup.confirm'),
  1147. header: Em.I18n.t('popup.confirmation.commonHeader'),
  1148. installComponentMessage: function () {
  1149. return Em.I18n.t('hosts.host.installComponent.msg').format(displayName);
  1150. }.property(),
  1151. bodyClass: Em.View.extend({
  1152. templateName: require('templates/main/host/details/installComponentPopup')
  1153. }),
  1154. onPrimary: function () {
  1155. this.hide();
  1156. App.ajax.send({
  1157. name: 'common.host.host_component.update',
  1158. sender: self,
  1159. data: {
  1160. hostName: self.get('content.hostName'),
  1161. serviceName: component.get('service.serviceName'),
  1162. componentName: componentName,
  1163. component: component,
  1164. context: Em.I18n.t('requestInfo.installHostComponent') + " " + displayName,
  1165. HostRoles: {
  1166. state: 'INSTALLED'
  1167. }
  1168. },
  1169. success: 'installComponentSuccessCallback',
  1170. error: 'ajaxErrorCallback'
  1171. });
  1172. }
  1173. });
  1174. },
  1175. /**
  1176. * Success callback for install component request
  1177. * @param {object} data
  1178. * @param {object} opt
  1179. * @param {object} params
  1180. * @method installComponentSuccessCallback
  1181. */
  1182. installComponentSuccessCallback: function (data, opt, params) {
  1183. console.log('Send request for REINSTALL COMPONENT successfully');
  1184. if (App.get('testMode')) {
  1185. this.mimicWorkStatusChange(params.component, App.HostComponentStatus.installing, App.HostComponentStatus.stopped);
  1186. }
  1187. this.showBackgroundOperationsPopup();
  1188. },
  1189. /**
  1190. * Send command to server to run decommission on DATANODE, TASKTRACKER, NODEMANAGER, REGIONSERVER
  1191. * @param {App.HostComponent} component
  1192. * @method decommission
  1193. */
  1194. decommission: function (component) {
  1195. var self = this;
  1196. return App.showConfirmationPopup(function () {
  1197. self.runDecommission.call(self, self.get('content.hostName'), component.get('service.serviceName'));
  1198. });
  1199. },
  1200. /**
  1201. * identify correct component to run decommission on them by service name,
  1202. * in result run proper decommission method
  1203. * @param hostName
  1204. * @param svcName
  1205. */
  1206. runDecommission: function (hostName, svcName) {
  1207. switch (svcName) {
  1208. case 'HDFS':
  1209. this.doDecommission(hostName, svcName, "NAMENODE", "DATANODE");
  1210. break;
  1211. case 'YARN':
  1212. this.doDecommission(hostName, svcName, "RESOURCEMANAGER", "NODEMANAGER");
  1213. break;
  1214. case 'HBASE':
  1215. this.warnBeforeDecommission(hostName);
  1216. }
  1217. },
  1218. /**
  1219. * Send command to server to run recommission on DATANODE, TASKTRACKER, NODEMANAGER
  1220. * @param {App.HostComponent} component
  1221. * @method recommission
  1222. */
  1223. recommission: function (component) {
  1224. var self = this;
  1225. return App.showConfirmationPopup(function () {
  1226. self.runRecommission.call(self, self.get('content.hostName'), component.get('service.serviceName'));
  1227. });
  1228. },
  1229. /**
  1230. * identify correct component to run recommission on them by service name,
  1231. * in result run proper recommission method
  1232. * @param hostName
  1233. * @param svcName
  1234. */
  1235. runRecommission: function (hostName, svcName) {
  1236. switch (svcName) {
  1237. case 'HDFS':
  1238. this.doRecommissionAndStart(hostName, svcName, "NAMENODE", "DATANODE");
  1239. break;
  1240. case 'YARN':
  1241. this.doRecommissionAndStart(hostName, svcName, "RESOURCEMANAGER", "NODEMANAGER");
  1242. break;
  1243. case 'HBASE':
  1244. this.doRecommissionAndStart(hostName, svcName, "HBASE_MASTER", "HBASE_REGIONSERVER");
  1245. }
  1246. this.showBackgroundOperationsPopup();
  1247. },
  1248. /**
  1249. * Performs Decommission (for DN, TT and NM)
  1250. * @param {string} hostName
  1251. * @param {string} serviceName
  1252. * @param {string} componentName
  1253. * @param {string} slaveType
  1254. * @method doDecommission
  1255. */
  1256. doDecommission: function (hostName, serviceName, componentName, slaveType) {
  1257. var contextNameString = 'hosts.host.' + slaveType.toLowerCase() + '.decommission';
  1258. var context = Em.I18n.t(contextNameString);
  1259. App.ajax.send({
  1260. name: 'host.host_component.decommission_slave',
  1261. sender: this,
  1262. data: {
  1263. context: context,
  1264. command: 'DECOMMISSION',
  1265. hostName: hostName,
  1266. serviceName: serviceName,
  1267. componentName: componentName,
  1268. slaveType: slaveType
  1269. },
  1270. success: 'decommissionSuccessCallback',
  1271. error: 'decommissionErrorCallback'
  1272. });
  1273. },
  1274. /**
  1275. * check is hbase regionserver in mm. If so - run decommission
  1276. * otherwise shows warning
  1277. * @method warnBeforeDecommission
  1278. * @param {string} hostNames - list of host when run from bulk operations or current host
  1279. */
  1280. warnBeforeDecommission: function (hostNames) {
  1281. if (this.get('content.hostComponents').findProperty('componentName', 'HBASE_REGIONSERVER').get('passiveState') == "OFF") {
  1282. this.showHbaseActiveWarning();
  1283. } else {
  1284. this.checkRegionServerState(hostNames);
  1285. }
  1286. },
  1287. /**
  1288. * send call to check is this regionserver last in cluster which has desired_admin_state property "INSERVICE"
  1289. * @method checkRegionServerState
  1290. * @param hostNames
  1291. */
  1292. checkRegionServerState: function (hostNames) {
  1293. return App.ajax.send({
  1294. name: 'host.region_servers.in_inservice',
  1295. sender: this,
  1296. data: {
  1297. hostNames: hostNames
  1298. },
  1299. success: 'checkRegionServerStateSuccessCallback'
  1300. });
  1301. },
  1302. /**
  1303. * check is this regionserver last in cluster which has desired_admin_state property "INSERVICE"
  1304. * @method checkRegionServerStateSuccessCallback
  1305. * @param data
  1306. * @param opt
  1307. * @param params
  1308. */
  1309. checkRegionServerStateSuccessCallback: function (data, opt, params) {
  1310. var hostArray = params.hostNames.split(",");
  1311. var decommissionPossible = (data.items.mapProperty('HostRoles.host_name').filter(function (hostName) {
  1312. return !hostArray.contains(hostName);
  1313. }, this).length >= 1);
  1314. if (decommissionPossible) {
  1315. this.doDecommissionRegionServer(params.hostNames, "HBASE", "HBASE_MASTER", "HBASE_REGIONSERVER");
  1316. } else {
  1317. this.showRegionServerWarning();
  1318. }
  1319. },
  1320. /**
  1321. * show warning that regionserver is last in cluster which has desired_admin_state property "INSERVICE"
  1322. * @method showRegionServerWarning
  1323. * @param hostNames
  1324. */
  1325. showRegionServerWarning: function () {
  1326. return App.ModalPopup.show({
  1327. header: Em.I18n.t('common.warning'),
  1328. message: Em.I18n.t('hosts.host.hbase_regionserver.decommission.warning'),
  1329. bodyClass: Ember.View.extend({
  1330. template: Em.Handlebars.compile('<div class="alert alert-warning">{{message}}</div>')
  1331. }),
  1332. secondary: false
  1333. });
  1334. },
  1335. /**
  1336. * shows warning: put hbase regionserver in passive state
  1337. * @method showHbaseActiveWarning
  1338. * @return {App.ModalPopup}
  1339. */
  1340. showHbaseActiveWarning: function () {
  1341. return App.ModalPopup.show({
  1342. header: Em.I18n.t('common.warning'),
  1343. message: function () {
  1344. return Em.I18n.t('hostPopup.recommendation.beforeDecommission').format(App.format.components["HBASE_REGIONSERVER"]);
  1345. }.property(),
  1346. bodyClass: Ember.View.extend({
  1347. template: Em.Handlebars.compile('<div class="alert alert-warning">{{message}}</div>')
  1348. }),
  1349. secondary: false
  1350. });
  1351. },
  1352. /**
  1353. * Performs Decommission (for RegionServer)
  1354. * @method doDecommissionRegionServer
  1355. * @param {string} hostNames - list of host when run from bulk operations or current host
  1356. * @param {string} serviceName - serviceName
  1357. * @param {string} componentName - master compoent name
  1358. * @param {string} slaveType - slave component name
  1359. */
  1360. doDecommissionRegionServer: function (hostNames, serviceName, componentName, slaveType) {
  1361. var batches = [
  1362. {
  1363. "order_id": 1,
  1364. "type": "POST",
  1365. "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + "/requests",
  1366. "RequestBodyInfo": {
  1367. "RequestInfo": {
  1368. "context": Em.I18n.t('hosts.host.regionserver.decommission.batch1'),
  1369. "command": "DECOMMISSION",
  1370. "exclusive" :"true",
  1371. "parameters": {
  1372. "slave_type": slaveType,
  1373. "excluded_hosts": hostNames
  1374. },
  1375. 'operation_level': {
  1376. level: "HOST_COMPONENT",
  1377. cluster_name: App.get('clusterName'),
  1378. host_name: hostNames,
  1379. service_name: serviceName
  1380. }
  1381. },
  1382. "Requests/resource_filters": [
  1383. {"service_name": serviceName, "component_name": componentName}
  1384. ]
  1385. }
  1386. }];
  1387. var id = 2;
  1388. var hAray = hostNames.split(",");
  1389. for (var i = 0; i < hAray.length; i++) {
  1390. batches.push({
  1391. "order_id": id,
  1392. "type": "PUT",
  1393. "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + "/hosts/" + hAray[i] + "/host_components/" + slaveType,
  1394. "RequestBodyInfo": {
  1395. "RequestInfo": {
  1396. context: Em.I18n.t('hosts.host.regionserver.decommission.batch2'),
  1397. exclusive: true,
  1398. operation_level: {
  1399. level: "HOST_COMPONENT",
  1400. cluster_name: App.get('clusterName'),
  1401. host_name: hostNames,
  1402. service_name: serviceName || null
  1403. }
  1404. },
  1405. "Body": {
  1406. HostRoles: {
  1407. state: "INSTALLED"
  1408. }
  1409. }
  1410. }
  1411. });
  1412. id++;
  1413. }
  1414. batches.push({
  1415. "order_id": id,
  1416. "type": "POST",
  1417. "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + "/requests",
  1418. "RequestBodyInfo": {
  1419. "RequestInfo": {
  1420. "context": Em.I18n.t('hosts.host.regionserver.decommission.batch3'),
  1421. "command": "DECOMMISSION",
  1422. "service_name": serviceName,
  1423. "component_name": componentName,
  1424. "parameters": {
  1425. "slave_type": slaveType,
  1426. "excluded_hosts": hostNames,
  1427. "mark_draining_only": true
  1428. },
  1429. 'operation_level': {
  1430. level: "HOST_COMPONENT",
  1431. cluster_name: App.get('clusterName'),
  1432. host_name: hostNames,
  1433. service_name: serviceName
  1434. }
  1435. },
  1436. "Requests/resource_filters": [
  1437. {"service_name": serviceName, "component_name": componentName}
  1438. ]
  1439. }
  1440. });
  1441. App.ajax.send({
  1442. name: 'host.host_component.recommission_and_restart',
  1443. sender: this,
  1444. data: {
  1445. intervalTimeSeconds: 1,
  1446. tolerateSize: 0,
  1447. batches: batches
  1448. },
  1449. success: 'decommissionSuccessCallback',
  1450. error: 'decommissionErrorCallback'
  1451. });
  1452. },
  1453. /**
  1454. * Error callback for decommission requests
  1455. * @param {object} request
  1456. * @param {object} ajaxOptions
  1457. * @param {string} error
  1458. * @method decommissionErrorCallback
  1459. */
  1460. decommissionErrorCallback: function (request, ajaxOptions, error) {
  1461. console.log('ERROR: ' + error);
  1462. },
  1463. /**
  1464. * Success ajax response for Recommission/Decommission slaves
  1465. * @param {object} data
  1466. * @method decommissionSuccessCallback
  1467. * @return {Boolean}
  1468. */
  1469. decommissionSuccessCallback: function (data) {
  1470. if (data && (data.Requests || data.resources[0].RequestSchedule)) {
  1471. this.showBackgroundOperationsPopup();
  1472. return true;
  1473. } else {
  1474. console.log('cannot get request id from ', data);
  1475. return false;
  1476. }
  1477. },
  1478. /**
  1479. * Performs Recommission and Start
  1480. * @param {string} hostNames
  1481. * @param {string} serviceName
  1482. * @param {string} componentName
  1483. * @param {string} slaveType
  1484. * @method doRecommissionAndStart
  1485. */
  1486. doRecommissionAndStart: function (hostNames, serviceName, componentName, slaveType) {
  1487. var contextNameString_1 = 'hosts.host.' + slaveType.toLowerCase() + '.recommission';
  1488. var context_1 = Em.I18n.t(contextNameString_1);
  1489. var contextNameString_2 = 'requestInfo.startHostComponent.' + slaveType.toLowerCase();
  1490. var startContext = Em.I18n.t(contextNameString_2);
  1491. var params = {
  1492. "slave_type": slaveType,
  1493. "included_hosts": hostNames
  1494. };
  1495. if (serviceName == "HBASE") {
  1496. params.mark_draining_only = true;
  1497. }
  1498. var batches = [
  1499. {
  1500. "order_id": 1,
  1501. "type": "POST",
  1502. "uri": App.apiPrefix + "/clusters/" + App.get('clusterName') + "/requests",
  1503. "RequestBodyInfo": {
  1504. "RequestInfo": {
  1505. "context": context_1,
  1506. "command": "DECOMMISSION",
  1507. "exclusive":"true",
  1508. "parameters": params,
  1509. 'operation_level': {
  1510. level: "HOST_COMPONENT",
  1511. cluster_name: App.get('clusterName'),
  1512. host_name: hostNames,
  1513. service_name: serviceName
  1514. }
  1515. },
  1516. "Requests/resource_filters": [
  1517. {"service_name": serviceName, "component_name": componentName}
  1518. ]
  1519. }
  1520. }];
  1521. var id = 2;
  1522. var hAray = hostNames.split(",");
  1523. for (var i = 0; i < hAray.length; i++) {
  1524. batches.push( {
  1525. "order_id": id,
  1526. "type": "PUT",
  1527. "uri": App.get('apiPrefix') + "/clusters/" + App.get('clusterName') + "/hosts/" + hAray[i] + "/host_components/" + slaveType,
  1528. "RequestBodyInfo": {
  1529. "RequestInfo": {
  1530. context: startContext,
  1531. operation_level: {
  1532. level: "HOST_COMPONENT",
  1533. cluster_name: App.get('clusterName'),
  1534. host_name: hostNames,
  1535. service_name: serviceName || null
  1536. }
  1537. },
  1538. "Body": {
  1539. HostRoles: {
  1540. state: "STARTED"
  1541. }
  1542. }
  1543. }
  1544. });
  1545. id++;
  1546. }
  1547. App.ajax.send({
  1548. name: 'host.host_component.recommission_and_restart',
  1549. sender: this,
  1550. data: {
  1551. intervalTimeSeconds: 1,
  1552. tolerateSize: 1,
  1553. batches: batches
  1554. },
  1555. success: 'decommissionSuccessCallback',
  1556. error: 'decommissionErrorCallback'
  1557. });
  1558. },
  1559. /**
  1560. * Handler for host-menu items actions
  1561. * @param {object} option
  1562. * @method doAction
  1563. */
  1564. doAction: function (option) {
  1565. switch (option.context.action) {
  1566. case "deleteHost":
  1567. this.validateAndDeleteHost();
  1568. break;
  1569. case "startAllComponents":
  1570. if (!this.get('content.isNotHeartBeating')) this.doStartAllComponents();
  1571. break;
  1572. case "stopAllComponents":
  1573. if (!this.get('content.isNotHeartBeating')) this.doStopAllComponents();
  1574. break;
  1575. case "restartAllComponents":
  1576. if (!this.get('content.isNotHeartBeating')) this.doRestartAllComponents();
  1577. break;
  1578. case "onOffPassiveModeForHost":
  1579. this.onOffPassiveModeForHost(option.context);
  1580. break;
  1581. case "setRackId":
  1582. this.setRackIdForHost();
  1583. break;
  1584. }
  1585. },
  1586. /**
  1587. * Turn On/Off Passive Mode for host
  1588. * @param {object} context
  1589. * @method onOffPassiveModeForHost
  1590. */
  1591. onOffPassiveModeForHost: function (context) {
  1592. var state = context.active ? 'ON' : 'OFF';
  1593. var self = this;
  1594. var message = Em.I18n.t('hosts.host.details.for.postfix').format(context.label);
  1595. return App.showConfirmationPopup(function () {
  1596. self.hostPassiveModeRequest(state, message);
  1597. },
  1598. Em.I18n.t('hosts.passiveMode.popup').format(context.active ? 'On' : 'Off', this.get('content.hostName'))
  1599. );
  1600. },
  1601. /**
  1602. * Set rack id for host
  1603. * @method setRackIdForHost
  1604. */
  1605. setRackIdForHost: function () {
  1606. var hostNames = [{hostName: this.get('content.hostName')}];
  1607. var rack = this.get('content.rack');
  1608. var operationData = {message: Em.I18n.t('hosts.host.details.setRackId')};
  1609. hostsManagement.setRackInfo(operationData, hostNames, rack);
  1610. },
  1611. /**
  1612. * Send request to get passive state for host
  1613. * @param {string} state
  1614. * @param {string} message
  1615. * @method hostPassiveModeRequest
  1616. */
  1617. hostPassiveModeRequest: function (state, message) {
  1618. App.ajax.send({
  1619. name: 'bulk_request.hosts.passive_state',
  1620. sender: this,
  1621. data: {
  1622. hostNames: this.get('content.hostName'),
  1623. passive_state: state,
  1624. requestInfo: message
  1625. },
  1626. success: 'updateHost'
  1627. });
  1628. },
  1629. /**
  1630. * Success callback for receiving host passive state
  1631. * @param {object} data
  1632. * @param {object} opt
  1633. * @param {object} params
  1634. * @method updateHost
  1635. */
  1636. updateHost: function (data, opt, params) {
  1637. this.set('content.passiveState', params.passive_state);
  1638. batchUtils.infoPassiveState(params.passive_state);
  1639. },
  1640. /**
  1641. * Send request to get passive state for hostComponent
  1642. * @param {object} component - hostComponentn object
  1643. * @param {string} state
  1644. * @param {string} message
  1645. * @method hostPassiveModeRequest
  1646. */
  1647. updateComponentPassiveState: function (component, state, message) {
  1648. App.ajax.send({
  1649. name: 'common.host.host_component.passive',
  1650. sender: this,
  1651. data: {
  1652. hostName: this.get('content.hostName'),
  1653. componentName: component.get('componentName'),
  1654. component: component,
  1655. passive_state: state,
  1656. context: message
  1657. },
  1658. success: 'updateHostComponent'
  1659. });
  1660. },
  1661. /**
  1662. * Success callback for receiving hostComponent passive state
  1663. * @param {object} data
  1664. * @param {object} opt
  1665. * @param {object} params
  1666. * @method updateHost
  1667. */
  1668. updateHostComponent: function (data, opt, params) {
  1669. params.component.set('passiveState', params.passive_state);
  1670. batchUtils.infoPassiveState(params.passive_state);
  1671. },
  1672. /**
  1673. * Show confirmation popup for action "start all components"
  1674. * @method doStartAllComponents
  1675. */
  1676. doStartAllComponents: function () {
  1677. var self = this;
  1678. var components = this.get('serviceNonClientActiveComponents');
  1679. var componentsLength = Em.isNone(components) ? 0 : components.get('length');
  1680. if (componentsLength > 0) {
  1681. return App.showConfirmationPopup(function () {
  1682. self.sendComponentCommand(components, Em.I18n.t('hosts.host.maintainance.startAllComponents.context'), App.HostComponentStatus.started);
  1683. });
  1684. }
  1685. },
  1686. /**
  1687. * Show confirmation popup for action "stop all components"
  1688. * @method doStopAllComponents
  1689. */
  1690. doStopAllComponents: function () {
  1691. var self = this;
  1692. var components = this.get('serviceNonClientActiveComponents');
  1693. var componentsLength = Em.isNone(components) ? 0 : components.get('length');
  1694. if (componentsLength > 0) {
  1695. return App.showConfirmationPopup(function () {
  1696. self.sendComponentCommand(components, Em.I18n.t('hosts.host.maintainance.stopAllComponents.context'), App.HostComponentStatus.stopped);
  1697. });
  1698. }
  1699. },
  1700. /**
  1701. * Show confirmation popup for action "restart all components"
  1702. * @method doRestartAllComponents
  1703. */
  1704. doRestartAllComponents: function () {
  1705. var self = this;
  1706. var components = this.get('serviceActiveComponents');
  1707. var componentsLength = Em.isNone(components) ? 0 : components.get('length');
  1708. if (componentsLength > 0) {
  1709. return App.showConfirmationPopup(function () {
  1710. batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allOnSelectedHost').format(self.get('content.hostName')), "HOST");
  1711. });
  1712. }
  1713. },
  1714. /**
  1715. * get info about host-components, exactly:
  1716. * - host-components grouped by status, features
  1717. * - flag, that indicate whether ZooKeeper Server is installed
  1718. * @return {Object}
  1719. */
  1720. getHostComponentsInfo: function () {
  1721. var componentsOnHost = this.get('content.hostComponents');
  1722. var allComponents = App.HostComponent.find();
  1723. var stoppedStates = [App.HostComponentStatus.stopped,
  1724. App.HostComponentStatus.install_failed,
  1725. App.HostComponentStatus.upgrade_failed,
  1726. App.HostComponentStatus.init,
  1727. App.HostComponentStatus.unknown];
  1728. var container = {
  1729. zkServerInstalled: false,
  1730. lastComponents: [],
  1731. masterComponents: [],
  1732. runningComponents: [],
  1733. nonDeletableComponents: [],
  1734. unknownComponents: []
  1735. };
  1736. if (componentsOnHost && componentsOnHost.get('length') > 0) {
  1737. componentsOnHost.forEach(function (cInstance) {
  1738. if (cInstance.get('componentName') === 'ZOOKEEPER_SERVER') {
  1739. container.zkServerInstalled = true;
  1740. }
  1741. if (allComponents.filterProperty('componentName', cInstance.get('componentName')).get('length') === 1) {
  1742. container.lastComponents.push(cInstance.get('displayName'));
  1743. }
  1744. var workStatus = cInstance.get('workStatus');
  1745. if (cInstance.get('isMaster') && !cInstance.get('isDeletable')) {
  1746. container.masterComponents.push(cInstance.get('displayName'));
  1747. }
  1748. if (stoppedStates.indexOf(workStatus) < 0) {
  1749. container.runningComponents.push(cInstance.get('displayName'));
  1750. }
  1751. if (!cInstance.get('isDeletable')) {
  1752. container.nonDeletableComponents.push(cInstance.get('displayName'));
  1753. }
  1754. if (workStatus === App.HostComponentStatus.unknown) {
  1755. container.unknownComponents.push(cInstance.get('displayName'));
  1756. }
  1757. });
  1758. }
  1759. return container;
  1760. },
  1761. /**
  1762. * Deletion of hosts not supported for this version
  1763. * @method validateAndDeleteHost
  1764. */
  1765. validateAndDeleteHost: function () {
  1766. var container = this.getHostComponentsInfo();
  1767. if (container.masterComponents.length > 0) {
  1768. this.raiseDeleteComponentsError(container.masterComponents, 'masterList');
  1769. return;
  1770. } else if (container.nonDeletableComponents.length > 0) {
  1771. this.raiseDeleteComponentsError(container.nonDeletableComponents, 'nonDeletableList');
  1772. return;
  1773. } else if (container.runningComponents.length > 0) {
  1774. this.raiseDeleteComponentsError(container.runningComponents, 'runningList');
  1775. return;
  1776. }
  1777. if (container.zkServerInstalled) {
  1778. var self = this;
  1779. return App.showConfirmationPopup(function () {
  1780. self.confirmDeleteHost(container.unknownComponents, container.lastComponents);
  1781. }, Em.I18n.t('hosts.host.addComponent.deleteHostWithZooKeeper'));
  1782. } else {
  1783. this.confirmDeleteHost(container.unknownComponents, container.lastComponents);
  1784. }
  1785. },
  1786. /**
  1787. * Show popup with info about reasons why host can't be deleted
  1788. * @param {string[]} components
  1789. * @param {string} type
  1790. * @method raiseDeleteComponentsError
  1791. */
  1792. raiseDeleteComponentsError: function (components, type) {
  1793. App.ModalPopup.show({
  1794. header: Em.I18n.t('hosts.cant.do.popup.title'),
  1795. type: type,
  1796. showBodyEnd: function () {
  1797. return this.get('type') === 'runningList' || this.get('type') === 'masterList';
  1798. }.property(),
  1799. components: components,
  1800. componentsStr: function () {
  1801. return this.get('components').join(", ");
  1802. }.property(),
  1803. componentsBody: function () {
  1804. return Em.I18n.t('hosts.cant.do.popup.' + type + '.body').format(this.get('components').length);
  1805. }.property(),
  1806. componentsBodyEnd: function () {
  1807. if (this.get('showBodyEnd')) {
  1808. return Em.I18n.t('hosts.cant.do.popup.' + type + '.body.end');
  1809. }
  1810. return '';
  1811. }.property(),
  1812. bodyClass: Em.View.extend({
  1813. templateName: require('templates/main/host/details/raiseDeleteComponentErrorPopup')
  1814. }),
  1815. secondary: null
  1816. });
  1817. },
  1818. /**
  1819. * Show confirmation popup to delete host
  1820. * @param {string[]} unknownComponents
  1821. * @param {string[]} lastComponents
  1822. * @method confirmDeleteHost
  1823. */
  1824. confirmDeleteHost: function (unknownComponents, lastComponents) {
  1825. var self = this;
  1826. return App.ModalPopup.show({
  1827. header: Em.I18n.t('hosts.delete.popup.title'),
  1828. deletePopupBody: function () {
  1829. return Em.I18n.t('hosts.delete.popup.body').format(self.get('content.publicHostName'));
  1830. }.property(),
  1831. lastComponent: function () {
  1832. if (lastComponents && lastComponents.length) {
  1833. this.set('isChecked', false);
  1834. return true;
  1835. } else {
  1836. this.set('isChecked', true);
  1837. return false;
  1838. }
  1839. }.property(),
  1840. disablePrimary: function () {
  1841. return !this.get('isChecked');
  1842. }.property('isChecked'),
  1843. isChecked: false,
  1844. lastComponentError: Em.View.extend({
  1845. template: Em.Handlebars.compile(Em.I18n.t('hosts.delete.popup.body.msg4').format(lastComponents))
  1846. }),
  1847. unknownComponents: function () {
  1848. if (unknownComponents && unknownComponents.length) {
  1849. return unknownComponents.join(", ");
  1850. }
  1851. return '';
  1852. }.property(),
  1853. bodyClass: Em.View.extend({
  1854. templateName: require('templates/main/host/details/doDeleteHostPopup')
  1855. }),
  1856. onPrimary: function () {
  1857. var popup = this;
  1858. var completeCallback = function () {
  1859. var remainingHosts = App.db.getSelectedHosts('mainHostController').removeObject(self.get('content.hostName'));
  1860. App.db.setSelectedHosts('mainHostController', remainingHosts);
  1861. popup.hide();
  1862. };
  1863. self.doDeleteHost(completeCallback);
  1864. }
  1865. });
  1866. },
  1867. /**
  1868. * send DELETE calls to components of host and after delete host itself
  1869. * @param completeCallback
  1870. * @method doDeleteHost
  1871. */
  1872. doDeleteHost: function (completeCallback) {
  1873. this.set('fromDeleteHost', true);
  1874. var allComponents = this.get('content.hostComponents');
  1875. var deleteError = null;
  1876. var dfd = $.Deferred();
  1877. var self = this;
  1878. if (allComponents.get('length') > 0) {
  1879. allComponents.forEach(function (component, index) {
  1880. var length = allComponents.get('length');
  1881. if (!deleteError) {
  1882. this._doDeleteHostComponent(component, function () {
  1883. deleteError = self.get('_deletedHostComponentResult');
  1884. if (index == length - 1) {
  1885. dfd.resolve();
  1886. }
  1887. });
  1888. }
  1889. }, this);
  1890. } else {
  1891. dfd.resolve();
  1892. }
  1893. dfd.done(function () {
  1894. if (!deleteError) {
  1895. App.ajax.send({
  1896. name: 'common.delete.host',
  1897. sender: self,
  1898. data: {
  1899. hostName: self.get('content.hostName')
  1900. },
  1901. callback: completeCallback,
  1902. success: 'deleteHostSuccessCallback',
  1903. error: 'deleteHostErrorCallback'
  1904. });
  1905. }
  1906. else {
  1907. completeCallback();
  1908. deleteError.xhr.responseText = "{\"message\": \"" + deleteError.xhr.statusText + "\"}";
  1909. App.ajax.defaultErrorHandler(deleteError.xhr, deleteError.url, deleteError.method, deleteError.xhr.status);
  1910. }
  1911. });
  1912. },
  1913. deleteHostSuccessCallback: function (data, rq, requestBody) {
  1914. var self = this;
  1915. App.router.get('updateController').updateHost(function () {
  1916. if (!!App.Service.find().findProperty('serviceName', 'HIVE')) {
  1917. self.loadConfigs('loadHiveConfigs');
  1918. }
  1919. self.loadConfigs();
  1920. App.router.transitionTo('hosts.index');
  1921. });
  1922. if(!!(requestBody && requestBody.hostName))
  1923. App.hostsMapper.deleteRecord(App.Host.find().findProperty('hostName', requestBody.hostName));
  1924. App.router.get('clusterController').getAllHostNames();
  1925. },
  1926. deleteHostErrorCallback: function (xhr, textStatus, errorThrown, opt) {
  1927. console.log('Error deleting host.');
  1928. console.log(textStatus);
  1929. console.log(errorThrown);
  1930. xhr.responseText = "{\"message\": \"" + xhr.statusText + "\"}";
  1931. this.loadConfigs();
  1932. App.ajax.defaultErrorHandler(xhr, opt.url, 'DELETE', xhr.status);
  1933. },
  1934. /**
  1935. * Send command to server to restart all host components with stale configs
  1936. * @method restartAllStaleConfigComponents
  1937. */
  1938. restartAllStaleConfigComponents: function () {
  1939. var self = this;
  1940. return App.showConfirmationPopup(function () {
  1941. var staleComponents = self.get('content.componentsWithStaleConfigs');
  1942. batchUtils.restartHostComponents(staleComponents, Em.I18n.t('rollingrestart.context.allWithStaleConfigsOnSelectedHost').format(self.get('content.hostName')), "HOST");
  1943. });
  1944. },
  1945. /**
  1946. * open Reassign Master Wizard with selected component
  1947. * @param {object} event
  1948. * @method moveComponent
  1949. */
  1950. moveComponent: function (event) {
  1951. return App.showConfirmationPopup(function () {
  1952. var component = event.context;
  1953. var reassignMasterController = App.router.get('reassignMasterController');
  1954. reassignMasterController.saveComponentToReassign(component);
  1955. reassignMasterController.getSecurityStatus();
  1956. reassignMasterController.setCurrentStep('1');
  1957. App.router.transitionTo('reassign');
  1958. });
  1959. },
  1960. /**
  1961. * Restart clients host components to apply config changes
  1962. * @param {object} event
  1963. * @method refreshConfigs
  1964. */
  1965. refreshConfigs: function (event) {
  1966. var self = this;
  1967. var components = event.context;
  1968. if (components.get('length') > 0) {
  1969. return App.showConfirmationPopup(function () {
  1970. batchUtils.restartHostComponents(components, Em.I18n.t('rollingrestart.context.allClientsOnSelectedHost').format(self.get('content.hostName')), "HOST");
  1971. });
  1972. }
  1973. },
  1974. toggleMaintenanceMode: function (event) {
  1975. var self = this;
  1976. var state = event.context.get('passiveState') === "ON" ? "OFF" : "ON";
  1977. var message = Em.I18n.t('passiveState.turn' + state.toCapital() + 'For').format(event.context.get('displayName'));
  1978. return App.showConfirmationPopup(function () {
  1979. self.updateComponentPassiveState(event.context, state, message);
  1980. });
  1981. },
  1982. downloadClientConfigs: function (event) {
  1983. componentsUtils.downloadClientConfigs.call(this, {
  1984. hostName: event.context.get('hostName'),
  1985. componentName: event.context.get('componentName'),
  1986. displayName: event.context.get('displayName')
  1987. });
  1988. },
  1989. installClients: function(event) {
  1990. var clientsToInstall = [],
  1991. clientsToAdd = [],
  1992. missedComponents = [],
  1993. dependentComponents = [],
  1994. self = this;
  1995. event.context.forEach(function (component) {
  1996. if (['INIT', 'INSTALL_FAILED'].contains(component.get('workStatus'))) {
  1997. clientsToInstall.push(component);
  1998. } else if (typeof component.get('workStatus') == 'undefined') {
  1999. clientsToAdd.push(component);
  2000. }
  2001. });
  2002. clientsToAdd.forEach(function (component, index, array) {
  2003. var dependencies = componentsUtils.checkComponentDependencies(component.get('componentName'), {
  2004. scope: 'host',
  2005. installedComponents: this.get('content.hostComponents').mapProperty('componentName')
  2006. }).reject(function (componentName) {
  2007. return array.mapProperty('componentName').contains(componentName);
  2008. });
  2009. if (dependencies.length) {
  2010. missedComponents.pushObjects(dependencies);
  2011. dependentComponents.push(component.get('displayName'));
  2012. }
  2013. }, this);
  2014. missedComponents = missedComponents.uniq();
  2015. if (missedComponents.length) {
  2016. var popupMessage = Em.I18n.t('host.host.addComponent.popup.clients.dependedComponents.body').format(stringUtils.getFormattedStringFromArray(dependentComponents),
  2017. stringUtils.getFormattedStringFromArray(missedComponents.map(function(componentName) {
  2018. return App.StackServiceComponent.find(componentName).get('displayName');
  2019. })));
  2020. App.showAlertPopup(Em.I18n.t('host.host.addComponent.popup.dependedComponents.header'), popupMessage);
  2021. } else {
  2022. App.get('router.mainAdminKerberosController').getKDCSessionState(function () {
  2023. var sendInstallCommand = function () {
  2024. if (clientsToInstall.length) {
  2025. self.sendComponentCommand(clientsToInstall, Em.I18n.t('host.host.details.installClients'), 'INSTALLED');
  2026. }
  2027. };
  2028. if (clientsToAdd.length) {
  2029. var message = stringUtils.getFormattedStringFromArray(clientsToAdd.mapProperty('displayName'));
  2030. self.showAddComponentPopup(message, function () {
  2031. sendInstallCommand();
  2032. clientsToAdd.forEach(function (component) {
  2033. this.primary(component);
  2034. }, self);
  2035. });
  2036. } else {
  2037. sendInstallCommand();
  2038. }
  2039. });
  2040. }
  2041. },
  2042. /**
  2043. * On click handler for custom command from items menu
  2044. * @param context
  2045. */
  2046. executeCustomCommand: function(event) {
  2047. var controller = this;
  2048. var context = event.context;
  2049. return App.showConfirmationPopup(function() {
  2050. App.ajax.send({
  2051. name : 'service.item.executeCustomCommand',
  2052. sender: controller,
  2053. data : {
  2054. command : context.command,
  2055. context : context.context || Em.I18n.t('services.service.actions.run.executeCustomCommand.context').format(context.command),
  2056. hosts : context.hosts,
  2057. serviceName : context.service,
  2058. componentName : context.component
  2059. },
  2060. success : 'executeCustomCommandSuccessCallback',
  2061. error : 'executeCustomCommandErrorCallback'
  2062. });
  2063. });
  2064. },
  2065. executeCustomCommandSuccessCallback : function(data, ajaxOptions, params) {
  2066. if (data.Requests.id) {
  2067. App.router.get('backgroundOperationsController').showPopup();
  2068. } else {
  2069. console.warn('Error during execution of ' + params.command + ' custom command on' + params.componentName);
  2070. }
  2071. },
  2072. executeCustomCommandErrorCallback : function(data) {
  2073. var error = Em.I18n.t('services.service.actions.run.executeCustomCommand.error');
  2074. if(data && data.responseText){
  2075. try {
  2076. var json = $.parseJSON(data.responseText);
  2077. error += json.message;
  2078. } catch (err) {}
  2079. }
  2080. App.showAlertPopup(Em.I18n.t('services.service.actions.run.executeCustomCommand.error'), error);
  2081. console.warn('Error during executing custom command');
  2082. },
  2083. /**
  2084. * show popup confirmation of version installation
  2085. * @param event
  2086. */
  2087. installVersionConfirmation: function (event) {
  2088. var self = this;
  2089. return App.showConfirmationPopup(function () {
  2090. self.installVersion(event);
  2091. },
  2092. Em.I18n.t('hosts.host.stackVersions.install.confirmation').format(event.context.get('displayName'))
  2093. );
  2094. },
  2095. /**
  2096. * install HostStackVersion on host
  2097. * @param {object} event
  2098. */
  2099. installVersion: function (event) {
  2100. App.ajax.send({
  2101. name: 'host.stack_versions.install',
  2102. sender: this,
  2103. data: {
  2104. hostName: this.get('content.hostName'),
  2105. version: event.context
  2106. },
  2107. success: 'installVersionSuccessCallback'
  2108. });
  2109. },
  2110. /**
  2111. * success callback of <code>installVersion</code>
  2112. * on success set version status to INSTALLING
  2113. * @param {object} data
  2114. * @param {object} opt
  2115. * @param {object} params
  2116. */
  2117. installVersionSuccessCallback: function (data, opt, params) {
  2118. App.HostStackVersion.find(params.version.get('id')).set('status', 'INSTALLING');
  2119. App.db.set('repoVersionInstall', 'id', [data.Requests.id]);
  2120. App.clusterStatus.setClusterStatus({
  2121. wizardControllerName: this.get('name'),
  2122. localdb: App.db.data
  2123. });
  2124. }
  2125. });