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.


1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
# File 'lib/wakame/service.rb', line 1077

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



1062
1063
1064
1065
1066
1067
1068
# File 'lib/wakame/service.rb', line 1062

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

.name(id) ⇒ Object



1070
1071
1072
# File 'lib/wakame/service.rb', line 1070

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

Instance Method Details

#basedirObject



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

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

#idObject



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

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

#on_child_changed(service_instance, action) ⇒ Object



1112
1113
# File 'lib/wakame/service.rb', line 1112

def on_child_changed(service_instance, action)
end

#on_enter_agent(service_instance, action) ⇒ Object



1117
1118
# File 'lib/wakame/service.rb', line 1117

def on_enter_agent(service_instance, action)
end

#on_parent_changed(service_instance, action) ⇒ Object



1114
1115
# File 'lib/wakame/service.rb', line 1114

def on_parent_changed(service_instance, action)
end

#on_quit_agent(service_instance, action) ⇒ Object



1119
1120
# File 'lib/wakame/service.rb', line 1119

def on_quit_agent(service_instance, action)
end

#reload(service_instance, action) ⇒ Object



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

def reload(service_instance, action); end

#render_config(template) ⇒ Object



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

def render_config(template)
end

#start(service_instance, action) ⇒ Object



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

def start(service_instance, action); end

#stop(service_instance, action) ⇒ Object



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

def stop(service_instance, action); end