controls_view.js 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  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. * if config value contains &|<|>|"|'
  57. * input field converts it to &|<|>|"|'
  58. * this mixin helps to aviod such convertation and show values as is.
  59. */
  60. App.SkipXmlEscapingSupport = Ember.Mixin.create({
  61. didInsertElement: function() {
  62. this._super();
  63. if (this.get('serviceConfig.value').match(/(&amp;|&lt;|&gt;|&quot;|&apos;)/g)) {
  64. this.set('value', this.get('serviceConfig.value').replace('&','&amp;'));
  65. this.set('value', this.get('value').replace('&amp;','&'));
  66. }
  67. }
  68. });
  69. /**
  70. * Default input control
  71. * @type {*}
  72. */
  73. App.ServiceConfigTextField = Ember.TextField.extend(App.ServiceConfigPopoverSupport, App.SkipXmlEscapingSupport, {
  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 Utits type specified
  104. * @type {*}
  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.SkipXmlEscapingSupport, {
  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.SkipXmlEscapingSupport, {
  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({
  171. rows: 10
  172. });
  173. /**
  174. * Checkbox control
  175. * @type {*}
  176. */
  177. App.ServiceConfigCheckbox = Ember.Checkbox.extend(App.ServiceConfigPopoverSupport, {
  178. checkedBinding: 'serviceConfig.value',
  179. disabled: function () {
  180. return !this.get('serviceConfig.isEditable');
  181. }.property('serviceConfig.isEditable')
  182. });
  183. App.ServiceConfigRadioButtons = Ember.View.extend({
  184. templateName: require('templates/wizard/controls_service_config_radio_buttons'),
  185. didInsertElement: function () {
  186. // on page render, automatically populate JDBC URLs only for default database settings
  187. // so as to not lose the user's customizations on these fields
  188. if (['addServiceController', 'installerController'].contains(App.clusterStatus.wizardControllerName) && ['New PostgreSQL Database', 'New MySQL Database', 'New Derby Database'].contains(this.get('serviceConfig.value'))) {
  189. this.onOptionsChange();
  190. }
  191. },
  192. configs: function () {
  193. if (this.get('controller.name') == 'mainServiceInfoConfigsController') return this.get('categoryConfigsAll');
  194. return this.get('categoryConfigsAll').filterProperty('isObserved', true);
  195. }.property('categoryConfigsAll'),
  196. serviceConfig: null,
  197. categoryConfigsAll: null,
  198. onOptionsChange: function () {
  199. // The following if condition will be satisfied only for installer wizard flow
  200. if (this.get('configs').length) {
  201. var connectionUrl = this.get('connectionUrl');
  202. var dbClass = this.get('dbClass');
  203. if (connectionUrl) {
  204. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  205. switch (this.get('serviceConfig.value')) {
  206. case 'New MySQL Database':
  207. case 'Existing MySQL Database':
  208. connectionUrl.set('value', "jdbc:mysql://" + this.get('hostName') + "/" + this.get('databaseName') + "?createDatabaseIfNotExist=true");
  209. dbClass.set('value', "com.mysql.jdbc.Driver");
  210. break;
  211. case 'New PostgreSQL Database':
  212. case Em.I18n.t('services.service.config.hive.oozie.postgresql'):
  213. connectionUrl.set('value', "jdbc:postgresql://" + this.get('hostName') + ":5432/" + this.get('databaseName'));
  214. dbClass.set('value', "org.postgresql.Driver");
  215. break;
  216. case 'Existing Oracle Database':
  217. connectionUrl.set('value', "jdbc:oracle:thin:@//" + this.get('hostName') + ":1521/" + this.get('databaseName'));
  218. dbClass.set('value', "oracle.jdbc.driver.OracleDriver");
  219. break;
  220. }
  221. } else if (this.get('serviceConfig.serviceName') === 'OOZIE') {
  222. switch (this.get('serviceConfig.value')) {
  223. case 'New Derby Database':
  224. connectionUrl.set('value', "jdbc:derby:${oozie.data.dir}/${oozie.db.schema.name}-db;create=true");
  225. dbClass.set('value', "org.apache.derby.jdbc.EmbeddedDriver");
  226. break;
  227. case 'Existing MySQL Database':
  228. connectionUrl.set('value', "jdbc:mysql://" + this.get('hostName') + "/" + this.get('databaseName'));
  229. dbClass.set('value', "com.mysql.jdbc.Driver");
  230. break;
  231. case Em.I18n.t('services.service.config.hive.oozie.postgresql'):
  232. connectionUrl.set('value', "jdbc:postgresql://" + this.get('hostName') + ":5432/" + this.get('databaseName'));
  233. dbClass.set('value', "org.postgresql.Driver");
  234. break;
  235. case 'Existing Oracle Database':
  236. connectionUrl.set('value', "jdbc:oracle:thin:@//" + this.get('hostName') + ":1521/" + this.get('databaseName'));
  237. dbClass.set('value', "oracle.jdbc.driver.OracleDriver");
  238. break;
  239. }
  240. }
  241. connectionUrl.set('defaultValue', connectionUrl.get('value'));
  242. }
  243. }
  244. }.observes('databaseName', 'hostName', 'connectionUrl','dbClass'),
  245. nameBinding: 'serviceConfig.radioName',
  246. databaseName: function () {
  247. switch (this.get('serviceConfig.serviceName')) {
  248. case 'HIVE':
  249. return this.get('categoryConfigsAll').findProperty('name', 'ambari.hive.db.schema.name').get('value');
  250. case 'OOZIE':
  251. return this.get('categoryConfigsAll').findProperty('name', 'oozie.db.schema.name').get('value');
  252. default:
  253. return null;
  254. }
  255. }.property('configs.@each.value', 'serviceConfig.serviceName'),
  256. hostName: function () {
  257. var value = this.get('serviceConfig.value');
  258. var returnValue;
  259. var hostname;
  260. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  261. switch (value) {
  262. case 'New MySQL Database':
  263. case 'New PostgreSQL Database':
  264. hostname = this.get('categoryConfigsAll').findProperty('name', 'hive_ambari_host');
  265. break;
  266. case 'Existing MySQL Database':
  267. hostname = this.get('categoryConfigsAll').findProperty('name', 'hive_existing_mysql_host');
  268. break;
  269. case Em.I18n.t('services.service.config.hive.oozie.postgresql'):
  270. hostname = this.get('categoryConfigsAll').findProperty('name', 'hive_existing_postgresql_host');
  271. break;
  272. case 'Existing Oracle Database':
  273. hostname = this.get('categoryConfigsAll').findProperty('name', 'hive_existing_oracle_host');
  274. break;
  275. }
  276. if (hostname) {
  277. returnValue = hostname.get('value');
  278. } else {
  279. returnValue = this.get('categoryConfigsAll').findProperty('name', 'hive_hostname').get('value');
  280. }
  281. } else if (this.get('serviceConfig.serviceName') === 'OOZIE') {
  282. switch (value) {
  283. case 'New Derby Database':
  284. hostname = this.get('categoryConfigsAll').findProperty('name', 'oozie_ambari_host');
  285. break;
  286. case 'Existing MySQL Database':
  287. hostname = this.get('categoryConfigsAll').findProperty('name', 'oozie_existing_mysql_host');
  288. break;
  289. case Em.I18n.t('services.service.config.hive.oozie.postgresql'):
  290. hostname = this.get('categoryConfigsAll').findProperty('name', 'oozie_existing_postgresql_host');
  291. break;
  292. case 'Existing Oracle Database':
  293. hostname = this.get('categoryConfigsAll').findProperty('name', 'oozie_existing_oracle_host');
  294. break;
  295. }
  296. if (hostname) {
  297. returnValue = hostname.get('value');
  298. } else {
  299. returnValue = this.get('categoryConfigsAll').findProperty('name', 'oozie_hostname').get('value');
  300. }
  301. }
  302. return returnValue;
  303. }.property('serviceConfig.serviceName', 'serviceConfig.value', 'configs.@each.value'),
  304. connectionUrl: function () {
  305. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  306. return this.get('categoryConfigsAll').findProperty('name', 'javax.jdo.option.ConnectionURL');
  307. } else {
  308. return this.get('categoryConfigsAll').findProperty('name', 'oozie.service.JPAService.jdbc.url');
  309. }
  310. }.property('serviceConfig.serviceName'),
  311. dbClass: function () {
  312. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  313. return this.get('categoryConfigsAll').findProperty('name', 'javax.jdo.option.ConnectionDriverName');
  314. } else {
  315. return this.get('categoryConfigsAll').findProperty('name', 'oozie.service.JPAService.jdbc.driver');
  316. }
  317. }.property('serviceConfig.serviceName'),
  318. /**
  319. * `Observer` that add <code>additionalView</code> to <code>App.ServiceConfigProperty</code>
  320. * that responsible for (if existing db selected)
  321. * 1. checking database connection
  322. * 2. showing jdbc driver setup warning msg.
  323. *
  324. * @method handleDBConnectionProperty
  325. **/
  326. handleDBConnectionProperty: function () {
  327. if (!['addServiceController', 'installerController'].contains(App.clusterStatus.wizardControllerName)) return;
  328. var handledProperties = ['oozie_database', 'hive_database'];
  329. var currentValue = this.get('serviceConfig.value');
  330. var databases = /MySQL|PostgreSQL|Oracle|Derby/gi;
  331. var currentDB = currentValue.match(databases)[0];
  332. var databasesTypes = /MySQL|PostgreS|Oracle|Derby/gi;
  333. var currentDBType = currentValue.match(databasesTypes)[0];
  334. var existingDatabase = /existing/gi.test(currentValue);
  335. // db connection check button show up if existed db selected
  336. var propertyAppendTo1 = this.get('categoryConfigsAll').findProperty('displayName', 'Database URL');
  337. if (currentDB && existingDatabase) {
  338. if (handledProperties.contains(this.get('serviceConfig.name'))) {
  339. if (propertyAppendTo1) propertyAppendTo1.set('additionalView', App.CheckDBConnectionView.extend({databaseName: currentDB}));
  340. }
  341. } else {
  342. propertyAppendTo1.set('additionalView', null);
  343. }
  344. // warning msg under database type radio buttons, to warn the user to setup jdbc driver if existed db selected
  345. var propertyHive = this.get('categoryConfigsAll').findProperty('displayName', 'Hive Database');
  346. var propertyOozie = this.get('categoryConfigsAll').findProperty('displayName', 'Oozie Database');
  347. var propertyAppendTo2 = propertyHive ? propertyHive : propertyOozie;
  348. if (currentDB && existingDatabase) {
  349. if (handledProperties.contains(this.get('serviceConfig.name'))) {
  350. if (propertyAppendTo2) {
  351. propertyAppendTo2.set('additionalView', Ember.View.extend({
  352. template: Ember.Handlebars.compile('<div class="alert">{{{view.message}}}</div>'),
  353. message: Em.I18n.t('services.service.config.database.msg.jdbcSetup').format(currentDBType.toLowerCase(), currentDBType.toLowerCase())
  354. }));
  355. }
  356. }
  357. } else {
  358. propertyAppendTo2.set('additionalView', null);
  359. }
  360. }.observes('serviceConfig.value', 'configs.@each.value'),
  361. optionsBinding: 'serviceConfig.options'
  362. });
  363. App.ServiceConfigRadioButton = Ember.Checkbox.extend({
  364. tagName: 'input',
  365. attributeBindings: ['type', 'name', 'value', 'checked'],
  366. checked: false,
  367. type: 'radio',
  368. name: null,
  369. value: null,
  370. didInsertElement: function () {
  371. console.debug('App.ServiceConfigRadioButton.didInsertElement');
  372. if (this.get('parentView.serviceConfig.value') === this.get('value')) {
  373. console.debug(this.get('name') + ":" + this.get('value') + ' is checked');
  374. this.set('checked', true);
  375. }
  376. },
  377. click: function () {
  378. this.set('checked', true);
  379. console.debug('App.ServiceConfigRadioButton.click');
  380. this.onChecked();
  381. },
  382. onChecked: function () {
  383. // Wrapping the call with Ember.run.next prevents a problem where setting isVisible on component
  384. // causes JS error due to re-rendering. For example, this occurs when switching the Config Group
  385. // in Service Config page
  386. Em.run.next(this, function() {
  387. console.debug('App.ServiceConfigRadioButton.onChecked');
  388. this.set('parentView.serviceConfig.value', this.get('value'));
  389. var components = this.get('parentView.serviceConfig.options');
  390. if (components) {
  391. components.forEach(function (_component) {
  392. if (_component.foreignKeys) {
  393. _component.foreignKeys.forEach(function (_componentName) {
  394. if (this.get('parentView.categoryConfigsAll').someProperty('name', _componentName)) {
  395. var component = this.get('parentView.categoryConfigsAll').findProperty('name', _componentName);
  396. component.set('isVisible', _component.displayName === this.get('value'));
  397. }
  398. }, this);
  399. }
  400. }, this);
  401. }
  402. });
  403. }.observes('checked'),
  404. disabled: function () {
  405. return !this.get('parentView.serviceConfig.isEditable');
  406. }.property('parentView.serviceConfig.isEditable')
  407. });
  408. App.ServiceConfigComboBox = Ember.Select.extend(App.ServiceConfigPopoverSupport, {
  409. contentBinding: 'serviceConfig.options',
  410. selectionBinding: 'serviceConfig.value',
  411. placeholderBinding: 'serviceConfig.defaultValue',
  412. classNames: [ 'span3' ]
  413. });
  414. /**
  415. * Base component for host config with popover support
  416. */
  417. App.ServiceConfigHostPopoverSupport = Ember.Mixin.create({
  418. /**
  419. * Config object. It will instance of App.ServiceConfigProperty
  420. */
  421. serviceConfig: null,
  422. didInsertElement: function () {
  423. App.popover(this.$(), {
  424. title: this.get('serviceConfig.displayName'),
  425. content: this.get('serviceConfig.description'),
  426. placement: 'right',
  427. trigger: 'hover'
  428. });
  429. }
  430. });
  431. /**
  432. * Master host component.
  433. * Show hostname without ability to edit it
  434. * @type {*}
  435. */
  436. App.ServiceConfigMasterHostView = Ember.View.extend(App.ServiceConfigHostPopoverSupport, {
  437. classNames: ['master-host', 'span6'],
  438. valueBinding: 'serviceConfig.value',
  439. template: Ember.Handlebars.compile('{{value}}')
  440. });
  441. /**
  442. * Show value as plain label in italics
  443. * @type {*}
  444. */
  445. App.ServiceConfigLabelView = Ember.View.extend(App.ServiceConfigHostPopoverSupport, {
  446. classNames: ['master-host', 'span6'],
  447. valueBinding: 'serviceConfig.value',
  448. template: Ember.Handlebars.compile('<i>{{view.value}}</i>')
  449. });
  450. /**
  451. * Base component to display Multiple hosts
  452. * @type {*}
  453. */
  454. App.ServiceConfigMultipleHostsDisplay = Ember.Mixin.create(App.ServiceConfigHostPopoverSupport, {
  455. hasNoHosts: function () {
  456. console.log('view', this.get('viewName')); //to know which View cause errors
  457. console.log('controller', this.get('controller').name); //should be slaveComponentGroupsController
  458. if (!this.get('value')) {
  459. return true;
  460. }
  461. return this.get('value').length === 0;
  462. }.property('value'),
  463. hasOneHost: function () {
  464. return this.get('value').length === 1;
  465. }.property('value'),
  466. hasMultipleHosts: function () {
  467. return this.get('value').length > 1;
  468. }.property('value'),
  469. otherLength: function () {
  470. var len = this.get('value').length;
  471. if (len > 2) {
  472. return Em.I18n.t('installer.controls.serviceConfigMultipleHosts.others').format(len - 1);
  473. } else {
  474. return Em.I18n.t('installer.controls.serviceConfigMultipleHosts.other');
  475. }
  476. }.property('value')
  477. });
  478. /**
  479. * Multiple master host component.
  480. * Show hostnames without ability to edit it
  481. * @type {*}
  482. */
  483. App.ServiceConfigMasterHostsView = Ember.View.extend(App.ServiceConfigMultipleHostsDisplay, {
  484. viewName: "serviceConfigMasterHostsView",
  485. valueBinding: 'serviceConfig.value',
  486. classNames: ['master-hosts', 'span6'],
  487. templateName: require('templates/wizard/master_hosts'),
  488. /**
  489. * Onclick handler for link
  490. */
  491. showHosts: function () {
  492. var serviceConfig = this.get('serviceConfig');
  493. App.ModalPopup.show({
  494. header: Em.I18n.t('installer.controls.serviceConfigMasterHosts.header').format(serviceConfig.category),
  495. bodyClass: Ember.View.extend({
  496. serviceConfig: serviceConfig,
  497. templateName: require('templates/wizard/master_hosts_popup')
  498. }),
  499. secondary: null
  500. });
  501. }
  502. });
  503. /**
  504. * Show tabs list for slave hosts
  505. * @type {*}
  506. */
  507. App.SlaveComponentGroupsMenu = Em.CollectionView.extend({
  508. content: function () {
  509. return this.get('controller.componentGroups');
  510. }.property('controller.componentGroups'),
  511. tagName: 'ul',
  512. classNames: ["nav", "nav-tabs"],
  513. itemViewClass: Em.View.extend({
  514. classNameBindings: ["active"],
  515. active: function () {
  516. return this.get('content.active');
  517. }.property('content.active'),
  518. errorCount: function () {
  519. return this.get('content.properties').filterProperty('isValid', false).filterProperty('isVisible', true).get('length');
  520. }.property('content.properties.@each.isValid', 'content.properties.@each.isVisible'),
  521. templateName: require('templates/wizard/controls_slave_component_groups_menu')
  522. })
  523. });
  524. /**
  525. * <code>Add group</code> button
  526. * @type {*}
  527. */
  528. App.AddSlaveComponentGroupButton = Ember.View.extend({
  529. tagName: 'span',
  530. slaveComponentName: null,
  531. didInsertElement: function () {
  532. App.popover(this.$(), {
  533. title: Em.I18n.t('installer.controls.addSlaveComponentGroupButton.title').format(this.get('slaveComponentName')),
  534. content: Em.I18n.t('installer.controls.addSlaveComponentGroupButton.content').format(this.get('slaveComponentName'), this.get('slaveComponentName'), this.get('slaveComponentName')),
  535. placement: 'right',
  536. trigger: 'hover'
  537. });
  538. }
  539. });
  540. /**
  541. * Multiple Slave Hosts component
  542. * @type {*}
  543. */
  544. App.ServiceConfigSlaveHostsView = Ember.View.extend(App.ServiceConfigMultipleHostsDisplay, {
  545. viewName: 'serviceConfigSlaveHostsView',
  546. classNames: ['slave-hosts', 'span6'],
  547. valueBinding: 'serviceConfig.value',
  548. templateName: require('templates/wizard/slave_hosts'),
  549. /**
  550. * Onclick handler for link
  551. */
  552. showHosts: function () {
  553. var serviceConfig = this.get('serviceConfig');
  554. App.ModalPopup.show({
  555. header: Em.I18n.t('installer.controls.serviceConfigMasterHosts.header').format(serviceConfig.category),
  556. bodyClass: Ember.View.extend({
  557. serviceConfig: serviceConfig,
  558. templateName: require('templates/wizard/master_hosts_popup')
  559. }),
  560. secondary: null
  561. });
  562. }
  563. });
  564. /**
  565. * properties for present active slave group
  566. * @type {*}
  567. */
  568. App.SlaveGroupPropertiesView = Ember.View.extend({
  569. viewName: 'serviceConfigSlaveHostsView',
  570. group: function () {
  571. return this.get('controller.activeGroup');
  572. }.property('controller.activeGroup'),
  573. groupConfigs: function () {
  574. console.log("************************************************************************");
  575. console.log("The value of group is: " + this.get('group'));
  576. console.log("************************************************************************");
  577. return this.get('group.properties');
  578. }.property('group.properties.@each').cacheable(),
  579. errorCount: function () {
  580. return this.get('group.properties').filterProperty('isValid', false).filterProperty('isVisible', true).get('length');
  581. }.property('configs.@each.isValid', 'configs.@each.isVisible')
  582. });
  583. /**
  584. * DropDown component for <code>select hosts for groups</code> popup
  585. * @type {*}
  586. */
  587. App.SlaveComponentDropDownGroupView = Ember.View.extend({
  588. viewName: "slaveComponentDropDownGroupView",
  589. /**
  590. * On change handler for <code>select hosts for groups</code> popup
  591. * @param event
  592. */
  593. changeGroup: function (event) {
  594. var host = this.get('content');
  595. var groupName = $('#' + this.get('elementId') + ' select').val();
  596. this.get('controller').changeHostGroup(host, groupName);
  597. },
  598. optionTag: Ember.View.extend({
  599. /**
  600. * Whether current value(OptionTag value) equals to host value(assigned to SlaveComponentDropDownGroupView.content)
  601. */
  602. selected: function () {
  603. return this.get('parentView.content.group') === this.get('content');
  604. }.property('content')
  605. })
  606. });
  607. /**
  608. * Show info about current group
  609. * @type {*}
  610. */
  611. App.SlaveComponentChangeGroupNameView = Ember.View.extend({
  612. contentBinding: 'controller.activeGroup',
  613. classNames: ['control-group'],
  614. classNameBindings: 'error',
  615. error: false,
  616. setError: function () {
  617. this.set('error', false);
  618. }.observes('controller.activeGroup'),
  619. errorMessage: function () {
  620. return this.get('error') ? Em.I18n.t('installer.controls.slaveComponentChangeGroupName.error') : '';
  621. }.property('error'),
  622. /**
  623. * Onclick handler for saving updated group name
  624. * @param event
  625. */
  626. changeGroupName: function (event) {
  627. var inputVal = $('#' + this.get('elementId') + ' input[type="text"]').val();
  628. if (inputVal !== this.get('content.name')) {
  629. var result = this.get('controller').changeSlaveGroupName(this.get('content'), inputVal);
  630. this.set('error', result);
  631. }
  632. }
  633. });
  634. /**
  635. * View for testing connection to database.
  636. **/
  637. App.CheckDBConnectionView = Ember.View.extend({
  638. templateName: require('templates/common/form/check_db_connection'),
  639. /** @property {string} btnCaption - text for button **/
  640. btnCaption: Em.I18n.t('services.service.config.database.btn.idle'),
  641. /** @property {string} responseCaption - text for status link **/
  642. responseCaption: null,
  643. /** @property {boolean} isConnecting - is request to server activated **/
  644. isConnecting: false,
  645. /** @property {boolean} isValidationPassed - check validation for required fields **/
  646. isValidationPassed: null,
  647. /** @property {string} databaseName- name of current database **/
  648. databaseName: null,
  649. /** @property {boolean} isRequestResolved - check for finished request to server **/
  650. isRequestResolved: false,
  651. /** @property {boolean} isConnectionSuccess - check for successful connection to database **/
  652. isConnectionSuccess: null,
  653. /** @property {string} responseFromServer - message from server response **/
  654. responseFromServer: null,
  655. /** @property {Object} ambariRequiredProperties - properties that need for custom action request **/
  656. ambariRequiredProperties: null,
  657. /** @property {Number} currentRequestId - current custom action request id **/
  658. currentRequestId: null,
  659. /** @property {Number} currentTaskId - current custom action task id **/
  660. currentTaskId: null,
  661. /** @property {jQuery.Deferred} request - current $.ajax request **/
  662. request: null,
  663. /** @property {Number} pollInterval - timeout interval for ajax polling **/
  664. pollInterval: 3000,
  665. /** @property {string} hostNameProperty - host name property based on service and database names **/
  666. hostNameProperty: function() {
  667. if (!/wizard/i.test(this.get('controller.name')) && this.get('parentView.service.serviceName') === 'HIVE') {
  668. return this.get('parentView.service.serviceName').toLowerCase() + '_hostname';
  669. }
  670. return '{0}_existing_{1}_host'.format(this.get('parentView.service.serviceName').toLowerCase(), this.get('databaseName').toLowerCase());
  671. }.property('databaseName'),
  672. /** @property {boolean} isBtnDisabled - disable button on failed validation or active request **/
  673. isBtnDisabled: function() {
  674. return !this.get('isValidationPassed') || this.get('isConnecting');
  675. }.property('isValidationPassed', 'isConnecting'),
  676. /** @property {object} requiredProperties - properties that necessary for database connection **/
  677. requiredProperties: function() {
  678. var propertiesMap = {
  679. 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'],
  680. HIVE: ['ambari.hive.db.schema.name','javax.jdo.option.ConnectionUserName','javax.jdo.option.ConnectionPassword','javax.jdo.option.ConnectionDriverName','javax.jdo.option.ConnectionURL']
  681. };
  682. return propertiesMap[this.get('parentView.service.serviceName')];
  683. }.property(),
  684. /** @property {Object} propertiesPattern - check pattern according to type of connection properties **/
  685. propertiesPattern: function() {
  686. return {
  687. user_name: /username$/ig,
  688. user_passwd: /password$/ig,
  689. db_connection_url: /jdbc\.url|connectionurl/ig
  690. }
  691. }.property(),
  692. /** @property {String} masterHostName - host name location of Master Component related to Service **/
  693. masterHostName: function() {
  694. var serviceMasterMap = {
  695. 'OOZIE': 'oozieserver_host',
  696. 'HIVE': 'hivemetastore_host'
  697. };
  698. return this.get('parentView.categoryConfigsAll').findProperty('name', serviceMasterMap[this.get('parentView.service.serviceName')]).get('value');
  699. }.property(),
  700. /** @property {Object} connectionProperties - service specific config values mapped for custom action request **/
  701. connectionProperties: function() {
  702. var propObj = {};
  703. for (var key in this.get('propertiesPattern')) {
  704. propObj[key] = this.getConnectionProperty(this.get('propertiesPattern')[key]);
  705. }
  706. return propObj;
  707. }.property('parentView.categoryConfigsAll.@each.value'),
  708. /**
  709. * Properties that stores in local storage used for handling
  710. * last success connection.
  711. *
  712. * @property {Object} preparedDBProperties
  713. **/
  714. preparedDBProperties: function() {
  715. var propObj = {};
  716. for (var key in this.get('propertiesPattern')) {
  717. var propName = this.getConnectionProperty(this.get('propertiesPattern')[key], true);
  718. propObj[propName] = this.get('parentView.categoryConfigsAll').findProperty('name', propName).get('value');
  719. }
  720. return propObj;
  721. }.property(),
  722. /** Check validation and load ambari properties **/
  723. didInsertElement: function() {
  724. this.handlePropertiesValidation();
  725. this.getAmbariProperties();
  726. },
  727. /** On view destroy **/
  728. willDestroyElement: function() {
  729. this.set('isConnecting', false);
  730. this._super();
  731. },
  732. /**
  733. * Observer that take care about enabling/disabling button based on required properties validation.
  734. *
  735. * @method handlePropertiesValidation
  736. **/
  737. handlePropertiesValidation: function() {
  738. this.restore();
  739. var isValid = true;
  740. var properties = [].concat(this.get('requiredProperties'));
  741. properties.push(this.get('hostNameProperty'));
  742. properties.forEach(function(propertyName) {
  743. var property = this.get('parentView.categoryConfigsAll').findProperty('name', propertyName);
  744. if(property && !property.get('isValid')) isValid = false;
  745. }, this);
  746. this.set('isValidationPassed', isValid);
  747. }.observes('parentView.categoryConfigsAll.@each.isValid', 'parentView.categoryConfigsAll.@each.value', 'databaseName'),
  748. getConnectionProperty: function(regexp, isGetName) {
  749. var _this = this;
  750. var propertyName = _this.get('requiredProperties').filter(function(item) {
  751. return regexp.test(item);
  752. })[0];
  753. return (isGetName) ? propertyName : _this.get('parentView.categoryConfigsAll').findProperty('name', propertyName).get('value');
  754. },
  755. /**
  756. * Set up ambari properties required for custom action request
  757. *
  758. * @method getAmbariProperties
  759. **/
  760. getAmbariProperties: function() {
  761. var clusterController = App.router.get('clusterController');
  762. var _this = this;
  763. if (!App.isEmptyObject(App.db.get('tmp', 'ambariProperties')) && !this.get('ambariProperties')) {
  764. this.set('ambariProperties', App.db.get('tmp', 'ambariProperties'));
  765. return;
  766. }
  767. if (App.isEmptyObject(clusterController.get('ambariProperties'))) {
  768. clusterController.loadAmbariProperties().done(function(data) {
  769. _this.formatAmbariProperties(data.RootServiceComponents.properties);
  770. });
  771. } else {
  772. this.formatAmbariProperties(clusterController.get('ambariProperties'));
  773. }
  774. },
  775. formatAmbariProperties: function(properties) {
  776. var defaults = {
  777. threshold: "60",
  778. ambari_server_host: location.hostname,
  779. check_execute_list : "db_connection_check"
  780. };
  781. var properties = App.permit(properties, ['jdk.name','jdk_location','java.home']);
  782. var renameKey = function(oldKey, newKey) {
  783. if (properties[oldKey]) {
  784. defaults[newKey] = properties[oldKey];
  785. delete properties[oldKey];
  786. }
  787. };
  788. renameKey('java.home', 'java_home');
  789. renameKey('jdk.name', 'jdk_name');
  790. $.extend(properties, defaults);
  791. App.db.set('tmp', 'ambariProperties', properties);
  792. this.set('ambariProperties', properties);
  793. },
  794. /**
  795. * `Action` method for starting connect to current database.
  796. *
  797. * @method connectToDatabase
  798. **/
  799. connectToDatabase: function() {
  800. if (this.get('isBtnDisabled')) return false;
  801. var self = this;
  802. self.set('isRequestResolved', false);
  803. App.db.set('tmp', this.get('parentView.service.serviceName') + '_connection', {});
  804. this.setConnectingStatus(true);
  805. this.createCustomAction();
  806. },
  807. /**
  808. * Run custom action for database connection.
  809. *
  810. * @method createCustomAction
  811. **/
  812. createCustomAction: function() {
  813. var dbName = this.get('databaseName').toLowerCase() === 'postgresql' ? 'postgres' : this.get('databaseName').toLowerCase();
  814. var params = $.extend(true, {}, { db_name: dbName }, this.get('connectionProperties'), this.get('ambariProperties'));
  815. App.ajax.send({
  816. name: 'custom_action.create',
  817. sender: this,
  818. data: {
  819. requestInfo: {
  820. parameters: params
  821. },
  822. filteredHosts: [this.get('masterHostName')]
  823. },
  824. success: 'onCreateActionSuccess',
  825. error: 'onCreateActionError'
  826. });
  827. },
  828. /**
  829. * Run updater if task is created successfully.
  830. *
  831. * @method onConnectActionS
  832. **/
  833. onCreateActionSuccess: function(data) {
  834. this.set('currentRequestId', data.Requests.id);
  835. App.ajax.send({
  836. name: 'custom_action.request',
  837. sender: this,
  838. data: {
  839. requestId: this.get('currentRequestId')
  840. },
  841. success: 'setCurrentTaskId'
  842. });
  843. },
  844. setCurrentTaskId: function(data) {
  845. this.set('currentTaskId', data.items[0].Tasks.id);
  846. this.startPolling();
  847. },
  848. startPolling: function() {
  849. if (this.get('isConnecting'))
  850. this.getTaskInfo();
  851. },
  852. getTaskInfo: function() {
  853. var request = App.ajax.send({
  854. name: 'custom_action.request',
  855. sender: this,
  856. data: {
  857. requestId: this.get('currentRequestId'),
  858. taskId: this.get('currentTaskId')
  859. },
  860. success: 'getTaskInfoSuccess'
  861. });
  862. this.set('request', request);
  863. },
  864. getTaskInfoSuccess: function(data) {
  865. var task = data.Tasks;
  866. if (task.status === 'COMPLETED') {
  867. var structuredOut = task.structured_out.db_connection_check;
  868. if (structuredOut.exit_code != 0) {
  869. this.set('responseFromServer', {
  870. stderr: task.stderr,
  871. stdout: task.stdout,
  872. structuredOut: structuredOut.message
  873. });
  874. this.setResponseStatus('failed');
  875. } else {
  876. App.db.set('tmp', this.get('parentView.service.serviceName') + '_connection', this.get('preparedDBProperties'));
  877. this.setResponseStatus('success');
  878. }
  879. }
  880. if (task.status === 'FAILED') {
  881. this.set('responseFromServer', {
  882. stderr: task.stderr,
  883. stdout: task.stdout
  884. });
  885. this.setResponseStatus('failed');
  886. }
  887. if (/PENDING|QUEUED|IN_PROGRESS/.test(task.status)) {
  888. Em.run.later(this, function() {
  889. this.startPolling();
  890. }, this.get('pollInterval'));
  891. }
  892. },
  893. onCreateActionError: function(jqXhr, status, errorMessage) {
  894. this.setResponseStatus('failed');
  895. this.set('responseFromServer', errorMessage);
  896. },
  897. setResponseStatus: function(isSuccess) {
  898. var isSuccess = isSuccess == 'success';
  899. this.setConnectingStatus(false);
  900. this.set('responseCaption', isSuccess ? Em.I18n.t('services.service.config.database.connection.success') : Em.I18n.t('services.service.config.database.connection.failed'));
  901. this.set('isConnectionSuccess', isSuccess);
  902. this.set('isRequestResolved', true);
  903. },
  904. /**
  905. * Switch captions and statuses for active/non-active request.
  906. *
  907. * @method setConnectionStatus
  908. * @param {Boolean} [active]
  909. */
  910. setConnectingStatus: function(active) {
  911. if (active) {
  912. this.set('responseCaption', null);
  913. this.set('responseFromServer', null);
  914. }
  915. this.set('btnCaption', !!active ? Em.I18n.t('services.service.config.database.btn.connecting') : Em.I18n.t('services.service.config.database.btn.idle'));
  916. this.set('isConnecting', !!active);
  917. },
  918. /**
  919. * Set view to init status.
  920. *
  921. * @method restore
  922. **/
  923. restore: function() {
  924. if (this.get('request')) {
  925. this.get('request').abort();
  926. this.set('request', null);
  927. }
  928. this.set('responseCaption', null);
  929. this.set('responseFromServer', null);
  930. this.setConnectingStatus(false);
  931. this.set('isRequestResolved', false);
  932. },
  933. /**
  934. * `Action` method for showing response from server in popup.
  935. *
  936. * @method showLogsPopup
  937. **/
  938. showLogsPopup: function() {
  939. if (this.get('isConnectionSuccess')) return;
  940. var _this = this;
  941. var popup = App.showAlertPopup('Error: {0} connection'.format(this.get('databaseName')));
  942. if (typeof this.get('responseFromServer') == 'object') {
  943. popup.set('bodyClass', Em.View.extend({
  944. templateName: require('templates/common/error_log_body'),
  945. openedTask: _this.get('responseFromServer')
  946. }));
  947. } else {
  948. popup.set('body', this.get('responseFromServer'));
  949. }
  950. return popup;
  951. }
  952. });