<commit_before>/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var App = require('app');
var batchUtils = require('utils/batch_scheduled_requests');

App.MainServiceItemView = Em.View.extend({
  templateName: require('templates/main/service/item'),

  serviceName: function() {
    return this.get('controller.content.serviceName');
  }.property('controller.content.serviceName'),

  displayName: function() {
    return this.get('controller.content.displayName');
  }.property('controller.content.displayName'),

  isPassive: function() {
    return this.get('controller.content.passiveState') === 'ON';
  }.property('controller.content.passiveState'),

  actionMap: function() {
    return {
      RESTART_ALL: {
        action: 'restartAllHostComponents',
        context: this.get('serviceName'),
        label: Em.I18n.t('restart.service.all'),
        cssClass: 'icon-repeat',
        disabled: false
      },
      RUN_SMOKE_TEST: {
        action: 'runSmokeTest',
        label: Em.I18n.t('services.service.actions.run.smoke'),
        cssClass: 'icon-thumbs-up-alt'
      },
      REFRESH_CONFIGS: {
        action: 'refreshConfigs',
        label: Em.I18n.t('hosts.host.details.refreshConfigs'),
        cssClass: 'icon-refresh',
        disabled: !this.get('controller.content.isRestartRequired')
      },
      ROLLING_RESTART: {
        action: 'rollingRestart',
        context: this.get('rollingRestartComponent'),
        label: Em.I18n.t('rollingrestart.dialog.title'),
        cssClass: 'icon-time',
        disabled: false
      },
      TOGGLE_PASSIVE: {
        action: 'turnOnOffPassive',
        context: this.get('isPassive') ? Em.I18n.t('passiveState.turnOffFor').format(this.get('displayName')) : Em.I18n.t('passiveState.turnOnFor').format(this.get('displayName')),
        label: this.get('isPassive') ? Em.I18n.t('passiveState.turnOff') : Em.I18n.t('passiveState.turnOn'),
        cssClass: 'icon-medkit',
        disabled: false
      },
      TOGGLE_HA: {
        action: App.isHaEnabled ? 'disableHighAvailability' : 'enableHighAvailability',
        label: App.isHaEnabled ? Em.I18n.t('admin.highAvailability.button.disable') : Em.I18n.t('admin.highAvailability.button.enable'),
        cssClass: App.isHaEnabled ? 'icon-arrow-down' : 'icon-arrow-up',
        isHidden: (App.isHAEnabled && !App.autoRollbackHA)
      },
      MOVE_COMPONENT: {
        action: 'reassignMaster',
        context: '',
        label: Em.I18n.t('services.service.actions.reassign.master'),
        cssClass: 'icon-share-alt',
        disabled: false
      }
    }
  },
  /**
   * Create option for MOVE_COMPONENT or ROLLING_RESTART task.
   *
   * @param {Object} option - one of the options that return by <code>actionMap()</code>
   * @param {Object} fields - option fields to add/rewrite
   * @return {Object}
   */
  createOption: function(option, fields) {
    return $.extend(true, {}, option, fields);
  },

  maintenance: function(){
    var self = this;
    var options = [];
    var service = this.get('controller.content');
    var allMasters = this.get('controller.content.hostComponents').filterProperty('isMaster').mapProperty('componentName').uniq();
    var allSlaves = this.get('controller.content.hostComponents').filterProperty('isSlave').mapProperty('componentName').uniq();
    var actionMap = this.actionMap();

    if (this.get('controller.isClientsOnlyService')) {
      options.push(actionMap.RUN_SMOKE_TEST);
      options.push(actionMap.REFRESH_CONFIGS);
      if (this.get('serviceName') === 'TEZ') {
        options = options.without(actionMap.RUN_SMOKE_TEST);
      }
    } else {
      if (this.get('serviceName') === 'FLUME') {
        options.push(actionMap.REFRESH_CONFIGS);
      }
      options.push(actionMap.RESTART_ALL);
      allSlaves.forEach(function(slave) {
        options.push(self.createOption(actionMap.ROLLING_RESTART, {
          context: slave,
          label: actionMap.ROLLING_RESTART.label.format(App.format.role(slave))
        }));
      });
      allMasters.filter(function(master) {
        return App.get('components.reassignable').contains(master);
      }).forEach(function(master) {
        options.push(self.createOption(actionMap.MOVE_COMPONENT, {
          context: master,
          label: actionMap.MOVE_COMPONENT.label.format(App.format.role(master))
        }));
      });
      if (service.get('serviceTypes').contains('HA_MODE')) {
        options.push(actionMap.TOGGLE_HA);
      }
      options.push(actionMap.RUN_SMOKE_TEST);
      options.push(actionMap.TOGGLE_PASSIVE);
    }
    return options;
  }.property('controller.content', 'controller.isStopDisabled','controller.isClientsOnlyService'),

  isMaintenanceActive: function() {
    return this.get('maintenance').length !== 0;
  }.property('maintenance'),

  hasConfigTab: function() {
    return !App.get('services.noConfigTypes').concat('HCATALOG').contains('controller.content.serviceName');
  }.property('controller.content.serviceName','App.services.noConfigTypes'),<commit_msg>AMBARI-6467 Refresh configs service menu action always remains disabled. (Buzhor Denys via atkach)<commit_after>/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var App = require('app');
var batchUtils = require('utils/batch_scheduled_requests');

App.MainServiceItemView = Em.View.extend({
  templateName: require('templates/main/service/item'),

  serviceName: function() {
    return this.get('controller.content.serviceName');
  }.property('controller.content.serviceName'),

  displayName: function() {
    return this.get('controller.content.displayName');
  }.property('controller.content.displayName'),

  isPassive: function() {
    return this.get('controller.content.passiveState') === 'ON';
  }.property('controller.content.passiveState'),

  actionMap: function() {
    return {
      RESTART_ALL: {
        action: 'restartAllHostComponents',
        context: this.get('serviceName'),
        label: Em.I18n.t('restart.service.all'),
        cssClass: 'icon-repeat',
        disabled: false
      },
      RUN_SMOKE_TEST: {
        action: 'runSmokeTest',
        label: Em.I18n.t('services.service.actions.run.smoke'),
        cssClass: 'icon-thumbs-up-alt'
      },
      REFRESH_CONFIGS: {
        action: 'refreshConfigs',
        label: Em.I18n.t('hosts.host.details.refreshConfigs'),
        cssClass: 'icon-refresh',
        disabled: !this.get('controller.content.isRestartRequired')
      },
      ROLLING_RESTART: {
        action: 'rollingRestart',
        context: this.get('rollingRestartComponent'),
        label: Em.I18n.t('rollingrestart.dialog.title'),
        cssClass: 'icon-time',
        disabled: false
      },
      TOGGLE_PASSIVE: {
        action: 'turnOnOffPassive',
        context: this.get('isPassive') ? Em.I18n.t('passiveState.turnOffFor').format(this.get('displayName')) : Em.I18n.t('passiveState.turnOnFor').format(this.get('displayName')),
        label: this.get('isPassive') ? Em.I18n.t('passiveState.turnOff') : Em.I18n.t('passiveState.turnOn'),
        cssClass: 'icon-medkit',
        disabled: false
      },
      TOGGLE_HA: {
        action: App.isHaEnabled ? 'disableHighAvailability' : 'enableHighAvailability',
        label: App.isHaEnabled ? Em.I18n.t('admin.highAvailability.button.disable') : Em.I18n.t('admin.highAvailability.button.enable'),
        cssClass: App.isHaEnabled ? 'icon-arrow-down' : 'icon-arrow-up',
        isHidden: (App.isHAEnabled && !App.autoRollbackHA)
      },
      MOVE_COMPONENT: {
        action: 'reassignMaster',
        context: '',
        label: Em.I18n.t('services.service.actions.reassign.master'),
        cssClass: 'icon-share-alt',
        disabled: false
      }
    }
  },
  /**
   * Create option for MOVE_COMPONENT or ROLLING_RESTART task.
   *
   * @param {Object} option - one of the options that return by <code>actionMap()</code>
   * @param {Object} fields - option fields to add/rewrite
   * @return {Object}
   */
  createOption: function(option, fields) {
    return $.extend(true, {}, option, fields);
  },

  maintenance: function(){
    var self = this;
    var options = [];
    var service = this.get('controller.content');
    var allMasters = this.get('controller.content.hostComponents').filterProperty('isMaster').mapProperty('componentName').uniq();
    var allSlaves = this.get('controller.content.hostComponents').filterProperty('isSlave').mapProperty('componentName').uniq();
    var actionMap = this.actionMap();

    if (this.get('controller.isClientsOnlyService')) {
      options.push(actionMap.RUN_SMOKE_TEST);
      options.push(actionMap.REFRESH_CONFIGS);
      if (this.get('serviceName') === 'TEZ') {
        options = options.without(actionMap.RUN_SMOKE_TEST);
      }
    } else {
      if (this.get('serviceName') === 'FLUME') {
        options.push(actionMap.REFRESH_CONFIGS);
      }
      options.push(actionMap.RESTART_ALL);
      allSlaves.forEach(function(slave) {
        options.push(self.createOption(actionMap.ROLLING_RESTART, {
          context: slave,
          label: actionMap.ROLLING_RESTART.label.format(App.format.role(slave))
        }));
      });
      allMasters.filter(function(master) {
        return App.get('components.reassignable').contains(master);
      }).forEach(function(master) {
        options.push(self.createOption(actionMap.MOVE_COMPONENT, {
          context: master,
          label: actionMap.MOVE_COMPONENT.label.format(App.format.role(master))
        }));
      });
      if (service.get('serviceTypes').contains('HA_MODE')) {
        options.push(actionMap.TOGGLE_HA);
      }
      options.push(actionMap.RUN_SMOKE_TEST);
      options.push(actionMap.TOGGLE_PASSIVE);
    }
    return options;
  }.property('controller.content', 'controller.isStopDisabled','controller.isClientsOnlyService', 'controller.content.isRestartRequired', 'isPassive'),

  isMaintenanceActive: function() {
    return this.get('maintenance').length !== 0;
  }.property('maintenance'),

  hasConfigTab: function() {
    return !App.get('services.noConfigTypes').concat('HCATALOG').contains('controller.content.serviceName');
  }.property('controller.content.serviceName','App.services.noConfigTypes'),
{'fraction_non_alphanumeric': 0.13819610522719508, 'fraction_numerical': 0.004953877690468056, 'mean_word_length': 3.426843100189036, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5513702', 'n_tokens_mistral': 3540, 'n_tokens_neox': 3471, 'n_words': 661}