dtk-node-agent 0.7.7 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +5 -13
  2. data/README.md +21 -4
  3. data/bin/dtk-node-agent +17 -0
  4. data/lib/config/install.config +2 -2
  5. data/lib/dtk-node-agent/installer.rb +30 -25
  6. data/lib/dtk-node-agent/version.rb +18 -1
  7. metadata +23 -110
  8. data/mcollective_additions/debian.mcollective.init +0 -92
  9. data/mcollective_additions/plugins/README.md +0 -1
  10. data/mcollective_additions/plugins/v1.2/agent/discovery.rb +0 -39
  11. data/mcollective_additions/plugins/v1.2/agent/get_log_fragment.ddl +0 -15
  12. data/mcollective_additions/plugins/v1.2/agent/get_log_fragment.rb +0 -79
  13. data/mcollective_additions/plugins/v1.2/agent/git_access.ddl +0 -9
  14. data/mcollective_additions/plugins/v1.2/agent/git_access.rb +0 -79
  15. data/mcollective_additions/plugins/v1.2/agent/netstat.ddl +0 -9
  16. data/mcollective_additions/plugins/v1.2/agent/netstat.rb +0 -34
  17. data/mcollective_additions/plugins/v1.2/agent/puppet_apply.ddl +0 -9
  18. data/mcollective_additions/plugins/v1.2/agent/puppet_apply.rb +0 -630
  19. data/mcollective_additions/plugins/v1.2/agent/rpcutil.ddl +0 -204
  20. data/mcollective_additions/plugins/v1.2/agent/rpcutil.rb +0 -101
  21. data/mcollective_additions/plugins/v1.2/facts/pbuilder_facts.rb +0 -35
  22. data/mcollective_additions/plugins/v2.2/agent/action_agent.ddl +0 -9
  23. data/mcollective_additions/plugins/v2.2/agent/action_agent.rb +0 -47
  24. data/mcollective_additions/plugins/v2.2/agent/dev_manager.ddl +0 -9
  25. data/mcollective_additions/plugins/v2.2/agent/dev_manager.rb +0 -111
  26. data/mcollective_additions/plugins/v2.2/agent/discovery.rb +0 -39
  27. data/mcollective_additions/plugins/v2.2/agent/dtk_node_agent_git_client.rb +0 -94
  28. data/mcollective_additions/plugins/v2.2/agent/execute_tests.ddl +0 -9
  29. data/mcollective_additions/plugins/v2.2/agent/execute_tests.rb +0 -111
  30. data/mcollective_additions/plugins/v2.2/agent/execute_tests_v2.ddl +0 -9
  31. data/mcollective_additions/plugins/v2.2/agent/execute_tests_v2.rb +0 -131
  32. data/mcollective_additions/plugins/v2.2/agent/get_log_fragment.ddl +0 -15
  33. data/mcollective_additions/plugins/v2.2/agent/get_log_fragment.rb +0 -79
  34. data/mcollective_additions/plugins/v2.2/agent/git_access.ddl +0 -9
  35. data/mcollective_additions/plugins/v2.2/agent/git_access.rb +0 -61
  36. data/mcollective_additions/plugins/v2.2/agent/netstat.ddl +0 -9
  37. data/mcollective_additions/plugins/v2.2/agent/netstat.rb +0 -34
  38. data/mcollective_additions/plugins/v2.2/agent/ps.ddl +0 -9
  39. data/mcollective_additions/plugins/v2.2/agent/ps.rb +0 -37
  40. data/mcollective_additions/plugins/v2.2/agent/puppet_apply.ddl +0 -9
  41. data/mcollective_additions/plugins/v2.2/agent/puppet_apply.rb +0 -818
  42. data/mcollective_additions/plugins/v2.2/agent/puppet_cancel.ddl +0 -10
  43. data/mcollective_additions/plugins/v2.2/agent/puppet_cancel.rb +0 -78
  44. data/mcollective_additions/plugins/v2.2/agent/rpcutil.ddl +0 -204
  45. data/mcollective_additions/plugins/v2.2/agent/rpcutil.rb +0 -101
  46. data/mcollective_additions/plugins/v2.2/agent/ssh_agent.ddl +0 -13
  47. data/mcollective_additions/plugins/v2.2/agent/ssh_agent.rb +0 -97
  48. data/mcollective_additions/plugins/v2.2/agent/sync_agent_code.ddl +0 -10
  49. data/mcollective_additions/plugins/v2.2/agent/sync_agent_code.rb +0 -85
  50. data/mcollective_additions/plugins/v2.2/agent/tail.ddl +0 -11
  51. data/mcollective_additions/plugins/v2.2/agent/tail.rb +0 -67
  52. data/mcollective_additions/plugins/v2.2/audit/logfile.rb +0 -26
  53. data/mcollective_additions/plugins/v2.2/connector/r8stomp.rb +0 -238
  54. data/mcollective_additions/plugins/v2.2/connector/stomp.rb +0 -349
  55. data/mcollective_additions/plugins/v2.2/connector/stomp_em.rb +0 -191
  56. data/mcollective_additions/plugins/v2.2/data/agent_data.ddl +0 -22
  57. data/mcollective_additions/plugins/v2.2/data/agent_data.rb +0 -17
  58. data/mcollective_additions/plugins/v2.2/data/collective_data.ddl +0 -20
  59. data/mcollective_additions/plugins/v2.2/data/collective_data.rb +0 -9
  60. data/mcollective_additions/plugins/v2.2/data/fact_data.ddl +0 -28
  61. data/mcollective_additions/plugins/v2.2/data/fact_data.rb +0 -55
  62. data/mcollective_additions/plugins/v2.2/data/fstat_data.ddl +0 -89
  63. data/mcollective_additions/plugins/v2.2/data/fstat_data.rb +0 -56
  64. data/mcollective_additions/plugins/v2.2/discovery/flatfile.ddl +0 -11
  65. data/mcollective_additions/plugins/v2.2/discovery/flatfile.rb +0 -48
  66. data/mcollective_additions/plugins/v2.2/discovery/mc.ddl +0 -11
  67. data/mcollective_additions/plugins/v2.2/discovery/mc.rb +0 -30
  68. data/mcollective_additions/plugins/v2.2/discovery/stdin.ddl +0 -11
  69. data/mcollective_additions/plugins/v2.2/discovery/stdin.rb +0 -66
  70. data/mcollective_additions/plugins/v2.2/facts/pbuilder_facts.rb +0 -37
  71. data/mcollective_additions/plugins/v2.2/facts/yaml_facts.rb +0 -61
  72. data/mcollective_additions/plugins/v2.2/registration/agentlist.rb +0 -10
  73. data/mcollective_additions/plugins/v2.2/security/sshkey.ddl +0 -9
  74. data/mcollective_additions/plugins/v2.2/security/sshkey.rb +0 -362
  75. data/mcollective_additions/plugins/v2.2/util/puppetrunner.rb +0 -36
  76. data/mcollective_additions/plugins/v2.2/validator/array_validator.ddl +0 -7
  77. data/mcollective_additions/plugins/v2.2/validator/array_validator.rb +0 -9
  78. data/mcollective_additions/plugins/v2.2/validator/ipv4address_validator.ddl +0 -7
  79. data/mcollective_additions/plugins/v2.2/validator/ipv4address_validator.rb +0 -16
  80. data/mcollective_additions/plugins/v2.2/validator/ipv6address_validator.ddl +0 -7
  81. data/mcollective_additions/plugins/v2.2/validator/ipv6address_validator.rb +0 -16
  82. data/mcollective_additions/plugins/v2.2/validator/length_validator.ddl +0 -7
  83. data/mcollective_additions/plugins/v2.2/validator/length_validator.rb +0 -11
  84. data/mcollective_additions/plugins/v2.2/validator/regex_validator.ddl +0 -7
  85. data/mcollective_additions/plugins/v2.2/validator/regex_validator.rb +0 -9
  86. data/mcollective_additions/plugins/v2.2/validator/shellsafe_validator.ddl +0 -7
  87. data/mcollective_additions/plugins/v2.2/validator/shellsafe_validator.rb +0 -13
  88. data/mcollective_additions/plugins/v2.2/validator/typecheck_validator.ddl +0 -7
  89. data/mcollective_additions/plugins/v2.2/validator/typecheck_validator.rb +0 -28
  90. data/mcollective_additions/redhat.mcollective.init +0 -139
  91. data/mcollective_additions/redhat.mcollective.service +0 -14
  92. data/mcollective_additions/server.cfg +0 -22
  93. data/src/etc/logrotate.d/mcollective +0 -10
  94. data/src/etc/mcollective.default +0 -6
@@ -1,39 +0,0 @@
1
- module MCollective
2
- module Agent
3
- # Discovery agent for The Marionette Collective
4
- #
5
- # Released under the Apache License, Version 2
6
- class Discovery
7
- attr_reader :timeout, :meta
8
-
9
- def initialize
10
- config = Config.instance.pluginconf
11
-
12
- @timeout = 5
13
- @timeout = config["discovery.timeout"].to_i if config.include?("discovery.timeout")
14
-
15
- @meta = {:license => "Apache License, Version 2",
16
- :author => "R.I.Pienaar <rip@devco.net>",
17
- :timeout => @timeout,
18
- :name => "Discovery Agent",
19
- :version => MCollective.version,
20
- :url => "http://www.marionette-collective.org",
21
- :description => "MCollective Discovery Agent"}
22
- end
23
-
24
- def handlemsg(msg, stomp)
25
- reply = "unknown request"
26
-
27
- case msg[:body]
28
- when "ping"
29
- reply = "pong"
30
-
31
- else
32
- reply = "Unknown Request: #{msg[:body]}"
33
- end
34
-
35
- reply
36
- end
37
- end
38
- end
39
- end
@@ -1,94 +0,0 @@
1
- require 'grit'
2
- module DTK
3
- module NodeAgent
4
- class GitClient
5
- def initialize(repo_dir,opts={})
6
- @repo_dir = repo_dir
7
- @grit_repo = (opts[:create] ? ::Grit::Repo.init(repo_dir) : ::Grit::Repo.new(repo_dir))
8
- end
9
-
10
- def clone_branch(remote_repo,branch,opts={})
11
- git_command__remote_add(remote_repo,branch)
12
- git_command__checkout(opts[:sha]||branch)
13
- end
14
-
15
- def pull_and_checkout_branch?(branch,opts={})
16
- sha = opts[:sha]
17
- #shortcut
18
- return if sha and (sha == current_branch_or_head())
19
-
20
- unless remote_branch_exists?(branch)
21
- git_command__remote_branch_add(branch)
22
- git_command__fetch()
23
- end
24
-
25
- if branch_exists?(branch)
26
- git_command__pull(branch)
27
- git_command__checkout(sha) if sha
28
- else
29
- git_command__checkout(sha||branch)
30
- end
31
- end
32
-
33
- private
34
- def git_command__remote_add(remote_repo,branch,remote_name=nil)
35
- remote_name ||= default_remote()
36
- git_command().remote(git_command_opts(),"add","-t", branch, "-f", remote_name, remote_repo)
37
- end
38
-
39
- def git_command__remote_branch_add(branch,remote_name=nil)
40
- remote_name ||= default_remote()
41
- git_command().remote(git_command_opts(),"set-branches", "--add", remote_name, branch)
42
- end
43
-
44
- def git_command__checkout(ref)
45
- unless current_branch_or_head() == ref
46
- git_command().checkout(git_command_opts(),ref)
47
- end
48
- end
49
-
50
- def git_command__fetch(remote_name=nil)
51
- remote_name ||= default_remote()
52
- git_command().fetch(git_command_opts(),remote_name)
53
- end
54
-
55
- def git_command__pull(branch,remote_name=nil)
56
- remote_name ||= default_remote()
57
- git_command().pull(git_command_opts(),remote_name,branch)
58
- end
59
-
60
- def branch_exists?(branch)
61
- @grit_repo.heads.find{|h|h.name == branch} ? true : nil
62
- end
63
-
64
- def remote_branch_exists?(branch,remote_name=nil)
65
- remote_name ||= default_remote()
66
- remote_branch = "#{remote_name}/#{branch}"
67
- @grit_repo.remotes.find{|h|h.name == remote_branch} ? true : nil
68
- end
69
-
70
- def current_branch_or_head()
71
- #this returns sha when detached head
72
- if @grit_repo.head
73
- @grit_repo.head.name
74
- elsif @grit_repo.commit('HEAD')
75
- @grit_repo.commit('HEAD').id
76
- end
77
- end
78
-
79
- def default_remote()
80
- 'origin'
81
- end
82
-
83
- def git_command_opts(opts={})
84
- ret = {:raise => true, :timeout => 60}
85
- ret.merge!(:chdir => @repo_dir) unless opts[:no_chdir]
86
- end
87
-
88
- def git_command()
89
- @grit_repo.git
90
- end
91
- end
92
- end
93
- end
94
-
@@ -1,9 +0,0 @@
1
- metadata :name => "component module tests executor",
2
- :description => "Agent to executing component module infrastructure tests",
3
- :author => "Reactor8",
4
- :license => "",
5
- :version => "",
6
- :url => "",
7
- :timeout => 10
8
- action "execute_tests", :description => "execute all component module infrastructure tests" do
9
- end
@@ -1,111 +0,0 @@
1
- module MCollective
2
- module Agent
3
- class Execute_tests < RPC::Agent
4
- def initialize()
5
- super()
6
- @log = Log.instance
7
- end
8
-
9
- def pull_modules(module_version_context, git_server)
10
- ENV['GIT_SHELL'] = nil #This is put in because if vcsrepo Puppet module used it sets this
11
- begin
12
- repo_dir = "#{ModulePath}/#{module_version_context[:implementation]}"
13
- remote_repo = "#{git_server}:#{module_version_context[:repo]}"
14
- opts = Hash.new
15
- begin
16
- if File.exists?(repo_dir)
17
- @log.info("Branch already exists. Checkout to branch and pull latest changes...")
18
- git_repo = ::DTK::NodeAgent::GitClient.new(repo_dir)
19
- git_repo.pull_and_checkout_branch?(module_version_context[:branch],opts)
20
- else
21
- @log.info("Branch does not exist. Cloning branch...")
22
- git_repo = ::DTK::NodeAgent::GitClient.new(repo_dir,:create=>true)
23
- git_repo.clone_branch(remote_repo,module_version_context[:branch],opts)
24
- end
25
- rescue Exception => e
26
- log_error(e)
27
- #to achieve idempotent behavior; fully remove directory if any problems
28
- FileUtils.rm_rf repo_dir
29
- raise e
30
- end
31
- rescue Exception => e
32
- log_error(e)
33
- end
34
- end
35
-
36
- def log_error(e)
37
- log_error = ([e.inspect]+backtrace_subset(e)).join("\n")
38
- @log.info("\n----------------error-----\n#{log_error}\n----------------error-----")
39
- end
40
-
41
- action "execute_tests" do
42
- #Get list of component modules that have spec tests
43
- list_output=`ls /etc/puppet/modules/*/dtk/serverspec/spec/localhost/*/*_spec.rb`
44
- regex_pattern=/modules\/(.+)\/dtk\/serverspec\/spec\/localhost\/(.+)\//
45
- ModuleInfo = Struct.new(:module_name, :component_name, :full_component_name)
46
- modules_info = []
47
-
48
- components = []
49
- #Strip away node part (/)...leave only part which represent full component name
50
- request[:components].each do |c|
51
- if c.include? "/"
52
- components << c.split("/").last
53
- else
54
- components << c
55
- end
56
- end
57
-
58
- list_output.each do |line|
59
- match = line.match(regex_pattern)
60
- components.each do |c|
61
- if c.include? "::"
62
- stripped_c = c.split("::").last
63
- modules_info << ModuleInfo.new(match[1],match[2],c) if stripped_c.eql? match[2]
64
- elsif c.eql? match[2]
65
- modules_info << ModuleInfo.new(match[1],match[2],c)
66
- end
67
- end
68
- end
69
-
70
- all_spec_results = []
71
- #filter out redundant module info if any
72
- modules_info = modules_info.uniq
73
- #Pull latest changes for modules if any
74
- git_server = Facts["git-server"]
75
-
76
- begin
77
- modules_info.each do |module_info|
78
- component_module = module_info[:module_name]
79
- component_name = module_info[:component_name]
80
- full_component_name = module_info[:full_component_name]
81
- #Filter out version context for modules that don't exist on node
82
- filtered_version_context = request[:version_context].select { |x| x[:implementation] == module_info[:module_name] }.first
83
- pull_modules(filtered_version_context,git_server)
84
-
85
- @log.info("Executing serverspec test: /etc/puppet/modules/#{component_module}/dtk/serverspec/spec/localhost/#{component_name}/*_spec.rb")
86
- spec_results=`/opt/puppet-omnibus/embedded/bin/rspec /etc/puppet/modules/#{component_module}/dtk/serverspec/spec/localhost/#{component_name}/*_spec.rb --format j 2>&1`
87
- raise spec_results unless spec_results_json = JSON.parse(spec_results)
88
-
89
- spec_results_json['examples'].each do |spec|
90
- spec_result = {}
91
- spec_result.store(:module_name, component_module)
92
- spec_result.store(:component_name, full_component_name)
93
- spec_result.store(:test_result, spec['full_description'])
94
- spec_result.store(:status, spec['status'])
95
- all_spec_results << spec_result
96
- end
97
- end
98
- reply[:data] = all_spec_results
99
- reply[:pbuilderid] = Facts["pbuilderid"]
100
- reply[:status] = :ok
101
- rescue Exception => e
102
- @log.info("Error while executing serverspec test")
103
- @log.info(e.message)
104
- reply[:data] = { :test_error => "#{e.message.lines.first}" }
105
- reply[:pbuilderid] = Facts["pbuilderid"]
106
- reply[:status] = :notok
107
- end
108
- end
109
- end
110
- end
111
- end
@@ -1,9 +0,0 @@
1
- metadata :name => "component module tests executor v2",
2
- :description => "Agent to executing component module infrastructure tests v2",
3
- :author => "Reactor8",
4
- :license => "",
5
- :version => "",
6
- :url => "",
7
- :timeout => 10
8
- action "execute_tests_v2", :description => "execute all component module infrastructure tests v2" do
9
- end
@@ -1,131 +0,0 @@
1
- require 'rspec'
2
- require 'rspec/core'
3
- require 'rspec/core/formatters/json_formatter'
4
- require 'json'
5
-
6
- ModulePath = "/etc/puppet/modules"
7
- ServerspecPath = "serverspec/spec/localhost"
8
-
9
- module MCollective
10
- module Agent
11
- class ServerSpecHelper
12
- def execute(spec_path, vars=[])
13
- vars.each do |var|
14
- var.each_pair do |k,v|
15
- Thread.current[k] = v
16
- end
17
- end
18
-
19
- config = RSpec.configuration
20
- json_formatter = RSpec::Core::Formatters::JsonFormatter.new(config.output)
21
- reporter = RSpec::Core::Reporter.new(json_formatter)
22
- config.instance_variable_set(:@reporter, reporter)
23
- begin
24
- ::RSpec::Core::Runner.run([spec_path,'--format','j'])
25
- json_formatter.output_hash
26
- rescue Exception => e
27
- return e.message
28
- end
29
- end
30
- end
31
-
32
- class Execute_tests_v2 < RPC::Agent
33
- def initialize()
34
- super()
35
- @log = Log.instance
36
- end
37
-
38
- def pull_modules(module_version_context, git_server)
39
- ENV['GIT_SHELL'] = nil #This is put in because if vcsrepo Puppet module used it sets this
40
- begin
41
- repo_dir = "#{ModulePath}/#{module_version_context[:implementation]}"
42
- remote_repo = "#{git_server}:#{module_version_context[:repo]}"
43
- opts = Hash.new
44
- begin
45
- if File.exists?(repo_dir)
46
- @log.info("Branch already exists. Checkout to branch and pull latest changes...")
47
- git_repo = ::DTK::NodeAgent::GitClient.new(repo_dir)
48
- git_repo.pull_and_checkout_branch?(module_version_context[:branch],opts)
49
- else
50
- @log.info("Branch does not exist. Cloning branch...")
51
- git_repo = ::DTK::NodeAgent::GitClient.new(repo_dir,:create=>true)
52
- git_repo.clone_branch(remote_repo,module_version_context[:branch],opts)
53
- end
54
- rescue Exception => e
55
- log_error(e)
56
- #to achieve idempotent behavior; fully remove directory if any problems
57
- FileUtils.rm_rf repo_dir
58
- raise e
59
- end
60
- rescue Exception => e
61
- log_error(e)
62
- end
63
- end
64
-
65
- def log_error(e)
66
- log_error = ([e.inspect]+e.backtrace).join("\n")
67
- @log.info("\n----------------error-----\n#{log_error}\n----------------error-----")
68
- end
69
-
70
- action "execute_tests_v2" do
71
- spec_helper = ServerSpecHelper.new
72
- all_spec_results = []
73
-
74
- #Pull latest changes for modules if any
75
- git_server = Facts["git-server"]
76
-
77
- request[:components].each do |component|
78
- #Filter version context for modules that exist on node
79
- filtered_version_context = request[:version_context].select { |x| x[:implementation] == component[:module_name] }.first
80
- pull_modules(filtered_version_context,git_server)
81
-
82
- component_name = ""
83
- if component[:component].include? "/"
84
- component_name = component[:component].split("/").last
85
- else
86
- component_name = component[:component]
87
- end
88
-
89
- #all_tests needs to be calculated after the pull module done
90
- all_tests = Dir["#{ModulePath}/*/#{ServerspecPath}/*.rb"]
91
- test = all_tests.select { |test| (test.include? component[:test_name]) && (test.include? component[:module_name]) }
92
- @log.info("Executing serverspec test: #{test.first}")
93
- spec_results = spec_helper.execute(test.first, component[:params])
94
- @log.info("Serverspec results: #{spec_results}")
95
-
96
- if spec_results.is_a?(Hash)
97
- spec_results[:examples].each do |spec|
98
- spec_result = {}
99
- spec_result.store(:module_name, component[:module_name])
100
- spec_result.store(:component_name, component_name)
101
- spec_result.store(:test_component_name, component[:test_component])
102
- spec_result.store(:test_name, component[:test_name])
103
- spec_result.store(:test_result, spec[:full_description])
104
- spec_result.store(:status, spec[:status])
105
-
106
- if spec[:status].include? "failed"
107
- backtrace = spec[:exception][:backtrace].find { |x| x.include? component[:module_name] }
108
- error = backtrace + " " + spec[:exception][:class] + ": " + spec[:exception][:message]
109
- spec_result.store(:test_error, error)
110
- end
111
- all_spec_results << spec_result
112
- end
113
- else
114
- spec_result = {}
115
- spec_result.store(:module_name, component[:module_name])
116
- spec_result.store(:component_name, component_name)
117
- spec_result.store(:test_component_name, component[:test_component])
118
- spec_result.store(:test_name, component[:test_name])
119
- spec_result.store(:test_result, "N/A")
120
- spec_result.store(:status, "failed")
121
- spec_result.store(:test_error, spec_results)
122
- all_spec_results << spec_result
123
- end
124
- end
125
- reply[:data] = all_spec_results
126
- reply[:pbuilderid] = Facts["pbuilderid"]
127
- reply[:status] = :ok
128
- end
129
- end
130
- end
131
- end
@@ -1,15 +0,0 @@
1
- metadata :name => "get log fragment",
2
- :description => "get log fragment",
3
- :author => "Reactor8",
4
- :license => "",
5
- :version => "",
6
- :url => "",
7
- :timeout => 20
8
- action "get", :description => "get log data fragment" do
9
- display :always
10
- %w{status error data pbuilderid}.each do |k|
11
- output k.to_sym,
12
- :description => k.capitalize,
13
- :display_as => k.capitalize
14
- end
15
- end
@@ -1,79 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'rubygems'
3
-
4
- module MCollective
5
- #TODO: shoudl go in common area
6
- LogFileHandles = {:task_id => Hash.new, :top_task_id => Hash.new}
7
-
8
- module Agent
9
- class Get_log_fragment < RPC::Agent
10
- metadata :name => "get log fragment",
11
- :description => "get log fragment",
12
- :author => "Reactor8",
13
- :license => "",
14
- :version => "",
15
- :url => "",
16
- :timeout => 20
17
- def initialize()
18
- super()
19
- @log = Log.instance
20
- end
21
- def get_action()
22
- validate :key, String
23
- validate :value, String
24
- log_file_dir = "/var/log/puppet"
25
- key = request[:key]
26
- value = request[:value]
27
- lines = get_log_fragment(log_file_dir,key,value)
28
- pbuilderid = Facts["pbuilderid"]
29
- if lines.nil?
30
- error_msg = "Cannot find log fragment matching #{key}=#{value}"
31
- error_response = {
32
- :status => :failed,
33
- :error => {
34
- :message => error_msg
35
- },
36
- :pbuilderid => pbuilderid
37
- }
38
- @log.error(error_msg)
39
- reply.data = error_response
40
- else
41
- ok_response = {
42
- :status => :ok,
43
- :data => lines,
44
- :pbuilderid => pbuilderid
45
- }
46
- reply.data = ok_response
47
- end
48
- end
49
- private
50
- def get_log_fragment(log_file_dir,key,value)
51
- #flush file if it is open
52
- if file_handle = (LogFileHandles[key.to_sym]||{})[value]
53
- file_handle.flush
54
- end
55
-
56
- delim = key.to_sym == :top_task_id ? "\\." : ":"
57
- string_key = "#{key}:#{value.to_s}#{delim}"
58
- ret = Array.new
59
- matches = Dir["#{log_file_dir}/*.log"].grep(Regexp.new(string_key))
60
- if matches.size == 0
61
- return nil
62
- end
63
- matching_file = matches.size == 1 ?
64
- matches.first :
65
- #this finds teh most recent file
66
- matches.map{|file|[file,File.mtime(file)]}.sort{|a,b|b[1]<=>a[1]}.first[0]
67
- begin
68
- f = File.open(matching_file)
69
- until f.eof
70
- ret << f.readline.chop
71
- end
72
- ensure
73
- f.close
74
- end
75
- ret
76
- end
77
- end
78
- end
79
- end