controls_view.js 44 KB

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