# File lib/openshift-origin-controller/app/models/application.rb, line 408
  def scaledown(comp_name=nil)
    result_io = ResultIO.new
    if not self.scalable
      raise OpenShift::UserException.new("Cannot scale a non-scalable application", 255, result_io)
    end
    comp_name = "web" if comp_name.nil?
    prof = @profile_name_map[@default_profile]
    cinst = ComponentInstance::find_component_in_cart(prof, self, comp_name, self.get_name_prefix)
    raise OpenShift::NodeException.new("Cannot find #{comp_name} in app #{self.name}.", 1, result_io) if cinst.nil?
    ginst = self.group_instance_map[cinst.group_instance_name]
    raise OpenShift::NodeException.new("Cannot find group #{cinst.group_instance_name} for #{comp_name} in app #{self.name}.", 1, result_io) if ginst.nil?
    # remove any gear out of this ginst
    raise OpenShift::UserException.new("Cannot scale below minimum gear requirements", 1, result_io) if ginst.gears.length <= ginst.min

    gear = ginst.gears.last

    dns = OpenShift::DnsService.instance
    begin
      dns.deregister_application(gear.name, @domain.namespace)
      dns.publish
    ensure
      dns.close
    end

    result_io.append ginst.remove_gear(gear)

    # inform anyone who needs to know that this gear is no more
    self.configure_dependencies
    self.execute_connections
    result_io
  end