scheduler.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 cmp = Ember.computed;
  20. App.CapschedSchedulerController = Ember.Controller.extend({
  21. needs: ['capsched'],
  22. scheduler: cmp.alias('controllers.capsched.content'),
  23. schedulerProps: ['maximum_am_resource_percent', 'maximum_applications', 'node_locality_delay', 'resource_calculator'],
  24. isRefreshOrRestartNeeded: false,
  25. actions: {
  26. rollbackSchedulerProps: function() {
  27. var tempRefreshNeeded = this.get('isRefreshOrRestartNeeded');
  28. var sched = this.get('scheduler'),
  29. attributes = sched.changedAttributes(),
  30. props = this.schedulerProps;
  31. props.forEach(function(prop) {
  32. if (attributes.hasOwnProperty(prop)) {
  33. sched.set(prop, attributes[prop][0]);
  34. }
  35. });
  36. this.set('isRefreshOrRestartNeeded', tempRefreshNeeded);
  37. },
  38. rollbackProp: function(prop, item) {
  39. var tempRefreshNeeded = this.get('isRefreshOrRestartNeeded');
  40. var attributes = item.changedAttributes();
  41. if (attributes.hasOwnProperty(prop)) {
  42. item.set(prop, attributes[prop][0]);
  43. }
  44. this.set('isRefreshOrRestartNeeded', tempRefreshNeeded);
  45. this.afterRollbackProp();
  46. },
  47. showConfirmDialog: function() {
  48. this.set('isConfirmDialogOpen', true);
  49. },
  50. showSaveConfigDialog: function(mode) {
  51. if (mode) {
  52. this.set('saveMode', mode);
  53. } else {
  54. this.set('saveMode', '');
  55. }
  56. this.set('isSaveConfigDialogOpen', true);
  57. }
  58. },
  59. isOperator: cmp.alias('controllers.capsched.isOperator'),
  60. saveMode: '',
  61. isConfirmDialogOpen: false,
  62. isSaveConfigDialogOpen: false,
  63. configNote: cmp.alias('store.configNote'),
  64. isSchedulerDirty: false,
  65. isSchedulerPropsNeedSaveOrRestart: cmp.or('isRefreshOrRestartNeeded', 'isSchedulerDirty'),
  66. forceRestartRequired: function() {
  67. return !this.get('isSchedulerDirty') && this.get('isRefreshOrRestartNeeded');
  68. }.property('isSchedulerDirty', 'isRefreshOrRestartNeeded'),
  69. schedulerBecomeDirty: function() {
  70. var sched = this.get('scheduler'),
  71. attributes = sched.changedAttributes(),
  72. props = this.schedulerProps;
  73. var isDirty = props.any(function(prop){
  74. return attributes.hasOwnProperty(prop);
  75. });
  76. this.set('isSchedulerDirty', isDirty);
  77. this.set('isRefreshOrRestartNeeded', isDirty);
  78. }.observes('scheduler.maximum_am_resource_percent', 'scheduler.maximum_applications', 'scheduler.node_locality_delay', 'scheduler.resource_calculator'),
  79. /**
  80. * Collection of modified fields in Scheduler.
  81. * @type {Object} - { [fileldName] : {Boolean} }
  82. */
  83. schedulerDirtyFields: {},
  84. dirtyObserver:function () {
  85. this.get('scheduler.constructor.transformedAttributes.keys.list').forEach(function(item) {
  86. this.addObserver('scheduler.' + item, this, 'propertyBecomeDirty');
  87. }.bind(this));
  88. }.observes('scheduler').on('init'),
  89. propertyBecomeDirty:function (controller, property) {
  90. var schedProp = property.split('.').objectAt(1);
  91. this.set('schedulerDirtyFields.' + schedProp, this.get('scheduler').changedAttributes().hasOwnProperty(schedProp));
  92. },
  93. resourceCalculatorValues: [{
  94. label: 'Default Resource Calculator',
  95. value: 'org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator'
  96. }, {
  97. label: 'Dominant Resource Calculator',
  98. value: 'org.apache.hadoop.yarn.util.resource.DominantResourceCalculator'
  99. }],
  100. afterRollbackProp: function() {
  101. if (this.get('isSchedulerDirty')) {
  102. this.set('isRefreshOrRestartNeeded', true);
  103. } else {
  104. this.set('isRefreshOrRestartNeeded', false);
  105. }
  106. }
  107. });