Class: Nodectl::Service
- Inherits:
-
Object
- Object
- Nodectl::Service
- Defined in:
- lib/nodectl/service.rb
Instance Attribute Summary collapse
-
#manifest ⇒ Object
readonly
Returns the value of attribute manifest.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #deps ⇒ Object
- #exist? ⇒ Boolean
-
#initialize(manifest) ⇒ Service
constructor
A new instance of Service.
- #inspect ⇒ Object
- #instances ⇒ Object
-
#logs ⇒ Object
TODO: Refactor this method (and may be whole log-related classes): service class should not know about log internals and streaming urls.
- #name ⇒ Object
- #path ⇒ Object
- #recipe ⇒ Object
- #recipe_binding ⇒ Object
- #recipe_name ⇒ Object
- #repo ⇒ Object
- #source_path ⇒ Object
- #status ⇒ Object
- #supported_actions ⇒ Object
- #supported_slots ⇒ Object
Constructor Details
Instance Attribute Details
#manifest ⇒ Object (readonly)
Returns the value of attribute manifest.
4 5 6 |
# File 'lib/nodectl/service.rb', line 4 def manifest @manifest end |
Class Method Details
Instance Method Details
#as_json ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/nodectl/service.rb', line 95 def as_json json = { "id" => name, "status" => status, "instance_ids" => instances.map(&:pid), "recipe_name" => recipe_name, "supported_actions" => supported_actions, "supported_slots" => supported_slots, "logs" => logs, "params" => recipe.params } binding = recipe_binding if status == :installed && binding.supported_slots.include?(:version) version = binding.run_slot(:version) json["version_id"] = version["id"] json["version_timestamp"] = version["timestamp"] json["version_message"] = version["message"] end json end |
#deps ⇒ Object
16 17 18 19 20 |
# File 'lib/nodectl/service.rb', line 16 def deps (@manifest["deps"] || []).map do |service_name| self.class.find!(service_name) end end |
#exist? ⇒ Boolean
34 35 36 37 |
# File 'lib/nodectl/service.rb', line 34 def exist? # TODO: think of a better criterion for existing installation source_path.exist? end |
#inspect ⇒ Object
26 27 28 |
# File 'lib/nodectl/service.rb', line 26 def inspect "#<#{self.class} name:#{name}>" end |
#instances ⇒ Object
51 52 53 |
# File 'lib/nodectl/service.rb', line 51 def instances Nodectl::Instance.all.select { |i| i.service == self } end |
#logs ⇒ Object
TODO: Refactor this method (and may be whole log-related classes):
service class should not know about log internals and streaming
urls
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/nodectl/service.rb', line 76 def logs unless @logs if recipe binding = recipe_binding @logs = recipe.logs.map do |log| { "id" => "#{name}-#{log}", "name" => log, "path" => "/logs/#{name}/#{log}", } end else @logs = [] end end @logs end |
#name ⇒ Object
12 |
# File 'lib/nodectl/service.rb', line 12 def name; @manifest["name"]; end |
#path ⇒ Object
13 |
# File 'lib/nodectl/service.rb', line 13 def path; @manifest["path"]; end |
#recipe ⇒ Object
43 44 45 |
# File 'lib/nodectl/service.rb', line 43 def recipe @recipe ||= Nodectl::Recipe.find(recipe_name) end |
#recipe_binding ⇒ Object
47 48 49 |
# File 'lib/nodectl/service.rb', line 47 def recipe_binding recipe.bind(self) if recipe end |
#recipe_name ⇒ Object
22 23 24 |
# File 'lib/nodectl/service.rb', line 22 def recipe_name @manifest["recipe"] end |
#repo ⇒ Object
14 |
# File 'lib/nodectl/service.rb', line 14 def repo; @manifest["repo"]; end |
#source_path ⇒ Object
30 31 32 |
# File 'lib/nodectl/service.rb', line 30 def source_path Nodectl.[:source_dir].join(path) end |
#status ⇒ Object
39 40 41 |
# File 'lib/nodectl/service.rb', line 39 def status exist? ? :installed : :available end |
#supported_actions ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/nodectl/service.rb', line 55 def supported_actions binding = recipe_binding if binding binding.supported_actions else [] end end |
#supported_slots ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/nodectl/service.rb', line 64 def supported_slots binding = recipe_binding if binding binding.supported_slots else [] end end |