controls_view.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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. placeholderBinding: 'serviceConfig.defaultValue',
  29. attributeBindings:['readOnly'],
  30. isPopoverEnabled: true,
  31. didInsertElement: function () {
  32. if (this.get('isPopoverEnabled') !== 'false') {
  33. App.popover(this.$(), {
  34. title: Em.I18n.t('installer.controls.serviceConfigPopover.title').format(
  35. this.get('serviceConfig.displayName'),
  36. (this.get('serviceConfig.displayName') == this.get('serviceConfig.name')) ? '' : this.get('serviceConfig.name')
  37. ),
  38. content: this.get('serviceConfig.description'),
  39. placement: 'right',
  40. trigger: 'hover'
  41. });
  42. }
  43. },
  44. readOnly: function () {
  45. return !this.get('serviceConfig.isEditable');
  46. }.property('serviceConfig.isEditable')
  47. });
  48. /**
  49. * Default input control
  50. * @type {*}
  51. */
  52. App.ServiceConfigTextField = Ember.TextField.extend(App.ServiceConfigPopoverSupport, {
  53. valueBinding: 'serviceConfig.value',
  54. classNameBindings: 'textFieldClassName',
  55. placeholderBinding: 'serviceConfig.defaultValue',
  56. keyPress: function (event) {
  57. if (event.keyCode == 13) {
  58. return false;
  59. }
  60. },
  61. //Set editDone true for last edited config text field parameter
  62. focusOut: function (event) {
  63. this.get('serviceConfig').set("editDone", true);
  64. },
  65. //Set editDone false for all current category config text field parameter
  66. focusIn: function (event) {
  67. if (!this.get('serviceConfig.isOverridden')) {
  68. this.get("parentView.categoryConfigsAll").setEach("editDone", false);
  69. }
  70. },
  71. textFieldClassName: function () {
  72. if (this.get('serviceConfig.unit')) {
  73. return ['input-small'];
  74. } else if (this.get('serviceConfig.displayType') === 'principal') {
  75. return ['span12'];
  76. } else {
  77. return ['span9'];
  78. }
  79. }.property('serviceConfig.displayType', 'serviceConfig.unit')
  80. });
  81. /**
  82. * Customized input control with Utits type specified
  83. * @type {*}
  84. */
  85. App.ServiceConfigTextFieldWithUnit = Ember.View.extend(App.ServiceConfigPopoverSupport, {
  86. valueBinding: 'serviceConfig.value',
  87. classNames: ['input-append', 'with-unit'],
  88. placeholderBinding: 'serviceConfig.defaultValue',
  89. templateName: require('templates/wizard/controls_service_config_textfield_with_unit')
  90. });
  91. /**
  92. * Password control
  93. * @type {*}
  94. */
  95. App.ServiceConfigPasswordField = Ember.TextField.extend({
  96. serviceConfig: null,
  97. type: 'password',
  98. attributeBindings:['readOnly'],
  99. valueBinding: 'serviceConfig.value',
  100. classNames: [ 'span4' ],
  101. placeholder: Em.I18n.t('form.item.placeholders.typePassword'),
  102. template: Ember.Handlebars.compile('{{view view.retypePasswordView}}'),
  103. keyPress: function (event) {
  104. if (event.keyCode == 13) {
  105. return false;
  106. }
  107. },
  108. retypePasswordView: Ember.TextField.extend({
  109. placeholder: Em.I18n.t('form.passwordRetype'),
  110. attributeBindings:['readOnly'],
  111. type: 'password',
  112. classNames: [ 'span4', 'retyped-password' ],
  113. keyPress: function (event) {
  114. if (event.keyCode == 13) {
  115. return false;
  116. }
  117. },
  118. valueBinding: 'parentView.serviceConfig.retypedPassword',
  119. readOnly: function () {
  120. return !this.get('parentView.serviceConfig.isEditable');
  121. }.property('parentView.serviceConfig.isEditable')
  122. }),
  123. readOnly: function () {
  124. return !this.get('serviceConfig.isEditable');
  125. }.property('serviceConfig.isEditable')
  126. });
  127. /**
  128. * Textarea control
  129. * @type {*}
  130. */
  131. App.ServiceConfigTextArea = Ember.TextArea.extend(App.ServiceConfigPopoverSupport, {
  132. valueBinding: 'serviceConfig.value',
  133. rows: 4,
  134. classNames: ['span9', 'directories'],
  135. placeholderBinding: 'serviceConfig.defaultValue'
  136. });
  137. /**
  138. * Textarea control with bigger height
  139. * @type {*}
  140. */
  141. App.ServiceConfigBigTextArea = App.ServiceConfigTextArea.extend({
  142. rows: 10
  143. });
  144. /**
  145. * Checkbox control
  146. * @type {*}
  147. */
  148. App.ServiceConfigCheckbox = Ember.Checkbox.extend(App.ServiceConfigPopoverSupport, {
  149. checkedBinding: 'serviceConfig.value',
  150. disabled: function () {
  151. return !this.get('serviceConfig.isEditable');
  152. }.property('serviceConfig.isEditable')
  153. });
  154. App.ServiceConfigRadioButtons = Ember.View.extend({
  155. templateName: require('templates/wizard/controls_service_config_radio_buttons'),
  156. didInsertElement: function () {
  157. // on page render, automatically populate JDBC URLs only for default database settings
  158. // so as to not lose the user's customizations on these fields
  159. if (['addServiceController', 'installerController'].contains(App.clusterStatus.wizardControllerName) && ['New MySQL Database', 'New Derby Database'].contains(this.get('serviceConfig.value'))) {
  160. this.onOptionsChange();
  161. }
  162. },
  163. configs: function () {
  164. return this.get('categoryConfigsAll').filterProperty('isObserved', true);
  165. }.property('categoryConfigsAll'),
  166. serviceConfig: null,
  167. categoryConfigsAll: null,
  168. onOptionsChange: function () {
  169. // The following if condition will be satisfied only for installer wizard flow
  170. if (this.get('configs').length) {
  171. var connectionUrl = this.get('connectionUrl');
  172. var dbClass = this.get('dbClass');
  173. if (connectionUrl) {
  174. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  175. switch (this.get('serviceConfig.value')) {
  176. case 'New MySQL Database':
  177. case 'Existing MySQL Database':
  178. connectionUrl.set('value', "jdbc:mysql://" + this.get('hostName') + "/" + this.get('databaseName') + "?createDatabaseIfNotExist=true");
  179. dbClass.set('value', "com.mysql.jdbc.Driver");
  180. break;
  181. case 'Existing Oracle Database':
  182. connectionUrl.set('value', "jdbc:oracle:thin:@//" + this.get('hostName') + ":1521/" + this.get('databaseName'));
  183. dbClass.set('value', "oracle.jdbc.driver.OracleDriver");
  184. break;
  185. }
  186. } else if (this.get('serviceConfig.serviceName') === 'OOZIE') {
  187. switch (this.get('serviceConfig.value')) {
  188. case 'New Derby Database':
  189. connectionUrl.set('value', "jdbc:derby:${oozie.data.dir}/${oozie.db.schema.name}-db;create=true");
  190. dbClass.set('value', "org.apache.derby.jdbc.EmbeddedDriver");
  191. break;
  192. case 'Existing MySQL Database':
  193. connectionUrl.set('value', "jdbc:mysql://" + this.get('hostName') + "/" + this.get('databaseName'));
  194. dbClass.set('value', "com.mysql.jdbc.Driver");
  195. break;
  196. case 'Existing Oracle Database':
  197. connectionUrl.set('value', "jdbc:oracle:thin:@//" + this.get('hostName') + ":1521/" + this.get('databaseName'));
  198. dbClass.set('value', "oracle.jdbc.driver.OracleDriver");
  199. break;
  200. }
  201. }
  202. connectionUrl.set('defaultValue', connectionUrl.get('value'));
  203. }
  204. }
  205. }.observes('databaseName', 'hostName', 'connectionUrl','dbClass'),
  206. nameBinding: 'serviceConfig.radioName',
  207. databaseName: function () {
  208. switch (this.get('serviceConfig.serviceName')) {
  209. case 'HIVE':
  210. return this.get('categoryConfigsAll').findProperty('name', 'ambari.hive.db.schema.name').get('value');
  211. case 'OOZIE':
  212. return this.get('categoryConfigsAll').findProperty('name', 'oozie.db.schema.name').get('value');
  213. default:
  214. return null;
  215. }
  216. }.property('configs.@each.value', 'serviceConfig.serviceName'),
  217. hostName: function () {
  218. var value = this.get('serviceConfig.value');
  219. var returnValue;
  220. var hostname;
  221. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  222. switch (value) {
  223. case 'New MySQL Database':
  224. hostname = this.get('categoryConfigsAll').findProperty('name', 'hive_ambari_host');
  225. break;
  226. case 'Existing MySQL Database':
  227. hostname = this.get('categoryConfigsAll').findProperty('name', 'hive_existing_mysql_host');
  228. break;
  229. case 'Existing Oracle Database':
  230. hostname = this.get('categoryConfigsAll').findProperty('name', 'hive_existing_oracle_host');
  231. break;
  232. }
  233. if (hostname) {
  234. returnValue = hostname.get('value');
  235. } else {
  236. returnValue = this.get('categoryConfigsAll').findProperty('name', 'hive_hostname').get('value');
  237. }
  238. } else if (this.get('serviceConfig.serviceName') === 'OOZIE') {
  239. switch (value) {
  240. case 'New Derby Database':
  241. hostname = this.get('categoryConfigsAll').findProperty('name', 'oozie_ambari_host');
  242. break;
  243. case 'Existing MySQL Database':
  244. hostname = this.get('categoryConfigsAll').findProperty('name', 'oozie_existing_mysql_host');
  245. break;
  246. case 'Existing Oracle Database':
  247. hostname = this.get('categoryConfigsAll').findProperty('name', 'oozie_existing_oracle_host');
  248. break;
  249. }
  250. if (hostname) {
  251. returnValue = hostname.get('value');
  252. } else {
  253. returnValue = this.get('categoryConfigsAll').findProperty('name', 'oozie_hostname').get('value');
  254. }
  255. }
  256. return returnValue;
  257. }.property('serviceConfig.serviceName', 'serviceConfig.value', 'configs.@each.value'),
  258. connectionUrl: function () {
  259. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  260. return this.get('categoryConfigsAll').findProperty('name', 'javax.jdo.option.ConnectionURL');
  261. } else {
  262. return this.get('categoryConfigsAll').findProperty('name', 'oozie.service.JPAService.jdbc.url');
  263. }
  264. }.property('serviceConfig.serviceName'),
  265. dbClass: function () {
  266. if (this.get('serviceConfig.serviceName') === 'HIVE') {
  267. return this.get('categoryConfigsAll').findProperty('name', 'javax.jdo.option.ConnectionDriverName');
  268. } else {
  269. return this.get('categoryConfigsAll').findProperty('name', 'oozie.service.JPAService.jdbc.driver');
  270. }
  271. }.property('serviceConfig.serviceName'),
  272. optionsBinding: 'serviceConfig.options'
  273. });
  274. App.ServiceConfigRadioButton = Ember.Checkbox.extend({
  275. tagName: 'input',
  276. attributeBindings: ['type', 'name', 'value', 'checked'],
  277. checked: false,
  278. type: 'radio',
  279. name: null,
  280. value: null,
  281. didInsertElement: function () {
  282. console.debug('App.ServiceConfigRadioButton.didInsertElement');
  283. if (this.get('parentView.serviceConfig.value') === this.get('value')) {
  284. console.debug(this.get('name') + ":" + this.get('value') + ' is checked');
  285. this.set('checked', true);
  286. }
  287. },
  288. click: function () {
  289. this.set('checked', true);
  290. console.debug('App.ServiceConfigRadioButton.click');
  291. this.onChecked();
  292. },
  293. onChecked: function () {
  294. // Wrapping the call with Ember.run.next prevents a problem where setting isVisible on component
  295. // causes JS error due to re-rendering. For example, this occurs when switching the Config Group
  296. // in Service Config page
  297. Ember.run.next(this, function() {
  298. console.debug('App.ServiceConfigRadioButton.onChecked');
  299. this.set('parentView.serviceConfig.value', this.get('value'));
  300. var components = this.get('parentView.serviceConfig.options');
  301. components
  302. .forEach(function (_component) {
  303. if (_component.foreignKeys) {
  304. _component.foreignKeys.forEach(function (_componentName) {
  305. if (this.get('parentView.categoryConfigsAll').someProperty('name', _componentName)) {
  306. var component = this.get('parentView.categoryConfigsAll').findProperty('name', _componentName);
  307. if (_component.displayName === this.get('value')) {
  308. console.debug('setting isVisible on ' + component.get('name'));
  309. component.set('isVisible', true);
  310. } else {
  311. component.set('isVisible', false);
  312. }
  313. }
  314. }, this);
  315. }
  316. }, this);
  317. });
  318. }.observes('checked'),
  319. disabled: function () {
  320. return !this.get('parentView.serviceConfig.isEditable');
  321. }.property('parentView.serviceConfig.isEditable')
  322. });
  323. App.ServiceConfigComboBox = Ember.Select.extend(App.ServiceConfigPopoverSupport, {
  324. contentBinding: 'serviceConfig.options',
  325. selectionBinding: 'serviceConfig.value',
  326. classNames: [ 'span3' ]
  327. });
  328. /**
  329. * Base component for host config with popover support
  330. */
  331. App.ServiceConfigHostPopoverSupport = Ember.Mixin.create({
  332. /**
  333. * Config object. It will instance of App.ServiceConfigProperty
  334. */
  335. serviceConfig: null,
  336. didInsertElement: function () {
  337. App.popover(this.$(), {
  338. title: this.get('serviceConfig.displayName'),
  339. content: this.get('serviceConfig.description'),
  340. placement: 'right',
  341. trigger: 'hover'
  342. });
  343. }
  344. });
  345. /**
  346. * Master host component.
  347. * Show hostname without ability to edit it
  348. * @type {*}
  349. */
  350. App.ServiceConfigMasterHostView = Ember.View.extend(App.ServiceConfigHostPopoverSupport, {
  351. classNames: ['master-host', 'span6'],
  352. valueBinding: 'serviceConfig.value',
  353. template: Ember.Handlebars.compile('{{value}}')
  354. });
  355. /**
  356. * Base component to display Multiple hosts
  357. * @type {*}
  358. */
  359. App.ServiceConfigMultipleHostsDisplay = Ember.Mixin.create(App.ServiceConfigHostPopoverSupport, {
  360. hasNoHosts: function () {
  361. console.log('view', this.get('viewName')); //to know which View cause errors
  362. console.log('controller', this.get('controller').name); //should be slaveComponentGroupsController
  363. if (!this.get('value')) {
  364. return true;
  365. }
  366. return this.get('value').length === 0;
  367. }.property('value'),
  368. hasOneHost: function () {
  369. return this.get('value').length === 1;
  370. }.property('value'),
  371. hasMultipleHosts: function () {
  372. return this.get('value').length > 1;
  373. }.property('value'),
  374. otherLength: function () {
  375. var len = this.get('value').length;
  376. if (len > 2) {
  377. return Em.I18n.t('installer.controls.serviceConfigMultipleHosts.others').format(len - 1);
  378. } else {
  379. return Em.I18n.t('installer.controls.serviceConfigMultipleHosts.other');
  380. }
  381. }.property('value')
  382. });
  383. /**
  384. * Multiple master host component.
  385. * Show hostnames without ability to edit it
  386. * @type {*}
  387. */
  388. App.ServiceConfigMasterHostsView = Ember.View.extend(App.ServiceConfigMultipleHostsDisplay, {
  389. viewName: "serviceConfigMasterHostsView",
  390. valueBinding: 'serviceConfig.value',
  391. classNames: ['master-hosts', 'span6'],
  392. templateName: require('templates/wizard/master_hosts'),
  393. /**
  394. * Onclick handler for link
  395. */
  396. showHosts: function () {
  397. var serviceConfig = this.get('serviceConfig');
  398. App.ModalPopup.show({
  399. header: Em.I18n.t('installer.controls.serviceConfigMasterHosts.header').format(serviceConfig.category),
  400. bodyClass: Ember.View.extend({
  401. serviceConfig: serviceConfig,
  402. templateName: require('templates/wizard/master_hosts_popup')
  403. }),
  404. secondary: null
  405. });
  406. }
  407. });
  408. /**
  409. * Show tabs list for slave hosts
  410. * @type {*}
  411. */
  412. App.SlaveComponentGroupsMenu = Em.CollectionView.extend({
  413. content: function () {
  414. return this.get('controller.componentGroups');
  415. }.property('controller.componentGroups'),
  416. tagName: 'ul',
  417. classNames: ["nav", "nav-tabs"],
  418. itemViewClass: Em.View.extend({
  419. classNameBindings: ["active"],
  420. active: function () {
  421. return this.get('content.active');
  422. }.property('content.active'),
  423. errorCount: function () {
  424. return this.get('content.properties').filterProperty('isValid', false).filterProperty('isVisible', true).get('length');
  425. }.property('content.properties.@each.isValid', 'content.properties.@each.isVisible'),
  426. templateName: require('templates/wizard/controls_slave_component_groups_menu')
  427. })
  428. });
  429. /**
  430. * <code>Add group</code> button
  431. * @type {*}
  432. */
  433. App.AddSlaveComponentGroupButton = Ember.View.extend({
  434. tagName: 'span',
  435. slaveComponentName: null,
  436. didInsertElement: function () {
  437. App.popover(this.$(), {
  438. title: Em.I18n.t('installer.controls.addSlaveComponentGroupButton.title').format(this.get('slaveComponentName')),
  439. content: Em.I18n.t('installer.controls.addSlaveComponentGroupButton.content').format(this.get('slaveComponentName'), this.get('slaveComponentName'), this.get('slaveComponentName')),
  440. placement: 'right',
  441. trigger: 'hover'
  442. });
  443. }
  444. });
  445. /**
  446. * Multiple Slave Hosts component
  447. * @type {*}
  448. */
  449. App.ServiceConfigSlaveHostsView = Ember.View.extend(App.ServiceConfigMultipleHostsDisplay, {
  450. viewName: 'serviceConfigSlaveHostsView',
  451. classNames: ['slave-hosts', 'span6'],
  452. valueBinding: 'serviceConfig.value',
  453. templateName: require('templates/wizard/slave_hosts'),
  454. /**
  455. * Onclick handler for link
  456. */
  457. showHosts: function () {
  458. var serviceConfig = this.get('serviceConfig');
  459. App.ModalPopup.show({
  460. header: Em.I18n.t('installer.controls.serviceConfigMasterHosts.header').format(serviceConfig.category),
  461. bodyClass: Ember.View.extend({
  462. serviceConfig: serviceConfig,
  463. templateName: require('templates/wizard/master_hosts_popup')
  464. }),
  465. secondary: null
  466. });
  467. }
  468. });
  469. /**
  470. * properties for present active slave group
  471. * @type {*}
  472. */
  473. App.SlaveGroupPropertiesView = Ember.View.extend({
  474. viewName: 'serviceConfigSlaveHostsView',
  475. group: function () {
  476. return this.get('controller.activeGroup');
  477. }.property('controller.activeGroup'),
  478. groupConfigs: function () {
  479. console.log("************************************************************************");
  480. console.log("The value of group is: " + this.get('group'));
  481. console.log("************************************************************************");
  482. return this.get('group.properties');
  483. }.property('group.properties.@each').cacheable(),
  484. errorCount: function () {
  485. return this.get('group.properties').filterProperty('isValid', false).filterProperty('isVisible', true).get('length');
  486. }.property('configs.@each.isValid', 'configs.@each.isVisible')
  487. });
  488. /**
  489. * DropDown component for <code>select hosts for groups</code> popup
  490. * @type {*}
  491. */
  492. App.SlaveComponentDropDownGroupView = Ember.View.extend({
  493. viewName: "slaveComponentDropDownGroupView",
  494. /**
  495. * On change handler for <code>select hosts for groups</code> popup
  496. * @param event
  497. */
  498. changeGroup: function (event) {
  499. var host = this.get('content');
  500. var groupName = $('#' + this.get('elementId') + ' select').val();
  501. this.get('controller').changeHostGroup(host, groupName);
  502. },
  503. optionTag: Ember.View.extend({
  504. /**
  505. * Whether current value(OptionTag value) equals to host value(assigned to SlaveComponentDropDownGroupView.content)
  506. */
  507. selected: function () {
  508. return this.get('parentView.content.group') === this.get('content');
  509. }.property('content')
  510. })
  511. });
  512. /**
  513. * Show info about current group
  514. * @type {*}
  515. */
  516. App.SlaveComponentChangeGroupNameView = Ember.View.extend({
  517. contentBinding: 'controller.activeGroup',
  518. classNames: ['control-group'],
  519. classNameBindings: 'error',
  520. error: false,
  521. setError: function () {
  522. this.set('error', false);
  523. }.observes('controller.activeGroup'),
  524. errorMessage: function () {
  525. return this.get('error') ? Em.I18n.t('installer.controls.slaveComponentChangeGroupName.error') : '';
  526. }.property('error'),
  527. /**
  528. * Onclick handler for saving updated group name
  529. * @param event
  530. */
  531. changeGroupName: function (event) {
  532. var inputVal = $('#' + this.get('elementId') + ' input[type="text"]').val();
  533. if (inputVal !== this.get('content.name')) {
  534. var result = this.get('controller').changeSlaveGroupName(this.get('content'), inputVal);
  535. this.set('error', result);
  536. }
  537. }
  538. });