details.js 68 KB

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