Class: ScoutAgent::Assignment

Inherits:
Object
  • Object
show all
Includes:
Tracked
Defined in:
lib/scout_agent/assignment.rb,
lib/scout_agent/assignment/stop.rb,
lib/scout_agent/assignment/queue.rb,
lib/scout_agent/assignment/reset.rb,
lib/scout_agent/assignment/start.rb,
lib/scout_agent/assignment/status.rb,
lib/scout_agent/assignment/update.rb,
lib/scout_agent/assignment/identify.rb,
lib/scout_agent/assignment/snapshot.rb,
lib/scout_agent/assignment/upload_log.rb,
lib/scout_agent/assignment/configuration.rb,
lib/scout_agent/assignment/test.rb

Overview

An Assignment is a command that can be given to the agent on the command-line. This object encapsulates the series of steps needed to invoke a command and subclasses supply the specific behavior.

Defined Under Namespace

Classes: Configuration, Identify, Queue, Reset, Snapshot, Start, Status, Stop, Test, Update, UploadLog

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Tracked

#clear_status, #force_status_database_reload, #status, #status_database, #status_log

Constructor Details

#initialize(switches, other_args) ⇒ Assignment

Builds a new Assignment with the passed switches and other_args. The Dispatcher usess this to prepare a command for running.



61
62
63
64
65
66
# File 'lib/scout_agent/assignment.rb', line 61

def initialize(switches, other_args)
  @switches   = switches
  @other_args = other_args
  @user       = nil
  @group      = nil
end

Instance Attribute Details

#groupObject (readonly)

The group to operate as, if selected. See choose_group() for details.



77
78
79
# File 'lib/scout_agent/assignment.rb', line 77

def group
  @group
end

#other_argsObject (readonly)

Any non-switch arguments passed to the command.



73
74
75
# File 'lib/scout_agent/assignment.rb', line 73

def other_args
  @other_args
end

#switchesObject (readonly)

The command-line switches passed to the command.



71
72
73
# File 'lib/scout_agent/assignment.rb', line 71

def switches
  @switches
end

#userObject (readonly)

The user to operate as, if selected. See choose_user() for details.



75
76
77
# File 'lib/scout_agent/assignment.rb', line 75

def user
  @user
end

Class Method Details

.choose_group(setting = nil) ⇒ Object

If setting is true, a group to operate as will be selected based on the configuration. Note that a group is just selected and it’s up to the command to make use of it. That group is available to commands via the group() method.



53
54
55
# File 'lib/scout_agent/assignment.rb', line 53

def self.choose_group(setting = nil)
  get_or_set(:choose_group, false, setting)
end

.choose_user(setting = nil) ⇒ Object

If setting is true, a user to operate as will be selected based on the configuration. Note that a user is just selected and it’s up to the command to make use of it. That user is available to commands via the user() method.



43
44
45
# File 'lib/scout_agent/assignment.rb', line 43

def self.choose_user(setting = nil)
  get_or_set(:choose_user, false, setting)
end

.plan(setting = nil) ⇒ Object

If the setting of this attribute includes the word “file”, the configuration file will be loaded before the command is invoked. Similarly, the word “switches” will cause the configuration to be updated using the provided command-line switches. The default setting is :file_and_switches.



33
34
35
# File 'lib/scout_agent/assignment.rb', line 33

def self.plan(setting = nil)
  get_or_set(:plan, :file_and_switches, setting)
end

Instance Method Details

#prepare_and_executeObject

Loads configuaration as directed by plan(), selects indentity as directed by choose_user() and choose_group(), then calls execute() for the command. Subclasses provide the execute() method to provide their specific behavior. The Dispatcher calls this method to launch a command.



85
86
87
88
89
# File 'lib/scout_agent/assignment.rb', line 85

def prepare_and_execute
  read_the_plan
  choose_identity
  execute
end