Class: Wakame::Service::Resource

Inherits:
Wakame::StatusDB::Model show all
Defined in:
lib/wakame/service.rb

Constant Summary

Constants included from AttributeHelper

AttributeHelper::CLASS_TYPE_KEY, AttributeHelper::CONVERT_CLASSES, AttributeHelper::PRIMITIVE_CLASSES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Wakame::StatusDB::Model

#delete, #dirty?, #new_record?, #on_after_delete, #on_after_load, #on_before_delete, #on_before_load, #save

Methods included from AttributeHelper

#dump_attrs, #retrieve_attr_attribute

Class Method Details

.id(name = nil) ⇒ Object

Returns the hashed resource class name representation.

Resource.id() is as same as sha1.digest('Wakame::Service::Resource')
With an argument, tries to get the class name and take digest.


1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
# File 'lib/wakame/service.rb', line 1067

def self.id(name=nil)
  res_class_name = case name
                   when nil
                     self.to_s
                   when String
                     raise "Invalid string as ruby constant: #{name}" unless name =~ /^(:-\:\:)?[A-Z]/
                     name.to_s
                   when Class
                     raise "Can't convert the argument: type of #{name.class}" unless name <= self
                     name.to_s
                   when Resource
                     name.class.to_s
                   else
                     raise "Can't convert the argument: type of #{name.class}"
                   end

  require 'digest/sha1'
  Digest::SHA1.hexdigest(res_class_name)
end

.inherited(klass) ⇒ Object



1052
1053
1054
1055
1056
1057
1058
# File 'lib/wakame/service.rb', line 1052

def self.inherited(klass)
  klass.class_eval {
    def self.id
      Resource.id(self)
    end
  }
end

.name(id) ⇒ Object



1060
1061
1062
# File 'lib/wakame/service.rb', line 1060

def self.name(id)
  find(id).class.to_s
end

Instance Method Details

#basedirObject



1091
1092
1093
# File 'lib/wakame/service.rb', line 1091

def basedir
  File.join(Wakame.config.root_path, 'cluster', 'resources', Util.snake_case(self.class))
end

#idObject



1087
1088
1089
# File 'lib/wakame/service.rb', line 1087

def id
  Resource.id(self.class.to_s)
end

#on_child_changed(service_instance, action) ⇒ Object



1102
1103
# File 'lib/wakame/service.rb', line 1102

def on_child_changed(service_instance, action)
end

#on_enter_agent(service_instance, action) ⇒ Object



1107
1108
# File 'lib/wakame/service.rb', line 1107

def on_enter_agent(service_instance, action)
end

#on_parent_changed(service_instance, action) ⇒ Object



1104
1105
# File 'lib/wakame/service.rb', line 1104

def on_parent_changed(service_instance, action)
end

#on_quit_agent(service_instance, action) ⇒ Object



1109
1110
# File 'lib/wakame/service.rb', line 1109

def on_quit_agent(service_instance, action)
end

#reload(service_instance, action) ⇒ Object



1097
# File 'lib/wakame/service.rb', line 1097

def reload(service_instance, action); end

#render_config(template) ⇒ Object



1099
1100
# File 'lib/wakame/service.rb', line 1099

def render_config(template)
end

#start(service_instance, action) ⇒ Object



1095
# File 'lib/wakame/service.rb', line 1095

def start(service_instance, action); end

#stop(service_instance, action) ⇒ Object



1096
# File 'lib/wakame/service.rb', line 1096

def stop(service_instance, action); end