Class: Oxidized::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/oxidized/core.rb

Defined Under Namespace

Classes: NoNodesFound

Instance Method Summary collapse

Constructor Details

#initialize(_args) ⇒ Core

Returns a new instance of Core.

Raises:



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
# File 'lib/oxidized/core.rb', line 11

def initialize(_args)
  Oxidized.mgr = Manager.new
  Oxidized.hooks = HookManager.from_config(Oxidized.config)
  nodes = Nodes.new
  raise NoNodesFound, 'source returns no usable nodes' if nodes.empty?

  @worker = Worker.new nodes
  @need_reload = false

  # If we receive a SIGHUP, queue a reload of the state
  reload_proc = proc do
    @need_reload = true
  end
  Signals.register_signal('HUP', reload_proc)

  # Load extensions, currently only oxidized-web
  # We have different namespaces for oxidized-web, which needs to be
  # adressed if we need a generic way to load extensions:
  # - gem: oxidized-web
  # - module: Oxidized::API
  # - path: oxidized/web
  # - entrypoint: Oxidized::API::Web.new(nodes, configuration)

  # Initialize oxidized-web if requested
  if Oxidized.config.has_key? 'rest'
    Oxidized.logger.warn(
      'configuration: "rest" is deprecated. Migrate to ' \
      '"extensions.oxidized-web" and remove "rest" from the configuration'
    )
    configuration = Oxidized.config.rest
  elsif Oxidized.config.extensions['oxidized-web'].load?
    # This comment stops rubocop complaining about Style/IfUnlessModifier
    configuration = Oxidized.config.extensions['oxidized-web']
  end

  if configuration
    begin
      require 'oxidized/web'
    rescue LoadError
      raise OxidizedError,
            'oxidized-web not found: install it or disable it by ' \
            'removing "rest" and "extensions.oxidized-web" from your ' \
            'configuration'
    end
    @rest = API::Web.new nodes, configuration
    @rest.run
  end
  run
end