Ravn::Tactical::Operation::
DownloadMissionArchive
class
Ravn-tactical Operation to download mission archive artifacts from a node.
Override the constructor to mandate a mission_id
.
25 def initialize( mission_id: )
26 super
27 end
Return a block for Roda::RodaPlugins::TypecastParams validation for this operation.
17 def self::param_validator
18 return ->( params ) do
19 params.uuid!( 'mission_id' )
20 end
21 end
after_run( node, response )
Post-run hook – move the archive into the right spot on the Control.
90 def after_run( node, response )
91 if response.status == 200
92 self.log.info "Reading archive from response: %d bytes" % [ response.body.bytesize ]
93 self.extract_archive( node, response )
94
95 self.mission.finish_archive if self.mission.all_nodes_archived?
96
97 return true
98 else
99 self.log.error "Request to download archive for %s failed: %d" %
100 [ node.device_id, response.status ]
101
102 return false
103 end
104 end
Streaming callback – called when the file is done being sent on the remote node.
82 def done_sending
83 self.log.info "Done streaming tar archive. Cleaning up the old archive file."
84 arch_directory = self.mission.archive_directory_path
85 arch_directory.rmtree
86 end
Fetch the mission associated with this operation by the :mission_id parameter.
39 def mission
40 return @mission ||= begin
41 Ravn::Tactical::Mission.fetch( self.mission_id ) or
42 raise "no such mission %p" % [ mission_id ]
43 end
44 end
Return the configured mission ID for this operation. Raises an exception if no valid mission ID parameter was specified.
32 def mission_id
33 return self.config[ :mission_id ]
34 end
Generate the tarball containing mission archive files and return it.
48 def run( context, request )
49 mission = self.mission
50
51 raise "Mission %s is not archived!" % [ mission.id ] unless mission.archived?
52 self.log.info "Downloading archive for mission %s." % [ mission.id ]
53 self.stream_files( mission, context )
54 end
stream_files( mission, context )
Stream a tar archive of the given mission
‘s archived files via the given context
.
58 def stream_files( mission, context )
59 files = mission.device_archive_files
60
61 self.log.info "Streaming tar archive with %d file/s" % [ files.size ]
62 context.response[ 'Content-type' ] = 'archive/tar'
63 context.stream( callback: self.method(:done_sending) ) do |raw_out|
64 self.log.debug "Starting archive for %p" % [ raw_out ]
65 out = Archive::Tar::Minitar::Output.new( raw_out )
66
67 Dir.chdir( mission.device_archive_directory_path ) do
68 files.each do |file|
69 file = file.relative_path_from( mission.device_archive_directory_path )
70 self.log.debug " adding %s" % [ file ]
71 Archive::Tar::Minitar.pack_file( file.to_s, out ) do |action, fn, stats|
72 self.log.debug "%s: %s %p" % [ action, fn, stats ]
73 end
74 end
75 end
76 end
77 end