class RHC::Rest::Mock::MockRestApplication

Public Class Methods

new(client, name, type, domain, scale=nil, gear_profile='default', initial_git_url=nil, environment_variables=nil) click to toggle source
Calls superclass method
# File lib/rhc/rest/mock.rb, line 756
def initialize(client, name, type, domain, scale=nil, gear_profile='default', initial_git_url=nil, environment_variables=nil)
  super({}, client)
  @name = name
  @domain = domain
  @cartridges = []
  @creation_time = Date.new(2000, 1, 1).strftime('%Y-%m-%dT%H:%M:%S%z')
  @uuid = fakeuuid
  @initial_git_url = initial_git_url
  @git_url = "git:fake.foo/git/#{@name}.git"
  @app_url = "https://#{@name}-#{@domain.name}.fake.foo/"
  @ssh_url = "ssh://#{@uuid}@127.0.0.1"
  @aliases = []
  @environment_variables = environment_variables || []
  @gear_profile = gear_profile
  @auto_deploy = true
  @keep_deployments = 1
  if scale
    @scalable = true
  end
  self.attributes = {:links => mock_response_links(mock_app_links('mock_domain_0', 'mock_app_0')), :messages => []}
  self.gear_count = 5
  types = Array(type)
  cart = add_cartridge(types.first, false) if types.first
  if scale
    cart.supported_scales_to = (cart.scales_to = -1)
    cart.supported_scales_from = (cart.scales_from = 2)
    cart.current_scale = 2
    cart.scales_with = "haproxy-1.4"
    prox = add_cartridge('haproxy-1.4')
    prox.collocated_with = [types.first]
  end
  types.drop(1).each{ |c| add_cartridge(c, false) }
  @framework = types.first
end

Public Instance Methods

add_alias(app_alias) click to toggle source
# File lib/rhc/rest/mock.rb, line 857
def add_alias(app_alias)
  @aliases << MockRestAlias.new(@client, app_alias)
end
add_cartridge(cart, embedded=true, environment_variables=nil) click to toggle source
# File lib/rhc/rest/mock.rb, line 795
def add_cartridge(cart, embedded=true, environment_variables=nil)
  name, url =
    if cart.is_a? String
      [cart, nil]
    elsif cart.respond_to? :[]
      [cart[:name] || cart['name'], cart[:url] || cart['url']]
    elsif RHC::Rest::Cartridge === cart
      [cart.name, cart.url]
    end

  type = embedded ? "embedded" : "standalone"
  c = MockRestCartridge.new(client, name, type, self)
  if url
    c.url = url
    c.name = c.url_basename
  end
  #set_environment_variables(environment_variables)
  c.properties << {'name' => 'prop1', 'value' => 'value1', 'description' => 'description1' }
  @cartridges << c
  c.messages << "Cartridge added with properties"
  c
end
add_member(member) click to toggle source
# File lib/rhc/rest/mock.rb, line 893
def add_member(member)
  (@members ||= []) << member
  self
end
aliases() click to toggle source
# File lib/rhc/rest/mock.rb, line 865
def aliases
  @aliases
end
auto_deploy() click to toggle source
# File lib/rhc/rest/mock.rb, line 902
def auto_deploy
  @auto_deploy || false
end
cartridges() click to toggle source
# File lib/rhc/rest/mock.rb, line 833
def cartridges
  @cartridges
end
configure(options={}) click to toggle source
# File lib/rhc/rest/mock.rb, line 898
def configure(options={})
  options.each {|key,value| self.instance_variable_set("@#{key.to_s}", value)}
end
deployments() click to toggle source
# File lib/rhc/rest/mock.rb, line 910
def deployments
  base_time1 = Time.local(2000,1,1,1,0,0).strftime('%Y-%m-%dT%H:%M:%S%z')
  base_time2 = Time.local(2000,1,1,2,0,0).strftime('%Y-%m-%dT%H:%M:%S%z')
  base_time3 = Time.local(2000,1,1,3,0,0).strftime('%Y-%m-%dT%H:%M:%S%z')
  base_time4 = Time.local(2000,1,1,4,0,0).strftime('%Y-%m-%dT%H:%M:%S%z')
  base_time5 = Time.local(2000,1,1,5,0,0).strftime('%Y-%m-%dT%H:%M:%S%z')
  base_time6 = Time.local(2000,1,1,6,0,0).strftime('%Y-%m-%dT%H:%M:%S%z')
  [
    MockRestDeployment.new(self, '0000001', 'master', '0000001', nil, false, base_time1, false, [base_time1]),
    MockRestDeployment.new(self, '0000002', 'master', '0000002', nil, false, base_time2, false, [base_time2, base_time6]),
    MockRestDeployment.new(self, '0000003', 'master', '0000003', nil, false, base_time3, false, [base_time3, base_time5]),
    MockRestDeployment.new(self, '0000004', 'master', '0000004', nil, false, base_time4, false, [base_time4]),
    MockRestDeployment.new(self, '0000005', 'master', '0000005', nil, false, base_time5, false, [base_time5]),
  ]
end
destroy() click to toggle source
# File lib/rhc/rest/mock.rb, line 791
def destroy
  @domain.applications.delete self
end
environment_variables() click to toggle source
# File lib/rhc/rest/mock.rb, line 869
def environment_variables
  if supports? "LIST_ENVIRONMENT_VARIABLES"
    @environment_variables || []
  else
    raise RHC::EnvironmentVariablesNotSupportedException.new
  end
end
fakeuuid() click to toggle source
# File lib/rhc/rest/mock.rb, line 752
def fakeuuid
  "fakeuuidfortests#{@name}"
end
gear_groups() click to toggle source
# File lib/rhc/rest/mock.rb, line 822
def gear_groups
  # we don't have heavy interaction with gear groups yet so keep this simple
  @gear_groups ||= begin
    if @scalable
      cartridges.map{ |c| MockRestGearGroup.new(client, [c.name], c.current_scale) if c.name != 'haproxy-1.4' }.compact
    else
      [MockRestGearGroup.new(client, cartridges.map{ |c| {'name' => c.name} }, 1)]
    end
  end
end
id() click to toggle source
# File lib/rhc/rest/mock.rb, line 818
def id
  @uuid || attributes['uuid'] || attributes['id']
end
keep_deployments() click to toggle source
# File lib/rhc/rest/mock.rb, line 906
def keep_deployments
  @keep_deployments
end
reload() click to toggle source
# File lib/rhc/rest/mock.rb, line 849
def reload
  @app
end
remove_alias(app_alias) click to toggle source
# File lib/rhc/rest/mock.rb, line 861
def remove_alias(app_alias)
  @aliases.delete_if {|x| x.id == app_alias}
end
restart() click to toggle source
# File lib/rhc/rest/mock.rb, line 845
def restart
  @app
end
set_environment_variables(env_vars=[]) click to toggle source
# File lib/rhc/rest/mock.rb, line 877
def set_environment_variables(env_vars=[])
  if supports? "SET_UNSET_ENVIRONMENT_VARIABLES"
    environment_variables.concat env_vars
  else
    raise RHC::EnvironmentVariablesNotSupportedException.new
  end
end
start() click to toggle source
# File lib/rhc/rest/mock.rb, line 837
def start
  @app
end
stop(*args) click to toggle source
# File lib/rhc/rest/mock.rb, line 841
def stop(*args)
  @app
end
tidy() click to toggle source
# File lib/rhc/rest/mock.rb, line 853
def tidy
  @app
end
unset_environment_variables(env_vars=[]) click to toggle source
# File lib/rhc/rest/mock.rb, line 885
def unset_environment_variables(env_vars=[])
  if supports? "SET_UNSET_ENVIRONMENT_VARIABLES"
    env_vars.each { |item| environment_variables.delete_if { |env_var| env_var.name == item } }
  else
    raise RHC::EnvironmentVariablesNotSupportedException.new
  end
end