Class: OsCtld::Commands::Self::HealthCheck

Inherits:
Base
  • Object
show all
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

Methods inherited from Base

#base_execute, #call_cmd, #call_cmd!, 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

#executeObject



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
# File 'lib/osctld/commands/self/health_check.rb', line 7

def execute
  ret = []
  errors = []

  Daemon.get.assets.each do |asset|
    next if %i(valid unknown).include?(asset.state)

    errors << {
      type: asset.type,
      path: asset.path,
      opts: asset.opts,
      errors: asset.errors,
    }
  end

  unless errors.empty?
    ret << {
      pool: nil,
      type: 'osctld',
      id: nil,
      assets: errors,
    }
  end

  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|
        errors = []

        ent.assets.each do |asset|
          next if %i(valid unknown).include?(asset.state)

          errors << {
            type: asset.type,
            path: asset.path,
            opts: asset.opts,
            errors: asset.errors,
          }
        end

        next if errors.empty?

        ret << {
          pool: ent.pool.name,
          type: ent.class.name.split('::').last.downcase,
          id: ent.id,
          assets: errors,
        }
      end
    end
  end

  ok(ret)
end

#poolsObject (protected)



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/osctld/commands/self/health_check.rb', line 67

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