sonar_push_connector 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Trampoline Systems Ltd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = sonar-push-connector
2
+
3
+ a connector for the sonar-connector framework : pushes content to the sonar-server
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Trampoline Systems Ltd. See LICENSE for details.
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "sonar_push_connector"
8
+ gem.summary = %Q{A push plugin for the Trampoline SONAR connector}
9
+ gem.description = %Q{Plugin to push email JSON data to an instance of SONAR. Works in tandem with the sonar-exchange-pull-connector.}
10
+ gem.email = "hello@empire42.com"
11
+ gem.homepage = "http://github.com/trampoline/sonar-push-connector"
12
+ gem.authors = ["Peter MacRobert", "Mark Meyer"]
13
+
14
+ gem.add_dependency "sonar_connector", ">= 0.5.1"
15
+ gem.add_dependency "activesupport", ">= 2.3.5"
16
+ gem.add_dependency "json_pure", ">= 1.2.2"
17
+
18
+ gem.add_development_dependency "rspec", ">= 1.2.9"
19
+ gem.add_development_dependency "rr", ">= 0.10.5"
20
+ end
21
+ Jeweler::GemcutterTasks.new
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
24
+ end
25
+
26
+ require 'spec/rake/spectask'
27
+ Spec::Rake::SpecTask.new(:spec) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.spec_files = FileList['spec/**/*_spec.rb']
30
+ end
31
+
32
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
33
+ spec.libs << 'lib' << 'spec'
34
+ spec.pattern = 'spec/**/*_spec.rb'
35
+ spec.rcov = true
36
+ end
37
+
38
+ task :default => :spec
39
+ task :spec => :check_dependencies
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.8.0
@@ -0,0 +1,59 @@
1
+ require 'sonar_connector'
2
+ require 'uri'
3
+ require 'net/http'
4
+
5
+ module Sonar
6
+ module Connector
7
+ class SonarPushConnector < Sonar::Connector::Base
8
+
9
+ attr_reader :uri
10
+ attr_reader :batch_size
11
+ attr_reader :connector_credentials
12
+
13
+ def parse(settings)
14
+ @uri = settings["uri"]
15
+ raise Sonar::Connector::InvalidConfig.new("Connector '#{name}': parameter 'uri' required.") if @uri.blank?
16
+
17
+ @connector_credentials = settings["connector_credentials"]
18
+ raise Sonar::Connector::InvalidConfig.new("Connector '#{name}': parameter 'connector_credentials' required") if @connector_credentials.blank?
19
+
20
+ # ensure that there's a source connector to pull data from
21
+ raise Sonar::Connector::InvalidConfig.new("Connector '#{name}': parameter 'source_connectors' required.") if settings["source_connectors"].blank? || settings["source_connectors"].empty?
22
+
23
+
24
+ @batch_size = settings["batch_size"] || 50
25
+ end
26
+
27
+ def action
28
+ source_connectors.each {|c| c.connector_filestore.flip(:complete, filestore, :working) }
29
+
30
+ begin
31
+ count = filestore.process_batch(@batch_size, :working) do |files|
32
+ paths = files.map{|f| filestore.file_path(:working, f)}
33
+ begin
34
+ log.debug"pushing #{files.length} files"
35
+ push_batch(paths)
36
+ rescue Exception => e
37
+ log.warn ["caught an exception : leaving files in working area",
38
+ e.class.to_s, e.message, e.backtrace].join('\n')
39
+ raise Sonar::Connector::FileStore::LeaveInSourceArea, e.message
40
+ end
41
+ end
42
+ end while count>0
43
+ end
44
+
45
+ def push_batch(files)
46
+ params = {"messages" => files.map{|file| JSON.parse(File.read file)}.to_json,
47
+ "connector_credentials" => connector_credentials}
48
+ res = Net::HTTP.post_form URI.parse(uri), params
49
+ case res
50
+ when Net::HTTPSuccess, Net::HTTPRedirection
51
+ log.info "pushed #{files.size} messages to #{uri}"
52
+ else
53
+ res.error!
54
+ end
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sonar::Connector::SonarPushConnector do
4
+ before do
5
+ # @connector = Sonar::Connector::SonarPushConnector.new
6
+ end
7
+
8
+ it "should be cool" do
9
+
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'rubygems'
5
+ require 'sonar_push_connector'
6
+
7
+ require 'sonar_connector/rspec/spec_helper'
8
+
9
+ require 'spec'
10
+ require 'spec/autorun'
11
+ require 'rr'
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sonar_push_connector
3
+ version: !ruby/object:Gem::Version
4
+ hash: 63
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
11
+ platform: ruby
12
+ authors:
13
+ - Peter MacRobert
14
+ - Mark Meyer
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-03-25 00:00:00 +00:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: sonar_connector
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 9
31
+ segments:
32
+ - 0
33
+ - 5
34
+ - 1
35
+ version: 0.5.1
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: activesupport
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 9
47
+ segments:
48
+ - 2
49
+ - 3
50
+ - 5
51
+ version: 2.3.5
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: json_pure
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 27
63
+ segments:
64
+ - 1
65
+ - 2
66
+ - 2
67
+ version: 1.2.2
68
+ type: :runtime
69
+ version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 13
79
+ segments:
80
+ - 1
81
+ - 2
82
+ - 9
83
+ version: 1.2.9
84
+ type: :development
85
+ version_requirements: *id004
86
+ - !ruby/object:Gem::Dependency
87
+ name: rr
88
+ prerelease: false
89
+ requirement: &id005 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 61
95
+ segments:
96
+ - 0
97
+ - 10
98
+ - 5
99
+ version: 0.10.5
100
+ type: :development
101
+ version_requirements: *id005
102
+ description: Plugin to push email JSON data to an instance of SONAR. Works in tandem with the sonar-exchange-pull-connector.
103
+ email: hello@empire42.com
104
+ executables: []
105
+
106
+ extensions: []
107
+
108
+ extra_rdoc_files:
109
+ - LICENSE
110
+ - README.rdoc
111
+ files:
112
+ - .document
113
+ - LICENSE
114
+ - README.rdoc
115
+ - Rakefile
116
+ - VERSION
117
+ - lib/sonar_push_connector.rb
118
+ - spec/sonar_push_connector_spec.rb
119
+ - spec/spec_helper.rb
120
+ has_rdoc: true
121
+ homepage: http://github.com/trampoline/sonar-push-connector
122
+ licenses: []
123
+
124
+ post_install_message:
125
+ rdoc_options: []
126
+
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: 3
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ requirements: []
148
+
149
+ rubyforge_project:
150
+ rubygems_version: 1.6.2
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: A push plugin for the Trampoline SONAR connector
154
+ test_files:
155
+ - spec/sonar_push_connector_spec.rb
156
+ - spec/spec_helper.rb