smith 0.5.7 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/smithctl +3 -1
- data/lib/smith.rb +1 -0
- data/lib/smith/acl_compiler.rb +17 -8
- data/lib/smith/agent_process.rb +1 -1
- data/lib/smith/command.rb +21 -43
- data/lib/smith/command_base.rb +64 -0
- data/lib/smith/commands/agency/{version.rb → agency_version.rb} +7 -6
- data/lib/smith/commands/agency/agents.rb +7 -1
- data/lib/smith/commands/agency/kill.rb +7 -1
- data/lib/smith/commands/agency/list.rb +8 -9
- data/lib/smith/commands/agency/logger.rb +8 -9
- data/lib/smith/commands/agency/metadata.rb +7 -1
- data/lib/smith/commands/agency/restart.rb +7 -8
- data/lib/smith/commands/agency/start.rb +9 -9
- data/lib/smith/commands/agency/state.rb +7 -1
- data/lib/smith/commands/agency/stop.rb +8 -8
- data/lib/smith/commands/{agency/common.rb → common.rb} +0 -0
- data/lib/smith/commands/smithctl/acls.rb +61 -0
- data/lib/smith/commands/smithctl/cat.rb +12 -13
- data/lib/smith/commands/smithctl/commands.rb +67 -0
- data/lib/smith/commands/smithctl/pop.rb +10 -11
- data/lib/smith/commands/smithctl/rm.rb +7 -12
- data/lib/smith/commands/smithctl/smithctl_version.rb +5 -6
- data/lib/smith/commands/smithctl/top.rb +6 -1
- data/lib/smith/logger.rb +5 -5
- metadata +37 -34
data/bin/smithctl
CHANGED
@@ -10,6 +10,8 @@ module Smith
|
|
10
10
|
|
11
11
|
include Logger
|
12
12
|
|
13
|
+
AGENCY_TIMEOUT = 60
|
14
|
+
|
13
15
|
def initialize
|
14
16
|
log_level(:info)
|
15
17
|
end
|
@@ -59,7 +61,7 @@ module Smith
|
|
59
61
|
def agency_command(command, args, &blk)
|
60
62
|
Messaging::Sender.new('agency.control', :auto_delete => true, :durable => false, :persistent => true, :strict => true).ready do |sender|
|
61
63
|
|
62
|
-
sender.timeout(
|
64
|
+
sender.timeout(AGENCY_TIMEOUT) { puts "Timeout. Is the agency still running"; Smith.stop(true) }
|
63
65
|
|
64
66
|
payload = ACL::Payload.new(:agency_command).content(:command => command, :args => args)
|
65
67
|
|
data/lib/smith.rb
CHANGED
@@ -226,6 +226,7 @@ require_relative 'smith/agent_cache'
|
|
226
226
|
require_relative 'smith/agent_process'
|
227
227
|
require_relative 'smith/agent_monitoring'
|
228
228
|
require_relative 'smith/command'
|
229
|
+
require_relative 'smith/command_base'
|
229
230
|
require_relative 'smith/messaging/amqp_options'
|
230
231
|
require_relative 'smith/messaging/queue_factory'
|
231
232
|
require_relative 'smith/messaging/payload'
|
data/lib/smith/acl_compiler.rb
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
require 'pp'
|
3
3
|
require 'protobuf/compiler/compiler'
|
4
4
|
|
5
|
+
# There doesn't seem to be a way to turn of printing. The code is generally run
|
6
|
+
# like this: log_writing unless silent but there is no way of setting silent!
|
7
|
+
# So monkey patch it.
|
8
|
+
class Protobuf::Visitor::Base
|
9
|
+
def log_writing(filename, message="writing..."); end
|
10
|
+
end
|
11
|
+
|
5
12
|
module Smith
|
6
13
|
class ACLCompiler
|
7
14
|
|
@@ -15,14 +22,16 @@ module Smith
|
|
15
22
|
# Compile any protocol buffer files. This checks the timestamp
|
16
23
|
# to see if the file needs compiling.
|
17
24
|
def compile
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
fork do
|
26
|
+
logger.debug { "Protocol buffer cache path: #{@cache_path}" }
|
27
|
+
Smith.acl_path.each do |path|
|
28
|
+
results = {}
|
29
|
+
path_glob(path) do |p|
|
30
|
+
if should_compile?(p)
|
31
|
+
logger.info { "Compiling: #{p}" }
|
32
|
+
# TODO put some error handling here.
|
33
|
+
Protobuf::Compiler.compile(p.basename, p.dirname, @cache_path)
|
34
|
+
end
|
26
35
|
end
|
27
36
|
end
|
28
37
|
end
|
data/lib/smith/agent_process.rb
CHANGED
data/lib/smith/command.rb
CHANGED
@@ -24,9 +24,10 @@ module Smith
|
|
24
24
|
clazz = Commands.const_get(Extlib::Inflection.camelize(command)).new
|
25
25
|
|
26
26
|
begin
|
27
|
-
options, target = parse_options(clazz, args)
|
28
27
|
|
29
|
-
|
28
|
+
clazz.parse_options(args)
|
29
|
+
|
30
|
+
vars.each do |k,v|
|
30
31
|
clazz.instance_eval <<-EOM, __FILE__, __LINE__ + 1
|
31
32
|
instance_variable_set(:"@#{k}", v)
|
32
33
|
def #{k}=(z); @#{k} = z; end
|
@@ -37,34 +38,20 @@ module Smith
|
|
37
38
|
clazz.execute
|
38
39
|
|
39
40
|
rescue Trollop::CommandlineError => e
|
40
|
-
vars[:responder].value(
|
41
|
+
vars[:responder].value(clazz.format_help(:prefix => "Error: #{e.message}.\n"))
|
41
42
|
rescue Trollop::HelpNeeded
|
42
|
-
vars[:responder].value(
|
43
|
+
vars[:responder].value(clazz.format_help)
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
46
|
-
# Banner callback. This is called when the parser is called.
|
47
|
-
# I'm sure there is a better way of doing this.
|
48
|
-
def self.banner(command)
|
49
|
-
"smithctl #{command} OPTIONS [Agents]"
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
47
|
# Determine whether the command is an agency or smithctl command and load
|
55
48
|
# accordingly.
|
56
|
-
def self.load_command(
|
57
|
-
require command_path(
|
58
|
-
end
|
59
|
-
|
60
|
-
# Check to see if the command is an agency or smithctl command.
|
61
|
-
def self.agency?
|
62
|
-
Smith.constants.include?(:Agency)
|
49
|
+
def self.load_command(command)
|
50
|
+
require command_path(command)
|
63
51
|
end
|
64
52
|
|
65
|
-
|
66
|
-
|
67
|
-
send("#{command_type(command)}_path").join(command)
|
53
|
+
def self.instantiate(command)
|
54
|
+
Commands.const_get(Extlib::Inflection.camelize(command)).new
|
68
55
|
end
|
69
56
|
|
70
57
|
# What type of command is it?
|
@@ -79,6 +66,18 @@ module Smith
|
|
79
66
|
end
|
80
67
|
end
|
81
68
|
|
69
|
+
private
|
70
|
+
|
71
|
+
# Check to see if the command is an agency or smithctl command.
|
72
|
+
def self.agency?
|
73
|
+
Smith.constants.include?(:Agency)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Return the full path of the ruby class.
|
77
|
+
def self.command_path(command)
|
78
|
+
send("#{command_type(command)}_path").join(command)
|
79
|
+
end
|
80
|
+
|
82
81
|
# Is the command an agency command?
|
83
82
|
def self.agency_command?(cmd)
|
84
83
|
agency_path.join(cmd).sub_ext('.rb').exist?
|
@@ -103,26 +102,5 @@ module Smith
|
|
103
102
|
def self.base_path
|
104
103
|
@c64a6f4f ||= Smith.root_path.join('lib').join("smith").join('commands')
|
105
104
|
end
|
106
|
-
|
107
|
-
# Uses the options_parser method in the specific command class to procees
|
108
|
-
# any options associated with that command. If no options_parser method
|
109
|
-
# exits then an empty Array is returned. Any members of the args array
|
110
|
-
# that are not parsed by the options parser are return as the target, i.e.
|
111
|
-
# the agent(s) that the command is to operate on.
|
112
|
-
def self.parse_options(clazz, args)
|
113
|
-
if clazz.respond_to?(:options_parser)
|
114
|
-
[clazz.options_parser.parse(args), args]
|
115
|
-
else
|
116
|
-
[{}, args]
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def self.parser_help(clazz, opts={})
|
121
|
-
StringIO.new.tap do |help|
|
122
|
-
help.puts opts[:prefix] if opts[:prefix]
|
123
|
-
clazz.options_parser.educate(help)
|
124
|
-
help.rewind
|
125
|
-
end.read
|
126
|
-
end
|
127
105
|
end
|
128
106
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'trollop'
|
4
|
+
|
5
|
+
module Smith
|
6
|
+
class CommandBase
|
7
|
+
class UnkownCommandError < RuntimeError; end
|
8
|
+
|
9
|
+
attr_reader :options, :target
|
10
|
+
|
11
|
+
include Logger
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@parser = Trollop::Parser.new
|
15
|
+
options_spec
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_options(args)
|
19
|
+
@options = @parser.parse(args)
|
20
|
+
@target = args
|
21
|
+
end
|
22
|
+
|
23
|
+
def format_help(opts={})
|
24
|
+
StringIO.new.tap do |help|
|
25
|
+
help.puts opts[:prefix] if opts[:prefix]
|
26
|
+
@parser.educate(help)
|
27
|
+
help.rewind
|
28
|
+
end.read
|
29
|
+
end
|
30
|
+
|
31
|
+
def banner(banner=nil, opts={})
|
32
|
+
if banner.nil?
|
33
|
+
@banner
|
34
|
+
else
|
35
|
+
@banner = banner
|
36
|
+
@parser.banner((opts[:no_template]) ? banner : banner_template(banner))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def opt(*opt_spec)
|
43
|
+
@parser.opt(*opt_spec)
|
44
|
+
end
|
45
|
+
|
46
|
+
def options_spec
|
47
|
+
banner "You should really set a proper banner notice for this command."
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def banner_template(text)
|
53
|
+
return <<-EOS
|
54
|
+
|
55
|
+
#{text}
|
56
|
+
|
57
|
+
Usage:
|
58
|
+
smithctl #{self.class.to_s.split('::').last.downcase} OPTIONS
|
59
|
+
|
60
|
+
OPTIONS are:
|
61
|
+
EOS
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
module Smith
|
3
3
|
module Commands
|
4
|
-
class
|
4
|
+
class AgencyVersion < CommandBase
|
5
5
|
def execute
|
6
6
|
version_file = Smith.root_path.join('VERSION')
|
7
7
|
|
@@ -12,11 +12,12 @@ module Smith
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
private
|
16
|
+
|
17
|
+
def options_spec
|
18
|
+
banner "Display the agency version."
|
19
|
+
|
20
|
+
opt :git, "run git describe, assuming git is installed", :short => :g
|
20
21
|
end
|
21
22
|
end
|
22
23
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
module Smith
|
3
3
|
module Commands
|
4
|
-
class Agents <
|
4
|
+
class Agents < CommandBase
|
5
5
|
def execute
|
6
6
|
responder.value do
|
7
7
|
# FIXME make sure that if the path doesn't exist don't blow up.
|
@@ -23,6 +23,12 @@ module Smith
|
|
23
23
|
(agent_paths.empty?) ? "" : agent_paths.sort.join(" ")
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def options_spec
|
30
|
+
banner "List all available agents."
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
@@ -1,13 +1,19 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
module Smith
|
3
3
|
module Commands
|
4
|
-
class Kill <
|
4
|
+
class Kill < CommandBase
|
5
5
|
def execute
|
6
6
|
target.each do |agent_name|
|
7
7
|
agents[agent_name].kill
|
8
8
|
end
|
9
9
|
responder.value
|
10
10
|
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def options_spec
|
15
|
+
banner "Kill an agent/agents."
|
16
|
+
end
|
11
17
|
end
|
12
18
|
end
|
13
19
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
module Smith
|
3
3
|
module Commands
|
4
|
-
class List <
|
4
|
+
class List < CommandBase
|
5
5
|
def execute
|
6
6
|
responder.value do
|
7
7
|
if options[:all]
|
@@ -29,14 +29,6 @@ module Smith
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def options_parser
|
33
|
-
Trollop::Parser.new do
|
34
|
-
banner Command.banner('list')
|
35
|
-
opt :long, "the number of times to send the message", :short => :l
|
36
|
-
opt :all, "show all agents in all states", :short => :a
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
32
|
private
|
41
33
|
|
42
34
|
def long_format(agents)
|
@@ -60,6 +52,13 @@ module Smith
|
|
60
52
|
acc << sprintf("#{col_widths.inject("") { |spec,w| spec << "%-#{w + 2}s"}}\n", *e)
|
61
53
|
end
|
62
54
|
end
|
55
|
+
|
56
|
+
def options_spec
|
57
|
+
banner "List the running agents."
|
58
|
+
|
59
|
+
opt :long, "the number of times to send the message", :short => :l
|
60
|
+
opt :all, "show all agents in all states", :short => :a
|
61
|
+
end
|
63
62
|
end
|
64
63
|
end
|
65
64
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
module Smith
|
3
3
|
module Commands
|
4
|
-
class Logger <
|
4
|
+
class Logger < CommandBase
|
5
5
|
def execute
|
6
6
|
responder.value do
|
7
7
|
if options[:level].nil?
|
@@ -36,14 +36,6 @@ module Smith
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
def options_parser
|
40
|
-
Trollop::Parser.new do
|
41
|
-
banner Command.banner('logger')
|
42
|
-
opt :level, "the log level you want to set", :type => :string, :short => :l
|
43
|
-
opt :trace, "turn trace on or off", :type => :boolean, :short => :t
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
39
|
private
|
48
40
|
|
49
41
|
def send_agent_control_message(agent, message)
|
@@ -51,6 +43,13 @@ module Smith
|
|
51
43
|
sender.publish(ACL::Payload.new(:agent_command).content(message))
|
52
44
|
end
|
53
45
|
end
|
46
|
+
|
47
|
+
def options_spec
|
48
|
+
banner "Change the log and trace level of the agents or the agency."
|
49
|
+
|
50
|
+
opt :level, "the log level you want to set", :type => :string, :short => :l
|
51
|
+
opt :trace, "turn trace on or off", :type => :boolean, :short => :t
|
52
|
+
end
|
54
53
|
end
|
55
54
|
end
|
56
55
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
module Smith
|
3
3
|
module Commands
|
4
|
-
class Metadata <
|
4
|
+
class Metadata < CommandBase
|
5
5
|
def execute
|
6
6
|
responder.value do
|
7
7
|
target.inject([]) do |acc,agent_name|
|
@@ -9,6 +9,12 @@ module Smith
|
|
9
9
|
end.join("\n")
|
10
10
|
end
|
11
11
|
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def options_spec
|
16
|
+
banner "Display an agent/agents metadata."
|
17
|
+
end
|
12
18
|
end
|
13
19
|
end
|
14
20
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
require_relative 'common'
|
3
|
+
require_relative '../common'
|
4
4
|
|
5
5
|
# This is a meta-command. It doesn't implement anything it simply sends
|
6
6
|
# messages to one or many existing commands to do the work.
|
7
7
|
|
8
8
|
module Smith
|
9
9
|
module Commands
|
10
|
-
class Restart <
|
10
|
+
class Restart < CommandBase
|
11
11
|
|
12
12
|
include Common
|
13
13
|
|
@@ -26,13 +26,12 @@ module Smith
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
private
|
29
30
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
opt :group, "Start everything in the specified group", :type => :string, :short => :g
|
35
|
-
end
|
31
|
+
def options_spec
|
32
|
+
banner "Restart an agent/agents."
|
33
|
+
|
34
|
+
opt :group, "Start everything in the specified group", :type => :string, :short => :g
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
require_relative 'common'
|
3
|
+
require_relative '../common'
|
4
4
|
|
5
5
|
module Smith
|
6
6
|
module Commands
|
7
|
-
class Start <
|
7
|
+
class Start < CommandBase
|
8
8
|
|
9
9
|
include Common
|
10
10
|
|
@@ -49,13 +49,13 @@ module Smith
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
private
|
53
|
+
|
54
|
+
def options_spec
|
55
|
+
banner "Start an agent/agents or group of agents."
|
56
|
+
|
57
|
+
opt :kill, "Reset the state of the agent before starting", :short => :k
|
58
|
+
opt :group, "Start everything in the specified group", :type => :string, :short => :g
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
module Smith
|
3
3
|
module Commands
|
4
|
-
class State <
|
4
|
+
class State < CommandBase
|
5
5
|
def execute
|
6
6
|
responder.value do
|
7
7
|
target.inject([]) do |acc,agent_name|
|
@@ -9,6 +9,12 @@ module Smith
|
|
9
9
|
end.join("\n")
|
10
10
|
end
|
11
11
|
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def options_spec
|
16
|
+
banner "Show the state of an agent/agents - deprecated."
|
17
|
+
end
|
12
18
|
end
|
13
19
|
end
|
14
20
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
require_relative 'common'
|
3
|
+
require_relative '../common'
|
4
4
|
|
5
5
|
module Smith
|
6
6
|
module Commands
|
7
|
-
class Stop <
|
7
|
+
class Stop < CommandBase
|
8
8
|
|
9
9
|
include Common
|
10
10
|
|
@@ -58,12 +58,12 @@ module Smith
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
private
|
62
|
+
|
63
|
+
def options_spec
|
64
|
+
banner "Stop an agent/agents."
|
65
|
+
|
66
|
+
opt :group, "Stop everything in the specified group", :type => :string, :short => :g
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
File without changes
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'extlib/string'
|
4
|
+
|
5
|
+
module Smith
|
6
|
+
module Commands
|
7
|
+
class Acls < CommandBase
|
8
|
+
def execute
|
9
|
+
responder.value do
|
10
|
+
if options[:show]
|
11
|
+
if target.empty?
|
12
|
+
"You must supply an ACL file name."
|
13
|
+
else
|
14
|
+
target.map do |acl|
|
15
|
+
acls = Smith.acl_path.inject([]) do |a,path|
|
16
|
+
a.tap do |acc|
|
17
|
+
acl_file = path.join("#{acl.snake_case}.proto")
|
18
|
+
if acl_file.exist?
|
19
|
+
acc << acl_file
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
case acls.length
|
25
|
+
when 0
|
26
|
+
"ACL file does not exist."
|
27
|
+
when 1
|
28
|
+
if target.length == 1
|
29
|
+
"\n#{indent_acl(acls.first.read)}\n"
|
30
|
+
else
|
31
|
+
"\n#{acl} ->\n#{indent_acl(acls.first.read)}"
|
32
|
+
end
|
33
|
+
else
|
34
|
+
"There are multiple ACLs with the name: #{target}"
|
35
|
+
end
|
36
|
+
end.join("\n")
|
37
|
+
end
|
38
|
+
else
|
39
|
+
join_string = (options[:long]) ? "\n" : " "
|
40
|
+
Pathname.glob(Smith.acl_path.map {|p| "#{p}#{File::SEPARATOR}*"}).map do |p|
|
41
|
+
p.basename(".proto")
|
42
|
+
end.sort.join(join_string)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def indent_acl(acl)
|
50
|
+
acl.split("\n").map { |l| l.sub(/^/, " ") }.join("\n")
|
51
|
+
end
|
52
|
+
|
53
|
+
def options_spec
|
54
|
+
banner "List and display acl files."
|
55
|
+
|
56
|
+
opt :long, "format the listing", :short => :l
|
57
|
+
opt :show, "show the contents of the acl file", :short => :s
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -4,7 +4,7 @@ require 'multi_json'
|
|
4
4
|
|
5
5
|
module Smith
|
6
6
|
module Commands
|
7
|
-
class Cat <
|
7
|
+
class Cat < CommandBase
|
8
8
|
def execute
|
9
9
|
if target.size == 0
|
10
10
|
responder.value("No queue specified. Please specify a queue.")
|
@@ -45,26 +45,25 @@ module Smith
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def options_parser
|
49
|
-
Trollop::Parser.new do
|
50
|
-
banner Command.banner('cat')
|
51
|
-
opt :type, "message type", :type => :string, :default => 'default', :short => :t
|
52
|
-
opt :json, "supply the json representation with this flag", :type => :string, :conflicts => :file, :short => :j
|
53
|
-
opt :file, "read the data from the named file", :type => :string, :conflicts => :json, :short => :f
|
54
|
-
opt :number, "the number of times to send the message", :type => :integer, :default => 1, :short => :n
|
55
|
-
opt :dynamic, "send message to a dynamic queue", :type => :boolean, :default => false, :short => :d
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
48
|
private
|
60
49
|
|
61
50
|
def json_to_payload(data, type)
|
62
51
|
Smith::ACL::Payload.new(type.to_sym).content do |m|
|
63
|
-
MultiJson.
|
52
|
+
MultiJson.load(data, :symbolize_keys => true).each do |k,v|
|
64
53
|
m.send("#{k}=".to_sym, v)
|
65
54
|
end
|
66
55
|
end
|
67
56
|
end
|
57
|
+
|
58
|
+
def options_spec
|
59
|
+
banner "Send a message to a queue. The ACL can also be specified."
|
60
|
+
|
61
|
+
opt :type, "message type", :type => :string, :default => 'default', :short => :t
|
62
|
+
opt :json, "supply the json representation with this flag", :type => :string, :conflicts => :file, :short => :j
|
63
|
+
opt :file, "read the data from the named file", :type => :string, :conflicts => :json, :short => :f
|
64
|
+
opt :number, "the number of times to send the message", :type => :integer, :default => 1, :short => :n
|
65
|
+
opt :dynamic, "send message to a dynamic queue", :type => :boolean, :default => false, :short => :d
|
66
|
+
end
|
68
67
|
end
|
69
68
|
end
|
70
69
|
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
module Smith
|
3
|
+
module Commands
|
4
|
+
class Commands < CommandBase
|
5
|
+
def execute
|
6
|
+
commands = (target.empty?) ? list_commands('agency') + list_commands('smithctl') : target
|
7
|
+
responder.value(format(commands))
|
8
|
+
end
|
9
|
+
|
10
|
+
def list_commands(type)
|
11
|
+
list_command_files(type).map {|command| to_command_name(command) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def format(commands)
|
15
|
+
if options[:long]
|
16
|
+
c = instantiate_commands(commands)
|
17
|
+
if options[:type]
|
18
|
+
c.map { |k,v| sprintf("%1$*4$s - %2$s [%3$s]", k, remove_new_lines(v), Command.command_type(k), -(max_length(c) + 1)) }.join("\n")
|
19
|
+
else
|
20
|
+
c.map { |k,v| sprintf("%1$*3$s - %2$s", k, remove_new_lines(v), -(max_length(c) + 1)) }.join("\n")
|
21
|
+
end
|
22
|
+
else
|
23
|
+
if options[:type]
|
24
|
+
instantiate_commands(commands).map { |k,v| sprintf("%s - %s", k, Command.command_type(k)) }
|
25
|
+
else
|
26
|
+
commands.sort.join("\n")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def list_command_files(type)
|
34
|
+
Pathname.glob(Command.base_path.join(type).join("**/*.rb"))
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_command_name(path)
|
38
|
+
path.basename(".rb").to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
def instantiate_commands(commands)
|
42
|
+
commands.sort.inject({}) do |a, command|
|
43
|
+
a.tap do |acc|
|
44
|
+
Command.load_command(command)
|
45
|
+
clazz = Command.instantiate(command)
|
46
|
+
acc[command] = clazz.banner
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def remove_new_lines(s)
|
52
|
+
s.split("\n").map(&:strip).select {|a| !a.empty? }.join(" ")
|
53
|
+
end
|
54
|
+
|
55
|
+
def options_spec
|
56
|
+
banner "List available commands.\n\n If a command/commands is given only that command will be shown."
|
57
|
+
|
58
|
+
opt :long, "include the short usage message", :short => :l
|
59
|
+
opt :type, "show whether the command is a smithctl command or an agency command ", :short => :t
|
60
|
+
end
|
61
|
+
|
62
|
+
def max_length(banners_hash)
|
63
|
+
banners_hash.keys.map(&:length).max
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -3,7 +3,7 @@ require 'yajl'
|
|
3
3
|
|
4
4
|
module Smith
|
5
5
|
module Commands
|
6
|
-
class Pop <
|
6
|
+
class Pop < CommandBase
|
7
7
|
def execute
|
8
8
|
case target.size
|
9
9
|
when 0
|
@@ -50,16 +50,6 @@ module Smith
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
def options_parser
|
54
|
-
Trollop::Parser.new do
|
55
|
-
banner Command.banner('pop-queue')
|
56
|
-
opt :print, "print the message", :short => :p
|
57
|
-
opt :json , "return the JSON representation of the message", :short => :j
|
58
|
-
opt :remove, "remove the message from the queue", :short => :r
|
59
|
-
opt :number, "the number of messages to remove", :default =>1, :short => :n
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
53
|
private
|
64
54
|
|
65
55
|
def print_message(message)
|
@@ -71,6 +61,15 @@ module Smith
|
|
71
61
|
end
|
72
62
|
end
|
73
63
|
end
|
64
|
+
|
65
|
+
def options_spec
|
66
|
+
banner "Pop messages off the named queue."
|
67
|
+
|
68
|
+
opt :print, "print the message", :short => :p
|
69
|
+
opt :json , "return the JSON representation of the message", :short => :j
|
70
|
+
opt :remove, "remove the message from the queue", :short => :r
|
71
|
+
opt :number, "the number of messages to remove", :default =>1, :short => :n
|
72
|
+
end
|
74
73
|
end
|
75
74
|
end
|
76
75
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
module Smith
|
3
3
|
module Commands
|
4
|
-
class Rm <
|
4
|
+
class Rm < CommandBase
|
5
5
|
def execute
|
6
6
|
case target.size
|
7
7
|
when 0
|
@@ -18,18 +18,13 @@ module Smith
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
Trollop::Parser.new do
|
23
|
-
banner Command.banner('remove-queue')
|
24
|
-
opt :force, "force the removal even if there are messages on the queue", :short => :f
|
25
|
-
opt :verbose, "print the number of messages deleted", :short => :v
|
26
|
-
end
|
27
|
-
end
|
21
|
+
private
|
28
22
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
23
|
+
def options_spec
|
24
|
+
banner "Display or remove a message from the named queue."
|
25
|
+
|
26
|
+
opt :force, "force the removal even if there are messages on the queue", :short => :f
|
27
|
+
opt :verbose, "print the number of messages deleted", :short => :v
|
33
28
|
end
|
34
29
|
end
|
35
30
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
module Smith
|
3
3
|
module Commands
|
4
|
-
class SmithctlVersion <
|
4
|
+
class SmithctlVersion < CommandBase
|
5
5
|
def execute
|
6
6
|
version_file = Smith.root_path.join('VERSION')
|
7
7
|
|
@@ -12,11 +12,10 @@ module Smith
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
15
|
+
def options_spec
|
16
|
+
banner "Displays the smithctl version."
|
17
|
+
|
18
|
+
opt :git, "run git describe, assuming git is installed", :short => :g
|
20
19
|
end
|
21
20
|
end
|
22
21
|
end
|
@@ -4,7 +4,7 @@ require 'curses'
|
|
4
4
|
|
5
5
|
module Smith
|
6
6
|
module Commands
|
7
|
-
class Top <
|
7
|
+
class Top < CommandBase
|
8
8
|
def execute
|
9
9
|
Curses.init_screen()
|
10
10
|
win = Curses::Window.new(Curses.lines, Curses.cols, 0, 0)
|
@@ -30,6 +30,7 @@ module Smith
|
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
33
|
+
|
33
34
|
def format_queues(queue_stats)
|
34
35
|
queue_stats.inject([]) do |a,queue_stat|
|
35
36
|
a.tap do |acc|
|
@@ -37,6 +38,10 @@ module Smith
|
|
37
38
|
end
|
38
39
|
end.join(";")
|
39
40
|
end
|
41
|
+
|
42
|
+
def options_spec
|
43
|
+
banner "Show information about running agents."
|
44
|
+
end
|
40
45
|
end
|
41
46
|
end
|
42
47
|
end
|
data/lib/smith/logger.rb
CHANGED
@@ -17,13 +17,14 @@ module Smith
|
|
17
17
|
module Methods
|
18
18
|
protected
|
19
19
|
|
20
|
+
@@__name = 'smith'
|
20
21
|
@@__pattern = Smith::Config.get.logging.default_pattern
|
21
22
|
@@__date_pattern = Smith::Config.get.logging.default_date_pattern
|
22
23
|
@@__level = Smith::Config.get.logging.level
|
23
24
|
@@__trace = Smith::Config.get.logging.trace
|
24
|
-
@@
|
25
|
-
|
26
|
-
|
25
|
+
@@__appender = Smith::Config.get.logging.appender._data.tap do |appender|
|
26
|
+
appender[:type] = Logging::Appenders.const_get(Extlib::Inflection.camelize(appender.delete(:type)))
|
27
|
+
end
|
27
28
|
|
28
29
|
def log_level(level=nil)
|
29
30
|
if level
|
@@ -40,8 +41,7 @@ module Smith
|
|
40
41
|
def log_appender(opts={})
|
41
42
|
if @appender.nil? || !opts.empty?
|
42
43
|
@@__name = opts[:name] if opts[:name]
|
43
|
-
|
44
|
-
@appender = @@__appender_type.send(:new, @@__name, :filename => @@__appender_filename, :layout => log_pattern)
|
44
|
+
@appender = @@__appender[:type].send(:new, @@__name, @@__appender.merge(:layout => log_pattern))
|
45
45
|
@reload = true
|
46
46
|
end
|
47
47
|
Logging.logger.root.appenders = @appender
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smith
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-02-22 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: amqp
|
16
|
-
requirement: &
|
16
|
+
requirement: &14081940 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.9.5.pre
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *14081940
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: dm-core
|
27
|
-
requirement: &
|
27
|
+
requirement: &14081460 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.1
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *14081460
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: dm-observer
|
38
|
-
requirement: &
|
38
|
+
requirement: &14081000 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - =
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.0.1
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *14081000
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: dm-yaml-adapter
|
49
|
-
requirement: &
|
49
|
+
requirement: &14080540 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - =
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.0.1
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *14080540
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: daemons
|
60
|
-
requirement: &
|
60
|
+
requirement: &13201300 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.1.4
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *13201300
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: eventmachine
|
71
|
-
requirement: &
|
71
|
+
requirement: &13848600 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.0.0.beta.4
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *13848600
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: extlib
|
82
|
-
requirement: &
|
82
|
+
requirement: &13848140 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 0.9.15
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *13848140
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: logging
|
93
|
-
requirement: &
|
93
|
+
requirement: &13847680 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: 1.6.1
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *13847680
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: optimism
|
104
|
-
requirement: &
|
104
|
+
requirement: &13847220 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: 3.0.3
|
110
110
|
type: :runtime
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *13847220
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: ruby_protobuf
|
115
|
-
requirement: &
|
115
|
+
requirement: &13846760 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - =
|
@@ -120,10 +120,10 @@ dependencies:
|
|
120
120
|
version: 0.4.11
|
121
121
|
type: :runtime
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *13846760
|
124
124
|
- !ruby/object:Gem::Dependency
|
125
125
|
name: state_machine
|
126
|
-
requirement: &
|
126
|
+
requirement: &13846300 !ruby/object:Gem::Requirement
|
127
127
|
none: false
|
128
128
|
requirements:
|
129
129
|
- - =
|
@@ -131,10 +131,10 @@ dependencies:
|
|
131
131
|
version: 1.1.2
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
|
-
version_requirements: *
|
134
|
+
version_requirements: *13846300
|
135
135
|
- !ruby/object:Gem::Dependency
|
136
136
|
name: trollop
|
137
|
-
requirement: &
|
137
|
+
requirement: &13845840 !ruby/object:Gem::Requirement
|
138
138
|
none: false
|
139
139
|
requirements:
|
140
140
|
- - ! '>='
|
@@ -142,10 +142,10 @@ dependencies:
|
|
142
142
|
version: 1.16.2
|
143
143
|
type: :runtime
|
144
144
|
prerelease: false
|
145
|
-
version_requirements: *
|
145
|
+
version_requirements: *13845840
|
146
146
|
- !ruby/object:Gem::Dependency
|
147
147
|
name: yajl-ruby
|
148
|
-
requirement: &
|
148
|
+
requirement: &13845380 !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|
151
151
|
- - ! '>='
|
@@ -153,7 +153,7 @@ dependencies:
|
|
153
153
|
version: 1.1.0
|
154
154
|
type: :runtime
|
155
155
|
prerelease: false
|
156
|
-
version_requirements: *
|
156
|
+
version_requirements: *13845380
|
157
157
|
description: Simple multi-agent framework. It uses AMQP for it's messaging layer.
|
158
158
|
email: rgh@filterfish.org
|
159
159
|
executables:
|
@@ -164,35 +164,33 @@ extra_rdoc_files: []
|
|
164
164
|
files:
|
165
165
|
- bin/agency
|
166
166
|
- bin/smithctl
|
167
|
-
- lib/smith/acl_compiler.rb
|
168
167
|
- lib/smith/agent.rb
|
169
168
|
- lib/smith/agent_cache.rb
|
170
169
|
- lib/smith/agent_config.rb
|
171
170
|
- lib/smith/agent_monitoring.rb
|
172
|
-
- lib/smith/agent_process.rb
|
173
171
|
- lib/smith/application/agency.rb
|
174
172
|
- lib/smith/bootstrap.rb
|
175
173
|
- lib/smith/cache.rb
|
176
|
-
- lib/smith/
|
174
|
+
- lib/smith/commands/agency/agency_version.rb
|
177
175
|
- lib/smith/commands/agency/agents.rb
|
178
|
-
- lib/smith/commands/agency/common.rb
|
179
176
|
- lib/smith/commands/agency/kill.rb
|
180
177
|
- lib/smith/commands/agency/list.rb
|
178
|
+
- lib/smith/commands/agency/logger.rb
|
181
179
|
- lib/smith/commands/agency/metadata.rb
|
182
180
|
- lib/smith/commands/agency/restart.rb
|
183
181
|
- lib/smith/commands/agency/start.rb
|
184
182
|
- lib/smith/commands/agency/state.rb
|
185
183
|
- lib/smith/commands/agency/stop.rb
|
186
|
-
- lib/smith/commands/
|
187
|
-
- lib/smith/commands/agency/logger.rb
|
184
|
+
- lib/smith/commands/smithctl/acls.rb
|
188
185
|
- lib/smith/commands/smithctl/cat.rb
|
186
|
+
- lib/smith/commands/smithctl/commands.rb
|
189
187
|
- lib/smith/commands/smithctl/pop.rb
|
190
188
|
- lib/smith/commands/smithctl/rm.rb
|
191
189
|
- lib/smith/commands/smithctl/smithctl_version.rb
|
192
190
|
- lib/smith/commands/smithctl/top.rb
|
193
191
|
- lib/smith/commands/template.rb
|
192
|
+
- lib/smith/commands/common.rb
|
194
193
|
- lib/smith/config.rb
|
195
|
-
- lib/smith/logger.rb
|
196
194
|
- lib/smith/messaging/acl/agency_command.proto
|
197
195
|
- lib/smith/messaging/acl/agent_command.proto
|
198
196
|
- lib/smith/messaging/acl/agent_config_request.proto
|
@@ -210,6 +208,11 @@ files:
|
|
210
208
|
- lib/smith/messaging/responder.rb
|
211
209
|
- lib/smith/messaging/sender.rb
|
212
210
|
- lib/smith/messaging/receiver.rb
|
211
|
+
- lib/smith/acl_compiler.rb
|
212
|
+
- lib/smith/agent_process.rb
|
213
|
+
- lib/smith/command.rb
|
214
|
+
- lib/smith/command_base.rb
|
215
|
+
- lib/smith/logger.rb
|
213
216
|
- lib/smith.rb
|
214
217
|
homepage: http://github.com/filterfish/smith2/
|
215
218
|
licenses: []
|