Module: PuppetDebugServer

Defined in:
lib/puppet_debugserver.rb,
lib/puppet-debugserver/hooks.rb,
lib/puppet-debugserver/message_handler.rb,
lib/puppet-debugserver/puppet_debug_session.rb,
lib/puppet-debugserver/debug_session/break_points.rb,
lib/puppet-debugserver/debug_session/flow_control.rb,
lib/puppet-debugserver/debug_session/hook_handlers.rb,
lib/puppet-debugserver/debug_session/puppet_session_state.rb,
lib/puppet-debugserver/debug_session/puppet_session_run_mode.rb

Defined Under Namespace

Modules: DebugSession Classes: CommandLineParser, Hooks, LogMessageAggregator, MessageHandler, PuppetDebugSession, SourcePosition

Class Method Summary collapse

Class Method Details

.execute(rpc_thread) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/puppet_debugserver.rb', line 148

def self.execute(rpc_thread)
  debug_session = PuppetDebugServer::PuppetDebugSession.instance
  debug_session.initialize_session

  # TODO: Can I use a real mutex here? might be hard with the rpc_thread.alive? call
  sleep(0.5) while !debug_session.flow_control.flag?(:start_puppet) && rpc_thread.alive? && !debug_session.flow_control.terminate?
  return unless rpc_thread.alive? || debug_session.flow_control.terminate?

  debug_session.run_puppet

  return unless rpc_thread.alive?

  debug_session.close
  rpc_thread.join
end

.init_puppet(options) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/puppet_debugserver.rb', line 106

def self.init_puppet(options)
  PuppetEditorServices.init_logging(options)
  log_message(:info, "Debug Server is v#{PuppetDebugServer.version}")
  log_message(:debug, 'Loading gems...')
  require_gems(options)
  log_message(:info, "Using OpenVox gem v#{OpenVoxRuntime.gem_version} (Puppet API v#{::Puppet.version})")

  raise("Detected OpenVox #{Puppet.version} however the Debug Server requires OpenVox 8.0 and above") if Gem::Version.new(Puppet.version) < Gem::Version.new('8.0.0')

  true
end

.log_message(severity, message) ⇒ Object



102
103
104
# File 'lib/puppet_debugserver.rb', line 102

def self.log_message(severity, message)
  PuppetEditorServices.log_message(severity, message)
end

.require_gems(options) ⇒ Object



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
# File 'lib/puppet_debugserver.rb', line 15

def self.require_gems(options)
  original_verbose = $VERBOSE
  $VERBOSE = nil

  # Use a specific OpenVox Gem version if requested.
  if options[:puppet_version].nil?
    OpenVoxRuntime.activate!
  else
    available_openvox_gems = OpenVoxRuntime.available_versions
    if available_openvox_gems.include?(options[:puppet_version])
      OpenVoxRuntime.activate!(options[:puppet_version])
    else
      log_message(:warn, "Unable to use OpenVox version #{options[:puppet_version]}, as only the following versions are available [#{available_openvox_gems.join(', ')}]")
      OpenVoxRuntime.activate!
    end
  end

  %w[
    message_handler
    hooks
    puppet_debug_session
    debug_session/break_points
    debug_session/hook_handlers
    debug_session/flow_control
    debug_session/puppet_session_run_mode
    debug_session/puppet_session_state
    puppet_monkey_patches
  ].each do |lib|
    require "puppet-debugserver/#{lib}"
  rescue LoadError
    require File.expand_path(File.join(File.dirname(__FILE__), 'puppet-debugserver', lib))
  end
ensure
  $VERBOSE = original_verbose
end

.rpc_server_async(options) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/puppet_debugserver.rb', line 118

def self.rpc_server_async(options)
  log_message(:info, 'Starting RPC Server (Async)...')

  Thread.new do
    Thread.current.abort_on_exception = true

    require 'puppet_editor_services/protocol/debug_adapter'
    require 'puppet_editor_services/server/tcp'

    server_options = options.dup
    protocol_options = { class: PuppetEditorServices::Protocol::DebugAdapter }.merge(options)
    handler_options = { class: PuppetDebugServer::MessageHandler }.merge(options)
    # TODO: Add max threads?
    server_options[:servicename] = 'DEBUG SERVER'

    log_message(:debug, 'Using TCP Server')
    server = ::PuppetEditorServices::Server::Tcp.new(server_options, protocol_options, handler_options)
    trap('INT') do
      server.stop_services(true)
      PuppetDebugServer::PuppetDebugSession.instance.flow_control.assert_flag(:terminate)
    end
    server.start

    log_message(:info, 'Debug Server exited.')
    # Forcibly kill the Debug Session
    log_message(:info, 'Signalling Debug Session to terminate with extreme prejudice')
    PuppetDebugServer::PuppetDebugSession.instance.force_terminate
  end
end

.versionObject



11
12
13
# File 'lib/puppet_debugserver.rb', line 11

def self.version
  PuppetEditorServices.version
end