class Gear

Attributes

app[RW]
configured_components[RW]
container[RW]
group_instance_name[RW]
name[RW]
node_profile[RW]
server_identity[RW]
uid[RW]
uuid[RW]

Public Class Methods

new(app, group_instance, uuid=nil, uid=nil) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 6
def initialize(app, group_instance, uuid=nil, uid=nil)
  self.app = app
  @uuid = uuid || StickShift::Model.gen_uuid
  self.name = @uuid[0..9]
  self.group_instance_name = group_instance.name
  self.node_profile = group_instance.node_profile
  self.configured_components = []
  @uid = uid
  get_proxy
end

Public Instance Methods

add_alias(server_alias) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 170
def add_alias(server_alias)
  if app.gear.uuid == self.uuid
    get_proxy.add_alias(app, self, app.framework, server_alias)
  else
    ResultIO.new
  end
end
add_authorized_ssh_key(ssh_key, key_type=nil, comment=nil) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 186
def add_authorized_ssh_key(ssh_key, key_type=nil, comment=nil)
  get_proxy.add_authorized_ssh_key(app, self, ssh_key, key_type, comment)
end
add_broker_auth_key(iv,token) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 237
def add_broker_auth_key(iv,token)
  get_proxy.add_broker_auth_key(app, self, iv, token)
end
add_env_var(key, value) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 194
def add_env_var(key, value)
  get_proxy.add_env_var(app, self, key, value)
end
app_state_job_show() click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 198
def app_state_job_show()
  job = get_proxy.get_show_state_job(app, self)
  job
end
broker_auth_key_job_add(iv, token) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 213
def broker_auth_key_job_add(iv, token)
  job = get_proxy.get_broker_auth_key_add_job(app, self, iv, token)
  job
end
broker_auth_key_job_remove() click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 228
def broker_auth_key_job_remove()
  job = get_proxy.get_broker_auth_key_remove_job(app, self)
  job
end
cartridges() click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 245
def cartridges
  group_instance = app.group_instance_map[group_instance_name]
  carts = group_instance.component_instances.map{ |comp_instance_name| app.comp_instance_map[comp_instance_name].parent_cart_name }
  carts.delete(app.name)
  carts
end
conceal_port(comp_inst) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 154
def conceal_port(comp_inst)
  get_proxy.conceal_port(app,self,comp_inst.parent_cart_name)
end
configure(comp_inst, template_git_url=nil) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 91
def configure(comp_inst, template_git_url=nil)
  r = ResultIO.new
  return r if self.configured_components.include?(comp_inst.name)
  result_io, cart_data = get_proxy.configure_cartridge(app, self, comp_inst.parent_cart_name, template_git_url)
  r.append result_io
  comp_inst.process_cart_data(cart_data)
  comp_inst.process_cart_properties(result_io.cart_properties)
  self.configured_components.push(comp_inst.name)
  r
end
create() click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 24
def create
  if server_identity.nil?
    ret = nil
    begin
      self.app.ngears += 1
      self.container = StickShift::ApplicationContainerProxy.find_available(self.node_profile)
      self.server_identity = self.container.id
      self.uid = self.container.reserve_uid
      self.app.group_instance_map[self.group_instance_name].gears << self
      self.app.save
      ret = self.container.create(app,self)
      self.app.track_usage(self, UsageRecord::EVENTS[:begin]) if ret.exitcode == 0
    rescue Exception => e
      Rails.logger.debug e.message
      Rails.logger.debug e.backtrace.join("\n")
      ret = ResultIO.new
      ret.errorIO << e.message
      ret.exitcode = 5
    end

    ## recovery action if creation failed above
    if ret.exitcode != 0
      begin
        get_proxy.destroy(self.app, self)
      rescue Exception => e
      end
      self.app.ngears -= 1
      self.app.group_instance_map[self.group_instance_name].gears.delete(self)
      self.app.save
      raise StickShift::NodeException.new("Unable to create gear on node", 1, ret)
    end
    return ret
  end
end
deconfigure(comp_inst, force=false) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 102
def deconfigure(comp_inst, force=false)
  r = ResultIO.new
  return r unless self.configured_components.include?(comp_inst.name) or force
  r.append get_proxy.deconfigure_cartridge(app,self,comp_inst.parent_cart_name)
  self.configured_components.delete(comp_inst.name)
  r
end
destroy() click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 59
def destroy
  ret = get_proxy.destroy(app,self)
  if ret.exitcode == 0
    self.app.destroyed_gears = [] unless self.app.destroyed_gears
    self.app.destroyed_gears << @uuid
    app.process_cartridge_commands(ret)
    track_destroy_usage
    self.app.ngears -= 1
    self.app.group_instance_map[self.group_instance_name].gears.delete(self)
    self.app.save
  else
    raise StickShift::NodeException.new("Unable to destroy gear on node", 1, ret)
  end
  return ret
end
env_var_job_add(key, value) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 203
def env_var_job_add(key, value)
  job = get_proxy.get_env_var_add_job(app, self, key, value)
  job
end
env_var_job_remove(key) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 218
def env_var_job_remove(key)
  job = get_proxy.get_env_var_remove_job(app, self, key)
  job
end
execute_connector(comp_inst, connector_name, input_args) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 110
def execute_connector(comp_inst, connector_name, input_args)
  get_proxy.execute_connector(app, self, comp_inst.parent_cart_name, connector_name, input_args)
end
expose_port(comp_inst) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 150
def expose_port(comp_inst)
  get_proxy.expose_port(app,self,comp_inst.parent_cart_name)
end
force_destroy() click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 75
def force_destroy
  begin
    begin
      get_proxy.destroy(app,self)
    rescue Exception => e
    end
    self.app.destroyed_gears = [] unless self.app.destroyed_gears
    self.app.destroyed_gears << @uuid
    track_destroy_usage
  ensure
    self.app.ngears -= 1
    self.app.group_instance_map[self.group_instance_name].gears.delete(self)
    self.app.save
  end
end
force_stop(comp_inst) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 130
def force_stop(comp_inst)
  get_proxy.force_stop(app,self,comp_inst.parent_cart_name)    
end
get_execute_connector_job(cart, connector_name, input_args) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 114
def get_execute_connector_job(cart, connector_name, input_args)
  get_proxy.get_execute_connector_job(app, self, cart, connector_name, input_args)
end
get_proxy() click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 17
def get_proxy
  if self.container.nil? and !@server_identity.nil?
    self.container = StickShift::ApplicationContainerProxy.instance(@server_identity)
  end    
  return self.container
end
group_instance() click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 252
def group_instance
  self.app.group_instance_map[self.group_instance_name]
end
prepare_namespace_update(dns_service, new_ns, old_ns) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 256
def prepare_namespace_update(dns_service, new_ns, old_ns)
  results = []
  gi = self.app.group_instance_map[self.group_instance_name]
  contains_proxy = false
  contains_framework = false    
  contains_mysql = false
  result_io = ResultIO.new
  
  gi.component_instances.each do |cname|
    ci = self.app.comp_instance_map[cname]
    contains_proxy = true if ci.parent_cart_name == self.app.proxy_cartridge
    contains_framework = true if ci.parent_cart_name == self.app.framework  
    contains_mysql = true if ci.parent_cart_name == "mysql-5.1"  
  end

  if contains_proxy || !self.app.scalable
    #proxy gear gets public dns
    register_application(dns_service, old_ns, new_ns, self.app.name)
  else
    #non-proxy gear gets gear specific dns
    register_application(dns_service, old_ns, new_ns, self.name)
  end

  if contains_framework
    result_io.append call_update_namespace_hook(self.app.framework, new_ns, old_ns)
  else
  #  elseif contains_mysql
     #  Yikes: contains_mysql ... making it more generic.
     #  We could also probably always call update-namespace on the abstract
     #  cartridge directly instead of app.framework above since all
     #  cartridges symlink it from abstract anyway.
    result_io.append call_update_namespace_hook("abstract", new_ns, old_ns)
  end
  result_io
end
reload(comp_inst) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 134
def reload(comp_inst)
  get_proxy.reload(app,self,comp_inst.parent_cart_name)    
end
remove_alias(server_alias) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 178
def remove_alias(server_alias)
  if app.gear.uuid == self.uuid
    get_proxy.remove_alias(app, self, app.framework, server_alias)
  else
    ResultIO.new
  end
end
remove_authorized_ssh_key(ssh_key, comment=nil) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 190
def remove_authorized_ssh_key(ssh_key, comment=nil)
  get_proxy.remove_authorized_ssh_key(app, self, ssh_key, comment)
end
remove_broker_auth_key() click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 241
def remove_broker_auth_key
  get_proxy.remove_broker_auth_key(app, self)    
end
remove_env_var(key) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 233
def remove_env_var(key)
  get_proxy.remove_env_var(app, self, key)
end
restart(comp_inst) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 126
def restart(comp_inst)
  get_proxy.restart(app,self,comp_inst.parent_cart_name)    
end
show_port(comp_inst) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 158
def show_port(comp_inst)
  get_proxy.show_port(app,self,comp_inst.parent_cart_name)
end
show_state() click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 142
def show_state()
  get_proxy.show_state(app, self)
end
ssh_key_job_add(ssh_key, ssh_key_type, ssh_key_comment) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 208
def ssh_key_job_add(ssh_key, ssh_key_type, ssh_key_comment)
  job = get_proxy.get_add_authorized_ssh_key_job(app, self, ssh_key, ssh_key_type, ssh_key_comment)
  job
end
ssh_key_job_remove(ssh_key, ssh_key_comment) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 223
def ssh_key_job_remove(ssh_key, ssh_key_comment)
  job = get_proxy.get_remove_authorized_ssh_key_job(app, self, ssh_key, ssh_key_comment)
  job
end
start(comp_inst) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 118
def start(comp_inst)
  get_proxy.start(app,self,comp_inst.parent_cart_name)
end
status(comp_inst) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 138
def status(comp_inst)
  get_proxy.status(app,self,comp_inst.parent_cart_name)    
end
stop(comp_inst) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 122
def stop(comp_inst)
  get_proxy.stop(app,self,comp_inst.parent_cart_name)    
end
system_messages(comp_inst) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 166
def system_messages(comp_inst)
  get_proxy.system_messages(app, self, comp_inst.parent_cart_name)
end
threaddump(comp_inst) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 162
def threaddump(comp_inst)
  get_proxy.threaddump(app,self,comp_inst.parent_cart_name)
end
tidy(comp_inst) click to toggle source
# File lib/stickshift-controller/app/models/gear.rb, line 146
def tidy(comp_inst)
  get_proxy.tidy(app,self,comp_inst.parent_cart_name)    
end