Class: Bosh::Agent::RemoteException

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh_agent/remote_exception.rb

Overview

Helper class to pass around and fromat exceptions in the agent to the director

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, backtrace = nil, blob = nil) ⇒ RemoteException



8
9
10
11
12
# File 'lib/bosh_agent/remote_exception.rb', line 8

def initialize(message, backtrace=nil, blob=nil)
  @message = message
  @backtrace = backtrace.nil? ? caller : backtrace
  @blob = blob
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



6
7
8
# File 'lib/bosh_agent/remote_exception.rb', line 6

def backtrace
  @backtrace
end

#blobObject (readonly)

Returns the value of attribute blob.



6
7
8
# File 'lib/bosh_agent/remote_exception.rb', line 6

def blob
  @blob
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/bosh_agent/remote_exception.rb', line 6

def message
  @message
end

Class Method Details

.from(exception) ⇒ Bosh::Agent::RemoteException

Helper class method that creates a [Bosh::Agent::RemoteException] from an [Exception]



53
54
55
56
57
58
59
# File 'lib/bosh_agent/remote_exception.rb', line 53

def self.from(exception)
  blob = nil
  if exception.instance_of?(Bosh::Agent::MessageHandlerError)
    blob = exception.blob
  end
  self.new(exception.message, exception.backtrace, blob)
end

Instance Method Details

#loggerObject



45
46
47
# File 'lib/bosh_agent/remote_exception.rb', line 45

def logger
  Bosh::Agent::Config.logger
end

#store_blobString

Stores the blob in the configured blobstore

string which can be displayed instead of the blob



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bosh_agent/remote_exception.rb', line 18

def store_blob
  bsc_options  = Bosh::Agent::Config.blobstore_options
  bsc_provider = Bosh::Agent::Config.blobstore_provider

  blobstore = Bosh::Blobstore::Client.create(bsc_provider, bsc_options)

  logger.info("Uploading blob for '#{@message}' to blobstore")

  blobstore_id = nil
  blobstore_id = blobstore.create(@blob)

  blobstore_id
rescue Bosh::Blobstore::BlobstoreError => e
  logger.warn("unable to upload blob for '#{@message}'")
  "error: unable to upload blob to blobstore: #{e.message}"
end

#to_hashHash

Returns a hash of the [RemoteException] suitable to convert to json



38
39
40
41
42
43
# File 'lib/bosh_agent/remote_exception.rb', line 38

def to_hash
  hash = {:message => @message}
  hash[:backtrace] = @backtrace
  hash[:blobstore_id] = store_blob if @blob
  {:exception => hash}
end