<commit_before>minispade.register('cluster', function() {

  /**
   * @class
   *
   * Responsible for modeling one specific cluster node.
   */
  RiakControl.CurrentClusterNode = Ember.Object.extend(
    /** @scope RiakControl.CurrentClusterNode.prototype */ {});

  /**
   * @class
   *
   * Responsible for modeling one specific cluster node.
   */
  RiakControl.StagedClusterNode = Ember.Object.extend(
    /** @scope RiakControl.StagedClusterNode.prototype */ {

    /**
     * Does the node have a replacement?
     *
     * @returns {boolean}
     */
    isReplaced: function() {
      return this.get('replacement') !== "undefined" ? true : false;
    }.property('replacement'),

    /**
     * Is the node taking an action?
     *
     * @returns {boolean}
     */
    isAction: function() {
        return this.get('action') !== "undefined" ? true : false;
    }.property('action')

  });

  /**
   * @class
   *
   * Responsible for modeling the current and staged cluster.
   */
  RiakControl.CurrentAndPlannedCluster = Ember.Object.extend(
    /** @scope RiakControl.CurrentAndPlannedCluster.prototype */ {});

  /**
   * @class
   *
   * ClusterController is responsible for display the list of nodes
   * in the cluster.  This controller is basically a placeholder and
   * wrapper around the legacy cluster page until we rewrite it.
   */
  RiakControl.ClusterController = Ember.ObjectController.extend(
    /** @scope RiakControl.ClusterController.prototype */ {

    /**
     * Refresh a particular cluster, giving a cluster returned as JSON,
     * and a cluster modeled in Ember.
     *
     * Not computationally efficient at all, but explicit for debugging
     * the Ember bindings and propagation.
     *
     * @returns {void}
     */
    refresh: function(newCluster, existingCluster, nodeFactory) {
      newCluster.forEach(function(node) {
        var exists = existingCluster.findProperty('name', node.name);

        // If it doesn't exist yet, add it.  If it does, update it.
        if(exists !== undefined) {
          exists.setProperties(node);
        } else {
          existingCluster.pushObject(nodeFactory.create(node));
        }
      });

      // Iterate the cluster removing nodes that shouldn't
      // be there.
      var changesOccurred    = false;
      var replacementCluster = [];

      existingCluster.forEach(function(node, i) {
        var exists = newCluster.findProperty('name', node.name);

        if(exists === undefined) {
          node.destroy();
          changesOccurred = true;
        } else {
          replacementCluster.pushObject(node);
        }
      });

      if(changesOccurred) {
        existingCluster.set('[]', replacementCluster.get('[]'));
      }
    },

    /**
     * Load data from server.
     *
     * @returns {void}
     */
    load: function() {
      var self = this;

      $.ajax({
        type:     'GET',
        url:      '/admin/cluster',
        dataType: 'json',

        success: function(d) {
          var updatedCurrentCluster = d.cluster.current;
          var currentCurrentCluster = self.get('content.currentCluster');

          self.refresh(updatedCurrentCluster,
            currentCurrentCluster, RiakControl.CurrentClusterNode);

          var updatedStagedCluster = d.cluster.staged;

          if(updatedStagedCluster === 'ring_not_ready') {
            self.set('ringNotReady', true);
          } else {
            self.set('ringNotReady', false);
          }

          if(updatedStagedCluster === 'legacy') {
            self.set('legacyRing', true);
          } else {
            self.set('legacyRing', false);
          }

          if($.isArray(updatedStagedCluster)) {
            var currentStagedCluster = self.get('content.stagedCluster');

            self.refresh(updatedStagedCluster,
              currentStagedCluster, RiakControl.StagedClusterNode);
          }
        },

        error: function (jqXHR, textStatus, errorThrown) {
          self.get('displayError').call(self, jqXHR, textStatus, errorThrown);
        }
      });<commit_msg>Handle failures on the node hosting control.<commit_after>minispade.register('cluster', function() {

  /**
   * @class
   *
   * Responsible for modeling one specific cluster node.
   */
  RiakControl.CurrentClusterNode = Ember.Object.extend(
    /** @scope RiakControl.CurrentClusterNode.prototype */ {});

  /**
   * @class
   *
   * Responsible for modeling one specific cluster node.
   */
  RiakControl.StagedClusterNode = Ember.Object.extend(
    /** @scope RiakControl.StagedClusterNode.prototype */ {

    /**
     * Does the node have a replacement?
     *
     * @returns {boolean}
     */
    isReplaced: function() {
      return this.get('replacement') !== "undefined" ? true : false;
    }.property('replacement'),

    /**
     * Is the node taking an action?
     *
     * @returns {boolean}
     */
    isAction: function() {
        return this.get('action') !== "undefined" ? true : false;
    }.property('action')

  });

  /**
   * @class
   *
   * Responsible for modeling the current and staged cluster.
   */
  RiakControl.CurrentAndPlannedCluster = Ember.Object.extend(
    /** @scope RiakControl.CurrentAndPlannedCluster.prototype */ {});

  /**
   * @class
   *
   * ClusterController is responsible for display the list of nodes
   * in the cluster.  This controller is basically a placeholder and
   * wrapper around the legacy cluster page until we rewrite it.
   */
  RiakControl.ClusterController = Ember.ObjectController.extend(
    /** @scope RiakControl.ClusterController.prototype */ {

    /**
     * Refresh a particular cluster, giving a cluster returned as JSON,
     * and a cluster modeled in Ember.
     *
     * Not computationally efficient at all, but explicit for debugging
     * the Ember bindings and propagation.
     *
     * @returns {void}
     */
    refresh: function(newCluster, existingCluster, nodeFactory) {
      newCluster.forEach(function(node) {
        var exists = existingCluster.findProperty('name', node.name);

        // If it doesn't exist yet, add it.  If it does, update it.
        if(exists !== undefined) {
          exists.setProperties(node);
        } else {
          existingCluster.pushObject(nodeFactory.create(node));
        }
      });

      // Iterate the cluster removing nodes that shouldn't
      // be there.
      var changesOccurred    = false;
      var replacementCluster = [];

      existingCluster.forEach(function(node, i) {
        var exists = newCluster.findProperty('name', node.name);

        if(exists === undefined) {
          node.destroy();
          changesOccurred = true;
        } else {
          replacementCluster.pushObject(node);
        }
      });

      if(changesOccurred) {
        existingCluster.set('[]', replacementCluster.get('[]'));
      }
    },

    /**
     * Load data from server.
     *
     * @returns {void}
     */
    load: function() {
      var self = this;

      $.ajax({
        type:     'GET',
        url:      '/admin/cluster',
        dataType: 'json',

        success: function(d) {
          var updatedCurrentCluster = d.cluster.current;
          var currentCurrentCluster = self.get('content.currentCluster');

          self.refresh(updatedCurrentCluster,
            currentCurrentCluster, RiakControl.CurrentClusterNode);

          var updatedStagedCluster = d.cluster.staged;

          if(updatedStagedCluster === 'ring_not_ready') {
            self.set('ringNotReady', true);
          } else {
            self.set('ringNotReady', false);
          }

          if(updatedStagedCluster === 'legacy') {
            self.set('legacyRing', true);
          } else {
            self.set('legacyRing', false);
          }

          if($.isArray(updatedStagedCluster)) {
            var currentStagedCluster = self.get('content.stagedCluster');

            self.refresh(updatedStagedCluster,
              currentStagedCluster, RiakControl.StagedClusterNode);
          }
        },

        error: function (jqXHR, textStatus, errorThrown) {
          if(jqXHR.status === 404) {
            self.get('displayError').call(self, undefined, undefined, "The node hosting Riak Control is unavailable.");
          } else {
            self.get('displayError').call(self, jqXHR, textStatus, errorThrown);
          }
        }
      });
{'fraction_non_alphanumeric': 0.12038695807954139, 'fraction_numerical': 0.00035829451809387314, 'mean_word_length': 2.2482544608223427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3794535', 'n_tokens_mistral': 2361, 'n_tokens_neox': 2256, 'n_words': 529}