<commit_before>module Stacks::Services::MongoDBCluster
  attr_accessor :database_name
  attr_accessor :supported_requirements
  attr_accessor :master_instances
  attr_accessor :arbiter_instances
  attr_accessor :backup_instances
  ### FIXME: Remove this temporary workaround when backup server is rebuilt in the correct logicalenv
  attr_accessor :backup_server_site

  def self.extended(object)
    object.configure
  end

  def configure
    @supported_requirements = :accept_any_requirement_default_all_servers
    @master_instances = 2
    @backup_instances = 1
    @arbiter_instances = 1
    @database_name = ''
    ### FIXME: Remove this temporary workaround when backup server is rebuilt in the correct logicalenv
    @backup_server_site = :secondary_site
  end

  def instantiate_machines(environment)
    i = 0
    @master_instances.times do
      instantiate_machine(name, :master, i += 1, environment, :primary_site)
    end
    i = 0
    @arbiter_instances.times do
      instantiate_machine(name, :arbiter, i += 1, environment, :primary_site)
    end
    i = 0
    @backup_instances.times do
      instantiate_machine(name, :backup, i += 1, environment, @backup_server_site)
    end
  end

  def instantiate_machine(name, type, i, environment, location)
    index = sprintf("%03d", i)
    server_name = "#{name}-#{index}"
    server_name = "#{name}#{type}-#{index}" if [:backup, :arbiter].include?(type)
    server = @type.new(server_name, i, self, type, location)
    server.group = groups[i % groups.size] if server.respond_to?(:group)
    server.availability_group = availability_group(environment) if server.respond_to?(:availability_group)
    @definitions["#{server_name}-#{location}"] = server
  end

  def requirement_of(dependant)
    dependent_on_this_cluster = dependant.depends_on.find { |dependency| dependency[0] == name }
    fail "Stack '#{dependant.name}' must specify requirement when using depend_on #{name} "\
          "in environment '#{environment.name}'. Usage: depend_on <environment>, <requirement>" \<commit_msg>rpearce: Allow backup server name to be temporarily changed to a legacy format<commit_after>module Stacks::Services::MongoDBCluster
  attr_accessor :database_name
  attr_accessor :supported_requirements
  attr_accessor :master_instances
  attr_accessor :arbiter_instances
  attr_accessor :backup_instances
  ### FIXME: Remove this temporary workaround when backup server is rebuilt in the correct logicalenv
  attr_accessor :backup_server_site
  attr_accessor :backup_server_legacy_naming

  def self.extended(object)
    object.configure
  end

  def configure
    @supported_requirements = :accept_any_requirement_default_all_servers
    @master_instances = 2
    @backup_instances = 1
    @arbiter_instances = 1
    @database_name = ''
    ### FIXME: Remove this temporary workaround when backup server is rebuilt in the correct logicalenv
    @backup_server_site = :secondary_site
    @backup_server_legacy_naming = false
  end

  def instantiate_machines(environment)
    i = 0
    @master_instances.times do
      instantiate_machine(name, :master, i += 1, environment, :primary_site)
    end
    i = 0
    @arbiter_instances.times do
      instantiate_machine(name, :arbiter, i += 1, environment, :primary_site)
    end
    i = 0
    @backup_instances.times do
      instantiate_machine(name, :backup, i += 1, environment, @backup_server_site)
    end
  end

  def instantiate_machine(name, type, i, environment, location)
    index = sprintf("%03d", i)

    server_name = "#{name}-#{index}"
    server_name = "#{name}#{type}-#{index}" if [:backup, :arbiter].include?(type) && !@backup_server_legacy_naming
    server = @type.new(server_name, i, self, type, location)
    server.group = groups[i % groups.size] if server.respond_to?(:group)
    server.availability_group = availability_group(environment) if server.respond_to?(:availability_group)
    @definitions["#{server_name}-#{location}"] = server
  end

  def requirement_of(dependant)
    dependent_on_this_cluster = dependant.depends_on.find { |dependency| dependency[0] == name }
    fail "Stack '#{dependant.name}' must specify requirement when using depend_on #{name} "\
          "in environment '#{environment.name}'. Usage: depend_on <environment>, <requirement>" \
{'fraction_non_alphanumeric': 0.09979016087666123, 'fraction_numerical': 0.00559570995570063, 'mean_word_length': 4.54980595084088, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2554069', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1295, 'n_words': 325}