<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.
 */

/**
 * Checks Slider-properties.
 * If they are not available, uses Ambari-configs to populate them:
 *  - Load cluster name
 *  - Load hostName for GANGLIA_SERVER
 *  - Load hostName for NAGIOS_SERVER
 *  - Load hostNames for ZOOKEEPER_SERVER
 *  - Load config tags
 *  - Load configs
 *  - Save Slider-properties
 * If Slider-properties exists:
 *  - Load cluster name
 *  - Load hostNames
 * After whole data has been loaded set <code>App.sliderConfigs</code> and enable/disable Slider
 * @type {Ember.Controller}
 */
App.SliderController = Ember.Controller.extend(App.RunPeriodically, {

  /**
   * Map for Slider-errors
   * If some config is empty, service isn't installed
   * @type {object}
   */
  serviceConfigMap: {
    HDFS: 'hdfsAddress',
    YARN: 'yarnResourceManager',
    ZOOKEEPER: 'zookeeperQuorum'
  },

  /**
   * List of Slider-properties mapped from Ambari-configs
   * Key-names used in Slider-Title-Popup, so don't change it pls
   * @type {Em.Object}
   */
  initialValuesToLoad: Em.Object.create({
    ambariAddress: null,
    clusterName: null,
    hdfsAddress: null,
    yarnResourceManager: null,
    yarnResourceManagerScheduler: null,
    zookeeperQuorum: null,
    gangliaServer: null,
    gangliaClusters: null
  }),

  /**
   * List of host names with ZOOKEEPER_SERVER installed
   * @type {string[]}
   */
  zookeeperHosts: [],

  /**
   *  Load resources on controller initialization
   * @method initResources
   */
  initResources: function () {
    this.getParametersFromViewProperties();
  },

  /**
   * Get Slider properties from View-parameters (set in the Ambari Admin View)
   * If parameters can't be found, use Ambari-configs to populate Slider properties
   * @returns {$.ajax}
   * @method getParametersFromViewProperties
   */
  getParametersFromViewProperties: function() {
    return App.ajax.send({
      name: 'slider.getViewParams',
      sender: this,
      success: 'getParametersFromViewPropertiesSuccessCallback',
      error: 'getParametersFromViewPropertiesErrorCallback'
    });
  },

  /**
   * Check if Slider-properties exist
   * If exist - set Slider properties using view-configs
   * If not - get Ambari configs to populate Slider properties
   * @param {object} data
   * @method getParametersFromViewPropertiesSuccessCallback
   */
  getParametersFromViewPropertiesSuccessCallback: function(data) {
    var properties = Em.get(data, 'ViewInstanceInfo.properties'),
      initialValuesToLoad = this.get('initialValuesToLoad');
    if (Em.isEmpty(properties)) {
      this.getClusterName();
    }
    else {
      initialValuesToLoad.setProperties({
        ambariAddress: location.protocol + "//" + document.location.host,
        hdfsAddress: properties['hdfs.address'],
        yarnResourceManager: properties['yarn.resourcemanager.address'],
        yarnResourceManagerScheduler: properties['yarn.resourcemanager.scheduler.address'],
        zookeeperQuorum: properties['zookeeper.quorum'],
        gangliaServer: properties['ganglia.server.hostname'],
        gangliaClusters: properties['ganglia.custom.clusters']
      });
      App.set('gangliaHost', properties['ganglia.server.hostname']);
      this.finishSliderConfiguration();
    }
  },

  /**
   * Error-callback for Slider-parameters request
   * @method getParametersFromViewPropertiesErrorCallback
   */
  getParametersFromViewPropertiesErrorCallback: function() {
    this.getClusterName();
  },

  /**
   * Get cluster name from server
   * @returns {$.ajax}
   * @method getClusterName
   */<commit_msg>AMBARI-7334. Slider View: Show view name along with hover of view properties - fixes (srimanth)<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.
 */

/**
 * Checks Slider-properties.
 * If they are not available, uses Ambari-configs to populate them:
 *  - Load cluster name
 *  - Load hostName for GANGLIA_SERVER
 *  - Load hostName for NAGIOS_SERVER
 *  - Load hostNames for ZOOKEEPER_SERVER
 *  - Load config tags
 *  - Load configs
 *  - Save Slider-properties
 * If Slider-properties exists:
 *  - Load cluster name
 *  - Load hostNames
 * After whole data has been loaded set <code>App.sliderConfigs</code> and enable/disable Slider
 * @type {Ember.Controller}
 */
App.SliderController = Ember.Controller.extend(App.RunPeriodically, {

  /**
   * Map for Slider-errors
   * If some config is empty, service isn't installed
   * @type {object}
   */
  serviceConfigMap: {
    HDFS: 'hdfsAddress',
    YARN: 'yarnResourceManager',
    ZOOKEEPER: 'zookeeperQuorum'
  },

  /**
   * List of Slider-properties mapped from Ambari-configs
   * Key-names used in Slider-Title-Popup, so don't change it pls
   * @type {Em.Object}
   */
  initialValuesToLoad: Em.Object.create({
    ambariAddress: null,
    clusterName: null,
    hdfsAddress: null,
    yarnResourceManager: null,
    yarnResourceManagerScheduler: null,
    zookeeperQuorum: null,
    gangliaServer: null,
    gangliaClusters: null
  }),

  /**
   * List of host names with ZOOKEEPER_SERVER installed
   * @type {string[]}
   */
  zookeeperHosts: [],

  /**
   *  Load resources on controller initialization
   * @method initResources
   */
  initResources: function () {
    this.getParametersFromViewProperties();
  },

  /**
   * Get Slider properties from View-parameters (set in the Ambari Admin View)
   * If parameters can't be found, use Ambari-configs to populate Slider properties
   * @returns {$.ajax}
   * @method getParametersFromViewProperties
   */
  getParametersFromViewProperties: function() {
    return App.ajax.send({
      name: 'slider.getViewParams',
      sender: this,
      success: 'getParametersFromViewPropertiesSuccessCallback',
      error: 'getParametersFromViewPropertiesErrorCallback'
    });
  },

  /**
   * Check if Slider-properties exist
   * If exist - set Slider properties using view-configs
   * If not - get Ambari configs to populate Slider properties
   * @param {object} data
   * @method getParametersFromViewPropertiesSuccessCallback
   */
  getParametersFromViewPropertiesSuccessCallback: function(data) {
    var properties = Em.get(data, 'ViewInstanceInfo.properties'),
      initialValuesToLoad = this.get('initialValuesToLoad');
    if (properties == null || properties['hdfs.address'] == null
        || properties['yarn.resourcemanager.address'] == null
        || properties['yarn.resourcemanager.scheduler.address'] == null
        || properties['zookeeper.quorum'] == null) {
      this.getClusterName();
    } else {
      initialValuesToLoad.setProperties({
        ambariAddress: location.protocol + "//" + document.location.host,
        hdfsAddress: properties['hdfs.address'],
        yarnResourceManager: properties['yarn.resourcemanager.address'],
        yarnResourceManagerScheduler: properties['yarn.resourcemanager.scheduler.address'],
        zookeeperQuorum: properties['zookeeper.quorum'],
        gangliaServer: properties['ganglia.server.hostname'],
        gangliaClusters: properties['ganglia.custom.clusters']
      });
      App.set('gangliaHost', properties['ganglia.server.hostname']);
      this.finishSliderConfiguration();
    }
  },

  /**
   * Error-callback for Slider-parameters request
   * @method getParametersFromViewPropertiesErrorCallback
   */
  getParametersFromViewPropertiesErrorCallback: function() {
    this.getClusterName();
  },

  /**
   * Get cluster name from server
   * @returns {$.ajax}
   * @method getClusterName
   */
{'fraction_non_alphanumeric': 0.09924678777137794, 'fraction_numerical': 0.001329198050509526, 'mean_word_length': 3.5463242698892246, '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': '6205735', 'n_tokens_mistral': 2544, 'n_tokens_neox': 2500, 'n_words': 736}