controls_view.js 20 KB

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