Class: OsCtld::Commands::Self::HealthCheck
- Defined in:
- lib/osctld/commands/self/health_check.rb
Instance Attribute Summary
Attributes inherited from Base
#client, #client_handler, #id, #opts
Instance Method Summary collapse
- #execute ⇒ Object
- #pools ⇒ Object protected
Methods inherited from Base
#base_execute, #call_cmd, #call_cmd!, #error, #error!, handle, #handled, #indirect?, #initialize, #manipulate, #manipulation_holder, #ok, #progress, #request_stop, run, run!
Constructor Details
This class inherits a constructor from OsCtld::Commands::Base
Instance Method Details
#execute ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/osctld/commands/self/health_check.rb', line 7 def execute validator = Assets::Validator.new # Collect all assets daemon_assets = Daemon.get.assets validator.add_assets(daemon_assets) pool_entity_assets = {} pools.each do |pool| filter = ->(v) { v.pool == pool } [DB::Pools, DB::Repositories, DB::Users, DB::Groups, DB::Containers].each do |klass| entities = klass.get.select(&filter) entities.each do |ent| ent_assets = ent.assets pool_entity_assets[pool.name] ||= {} pool_entity_assets[pool.name][ent] = ent_assets validator.add_assets(ent_assets) end end end # Run validation validator.validate # Collect errors and return them to the client ret = [] daemon_errors = [] daemon_assets.each do |asset| next if %i[valid unknown].include?(asset.state) daemon_errors << { type: asset.type, path: asset.path, opts: asset.opts, errors: asset.errors } end unless daemon_errors.empty? ret << { pool: nil, type: 'osctld', id: nil, assets: daemon_errors } end pool_entity_assets.each_value do |entities| entities.each do |ent, ent_assets| ent_errors = [] ent_assets.each do |asset| next if %i[valid unknown].include?(asset.state) ent_errors << { type: asset.type, path: asset.path, opts: asset.opts, errors: asset.errors } end next if ent_errors.empty? ret << { pool: ent.pool.name, type: ent.class.name.split('::').last.downcase, id: ent.id, assets: ent_errors } end end ok(ret) end |
#pools ⇒ Object (protected)
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/osctld/commands/self/health_check.rb', line 91 def pools if opts[:pools] opts[:pools].map do |name| DB::Pools.find(name) || (raise CommandFailed, "pool #{name} not found") end elsif opts[:all] DB::Pools.get else [] end end |