Ravn::Tactical::Operation::

SetMission class

Ravn-tactical Operation to set the current mission.

Public Class Methods

param_validator()

Return a block for Roda::RodaPlugins::TypecastParams validation for this operation.

   # File lib/ravn/tactical/operation/set_mission.rb
16 def self::param_validator
17     return ->( params ) do
18         params.convert!( 'mission' ) do |m|
19             m.uuid!( 'id' )
20             m.nonempty_str!( 'name' )
21             m.pos_int!( 'format_version' )
22             m.nonempty_str!( 'version' )
23 
24             # :TODO: Nested untainting
25             m.Hash!( 'callsigns' )
26             m.Hash!( 'segments' )
27             m.Hash!( 'bolts' )
28             m.array!( :Hash, 'pois' )
29 
30             m.pos_int!( 'timestamp' )
31         end
32     end
33 end

Public Instance Methods

run( * )

Attempt to set the mission on the target node.

   # File lib/ravn/tactical/operation/set_mission.rb
37 def run( * )
38     mission_data = self.config[:mission]
39     mission_data = symbolify_keys( mission_data )
40     mission = Ravn::Tactical::Mission.new( **mission_data )
41 
42     self.log.warn "Setting the current mission to %s (%s)" % [ mission.name, mission.id ]
43 
44     task = self.set_mission( mission )
45     rv = Ravn::Executor.exec( task )
46 
47     if rv[:response] == :ok
48         self.log.info "Restarting the BDE succeeded."
49     else
50         errmsg = "Failed to restart the BDE: %s: %s" % rv.values_at( :response, :output )
51         self.log.error( errmsg )
52         raise errmsg
53     end
54 end
set_mission( mission )

Write the given mission to disk and make it the current one. Returns which Executor task needs to be run to make it take effect.

   # File lib/ravn/tactical/operation/set_mission.rb
59 def set_mission( mission )
60 
61     # If it's not the current mission, archive the current one and make this one
62     # current
63     if mission.current?
64         self.log.debug "  this is an update to the current mission; updating it."
65         mission.write( true )
66         return :restart_helios
67     else
68         if (previous_mission = Ravn::Tactical::Mission.current)
69             self.log.info "  archiving the previous mission: %s (%s)" %
70                 [ previous_mission.name, previous_mission.id ]
71             previous_mission.archive
72         else
73             self.log.debug "  no previous mission"
74         end
75 
76         mission.make_current
77 
78         return :reset_helios
79     end
80 end