<commit_before>require 'stacks/namespace'
require 'stacks/machine_def'

class Stacks::Services::AppServer < Stacks::MachineDef
  attr_reader :environment
  attr_reader :location
  attr_accessor :group
  attr_accessor :launch_config

  def initialize(virtual_service, index, networks = [:mgmt, :prod], location = :primary_site)
    super(virtual_service.name + "-" + index, networks, location)
    @virtual_service = virtual_service
    @allowed_hosts = []
    @launch_config = {}
    modify_storage('/' => { :size => '5G' })
  end

  def bind_to(environment)
    super(environment)
  end

  def allow_host(source_host_or_network)
    @allowed_hosts << source_host_or_network
    @allowed_hosts.uniq!
  end

  def dependency_config_sftp_servers_only(location)
    @virtual_service.dependency_config(location).reject { |key, _value| key != 'sftp_servers' }
  end

  def dependency_config_excluding_sftp_servers(location)
    @virtual_service.dependency_config(location).reject! { |key, _value| key == 'sftp_servers' }
  end

  def to_enc
    enc = super
    enc['role::http_app'] = {
      'application'                       => @virtual_service.application,
      'group'                             => group,
      'cluster'                           => availability_group,
      'environment'                       => environment.name,
      'dependencies'                      => @virtual_service.dependency_config(location),
      'application_dependant_instances'   => @virtual_service.dependant_instance_fqdns(location),
      'participation_dependant_instances' => @virtual_service.dependant_load_balancer_fqdns(location),
      'port'                              => '8000'
    }

    enc['role::http_app']['jvm_args'] = @virtual_service.jvm_args unless @virtual_service.jvm_args.nil?
    enc['role::http_app']['sso_port'] = @virtual_service.sso_port unless @virtual_service.sso_port.nil?
    enc['role::http_app']['ajp_port'] = @virtual_service.ajp_port unless @virtual_service.ajp_port.nil?

    allowed_hosts = @allowed_hosts<commit_msg>bkhidhir / provide normalize_storage option to virtual appserver<commit_after>require 'stacks/namespace'
require 'stacks/machine_def'

class Stacks::Services::AppServer < Stacks::MachineDef
  attr_reader :environment
  attr_reader :location
  attr_reader :ram
  attr_reader :storage
  attr_accessor :group
  attr_accessor :launch_config

  def initialize(virtual_service, index, networks = [:mgmt, :prod], location = :primary_site)
    super(virtual_service.name + "-" + index, networks, location)
    @virtual_service = virtual_service
    @allowed_hosts = []
    @launch_config = {}
    modify_storage('/' => { :size => '5G' })
  end

  def bind_to(environment)
    super(environment)
  end

  def allow_host(source_host_or_network)
    @allowed_hosts << source_host_or_network
    @allowed_hosts.uniq!
  end

  def dependency_config_sftp_servers_only(location)
    @virtual_service.dependency_config(location).reject { |key, _value| key != 'sftp_servers' }
  end

  def dependency_config_excluding_sftp_servers(location)
    @virtual_service.dependency_config(location).reject! { |key, _value| key == 'sftp_servers' }
  end

  def normalize_storage
    root_size_cur = @storage['/'.to_sym][:size].chomp('G').to_i
    root_size_min = @ram.to_i / 524288 + 2

    if root_size_cur < root_size_min
      modify_storage('/' => { :size => root_size_min.to_s.concat('G') })
    end
  end

  def to_enc
    enc = super
    enc['role::http_app'] = {
      'application'                       => @virtual_service.application,
      'group'                             => group,
      'cluster'                           => availability_group,
      'environment'                       => environment.name,
      'dependencies'                      => @virtual_service.dependency_config(location),
      'application_dependant_instances'   => @virtual_service.dependant_instance_fqdns(location),
      'participation_dependant_instances' => @virtual_service.dependant_load_balancer_fqdns(location),
      'port'                              => '8000'
    }

    enc['role::http_app']['jvm_args'] = @virtual_service.jvm_args unless @virtual_service.jvm_args.nil?
    enc['role::http_app']['sso_port'] = @virtual_service.sso_port unless @virtual_service.sso_port.nil?
    enc['role::http_app']['ajp_port'] = @virtual_service.ajp_port unless @virtual_service.ajp_port.nil?

    allowed_hosts = @allowed_hosts
{'fraction_non_alphanumeric': 0.11386138613861387, 'fraction_numerical': 0.003825382538253825, 'mean_word_length': 3.4317048853439682, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '502052', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1370, 'n_words': 217}