services_config.js 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  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. var stringUtils = require('utils/string_utils');
  21. var hostsUtils = require('utils/hosts');
  22. App.ServicesConfigView = Em.View.extend({
  23. templateName: require('templates/common/configs/services_config'),
  24. didInsertElement: function () {
  25. var controller = this.get('controller');
  26. controller.loadStep();
  27. }
  28. });
  29. App.ServiceConfigView = Em.View.extend({
  30. templateName: require('templates/common/configs/service_config'),
  31. isRestartMessageCollapsed: false,
  32. filter: '', //from template
  33. columns: [], //from template
  34. canEdit: true, // View is editable or read-only?
  35. toggleRestartMessageView: function () {
  36. this.$('.service-body').toggle('blind', 200);
  37. this.set('isRestartMessageCollapsed', !this.get('isRestartMessageCollapsed'));
  38. },
  39. didInsertElement: function () {
  40. if(this.get('isNotEditable') === true) {
  41. this.set('canEdit', false);
  42. }
  43. this.$('.service-body').hide();
  44. $(".restart-required-property").tooltip({html: true});
  45. $(".icon-lock").tooltip({placement: 'right'});
  46. }
  47. });
  48. App.ServiceConfigsByCategoryView = Ember.View.extend({
  49. classNames: ['accordion-group', 'common-config-category'],
  50. classNameBindings: ['category.name', 'isShowBlock::hidden'],
  51. content: null,
  52. category: null,
  53. service: null,
  54. canEdit: true, // View is editable or read-only?
  55. serviceConfigs: null, // General, Advanced, NameNode, SNameNode, DataNode, etc.
  56. // total number of
  57. // hosts (by
  58. // default,
  59. // cacheable )
  60. categoryConfigs: function () {
  61. return this.get('serviceConfigs').filterProperty('category', this.get('category.name')).filterProperty('isVisible', true);
  62. }.property('serviceConfigs.@each', 'categoryConfigsAll.@each.isVisible').cacheable(),
  63. /**
  64. * This method provides all the properties which apply
  65. * to this category, irrespective of visibility. This
  66. * is helpful in Oozie/Hive database configuration, where
  67. * MySQL etc. database options don't show up, because
  68. * they were not visible initially.
  69. */
  70. categoryConfigsAll: function () {
  71. return this.get('serviceConfigs').filterProperty('category', this.get('category.name'));
  72. }.property('serviceConfigs.@each').cacheable(),
  73. /**
  74. * Warn/prompt user to adjust Service props when changing user/groups in Misc
  75. * Is triggered when user ended editing text field
  76. */
  77. miscConfigChange: function (manuallyChangedProperty) {
  78. var changedProperty;
  79. if(manuallyChangedProperty.get("id")){
  80. changedProperty = [manuallyChangedProperty];
  81. }else{
  82. changedProperty = this.get("serviceConfigs").filterProperty("editDone", true);
  83. }
  84. if (changedProperty.length > 0) {
  85. changedProperty = changedProperty.objectAt(0);
  86. } else {
  87. return;
  88. }
  89. if (this.get('controller.selectedService.serviceName') == 'MISC') {
  90. var newValue = changedProperty.get("value");
  91. var stepConfigs = this.get("controller.stepConfigs");
  92. this.affectedProperties = [];
  93. var curConfigs = "";
  94. var affectedPropertyName = App.get('isHadoop2Stack') ? "dfs.permissions.superusergroup" : "dfs.permissions.supergroup";
  95. if (changedProperty.get("name") == "hdfs_user") {
  96. curConfigs = stepConfigs.findProperty("serviceName", "HDFS").get("configs");
  97. if (newValue != curConfigs.findProperty("name", affectedPropertyName).get("value")) {
  98. this.affectedProperties.push(
  99. {
  100. serviceName: "HDFS",
  101. propertyName: affectedPropertyName,
  102. propertyDisplayName: affectedPropertyName,
  103. newValue: newValue,
  104. curValue: curConfigs.findProperty("name", affectedPropertyName).get("value"),
  105. changedPropertyName: "hdfs_user"
  106. }
  107. );
  108. }
  109. if ($.trim(newValue) != $.trim(curConfigs.findProperty("name", "dfs.cluster.administrators").get("value"))) {
  110. this.affectedProperties.push(
  111. {
  112. serviceName: "HDFS",
  113. propertyName: "dfs.cluster.administrators",
  114. propertyDisplayName: "dfs.cluster.administrators",
  115. newValue: " " + $.trim(newValue),
  116. curValue: curConfigs.findProperty("name", "dfs.cluster.administrators").get("value"),
  117. changedPropertyName: "hdfs_user"
  118. }
  119. );
  120. }
  121. } else if (changedProperty.get("name") == "hbase_user" && !App.get('isHadoop2Stack')) {
  122. curConfigs = stepConfigs.findProperty("serviceName", "HDFS").get("configs");
  123. if (newValue != curConfigs.findProperty("name", "dfs.block.local-path-access.user").get("value")) {
  124. this.affectedProperties.push(
  125. {
  126. serviceName: "HDFS",
  127. propertyName: "dfs.block.local-path-access.user",
  128. propertyDisplayName: "dfs.block.local-path-access.user",
  129. newValue: newValue,
  130. curValue: curConfigs.findProperty("name", "dfs.block.local-path-access.user").get("value"),
  131. changedPropertyName: "hbase_user"
  132. }
  133. );
  134. }
  135. var hbaseCurConfigs = stepConfigs.findProperty("serviceName", "HBASE").get("configs");
  136. if (newValue != hbaseCurConfigs.findProperty("name", "hbase.superuser").get("value")) {
  137. this.affectedProperties.push(
  138. {
  139. serviceName: "HBASE",
  140. propertyName: "hbase.superuser",
  141. propertyDisplayName: "hbase.superuser",
  142. newValue: newValue,
  143. curValue: hbaseCurConfigs.findProperty("name", "hbase.superuser").get("value"),
  144. changedPropertyName: "hbase_user"
  145. }
  146. );
  147. }
  148. } else if (changedProperty.get("name") == "user_group") {
  149. if (!((this.get("controller.selectedServiceNames").indexOf("MAPREDUCE") >= 0) || (this.get("controller.selectedServiceNames").indexOf("YARN") >= 0))) {
  150. return;
  151. }
  152. if(this.get("controller.selectedServiceNames").indexOf("MAPREDUCE") >= 0) {
  153. curConfigs = stepConfigs.findProperty("serviceName", "MAPREDUCE").get("configs");
  154. if (newValue != curConfigs.findProperty("name", "mapreduce.tasktracker.group").get("value")) {
  155. this.affectedProperties.push(
  156. {
  157. serviceName: "MAPREDUCE",
  158. propertyName: "mapreduce.tasktracker.group",
  159. propertyDisplayName: "mapreduce.tasktracker.group",
  160. newValue: newValue,
  161. curValue: curConfigs.findProperty("name", "mapreduce.tasktracker.group").get("value"),
  162. changedPropertyName: "user_group"
  163. }
  164. )
  165. }
  166. if ($.trim(newValue) != $.trim(curConfigs.findProperty("name", "mapreduce.cluster.administrators").get("value"))) {
  167. this.affectedProperties.push(
  168. {
  169. serviceName: "MAPREDUCE",
  170. propertyName: "mapreduce.cluster.administrators",
  171. propertyDisplayName: "mapreduce.cluster.administrators",
  172. newValue: " " + $.trim(newValue),
  173. curValue: curConfigs.findProperty("name", "mapreduce.cluster.administrators").get("value"),
  174. changedPropertyName: "user_group"
  175. }
  176. );
  177. }
  178. }
  179. if(this.get("controller.selectedServiceNames").indexOf("MAPREDUCE2") >= 0) {
  180. curConfigs = stepConfigs.findProperty("serviceName", "MAPREDUCE2").get("configs");
  181. if ($.trim(newValue) != $.trim(curConfigs.findProperty("name", "mapreduce.cluster.administrators").get("value"))) {
  182. this.affectedProperties.push(
  183. {
  184. serviceName: "MAPREDUCE2",
  185. propertyName: "mapreduce.cluster.administrators",
  186. propertyDisplayName: "mapreduce.cluster.administrators",
  187. newValue: " " + $.trim(newValue),
  188. curValue: curConfigs.findProperty("name", "mapreduce.cluster.administrators").get("value"),
  189. changedPropertyName: "user_group"
  190. }
  191. );
  192. }
  193. }
  194. if (this.get("controller.selectedServiceNames").indexOf("YARN") >= 0) {
  195. curConfigs = stepConfigs.findProperty("serviceName", "YARN").get("configs");
  196. if (newValue != curConfigs.findProperty("name", "yarn.nodemanager.linux-container-executor.group").get("value")) {
  197. this.affectedProperties.push(
  198. {
  199. serviceName: "YARN",
  200. propertyName: "yarn.nodemanager.linux-container-executor.group",
  201. propertyDisplayName: "yarn.nodemanager.linux-container-executor.group",
  202. newValue: newValue,
  203. curValue: curConfigs.findProperty("name", "yarn.nodemanager.linux-container-executor.group").get("value"),
  204. changedPropertyName: "user_group"
  205. }
  206. )
  207. }
  208. }
  209. }
  210. if (this.affectedProperties.length > 0 && !this.get("controller.miscModalVisible")) {
  211. this.newAffectedProperties = this.affectedProperties;
  212. var self = this;
  213. return App.ModalPopup.show({
  214. classNames: ['modal-690px-width'],
  215. showCloseButton: false,
  216. header: "Warning: you must also change these Service properties",
  217. onApply: function () {
  218. self.get("newAffectedProperties").forEach(function (item) {
  219. self.get("controller.stepConfigs").findProperty("serviceName", item.serviceName).get("configs")
  220. .findProperty("name", item.propertyName).set("value", item.newValue);
  221. });
  222. self.get("controller").set("miscModalVisible", false);
  223. this.hide();
  224. },
  225. onIgnore: function () {
  226. self.get("controller").set("miscModalVisible", false);
  227. this.hide();
  228. },
  229. onUndo: function () {
  230. var affected = self.get("newAffectedProperties").objectAt(0);
  231. self.get("controller.stepConfigs").findProperty("serviceName", "MISC").get("configs")
  232. .findProperty("name", affected.changedPropertyName).set("value", $.trim(affected.curValue));
  233. self.get("controller").set("miscModalVisible", false);
  234. this.hide();
  235. },
  236. footerClass: Ember.View.extend({
  237. classNames: ['modal-footer'],
  238. template: Ember.Handlebars.compile([
  239. '<div class="pull-right">',
  240. '<button class="btn" {{action onUndo target="view.parentView"}}>Cancel</button>',
  241. '<button class="btn btn-warning" {{action onIgnore target="view.parentView"}}>Ignore</button>',
  242. '<button class="btn btn-success" {{action onApply target="view.parentView"}}>Apply</button>',
  243. '</div>'
  244. ].join(''))
  245. }),
  246. bodyClass: Ember.View.extend({
  247. templateName: require('templates/common/configs/propertyDependence'),
  248. controller: this,
  249. propertyChange: self.get("newAffectedProperties"),
  250. didInsertElement: function () {
  251. self.get("controller").set("miscModalVisible", true);
  252. }
  253. })
  254. });
  255. }
  256. }
  257. }.observes('categoryConfigs.@each.editDone'),
  258. /**
  259. * When the view is in read-only mode, it marks
  260. * the properties as read-only.
  261. */
  262. updateReadOnlyFlags: function () {
  263. var configs = this.get('serviceConfigs');
  264. var canEdit = this.get('canEdit');
  265. if (!canEdit && configs) {
  266. configs.forEach(function(c){
  267. c.set('isEditable', false);
  268. var overrides = c.get('overrides');
  269. if (overrides!=null) {
  270. overrides.setEach('isEditable', false);
  271. }
  272. });
  273. }
  274. },
  275. /**
  276. * Filtered <code>categoryConfigs</code> array. Used to show filtered result
  277. */
  278. filteredCategoryConfigs: function () {
  279. var filter = this.get('parentView.filter').toLowerCase();
  280. var isOnlyModified = this.get('parentView.columns').length && this.get('parentView.columns')[1].get('selected');
  281. var isOnlyOverridden = this.get('parentView.columns').length && this.get('parentView.columns')[0].get('selected');
  282. var isOnlyRestartRequired = this.get('parentView.columns').length && this.get('parentView.columns')[2].get('selected');
  283. var filteredResult = this.get('categoryConfigs').filter(function (config) {
  284. if (isOnlyModified && !config.get('isNotDefaultValue')) {
  285. return false;
  286. }
  287. if (isOnlyOverridden && !config.get('isOverridden')) {
  288. return false;
  289. }
  290. if (isOnlyRestartRequired && !config.get('isRestartRequired')) {
  291. return false;
  292. }
  293. var searchString = config.get('defaultValue') + config.get('description') +
  294. config.get('displayName') + config.get('name');
  295. return searchString.toLowerCase().indexOf(filter) > -1;
  296. });
  297. filteredResult = this.sortByIndex(filteredResult);
  298. return filteredResult;
  299. }.property('categoryConfigs', 'parentView.filter', 'parentView.columns.@each.selected'),
  300. /**
  301. * sort configs in current category by index
  302. * @param configs
  303. * @return {*}
  304. */
  305. sortByIndex: function (configs) {
  306. var sortedConfigs = [];
  307. var unSorted = [];
  308. if (!configs.someProperty('index')) {
  309. return configs;
  310. }
  311. configs.forEach(function (config) {
  312. var index = config.get('index');
  313. if ((index !== null) && isFinite(index)) {
  314. sortedConfigs[index] ? sortedConfigs.splice(index, 0, config) : sortedConfigs[index] = config;
  315. } else {
  316. unSorted.push(config);
  317. }
  318. });
  319. // remove undefined elements from array
  320. sortedConfigs = sortedConfigs.filter(function (config) {
  321. if (config !== undefined) return true;
  322. });
  323. return sortedConfigs.concat(unSorted);
  324. },
  325. /**
  326. * Onclick handler for Config Group Header. Used to show/hide block
  327. */
  328. onToggleBlock: function () {
  329. this.$('.accordion-body').toggle('blind', 500);
  330. this.set('category.isCollapsed', !this.get('category.isCollapsed'));
  331. },
  332. /**
  333. * Should we show config group or not
  334. */
  335. isShowBlock: function () {
  336. return this.get('category.canAddProperty') || this.get('filteredCategoryConfigs').length > 0;
  337. }.property('category.canAddProperty', 'filteredCategoryConfigs.length'),
  338. didInsertElement: function () {
  339. var isCollapsed = (this.get('category.name').indexOf('Advanced') != -1);
  340. var self = this;
  341. this.set('category.isCollapsed', isCollapsed);
  342. if (isCollapsed) {
  343. this.$('.accordion-body').hide();
  344. }
  345. this.updateReadOnlyFlags();
  346. Em.run.next(function() {
  347. self.updateReadOnlyFlags();
  348. });
  349. },
  350. childView: App.ServiceConfigsOverridesView,
  351. changeFlag: Ember.Object.create({
  352. val: 1
  353. }),
  354. isOneOfAdvancedSections: function () {
  355. var category = this.get('category');
  356. return category.indexOf("Advanced") != -1;
  357. },
  358. showAddPropertyWindow: function (event) {
  359. var configsOfFile = this.get('service.configs').filterProperty('filename', this.get('category.siteFileName'));
  360. var self =this;
  361. var serviceConfigObj = Ember.Object.create({
  362. name: '',
  363. value: '',
  364. defaultValue: null,
  365. filename: '',
  366. isUserProperty: true,
  367. isKeyError: false,
  368. errorMessage: "",
  369. observeAddPropertyValue: function () {
  370. var name = this.get('name');
  371. if (name.trim() != "") {
  372. if (validator.isValidConfigKey(name)) {
  373. var configMappingProperty = App.config.get('configMapping').all().filterProperty('filename',self.get('category.siteFileName')).findProperty('name', name);
  374. if ((configMappingProperty == null) && (!configsOfFile.findProperty('name', name))) {
  375. this.set("isKeyError", false);
  376. this.set("errorMessage", "");
  377. } else {
  378. this.set("isKeyError", true);
  379. this.set("errorMessage", Em.I18n.t('services.service.config.addPropertyWindow.error.derivedKey'));
  380. }
  381. } else {
  382. this.set("isKeyError", true);
  383. this.set("errorMessage", Em.I18n.t('form.validator.configKey'));
  384. }
  385. } else {
  386. this.set("isKeyError", true);
  387. this.set("errorMessage", Em.I18n.t('services.service.config.addPropertyWindow.errorMessage'));
  388. }
  389. }.observes("name")
  390. });
  391. var category = this.get('category');
  392. serviceConfigObj.displayType = "advanced";
  393. serviceConfigObj.category = category.get('name');
  394. var serviceName = this.get('service.serviceName');
  395. var serviceConfigsMetaData = App.config.get('preDefinedServiceConfigs');
  396. var serviceConfigMetaData = serviceConfigsMetaData.findProperty('serviceName', serviceName);
  397. var categoryMetaData = serviceConfigMetaData == null ? null : serviceConfigMetaData.configCategories.findProperty('name', category.get('name'));
  398. if (categoryMetaData != null) {
  399. serviceConfigObj.filename = categoryMetaData.siteFileName;
  400. }
  401. var self = this;
  402. App.ModalPopup.show({
  403. // classNames: ['big-modal'],
  404. classNames: [ 'sixty-percent-width-modal'],
  405. header: "Add Property",
  406. primary: 'Add',
  407. secondary: 'Cancel',
  408. onPrimary: function () {
  409. serviceConfigObj.observeAddPropertyValue();
  410. /**
  411. * For the first entrance use this if (serviceConfigObj.name.trim() != "")
  412. */
  413. if (!serviceConfigObj.isKeyError) {
  414. serviceConfigObj.displayName = serviceConfigObj.name;
  415. serviceConfigObj.id = 'site property';
  416. serviceConfigObj.serviceName = serviceName;
  417. serviceConfigObj.displayType = stringUtils.isSingleLine(serviceConfigObj.get('value')) ? 'advanced' : 'multiLine';
  418. var serviceConfigProperty = App.ServiceConfigProperty.create(serviceConfigObj);
  419. self.get('controller.secureConfigs').filterProperty('filename', self.get('category.siteFileName')).forEach(function (_secureConfig) {
  420. if (_secureConfig.name === serviceConfigProperty.get('name')) {
  421. serviceConfigProperty.set('isSecureConfig', true);
  422. }
  423. }, this);
  424. self.get('serviceConfigs').pushObject(serviceConfigProperty);
  425. this.hide();
  426. }
  427. },
  428. onSecondary: function () {
  429. this.hide();
  430. },
  431. bodyClass: Ember.View.extend({
  432. templateName: require('templates/common/configs/addPropertyWindow'),
  433. controllerBinding: 'App.router.mainServiceInfoConfigsController',
  434. serviceConfigProperty: serviceConfigObj
  435. })
  436. });
  437. },
  438. /**
  439. * Removes the top-level property from list of properties.
  440. * Should be only called on user properties.
  441. */
  442. removeProperty: function (event) {
  443. var serviceConfigProperty = event.contexts[0];
  444. this.get('serviceConfigs').removeObject(serviceConfigProperty);
  445. },
  446. /**
  447. * Restores given property's value to be its default value.
  448. * Does not update if there is no default value.
  449. */
  450. doRestoreDefaultValue: function (event) {
  451. var serviceConfigProperty = event.contexts[0];
  452. var value = serviceConfigProperty.get('value');
  453. var dValue = serviceConfigProperty.get('defaultValue');
  454. if (dValue != null) {
  455. if (serviceConfigProperty.get('displayType') === 'password') {
  456. serviceConfigProperty.set('retypedPassword', dValue);
  457. }
  458. serviceConfigProperty.set('value', dValue);
  459. }
  460. this.miscConfigChange(serviceConfigProperty);
  461. },
  462. createOverrideProperty: function (event) {
  463. var serviceConfigProperty = event.contexts[0];
  464. // Launch dialog to pick/create Config-group
  465. var serviceConfigGroups = [];
  466. App.config.launchConfigGroupSelectionCreationDialog(this.get('service.serviceName'),
  467. serviceConfigGroups, function(selectedConfigGroup){
  468. console.log("launchConfigGroupSelectionCreationDialog(): Selected/Created:", selectedConfigGroup);
  469. if (selectedConfigGroup) {
  470. // TODO - show configurations for this new config-group
  471. // var overrides = serviceConfigProperty.get('overrides');
  472. // if (!overrides) {
  473. // overrides = [];
  474. // serviceConfigProperty.set('overrides', overrides);
  475. // }
  476. // // create new override with new value
  477. // var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  478. // newSCP.set('value', '');
  479. // newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  480. // newSCP.set('parentSCP', serviceConfigProperty);
  481. // newSCP.set('selectedHostOptions', Ember.A([]));
  482. // console.debug("createOverrideProperty(): Added:", newSCP, " to main-property:", serviceConfigProperty);
  483. // overrides.pushObject(newSCP);
  484. //
  485. // // Launch override window
  486. // var dummyEvent = {contexts: [newSCP]};
  487. // this.showOverrideWindow(dummyEvent);
  488. } else {
  489. // Cancelled dialog
  490. }
  491. });
  492. },
  493. showOverrideWindow: function (event) {
  494. // argument 1
  495. var serviceConfigProperty = event.contexts[0];
  496. var parentServiceConfigProperty = serviceConfigProperty.get('parentSCP');
  497. var alreadyOverriddenHosts = [];
  498. parentServiceConfigProperty.get('overrides').forEach(function (override) {
  499. if (override != null && override != serviceConfigProperty && override.get('selectedHostOptions') != null) {
  500. alreadyOverriddenHosts = alreadyOverriddenHosts.concat(override.get('selectedHostOptions'))
  501. }
  502. });
  503. var selectedHosts = serviceConfigProperty.get('selectedHostOptions');
  504. /**
  505. * Get all the hosts available for selection. Since data is dependent on
  506. * controller, we ask it, instead of doing regular Ember's App.Host.find().
  507. * This should be an array of App.Host.
  508. */
  509. var allHosts = this.get('controller.getAllHosts');
  510. var availableHosts = Ember.A([]);
  511. allHosts.forEach(function (host) {
  512. var hostId = host.get('id');
  513. if (alreadyOverriddenHosts.indexOf(hostId) < 0) {
  514. availableHosts.pushObject(Ember.Object.create({
  515. selected: selectedHosts.indexOf(hostId) > -1,
  516. host: host
  517. }));
  518. }
  519. });
  520. /**
  521. * From the currently selected service we want the service-components.
  522. * We only need an array of objects which have the 'componentName' and
  523. * 'displayName' properties. Since each controller has its own objects,
  524. * we ask for a normalized array back.
  525. */
  526. var validComponents = this.get('controller.getCurrentServiceComponents');
  527. hostsUtils.launchHostsSelectionDialog(availableHosts, selectedHosts,
  528. false, validComponents, function(newSelectedHosts){
  529. if (newSelectedHosts!=null) {
  530. serviceConfigProperty.set('selectedHostOptions', newSelectedHosts);
  531. serviceConfigProperty.validate();
  532. } else {
  533. // Dialog cancelled
  534. // If property has no hosts already, then remove it from the parent.
  535. var hostCount = serviceConfigProperty.get('selectedHostOptions.length');
  536. if (hostCount < 1) {
  537. var parentSCP = serviceConfigProperty.get('parentSCP');
  538. var overrides = parentSCP.get('overrides');
  539. overrides.removeObject(serviceConfigProperty);
  540. }
  541. }
  542. });
  543. }
  544. });
  545. App.ServiceConfigTab = Ember.View.extend({
  546. tagName: 'li',
  547. selectService: function (event) {
  548. this.set('controller.selectedService', event.context);
  549. },
  550. didInsertElement: function () {
  551. var serviceName = this.get('controller.selectedService.serviceName');
  552. this.$('a[href="#' + serviceName + '"]').tab('show');
  553. }
  554. });
  555. /**
  556. * custom view for capacity scheduler category
  557. * @type {*}
  558. */
  559. App.ServiceConfigCapacityScheduler = App.ServiceConfigsByCategoryView.extend({
  560. templateName: require('templates/common/configs/capacity_scheduler'),
  561. category: null,
  562. service: null,
  563. serviceConfigs: null,
  564. customConfigs: function(){
  565. return App.config.get('preDefinedCustomConfigs');
  566. }.property('App.config.preDefinedCustomConfigs'),
  567. /**
  568. * configs filtered by capacity-scheduler category
  569. */
  570. categoryConfigs: function () {
  571. return this.get('serviceConfigs').filterProperty('category', this.get('category.name'));
  572. }.property('queueObserver', 'serviceConfigs.@each'),
  573. /**
  574. * rewrote method to avoid incompatibility with parent
  575. */
  576. filteredCategoryConfigs: function () {
  577. return this.get('categoryConfigs');
  578. }.property(),
  579. advancedConfigs: function () {
  580. return this.get('categoryConfigs').filterProperty('isQueue', undefined) || [];
  581. }.property('categoryConfigs.@each'),
  582. didInsertElement: function () {
  583. this._super();
  584. this.createEmptyQueue(this.get('customConfigs').filterProperty('isQueue'));
  585. },
  586. //list of fields which will be populated by default in a new queue
  587. fieldsToPopulate: function(){
  588. if(App.get('isHadoop2Stack')){
  589. return ["yarn.scheduler.capacity.root.<queue-name>.user-limit-factor",
  590. "yarn.scheduler.capacity.root.<queue-name>.state"];
  591. }
  592. return [
  593. "mapred.capacity-scheduler.queue.<queue-name>.minimum-user-limit-percent",
  594. "mapred.capacity-scheduler.queue.<queue-name>.user-limit-factor",
  595. "mapred.capacity-scheduler.queue.<queue-name>.supports-priority",
  596. "mapred.capacity-scheduler.queue.<queue-name>.maximum-initialized-active-tasks",
  597. "mapred.capacity-scheduler.queue.<queue-name>.maximum-initialized-active-tasks-per-user",
  598. "mapred.capacity-scheduler.queue.<queue-name>.init-accept-jobs-factor"
  599. ];
  600. }.property('App.isHadoop2Stack'),
  601. /**
  602. * create empty queue
  603. * take some queue then copy it and set all config values to null
  604. * @param customConfigs
  605. */
  606. createEmptyQueue: function (customConfigs) {
  607. var emptyQueue = {
  608. name: '<queue-name>',
  609. configs: []
  610. };
  611. var fieldsToPopulate = this.get('fieldsToPopulate');
  612. customConfigs.forEach(function (config) {
  613. var newConfig = $.extend({}, config);
  614. if (fieldsToPopulate.contains(config.name)) {
  615. newConfig.value = config.defaultValue;
  616. }
  617. newConfig = App.ServiceConfigProperty.create(newConfig);
  618. newConfig.validate();
  619. emptyQueue.configs.push(newConfig);
  620. });
  621. this.set('emptyQueue', emptyQueue);
  622. },
  623. deriveQueueNames: function(configs){
  624. var queueNames = [];
  625. configs.mapProperty('name').forEach(function(name){
  626. var queueName;
  627. if(App.get('isHadoop2Stack')){
  628. queueName = /^yarn\.scheduler\.capacity\.root\.(.*?)\./.exec(name);
  629. } else {
  630. queueName = /^mapred\.capacity-scheduler\.queue\.(.*?)\./.exec(name);
  631. }
  632. if(queueName){
  633. queueNames.push(queueName[1]);
  634. }
  635. });
  636. return queueNames.uniq();
  637. },
  638. queues: function(){
  639. var configs = this.get('categoryConfigs').filterProperty('isQueue', true);
  640. var queueNames = this.deriveQueueNames(configs);
  641. var queues = [];
  642. queueNames.forEach(function(queueName){
  643. queues.push({
  644. name: queueName,
  645. color: this.generateColor(queueName),
  646. configs: this.groupConfigsByQueue(queueName, configs)
  647. })
  648. }, this);
  649. return queues;
  650. }.property('queueObserver'),
  651. /**
  652. * group configs by queue
  653. * @param queueName
  654. * @param configs
  655. */
  656. groupConfigsByQueue: function (queueName, configs) {
  657. var customConfigs = [];
  658. var queue = [];
  659. this.get('customConfigs').forEach(function(_config){
  660. var copy = $.extend({}, _config);
  661. copy.name = _config.name.replace('<queue-name>', queueName);
  662. customConfigs.push(copy);
  663. });
  664. configs.forEach(function (config) {
  665. var customConfig = customConfigs.findProperty('name', config.get('name'));
  666. if (customConfig) {
  667. config.set('description', customConfig.description);
  668. config.set('displayName', customConfig.displayName);
  669. config.set('isRequired', customConfig.isRequired);
  670. config.set('unit', customConfig.unit);
  671. config.set('displayType', customConfig.displayType);
  672. config.set('valueRange', customConfig.valueRange);
  673. config.set('isVisible', customConfig.isVisible);
  674. config.set('inTable', customConfig.inTable);
  675. config.set('index', customConfig.index);
  676. queue.push(config);
  677. }
  678. });
  679. if(queue.length < customConfigs.length){
  680. this.addMissingProperties(queue, customConfigs);
  681. }
  682. return queue;
  683. },
  684. /**
  685. * add missing properties to queue when they don't come from server
  686. * @param queue
  687. * @param customConfigs
  688. */
  689. addMissingProperties: function(queue, customConfigs){
  690. customConfigs.forEach(function(_config){
  691. var serviceConfigProperty;
  692. if(!queue.someProperty('name', _config.name)){
  693. _config.value = _config.defaultValue;
  694. serviceConfigProperty = App.ServiceConfigProperty.create(_config);
  695. serviceConfigProperty.validate();
  696. queue.push(serviceConfigProperty);
  697. }
  698. }, this);
  699. },
  700. /**
  701. * convert queues to table content
  702. */
  703. tableContent: function () {
  704. var result = [];
  705. this.get('queues').forEach(function (queue) {
  706. var usersAndGroups = queue.configs.findProperty('name', this.getUserAndGroupNames(queue.name)[0]).get('value');
  707. usersAndGroups = (usersAndGroups) ? usersAndGroups.split(' ') : [''];
  708. if (usersAndGroups.length == 1) {
  709. usersAndGroups.push('');
  710. }
  711. var queueObject = {
  712. name: queue.name,
  713. color: 'background-color:' + queue.color + ';',
  714. configs: this.sortByIndex(queue.configs.filterProperty('inTable'))
  715. };
  716. //push acl_submit_jobs users
  717. queueObject.configs.unshift({
  718. value: usersAndGroups[1],
  719. inTable: true,
  720. displayName: Em.I18n.t('common.users')
  721. });
  722. //push acl_submit_jobs groups
  723. queueObject.configs.unshift({
  724. value: usersAndGroups[0],
  725. inTable: true,
  726. displayName: Em.I18n.t('services.mapReduce.config.queue.groups')
  727. });
  728. result.push(queueObject);
  729. }, this);
  730. return result;
  731. }.property('queues'),
  732. /**
  733. * create headers depending on existed properties in queue
  734. */
  735. tableHeaders: function(){
  736. var headers = [
  737. Em.I18n.t('services.mapReduce.config.queue.name')
  738. ];
  739. return (this.get('tableContent').length) ?
  740. headers.concat(this.get('tableContent').objectAt(0).configs.filterProperty('inTable').mapProperty('displayName')):
  741. headers;
  742. }.property('tableContent'),
  743. queueObserver: null,
  744. /**
  745. * uses as template for adding new queue
  746. */
  747. emptyQueue: {},
  748. /**
  749. * get capacities sum of queues except of current
  750. * @param queueName
  751. * @return {Number}
  752. */
  753. getQueuesCapacitySum: function(queueName){
  754. var capacitySum = 0;
  755. this.get('queues').filter(function(queue){
  756. return queue.name !== queueName;
  757. }).forEach(function(queue){
  758. capacitySum = capacitySum + window.parseInt(queue.configs.find(function(config){
  759. return config.get('name').substr(-9, 9) === '.capacity';
  760. }).get('value'));
  761. });
  762. return capacitySum;
  763. },
  764. /**
  765. * get names of configs, for users and groups, which have different names in HDP1 and HDP2
  766. * @param queueName
  767. * @return {Array}
  768. */
  769. getUserAndGroupNames: function(queueName){
  770. queueName = queueName || '<queue-name>';
  771. if(App.config.get('isHDP2')){
  772. return ['yarn.scheduler.capacity.root.' + queueName + '.acl_submit_jobs',
  773. 'yarn.scheduler.capacity.root.' + queueName + '.acl_administer_jobs']
  774. }
  775. return ['mapred.queue.' + queueName + '.acl-submit-job',
  776. 'mapred.queue.' + queueName + '.acl-administer-jobs']
  777. },
  778. generateColor: function (str) {
  779. var hash = 0;
  780. for (var i = 0; i < str.length; i++) {
  781. hash = str.charCodeAt(i) + ((hash << 5) - hash);
  782. }
  783. return '#' + Number(Math.abs(hash)).toString(16).concat('00000').substr(0, 6);
  784. },
  785. /**
  786. * add new queue
  787. * add created configs to serviceConfigs with current queue name
  788. * @param queue
  789. */
  790. addQueue: function (queue) {
  791. var serviceConfigs = this.get('serviceConfigs');
  792. var admin = [];
  793. var submit = [];
  794. var submitConfig;
  795. var adminConfig;
  796. queue.name = queue.configs.findProperty('name', 'queueName').get('value');
  797. queue.configs.forEach(function (config) {
  798. var adminName = this.getUserAndGroupNames()[1];
  799. var submitName = this.getUserAndGroupNames()[0];
  800. if(config.name == adminName){
  801. if (config.type == 'USERS') {
  802. admin[0] = config.value;
  803. }
  804. if (config.type == 'GROUPS') {
  805. admin[1] = config.value;
  806. }
  807. if (config.isQueue) {
  808. adminConfig = config;
  809. }
  810. }
  811. if(config.name == submitName){
  812. if (config.type == 'USERS') {
  813. submit[0] = config.value;
  814. }
  815. if (config.type == 'GROUPS') {
  816. submit[1] = config.value;
  817. }
  818. if (config.isQueue) {
  819. submitConfig = config;
  820. }
  821. }
  822. config.set('name', config.get('name').replace('<queue-name>', queue.name));
  823. config.set('value', config.get('value').toString());
  824. if (config.isQueue) {
  825. serviceConfigs.push(config);
  826. }
  827. }, this);
  828. adminConfig.set('value', admin.join(' '));
  829. submitConfig.set('value', submit.join(' '));
  830. this.set('queueObserver', new Date().getTime());
  831. },
  832. /**
  833. * delete queue
  834. * delete configs from serviceConfigs which have current queue name
  835. * @param queue
  836. */
  837. deleteQueue: function (queue) {
  838. var serviceConfigs = this.get('serviceConfigs');
  839. var configNames = queue.configs.filterProperty('isQueue').mapProperty('name');
  840. for (var i = 0, l = serviceConfigs.length; i < l; i++) {
  841. if (configNames.contains(serviceConfigs[i].name)) {
  842. serviceConfigs.splice(i, 1);
  843. l--;
  844. i--;
  845. }
  846. }
  847. this.set('queueObserver', new Date().getTime());
  848. },
  849. /**
  850. * save changes that was made to queue
  851. * edit configs from serviceConfigs which have current queue name
  852. * @param queue
  853. */
  854. editQueue: function (queue) {
  855. var serviceConfigs = this.get('serviceConfigs');
  856. var configNames = queue.configs.filterProperty('isQueue').mapProperty('name');
  857. serviceConfigs.forEach(function (_config) {
  858. var configName = _config.get('name');
  859. var admin = [];
  860. var submit = [];
  861. //comparison executes including 'queue.<queue-name>' to avoid false matches
  862. var queueNamePrefix = App.config.get('isHDP2') ? 'root.' : 'queue.';
  863. if (configNames.contains(_config.get('name'))) {
  864. if(configName == this.getUserAndGroupNames(queue.name)[0]){
  865. submit = queue.configs.filterProperty('name', configName);
  866. submit = submit.findProperty('type', 'USERS').get('value') + ' ' + submit.findProperty('type', 'GROUPS').get('value');
  867. _config.set('value', submit);
  868. } else if(configName == this.getUserAndGroupNames(queue.name)[1]){
  869. admin = queue.configs.filterProperty('name', configName);
  870. admin = admin.findProperty('type', 'USERS').get('value') + ' ' + admin.findProperty('type', 'GROUPS').get('value');
  871. _config.set('value', admin);
  872. } else {
  873. _config.set('value', queue.configs.findProperty('name', _config.get('name')).get('value').toString());
  874. }
  875. _config.set('name', configName.replace(queueNamePrefix + queue.name, queueNamePrefix + queue.configs.findProperty('name', 'queueName').get('value')));
  876. }
  877. }, this);
  878. this.set('queueObserver', new Date().getTime());
  879. },
  880. pieChart: App.ChartPieView.extend({
  881. w: 200,
  882. h: 200,
  883. queues: null,
  884. didInsertElement: function () {
  885. this.update();
  886. },
  887. data: [{"label":"default", "value":100}],
  888. update: function () {
  889. var self = this;
  890. var data = [];
  891. var queues = this.get('queues');
  892. var capacitiesSum = 0;
  893. queues.forEach(function (queue) {
  894. var value = window.parseInt(queue.configs.find(function(_config){
  895. return _config.get('name').substr(-9, 9) === '.capacity';
  896. }).get('value'));
  897. data.push({
  898. label: queue.name,
  899. value: value,
  900. color: queue.color
  901. })
  902. });
  903. data.mapProperty('value').forEach(function (capacity) {
  904. capacitiesSum += capacity;
  905. });
  906. if (capacitiesSum < 100) {
  907. data.push({
  908. label: Em.I18n.t('common.empty'),
  909. value: (100 - capacitiesSum),
  910. color: 'transparent',
  911. isEmpty: true
  912. })
  913. }
  914. $(d3.select(this.get('selector'))[0]).children().remove();
  915. this.set('data', data);
  916. this.set('palette', new Rickshaw.Color.Palette({
  917. scheme: data.mapProperty('color')
  918. }));
  919. this.appendSvg();
  920. this.get('arcs')
  921. .on("click",function (d, i) {
  922. var event = {context: d.data.label};
  923. if (d.data.isEmpty !== true) self.get('parentView').queuePopup(event);
  924. }).on('mouseover', function (d, i) {
  925. var position = d3.svg.mouse(this);
  926. var label = $('#section_label');
  927. label.css('left', position[0] + 100);
  928. label.css('top', position[1] + 100);
  929. label.text(d.data.label);
  930. label.show();
  931. })
  932. .on('mouseout', function (d, i) {
  933. $('#section_label').hide();
  934. })
  935. }.observes('queues'),
  936. donut: d3.layout.pie().sort(null).value(function (d) {
  937. return d.value;
  938. })
  939. }),
  940. /**
  941. * open popup with chosen queue
  942. * @param event
  943. */
  944. queuePopup: function (event) {
  945. //if queueName was handed that means "Edit" mode, otherwise "Add" mode
  946. var queueName = event.context || null;
  947. var self = this;
  948. App.ModalPopup.show({
  949. didInsertElement: function () {
  950. if (queueName) {
  951. this.set('header', Em.I18n.t('services.mapReduce.config.editQueue'));
  952. this.set('secondary', Em.I18n.t('common.save'));
  953. if (self.get('queues').length > 1 && self.get('canEdit')) {
  954. this.set('delete', Em.I18n.t('common.delete'));
  955. }
  956. }
  957. },
  958. header: Em.I18n.t('services.mapReduce.config.addQueue'),
  959. secondary: Em.I18n.t('common.add'),
  960. primary: Em.I18n.t('common.cancel'),
  961. delete: null,
  962. isError: function () {
  963. if (!self.get('canEdit')) {
  964. return true;
  965. }
  966. var content = this.get('content');
  967. var configs = content.configs.filter(function (config) {
  968. return !(config.name == self.getUserAndGroupNames(content.name)[0] ||
  969. config.name == self.getUserAndGroupNames(content.name)[1] &&
  970. config.isQueue);
  971. });
  972. return configs.someProperty('isValid', false);
  973. }.property('content.configs.@each.isValid'),
  974. onDelete: function () {
  975. var view = this;
  976. App.ModalPopup.show({
  977. header: Em.I18n.t('popup.confirmation.commonHeader'),
  978. body: Em.I18n.t('hosts.delete.popup.body'),
  979. primary: Em.I18n.t('yes'),
  980. onPrimary: function () {
  981. self.deleteQueue(view.get('content'));
  982. view.hide();
  983. this.hide();
  984. }
  985. });
  986. },
  987. onSecondary: function () {
  988. if (queueName) {
  989. self.editQueue(this.get('content'));
  990. } else {
  991. self.addQueue(this.get('content'));
  992. }
  993. this.hide();
  994. },
  995. /**
  996. * Queue properties order:
  997. * 1. Queue Name
  998. * 2. Capacity
  999. * 3. Max Capacity
  1000. * 4. Users
  1001. * 5. Groups
  1002. * 6. Admin Users
  1003. * 7. Admin Groups
  1004. * 8. Support Priority
  1005. * ...
  1006. */
  1007. content: function () {
  1008. var content = (queueName) ? self.get('queues').findProperty('name', queueName) : self.get('emptyQueue');
  1009. var configs = [];
  1010. // copy of queue configs
  1011. content.configs.forEach(function (config, index) {
  1012. if(config.get('name').substr(-9, 9) === '.capacity') {
  1013. //added validation function for capacity property
  1014. config.reopen({
  1015. validate: function () {
  1016. var value = this.get('value');
  1017. var isError = false;
  1018. var capacitySum = self.getQueuesCapacitySum(content.name);
  1019. if (value == '') {
  1020. if (this.get('isRequired')) {
  1021. this.set('errorMessage', 'This is required');
  1022. isError = true;
  1023. } else {
  1024. return;
  1025. }
  1026. }
  1027. if (!isError) {
  1028. if (!validator.isValidInt(value)) {
  1029. this.set('errorMessage', 'Must contain digits only');
  1030. isError = true;
  1031. }
  1032. }
  1033. if (!isError) {
  1034. if ((capacitySum + parseInt(value)) > 100) {
  1035. isError = true;
  1036. this.set('errorMessage', 'The sum of capacities more than 100');
  1037. }
  1038. if (!isError) {
  1039. this.set('errorMessage', '');
  1040. }
  1041. }
  1042. }.observes('value')
  1043. });
  1044. }
  1045. if (config.name == 'mapred.capacity-scheduler.queue.' + content.name + '.supports-priority') {
  1046. if (config.get('value') == 'true' || config.get('value') === true) {
  1047. config.set('value', true);
  1048. } else {
  1049. config.set('value', false);
  1050. }
  1051. }
  1052. if(config.name === 'yarn.scheduler.capacity.root.' + content.name + '.state'){
  1053. config.reopen({
  1054. validate: function(){
  1055. var value = this.get('value');
  1056. this._super();
  1057. if(!this.get('errorMessage')){
  1058. if(!(value === 'STOPPED' || value === 'RUNNING')){
  1059. this.set('errorMessage', 'State value should be RUNNING or STOPPED');
  1060. }
  1061. }
  1062. }.observes('value')
  1063. })
  1064. }
  1065. configs[index] = App.ServiceConfigProperty.create(config);
  1066. });
  1067. content = {
  1068. name: content.name,
  1069. configs: configs
  1070. };
  1071. content = this.insertExtraConfigs(content);
  1072. content.configs = self.sortByIndex(content.configs);
  1073. return content;
  1074. }.property(),
  1075. footerClass: Ember.View.extend({
  1076. classNames: ['modal-footer', 'host-checks-update'],
  1077. template: Ember.Handlebars.compile([
  1078. '{{#if view.parentView.delete}}<div class="pull-left">',
  1079. '<button class="btn btn-danger" {{action onDelete target="view.parentView"}}>',
  1080. '{{view.parentView.delete}}</button></div>{{/if}}',
  1081. '<p class="pull-right">',
  1082. '{{#if view.parentView.primary}}<button type="button" class="btn" {{action onPrimary target="view.parentView"}}>',
  1083. '{{view.parentView.primary}}</button>{{/if}}',
  1084. '{{#if view.parentView.secondary}}',
  1085. '<button type="button" {{bindAttr disabled="view.parentView.isError"}} class="btn btn-success" {{action onSecondary target="view.parentView"}}>',
  1086. '{{view.parentView.secondary}}</button>{{/if}}',
  1087. '</p>'
  1088. ].join(''))
  1089. }),
  1090. bodyClass: Ember.View.extend({
  1091. template: Ember.Handlebars.compile([
  1092. '<form class="form-horizontal pre-scrollable" autocomplete="off">{{#each view.parentView.content.configs}}',
  1093. '{{#if isVisible}}',
  1094. '<div class="row-fluid control-group">',
  1095. ' <div {{bindAttr class="errorMessage:error :control-label-span :span4"}}>',
  1096. ' <label>{{displayName}}</label>',
  1097. ' </div>',
  1098. ' <div {{bindAttr class="errorMessage:error :control-group :span8"}}>',
  1099. ' {{view viewClass serviceConfigBinding="this" categoryConfigsBinding="view.categoryConfigs" }}',
  1100. ' <span class="help-inline">{{errorMessage}}</span>',
  1101. ' </div>',
  1102. '</div>',
  1103. '{{/if}}',
  1104. '{{/each}}</form>'
  1105. ].join(''))
  1106. }),
  1107. /**
  1108. * Insert extra config in popup according to queue
  1109. *
  1110. * the mapred.queue.default.acl-administer-jobs turns into two implicit configs:
  1111. * "Admin Users" field and "Admin Groups" field
  1112. * the mapred.queue.default.acl-submit-job turns into two implicit configs:
  1113. * "Users" field and "Groups" field
  1114. * Add implicit config that contain "Queue Name"
  1115. * @param content
  1116. * @return {*}
  1117. */
  1118. insertExtraConfigs: function (content) {
  1119. var that = this;
  1120. var admin = content.configs.findProperty('name', self.getUserAndGroupNames(content.name)[1]).get('value');
  1121. var submit = content.configs.findProperty('name', self.getUserAndGroupNames(content.name)[0]).get('value');
  1122. admin = (admin) ? admin.split(' ') : [''];
  1123. submit = (submit) ? submit.split(' ') : [''];
  1124. if (admin.length < 2) {
  1125. admin.push('');
  1126. }
  1127. if (submit.length < 2) {
  1128. submit.push('');
  1129. }
  1130. var nameField = App.ServiceConfigProperty.create({
  1131. name: 'queueName',
  1132. displayName: Em.I18n.t('services.mapReduce.extraConfig.queue.name'),
  1133. description: Em.I18n.t('services.mapReduce.description.queue.name'),
  1134. value: (content.name == '<queue-name>') ? '' : content.name,
  1135. validate: function () {
  1136. var queueNames = self.get('queues').mapProperty('name');
  1137. var value = this.get('value');
  1138. var isError = false;
  1139. var regExp = /^[a-z]([\_\-a-z0-9]{0,50})\$?$/i;
  1140. if (value == '') {
  1141. if (this.get('isRequired')) {
  1142. this.set('errorMessage', 'This is required');
  1143. isError = true;
  1144. } else {
  1145. return;
  1146. }
  1147. }
  1148. if (!isError) {
  1149. if ((queueNames.indexOf(value) !== -1) && (value != content.name)) {
  1150. this.set('errorMessage', 'Queue name is already used');
  1151. isError = true;
  1152. }
  1153. }
  1154. if (!isError) {
  1155. if (!regExp.test(value)) {
  1156. this.set('errorMessage', 'Incorrect input');
  1157. isError = true;
  1158. }
  1159. }
  1160. if (!isError) {
  1161. this.set('errorMessage', '');
  1162. }
  1163. }.observes('value'),
  1164. isRequired: true,
  1165. isVisible: true,
  1166. isEditable: self.get('canEdit'),
  1167. index: 0
  1168. });
  1169. nameField.validate();
  1170. content.configs.unshift(nameField);
  1171. var submitUser = App.ServiceConfigProperty.create({
  1172. name: self.getUserAndGroupNames(content.name)[0],
  1173. displayName: Em.I18n.t('common.users'),
  1174. value: submit[0],
  1175. description: Em.I18n.t('services.mapReduce.description.queue.submit.user'),
  1176. isRequired: true,
  1177. isVisible: true,
  1178. type: 'USERS',
  1179. displayType: "UNIXList",
  1180. isEditable: self.get('canEdit'),
  1181. index: 3
  1182. });
  1183. var submitGroup = App.ServiceConfigProperty.create({
  1184. name: self.getUserAndGroupNames(content.name)[0],
  1185. displayName: Em.I18n.t('services.mapReduce.config.queue.groups'),
  1186. description: Em.I18n.t('services.mapReduce.description.queue.submit.group'),
  1187. value: submit[1],
  1188. isRequired: true,
  1189. isVisible: true,
  1190. "displayType": "UNIXList",
  1191. type: 'GROUPS',
  1192. isEditable: self.get('canEdit'),
  1193. index: 4
  1194. });
  1195. var adminUser = App.ServiceConfigProperty.create({
  1196. name: self.getUserAndGroupNames(content.name)[1],
  1197. displayName: Em.I18n.t('services.mapReduce.config.queue.adminUsers'),
  1198. description: Em.I18n.t('services.mapReduce.description.queue.admin.user'),
  1199. value: admin[0],
  1200. isRequired: true,
  1201. isVisible: true,
  1202. type: 'USERS',
  1203. displayType: "UNIXList",
  1204. isEditable: self.get('canEdit'),
  1205. index: 5
  1206. });
  1207. var adminGroup = App.ServiceConfigProperty.create({
  1208. name: self.getUserAndGroupNames(content.name)[1],
  1209. displayName: Em.I18n.t('services.mapReduce.config.queue.adminGroups'),
  1210. value: admin[1],
  1211. description: Em.I18n.t('services.mapReduce.description.queue.admin.group'),
  1212. isRequired: true,
  1213. isVisible: true,
  1214. "displayType": "UNIXList",
  1215. type: 'GROUPS',
  1216. isEditable: self.get('canEdit'),
  1217. index: 6
  1218. });
  1219. submitUser.reopen({
  1220. validate: function () {
  1221. that.userGroupValidation(this, submitGroup);
  1222. }.observes('value')
  1223. });
  1224. submitGroup.reopen({
  1225. validate: function () {
  1226. that.userGroupValidation(this, submitUser);
  1227. }.observes('value')
  1228. });
  1229. adminUser.reopen({
  1230. validate: function () {
  1231. that.userGroupValidation(this, adminGroup);
  1232. }.observes('value')
  1233. });
  1234. adminGroup.reopen({
  1235. validate: function () {
  1236. that.userGroupValidation(this, adminUser);
  1237. }.observes('value')
  1238. });
  1239. submitUser.validate();
  1240. adminUser.validate();
  1241. content.configs.push(submitUser);
  1242. content.configs.push(submitGroup);
  1243. content.configs.push(adminUser);
  1244. content.configs.push(adminGroup);
  1245. return content;
  1246. },
  1247. /**
  1248. * Validate by follow rules:
  1249. * Users can be blank. If it is blank, Groups must not be blank.
  1250. * Groups can be blank. If it is blank, Users must not be blank.
  1251. * @param context
  1252. * @param boundConfig
  1253. */
  1254. userGroupValidation: function (context, boundConfig) {
  1255. if (context.get('value') == '') {
  1256. if (boundConfig.get('value') == '') {
  1257. context._super();
  1258. } else {
  1259. boundConfig.validate();
  1260. }
  1261. } else {
  1262. if (boundConfig.get('value') == '') {
  1263. boundConfig.set('errorMessage', '');
  1264. }
  1265. context._super();
  1266. }
  1267. }
  1268. })
  1269. }
  1270. });