controls_view.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  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. /**
  20. * Abstract view for config fields.
  21. * Add popover support to control
  22. */
  23. App.ServiceConfigPopoverSupport = Ember.Mixin.create({
  24. /**
  25. * Config object. It will instance of App.ServiceConfigProperty
  26. */
  27. serviceConfig: null,
  28. attributeBindings:['readOnly'],
  29. isPopoverEnabled: true,
  30. didInsertElement: function () {
  31. $('body').tooltip({
  32. selector: '[data-toggle=tooltip]',
  33. placement: 'top'
  34. });
  35. // if description for this serviceConfig not exist, then no need to show popover
  36. if (this.get('isPopoverEnabled') !== 'false' && this.get('serviceConfig.description')) {
  37. App.popover(this.$(), {
  38. title: Em.I18n.t('installer.controls.serviceConfigPopover.title').format(
  39. this.get('serviceConfig.displayName'),
  40. (this.get('serviceConfig.displayName') == this.get('serviceConfig.name')) ? '' : this.get('serviceConfig.name')
  41. ),
  42. content: this.get('serviceConfig.description'),
  43. placement: 'right',
  44. trigger: 'hover'
  45. });
  46. }
  47. },
  48. willDestroyElement: function() {
  49. this.$().popover('destroy');
  50. },
  51. readOnly: function () {
  52. return !this.get('serviceConfig.isEditable');
  53. }.property('serviceConfig.isEditable')
  54. });
  55. /**
  56. * mixin set class that serve as unique element identificator,
  57. * id not used in order to avoid collision with ember ids
  58. */
  59. App.ServiceConfigCalculateId = Ember.Mixin.create({
  60. idClass: Ember.computed(function () {
  61. var label = Em.get(this, 'serviceConfig.name') ? Em.get(this, 'serviceConfig.name').toLowerCase().replace(/\./g, '-') : '',
  62. fileName = Em.get(this, 'serviceConfig.filename') ? Em.get(this, 'serviceConfig.filename').toLowerCase().replace(/\./g, '-') : '',
  63. group = Em.get(this, 'serviceConfig.group.name') || 'default';
  64. isOrigin = Em.get(this, 'serviceConfig.compareConfigs.length') > 0 ? '-origin' : '';
  65. return 'service-config-' + label + '-' + fileName + '-' + group + isOrigin;
  66. }),
  67. classNameBindings: 'idClass'
  68. });
  69. /**
  70. * Default input control
  71. * @type {*}
  72. */
  73. App.ServiceConfigTextField = Ember.TextField.extend(App.ServiceConfigPopoverSupport, App.ServiceConfigCalculateId, {
  74. valueBinding: 'serviceConfig.value',
  75. classNameBindings: 'textFieldClassName',
  76. placeholderBinding: 'serviceConfig.defaultValue',
  77. keyPress: function (event) {
  78. if (event.keyCode == 13) {
  79. return false;
  80. }
  81. },
  82. //Set editDone true for last edited config text field parameter
  83. focusOut: function (event) {
  84. this.get('serviceConfig').set("editDone", true);
  85. },
  86. //Set editDone false for all current category config text field parameter
  87. focusIn: function (event) {
  88. if (!this.get('serviceConfig.isOverridden') && !this.get('serviceConfig.isComparison')) {
  89. this.get("parentView.categoryConfigsAll").setEach("editDone", false);
  90. }
  91. },
  92. textFieldClassName: function () {
  93. if (this.get('serviceConfig.unit')) {
  94. return ['input-small'];
  95. } else if (this.get('serviceConfig.displayType') === 'principal') {
  96. return ['span12'];
  97. } else {
  98. return ['span9'];
  99. }
  100. }.property('serviceConfig.displayType', 'serviceConfig.unit')
  101. });
  102. /**
  103. * Customized input control with Units type specified
  104. * @type {Em.View}
  105. */
  106. App.ServiceConfigTextFieldWithUnit = Ember.View.extend(App.ServiceConfigPopoverSupport, {
  107. valueBinding: 'serviceConfig.value',
  108. classNames: ['input-append', 'with-unit'],
  109. placeholderBinding: 'serviceConfig.defaultValue',
  110. templateName: require('templates/wizard/controls_service_config_textfield_with_unit')
  111. });
  112. /**
  113. * Password control
  114. * @type {*}
  115. */
  116. App.ServiceConfigPasswordField = Ember.TextField.extend({
  117. serviceConfig: null,
  118. type: 'password',
  119. attributeBindings:['readOnly'],
  120. valueBinding: 'serviceConfig.value',
  121. classNames: [ 'span4' ],
  122. placeholder: Em.I18n.t('form.item.placeholders.typePassword'),
  123. template: Ember.Handlebars.compile('{{view view.retypePasswordView}}'),
  124. keyPress: function (event) {
  125. if (event.keyCode == 13) {
  126. return false;
  127. }
  128. },
  129. retypePasswordView: Ember.TextField.extend({
  130. placeholder: Em.I18n.t('form.passwordRetype'),
  131. attributeBindings:['readOnly'],
  132. type: 'password',
  133. classNames: [ 'span4', 'retyped-password' ],
  134. keyPress: function (event) {
  135. if (event.keyCode == 13) {
  136. return false;
  137. }
  138. },
  139. valueBinding: 'parentView.serviceConfig.retypedPassword',
  140. readOnly: function () {
  141. return !this.get('parentView.serviceConfig.isEditable');
  142. }.property('parentView.serviceConfig.isEditable')
  143. }),
  144. readOnly: function () {
  145. return !this.get('serviceConfig.isEditable');
  146. }.property('serviceConfig.isEditable')
  147. });
  148. /**
  149. * Textarea control
  150. * @type {*}
  151. */
  152. App.ServiceConfigTextArea = Ember.TextArea.extend(App.ServiceConfigPopoverSupport, App.ServiceConfigCalculateId, {
  153. valueBinding: 'serviceConfig.value',
  154. rows: 4,
  155. classNames: ['span9', 'directories']
  156. });
  157. /**
  158. * Textarea control for content type
  159. * @type {*}
  160. */
  161. App.ServiceConfigTextAreaContent = Ember.TextArea.extend(App.ServiceConfigPopoverSupport, App.ServiceConfigCalculateId, {
  162. valueBinding: 'serviceConfig.value',
  163. rows: 20,
  164. classNames: ['span10']
  165. });
  166. /**
  167. * Textarea control with bigger height
  168. * @type {*}
  169. */
  170. App.ServiceConfigBigTextArea = App.ServiceConfigTextArea.extend(App.ServiceConfigCalculateId, {
  171. rows: 10
  172. });
  173. /**
  174. * Checkbox control
  175. * @type {*}
  176. */
  177. App.ServiceConfigCheckbox = Ember.Checkbox.extend(App.ServiceConfigPopoverSupport, App.ServiceConfigCalculateId, {
  178. allowedPairs: {
  179. 'trueFalse': ["true", "false"],
  180. 'YesNo': ["Yes", "No"],
  181. 'YESNO': ["YES", "NO"],
  182. 'yesNo': ["yes", "no"]
  183. },
  184. trueValue: true,
  185. falseValue: false,
  186. checked: false,
  187. /**
  188. * set appropriate config values pair
  189. * to define which value is positive (checked) property
  190. * and what value is negative (unchecked) proeprty
  191. */
  192. didInsertElement: function() {
  193. this._super();
  194. this.addObserver('serviceConfig.value', this, 'toggleChecker');
  195. Object.keys(this.get('allowedPairs')).forEach(function(key) {
  196. if (this.get('allowedPairs')[key].contains(this.get('serviceConfig.value'))) {
  197. this.set('trueValue', this.get('allowedPairs')[key][0]);
  198. this.set('falseValue', this.get('allowedPairs')[key][1]);
  199. }
  200. }, this);
  201. this.set('checked', this.get('serviceConfig.value') === this.get('trueValue'))
  202. },
  203. willDestroyElement: function() {
  204. this.removeObserver('serviceConfig.value', this, 'checkedBinding');
  205. },
  206. /***
  207. * defines if checkbox value appropriate to the config value
  208. * @returns {boolean}
  209. */
  210. isNotAppropriateValue: function() {
  211. return this.get('serviceConfig.value') !== this.get(this.get('checked') + 'Value');
  212. },
  213. /**
  214. * change service config value if click on checkbox
  215. */
  216. toggleValue: function() {
  217. if (this.isNotAppropriateValue()){
  218. this.set('serviceConfig.value', this.get(this.get('checked') + 'Value'));
  219. this.get('serviceConfig').set("editDone", true);
  220. }
  221. }.observes('checked'),
  222. /**
  223. * change checkbox value if click on undo
  224. */
  225. toggleChecker: function() {
  226. if (this.isNotAppropriateValue())
  227. this.set('checked', !this.get('checked'));
  228. },
  229. disabled: function () {
  230. return !this.get('serviceConfig.isEditable');
  231. }.property('serviceConfig.isEditable'),
  232. //Set editDone false for all current category config text field parameter
  233. focusIn: function (event) {
  234. if (!this.get('serviceConfig.isOverridden') && !this.get('serviceConfig.isComparison')) {
  235. this.get("parentView.categoryConfigsAll").setEach("editDone", false);
  236. }
  237. }
  238. });
  239. /**
  240. * Checkbox control which can hide or show dependent properties
  241. * @type {*|void}
  242. */
  243. App.ServiceConfigCheckboxWithDependencies = App.ServiceConfigCheckbox.extend({
  244. didInsertElement: function() {
  245. this._super();
  246. this.toggleDependentConfigs();
  247. },
  248. toggleDependentConfigs: function() {
  249. if (this.get('serviceConfig.dependentConfigPattern')) {
  250. if (this.get('serviceConfig.dependentConfigPattern') === "CATEGORY") {
  251. this.disableEnableCategoryCongis();
  252. } else {
  253. this.showHideDependentConfigs();
  254. }
  255. }
  256. }.observes('checked'),
  257. disableEnableCategoryCongis: function () {
  258. this.get('categoryConfigsAll').setEach('isEditable', this.get('checked'));
  259. this.set('serviceConfig.isEditable', true);
  260. },
  261. showHideDependentConfigs: function () {
  262. this.get('categoryConfigsAll').forEach(function (c) {
  263. if (c.get('name').match(this.get('serviceConfig.dependentConfigPattern')) && c.get('name') != this.get('serviceConfig.name'))
  264. c.set('isVisible', this.get('checked'))
  265. }, this);
  266. }
  267. });
  268. App.ServiceConfigRadioButtons = Ember.View.extend(App.ServiceConfigCalculateId, {
  269. templateName: require('templates/wizard/controls_service_config_radio_buttons'),
  270. didInsertElement: function () {
  271. // on page render, automatically populate JDBC URLs only for default database settings
  272. // so as to not lose the user's customizations on these fields
  273. if (['addServiceController', 'installerController'].contains(this.get('controller.wizardController.name'))) {
  274. if (/^New\s\w+\sDatabase$/.test(this.get('serviceConfig.value')) || this.dontUseHandleDbConnection.contains(this.get('serviceConfig.name'))) {
  275. this.onOptionsChange();
  276. } else {
  277. this.handleDBConnectionProperty();
  278. }
  279. }
  280. },
  281. /**
  282. * properties with these names don'use handleDBConnectionProperty mathod
  283. */
  284. dontUseHandleDbConnection: ['DB_FLAVOR', 'authentication_method'],
  285. configs: function () {
  286. if (this.get('controller.name') == 'mainServiceInfoConfigsController') return this.get('categoryConfigsAll');
  287. return this.get('categoryConfigsAll').filterProperty('isObserved', true);
  288. }.property('categoryConfigsAll'),
  289. serviceConfig: null,
  290. categoryConfigsAll: null,
  291. onOptionsChange: function () {
  292. // The following if condition will be satisfied only for installer wizard flow
  293. if (this.get('configs').length) {
  294. var connectionUrl = this.get('connectionUrl');
  295. var dbClass = this.get('dbClass');
  296. if (connectionUrl) {
  297. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  298. var hiveDbType = this.get('parentView.serviceConfigs').findProperty('name', 'hive_database_type');
  299. switch (this.get('serviceConfig.value')) {
  300. case 'New MySQL Database':
  301. case 'Existing MySQL Database':
  302. connectionUrl.set('value', "jdbc:mysql://" + this.get('hostName') + "/" + this.get('databaseName') + "?createDatabaseIfNotExist=true");
  303. dbClass.set('value', "com.mysql.jdbc.Driver");
  304. Em.set(hiveDbType, 'value', 'mysql');
  305. break;
  306. case Em.I18n.t('services.service.config.hive.oozie.postgresql'):
  307. connectionUrl.set('value', "jdbc:postgresql://" + this.get('hostName') + ":5432/" + this.get('databaseName'));
  308. dbClass.set('value', "org.postgresql.Driver");
  309. Em.set(hiveDbType, 'value', 'postgres');
  310. break;
  311. case 'Existing Oracle Database':
  312. connectionUrl.set('value', "jdbc:oracle:thin:@//" + this.get('hostName') + ":1521/" + this.get('databaseName'));
  313. dbClass.set('value', "oracle.jdbc.driver.OracleDriver");
  314. Em.set(hiveDbType, 'value', 'oracle');
  315. break;
  316. case 'Existing MSSQL Server database with SQL authentication':
  317. connectionUrl.set('value', "jdbc:sqlserver://" + this.get('hostName') + ";databaseName=" + this.get('databaseName'));
  318. dbClass.set('value', "com.microsoft.sqlserver.jdbc.SQLServerDriver");
  319. Em.set(hiveDbType, 'value', 'mssql');
  320. break;
  321. case 'Existing MSSQL Server database with integrated authentication':
  322. connectionUrl.set('value', "jdbc:sqlserver://" + this.get('hostName') + ";databaseName=" + this.get('databaseName') + ";integratedSecurity=true");
  323. dbClass.set('value', "com.microsoft.sqlserver.jdbc.SQLServerDriver");
  324. Em.set(hiveDbType, 'value', 'mssql');
  325. break;
  326. }
  327. var isNotExistingMySQLServer = this.get('serviceConfig.value') !== 'Existing MSSQL Server database with integrated authentication';
  328. this.get('categoryConfigsAll').findProperty('name', 'javax.jdo.option.ConnectionUserName').setProperties({
  329. isVisible: isNotExistingMySQLServer,
  330. isRequired: isNotExistingMySQLServer
  331. });
  332. this.get('categoryConfigsAll').findProperty('name', 'javax.jdo.option.ConnectionPassword').setProperties({
  333. isVisible: isNotExistingMySQLServer,
  334. isRequired: isNotExistingMySQLServer
  335. });
  336. } else if (this.get('serviceConfig.serviceName') === 'OOZIE') {
  337. switch (this.get('serviceConfig.value')) {
  338. case 'New Derby Database':
  339. connectionUrl.set('value', "jdbc:derby:${oozie.data.dir}/${oozie.db.schema.name}-db;create=true");
  340. dbClass.set('value', "org.apache.derby.jdbc.EmbeddedDriver");
  341. break;
  342. case 'Existing MySQL Database':
  343. connectionUrl.set('value', "jdbc:mysql://" + this.get('hostName') + "/" + this.get('databaseName'));
  344. dbClass.set('value', "com.mysql.jdbc.Driver");
  345. break;
  346. case Em.I18n.t('services.service.config.hive.oozie.postgresql'):
  347. connectionUrl.set('value', "jdbc:postgresql://" + this.get('hostName') + ":5432/" + this.get('databaseName'));
  348. dbClass.set('value', "org.postgresql.Driver");
  349. break;
  350. case 'Existing Oracle Database':
  351. connectionUrl.set('value', "jdbc:oracle:thin:@//" + this.get('hostName') + ":1521/" + this.get('databaseName'));
  352. dbClass.set('value', "oracle.jdbc.driver.OracleDriver");
  353. break;
  354. case 'Existing MSSQL Server database with SQL authentication':
  355. connectionUrl.set('value', "jdbc:sqlserver://" + this.get('hostName') + ";databaseName=" + this.get('databaseName'));
  356. dbClass.set('value', "com.microsoft.sqlserver.jdbc.SQLServerDriver");
  357. break;
  358. case 'Existing MSSQL Server database with integrated authentication':
  359. connectionUrl.set('value', "jdbc:sqlserver://" + this.get('hostName') + ";databaseName=" + this.get('databaseName') + ";integratedSecurity=true");
  360. dbClass.set('value', "com.microsoft.sqlserver.jdbc.SQLServerDriver");
  361. break;
  362. }
  363. isNotExistingMySQLServer = this.get('serviceConfig.value') !== 'Existing MSSQL Server database with integrated authentication';
  364. this.get('categoryConfigsAll').findProperty('name', 'oozie.service.JPAService.jdbc.username').setProperties({
  365. isVisible: isNotExistingMySQLServer,
  366. isRequired: isNotExistingMySQLServer
  367. });
  368. this.get('categoryConfigsAll').findProperty('name', 'oozie.service.JPAService.jdbc.password').setProperties({
  369. isVisible: isNotExistingMySQLServer,
  370. isRequired: isNotExistingMySQLServer
  371. });
  372. }
  373. connectionUrl.set('defaultValue', connectionUrl.get('value'));
  374. }
  375. }
  376. }.observes('databaseName', 'hostName'),
  377. nameBinding: 'serviceConfig.radioName',
  378. databaseNameProperty: function () {
  379. switch (this.get('serviceConfig.serviceName')) {
  380. case 'HIVE':
  381. return this.get('categoryConfigsAll').findProperty('name', 'ambari.hive.db.schema.name');
  382. case 'OOZIE':
  383. return this.get('categoryConfigsAll').findProperty('name', 'oozie.db.schema.name');
  384. default:
  385. return null;
  386. }
  387. }.property('serviceConfig.serviceName'),
  388. databaseName: function () {
  389. return this.get('databaseNameProperty.value');
  390. }.property('databaseNameProperty.value'),
  391. hostNameProperty: function () {
  392. var value = this.get('serviceConfig.value');
  393. var returnValue;
  394. var hostname;
  395. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  396. switch (value) {
  397. case 'New MySQL Database':
  398. hostname = this.get('categoryConfigsAll').findProperty('name', 'hive_ambari_host');
  399. break;
  400. case 'Existing MySQL Database':
  401. hostname = this.get('categoryConfigsAll').findProperty('name', 'hive_existing_mysql_host');
  402. break;
  403. case Em.I18n.t('services.service.config.hive.oozie.postgresql'):
  404. hostname = this.get('categoryConfigsAll').findProperty('name', 'hive_existing_postgresql_host');
  405. break;
  406. case 'Existing Oracle Database':
  407. hostname = this.get('categoryConfigsAll').findProperty('name', 'hive_existing_oracle_host');
  408. break;
  409. case 'Existing MSSQL Server database with SQL authentication':
  410. hostname = this.get('categoryConfigsAll').findProperty('name', 'hive_existing_mssql_server_host');
  411. break;
  412. case 'Existing MSSQL Server database with integrated authentication':
  413. hostname = this.get('categoryConfigsAll').findProperty('name', 'hive_existing_mssql_server_2_host');
  414. break;
  415. }
  416. if (hostname) {
  417. returnValue = hostname;
  418. } else {
  419. returnValue = this.get('categoryConfigsAll').findProperty('name', 'hive_hostname');
  420. }
  421. } else if (this.get('serviceConfig.serviceName') === 'OOZIE') {
  422. switch (value) {
  423. case 'New Derby Database':
  424. hostname = this.get('categoryConfigsAll').findProperty('name', 'oozie_ambari_host');
  425. break;
  426. case 'Existing MySQL Database':
  427. hostname = this.get('categoryConfigsAll').findProperty('name', 'oozie_existing_mysql_host');
  428. break;
  429. case Em.I18n.t('services.service.config.hive.oozie.postgresql'):
  430. hostname = this.get('categoryConfigsAll').findProperty('name', 'oozie_existing_postgresql_host');
  431. break;
  432. case 'Existing Oracle Database':
  433. hostname = this.get('categoryConfigsAll').findProperty('name', 'oozie_existing_oracle_host');
  434. break;
  435. case 'Existing MSSQL Server database with SQL authentication':
  436. hostname = this.get('categoryConfigsAll').findProperty('name', 'oozie_existing_mssql_server_host');
  437. break;
  438. case 'Existing MSSQL Server database with integrated authentication':
  439. hostname = this.get('categoryConfigsAll').findProperty('name', 'oozie_existing_mssql_server_2_host');
  440. break;
  441. }
  442. if (hostname) {
  443. returnValue = hostname;
  444. } else {
  445. returnValue = this.get('categoryConfigsAll').findProperty('name', 'oozie_hostname');
  446. }
  447. }
  448. return returnValue;
  449. }.property('serviceConfig.serviceName', 'serviceConfig.value'),
  450. hostName: function () {
  451. return this.get('hostNameProperty.value');
  452. }.property('hostNameProperty.value'),
  453. connectionUrl: function () {
  454. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  455. return this.get('categoryConfigsAll').findProperty('name', 'javax.jdo.option.ConnectionURL');
  456. } else {
  457. return this.get('categoryConfigsAll').findProperty('name', 'oozie.service.JPAService.jdbc.url');
  458. }
  459. }.property('serviceConfig.serviceName'),
  460. dbClass: function () {
  461. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  462. return this.get('categoryConfigsAll').findProperty('name', 'javax.jdo.option.ConnectionDriverName');
  463. } else {
  464. return this.get('categoryConfigsAll').findProperty('name', 'oozie.service.JPAService.jdbc.driver');
  465. }
  466. }.property('serviceConfig.serviceName'),
  467. /**
  468. * `Observer` that add <code>additionalView</code> to <code>App.ServiceConfigProperty</code>
  469. * that responsible for (if existing db selected)
  470. * 1. checking database connection
  471. * 2. showing jdbc driver setup warning msg.
  472. *
  473. * @method handleDBConnectionProperty
  474. **/
  475. handleDBConnectionProperty: function() {
  476. if (this.dontUseHandleDbConnection.contains(this.get('serviceConfig.name')))
  477. return;
  478. var handledProperties = ['oozie_database', 'hive_database'];
  479. var currentValue = this.get('serviceConfig.value');
  480. var databases = /MySQL|PostgreSQL|Oracle|Derby|MSSQL/gi;
  481. var currentDB = currentValue.match(databases)[0];
  482. var databasesTypes = /MySQL|PostgreS|Oracle|Derby|MSSQL/gi;
  483. var currentDBType = currentValue.match(databasesTypes)[0];
  484. var existingDatabase = /existing/gi.test(currentValue);
  485. // db connection check button show up if existed db selected
  486. var propertyAppendTo1 = this.get('categoryConfigsAll').findProperty('displayName', 'Database URL');
  487. if (currentDB && existingDatabase) {
  488. if (handledProperties.contains(this.get('serviceConfig.name'))) {
  489. if (propertyAppendTo1) propertyAppendTo1.set('additionalView', App.CheckDBConnectionView.extend({databaseName: currentDB}));
  490. }
  491. } else {
  492. propertyAppendTo1.set('additionalView', null);
  493. }
  494. // warning msg under database type radio buttons, to warn the user to setup jdbc driver if existed db selected
  495. var propertyHive = this.get('categoryConfigsAll').findProperty('displayName', 'Hive Database');
  496. var propertyOozie = this.get('categoryConfigsAll').findProperty('displayName', 'Oozie Database');
  497. var propertyAppendTo2 = propertyHive ? propertyHive : propertyOozie;
  498. if (currentDB && existingDatabase) {
  499. if (handledProperties.contains(this.get('serviceConfig.name'))) {
  500. if (propertyAppendTo2) {
  501. propertyAppendTo2.set('additionalView', Ember.View.extend({
  502. template: Ember.Handlebars.compile('<div class="alert">{{{view.message}}}</div>'),
  503. message: Em.I18n.t('services.service.config.database.msg.jdbcSetup').format(currentDBType.toLowerCase(), currentDBType.toLowerCase())
  504. }));
  505. }
  506. }
  507. } else {
  508. propertyAppendTo2.set('additionalView', null);
  509. }
  510. }.observes('serviceConfig.value'),
  511. optionsBinding: 'serviceConfig.options'
  512. });
  513. App.ServiceConfigRadioButton = Ember.Checkbox.extend({
  514. tagName: 'input',
  515. attributeBindings: ['type', 'name', 'value', 'checked', 'disabled'],
  516. checked: false,
  517. type: 'radio',
  518. name: null,
  519. value: null,
  520. didInsertElement: function () {
  521. console.debug('App.ServiceConfigRadioButton.didInsertElement');
  522. if (this.get('parentView.serviceConfig.value') === this.get('value')) {
  523. console.debug(this.get('name') + ":" + this.get('value') + ' is checked');
  524. this.set('checked', true);
  525. }
  526. },
  527. click: function () {
  528. this.set('checked', true);
  529. console.debug('App.ServiceConfigRadioButton.click');
  530. this.onChecked();
  531. },
  532. onChecked: function () {
  533. // Wrapping the call with Ember.run.next prevents a problem where setting isVisible on component
  534. // causes JS error due to re-rendering. For example, this occurs when switching the Config Group
  535. // in Service Config page
  536. Em.run.next(this, function() {
  537. console.debug('App.ServiceConfigRadioButton.onChecked');
  538. this.set('parentView.serviceConfig.value', this.get('value'));
  539. var components = this.get('parentView.serviceConfig.options');
  540. if (components) {
  541. components.forEach(function (_component) {
  542. if (_component.foreignKeys) {
  543. _component.foreignKeys.forEach(function (_componentName) {
  544. if (this.get('parentView.parentView.serviceConfigs').someProperty('name', _componentName)) {
  545. var component = this.get('parentView.parentView.serviceConfigs').findProperty('name', _componentName);
  546. component.set('isVisible', _component.displayName === this.get('value'));
  547. }
  548. }, this);
  549. }
  550. }, this);
  551. }
  552. });
  553. }.observes('checked'),
  554. disabled: function () {
  555. return !this.get('parentView.serviceConfig.isEditable') ||
  556. !['addServiceController', 'installerController'].contains(this.get('controller.wizardController.name')) && /^New\s\w+\sDatabase$/.test(this.get('value'));
  557. }.property('parentView.serviceConfig.isEditable')
  558. });
  559. App.ServiceConfigComboBox = Ember.Select.extend(App.ServiceConfigPopoverSupport, App.ServiceConfigCalculateId, {
  560. contentBinding: 'serviceConfig.options',
  561. selectionBinding: 'serviceConfig.value',
  562. placeholderBinding: 'serviceConfig.defaultValue',
  563. classNames: [ 'span3' ]
  564. });
  565. /**
  566. * Base component for host config with popover support
  567. */
  568. App.ServiceConfigHostPopoverSupport = Ember.Mixin.create({
  569. /**
  570. * Config object. It will instance of App.ServiceConfigProperty
  571. */
  572. serviceConfig: null,
  573. didInsertElement: function () {
  574. App.popover(this.$(), {
  575. title: this.get('serviceConfig.displayName'),
  576. content: this.get('serviceConfig.description'),
  577. placement: 'right',
  578. trigger: 'hover'
  579. });
  580. }
  581. });
  582. /**
  583. * Master host component.
  584. * Show hostname without ability to edit it
  585. * @type {*}
  586. */
  587. App.ServiceConfigMasterHostView = Ember.View.extend(App.ServiceConfigHostPopoverSupport, App.ServiceConfigCalculateId, {
  588. classNames: ['master-host', 'span6'],
  589. valueBinding: 'serviceConfig.value',
  590. template: Ember.Handlebars.compile('{{value}}')
  591. });
  592. /**
  593. * text field property view that enables possibility
  594. * for check connectio
  595. * @type {*}
  596. */
  597. App.checkConnectionView = App.ServiceConfigTextField.extend({
  598. didInsertElement: function() {
  599. this._super();
  600. var kdc = this.get('categoryConfigsAll').findProperty('name', 'kdc_type');
  601. var propertyAppendTo = this.get('categoryConfigsAll').findProperty('name', 'domains');
  602. if (propertyAppendTo) propertyAppendTo.set('additionalView', App.CheckDBConnectionView.extend({databaseName: kdc && kdc.get('value')}));
  603. }
  604. });
  605. /**
  606. * Show value as plain label in italics
  607. * @type {*}
  608. */
  609. App.ServiceConfigLabelView = Ember.View.extend(App.ServiceConfigHostPopoverSupport, App.ServiceConfigCalculateId, {
  610. classNames: ['master-host', 'span6'],
  611. valueBinding: 'serviceConfig.value',
  612. template: Ember.Handlebars.compile('<i>{{view.value}}</i>')
  613. });
  614. /**
  615. * Base component to display Multiple hosts
  616. * @type {*}
  617. */
  618. App.ServiceConfigMultipleHostsDisplay = Ember.Mixin.create(App.ServiceConfigHostPopoverSupport, App.ServiceConfigCalculateId, {
  619. hasNoHosts: function () {
  620. console.log('view', this.get('viewName')); //to know which View cause errors
  621. console.log('controller', this.get('controller').name); //should be slaveComponentGroupsController
  622. if (!this.get('value')) {
  623. return true;
  624. }
  625. return this.get('value').length === 0;
  626. }.property('value'),
  627. hasOneHost: function () {
  628. return this.get('value').length === 1;
  629. }.property('value'),
  630. hasMultipleHosts: function () {
  631. return this.get('value').length > 1;
  632. }.property('value'),
  633. otherLength: function () {
  634. var len = this.get('value').length;
  635. if (len > 2) {
  636. return Em.I18n.t('installer.controls.serviceConfigMultipleHosts.others').format(len - 1);
  637. } else {
  638. return Em.I18n.t('installer.controls.serviceConfigMultipleHosts.other');
  639. }
  640. }.property('value')
  641. });
  642. /**
  643. * Multiple master host component.
  644. * Show hostnames without ability to edit it
  645. * @type {*}
  646. */
  647. App.ServiceConfigMasterHostsView = Ember.View.extend(App.ServiceConfigMultipleHostsDisplay, App.ServiceConfigCalculateId, {
  648. viewName: "serviceConfigMasterHostsView",
  649. valueBinding: 'serviceConfig.value',
  650. classNames: ['master-hosts', 'span6'],
  651. templateName: require('templates/wizard/master_hosts'),
  652. /**
  653. * Onclick handler for link
  654. */
  655. showHosts: function () {
  656. var serviceConfig = this.get('serviceConfig');
  657. App.ModalPopup.show({
  658. header: Em.I18n.t('installer.controls.serviceConfigMasterHosts.header').format(serviceConfig.category),
  659. bodyClass: Ember.View.extend({
  660. serviceConfig: serviceConfig,
  661. templateName: require('templates/wizard/master_hosts_popup')
  662. }),
  663. secondary: null
  664. });
  665. }
  666. });
  667. /**
  668. * Show tabs list for slave hosts
  669. * @type {*}
  670. */
  671. App.SlaveComponentGroupsMenu = Em.CollectionView.extend(App.ServiceConfigCalculateId, {
  672. content: function () {
  673. return this.get('controller.componentGroups');
  674. }.property('controller.componentGroups'),
  675. tagName: 'ul',
  676. classNames: ["nav", "nav-tabs"],
  677. itemViewClass: Em.View.extend({
  678. classNameBindings: ["active"],
  679. active: function () {
  680. return this.get('content.active');
  681. }.property('content.active'),
  682. errorCount: function () {
  683. return this.get('content.properties').filterProperty('isValid', false).filterProperty('isVisible', true).get('length');
  684. }.property('content.properties.@each.isValid', 'content.properties.@each.isVisible'),
  685. templateName: require('templates/wizard/controls_slave_component_groups_menu')
  686. })
  687. });
  688. /**
  689. * <code>Add group</code> button
  690. * @type {*}
  691. */
  692. App.AddSlaveComponentGroupButton = Ember.View.extend(App.ServiceConfigCalculateId, {
  693. tagName: 'span',
  694. slaveComponentName: null,
  695. didInsertElement: function () {
  696. App.popover(this.$(), {
  697. title: Em.I18n.t('installer.controls.addSlaveComponentGroupButton.title').format(this.get('slaveComponentName')),
  698. content: Em.I18n.t('installer.controls.addSlaveComponentGroupButton.content').format(this.get('slaveComponentName'), this.get('slaveComponentName'), this.get('slaveComponentName')),
  699. placement: 'right',
  700. trigger: 'hover'
  701. });
  702. }
  703. });
  704. /**
  705. * Multiple Slave Hosts component
  706. * @type {*}
  707. */
  708. App.ServiceConfigSlaveHostsView = Ember.View.extend(App.ServiceConfigMultipleHostsDisplay, App.ServiceConfigCalculateId, {
  709. viewName: 'serviceConfigSlaveHostsView',
  710. classNames: ['slave-hosts', 'span6'],
  711. valueBinding: 'serviceConfig.value',
  712. templateName: require('templates/wizard/slave_hosts'),
  713. /**
  714. * Onclick handler for link
  715. */
  716. showHosts: function () {
  717. var serviceConfig = this.get('serviceConfig');
  718. App.ModalPopup.show({
  719. header: Em.I18n.t('installer.controls.serviceConfigMasterHosts.header').format(serviceConfig.category),
  720. bodyClass: Ember.View.extend({
  721. serviceConfig: serviceConfig,
  722. templateName: require('templates/wizard/master_hosts_popup')
  723. }),
  724. secondary: null
  725. });
  726. }
  727. });
  728. /**
  729. * properties for present active slave group
  730. * @type {*}
  731. */
  732. App.SlaveGroupPropertiesView = Ember.View.extend(App.ServiceConfigCalculateId, {
  733. viewName: 'serviceConfigSlaveHostsView',
  734. group: function () {
  735. return this.get('controller.activeGroup');
  736. }.property('controller.activeGroup'),
  737. groupConfigs: function () {
  738. console.log("************************************************************************");
  739. console.log("The value of group is: " + this.get('group'));
  740. console.log("************************************************************************");
  741. return this.get('group.properties');
  742. }.property('group.properties.@each').cacheable(),
  743. errorCount: function () {
  744. return this.get('group.properties').filterProperty('isValid', false).filterProperty('isVisible', true).get('length');
  745. }.property('configs.@each.isValid', 'configs.@each.isVisible')
  746. });
  747. /**
  748. * DropDown component for <code>select hosts for groups</code> popup
  749. * @type {*}
  750. */
  751. App.SlaveComponentDropDownGroupView = Ember.View.extend(App.ServiceConfigCalculateId, {
  752. viewName: "slaveComponentDropDownGroupView",
  753. /**
  754. * On change handler for <code>select hosts for groups</code> popup
  755. * @param event
  756. */
  757. changeGroup: function (event) {
  758. var host = this.get('content');
  759. var groupName = $('#' + this.get('elementId') + ' select').val();
  760. this.get('controller').changeHostGroup(host, groupName);
  761. },
  762. optionTag: Ember.View.extend({
  763. /**
  764. * Whether current value(OptionTag value) equals to host value(assigned to SlaveComponentDropDownGroupView.content)
  765. */
  766. selected: function () {
  767. return this.get('parentView.content.group') === this.get('content');
  768. }.property('content')
  769. })
  770. });
  771. /**
  772. * Show info about current group
  773. * @type {*}
  774. */
  775. App.SlaveComponentChangeGroupNameView = Ember.View.extend(App.ServiceConfigCalculateId, {
  776. contentBinding: 'controller.activeGroup',
  777. classNames: ['control-group'],
  778. classNameBindings: 'error',
  779. error: false,
  780. setError: function () {
  781. this.set('error', false);
  782. }.observes('controller.activeGroup'),
  783. errorMessage: function () {
  784. return this.get('error') ? Em.I18n.t('installer.controls.slaveComponentChangeGroupName.error') : '';
  785. }.property('error'),
  786. /**
  787. * Onclick handler for saving updated group name
  788. * @param event
  789. */
  790. changeGroupName: function (event) {
  791. var inputVal = $('#' + this.get('elementId') + ' input[type="text"]').val();
  792. if (inputVal !== this.get('content.name')) {
  793. var result = this.get('controller').changeSlaveGroupName(this.get('content'), inputVal);
  794. this.set('error', result);
  795. }
  796. }
  797. });
  798. /**
  799. * View for testing connection to database.
  800. **/
  801. App.CheckDBConnectionView = Ember.View.extend({
  802. templateName: require('templates/common/form/check_db_connection'),
  803. /** @property {string} btnCaption - text for button **/
  804. btnCaption: function() {
  805. return this.get('parentView.service.serviceName') === 'KERBEROS'
  806. ? Em.I18n.t('services.service.config.kdc.btn.idle')
  807. : Em.I18n.t('services.service.config.database.btn.idle')
  808. }.property('parentView.service.serviceName'),
  809. /** @property {string} responseCaption - text for status link **/
  810. responseCaption: null,
  811. /** @property {boolean} isConnecting - is request to server activated **/
  812. isConnecting: false,
  813. /** @property {boolean} isValidationPassed - check validation for required fields **/
  814. isValidationPassed: null,
  815. /** @property {string} databaseName- name of current database **/
  816. databaseName: null,
  817. /** @property {boolean} isRequestResolved - check for finished request to server **/
  818. isRequestResolved: false,
  819. /** @property {boolean} isConnectionSuccess - check for successful connection to database **/
  820. isConnectionSuccess: null,
  821. /** @property {string} responseFromServer - message from server response **/
  822. responseFromServer: null,
  823. /** @property {Object} ambariRequiredProperties - properties that need for custom action request **/
  824. ambariRequiredProperties: null,
  825. /** @property {Number} currentRequestId - current custom action request id **/
  826. currentRequestId: null,
  827. /** @property {Number} currentTaskId - current custom action task id **/
  828. currentTaskId: null,
  829. /** @property {jQuery.Deferred} request - current $.ajax request **/
  830. request: null,
  831. /** @property {Number} pollInterval - timeout interval for ajax polling **/
  832. pollInterval: 3000,
  833. /** @property {string} hostNameProperty - host name property based on service and database names **/
  834. hostNameProperty: function() {
  835. if (!/wizard/i.test(this.get('controller.name')) && this.get('parentView.service.serviceName') === 'HIVE') {
  836. return this.get('parentView.service.serviceName').toLowerCase() + '_hostname';
  837. } else if (this.get('parentView.service.serviceName') === 'KERBEROS') {
  838. return 'kdc_host';
  839. }
  840. return '{0}_existing_{1}_host'.format(this.get('parentView.service.serviceName').toLowerCase(), this.get('databaseName').toLowerCase());
  841. }.property('databaseName'),
  842. /** @property {boolean} isBtnDisabled - disable button on failed validation or active request **/
  843. isBtnDisabled: function() {
  844. return !this.get('isValidationPassed') || this.get('isConnecting');
  845. }.property('isValidationPassed', 'isConnecting'),
  846. /** @property {object} requiredProperties - properties that necessary for database connection **/
  847. requiredProperties: function() {
  848. var propertiesMap = {
  849. 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'],
  850. HIVE: ['ambari.hive.db.schema.name','javax.jdo.option.ConnectionUserName','javax.jdo.option.ConnectionPassword','javax.jdo.option.ConnectionDriverName','javax.jdo.option.ConnectionURL'],
  851. KERBEROS: ['kdc_host']
  852. };
  853. return propertiesMap[this.get('parentView.service.serviceName')];
  854. }.property(),
  855. /** @property {Object} propertiesPattern - check pattern according to type of connection properties **/
  856. propertiesPattern: function() {
  857. var patterns = {
  858. db_connection_url: /jdbc\.url|connectionurl|kdc_host/ig
  859. };
  860. if (this.get('parentView.service.serviceName') != "KERBEROS") {
  861. patterns.user_name = /(username|dblogin)$/ig;
  862. patterns.user_passwd = /(dbpassword|password)$/ig;
  863. }
  864. return patterns;
  865. }.property('parentView.service.serviceName'),
  866. /** @property {String} masterHostName - host name location of Master Component related to Service **/
  867. masterHostName: function() {
  868. var serviceMasterMap = {
  869. 'OOZIE': 'oozieserver_host',
  870. 'HDFS': 'hadoop_host',
  871. 'HIVE': 'hive_ambari_host',
  872. 'KERBEROS': 'kdc_host'
  873. };
  874. return this.get('parentView.categoryConfigsAll').findProperty('name', serviceMasterMap[this.get('parentView.service.serviceName')]).get('value');
  875. }.property('parentView.service.serviceName', 'parentView.categoryConfigsAll.@each.value'),
  876. /** @property {Object} connectionProperties - service specific config values mapped for custom action request **/
  877. connectionProperties: function() {
  878. var propObj = {};
  879. for (var key in this.get('propertiesPattern')) {
  880. propObj[key] = this.getConnectionProperty(this.get('propertiesPattern')[key]);
  881. }
  882. return propObj;
  883. }.property('parentView.categoryConfigsAll.@each.value'),
  884. /**
  885. * Properties that stores in local storage used for handling
  886. * last success connection.
  887. *
  888. * @property {Object} preparedDBProperties
  889. **/
  890. preparedDBProperties: function() {
  891. var propObj = {};
  892. for (var key in this.get('propertiesPattern')) {
  893. var propName = this.getConnectionProperty(this.get('propertiesPattern')[key], true);
  894. propObj[propName] = this.get('parentView.categoryConfigsAll').findProperty('name', propName).get('value');
  895. }
  896. return propObj;
  897. }.property(),
  898. /** Check validation and load ambari properties **/
  899. didInsertElement: function() {
  900. var kdc = this.get('parentView.categoryConfigsAll').findProperty('name', 'kdc_type');
  901. if (kdc) {
  902. var name = kdc.get('value') == 'Existing MIT KDC' ? 'KDC' : 'AD';
  903. App.popover(this.$(), {
  904. title: Em.I18n.t('services.service.config.database.btn.idle'),
  905. content: Em.I18n.t('installer.controls.checkConnection.popover').format(name),
  906. placement: 'right',
  907. trigger: 'hover'
  908. });
  909. }
  910. this.handlePropertiesValidation();
  911. this.getAmbariProperties();
  912. },
  913. /** On view destroy **/
  914. willDestroyElement: function() {
  915. this.set('isConnecting', false);
  916. this._super();
  917. },
  918. /**
  919. * Observer that take care about enabling/disabling button based on required properties validation.
  920. *
  921. * @method handlePropertiesValidation
  922. **/
  923. handlePropertiesValidation: function() {
  924. this.restore();
  925. var isValid = true;
  926. var properties = [].concat(this.get('requiredProperties'));
  927. properties.push(this.get('hostNameProperty'));
  928. properties.forEach(function(propertyName) {
  929. var property = this.get('parentView.categoryConfigsAll').findProperty('name', propertyName);
  930. if(property && !property.get('isValid')) isValid = false;
  931. }, this);
  932. this.set('isValidationPassed', isValid);
  933. }.observes('parentView.categoryConfigsAll.@each.isValid', 'parentView.categoryConfigsAll.@each.value', 'databaseName'),
  934. getConnectionProperty: function(regexp, isGetName) {
  935. var _this = this;
  936. var propertyName = _this.get('requiredProperties').filter(function(item) {
  937. return regexp.test(item);
  938. })[0];
  939. return (isGetName) ? propertyName : _this.get('parentView.categoryConfigsAll').findProperty('name', propertyName).get('value');
  940. },
  941. /**
  942. * Set up ambari properties required for custom action request
  943. *
  944. * @method getAmbariProperties
  945. **/
  946. getAmbariProperties: function() {
  947. var clusterController = App.router.get('clusterController');
  948. var _this = this;
  949. if (!App.isEmptyObject(App.db.get('tmp', 'ambariProperties')) && !this.get('ambariProperties')) {
  950. this.set('ambariProperties', App.db.get('tmp', 'ambariProperties'));
  951. return;
  952. }
  953. if (App.isEmptyObject(clusterController.get('ambariProperties'))) {
  954. clusterController.loadAmbariProperties().done(function(data) {
  955. _this.formatAmbariProperties(data.RootServiceComponents.properties);
  956. });
  957. } else {
  958. this.formatAmbariProperties(clusterController.get('ambariProperties'));
  959. }
  960. },
  961. formatAmbariProperties: function(properties) {
  962. var defaults = {
  963. threshold: "60",
  964. ambari_server_host: location.hostname,
  965. check_execute_list : "db_connection_check"
  966. };
  967. var properties = App.permit(properties, ['jdk.name','jdk_location','java.home']);
  968. var renameKey = function(oldKey, newKey) {
  969. if (properties[oldKey]) {
  970. defaults[newKey] = properties[oldKey];
  971. delete properties[oldKey];
  972. }
  973. };
  974. renameKey('java.home', 'java_home');
  975. renameKey('jdk.name', 'jdk_name');
  976. $.extend(properties, defaults);
  977. App.db.set('tmp', 'ambariProperties', properties);
  978. this.set('ambariProperties', properties);
  979. },
  980. /**
  981. * `Action` method for starting connect to current database.
  982. *
  983. * @method connectToDatabase
  984. **/
  985. connectToDatabase: function() {
  986. if (this.get('isBtnDisabled')) return;
  987. this.set('isRequestResolved', false);
  988. App.db.set('tmp', this.get('parentView.service.serviceName') + '_connection', {});
  989. this.setConnectingStatus(true);
  990. if (App.get('testMode')) {
  991. this.startPolling();
  992. } else {
  993. this.runCheckConnection();
  994. }
  995. },
  996. /**
  997. * runs check connections methods depending on service
  998. * @return {void}
  999. * @method runCheckConnection
  1000. */
  1001. runCheckConnection: function() {
  1002. if (this.get('parentView.service.serviceName') === 'KERBEROS') {
  1003. this.runKDCCheck();
  1004. } else {
  1005. this.createCustomAction();
  1006. }
  1007. },
  1008. /**
  1009. * send ajax request to perforn kdc host check
  1010. * @return {App.ajax}
  1011. * @method runKDCCheck
  1012. */
  1013. runKDCCheck: function() {
  1014. return App.ajax.send({
  1015. name: 'admin.kerberos_security.test_connection',
  1016. sender: this,
  1017. data: {
  1018. kdcHostname: this.get('masterHostName')
  1019. },
  1020. success: 'onRunKDCCheckSuccess',
  1021. error: 'onCreateActionError'
  1022. });
  1023. },
  1024. /**
  1025. *
  1026. * @param data
  1027. */
  1028. onRunKDCCheckSuccess: function(data) {
  1029. var statusCode = {
  1030. success: 'REACHABLE',
  1031. failed: 'UNREACHABLE'
  1032. };
  1033. if (data == statusCode['success']) {
  1034. this.setResponseStatus('success');
  1035. } else {
  1036. this.setResponseStatus('failed');
  1037. }
  1038. this.set('responseFromServer', data);
  1039. },
  1040. /**
  1041. * Run custom action for database connection.
  1042. *
  1043. * @method createCustomAction
  1044. **/
  1045. createCustomAction: function() {
  1046. var dbName = this.get('databaseName').toLowerCase() === 'postgresql' ? 'postgres' : this.get('databaseName').toLowerCase();
  1047. var params = $.extend(true, {}, { db_name: dbName }, this.get('connectionProperties'), this.get('ambariProperties'));
  1048. App.ajax.send({
  1049. name: 'custom_action.create',
  1050. sender: this,
  1051. data: {
  1052. requestInfo: {
  1053. parameters: params
  1054. },
  1055. filteredHosts: [this.get('masterHostName')]
  1056. },
  1057. success: 'onCreateActionSuccess',
  1058. error: 'onCreateActionError'
  1059. });
  1060. },
  1061. /**
  1062. * Run updater if task is created successfully.
  1063. *
  1064. * @method onConnectActionS
  1065. **/
  1066. onCreateActionSuccess: function(data) {
  1067. this.set('currentRequestId', data.Requests.id);
  1068. App.ajax.send({
  1069. name: 'custom_action.request',
  1070. sender: this,
  1071. data: {
  1072. requestId: this.get('currentRequestId')
  1073. },
  1074. success: 'setCurrentTaskId'
  1075. });
  1076. },
  1077. setCurrentTaskId: function(data) {
  1078. this.set('currentTaskId', data.items[0].Tasks.id);
  1079. this.startPolling();
  1080. },
  1081. startPolling: function() {
  1082. if (this.get('isConnecting'))
  1083. this.getTaskInfo();
  1084. },
  1085. getTaskInfo: function() {
  1086. var request = App.ajax.send({
  1087. name: 'custom_action.request',
  1088. sender: this,
  1089. data: {
  1090. requestId: this.get('currentRequestId'),
  1091. taskId: this.get('currentTaskId')
  1092. },
  1093. success: 'getTaskInfoSuccess'
  1094. });
  1095. this.set('request', request);
  1096. },
  1097. getTaskInfoSuccess: function(data) {
  1098. var task = data.Tasks;
  1099. this.set('responseFromServer', {
  1100. stderr: task.stderr,
  1101. stdout: task.stdout
  1102. });
  1103. if (task.status === 'COMPLETED') {
  1104. var structuredOut = task.structured_out.db_connection_check;
  1105. if (structuredOut.exit_code != 0) {
  1106. this.set('responseFromServer', {
  1107. stderr: task.stderr,
  1108. stdout: task.stdout,
  1109. structuredOut: structuredOut.message
  1110. });
  1111. this.setResponseStatus('failed');
  1112. } else {
  1113. App.db.set('tmp', this.get('parentView.service.serviceName') + '_connection', this.get('preparedDBProperties'));
  1114. this.setResponseStatus('success');
  1115. }
  1116. }
  1117. if (task.status === 'FAILED') {
  1118. this.setResponseStatus('failed');
  1119. }
  1120. if (/PENDING|QUEUED|IN_PROGRESS/.test(task.status)) {
  1121. Em.run.later(this, function() {
  1122. this.startPolling();
  1123. }, this.get('pollInterval'));
  1124. }
  1125. },
  1126. onCreateActionError: function(jqXhr, status, errorMessage) {
  1127. this.setResponseStatus('failed');
  1128. this.set('responseFromServer', errorMessage);
  1129. },
  1130. setResponseStatus: function(isSuccess) {
  1131. var isSuccess = isSuccess == 'success';
  1132. this.setConnectingStatus(false);
  1133. this.set('responseCaption', isSuccess ? Em.I18n.t('services.service.config.database.connection.success') : Em.I18n.t('services.service.config.database.connection.failed'));
  1134. this.set('isConnectionSuccess', isSuccess);
  1135. this.set('isRequestResolved', true);
  1136. },
  1137. /**
  1138. * Switch captions and statuses for active/non-active request.
  1139. *
  1140. * @method setConnectionStatus
  1141. * @param {Boolean} [active]
  1142. */
  1143. setConnectingStatus: function(active) {
  1144. if (active) {
  1145. this.set('responseCaption', Em.I18n.t('services.service.config.database.connection.inProgress'));
  1146. }
  1147. this.set('controller.testConnectionInProgress', !!active);
  1148. this.set('btnCaption', !!active ? Em.I18n.t('services.service.config.database.btn.connecting') : Em.I18n.t('services.service.config.database.btn.idle'));
  1149. this.set('isConnecting', !!active);
  1150. },
  1151. /**
  1152. * Set view to init status.
  1153. *
  1154. * @method restore
  1155. **/
  1156. restore: function() {
  1157. if (this.get('request')) {
  1158. this.get('request').abort();
  1159. this.set('request', null);
  1160. }
  1161. this.set('responseCaption', null);
  1162. this.set('responseFromServer', null);
  1163. this.setConnectingStatus(false);
  1164. this.set('isRequestResolved', false);
  1165. },
  1166. /**
  1167. * `Action` method for showing response from server in popup.
  1168. *
  1169. * @method showLogsPopup
  1170. **/
  1171. showLogsPopup: function() {
  1172. if (this.get('isConnectionSuccess')) return;
  1173. var _this = this;
  1174. var popup = App.showAlertPopup('Error: {0} connection'.format(this.get('databaseName')));
  1175. if (typeof this.get('responseFromServer') == 'object') {
  1176. popup.set('bodyClass', Em.View.extend({
  1177. templateName: require('templates/common/error_log_body'),
  1178. openedTask: _this.get('responseFromServer')
  1179. }));
  1180. } else {
  1181. popup.set('body', this.get('responseFromServer'));
  1182. }
  1183. return popup;
  1184. }
  1185. });
  1186. /**
  1187. *
  1188. * @type {*}
  1189. */
  1190. App.BaseUrlTextField = Ember.TextField.extend({
  1191. valueBinding: 'repository.baseUrl',
  1192. keyUp: function (event) {
  1193. if (Em.get(this, 'repository.hasError')) {
  1194. Em.set(this, 'repository.hasError', false);
  1195. }
  1196. }
  1197. });