service_config_property.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. var validator = require('utils/validator');
  20. /**
  21. * @class ServiceConfigProperty
  22. */
  23. App.ServiceConfigProperty = Em.Object.extend({
  24. name: '',
  25. displayName: '',
  26. /**
  27. * value that is shown on IU
  28. * and is changing by user
  29. * @type {String|null}
  30. */
  31. value: '',
  32. /**
  33. * value that is saved on cluster configs
  34. * and stored in /api/v1/clusters/{name}/configurations
  35. * @type {String|null}
  36. */
  37. savedValue: null,
  38. /**
  39. * value that is returned from server as recommended
  40. * or stored on stack
  41. * @type {String|null}
  42. */
  43. recommendedValue: null,
  44. /**
  45. * initial value of config. if value is saved it will be initial
  46. * otherwise first recommendedValue will be initial
  47. * @type {String|null}
  48. */
  49. initialValue: null,
  50. /**
  51. * value that is shown on IU
  52. * and is changing by user
  53. * @type {boolean}
  54. */
  55. isFinal: false,
  56. /**
  57. * value that is saved on cluster configs api
  58. * @type {boolean}
  59. */
  60. savedIsFinal: null,
  61. /**
  62. * value that is returned from server as recommended
  63. * or stored on stack
  64. * @type {boolean}
  65. */
  66. recommendedIsFinal: null,
  67. /**
  68. * @type {boolean}
  69. */
  70. supportsFinal: false,
  71. /**
  72. * Hint message to display in tooltip. Tooltip will be wrapped on question mark icon.
  73. * If value is <code>false</code> no tooltip and question mark icon.
  74. *
  75. * @type {boolean|string}
  76. */
  77. hintMessage: false,
  78. /**
  79. * Display label on the right side from input. In general used for checkbox only.
  80. *
  81. * @type {boolean}
  82. */
  83. rightSideLabel: false,
  84. /**
  85. * Text to be shown as placeholder
  86. * By default savedValue is shown as placeholder
  87. * @type {String}
  88. */
  89. placeholderText: '',
  90. /**
  91. * type of widget View
  92. * @type {string}
  93. * @default null
  94. */
  95. widgetType: null,
  96. /**
  97. * Placeholder used for configs with input type text
  98. */
  99. placeholder: function () {
  100. return this.get('placeholderText') || this.get('savedValue');
  101. }.property('savedValue', 'placeholderText'),
  102. retypedPassword: '',
  103. description: '',
  104. displayType: 'string', // string, digits, number, directories, custom
  105. unit: '',
  106. category: 'General',
  107. isRequired: true, // by default a config property is required
  108. isReconfigurable: true, // by default a config property is reconfigurable
  109. isEditable: true, // by default a config property is editable
  110. isNotEditable: Ember.computed.not('isEditable'),
  111. hideFinalIcon: function () {
  112. return (!this.get('isFinal')) && this.get('isNotEditable');
  113. }.property('isFinal', 'isNotEditable'),
  114. isVisible: true,
  115. isMock: false, // mock config created created only to displaying
  116. isRequiredByAgent: true, // Setting it to true implies property will be stored in configuration
  117. isSecureConfig: false,
  118. errorMessage: '',
  119. warnMessage: '',
  120. serviceConfig: null, // points to the parent App.ServiceConfig object
  121. filename: '',
  122. isOriginalSCP : true, // if true, then this is original SCP instance and its value is not overridden value.
  123. parentSCP: null, // This is the main SCP which is overridden by this. Set only when isOriginalSCP is false.
  124. overrides : null,
  125. overrideValues: [],
  126. group: null, // Contain group related to this property. Set only when isOriginalSCP is false.
  127. isUserProperty: null, // This property was added by user. Hence they get removal actions etc.
  128. isOverridable: true,
  129. compareConfigs: [],
  130. isComparison: false,
  131. hasCompareDiffs: false,
  132. showLabel: true,
  133. error: false,
  134. warn: false,
  135. previousValue: null, // cached value before changing config <code>value</code>
  136. /**
  137. * List of <code>isFinal</code>-values for overrides
  138. * Set in the controller
  139. * Should be empty array by default!
  140. * @type {boolean[]}
  141. */
  142. overrideIsFinalValues: [],
  143. /**
  144. * true if property has warning or error
  145. * @type {boolean}
  146. */
  147. hasIssues: function () {
  148. var originalSCPIssued = (this.get('errorMessage') + this.get('warnMessage')) !== "";
  149. var overridesIssue = false;
  150. (this.get('overrides') || []).forEach(function(override) {
  151. if (override.get('errorMessage') + override.get('warnMessage') !== "") {
  152. overridesIssue = true;
  153. return;
  154. }
  155. });
  156. return originalSCPIssued || overridesIssue;
  157. }.property('errorMessage', 'warnMessage', 'overrideErrorTrigger'),
  158. overrideErrorTrigger: 0, //Trigger for overridable property error
  159. index: null, //sequence number in category
  160. editDone: false, //Text field: on focusOut: true, on focusIn: false
  161. isNotSaved: false, // user property was added but not saved
  162. hasInitialValue: false, //if true then property value is defined and saved to server
  163. isHiddenByFilter: false, //if true then hide this property (filtered out)
  164. rowStyleClass: null, // CSS-Class to be applied on the row showing this config
  165. showAsTextBox: false,
  166. /**
  167. * config is invisible since wrapper section is hidden
  168. * @type {boolean}
  169. */
  170. hiddenBySection: false,
  171. /**
  172. * @type {boolean}
  173. */
  174. recommendedValueExists: function () {
  175. return !Em.isNone(this.get('recommendedValue')) && (this.get('recommendedValue') != "")
  176. && this.get('isRequiredByAgent') && !this.get('cantBeUndone');
  177. }.property('recommendedValue'),
  178. /**
  179. * Usage example see on <code>App.ServiceConfigRadioButtons.handleDBConnectionProperty()</code>
  180. *
  181. * @property {Ember.View} additionalView - custom view related to property
  182. **/
  183. additionalView: null,
  184. /**
  185. * On Overridable property error message, change overrideErrorTrigger value to recount number of errors service have
  186. */
  187. observeErrors: function () {
  188. this.set("overrideErrorTrigger", this.get("overrideErrorTrigger") + 1);
  189. }.observes("overrides.@each.errorMessage"),
  190. /**
  191. * No override capabilities for fields which are not edtiable
  192. * and fields which represent master hosts.
  193. */
  194. isPropertyOverridable: function () {
  195. var overrideable = this.get('isOverridable');
  196. var editable = this.get('isEditable');
  197. var overrides = this.get('overrides');
  198. var dt = this.get('displayType');
  199. return overrideable && (editable || !overrides || !overrides.length) && (!["componentHost", "password"].contains(dt));
  200. }.property('isEditable', 'displayType', 'isOverridable', 'overrides.length'),
  201. isOverridden: function() {
  202. return (this.get('overrides') != null && this.get('overrides.length') > 0) || !this.get('isOriginalSCP');
  203. }.property('overrides', 'overrides.length', 'isOriginalSCP'),
  204. isOverrideChanged: function () {
  205. if (Em.isNone(this.get('overrides')) && this.get('overrideValues.length') === 0) return false;
  206. return JSON.stringify(this.get('overrides').mapProperty('isFinal')) !== JSON.stringify(this.get('overrideIsFinalValues'))
  207. || JSON.stringify(this.get('overrides').mapProperty('value')) !== JSON.stringify(this.get('overrideValues'));
  208. }.property('isOverridden', 'overrides.@each.isNotDefaultValue', 'overrideValues.length'),
  209. isRemovable: function() {
  210. return this.get('isEditable') && this.get('isRequiredByAgent') && !(this.get('overrides.length') > 0)
  211. && (this.get('isUserProperty') || !this.get('isOriginalSCP'));
  212. }.property('isUserProperty', 'isOriginalSCP', 'overrides.length', 'isRequiredByAgent'),
  213. init: function () {
  214. if (this.get('value') == '') {
  215. if (this.get('savedValue')) {
  216. this.set('value', this.get('savedValue'));
  217. } else if (this.get('recommendedValue')) {
  218. this.set('value', this.get('recommendedValue'));
  219. }
  220. }
  221. if(this.get("displayType") === "password") {
  222. this.set('retypedPassword', this.get('value'));
  223. this.set('recommendedValue', '');
  224. }
  225. this.set('initialValue', this.get('value'));
  226. this.updateDescription();
  227. },
  228. /**
  229. * Indicates when value is not the default value.
  230. * Returns false when there is no default value.
  231. */
  232. isNotDefaultValue: function () {
  233. var value = this.get('value');
  234. var savedValue = this.get('savedValue');
  235. var supportsFinal = this.get('supportsFinal');
  236. var isFinal = this.get('isFinal');
  237. var savedIsFinal = this.get('savedIsFinal');
  238. // ignore precision difference for configs with type of `float` which value may ends with 0
  239. // e.g. between 0.4 and 0.40
  240. if (this.get('stackConfigProperty') && this.get('stackConfigProperty.valueAttributes.type') == 'float') {
  241. savedValue = !Em.isNone(savedValue) ? '' + parseFloat(savedValue) : null;
  242. value = '' + parseFloat(value);
  243. }
  244. return (savedValue != null && value !== savedValue) || (supportsFinal && !Em.isNone(savedIsFinal) && isFinal !== savedIsFinal);
  245. }.property('value', 'savedValue', 'isEditable', 'isFinal', 'savedIsFinal'),
  246. /**
  247. * Don't show "Undo" for hosts on Installer Step7
  248. */
  249. cantBeUndone: function() {
  250. return ["componentHost", "componentHosts", "radio button"].contains(this.get('displayType'));
  251. }.property('displayType'),
  252. isValid: function () {
  253. return this.get('errorMessage') === '';
  254. }.property('errorMessage'),
  255. viewClass: function () {
  256. switch (this.get('displayType')) {
  257. case 'checkbox':
  258. case 'boolean':
  259. if (this.get('dependentConfigPattern')) {
  260. return App.ServiceConfigCheckboxWithDependencies;
  261. } else {
  262. return App.ServiceConfigCheckbox;
  263. }
  264. case 'password':
  265. return App.ServiceConfigPasswordField;
  266. case 'combobox':
  267. return App.ServiceConfigComboBox;
  268. case 'radio button':
  269. return App.ServiceConfigRadioButtons;
  270. break;
  271. case 'directories':
  272. return App.ServiceConfigTextArea;
  273. break;
  274. case 'content':
  275. return App.ServiceConfigTextAreaContent;
  276. break;
  277. case 'multiLine':
  278. return App.ServiceConfigTextArea;
  279. break;
  280. case 'custom':
  281. return App.ServiceConfigBigTextArea;
  282. case 'componentHost':
  283. return App.ServiceConfigMasterHostView;
  284. case 'label':
  285. return App.ServiceConfigLabelView;
  286. case 'componentHosts':
  287. return App.ServiceConfigComponentHostsView;
  288. case 'supportTextConnection':
  289. return App.checkConnectionView;
  290. default:
  291. if (this.get('unit')) {
  292. return App.ServiceConfigTextFieldWithUnit;
  293. } else {
  294. return App.ServiceConfigTextField;
  295. }
  296. }
  297. }.property('displayType'),
  298. validate: function () {
  299. var value = this.get('value');
  300. var supportsFinal = this.get('supportsFinal');
  301. var isFinal = this.get('isFinal');
  302. var valueRange = this.get('valueRange');
  303. var isError = false;
  304. var isWarn = false;
  305. if (typeof value === 'string' && value.length === 0) {
  306. if (this.get('isRequired')) {
  307. this.set('errorMessage', 'This is required');
  308. isError = true;
  309. } else {
  310. return;
  311. }
  312. }
  313. if (!isError) {
  314. switch (this.get('displayType')) {
  315. case 'int':
  316. if (('' + value).trim().length === 0) {
  317. this.set('errorMessage', '');
  318. isError = false;
  319. return;
  320. }
  321. if (validator.isConfigValueLink(value)) {
  322. isError = false;
  323. } else if (!validator.isValidInt(value)) {
  324. this.set('errorMessage', 'Must contain digits only');
  325. isError = true;
  326. } else {
  327. if(valueRange){
  328. if(value < valueRange[0] || value > valueRange[1]){
  329. this.set('errorMessage', 'Must match the range');
  330. isError = true;
  331. }
  332. }
  333. }
  334. break;
  335. case 'float':
  336. if (validator.isConfigValueLink(value)) {
  337. isError = false;
  338. } else if (!validator.isValidFloat(value)) {
  339. this.set('errorMessage', 'Must be a valid number');
  340. isError = true;
  341. }
  342. break;
  343. case 'checkbox':
  344. break;
  345. case 'directories':
  346. case 'directory':
  347. if (this.get('configSupportHeterogeneous')) {
  348. if (!validator.isValidDataNodeDir(value)) {
  349. this.set('errorMessage', 'dir format is wrong, can be "[{storage type}]/{dir name}"');
  350. isError = true;
  351. }
  352. } else {
  353. if (!validator.isValidDir(value)) {
  354. this.set('errorMessage', 'Must be a slash or drive at the start, and must not contain white spaces');
  355. isError = true;
  356. }
  357. }
  358. if (!isError) {
  359. if (!validator.isAllowedDir(value)) {
  360. this.set('errorMessage', 'Can\'t start with "home(s)"');
  361. isError = true;
  362. } else {
  363. // Invalidate values which end with spaces.
  364. if (value !== ' ' && validator.isNotTrimmedRight(value)) {
  365. this.set('errorMessage', Em.I18n.t('form.validator.error.trailingSpaces'));
  366. isError = true;
  367. }
  368. }
  369. }
  370. break;
  371. case 'custom':
  372. break;
  373. case 'email':
  374. if (!validator.isValidEmail(value)) {
  375. this.set('errorMessage', 'Must be a valid email address');
  376. isError = true;
  377. }
  378. break;
  379. case 'supportTextConnection':
  380. case 'host':
  381. var connectionProperties = ['kdc_host'];
  382. var hiveOozieHostNames = ['hive_hostname','oozie_hostname'];
  383. if(hiveOozieHostNames.contains(this.get('name'))) {
  384. if (validator.hasSpaces(value)) {
  385. this.set('errorMessage', Em.I18n.t('host.spacesValidation'));
  386. isError = true;
  387. }
  388. } else {
  389. if ((validator.isNotTrimmed(value) && connectionProperties.contains(this.get('name')) || validator.isNotTrimmed(value))) {
  390. this.set('errorMessage', Em.I18n.t('host.trimspacesValidation'));
  391. isError = true;
  392. }
  393. }
  394. break;
  395. case 'password':
  396. // retypedPassword is set by the retypePasswordView child view of App.ServiceConfigPasswordField
  397. if (value !== this.get('retypedPassword')) {
  398. this.set('errorMessage', 'Passwords do not match');
  399. isError = true;
  400. }
  401. break;
  402. case 'multiLine':
  403. case 'content':
  404. default:
  405. if(this.get('name')=='javax.jdo.option.ConnectionURL' || this.get('name')=='oozie.service.JPAService.jdbc.url') {
  406. if (validator.isConfigValueLink(value)) {
  407. isError = false;
  408. } else if (validator.isNotTrimmed(value)) {
  409. this.set('errorMessage', Em.I18n.t('host.trimspacesValidation'));
  410. isError = true;
  411. }
  412. } else {
  413. // Avoid single space values which is work around for validate empty properties.
  414. // Invalidate values which end with spaces.
  415. if (value !== ' ' && validator.isNotTrimmedRight(value)) {
  416. this.set('errorMessage', Em.I18n.t('form.validator.error.trailingSpaces'));
  417. isError = true;
  418. }
  419. }
  420. break;
  421. }
  422. }
  423. if (!isWarn || isError) { // Errors get priority
  424. this.set('warnMessage', '');
  425. this.set('warn', false);
  426. } else {
  427. this.set('warn', true);
  428. }
  429. if (!isError) {
  430. this.set('errorMessage', '');
  431. this.set('error', false);
  432. } else {
  433. this.set('error', true);
  434. }
  435. }.observes('value', 'isFinal', 'retypedPassword'),
  436. /**
  437. * defines specific directory properties that
  438. * allows setting drive type before dir name
  439. * ex: [SSD]/usr/local/my_dir
  440. * @param config
  441. * @returns {*|Boolean|boolean}
  442. */
  443. configSupportHeterogeneous: function() {
  444. if (App.get('isHadoop22Stack')) {
  445. return ['directories', 'directory'].contains(this.get('displayType')) && ['dfs.datanode.data.dir'].contains(this.get('name'));
  446. } else {
  447. return false;
  448. }
  449. }.property('displayType', 'name', 'App.isHadoop22Stack'),
  450. /**
  451. * Update description for `password`-config
  452. * Add extra-message about their comparison
  453. *
  454. * @method updateDescription
  455. */
  456. updateDescription: function () {
  457. var description = this.get('description');
  458. var displayType = this.get('displayType');
  459. var additionalDescription = Em.I18n.t('services.service.config.password.additionalDescription');
  460. if ('password' === displayType && !description.contains(additionalDescription)) {
  461. description += '<br />' + additionalDescription;
  462. }
  463. this.set('description', description);
  464. }
  465. });