Class: Bosh::Agent::Message::FetchLogs

Inherits:
Base show all
Defined in:
lib/bosh_agent/message/logs.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#base_dir, #handler_error, #logger, #logs_dir, #settings, #store_migration_target, #store_path

Constructor Details

#initialize(args) ⇒ FetchLogs

Returns a new instance of FetchLogs.



17
18
19
20
21
22
23
# File 'lib/bosh_agent/message/logs.rb', line 17

def initialize(args)
  @log_type = args[0]
  @filters = Set.new(args[1])
  @state = Bosh::Agent::Config.state.to_hash
  @matcher = default_matcher
  @aggregator = Bosh::Agent::FileAggregator.new
end

Instance Attribute Details

#aggregatorObject

Returns the value of attribute aggregator.



15
16
17
# File 'lib/bosh_agent/message/logs.rb', line 15

def aggregator
  @aggregator
end

#matcherObject

Returns the value of attribute matcher.



15
16
17
# File 'lib/bosh_agent/message/logs.rb', line 15

def matcher
  @matcher
end

Class Method Details

.long_running?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/bosh_agent/message/logs.rb', line 7

def self.long_running?
  true
end

.process(args) ⇒ Object



11
12
13
# File 'lib/bosh_agent/message/logs.rb', line 11

def self.process(args)
  new(args).process
end

Instance Method Details

#processObject



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/bosh_agent/message/logs.rb', line 25

def process
  handler_error("matcher for #{@log_type} logs not found") unless @matcher
  handler_error("aggregator for #{@log_type} logs not found") unless @aggregator

  if @filters && @filters.size > 0
    @matcher.globs = filter_globs
  end

  aggregator.matcher = @matcher

  tarball_path = aggregator.generate_tarball
  tarball_size = File.size(tarball_path)

  logger.info("Generated log tarball: #{tarball_path} (size: #{tarball_size})")
  blobstore_id = upload_tarball(tarball_path)

  { "blobstore_id" => blobstore_id }

rescue Bosh::Agent::FileAggregator::DirectoryNotFound => e
  handler_error("unable to find #{@log_type} logs directory")
rescue Bosh::Agent::FileAggregator::Error => e
  handler_error("error aggregating logs: #{e}")
ensure
  aggregator.cleanup
end