class RHC::Rest::Application

Attributes

aliases[R]
app_url[R]
creation_time[R]
domain_id[R]
embedded[R]
framework[R]
gear_count[R]
gear_profile[R]
git_url[R]
health_check_path[R]
name[R]
scalable[R]
ssh_url[R]
uuid[R]

Public Instance Methods

add_alias(app_alias) click to toggle source
# File lib/rhc/rest/application.rb, line 84
def add_alias(app_alias)
  debug "Running add_alias for #{name}"
  rest_method "ADD_ALIAS", :event => "add-alias", :alias => app_alias
end
add_cartridge(name, timeout=nil) click to toggle source
# File lib/rhc/rest/application.rb, line 26
def add_cartridge(name, timeout=nil)
  debug "Adding cartridge #{name}"
  rest_method "ADD_CARTRIDGE", {:name => name}, timeout
end
cartridges() click to toggle source
# File lib/rhc/rest/application.rb, line 31
def cartridges
  debug "Getting all cartridges for application #{name}"
  rest_method "LIST_CARTRIDGES"
end
delete() click to toggle source
Alias for: destroy
destroy() click to toggle source
# File lib/rhc/rest/application.rb, line 68
def destroy
  debug "Deleting application #{name}"
  rest_method "DELETE"
end
Also aliased as: delete
find_cartridge(sought, options={}) click to toggle source

Find Cartridge by name

# File lib/rhc/rest/application.rb, line 95
def find_cartridge(sought, options={})
  debug "Finding cartridge #{sought} in app #{name}"

  type = options[:type]

  cartridges.each { |cart| return cart if cart.name == sought and (type.nil? or cart.type == type) }

  suggested_msg = ""
  valid_cartridges = cartridges.select {|c| type.nil? or c.type == type}
  unless valid_cartridges.empty?
    suggested_msg = "\n\nValid cartridges:"
    valid_cartridges.each { |cart| suggested_msg += "\n#{cart.name}" }
  end
  raise RHC::CartridgeNotFoundException.new("Cartridge #{sought} can't be found in application #{name}.#{suggested_msg}")
end
find_cartridges(name, options={}) click to toggle source

Find Cartridges by name or regex

# File lib/rhc/rest/application.rb, line 112
def find_cartridges(name, options={})
  if name.is_a?(Hash)
    options = name
    name = options[:name]
  end

  type = options[:type]
  regex = options[:regex]
  debug "Finding cartridge #{name || regex} in app #{@name}"

  filtered = Array.new
  cartridges.each do |cart|
    if regex
      filtered.push(cart) if cart.name.match(regex) and (type.nil? or cart.type == type)
    else
      filtered.push(cart) if cart.name == name and (type.nil? or cart.type == type)
    end
  end
  filtered
end
gear_groups() click to toggle source
# File lib/rhc/rest/application.rb, line 36
def gear_groups
  debug "Getting all gear groups for application #{name}"
  rest_method "GET_GEAR_GROUPS"
end
host() click to toggle source
# File lib/rhc/rest/application.rb, line 133
def host
  @host ||= URI(app_url).host
end
reload() click to toggle source
# File lib/rhc/rest/application.rb, line 74
def reload
  debug "Reload application #{name}"
  rest_method "RELOAD", :event => "reload"
end
remove_alias(app_alias) click to toggle source
# File lib/rhc/rest/application.rb, line 89
def remove_alias(app_alias)
  debug "Running add_alias for #{name}"
  rest_method "REMOVE_ALIAS", :event => "remove-alias", :alias => app_alias
end
restart() click to toggle source
# File lib/rhc/rest/application.rb, line 63
def restart
  debug "Restarting application #{name}"
  rest_method "RESTART", :event => "restart"
end
scalable?() click to toggle source

Query helper to say consistent with cartridge

# File lib/rhc/rest/application.rb, line 15
def scalable?
  scalable
end
scalable_carts() click to toggle source
# File lib/rhc/rest/application.rb, line 19
def scalable_carts
  return [] unless scalable?
  carts = cartridges.select(&:scalable?)
  scales_with = carts.map(&:scales_with)
  carts.delete_if{|x| scales_with.include?(x.name)}
end
start() click to toggle source
# File lib/rhc/rest/application.rb, line 46
def start
  debug "Starting application #{name}"
  rest_method 'START', :event => "start"
end
stop(force=false) click to toggle source
# File lib/rhc/rest/application.rb, line 51
def stop(force=false)
  debug "Stopping application #{name} force-#{force}"

  if force
    payload = {:event=> "force-stop"}
  else
    payload = {:event=> "stop"}
  end

  rest_method "STOP", payload
end
tail(options) click to toggle source

Application log file tailing

# File lib/rhc/rest/application.rb, line 138
      def tail(options)
        debug "Tail in progress for #{name}"

        file_glob = options.files ? options.files : "#{cartridges.first.name}/logs/*"
        remote_cmd = "tail#{options.opts ? ' --opts ' + Base64::encode64(options.opts).chomp : ''} #{file_glob}"
        ssh_cmd = "ssh -t #{uuid}@#{host} '#{remote_cmd}'"
        begin
          #Use ssh -t to tail the logs
          debug ssh_cmd
          ssh_ruby(host, uuid, remote_cmd)
        rescue SocketError => e
          msg ="Could not connect: #{e.message}
You can try to run this manually if you have ssh installed:
#{ssh_cmd}

"
          debug "DEBUG: #{e.message}\n"
          raise SocketError, msg
        end
      end
threaddump() click to toggle source
# File lib/rhc/rest/application.rb, line 79
def threaddump
  debug "Running thread dump for #{name}"
  rest_method "THREAD_DUMP", :event => "thread-dump"
end
tidy() click to toggle source
# File lib/rhc/rest/application.rb, line 41
def tidy
  debug "Starting application #{name}"
  rest_method 'TIDY', :event => "tidy"
end