controls_view.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  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 validator = require('utils/validator');
  20. var dbInfo = require('data/db_properties_info') || {};
  21. var delay = (function(){
  22. var timer = 0;
  23. return function(callback, ms){
  24. clearTimeout (timer);
  25. timer = setTimeout(callback, ms);
  26. };
  27. })();
  28. /**
  29. * Abstract view for config fields.
  30. * Add popover support to control
  31. */
  32. App.ServiceConfigPopoverSupport = Ember.Mixin.create({
  33. /**
  34. * Config object. It will instance of App.ServiceConfigProperty
  35. */
  36. serviceConfig: null,
  37. attributeBindings:['readOnly'],
  38. isPopoverEnabled: true,
  39. popoverPlacement: 'right',
  40. didInsertElement: function () {
  41. App.tooltip(this.$('[data-toggle=tooltip]'), {placement: 'top'});
  42. // if description for this serviceConfig not exist, then no need to show popover
  43. if (this.get('isPopoverEnabled') !== 'false' && this.get('serviceConfig.description')) {
  44. this.addPopover();
  45. }
  46. },
  47. /**
  48. * Element where popover is "appended"
  49. */
  50. elementForPopover: function () {
  51. return this.$();
  52. }.property(),
  53. /**
  54. * Add Popover for config-boxes
  55. *
  56. * @method addPopover
  57. */
  58. addPopover: function () {
  59. App.popover(this.get('elementForPopover'), {
  60. title: Em.I18n.t('installer.controls.serviceConfigPopover.title').format(
  61. this.get('serviceConfig.displayName'),
  62. (this.get('serviceConfig.displayName') === this.get('serviceConfig.name')) ? '' : this.get('serviceConfig.name')
  63. ),
  64. content: this.get('serviceConfig.description'),
  65. placement: this.get('popoverPlacement'),
  66. trigger: 'hover'
  67. });
  68. },
  69. willDestroyElement: function() {
  70. this.$().popover('destroy');
  71. },
  72. readOnly: Em.computed.not('serviceConfig.isEditable')
  73. });
  74. App.SupportsDependentConfigs = Ember.Mixin.create({
  75. /**
  76. * method send request to check if some of dependent configs was changes
  77. * and in case there was changes shows popup with info about changed configs
  78. *
  79. * @param {App.ServiceConfigProperty} config
  80. * @param [controller]
  81. * @returns {$.Deferred}
  82. */
  83. sendRequestRorDependentConfigs: function(config, controller) {
  84. if (!config || (!config.get('isValid') && config.get('isNotDefaultValue'))) return $.Deferred().resolve().promise();
  85. controller = controller || this.get('controller');
  86. if (controller && ['mainServiceInfoConfigsController','wizardStep7Controller'].contains(controller.get('name'))) {
  87. var name = config.get('name');
  88. var saveRecommended = (config.get('value') === config.get('recommendedValue'));
  89. var type = App.config.getConfigTagFromFileName(config.get('filename'));
  90. var p = App.configsCollection.getConfig(App.config.configId(name, type));
  91. controller.removeCurrentFromDependentList(config, saveRecommended);
  92. if ((p && Em.get(p, 'propertyDependedBy.length') > 0 || config.get('displayType') === 'user') && config.get('oldValue') !== config.get('value')) {
  93. var old = config.get('oldValue');
  94. config.set('oldValue', config.get('value'));
  95. return controller.loadConfigRecommendations([{
  96. "type": type,
  97. "name": name,
  98. "old_value": Em.isNone(old) ? config.get('initialValue') : old
  99. }]);
  100. }
  101. }
  102. return $.Deferred().resolve().promise();
  103. },
  104. /**
  105. * Restore values for dependent configs by parent config info.
  106. * NOTE: If dependent config inherited from multiply configs its
  107. * value will be restored only when all parent configs are being restored.
  108. *
  109. * @param {App.ServiceConfigProperty} parentConfig
  110. */
  111. restoreDependentConfigs: function(parentConfig) {
  112. var controller = this.get('controller');
  113. var dependentConfigs = controller.get('recommendations');
  114. try {
  115. controller.set('recommendations', dependentConfigs.reject(function(item) {
  116. if (item.parentConfigs.contains(parentConfig.get('name'))) {
  117. if (item.parentConfigs.length > 1) {
  118. item.parentConfigs.removeObject(parentConfig.get('name'));
  119. } else {
  120. // reset property value
  121. var property = App.config.findConfigProperty(controller.get('stepConfigs'), item.propertyName, App.config.getOriginalFileName(item.fileName));
  122. if (property) {
  123. property.set('value', property.get('savedValue') || property.get('initialValue'));
  124. }
  125. return true;
  126. }
  127. }
  128. return false;
  129. }));
  130. } catch(e) {
  131. console.warn('Dependent properties popup was not cleared');
  132. }
  133. }
  134. });
  135. /**
  136. * mixin is used to send request for recommendations
  137. * when config value is updated by user
  138. */
  139. App.ValueObserver = Em.Mixin.create(App.SupportsDependentConfigs, {
  140. selected: false,
  141. focusOut: function () {
  142. this.set('selected', false);
  143. },
  144. focusIn: function () {
  145. this.set('selected', true);
  146. },
  147. onValueUpdate: function () {
  148. if (this.get('selected')) {
  149. var self = this, config = this.get('serviceConfig'),
  150. controller = this.get('controller');
  151. delay(function(){
  152. self.sendRequestRorDependentConfigs(config, controller);
  153. }, 500);
  154. }
  155. }.observes('serviceConfig.value')
  156. });
  157. /**
  158. * mixin set class that serve as unique element identifier,
  159. * id not used in order to avoid collision with ember ids
  160. */
  161. App.ServiceConfigCalculateId = Ember.Mixin.create({
  162. idClass: Ember.computed(function () {
  163. var config = this.get('config') && this.get('config.widget') ? this.get('config') : this.get('serviceConfig') || {};
  164. var label = Em.get(config, 'name') ? Em.get(config, 'name').toLowerCase().replace(/\./g, '-') : '',
  165. fileName = Em.get(config, 'filename') ? Em.get(config, 'filename').toLowerCase().replace(/\./g, '-') : '',
  166. group = Em.get(config, 'group.name') || 'default',
  167. isOrigin = Em.getWithDefault(config, 'compareConfigs.length', 0) > 0 ? '-origin' : '';
  168. return 'service-config-' + label + '-' + fileName + '-' + group + isOrigin;
  169. }),
  170. classNameBindings: 'idClass'
  171. });
  172. /**
  173. * Default input control
  174. * @type {*}
  175. */
  176. App.ServiceConfigTextField = Ember.TextField.extend(App.ServiceConfigPopoverSupport, App.ServiceConfigCalculateId, App.ValueObserver, {
  177. valueBinding: 'serviceConfig.value',
  178. classNameBindings: 'textFieldClassName',
  179. placeholderBinding: 'serviceConfig.placeholder',
  180. //Set editDone true for last edited config text field parameter
  181. focusOut: function () {
  182. this._super();
  183. this.get('serviceConfig').set("editDone", true);
  184. },
  185. //Set editDone false for all current category config text field parameter
  186. focusIn: function () {
  187. this._super();
  188. if (!this.get('serviceConfig.isOverridden') && !this.get('serviceConfig.isComparison')) {
  189. if (this.get('parentView.categoryConfigsAll')) {
  190. this.get("parentView.categoryConfigsAll").setEach("editDone", false);
  191. }
  192. }
  193. },
  194. textFieldClassName: function () {
  195. if (this.get('serviceConfig.unit')) {
  196. return ['input-small'];
  197. } else if (this.get('serviceConfig.displayType') === 'principal') {
  198. return ['span12'];
  199. } else {
  200. return ['span9'];
  201. }
  202. }.property('serviceConfig.displayType', 'serviceConfig.unit')
  203. });
  204. /**
  205. * Customized input control with Units type specified
  206. * @type {Em.View}
  207. */
  208. App.ServiceConfigTextFieldWithUnit = Ember.View.extend(App.ServiceConfigPopoverSupport, App.ValueObserver, {
  209. valueBinding: 'serviceConfig.value',
  210. classNames: ['input-append', 'with-unit'],
  211. placeholderBinding: 'serviceConfig.savedValue',
  212. templateName: require('templates/wizard/controls_service_config_textfield_with_unit')
  213. });
  214. /**
  215. * Password control
  216. * @type {*}
  217. */
  218. App.ServiceConfigPasswordField = Ember.TextField.extend(App.ServiceConfigPopoverSupport, {
  219. serviceConfig: null,
  220. type: 'password',
  221. attributeBindings:['readOnly'],
  222. valueBinding: 'serviceConfig.value',
  223. classNames: [ 'span4' ],
  224. placeholder: Em.I18n.t('form.item.placeholders.typePassword'),
  225. template: Ember.Handlebars.compile('{{view view.retypePasswordView}}'),
  226. keyPress: function (event) {
  227. if (event.keyCode == 13) {
  228. return false;
  229. }
  230. },
  231. retypePasswordView: Ember.TextField.extend({
  232. placeholder: Em.I18n.t('form.passwordRetype'),
  233. attributeBindings:['readOnly'],
  234. type: 'password',
  235. classNames: [ 'span4', 'retyped-password' ],
  236. keyPress: function (event) {
  237. if (event.keyCode == 13) {
  238. return false;
  239. }
  240. },
  241. valueBinding: 'parentView.serviceConfig.retypedPassword',
  242. readOnly: Em.computed.not('parentView.serviceConfig.isEditable')
  243. }),
  244. readOnly: Em.computed.not('serviceConfig.isEditable')
  245. });
  246. /**
  247. * Textarea control
  248. * @type {*}
  249. */
  250. App.ServiceConfigTextArea = Ember.TextArea.extend(App.ServiceConfigPopoverSupport, App.ServiceConfigCalculateId, App.ValueObserver, {
  251. valueBinding: 'serviceConfig.value',
  252. rows: 4,
  253. classNames: ['directories'],
  254. classNameBindings: ['widthClass'],
  255. widthClass: 'span9'
  256. });
  257. /**
  258. * Special config type for Capacity Scheduler
  259. */
  260. App.CapacitySceduler = App.ServiceConfigTextArea.extend({
  261. rows: 16,
  262. /**
  263. * specific property handling for cs
  264. *
  265. * @param {App.ServiceConfigProperty} config
  266. * @param [controller]
  267. * @returns {$.Deferred}
  268. * @override
  269. */
  270. sendRequestRorDependentConfigs: function(config, controller) {
  271. if (!config.get('isValid') && config.get('isNotDefaultValue')) return $.Deferred().resolve().promise();
  272. controller = controller || this.get('controller');
  273. if (controller && ['mainServiceInfoConfigsController','wizardStep7Controller'].contains(controller.get('name'))) {
  274. return controller.loadConfigRecommendations(config.get('value').split('\n').map(function (_property) {
  275. return {
  276. "type": 'capacity-scheduler',
  277. "name": _property.split('=')[0]
  278. }
  279. }));
  280. }
  281. return $.Deferred().resolve().promise();
  282. }
  283. });
  284. /**
  285. * Textarea control for content type
  286. * @type {*}
  287. */
  288. App.ServiceConfigTextAreaContent = Ember.TextArea.extend(App.ServiceConfigPopoverSupport, App.ServiceConfigCalculateId, App.ValueObserver, {
  289. valueBinding: 'serviceConfig.value',
  290. rows: 20,
  291. classNames: ['span10']
  292. });
  293. /**
  294. * Textarea control with bigger height
  295. * @type {*}
  296. */
  297. App.ServiceConfigBigTextArea = App.ServiceConfigTextArea.extend(App.ServiceConfigCalculateId, {
  298. rows: 10
  299. });
  300. /**
  301. * Checkbox control
  302. * @type {*}
  303. */
  304. App.ServiceConfigCheckbox = Ember.Checkbox.extend(App.ServiceConfigPopoverSupport, App.ServiceConfigCalculateId, App.SupportsDependentConfigs, {
  305. allowedPairs: {
  306. 'trueFalse': ["true", "false"],
  307. 'YesNo': ["Yes", "No"],
  308. 'YESNO': ["YES", "NO"],
  309. 'yesNo': ["yes", "no"]
  310. },
  311. trueValue: true,
  312. falseValue: false,
  313. checked: false,
  314. elementForPopover: function () {
  315. return this.$().parent('.control-group').find('.bootstrap-checkbox');
  316. }.property(),
  317. /**
  318. * set appropriate config values pair
  319. * to define which value is positive (checked) property
  320. * and what value is negative (unchecked) property
  321. */
  322. didInsertElement: function() {
  323. var self = this;
  324. if (this.get('serviceConfig').isDestroyed) return;
  325. this._super();
  326. this.addObserver('serviceConfig.value', this, 'toggleChecker');
  327. Object.keys(this.get('allowedPairs')).forEach(function(key) {
  328. if (this.get('allowedPairs')[key].contains(this.get('serviceConfig.value'))) {
  329. this.set('trueValue', this.get('allowedPairs')[key][0]);
  330. this.set('falseValue', this.get('allowedPairs')[key][1]);
  331. }
  332. }, this);
  333. this.set('checked', this.get('serviceConfig.value') === this.get('trueValue'));
  334. this.propertyDidChange('checked');
  335. Em.run.next(function () {
  336. if (self.$()) {
  337. self.$().checkbox({
  338. defaultState: self.get('serviceConfig.value'),
  339. buttonStyle: 'btn-link btn-large',
  340. checkedClass: 'icon-check',
  341. uncheckedClass: 'icon-check-empty'
  342. });
  343. self.propertyDidChange('elementForPopover');
  344. self.addPopover();
  345. }
  346. });
  347. },
  348. willDestroyElement: function() {
  349. this.removeObserver('serviceConfig.value', this, 'checkedBinding');
  350. },
  351. /***
  352. * defines if checkbox value appropriate to the config value
  353. * @returns {boolean}
  354. */
  355. isNotAppropriateValue: function() {
  356. return this.get('serviceConfig.value') !== this.get(this.get('checked') + 'Value');
  357. },
  358. /**
  359. * change service config value if click on checkbox
  360. */
  361. toggleValue: function() {
  362. if (this.isNotAppropriateValue()){
  363. this.set('serviceConfig.value', this.get(this.get('checked') + 'Value'));
  364. this.get('serviceConfig').set("editDone", true);
  365. this.sendRequestRorDependentConfigs(this.get('serviceConfig'));
  366. }
  367. }.observes('checked'),
  368. /**
  369. * change checkbox value if click on undo
  370. */
  371. toggleChecker: function() {
  372. if (this.isNotAppropriateValue()) {
  373. this.set('checked', !this.get('checked'));
  374. // change bootstrap-checkbox state
  375. this.$().change();
  376. }
  377. },
  378. disabled: Em.computed.not('serviceConfig.isEditable'),
  379. //Set editDone false for all current category config text field parameter
  380. focusIn: function (event) {
  381. if (!this.get('serviceConfig.isOverridden') && !this.get('serviceConfig.isComparison')) {
  382. this.get("parentView.categoryConfigsAll").setEach("editDone", false);
  383. }
  384. }
  385. });
  386. /**
  387. * Checkbox control which can hide or show dependent properties
  388. * @type {*|void}
  389. */
  390. App.ServiceConfigCheckboxWithDependencies = App.ServiceConfigCheckbox.extend({
  391. toggleDependentConfigs: function() {
  392. if (this.get('serviceConfig.dependentConfigPattern')) {
  393. if (this.get('serviceConfig.dependentConfigPattern') === "CATEGORY") {
  394. this.disableEnableCategoryConfigs();
  395. } else {
  396. this.showHideDependentConfigs();
  397. }
  398. }
  399. }.observes('checked'),
  400. disableEnableCategoryConfigs: function () {
  401. this.get('categoryConfigsAll').setEach('isEditable', this.get('checked'));
  402. this.set('serviceConfig.isEditable', true);
  403. },
  404. showHideDependentConfigs: function () {
  405. this.get('categoryConfigsAll').forEach(function (c) {
  406. if (c.get('name').match(this.get('serviceConfig.dependentConfigPattern')) && c.get('name') != this.get('serviceConfig.name'))
  407. c.set('isVisible', this.get('checked'))
  408. }, this);
  409. }
  410. });
  411. App.ServiceConfigRadioButtons = Ember.View.extend(App.ServiceConfigCalculateId, App.SupportsDependentConfigs, {
  412. templateName: require('templates/wizard/controls_service_config_radio_buttons'),
  413. didInsertElement: function () {
  414. // on page render, automatically populate JDBC URLs only for default database settings
  415. // so as to not lose the user's customizations on these fields
  416. if (this.get('hostNameProperty')) {
  417. this.get('hostNameProperty').set('isEditable', !this.get('isNewDb'));
  418. }
  419. if (['addServiceController', 'installerController'].contains(this.get('controller.wizardController.name')) && !App.StackService.find(this.get('serviceConfig.serviceName')).get('isInstalled')) {
  420. if (this.get('isNewDb') || this.get('dontUseHandleDbConnection').contains(this.get('serviceConfig.name'))) {
  421. this.onOptionsChange();
  422. } else {
  423. if ((App.get('isHadoopWindowsStack') && this.get('inMSSQLWithIA')) || this.get('serviceConfig.name') === 'DB_FLAVOR') {
  424. this.onOptionsChange();
  425. }
  426. this.handleDBConnectionProperty();
  427. }
  428. }
  429. },
  430. /**
  431. * Radio buttons that are not DB options and should not trigger any observer or change any other property's value
  432. * Ranger service -> "Authentication method" property is an example for non DB related radio button
  433. */
  434. nonDBRadioButtons: function() {
  435. return this.get('dontUseHandleDbConnection').without('DB_FLAVOR');
  436. }.property('dontUseHandleDbConnection'),
  437. /**
  438. * properties with these names don'use handleDBConnectionProperty method
  439. */
  440. dontUseHandleDbConnection: function () {
  441. // functionality added in Ranger 0.5
  442. // remove DB_FLAVOR so it can handle DB Connection checks
  443. var rangerService = App.StackService.find().findProperty('serviceName', 'RANGER');
  444. var rangerVersion = rangerService ? rangerService.get('serviceVersion') : '';
  445. if (rangerVersion && rangerVersion.split('.')[0] < 1 && rangerVersion.split('.')[1] < 5) {
  446. return ['DB_FLAVOR', 'authentication_method'];
  447. }
  448. return ['ranger.authentication.method'];
  449. }.property('App.currentStackName'),
  450. serviceConfig: null,
  451. categoryConfigsAll: null,
  452. /**
  453. * defines if new db is selected;
  454. * @type {boolean}
  455. */
  456. isNewDb: function() {
  457. return /New /g.test(this.get('serviceConfig.value'));
  458. }.property('serviceConfig.serviceName', 'serviceConfig.value'),
  459. /**
  460. * defines if 'Existing MSSQL Server database with integrated authentication' is selected
  461. * in this case some properties can have different behaviour
  462. * @type {boolean}
  463. */
  464. inMSSQLWithIA: Em.computed.equal('serviceConfig.value', 'Existing MSSQL Server database with integrated authentication'),
  465. /**
  466. * Radio button has very uncomfortable values for managing it's state
  467. * so it's better to use code values that easier to manipulate. Ex:
  468. * "Existing MySQL Database" transforms to "MYSQL"
  469. * @type {string}
  470. */
  471. getDbTypeFromRadioValue: function() {
  472. var currentValue = this.get('serviceConfig.value');
  473. /** TODO: Remove SQLA from the list of databases once Ranger DB_FLAVOR=SQLA is replaced with SQL Anywhere */
  474. var databases = /MySQL|Postgres|Oracle|Derby|MSSQL|SQLA|Anywhere/gi;
  475. if (this.get('inMSSQLWithIA')) {
  476. return 'MSSQL2';
  477. } else {
  478. var matches = currentValue.match(databases);
  479. if (matches) {
  480. return currentValue.match(databases)[0].toUpperCase();
  481. } else {
  482. return "MYSQL";
  483. }
  484. }
  485. }.property('serviceConfig.serviceName', 'serviceConfig.value'),
  486. onOptionsChange: function () {
  487. if (!this.get('nonDBRadioButtons').contains(this.get('serviceConfig.name'))) {
  488. /** if new db is selected host name must be same as master of selected service (and can't be changed)**/
  489. this.handleSpecialUserPassProperties();
  490. }
  491. }.observes('databaseProperty.value', 'hostNameProperty.value', 'serviceConfig.value'),
  492. name: function () {
  493. var name = this.get('serviceConfig.radioName');
  494. if (!this.get('serviceConfig.isOriginalSCP')) {
  495. if (this.get('serviceConfig.isComparison')) {
  496. var version = this.get('serviceConfig.compareConfigs') ? this.get('controller.selectedVersion') : this.get('version');
  497. name += '-v' + version;
  498. } else {
  499. var group = this.get('serviceConfig.group.name');
  500. name += '-' + group;
  501. }
  502. }
  503. return name;
  504. }.property('serviceConfig.radioName'),
  505. /**
  506. * Just property object for database name
  507. * @type {App.ServiceConfigProperty}
  508. */
  509. databaseProperty: function () {
  510. return this.getPropertyByType('db_name');
  511. }.property('serviceConfig.serviceName'),
  512. /**
  513. * Just property object for host name
  514. * @type {App.ServiceConfigProperty}
  515. */
  516. hostNameProperty: function () {
  517. var host = this.getPropertyByType('host_name');
  518. if (host && !host.get('value')) {
  519. if (host.get('savedValue')) {
  520. host.set('value', host.get('savedValue'));
  521. } else if (host.get('recommendedValue')) {
  522. host.set('value', host.get('recommendedValue'));
  523. }
  524. }
  525. return host;
  526. }.property('serviceConfig.serviceName', 'serviceConfig.value'),
  527. /**
  528. * Just property object for database name
  529. * @type {App.ServiceConfigProperty}
  530. */
  531. userProperty: function () {
  532. return this.getPropertyByType('user_name');
  533. }.property('serviceConfig.serviceName'),
  534. /**
  535. * Just property object for database name
  536. * @type {App.ServiceConfigProperty}
  537. */
  538. passwordProperty: function () {
  539. return this.getPropertyByType('password');
  540. }.property('serviceConfig.serviceName'),
  541. /**
  542. *
  543. * @param propertyType
  544. * @returns {*}
  545. */
  546. getDefaultPropertyValue: function(propertyType) {
  547. var dbProperties = dbInfo.dpPropertiesMap[this.get('getDbTypeFromRadioValue')],
  548. serviceName = this.get('serviceConfig.serviceName');
  549. return dbProperties[serviceName] && dbProperties[serviceName][propertyType]
  550. ? dbProperties[serviceName][propertyType] : dbProperties[propertyType];
  551. },
  552. /**
  553. *
  554. * @param propertyType
  555. * @returns {*|Object}
  556. */
  557. getPropertyByType: function(propertyType) {
  558. if (dbInfo.dpPropertiesByServiceMap[this.get('serviceConfig.serviceName')]) {
  559. //@TODO: dbInfo.dpPropertiesByServiceMap has corresponding property name but does not have filenames with it. this can cause issue when there are multiple db properties with same name belonging to different files
  560. /** check if selected service has db properties**/
  561. return this.get('controller.selectedService.configs').findProperty('name', dbInfo.dpPropertiesByServiceMap[this.get('serviceConfig.serviceName')][propertyType]);
  562. }
  563. return null;
  564. },
  565. /**
  566. * This method hides properties <code>user_name<code> and <code>password<code> in case selected db is
  567. * "Existing MSSQL Server database with integrated authentication" or similar
  568. * @method handleSpecialUserPassProperties
  569. */
  570. handleSpecialUserPassProperties: function() {
  571. ['user_name', 'password'].forEach(function(pType) {
  572. var property = this.getPropertyByType(pType);
  573. if (property) {
  574. property.setProperties({
  575. 'isVisible': !this.get('inMSSQLWithIA'),
  576. 'isRequired': !this.get('inMSSQLWithIA')
  577. });
  578. }
  579. }, this);
  580. },
  581. /**
  582. * `Observer` that add <code>additionalView</code> to <code>App.ServiceConfigProperty</code>
  583. * that responsible for (if existing db selected)
  584. * 1. checking database connection
  585. * 2. showing jdbc driver setup warning msg.
  586. *
  587. * @method handleDBConnectionProperty
  588. **/
  589. handleDBConnectionProperty: function() {
  590. if (this.get('dontUseHandleDbConnection').contains(this.get('serviceConfig.name'))) {
  591. return;
  592. }
  593. var handledProperties = ['oozie_database', 'hive_database', 'DB_FLAVOR'];
  594. var currentValue = this.get('serviceConfig.value');
  595. /** TODO: Remove SQLA from the list of databases once Ranger DB_FLAVOR=SQLA is replaced with SQL Anywhere */
  596. var databases = /MySQL|PostgreSQL|Postgres|Oracle|Derby|MSSQL|SQLA|Anywhere/gi;
  597. var currentDB = currentValue.match(databases)[0];
  598. /** TODO: Remove SQLA from the list of databases once Ranger DB_FLAVOR=SQLA is replaced with SQL Anywhere */
  599. var databasesTypes = /MySQL|Postgres|Oracle|Derby|MSSQL|SQLA|Anywhere/gi;
  600. var currentDBType = currentValue.match(databasesTypes)[0];
  601. var checkDatabase = /existing/gi.test(currentValue);
  602. // db connection check button show up if existed db selected
  603. var propertyAppendTo1 = this.get('categoryConfigsAll').findProperty('displayName', 'Database URL');
  604. // warning msg under database type radio buttons, to warn the user to setup jdbc driver if existed db selected
  605. var propertyHive = this.get('categoryConfigsAll').findProperty('displayName', 'Hive Database');
  606. var propertyOozie = this.get('categoryConfigsAll').findProperty('displayName', 'Oozie Database');
  607. var propertyAppendTo2 = propertyHive ? propertyHive : propertyOozie;
  608. // RANGER specific
  609. if (this.get('serviceConfig.serviceName') === 'RANGER') {
  610. propertyAppendTo1 = this.get('categoryConfigsAll').findProperty('name', 'ranger.jpa.jdbc.url');
  611. propertyAppendTo2 = this.get('categoryConfigsAll').findProperty('name', 'DB_FLAVOR');
  612. // check for all db types when installing Ranger - not only for existing ones
  613. checkDatabase = true;
  614. }
  615. if (propertyAppendTo1) {
  616. propertyAppendTo1.set('additionalView', null);
  617. }
  618. if (propertyAppendTo2) {
  619. propertyAppendTo2.set('additionalView', null);
  620. }
  621. var shouldAdditionalViewsBeSet = currentDB && checkDatabase && handledProperties.contains(this.get('serviceConfig.name')),
  622. driver = this.getDefaultPropertyValue('sql_jar_connector') ? this.getDefaultPropertyValue('sql_jar_connector').split("/").pop() : 'driver.jar',
  623. dbType = this.getDefaultPropertyValue('db_type'),
  624. additionalView1 = shouldAdditionalViewsBeSet ? App.CheckDBConnectionView.extend({databaseName: dbType}) : null,
  625. additionalView2 = shouldAdditionalViewsBeSet ? Ember.View.extend({
  626. template: Ember.Handlebars.compile('<div class="alert">{{{view.message}}}</div>'),
  627. message: function() {
  628. return Em.I18n.t('services.service.config.database.msg.jdbcSetup').format(dbType, driver);
  629. }.property()
  630. }) : null;
  631. if (propertyAppendTo1) {
  632. Em.run.next(function () {
  633. propertyAppendTo1.set('additionalView', additionalView1);
  634. });
  635. }
  636. if (propertyAppendTo2) {
  637. Em.run.next(function () {
  638. propertyAppendTo2.set('additionalView', additionalView2);
  639. });
  640. }
  641. }.observes('serviceConfig.value'),
  642. options: function () {
  643. return this.get('serviceConfig.options').map(function (option) {
  644. var dbTypePattern = /mysql|postgres|oracle|derby|mssql|sql\s?a/i,
  645. className = '',
  646. displayName = Em.get(option, 'displayName'),
  647. dbTypeMatch = displayName.match(dbTypePattern);
  648. if (dbTypeMatch) {
  649. var dbSourcePattern = /new/i,
  650. newDbMatch = displayName.match(dbSourcePattern);
  651. if (newDbMatch) {
  652. className += 'new-';
  653. }
  654. className += dbTypeMatch[0].replace(' ', '').toLowerCase();
  655. }
  656. return className ? Em.Object.create(option, {
  657. className: className
  658. }) : option;
  659. });
  660. }.property('serviceConfig.options')
  661. });
  662. App.ServiceConfigRadioButton = Ember.Checkbox.extend(App.SupportsDependentConfigs, {
  663. tagName: 'input',
  664. attributeBindings: ['type', 'name', 'value', 'checked', 'disabled'],
  665. checked: false,
  666. clicked: false,
  667. type: 'radio',
  668. name: null,
  669. value: null,
  670. didInsertElement: function () {
  671. this.set('checked', this.get('parentView.serviceConfig.value') === this.get('value'));
  672. },
  673. click: function () {
  674. this.set('clicked', true);
  675. this.set('checked', true);
  676. this.onChecked();
  677. },
  678. onChecked: function () {
  679. // Wrapping the call with Ember.run.next prevents a problem where setting isVisible on component
  680. // causes JS error due to re-rendering. For example, this occurs when switching the Config Group
  681. // in Service Config page
  682. if (this.get('clicked')) {
  683. Em.run.next(this, function() {
  684. this.set('parentView.serviceConfig.value', this.get('value'));
  685. this.sendRequestRorDependentConfigs(this.get('parentView.serviceConfig'));
  686. this.set('clicked', false);
  687. this.updateForeignKeys();
  688. });
  689. }
  690. }.observes('checked'),
  691. updateCheck: function() {
  692. if (!this.get('clicked')) {
  693. this.set('checked', this.get('parentView.serviceConfig.value') === this.get('value'));
  694. this.updateForeignKeys();
  695. }
  696. }.observes('parentView.serviceConfig.value'),
  697. updateForeignKeys: function() {
  698. var components = this.get('parentView.serviceConfig.options');
  699. if (components && components.someProperty('foreignKeys')) {
  700. this.get('controller.stepConfigs').findProperty('serviceName', this.get('parentView.serviceConfig.serviceName')).propertyDidChange('errorCount');
  701. }
  702. },
  703. disabled: function () {
  704. return !this.get('parentView.serviceConfig.isEditable') ||
  705. !['addServiceController', 'installerController'].contains(this.get('controller.wizardController.name')) && /^New\s\w+\sDatabase$/.test(this.get('value'));
  706. }.property('parentView.serviceConfig.isEditable')
  707. });
  708. App.ServiceConfigComboBox = Ember.Select.extend(App.ServiceConfigPopoverSupport, App.ServiceConfigCalculateId, App.SupportsDependentConfigs, {
  709. contentBinding: 'serviceConfig.options',
  710. selectionBinding: 'serviceConfig.value',
  711. placeholderBinding: 'serviceConfig.savedValue',
  712. classNames: [ 'span3' ]
  713. });
  714. /**
  715. * Base component for host config with popover support
  716. */
  717. App.ServiceConfigHostPopoverSupport = Ember.Mixin.create({
  718. /**
  719. * Config object. It will instance of App.ServiceConfigProperty
  720. */
  721. serviceConfig: null,
  722. didInsertElement: function () {
  723. App.popover(this.$(), {
  724. title: this.get('serviceConfig.displayName'),
  725. content: this.get('serviceConfig.description'),
  726. placement: 'right',
  727. trigger: 'hover'
  728. });
  729. }
  730. });
  731. /**
  732. * Master host component.
  733. * Show hostname without ability to edit it
  734. * @type {*}
  735. */
  736. App.ServiceConfigMasterHostView = Ember.View.extend(App.ServiceConfigHostPopoverSupport, App.ServiceConfigCalculateId, {
  737. classNames: ['master-host', 'span6'],
  738. valueBinding: 'serviceConfig.value',
  739. template: Ember.Handlebars.compile('{{value}}')
  740. });
  741. /**
  742. * text field property view that enables possibility
  743. * for check connection
  744. * @type {*}
  745. */
  746. App.checkConnectionView = App.ServiceConfigTextField.extend({
  747. didInsertElement: function() {
  748. this._super();
  749. if (this.get('controller.isHostsConfigsPage')) {
  750. return;
  751. }
  752. var kdc = this.get('categoryConfigsAll').findProperty('name', 'kdc_type');
  753. var propertyAppendTo = this.get('categoryConfigsAll').findProperty('name', 'domains');
  754. if (propertyAppendTo) {
  755. try {
  756. propertyAppendTo.set('additionalView', App.CheckDBConnectionView.extend({databaseName: kdc && kdc.get('value')}));
  757. } catch (e) {
  758. console.error('error while adding "Test connection button"');
  759. }
  760. }
  761. }
  762. });
  763. /**
  764. * Show value as plain label in italics
  765. * @type {*}
  766. */
  767. App.ServiceConfigLabelView = Ember.View.extend(App.ServiceConfigHostPopoverSupport, App.ServiceConfigCalculateId, {
  768. classNames: ['master-host', 'span6'],
  769. valueBinding: 'serviceConfig.value',
  770. template: Ember.Handlebars.compile('<i>{{view.value}}</i>')
  771. });
  772. /**
  773. * Base component to display Multiple hosts
  774. * @type {*}
  775. */
  776. App.ServiceConfigMultipleHostsDisplay = Ember.Mixin.create(App.ServiceConfigHostPopoverSupport, App.ServiceConfigCalculateId, {
  777. hasNoHosts: function () {
  778. if (!this.get('value')) {
  779. return true;
  780. }
  781. return this.get('value').length === 0;
  782. }.property('value'),
  783. formatValue: function() {
  784. if (Em.isArray(this.get('value')) && this.get('value').length === 1) {
  785. return this.get('value.firstObject');
  786. } else {
  787. return this.get('value');
  788. }
  789. }.property('value'),
  790. hasOneHost: Em.computed.equal('value.length', 1),
  791. hasMultipleHosts: Em.computed.gt('value.length', 1),
  792. otherLength: function () {
  793. var len = this.get('value').length;
  794. if (len > 2) {
  795. return Em.I18n.t('installer.controls.serviceConfigMultipleHosts.others').format(len - 1);
  796. } else {
  797. return Em.I18n.t('installer.controls.serviceConfigMultipleHosts.other');
  798. }
  799. }.property('value')
  800. });
  801. /**
  802. * Multiple Slave Hosts component
  803. * @type {*}
  804. */
  805. App.ServiceConfigComponentHostsView = Ember.View.extend(App.ServiceConfigMultipleHostsDisplay, App.ServiceConfigCalculateId, {
  806. viewName: 'serviceConfigSlaveHostsView',
  807. classNames: ['component-hosts', 'span6'],
  808. valueBinding: 'serviceConfig.value',
  809. templateName: require('templates/wizard/component_hosts'),
  810. /**
  811. * Onclick handler for link
  812. */
  813. showHosts: function () {
  814. var serviceConfig = this.get('serviceConfig');
  815. App.ModalPopup.show({
  816. header: Em.I18n.t('installer.controls.serviceConfigMasterHosts.header').format(serviceConfig.category),
  817. bodyClass: Ember.View.extend({
  818. serviceConfig: serviceConfig,
  819. templateName: require('templates/wizard/component_hosts_popup')
  820. }),
  821. secondary: null
  822. });
  823. }
  824. });
  825. /**
  826. * DropDown component for <code>select hosts for groups</code> popup
  827. * @type {*}
  828. */
  829. App.SlaveComponentDropDownGroupView = Ember.View.extend(App.ServiceConfigCalculateId, {
  830. viewName: "slaveComponentDropDownGroupView",
  831. /**
  832. * On change handler for <code>select hosts for groups</code> popup
  833. * @param event
  834. */
  835. changeGroup: function (event) {
  836. var host = this.get('content');
  837. var groupName = $('#' + this.get('elementId') + ' select').val();
  838. this.get('controller').changeHostGroup(host, groupName);
  839. },
  840. optionTag: Ember.View.extend({
  841. /**
  842. * Whether current value(OptionTag value) equals to host value(assigned to SlaveComponentDropDownGroupView.content)
  843. */
  844. selected: function () {
  845. return this.get('parentView.content.group') === this.get('content');
  846. }.property('content')
  847. })
  848. });
  849. /**
  850. * View for testing connection to database.
  851. **/
  852. App.CheckDBConnectionView = Ember.View.extend({
  853. templateName: require('templates/common/form/check_db_connection'),
  854. /** @property {string} btnCaption - text for button **/
  855. btnCaption: function() {
  856. return this.get('parentView.service.serviceName') === 'KERBEROS'
  857. ? Em.I18n.t('services.service.config.kdc.btn.idle')
  858. : Em.I18n.t('services.service.config.database.btn.idle')
  859. }.property('parentView.service.serviceName'),
  860. /** @property {string} responseCaption - text for status link **/
  861. responseCaption: null,
  862. /** @property {boolean} isConnecting - is request to server activated **/
  863. isConnecting: false,
  864. /** @property {boolean} isValidationPassed - check validation for required fields **/
  865. isValidationPassed: null,
  866. /** @property {string} databaseName- name of current database **/
  867. databaseName: null,
  868. /** @property {boolean} isRequestResolved - check for finished request to server **/
  869. isRequestResolved: false,
  870. /** @property {boolean} isConnectionSuccess - check for successful connection to database **/
  871. isConnectionSuccess: null,
  872. /** @property {string} responseFromServer - message from server response **/
  873. responseFromServer: null,
  874. /** @property {Object} ambariRequiredProperties - properties that need for custom action request **/
  875. ambariRequiredProperties: null,
  876. /** @property {Number} currentRequestId - current custom action request id **/
  877. currentRequestId: null,
  878. /** @property {Number} currentTaskId - current custom action task id **/
  879. currentTaskId: null,
  880. /** @property {jQuery.Deferred} request - current $.ajax request **/
  881. request: null,
  882. /** @property {Number} pollInterval - timeout interval for ajax polling **/
  883. pollInterval: 3000,
  884. /** @property {Object} logsPopup - popup with DB connection check info **/
  885. logsPopup: null,
  886. /** @property {string} hostNameProperty - host name property based on service and database names **/
  887. hostNameProperty: function() {
  888. if (!/wizard/i.test(this.get('controller.name')) && this.get('parentView.service.serviceName') === 'HIVE') {
  889. return this.get('parentView.service.serviceName').toLowerCase() + '_hostname';
  890. } else if (this.get('parentView.service.serviceName') === 'KERBEROS') {
  891. return 'kdc_hosts';
  892. } else if (this.get('parentView.service.serviceName') === 'RANGER') {
  893. return '{0}_{1}_host'.format(this.get('parentView.service.serviceName').toLowerCase(), this.get('databaseName').toLowerCase());
  894. }
  895. return '{0}_existing_{1}_host'.format(this.get('parentView.service.serviceName').toLowerCase(), this.get('databaseName').toLowerCase());
  896. }.property('databaseName'),
  897. /** @property {boolean} isBtnDisabled - disable button on failed validation or active request **/
  898. isBtnDisabled: Em.computed.or('!isValidationPassed', 'isConnecting'),
  899. /** @property {object} requiredProperties - properties that necessary for database connection **/
  900. requiredProperties: function() {
  901. var propertiesMap = {
  902. OOZIE: ['oozie.db.schema.name', 'oozie.service.JPAService.jdbc.username', 'oozie.service.JPAService.jdbc.password', 'oozie.service.JPAService.jdbc.driver', 'oozie.service.JPAService.jdbc.url'],
  903. HIVE: ['ambari.hive.db.schema.name', 'javax.jdo.option.ConnectionUserName', 'javax.jdo.option.ConnectionPassword', 'javax.jdo.option.ConnectionDriverName', 'javax.jdo.option.ConnectionURL'],
  904. KERBEROS: ['kdc_hosts'],
  905. RANGER: App.get('isHadoop23Stack') ? ['db_user', 'db_password', 'db_name', 'ranger.jpa.jdbc.url', 'ranger.jpa.jdbc.driver'] :
  906. ['db_user', 'db_password', 'db_name', 'ranger_jdbc_connection_url', 'ranger_jdbc_driver']
  907. };
  908. return propertiesMap[this.get('parentView.service.serviceName')];
  909. }.property('App.isHadoop23Stack'),
  910. /** @property {Object} propertiesPattern - check pattern according to type of connection properties **/
  911. propertiesPattern: function() {
  912. var patterns = {
  913. db_connection_url: /jdbc\.url|connection_url|connectionurl|kdc_hosts/ig
  914. };
  915. if (this.get('parentView.service.serviceName') != "KERBEROS") {
  916. patterns.user_name = /(username|dblogin|db_user)$/ig;
  917. patterns.user_passwd = /(dbpassword|password|db_password)$/ig;
  918. }
  919. return patterns;
  920. }.property('parentView.service.serviceName'),
  921. /** @property {String} masterHostName - host name location of Master Component related to Service **/
  922. masterHostName: function() {
  923. var serviceMasterMap = {
  924. 'OOZIE': 'oozie_server_hosts',
  925. 'HDFS': 'hadoop_host',
  926. 'HIVE': 'hive_metastore_hosts',
  927. 'KERBEROS': 'kdc_hosts',
  928. 'RANGER': 'ranger_server_hosts'
  929. };
  930. return this.get('parentView.categoryConfigsAll').findProperty('name', serviceMasterMap[this.get('parentView.service.serviceName')]).get('value');
  931. }.property('parentView.service.serviceName', 'parentView.categoryConfigsAll.@each.value'),
  932. /** @property {Object} connectionProperties - service specific config values mapped for custom action request **/
  933. connectionProperties: function() {
  934. var propObj = {};
  935. for (var key in this.get('propertiesPattern')) {
  936. propObj[key] = this.getConnectionProperty(this.get('propertiesPattern')[key]);
  937. }
  938. if (this.get('parentView.service.serviceName') === 'RANGER') {
  939. var dbFlavor = this.get('parentView.categoryConfigsAll').findProperty('name','DB_FLAVOR').get('value'),
  940. /** TODO: Remove SQLA from the list of databases once Ranger DB_FLAVOR=SQLA is replaced with SQL Anywhere */
  941. databasesTypes = /MYSQL|POSTGRES|ORACLE|MSSQL|SQLA|Anywhere/gi,
  942. dbType = dbFlavor.match(databasesTypes)?dbFlavor.match(databasesTypes)[0].toLowerCase():'';
  943. if (dbType==='oracle') {
  944. // fixes oracle SYSDBA issue
  945. propObj['user_name'] = "\'%@ as sysdba\'".fmt(propObj['user_name']);
  946. }
  947. }
  948. return propObj;
  949. }.property('parentView.categoryConfigsAll.@each.value'),
  950. /**
  951. * Properties that stores in local storage used for handling
  952. * last success connection.
  953. *
  954. * @property {Object} preparedDBProperties
  955. **/
  956. preparedDBProperties: function() {
  957. var propObj = {};
  958. for (var key in this.get('propertiesPattern')) {
  959. var propName = this.getConnectionProperty(this.get('propertiesPattern')[key], true);
  960. propObj[propName] = this.get('parentView.categoryConfigsAll').findProperty('name', propName).get('value');
  961. }
  962. return propObj;
  963. }.property(),
  964. /** Check validation and load ambari properties **/
  965. didInsertElement: function() {
  966. var kdc = this.get('parentView.categoryConfigsAll').findProperty('name', 'kdc_type');
  967. if (kdc) {
  968. var name = kdc.get('value');
  969. if (name == 'Existing MIT KDC') {
  970. name = 'KDC';
  971. } else if (name == 'Existing IPA') {
  972. name = 'IPA';
  973. } else {
  974. name = 'AD';
  975. }
  976. App.popover(this.$(), {
  977. title: Em.I18n.t('services.service.config.database.btn.idle'),
  978. content: Em.I18n.t('installer.controls.checkConnection.popover').format(name),
  979. placement: 'right',
  980. trigger: 'hover'
  981. });
  982. }
  983. this.handlePropertiesValidation();
  984. this.getAmbariProperties();
  985. },
  986. /** On view destroy **/
  987. willDestroyElement: function() {
  988. this.set('isConnecting', false);
  989. this._super();
  990. },
  991. /**
  992. * Observer that take care about enabling/disabling button based on required properties validation.
  993. *
  994. * @method handlePropertiesValidation
  995. **/
  996. handlePropertiesValidation: function() {
  997. this.restore();
  998. var isValid = true;
  999. var properties = [].concat(this.get('requiredProperties'));
  1000. properties.push(this.get('hostNameProperty'));
  1001. properties.forEach(function(propertyName) {
  1002. var property = this.get('parentView.categoryConfigsAll').findProperty('name', propertyName);
  1003. if(property && !property.get('isValid')) isValid = false;
  1004. }, this);
  1005. this.set('isValidationPassed', isValid);
  1006. }.observes('parentView.categoryConfigsAll.@each.isValid', 'parentView.categoryConfigsAll.@each.value', 'databaseName'),
  1007. getConnectionProperty: function (regexp, isGetName) {
  1008. var _this = this;
  1009. var propertyName = _this.get('requiredProperties').filter(function (item) {
  1010. return regexp.test(item);
  1011. })[0];
  1012. return (isGetName) ? propertyName : _this.get('parentView.categoryConfigsAll').findProperty('name', propertyName).get('value');
  1013. },
  1014. /**
  1015. * Set up ambari properties required for custom action request
  1016. *
  1017. * @method getAmbariProperties
  1018. **/
  1019. getAmbariProperties: function() {
  1020. var clusterController = App.router.get('clusterController');
  1021. var _this = this;
  1022. if (!App.isEmptyObject(App.db.get('tmp', 'ambariProperties')) && !this.get('ambariProperties')) {
  1023. this.set('ambariProperties', App.db.get('tmp', 'ambariProperties'));
  1024. return;
  1025. }
  1026. if (App.isEmptyObject(clusterController.get('ambariProperties'))) {
  1027. clusterController.loadAmbariProperties().done(function(data) {
  1028. _this.formatAmbariProperties(data.RootServiceComponents.properties);
  1029. });
  1030. } else {
  1031. this.formatAmbariProperties(clusterController.get('ambariProperties'));
  1032. }
  1033. },
  1034. formatAmbariProperties: function(properties) {
  1035. var defaults = {
  1036. threshold: "60",
  1037. ambari_server_host: location.hostname,
  1038. check_execute_list : "db_connection_check"
  1039. };
  1040. var properties = App.permit(properties, ['jdk.name','jdk_location','java.home']);
  1041. var renameKey = function(oldKey, newKey) {
  1042. if (properties[oldKey]) {
  1043. defaults[newKey] = properties[oldKey];
  1044. delete properties[oldKey];
  1045. }
  1046. };
  1047. renameKey('java.home', 'java_home');
  1048. renameKey('jdk.name', 'jdk_name');
  1049. $.extend(properties, defaults);
  1050. App.db.set('tmp', 'ambariProperties', properties);
  1051. this.set('ambariProperties', properties);
  1052. },
  1053. /**
  1054. * `Action` method for starting connect to current database.
  1055. *
  1056. * @method connectToDatabase
  1057. **/
  1058. connectToDatabase: function() {
  1059. if (this.get('isBtnDisabled')) return;
  1060. this.set('isRequestResolved', false);
  1061. App.db.set('tmp', this.get('parentView.service.serviceName') + '_connection', {});
  1062. this.setConnectingStatus(true);
  1063. if (App.get('testMode')) {
  1064. this.startPolling();
  1065. } else {
  1066. this.runCheckConnection();
  1067. }
  1068. },
  1069. /**
  1070. * runs check connections methods depending on service
  1071. * @return {void}
  1072. * @method runCheckConnection
  1073. */
  1074. runCheckConnection: function() {
  1075. if (this.get('parentView.service.serviceName') === 'KERBEROS') {
  1076. this.runKDCCheck();
  1077. } else {
  1078. this.createCustomAction();
  1079. }
  1080. },
  1081. /**
  1082. * send ajax request to perforn kdc host check
  1083. * @return {App.ajax}
  1084. * @method runKDCCheck
  1085. */
  1086. runKDCCheck: function() {
  1087. return App.ajax.send({
  1088. name: 'admin.kerberos_security.test_connection',
  1089. sender: this,
  1090. data: {
  1091. kdcHostname: this.get('masterHostName')
  1092. },
  1093. success: 'onRunKDCCheckSuccess',
  1094. error: 'onCreateActionError'
  1095. });
  1096. },
  1097. /**
  1098. *
  1099. * @param data
  1100. */
  1101. onRunKDCCheckSuccess: function(data) {
  1102. var statusCode = {
  1103. success: 'REACHABLE',
  1104. failed: 'UNREACHABLE'
  1105. };
  1106. if (data == statusCode['success']) {
  1107. this.setResponseStatus('success');
  1108. } else {
  1109. this.setResponseStatus('failed');
  1110. }
  1111. this.set('responseFromServer', data);
  1112. },
  1113. /**
  1114. * Run custom action for database connection.
  1115. *
  1116. * @method createCustomAction
  1117. **/
  1118. createCustomAction: function() {
  1119. var isServiceInstalled = App.Service.find(this.get('parentView.service.serviceName')).get('isLoaded');
  1120. var params = $.extend(true, {}, { db_name: this.get('databaseName').toLowerCase() }, this.get('connectionProperties'), this.get('ambariProperties'));
  1121. App.ajax.send({
  1122. name: (isServiceInstalled) ? 'cluster.custom_action.create' : 'custom_action.create',
  1123. sender: this,
  1124. data: {
  1125. requestInfo: {
  1126. parameters: params
  1127. },
  1128. filteredHosts: [this.get('masterHostName')]
  1129. },
  1130. success: 'onCreateActionSuccess',
  1131. error: 'onCreateActionError'
  1132. });
  1133. },
  1134. /**
  1135. * Run updater if task is created successfully.
  1136. *
  1137. * @method onConnectActionS
  1138. **/
  1139. onCreateActionSuccess: function(data) {
  1140. this.set('currentRequestId', data.Requests.id);
  1141. App.ajax.send({
  1142. name: 'custom_action.request',
  1143. sender: this,
  1144. data: {
  1145. requestId: this.get('currentRequestId')
  1146. },
  1147. success: 'setCurrentTaskId'
  1148. });
  1149. },
  1150. setCurrentTaskId: function(data) {
  1151. this.set('currentTaskId', data.items[0].Tasks.id);
  1152. this.startPolling();
  1153. },
  1154. startPolling: function() {
  1155. if (this.get('isConnecting'))
  1156. this.getTaskInfo();
  1157. },
  1158. getTaskInfo: function() {
  1159. var request = App.ajax.send({
  1160. name: 'custom_action.request',
  1161. sender: this,
  1162. data: {
  1163. requestId: this.get('currentRequestId'),
  1164. taskId: this.get('currentTaskId')
  1165. },
  1166. success: 'getTaskInfoSuccess'
  1167. });
  1168. this.set('request', request);
  1169. },
  1170. getTaskInfoSuccess: function(data) {
  1171. var task = data.Tasks;
  1172. this.set('responseFromServer', {
  1173. stderr: task.stderr,
  1174. stdout: task.stdout
  1175. });
  1176. if (task.status === 'COMPLETED') {
  1177. var structuredOut = task.structured_out.db_connection_check;
  1178. if (structuredOut.exit_code != 0) {
  1179. this.set('responseFromServer', {
  1180. stderr: task.stderr,
  1181. stdout: task.stdout,
  1182. structuredOut: structuredOut.message
  1183. });
  1184. this.setResponseStatus('failed');
  1185. } else {
  1186. App.db.set('tmp', this.get('parentView.service.serviceName') + '_connection', this.get('preparedDBProperties'));
  1187. this.setResponseStatus('success');
  1188. }
  1189. }
  1190. if (task.status === 'FAILED') {
  1191. this.setResponseStatus('failed');
  1192. }
  1193. if (/PENDING|QUEUED|IN_PROGRESS/.test(task.status)) {
  1194. Em.run.later(this, function() {
  1195. this.startPolling();
  1196. }, this.get('pollInterval'));
  1197. }
  1198. },
  1199. onCreateActionError: function(jqXhr, status, errorMessage) {
  1200. this.setResponseStatus('failed');
  1201. this.set('responseFromServer', errorMessage);
  1202. },
  1203. setResponseStatus: function(isSuccess) {
  1204. var isSuccess = isSuccess == 'success';
  1205. this.setConnectingStatus(false);
  1206. this.set('responseCaption', isSuccess ? Em.I18n.t('services.service.config.database.connection.success') : Em.I18n.t('services.service.config.database.connection.failed'));
  1207. this.set('isConnectionSuccess', isSuccess);
  1208. this.set('isRequestResolved', true);
  1209. if (this.get('logsPopup')) {
  1210. var statusString = isSuccess ? 'common.success' : 'common.error';
  1211. this.set('logsPopup.header', Em.I18n.t('services.service.config.connection.logsPopup.header').format(this.get('databaseName'), Em.I18n.t(statusString)));
  1212. }
  1213. },
  1214. /**
  1215. * Switch captions and statuses for active/non-active request.
  1216. *
  1217. * @method setConnectionStatus
  1218. * @param {Boolean} [active]
  1219. */
  1220. setConnectingStatus: function(active) {
  1221. if (active) {
  1222. this.set('responseCaption', Em.I18n.t('services.service.config.database.connection.inProgress'));
  1223. }
  1224. this.set('controller.testConnectionInProgress', !!active);
  1225. this.set('btnCaption', !!active ? Em.I18n.t('services.service.config.database.btn.connecting') : Em.I18n.t('services.service.config.database.btn.idle'));
  1226. this.set('isConnecting', !!active);
  1227. },
  1228. /**
  1229. * Set view to init status.
  1230. *
  1231. * @method restore
  1232. **/
  1233. restore: function() {
  1234. if (this.get('request')) {
  1235. this.get('request').abort();
  1236. this.set('request', null);
  1237. }
  1238. this.set('responseCaption', null);
  1239. this.set('responseFromServer', null);
  1240. this.setConnectingStatus(false);
  1241. this.set('isRequestResolved', false);
  1242. },
  1243. /**
  1244. * `Action` method for showing response from server in popup.
  1245. *
  1246. * @method showLogsPopup
  1247. **/
  1248. showLogsPopup: function() {
  1249. if (this.get('isConnectionSuccess')) return;
  1250. var _this = this;
  1251. var statusString = this.get('isRequestResolved') ? 'common.error' : 'common.testing';
  1252. var popup = App.showAlertPopup(Em.I18n.t('services.service.config.connection.logsPopup.header').format(this.get('databaseName'), Em.I18n.t(statusString)), null, function () {
  1253. _this.set('logsPopup', null);
  1254. });
  1255. popup.reopen({
  1256. onClose: function () {
  1257. this._super();
  1258. _this.set('logsPopup', null);
  1259. }
  1260. });
  1261. if (typeof this.get('responseFromServer') == 'object') {
  1262. popup.set('bodyClass', Em.View.extend({
  1263. checkDBConnectionView: _this,
  1264. templateName: require('templates/common/error_log_body'),
  1265. openedTask: function () {
  1266. return this.get('checkDBConnectionView.responseFromServer');
  1267. }.property('checkDBConnectionView.responseFromServer.stderr', 'checkDBConnectionView.responseFromServer.stdout', 'checkDBConnectionView.responseFromServer.structuredOut')
  1268. }));
  1269. } else {
  1270. popup.set('body', this.get('responseFromServer'));
  1271. }
  1272. this.set('logsPopup', popup);
  1273. return popup;
  1274. }
  1275. });
  1276. /**
  1277. * View for switch group text
  1278. *
  1279. * @type {Em.View}
  1280. */
  1281. App.SwitchToGroupView = Em.View.extend({
  1282. group: null,
  1283. tagName: 'a',
  1284. classNames: ['action'],
  1285. template: Ember.Handlebars.compile('{{ view.group.switchGroupTextShort }}'),
  1286. didInsertElement: function() {
  1287. var self = this;
  1288. App.tooltip($(self.get('element')), {
  1289. placement: 'top',
  1290. title: self.get('group.switchGroupTextFull')
  1291. });
  1292. },
  1293. willDestroyElement: function() {
  1294. $(this.get('element')).tooltip('destroy');
  1295. },
  1296. click: function() {
  1297. this.get('controller').selectConfigGroup({context: this.get('group')});
  1298. }
  1299. });
  1300. /**
  1301. * View with input field used to repo-version URLs
  1302. * @type {*}
  1303. */
  1304. App.BaseUrlTextField = Ember.TextField.extend({
  1305. layout: Ember.Handlebars.compile('<div class="pull-left">{{yield}}</div> {{#if view.valueWasChanged}}<div class="pull-right"><a class="btn-small" {{action "restoreValue" target="view"}}><i class="icon-undo"></i></a></div>{{/if}}'),
  1306. /**
  1307. * Binding in the template
  1308. * @type {App.RepositoryVersion}
  1309. */
  1310. repository: null,
  1311. /**
  1312. * @type {string}
  1313. */
  1314. valueBinding: 'repository.baseUrl',
  1315. /**
  1316. * @type {string}
  1317. */
  1318. defaultValue: '',
  1319. /**
  1320. * validate base URL
  1321. */
  1322. validate: function () {
  1323. if (this.get('repository.skipValidation')) {
  1324. this.set('repository.hasError', false);
  1325. } else {
  1326. this.set('repository.hasError', !(validator.isValidBaseUrl(this.get('value'))));
  1327. }
  1328. this.get('parentView').uiValidation();
  1329. }.observes('value', 'repository.skipValidation'),
  1330. /**
  1331. * Determines if user have put some new value
  1332. * @type {boolean}
  1333. */
  1334. valueWasChanged: function () {
  1335. return this.get('value') !== this.get('defaultValue');
  1336. }.property('value', 'defaultValue'),
  1337. didInsertElement: function () {
  1338. this.set('defaultValue', this.get('value'));
  1339. },
  1340. /**
  1341. * Restore value and unset error-flag
  1342. * @method restoreValue
  1343. */
  1344. restoreValue: function () {
  1345. this.set('value', this.get('defaultValue'));
  1346. }
  1347. });